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

1482 lines
37 KiB
C++
Raw Normal View History

2014-06-25 04:11:11 +08:00
/*
Copyright (C) 2013 by Maxim Biro <nurupo.contributions@gmail.com>
Copyright © 2014-2015 by The qTox Project
This file is part of qTox, a Qt-based graphical interface for Tox.
2014-06-25 04:11:11 +08:00
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
qTox is distributed in the hope that it will be useful,
2014-06-25 04:11:11 +08:00
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with qTox. If not, see <http://www.gnu.org/licenses/>.
2014-06-25 04:11:11 +08:00
*/
#include "settings.h"
2015-06-06 07:44:47 +08:00
#include "src/persistence/smileypack.h"
#include "src/persistence/db/plaindb.h"
#include "src/core/corestructs.h"
#include "src/core/core.h"
#include "src/widget/gui.h"
2015-06-06 07:44:47 +08:00
#include "src/persistence/profilelocker.h"
#include "src/persistence/settingsserializer.h"
#include "src/persistence/historykeeper.h"
#include "src/nexus.h"
#include "src/persistence/profile.h"
2014-12-17 21:44:23 +08:00
#ifdef QTOX_PLATFORM_EXT
#include "src/platform/autorun.h"
#endif
#include "src/ipc.h"
2014-06-25 04:11:11 +08:00
2014-09-11 21:44:34 +08:00
#include <QFont>
2014-06-25 04:11:11 +08:00
#include <QApplication>
#include <QDir>
#include <QFile>
#include <QStandardPaths>
#include <QDebug>
2014-08-01 20:46:28 +08:00
#include <QList>
#include <QStyleFactory>
#include <QCryptographicHash>
2015-06-05 22:27:15 +08:00
#include <QMutexLocker>
2015-06-06 00:01:50 +08:00
#include <QThread>
2014-06-25 04:11:11 +08:00
#define SHOW_SYSTEM_TRAY_DEFAULT (bool) true
2015-06-04 20:19:18 +08:00
const QString Settings::globalSettingsFile = "qtox.ini";
Settings* Settings::settings{nullptr};
2015-06-05 22:27:15 +08:00
QMutex Settings::bigLock{QMutex::Recursive};
2015-06-06 00:01:50 +08:00
QThread* Settings::settingsThread{nullptr};
2014-06-25 04:11:11 +08:00
Settings::Settings() :
2015-06-05 22:24:47 +08:00
loaded(false), useCustomDhtList{false},
makeToxPortable{false}, currentProfileId(0)
2014-06-25 04:11:11 +08:00
{
2015-06-06 00:01:50 +08:00
settingsThread = new QThread();
settingsThread->setObjectName("qTox Settings");
settingsThread->start(QThread::LowPriority);
moveToThread(settingsThread);
loadGlobal();
2014-06-25 04:11:11 +08:00
}
2015-06-06 00:01:50 +08:00
Settings::~Settings()
{
sync();
settingsThread->exit(0);
settingsThread->wait();
delete settingsThread;
}
2014-06-25 04:11:11 +08:00
Settings& Settings::getInstance()
{
if (!settings)
settings = new Settings();
2015-04-24 19:01:50 +08:00
return *settings;
2014-06-25 04:11:11 +08:00
}
2015-06-06 00:01:50 +08:00
void Settings::destroyInstance()
{
delete settings;
settings = nullptr;
}
void Settings::loadGlobal()
2014-06-25 04:11:11 +08:00
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
2014-12-03 06:47:55 +08:00
if (loaded)
2014-06-25 04:11:11 +08:00
return;
2015-06-04 20:19:18 +08:00
createSettingsDir();
2015-06-04 20:19:18 +08:00
if (QFile(globalSettingsFile).exists())
{
2015-06-04 20:19:18 +08:00
QSettings ps(globalSettingsFile, QSettings::IniFormat);
2014-12-03 06:47:55 +08:00
ps.beginGroup("General");
makeToxPortable = ps.value("makeToxPortable", false).toBool();
ps.endGroup();
}
else
2015-04-24 19:01:50 +08:00
{
makeToxPortable = false;
2015-04-24 19:01:50 +08:00
}
2014-07-13 04:58:58 +08:00
QDir dir(getSettingsDirPath());
2015-06-04 20:19:18 +08:00
QString filePath = dir.filePath(globalSettingsFile);
2014-06-25 04:11:11 +08:00
2015-06-04 20:19:18 +08:00
// If no settings file exist -- use the default one
2014-12-03 06:47:55 +08:00
if (!QFile(filePath).exists())
{
2015-06-04 20:19:18 +08:00
qDebug() << "No settings file found, using defaults";
filePath = ":/conf/" + globalSettingsFile;
2014-06-25 04:11:11 +08:00
}
qDebug() << "Loading settings from " + filePath;
2014-06-25 04:11:11 +08:00
QSettings s(filePath, QSettings::IniFormat);
2015-06-05 21:24:02 +08:00
s.beginGroup("Login");
autoLogin = s.value("autoLogin", false).toBool();
s.endGroup();
2014-06-25 04:11:11 +08:00
s.beginGroup("DHT Server");
if (s.value("useCustomList").toBool())
{
useCustomDhtList = true;
qDebug() << "Using custom bootstrap nodes list";
int serverListSize = s.beginReadArray("dhtServerList");
2015-04-24 19:01:50 +08:00
for (int i = 0; i < serverListSize; i ++)
{
s.setArrayIndex(i);
DhtServer server;
server.name = s.value("name").toString();
server.userId = s.value("userId").toString();
server.address = s.value("address").toString();
server.port = s.value("port").toInt();
dhtServerList << server;
}
s.endArray();
2014-06-25 04:11:11 +08:00
}
else
2015-04-24 19:01:50 +08:00
{
useCustomDhtList=false;
2015-04-24 19:01:50 +08:00
}
2014-06-25 04:11:11 +08:00
s.endGroup();
s.beginGroup("General");
2014-07-02 06:47:06 +08:00
enableIPv6 = s.value("enableIPv6", true).toBool();
translation = s.value("translation", "en").toString();
showSystemTray = s.value("showSystemTray", SHOW_SYSTEM_TRAY_DEFAULT).toBool();
2014-07-13 04:58:58 +08:00
makeToxPortable = s.value("makeToxPortable", false).toBool();
autostartInTray = s.value("autostartInTray", false).toBool();
2015-06-05 22:27:15 +08:00
closeToTray = s.value("closeToTray", false).toBool();
forceTCP = s.value("forceTCP", false).toBool();
2014-12-28 21:04:32 +08:00
setProxyType(s.value("proxyType", static_cast<int>(ProxyType::ptNone)).toInt());
proxyAddr = s.value("proxyAddr", "").toString();
proxyPort = s.value("proxyPort", 0).toInt();
if (currentProfile.isEmpty())
{
currentProfile = s.value("currentProfile", "").toString();
currentProfileId = makeProfileId(currentProfile);
}
2014-11-12 20:56:24 +08:00
autoAwayTime = s.value("autoAwayTime", 10).toInt();
checkUpdates = s.value("checkUpdates", false).toBool();
showWindow = s.value("showWindow", true).toBool();
showInFront = s.value("showInFront", false).toBool();
notifySound = s.value("notifySound", true).toBool();
groupAlwaysNotify = s.value("groupAlwaysNotify", false).toBool();
2014-11-11 06:45:09 +08:00
fauxOfflineMessaging = s.value("fauxOfflineMessaging", true).toBool();
2014-11-17 18:10:38 +08:00
autoSaveEnabled = s.value("autoSaveEnabled", false).toBool();
globalAutoAcceptDir = s.value("globalAutoAcceptDir",
QStandardPaths::locate(QStandardPaths::HomeLocation, QString(), QStandardPaths::LocateDirectory)
).toString();
separateWindow = s.value("separateWindow", false).toBool();
dontGroupWindows = s.value("dontGroupWindows", true).toBool();
groupchatPosition = s.value("groupchatPosition", true).toBool();
2014-06-25 04:11:11 +08:00
s.endGroup();
2014-11-12 20:56:24 +08:00
s.beginGroup("Advanced");
int sType = s.value("dbSyncType", static_cast<int>(Db::syncType::stFull)).toInt();
setDbSyncType(sType);
s.endGroup();
2014-06-25 04:11:11 +08:00
s.beginGroup("Widgets");
QList<QString> objectNames = s.childKeys();
2015-04-24 19:01:50 +08:00
for (const QString& name : objectNames)
2014-06-25 04:11:11 +08:00
widgetSettings[name] = s.value(name).toByteArray();
2015-04-24 19:01:50 +08:00
2014-06-25 04:11:11 +08:00
s.endGroup();
s.beginGroup("GUI");
smileyPack = s.value("smileyPack", ":/smileys/TwitterEmojiSVG/emoticons.xml").toString();
emojiFontPointSize = s.value("emojiFontPointSize", 16).toInt();
2014-06-25 04:11:11 +08:00
firstColumnHandlePos = s.value("firstColumnHandlePos", 50).toInt();
secondColumnHandlePosFromRight = s.value("secondColumnHandlePosFromRight", 50).toInt();
timestampFormat = s.value("timestampFormat", "hh:mm:ss").toString();
dateFormat = s.value("dateFormat", "dddd, MMMM d, yyyy").toString();
2014-06-25 04:11:11 +08:00
minimizeOnClose = s.value("minimizeOnClose", false).toBool();
2014-10-20 19:50:12 +08:00
minimizeToTray = s.value("minimizeToTray", false).toBool();
2014-12-12 03:34:12 +08:00
lightTrayIcon = s.value("lightTrayIcon", false).toBool();
useEmoticons = s.value("useEmoticons", true).toBool();
statusChangeNotificationEnabled = s.value("statusChangeNotificationEnabled", false).toBool();
2014-11-16 04:30:20 +08:00
themeColor = s.value("themeColor", 0).toInt();
style = s.value("style", "").toString();
if (style == "") // Default to Fusion if available, otherwise no style
{
if (QStyleFactory::keys().contains("Fusion"))
style = "Fusion";
else
style = "None";
}
2014-08-11 23:33:32 +08:00
s.endGroup();
s.beginGroup("State");
windowGeometry = s.value("windowGeometry", QByteArray()).toByteArray();
windowState = s.value("windowState", QByteArray()).toByteArray();
2014-08-11 20:07:27 +08:00
splitterState = s.value("splitterState", QByteArray()).toByteArray();
2015-06-19 22:58:48 +08:00
dialogGeometry = s.value("dialogGeometry", QByteArray()).toByteArray();
dialogSplitterState = s.value("dialogSplitterState", QByteArray()).toByteArray();
dialogSettingsGeometry = s.value("dialogSettingsGeometry", QByteArray()).toByteArray();
2014-06-25 04:11:11 +08:00
s.endGroup();
2014-10-29 04:21:37 +08:00
s.beginGroup("Audio");
inDev = s.value("inDev", "").toString();
outDev = s.value("outDev", "").toString();
filterAudio = s.value("filterAudio", false).toBool();
2014-10-29 04:21:37 +08:00
s.endGroup();
s.beginGroup("Video");
2015-05-14 10:46:28 +08:00
videoDev = s.value("videoDev", "").toString();
camVideoRes = s.value("camVideoRes",QSize()).toSize();
s.endGroup();
// Read the embedded DHT bootsrap nodes list if needed
if (dhtServerList.isEmpty())
{
QSettings rcs(":/conf/settings.ini", QSettings::IniFormat);
rcs.beginGroup("DHT Server");
int serverListSize = rcs.beginReadArray("dhtServerList");
2015-04-24 19:01:50 +08:00
for (int i = 0; i < serverListSize; i ++)
{
rcs.setArrayIndex(i);
DhtServer server;
server.name = rcs.value("name").toString();
server.userId = rcs.value("userId").toString();
server.address = rcs.value("address").toString();
server.port = rcs.value("port").toInt();
dhtServerList << server;
}
rcs.endArray();
rcs.endGroup();
}
2014-06-25 04:11:11 +08:00
loaded = true;
}
void Settings::loadPersonnal()
{
Profile* profile = Nexus::getProfile();
if (!profile)
{
qCritical() << "No active profile, couldn't load personnal settings";
return;
}
loadPersonnal(profile);
2014-06-25 04:11:11 +08:00
}
void Settings::loadPersonnal(Profile* profile)
2014-06-25 04:11:11 +08:00
{
QMutexLocker locker{&bigLock};
2015-06-06 00:01:50 +08:00
QDir dir(getSettingsDirPath());
QString filePath = dir.filePath(globalSettingsFile);
2014-06-25 04:11:11 +08:00
// load from a profile specific friend data list if possible
QString tmp = dir.filePath(profile->getName() + ".ini");
if (QFile(tmp).exists()) // otherwise, filePath remains the global file
filePath = tmp;
2015-06-06 00:01:50 +08:00
qDebug()<<"Loading personnal settings from"<<filePath;
SettingsSerializer ps(filePath, profile->getPassword());
ps.load();
friendLst.clear();
ps.beginGroup("Friends");
int size = ps.beginReadArray("Friend");
friendLst.reserve(size);
for (int i = 0; i < size; i ++)
{
ps.setArrayIndex(i);
friendProp fp;
fp.addr = ps.value("addr").toString();
fp.alias = ps.value("alias").toString();
fp.autoAcceptDir = ps.value("autoAcceptDir").toString();
fp.circleID = ps.value("circle", -1).toInt();
if (getEnableLogging())
fp.activity = ps.value("activity", QDate()).toDate();
friendLst[ToxId(fp.addr).publicKey] = fp;
}
ps.endArray();
ps.endGroup();
ps.beginGroup("General");
compactLayout = ps.value("compactLayout", true).toBool();
ps.endGroup();
ps.beginGroup("Circles");
size = ps.beginReadArray("Circle");
circleLst.clear();
circleLst.reserve(size);
for (int i = 0; i < size; i ++)
{
ps.setArrayIndex(i);
circleProp cp;
cp.name = ps.value("name").toString();
cp.expanded = ps.value("expanded", true).toBool();
circleLst.push_back(cp);
}
ps.endArray();
ps.endGroup();
ps.beginGroup("Privacy");
typingNotification = ps.value("typingNotification", true).toBool();
enableLogging = ps.value("enableLogging", true).toBool();
ps.endGroup();
}
void Settings::saveGlobal()
{
if (QThread::currentThread() != settingsThread)
return (void) QMetaObject::invokeMethod(&getInstance(), "saveGlobal");
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
QString path = getSettingsDirPath() + globalSettingsFile;
qDebug() << "Saving global settings at " + path;
2014-07-13 04:58:58 +08:00
QSettings s(path, QSettings::IniFormat);
2014-06-25 04:11:11 +08:00
s.clear();
2015-06-05 21:24:02 +08:00
s.beginGroup("Login");
s.setValue("autoLogin", autoLogin);
s.endGroup();
2014-06-25 04:11:11 +08:00
s.beginGroup("DHT Server");
s.setValue("useCustomList", useCustomDhtList);
2014-06-25 04:11:11 +08:00
s.beginWriteArray("dhtServerList", dhtServerList.size());
2015-04-24 19:01:50 +08:00
for (int i = 0; i < dhtServerList.size(); i ++)
{
2014-06-25 04:11:11 +08:00
s.setArrayIndex(i);
s.setValue("name", dhtServerList[i].name);
s.setValue("userId", dhtServerList[i].userId);
s.setValue("address", dhtServerList[i].address);
s.setValue("port", dhtServerList[i].port);
}
s.endArray();
s.endGroup();
s.beginGroup("General");
2014-07-02 06:47:06 +08:00
s.setValue("enableIPv6", enableIPv6);
s.setValue("translation",translation);
2014-07-13 04:58:58 +08:00
s.setValue("makeToxPortable",makeToxPortable);
s.setValue("showSystemTray", showSystemTray);
s.setValue("autostartInTray",autostartInTray);
2014-10-20 03:47:06 +08:00
s.setValue("closeToTray", closeToTray);
2014-12-28 20:32:25 +08:00
s.setValue("proxyType", static_cast<int>(proxyType));
s.setValue("forceTCP", forceTCP);
s.setValue("proxyAddr", proxyAddr);
s.setValue("proxyPort", proxyPort);
s.setValue("currentProfile", currentProfile);
2014-10-16 17:47:58 +08:00
s.setValue("autoAwayTime", autoAwayTime);
s.setValue("checkUpdates", checkUpdates);
s.setValue("showWindow", showWindow);
s.setValue("showInFront", showInFront);
s.setValue("notifySound", notifySound);
s.setValue("groupAlwaysNotify", groupAlwaysNotify);
2014-11-10 21:06:35 +08:00
s.setValue("fauxOfflineMessaging", fauxOfflineMessaging);
s.setValue("separateWindow", separateWindow);
2015-06-19 22:58:48 +08:00
s.setValue("dontGroupWindows", dontGroupWindows);
s.setValue("groupchatPosition", groupchatPosition);
2014-11-17 18:10:38 +08:00
s.setValue("autoSaveEnabled", autoSaveEnabled);
s.setValue("globalAutoAcceptDir", globalAutoAcceptDir);
2014-06-25 04:11:11 +08:00
s.endGroup();
2014-11-12 20:56:24 +08:00
s.beginGroup("Advanced");
s.setValue("dbSyncType", static_cast<int>(dbSyncType));
s.endGroup();
2014-06-25 04:11:11 +08:00
s.beginGroup("Widgets");
const QList<QString> widgetNames = widgetSettings.keys();
2015-04-24 19:01:50 +08:00
for (const QString& name : widgetNames)
2014-06-25 04:11:11 +08:00
s.setValue(name, widgetSettings.value(name));
s.endGroup();
s.beginGroup("GUI");
s.setValue("smileyPack", smileyPack);
s.setValue("emojiFontPointSize", emojiFontPointSize);
s.setValue("firstColumnHandlePos", firstColumnHandlePos);
s.setValue("secondColumnHandlePosFromRight", secondColumnHandlePosFromRight);
s.setValue("timestampFormat", timestampFormat);
s.setValue("dateFormat", dateFormat);
2014-06-25 04:11:11 +08:00
s.setValue("minimizeOnClose", minimizeOnClose);
2014-10-20 19:50:12 +08:00
s.setValue("minimizeToTray", minimizeToTray);
2014-12-12 03:34:12 +08:00
s.setValue("lightTrayIcon", lightTrayIcon);
s.setValue("useEmoticons", useEmoticons);
2014-11-16 04:30:20 +08:00
s.setValue("themeColor", themeColor);
s.setValue("style", style);
s.setValue("statusChangeNotificationEnabled", statusChangeNotificationEnabled);
2014-08-11 23:33:32 +08:00
s.endGroup();
s.beginGroup("State");
s.setValue("windowGeometry", windowGeometry);
s.setValue("windowState", windowState);
2014-08-11 20:07:27 +08:00
s.setValue("splitterState", splitterState);
s.setValue("dialogGeometry", dialogGeometry);
s.setValue("dialogSplitterState", dialogSplitterState);
s.setValue("dialogSettingsGeometry", dialogSettingsGeometry);
2014-06-25 04:11:11 +08:00
s.endGroup();
2014-10-29 04:21:37 +08:00
s.beginGroup("Audio");
s.setValue("inDev", inDev);
s.setValue("outDev", outDev);
s.setValue("filterAudio", filterAudio);
2014-10-29 04:21:37 +08:00
s.endGroup();
s.beginGroup("Video");
2015-05-14 10:46:28 +08:00
s.setValue("videoDev", videoDev);
s.setValue("camVideoRes",camVideoRes);
s.endGroup();
}
void Settings::savePersonal()
{
savePersonal(Nexus::getProfile());
}
void Settings::savePersonal(Profile* profile)
{
if (!profile)
{
qDebug() << "Could not save personal settings because there is no active profile";
return;
}
savePersonal(profile->getName(), profile->getPassword());
}
void Settings::savePersonal(QString profileName, QString password)
{
if (QThread::currentThread() != settingsThread)
return (void) QMetaObject::invokeMethod(&getInstance(), "savePersonal",
Q_ARG(QString, profileName), Q_ARG(QString, password));
QMutexLocker locker{&bigLock};
QString path = getSettingsDirPath() + profileName + ".ini";
qDebug() << "Saving personal settings at " << path;
SettingsSerializer ps(path, password);
ps.beginGroup("Friends");
ps.beginWriteArray("Friend", friendLst.size());
int index = 0;
for (auto& frnd : friendLst)
{
ps.setArrayIndex(index);
ps.setValue("addr", frnd.addr);
ps.setValue("alias", frnd.alias);
ps.setValue("autoAcceptDir", frnd.autoAcceptDir);
ps.setValue("circle", frnd.circleID);
if (getEnableLogging())
ps.setValue("activity", frnd.activity);
index++;
}
ps.endArray();
ps.endGroup();
ps.beginGroup("General");
ps.setValue("compactLayout", compactLayout);
ps.endGroup();
ps.beginGroup("Circles");
ps.beginWriteArray("Circle", circleLst.size());
index = 0;
for (auto& circle : circleLst)
{
ps.setArrayIndex(index);
ps.setValue("name", circle.name);
ps.setValue("expanded", circle.expanded);
index++;
}
ps.endArray();
ps.endGroup();
ps.beginGroup("Privacy");
ps.setValue("typingNotification", typingNotification);
ps.setValue("enableLogging", enableLogging);
ps.endGroup();
ps.save();
2014-06-25 04:11:11 +08:00
}
uint32_t Settings::makeProfileId(const QString& profile)
{
QByteArray data = QCryptographicHash::hash(profile.toUtf8(), QCryptographicHash::Md5);
const uint32_t* dwords = (uint32_t*)data.constData();
return dwords[0] ^ dwords[1] ^ dwords[2] ^ dwords[3];
2014-06-25 04:11:11 +08:00
}
QString Settings::getSettingsDirPath()
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
2014-07-13 04:58:58 +08:00
if (makeToxPortable)
2015-06-05 18:44:22 +08:00
return QString(".")+QDir::separator();
2014-07-13 04:58:58 +08:00
2014-06-25 04:11:11 +08:00
// workaround for https://bugreports.qt-project.org/browse/QTBUG-38845
#ifdef Q_OS_WIN
2015-06-05 18:44:22 +08:00
return QDir::cleanPath(QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + QDir::separator()
2015-06-05 22:24:47 +08:00
+ "AppData" + QDir::separator() + "Roaming" + QDir::separator() + "tox")+QDir::separator();
2014-06-25 04:11:11 +08:00
#else
2015-06-05 18:44:22 +08:00
return QDir::cleanPath(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation)
2015-06-05 22:24:47 +08:00
+ QDir::separator() + "tox")+QDir::separator();
2014-06-25 04:11:11 +08:00
#endif
}
2014-09-24 23:55:54 +08:00
QPixmap Settings::getSavedAvatar(const QString &ownerId)
2014-09-24 22:51:16 +08:00
{
return HistoryKeeper::getInstance()->getSavedAvatar(ownerId);
2014-09-24 22:51:16 +08:00
}
2014-09-24 23:55:54 +08:00
void Settings::saveAvatar(QPixmap& pic, const QString& ownerId)
2014-09-24 22:51:16 +08:00
{
HistoryKeeper::getInstance()->saveAvatar(pic,ownerId);
2014-09-24 22:51:16 +08:00
}
void Settings::saveAvatarHash(const QByteArray& hash, const QString& ownerId)
{
HistoryKeeper::getInstance()->saveAvatarHash(hash,ownerId);
}
QByteArray Settings::getAvatarHash(const QString& ownerId)
{
return HistoryKeeper::getInstance()->getAvatarHash(ownerId);
}
2015-06-05 22:24:47 +08:00
const QList<DhtServer>& Settings::getDhtServerList() const
2014-06-25 04:11:11 +08:00
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
2014-06-25 04:11:11 +08:00
return dhtServerList;
}
void Settings::setDhtServerList(const QList<DhtServer>& newDhtServerList)
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
2014-06-25 04:11:11 +08:00
dhtServerList = newDhtServerList;
emit dhtServerListChanged();
}
2014-07-02 06:47:06 +08:00
bool Settings::getEnableIPv6() const
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
2014-07-02 06:47:06 +08:00
return enableIPv6;
}
void Settings::setEnableIPv6(bool newValue)
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
2014-07-02 06:47:06 +08:00
enableIPv6 = newValue;
}
2014-07-13 04:58:58 +08:00
bool Settings::getMakeToxPortable() const
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
2014-07-13 04:58:58 +08:00
return makeToxPortable;
}
void Settings::setMakeToxPortable(bool newValue)
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
2015-06-06 00:53:27 +08:00
QFile(getSettingsDirPath()+globalSettingsFile).remove();
2014-07-13 04:58:58 +08:00
makeToxPortable = newValue;
saveGlobal();
2014-07-13 04:58:58 +08:00
}
2014-12-17 21:44:23 +08:00
bool Settings::getAutorun() const
{
#ifdef QTOX_PLATFORM_EXT
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
2014-12-17 21:44:23 +08:00
return Platform::getAutorun();
#else
return false;
#endif
}
void Settings::setAutorun(bool newValue)
{
#ifdef QTOX_PLATFORM_EXT
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
2014-12-17 21:44:23 +08:00
Platform::setAutorun(newValue);
2015-02-23 00:24:01 +08:00
#else
Q_UNUSED(newValue);
2014-12-17 21:44:23 +08:00
#endif
}
bool Settings::getAutostartInTray() const
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
return autostartInTray;
}
QString Settings::getStyle() const
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
return style;
}
void Settings::setStyle(const QString& newStyle)
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
style = newStyle;
}
bool Settings::getShowSystemTray() const
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
return showSystemTray;
}
void Settings::setShowSystemTray(const bool& newValue)
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
showSystemTray = newValue;
}
void Settings::setUseEmoticons(bool newValue)
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
useEmoticons = newValue;
}
bool Settings::getUseEmoticons() const
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
return useEmoticons;
}
void Settings::setAutoSaveEnabled(bool newValue)
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
autoSaveEnabled = newValue;
}
bool Settings::getAutoSaveEnabled() const
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
return autoSaveEnabled;
}
void Settings::setAutostartInTray(bool newValue)
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
autostartInTray = newValue;
}
2014-10-20 03:47:06 +08:00
bool Settings::getCloseToTray() const
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
2014-10-20 03:47:06 +08:00
return closeToTray;
}
void Settings::setCloseToTray(bool newValue)
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
2014-10-20 03:47:06 +08:00
closeToTray = newValue;
}
2014-10-20 19:50:12 +08:00
bool Settings::getMinimizeToTray() const
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
2014-10-20 19:50:12 +08:00
return minimizeToTray;
}
void Settings::setMinimizeToTray(bool newValue)
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
2014-10-20 19:50:12 +08:00
minimizeToTray = newValue;
}
2014-12-12 03:34:12 +08:00
bool Settings::getLightTrayIcon() const
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
2014-12-12 03:34:12 +08:00
return lightTrayIcon;
}
void Settings::setLightTrayIcon(bool newValue)
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
2014-12-12 03:34:12 +08:00
lightTrayIcon = newValue;
}
bool Settings::getStatusChangeNotificationEnabled() const
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
return statusChangeNotificationEnabled;
}
void Settings::setStatusChangeNotificationEnabled(bool newValue)
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
statusChangeNotificationEnabled = newValue;
}
bool Settings::getShowInFront() const
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
return showInFront;
}
void Settings::setShowInFront(bool newValue)
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
showInFront = newValue;
}
bool Settings::getNotifySound() const
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
return notifySound;
}
void Settings::setNotifySound(bool newValue)
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
notifySound = newValue;
}
bool Settings::getGroupAlwaysNotify() const
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
return groupAlwaysNotify;
}
void Settings::setGroupAlwaysNotify(bool newValue)
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
groupAlwaysNotify = newValue;
}
QString Settings::getTranslation() const
2014-07-05 01:22:43 +08:00
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
return translation;
2014-07-05 01:22:43 +08:00
}
void Settings::setTranslation(QString newValue)
2014-07-05 01:22:43 +08:00
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
translation = newValue;
2014-10-06 04:49:44 +08:00
}
bool Settings::getForceTCP() const
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
2014-10-06 04:49:44 +08:00
return forceTCP;
}
void Settings::setForceTCP(bool newValue)
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
2014-10-06 04:49:44 +08:00
forceTCP = newValue;
}
2014-12-28 20:32:25 +08:00
ProxyType Settings::getProxyType() const
2014-10-07 10:09:15 +08:00
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
2014-12-28 20:32:25 +08:00
return proxyType;
2014-10-07 10:09:15 +08:00
}
2014-12-28 20:32:25 +08:00
void Settings::setProxyType(int newValue)
2014-10-07 10:09:15 +08:00
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
2014-12-28 21:04:32 +08:00
if (newValue >= 0 && newValue <= 2)
2014-12-28 20:32:25 +08:00
proxyType = static_cast<ProxyType>(newValue);
else
proxyType = ProxyType::ptNone;
2014-10-07 10:09:15 +08:00
}
2014-10-06 04:49:44 +08:00
QString Settings::getProxyAddr() const
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
2014-10-06 04:49:44 +08:00
return proxyAddr;
}
void Settings::setProxyAddr(const QString& newValue)
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
2014-10-06 04:49:44 +08:00
proxyAddr = newValue;
}
int Settings::getProxyPort() const
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
2014-10-06 04:49:44 +08:00
return proxyPort;
}
void Settings::setProxyPort(int newValue)
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
2014-10-06 04:49:44 +08:00
proxyPort = newValue;
2014-07-05 01:22:43 +08:00
}
QString Settings::getCurrentProfile() const
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
return currentProfile;
}
uint32_t Settings::getCurrentProfileId() const
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
return currentProfileId;
}
void Settings::setCurrentProfile(QString profile)
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
currentProfile = profile;
currentProfileId = makeProfileId(currentProfile);
}
2014-06-25 04:11:11 +08:00
bool Settings::getEnableLogging() const
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
2014-06-25 04:11:11 +08:00
return enableLogging;
}
void Settings::setEnableLogging(bool newValue)
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
2014-06-25 04:11:11 +08:00
enableLogging = newValue;
}
2014-11-12 20:56:24 +08:00
Db::syncType Settings::getDbSyncType() const
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
2014-11-12 20:56:24 +08:00
return dbSyncType;
}
void Settings::setDbSyncType(int newValue)
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
2014-11-12 20:56:24 +08:00
if (newValue >= 0 && newValue <= 2)
dbSyncType = static_cast<Db::syncType>(newValue);
else
dbSyncType = Db::syncType::stFull;
}
2014-10-16 17:47:58 +08:00
int Settings::getAutoAwayTime() const
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
2014-10-16 17:47:58 +08:00
return autoAwayTime;
}
void Settings::setAutoAwayTime(int newValue)
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
2014-10-16 17:47:58 +08:00
if (newValue < 0)
newValue = 10;
2015-04-24 19:01:50 +08:00
2014-10-16 17:47:58 +08:00
autoAwayTime = newValue;
}
QString Settings::getAutoAcceptDir(const ToxId& id) const
2014-10-18 11:02:13 +08:00
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
2014-11-17 18:10:38 +08:00
QString key = id.publicKey;
auto it = friendLst.find(key);
if (it != friendLst.end())
return it->autoAcceptDir;
return QString();
2014-10-18 11:02:13 +08:00
}
void Settings::setAutoAcceptDir(const ToxId &id, const QString& dir)
2014-10-18 11:02:13 +08:00
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
2014-11-17 18:10:38 +08:00
QString key = id.publicKey;
auto it = friendLst.find(key);
if (it != friendLst.end())
{
it->autoAcceptDir = dir;
}
else
{
2014-11-17 18:10:38 +08:00
updateFriendAdress(id.toString());
setAutoAcceptDir(id, dir);
}
2014-10-18 11:02:13 +08:00
}
2014-10-20 12:25:52 +08:00
QString Settings::getGlobalAutoAcceptDir() const
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
2014-10-20 12:25:52 +08:00
return globalAutoAcceptDir;
}
void Settings::setGlobalAutoAcceptDir(const QString& newValue)
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
2014-10-20 12:25:52 +08:00
globalAutoAcceptDir = newValue;
}
2014-06-25 04:11:11 +08:00
void Settings::setWidgetData(const QString& uniqueName, const QByteArray& data)
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
2014-06-25 04:11:11 +08:00
widgetSettings[uniqueName] = data;
}
QByteArray Settings::getWidgetData(const QString& uniqueName) const
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
2014-06-25 04:11:11 +08:00
return widgetSettings.value(uniqueName);
}
2014-07-25 20:52:14 +08:00
QString Settings::getSmileyPack() const
2014-06-25 04:11:11 +08:00
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
2014-06-25 04:11:11 +08:00
return smileyPack;
}
2014-07-25 20:52:14 +08:00
void Settings::setSmileyPack(const QString &value)
2014-06-25 04:11:11 +08:00
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
2014-06-25 04:11:11 +08:00
smileyPack = value;
emit smileyPackChanged();
}
int Settings::getEmojiFontPointSize() const
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
2014-06-25 04:11:11 +08:00
return emojiFontPointSize;
}
void Settings::setEmojiFontPointSize(int value)
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
2014-06-25 04:11:11 +08:00
emojiFontPointSize = value;
emit emojiFontChanged();
}
int Settings::getFirstColumnHandlePos() const
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
2014-06-25 04:11:11 +08:00
return firstColumnHandlePos;
}
void Settings::setFirstColumnHandlePos(const int pos)
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
2014-06-25 04:11:11 +08:00
firstColumnHandlePos = pos;
}
int Settings::getSecondColumnHandlePosFromRight() const
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
2014-06-25 04:11:11 +08:00
return secondColumnHandlePosFromRight;
}
void Settings::setSecondColumnHandlePosFromRight(const int pos)
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
2014-06-25 04:11:11 +08:00
secondColumnHandlePosFromRight = pos;
}
const QString& Settings::getTimestampFormat() const
2014-06-25 04:11:11 +08:00
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
2014-06-25 04:11:11 +08:00
return timestampFormat;
}
void Settings::setTimestampFormat(const QString &format)
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
2014-06-25 04:11:11 +08:00
timestampFormat = format;
}
const QString& Settings::getDateFormat() const
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
return dateFormat;
}
void Settings::setDateFormat(const QString &format)
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
dateFormat = format;
}
QByteArray Settings::getWindowGeometry() const
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
return windowGeometry;
}
void Settings::setWindowGeometry(const QByteArray &value)
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
windowGeometry = value;
}
QByteArray Settings::getWindowState() const
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
return windowState;
}
void Settings::setWindowState(const QByteArray &value)
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
windowState = value;
}
bool Settings::getCheckUpdates() const
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
return checkUpdates;
}
void Settings::setCheckUpdates(bool newValue)
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
checkUpdates = newValue;
}
bool Settings::getShowWindow() const
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
return showWindow;
}
void Settings::setShowWindow(bool newValue)
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
showWindow = newValue;
}
2014-08-11 20:07:27 +08:00
QByteArray Settings::getSplitterState() const
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
2014-08-11 20:07:27 +08:00
return splitterState;
}
void Settings::setSplitterState(const QByteArray &value)
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
2014-08-11 20:07:27 +08:00
splitterState = value;
}
2015-06-19 22:58:48 +08:00
QByteArray Settings::getDialogGeometry() const
{
QMutexLocker locker{&bigLock};
return dialogGeometry;
}
void Settings::setDialogGeometry(const QByteArray &value)
{
QMutexLocker locker{&bigLock};
dialogGeometry = value;
}
QByteArray Settings::getDialogSplitterState() const
{
QMutexLocker locker{&bigLock};
return dialogSplitterState;
}
void Settings::setDialogSplitterState(const QByteArray &value)
{
QMutexLocker locker{&bigLock};
dialogSplitterState = value;
}
QByteArray Settings::getDialogSettingsGeometry() const
{
QMutexLocker locker{&bigLock};
return dialogSettingsGeometry;
}
void Settings::setDialogSettingsGeometry(const QByteArray &value)
{
QMutexLocker locker{&bigLock};
dialogSettingsGeometry = value;
}
2014-06-25 04:11:11 +08:00
bool Settings::isMinimizeOnCloseEnabled() const
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
2014-06-25 04:11:11 +08:00
return minimizeOnClose;
}
void Settings::setMinimizeOnClose(bool newValue)
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
2014-06-25 04:11:11 +08:00
minimizeOnClose = newValue;
}
bool Settings::isTypingNotificationEnabled() const
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
2014-06-25 04:11:11 +08:00
return typingNotification;
}
void Settings::setTypingNotification(bool enabled)
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
2014-06-25 04:11:11 +08:00
typingNotification = enabled;
}
2014-10-29 04:21:37 +08:00
QString Settings::getInDev() const
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
2014-10-29 04:21:37 +08:00
return inDev;
}
void Settings::setInDev(const QString& deviceSpecifier)
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
2014-10-29 04:21:37 +08:00
inDev = deviceSpecifier;
}
2015-05-14 10:46:28 +08:00
QString Settings::getVideoDev() const
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
2015-05-14 10:46:28 +08:00
return videoDev;
}
void Settings::setVideoDev(const QString& deviceSpecifier)
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
2015-05-14 10:46:28 +08:00
videoDev = deviceSpecifier;
}
2014-10-29 04:21:37 +08:00
QString Settings::getOutDev() const
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
2014-10-29 04:21:37 +08:00
return outDev;
}
void Settings::setOutDev(const QString& deviceSpecifier)
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
2014-10-29 04:21:37 +08:00
outDev = deviceSpecifier;
}
2014-12-17 08:05:13 +08:00
bool Settings::getFilterAudio() const
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
return filterAudio;
}
2014-12-17 08:05:13 +08:00
void Settings::setFilterAudio(bool newValue)
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
filterAudio = newValue;
}
QSize Settings::getCamVideoRes() const
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
return camVideoRes;
}
void Settings::setCamVideoRes(QSize newValue)
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
camVideoRes = newValue;
}
QString Settings::getFriendAdress(const QString &publicKey) const
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
QString key = ToxId(publicKey).publicKey;
auto it = friendLst.find(key);
if (it != friendLst.end())
return it->addr;
return QString();
}
void Settings::updateFriendAdress(const QString &newAddr)
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
QString key = ToxId(newAddr).publicKey;
auto it = friendLst.find(key);
if (it != friendLst.end())
{
it->addr = newAddr;
2015-04-24 19:01:50 +08:00
}
else
{
friendProp fp;
fp.addr = newAddr;
fp.alias = "";
2014-11-17 18:10:38 +08:00
fp.autoAcceptDir = "";
friendLst[newAddr] = fp;
}
}
QString Settings::getFriendAlias(const ToxId &id) const
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
QString key = id.publicKey;
auto it = friendLst.find(key);
if (it != friendLst.end())
return it->alias;
return QString();
}
void Settings::setFriendAlias(const ToxId &id, const QString &alias)
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
QString key = id.publicKey;
auto it = friendLst.find(key);
if (it != friendLst.end())
{
it->alias = alias;
2015-04-24 19:01:50 +08:00
}
else
{
friendProp fp;
fp.addr = key;
fp.alias = alias;
2014-11-17 18:10:38 +08:00
fp.autoAcceptDir = "";
friendLst[key] = fp;
}
}
2014-11-10 21:06:35 +08:00
int Settings::getFriendCircleID(const ToxId &id) const
{
QString key = id.publicKey;
auto it = friendLst.find(key);
if (it != friendLst.end())
return it->circleID;
return -1;
}
void Settings::setFriendCircleID(const ToxId &id, int circleID)
{
QString key = id.publicKey;
auto it = friendLst.find(key);
if (it != friendLst.end())
{
it->circleID = circleID;
}
2015-06-06 01:38:07 +08:00
else
{
friendProp fp;
fp.addr = key;
fp.alias = "";
fp.autoAcceptDir = "";
fp.circleID = circleID;
2015-06-06 01:38:07 +08:00
friendLst[key] = fp;
}
}
QDate Settings::getFriendActivity(const ToxId &id) const
{
QString key = id.publicKey;
auto it = friendLst.find(key);
if (it != friendLst.end())
return it->activity;
return QDate();
}
void Settings::setFriendActivity(const ToxId &id, const QDate &activity)
{
QString key = id.publicKey;
auto it = friendLst.find(key);
if (it != friendLst.end())
{
it->activity = activity;
}
else
{
friendProp fp;
fp.addr = key;
fp.alias = "";
fp.autoAcceptDir = "";
fp.circleID = -1;
fp.activity = activity;
friendLst[key] = fp;
}
}
void Settings::removeFriendSettings(const ToxId &id)
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
QString key = id.publicKey;
friendLst.remove(key);
}
2014-11-10 21:06:35 +08:00
bool Settings::getFauxOfflineMessaging() const
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
2014-11-10 21:06:35 +08:00
return fauxOfflineMessaging;
}
void Settings::setFauxOfflineMessaging(bool value)
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
2014-11-10 21:06:35 +08:00
fauxOfflineMessaging = value;
}
2014-11-16 04:30:20 +08:00
2014-12-11 22:31:01 +08:00
bool Settings::getCompactLayout() const
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
return compactLayout;
}
2014-12-11 22:31:01 +08:00
void Settings::setCompactLayout(bool value)
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
compactLayout = value;
}
bool Settings::getSeparateWindow() const
{
QMutexLocker locker{&bigLock};
return separateWindow;
}
void Settings::setSeparateWindow(bool value)
{
QMutexLocker locker{&bigLock};
separateWindow = value;
}
2015-06-19 22:58:48 +08:00
bool Settings::getDontGroupWindows() const
{
QMutexLocker locker{&bigLock};
return dontGroupWindows;
}
void Settings::setDontGroupWindows(bool value)
{
QMutexLocker locker{&bigLock};
dontGroupWindows = value;
}
bool Settings::getGroupchatPosition() const
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
return groupchatPosition;
}
void Settings::setGroupchatPosition(bool value)
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
groupchatPosition = value;
}
int Settings::getCircleCount() const
{
return circleLst.size();
}
QString Settings::getCircleName(int id) const
{
return circleLst[id].name;
}
void Settings::setCircleName(int id, const QString &name)
{
circleLst[id].name = name;
2015-06-10 07:42:51 +08:00
savePersonal();
}
int Settings::addCircle(const QString &name)
{
circleProp cp;
cp.expanded = false;
if (name.isEmpty())
cp.name = tr("Circle #%1").arg(circleLst.count() + 1);
else
cp.name = name;
circleLst.append(cp);
savePersonal();
return circleLst.count() - 1;
}
bool Settings::getCircleExpanded(int id) const
{
return circleLst[id].expanded;
}
void Settings::setCircleExpanded(int id, bool expanded)
{
circleLst[id].expanded = expanded;
}
int Settings::removeCircle(int id)
{
// Replace index with last one and remove last one instead.
// This gives you contiguous ids all the time.
circleLst[id] = circleLst.last();
circleLst.pop_back();
savePersonal();
return circleLst.count();
}
2014-11-16 04:30:20 +08:00
int Settings::getThemeColor() const
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
2014-11-16 04:30:20 +08:00
return themeColor;
}
void Settings::setThemeColor(const int &value)
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
2014-11-16 04:30:20 +08:00
themeColor = value;
}
2015-06-04 05:20:47 +08:00
2015-06-05 22:27:15 +08:00
bool Settings::getAutoLogin() const
{
QMutexLocker locker{&bigLock};
return autoLogin;
}
void Settings::setAutoLogin(bool state)
{
QMutexLocker locker{&bigLock};
autoLogin = state;
}
2015-06-04 05:20:47 +08:00
void Settings::createPersonal(QString basename)
{
QString path = getSettingsDirPath() + QDir::separator() + basename + ".ini";
qDebug() << "Creating new profile settings in " << path;
QSettings ps(path, QSettings::IniFormat);
ps.beginGroup("Friends");
ps.beginWriteArray("Friend", 0);
ps.endArray();
ps.endGroup();
ps.beginGroup("Privacy");
ps.endGroup();
}
void Settings::createSettingsDir()
{
QString dir = Settings::getSettingsDirPath();
QDir directory(dir);
if (!directory.exists() && !directory.mkpath(directory.absolutePath()))
qCritical() << "Error while creating directory " << dir;
}
2015-06-06 00:01:50 +08:00
void Settings::sync()
{
if (QThread::currentThread() != settingsThread)
{
QMetaObject::invokeMethod(&getInstance(), "sync", Qt::BlockingQueuedConnection);
return;
}
QMutexLocker locker{&bigLock};
qApp->processEvents();
}