mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
refactor: Integrate ICoreSettings in Core
This commit is contained in:
parent
4e3b2291f5
commit
7f2bd726ef
|
@ -21,6 +21,7 @@
|
|||
#include "core.h"
|
||||
#include "corefile.h"
|
||||
#include "src/core/coreav.h"
|
||||
#include "src/core/icoresettings.h"
|
||||
#include "src/core/toxstring.h"
|
||||
#include "src/model/groupinvite.h"
|
||||
#include "src/nexus.h"
|
||||
|
@ -41,17 +42,20 @@ static const int MAX_PROXY_ADDRESS_LENGTH = 255;
|
|||
|
||||
#define MAX_GROUP_MESSAGE_LEN 1024
|
||||
|
||||
Core::Core(QThread* CoreThread, Profile& profile)
|
||||
Core::Core(QThread* CoreThread, Profile& profile, const ICoreSettings* const settings)
|
||||
: tox(nullptr)
|
||||
, av(nullptr)
|
||||
, profile(profile)
|
||||
, ready(false)
|
||||
, s{settings}
|
||||
{
|
||||
coreThread = CoreThread;
|
||||
toxTimer = new QTimer(this);
|
||||
toxTimer->setSingleShot(true);
|
||||
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()
|
||||
|
@ -112,16 +116,15 @@ CoreAV* Core::getAv()
|
|||
* @param savedata Previously saved Tox data
|
||||
* @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
|
||||
// disabled in options.
|
||||
const Settings& s = Settings::getInstance();
|
||||
bool enableIPv6 = s.getEnableIPv6();
|
||||
bool forceTCP = s.getForceTCP();
|
||||
ICoreSettings::ProxyType proxyType = s.getProxyType();
|
||||
quint16 proxyPort = s.getProxyPort();
|
||||
QString proxyAddr = s.getProxyAddr();
|
||||
bool enableIPv6 = s->getEnableIPv6();
|
||||
bool forceTCP = s->getForceTCP();
|
||||
ICoreSettings::ProxyType proxyType = s->getProxyType();
|
||||
quint16 proxyPort = s->getProxyPort();
|
||||
QString proxyAddr = s->getProxyAddr();
|
||||
QByteArray proxyAddrData = proxyAddr.toUtf8();
|
||||
|
||||
if (enableIPv6) {
|
||||
|
@ -170,7 +173,7 @@ Tox_Options initToxOptions(const QByteArray& savedata)
|
|||
*/
|
||||
void Core::makeTox(QByteArray savedata)
|
||||
{
|
||||
Tox_Options toxOptions = initToxOptions(savedata);
|
||||
Tox_Options toxOptions = initToxOptions(savedata, s);
|
||||
TOX_ERR_NEW tox_err;
|
||||
tox = tox_new(&toxOptions, &tox_err);
|
||||
|
||||
|
@ -184,7 +187,7 @@ void Core::makeTox(QByteArray savedata)
|
|||
return;
|
||||
|
||||
case TOX_ERR_NEW_PORT_ALLOC:
|
||||
if (Settings::getInstance().getEnableIPv6()) {
|
||||
if (s->getEnableIPv6()) {
|
||||
toxOptions.ipv6_enabled = false;
|
||||
tox = tox_new(&toxOptions, &tox_err);
|
||||
if (tox_err == TOX_ERR_NEW_OK) {
|
||||
|
@ -387,8 +390,7 @@ bool Core::checkConnection()
|
|||
*/
|
||||
void Core::bootstrapDht()
|
||||
{
|
||||
const Settings& s = Settings::getInstance();
|
||||
QList<DhtServer> dhtServerList = s.getDhtServerList();
|
||||
QList<DhtServer> dhtServerList = s->getDhtServerList();
|
||||
int listSize = dhtServerList.size();
|
||||
if (!listSize) {
|
||||
qWarning() << "no bootstrap list?!?";
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include <QObject>
|
||||
|
||||
class CoreAV;
|
||||
class ICoreSettings;
|
||||
class GroupInvite;
|
||||
class Profile;
|
||||
class QTimer;
|
||||
|
@ -38,7 +39,7 @@ class Core : public QObject
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit Core(QThread* coreThread, Profile& profile);
|
||||
Core(QThread* coreThread, Profile& profile, const ICoreSettings* const settings);
|
||||
static Core* getInstance();
|
||||
const CoreAV* getAv() const;
|
||||
CoreAV* getAv();
|
||||
|
@ -225,6 +226,7 @@ private:
|
|||
Profile& profile;
|
||||
QMutex messageSendMutex;
|
||||
bool ready;
|
||||
const ICoreSettings* const s;
|
||||
|
||||
static QThread* coreThread;
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ Profile::Profile(QString name, const QString& password, bool isNewProfile, const
|
|||
|
||||
coreThread = new QThread();
|
||||
coreThread->setObjectName("qTox Core");
|
||||
core = new Core(coreThread, *this);
|
||||
core = new Core(coreThread, *this, &Settings::getInstance());
|
||||
QObject::connect(core, &Core::idSet, this,
|
||||
[this, password](const ToxId& id) { loadDatabase(id, password); },
|
||||
Qt::QueuedConnection);
|
||||
|
|
|
@ -805,12 +805,12 @@ const QList<DhtServer>& Settings::getDhtServerList() const
|
|||
return dhtServerList;
|
||||
}
|
||||
|
||||
void Settings::setDhtServerList(const QList<DhtServer>& newDhtServerList)
|
||||
void Settings::setDhtServerList(const QList<DhtServer>& servers)
|
||||
{
|
||||
QMutexLocker locker{&bigLock};
|
||||
|
||||
if (newDhtServerList != dhtServerList) {
|
||||
dhtServerList = newDhtServerList;
|
||||
if (servers != dhtServerList) {
|
||||
dhtServerList = servers;
|
||||
emit dhtServerListChanged(dhtServerList);
|
||||
}
|
||||
}
|
||||
|
@ -836,12 +836,12 @@ bool Settings::getEnableIPv6() const
|
|||
return enableIPv6;
|
||||
}
|
||||
|
||||
void Settings::setEnableIPv6(bool newValue)
|
||||
void Settings::setEnableIPv6(bool enabled)
|
||||
{
|
||||
QMutexLocker locker{&bigLock};
|
||||
|
||||
if (newValue != enableIPv6) {
|
||||
enableIPv6 = newValue;
|
||||
if (enabled != enableIPv6) {
|
||||
enableIPv6 = enabled;
|
||||
emit enableIPv6Changed(enableIPv6);
|
||||
}
|
||||
}
|
||||
|
@ -1209,12 +1209,12 @@ bool Settings::getForceTCP() const
|
|||
return forceTCP;
|
||||
}
|
||||
|
||||
void Settings::setForceTCP(bool newValue)
|
||||
void Settings::setForceTCP(bool enabled)
|
||||
{
|
||||
QMutexLocker locker{&bigLock};
|
||||
|
||||
if (newValue != forceTCP) {
|
||||
forceTCP = newValue;
|
||||
if (enabled != forceTCP) {
|
||||
forceTCP = enabled;
|
||||
emit forceTCPChanged(forceTCP);
|
||||
}
|
||||
}
|
||||
|
@ -1265,12 +1265,12 @@ QString Settings::getProxyAddr() const
|
|||
return proxyAddr;
|
||||
}
|
||||
|
||||
void Settings::setProxyAddr(const QString& newValue)
|
||||
void Settings::setProxyAddr(const QString& address)
|
||||
{
|
||||
QMutexLocker locker{&bigLock};
|
||||
|
||||
if (newValue != proxyAddr) {
|
||||
proxyAddr = newValue;
|
||||
if (address != proxyAddr) {
|
||||
proxyAddr = address;
|
||||
emit proxyAddressChanged(proxyAddr);
|
||||
}
|
||||
}
|
||||
|
@ -1281,12 +1281,12 @@ quint16 Settings::getProxyPort() const
|
|||
return proxyPort;
|
||||
}
|
||||
|
||||
void Settings::setProxyPort(quint16 newValue)
|
||||
void Settings::setProxyPort(quint16 port)
|
||||
{
|
||||
QMutexLocker locker{&bigLock};
|
||||
|
||||
if (newValue != proxyPort) {
|
||||
proxyPort = newValue;
|
||||
if (port != proxyPort) {
|
||||
proxyPort = port;
|
||||
emit proxyPortChanged(proxyPort);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -160,12 +160,6 @@ public slots:
|
|||
|
||||
signals:
|
||||
// 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 autoSaveEnabledChanged(bool enabled);
|
||||
void autostartInTrayChanged(bool enabled);
|
||||
|
@ -302,25 +296,32 @@ public:
|
|||
bool getAutoSaveEnabled() const;
|
||||
|
||||
// ICoreSettings
|
||||
virtual const QList<DhtServer>& getDhtServerList() const override;
|
||||
virtual void setDhtServerList(const QList<DhtServer>& newDhtServerList) override;
|
||||
const QList<DhtServer>& getDhtServerList() const override;
|
||||
void setDhtServerList(const QList<DhtServer>& servers) override;
|
||||
|
||||
virtual bool getEnableIPv6() const override;
|
||||
virtual void setEnableIPv6(bool newValue) override;
|
||||
bool getEnableIPv6() const override;
|
||||
void setEnableIPv6(bool enabled) override;
|
||||
|
||||
virtual bool getForceTCP() const override;
|
||||
virtual void setForceTCP(bool newValue) override;
|
||||
bool getForceTCP() const 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;
|
||||
virtual void setProxyAddr(const QString& newValue) override;
|
||||
ICoreSettings::ProxyType getProxyType() const override;
|
||||
void setProxyType(ICoreSettings::ProxyType type) override;
|
||||
|
||||
virtual ICoreSettings::ProxyType getProxyType() const override;
|
||||
virtual void setProxyType(ICoreSettings::ProxyType newValue) override;
|
||||
quint16 getProxyPort() const override;
|
||||
void setProxyPort(quint16 port) override;
|
||||
|
||||
virtual quint16 getProxyPort() const override;
|
||||
virtual void setProxyPort(quint16 newValue) override;
|
||||
QNetworkProxy getProxy() const 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;
|
||||
void setEnableLogging(bool newValue);
|
||||
|
|
Loading…
Reference in New Issue
Block a user