diff --git a/CMakeLists.txt b/CMakeLists.txt index 65e45a9dc..04ba50485 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -232,6 +232,7 @@ set(${PROJECT_NAME}_SOURCES src/core/corestructs.h src/core/dhtserver.cpp src/core/dhtserver.h + src/core/icoresettings.h src/core/indexedlist.h src/core/recursivesignalblocker.cpp src/core/recursivesignalblocker.h diff --git a/src/core/core.cpp b/src/core/core.cpp index 2bbc2d210..02f39fbd4 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -119,7 +119,7 @@ Tox_Options initToxOptions(const QByteArray& savedata) const Settings& s = Settings::getInstance(); bool enableIPv6 = s.getEnableIPv6(); bool forceTCP = s.getForceTCP(); - Settings::ProxyType proxyType = s.getProxyType(); + ICoreSettings::ProxyType proxyType = s.getProxyType(); quint16 proxyPort = s.getProxyPort(); QString proxyAddr = s.getProxyAddr(); QByteArray proxyAddrData = proxyAddr.toUtf8(); @@ -144,15 +144,15 @@ Tox_Options initToxOptions(const QByteArray& savedata) toxOptions.savedata_data = reinterpret_cast(savedata.data()); toxOptions.savedata_length = savedata.size(); - if (proxyType != Settings::ProxyType::ptNone) { + if (proxyType != ICoreSettings::ProxyType::ptNone) { if (proxyAddr.length() > MAX_PROXY_ADDRESS_LENGTH) { qWarning() << "proxy address" << proxyAddr << "is too long"; } else if (!proxyAddr.isEmpty() && proxyPort > 0) { qDebug() << "using proxy" << proxyAddr << ":" << proxyPort; // protection against changings in TOX_PROXY_TYPE enum - if (proxyType == Settings::ProxyType::ptSOCKS5) { + if (proxyType == ICoreSettings::ProxyType::ptSOCKS5) { toxOptions.proxy_type = TOX_PROXY_TYPE_SOCKS5; - } else if (proxyType == Settings::ProxyType::ptHTTP) { + } else if (proxyType == ICoreSettings::ProxyType::ptHTTP) { toxOptions.proxy_type = TOX_PROXY_TYPE_HTTP; } diff --git a/src/core/icoresettings.h b/src/core/icoresettings.h new file mode 100644 index 000000000..099dee940 --- /dev/null +++ b/src/core/icoresettings.h @@ -0,0 +1,48 @@ +#ifndef I_CORE_SETTINGS_H +#define I_CORE_SETTINGS_H + +#include "src/model/interface.h" +#include "src/core/dhtserver.h" + +#include +#include +#include + +class ICoreSettings { +public: + enum class ProxyType + { + ptNone = 0, + ptSOCKS5 = 1, + ptHTTP = 2 + }; + + virtual bool getEnableIPv6() const = 0; + virtual void setEnableIPv6(bool enable) = 0; + + virtual bool getForceTCP() const = 0; + virtual void setForceTCP(bool enable) = 0; + + virtual QString getProxyAddr() const = 0; + virtual void setProxyAddr(const QString& address) = 0; + + virtual ProxyType getProxyType() const = 0; + virtual void setProxyType(ProxyType type) = 0; + + virtual quint16 getProxyPort() const = 0; + virtual void setProxyPort(quint16 port) = 0; + + virtual const QList& getDhtServerList() const = 0; + virtual void setDhtServerList(const QList& servers) = 0; + + virtual QNetworkProxy getProxy() const = 0; + + DECLARE_SIGNAL(enableIPv6Changed, bool enabled); + DECLARE_SIGNAL(forceTCPChanged, bool enabled); + DECLARE_SIGNAL(proxyTypeChanged, ICoreSettings::ProxyType type); + DECLARE_SIGNAL(proxyAddressChanged, const QString& address); + DECLARE_SIGNAL(proxyPortChanged, quint16 port); + DECLARE_SIGNAL(dhtServerListChanged, const QList& servers); +}; + +#endif // I_CORE_SETTINGS_H diff --git a/src/persistence/settings.h b/src/persistence/settings.h index cde81b871..aeb43d3d7 100644 --- a/src/persistence/settings.h +++ b/src/persistence/settings.h @@ -22,8 +22,8 @@ #define SETTINGS_HPP #include "src/core/corestructs.h" +#include "src/core/icoresettings.h" #include "src/core/toxencrypt.h" -#include "src/core/dhtserver.h" #include #include @@ -41,11 +41,10 @@ namespace Db { enum class syncType; } -class Settings : public QObject +class Settings : public QObject, public ICoreSettings { Q_OBJECT - Q_ENUMS(ProxyType) Q_ENUMS(StyleType) // general @@ -115,12 +114,6 @@ class Settings : public QObject Q_PROPERTY(quint16 camVideoFPS READ getCamVideoFPS WRITE setCamVideoFPS NOTIFY camVideoFPSChanged FINAL) public: - enum class ProxyType - { - ptNone = 0, - ptSOCKS5 = 1, - ptHTTP = 2 - }; enum class StyleType { NONE = 0, @@ -169,7 +162,7 @@ signals: // General void enableIPv6Changed(bool enabled); void forceTCPChanged(bool enabled); - void proxyTypeChanged(ProxyType type); + void proxyTypeChanged(ICoreSettings::ProxyType type); void proxyAddressChanged(const QString& address); void proxyPortChanged(quint16 port); void dhtServerListChanged(const QList& servers); @@ -256,12 +249,6 @@ signals: void camVideoFPSChanged(quint16 fps); public: - const QList& getDhtServerList() const; - void setDhtServerList(const QList& newDhtServerList); - - bool getEnableIPv6() const; - void setEnableIPv6(bool newValue); - bool getMakeToxPortable() const; void setMakeToxPortable(bool newValue); @@ -314,19 +301,26 @@ public: void setAutoSaveEnabled(bool newValue); bool getAutoSaveEnabled() const; - bool getForceTCP() const; - void setForceTCP(bool newValue); + // ICoreSettings + virtual const QList& getDhtServerList() const override; + virtual void setDhtServerList(const QList& newDhtServerList) override; - QNetworkProxy getProxy() const; + virtual bool getEnableIPv6() const override; + virtual void setEnableIPv6(bool newValue) override; - QString getProxyAddr() const; - void setProxyAddr(const QString& newValue); + virtual bool getForceTCP() const override; + virtual void setForceTCP(bool newValue) override; - ProxyType getProxyType() const; - void setProxyType(ProxyType newValue); + virtual QNetworkProxy getProxy() const override; - quint16 getProxyPort() const; - void setProxyPort(quint16 newValue); + virtual QString getProxyAddr() const override; + virtual void setProxyAddr(const QString& newValue) override; + + virtual ICoreSettings::ProxyType getProxyType() const override; + virtual void setProxyType(ICoreSettings::ProxyType newValue) override; + + virtual quint16 getProxyPort() const override; + virtual void setProxyPort(quint16 newValue) override; bool getEnableLogging() const; void setEnableLogging(bool newValue); @@ -580,7 +574,7 @@ private: bool forceTCP; - ProxyType proxyType; + ICoreSettings::ProxyType proxyType; QString proxyAddr; quint16 proxyPort;