diff --git a/src/DelayedSaveManagerImpl.cpp b/src/DelayedSaveManagerImpl.cpp index bad6fdb..928a781 100644 --- a/src/DelayedSaveManagerImpl.cpp +++ b/src/DelayedSaveManagerImpl.cpp @@ -51,6 +51,11 @@ bool DelayedSaveManagerImpl::appExiting() { return true; } +void DelayedSaveManagerImpl::saveNow() { + assert(isSaverValid()); + saver->save(isReloadAfterSave(), FocusEnum::noFocus); +} + DelayedSaveThread::DelayedSaveThread(DelayedSaveManagerImpl* delayedSaveManagerImpl_): delayedSaveManagerImpl(delayedSaveManagerImpl_), mutex(new QMutex()), diff --git a/src/DelayedSaveManagerImpl.h b/src/DelayedSaveManagerImpl.h index c9a77c3..0698b56 100644 --- a/src/DelayedSaveManagerImpl.h +++ b/src/DelayedSaveManagerImpl.h @@ -53,6 +53,7 @@ public: virtual void setSaver(Saver* saver); virtual void start(); virtual void delayedSave(bool reloadAfterSave, DATA_SERIAL_TYPE dataSerial, FocusEnum focusOn, std::string tunnelNameToFocus, QWidget* widgetToFocus); + void saveNow(); virtual bool appExiting(); typedef DelayedSaveThread::TIMESTAMP_TYPE TIMESTAMP_TYPE; diff --git a/src/TunnelConfig.h b/src/TunnelConfig.h index b33f882..1a87b38 100644 --- a/src/TunnelConfig.h +++ b/src/TunnelConfig.h @@ -81,13 +81,15 @@ class TunnelConfig { */ QString type; std::string name; + int _tunnelId; TunnelPane* tunnelPane; int cryptoType; public: - TunnelConfig(std::string name_, QString& type_, I2CPParameters& i2cpParameters_, int cryptoType_): - type(type_), name(name_), cryptoType(cryptoType_), i2cpParameters(i2cpParameters_) {} + TunnelConfig(int tunnelId, std::string name_, QString& type_, I2CPParameters& i2cpParameters_, int cryptoType_): + type(type_), name(name_), _tunnelId(tunnelId), cryptoType(cryptoType_), i2cpParameters(i2cpParameters_) {} virtual ~TunnelConfig(){} const QString& getType(){return type;} + int get_TunnelId(){return _tunnelId;} const std::string& getName(){return name;} int getcryptoType(){return cryptoType;} void setType(const QString& type_){type=type_;} @@ -135,14 +137,14 @@ class ClientTunnelConfig : public TunnelConfig { int destinationPort; i2p::data::SigningKeyType sigType; public: - ClientTunnelConfig(std::string name_, QString type_, I2CPParameters& i2cpParameters_, + ClientTunnelConfig(int tunnelId, std::string name_, QString type_, I2CPParameters& i2cpParameters_, std::string dest_, int port_, std::string keys_, std::string address_, int destinationPort_, i2p::data::SigningKeyType sigType_, - int cryptoType_): TunnelConfig(name_, type_, i2cpParameters_, cryptoType_), + int cryptoType_): TunnelConfig(tunnelId, name_, type_, i2cpParameters_, cryptoType_), dest(dest_), port(port_), keys(keys_), @@ -205,7 +207,7 @@ class ServerTunnelConfig : public TunnelConfig { std::string address; bool isUniqueLocal; public: - ServerTunnelConfig(std::string name_, QString type_, I2CPParameters& i2cpParameters_, + ServerTunnelConfig(int tunnelId, std::string name_, QString type_, I2CPParameters& i2cpParameters_, std::string host_, int port_, std::string keys_, @@ -217,7 +219,7 @@ public: i2p::data::SigningKeyType sigType_, std::string address_, bool isUniqueLocal_, - int cryptoType_): TunnelConfig(name_, type_, i2cpParameters_, cryptoType_), + int cryptoType_): TunnelConfig(tunnelId, name_, type_, i2cpParameters_, cryptoType_), host(host_), port(port_), keys(keys_), diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 433630a..4537a27 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -68,6 +68,7 @@ MainWindow::MainWindow(std::shared_ptr logStream_, QWidget *paren ,confpath() ,tunconfpath() ,tunnelConfigs() + ,tunnelConfigsById() ,tunnelsPageUpdateListener(this) ,preventSaveTunnelsBool(false) ,saverPtr( @@ -601,7 +602,7 @@ void MainWindow::iconActivated(QSystemTrayIcon::ActivationReason reason) { setVisible(!isVisible()); break; default: - qDebug() << "MainWindow::iconActivated(): unknown reason: " << reason << endl; + qDebug() << "MainWindow::iconActivated(): unknown reason: " << reason << Qt::endl; break; } } @@ -973,7 +974,7 @@ void MainWindow::TunnelsPageUpdateListenerMainWindowImpl::updated(std::string ol std::map::const_iterator it=mainWindow->tunnelConfigs.find(oldName); if(it!=mainWindow->tunnelConfigs.end())mainWindow->tunnelConfigs.erase(it); mainWindow->tunnelConfigs[tunConf->getName()]=tunConf; - mainWindow->saveAllConfigs(true, FocusEnum::focusOnTunnelName, tunConf->getName()); + mainWindow->saveAllConfigs(false, FocusEnum::focusOnTunnelName, tunConf->getName()); } else mainWindow->saveAllConfigs(false, FocusEnum::noFocus); diff --git a/src/mainwindow.h b/src/mainwindow.h index 1522e4c..17e85e0 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -244,8 +244,7 @@ public: virtual ~LogDestinationComboBoxItem(){} virtual void loadFromConfigOption(){ MainWindowItem::loadFromConfigOption(); - const char * ld = boost::any_cast(optionValue).c_str(); - comboBox->setCurrentText(QString(ld)); + comboBox->setCurrentText(QString(boost::any_cast(optionValue).c_str())); } virtual void saveToStringStream(std::stringstream& out){ std::string logDest = comboBox->currentText().toStdString(); @@ -262,8 +261,7 @@ public: virtual ~LogLevelComboBoxItem(){} virtual void loadFromConfigOption(){ MainWindowItem::loadFromConfigOption(); - const char * ll = boost::any_cast(optionValue).c_str(); - comboBox->setCurrentText(QString(ll)); + comboBox->setCurrentText(QString(boost::any_cast(optionValue).c_str())); } virtual void saveToStringStream(std::stringstream& out){ optionValue=comboBox->currentText().toStdString(); @@ -573,6 +571,7 @@ private: QString tunconfpath; std::map tunnelConfigs; + std::map tunnelConfigsById; std::list tunnelPanes; void appendTunnelForms(std::string tunnelNameToFocus); @@ -661,9 +660,11 @@ private: TunnelConfig* tc=it->second; deleteTunnelFromUI(name, tc); tunnelConfigs.erase(it); + tunnelConfigsById.erase(tc->get_TunnelId()); delete tc; } saveAllConfigs(true, FocusEnum::noFocus); + delayedSaveManagerPtr->saveNow(); } std::string GenerateNewTunnelName() { @@ -677,7 +678,16 @@ private: } } + int GenerateNewTunnelId() { + int i=1; + while(true){ + if(tunnelConfigsById.find(i)==tunnelConfigsById.end())return i; + ++i; + } + } + void CreateDefaultClientTunnel() {//TODO dedup default values with ReadTunnelsConfig() and with ClientContext.cpp::ReadTunnels () + int tunnelId=GenerateNewTunnelId(); std::string name=GenerateNewTunnelName(); std::string type = I2P_TUNNELS_SECTION_TYPE_CLIENT; std::string dest = "127.0.0.1"; @@ -691,7 +701,9 @@ private: I2CPParameters i2cpParameters; CreateDefaultI2CPOptions (i2cpParameters); - tunnelConfigs[name]=new ClientTunnelConfig(name, QString(type.c_str()), i2cpParameters, + tunnelConfigs[name]=tunnelConfigsById[tunnelId]=new ClientTunnelConfig( + tunnelId, + name, QString(type.c_str()), i2cpParameters, dest, port, keys, @@ -701,9 +713,11 @@ private: cryptoType); saveAllConfigs(true, FocusEnum::focusOnTunnelName, name); + delayedSaveManagerPtr->saveNow(); } void CreateDefaultServerTunnel() {//TODO dedup default values with ReadTunnelsConfig() and with ClientContext.cpp::ReadTunnels () + int tunnelId=GenerateNewTunnelId(); std::string name=GenerateNewTunnelName(); std::string type=I2P_TUNNELS_SECTION_TYPE_SERVER; std::string host = "127.0.0.1"; @@ -723,7 +737,9 @@ private: I2CPParameters i2cpParameters; CreateDefaultI2CPOptions (i2cpParameters); - tunnelConfigs[name]=new ServerTunnelConfig(name, QString(type.c_str()), i2cpParameters, + tunnelConfigs[name]=tunnelConfigsById[tunnelId]=new ServerTunnelConfig( + tunnelId, + name, QString(type.c_str()), i2cpParameters, host, port, keys, @@ -739,6 +755,7 @@ private: saveAllConfigs(true, FocusEnum::focusOnTunnelName, name); + delayedSaveManagerPtr->saveNow(); } void ReadTunnelsConfig() //TODO deduplicate the code with ClientContext.cpp::ReadTunnels () @@ -797,8 +814,10 @@ private: std::map options; I2CPParameters i2cpParameters; ReadI2CPOptions (section, options, i2cpParameters); + int tunnelId=GenerateNewTunnelId(); - tunnelConfigs[name]=new ClientTunnelConfig(name, QString(type.c_str()), i2cpParameters, + tunnelConfigs[name]=tunnelConfigsById[tunnelId]= + new ClientTunnelConfig(tunnelId,name, QString(type.c_str()), i2cpParameters, dest, port, keys, @@ -831,6 +850,7 @@ private: std::map options; I2CPParameters i2cpParameters; ReadI2CPOptions (section, options, i2cpParameters); + int tunnelId=GenerateNewTunnelId(); /* std::set idents; @@ -848,7 +868,8 @@ private: while (comma != std::string::npos); } */ - tunnelConfigs[name]=new ServerTunnelConfig(name, QString(type.c_str()), i2cpParameters, + tunnelConfigs[name]=tunnelConfigsById[tunnelId]= + new ServerTunnelConfig(tunnelId,name, QString(type.c_str()), i2cpParameters, host, port, keys,