mirror of
https://github.com/PurpleI2P/i2pd-qt.git
synced 2025-01-26 06:14:15 +00:00
parent
37c1d53406
commit
c0931a9e4b
10
i2pd_qt.pro
10
i2pd_qt.pro
@ -29,7 +29,6 @@ CONFIG(debug, debug|release) {
|
|||||||
|
|
||||||
DEFINES += I2PD_QT_DEBUG
|
DEFINES += I2PD_QT_DEBUG
|
||||||
I2PDMAKE += DEBUG=yes
|
I2PDMAKE += DEBUG=yes
|
||||||
QMAKE_CXXFLAGS_DEBUG += "-O0"
|
|
||||||
}
|
}
|
||||||
CONFIG(release, debug|release) {
|
CONFIG(release, debug|release) {
|
||||||
message(Release build)
|
message(Release build)
|
||||||
@ -38,9 +37,7 @@ CONFIG(release, debug|release) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
src/launcher/i2pd_qt_launcher.cpp \
|
src/DaemonQT.cpp \
|
||||||
src/controller/i2pd_daemon_controller.cpp \
|
|
||||||
src/MutexWrapperLock.cpp \
|
|
||||||
src/mainwindow.cpp \
|
src/mainwindow.cpp \
|
||||||
src/ClientTunnelPane.cpp \
|
src/ClientTunnelPane.cpp \
|
||||||
src/MainWindowItems.cpp \
|
src/MainWindowItems.cpp \
|
||||||
@ -67,10 +64,7 @@ SOURCES += \
|
|||||||
src/I2pdQtUtil.cpp
|
src/I2pdQtUtil.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
src/ConcurrentHolder.h \
|
src/DaemonQT.h \
|
||||||
src/launcher/i2pd_qt_launcher.h \
|
|
||||||
src/controller/i2pd_daemon_controller.h \
|
|
||||||
src/MutexWrapperLock.h \
|
|
||||||
src/mainwindow.h \
|
src/mainwindow.h \
|
||||||
src/ClientTunnelPane.h \
|
src/ClientTunnelPane.h \
|
||||||
src/MainWindowItems.h \
|
src/MainWindowItems.h \
|
||||||
|
@ -1,33 +0,0 @@
|
|||||||
#ifndef ConcurrentHolder_H
|
|
||||||
#define ConcurrentHolder_H
|
|
||||||
|
|
||||||
#include <QRecursiveMutex>
|
|
||||||
#include "MutexWrapperLock.h"
|
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
template <class HeldDataType>
|
|
||||||
class ConcurrentHolder
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
ConcurrentHolder(HeldDataType _data) {
|
|
||||||
data = _data;
|
|
||||||
mutex = new QRecursiveMutex();
|
|
||||||
assert(mutex!=nullptr);
|
|
||||||
}
|
|
||||||
~ConcurrentHolder() {
|
|
||||||
assert(mutex!=nullptr);
|
|
||||||
delete mutex;
|
|
||||||
}
|
|
||||||
QRecursiveMutex* getMutex() {
|
|
||||||
assert(mutex!=nullptr);
|
|
||||||
return mutex;
|
|
||||||
}
|
|
||||||
HeldDataType& getData() {
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
private:
|
|
||||||
HeldDataType data;
|
|
||||||
QRecursiveMutex* mutex;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // ConcurrentHolder_H
|
|
@ -1,6 +1,6 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "controller/i2pd_daemon_controller.h"
|
#include "DaemonQT.h"
|
||||||
#include "Daemon.h"
|
#include "Daemon.h"
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
|
|
||||||
@ -11,8 +11,12 @@
|
|||||||
#include <QMutexLocker>
|
#include <QMutexLocker>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
|
|
||||||
namespace i2p {
|
//#define DEBUG_WITH_DEFAULT_LOGGING (1)
|
||||||
namespace qt {
|
|
||||||
|
namespace i2p
|
||||||
|
{
|
||||||
|
namespace qt
|
||||||
|
{
|
||||||
Worker::Worker (DaemonQTImpl& daemon):
|
Worker::Worker (DaemonQTImpl& daemon):
|
||||||
m_Daemon (daemon)
|
m_Daemon (daemon)
|
||||||
{
|
{
|
||||||
@ -142,6 +146,50 @@ namespace qt {
|
|||||||
m_RunningChangedCallback();
|
m_RunningChangedCallback();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int RunQT (int argc, char* argv[])
|
||||||
|
{
|
||||||
|
QApplication app(argc, argv);
|
||||||
|
int result;
|
||||||
|
|
||||||
|
{
|
||||||
|
std::shared_ptr<std::iostream> logstreamptr=
|
||||||
|
#ifdef DEBUG_WITH_DEFAULT_LOGGING
|
||||||
|
nullptr
|
||||||
|
#else
|
||||||
|
std::make_shared<std::stringstream>()
|
||||||
|
#endif
|
||||||
|
;
|
||||||
|
//TODO move daemon init deinit to a bg thread
|
||||||
|
DaemonQTImpl daemon;
|
||||||
|
if(logstreamptr) (*logstreamptr) << "Initialising the daemon..." << std::endl;
|
||||||
|
bool daemonInitSuccess = daemon.init(argc, argv, logstreamptr);
|
||||||
|
if(!daemonInitSuccess)
|
||||||
|
{
|
||||||
|
QMessageBox::critical(0, "Error", "Daemon init failed");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
LogPrint(eLogDebug, "Initialised, creating the main window...");
|
||||||
|
MainWindow w(logstreamptr);
|
||||||
|
LogPrint(eLogDebug, "Before main window.show()...");
|
||||||
|
w.show ();
|
||||||
|
|
||||||
|
{
|
||||||
|
i2p::qt::Controller daemonQtController(daemon);
|
||||||
|
w.setI2PController(&daemonQtController);
|
||||||
|
LogPrint(eLogDebug, "Starting the daemon...");
|
||||||
|
emit daemonQtController.startDaemon();
|
||||||
|
//daemon.start ();
|
||||||
|
LogPrint(eLogDebug, "Starting GUI event loop...");
|
||||||
|
result = app.exec();
|
||||||
|
//daemon.stop ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//QMessageBox::information(&w, "Debug", "demon stopped");
|
||||||
|
LogPrint(eLogDebug, "Exiting the application");
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,5 +1,5 @@
|
|||||||
#ifndef I2PD_DAEMON_CONTROLLER_H
|
#ifndef DAEMONQT_H
|
||||||
#define I2PD_DAEMON_CONTROLLER_H
|
#define DAEMONQT_H
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
@ -85,4 +85,4 @@ namespace qt
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // I2PD_DAEMON_CONTROLLER_H
|
#endif // DAEMONQT_H
|
@ -51,11 +51,6 @@ bool DelayedSaveManagerImpl::appExiting() {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DelayedSaveManagerImpl::saveNow() {
|
|
||||||
assert(isSaverValid());
|
|
||||||
saver->save(isReloadAfterSave(), FocusEnum::noFocus);
|
|
||||||
}
|
|
||||||
|
|
||||||
DelayedSaveThread::DelayedSaveThread(DelayedSaveManagerImpl* delayedSaveManagerImpl_):
|
DelayedSaveThread::DelayedSaveThread(DelayedSaveManagerImpl* delayedSaveManagerImpl_):
|
||||||
delayedSaveManagerImpl(delayedSaveManagerImpl_),
|
delayedSaveManagerImpl(delayedSaveManagerImpl_),
|
||||||
mutex(new QMutex()),
|
mutex(new QMutex()),
|
||||||
|
@ -53,7 +53,6 @@ public:
|
|||||||
virtual void setSaver(Saver* saver);
|
virtual void setSaver(Saver* saver);
|
||||||
virtual void start();
|
virtual void start();
|
||||||
virtual void delayedSave(bool reloadAfterSave, DATA_SERIAL_TYPE dataSerial, FocusEnum focusOn, std::string tunnelNameToFocus, QWidget* widgetToFocus);
|
virtual void delayedSave(bool reloadAfterSave, DATA_SERIAL_TYPE dataSerial, FocusEnum focusOn, std::string tunnelNameToFocus, QWidget* widgetToFocus);
|
||||||
void saveNow();
|
|
||||||
virtual bool appExiting();
|
virtual bool appExiting();
|
||||||
|
|
||||||
typedef DelayedSaveThread::TIMESTAMP_TYPE TIMESTAMP_TYPE;
|
typedef DelayedSaveThread::TIMESTAMP_TYPE TIMESTAMP_TYPE;
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
#include "MutexWrapperLock.h"
|
|
||||||
|
|
||||||
MutexWrapperLock::MutexWrapperLock(QRecursiveMutex* _mutex) {
|
|
||||||
mutex = _mutex;
|
|
||||||
_mutex->lock();
|
|
||||||
}
|
|
||||||
|
|
||||||
MutexWrapperLock::~MutexWrapperLock() {
|
|
||||||
mutex->unlock();
|
|
||||||
}
|
|
@ -1,15 +0,0 @@
|
|||||||
#ifndef MUTEXWRAPPERLOCK_H
|
|
||||||
#define MUTEXWRAPPERLOCK_H
|
|
||||||
|
|
||||||
#include <QRecursiveMutex>
|
|
||||||
|
|
||||||
class MutexWrapperLock
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
MutexWrapperLock(QRecursiveMutex* _mutex);
|
|
||||||
~MutexWrapperLock();
|
|
||||||
private:
|
|
||||||
QRecursiveMutex* mutex;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // MUTEXWRAPPERLOCK_H
|
|
@ -9,8 +9,8 @@
|
|||||||
|
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
|
|
||||||
SaverImpl::SaverImpl(MainWindow *mainWindowPtr_) :
|
SaverImpl::SaverImpl(MainWindow *mainWindowPtr_, QList<MainWindowItem*>* configItems_, std::map<std::string,TunnelConfig*>* tunnelConfigs_) :
|
||||||
confpath(), tunconfpath(), mainWindowPtr(mainWindowPtr_)
|
configItems(configItems_), tunnelConfigs(tunnelConfigs_), confpath(), tunconfpath(), mainWindowPtr(mainWindowPtr_)
|
||||||
{
|
{
|
||||||
QObject::connect(this, SIGNAL(showPreventedSaveTunnelsConfMessage()), mainWindowPtr, SLOT(showTunnelsPagePreventedMessage()));
|
QObject::connect(this, SIGNAL(showPreventedSaveTunnelsConfMessage()), mainWindowPtr, SLOT(showTunnelsPagePreventedMessage()));
|
||||||
}
|
}
|
||||||
@ -18,13 +18,10 @@ SaverImpl::SaverImpl(MainWindow *mainWindowPtr_) :
|
|||||||
SaverImpl::~SaverImpl() {}
|
SaverImpl::~SaverImpl() {}
|
||||||
|
|
||||||
bool SaverImpl::save(bool reloadAfterSave, const FocusEnum focusOn, const std::string& tunnelNameToFocus, QWidget* widgetToFocus) {
|
bool SaverImpl::save(bool reloadAfterSave, const FocusEnum focusOn, const std::string& tunnelNameToFocus, QWidget* widgetToFocus) {
|
||||||
MutexWrapperLock lock(mainWindowPtr->volatileDataHolder->getMutex());
|
|
||||||
MainWindow::VolatileData* vdata = mainWindowPtr->volatileDataHolder->getData();
|
|
||||||
|
|
||||||
//save main config
|
//save main config
|
||||||
{
|
{
|
||||||
std::stringstream out;
|
std::stringstream out;
|
||||||
for(QList<MainWindowItem*>::iterator it = vdata->configItems.begin(); it!= vdata->configItems.end(); ++it) {
|
for(QList<MainWindowItem*>::iterator it = configItems->begin(); it!= configItems->end(); ++it) {
|
||||||
MainWindowItem* item = *it;
|
MainWindowItem* item = *it;
|
||||||
item->saveToStringStream(out);
|
item->saveToStringStream(out);
|
||||||
}
|
}
|
||||||
@ -47,9 +44,9 @@ bool SaverImpl::save(bool reloadAfterSave, const FocusEnum focusOn, const std::s
|
|||||||
}else{
|
}else{
|
||||||
std::stringstream out;
|
std::stringstream out;
|
||||||
|
|
||||||
for (const auto& it : vdata->tunnelConfigs) {
|
for (std::map<std::string,TunnelConfig*>::iterator it=tunnelConfigs->begin(); it!=tunnelConfigs->end(); ++it) {
|
||||||
//const std::string& name = it->first;
|
//const std::string& name = it->first;
|
||||||
TunnelConfig* tunconf = it.second;
|
TunnelConfig* tunconf = it->second;
|
||||||
tunconf->saveHeaderToStringStream(out);
|
tunconf->saveHeaderToStringStream(out);
|
||||||
tunconf->saveToStringStream(out);
|
tunconf->saveToStringStream(out);
|
||||||
tunconf->saveI2CPParametersToStringStream(out);
|
tunconf->saveI2CPParametersToStringStream(out);
|
||||||
|
@ -16,12 +16,14 @@ class TunnelConfig;
|
|||||||
|
|
||||||
class SaverImpl : public Saver {
|
class SaverImpl : public Saver {
|
||||||
public:
|
public:
|
||||||
SaverImpl(MainWindow *mainWindowPtr_);
|
SaverImpl(MainWindow *mainWindowPtr_, QList<MainWindowItem*>* configItems_, 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;
|
||||||
|
std::map<std::string,TunnelConfig*>* tunnelConfigs;
|
||||||
QString confpath;
|
QString confpath;
|
||||||
QString tunconfpath;
|
QString tunconfpath;
|
||||||
MainWindow* mainWindowPtr;
|
MainWindow* mainWindowPtr;
|
||||||
|
@ -81,15 +81,13 @@ class TunnelConfig {
|
|||||||
*/
|
*/
|
||||||
QString type;
|
QString type;
|
||||||
std::string name;
|
std::string name;
|
||||||
int _tunnelId;
|
|
||||||
TunnelPane* tunnelPane;
|
TunnelPane* tunnelPane;
|
||||||
int cryptoType;
|
int cryptoType;
|
||||||
public:
|
public:
|
||||||
TunnelConfig(int tunnelId, std::string name_, QString& type_, I2CPParameters& i2cpParameters_, int cryptoType_):
|
TunnelConfig(std::string name_, QString& type_, I2CPParameters& i2cpParameters_, int cryptoType_):
|
||||||
type(type_), name(name_), _tunnelId(tunnelId), cryptoType(cryptoType_), i2cpParameters(i2cpParameters_) {}
|
type(type_), name(name_), cryptoType(cryptoType_), i2cpParameters(i2cpParameters_) {}
|
||||||
virtual ~TunnelConfig(){}
|
virtual ~TunnelConfig(){}
|
||||||
const QString& getType(){return type;}
|
const QString& getType(){return type;}
|
||||||
int get_TunnelId(){return _tunnelId;}
|
|
||||||
const std::string& getName(){return name;}
|
const std::string& getName(){return name;}
|
||||||
int getcryptoType(){return cryptoType;}
|
int getcryptoType(){return cryptoType;}
|
||||||
void setType(const QString& type_){type=type_;}
|
void setType(const QString& type_){type=type_;}
|
||||||
@ -137,14 +135,14 @@ class ClientTunnelConfig : public TunnelConfig {
|
|||||||
int destinationPort;
|
int destinationPort;
|
||||||
i2p::data::SigningKeyType sigType;
|
i2p::data::SigningKeyType sigType;
|
||||||
public:
|
public:
|
||||||
ClientTunnelConfig(int tunnelId, std::string name_, QString type_, I2CPParameters& i2cpParameters_,
|
ClientTunnelConfig(std::string name_, QString type_, I2CPParameters& i2cpParameters_,
|
||||||
std::string dest_,
|
std::string dest_,
|
||||||
int port_,
|
int port_,
|
||||||
std::string keys_,
|
std::string keys_,
|
||||||
std::string address_,
|
std::string address_,
|
||||||
int destinationPort_,
|
int destinationPort_,
|
||||||
i2p::data::SigningKeyType sigType_,
|
i2p::data::SigningKeyType sigType_,
|
||||||
int cryptoType_): TunnelConfig(tunnelId, name_, type_, i2cpParameters_, cryptoType_),
|
int cryptoType_): TunnelConfig(name_, type_, i2cpParameters_, cryptoType_),
|
||||||
dest(dest_),
|
dest(dest_),
|
||||||
port(port_),
|
port(port_),
|
||||||
keys(keys_),
|
keys(keys_),
|
||||||
@ -207,7 +205,7 @@ class ServerTunnelConfig : public TunnelConfig {
|
|||||||
std::string address;
|
std::string address;
|
||||||
bool isUniqueLocal;
|
bool isUniqueLocal;
|
||||||
public:
|
public:
|
||||||
ServerTunnelConfig(int tunnelId, std::string name_, QString type_, I2CPParameters& i2cpParameters_,
|
ServerTunnelConfig(std::string name_, QString type_, I2CPParameters& i2cpParameters_,
|
||||||
std::string host_,
|
std::string host_,
|
||||||
int port_,
|
int port_,
|
||||||
std::string keys_,
|
std::string keys_,
|
||||||
@ -219,7 +217,7 @@ public:
|
|||||||
i2p::data::SigningKeyType sigType_,
|
i2p::data::SigningKeyType sigType_,
|
||||||
std::string address_,
|
std::string address_,
|
||||||
bool isUniqueLocal_,
|
bool isUniqueLocal_,
|
||||||
int cryptoType_): TunnelConfig(tunnelId, name_, type_, i2cpParameters_, cryptoType_),
|
int cryptoType_): TunnelConfig(name_, type_, i2cpParameters_, cryptoType_),
|
||||||
host(host_),
|
host(host_),
|
||||||
port(port_),
|
port(port_),
|
||||||
keys(keys_),
|
keys(keys_),
|
||||||
|
@ -1,65 +0,0 @@
|
|||||||
#include <memory>
|
|
||||||
|
|
||||||
#include "launcher/i2pd_qt_launcher.h"
|
|
||||||
#include "controller/i2pd_daemon_controller.h"
|
|
||||||
#include "Daemon.h"
|
|
||||||
#include "mainwindow.h"
|
|
||||||
|
|
||||||
#include "Log.h"
|
|
||||||
|
|
||||||
#include <QMessageBox>
|
|
||||||
#include <QApplication>
|
|
||||||
#include <QMutexLocker>
|
|
||||||
#include <QThread>
|
|
||||||
|
|
||||||
//#define DEBUG_WITH_DEFAULT_LOGGING (1)
|
|
||||||
|
|
||||||
namespace i2p {
|
|
||||||
namespace qt {
|
|
||||||
|
|
||||||
//TODO rework for clean MVC
|
|
||||||
int RunQT (int argc, char* argv[]) {
|
|
||||||
|
|
||||||
QApplication app(argc, argv);
|
|
||||||
|
|
||||||
int result;
|
|
||||||
|
|
||||||
{
|
|
||||||
std::shared_ptr<std::iostream> logstreamptr =
|
|
||||||
#ifdef DEBUG_WITH_DEFAULT_LOGGING
|
|
||||||
nullptr
|
|
||||||
#else
|
|
||||||
std::make_shared<std::stringstream>()
|
|
||||||
#endif
|
|
||||||
;
|
|
||||||
//TODO move daemon init deinit to a bg thread
|
|
||||||
DaemonQTImpl daemon;
|
|
||||||
if (logstreamptr) (*logstreamptr) << "Initialising the daemon..." << std::endl;
|
|
||||||
bool daemonInitSuccess = daemon.init(argc, argv, logstreamptr);
|
|
||||||
if (!daemonInitSuccess) {
|
|
||||||
QMessageBox::critical(0, "Error", "Daemon init failed");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
LogPrint(eLogDebug, "Initialised, creating the main window...");
|
|
||||||
MainWindow w(logstreamptr);
|
|
||||||
LogPrint(eLogDebug, "Before main window.show()...");
|
|
||||||
w.show ();
|
|
||||||
|
|
||||||
{
|
|
||||||
i2p::qt::Controller daemonQtController(daemon);
|
|
||||||
w.setI2PController(&daemonQtController);
|
|
||||||
LogPrint(eLogDebug, "Starting the daemon...");
|
|
||||||
emit daemonQtController.startDaemon();
|
|
||||||
//daemon.start ();
|
|
||||||
LogPrint(eLogDebug, "Starting GUI event loop...");
|
|
||||||
result = app.exec();
|
|
||||||
//daemon.stop ();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//QMessageBox::information(&w, "Debug", "demon stopped");
|
|
||||||
LogPrint(eLogDebug, "Exiting the application");
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
#ifndef I2PD_QT_LAUNCHER_H
|
|
||||||
#define I2PD_QT_LAUNCHER_H
|
|
||||||
|
|
||||||
namespace i2p {
|
|
||||||
namespace qt {
|
|
||||||
int RunQT (int argc, char* argv[]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // I2PD_QT_LAUNCHER_H
|
|
@ -33,8 +33,7 @@
|
|||||||
# include <QtDebug>
|
# include <QtDebug>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "controller/i2pd_daemon_controller.h"
|
#include "DaemonQT.h"
|
||||||
|
|
||||||
#include "SignatureTypeComboboxFactory.h"
|
#include "SignatureTypeComboboxFactory.h"
|
||||||
|
|
||||||
#include "logviewermanager.h"
|
#include "logviewermanager.h"
|
||||||
@ -64,24 +63,22 @@ MainWindow::MainWindow(std::shared_ptr<std::iostream> logStream_, QWidget *paren
|
|||||||
,routerCommandsParent(new QWidget(this))
|
,routerCommandsParent(new QWidget(this))
|
||||||
,widgetlocks()
|
,widgetlocks()
|
||||||
,i2pController(nullptr)
|
,i2pController(nullptr)
|
||||||
|
,configItems()
|
||||||
,datadir()
|
,datadir()
|
||||||
,confpath()
|
,confpath()
|
||||||
,tunconfpath()
|
,tunconfpath()
|
||||||
,ignoreUpdatesOnAppendForms(false)
|
,tunnelConfigs()
|
||||||
,volatileDataHolder(new ConcurrentHolder<VolatileData*>(new VolatileData()))
|
|
||||||
,tunnelsPageUpdateListener(this)
|
,tunnelsPageUpdateListener(this)
|
||||||
,preventSaveTunnelsBool(false)
|
,preventSaveTunnelsBool(false)
|
||||||
,saverPtr(nullptr)
|
,saverPtr(
|
||||||
|
new SaverImpl(this,
|
||||||
|
&configItems,
|
||||||
|
&tunnelConfigs))
|
||||||
|
|
||||||
{
|
{
|
||||||
assert(delayedSaveManagerPtr!=nullptr);
|
assert(delayedSaveManagerPtr!=nullptr);
|
||||||
assert(volatileDataHolder!=nullptr);
|
|
||||||
assert(volatileDataHolder->getData()!=nullptr);
|
|
||||||
saverPtr=new SaverImpl(this);
|
|
||||||
assert(saverPtr!=nullptr);
|
assert(saverPtr!=nullptr);
|
||||||
|
|
||||||
MutexWrapperLock lock(volatileDataHolder->getMutex());
|
|
||||||
VolatileData* vdata = volatileDataHolder->getData();
|
|
||||||
|
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
statusButtonsUI->setupUi(ui->statusButtonsPane);
|
statusButtonsUI->setupUi(ui->statusButtonsPane);
|
||||||
routerCommandsUI->setupUi(routerCommandsParent);
|
routerCommandsUI->setupUi(routerCommandsParent);
|
||||||
@ -211,8 +208,8 @@ MainWindow::MainWindow(std::shared_ptr<std::iostream> logStream_, QWidget *paren
|
|||||||
initFolderChooser( OPTION("","datadir",[]{return "";}), uiSettings->dataFolderLineEdit, uiSettings->dataFolderBrowsePushButton);
|
initFolderChooser( OPTION("","datadir",[]{return "";}), uiSettings->dataFolderLineEdit, uiSettings->dataFolderBrowsePushButton);
|
||||||
initIPAddressBox( OPTION("","host",[]{return "";}), uiSettings->routerExternalHostLineEdit, tr("Router external address -> Host"));
|
initIPAddressBox( OPTION("","host",[]{return "";}), uiSettings->routerExternalHostLineEdit, tr("Router external address -> Host"));
|
||||||
initTCPPortBox( OPTION("","port",[]{return "";}), uiSettings->routerExternalPortLineEdit, tr("Router external address -> Port"));
|
initTCPPortBox( OPTION("","port",[]{return "";}), uiSettings->routerExternalPortLineEdit, tr("Router external address -> Port"));
|
||||||
daemonOption=initNonGUIOption( OPTION("","daemon",[]{return "";}),type_bool);
|
daemonOption=initNonGUIOption( OPTION("","daemon",[]{return "";}));
|
||||||
serviceOption=initNonGUIOption( OPTION("","service",[]{return "";}),type_bool);
|
serviceOption=initNonGUIOption( OPTION("","service",[]{return "";}));
|
||||||
initStringBox( OPTION("","ifname4",[]{return "";}), uiSettings->ifname4LineEdit);//Network interface to bind to for IPv4
|
initStringBox( OPTION("","ifname4",[]{return "";}), uiSettings->ifname4LineEdit);//Network interface to bind to for IPv4
|
||||||
initStringBox( OPTION("","ifname6",[]{return "";}), uiSettings->ifname6LineEdit);//Network interface to bind to for IPv6
|
initStringBox( OPTION("","ifname6",[]{return "";}), uiSettings->ifname6LineEdit);//Network interface to bind to for IPv6
|
||||||
initCheckBox( OPTION("","nat",[]{return "true";}), uiSettings->natCheckBox);//If true, assume we are behind NAT. true by default
|
initCheckBox( OPTION("","nat",[]{return "true";}), uiSettings->natCheckBox);//If true, assume we are behind NAT. true by default
|
||||||
@ -391,7 +388,7 @@ MainWindow::MainWindow(std::shared_ptr<std::iostream> logStream_, QWidget *paren
|
|||||||
uiSettings->configFileLineEdit->setText(confpath);
|
uiSettings->configFileLineEdit->setText(confpath);
|
||||||
uiSettings->tunnelsConfigFileLineEdit->setText(tunconfpath);
|
uiSettings->tunnelsConfigFileLineEdit->setText(tunconfpath);
|
||||||
|
|
||||||
for(QList<MainWindowItem*>::iterator it = vdata->configItems.begin(); it!= vdata->configItems.end(); ++it) {
|
for(QList<MainWindowItem*>::iterator it = configItems.begin(); it!= configItems.end(); ++it) {
|
||||||
MainWindowItem* item = *it;
|
MainWindowItem* item = *it;
|
||||||
item->installListeners(this);
|
item->installListeners(this);
|
||||||
}
|
}
|
||||||
@ -604,7 +601,7 @@ void MainWindow::iconActivated(QSystemTrayIcon::ActivationReason reason) {
|
|||||||
setVisible(!isVisible());
|
setVisible(!isVisible());
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
qDebug() << "MainWindow::iconActivated(): unknown reason: " << reason << Qt::endl;
|
qDebug() << "MainWindow::iconActivated(): unknown reason: " << reason << endl;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -667,13 +664,11 @@ MainWindow::~MainWindow()
|
|||||||
delete statusPageUpdateTimer;
|
delete statusPageUpdateTimer;
|
||||||
delete delayedSaveManagerPtr;
|
delete delayedSaveManagerPtr;
|
||||||
delete saverPtr;
|
delete saverPtr;
|
||||||
MutexWrapperLock lock(volatileDataHolder->getMutex());
|
for(QList<MainWindowItem*>::iterator it = configItems.begin(); it!= configItems.end(); ++it) {
|
||||||
VolatileData* vdata = volatileDataHolder->getData();
|
|
||||||
for(QList<MainWindowItem*>::iterator it = vdata->configItems.begin(); it!= vdata->configItems.end(); ++it) {
|
|
||||||
MainWindowItem* item = *it;
|
MainWindowItem* item = *it;
|
||||||
item->deleteLater();
|
item->deleteLater();
|
||||||
}
|
}
|
||||||
vdata->configItems.clear();
|
configItems.clear();
|
||||||
//QMessageBox::information(0, "Debug", "mw destructor 1");
|
//QMessageBox::information(0, "Debug", "mw destructor 1");
|
||||||
//delete ui;
|
//delete ui;
|
||||||
//QMessageBox::information(0, "Debug", "mw destructor 2");
|
//QMessageBox::information(0, "Debug", "mw destructor 2");
|
||||||
@ -683,82 +678,53 @@ FileChooserItem* MainWindow::initFileChooser(ConfigOption option, QLineEdit* fil
|
|||||||
FileChooserItem* retVal;
|
FileChooserItem* retVal;
|
||||||
retVal=new FileChooserItem(option, fileNameLineEdit, fileBrowsePushButton, this, requireExistingFile, readOnly);
|
retVal=new FileChooserItem(option, fileNameLineEdit, fileBrowsePushButton, this, requireExistingFile, readOnly);
|
||||||
MainWindowItem* super=retVal;
|
MainWindowItem* super=retVal;
|
||||||
MutexWrapperLock lock(volatileDataHolder->getMutex());
|
configItems.append(super);
|
||||||
VolatileData* vdata = volatileDataHolder->getData();
|
|
||||||
vdata->configItems.append(super);
|
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
void MainWindow::initFolderChooser(ConfigOption option, QLineEdit* folderLineEdit, QPushButton* folderBrowsePushButton){
|
void MainWindow::initFolderChooser(ConfigOption option, QLineEdit* folderLineEdit, QPushButton* folderBrowsePushButton){
|
||||||
MutexWrapperLock lock(volatileDataHolder->getMutex());
|
configItems.append(new FolderChooserItem(option, folderLineEdit, folderBrowsePushButton, this, true));
|
||||||
VolatileData* vdata = volatileDataHolder->getData();
|
|
||||||
vdata->configItems.append(new FolderChooserItem(option, folderLineEdit, folderBrowsePushButton, this, true));
|
|
||||||
}
|
}
|
||||||
/*void MainWindow::initCombobox(ConfigOption option, QComboBox* comboBox){
|
/*void MainWindow::initCombobox(ConfigOption option, QComboBox* comboBox){
|
||||||
configItems.append(new ComboBoxItem(option, comboBox));
|
configItems.append(new ComboBoxItem(option, comboBox));
|
||||||
QObject::connect(comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(saveAllConfigs()));
|
QObject::connect(comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(saveAllConfigs()));
|
||||||
}*/
|
}*/
|
||||||
void MainWindow::initLogDestinationCombobox(ConfigOption option, QComboBox* comboBox){
|
void MainWindow::initLogDestinationCombobox(ConfigOption option, QComboBox* comboBox){
|
||||||
MutexWrapperLock lock(volatileDataHolder->getMutex());
|
configItems.append(new LogDestinationComboBoxItem(option, comboBox));
|
||||||
VolatileData* vdata = volatileDataHolder->getData();
|
|
||||||
vdata->configItems.append(new LogDestinationComboBoxItem(option, comboBox));
|
|
||||||
}
|
}
|
||||||
void MainWindow::initLogLevelCombobox(ConfigOption option, QComboBox* comboBox){
|
void MainWindow::initLogLevelCombobox(ConfigOption option, QComboBox* comboBox){
|
||||||
MutexWrapperLock lock(volatileDataHolder->getMutex());
|
configItems.append(new LogLevelComboBoxItem(option, comboBox));
|
||||||
VolatileData* vdata = volatileDataHolder->getData();
|
|
||||||
vdata->configItems.append(new LogLevelComboBoxItem(option, comboBox));
|
|
||||||
}
|
}
|
||||||
void MainWindow::initSignatureTypeCombobox(ConfigOption option, QComboBox* comboBox){
|
void MainWindow::initSignatureTypeCombobox(ConfigOption option, QComboBox* comboBox){
|
||||||
MutexWrapperLock lock(volatileDataHolder->getMutex());
|
configItems.append(new SignatureTypeComboBoxItem(option, comboBox));
|
||||||
VolatileData* vdata = volatileDataHolder->getData();
|
|
||||||
vdata->configItems.append(new SignatureTypeComboBoxItem(option, comboBox));
|
|
||||||
}
|
}
|
||||||
void MainWindow::initIPAddressBox(ConfigOption option, QLineEdit* addressLineEdit, QString fieldNameTranslated){
|
void MainWindow::initIPAddressBox(ConfigOption option, QLineEdit* addressLineEdit, QString fieldNameTranslated){
|
||||||
MutexWrapperLock lock(volatileDataHolder->getMutex());
|
configItems.append(new IPAddressStringItem(option, addressLineEdit, fieldNameTranslated, this));
|
||||||
VolatileData* vdata = volatileDataHolder->getData();
|
|
||||||
vdata->configItems.append(new IPAddressStringItem(option, addressLineEdit, fieldNameTranslated, this));
|
|
||||||
}
|
}
|
||||||
void MainWindow::initTCPPortBox(ConfigOption option, QLineEdit* portLineEdit, QString fieldNameTranslated){
|
void MainWindow::initTCPPortBox(ConfigOption option, QLineEdit* portLineEdit, QString fieldNameTranslated){
|
||||||
MutexWrapperLock lock(volatileDataHolder->getMutex());
|
configItems.append(new TCPPortStringItem(option, portLineEdit, fieldNameTranslated, this));
|
||||||
VolatileData* vdata = volatileDataHolder->getData();
|
|
||||||
vdata->configItems.append(new TCPPortStringItem(option, portLineEdit, fieldNameTranslated, this));
|
|
||||||
}
|
}
|
||||||
void MainWindow::initCheckBox(ConfigOption option, QCheckBox* checkBox) {
|
void MainWindow::initCheckBox(ConfigOption option, QCheckBox* checkBox) {
|
||||||
MutexWrapperLock lock(volatileDataHolder->getMutex());
|
configItems.append(new CheckBoxItem(option, checkBox));
|
||||||
VolatileData* vdata = volatileDataHolder->getData();
|
|
||||||
vdata->configItems.append(new CheckBoxItem(option, checkBox));
|
|
||||||
}
|
}
|
||||||
void MainWindow::initIntegerBox(ConfigOption option, QLineEdit* numberLineEdit, QString fieldNameTranslated){
|
void MainWindow::initIntegerBox(ConfigOption option, QLineEdit* numberLineEdit, QString fieldNameTranslated){
|
||||||
MutexWrapperLock lock(volatileDataHolder->getMutex());
|
configItems.append(new IntegerStringItem(option, numberLineEdit, fieldNameTranslated, this));
|
||||||
VolatileData* vdata = volatileDataHolder->getData();
|
|
||||||
vdata->configItems.append(new IntegerStringItem(option, numberLineEdit, fieldNameTranslated, this));
|
|
||||||
}
|
}
|
||||||
void MainWindow::initUInt32Box(ConfigOption option, QLineEdit* numberLineEdit, QString fieldNameTranslated){
|
void MainWindow::initUInt32Box(ConfigOption option, QLineEdit* numberLineEdit, QString fieldNameTranslated){
|
||||||
MutexWrapperLock lock(volatileDataHolder->getMutex());
|
configItems.append(new UInt32StringItem(option, numberLineEdit, fieldNameTranslated, this));
|
||||||
VolatileData* vdata = volatileDataHolder->getData();
|
|
||||||
vdata->configItems.append(new UInt32StringItem(option, numberLineEdit, fieldNameTranslated, this));
|
|
||||||
}
|
}
|
||||||
void MainWindow::initUInt16Box(ConfigOption option, QLineEdit* numberLineEdit, QString fieldNameTranslated){
|
void MainWindow::initUInt16Box(ConfigOption option, QLineEdit* numberLineEdit, QString fieldNameTranslated){
|
||||||
MutexWrapperLock lock(volatileDataHolder->getMutex());
|
configItems.append(new UInt16StringItem(option, numberLineEdit, fieldNameTranslated, this));
|
||||||
VolatileData* vdata = volatileDataHolder->getData();
|
|
||||||
vdata->configItems.append(new UInt16StringItem(option, numberLineEdit, fieldNameTranslated, this));
|
|
||||||
}
|
}
|
||||||
void MainWindow::initStringBox(ConfigOption option, QLineEdit* lineEdit){
|
void MainWindow::initStringBox(ConfigOption option, QLineEdit* lineEdit){
|
||||||
MutexWrapperLock lock(volatileDataHolder->getMutex());
|
configItems.append(new BaseStringItem(option, lineEdit, QString(), this));
|
||||||
VolatileData* vdata = volatileDataHolder->getData();
|
|
||||||
vdata->configItems.append(new BaseStringItem(option, lineEdit, QString(), this));
|
|
||||||
}
|
}
|
||||||
NonGUIOptionItem* MainWindow::initNonGUIOption(ConfigOption option, TypeEnum optionValueType) {
|
NonGUIOptionItem* MainWindow::initNonGUIOption(ConfigOption option) {
|
||||||
NonGUIOptionItem * retValue;
|
NonGUIOptionItem * retValue;
|
||||||
MutexWrapperLock lock(volatileDataHolder->getMutex());
|
configItems.append(retValue=new NonGUIOptionItem(option));
|
||||||
VolatileData* vdata = volatileDataHolder->getData();
|
|
||||||
vdata->configItems.append(retValue=new NonGUIOptionItem(option));
|
|
||||||
retValue->optionValueType=optionValueType;
|
|
||||||
return retValue;
|
return retValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::loadAllConfigs(SaverImpl* saverPtr){
|
void MainWindow::loadAllConfigs(SaverImpl* saverPtr){
|
||||||
MutexWrapperLock lock(volatileDataHolder->getMutex());
|
|
||||||
VolatileData* vdata = volatileDataHolder->getData();
|
|
||||||
|
|
||||||
//BORROWED FROM ??? //TODO move this code into single location
|
//BORROWED FROM ??? //TODO move this code into single location
|
||||||
std::string config; i2p::config::GetOption("conf", config);
|
std::string config; i2p::config::GetOption("conf", config);
|
||||||
@ -802,7 +768,7 @@ void MainWindow::loadAllConfigs(SaverImpl* saverPtr){
|
|||||||
saverPtr->setConfPath(this->confpath);
|
saverPtr->setConfPath(this->confpath);
|
||||||
saverPtr->setTunnelsConfPath(this->tunconfpath);
|
saverPtr->setTunnelsConfPath(this->tunconfpath);
|
||||||
|
|
||||||
for(QList<MainWindowItem*>::iterator it = vdata->configItems.begin(); it!= vdata->configItems.end(); ++it) {
|
for(QList<MainWindowItem*>::iterator it = configItems.begin(); it!= configItems.end(); ++it) {
|
||||||
MainWindowItem* item = *it;
|
MainWindowItem* item = *it;
|
||||||
item->loadFromConfigOption();
|
item->loadFromConfigOption();
|
||||||
}
|
}
|
||||||
@ -821,14 +787,12 @@ void MainWindow::DisableTunnelsPage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::layoutTunnels() {
|
void MainWindow::layoutTunnels() {
|
||||||
MutexWrapperLock lock(volatileDataHolder->getMutex());
|
|
||||||
VolatileData* vdata = volatileDataHolder->getData();
|
|
||||||
|
|
||||||
int height=0;
|
int height=0;
|
||||||
ui->tunnelsScrollAreaWidgetContents->setGeometry(0,0,0,0);
|
ui->tunnelsScrollAreaWidgetContents->setGeometry(0,0,0,0);
|
||||||
for(const auto& it : vdata->tunnelConfigs) {
|
for(std::map<std::string, TunnelConfig*>::iterator it = tunnelConfigs.begin(); it != tunnelConfigs.end(); ++it) {
|
||||||
//const std::string& name=it.first;
|
//const std::string& name=it->first;
|
||||||
TunnelConfig* tunconf = it.second;
|
TunnelConfig* tunconf = it->second;
|
||||||
TunnelPane * tunnelPane=tunconf->getTunnelPane();
|
TunnelPane * tunnelPane=tunconf->getTunnelPane();
|
||||||
if(!tunnelPane)continue;
|
if(!tunnelPane)continue;
|
||||||
int h=tunnelPane->height();
|
int h=tunnelPane->height();
|
||||||
@ -844,12 +808,9 @@ void MainWindow::layoutTunnels() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::deleteTunnelFromUI(std::string tunnelName, TunnelConfig* cnf) {
|
void MainWindow::deleteTunnelFromUI(std::string tunnelName, TunnelConfig* cnf) {
|
||||||
MutexWrapperLock lock(volatileDataHolder->getMutex());
|
|
||||||
VolatileData* vdata = volatileDataHolder->getData();
|
|
||||||
|
|
||||||
TunnelPane* tp = cnf->getTunnelPane();
|
TunnelPane* tp = cnf->getTunnelPane();
|
||||||
if(!tp)return;
|
if(!tp)return;
|
||||||
vdata->tunnelPanes.remove(tp);
|
tunnelPanes.remove(tp);
|
||||||
tp->deleteWidget();
|
tp->deleteWidget();
|
||||||
layoutTunnels();
|
layoutTunnels();
|
||||||
}
|
}
|
||||||
@ -863,10 +824,7 @@ bool MainWindow::saveAllConfigs(bool reloadAfterSave, FocusEnum focusOn, std::st
|
|||||||
daemonOption->optionValue=boost::any(false);
|
daemonOption->optionValue=boost::any(false);
|
||||||
serviceOption->optionValue=boost::any(false);
|
serviceOption->optionValue=boost::any(false);
|
||||||
|
|
||||||
MutexWrapperLock lock(volatileDataHolder->getMutex());
|
for(QList<MainWindowItem*>::iterator it = configItems.begin(); it!= configItems.end(); ++it) {
|
||||||
VolatileData* vdata = volatileDataHolder->getData();
|
|
||||||
|
|
||||||
for(QList<MainWindowItem*>::iterator it = vdata->configItems.begin(); it != vdata->configItems.end(); ++it) {
|
|
||||||
MainWindowItem* item = *it;
|
MainWindowItem* item = *it;
|
||||||
bool alreadyDisplayedIfWrong=false;
|
bool alreadyDisplayedIfWrong=false;
|
||||||
if(!item->isValid(alreadyDisplayedIfWrong)){
|
if(!item->isValid(alreadyDisplayedIfWrong)){
|
||||||
@ -925,39 +883,34 @@ void MainWindow::updated() {
|
|||||||
void MainWindowItem::installListeners(MainWindow *mainWindow) {}
|
void MainWindowItem::installListeners(MainWindow *mainWindow) {}
|
||||||
|
|
||||||
void MainWindow::appendTunnelForms(std::string tunnelNameToFocus) {
|
void MainWindow::appendTunnelForms(std::string tunnelNameToFocus) {
|
||||||
MutexWrapperLock lock(volatileDataHolder->getMutex());
|
|
||||||
VolatileData* vdata = volatileDataHolder->getData();
|
|
||||||
|
|
||||||
ignoreUpdatesOnAppendForms = true;
|
|
||||||
|
|
||||||
int height=0;
|
int height=0;
|
||||||
ui->tunnelsScrollAreaWidgetContents->setGeometry(0,0,0,0);
|
ui->tunnelsScrollAreaWidgetContents->setGeometry(0,0,0,0);
|
||||||
std::unordered_map<std::string, TunnelConfig*> tunnelConfigsCopy(vdata->tunnelConfigs);
|
for(std::map<std::string, TunnelConfig*>::iterator it = tunnelConfigs.begin(); it != tunnelConfigs.end(); ++it) {
|
||||||
for(const auto& it : tunnelConfigsCopy) {
|
const std::string& name=it->first;
|
||||||
const std::string& name=it.first;
|
TunnelConfig* tunconf = it->second;
|
||||||
ServerTunnelConfig* stc = it.second->asServerTunnelConfig();
|
ServerTunnelConfig* stc = tunconf->asServerTunnelConfig();
|
||||||
if(stc){
|
if(stc){
|
||||||
ServerTunnelPane * tunnelPane=new ServerTunnelPane(&tunnelsPageUpdateListener, stc, ui->wrongInputLabel, ui->wrongInputLabel, this);
|
ServerTunnelPane * tunnelPane=new ServerTunnelPane(&tunnelsPageUpdateListener, stc, ui->wrongInputLabel, ui->wrongInputLabel, this);
|
||||||
stc->setTunnelPane(tunnelPane);
|
tunconf->setTunnelPane(tunnelPane);
|
||||||
int h=tunnelPane->appendServerTunnelForm(stc, ui->tunnelsScrollAreaWidgetContents, vdata->tunnelPanes.size(), height);
|
int h=tunnelPane->appendServerTunnelForm(stc, ui->tunnelsScrollAreaWidgetContents, tunnelPanes.size(), height);
|
||||||
height+=h;
|
height+=h;
|
||||||
//qDebug() << "tun.height:" << height << "sz:" << tunnelPanes.size();
|
//qDebug() << "tun.height:" << height << "sz:" << tunnelPanes.size();
|
||||||
vdata->tunnelPanes.push_back(tunnelPane);
|
tunnelPanes.push_back(tunnelPane);
|
||||||
if(name.compare(tunnelNameToFocus)==0){
|
if(name==tunnelNameToFocus){
|
||||||
tunnelPane->getNameLineEdit()->setFocus();
|
tunnelPane->getNameLineEdit()->setFocus();
|
||||||
ui->tunnelsScrollArea->ensureWidgetVisible(tunnelPane->getNameLineEdit());
|
ui->tunnelsScrollArea->ensureWidgetVisible(tunnelPane->getNameLineEdit());
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ClientTunnelConfig* ctc = it.second->asClientTunnelConfig();
|
ClientTunnelConfig* ctc = tunconf->asClientTunnelConfig();
|
||||||
if(ctc){
|
if(ctc){
|
||||||
ClientTunnelPane * tunnelPane=new ClientTunnelPane(&tunnelsPageUpdateListener, ctc, ui->wrongInputLabel, ui->wrongInputLabel, this);
|
ClientTunnelPane * tunnelPane=new ClientTunnelPane(&tunnelsPageUpdateListener, ctc, ui->wrongInputLabel, ui->wrongInputLabel, this);
|
||||||
ctc->setTunnelPane(tunnelPane);
|
tunconf->setTunnelPane(tunnelPane);
|
||||||
int h=tunnelPane->appendClientTunnelForm(ctc, ui->tunnelsScrollAreaWidgetContents, vdata->tunnelPanes.size(), height);
|
int h=tunnelPane->appendClientTunnelForm(ctc, ui->tunnelsScrollAreaWidgetContents, tunnelPanes.size(), height);
|
||||||
height+=h;
|
height+=h;
|
||||||
//qDebug() << "tun.height:" << height << "sz:" << tunnelPanes.size();
|
//qDebug() << "tun.height:" << height << "sz:" << tunnelPanes.size();
|
||||||
vdata->tunnelPanes.push_back(tunnelPane);
|
tunnelPanes.push_back(tunnelPane);
|
||||||
if(name.compare(tunnelNameToFocus)==0){
|
if(name==tunnelNameToFocus){
|
||||||
tunnelPane->getNameLineEdit()->setFocus();
|
tunnelPane->getNameLineEdit()->setFocus();
|
||||||
ui->tunnelsScrollArea->ensureWidgetVisible(tunnelPane->getNameLineEdit());
|
ui->tunnelsScrollArea->ensureWidgetVisible(tunnelPane->getNameLineEdit());
|
||||||
}
|
}
|
||||||
@ -970,12 +923,9 @@ void MainWindow::appendTunnelForms(std::string tunnelNameToFocus) {
|
|||||||
QList<QWidget*> childWidgets = ui->tunnelsScrollAreaWidgetContents->findChildren<QWidget*>();
|
QList<QWidget*> childWidgets = ui->tunnelsScrollAreaWidgetContents->findChildren<QWidget*>();
|
||||||
foreach(QWidget* widget, childWidgets)
|
foreach(QWidget* widget, childWidgets)
|
||||||
widget->show();
|
widget->show();
|
||||||
ignoreUpdatesOnAppendForms = false;
|
|
||||||
}
|
}
|
||||||
void MainWindow::deleteTunnelForms() {
|
void MainWindow::deleteTunnelForms() {
|
||||||
MutexWrapperLock lock(volatileDataHolder->getMutex());
|
for(std::list<TunnelPane*>::iterator it = tunnelPanes.begin(); it != tunnelPanes.end(); ++it) {
|
||||||
VolatileData* vdata = volatileDataHolder->getData();
|
|
||||||
for(std::list<TunnelPane*>::iterator it = vdata->tunnelPanes.begin(); it != vdata->tunnelPanes.end(); ++it) {
|
|
||||||
TunnelPane* tp = *it;
|
TunnelPane* tp = *it;
|
||||||
ServerTunnelPane* stp = tp->asServerTunnelPane();
|
ServerTunnelPane* stp = tp->asServerTunnelPane();
|
||||||
if(stp){
|
if(stp){
|
||||||
@ -991,13 +941,11 @@ void MainWindow::deleteTunnelForms() {
|
|||||||
}
|
}
|
||||||
throw "unknown TunnelPane subtype";
|
throw "unknown TunnelPane subtype";
|
||||||
}
|
}
|
||||||
vdata->tunnelPanes.clear();
|
tunnelPanes.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MainWindow::applyTunnelsUiToConfigs() {
|
bool MainWindow::applyTunnelsUiToConfigs() {
|
||||||
MutexWrapperLock lock(volatileDataHolder->getMutex());
|
for(std::list<TunnelPane*>::iterator it = tunnelPanes.begin(); it != tunnelPanes.end(); ++it) {
|
||||||
VolatileData* vdata = volatileDataHolder->getData();
|
|
||||||
for(std::list<TunnelPane*>::iterator it = vdata->tunnelPanes.begin(); it != vdata->tunnelPanes.end(); ++it) {
|
|
||||||
TunnelPane* tp = *it;
|
TunnelPane* tp = *it;
|
||||||
if(!tp->applyDataFromUIToTunnelConfig())return false;
|
if(!tp->applyDataFromUIToTunnelConfig())return false;
|
||||||
}
|
}
|
||||||
@ -1009,32 +957,23 @@ void MainWindow::reloadTunnelsConfigAndUI_QString(QString tunnelNameToFocus) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::reloadTunnelsConfigAndUI(std::string tunnelNameToFocus, QWidget* widgetToFocus) {
|
void MainWindow::reloadTunnelsConfigAndUI(std::string tunnelNameToFocus, QWidget* widgetToFocus) {
|
||||||
MutexWrapperLock lock(volatileDataHolder->getMutex());
|
|
||||||
VolatileData* vdata = volatileDataHolder->getData();
|
|
||||||
deleteTunnelForms();
|
deleteTunnelForms();
|
||||||
const std::unordered_map<std::string, TunnelConfig*> tunnelConfigsCopy(vdata->tunnelConfigs);
|
for (std::map<std::string,TunnelConfig*>::iterator it=tunnelConfigs.begin(); it!=tunnelConfigs.end(); ++it) {
|
||||||
for (const auto& it : tunnelConfigsCopy) {
|
TunnelConfig* tunconf = it->second;
|
||||||
TunnelConfig* tunconf = it.second;
|
|
||||||
vdata->tunnelConfigs[tunconf->getName()]=nullptr;
|
|
||||||
vdata->tunnelConfigsById[tunconf->get_TunnelId()]=nullptr;
|
|
||||||
delete tunconf;
|
delete tunconf;
|
||||||
}
|
}
|
||||||
vdata->tunnelConfigs.clear();
|
tunnelConfigs.clear();
|
||||||
vdata->tunnelConfigsById.clear();
|
|
||||||
ReadTunnelsConfig();
|
ReadTunnelsConfig();
|
||||||
appendTunnelForms(tunnelNameToFocus);
|
appendTunnelForms(tunnelNameToFocus);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::TunnelsPageUpdateListenerMainWindowImpl::updated(std::string oldName, TunnelConfig* tunConf) {
|
void MainWindow::TunnelsPageUpdateListenerMainWindowImpl::updated(std::string oldName, TunnelConfig* tunConf) {
|
||||||
MutexWrapperLock lock(mainWindow->volatileDataHolder->getMutex());
|
if(oldName!=tunConf->getName()) {
|
||||||
VolatileData* vdata = mainWindow->volatileDataHolder->getData();
|
|
||||||
if(mainWindow->ignoreUpdatesOnAppendForms)return;
|
|
||||||
if(oldName.compare(tunConf->getName())!=0) {
|
|
||||||
//name has changed
|
//name has changed
|
||||||
auto it=vdata->tunnelConfigs.find(oldName);
|
std::map<std::string,TunnelConfig*>::const_iterator it=mainWindow->tunnelConfigs.find(oldName);
|
||||||
if(it!=vdata->tunnelConfigs.end())vdata->tunnelConfigs.erase(it);
|
if(it!=mainWindow->tunnelConfigs.end())mainWindow->tunnelConfigs.erase(it);
|
||||||
vdata->tunnelConfigs[tunConf->getName()]=tunConf;
|
mainWindow->tunnelConfigs[tunConf->getName()]=tunConf;
|
||||||
mainWindow->saveAllConfigs(false, FocusEnum::focusOnTunnelName, tunConf->getName());
|
mainWindow->saveAllConfigs(true, FocusEnum::focusOnTunnelName, tunConf->getName());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
mainWindow->saveAllConfigs(false, FocusEnum::noFocus);
|
mainWindow->saveAllConfigs(false, FocusEnum::noFocus);
|
||||||
@ -1213,18 +1152,3 @@ bool MainWindow::isPreventSaveTunnelsMode() {
|
|||||||
void MainWindow::showTunnelsPagePreventedMessage() {
|
void MainWindow::showTunnelsPagePreventedMessage() {
|
||||||
QMessageBox::critical(this,QObject::tr("Error"),QObject::tr("Not saving tunnels configuration due to previous errors with it."));
|
QMessageBox::critical(this,QObject::tr("Error"),QObject::tr("Not saving tunnels configuration due to previous errors with it."));
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::DeleteTunnelNamed(std::string name) {
|
|
||||||
MutexWrapperLock lock(volatileDataHolder->getMutex());
|
|
||||||
VolatileData* tunnels = volatileDataHolder->getData();
|
|
||||||
auto it=tunnels->tunnelConfigs.find(name);
|
|
||||||
if(it!=tunnels->tunnelConfigs.end()){
|
|
||||||
TunnelConfig* tc=it->second;
|
|
||||||
deleteTunnelFromUI(name, tc);
|
|
||||||
tunnels->tunnelConfigs.erase(it);
|
|
||||||
tunnels->tunnelConfigsById.erase(tc->get_TunnelId());
|
|
||||||
delete tc;
|
|
||||||
}
|
|
||||||
saveAllConfigs(true, FocusEnum::noFocus);
|
|
||||||
delayedSaveManagerPtr->saveNow();
|
|
||||||
}
|
|
||||||
|
152
src/mainwindow.h
152
src/mainwindow.h
@ -56,8 +56,7 @@
|
|||||||
|
|
||||||
#include "TunnelsPageUpdateListener.h"
|
#include "TunnelsPageUpdateListener.h"
|
||||||
|
|
||||||
#include "controller/i2pd_daemon_controller.h"
|
#include "DaemonQT.h"
|
||||||
|
|
||||||
#include "SignatureTypeComboboxFactory.h"
|
#include "SignatureTypeComboboxFactory.h"
|
||||||
#include "pagewithbackbutton.h"
|
#include "pagewithbackbutton.h"
|
||||||
|
|
||||||
@ -72,14 +71,11 @@
|
|||||||
|
|
||||||
#include "I2pdQtUtil.h"
|
#include "I2pdQtUtil.h"
|
||||||
|
|
||||||
#include "ConcurrentHolder.h"
|
|
||||||
#include "MutexWrapperLock.h"
|
|
||||||
|
|
||||||
class SaverImpl;
|
class SaverImpl;
|
||||||
|
|
||||||
class LogViewerManager;
|
class LogViewerManager;
|
||||||
|
|
||||||
/*template<typename ValueType>
|
template<typename ValueType>
|
||||||
bool isType(boost::any& a) {
|
bool isType(boost::any& a) {
|
||||||
return
|
return
|
||||||
#ifdef BOOST_AUX_ANY_TYPE_ID_NAME
|
#ifdef BOOST_AUX_ANY_TYPE_ID_NAME
|
||||||
@ -88,17 +84,7 @@ bool isType(boost::any& a) {
|
|||||||
a.type() == typeid(ValueType)
|
a.type() == typeid(ValueType)
|
||||||
#endif
|
#endif
|
||||||
;
|
;
|
||||||
}*/
|
}
|
||||||
|
|
||||||
enum TypeEnum {
|
|
||||||
type_unknown,
|
|
||||||
type_std_string,
|
|
||||||
type_bool,
|
|
||||||
type_uint16,
|
|
||||||
type_uint32,
|
|
||||||
type_int,
|
|
||||||
type_ushort
|
|
||||||
};
|
|
||||||
|
|
||||||
class ConfigOption {
|
class ConfigOption {
|
||||||
public:
|
public:
|
||||||
@ -131,7 +117,6 @@ public:
|
|||||||
QString& getRequirementToBeValid() { return requirementToBeValid; }
|
QString& getRequirementToBeValid() { return requirementToBeValid; }
|
||||||
ConfigOption& getConfigOption() { return option; }
|
ConfigOption& getConfigOption() { return option; }
|
||||||
boost::any optionValue;
|
boost::any optionValue;
|
||||||
TypeEnum optionValueType;
|
|
||||||
virtual ~MainWindowItem(){}
|
virtual ~MainWindowItem(){}
|
||||||
virtual void installListeners(MainWindow *mainWindow);
|
virtual void installListeners(MainWindow *mainWindow);
|
||||||
virtual void loadFromConfigOption(){
|
virtual void loadFromConfigOption(){
|
||||||
@ -141,43 +126,39 @@ public:
|
|||||||
//qDebug() << "loadFromConfigOption[" << optName.c_str() << "]";
|
//qDebug() << "loadFromConfigOption[" << optName.c_str() << "]";
|
||||||
boost::any programOption;
|
boost::any programOption;
|
||||||
i2p::config::GetOptionAsAny(optName, programOption);
|
i2p::config::GetOptionAsAny(optName, programOption);
|
||||||
if(programOption.empty()){
|
optionValue=programOption.empty()?boost::any(std::string(""))
|
||||||
optionValue=boost::any(std::string(""));
|
:boost::any_cast<boost::program_options::variable_value>(programOption).value();
|
||||||
optionValueType=type_std_string;
|
|
||||||
}else{
|
|
||||||
optionValue=boost::any_cast<boost::program_options::variable_value>(programOption).value();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
virtual void saveToStringStream(std::stringstream& out){
|
virtual void saveToStringStream(std::stringstream& out){
|
||||||
if(readOnly)return; //should readOnly items (conf=) error somewhere, instead of silently skipping save?
|
if(readOnly)return; //should readOnly items (conf=) error somewhere, instead of silently skipping save?
|
||||||
if(optionValueType==type_std_string) {
|
if(isType<std::string>(optionValue)) {
|
||||||
const std::string v = boost::any_cast<std::string>(optionValue);
|
std::string v = boost::any_cast<std::string>(optionValue);
|
||||||
if(v.empty())return;
|
if(v.empty())return;
|
||||||
}
|
}
|
||||||
if(optionValue.empty())return;
|
if(optionValue.empty())return;
|
||||||
//std::string rtti = optionValue.type().name();
|
std::string rtti = optionValue.type().name();
|
||||||
std::string optName="";
|
std::string optName="";
|
||||||
if(!option.section.isEmpty())optName=option.section.toStdString()+std::string(".");
|
if(!option.section.isEmpty())optName=option.section.toStdString()+std::string(".");
|
||||||
optName+=std::string(option.option.toStdString());
|
optName+=option.option.toStdString();
|
||||||
//qDebug() << "Writing option" << optName.c_str() << "of type" << rtti.c_str();
|
//qDebug() << "Writing option" << optName.c_str() << "of type" << rtti.c_str();
|
||||||
std::string sectionAsStdStr = std::string(option.section.toStdString());
|
std::string sectionAsStdStr = option.section.toStdString();
|
||||||
if(!option.section.isEmpty() &&
|
if(!option.section.isEmpty() &&
|
||||||
sectionAsStdStr!=programOptionsWriterCurrentSection) {
|
sectionAsStdStr!=programOptionsWriterCurrentSection) {
|
||||||
out << "[" << sectionAsStdStr << "]\n";
|
out << "[" << sectionAsStdStr << "]\n";
|
||||||
programOptionsWriterCurrentSection=sectionAsStdStr;
|
programOptionsWriterCurrentSection=sectionAsStdStr;
|
||||||
}
|
}
|
||||||
out << std::string(option.option.toStdString()) << "=";
|
out << option.option.toStdString() << "=";
|
||||||
if(type_std_string==optionValueType) {
|
if(isType<std::string>(optionValue)) {
|
||||||
out << boost::any_cast<const std::string>(optionValue);
|
out << boost::any_cast<std::string>(optionValue);
|
||||||
}else if(type_bool==optionValueType) {
|
}else if(isType<bool>(optionValue)) {
|
||||||
out << (boost::any_cast<bool>(optionValue) ? "true" : "false");
|
out << (boost::any_cast<bool>(optionValue) ? "true" : "false");
|
||||||
}else if(type_uint16==optionValueType) {
|
}else if(isType<uint16_t>(optionValue)) {
|
||||||
out << boost::any_cast<uint16_t>(optionValue);
|
out << boost::any_cast<uint16_t>(optionValue);
|
||||||
}else if(type_uint32==optionValueType) {
|
}else if(isType<uint32_t>(optionValue)) {
|
||||||
out << boost::any_cast<uint32_t>(optionValue);
|
out << boost::any_cast<uint32_t>(optionValue);
|
||||||
}else if(type_int==optionValueType) {
|
}else if(isType<int>(optionValue)) {
|
||||||
out << boost::any_cast<int>(optionValue);
|
out << boost::any_cast<int>(optionValue);
|
||||||
}else if(type_ushort==optionValueType) {
|
}else if(isType<unsigned short>(optionValue)) {
|
||||||
out << boost::any_cast<unsigned short>(optionValue);
|
out << boost::any_cast<unsigned short>(optionValue);
|
||||||
}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";
|
||||||
@ -213,11 +194,9 @@ public:
|
|||||||
|
|
||||||
virtual void saveToStringStream(std::stringstream& out){
|
virtual void saveToStringStream(std::stringstream& out){
|
||||||
optionValue=fromString(lineEdit->text());
|
optionValue=fromString(lineEdit->text());
|
||||||
optionValueType=getOptionValueType();
|
|
||||||
MainWindowItem::saveToStringStream(out);
|
MainWindowItem::saveToStringStream(out);
|
||||||
}
|
}
|
||||||
virtual bool isValid(bool & alreadyDisplayedIfWrong);
|
virtual bool isValid(bool & alreadyDisplayedIfWrong);
|
||||||
virtual TypeEnum getOptionValueType() {return type_std_string;}
|
|
||||||
};
|
};
|
||||||
class FileOrFolderChooserItem : public BaseStringItem {
|
class FileOrFolderChooserItem : public BaseStringItem {
|
||||||
protected:
|
protected:
|
||||||
@ -227,7 +206,6 @@ public:
|
|||||||
FileOrFolderChooserItem(ConfigOption option_, QLineEdit* lineEdit_, QPushButton* browsePushButton_, MainWindow* mw, bool requireExistingFile_, bool readOnly) :
|
FileOrFolderChooserItem(ConfigOption option_, QLineEdit* lineEdit_, QPushButton* browsePushButton_, MainWindow* mw, bool requireExistingFile_, bool readOnly) :
|
||||||
BaseStringItem(option_, lineEdit_, QString(), mw, readOnly), requireExistingFile(requireExistingFile_), browsePushButton(browsePushButton_) {}
|
BaseStringItem(option_, lineEdit_, QString(), mw, readOnly), requireExistingFile(requireExistingFile_), browsePushButton(browsePushButton_) {}
|
||||||
virtual ~FileOrFolderChooserItem(){}
|
virtual ~FileOrFolderChooserItem(){}
|
||||||
TypeEnum getOptionValueType() {return type_std_string;}
|
|
||||||
};
|
};
|
||||||
class FileChooserItem : public FileOrFolderChooserItem {
|
class FileChooserItem : public FileOrFolderChooserItem {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -266,16 +244,15 @@ public:
|
|||||||
virtual ~LogDestinationComboBoxItem(){}
|
virtual ~LogDestinationComboBoxItem(){}
|
||||||
virtual void loadFromConfigOption(){
|
virtual void loadFromConfigOption(){
|
||||||
MainWindowItem::loadFromConfigOption();
|
MainWindowItem::loadFromConfigOption();
|
||||||
comboBox->setCurrentText(QString(boost::any_cast<std::string>(optionValue).c_str()));
|
const char * ld = boost::any_cast<std::string>(optionValue).c_str();
|
||||||
|
comboBox->setCurrentText(QString(ld));
|
||||||
}
|
}
|
||||||
virtual void saveToStringStream(std::stringstream& out){
|
virtual void saveToStringStream(std::stringstream& out){
|
||||||
const std::string logDest = std::string(comboBox->currentText().toStdString());
|
std::string logDest = comboBox->currentText().toStdString();
|
||||||
optionValue=logDest;
|
optionValue=logDest;
|
||||||
optionValueType=type_std_string;
|
|
||||||
MainWindowItem::saveToStringStream(out);
|
MainWindowItem::saveToStringStream(out);
|
||||||
}
|
}
|
||||||
//virtual bool isValid(bool & alreadyDisplayedIfWrong) { return true; }
|
//virtual bool isValid(bool & alreadyDisplayedIfWrong) { return true; }
|
||||||
TypeEnum getOptionValueType() {return type_std_string;}
|
|
||||||
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
};
|
};
|
||||||
@ -285,14 +262,13 @@ public:
|
|||||||
virtual ~LogLevelComboBoxItem(){}
|
virtual ~LogLevelComboBoxItem(){}
|
||||||
virtual void loadFromConfigOption(){
|
virtual void loadFromConfigOption(){
|
||||||
MainWindowItem::loadFromConfigOption();
|
MainWindowItem::loadFromConfigOption();
|
||||||
comboBox->setCurrentText(QString(boost::any_cast<std::string>(optionValue).c_str()));
|
const char * ll = boost::any_cast<std::string>(optionValue).c_str();
|
||||||
|
comboBox->setCurrentText(QString(ll));
|
||||||
}
|
}
|
||||||
virtual void saveToStringStream(std::stringstream& out){
|
virtual void saveToStringStream(std::stringstream& out){
|
||||||
optionValue=comboBox->currentText().toStdString();
|
optionValue=comboBox->currentText().toStdString();
|
||||||
optionValueType=type_std_string;
|
|
||||||
MainWindowItem::saveToStringStream(out);
|
MainWindowItem::saveToStringStream(out);
|
||||||
}
|
}
|
||||||
TypeEnum getOptionValueType() {return type_std_string;}
|
|
||||||
//virtual bool isValid(bool & alreadyDisplayedIfWrong) { return true; }
|
//virtual bool isValid(bool & alreadyDisplayedIfWrong) { return true; }
|
||||||
};
|
};
|
||||||
class SignatureTypeComboBoxItem : public ComboBoxItem {
|
class SignatureTypeComboBoxItem : public ComboBoxItem {
|
||||||
@ -308,11 +284,9 @@ public:
|
|||||||
virtual void saveToStringStream(std::stringstream& out){
|
virtual void saveToStringStream(std::stringstream& out){
|
||||||
uint16_t selected = SignatureTypeComboBoxFactory::getSigType(comboBox->currentData());
|
uint16_t selected = SignatureTypeComboBoxFactory::getSigType(comboBox->currentData());
|
||||||
optionValue=(unsigned short)selected;
|
optionValue=(unsigned short)selected;
|
||||||
optionValueType=type_ushort;
|
|
||||||
MainWindowItem::saveToStringStream(out);
|
MainWindowItem::saveToStringStream(out);
|
||||||
}
|
}
|
||||||
//virtual bool isValid(bool & alreadyDisplayedIfWrong) { return true; }
|
//virtual bool isValid(bool & alreadyDisplayedIfWrong) { return true; }
|
||||||
TypeEnum getOptionValueType() {return type_ushort;}
|
|
||||||
};
|
};
|
||||||
class CheckBoxItem : public MainWindowItem {
|
class CheckBoxItem : public MainWindowItem {
|
||||||
public:
|
public:
|
||||||
@ -326,12 +300,10 @@ public:
|
|||||||
checkBox->setChecked(boost::any_cast<bool>(optionValue));
|
checkBox->setChecked(boost::any_cast<bool>(optionValue));
|
||||||
}
|
}
|
||||||
virtual void saveToStringStream(std::stringstream& out){
|
virtual void saveToStringStream(std::stringstream& out){
|
||||||
optionValue=static_cast<bool>(checkBox->isChecked());
|
optionValue=checkBox->isChecked();
|
||||||
optionValueType=type_bool;
|
|
||||||
MainWindowItem::saveToStringStream(out);
|
MainWindowItem::saveToStringStream(out);
|
||||||
}
|
}
|
||||||
//virtual bool isValid(bool & alreadyDisplayedIfWrong) { return true; }
|
//virtual bool isValid(bool & alreadyDisplayedIfWrong) { return true; }
|
||||||
TypeEnum getOptionValueType() {return type_bool;}
|
|
||||||
};
|
};
|
||||||
class BaseFormattedStringItem : public BaseStringItem {
|
class BaseFormattedStringItem : public BaseStringItem {
|
||||||
public:
|
public:
|
||||||
@ -340,7 +312,6 @@ public:
|
|||||||
BaseStringItem(option_, lineEdit_, requirementToBeValid_, mw), fieldNameTranslated(fieldNameTranslated_) {}
|
BaseStringItem(option_, lineEdit_, requirementToBeValid_, mw), fieldNameTranslated(fieldNameTranslated_) {}
|
||||||
virtual ~BaseFormattedStringItem(){}
|
virtual ~BaseFormattedStringItem(){}
|
||||||
//virtual bool isValid(bool & alreadyDisplayedIfWrong)=0;
|
//virtual bool isValid(bool & alreadyDisplayedIfWrong)=0;
|
||||||
TypeEnum getOptionValueType() {return type_std_string;}
|
|
||||||
};
|
};
|
||||||
class IntegerStringItem : public BaseFormattedStringItem {
|
class IntegerStringItem : public BaseFormattedStringItem {
|
||||||
public:
|
public:
|
||||||
@ -358,7 +329,6 @@ public:
|
|||||||
}
|
}
|
||||||
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()));}
|
||||||
TypeEnum getOptionValueType() {return type_int;}
|
|
||||||
};
|
};
|
||||||
class UShortStringItem : public BaseFormattedStringItem {
|
class UShortStringItem : public BaseFormattedStringItem {
|
||||||
public:
|
public:
|
||||||
@ -376,7 +346,6 @@ public:
|
|||||||
}
|
}
|
||||||
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()));}
|
||||||
TypeEnum getOptionValueType() {return type_ushort;}
|
|
||||||
};
|
};
|
||||||
class UInt32StringItem : public BaseFormattedStringItem {
|
class UInt32StringItem : public BaseFormattedStringItem {
|
||||||
public:
|
public:
|
||||||
@ -394,7 +363,6 @@ public:
|
|||||||
}
|
}
|
||||||
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()));}
|
||||||
TypeEnum getOptionValueType() {return type_uint32;}
|
|
||||||
};
|
};
|
||||||
class UInt16StringItem : public BaseFormattedStringItem {
|
class UInt16StringItem : public BaseFormattedStringItem {
|
||||||
public:
|
public:
|
||||||
@ -412,14 +380,12 @@ public:
|
|||||||
}
|
}
|
||||||
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()));}
|
||||||
TypeEnum getOptionValueType() {return type_uint16;}
|
|
||||||
};
|
};
|
||||||
class IPAddressStringItem : public BaseFormattedStringItem {
|
class IPAddressStringItem : public BaseFormattedStringItem {
|
||||||
public:
|
public:
|
||||||
IPAddressStringItem(ConfigOption option_, QLineEdit* lineEdit_, QString fieldNameTranslated_, MainWindow* mw) :
|
IPAddressStringItem(ConfigOption option_, QLineEdit* lineEdit_, QString fieldNameTranslated_, MainWindow* mw) :
|
||||||
BaseFormattedStringItem(option_, lineEdit_, fieldNameTranslated_, QApplication::tr("Must be an IPv4 address"), mw) {}
|
BaseFormattedStringItem(option_, lineEdit_, fieldNameTranslated_, QApplication::tr("Must be an IPv4 address"), mw) {}
|
||||||
//virtual bool isValid(bool & alreadyDisplayedIfWrong){return true;}//todo
|
//virtual bool isValid(bool & alreadyDisplayedIfWrong){return true;}//todo
|
||||||
TypeEnum getOptionValueType() {return type_std_string;}
|
|
||||||
};
|
};
|
||||||
class TCPPortStringItem : public UShortStringItem {
|
class TCPPortStringItem : public UShortStringItem {
|
||||||
public:
|
public:
|
||||||
@ -561,6 +527,7 @@ protected:
|
|||||||
|
|
||||||
QString getStatusPageHtml(bool showHiddenInfo);
|
QString getStatusPageHtml(bool showHiddenInfo);
|
||||||
|
|
||||||
|
QList<MainWindowItem*> configItems;
|
||||||
NonGUIOptionItem* daemonOption;
|
NonGUIOptionItem* daemonOption;
|
||||||
NonGUIOptionItem* serviceOption;
|
NonGUIOptionItem* serviceOption;
|
||||||
//LogDestinationComboBoxItem* logOption;
|
//LogDestinationComboBoxItem* logOption;
|
||||||
@ -579,7 +546,7 @@ protected:
|
|||||||
void initUInt32Box(ConfigOption option, QLineEdit* numberLineEdit, QString fieldNameTranslated);
|
void initUInt32Box(ConfigOption option, QLineEdit* numberLineEdit, QString fieldNameTranslated);
|
||||||
void initUInt16Box(ConfigOption option, QLineEdit* numberLineEdit, QString fieldNameTranslated);
|
void initUInt16Box(ConfigOption option, QLineEdit* numberLineEdit, QString fieldNameTranslated);
|
||||||
void initStringBox(ConfigOption option, QLineEdit* lineEdit);
|
void initStringBox(ConfigOption option, QLineEdit* lineEdit);
|
||||||
NonGUIOptionItem* initNonGUIOption(ConfigOption option, TypeEnum optionValueType);
|
NonGUIOptionItem* initNonGUIOption(ConfigOption option);
|
||||||
|
|
||||||
void loadAllConfigs(SaverImpl* saverPtr);
|
void loadAllConfigs(SaverImpl* saverPtr);
|
||||||
void layoutTunnels();
|
void layoutTunnels();
|
||||||
@ -604,20 +571,10 @@ private:
|
|||||||
QString datadir;
|
QString datadir;
|
||||||
QString confpath;
|
QString confpath;
|
||||||
QString tunconfpath;
|
QString tunconfpath;
|
||||||
bool ignoreUpdatesOnAppendForms;
|
|
||||||
|
|
||||||
public:
|
std::map<std::string, TunnelConfig*> tunnelConfigs;
|
||||||
struct VolatileData {
|
std::list<TunnelPane*> tunnelPanes;
|
||||||
QList<MainWindowItem*> configItems;
|
|
||||||
std::unordered_map<std::string, TunnelConfig*> tunnelConfigs;
|
|
||||||
std::unordered_map<int, TunnelConfig*> tunnelConfigsById;
|
|
||||||
std::list<TunnelPane*> tunnelPanes;
|
|
||||||
VolatileData():configItems(), tunnelConfigs(), tunnelConfigsById(), tunnelPanes() {}
|
|
||||||
};
|
|
||||||
|
|
||||||
ConcurrentHolder<VolatileData*>* volatileDataHolder;
|
|
||||||
|
|
||||||
private:
|
|
||||||
void appendTunnelForms(std::string tunnelNameToFocus);
|
void appendTunnelForms(std::string tunnelNameToFocus);
|
||||||
void deleteTunnelForms();
|
void deleteTunnelForms();
|
||||||
void deleteTunnelFromUI(std::string tunnelName, TunnelConfig* cnf);
|
void deleteTunnelFromUI(std::string tunnelName, TunnelConfig* cnf);
|
||||||
@ -697,35 +654,30 @@ private:
|
|||||||
param.set_i2p_streaming_initialAckDelay(QString::number(_i2p_streaming_initialAckDelay));
|
param.set_i2p_streaming_initialAckDelay(QString::number(_i2p_streaming_initialAckDelay));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeleteTunnelNamed(std::string name);
|
|
||||||
|
void DeleteTunnelNamed(std::string name) {
|
||||||
|
std::map<std::string,TunnelConfig*>::const_iterator it=tunnelConfigs.find(name);
|
||||||
|
if(it!=tunnelConfigs.end()){
|
||||||
|
TunnelConfig* tc=it->second;
|
||||||
|
deleteTunnelFromUI(name, tc);
|
||||||
|
tunnelConfigs.erase(it);
|
||||||
|
delete tc;
|
||||||
|
}
|
||||||
|
saveAllConfigs(true, FocusEnum::noFocus);
|
||||||
|
}
|
||||||
|
|
||||||
std::string GenerateNewTunnelName() {
|
std::string GenerateNewTunnelName() {
|
||||||
MutexWrapperLock lock(volatileDataHolder->getMutex());
|
|
||||||
VolatileData* tunnels = volatileDataHolder->getData();
|
|
||||||
int i=1;
|
int i=1;
|
||||||
while(true){
|
while(true){
|
||||||
std::stringstream name;
|
std::stringstream name;
|
||||||
name << "name" << i;
|
name << "name" << i;
|
||||||
const std::string& str=name.str();
|
const std::string& str=name.str();
|
||||||
if(tunnels->tunnelConfigs.find(str)==tunnels->tunnelConfigs.end())return str;
|
if(tunnelConfigs.find(str)==tunnelConfigs.end())return str;
|
||||||
++i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int GenerateNewTunnelId() {
|
|
||||||
MutexWrapperLock lock(volatileDataHolder->getMutex());
|
|
||||||
VolatileData* tunnels = volatileDataHolder->getData();
|
|
||||||
int i=1;
|
|
||||||
while(true){
|
|
||||||
if(tunnels->tunnelConfigsById.find(i)==tunnels->tunnelConfigsById.end())return i;
|
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CreateDefaultClientTunnel() {//TODO dedup default values with ReadTunnelsConfig() and with ClientContext.cpp::ReadTunnels ()
|
void CreateDefaultClientTunnel() {//TODO dedup default values with ReadTunnelsConfig() and with ClientContext.cpp::ReadTunnels ()
|
||||||
MutexWrapperLock lock(volatileDataHolder->getMutex());
|
|
||||||
VolatileData* tunnels = volatileDataHolder->getData();
|
|
||||||
int tunnelId=GenerateNewTunnelId();
|
|
||||||
std::string name=GenerateNewTunnelName();
|
std::string name=GenerateNewTunnelName();
|
||||||
std::string type = I2P_TUNNELS_SECTION_TYPE_CLIENT;
|
std::string type = I2P_TUNNELS_SECTION_TYPE_CLIENT;
|
||||||
std::string dest = "127.0.0.1";
|
std::string dest = "127.0.0.1";
|
||||||
@ -739,9 +691,7 @@ private:
|
|||||||
I2CPParameters i2cpParameters;
|
I2CPParameters i2cpParameters;
|
||||||
CreateDefaultI2CPOptions (i2cpParameters);
|
CreateDefaultI2CPOptions (i2cpParameters);
|
||||||
|
|
||||||
tunnels->tunnelConfigs[name]=tunnels->tunnelConfigsById[tunnelId]=new ClientTunnelConfig(
|
tunnelConfigs[name]=new ClientTunnelConfig(name, QString(type.c_str()), i2cpParameters,
|
||||||
tunnelId,
|
|
||||||
name, QString(type.c_str()), i2cpParameters,
|
|
||||||
dest,
|
dest,
|
||||||
port,
|
port,
|
||||||
keys,
|
keys,
|
||||||
@ -751,13 +701,9 @@ private:
|
|||||||
cryptoType);
|
cryptoType);
|
||||||
|
|
||||||
saveAllConfigs(true, FocusEnum::focusOnTunnelName, name);
|
saveAllConfigs(true, FocusEnum::focusOnTunnelName, name);
|
||||||
delayedSaveManagerPtr->saveNow();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CreateDefaultServerTunnel() {//TODO dedup default values with ReadTunnelsConfig() and with ClientContext.cpp::ReadTunnels ()
|
void CreateDefaultServerTunnel() {//TODO dedup default values with ReadTunnelsConfig() and with ClientContext.cpp::ReadTunnels ()
|
||||||
MutexWrapperLock lock(volatileDataHolder->getMutex());
|
|
||||||
VolatileData* tunnels = volatileDataHolder->getData();
|
|
||||||
int tunnelId=GenerateNewTunnelId();
|
|
||||||
std::string name=GenerateNewTunnelName();
|
std::string name=GenerateNewTunnelName();
|
||||||
std::string type=I2P_TUNNELS_SECTION_TYPE_SERVER;
|
std::string type=I2P_TUNNELS_SECTION_TYPE_SERVER;
|
||||||
std::string host = "127.0.0.1";
|
std::string host = "127.0.0.1";
|
||||||
@ -777,9 +723,7 @@ private:
|
|||||||
I2CPParameters i2cpParameters;
|
I2CPParameters i2cpParameters;
|
||||||
CreateDefaultI2CPOptions (i2cpParameters);
|
CreateDefaultI2CPOptions (i2cpParameters);
|
||||||
|
|
||||||
tunnels->tunnelConfigs[name]=tunnels->tunnelConfigsById[tunnelId]=new ServerTunnelConfig(
|
tunnelConfigs[name]=new ServerTunnelConfig(name, QString(type.c_str()), i2cpParameters,
|
||||||
tunnelId,
|
|
||||||
name, QString(type.c_str()), i2cpParameters,
|
|
||||||
host,
|
host,
|
||||||
port,
|
port,
|
||||||
keys,
|
keys,
|
||||||
@ -795,14 +739,10 @@ private:
|
|||||||
|
|
||||||
|
|
||||||
saveAllConfigs(true, FocusEnum::focusOnTunnelName, name);
|
saveAllConfigs(true, FocusEnum::focusOnTunnelName, name);
|
||||||
delayedSaveManagerPtr->saveNow();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ReadTunnelsConfig() //TODO deduplicate the code with ClientContext.cpp::ReadTunnels ()
|
void ReadTunnelsConfig() //TODO deduplicate the code with ClientContext.cpp::ReadTunnels ()
|
||||||
{
|
{
|
||||||
MutexWrapperLock lock(volatileDataHolder->getMutex());
|
|
||||||
VolatileData* tunnels = volatileDataHolder->getData();
|
|
||||||
|
|
||||||
boost::property_tree::ptree pt;
|
boost::property_tree::ptree pt;
|
||||||
std::string tunConf=tunconfpath.toStdString();
|
std::string tunConf=tunconfpath.toStdString();
|
||||||
if (tunConf == "") {
|
if (tunConf == "") {
|
||||||
@ -857,10 +797,8 @@ private:
|
|||||||
std::map<std::string, std::string> options;
|
std::map<std::string, std::string> options;
|
||||||
I2CPParameters i2cpParameters;
|
I2CPParameters i2cpParameters;
|
||||||
ReadI2CPOptions (section, options, i2cpParameters);
|
ReadI2CPOptions (section, options, i2cpParameters);
|
||||||
int tunnelId=GenerateNewTunnelId();
|
|
||||||
|
|
||||||
tunnels->tunnelConfigs[name]=tunnels->tunnelConfigsById[tunnelId]=
|
tunnelConfigs[name]=new ClientTunnelConfig(name, QString(type.c_str()), i2cpParameters,
|
||||||
new ClientTunnelConfig(tunnelId,name, QString(type.c_str()), i2cpParameters,
|
|
||||||
dest,
|
dest,
|
||||||
port,
|
port,
|
||||||
keys,
|
keys,
|
||||||
@ -893,7 +831,6 @@ private:
|
|||||||
std::map<std::string, std::string> options;
|
std::map<std::string, std::string> options;
|
||||||
I2CPParameters i2cpParameters;
|
I2CPParameters i2cpParameters;
|
||||||
ReadI2CPOptions (section, options, i2cpParameters);
|
ReadI2CPOptions (section, options, i2cpParameters);
|
||||||
int tunnelId=GenerateNewTunnelId();
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
std::set<i2p::data::IdentHash> idents;
|
std::set<i2p::data::IdentHash> idents;
|
||||||
@ -911,8 +848,7 @@ private:
|
|||||||
while (comma != std::string::npos);
|
while (comma != std::string::npos);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
tunnels->tunnelConfigs[name]=tunnels->tunnelConfigsById[tunnelId]=
|
tunnelConfigs[name]=new ServerTunnelConfig(name, QString(type.c_str()), i2cpParameters,
|
||||||
new ServerTunnelConfig(tunnelId,name, QString(type.c_str()), i2cpParameters,
|
|
||||||
host,
|
host,
|
||||||
port,
|
port,
|
||||||
keys,
|
keys,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user