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

2405 lines
59 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"
#include "src/widget/style.h"
2015-06-06 07:44:47 +08:00
#include "src/persistence/profilelocker.h"
#include "src/persistence/settingsserializer.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>
#include <QNetworkProxy>
2014-06-25 04:11:11 +08:00
/**
2016-08-01 16:21:23 +08:00
* @var QHash<QString, QByteArray> Settings::widgetSettings
* @brief Assume all widgets have unique names
* @warning Don't use it to save every single thing you want to save, use it
* for some general purpose widgets, such as MainWindows or Splitters,
* which have widget->saveX() and widget->loadX() methods.
*
* @var QString Settings::toxmeInfo
* @brief Toxme info like name@server
*/
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;
}
/**
2016-08-01 16:21:23 +08:00
* @brief Returns the singleton instance.
*/
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();
QString localSettingsPath = qApp->applicationDirPath() + QDir::separator()
+ globalSettingsFile;
if (QFile(localSettingsPath).exists())
{
QSettings ps(localSettingsPath, QSettings::IniFormat);
2016-01-21 11:59:20 +08:00
ps.setIniCodec("UTF-8");
ps.beginGroup("Advanced");
2014-12-03 06:47:55 +08:00
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);
2016-01-21 11:59:20 +08:00
s.setIniCodec("UTF-8");
2015-06-05 21:24:02 +08:00
s.beginGroup("Login");
{
2015-06-05 21:24:02 +08:00
autoLogin = s.value("autoLogin", false).toBool();
}
2015-06-05 21:24:02 +08:00
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 = static_cast<quint16>(s.value("port").toUInt());
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");
{
{
// TODO: values in this block are moved -> remove @ v1.8
enableIPv6 = s.value("enableIPv6", true).toBool();
makeToxPortable = s.value("makeToxPortable", false).toBool();
forceTCP = s.value("forceTCP", false).toBool();
proxyType = static_cast<ProxyType>(s.value("proxyType", 0).toInt());
proxyAddr = s.value("proxyAddr", "").toString();
proxyPort = static_cast<quint16>(s.value("proxyPort", 0).toUInt());
showWindow = s.value("showWindow", true).toBool();
showInFront = s.value("showInFront", false).toBool();
groupAlwaysNotify = s.value("groupAlwaysNotify", false).toBool();
separateWindow = s.value("separateWindow", false).toBool();
dontGroupWindows = s.value("dontGroupWindows", true).toBool();
groupchatPosition = s.value("groupchatPosition", true).toBool();
}
translation = s.value("translation", "en").toString();
showSystemTray = s.value("showSystemTray", true).toBool();
autostartInTray = s.value("autostartInTray", false).toBool();
2015-06-05 22:27:15 +08:00
closeToTray = s.value("closeToTray", false).toBool();
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", true).toBool();
notifySound = s.value("notifySound", true).toBool();
busySound = s.value("busySound", 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();
stylePreference = static_cast<StyleType>(s.value("stylePreference", 1).toInt());
}
2014-06-25 04:11:11 +08:00
s.endGroup();
2014-11-12 20:56:24 +08:00
s.beginGroup("Advanced");
{
// TODO: Default values in this block should be changed @ v1.8
makeToxPortable = s.value("makeToxPortable", makeToxPortable).toBool();
enableIPv6 = s.value("enableIPv6", enableIPv6).toBool();
forceTCP = s.value("forceTCP", forceTCP).toBool();
int type = s.value("dbSyncType", static_cast<int>(Db::syncType::stFull)).toInt();
Db::syncType sType = static_cast<Db::syncType>(type);
2014-11-12 20:56:24 +08:00
setDbSyncType(sType);
}
2014-11-12 20:56:24 +08:00
s.endGroup();
2014-06-25 04:11:11 +08:00
s.beginGroup("Widgets");
{
2014-06-25 04:11:11 +08:00
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();
}
2014-06-25 04:11:11 +08:00
s.endGroup();
s.beginGroup("GUI");
{
// TODO: Default values in this block should be changed @ v1.8
showWindow = s.value("showWindow", showWindow).toBool();
showInFront = s.value("showInFront", showInFront).toBool();
groupAlwaysNotify = s.value("groupAlwaysNotify", groupAlwaysNotify).toBool();
groupchatPosition = s.value("groupchatPosition", groupchatPosition).toBool();
separateWindow = s.value("separateWindow", separateWindow).toBool();
dontGroupWindows = s.value("dontGroupWindows", dontGroupWindows).toBool();
const QString DEFAULT_SMILEYS = ":/smileys/emojione/emoticons.xml";
smileyPack = s.value("smileyPack", DEFAULT_SMILEYS).toString();
if (!SmileyPack::isValid(smileyPack))
smileyPack = DEFAULT_SMILEYS;
emojiFontPointSize = s.value("emojiFontPointSize", 24).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", "yyyy-MM-dd").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("Chat");
{
chatMessageFont = s.value("chatMessageFont", Style::getFont(Style::Big)).value<QFont>();
}
s.endGroup();
2014-08-11 23:33:32 +08:00
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");
{
2014-10-29 04:21:37 +08:00
inDev = s.value("inDev", "").toString();
audioInDevEnabled = s.value("audioInDevEnabled", true).toBool();
2014-10-29 04:21:37 +08:00
outDev = s.value("outDev", "").toString();
audioOutDevEnabled = s.value("audioOutDevEnabled", true).toBool();
audioInGainDecibel = s.value("inGain", 0).toReal();
outVolume = s.value("outVolume", 100).toInt();
}
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", QRect()).toRect();
screenRegion = s.value("screenRegion", QRect()).toRect();
screenGrabbed = s.value("screenGrabbed", false).toBool();
camVideoFPS = static_cast<quint16>(s.value("camVideoFPS", 0).toUInt());
}
s.endGroup();
// Read the embedded DHT bootstrap nodes list if needed
if (dhtServerList.isEmpty())
{
QSettings rcs(":/conf/settings.ini", QSettings::IniFormat);
2016-01-21 11:59:20 +08:00
rcs.setIniCodec("UTF-8");
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 = static_cast<quint16>(rcs.value("port").toUInt());
dhtServerList << server;
}
rcs.endArray();
rcs.endGroup();
}
2014-06-25 04:11:11 +08:00
loaded = true;
}
void Settings::loadPersonal()
{
Profile* profile = Nexus::getProfile();
if (!profile)
{
qCritical() << "No active profile, couldn't load personal settings";
return;
}
loadPersonal(profile);
2014-06-25 04:11:11 +08:00
}
void Settings::loadPersonal(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 personal settings from"<<filePath;
SettingsSerializer ps(filePath, profile->getPassword());
ps.load();
friendLst.clear();
ps.beginGroup("Privacy");
{
typingNotification = ps.value("typingNotification", true).toBool();
enableLogging = ps.value("enableLogging", true).toBool();
}
ps.endGroup();
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();
2015-11-10 04:54:28 +08:00
fp.note = ps.value("note").toString();
fp.autoAcceptDir = ps.value("autoAcceptDir").toString();
if(fp.autoAcceptDir == "")
fp.autoAcceptDir = ps.value("autoAccept").toString();
fp.autoAcceptCall = Settings::AutoAcceptCallFlags(QFlag(ps.value("autoAcceptCall", 0).toInt()));
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("Requests");
{
int size = ps.beginReadArray("Request");
friendRequests.clear();
friendRequests.reserve(size);
for (int i = 0; i < size; i ++)
{
ps.setArrayIndex(i);
Request request;
request.address = ps.value("addr").toString();
request.message = ps.value("message").toString();
request.read = ps.value("read").toBool();
friendRequests.push_back(request);
}
ps.endArray();
}
ps.endGroup();
// TODO: values in this group are moved -> remove @ v1.8
ps.beginGroup("General");
{
compactLayout = ps.value("compactLayout", true).toBool();
}
ps.endGroup();
ps.beginGroup("GUI");
{
// TODO: Default values in this block should be changed @ v1.8
compactLayout = ps.value("compactLayout", compactLayout).toBool();
}
ps.endGroup();
ps.beginGroup("Proxy");
{
int type = ps.value("proxyType", static_cast<int>(getProxyType())).toInt();
setProxyType(static_cast<ProxyType>(type));
proxyAddr = ps.value("proxyAddr", proxyAddr).toString();
proxyPort = static_cast<quint16>(ps.value("proxyPort", proxyPort).toUInt());
}
ps.endGroup();
ps.beginGroup("Circles");
{
int 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();
2016-01-24 05:50:57 +08:00
ps.beginGroup("Toxme");
{
2016-01-24 05:50:57 +08:00
toxmeInfo = ps.value("info", "").toString();
toxmeBio = ps.value("bio", "").toString();
toxmePriv = ps.value("priv", false).toBool();
toxmePass = ps.value("pass", "").toString();
}
2016-01-24 05:50:57 +08:00
ps.endGroup();
}
void Settings::resetToDefault()
{
// To stop saving
loaded = false;
// Remove file with profile settings
QDir dir(getSettingsDirPath());
Profile *profile = Nexus::getProfile();
QString localPath = dir.filePath(profile->getName() + ".ini");
QFile local(localPath);
if (local.exists())
local.remove();
}
/**
2016-08-01 16:21:23 +08:00
* @brief Asynchronous, saves the global settings.
*/
void Settings::saveGlobal()
{
if (QThread::currentThread() != settingsThread)
return (void) QMetaObject::invokeMethod(&getInstance(), "saveGlobal");
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
if (!loaded)
return;
QString path = getSettingsDirPath() + globalSettingsFile;
qDebug() << "Saving global settings at " + path;
2014-07-13 04:58:58 +08:00
QSettings s(path, QSettings::IniFormat);
2016-01-21 11:59:20 +08:00
s.setIniCodec("UTF-8");
2014-06-25 04:11:11 +08:00
s.clear();
2015-06-05 21:24:02 +08:00
s.beginGroup("Login");
{
2015-06-05 21:24:02 +08:00
s.setValue("autoLogin", autoLogin);
}
2015-06-05 21:24:02 +08:00
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();
}
2014-06-25 04:11:11 +08:00
s.endGroup();
s.beginGroup("General");
{
s.setValue("translation",translation);
s.setValue("showSystemTray", showSystemTray);
s.setValue("autostartInTray",autostartInTray);
2014-10-20 03:47:06 +08:00
s.setValue("closeToTray", closeToTray);
s.setValue("currentProfile", currentProfile);
2014-10-16 17:47:58 +08:00
s.setValue("autoAwayTime", autoAwayTime);
s.setValue("checkUpdates", checkUpdates);
s.setValue("notifySound", notifySound);
s.setValue("busySound", busySound);
2014-11-10 21:06:35 +08:00
s.setValue("fauxOfflineMessaging", fauxOfflineMessaging);
2014-11-17 18:10:38 +08:00
s.setValue("autoSaveEnabled", autoSaveEnabled);
s.setValue("globalAutoAcceptDir", globalAutoAcceptDir);
s.setValue("stylePreference", static_cast<int>(stylePreference));
}
2014-06-25 04:11:11 +08:00
s.endGroup();
2014-11-12 20:56:24 +08:00
s.beginGroup("Advanced");
{
s.setValue("makeToxPortable",makeToxPortable);
s.setValue("enableIPv6", enableIPv6);
s.setValue("forceTCP", forceTCP);
2014-11-12 20:56:24 +08:00
s.setValue("dbSyncType", static_cast<int>(dbSyncType));
}
2014-11-12 20:56:24 +08:00
s.endGroup();
2014-06-25 04:11:11 +08:00
s.beginGroup("Widgets");
{
const QList<QString> widgetNames = widgetSettings.keys();
for (const QString& name : widgetNames)
s.setValue(name, widgetSettings.value(name));
}
2014-06-25 04:11:11 +08:00
s.endGroup();
s.beginGroup("GUI");
{
s.setValue("showWindow", showWindow);
s.setValue("showInFront", showInFront);
s.setValue("groupAlwaysNotify", groupAlwaysNotify);
s.setValue("separateWindow", separateWindow);
s.setValue("dontGroupWindows", dontGroupWindows);
s.setValue("groupchatPosition", groupchatPosition);
2014-06-25 04:11:11 +08:00
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("Chat");
{
s.setValue("chatMessageFont", chatMessageFont);
}
s.endGroup();
2014-08-11 23:33:32 +08:00
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");
{
2014-10-29 04:21:37 +08:00
s.setValue("inDev", inDev);
s.setValue("audioInDevEnabled", audioInDevEnabled);
2014-10-29 04:21:37 +08:00
s.setValue("outDev", outDev);
s.setValue("audioOutDevEnabled", audioOutDevEnabled);
s.setValue("inGain", audioInGainDecibel);
s.setValue("outVolume", outVolume);
}
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.setValue("camVideoFPS", camVideoFPS);
s.setValue("screenRegion", screenRegion);
s.setValue("screenGrabbed", screenGrabbed);
}
s.endGroup();
}
/**
2016-08-01 16:21:23 +08:00
* @brief Asynchronous, saves the current profile.
*/
void Settings::savePersonal()
{
savePersonal(Nexus::getProfile());
}
/**
2016-08-01 16:21:23 +08:00
* @brief Asynchronous, saves the profile.
* @param profile Profile to save.
*/
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, const QString &password)
{
if (QThread::currentThread() != settingsThread)
return (void) QMetaObject::invokeMethod(&getInstance(), "savePersonal",
Q_ARG(QString, profileName), Q_ARG(QString, password));
QMutexLocker locker{&bigLock};
if (!loaded)
return;
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);
2015-11-10 04:54:28 +08:00
ps.setValue("note", frnd.note);
ps.setValue("autoAcceptDir", frnd.autoAcceptDir);
ps.setValue("autoAcceptCall", static_cast<int>(frnd.autoAcceptCall));
ps.setValue("circle", frnd.circleID);
if (getEnableLogging())
ps.setValue("activity", frnd.activity);
++index;
}
ps.endArray();
}
ps.endGroup();
ps.beginGroup("Requests");
{
ps.beginWriteArray("Request", friendRequests.size());
int index = 0;
for (auto& request : friendRequests)
{
ps.setArrayIndex(index);
ps.setValue("addr", request.address);
ps.setValue("message", request.message);
ps.setValue("read", request.read);
++index;
}
ps.endArray();
}
ps.endGroup();
ps.beginGroup("GUI");
{
ps.setValue("compactLayout", compactLayout);
}
ps.endGroup();
ps.beginGroup("Proxy");
{
ps.setValue("proxyType", static_cast<int>(proxyType));
ps.setValue("proxyAddr", proxyAddr);
ps.setValue("proxyPort", proxyPort);
}
ps.endGroup();
ps.beginGroup("Circles");
{
ps.beginWriteArray("Circle", circleLst.size());
int 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();
2016-01-24 05:50:57 +08:00
ps.beginGroup("Toxme");
{
2016-01-24 05:50:57 +08:00
ps.setValue("info", toxmeInfo);
ps.setValue("bio", toxmeBio);
ps.setValue("priv", toxmePriv);
ps.setValue("pass", toxmePass);
}
2016-01-24 05:50:57 +08:00
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 = reinterpret_cast<const uint32_t*>(data.constData());
return dwords[0] ^ dwords[1] ^ dwords[2] ^ dwords[3];
2014-06-25 04:11:11 +08:00
}
/**
2016-08-01 16:21:23 +08:00
* @brief Get path to directory, where the settings files are stored.
* @return Path to settings directory, ends with a directory separator.
*/
2016-08-05 01:56:23 +08:00
QString Settings::getSettingsDirPath() const
2014-06-25 04:11:11 +08:00
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
2014-07-13 04:58:58 +08:00
if (makeToxPortable)
return qApp->applicationDirPath()+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();
#elif defined(Q_OS_OSX)
return QDir::cleanPath(QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + QDir::separator()
+ "Library" + QDir::separator() + "Application Support" + 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
}
/**
2016-08-01 16:21:23 +08:00
* @brief Get path to directory, where the application data are stored.
* @return Path to application data, ends with a directory separator.
*/
2016-08-05 01:56:23 +08:00
QString Settings::getAppDataDirPath() const
{
QMutexLocker locker{&bigLock};
if (makeToxPortable)
return qApp->applicationDirPath()+QDir::separator();
// workaround for https://bugreports.qt-project.org/browse/QTBUG-38845
#ifdef Q_OS_WIN
return QDir::cleanPath(QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + QDir::separator()
+ "AppData" + QDir::separator() + "Roaming" + QDir::separator() + "tox")+QDir::separator();
#elif defined(Q_OS_OSX)
return QDir::cleanPath(QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + QDir::separator()
+ "Library" + QDir::separator() + "Application Support" + QDir::separator() + "Tox")+QDir::separator();
#else
/*
2016-08-15 17:00:06 +08:00
* TODO: Change QStandardPaths::DataLocation to AppDataLocation when upgrate Qt to 5.4+
2016-08-01 16:28:28 +08:00
* For now we need support Qt 5.3, so we use deprecated DataLocation
* BTW, it's not a big deal since for linux AppDataLocation and DataLocation are equal
*/
return QDir::cleanPath(QStandardPaths::writableLocation(QStandardPaths::DataLocation))+QDir::separator();
#endif
}
/**
2016-08-01 16:21:23 +08:00
* @brief Get path to directory, where the application cache are stored.
* @return Path to application cache, ends with a directory separator.
*/
2016-08-05 01:56:23 +08:00
QString Settings::getAppCacheDirPath() const
{
QMutexLocker locker{&bigLock};
if (makeToxPortable)
return qApp->applicationDirPath()+QDir::separator();
// workaround for https://bugreports.qt-project.org/browse/QTBUG-38845
#ifdef Q_OS_WIN
return QDir::cleanPath(QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + QDir::separator()
+ "AppData" + QDir::separator() + "Roaming" + QDir::separator() + "tox")+QDir::separator();
#elif defined(Q_OS_OSX)
return QDir::cleanPath(QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + QDir::separator()
+ "Library" + QDir::separator() + "Application Support" + QDir::separator() + "Tox")+QDir::separator();
#else
return QDir::cleanPath(QStandardPaths::writableLocation(QStandardPaths::CacheLocation))+QDir::separator();
#endif
}
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};
if (newDhtServerList != dhtServerList)
{
dhtServerList = newDhtServerList;
emit dhtServerListChanged(dhtServerList);
}
2014-06-25 04:11:11 +08:00
}
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};
if (newValue != enableIPv6)
{
enableIPv6 = newValue;
emit enableIPv6Changed(enableIPv6);
}
2014-07-02 06:47:06 +08:00
}
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};
if (newValue != makeToxPortable)
{
QFile(getSettingsDirPath() + globalSettingsFile).remove();
makeToxPortable = newValue;
saveGlobal();
emit makeToxPortableChanged(makeToxPortable);
}
2014-07-13 04:58:58 +08:00
}
2014-12-17 21:44:23 +08:00
bool Settings::getAutorun() const
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
#ifdef QTOX_PLATFORM_EXT
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};
bool autorun = Platform::getAutorun();
if (newValue != autorun)
{
Platform::setAutorun(newValue);
emit autorunChanged(autorun);
}
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};
if (newStyle != style)
{
style = newStyle;
emit styleChanged(style);
}
}
bool Settings::getShowSystemTray() const
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
return showSystemTray;
}
void Settings::setShowSystemTray(bool newValue)
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
if (newValue != showSystemTray)
{
showSystemTray = newValue;
emit showSystemTrayChanged(newValue);
}
}
void Settings::setUseEmoticons(bool newValue)
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
if (newValue != useEmoticons)
{
useEmoticons = newValue;
emit useEmoticonsChanged(useEmoticons);
}
}
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};
if (newValue != autoSaveEnabled)
{
autoSaveEnabled = newValue;
emit autoSaveEnabledChanged(autoSaveEnabled);
}
}
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};
if (newValue != autostartInTray)
{
autostartInTray = newValue;
emit autostartInTrayChanged(autostartInTray);
}
}
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};
if (newValue != closeToTray)
{
closeToTray = newValue;
emit closeToTrayChanged(newValue);
}
2014-10-20 03:47:06 +08:00
}
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};
if (newValue != minimizeToTray)
{
minimizeToTray = newValue;
emit minimizeToTrayChanged(minimizeToTray);
}
2014-10-20 19:50:12 +08:00
}
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};
if (newValue != lightTrayIcon)
{
lightTrayIcon = newValue;
emit lightTrayIconChanged(lightTrayIcon);
}
2014-12-12 03:34:12 +08:00
}
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};
if (newValue != statusChangeNotificationEnabled)
{
statusChangeNotificationEnabled = newValue;
emit statusChangeNotificationEnabledChanged(statusChangeNotificationEnabled);
}
}
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};
if (newValue != showInFront)
{
showInFront = newValue;
emit showInFrontChanged(showInFront);
}
}
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};
if (newValue != notifySound)
{
notifySound = newValue;
emit notifySoundChanged(notifySound);
}
}
bool Settings::getBusySound() const
{
QMutexLocker locker{&bigLock};
return busySound;
}
void Settings::setBusySound(bool newValue)
{
QMutexLocker locker{&bigLock};
if (newValue != busySound)
{
busySound = newValue;
emit busySoundChanged(busySound);
}
}
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};
if (newValue != groupAlwaysNotify)
{
groupAlwaysNotify = newValue;
emit groupAlwaysNotifyChanged(groupAlwaysNotify);
}
}
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(const QString& newValue)
2014-07-05 01:22:43 +08:00
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
if (newValue != translation)
{
translation = newValue;
emit translationChanged(translation);
}
2014-10-06 04:49:44 +08:00
}
2016-01-24 05:50:57 +08:00
void Settings::deleteToxme()
{
setToxmeInfo("");
setToxmeBio("");
setToxmePriv(false);
2016-01-24 05:50:57 +08:00
setToxmePass("");
}
void Settings::setToxme(QString name, QString server, QString bio, bool priv, QString pass)
{
setToxmeInfo(name + "@" + server);
setToxmeBio(bio);
setToxmePriv(priv);
if (!pass.isEmpty())
setToxmePass(pass);
}
QString Settings::getToxmeInfo() const
{
QMutexLocker locker{&bigLock};
return toxmeInfo;
}
void Settings::setToxmeInfo(const QString& info)
2016-01-24 05:50:57 +08:00
{
QMutexLocker locker{&bigLock};
if (info != toxmeInfo)
{
if (info.split("@").size() == 2)
{
toxmeInfo = info;
emit toxmeInfoChanged(toxmeInfo);
}
else
{
qWarning() << info << "is not a valid toxme string -> value ignored.";
}
}
2016-01-24 05:50:57 +08:00
}
QString Settings::getToxmeBio() const
{
QMutexLocker locker{&bigLock};
return toxmeBio;
}
void Settings::setToxmeBio(const QString& bio)
2016-01-24 05:50:57 +08:00
{
QMutexLocker locker{&bigLock};
if (bio != toxmeBio)
{
toxmeBio = bio;
emit toxmeBioChanged(toxmeBio);
}
2016-01-24 05:50:57 +08:00
}
bool Settings::getToxmePriv() const
{
QMutexLocker locker{&bigLock};
return toxmePriv;
}
void Settings::setToxmePriv(bool priv)
{
QMutexLocker locker{&bigLock};
if (priv != toxmePriv)
{
toxmePriv = priv;
emit toxmePrivChanged(toxmePriv);
}
2016-01-24 05:50:57 +08:00
}
QString Settings::getToxmePass() const
{
QMutexLocker locker{&bigLock};
return toxmePass;
}
void Settings::setToxmePass(const QString& pass)
2016-01-24 05:50:57 +08:00
{
QMutexLocker locker{&bigLock};
if (pass != toxmePass)
{
toxmePass = pass;
// password is not exposed for security reasons
emit toxmePassChanged();
}
2016-01-24 05:50:57 +08:00
}
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};
if (newValue != forceTCP)
{
forceTCP = newValue;
emit forceTCPChanged(forceTCP);
}
2014-10-06 04:49:44 +08:00
}
QNetworkProxy Settings::getProxy() const
{
QNetworkProxy proxy;
switch(Settings::getProxyType())
{
case ProxyType::ptNone:
proxy.setType(QNetworkProxy::NoProxy);
break;
case ProxyType::ptSOCKS5:
proxy.setType(QNetworkProxy::Socks5Proxy);
break;
case ProxyType::ptHTTP:
proxy.setType(QNetworkProxy::HttpProxy);
break;
default:
proxy.setType(QNetworkProxy::NoProxy);
qWarning() << "Invalid Proxy type, setting to NoProxy";
break;
}
proxy.setHostName(Settings::getProxyAddr());
proxy.setPort(Settings::getProxyPort());
return proxy;
}
Settings::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(ProxyType newValue)
2014-10-07 10:09:15 +08:00
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
if (newValue != proxyType)
{
proxyType = newValue;
emit proxyTypeChanged(proxyType);
}
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};
if (newValue != proxyAddr)
{
proxyAddr = newValue;
emit proxyAddressChanged(proxyAddr);
}
2014-10-06 04:49:44 +08:00
}
quint16 Settings::getProxyPort() const
2014-10-06 04:49:44 +08:00
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
2014-10-06 04:49:44 +08:00
return proxyPort;
}
void Settings::setProxyPort(quint16 newValue)
2014-10-06 04:49:44 +08:00
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
if (newValue != proxyPort)
{
proxyPort = newValue;
emit proxyPortChanged(proxyPort);
}
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(const QString& profile)
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
if (profile != currentProfile)
{
currentProfile = profile;
currentProfileId = makeProfileId(currentProfile);
emit currentProfileChanged(currentProfile);
emit currentProfileIdChanged(currentProfileId);
}
}
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};
if (newValue != enableLogging)
{
enableLogging = newValue;
emit enableLoggingChanged(enableLogging);
}
2014-06-25 04:11:11 +08:00
}
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(Db::syncType newValue)
2014-11-12 20:56:24 +08:00
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
if (newValue != dbSyncType)
{
dbSyncType = newValue;
emit dbSyncTypeChanged(dbSyncType);
}
2014-11-12 20:56:24 +08:00
}
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;
}
/**
* @brief Sets how long the user may stay idle, before online status is set to "away".
* @param[in] newValue the user idle duration in minutes
* @note Values < 0 default to 10 minutes.
*/
2014-10-16 17:47:58 +08:00
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
if (newValue != autoAwayTime)
{
autoAwayTime = newValue;
emit autoAwayTimeChanged(autoAwayTime);
}
2014-10-16 17:47:58 +08:00
}
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
{
updateFriendAddress(id.toString());
2014-11-17 18:10:38 +08:00
setAutoAcceptDir(id, dir);
}
2014-10-18 11:02:13 +08:00
}
Settings::AutoAcceptCallFlags Settings::getAutoAcceptCall(const ToxId &id) const
{
QMutexLocker locker{&bigLock};
QString key = id.publicKey;
auto it = friendLst.find(key);
if (it != friendLst.end())
return it->autoAcceptCall;
return Settings::AutoAcceptCallFlags();
}
void Settings::setAutoAcceptCall(const ToxId& id, AutoAcceptCallFlags accept)
{
QMutexLocker locker{&bigLock};
QString key = id.publicKey;
auto it = friendLst.find(key);
if(it != friendLst.end())
{
it->autoAcceptCall = accept;
emit autoAcceptCallChanged(id, accept);
}
}
2015-11-10 04:54:28 +08:00
QString Settings::getContactNote(const ToxId &id) const
{
QMutexLocker locker{&bigLock};
auto it = friendLst.find(id.publicKey);
if (it != friendLst.end())
return it->note;
return QString();
}
void Settings::setContactNote(const ToxId &id, const QString& note)
{
QMutexLocker locker{&bigLock};
auto it = friendLst.find(id.publicKey);
if (it != friendLst.end())
{
qDebug() << note;
it->note = note;
}
else
{
updateFriendAddress(id.toString());
2015-11-10 04:54:28 +08:00
setContactNote(id, note);
}
}
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};
if (newValue != globalAutoAcceptDir)
{
globalAutoAcceptDir = newValue;
emit globalAutoAcceptDirChanged(globalAutoAcceptDir);
}
2014-10-20 12:25:52 +08:00
}
const QFont& Settings::getChatMessageFont() const
{
QMutexLocker locker(&bigLock);
return chatMessageFont;
}
void Settings::setChatMessageFont(const QFont& font)
{
QMutexLocker locker(&bigLock);
if (font != chatMessageFont)
{
chatMessageFont = font;
emit chatMessageFontChanged(chatMessageFont);
}
}
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};
if (!widgetSettings.contains(uniqueName) ||
widgetSettings[uniqueName] != data)
{
widgetSettings[uniqueName] = data;
emit widgetDataChanged(uniqueName);
}
2014-06-25 04:11:11 +08:00
}
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;
}
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};
if (value != smileyPack)
{
smileyPack = value;
emit smileyPackChanged(smileyPack);
}
2014-06-25 04:11:11 +08:00
}
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
if (value != emojiFontPointSize)
{
emojiFontPointSize = value;
emit emojiFontPointSizeChanged(emojiFontPointSize);
}
2014-06-25 04:11:11 +08:00
}
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)
2014-06-25 04:11:11 +08:00
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
if (format != timestampFormat)
{
timestampFormat = format;
emit timestampFormatChanged(timestampFormat);
}
2014-06-25 04:11:11 +08:00
}
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};
if (format != dateFormat)
{
dateFormat = format;
emit dateFormatChanged(dateFormat);
}
}
Settings::StyleType Settings::getStylePreference() const
{
QMutexLocker locker{&bigLock};
return stylePreference;
}
void Settings::setStylePreference(StyleType newValue)
{
QMutexLocker locker{&bigLock};
if (newValue != stylePreference)
{
stylePreference = newValue;
emit stylePreferenceChanged(stylePreference);
}
}
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};
if (value != windowGeometry)
{
windowGeometry = value;
emit windowGeometryChanged(windowGeometry);
}
}
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};
if (value != windowState)
{
windowState = value;
emit windowStateChanged(windowState);
}
}
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};
if (newValue != checkUpdates)
{
checkUpdates = newValue;
emit checkUpdatesChanged(checkUpdates);
}
}
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};
if (newValue != showWindow)
{
showWindow = newValue;
emit showWindowChanged(showWindow);
}
}
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)
2014-08-11 20:07:27 +08:00
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
if(value != splitterState)
{
splitterState = value;
emit splitterStateChanged(splitterState);
}
2014-08-11 20:07:27 +08:00
}
2015-06-19 22:58:48 +08:00
QByteArray Settings::getDialogGeometry() const
{
QMutexLocker locker{&bigLock};
return dialogGeometry;
}
void Settings::setDialogGeometry(const QByteArray& value)
2015-06-19 22:58:48 +08:00
{
QMutexLocker locker{&bigLock};
if (value != dialogGeometry)
{
dialogGeometry = value;
emit dialogGeometryChanged(dialogGeometry);
}
2015-06-19 22:58:48 +08:00
}
QByteArray Settings::getDialogSplitterState() const
{
QMutexLocker locker{&bigLock};
return dialogSplitterState;
}
void Settings::setDialogSplitterState(const QByteArray& value)
2015-06-19 22:58:48 +08:00
{
QMutexLocker locker{&bigLock};
if (value != dialogSplitterState)
{
dialogSplitterState = value;
emit dialogSplitterStateChanged(dialogSplitterState);
}
2015-06-19 22:58:48 +08:00
}
QByteArray Settings::getDialogSettingsGeometry() const
{
QMutexLocker locker{&bigLock};
return dialogSettingsGeometry;
}
void Settings::setDialogSettingsGeometry(const QByteArray& value)
{
QMutexLocker locker{&bigLock};
if (value != dialogSettingsGeometry)
{
dialogSettingsGeometry = value;
emit dialogSettingsGeometryChanged(dialogSettingsGeometry);
}
}
bool Settings::getMinimizeOnClose() 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 minimizeOnClose;
}
void Settings::setMinimizeOnClose(bool newValue)
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
if (newValue != minimizeOnClose)
{
minimizeOnClose = newValue;
emit minimizeOnCloseChanged(minimizeOnClose);
}
2014-06-25 04:11:11 +08:00
}
bool Settings::getTypingNotification() 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 typingNotification;
}
void Settings::setTypingNotification(bool enabled)
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
if (enabled != typingNotification)
{
typingNotification = enabled;
emit typingNotificationChanged(typingNotification);
}
2014-06-25 04:11:11 +08:00
}
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};
if (deviceSpecifier != inDev)
{
inDev = deviceSpecifier;
emit inDevChanged(inDev);
}
2014-10-29 04:21:37 +08:00
}
bool Settings::getAudioInDevEnabled() const
{
QMutexLocker locker(&bigLock);
return audioInDevEnabled;
}
void Settings::setAudioInDevEnabled(bool enabled)
{
QMutexLocker locker(&bigLock);
if (enabled != audioInDevEnabled)
{
audioInDevEnabled = enabled;
emit audioInDevEnabledChanged(enabled);
}
}
qreal Settings::getAudioInGainDecibel() const
{
QMutexLocker locker{&bigLock};
return audioInGainDecibel;
}
void Settings::setAudioInGainDecibel(qreal dB)
{
QMutexLocker locker{&bigLock};
if (dB < audioInGainDecibel || dB > audioInGainDecibel)
{
audioInGainDecibel = dB;
emit audioInGainDecibelChanged(audioInGainDecibel);
}
}
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};
if(deviceSpecifier != videoDev)
{
videoDev = deviceSpecifier;
emit videoDevChanged(videoDev);
}
2015-05-14 10:46:28 +08:00
}
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};
if (deviceSpecifier != outDev)
{
outDev = deviceSpecifier;
emit outDevChanged(outDev);
}
2014-10-29 04:21:37 +08:00
}
bool Settings::getAudioOutDevEnabled() const
{
QMutexLocker locker(&bigLock);
return audioOutDevEnabled;
}
void Settings::setAudioOutDevEnabled(bool enabled)
{
QMutexLocker locker(&bigLock);
if(enabled != audioOutDevEnabled)
{
audioOutDevEnabled = enabled;
emit audioOutDevEnabledChanged(audioOutDevEnabled);
}
}
int Settings::getOutVolume() const
{
QMutexLocker locker{&bigLock};
return outVolume;
}
void Settings::setOutVolume(int volume)
{
QMutexLocker locker{&bigLock};
if (volume != outVolume)
{
outVolume = volume;
emit outVolumeChanged(outVolume);
}
}
QRect Settings::getScreenRegion() const
{
QMutexLocker locker (&bigLock);
return screenRegion;
}
void Settings::setScreenRegion(const QRect& value)
{
QMutexLocker locker{&bigLock};
if (value != screenRegion)
{
screenRegion = value;
emit screenRegionChanged(screenRegion);
}
}
bool Settings::getScreenGrabbed() const
{
QMutexLocker locker(&bigLock);
return screenGrabbed;
}
void Settings::setScreenGrabbed(bool value)
{
QMutexLocker locker{&bigLock};
if (value != screenGrabbed)
{
screenGrabbed = value;
emit screenGrabbedChanged(screenGrabbed);
}
}
QRect Settings::getCamVideoRes() const
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
return camVideoRes;
}
void Settings::setCamVideoRes(QRect newValue)
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
if (newValue != camVideoRes)
{
camVideoRes = newValue;
emit camVideoResChanged(camVideoRes);
}
}
2015-08-19 05:44:34 +08:00
unsigned short Settings::getCamVideoFPS() const
{
QMutexLocker locker{&bigLock};
return camVideoFPS;
}
void Settings::setCamVideoFPS(unsigned short newValue)
{
QMutexLocker locker{&bigLock};
if (newValue != camVideoFPS)
{
camVideoFPS = newValue;
emit camVideoFPSChanged(camVideoFPS);
}
2015-08-19 05:44:34 +08:00
}
QString Settings::getFriendAddress(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::updateFriendAddress(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 = "";
2015-11-10 04:54:28 +08:00
fp.note = "";
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;
2015-11-10 04:54:28 +08:00
fp.note = "";
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 = "";
2015-11-10 04:54:28 +08:00
fp.note = "";
2015-06-06 01:38:07 +08:00
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 = "";
2015-11-10 04:54:28 +08:00
fp.note = "";
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};
if (value != fauxOfflineMessaging)
{
fauxOfflineMessaging = value;
emit fauxOfflineMessagingChanged(fauxOfflineMessaging);
}
2014-11-10 21:06:35 +08:00
}
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};
if (value != compactLayout)
{
compactLayout = value;
emit compactLayoutChanged(value);
}
}
bool Settings::getSeparateWindow() const
{
QMutexLocker locker{&bigLock};
return separateWindow;
}
void Settings::setSeparateWindow(bool value)
{
QMutexLocker locker{&bigLock};
if (value != separateWindow)
{
separateWindow = value;
emit separateWindowChanged(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};
if (value != dontGroupWindows)
{
dontGroupWindows = value;
emit dontGroupWindowsChanged(dontGroupWindows);
}
2015-06-19 22:58:48 +08:00
}
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};
if (value != groupchatPosition)
{
groupchatPosition = value;
emit groupchatPositionChanged(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;
}
bool Settings::addFriendRequest(const QString& friendAddress, const QString& message)
{
QMutexLocker locker{&bigLock};
for (auto queued : friendRequests)
{
if (queued.address == friendAddress)
{
queued.message = message;
queued.read = false;
return false;
}
}
Request request;
request.address = friendAddress;
request.message = message;
request.read = false;
friendRequests.push_back(request);
return true;
}
unsigned int Settings::getUnreadFriendRequests() const
{
QMutexLocker locker{&bigLock};
unsigned int unreadFriendRequests = 0;
for (auto request : friendRequests)
if (!request.read)
unreadFriendRequests++;
return unreadFriendRequests;
}
Settings::Request Settings::getFriendRequest(int index) const
{
QMutexLocker locker{&bigLock};
return friendRequests.at(index);
}
int Settings::getFriendRequestSize() const
{
QMutexLocker locker{&bigLock};
return friendRequests.size();
}
void Settings::clearUnreadFriendRequests()
{
QMutexLocker locker{&bigLock};
for (auto& request : friendRequests)
request.read = true;
}
void Settings::removeFriendRequest(int index)
{
QMutexLocker locker{&bigLock};
friendRequests.removeAt(index);
}
void Settings::readFriendRequest(int index)
{
QMutexLocker locker{&bigLock};
friendRequests[index].read = true;
}
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(int value)
2014-11-16 04:30:20 +08:00
{
2015-06-05 22:27:15 +08:00
QMutexLocker locker{&bigLock};
if (value != themeColor)
{
themeColor = value;
emit themeColorChanged(themeColor);
}
2014-11-16 04:30:20 +08:00
}
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};
if (state != autoLogin)
{
autoLogin = state;
emit autoLoginChanged(autoLogin);
}
2015-06-05 22:27:15 +08:00
}
/**
2016-08-01 16:21:23 +08:00
* @brief Write a default personal .ini settings file for a profile.
* @param basename Filename without extension to save settings.
* @example If basename is "profile", settings will be saved in profile.ini
*/
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);
2016-01-21 11:59:20 +08:00
ps.setIniCodec("UTF-8");
2015-06-04 05:20:47 +08:00
ps.beginGroup("Friends");
ps.beginWriteArray("Friend", 0);
ps.endArray();
ps.endGroup();
ps.beginGroup("Privacy");
ps.endGroup();
}
/**
2016-08-01 16:21:23 +08:00
* @brief Creates a path to the settings dir, if it doesn't already exist
*/
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
/**
2016-08-01 16:21:23 +08:00
* @brief Waits for all asynchronous operations to complete
*/
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();
}