diff --git a/src/DaemonQT.cpp b/src/DaemonQT.cpp index 1e45c58..e9bd592 100644 --- a/src/DaemonQT.cpp +++ b/src/DaemonQT.cpp @@ -25,40 +25,40 @@ namespace qt void Worker::startDaemon() { qDebug("Performing daemon start..."); - //try{ + try{ m_Daemon.start(); qDebug("Daemon started."); emit resultReady(false, ""); - /*}catch(std::exception ex){ + }catch(std::exception& ex){ emit resultReady(true, ex.what()); }catch(...){ emit resultReady(true, QObject::tr("Error: unknown exception")); - }*/ + } } void Worker::restartDaemon() { qDebug("Performing daemon restart..."); - //try{ + try{ m_Daemon.restart(); qDebug("Daemon restarted."); emit resultReady(false, ""); - /*}catch(std::exception ex){ + }catch(std::exception& ex){ emit resultReady(true, ex.what()); }catch(...){ emit resultReady(true, QObject::tr("Error: unknown exception")); - }*/ + } } void Worker::stopDaemon() { qDebug("Performing daemon stop..."); - //try{ + try{ m_Daemon.stop(); qDebug("Daemon stopped."); emit resultReady(false, ""); - /*}catch(std::exception ex){ + }catch(std::exception& ex){ emit resultReady(true, ex.what()); }catch(...){ emit resultReady(true, QObject::tr("Error: unknown exception")); - }*/ + } } Controller::Controller(DaemonQTImpl& daemon): diff --git a/src/Saver.h b/src/Saver.h index bf971fb..44d900a 100644 --- a/src/Saver.h +++ b/src/Saver.h @@ -19,7 +19,7 @@ public: signals: void reloadTunnelsConfigAndUISignal(const QString); - + void showPreventedSaveTunnelsConfMessage(); }; #endif // SAVER_H diff --git a/src/SaverImpl.cpp b/src/SaverImpl.cpp index 4b22bf4..5a12c29 100644 --- a/src/SaverImpl.cpp +++ b/src/SaverImpl.cpp @@ -9,9 +9,11 @@ #include "mainwindow.h" -SaverImpl::SaverImpl(MainWindow *mainWindowPtr_, QSharedPointer> configItems_, QSharedPointer> tunnelConfigs_) : +SaverImpl::SaverImpl(MainWindow *mainWindowPtr_, QList* configItems_, std::map* tunnelConfigs_) : configItems(configItems_), tunnelConfigs(tunnelConfigs_), confpath(), tunconfpath(), mainWindowPtr(mainWindowPtr_) -{} +{ + QObject::connect(this, SIGNAL(showPreventedSaveTunnelsConfMessage()), mainWindowPtr, SLOT(showTunnelsPagePreventedMessage())); +} SaverImpl::~SaverImpl() {} @@ -37,7 +39,9 @@ bool SaverImpl::save(bool reloadAfterSave, const FocusEnum focusOn, const std::s } //save tunnels config - { + if (mainWindowPtr->isPreventSaveTunnelsMode()) { + emit showPreventedSaveTunnelsConfMessage(); + }else{ std::stringstream out; for (std::map::iterator it=tunnelConfigs->begin(); it!=tunnelConfigs->end(); ++it) { diff --git a/src/SaverImpl.h b/src/SaverImpl.h index 84c20dd..6f8ab91 100644 --- a/src/SaverImpl.h +++ b/src/SaverImpl.h @@ -6,7 +6,6 @@ #include #include "QList" -#include "QSharedPointer" #include "mainwindow.h" #include "TunnelConfig.h" @@ -15,17 +14,16 @@ class MainWindowItem; class TunnelConfig; -class SaverImpl : public Saver -{ +class SaverImpl : public Saver { public: - SaverImpl(MainWindow *mainWindowPtr_, QSharedPointer> configItems_, QSharedPointer> tunnelConfigs_); + SaverImpl(MainWindow *mainWindowPtr_, QList* configItems_, std::map* tunnelConfigs_); virtual ~SaverImpl(); virtual bool save(bool reloadAfterSave, const FocusEnum focusOn, const std::string& tunnelNameToFocus, QWidget* widgetToFocus); void setConfPath(QString& confpath_); void setTunnelsConfPath(QString& tunconfpath_); private: - QSharedPointer> configItems; - QSharedPointer> tunnelConfigs; + QList* configItems; + std::map* tunnelConfigs; QString confpath; QString tunconfpath; MainWindow* mainWindowPtr; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index adc0099..433630a 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include @@ -68,10 +69,11 @@ MainWindow::MainWindow(std::shared_ptr logStream_, QWidget *paren ,tunconfpath() ,tunnelConfigs() ,tunnelsPageUpdateListener(this) + ,preventSaveTunnelsBool(false) ,saverPtr( new SaverImpl(this, - QSharedPointer>(&configItems), - QSharedPointer>(&tunnelConfigs))) + &configItems, + &tunnelConfigs)) { assert(delayedSaveManagerPtr!=nullptr); @@ -778,6 +780,10 @@ void MainWindow::loadAllConfigs(SaverImpl* saverPtr){ void MainWindow::DisableTunnelsPage() { ui->tunnelsScrollAreaWidgetContents->setEnabled(false); + ui->tunnelsScrollArea->setEnabled(false); + ui->addClientTunnelPushButton->setEnabled(false); + ui->addServerTunnelPushButton->setEnabled(false); + preventSaveTunnels(); } void MainWindow::layoutTunnels() { @@ -1135,3 +1141,14 @@ void MainWindow::syncLogLevel (int /*comboBoxIndex*/) { i2p::log::Logger().Reopen (); } +void MainWindow::preventSaveTunnels() { + preventSaveTunnelsBool = true; +} + +bool MainWindow::isPreventSaveTunnelsMode() { + return preventSaveTunnelsBool; +} + +void MainWindow::showTunnelsPagePreventedMessage() { + QMessageBox::critical(this,QObject::tr("Error"),QObject::tr("Not saving tunnels configuration due to previous errors with it.")); +} diff --git a/src/mainwindow.h b/src/mainwindow.h index 525ff63..1522e4c 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -500,6 +500,8 @@ public: Ui::GeneralSettingsContentsForm* uiSettings; void adjustSizesAccordingToWrongLabel(); bool applyTunnelsUiToConfigs(); + void preventSaveTunnels(); + bool isPreventSaveTunnelsMode(); private: int settingsTitleLabelNominalHeight; TextBrowserTweaked1 * textBrowser; @@ -894,9 +896,13 @@ private: //void onLoggingOptionsChange() {} + bool preventSaveTunnelsBool; SaverImpl* saverPtr; void DisableTunnelsPage(); + +public slots: + void showTunnelsPagePreventedMessage(); }; #endif // MAINWINDOW_H