Browse Source

tunnels.conf code fixes

* Now shows a message box and disables tunnels UI control on errors;
* QSharedPointer instead of simple C pointer within SaverImpl.
pull/78/head
nonlin-lin-chaos-order-etc-etal 2 years ago
parent
commit
d5690c6280
  1. 2
      src/SaverImpl.cpp
  2. 7
      src/SaverImpl.h
  3. 9
      src/mainwindow.cpp
  4. 29
      src/mainwindow.h

2
src/SaverImpl.cpp

@ -9,7 +9,7 @@
#include "mainwindow.h" #include "mainwindow.h"
SaverImpl::SaverImpl(MainWindow *mainWindowPtr_, QList<MainWindowItem*> * configItems_, std::map<std::string,TunnelConfig*>* tunnelConfigs_) : SaverImpl::SaverImpl(MainWindow *mainWindowPtr_, QSharedPointer<QList<MainWindowItem*>> configItems_, QSharedPointer<std::map<std::string,TunnelConfig*>> tunnelConfigs_) :
configItems(configItems_), tunnelConfigs(tunnelConfigs_), confpath(), tunconfpath(), mainWindowPtr(mainWindowPtr_) configItems(configItems_), tunnelConfigs(tunnelConfigs_), confpath(), tunconfpath(), mainWindowPtr(mainWindowPtr_)
{} {}

7
src/SaverImpl.h

@ -6,6 +6,7 @@
#include <QObject> #include <QObject>
#include "QList" #include "QList"
#include "QSharedPointer"
#include "mainwindow.h" #include "mainwindow.h"
#include "TunnelConfig.h" #include "TunnelConfig.h"
@ -17,14 +18,14 @@ class TunnelConfig;
class SaverImpl : public Saver class SaverImpl : public Saver
{ {
public: public:
SaverImpl(MainWindow *mainWindowPtr_, QList<MainWindowItem*> * configItems_, std::map<std::string,TunnelConfig*>* tunnelConfigs_); SaverImpl(MainWindow *mainWindowPtr_, QSharedPointer<QList<MainWindowItem*>> configItems_, QSharedPointer<std::map<std::string,TunnelConfig*>> tunnelConfigs_);
virtual ~SaverImpl(); virtual ~SaverImpl();
virtual bool save(bool reloadAfterSave, const FocusEnum focusOn, const std::string& tunnelNameToFocus, QWidget* widgetToFocus); virtual bool save(bool reloadAfterSave, const FocusEnum focusOn, const std::string& tunnelNameToFocus, QWidget* widgetToFocus);
void setConfPath(QString& confpath_); void setConfPath(QString& confpath_);
void setTunnelsConfPath(QString& tunconfpath_); void setTunnelsConfPath(QString& tunconfpath_);
private: private:
QList<MainWindowItem*> * configItems; QSharedPointer<QList<MainWindowItem*>> configItems;
std::map<std::string,TunnelConfig*>* tunnelConfigs; QSharedPointer<std::map<std::string,TunnelConfig*>> tunnelConfigs;
QString confpath; QString confpath;
QString tunconfpath; QString tunconfpath;
MainWindow* mainWindowPtr; MainWindow* mainWindowPtr;

9
src/mainwindow.cpp

@ -68,7 +68,10 @@ MainWindow::MainWindow(std::shared_ptr<std::iostream> logStream_, QWidget *paren
,tunconfpath() ,tunconfpath()
,tunnelConfigs() ,tunnelConfigs()
,tunnelsPageUpdateListener(this) ,tunnelsPageUpdateListener(this)
,saverPtr(new SaverImpl(this, &configItems, &tunnelConfigs)) ,saverPtr(
new SaverImpl(this,
QSharedPointer<QList<MainWindowItem*>>(&configItems),
QSharedPointer<std::map<std::string,TunnelConfig*>>(&tunnelConfigs)))
{ {
assert(delayedSaveManagerPtr!=nullptr); assert(delayedSaveManagerPtr!=nullptr);
@ -773,6 +776,10 @@ void MainWindow::loadAllConfigs(SaverImpl* saverPtr){
//onLoggingOptionsChange(); //onLoggingOptionsChange();
} }
void MainWindow::DisableTunnelsPage() {
ui->tunnelsScrollAreaWidgetContents->setEnabled(false);
}
void MainWindow::layoutTunnels() { void MainWindow::layoutTunnels() {
int height=0; int height=0;

29
src/mainwindow.h

@ -1,9 +1,12 @@
#ifndef MAINWINDOW_H #ifndef MAINWINDOW_H
#define MAINWINDOW_H #define MAINWINDOW_H
#include <sstream>
#include <QObject> #include <QObject>
#include <QMainWindow> #include <QMainWindow>
#include <QPushButton> #include <QPushButton>
#include <QMessageBox>
#include <QtCore/QVariant> #include <QtCore/QVariant>
#include <QtWidgets/QAction> #include <QtWidgets/QAction>
#include <QtWidgets/QApplication> #include <QtWidgets/QApplication>
@ -756,7 +759,11 @@ private:
} }
catch (std::exception& ex) catch (std::exception& ex)
{ {
LogPrint (eLogWarning, "Clients: Can't read ", tunConf, ": ", ex.what ());//TODO show err box and disable tunn.page LogPrint (eLogWarning, "Clients: Can't read ", tunConf, ": ", ex.what ());
std::stringstream error;
error << "Error reading tunnels configuration file " << tunConf << ": " << ex.what();
QMessageBox::critical(this, "Error", error.str().c_str());
DisableTunnelsPage();
return; return;
} }
@ -853,13 +860,23 @@ private:
isUniqueLocal, isUniqueLocal,
cryptoType); cryptoType);
} }
else else {
LogPrint (eLogWarning, "Clients: Unknown section type=", type, " of ", name, " in ", tunConf);//TODO show err box and disable the tunn gui LogPrint (eLogWarning, "Clients: Unknown section type=", type, " of ", name, " in ", tunConf);
std::stringstream error;
error << "Error reading tunnels configuration file " << tunConf << ": Unknown section type " << type << " of " << name;
QMessageBox::critical(this, "Error", error.str().c_str());
DisableTunnelsPage();
return;
}
} }
catch (std::exception& ex) catch (std::exception& ex)
{ {
LogPrint (eLogError, "Clients: Can't read tunnel ", name, " params: ", ex.what ());//TODO show err box and disable the tunn gui LogPrint (eLogError, "Clients: ", name, " params: ", ex.what ());
std::stringstream error;
error << "Error reading tunnels configuration file " << tunConf << ": Can't read tunnel named '" << name << "': " << ex.what();
QMessageBox::critical(this, "Error", error.str().c_str());
DisableTunnelsPage();
return;
} }
} }
} }
@ -878,6 +895,8 @@ private:
//void onLoggingOptionsChange() {} //void onLoggingOptionsChange() {}
SaverImpl* saverPtr; SaverImpl* saverPtr;
void DisableTunnelsPage();
}; };
#endif // MAINWINDOW_H #endif // MAINWINDOW_H

Loading…
Cancel
Save