2014-06-25 04:11:11 +08:00
|
|
|
/*
|
|
|
|
Copyright (C) 2013 by Maxim Biro <nurupo.contributions@gmail.com>
|
2014-10-08 22:17:05 +08:00
|
|
|
|
2014-06-25 04:11:11 +08:00
|
|
|
This file is part of Tox Qt GUI.
|
2014-10-08 22:17:05 +08:00
|
|
|
|
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-10-08 22:17:05 +08:00
|
|
|
|
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-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>
|
2014-06-26 19:09:08 +08:00
|
|
|
#include <QDebug>
|
2014-08-01 20:46:28 +08:00
|
|
|
#include <QList>
|
2014-11-09 08:10:06 +08:00
|
|
|
#include <QStyleFactory>
|
2014-06-25 04:11:11 +08:00
|
|
|
|
|
|
|
const QString Settings::FILENAME = "settings.ini";
|
2014-07-13 04:58:58 +08:00
|
|
|
bool Settings::makeToxPortable{false};
|
2014-06-25 04:11:11 +08:00
|
|
|
|
|
|
|
Settings::Settings() :
|
2014-09-05 05:13:59 +08:00
|
|
|
loaded(false), useCustomDhtList{false}
|
2014-06-25 04:11:11 +08:00
|
|
|
{
|
|
|
|
load();
|
|
|
|
}
|
|
|
|
|
|
|
|
Settings& Settings::getInstance()
|
|
|
|
{
|
|
|
|
static Settings settings;
|
|
|
|
return settings;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Settings::load()
|
|
|
|
{
|
2014-09-05 05:13:59 +08:00
|
|
|
if (loaded) {
|
2014-06-25 04:11:11 +08:00
|
|
|
return;
|
2014-09-05 05:13:59 +08:00
|
|
|
}
|
2014-06-25 04:11:11 +08:00
|
|
|
|
2014-07-13 04:58:58 +08:00
|
|
|
QFile portableSettings(FILENAME);
|
|
|
|
if (portableSettings.exists())
|
2014-09-05 05:11:46 +08:00
|
|
|
{
|
|
|
|
QSettings ps(FILENAME, 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-08-30 16:28:00 +08:00
|
|
|
QString filePath = QDir(getSettingsDirPath()).filePath(FILENAME);
|
2014-06-25 04:11:11 +08:00
|
|
|
|
|
|
|
//if no settings file exist -- use the default one
|
|
|
|
QFile file(filePath);
|
|
|
|
if (!file.exists()) {
|
2014-06-26 19:09:08 +08:00
|
|
|
qDebug() << "No settings file found, using defaults";
|
2014-06-25 04:11:11 +08:00
|
|
|
filePath = ":/conf/" + FILENAME;
|
|
|
|
}
|
|
|
|
|
2014-09-05 05:13:59 +08:00
|
|
|
qDebug() << "Settings: Loading from "<<filePath;
|
|
|
|
|
2014-06-25 04:11:11 +08:00
|
|
|
QSettings s(filePath, QSettings::IniFormat);
|
|
|
|
s.beginGroup("DHT Server");
|
2014-09-05 05:13:59 +08:00
|
|
|
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
|
|
|
}
|
2014-09-05 05:13:59 +08:00
|
|
|
else
|
|
|
|
useCustomDhtList=false;
|
2014-06-25 04:11:11 +08:00
|
|
|
s.endGroup();
|
|
|
|
|
2014-11-08 00:02:10 +08:00
|
|
|
friendLst.clear();
|
2014-09-01 04:26:45 +08:00
|
|
|
s.beginGroup("Friends");
|
|
|
|
int size = s.beginReadArray("fullAddresses");
|
2014-11-08 00:02:10 +08:00
|
|
|
for (int i = 0; i < size; i ++)
|
|
|
|
{
|
2014-09-01 04:26:45 +08:00
|
|
|
s.setArrayIndex(i);
|
2014-11-08 00:02:10 +08:00
|
|
|
friendProp fp;
|
|
|
|
fp.addr = s.value("addr").toString();
|
|
|
|
fp.alias = s.value("alias").toString();
|
|
|
|
friendLst[ToxID::fromString(fp.addr).publicKey] = fp;
|
2014-09-01 04:26:45 +08:00
|
|
|
}
|
|
|
|
s.endArray();
|
|
|
|
s.endGroup();
|
|
|
|
|
2014-06-25 04:11:11 +08:00
|
|
|
s.beginGroup("General");
|
2014-07-02 06:47:06 +08:00
|
|
|
enableIPv6 = s.value("enableIPv6", true).toBool();
|
2014-11-06 06:34:28 +08:00
|
|
|
translation = s.value("translation", "en").toString();
|
2014-07-13 04:58:58 +08:00
|
|
|
makeToxPortable = s.value("makeToxPortable", false).toBool();
|
2014-10-08 22:17:05 +08:00
|
|
|
autostartInTray = s.value("autostartInTray", false).toBool();
|
2014-10-20 03:47:06 +08:00
|
|
|
closeToTray = s.value("closeToTray", false).toBool();
|
2014-10-07 10:16:06 +08:00
|
|
|
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();
|
|
|
|
autoAwayTime = s.value("autoAwayTime", 10).toInt();
|
2014-11-10 07:31:29 +08:00
|
|
|
checkUpdates = s.value("checkUpdates", false).toBool();
|
2014-11-10 08:23:41 +08:00
|
|
|
showInFront = s.value("showInFront", false).toBool();
|
2014-11-11 06:45:09 +08:00
|
|
|
fauxOfflineMessaging = s.value("fauxOfflineMessaging", true).toBool();
|
2014-06-25 04:11:11 +08:00
|
|
|
s.endGroup();
|
|
|
|
|
|
|
|
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", QApplication::font().pointSize()).toInt();
|
|
|
|
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-08-11 00:14:50 +08:00
|
|
|
useNativeStyle = s.value("nativeStyle", false).toBool();
|
2014-11-05 23:20:32 +08:00
|
|
|
useEmoticons = s.value("useEmoticons", true).toBool();
|
2014-10-11 07:18:32 +08:00
|
|
|
statusChangeNotificationEnabled = s.value("statusChangeNotificationEnabled", false).toBool();
|
2014-11-09 08:10:06 +08:00
|
|
|
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");
|
2014-08-11 16:00:08 +08:00
|
|
|
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-18 11:02:13 +08:00
|
|
|
s.beginGroup("AutoAccept");
|
2014-11-06 05:59:29 +08:00
|
|
|
autoSaveEnabled = s.value("autoSaveEnabled", false).toBool();
|
|
|
|
globalAutoAcceptDir = s.value("globalAutoAcceptDir",
|
|
|
|
QStandardPaths::locate(QStandardPaths::HomeLocation, QString(), QStandardPaths::LocateDirectory)
|
|
|
|
).toString();
|
|
|
|
|
2014-10-18 11:02:13 +08:00
|
|
|
for (auto& key : s.childKeys())
|
|
|
|
autoAccept[key] = s.value(key).toString();
|
|
|
|
s.endGroup();
|
|
|
|
|
2014-10-29 04:21:37 +08:00
|
|
|
s.beginGroup("Audio");
|
|
|
|
inDev = s.value("inDev", "").toString();
|
|
|
|
outDev = s.value("outDev", "").toString();
|
|
|
|
s.endGroup();
|
|
|
|
|
2014-09-05 05:13:59 +08:00
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Settings::save()
|
|
|
|
{
|
2014-08-30 16:28:00 +08:00
|
|
|
QString filePath = QDir(getSettingsDirPath()).filePath(FILENAME);
|
2014-07-13 04:58:58 +08:00
|
|
|
save(filePath);
|
|
|
|
}
|
2014-06-25 04:11:11 +08:00
|
|
|
|
2014-07-13 04:58:58 +08:00
|
|
|
void Settings::save(QString path)
|
|
|
|
{
|
2014-09-05 05:13:59 +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");
|
2014-09-05 05:13:59 +08:00
|
|
|
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();
|
|
|
|
|
2014-09-01 04:26:45 +08:00
|
|
|
s.beginGroup("Friends");
|
2014-11-08 00:02:10 +08:00
|
|
|
s.beginWriteArray("fullAddresses", friendLst.size());
|
|
|
|
int index = 0;
|
|
|
|
for (auto &frnd : friendLst)
|
|
|
|
{
|
|
|
|
s.setArrayIndex(index);
|
|
|
|
s.setValue("addr", frnd.addr);
|
|
|
|
s.setValue("alias", frnd.alias);
|
|
|
|
index++;
|
2014-09-01 04:26:45 +08:00
|
|
|
}
|
|
|
|
s.endArray();
|
|
|
|
s.endGroup();
|
|
|
|
|
2014-06-25 04:11:11 +08:00
|
|
|
s.beginGroup("General");
|
2014-07-02 06:47:06 +08:00
|
|
|
s.setValue("enableIPv6", enableIPv6);
|
2014-10-18 07:06:30 +08:00
|
|
|
s.setValue("translation",translation);
|
2014-07-13 04:58:58 +08:00
|
|
|
s.setValue("makeToxPortable",makeToxPortable);
|
2014-10-08 22:17:05 +08:00
|
|
|
s.setValue("autostartInTray",autostartInTray);
|
2014-10-20 03:47:06 +08:00
|
|
|
s.setValue("closeToTray", closeToTray);
|
2014-10-07 10:16:06 +08:00
|
|
|
s.setValue("useProxy", useProxy);
|
|
|
|
s.setValue("forceTCP", forceTCP);
|
|
|
|
s.setValue("proxyAddr", proxyAddr);
|
|
|
|
s.setValue("proxyPort", proxyPort);
|
2014-07-17 06:43:30 +08:00
|
|
|
s.setValue("currentProfile", currentProfile);
|
2014-10-16 17:47:58 +08:00
|
|
|
s.setValue("autoAwayTime", autoAwayTime);
|
2014-11-10 07:31:29 +08:00
|
|
|
s.setValue("checkUpdates", checkUpdates);
|
2014-11-10 08:23:41 +08:00
|
|
|
s.setValue("showInFront", showInFront);
|
2014-11-10 21:06:35 +08:00
|
|
|
s.setValue("fauxOfflineMessaging", fauxOfflineMessaging);
|
2014-06-25 04:11:11 +08:00
|
|
|
s.endGroup();
|
|
|
|
|
|
|
|
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-08-11 00:14:50 +08:00
|
|
|
s.setValue("nativeStyle", useNativeStyle);
|
2014-11-05 23:20:32 +08:00
|
|
|
s.setValue("useEmoticons", useEmoticons);
|
|
|
|
s.setValue("style", style);
|
2014-10-11 07:18:32 +08:00
|
|
|
s.setValue("statusChangeNotificationEnabled", statusChangeNotificationEnabled);
|
2014-08-11 23:33:32 +08:00
|
|
|
s.endGroup();
|
|
|
|
|
|
|
|
s.beginGroup("State");
|
2014-08-11 16:00:08 +08:00
|
|
|
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
|
|
|
|
|
|
|
s.beginGroup("AutoAccept");
|
2014-11-06 06:34:28 +08:00
|
|
|
s.setValue("autoSaveEnabled", autoSaveEnabled);
|
2014-10-20 12:25:52 +08:00
|
|
|
s.setValue("globalAutoAcceptDir", globalAutoAcceptDir);
|
2014-10-18 11:02:13 +08:00
|
|
|
for (auto& id : autoAccept.keys())
|
|
|
|
s.setValue(id, autoAccept.value(id));
|
|
|
|
s.endGroup();
|
2014-10-29 04:21:37 +08:00
|
|
|
|
|
|
|
s.beginGroup("Audio");
|
|
|
|
s.setValue("inDev", inDev);
|
|
|
|
s.setValue("outDev", outDev);
|
|
|
|
s.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
|
2014-08-30 16:28:00 +08:00
|
|
|
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
|
|
|
{
|
2014-09-28 05:37:39 +08:00
|
|
|
QDir dir(getSettingsDirPath());
|
2014-09-28 06:19:30 +08:00
|
|
|
QString filePath = dir.filePath("avatars/"+ownerId.left(64)+".png");
|
2014-09-28 05:37:39 +08:00
|
|
|
QFileInfo info(filePath);
|
2014-09-24 22:51:16 +08:00
|
|
|
QPixmap pic;
|
2014-09-28 05:37:39 +08:00
|
|
|
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);
|
2014-09-28 05:37:39 +08:00
|
|
|
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
|
|
|
{
|
2014-09-28 05:37:39 +08:00
|
|
|
QDir dir(getSettingsDirPath());
|
2014-09-29 09:54:28 +08:00
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
2014-09-29 09:54:28 +08:00
|
|
|
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
|
2014-09-01 04:44:52 +08:00
|
|
|
if (!newValue) // Update the new file right now if not already done
|
|
|
|
save();
|
2014-07-13 04:58:58 +08:00
|
|
|
}
|
|
|
|
|
2014-10-08 22:17:05 +08:00
|
|
|
bool Settings::getAutostartInTray() const
|
|
|
|
{
|
|
|
|
return autostartInTray;
|
|
|
|
}
|
|
|
|
|
2014-10-09 06:31:20 +08:00
|
|
|
QString Settings::getStyle() const
|
|
|
|
{
|
|
|
|
return style;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Settings::setStyle(const QString& newStyle)
|
|
|
|
{
|
|
|
|
style = newStyle;
|
|
|
|
}
|
|
|
|
|
2014-11-05 23:20:32 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-10-08 22:17:05 +08:00
|
|
|
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-10-11 07:18:32 +08:00
|
|
|
bool Settings::getStatusChangeNotificationEnabled() const
|
|
|
|
{
|
|
|
|
return statusChangeNotificationEnabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Settings::setStatusChangeNotificationEnabled(bool newValue)
|
|
|
|
{
|
|
|
|
statusChangeNotificationEnabled = newValue;
|
|
|
|
}
|
|
|
|
|
2014-11-10 08:23:41 +08:00
|
|
|
bool Settings::getShowInFront() const
|
|
|
|
{
|
|
|
|
return showInFront;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Settings::setShowInFront(bool newValue)
|
|
|
|
{
|
|
|
|
showInFront = newValue;
|
|
|
|
}
|
|
|
|
|
2014-10-18 07:06:30 +08:00
|
|
|
QString Settings::getTranslation() const
|
2014-07-05 01:22:43 +08:00
|
|
|
{
|
2014-10-18 07:06:30 +08:00
|
|
|
return translation;
|
2014-07-05 01:22:43 +08:00
|
|
|
}
|
|
|
|
|
2014-10-18 07:06:30 +08:00
|
|
|
void Settings::setTranslation(QString newValue)
|
2014-07-05 01:22:43 +08:00
|
|
|
{
|
2014-10-18 07:06:30 +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
|
|
|
}
|
|
|
|
|
2014-10-11 06:43:15 +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-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-10-18 11:02:13 +08:00
|
|
|
QString Settings::getAutoAcceptDir(const QString& id) const
|
|
|
|
{
|
|
|
|
return autoAccept.value(id.left(TOX_ID_PUBLIC_KEY_LENGTH));
|
|
|
|
}
|
|
|
|
|
2014-10-18 11:59:59 +08:00
|
|
|
void Settings::setAutoAcceptDir(const QString& id, const QString& dir)
|
2014-10-18 11:02:13 +08:00
|
|
|
{
|
2014-10-18 11:59:59 +08:00
|
|
|
if (dir.isEmpty())
|
|
|
|
autoAccept.remove(id.left(TOX_ID_PUBLIC_KEY_LENGTH));
|
|
|
|
else
|
|
|
|
autoAccept[id.left(TOX_ID_PUBLIC_KEY_LENGTH)] = 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;
|
|
|
|
}
|
|
|
|
|
2014-08-11 16:00:08 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-11-10 07:31:29 +08:00
|
|
|
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;
|
|
|
|
}
|
2014-11-08 00:02:10 +08:00
|
|
|
|
|
|
|
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 = "";
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2014-11-10 21:06:35 +08:00
|
|
|
|
|
|
|
bool Settings::getFauxOfflineMessaging() const
|
|
|
|
{
|
|
|
|
return fauxOfflineMessaging;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Settings::setFauxOfflineMessaging(bool value)
|
|
|
|
{
|
|
|
|
fauxOfflineMessaging = value;
|
|
|
|
}
|