Browse Source

qt: fixes #1180

pull/1604/head
user 4 years ago
parent
commit
ccc604c0f4
  1. 7
      qt/i2pd_qt/ClientTunnelPane.h
  2. 12
      qt/i2pd_qt/I2pdQtUtil.cpp
  3. 9
      qt/i2pd_qt/I2pdQtUtil.h
  4. 11
      qt/i2pd_qt/ServerTunnelPane.h
  5. 8
      qt/i2pd_qt/TunnelPane.cpp
  6. 17
      qt/i2pd_qt/TunnelPane.h
  7. 6
      qt/i2pd_qt/i2pd_qt.pro
  8. 47
      qt/i2pd_qt/mainwindow.cpp
  9. 103
      qt/i2pd_qt/mainwindow.h

7
qt/i2pd_qt/ClientTunnelPane.h

@ -79,6 +79,13 @@ protected: @@ -79,6 +79,13 @@ protected:
ClientTunnelConfig* ctc=tunnelConfig->asClientTunnelConfig();
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
ctc->setdest(destinationLineEdit->text().toStdString());

12
qt/i2pd_qt/I2pdQtUtil.cpp

@ -0,0 +1,12 @@ @@ -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

@ -0,0 +1,9 @@ @@ -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

11
qt/i2pd_qt/ServerTunnelPane.h

@ -124,6 +124,17 @@ protected: @@ -124,6 +124,17 @@ protected:
if(!ok)return false;
ServerTunnelConfig* stc=tunnelConfig->asServerTunnelConfig();
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());
auto portStr=portLineEdit->text();

8
qt/i2pd_qt/TunnelPane.cpp

@ -4,6 +4,8 @@ @@ -4,6 +4,8 @@
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "I2pdQtUtil.h"
TunnelPane::TunnelPane(TunnelsPageUpdateListener* tunnelsPageUpdateListener_, TunnelConfig* tunnelConfig_, QWidget* wrongInputPane_, QLabel* wrongInputLabel_, MainWindow* mainWindow_):
QObject(),
mainWindow(mainWindow_),
@ -47,8 +49,6 @@ void TunnelPane::setupTunnelPane( @@ -47,8 +49,6 @@ void TunnelPane::setupTunnelPane(
nameLineEdit->setText(tunnelName);
setGroupBoxTitle(tunnelName);
QObject::connect(nameLineEdit, SIGNAL(textChanged(const QString &)),
this, SLOT(setGroupBoxTitle(const QString &)));
QObject::connect(nameLineEdit, SIGNAL(textChanged(const QString &)),
this, SLOT(updated()));
@ -399,3 +399,7 @@ void TunnelPane::hideWrongInputLabel() const { @@ -399,3 +399,7 @@ void TunnelPane::hideWrongInputLabel() const {
wrongInputPane->setVisible(false);
mainWindow->adjustSizesAccordingToWrongLabel();
}
bool TunnelPane::isValidSingleLine(QLineEdit* widget) {
return ::isValidSingleLine(widget, WrongInputPageEnum::tunnelsSettingsPage, mainWindow);
}

17
qt/i2pd_qt/TunnelPane.h

@ -119,6 +119,21 @@ protected: @@ -119,6 +119,21 @@ protected:
public:
//returns false when invalid data at UI
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->setType(readTunnelTypeComboboxData());
I2CPParameters& i2cpParams=tunnelConfig->getI2cpParameters();
@ -169,6 +184,8 @@ private: @@ -169,6 +184,8 @@ private:
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));
}
protected:
bool isValidSingleLine(QLineEdit* widget);
};
#endif // TUNNELPANE_H

6
qt/i2pd_qt/i2pd_qt.pro

@ -37,7 +37,8 @@ SOURCES += DaemonQT.cpp mainwindow.cpp \ @@ -37,7 +37,8 @@ SOURCES += DaemonQT.cpp mainwindow.cpp \
../../daemon/I2PControl.cpp \
../../daemon/i2pd.cpp \
../../daemon/UPnP.cpp \
AboutDialog.cpp
AboutDialog.cpp \
I2pdQtUtil.cpp
HEADERS += DaemonQT.h mainwindow.h \
ClientTunnelPane.h \
@ -62,7 +63,8 @@ HEADERS += DaemonQT.h mainwindow.h \ @@ -62,7 +63,8 @@ HEADERS += DaemonQT.h mainwindow.h \
../../daemon/I2PControl.h \
../../daemon/UPnP.h \
AboutDialog.h \
BuildDateTimeQt.h
BuildDateTimeQt.h \
I2pdQtUtil.h
INCLUDEPATH += ../../libi2pd
INCLUDEPATH += ../../libi2pd_client

