@ -93,8 +93,13 @@ class MainWindow;
class MainWindowItem : public QObject {
class MainWindowItem : public QObject {
Q_OBJECT
Q_OBJECT
ConfigOption option ;
ConfigOption option ;
QWidget * widgetToFocus ;
QString requirementToBeValid ;
public :
public :
MainWindowItem ( ConfigOption option_ ) : option ( option_ ) { }
MainWindowItem ( ConfigOption option_ , QWidget * widgetToFocus_ , QString requirementToBeValid_ ) : option ( option_ ) , widgetToFocus ( widgetToFocus_ ) , requirementToBeValid ( requirementToBeValid_ ) { }
QWidget * getWidgetToFocus ( ) { return widgetToFocus ; }
QString & getRequirementToBeValid ( ) { return requirementToBeValid ; }
ConfigOption & getConfigOption ( ) { return option ; }
boost : : any optionValue ;
boost : : any optionValue ;
virtual ~ MainWindowItem ( ) { }
virtual ~ MainWindowItem ( ) { }
virtual void installListeners ( MainWindow * mainWindow ) ;
virtual void installListeners ( MainWindow * mainWindow ) ;
@ -145,7 +150,7 @@ public:
} ;
} ;
class NonGUIOptionItem : public MainWindowItem {
class NonGUIOptionItem : public MainWindowItem {
public :
public :
NonGUIOptionItem ( ConfigOption option_ ) : MainWindowItem ( option_ ) { } ;
NonGUIOptionItem ( ConfigOption option_ ) : MainWindowItem ( option_ , nullptr , QString ( ) ) { } ;
virtual ~ NonGUIOptionItem ( ) { }
virtual ~ NonGUIOptionItem ( ) { }
virtual bool isValid ( ) { return true ; }
virtual bool isValid ( ) { return true ; }
} ;
} ;
@ -153,7 +158,7 @@ class BaseStringItem : public MainWindowItem {
Q_OBJECT
Q_OBJECT
public :
public :
QLineEdit * lineEdit ;
QLineEdit * lineEdit ;
BaseStringItem ( ConfigOption option_ , QLineEdit * lineEdit_ ) : MainWindowItem ( option_ ) , lineEdit ( lineEdit_ ) { } ;
BaseStringItem ( ConfigOption option_ , QLineEdit * lineEdit_ , QString requirementToBeValid_ ) : MainWindowItem ( option_ , lineEdit_ , requirementToBeValid _ ) , lineEdit ( lineEdit_ ) { } ;
virtual ~ BaseStringItem ( ) { }
virtual ~ BaseStringItem ( ) { }
virtual void installListeners ( MainWindow * mainWindow ) ;
virtual void installListeners ( MainWindow * mainWindow ) ;
virtual QString toString ( ) {
virtual QString toString ( ) {
@ -175,7 +180,7 @@ class FileOrFolderChooserItem : public BaseStringItem {
public :
public :
QPushButton * browsePushButton ;
QPushButton * browsePushButton ;
FileOrFolderChooserItem ( ConfigOption option_ , QLineEdit * lineEdit_ , QPushButton * browsePushButton_ ) :
FileOrFolderChooserItem ( ConfigOption option_ , QLineEdit * lineEdit_ , QPushButton * browsePushButton_ ) :
BaseStringItem ( option_ , lineEdit_ ) , browsePushButton ( browsePushButton_ ) { }
BaseStringItem ( option_ , lineEdit_ , QString ( ) ) , browsePushButton ( browsePushButton_ ) { }
virtual ~ FileOrFolderChooserItem ( ) { }
virtual ~ FileOrFolderChooserItem ( ) { }
} ;
} ;
class FileChooserItem : public FileOrFolderChooserItem {
class FileChooserItem : public FileOrFolderChooserItem {
@ -201,7 +206,7 @@ public:
class ComboBoxItem : public MainWindowItem {
class ComboBoxItem : public MainWindowItem {
public :
public :
QComboBox * comboBox ;
QComboBox * comboBox ;
ComboBoxItem ( ConfigOption option_ , QComboBox * comboBox_ ) : MainWindowItem ( option_ ) , 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 ;
@ -260,7 +265,7 @@ public:
class CheckBoxItem : public MainWindowItem {
class CheckBoxItem : public MainWindowItem {
public :
public :
QCheckBox * checkBox ;
QCheckBox * checkBox ;
CheckBoxItem ( ConfigOption option_ , QCheckBox * checkBox_ ) : MainWindowItem ( option_ ) , 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 ( ) {
@ -276,58 +281,77 @@ public:
class BaseFormattedStringItem : public BaseStringItem {
class BaseFormattedStringItem : public BaseStringItem {
public :
public :
QString fieldNameTranslated ;
QString fieldNameTranslated ;
BaseFormattedStringItem ( ConfigOption option_ , QLineEdit * lineEdit_ , QString fieldNameTranslated_ ) :
BaseFormattedStringItem ( ConfigOption option_ , QLineEdit * lineEdit_ , QString fieldNameTranslated_ , QString requirementToBeValid_ ) :
BaseStringItem ( option_ , lineEdit_ ) , fieldNameTranslated ( fieldNameTranslated_ ) { } ;
BaseStringItem ( option_ , lineEdit_ , requirementToBeValid_ ) , fieldNameTranslated ( fieldNameTranslated_ ) { } ;
virtual ~ BaseFormattedStringItem ( ) { }
virtual ~ BaseFormattedStringItem ( ) { }
virtual bool isValid ( ) = 0 ;
virtual bool isValid ( ) = 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_ ) :
BaseFormattedStringItem ( option_ , lineEdit_ , fieldNameTranslated_ ) { } ;
BaseFormattedStringItem ( option_ , lineEdit_ , fieldNameTranslated_ , QApplication : : tr ( " Must be a valid integer. " ) ) { } ;
virtual ~ IntegerStringItem ( ) { }
virtual ~ IntegerStringItem ( ) { }
virtual bool isValid ( ) { return true ; }
virtual bool isValid ( ) {
auto str = lineEdit - > text ( ) ;
bool ok ;
str . toInt ( & ok ) ;
return ok ;
}
virtual QString toString ( ) { return QString : : number ( boost : : any_cast < int > ( optionValue ) ) ; }
virtual QString toString ( ) { return QString : : number ( boost : : any_cast < int > ( optionValue ) ) ; }
virtual boost : : any fromString ( QString s ) { return boost : : any ( std : : stoi ( s . toStdString ( ) ) ) ; }
virtual boost : : any fromString ( QString s ) { return boost : : any ( std : : stoi ( s . toStdString ( ) ) ) ; }
} ;
} ;
class UShortStringItem : public BaseFormattedStringItem {
class UShortStringItem : public BaseFormattedStringItem {
public :
public :
UShortStringItem ( ConfigOption option_ , QLineEdit * lineEdit_ , QString fieldNameTranslated_ ) :
UShortStringItem ( ConfigOption option_ , QLineEdit * lineEdit_ , QString fieldNameTranslated_ ) :
BaseFormattedStringItem ( option_ , lineEdit_ , fieldNameTranslated_ ) { } ;
BaseFormattedStringItem ( option_ , lineEdit_ , fieldNameTranslated_ , QApplication : : tr ( " Must be unsigned short integer. " ) ) { } ;
virtual ~ UShortStringItem ( ) { }
virtual ~ UShortStringItem ( ) { }
virtual bool isValid ( ) { return true ; }
virtual bool isValid ( ) {
auto str = lineEdit - > text ( ) ;
bool ok ;
str . toUShort ( & ok ) ;
return ok ;
}
virtual QString toString ( ) { return QString : : number ( boost : : any_cast < unsigned short > ( optionValue ) ) ; }
virtual QString toString ( ) { return QString : : number ( boost : : any_cast < unsigned short > ( optionValue ) ) ; }
virtual boost : : any fromString ( QString s ) { return boost : : any ( ( unsigned short ) std : : stoi ( s . toStdString ( ) ) ) ; }
virtual boost : : any fromString ( QString s ) { return boost : : any ( ( unsigned short ) std : : stoi ( s . toStdString ( ) ) ) ; }
} ;
} ;
class UInt32StringItem : public BaseFormattedStringItem {
class UInt32StringItem : public BaseFormattedStringItem {
public :
public :
UInt32StringItem ( ConfigOption option_ , QLineEdit * lineEdit_ , QString fieldNameTranslated_ ) :
UInt32StringItem ( ConfigOption option_ , QLineEdit * lineEdit_ , QString fieldNameTranslated_ ) :
BaseFormattedStringItem ( option_ , lineEdit_ , fieldNameTranslated_ ) { } ;
BaseFormattedStringItem ( option_ , lineEdit_ , fieldNameTranslated_ , QApplication : : tr ( " Must be unsigned 32-bit integer. " ) ) { } ;
virtual ~ UInt32StringItem ( ) { }
virtual ~ UInt32StringItem ( ) { }
virtual bool isValid ( ) { return true ; }
virtual bool isValid ( ) {
auto str = lineEdit - > text ( ) ;
bool ok ;
str . toUInt ( & ok ) ;
return ok ;
}
virtual QString toString ( ) { return QString : : number ( boost : : any_cast < uint32_t > ( optionValue ) ) ; }
virtual QString toString ( ) { return QString : : number ( boost : : any_cast < uint32_t > ( optionValue ) ) ; }
virtual boost : : any fromString ( QString s ) { return boost : : any ( ( uint32_t ) std : : stoi ( s . toStdString ( ) ) ) ; }
virtual boost : : any fromString ( QString s ) { return boost : : any ( ( uint32_t ) std : : stoi ( s . toStdString ( ) ) ) ; }
} ;
} ;
class UInt16StringItem : public BaseFormattedStringItem {
class UInt16StringItem : public BaseFormattedStringItem {
public :
public :
UInt16StringItem ( ConfigOption option_ , QLineEdit * lineEdit_ , QString fieldNameTranslated_ ) :
UInt16StringItem ( ConfigOption option_ , QLineEdit * lineEdit_ , QString fieldNameTranslated_ ) :
BaseFormattedStringItem ( option_ , lineEdit_ , fieldNameTranslated_ ) { } ;
BaseFormattedStringItem ( option_ , lineEdit_ , fieldNameTranslated_ , QApplication : : tr ( " Must be unsigned 16-bit integer. " ) ) { } ;
virtual ~ UInt16StringItem ( ) { }
virtual ~ UInt16StringItem ( ) { }
virtual bool isValid ( ) { return true ; }
virtual bool isValid ( ) {
auto str = lineEdit - > text ( ) ;
bool ok ;
str . toUShort ( & ok ) ;
return ok ;
}
virtual QString toString ( ) { return QString : : number ( boost : : any_cast < uint16_t > ( optionValue ) ) ; }
virtual QString toString ( ) { return QString : : number ( boost : : any_cast < uint16_t > ( optionValue ) ) ; }
virtual boost : : any fromString ( QString s ) { return boost : : any ( ( uint16_t ) std : : stoi ( s . toStdString ( ) ) ) ; }
virtual boost : : any fromString ( QString s ) { return boost : : any ( ( uint16_t ) std : : stoi ( s . toStdString ( ) ) ) ; }
} ;
} ;
class IPAddressStringItem : public BaseFormattedStringItem {
class IPAddressStringItem : public BaseFormattedStringItem {
public :
public :
IPAddressStringItem ( ConfigOption option_ , QLineEdit * lineEdit_ , QString fieldNameTranslated_ ) :
IPAddressStringItem ( ConfigOption option_ , QLineEdit * lineEdit_ , QString fieldNameTranslated_ ) :
BaseFormattedStringItem ( option_ , lineEdit_ , fieldNameTranslated_ ) { } ;
BaseFormattedStringItem ( option_ , lineEdit_ , fieldNameTranslated_ , QApplication : : tr ( " Must be an IPv4 address " ) ) { } ;
virtual bool isValid ( ) { return true ; }
virtual bool isValid ( ) { 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_ ) :
UShortStringItem ( option_ , lineEdit_ , fieldNameTranslated_ ) { } ;
UShortStringItem ( option_ , lineEdit_ , fieldNameTranslated_ ) { } ;
virtual bool isValid ( ) { return true ; }
} ;
} ;
namespace Ui {
namespace Ui {
@ -354,6 +378,8 @@ public:
void setI2PController ( i2p : : qt : : Controller * controller_ ) ;
void setI2PController ( i2p : : qt : : Controller * controller_ ) ;
void highlightWrongInput ( QString warningText , QWidget * widgetToFocus ) ;
//typedef std::function<QString ()> DefaultValueGetter;
//typedef std::function<QString ()> DefaultValueGetter;
//#ifndef ANDROID
//#ifndef ANDROID
@ -385,7 +411,7 @@ private slots:
void runPeerTest ( ) ;
void runPeerTest ( ) ;
void enableTransit ( ) ;
void enableTransit ( ) ;
void disableTransit ( ) ;
void disableTransit ( ) ;
public slots :
void showStatus_local_destinations_Page ( ) ;
void showStatus_local_destinations_Page ( ) ;
void showStatus_leasesets_Page ( ) ;
void showStatus_leasesets_Page ( ) ;
void showStatus_tunnels_Page ( ) ;
void showStatus_tunnels_Page ( ) ;
@ -546,9 +572,9 @@ private:
TunnelConfig * tc = it - > second ;
TunnelConfig * tc = it - > second ;
tunnelConfigs . erase ( it ) ;
tunnelConfigs . erase ( it ) ;
delete tc ;
delete tc ;
SaveTunnelsConfig ( ) ;
reloadTunnelsConfigAndUI ( " " ) ;
}
}
saveAllConfigs ( ) ;
reloadTunnelsConfigAndUI ( " " ) ;
}
}
std : : string GenerateNewTunnelName ( ) {
std : : string GenerateNewTunnelName ( ) {
@ -583,7 +609,7 @@ private:
destinationPort ,
destinationPort ,
sigType ) ;
sigType ) ;
SaveTunnelsConfig ( ) ;
saveAllConfigs ( ) ;
reloadTunnelsConfigAndUI ( name ) ;
reloadTunnelsConfigAndUI ( name ) ;
}
}
@ -622,7 +648,7 @@ private:
isUniqueLocal ) ;
isUniqueLocal ) ;
SaveTunnelsConfig ( ) ;
saveAllConfigs ( ) ;
reloadTunnelsConfigAndUI ( name ) ;
reloadTunnelsConfigAndUI ( name ) ;
}
}