1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

refactor: Create interface for core settings

This commit is contained in:
Diadlo 2017-09-27 23:28:54 +03:00
parent 0c8c16e743
commit 4e3b2291f5
No known key found for this signature in database
GPG Key ID: 5AF9F2E29107C727
4 changed files with 73 additions and 30 deletions

View File

@ -232,6 +232,7 @@ set(${PROJECT_NAME}_SOURCES
src/core/corestructs.h src/core/corestructs.h
src/core/dhtserver.cpp src/core/dhtserver.cpp
src/core/dhtserver.h src/core/dhtserver.h
src/core/icoresettings.h
src/core/indexedlist.h src/core/indexedlist.h
src/core/recursivesignalblocker.cpp src/core/recursivesignalblocker.cpp
src/core/recursivesignalblocker.h src/core/recursivesignalblocker.h

View File

@ -119,7 +119,7 @@ Tox_Options initToxOptions(const QByteArray& savedata)
const Settings& s = Settings::getInstance(); const Settings& s = Settings::getInstance();
bool enableIPv6 = s.getEnableIPv6(); bool enableIPv6 = s.getEnableIPv6();
bool forceTCP = s.getForceTCP(); bool forceTCP = s.getForceTCP();
Settings::ProxyType proxyType = s.getProxyType(); ICoreSettings::ProxyType proxyType = s.getProxyType();
quint16 proxyPort = s.getProxyPort(); quint16 proxyPort = s.getProxyPort();
QString proxyAddr = s.getProxyAddr(); QString proxyAddr = s.getProxyAddr();
QByteArray proxyAddrData = proxyAddr.toUtf8(); QByteArray proxyAddrData = proxyAddr.toUtf8();
@ -144,15 +144,15 @@ Tox_Options initToxOptions(const QByteArray& savedata)
toxOptions.savedata_data = reinterpret_cast<const uint8_t*>(savedata.data()); toxOptions.savedata_data = reinterpret_cast<const uint8_t*>(savedata.data());
toxOptions.savedata_length = savedata.size(); toxOptions.savedata_length = savedata.size();
if (proxyType != Settings::ProxyType::ptNone) { if (proxyType != ICoreSettings::ProxyType::ptNone) {
if (proxyAddr.length() > MAX_PROXY_ADDRESS_LENGTH) { if (proxyAddr.length() > MAX_PROXY_ADDRESS_LENGTH) {
qWarning() << "proxy address" << proxyAddr << "is too long"; qWarning() << "proxy address" << proxyAddr << "is too long";
} else if (!proxyAddr.isEmpty() && proxyPort > 0) { } else if (!proxyAddr.isEmpty() && proxyPort > 0) {
qDebug() << "using proxy" << proxyAddr << ":" << proxyPort; qDebug() << "using proxy" << proxyAddr << ":" << proxyPort;
// protection against changings in TOX_PROXY_TYPE enum // 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; 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; toxOptions.proxy_type = TOX_PROXY_TYPE_HTTP;
} }

48
src/core/icoresettings.h Normal file
View File

@ -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 <QList>
#include <QNetworkProxy>
#include <QString>
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<DhtServer>& getDhtServerList() const = 0;
virtual void setDhtServerList(const QList<DhtServer>& 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<DhtServer>& servers);
};
#endif // I_CORE_SETTINGS_H

View File

@ -22,8 +22,8 @@
#define SETTINGS_HPP #define SETTINGS_HPP
#include "src/core/corestructs.h" #include "src/core/corestructs.h"
#include "src/core/icoresettings.h"
#include "src/core/toxencrypt.h" #include "src/core/toxencrypt.h"
#include "src/core/dhtserver.h"
#include <QDate> #include <QDate>
#include <QFlags> #include <QFlags>
@ -41,11 +41,10 @@ namespace Db {
enum class syncType; enum class syncType;
} }
class Settings : public QObject class Settings : public QObject, public ICoreSettings
{ {
Q_OBJECT Q_OBJECT
Q_ENUMS(ProxyType)
Q_ENUMS(StyleType) Q_ENUMS(StyleType)
// general // general
@ -115,12 +114,6 @@ class Settings : public QObject
Q_PROPERTY(quint16 camVideoFPS READ getCamVideoFPS WRITE setCamVideoFPS NOTIFY camVideoFPSChanged FINAL) Q_PROPERTY(quint16 camVideoFPS READ getCamVideoFPS WRITE setCamVideoFPS NOTIFY camVideoFPSChanged FINAL)
public: public:
enum class ProxyType
{
ptNone = 0,
ptSOCKS5 = 1,
ptHTTP = 2
};
enum class StyleType enum class StyleType
{ {
NONE = 0, NONE = 0,
@ -169,7 +162,7 @@ signals:
// General // General
void enableIPv6Changed(bool enabled); void enableIPv6Changed(bool enabled);
void forceTCPChanged(bool enabled); void forceTCPChanged(bool enabled);
void proxyTypeChanged(ProxyType type); void proxyTypeChanged(ICoreSettings::ProxyType type);
void proxyAddressChanged(const QString& address); void proxyAddressChanged(const QString& address);
void proxyPortChanged(quint16 port); void proxyPortChanged(quint16 port);
void dhtServerListChanged(const QList<DhtServer>& servers); void dhtServerListChanged(const QList<DhtServer>& servers);
@ -256,12 +249,6 @@ signals:
void camVideoFPSChanged(quint16 fps); void camVideoFPSChanged(quint16 fps);
public: public:
const QList<DhtServer>& getDhtServerList() const;
void setDhtServerList(const QList<DhtServer>& newDhtServerList);
bool getEnableIPv6() const;
void setEnableIPv6(bool newValue);
bool getMakeToxPortable() const; bool getMakeToxPortable() const;
void setMakeToxPortable(bool newValue); void setMakeToxPortable(bool newValue);
@ -314,19 +301,26 @@ public:
void setAutoSaveEnabled(bool newValue); void setAutoSaveEnabled(bool newValue);
bool getAutoSaveEnabled() const; bool getAutoSaveEnabled() const;
bool getForceTCP() const; // ICoreSettings
void setForceTCP(bool newValue); virtual const QList<DhtServer>& getDhtServerList() const override;
virtual void setDhtServerList(const QList<DhtServer>& newDhtServerList) override;
QNetworkProxy getProxy() const; virtual bool getEnableIPv6() const override;
virtual void setEnableIPv6(bool newValue) override;
QString getProxyAddr() const; virtual bool getForceTCP() const override;
void setProxyAddr(const QString& newValue); virtual void setForceTCP(bool newValue) override;
ProxyType getProxyType() const; virtual QNetworkProxy getProxy() const override;
void setProxyType(ProxyType newValue);
quint16 getProxyPort() const; virtual QString getProxyAddr() const override;
void setProxyPort(quint16 newValue); 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; bool getEnableLogging() const;
void setEnableLogging(bool newValue); void setEnableLogging(bool newValue);
@ -580,7 +574,7 @@ private:
bool forceTCP; bool forceTCP;
ProxyType proxyType; ICoreSettings::ProxyType proxyType;
QString proxyAddr; QString proxyAddr;
quint16 proxyPort; quint16 proxyPort;