mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 16:34:13 +00:00
qt: fixes #1180
This commit is contained in:
parent
d3bf8c2417
commit
ccc604c0f4
@ -79,6 +79,13 @@ protected:
|
|||||||
ClientTunnelConfig* ctc=tunnelConfig->asClientTunnelConfig();
|
ClientTunnelConfig* ctc=tunnelConfig->asClientTunnelConfig();
|
||||||
assert(ctc!=nullptr);
|
assert(ctc!=nullptr);
|
||||||
|
|
||||||
|
if(!isValidSingleLine(destinationLineEdit))return false;
|
||||||
|
if(!isValidSingleLine(portLineEdit))return false;
|
||||||
|
if(!isValidSingleLine(cryptoTypeLineEdit))return false;
|
||||||
|
if(!isValidSingleLine(keysLineEdit))return false;
|
||||||
|
if(!isValidSingleLine(addressLineEdit))return false;
|
||||||
|
if(!isValidSingleLine(destinationPortLineEdit))return false;
|
||||||
|
|
||||||
//destination
|
//destination
|
||||||
ctc->setdest(destinationLineEdit->text().toStdString());
|
ctc->setdest(destinationLineEdit->text().toStdString());
|
||||||
|
|
||||||
|
12
qt/i2pd_qt/I2pdQtUtil.cpp
Normal file
12
qt/i2pd_qt/I2pdQtUtil.cpp
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#include "I2pdQtUtil.h"
|
||||||
|
|
||||||
|
bool isValidSingleLine(QLineEdit* widget, WrongInputPageEnum inputPage, MainWindow* mainWindow) {
|
||||||
|
bool correct = !widget->text().contains(QRegularExpression("[\r\n]"), nullptr);
|
||||||
|
if(!correct) {
|
||||||
|
mainWindow->highlightWrongInput(
|
||||||
|
QApplication::tr("Single line input expected, but it's multiline"),
|
||||||
|
inputPage,
|
||||||
|
widget);
|
||||||
|
}
|
||||||
|
return correct;
|
||||||
|
}
|
9
qt/i2pd_qt/I2pdQtUtil.h
Normal file
9
qt/i2pd_qt/I2pdQtUtil.h
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#ifndef I2pdQtUtil_H
|
||||||
|
#define I2pdQtUtil_H
|
||||||
|
|
||||||
|
class QLineEdit;
|
||||||
|
#include "mainwindow.h"
|
||||||
|
|
||||||
|
bool isValidSingleLine(QLineEdit* widget, WrongInputPageEnum inputPage, MainWindow* mainWindow);
|
||||||
|
|
||||||
|
#endif // I2pdQtUtil_H
|
@ -124,6 +124,17 @@ protected:
|
|||||||
if(!ok)return false;
|
if(!ok)return false;
|
||||||
ServerTunnelConfig* stc=tunnelConfig->asServerTunnelConfig();
|
ServerTunnelConfig* stc=tunnelConfig->asServerTunnelConfig();
|
||||||
assert(stc!=nullptr);
|
assert(stc!=nullptr);
|
||||||
|
|
||||||
|
if(!isValidSingleLine(hostLineEdit))return false;
|
||||||
|
if(!isValidSingleLine(portLineEdit))return false;
|
||||||
|
if(!isValidSingleLine(cryptoTypeLineEdit))return false;
|
||||||
|
if(!isValidSingleLine(keysLineEdit))return false;
|
||||||
|
if(!isValidSingleLine(inPortLineEdit))return false;
|
||||||
|
if(!isValidSingleLine(accessListLineEdit))return false;
|
||||||
|
if(!isValidSingleLine(hostOverrideLineEdit))return false;
|
||||||
|
if(!isValidSingleLine(webIRCPassLineEdit))return false;
|
||||||
|
if(!isValidSingleLine(addressLineEdit))return false;
|
||||||
|
|
||||||
stc->sethost(hostLineEdit->text().toStdString());
|
stc->sethost(hostLineEdit->text().toStdString());
|
||||||
|
|
||||||
auto portStr=portLineEdit->text();
|
auto portStr=portLineEdit->text();
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "ui_mainwindow.h"
|
#include "ui_mainwindow.h"
|
||||||
|
|
||||||
|
#include "I2pdQtUtil.h"
|
||||||
|
|
||||||
TunnelPane::TunnelPane(TunnelsPageUpdateListener* tunnelsPageUpdateListener_, TunnelConfig* tunnelConfig_, QWidget* wrongInputPane_, QLabel* wrongInputLabel_, MainWindow* mainWindow_):
|
TunnelPane::TunnelPane(TunnelsPageUpdateListener* tunnelsPageUpdateListener_, TunnelConfig* tunnelConfig_, QWidget* wrongInputPane_, QLabel* wrongInputLabel_, MainWindow* mainWindow_):
|
||||||
QObject(),
|
QObject(),
|
||||||
mainWindow(mainWindow_),
|
mainWindow(mainWindow_),
|
||||||
@ -47,8 +49,6 @@ void TunnelPane::setupTunnelPane(
|
|||||||
nameLineEdit->setText(tunnelName);
|
nameLineEdit->setText(tunnelName);
|
||||||
setGroupBoxTitle(tunnelName);
|
setGroupBoxTitle(tunnelName);
|
||||||
|
|
||||||
QObject::connect(nameLineEdit, SIGNAL(textChanged(const QString &)),
|
|
||||||
this, SLOT(setGroupBoxTitle(const QString &)));
|
|
||||||
QObject::connect(nameLineEdit, SIGNAL(textChanged(const QString &)),
|
QObject::connect(nameLineEdit, SIGNAL(textChanged(const QString &)),
|
||||||
this, SLOT(updated()));
|
this, SLOT(updated()));
|
||||||
|
|
||||||
@ -399,3 +399,7 @@ void TunnelPane::hideWrongInputLabel() const {
|
|||||||
wrongInputPane->setVisible(false);
|
wrongInputPane->setVisible(false);
|
||||||
mainWindow->adjustSizesAccordingToWrongLabel();
|
mainWindow->adjustSizesAccordingToWrongLabel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool TunnelPane::isValidSingleLine(QLineEdit* widget) {
|
||||||
|
return ::isValidSingleLine(widget, WrongInputPageEnum::tunnelsSettingsPage, mainWindow);
|
||||||
|
}
|
||||||
|
@ -119,6 +119,21 @@ protected:
|
|||||||
public:
|
public:
|
||||||
//returns false when invalid data at UI
|
//returns false when invalid data at UI
|
||||||
virtual bool applyDataFromUIToTunnelConfig() {
|
virtual bool applyDataFromUIToTunnelConfig() {
|
||||||
|
if(!isValidSingleLine(nameLineEdit)){
|
||||||
|
setGroupBoxTitle(QApplication::translate("tunPage", "invalid_tunnel_name"));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(!isValidSingleLine(inbound_lengthLineEdit))return false;
|
||||||
|
if(!isValidSingleLine(inbound_quantityLineEdit))return false;
|
||||||
|
if(!isValidSingleLine(outbound_lengthLineEdit))return false;
|
||||||
|
if(!isValidSingleLine(outbound_quantityLineEdit))return false;
|
||||||
|
if(!isValidSingleLine(crypto_tagsToSendLineEdit))return false;
|
||||||
|
if(!isValidSingleLine(i2cp_leaseSetAuthTypeLineEdit))return false;
|
||||||
|
if(!isValidSingleLine(i2cp_leaseSetEncTypeLineEdit))return false;
|
||||||
|
if(!isValidSingleLine(i2cp_leaseSetPrivKeyLineEdit))return false;
|
||||||
|
if(!isValidSingleLine(i2cp_leaseSetTypeLineEdit))return false;
|
||||||
|
if(!isValidSingleLine(i2p_streaming_initialAckDelayLineEdit))return false;
|
||||||
|
setGroupBoxTitle(nameLineEdit->text());
|
||||||
tunnelConfig->setName(nameLineEdit->text().toStdString());
|
tunnelConfig->setName(nameLineEdit->text().toStdString());
|
||||||
tunnelConfig->setType(readTunnelTypeComboboxData());
|
tunnelConfig->setType(readTunnelTypeComboboxData());
|
||||||
I2CPParameters& i2cpParams=tunnelConfig->getI2cpParameters();
|
I2CPParameters& i2cpParams=tunnelConfig->getI2cpParameters();
|
||||||
@ -169,6 +184,8 @@ private:
|
|||||||
i2cp_leaseSetPrivKeyLabel->setText(QApplication::translate("tunForm", "Decryption key for encrypted LeaseSet in base64. PSK or private DH:", 0));
|
i2cp_leaseSetPrivKeyLabel->setText(QApplication::translate("tunForm", "Decryption key for encrypted LeaseSet in base64. PSK or private DH:", 0));
|
||||||
i2cp_leaseSetAuthTypeLabel->setText(QApplication::translate("tunForm", "Auth type for encrypted LeaseSet. 0 - no auth, 1 - DH, 2 - PSK:", 0));
|
i2cp_leaseSetAuthTypeLabel->setText(QApplication::translate("tunForm", "Auth type for encrypted LeaseSet. 0 - no auth, 1 - DH, 2 - PSK:", 0));
|
||||||
}
|
}
|
||||||
|
protected:
|
||||||
|
bool isValidSingleLine(QLineEdit* widget);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TUNNELPANE_H
|
#endif // TUNNELPANE_H
|
||||||
|
@ -37,7 +37,8 @@ SOURCES += DaemonQT.cpp mainwindow.cpp \
|
|||||||
../../daemon/I2PControl.cpp \
|
../../daemon/I2PControl.cpp \
|
||||||
../../daemon/i2pd.cpp \
|
../../daemon/i2pd.cpp \
|
||||||
../../daemon/UPnP.cpp \
|
../../daemon/UPnP.cpp \
|
||||||
AboutDialog.cpp
|
AboutDialog.cpp \
|
||||||
|
I2pdQtUtil.cpp
|
||||||
|
|
||||||
HEADERS += DaemonQT.h mainwindow.h \
|
HEADERS += DaemonQT.h mainwindow.h \
|
||||||
ClientTunnelPane.h \
|
ClientTunnelPane.h \
|
||||||
@ -62,7 +63,8 @@ HEADERS += DaemonQT.h mainwindow.h \
|
|||||||
../../daemon/I2PControl.h \
|
../../daemon/I2PControl.h \
|
||||||
../../daemon/UPnP.h \
|
../../daemon/UPnP.h \
|
||||||
AboutDialog.h \
|
AboutDialog.h \
|
||||||
BuildDateTimeQt.h
|
BuildDateTimeQt.h \
|
||||||
|
I2pdQtUtil.h
|
||||||
|
|
||||||
INCLUDEPATH += ../../libi2pd
|
INCLUDEPATH += ../../libi2pd
|
||||||
INCLUDEPATH += ../../libi2pd_client
|
INCLUDEPATH += ../../libi2pd_client
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
|
#include "I2pdQtUtil.h"
|
||||||
#include "AboutDialog.h"
|
#include "AboutDialog.h"
|
||||||
#include "ui_mainwindow.h"
|
#include "ui_mainwindow.h"
|
||||||
#include "ui_statusbuttons.h"
|
#include "ui_statusbuttons.h"
|
||||||
@ -16,6 +17,8 @@
|
|||||||
#include <QScreen>
|
#include <QScreen>
|
||||||
#include <QWindow>
|
#include <QWindow>
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
#include "RouterContext.h"
|
#include "RouterContext.h"
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include "FS.h"
|
#include "FS.h"
|
||||||
@ -37,6 +40,7 @@
|
|||||||
#include "DelayedSaveManagerImpl.h"
|
#include "DelayedSaveManagerImpl.h"
|
||||||
#include "SaverImpl.h"
|
#include "SaverImpl.h"
|
||||||
|
|
||||||
|
|
||||||
std::string programOptionsWriterCurrentSection;
|
std::string programOptionsWriterCurrentSection;
|
||||||
|
|
||||||
MainWindow::MainWindow(std::shared_ptr<std::iostream> logStream_, QWidget *parent) :
|
MainWindow::MainWindow(std::shared_ptr<std::iostream> logStream_, QWidget *parent) :
|
||||||
@ -647,13 +651,13 @@ MainWindow::~MainWindow()
|
|||||||
|
|
||||||
FileChooserItem* MainWindow::initFileChooser(ConfigOption option, QLineEdit* fileNameLineEdit, QPushButton* fileBrowsePushButton){
|
FileChooserItem* MainWindow::initFileChooser(ConfigOption option, QLineEdit* fileNameLineEdit, QPushButton* fileBrowsePushButton){
|
||||||
FileChooserItem* retVal;
|
FileChooserItem* retVal;
|
||||||
retVal=new FileChooserItem(option, fileNameLineEdit, fileBrowsePushButton);
|
retVal=new FileChooserItem(option, fileNameLineEdit, fileBrowsePushButton, this);
|
||||||
MainWindowItem* super=retVal;
|
MainWindowItem* super=retVal;
|
||||||
configItems.append(super);
|
configItems.append(super);
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
void MainWindow::initFolderChooser(ConfigOption option, QLineEdit* folderLineEdit, QPushButton* folderBrowsePushButton){
|
void MainWindow::initFolderChooser(ConfigOption option, QLineEdit* folderLineEdit, QPushButton* folderBrowsePushButton){
|
||||||
configItems.append(new FolderChooserItem(option, folderLineEdit, folderBrowsePushButton));
|
configItems.append(new FolderChooserItem(option, folderLineEdit, folderBrowsePushButton, this));
|
||||||
}
|
}
|
||||||
/*void MainWindow::initCombobox(ConfigOption option, QComboBox* comboBox){
|
/*void MainWindow::initCombobox(ConfigOption option, QComboBox* comboBox){
|
||||||
configItems.append(new ComboBoxItem(option, comboBox));
|
configItems.append(new ComboBoxItem(option, comboBox));
|
||||||
@ -669,25 +673,25 @@ void MainWindow::initSignatureTypeCombobox(ConfigOption option, QComboBox* combo
|
|||||||
configItems.append(new SignatureTypeComboBoxItem(option, comboBox));
|
configItems.append(new SignatureTypeComboBoxItem(option, comboBox));
|
||||||
}
|
}
|
||||||
void MainWindow::initIPAddressBox(ConfigOption option, QLineEdit* addressLineEdit, QString fieldNameTranslated){
|
void MainWindow::initIPAddressBox(ConfigOption option, QLineEdit* addressLineEdit, QString fieldNameTranslated){
|
||||||
configItems.append(new IPAddressStringItem(option, addressLineEdit, fieldNameTranslated));
|
configItems.append(new IPAddressStringItem(option, addressLineEdit, fieldNameTranslated, this));
|
||||||
}
|
}
|
||||||
void MainWindow::initTCPPortBox(ConfigOption option, QLineEdit* portLineEdit, QString fieldNameTranslated){
|
void MainWindow::initTCPPortBox(ConfigOption option, QLineEdit* portLineEdit, QString fieldNameTranslated){
|
||||||
configItems.append(new TCPPortStringItem(option, portLineEdit, fieldNameTranslated));
|
configItems.append(new TCPPortStringItem(option, portLineEdit, fieldNameTranslated, this));
|
||||||
}
|
}
|
||||||
void MainWindow::initCheckBox(ConfigOption option, QCheckBox* checkBox) {
|
void MainWindow::initCheckBox(ConfigOption option, QCheckBox* checkBox) {
|
||||||
configItems.append(new CheckBoxItem(option, checkBox));
|
configItems.append(new CheckBoxItem(option, checkBox));
|
||||||
}
|
}
|
||||||
void MainWindow::initIntegerBox(ConfigOption option, QLineEdit* numberLineEdit, QString fieldNameTranslated){
|
void MainWindow::initIntegerBox(ConfigOption option, QLineEdit* numberLineEdit, QString fieldNameTranslated){
|
||||||
configItems.append(new IntegerStringItem(option, numberLineEdit, fieldNameTranslated));
|
configItems.append(new IntegerStringItem(option, numberLineEdit, fieldNameTranslated, this));
|
||||||
}
|
}
|
||||||
void MainWindow::initUInt32Box(ConfigOption option, QLineEdit* numberLineEdit, QString fieldNameTranslated){
|
void MainWindow::initUInt32Box(ConfigOption option, QLineEdit* numberLineEdit, QString fieldNameTranslated){
|
||||||
configItems.append(new UInt32StringItem(option, numberLineEdit, fieldNameTranslated));
|
configItems.append(new UInt32StringItem(option, numberLineEdit, fieldNameTranslated, this));
|
||||||
}
|
}
|
||||||
void MainWindow::initUInt16Box(ConfigOption option, QLineEdit* numberLineEdit, QString fieldNameTranslated){
|
void MainWindow::initUInt16Box(ConfigOption option, QLineEdit* numberLineEdit, QString fieldNameTranslated){
|
||||||
configItems.append(new UInt16StringItem(option, numberLineEdit, fieldNameTranslated));
|
configItems.append(new UInt16StringItem(option, numberLineEdit, fieldNameTranslated, this));
|
||||||
}
|
}
|
||||||
void MainWindow::initStringBox(ConfigOption option, QLineEdit* lineEdit){
|
void MainWindow::initStringBox(ConfigOption option, QLineEdit* lineEdit){
|
||||||
configItems.append(new BaseStringItem(option, lineEdit, QString()));
|
configItems.append(new BaseStringItem(option, lineEdit, QString(), this));
|
||||||
}
|
}
|
||||||
NonGUIOptionItem* MainWindow::initNonGUIOption(ConfigOption option) {
|
NonGUIOptionItem* MainWindow::initNonGUIOption(ConfigOption option) {
|
||||||
NonGUIOptionItem * retValue;
|
NonGUIOptionItem * retValue;
|
||||||
@ -789,12 +793,17 @@ bool MainWindow::saveAllConfigs(bool focusOnTunnel, std::string tunnelNameToFocu
|
|||||||
|
|
||||||
for(QList<MainWindowItem*>::iterator it = configItems.begin(); it!= configItems.end(); ++it) {
|
for(QList<MainWindowItem*>::iterator it = configItems.begin(); it!= configItems.end(); ++it) {
|
||||||
MainWindowItem* item = *it;
|
MainWindowItem* item = *it;
|
||||||
if(!item->isValid()){
|
bool alreadyDisplayedIfWrong=false;
|
||||||
highlightWrongInput(QApplication::tr("Invalid value for")+" "+item->getConfigOption().section+"::"+item->getConfigOption().option+". "+item->getRequirementToBeValid()+" "+cannotSaveSettings, item->getWidgetToFocus());
|
if(!item->isValid(alreadyDisplayedIfWrong)){
|
||||||
|
if(!alreadyDisplayedIfWrong)
|
||||||
|
highlightWrongInput(
|
||||||
|
QApplication::tr("Invalid value for")+" "+item->getConfigOption().section+"::"+item->getConfigOption().option+". "+item->getRequirementToBeValid()+" "+cannotSaveSettings,
|
||||||
|
WrongInputPageEnum::generalSettingsPage,
|
||||||
|
item->getWidgetToFocus());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delayedSaveManagerPtr->delayedSave(++dataSerial, focusOnTunnel, tunnelNameToFocus);
|
delayedSaveManagerPtr->delayedSave(++dataSerial, focusOnTunnel, tunnelNameToFocus);//TODO does dataSerial work? //FIXME
|
||||||
|
|
||||||
//onLoggingOptionsChange();
|
//onLoggingOptionsChange();
|
||||||
return true;
|
return true;
|
||||||
@ -814,6 +823,11 @@ void FolderChooserItem::pushButtonReleased() {
|
|||||||
void BaseStringItem::installListeners(MainWindow *mainWindow) {
|
void BaseStringItem::installListeners(MainWindow *mainWindow) {
|
||||||
QObject::connect(lineEdit, SIGNAL(textChanged(const QString &)), mainWindow, SLOT(updated()));
|
QObject::connect(lineEdit, SIGNAL(textChanged(const QString &)), mainWindow, SLOT(updated()));
|
||||||
}
|
}
|
||||||
|
bool BaseStringItem::isValid(bool & alreadyDisplayedIfWrong) {
|
||||||
|
alreadyDisplayedIfWrong=true;
|
||||||
|
return ::isValidSingleLine(lineEdit, WrongInputPageEnum::generalSettingsPage, mainWindow);
|
||||||
|
}
|
||||||
|
|
||||||
void ComboBoxItem::installListeners(MainWindow *mainWindow) {
|
void ComboBoxItem::installListeners(MainWindow *mainWindow) {
|
||||||
QObject::connect(comboBox, SIGNAL(currentIndexChanged(int)), mainWindow, SLOT(updated()));
|
QObject::connect(comboBox, SIGNAL(currentIndexChanged(int)), mainWindow, SLOT(updated()));
|
||||||
}
|
}
|
||||||
@ -825,7 +839,8 @@ void MainWindow::updated() {
|
|||||||
ui->wrongInputLabel->setVisible(false);
|
ui->wrongInputLabel->setVisible(false);
|
||||||
adjustSizesAccordingToWrongLabel();
|
adjustSizesAccordingToWrongLabel();
|
||||||
|
|
||||||
applyTunnelsUiToConfigs();
|
bool correct = applyTunnelsUiToConfigs();
|
||||||
|
if(!correct) return;
|
||||||
saveAllConfigs(false);
|
saveAllConfigs(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1010,11 +1025,15 @@ void MainWindow::adjustSizesAccordingToWrongLabel() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::highlightWrongInput(QString warningText, QWidget* widgetToFocus) {
|
void MainWindow::highlightWrongInput(QString warningText, WrongInputPageEnum inputPage, QWidget* widgetToFocus) {
|
||||||
bool redVisible = ui->wrongInputLabel->isVisible();
|
bool redVisible = ui->wrongInputLabel->isVisible();
|
||||||
ui->wrongInputLabel->setVisible(true);
|
ui->wrongInputLabel->setVisible(true);
|
||||||
ui->wrongInputLabel->setText(warningText);
|
ui->wrongInputLabel->setText(warningText);
|
||||||
if(!redVisible)adjustSizesAccordingToWrongLabel();
|
if(!redVisible)adjustSizesAccordingToWrongLabel();
|
||||||
if(widgetToFocus){ui->settingsScrollArea->ensureWidgetVisible(widgetToFocus);widgetToFocus->setFocus();}
|
if(widgetToFocus){ui->settingsScrollArea->ensureWidgetVisible(widgetToFocus);widgetToFocus->setFocus();}
|
||||||
showSettingsPage();
|
switch(inputPage) {
|
||||||
|
case WrongInputPageEnum::generalSettingsPage: showSettingsPage(); break;
|
||||||
|
case WrongInputPageEnum::tunnelsSettingsPage: showTunnelsPage(); break;
|
||||||
|
default: assert(false); break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
#ifndef MAINWINDOW_H
|
#ifndef MAINWINDOW_H
|
||||||
#define MAINWINDOW_H
|
#define MAINWINDOW_H
|
||||||
|
|
||||||
|
enum WrongInputPageEnum { generalSettingsPage, tunnelsSettingsPage };
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
@ -66,6 +68,8 @@
|
|||||||
#include "DelayedSaveManagerImpl.h"
|
#include "DelayedSaveManagerImpl.h"
|
||||||
#include "SaverImpl.h"
|
#include "SaverImpl.h"
|
||||||
|
|
||||||
|
#include "I2pdQtUtil.h"
|
||||||
|
|
||||||
class SaverImpl;
|
class SaverImpl;
|
||||||
|
|
||||||
class LogViewerManager;
|
class LogViewerManager;
|
||||||
@ -155,19 +159,24 @@ public:
|
|||||||
}else out << boost::any_cast<std::string>(optionValue); //let it throw
|
}else out << boost::any_cast<std::string>(optionValue); //let it throw
|
||||||
out << "\n\n";
|
out << "\n\n";
|
||||||
}
|
}
|
||||||
virtual bool isValid(){return true;}
|
virtual bool isValid(bool & alreadyDisplayedIfWrong){alreadyDisplayedIfWrong=false;return true;}
|
||||||
};
|
};
|
||||||
class NonGUIOptionItem : public MainWindowItem {
|
class NonGUIOptionItem : public MainWindowItem {
|
||||||
public:
|
public:
|
||||||
NonGUIOptionItem(ConfigOption option_) : MainWindowItem(option_, nullptr, QString()) {};
|
NonGUIOptionItem(ConfigOption option_) : MainWindowItem(option_, nullptr, QString()) {}
|
||||||
virtual ~NonGUIOptionItem(){}
|
virtual ~NonGUIOptionItem(){}
|
||||||
virtual bool isValid() { return true; }
|
//virtual bool isValid(bool & alreadyDisplayedIfWrong) { return true; }
|
||||||
};
|
};
|
||||||
class BaseStringItem : public MainWindowItem {
|
class BaseStringItem : public MainWindowItem {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
QLineEdit* lineEdit;
|
QLineEdit* lineEdit;
|
||||||
BaseStringItem(ConfigOption option_, QLineEdit* lineEdit_, QString requirementToBeValid_) : MainWindowItem(option_, lineEdit_, requirementToBeValid_), lineEdit(lineEdit_){};
|
MainWindow *mainWindow;
|
||||||
|
BaseStringItem(ConfigOption option_, QLineEdit* lineEdit_, QString requirementToBeValid_, MainWindow* mainWindow_):
|
||||||
|
MainWindowItem(option_, lineEdit_, requirementToBeValid_),
|
||||||
|
lineEdit(lineEdit_),
|
||||||
|
mainWindow(mainWindow_)
|
||||||
|
{};
|
||||||
virtual ~BaseStringItem(){}
|
virtual ~BaseStringItem(){}
|
||||||
virtual void installListeners(MainWindow *mainWindow);
|
virtual void installListeners(MainWindow *mainWindow);
|
||||||
virtual QString toString(){
|
virtual QString toString(){
|
||||||
@ -183,13 +192,13 @@ public:
|
|||||||
optionValue=fromString(lineEdit->text());
|
optionValue=fromString(lineEdit->text());
|
||||||
MainWindowItem::saveToStringStream(out);
|
MainWindowItem::saveToStringStream(out);
|
||||||
}
|
}
|
||||||
virtual bool isValid() { return true; }
|
virtual bool isValid(bool & alreadyDisplayedIfWrong);
|
||||||
};
|
};
|
||||||
class FileOrFolderChooserItem : public BaseStringItem {
|
class FileOrFolderChooserItem : public BaseStringItem {
|
||||||
public:
|
public:
|
||||||
QPushButton* browsePushButton;
|
QPushButton* browsePushButton;
|
||||||
FileOrFolderChooserItem(ConfigOption option_, QLineEdit* lineEdit_, QPushButton* browsePushButton_) :
|
FileOrFolderChooserItem(ConfigOption option_, QLineEdit* lineEdit_, QPushButton* browsePushButton_, MainWindow* mw) :
|
||||||
BaseStringItem(option_, lineEdit_, QString()), browsePushButton(browsePushButton_) {}
|
BaseStringItem(option_, lineEdit_, QString(), mw), browsePushButton(browsePushButton_) {}
|
||||||
virtual ~FileOrFolderChooserItem(){}
|
virtual ~FileOrFolderChooserItem(){}
|
||||||
};
|
};
|
||||||
class FileChooserItem : public FileOrFolderChooserItem {
|
class FileChooserItem : public FileOrFolderChooserItem {
|
||||||
@ -197,8 +206,8 @@ class FileChooserItem : public FileOrFolderChooserItem {
|
|||||||
private slots:
|
private slots:
|
||||||
void pushButtonReleased();
|
void pushButtonReleased();
|
||||||
public:
|
public:
|
||||||
FileChooserItem(ConfigOption option_, QLineEdit* lineEdit_, QPushButton* browsePushButton_) :
|
FileChooserItem(ConfigOption option_, QLineEdit* lineEdit_, QPushButton* browsePushButton_, MainWindow* mw) :
|
||||||
FileOrFolderChooserItem(option_, lineEdit_, browsePushButton_) {
|
FileOrFolderChooserItem(option_, lineEdit_, browsePushButton_, mw) {
|
||||||
QObject::connect(browsePushButton, SIGNAL(released()), this, SLOT(pushButtonReleased()));
|
QObject::connect(browsePushButton, SIGNAL(released()), this, SLOT(pushButtonReleased()));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -207,20 +216,20 @@ class FolderChooserItem : public FileOrFolderChooserItem{
|
|||||||
private slots:
|
private slots:
|
||||||
void pushButtonReleased();
|
void pushButtonReleased();
|
||||||
public:
|
public:
|
||||||
FolderChooserItem(ConfigOption option_, QLineEdit* lineEdit_, QPushButton* browsePushButton_) :
|
FolderChooserItem(ConfigOption option_, QLineEdit* lineEdit_, QPushButton* browsePushButton_, MainWindow* mw) :
|
||||||
FileOrFolderChooserItem(option_, lineEdit_, browsePushButton_) {
|
FileOrFolderChooserItem(option_, lineEdit_, browsePushButton_, mw) {
|
||||||
QObject::connect(browsePushButton, SIGNAL(released()), this, SLOT(pushButtonReleased()));
|
QObject::connect(browsePushButton, SIGNAL(released()), this, SLOT(pushButtonReleased()));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
class ComboBoxItem : public MainWindowItem {
|
class ComboBoxItem : public MainWindowItem {
|
||||||
public:
|
public:
|
||||||
QComboBox* comboBox;
|
QComboBox* comboBox;
|
||||||
ComboBoxItem(ConfigOption option_, QComboBox* comboBox_) : MainWindowItem(option_,comboBox_,QString()), comboBox(comboBox_){};
|
ComboBoxItem(ConfigOption option_, QComboBox* comboBox_) : MainWindowItem(option_,comboBox_,QString()), comboBox(comboBox_){}
|
||||||
virtual ~ComboBoxItem(){}
|
virtual ~ComboBoxItem(){}
|
||||||
virtual void installListeners(MainWindow *mainWindow);
|
virtual void installListeners(MainWindow *mainWindow);
|
||||||
virtual void loadFromConfigOption()=0;
|
virtual void loadFromConfigOption()=0;
|
||||||
virtual void saveToStringStream(std::stringstream& out)=0;
|
virtual void saveToStringStream(std::stringstream& out)=0;
|
||||||
virtual bool isValid() { return true; }
|
//virtual bool isValid(bool & alreadyDisplayedIfWrong) { return ; }
|
||||||
};
|
};
|
||||||
class LogDestinationComboBoxItem : public ComboBoxItem {
|
class LogDestinationComboBoxItem : public ComboBoxItem {
|
||||||
public:
|
public:
|
||||||
@ -237,13 +246,13 @@ public:
|
|||||||
optionValue=logDest;
|
optionValue=logDest;
|
||||||
MainWindowItem::saveToStringStream(out);
|
MainWindowItem::saveToStringStream(out);
|
||||||
}
|
}
|
||||||
virtual bool isValid() { return true; }
|
//virtual bool isValid(bool & alreadyDisplayedIfWrong) { return true; }
|
||||||
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
};
|
};
|
||||||
class LogLevelComboBoxItem : public ComboBoxItem {
|
class LogLevelComboBoxItem : public ComboBoxItem {
|
||||||
public:
|
public:
|
||||||
LogLevelComboBoxItem(ConfigOption option_, QComboBox* comboBox_) : ComboBoxItem(option_, comboBox_) {};
|
LogLevelComboBoxItem(ConfigOption option_, QComboBox* comboBox_) : ComboBoxItem(option_, comboBox_) {}
|
||||||
virtual ~LogLevelComboBoxItem(){}
|
virtual ~LogLevelComboBoxItem(){}
|
||||||
virtual void loadFromConfigOption(){
|
virtual void loadFromConfigOption(){
|
||||||
MainWindowItem::loadFromConfigOption();
|
MainWindowItem::loadFromConfigOption();
|
||||||
@ -254,11 +263,11 @@ public:
|
|||||||
optionValue=comboBox->currentText().toStdString();
|
optionValue=comboBox->currentText().toStdString();
|
||||||
MainWindowItem::saveToStringStream(out);
|
MainWindowItem::saveToStringStream(out);
|
||||||
}
|
}
|
||||||
virtual bool isValid() { return true; }
|
//virtual bool isValid(bool & alreadyDisplayedIfWrong) { return true; }
|
||||||
};
|
};
|
||||||
class SignatureTypeComboBoxItem : public ComboBoxItem {
|
class SignatureTypeComboBoxItem : public ComboBoxItem {
|
||||||
public:
|
public:
|
||||||
SignatureTypeComboBoxItem(ConfigOption option_, QComboBox* comboBox_) : ComboBoxItem(option_, comboBox_) {};
|
SignatureTypeComboBoxItem(ConfigOption option_, QComboBox* comboBox_) : ComboBoxItem(option_, comboBox_) {}
|
||||||
virtual ~SignatureTypeComboBoxItem(){}
|
virtual ~SignatureTypeComboBoxItem(){}
|
||||||
virtual void loadFromConfigOption(){
|
virtual void loadFromConfigOption(){
|
||||||
MainWindowItem::loadFromConfigOption();
|
MainWindowItem::loadFromConfigOption();
|
||||||
@ -271,12 +280,12 @@ public:
|
|||||||
optionValue=(unsigned short)selected;
|
optionValue=(unsigned short)selected;
|
||||||
MainWindowItem::saveToStringStream(out);
|
MainWindowItem::saveToStringStream(out);
|
||||||
}
|
}
|
||||||
virtual bool isValid() { return true; }
|
//virtual bool isValid(bool & alreadyDisplayedIfWrong) { return true; }
|
||||||
};
|
};
|
||||||
class CheckBoxItem : public MainWindowItem {
|
class CheckBoxItem : public MainWindowItem {
|
||||||
public:
|
public:
|
||||||
QCheckBox* checkBox;
|
QCheckBox* checkBox;
|
||||||
CheckBoxItem(ConfigOption option_, QCheckBox* checkBox_) : MainWindowItem(option_,checkBox_,QString()), checkBox(checkBox_){};
|
CheckBoxItem(ConfigOption option_, QCheckBox* checkBox_) : MainWindowItem(option_,checkBox_,QString()), checkBox(checkBox_){}
|
||||||
virtual ~CheckBoxItem(){}
|
virtual ~CheckBoxItem(){}
|
||||||
virtual void installListeners(MainWindow *mainWindow);
|
virtual void installListeners(MainWindow *mainWindow);
|
||||||
virtual void loadFromConfigOption(){
|
virtual void loadFromConfigOption(){
|
||||||
@ -288,22 +297,25 @@ public:
|
|||||||
optionValue=checkBox->isChecked();
|
optionValue=checkBox->isChecked();
|
||||||
MainWindowItem::saveToStringStream(out);
|
MainWindowItem::saveToStringStream(out);
|
||||||
}
|
}
|
||||||
virtual bool isValid() { return true; }
|
//virtual bool isValid(bool & alreadyDisplayedIfWrong) { return true; }
|
||||||
};
|
};
|
||||||
class BaseFormattedStringItem : public BaseStringItem {
|
class BaseFormattedStringItem : public BaseStringItem {
|
||||||
public:
|
public:
|
||||||
QString fieldNameTranslated;
|
QString fieldNameTranslated;
|
||||||
BaseFormattedStringItem(ConfigOption option_, QLineEdit* lineEdit_, QString fieldNameTranslated_, QString requirementToBeValid_) :
|
BaseFormattedStringItem(ConfigOption option_, QLineEdit* lineEdit_, QString fieldNameTranslated_, QString requirementToBeValid_, MainWindow* mw) :
|
||||||
BaseStringItem(option_, lineEdit_, requirementToBeValid_), fieldNameTranslated(fieldNameTranslated_) {};
|
BaseStringItem(option_, lineEdit_, requirementToBeValid_, mw), fieldNameTranslated(fieldNameTranslated_) {}
|
||||||
virtual ~BaseFormattedStringItem(){}
|
virtual ~BaseFormattedStringItem(){}
|
||||||
virtual bool isValid()=0;
|
//virtual bool isValid(bool & alreadyDisplayedIfWrong)=0;
|
||||||
};
|
};
|
||||||
class IntegerStringItem : public BaseFormattedStringItem {
|
class IntegerStringItem : public BaseFormattedStringItem {
|
||||||
public:
|
public:
|
||||||
IntegerStringItem(ConfigOption option_, QLineEdit* lineEdit_, QString fieldNameTranslated_) :
|
IntegerStringItem(ConfigOption option_, QLineEdit* lineEdit_, QString fieldNameTranslated_, MainWindow* mw) :
|
||||||
BaseFormattedStringItem(option_, lineEdit_, fieldNameTranslated_, QApplication::tr("Must be a valid integer.")) {};
|
BaseFormattedStringItem(option_, lineEdit_, fieldNameTranslated_, QApplication::tr("Must be a valid integer."), mw) {}
|
||||||
virtual ~IntegerStringItem(){}
|
virtual ~IntegerStringItem(){}
|
||||||
virtual bool isValid(){
|
virtual bool isValid(bool & alreadyDisplayedIfWrong){
|
||||||
|
bool correct = BaseFormattedStringItem::isValid(alreadyDisplayedIfWrong);
|
||||||
|
if(!correct)return false;
|
||||||
|
alreadyDisplayedIfWrong = false;
|
||||||
auto str=lineEdit->text();
|
auto str=lineEdit->text();
|
||||||
bool ok;
|
bool ok;
|
||||||
str.toInt(&ok);
|
str.toInt(&ok);
|
||||||
@ -314,10 +326,13 @@ public:
|
|||||||
};
|
};
|
||||||
class UShortStringItem : public BaseFormattedStringItem {
|
class UShortStringItem : public BaseFormattedStringItem {
|
||||||
public:
|
public:
|
||||||
UShortStringItem(ConfigOption option_, QLineEdit* lineEdit_, QString fieldNameTranslated_) :
|
UShortStringItem(ConfigOption option_, QLineEdit* lineEdit_, QString fieldNameTranslated_, MainWindow* mw) :
|
||||||
BaseFormattedStringItem(option_, lineEdit_, fieldNameTranslated_, QApplication::tr("Must be unsigned short integer.")) {};
|
BaseFormattedStringItem(option_, lineEdit_, fieldNameTranslated_, QApplication::tr("Must be unsigned short integer."), mw) {}
|
||||||
virtual ~UShortStringItem(){}
|
virtual ~UShortStringItem(){}
|
||||||
virtual bool isValid(){
|
virtual bool isValid(bool & alreadyDisplayedIfWrong){
|
||||||
|
bool correct = BaseFormattedStringItem::isValid(alreadyDisplayedIfWrong);
|
||||||
|
if(!correct)return false;
|
||||||
|
alreadyDisplayedIfWrong = false;
|
||||||
auto str=lineEdit->text();
|
auto str=lineEdit->text();
|
||||||
bool ok;
|
bool ok;
|
||||||
str.toUShort(&ok);
|
str.toUShort(&ok);
|
||||||
@ -328,10 +343,13 @@ public:
|
|||||||
};
|
};
|
||||||
class UInt32StringItem : public BaseFormattedStringItem {
|
class UInt32StringItem : public BaseFormattedStringItem {
|
||||||
public:
|
public:
|
||||||
UInt32StringItem(ConfigOption option_, QLineEdit* lineEdit_, QString fieldNameTranslated_) :
|
UInt32StringItem(ConfigOption option_, QLineEdit* lineEdit_, QString fieldNameTranslated_, MainWindow* mw) :
|
||||||
BaseFormattedStringItem(option_, lineEdit_, fieldNameTranslated_, QApplication::tr("Must be unsigned 32-bit integer.")) {};
|
BaseFormattedStringItem(option_, lineEdit_, fieldNameTranslated_, QApplication::tr("Must be unsigned 32-bit integer."), mw) {}
|
||||||
virtual ~UInt32StringItem(){}
|
virtual ~UInt32StringItem(){}
|
||||||
virtual bool isValid(){
|
virtual bool isValid(bool & alreadyDisplayedIfWrong){
|
||||||
|
bool correct = BaseFormattedStringItem::isValid(alreadyDisplayedIfWrong);
|
||||||
|
if(!correct)return false;
|
||||||
|
alreadyDisplayedIfWrong = false;
|
||||||
auto str=lineEdit->text();
|
auto str=lineEdit->text();
|
||||||
bool ok;
|
bool ok;
|
||||||
str.toUInt(&ok);
|
str.toUInt(&ok);
|
||||||
@ -342,10 +360,13 @@ public:
|
|||||||
};
|
};
|
||||||
class UInt16StringItem : public BaseFormattedStringItem {
|
class UInt16StringItem : public BaseFormattedStringItem {
|
||||||
public:
|
public:
|
||||||
UInt16StringItem(ConfigOption option_, QLineEdit* lineEdit_, QString fieldNameTranslated_) :
|
UInt16StringItem(ConfigOption option_, QLineEdit* lineEdit_, QString fieldNameTranslated_, MainWindow* mw) :
|
||||||
BaseFormattedStringItem(option_, lineEdit_, fieldNameTranslated_, QApplication::tr("Must be unsigned 16-bit integer.")) {};
|
BaseFormattedStringItem(option_, lineEdit_, fieldNameTranslated_, QApplication::tr("Must be unsigned 16-bit integer."), mw) {}
|
||||||
virtual ~UInt16StringItem(){}
|
virtual ~UInt16StringItem(){}
|
||||||
virtual bool isValid(){
|
virtual bool isValid(bool & alreadyDisplayedIfWrong){
|
||||||
|
bool correct = BaseFormattedStringItem::isValid(alreadyDisplayedIfWrong);
|
||||||
|
if(!correct)return false;
|
||||||
|
alreadyDisplayedIfWrong = false;
|
||||||
auto str=lineEdit->text();
|
auto str=lineEdit->text();
|
||||||
bool ok;
|
bool ok;
|
||||||
str.toUShort(&ok);
|
str.toUShort(&ok);
|
||||||
@ -356,14 +377,14 @@ public:
|
|||||||
};
|
};
|
||||||
class IPAddressStringItem : public BaseFormattedStringItem {
|
class IPAddressStringItem : public BaseFormattedStringItem {
|
||||||
public:
|
public:
|
||||||
IPAddressStringItem(ConfigOption option_, QLineEdit* lineEdit_, QString fieldNameTranslated_) :
|
IPAddressStringItem(ConfigOption option_, QLineEdit* lineEdit_, QString fieldNameTranslated_, MainWindow* mw) :
|
||||||
BaseFormattedStringItem(option_, lineEdit_, fieldNameTranslated_, QApplication::tr("Must be an IPv4 address")) {};
|
BaseFormattedStringItem(option_, lineEdit_, fieldNameTranslated_, QApplication::tr("Must be an IPv4 address"), mw) {}
|
||||||
virtual bool isValid(){return true;}//todo
|
//virtual bool isValid(bool & alreadyDisplayedIfWrong){return true;}//todo
|
||||||
};
|
};
|
||||||
class TCPPortStringItem : public UShortStringItem {
|
class TCPPortStringItem : public UShortStringItem {
|
||||||
public:
|
public:
|
||||||
TCPPortStringItem(ConfigOption option_, QLineEdit* lineEdit_, QString fieldNameTranslated_) :
|
TCPPortStringItem(ConfigOption option_, QLineEdit* lineEdit_, QString fieldNameTranslated_, MainWindow* mw) :
|
||||||
UShortStringItem(option_, lineEdit_, fieldNameTranslated_) {};
|
UShortStringItem(option_, lineEdit_, fieldNameTranslated_,mw) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
@ -395,7 +416,7 @@ public:
|
|||||||
|
|
||||||
void setI2PController(i2p::qt::Controller* controller_);
|
void setI2PController(i2p::qt::Controller* controller_);
|
||||||
|
|
||||||
void highlightWrongInput(QString warningText, QWidget* widgetToFocus);
|
void highlightWrongInput(QString warningText, WrongInputPageEnum inputPage, QWidget* widgetToFocus);
|
||||||
|
|
||||||
//typedef std::function<QString ()> DefaultValueGetter;
|
//typedef std::function<QString ()> DefaultValueGetter;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user