@ -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;