Browse Source

refactor: Integrate ICoreSettings in Core

pull/4696/head
Diadlo 8 years ago
parent
commit
7f2bd726ef
No known key found for this signature in database
GPG Key ID: 5AF9F2E29107C727
  1. 28
      src/core/core.cpp
  2. 4
      src/core/core.h
  3. 2
      src/persistence/profile.cpp
  4. 30
      src/persistence/settings.cpp
  5. 39
      src/persistence/settings.h

28
src/core/core.cpp

@ -21,6 +21,7 @@
#include "core.h" #include "core.h"
#include "corefile.h" #include "corefile.h"
#include "src/core/coreav.h" #include "src/core/coreav.h"
#include "src/core/icoresettings.h"
#include "src/core/toxstring.h" #include "src/core/toxstring.h"
#include "src/model/groupinvite.h" #include "src/model/groupinvite.h"
#include "src/nexus.h" #include "src/nexus.h"
@ -41,17 +42,20 @@ static const int MAX_PROXY_ADDRESS_LENGTH = 255;
#define MAX_GROUP_MESSAGE_LEN 1024 #define MAX_GROUP_MESSAGE_LEN 1024
Core::Core(QThread* CoreThread, Profile& profile) Core::Core(QThread* CoreThread, Profile& profile, const ICoreSettings* const settings)
: tox(nullptr) : tox(nullptr)
, av(nullptr) , av(nullptr)
, profile(profile) , profile(profile)
, ready(false) , ready(false)
, s{settings}
{ {
coreThread = CoreThread; coreThread = CoreThread;
toxTimer = new QTimer(this); toxTimer = new QTimer(this);
toxTimer->setSingleShot(true); toxTimer->setSingleShot(true);
connect(toxTimer, &QTimer::timeout, this, &Core::process); connect(toxTimer, &QTimer::timeout, this, &Core::process);
connect(&Settings::getInstance(), &Settings::dhtServerListChanged, this, &Core::process); s->connectTo_dhtServerListChanged([=](const QList<DhtServer>& servers){
process();
});
} }
void Core::deadifyTox() void Core::deadifyTox()
@ -112,16 +116,15 @@ CoreAV* Core::getAv()
* @param savedata Previously saved Tox data * @param savedata Previously saved Tox data
* @return Tox_Options instance needed to create Tox instance * @return Tox_Options instance needed to create Tox instance
*/ */
Tox_Options initToxOptions(const QByteArray& savedata) Tox_Options initToxOptions(const QByteArray& savedata, const ICoreSettings* s)
{ {
// IPv6 needed for LAN discovery, but can crash some weird routers. On by default, can be // IPv6 needed for LAN discovery, but can crash some weird routers. On by default, can be
// disabled in options. // disabled in options.
const Settings& s = Settings::getInstance(); bool enableIPv6 = s->getEnableIPv6();
bool enableIPv6 = s.getEnableIPv6(); bool forceTCP = s->getForceTCP();
bool forceTCP = s.getForceTCP(); ICoreSettings::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();
if (enableIPv6) { if (enableIPv6) {
@ -170,7 +173,7 @@ Tox_Options initToxOptions(const QByteArray& savedata)
*/ */
void Core::makeTox(QByteArray savedata) void Core::makeTox(QByteArray savedata)
{ {
Tox_Options toxOptions = initToxOptions(savedata); Tox_Options toxOptions = initToxOptions(savedata, s);
TOX_ERR_NEW tox_err; TOX_ERR_NEW tox_err;
tox = tox_new(&toxOptions, &tox_err); tox = tox_new(&toxOptions, &tox_err);
@ -184,7 +187,7 @@ void Core::makeTox(QByteArray savedata)
return; return;
case TOX_ERR_NEW_PORT_ALLOC: case TOX_ERR_NEW_PORT_ALLOC:
if (Settings::getInstance().getEnableIPv6()) { if (s->getEnableIPv6()) {
toxOptions.ipv6_enabled = false; toxOptions.ipv6_enabled = false;
tox = tox_new(&toxOptions, &tox_err); tox = tox_new(&toxOptions, &tox_err);
if (tox_err == TOX_ERR_NEW_OK) { if (tox_err == TOX_ERR_NEW_OK) {
@ -387,8 +390,7 @@ bool Core::checkConnection()
*/ */
void Core::bootstrapDht() void Core::bootstrapDht()
{ {
const Settings& s = Settings::getInstance(); QList<DhtServer> dhtServerList = s->getDhtServerList();
QList<DhtServer> dhtServerList = s.getDhtServerList();
int listSize = dhtServerList.size(); int listSize = dhtServerList.size();
if (!listSize) { if (!listSize) {
qWarning() << "no bootstrap list?!?"; qWarning() << "no bootstrap list?!?";

4
src/core/core.h

@ -30,6 +30,7 @@
#include <QObject> #include <QObject>
class CoreAV; class CoreAV;
class ICoreSettings;
class GroupInvite; class GroupInvite;
class Profile; class Profile;
class QTimer; class QTimer;
@ -38,7 +39,7 @@ class Core : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit Core(QThread* coreThread, Profile& profile); Core(QThread* coreThread, Profile& profile, const ICoreSettings* const settings);
static Core* getInstance(); static Core* getInstance();
const CoreAV* getAv() const; const CoreAV* getAv() const;
CoreAV* getAv(); CoreAV* getAv();
@ -225,6 +226,7 @@ private:
Profile& profile; Profile& profile;
QMutex messageSendMutex; QMutex messageSendMutex;
bool ready; bool ready;
const ICoreSettings* const s;
static QThread* coreThread; static QThread* coreThread;

2
src/persistence/profile.cpp

@ -62,7 +62,7 @@ Profile::Profile(QString name, const QString& password, bool isNewProfile, const
coreThread = new QThread(); coreThread = new QThread();
coreThread->setObjectName("qTox Core"); coreThread->setObjectName("qTox Core");
core = new Core(coreThread, *this); core = new Core(coreThread, *this, &Settings::getInstance());
QObject::connect(core, &Core::idSet, this, QObject::connect(core, &Core::idSet, this,
[this, password](const ToxId& id) { loadDatabase(id, password); }, [this, password](const ToxId& id) { loadDatabase(id, password); },
Qt::QueuedConnection); Qt::QueuedConnection);

30
src/persistence/settings.cpp

@ -805,12 +805,12 @@ const QList<DhtServer>& Settings::getDhtServerList() const
return dhtServerList; return dhtServerList;
} }
void Settings::setDhtServerList(const QList<DhtServer>& newDhtServerList) void Settings::setDhtServerList(const QList<DhtServer>& servers)
{ {
QMutexLocker locker{&bigLock}; QMutexLocker locker{&bigLock};
if (newDhtServerList != dhtServerList) { if (servers != dhtServerList) {
dhtServerList = newDhtServerList; dhtServerList = servers;
emit dhtServerListChanged(dhtServerList); emit dhtServerListChanged(dhtServerList);
} }
} }
@ -836,12 +836,12 @@ bool Settings::getEnableIPv6() const
return enableIPv6; return enableIPv6;
} }
void Settings::setEnableIPv6(bool newValue) void Settings::setEnableIPv6(bool enabled)
{ {
QMutexLocker locker{&bigLock}; QMutexLocker locker{&bigLock};
if (newValue != enableIPv6) { if (enabled != enableIPv6) {
enableIPv6 = newValue; enableIPv6 = enabled;
emit enableIPv6Changed(enableIPv6); emit enableIPv6Changed(enableIPv6);
} }
} }
@ -1209,12 +1209,12 @@ bool Settings::getForceTCP() const
return forceTCP; return forceTCP;
} }
void Settings::setForceTCP(bool newValue) void Settings::setForceTCP(bool enabled)
{ {
QMutexLocker locker{&bigLock}; QMutexLocker locker{&bigLock};
if (newValue != forceTCP) { if (enabled != forceTCP) {
forceTCP = newValue; forceTCP = enabled;
emit forceTCPChanged(forceTCP); emit forceTCPChanged(forceTCP);
} }
} }
@ -1265,12 +1265,12 @@ QString Settings::getProxyAddr() const
return proxyAddr; return proxyAddr;
} }
void Settings::setProxyAddr(const QString& newValue) void Settings::setProxyAddr(const QString& address)
{ {
QMutexLocker locker{&bigLock}; QMutexLocker locker{&bigLock};
if (newValue != proxyAddr) { if (address != proxyAddr) {
proxyAddr = newValue; proxyAddr = address;
emit proxyAddressChanged(proxyAddr); emit proxyAddressChanged(proxyAddr);
} }
} }
@ -1281,12 +1281,12 @@ quint16 Settings::getProxyPort() const
return proxyPort; return proxyPort;
} }
void Settings::setProxyPort(quint16 newValue) void Settings::setProxyPort(quint16 port)
{ {
QMutexLocker locker{&bigLock}; QMutexLocker locker{&bigLock};
if (newValue != proxyPort) { if (port != proxyPort) {
proxyPort = newValue; proxyPort = port;
emit proxyPortChanged(proxyPort); emit proxyPortChanged(proxyPort);
} }
} }

39
src/persistence/settings.h

@ -160,12 +160,6 @@ public slots:
signals: signals:
// General // General
void enableIPv6Changed(bool enabled);
void forceTCPChanged(bool enabled);
void proxyTypeChanged(ICoreSettings::ProxyType type);
void proxyAddressChanged(const QString& address);
void proxyPortChanged(quint16 port);
void dhtServerListChanged(const QList<DhtServer>& servers);
void autorunChanged(bool enabled); void autorunChanged(bool enabled);
void autoSaveEnabledChanged(bool enabled); void autoSaveEnabledChanged(bool enabled);
void autostartInTrayChanged(bool enabled); void autostartInTrayChanged(bool enabled);
@ -302,25 +296,32 @@ public:
bool getAutoSaveEnabled() const; bool getAutoSaveEnabled() const;
// ICoreSettings // ICoreSettings
virtual const QList<DhtServer>& getDhtServerList() const override; const QList<DhtServer>& getDhtServerList() const override;
virtual void setDhtServerList(const QList<DhtServer>& newDhtServerList) override; void setDhtServerList(const QList<DhtServer>& servers) override;
virtual bool getEnableIPv6() const override; bool getEnableIPv6() const override;
virtual void setEnableIPv6(bool newValue) override; void setEnableIPv6(bool enabled) override;
virtual bool getForceTCP() const override; bool getForceTCP() const override;
virtual void setForceTCP(bool newValue) override; void setForceTCP(bool enabled) override;
virtual QNetworkProxy getProxy() const override; QString getProxyAddr() const override;
void setProxyAddr(const QString& address) override;
virtual QString getProxyAddr() const override; ICoreSettings::ProxyType getProxyType() const override;
virtual void setProxyAddr(const QString& newValue) override; void setProxyType(ICoreSettings::ProxyType type) override;
virtual ICoreSettings::ProxyType getProxyType() const override; quint16 getProxyPort() const override;
virtual void setProxyType(ICoreSettings::ProxyType newValue) override; void setProxyPort(quint16 port) override;
virtual quint16 getProxyPort() const override; QNetworkProxy getProxy() const override;
virtual void setProxyPort(quint16 newValue) override;
SIGNAL_IMPL(Settings, enableIPv6Changed, bool enabled)
SIGNAL_IMPL(Settings, forceTCPChanged, bool enabled)
SIGNAL_IMPL(Settings, proxyTypeChanged, ICoreSettings::ProxyType type)
SIGNAL_IMPL(Settings, proxyAddressChanged, const QString& address)
SIGNAL_IMPL(Settings, proxyPortChanged, quint16 port)
SIGNAL_IMPL(Settings, dhtServerListChanged, const QList<DhtServer>& servers)
bool getEnableLogging() const; bool getEnableLogging() const;
void setEnableLogging(bool newValue); void setEnableLogging(bool newValue);

Loading…
Cancel
Save