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

992 lines
25 KiB
C++
Raw Normal View History

2014-06-25 04:11:11 +08:00
/*
Copyright (C) 2013 by Maxim Biro <nurupo.contributions@gmail.com>
2014-06-25 04:11:11 +08:00
This file is part of Tox Qt GUI.
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.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
2014-06-25 04:11:11 +08:00
See the COPYING file for more details.
*/
#include "settings.h"
2014-08-01 20:46:28 +08:00
#include "smileypack.h"
2014-10-18 11:02:13 +08:00
#include "src/corestructs.h"
2014-11-12 20:56:24 +08:00
#include "src/misc/db/plaindb.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 <QSettings>
#include <QStandardPaths>
#include <QDebug>
2014-08-01 20:46:28 +08:00
#include <QList>
#include <QStyleFactory>
2014-06-25 04:11:11 +08:00
#ifdef Q_OS_LINUX
#define SHOW_SYSTEM_TRAY_DEFAULT (bool) false
#else // OS is not linux
#define SHOW_SYSTEM_TRAY_DEFAULT (bool) true
#endif
2014-12-03 06:47:55 +08:00
const QString Settings::OLDFILENAME = "settings.ini";
const QString Settings::FILENAME = "qtox.ini";
Settings* Settings::settings{nullptr};
2014-07-13 04:58:58 +08:00
bool Settings::makeToxPortable{false};
2014-06-25 04:11:11 +08:00
Settings::Settings() :
loaded(false), useCustomDhtList{false}
2014-06-25 04:11:11 +08:00
{
load();
}
Settings& Settings::getInstance()
{
if (!settings)
settings = new Settings();
return *settings;
2014-06-25 04:11:11 +08:00
}
void Settings::resetInstance()
{
if (settings)
{
delete settings;
settings = nullptr;
}
}
2014-06-25 04:11:11 +08:00
void Settings::load()
{
2014-12-03 06:47:55 +08:00
if (loaded)
2014-06-25 04:11:11 +08:00
return;
2014-12-03 06:47:55 +08:00
if (QFile(FILENAME).exists())
{
QSettings ps(FILENAME, QSettings::IniFormat);
ps.beginGroup("General");
makeToxPortable = ps.value("makeToxPortable", false).toBool();
ps.endGroup();
}
2014-12-03 06:47:55 +08:00
else if (QFile(OLDFILENAME).exists())
{
QSettings ps(OLDFILENAME, QSettings::IniFormat);
ps.beginGroup("General");
makeToxPortable = ps.value("makeToxPortable", false).toBool();
ps.endGroup();
}
else
makeToxPortable = false;
2014-07-13 04:58:58 +08:00
2014-12-03 06:47:55 +08:00
QDir dir(getSettingsDirPath());
QString filePath = dir.filePath(FILENAME);
2014-06-25 04:11:11 +08:00
//if no settings file exist -- use the default one
2014-12-03 06:47:55 +08:00
if (!QFile(filePath).exists())
{
if (!QFile(filePath = dir.filePath(OLDFILENAME)).exists())
{
qDebug() << "No settings file found, using defaults";
filePath = ":/conf/" + FILENAME;
}
2014-06-25 04:11:11 +08:00
}
qDebug() << "Settings: Loading from "<<filePath;
2014-06-25 04:11:11 +08:00
QSettings s(filePath, QSettings::IniFormat);
s.beginGroup("DHT Server");
if (s.value("useCustomList").toBool())
{
useCustomDhtList = true;
qDebug() << "Using custom bootstrap nodes list";
int serverListSize = s.beginReadArray("dhtServerList");
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
useCustomDhtList=false;
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();
2014-10-20 03:47:06 +08:00
closeToTray = s.value("closeToTray", false).toBool();
forceTCP = s.value("forceTCP", false).toBool();
useProxy = s.value("useProxy", false).toBool();
proxyAddr = s.value("proxyAddr", "").toString();
proxyPort = s.value("proxyPort", 0).toInt();
2014-10-16 17:47:58 +08:00
currentProfile = s.value("currentProfile", "").toString();
2014-11-12 20:56:24 +08:00
autoAwayTime = s.value("autoAwayTime", 10).toInt();
checkUpdates = s.value("checkUpdates", false).toBool();
showInFront = s.value("showInFront", 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();
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();
for (const QString& name : objectNames) {
widgetSettings[name] = s.value(name).toByteArray();
}
s.endGroup();
s.beginGroup("GUI");
enableSmoothAnimation = s.value("smoothAnimation", true).toBool();
2014-11-03 05:13:17 +08:00
smileyPack = s.value("smileyPack", ":/smileys/cylgom/emoticons.xml").toString();
2014-06-25 04:11:11 +08:00
customEmojiFont = s.value("customEmojiFont", true).toBool();
emojiFontFamily = s.value("emojiFontFamily", "DejaVu Sans").toString();
emojiFontPointSize = s.value("emojiFontPointSize", 12).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").toString();
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();
2014-08-11 00:14:50 +08:00
useNativeStyle = s.value("nativeStyle", 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();
2014-06-25 04:11:11 +08:00
s.endGroup();
s.beginGroup("Privacy");
typingNotification = s.value("typingNotification", false).toBool();
2014-10-09 22:36:24 +08:00
enableLogging = s.value("enableLogging", false).toBool();
encryptLogs = s.value("encryptLogs", false).toBool();
2014-10-19 22:59:58 +08:00
encryptTox = s.value("encryptTox", false).toBool();
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();
// Read the embedded DHT bootsrap nodes list if needed
if (dhtServerList.isEmpty())
{
qDebug() << "Using embeded bootstrap nodes list";
QSettings rcs(":/conf/settings.ini", QSettings::IniFormat);
rcs.beginGroup("DHT Server");
int serverListSize = rcs.beginReadArray("dhtServerList");
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;
if (currentProfile.isEmpty()) // new profile in Core::switchConfiguration
return;
// load from a profile specific friend data list if possible
QString tmp = dir.filePath(currentProfile + ".ini");
if (QFile(tmp).exists())
filePath = tmp;
QSettings fs(filePath, QSettings::IniFormat);
friendLst.clear();
fs.beginGroup("Friends");
int size = fs.beginReadArray("Friend");
for (int i = 0; i < size; i ++)
{
fs.setArrayIndex(i);
friendProp fp;
fp.addr = fs.value("addr").toString();
fp.alias = fs.value("alias").toString();
fp.autoAcceptDir = fs.value("autoAcceptDir").toString();
friendLst[ToxID::fromString(fp.addr).publicKey] = fp;
}
fs.endArray();
fs.endGroup();
2014-06-25 04:11:11 +08:00
}
void Settings::save(bool writeFriends)
2014-06-25 04:11:11 +08:00
{
QString filePath = QDir(getSettingsDirPath()).filePath(FILENAME);
save(filePath, writeFriends);
2014-07-13 04:58:58 +08:00
}
2014-06-25 04:11:11 +08:00
void Settings::save(QString path, bool writeFriends)
2014-07-13 04:58:58 +08:00
{
qDebug() << "Settings: Saving in "<<path;
2014-07-13 04:58:58 +08:00
QSettings s(path, QSettings::IniFormat);
2014-06-25 04:11:11 +08:00
s.clear();
s.beginGroup("DHT Server");
s.setValue("useCustomList", useCustomDhtList);
2014-06-25 04:11:11 +08:00
s.beginWriteArray("dhtServerList", dhtServerList.size());
for (int i = 0; i < dhtServerList.size(); i ++) {
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);
s.setValue("useProxy", useProxy);
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("showInFront", showInFront);
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);
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();
for (const QString& name : widgetNames) {
s.setValue(name, widgetSettings.value(name));
}
s.endGroup();
s.beginGroup("GUI");
s.setValue("smoothAnimation", enableSmoothAnimation);
s.setValue("smileyPack", smileyPack);
s.setValue("customEmojiFont", customEmojiFont);
s.setValue("emojiFontFamily", emojiFontFamily);
s.setValue("emojiFontPointSize", emojiFontPointSize);
s.setValue("firstColumnHandlePos", firstColumnHandlePos);
s.setValue("secondColumnHandlePosFromRight", secondColumnHandlePosFromRight);
s.setValue("timestampFormat", timestampFormat);
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);
2014-08-11 00:14:50 +08:00
s.setValue("nativeStyle", useNativeStyle);
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);
2014-06-25 04:11:11 +08:00
s.endGroup();
s.beginGroup("Privacy");
s.setValue("typingNotification", typingNotification);
2014-10-09 22:36:24 +08:00
s.setValue("enableLogging", enableLogging);
s.setValue("encryptLogs", encryptLogs);
2014-10-19 22:59:58 +08:00
s.setValue("encryptTox", encryptTox);
2014-06-25 04:11:11 +08:00
s.endGroup();
2014-10-18 11:02:13 +08:00
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();
if (!writeFriends || currentProfile.isEmpty()) // Core::switchConfiguration
return;
QSettings fs(QFileInfo(path).dir().filePath(currentProfile + ".ini"), QSettings::IniFormat);
fs.beginGroup("Friends");
fs.beginWriteArray("Friend", friendLst.size());
int index = 0;
for (auto& frnd : friendLst)
{
fs.setArrayIndex(index);
fs.setValue("addr", frnd.addr);
fs.setValue("alias", frnd.alias);
fs.setValue("autoAcceptDir", frnd.autoAcceptDir);
index++;
}
fs.endArray();
fs.endGroup();
2014-06-25 04:11:11 +08:00
}
QString Settings::getSettingsDirPath()
{
2014-07-13 04:58:58 +08:00
if (makeToxPortable)
return ".";
2014-06-25 04:11:11 +08:00
// workaround for https://bugreports.qt-project.org/browse/QTBUG-38845
#ifdef Q_OS_WIN
2014-11-01 22:02:43 +08:00
return QDir::cleanPath(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)
+ QDir::separator() + "AppData" + QDir::separator() + "Roaming" + QDir::separator() + "tox");
2014-06-25 04:11:11 +08:00
#else
return QDir::cleanPath(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QDir::separator() + "tox");
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
{
QDir dir(getSettingsDirPath());
2014-09-28 06:19:30 +08:00
QString filePath = dir.filePath("avatars/"+ownerId.left(64)+".png");
QFileInfo info(filePath);
2014-09-24 22:51:16 +08:00
QPixmap pic;
if (!info.exists())
{
2014-09-28 06:19:30 +08:00
QString filePath = dir.filePath("avatar_"+ownerId.left(64));
if (!QFileInfo(filePath).exists()) // try without truncation, for old self avatars
2014-09-28 06:36:19 +08:00
filePath = dir.filePath("avatar_"+ownerId);
pic.load(filePath);
saveAvatar(pic, ownerId);
QFile::remove(filePath);
}
else
pic.load(filePath);
2014-09-24 22:51:16 +08:00
return pic;
}
2014-09-24 23:55:54 +08:00
void Settings::saveAvatar(QPixmap& pic, const QString& ownerId)
2014-09-24 22:51:16 +08:00
{
QDir dir(getSettingsDirPath());
dir.mkdir("avatars/");
2014-09-28 06:19:30 +08:00
// ignore nospam (good idea, and also the addFriend funcs which call getAvatar don't have it)
QString filePath = dir.filePath("avatars/"+ownerId.left(64)+".png");
2014-09-24 22:51:16 +08:00
pic.save(filePath, "png");
}
void Settings::saveAvatarHash(const QByteArray& hash, const QString& ownerId)
{
QDir dir(getSettingsDirPath());
dir.mkdir("avatars/");
QFile file(dir.filePath("avatars/"+ownerId.left(64)+".hash"));
if (!file.open(QIODevice::WriteOnly))
return;
file.write(hash);
file.close();
}
QByteArray Settings::getAvatarHash(const QString& ownerId)
{
QDir dir(getSettingsDirPath());
dir.mkdir("avatars/");
QFile file(dir.filePath("avatars/"+ownerId.left(64)+".hash"));
if (!file.open(QIODevice::ReadOnly))
return QByteArray();
QByteArray out = file.readAll();
file.close();
return out;
}
2014-06-25 04:11:11 +08:00
const QList<Settings::DhtServer>& Settings::getDhtServerList() const
{
return dhtServerList;
}
void Settings::setDhtServerList(const QList<DhtServer>& newDhtServerList)
{
dhtServerList = newDhtServerList;
emit dhtServerListChanged();
}
2014-07-02 06:47:06 +08:00
bool Settings::getEnableIPv6() const
{
return enableIPv6;
}
void Settings::setEnableIPv6(bool newValue)
{
enableIPv6 = newValue;
}
2014-07-13 04:58:58 +08:00
bool Settings::getMakeToxPortable() const
{
return makeToxPortable;
}
void Settings::setMakeToxPortable(bool newValue)
{
makeToxPortable = newValue;
save(FILENAME); // Commit to the portable file that we don't want to use it
if (!newValue) // Update the new file right now if not already done
save();
2014-07-13 04:58:58 +08:00
}
bool Settings::getAutostartInTray() const
{
return autostartInTray;
}
QString Settings::getStyle() const
{
return style;
}
void Settings::setStyle(const QString& newStyle)
{
style = newStyle;
}
bool Settings::getShowSystemTray() const
{
return showSystemTray;
}
void Settings::setShowSystemTray(const bool& newValue)
{
showSystemTray = newValue;
}
void Settings::setUseEmoticons(bool newValue)
{
useEmoticons = newValue;
}
bool Settings::getUseEmoticons() const
{
return useEmoticons;
}
void Settings::setAutoSaveEnabled(bool newValue)
{
autoSaveEnabled = newValue;
}
bool Settings::getAutoSaveEnabled() const
{
return autoSaveEnabled;
}
void Settings::setAutostartInTray(bool newValue)
{
autostartInTray = newValue;
}
2014-10-20 03:47:06 +08:00
bool Settings::getCloseToTray() const
{
return closeToTray;
}
void Settings::setCloseToTray(bool newValue)
{
closeToTray = newValue;
}
2014-10-20 19:50:12 +08:00
bool Settings::getMinimizeToTray() const
{
return minimizeToTray;
}
void Settings::setMinimizeToTray(bool newValue)
{
minimizeToTray = newValue;
}
2014-12-12 03:34:12 +08:00
bool Settings::getLightTrayIcon() const
{
return lightTrayIcon;
}
void Settings::setLightTrayIcon(bool newValue)
{
lightTrayIcon = newValue;
}
bool Settings::getStatusChangeNotificationEnabled() const
{
return statusChangeNotificationEnabled;
}
void Settings::setStatusChangeNotificationEnabled(bool newValue)
{
statusChangeNotificationEnabled = newValue;
}
bool Settings::getShowInFront() const
{
return showInFront;
}
void Settings::setShowInFront(bool newValue)
{
showInFront = newValue;
}
QString Settings::getTranslation() const
2014-07-05 01:22:43 +08:00
{
return translation;
2014-07-05 01:22:43 +08:00
}
void Settings::setTranslation(QString newValue)
2014-07-05 01:22:43 +08:00
{
translation = newValue;
2014-10-06 04:49:44 +08:00
}
bool Settings::getForceTCP() const
{
return forceTCP;
}
void Settings::setForceTCP(bool newValue)
{
forceTCP = newValue;
}
2014-10-07 10:09:15 +08:00
bool Settings::getUseProxy() const
{
return useProxy;
}
void Settings::setUseProxy(bool newValue)
{
useProxy = newValue;
}
2014-10-06 04:49:44 +08:00
QString Settings::getProxyAddr() const
{
return proxyAddr;
}
void Settings::setProxyAddr(const QString& newValue)
{
proxyAddr = newValue;
}
int Settings::getProxyPort() const
{
return proxyPort;
}
void Settings::setProxyPort(int newValue)
{
proxyPort = newValue;
2014-07-05 01:22:43 +08:00
}
QString Settings::getCurrentProfile() const
{
return currentProfile;
}
void Settings::setCurrentProfile(QString profile)
{
currentProfile = profile;
}
2014-06-25 04:11:11 +08:00
bool Settings::getEnableLogging() const
{
return enableLogging;
}
void Settings::setEnableLogging(bool newValue)
{
enableLogging = newValue;
}
bool Settings::getEncryptLogs() const
{
return encryptLogs;
}
void Settings::setEncryptLogs(bool newValue)
{
encryptLogs = newValue;
}
2014-10-12 15:31:48 +08:00
bool Settings::getEncryptTox() const
{
return encryptTox;
}
void Settings::setEncryptTox(bool newValue)
{
encryptTox = newValue;
}
2014-11-12 20:56:24 +08:00
Db::syncType Settings::getDbSyncType() const
{
return dbSyncType;
}
void Settings::setDbSyncType(int newValue)
{
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
{
return autoAwayTime;
}
void Settings::setAutoAwayTime(int newValue)
{
if (newValue < 0)
newValue = 10;
autoAwayTime = newValue;
}
2014-11-17 18:10:38 +08:00
QString Settings::getAutoAcceptDir(const ToxID& id) const
2014-10-18 11:02:13 +08:00
{
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
}
2014-11-17 18:10:38 +08:00
void Settings::setAutoAcceptDir(const ToxID &id, const QString& dir)
2014-10-18 11:02:13 +08:00
{
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 {
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
{
return globalAutoAcceptDir;
}
void Settings::setGlobalAutoAcceptDir(const QString& newValue)
{
globalAutoAcceptDir = newValue;
}
2014-06-25 04:11:11 +08:00
void Settings::setWidgetData(const QString& uniqueName, const QByteArray& data)
{
widgetSettings[uniqueName] = data;
}
QByteArray Settings::getWidgetData(const QString& uniqueName) const
{
return widgetSettings.value(uniqueName);
}
bool Settings::isAnimationEnabled() const
{
return enableSmoothAnimation;
}
void Settings::setAnimationEnabled(bool newValue)
{
enableSmoothAnimation = newValue;
}
2014-07-25 20:52:14 +08:00
QString Settings::getSmileyPack() const
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
{
smileyPack = value;
emit smileyPackChanged();
}
bool Settings::isCurstomEmojiFont() const
{
return customEmojiFont;
}
void Settings::setCurstomEmojiFont(bool value)
{
customEmojiFont = value;
emit emojiFontChanged();
}
int Settings::getEmojiFontPointSize() const
{
return emojiFontPointSize;
}
void Settings::setEmojiFontPointSize(int value)
{
emojiFontPointSize = value;
emit emojiFontChanged();
}
int Settings::getFirstColumnHandlePos() const
{
return firstColumnHandlePos;
}
void Settings::setFirstColumnHandlePos(const int pos)
{
firstColumnHandlePos = pos;
}
int Settings::getSecondColumnHandlePosFromRight() const
{
return secondColumnHandlePosFromRight;
}
void Settings::setSecondColumnHandlePosFromRight(const int pos)
{
secondColumnHandlePosFromRight = pos;
}
const QString &Settings::getTimestampFormat() const
{
return timestampFormat;
}
void Settings::setTimestampFormat(const QString &format)
{
timestampFormat = format;
emit timestampFormatChanged();
}
QString Settings::getEmojiFontFamily() const
{
return emojiFontFamily;
}
void Settings::setEmojiFontFamily(const QString &value)
{
emojiFontFamily = value;
emit emojiFontChanged();
}
2014-08-11 00:14:50 +08:00
bool Settings::getUseNativeStyle() const
{
return useNativeStyle;
}
void Settings::setUseNativeStyle(bool value)
{
useNativeStyle = value;
}
QByteArray Settings::getWindowGeometry() const
{
return windowGeometry;
}
void Settings::setWindowGeometry(const QByteArray &value)
{
windowGeometry = value;
}
QByteArray Settings::getWindowState() const
{
return windowState;
}
void Settings::setWindowState(const QByteArray &value)
{
windowState = value;
}
bool Settings::getCheckUpdates() const
{
return checkUpdates;
}
void Settings::setCheckUpdates(bool newValue)
{
checkUpdates = newValue;
}
2014-08-11 20:07:27 +08:00
QByteArray Settings::getSplitterState() const
{
return splitterState;
}
void Settings::setSplitterState(const QByteArray &value)
{
splitterState = value;
}
2014-06-25 04:11:11 +08:00
bool Settings::isMinimizeOnCloseEnabled() const
{
return minimizeOnClose;
}
void Settings::setMinimizeOnClose(bool newValue)
{
minimizeOnClose = newValue;
}
bool Settings::isTypingNotificationEnabled() const
{
return typingNotification;
}
void Settings::setTypingNotification(bool enabled)
{
typingNotification = enabled;
}
2014-10-29 04:21:37 +08:00
QString Settings::getInDev() const
{
return inDev;
}
void Settings::setInDev(const QString& deviceSpecifier)
{
inDev = deviceSpecifier;
}
QString Settings::getOutDev() const
{
return outDev;
}
void Settings::setOutDev(const QString& deviceSpecifier)
{
outDev = deviceSpecifier;
}
bool Settings::getFilterAudio() const{
return filterAudio;
}
void Settings::setFilterAudio(bool newValue){
filterAudio = newValue;
}
QString Settings::getFriendAdress(const QString &publicKey) const
{
QString key = ToxID::fromString(publicKey).publicKey;
auto it = friendLst.find(key);
if (it != friendLst.end())
{
return it->addr;
}
return QString();
}
void Settings::updateFriendAdress(const QString &newAddr)
{
QString key = ToxID::fromString(newAddr).publicKey;
auto it = friendLst.find(key);
if (it != friendLst.end())
{
it->addr = newAddr;
} 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
{
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)
{
QString key = id.publicKey;
auto it = friendLst.find(key);
if (it != friendLst.end())
{
it->alias = alias;
} 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
void Settings::removeFriendSettings(const ToxID &id)
{
QString key = id.publicKey;
friendLst.remove(key);
}
2014-11-10 21:06:35 +08:00
bool Settings::getFauxOfflineMessaging() const
{
return fauxOfflineMessaging;
}
void Settings::setFauxOfflineMessaging(bool value)
{
fauxOfflineMessaging = value;
}
2014-11-16 04:30:20 +08:00
int Settings::getThemeColor() const
{
return themeColor;
}
void Settings::setThemeColor(const int &value)
{
themeColor = value;
}