47
qt/i2pd_qt/mainwindow.cpp

@ -1,4 +1,5 @@ @@ -1,4 +1,5 @@
#include "mainwindow.h"
#include "I2pdQtUtil.h"
#include "AboutDialog.h"
#include "ui_mainwindow.h"
#include "ui_statusbuttons.h"
@ -16,6 +17,8 @@ @@ -16,6 +17,8 @@
#include <QScreen>
#include <QWindow>
#include <assert.h>
#include "RouterContext.h"
#include "Config.h"
#include "FS.h"
@ -37,6 +40,7 @@ @@ -37,6 +40,7 @@
#include "DelayedSaveManagerImpl.h"
#include "SaverImpl.h"
std::string programOptionsWriterCurrentSection;
MainWindow::MainWindow(std::shared_ptr<std::iostream> logStream_, QWidget *parent) :
@ -647,13 +651,13 @@ MainWindow::~MainWindow() @@ -647,13 +651,13 @@ MainWindow::~MainWindow()
FileChooserItem* MainWindow::initFileChooser(ConfigOption option, QLineEdit* fileNameLineEdit, QPushButton* fileBrowsePushButton){
FileChooserItem* retVal;
retVal=new FileChooserItem(option, fileNameLineEdit, fileBrowsePushButton);
retVal=new FileChooserItem(option, fileNameLineEdit, fileBrowsePushButton, this);
MainWindowItem* super=retVal;
configItems.append(super);
return retVal;
}
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){
configItems.append(new ComboBoxItem(option, comboBox));
@ -669,25 +673,25 @@ void MainWindow::initSignatureTypeCombobox(ConfigOption option, QComboBox* combo @@ -669,25 +673,25 @@ void MainWindow::initSignatureTypeCombobox(ConfigOption option, QComboBox* combo
configItems.append(new SignatureTypeComboBoxItem(option, comboBox));
}
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){
configItems.append(new TCPPortStringItem(option, portLineEdit, fieldNameTranslated));
configItems.append(new TCPPortStringItem(option, portLineEdit, fieldNameTranslated, this));
}
void MainWindow::initCheckBox(ConfigOption option, QCheckBox* checkBox) {
configItems.append(new CheckBoxItem(option, checkBox));
}
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){
configItems.append(new UInt32StringItem(option, numberLineEdit, fieldNameTranslated));
configItems.append(new UInt32StringItem(option, numberLineEdit, fieldNameTranslated, this));
}
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){
configItems.append(new BaseStringItem(option, lineEdit, QString()));
configItems.append(new BaseStringItem(option, lineEdit, QString(), this));
}
NonGUIOptionItem* MainWindow::initNonGUIOption(ConfigOption option) {
NonGUIOptionItem * retValue;
@ -789,12 +793,17 @@ bool MainWindow::saveAllConfigs(bool focusOnTunnel, std::string tunnelNameToFocu @@ -789,12 +793,17 @@ bool MainWindow::saveAllConfigs(bool focusOnTunnel, std::string tunnelNameToFocu
for(QList<MainWindowItem*>::iterator it = configItems.begin(); it!= configItems.end(); ++it) {
MainWindowItem* item = *it;
if(!item->isValid()){
highlightWrongInput(QApplication::tr("Invalid value for")+" "+item->getConfigOption().section+"::"+item->getConfigOption().option+". "+item->getRequirementToBeValid()+" "+cannotSaveSettings, item->getWidgetToFocus());
bool alreadyDisplayedIfWrong=false;
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;
}
}
delayedSaveManagerPtr->delayedSave(++dataSerial, focusOnTunnel, tunnelNameToFocus);
delayedSaveManagerPtr->delayedSave(++dataSerial, focusOnTunnel, tunnelNameToFocus);//TODO does dataSerial work? //FIXME
//onLoggingOptionsChange();
return true;
@ -814,6 +823,11 @@ void FolderChooserItem::pushButtonReleased() { @@ -814,6 +823,11 @@ void FolderChooserItem::pushButtonReleased() {
void BaseStringItem::installListeners(MainWindow *mainWindow) {
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) {
QObject::connect(comboBox, SIGNAL(currentIndexChanged(int)), mainWindow, SLOT(updated()));
}
@ -825,7 +839,8 @@ void MainWindow::updated() { @@ -825,7 +839,8 @@ void MainWindow::updated() {
ui->wrongInputLabel->setVisible(false);
adjustSizesAccordingToWrongLabel();
applyTunnelsUiToConfigs();
bool correct = applyTunnelsUiToConfigs();
if(!correct) return;
saveAllConfigs(false);
}
@ -1010,11 +1025,15 @@ void MainWindow::adjustSizesAccordingToWrongLabel() { @@ -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();
ui->wrongInputLabel->setVisible(true);
ui->wrongInputLabel->setText(warningText);
if(!redVisible)adjustSizesAccordingToWrongLabel();
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;
}
}

103
qt/i2pd_qt/mainwindow.h

@ -1,6 +1,8 @@ @@ -1,6 +1,8 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
enum WrongInputPageEnum { generalSettingsPage, tunnelsSettingsPage };
#include <QObject>
#include <QMainWindow>
#include <QPushButton>
@ -66,6 +68,8 @@ @@ -66,6 +68,8 @@
#include "DelayedSaveManagerImpl.h"
#include "SaverImpl.h"
#include "I2pdQtUtil.h"
class SaverImpl;
class LogViewerManager;
@ -155,19 +159,24 @@ public: @@ -155,19 +159,24 @@ public:
}else out << boost::any_cast<std::string>(optionValue); //let it throw
out << "\n\n";
}
virtual bool isValid(){return true;}
virtual bool isValid(bool & alreadyDisplayedIfWrong){alreadyDisplayedIfWrong=false;return true;}
};
class NonGUIOptionItem : public MainWindowItem {
public:
NonGUIOptionItem(ConfigOption option_) : MainWindowItem(option_, nullptr, QString()) {};
NonGUIOptionItem(ConfigOption option_) : MainWindowItem(option_, nullptr, QString()) {}
virtual ~NonGUIOptionItem(){}
virtual bool isValid() { return true; }
//virtual bool isValid(bool & alreadyDisplayedIfWrong) { return true; }
};
class BaseStringItem : public MainWindowItem {
Q_OBJECT
public:
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 void installListeners(MainWindow *mainWindow);
virtual QString toString(){
@ -183,13 +192,13 @@ public: @@ -183,13 +192,13 @@ public:
optionValue=fromString(lineEdit->text());
MainWindowItem::saveToStringStream(out);
}
virtual bool isValid() { return true; }
virtual bool isValid(bool & alreadyDisplayedIfWrong);
};
class FileOrFolderChooserItem : public BaseStringItem {
public:
QPushButton* browsePushButton;
FileOrFolderChooserItem(ConfigOption option_, QLineEdit* lineEdit_, QPushButton* browsePushButton_) :
BaseStringItem(option_, lineEdit_, QString()), browsePushButton(browsePushButton_) {}
FileOrFolderChooserItem(ConfigOption option_, QLineEdit* lineEdit_, QPushButton* browsePushButton_, MainWindow* mw) :
BaseStringItem(option_, lineEdit_, QString(), mw), browsePushButton(browsePushButton_) {}
virtual ~FileOrFolderChooserItem(){}
};
class FileChooserItem : public FileOrFolderChooserItem {
@ -197,8 +206,8 @@ class FileChooserItem : public FileOrFolderChooserItem { @@ -197,8 +206,8 @@ class FileChooserItem : public FileOrFolderChooserItem {
private slots:
void pushButtonReleased();
public:
FileChooserItem(ConfigOption option_, QLineEdit* lineEdit_, QPushButton* browsePushButton_) :
FileOrFolderChooserItem(option_, lineEdit_, browsePushButton_) {
FileChooserItem(ConfigOption option_, QLineEdit* lineEdit_, QPushButton* browsePushButton_, MainWindow* mw) :
FileOrFolderChooserItem(option_, lineEdit_, browsePushButton_, mw) {
QObject::connect(browsePushButton, SIGNAL(released()), this, SLOT(pushButtonReleased()));
}
};
@ -207,20 +216,20 @@ class FolderChooserItem : public FileOrFolderChooserItem{ @@ -207,20 +216,20 @@ class FolderChooserItem : public FileOrFolderChooserItem{
private slots:
void pushButtonReleased();
public:
FolderChooserItem(ConfigOption option_, QLineEdit* lineEdit_, QPushButton* browsePushButton_) :
FileOrFolderChooserItem(option_, lineEdit_, browsePushButton_) {
FolderChooserItem(ConfigOption option_, QLineEdit* lineEdit_, QPushButton* browsePushButton_, MainWindow* mw) :
FileOrFolderChooserItem(option_, lineEdit_, browsePushButton_, mw) {
QObject::connect(browsePushButton, SIGNAL(released()), this, SLOT(pushButtonReleased()));
}
};
class ComboBoxItem : public MainWindowItem {
public:
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 void installListeners(MainWindow *mainWindow);
virtual void loadFromConfigOption()=0;
virtual void saveToStringStream(std::stringstream& out)=0;
virtual bool isValid() { return true; }
//virtual bool isValid(bool & alreadyDisplayedIfWrong) { return ; }
};
class LogDestinationComboBoxItem : public ComboBoxItem {
public:
@ -237,13 +246,13 @@ public: @@ -237,13 +246,13 @@ public:
optionValue=logDest;
MainWindowItem::saveToStringStream(out);
}
virtual bool isValid() { return true; }
//virtual bool isValid(bool & alreadyDisplayedIfWrong) { return true; }
Q_OBJECT
};
class LogLevelComboBoxItem : public ComboBoxItem {
public:
LogLevelComboBoxItem(ConfigOption option_, QComboBox* comboBox_) : ComboBoxItem(option_, comboBox_) {};
LogLevelComboBoxItem(ConfigOption option_, QComboBox* comboBox_) : ComboBoxItem(option_, comboBox_) {}
virtual ~LogLevelComboBoxItem(){}
virtual void loadFromConfigOption(){
MainWindowItem::loadFromConfigOption();
@ -254,11 +263,11 @@ public: @@ -254,11 +263,11 @@ public:
optionValue=comboBox->currentText().toStdString();
MainWindowItem::saveToStringStream(out);
}
virtual bool isValid() { return true; }
//virtual bool isValid(bool & alreadyDisplayedIfWrong) { return true; }
};
class SignatureTypeComboBoxItem : public ComboBoxItem {
public:
SignatureTypeComboBoxItem(ConfigOption option_, QComboBox* comboBox_) : ComboBoxItem(option_, comboBox_) {};
SignatureTypeComboBoxItem(ConfigOption option_, QComboBox* comboBox_) : ComboBoxItem(option_, comboBox_) {}
virtual ~SignatureTypeComboBoxItem(){}
virtual void loadFromConfigOption(){
MainWindowItem::loadFromConfigOption();
@ -271,12 +280,12 @@ public: @@ -271,12 +280,12 @@ public:
optionValue=(unsigned short)selected;
MainWindowItem::saveToStringStream(out);
}
virtual bool isValid() { return true; }
//virtual bool isValid(bool & alreadyDisplayedIfWrong) { return true; }
};
class CheckBoxItem : public MainWindowItem {
public:
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 void installListeners(MainWindow *mainWindow);
virtual void loadFromConfigOption(){
@ -288,22 +297,25 @@ public: @@ -288,22 +297,25 @@ public:
optionValue=checkBox->isChecked();
MainWindowItem::saveToStringStream(out);
}
virtual bool isValid() { return true; }
//virtual bool isValid(bool & alreadyDisplayedIfWrong) { return true; }
};
class BaseFormattedStringItem : public BaseStringItem {
public:
QString fieldNameTranslated;
BaseFormattedStringItem(ConfigOption option_, QLineEdit* lineEdit_, QString fieldNameTranslated_, QString requirementToBeValid_) :
BaseStringItem(option_, lineEdit_, requirementToBeValid_), fieldNameTranslated(fieldNameTranslated_) {};
BaseFormattedStringItem(ConfigOption option_, QLineEdit* lineEdit_, QString fieldNameTranslated_, QString requirementToBeValid_, MainWindow* mw) :
BaseStringItem(option_, lineEdit_, requirementToBeValid_, mw), fieldNameTranslated(fieldNameTranslated_) {}
virtual ~BaseFormattedStringItem(){}
virtual bool isValid()=0;
//virtual bool isValid(bool & alreadyDisplayedIfWrong)=0;
};
class IntegerStringItem : public BaseFormattedStringItem {
public:
IntegerStringItem(ConfigOption option_, QLineEdit* lineEdit_, QString fieldNameTranslated_) :
BaseFormattedStringItem(option_, lineEdit_, fieldNameTranslated_, QApplication::tr("Must be a valid integer.")) {};
IntegerStringItem(ConfigOption option_, QLineEdit* lineEdit_, QString fieldNameTranslated_, MainWindow* mw) :
BaseFormattedStringItem(option_, lineEdit_, fieldNameTranslated_, QApplication::tr("Must be a valid integer."), mw) {}
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();
bool ok;
str.toInt(&ok);
@ -314,10 +326,13 @@ public: @@ -314,10 +326,13 @@ public:
};
class UShortStringItem : public BaseFormattedStringItem {
public:
UShortStringItem(ConfigOption option_, QLineEdit* lineEdit_, QString fieldNameTranslated_) :
BaseFormattedStringItem(option_, lineEdit_, fieldNameTranslated_, QApplication::tr("Must be unsigned short integer.")) {};
UShortStringItem(ConfigOption option_, QLineEdit* lineEdit_, QString fieldNameTranslated_, MainWindow* mw) :
BaseFormattedStringItem(option_, lineEdit_, fieldNameTranslated_, QApplication::tr("Must be unsigned short integer."), mw) {}
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();
bool ok;
str.toUShort(&ok);
@ -328,10 +343,13 @@ public: @@ -328,10 +343,13 @@ public:
};
class UInt32StringItem : public BaseFormattedStringItem {
public:
UInt32StringItem(ConfigOption option_, QLineEdit* lineEdit_, QString fieldNameTranslated_) :
BaseFormattedStringItem(option_, lineEdit_, fieldNameTranslated_, QApplication::tr("Must be unsigned 32-bit integer.")) {};
UInt32StringItem(ConfigOption option_, QLineEdit* lineEdit_, QString fieldNameTranslated_, MainWindow* mw) :
BaseFormattedStringItem(option_, lineEdit_, fieldNameTranslated_, QApplication::tr("Must be unsigned 32-bit integer."), mw) {}
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();
bool ok;
str.toUInt(&ok);
@ -342,10 +360,13 @@ public: @@ -342,10 +360,13 @@ public:
};
class UInt16StringItem : public BaseFormattedStringItem {
public:
UInt16StringItem(ConfigOption option_, QLineEdit* lineEdit_, QString fieldNameTranslated_) :
BaseFormattedStringItem(option_, lineEdit_, fieldNameTranslated_, QApplication::tr("Must be unsigned 16-bit integer.")) {};
UInt16StringItem(ConfigOption option_, QLineEdit* lineEdit_, QString fieldNameTranslated_, MainWindow* mw) :
BaseFormattedStringItem(option_, lineEdit_, fieldNameTranslated_, QApplication::tr("Must be unsigned 16-bit integer."), mw) {}
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();
bool ok;
str.toUShort(&ok);
@ -356,14 +377,14 @@ public: @@ -356,14 +377,14 @@ public:
};
class IPAddressStringItem : public BaseFormattedStringItem {
public:
IPAddressStringItem(ConfigOption option_, QLineEdit* lineEdit_, QString fieldNameTranslated_) :
BaseFormattedStringItem(option_, lineEdit_, fieldNameTranslated_, QApplication::tr("Must be an IPv4 address")) {};
virtual bool isValid(){return true;}//todo
IPAddressStringItem(ConfigOption option_, QLineEdit* lineEdit_, QString fieldNameTranslated_, MainWindow* mw) :
BaseFormattedStringItem(option_, lineEdit_, fieldNameTranslated_, QApplication::tr("Must be an IPv4 address"), mw) {}
//virtual bool isValid(bool & alreadyDisplayedIfWrong){return true;}//todo
};
class TCPPortStringItem : public UShortStringItem {
public:
TCPPortStringItem(ConfigOption option_, QLineEdit* lineEdit_, QString fieldNameTranslated_) :
UShortStringItem(option_, lineEdit_, fieldNameTranslated_) {};
TCPPortStringItem(ConfigOption option_, QLineEdit* lineEdit_, QString fieldNameTranslated_, MainWindow* mw) :
UShortStringItem(option_, lineEdit_, fieldNameTranslated_,mw) {}
};
namespace Ui {
@ -395,7 +416,7 @@ public: @@ -395,7 +416,7 @@ public:
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;

Loading…
Cancel
Save