Browse Source

some work + fixed red errors on malformed input

pull/948/head
hypnosis-i2p 7 years ago
parent
commit
96cb663fa8
  1. 4
      qt/i2pd_qt/ClientTunnelPane.cpp
  2. 2
      qt/i2pd_qt/ClientTunnelPane.h
  3. 4
      qt/i2pd_qt/ServerTunnelPane.cpp
  4. 8
      qt/i2pd_qt/ServerTunnelPane.h
  5. 14
      qt/i2pd_qt/TunnelPane.cpp
  6. 16
      qt/i2pd_qt/TunnelPane.h
  7. 26
      qt/i2pd_qt/mainwindow.cpp
  8. 10
      qt/i2pd_qt/mainwindow.h
  9. 6
      qt/i2pd_qt/mainwindow.ui

4
qt/i2pd_qt/ClientTunnelPane.cpp

@ -3,8 +3,8 @@ @@ -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);

2
qt/i2pd_qt/ClientTunnelPane.h

@ -14,7 +14,7 @@ class TunnelPane; @@ -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();

4
qt/i2pd_qt/ServerTunnelPane.cpp

@ -2,8 +2,8 @@ @@ -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);

8
qt/i2pd_qt/ServerTunnelPane.h

@ -1,9 +1,6 @@ @@ -1,9 +1,6 @@
#ifndef SERVERTUNNELPANE_H
#define SERVERTUNNELPANE_H
#include "TunnelPane.h"
#include "TunnelsPageUpdateListener.h"
#include <QtCore/QVariant>
#include <QtWidgets/QAction>
#include <QtWidgets/QApplication>
@ -23,6 +20,9 @@ @@ -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 { @@ -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();

14
qt/i2pd_qt/TunnelPane.cpp

@ -1,8 +1,11 @@ @@ -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, @@ -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 @@ -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();
}

16
qt/i2pd_qt/TunnelPane.h

@ -23,27 +23,26 @@ class ClientTunnelPane; @@ -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: @@ -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: @@ -106,7 +106,7 @@ protected:
i2cpParams.setCrypto_tagsToSend(crypto_tagsToSendLineEdit->text());
return true;
}
protected:
void setupTunnelPane(
TunnelConfig* tunnelConfig,
QGroupBox *tunnelGroupBox,

26
qt/i2pd_qt/mainwindow.cpp

@ -699,22 +699,28 @@ void MainWindow::appendTunnelForms(std::string tunnelNameToFocus) { @@ -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) { @@ -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<TunnelPane*>::iterator it=tunnelPanes.begin(); it!=tunnelPanes.end(); ++it) {
TunnelPane* tunpane = *it;
if(!tunpane->applyDataFromUIToTunnelConfig()) {
//!valid
return;
}
}
for (std::map<std::string,TunnelConfig*>::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 @@ -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 @@ -849,4 +864,5 @@ void MainWindow::highlightWrongInput(QString warningText, QWidget* widgetToFocus
ui->wrongInputLabel->setVisible(true);
ui->wrongInputLabel->setText(warningText);
if(widgetToFocus)widgetToFocus->setFocus();
showSettingsPage();
}

10
qt/i2pd_qt/mainwindow.h

@ -411,7 +411,7 @@ private slots: @@ -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: @@ -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: @@ -609,7 +609,7 @@ private:
destinationPort,
sigType);
SaveTunnelsConfig();
saveAllConfigs();
reloadTunnelsConfigAndUI(name);
}
@ -648,7 +648,7 @@ private: @@ -648,7 +648,7 @@ private:
isUniqueLocal);
SaveTunnelsConfig();
saveAllConfigs();
reloadTunnelsConfigAndUI(name);
}

6
qt/i2pd_qt/mainwindow.ui

@ -624,7 +624,7 @@ @@ -624,7 +624,7 @@
</size>
</property>
<property name="currentIndex">
<number>0</number>
<number>1</number>
</property>
<widget class="QWidget" name="statusPage">
<property name="sizePolicy">
@ -719,8 +719,8 @@ @@ -719,8 +719,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>80</width>
<height>26</height>
<width>689</width>
<height>496</height>
</rect>
</property>
<property name="sizePolicy">

Loading…
Cancel
Save