From 96cb663fa8ce218065350f9d3ae3a4183f6c9cec Mon Sep 17 00:00:00 2001 From: hypnosis-i2p Date: Fri, 8 Sep 2017 18:58:04 +0800 Subject: [PATCH] some work + fixed red errors on malformed input --- qt/i2pd_qt/ClientTunnelPane.cpp | 4 ++-- qt/i2pd_qt/ClientTunnelPane.h | 2 +- qt/i2pd_qt/ServerTunnelPane.cpp | 4 ++-- qt/i2pd_qt/ServerTunnelPane.h | 8 ++++---- qt/i2pd_qt/TunnelPane.cpp | 14 ++++++++++++-- qt/i2pd_qt/TunnelPane.h | 16 ++++++++-------- qt/i2pd_qt/mainwindow.cpp | 26 +++++++++++++++++++++----- qt/i2pd_qt/mainwindow.h | 10 +++++----- qt/i2pd_qt/mainwindow.ui | 6 +++--- 9 files changed, 58 insertions(+), 32 deletions(-) diff --git a/qt/i2pd_qt/ClientTunnelPane.cpp b/qt/i2pd_qt/ClientTunnelPane.cpp index 4d4bb5ce..256d0510 100644 --- a/qt/i2pd_qt/ClientTunnelPane.cpp +++ b/qt/i2pd_qt/ClientTunnelPane.cpp @@ -3,8 +3,8 @@ #include "SignatureTypeComboboxFactory.h" #include "QVBoxLayout" -ClientTunnelPane::ClientTunnelPane(TunnelsPageUpdateListener* tunnelsPageUpdateListener, ClientTunnelConfig* tunconf, QWidget* wrongInputPane_, QLabel* wrongInputLabel_): - TunnelPane(tunnelsPageUpdateListener, tunconf, wrongInputPane_, wrongInputLabel_) {} +ClientTunnelPane::ClientTunnelPane(TunnelsPageUpdateListener* tunnelsPageUpdateListener, ClientTunnelConfig* tunconf, QWidget* wrongInputPane_, QLabel* wrongInputLabel_, MainWindow* mainWindow): + TunnelPane(tunnelsPageUpdateListener, tunconf, wrongInputPane_, wrongInputLabel_, mainWindow) {} void ClientTunnelPane::setGroupBoxTitle(const QString & title) { clientTunnelNameGroupBox->setTitle(title); diff --git a/qt/i2pd_qt/ClientTunnelPane.h b/qt/i2pd_qt/ClientTunnelPane.h index 0b80103e..c2e076b7 100644 --- a/qt/i2pd_qt/ClientTunnelPane.h +++ b/qt/i2pd_qt/ClientTunnelPane.h @@ -14,7 +14,7 @@ class TunnelPane; class ClientTunnelPane : public TunnelPane { Q_OBJECT public: - ClientTunnelPane(TunnelsPageUpdateListener* tunnelsPageUpdateListener, ClientTunnelConfig* tunconf, QWidget* wrongInputPane_, QLabel* wrongInputLabel_); + ClientTunnelPane(TunnelsPageUpdateListener* tunnelsPageUpdateListener, ClientTunnelConfig* tunconf, QWidget* wrongInputPane_, QLabel* wrongInputLabel_, MainWindow* mainWindow); virtual ~ClientTunnelPane(){} virtual ServerTunnelPane* asServerTunnelPane(); virtual ClientTunnelPane* asClientTunnelPane(); diff --git a/qt/i2pd_qt/ServerTunnelPane.cpp b/qt/i2pd_qt/ServerTunnelPane.cpp index a2ba9558..029a3ea2 100644 --- a/qt/i2pd_qt/ServerTunnelPane.cpp +++ b/qt/i2pd_qt/ServerTunnelPane.cpp @@ -2,8 +2,8 @@ #include "ClientContext.h" #include "SignatureTypeComboboxFactory.h" -ServerTunnelPane::ServerTunnelPane(TunnelsPageUpdateListener* tunnelsPageUpdateListener, ServerTunnelConfig* tunconf, QWidget* wrongInputPane_, QLabel* wrongInputLabel_): - TunnelPane(tunnelsPageUpdateListener, tunconf, wrongInputPane_, wrongInputLabel_) {} +ServerTunnelPane::ServerTunnelPane(TunnelsPageUpdateListener* tunnelsPageUpdateListener, ServerTunnelConfig* tunconf, QWidget* wrongInputPane_, QLabel* wrongInputLabel_, MainWindow* mainWindow): + TunnelPane(tunnelsPageUpdateListener, tunconf, wrongInputPane_, wrongInputLabel_, mainWindow) {} void ServerTunnelPane::setGroupBoxTitle(const QString & title) { serverTunnelNameGroupBox->setTitle(title); diff --git a/qt/i2pd_qt/ServerTunnelPane.h b/qt/i2pd_qt/ServerTunnelPane.h index b7b5ef1c..556c8473 100644 --- a/qt/i2pd_qt/ServerTunnelPane.h +++ b/qt/i2pd_qt/ServerTunnelPane.h @@ -1,9 +1,6 @@ #ifndef SERVERTUNNELPANE_H #define SERVERTUNNELPANE_H -#include "TunnelPane.h" -#include "TunnelsPageUpdateListener.h" - #include #include #include @@ -23,6 +20,9 @@ #include "assert.h" +#include "TunnelPane.h" +#include "TunnelsPageUpdateListener.h" + class ServerTunnelConfig; class ClientTunnelPane; @@ -31,7 +31,7 @@ class ServerTunnelPane : public TunnelPane { Q_OBJECT public: - ServerTunnelPane(TunnelsPageUpdateListener* tunnelsPageUpdateListener, ServerTunnelConfig* tunconf, QWidget* wrongInputPane_, QLabel* wrongInputLabel_); + ServerTunnelPane(TunnelsPageUpdateListener* tunnelsPageUpdateListener, ServerTunnelConfig* tunconf, QWidget* wrongInputPane_, QLabel* wrongInputLabel_, MainWindow* mainWindow); virtual ~ServerTunnelPane(){} virtual ServerTunnelPane* asServerTunnelPane(); diff --git a/qt/i2pd_qt/TunnelPane.cpp b/qt/i2pd_qt/TunnelPane.cpp index a86adbb1..48adcf78 100644 --- a/qt/i2pd_qt/TunnelPane.cpp +++ b/qt/i2pd_qt/TunnelPane.cpp @@ -1,8 +1,11 @@ #include "TunnelPane.h" + #include "QMessageBox" +#include "mainwindow.h" -TunnelPane::TunnelPane(TunnelsPageUpdateListener* tunnelsPageUpdateListener_, TunnelConfig* tunnelConfig_, QWidget* wrongInputPane_, QLabel* wrongInputLabel_): +TunnelPane::TunnelPane(TunnelsPageUpdateListener* tunnelsPageUpdateListener_, TunnelConfig* tunnelConfig_, QWidget* wrongInputPane_, QLabel* wrongInputLabel_, MainWindow* mainWindow_): QObject(), + mainWindow(mainWindow_), wrongInputPane(wrongInputPane_), wrongInputLabel(wrongInputLabel_), tunnelConfig(tunnelConfig_), @@ -181,7 +184,7 @@ void TunnelPane::appendControlsForI2CPParameters(I2CPParameters& i2cpParameters, void TunnelPane::updated() { std::string oldName=tunnelConfig->getName(); - if(!applyDataFromUIToTunnelConfig())return;//TODO visualise bad input + if(!applyDataFromUIToTunnelConfig())return; tunnelsPageUpdateListener->updated(oldName, tunnelConfig); } @@ -224,3 +227,10 @@ i2p::data::SigningKeyType TunnelPane::readSigTypeComboboxUI(QComboBox* sigTypeCo void TunnelPane::deleteTunnelForm() { widgetlocks.deleteListeners(); } + +void TunnelPane::highlightWrongInput(QString warningText, QWidget* controlWithWrongInput) { + wrongInputPane->setVisible(true); + wrongInputLabel->setText(warningText); + if(controlWithWrongInput)controlWithWrongInput->setFocus(); + mainWindow->showTunnelsPage(); +} diff --git a/qt/i2pd_qt/TunnelPane.h b/qt/i2pd_qt/TunnelPane.h index 8d28f07f..3a647635 100644 --- a/qt/i2pd_qt/TunnelPane.h +++ b/qt/i2pd_qt/TunnelPane.h @@ -23,27 +23,26 @@ class ClientTunnelPane; class TunnelConfig; class I2CPParameters; +class MainWindow; + class TunnelPane : public QObject { Q_OBJECT public: - TunnelPane(TunnelsPageUpdateListener* tunnelsPageUpdateListener_, TunnelConfig* tunconf, QWidget* wrongInputPane_, QLabel* wrongInputLabel_); + TunnelPane(TunnelsPageUpdateListener* tunnelsPageUpdateListener_, TunnelConfig* tunconf, QWidget* wrongInputPane_, QLabel* wrongInputLabel_, MainWindow* mainWindow_); virtual ~TunnelPane(){} void deleteTunnelForm(); - void hideWrongInputLabel() { wrongInputPane->setVisible(false); } - void highlightWrongInput(QString warningText, QWidget* controlWithWrongInput) { - wrongInputPane->setVisible(true); - wrongInputLabel->setText(warningText); - if(controlWithWrongInput)controlWithWrongInput->setFocus(); - } + void hideWrongInputLabel() const { wrongInputPane->setVisible(false); } + void highlightWrongInput(QString warningText, QWidget* controlWithWrongInput); virtual ServerTunnelPane* asServerTunnelPane()=0; virtual ClientTunnelPane* asClientTunnelPane()=0; protected: + MainWindow* mainWindow; QWidget * wrongInputPane; QLabel* wrongInputLabel; TunnelConfig* tunnelConfig; @@ -93,6 +92,7 @@ protected: //should be created by factory i2p::data::SigningKeyType readSigTypeComboboxUI(QComboBox* sigTypeComboBox); +public: //returns false when invalid data at UI virtual bool applyDataFromUIToTunnelConfig() { hideWrongInputLabel(); @@ -106,7 +106,7 @@ protected: i2cpParams.setCrypto_tagsToSend(crypto_tagsToSendLineEdit->text()); return true; } - +protected: void setupTunnelPane( TunnelConfig* tunnelConfig, QGroupBox *tunnelGroupBox, diff --git a/qt/i2pd_qt/mainwindow.cpp b/qt/i2pd_qt/mainwindow.cpp index ec636646..7f9810cc 100644 --- a/qt/i2pd_qt/mainwindow.cpp +++ b/qt/i2pd_qt/mainwindow.cpp @@ -699,22 +699,28 @@ void MainWindow::appendTunnelForms(std::string tunnelNameToFocus) { TunnelConfig* tunconf = it->second; ServerTunnelConfig* stc = tunconf->asServerTunnelConfig(); if(stc){ - ServerTunnelPane * tunnelPane=new ServerTunnelPane(&tunnelsPageUpdateListener, stc, ui->wrongInputLabel, ui->wrongInputLabel); + ServerTunnelPane * tunnelPane=new ServerTunnelPane(&tunnelsPageUpdateListener, stc, ui->wrongInputLabel, ui->wrongInputLabel, this); int h=tunnelPane->appendServerTunnelForm(stc, ui->tunnelsScrollAreaWidgetContents, tunnelPanes.size(), height); height+=h; //qDebug() << "tun.height:" << height << "sz:" << tunnelPanes.size(); tunnelPanes.push_back(tunnelPane); - if(name==tunnelNameToFocus)tunnelPane->getNameLineEdit()->setFocus(); + if(name==tunnelNameToFocus){ + tunnelPane->getNameLineEdit()->setFocus(); + //todo ui->settingsScrollArea->###scroll + } continue; } ClientTunnelConfig* ctc = tunconf->asClientTunnelConfig(); if(ctc){ - ClientTunnelPane * tunnelPane=new ClientTunnelPane(&tunnelsPageUpdateListener, ctc, ui->wrongInputLabel, ui->wrongInputLabel); + ClientTunnelPane * tunnelPane=new ClientTunnelPane(&tunnelsPageUpdateListener, ctc, ui->wrongInputLabel, ui->wrongInputLabel, this); int h=tunnelPane->appendClientTunnelForm(ctc, ui->tunnelsScrollAreaWidgetContents, tunnelPanes.size(), height); height+=h; //qDebug() << "tun.height:" << height << "sz:" << tunnelPanes.size(); tunnelPanes.push_back(tunnelPane); - if(name==tunnelNameToFocus)tunnelPane->getNameLineEdit()->setFocus(); + if(name==tunnelNameToFocus){ + tunnelPane->getNameLineEdit()->setFocus(); + //todo ui->settingsScrollArea->###scroll + } continue; } throw "unknown TunnelConfig subtype"; @@ -759,6 +765,15 @@ void MainWindow::reloadTunnelsConfigAndUI(std::string tunnelNameToFocus) { void MainWindow::SaveTunnelsConfig() { std::stringstream out; + //validate and show red if wrong + for (std::list::iterator it=tunnelPanes.begin(); it!=tunnelPanes.end(); ++it) { + TunnelPane* tunpane = *it; + if(!tunpane->applyDataFromUIToTunnelConfig()) { + //!valid + return; + } + } + for (std::map::iterator it=tunnelConfigs.begin(); it!=tunnelConfigs.end(); ++it) { const std::string& name = it->first; TunnelConfig* tunconf = it->second; @@ -788,7 +803,7 @@ void MainWindow::TunnelsPageUpdateListenerMainWindowImpl::updated(std::string ol if(it!=mainWindow->tunnelConfigs.end())mainWindow->tunnelConfigs.erase(it); mainWindow->tunnelConfigs[tunConf->getName()]=tunConf; } - mainWindow->SaveTunnelsConfig(); + mainWindow->saveAllConfigs(); } void MainWindow::TunnelsPageUpdateListenerMainWindowImpl::needsDeleting(std::string oldName){ @@ -849,4 +864,5 @@ void MainWindow::highlightWrongInput(QString warningText, QWidget* widgetToFocus ui->wrongInputLabel->setVisible(true); ui->wrongInputLabel->setText(warningText); if(widgetToFocus)widgetToFocus->setFocus(); + showSettingsPage(); } diff --git a/qt/i2pd_qt/mainwindow.h b/qt/i2pd_qt/mainwindow.h index 1805ad87..831ce7b5 100644 --- a/qt/i2pd_qt/mainwindow.h +++ b/qt/i2pd_qt/mainwindow.h @@ -411,7 +411,7 @@ private slots: void runPeerTest(); void enableTransit(); void disableTransit(); - +public slots: void showStatus_local_destinations_Page(); void showStatus_leasesets_Page(); void showStatus_tunnels_Page(); @@ -572,9 +572,9 @@ private: TunnelConfig* tc=it->second; tunnelConfigs.erase(it); delete tc; - SaveTunnelsConfig(); - reloadTunnelsConfigAndUI(""); } + saveAllConfigs(); + reloadTunnelsConfigAndUI(""); } std::string GenerateNewTunnelName() { @@ -609,7 +609,7 @@ private: destinationPort, sigType); - SaveTunnelsConfig(); + saveAllConfigs(); reloadTunnelsConfigAndUI(name); } @@ -648,7 +648,7 @@ private: isUniqueLocal); - SaveTunnelsConfig(); + saveAllConfigs(); reloadTunnelsConfigAndUI(name); } diff --git a/qt/i2pd_qt/mainwindow.ui b/qt/i2pd_qt/mainwindow.ui index 2363614b..bdd4693d 100644 --- a/qt/i2pd_qt/mainwindow.ui +++ b/qt/i2pd_qt/mainwindow.ui @@ -624,7 +624,7 @@ - 0 + 1 @@ -719,8 +719,8 @@ 0 0 - 80 - 26 + 689 + 496