Skip to content

Commit

Permalink
some work + fixed red errors on malformed input
Browse files Browse the repository at this point in the history
  • Loading branch information
nonlin-lin-chaos-order-etc-etal committed Sep 8, 2017
1 parent 1efc2a9 commit 96cb663
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 32 deletions.
4 changes: 2 additions & 2 deletions qt/i2pd_qt/ClientTunnelPane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion qt/i2pd_qt/ClientTunnelPane.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions qt/i2pd_qt/ServerTunnelPane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions qt/i2pd_qt/ServerTunnelPane.h
Original file line number Diff line number Diff line change
@@ -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>
Expand All @@ -23,6 +20,9 @@

#include "assert.h"

#include "TunnelPane.h"
#include "TunnelsPageUpdateListener.h"

class ServerTunnelConfig;

class ClientTunnelPane;
Expand All @@ -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();
Expand Down
14 changes: 12 additions & 2 deletions qt/i2pd_qt/TunnelPane.cpp
Original file line number Diff line number Diff line change
@@ -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_),
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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 changes: 8 additions & 8 deletions qt/i2pd_qt/TunnelPane.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -93,6 +92,7 @@ public slots:
//should be created by factory
i2p::data::SigningKeyType readSigTypeComboboxUI(QComboBox* sigTypeComboBox);

public:
//returns false when invalid data at UI
virtual bool applyDataFromUIToTunnelConfig() {
hideWrongInputLabel();
Expand All @@ -106,7 +106,7 @@ public slots:
i2cpParams.setCrypto_tagsToSend(crypto_tagsToSendLineEdit->text());
return true;
}

protected:
void setupTunnelPane(
TunnelConfig* tunnelConfig,
QGroupBox *tunnelGroupBox,
Expand Down
26 changes: 21 additions & 5 deletions qt/i2pd_qt/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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){
Expand Down Expand Up @@ -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 changes: 5 additions & 5 deletions qt/i2pd_qt/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -572,9 +572,9 @@ public slots:
TunnelConfig* tc=it->second;
tunnelConfigs.erase(it);
delete tc;
SaveTunnelsConfig();
reloadTunnelsConfigAndUI("");
}
saveAllConfigs();
reloadTunnelsConfigAndUI("");
}

std::string GenerateNewTunnelName() {
Expand Down Expand Up @@ -609,7 +609,7 @@ public slots:
destinationPort,
sigType);

SaveTunnelsConfig();
saveAllConfigs();
reloadTunnelsConfigAndUI(name);
}

Expand Down Expand Up @@ -648,7 +648,7 @@ public slots:
isUniqueLocal);


SaveTunnelsConfig();
saveAllConfigs();
reloadTunnelsConfigAndUI(name);
}

Expand Down
6 changes: 3 additions & 3 deletions qt/i2pd_qt/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@
</size>
</property>
<property name="currentIndex">
<number>0</number>
<number>1</number>
</property>
<widget class="QWidget" name="statusPage">
<property name="sizePolicy">
Expand Down Expand Up @@ -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">
Expand Down

0 comments on commit 96cb663

Please sign in to comment.