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

Add Settings biglock

This commit is contained in:
tux3 2015-06-05 16:27:15 +02:00
parent 1ded562d9d
commit 61de5d4c67
No known key found for this signature in database
GPG Key ID: 7E086DD661263264
2 changed files with 138 additions and 15 deletions

View File

@ -36,12 +36,14 @@
#include <QList>
#include <QStyleFactory>
#include <QCryptographicHash>
#include <QMutexLocker>
#define SHOW_SYSTEM_TRAY_DEFAULT (bool) true
const QString Settings::globalSettingsFile = "qtox.ini";
Settings* Settings::settings{nullptr};
QMutex Settings::bigLock{QMutex::Recursive};
Settings::Settings() :
loaded(false), useCustomDhtList{false},
@ -60,6 +62,8 @@ Settings& Settings::getInstance()
void Settings::load()
{
QMutexLocker locker{&bigLock};
if (loaded)
return;
@ -276,6 +280,7 @@ void Settings::save(QString path, bool writePersonal)
void Settings::saveGlobal(QString path)
{
QMutexLocker locker{&bigLock};
qDebug() << "Saving settings in " + path;
QSettings s(path, QSettings::IniFormat);
@ -376,6 +381,7 @@ void Settings::saveGlobal(QString path)
void Settings::savePersonal(QString path)
{
QMutexLocker locker{&bigLock};
if (currentProfile.isEmpty())
{
qDebug() << "could not save personal settings because currentProfile profile is empty";
@ -414,6 +420,7 @@ uint32_t Settings::makeProfileId(const QString& profile)
QString Settings::getSettingsDirPath()
{
QMutexLocker locker{&bigLock};
if (makeToxPortable)
return QString(".")+QDir::separator();
@ -486,32 +493,38 @@ QByteArray Settings::getAvatarHash(const QString& ownerId)
const QList<DhtServer>& Settings::getDhtServerList() const
{
QMutexLocker locker{&bigLock};
return dhtServerList;
}
void Settings::setDhtServerList(const QList<DhtServer>& newDhtServerList)
{
QMutexLocker locker{&bigLock};
dhtServerList = newDhtServerList;
emit dhtServerListChanged();
}
bool Settings::getEnableIPv6() const
{
QMutexLocker locker{&bigLock};
return enableIPv6;
}
void Settings::setEnableIPv6(bool newValue)
{
QMutexLocker locker{&bigLock};
enableIPv6 = newValue;
}
bool Settings::getMakeToxPortable() const
{
QMutexLocker locker{&bigLock};
return makeToxPortable;
}
void Settings::setMakeToxPortable(bool newValue)
{
QMutexLocker locker{&bigLock};
makeToxPortable = newValue;
save(globalSettingsFile); // 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
@ -521,6 +534,7 @@ void Settings::setMakeToxPortable(bool newValue)
bool Settings::getAutorun() const
{
#ifdef QTOX_PLATFORM_EXT
QMutexLocker locker{&bigLock};
return Platform::getAutorun();
#else
return false;
@ -530,6 +544,7 @@ bool Settings::getAutorun() const
void Settings::setAutorun(bool newValue)
{
#ifdef QTOX_PLATFORM_EXT
QMutexLocker locker{&bigLock};
Platform::setAutorun(newValue);
#else
Q_UNUSED(newValue);
@ -538,152 +553,181 @@ void Settings::setAutorun(bool newValue)
bool Settings::getAutostartInTray() const
{
QMutexLocker locker{&bigLock};
return autostartInTray;
}
QString Settings::getStyle() const
{
QMutexLocker locker{&bigLock};
return style;
}
void Settings::setStyle(const QString& newStyle)
{
QMutexLocker locker{&bigLock};
style = newStyle;
}
bool Settings::getShowSystemTray() const
{
QMutexLocker locker{&bigLock};
return showSystemTray;
}
void Settings::setShowSystemTray(const bool& newValue)
{
QMutexLocker locker{&bigLock};
showSystemTray = newValue;
}
void Settings::setUseEmoticons(bool newValue)
{
QMutexLocker locker{&bigLock};
useEmoticons = newValue;
}
bool Settings::getUseEmoticons() const
{
QMutexLocker locker{&bigLock};
return useEmoticons;
}
void Settings::setAutoSaveEnabled(bool newValue)
{
QMutexLocker locker{&bigLock};
autoSaveEnabled = newValue;
}
bool Settings::getAutoSaveEnabled() const
{
QMutexLocker locker{&bigLock};
return autoSaveEnabled;
}
void Settings::setAutostartInTray(bool newValue)
{
QMutexLocker locker{&bigLock};
autostartInTray = newValue;
}
bool Settings::getCloseToTray() const
{
QMutexLocker locker{&bigLock};
return closeToTray;
}
void Settings::setCloseToTray(bool newValue)
{
QMutexLocker locker{&bigLock};
closeToTray = newValue;
}
bool Settings::getMinimizeToTray() const
{
QMutexLocker locker{&bigLock};
return minimizeToTray;
}
void Settings::setMinimizeToTray(bool newValue)
{
QMutexLocker locker{&bigLock};
minimizeToTray = newValue;
}
bool Settings::getLightTrayIcon() const
{
QMutexLocker locker{&bigLock};
return lightTrayIcon;
}
void Settings::setLightTrayIcon(bool newValue)
{
QMutexLocker locker{&bigLock};
lightTrayIcon = newValue;
}
bool Settings::getStatusChangeNotificationEnabled() const
{
QMutexLocker locker{&bigLock};
return statusChangeNotificationEnabled;
}
void Settings::setStatusChangeNotificationEnabled(bool newValue)
{
QMutexLocker locker{&bigLock};
statusChangeNotificationEnabled = newValue;
}
bool Settings::getShowInFront() const
{
QMutexLocker locker{&bigLock};
return showInFront;
}
void Settings::setShowInFront(bool newValue)
{
QMutexLocker locker{&bigLock};
showInFront = newValue;
}
bool Settings::getNotifySound() const
{
return notifySound;
QMutexLocker locker{&bigLock};
return notifySound;
}
void Settings::setNotifySound(bool newValue)
{
QMutexLocker locker{&bigLock};
notifySound = newValue;
}
bool Settings::getGroupAlwaysNotify() const
{
QMutexLocker locker{&bigLock};
return groupAlwaysNotify;
}
void Settings::setGroupAlwaysNotify(bool newValue)
{
QMutexLocker locker{&bigLock};
groupAlwaysNotify = newValue;
}
QString Settings::getTranslation() const
{
QMutexLocker locker{&bigLock};
return translation;
}
void Settings::setTranslation(QString newValue)
{
QMutexLocker locker{&bigLock};
translation = newValue;
}
bool Settings::getForceTCP() const
{
QMutexLocker locker{&bigLock};
return forceTCP;
}
void Settings::setForceTCP(bool newValue)
{
QMutexLocker locker{&bigLock};
forceTCP = newValue;
}
ProxyType Settings::getProxyType() const
{
QMutexLocker locker{&bigLock};
return proxyType;
}
void Settings::setProxyType(int newValue)
{
QMutexLocker locker{&bigLock};
if (newValue >= 0 && newValue <= 2)
proxyType = static_cast<ProxyType>(newValue);
else
@ -692,57 +736,68 @@ void Settings::setProxyType(int newValue)
QString Settings::getProxyAddr() const
{
QMutexLocker locker{&bigLock};
return proxyAddr;
}
void Settings::setProxyAddr(const QString& newValue)
{
QMutexLocker locker{&bigLock};
proxyAddr = newValue;
}
int Settings::getProxyPort() const
{
QMutexLocker locker{&bigLock};
return proxyPort;
}
void Settings::setProxyPort(int newValue)
{
QMutexLocker locker{&bigLock};
proxyPort = newValue;
}
QString Settings::getCurrentProfile() const
{
QMutexLocker locker{&bigLock};
return currentProfile;
}
uint32_t Settings::getCurrentProfileId() const
{
QMutexLocker locker{&bigLock};
return currentProfileId;
}
void Settings::setCurrentProfile(QString profile)
{
QMutexLocker locker{&bigLock};
currentProfile = profile;
currentProfileId = makeProfileId(currentProfile);
}
bool Settings::getEnableLogging() const
{
QMutexLocker locker{&bigLock};
return enableLogging;
}
void Settings::setEnableLogging(bool newValue)
{
QMutexLocker locker{&bigLock};
enableLogging = newValue;
}
Db::syncType Settings::getDbSyncType() const
{
QMutexLocker locker{&bigLock};
return dbSyncType;
}
void Settings::setDbSyncType(int newValue)
{
QMutexLocker locker{&bigLock};
if (newValue >= 0 && newValue <= 2)
dbSyncType = static_cast<Db::syncType>(newValue);
else
@ -751,11 +806,13 @@ void Settings::setDbSyncType(int newValue)
int Settings::getAutoAwayTime() const
{
QMutexLocker locker{&bigLock};
return autoAwayTime;
}
void Settings::setAutoAwayTime(int newValue)
{
QMutexLocker locker{&bigLock};
if (newValue < 0)
newValue = 10;
@ -764,6 +821,7 @@ void Settings::setAutoAwayTime(int newValue)
QString Settings::getAutoAcceptDir(const ToxId& id) const
{
QMutexLocker locker{&bigLock};
QString key = id.publicKey;
auto it = friendLst.find(key);
@ -775,6 +833,7 @@ QString Settings::getAutoAcceptDir(const ToxId& id) const
void Settings::setAutoAcceptDir(const ToxId &id, const QString& dir)
{
QMutexLocker locker{&bigLock};
QString key = id.publicKey;
auto it = friendLst.find(key);
@ -791,251 +850,299 @@ void Settings::setAutoAcceptDir(const ToxId &id, const QString& dir)
QString Settings::getGlobalAutoAcceptDir() const
{
QMutexLocker locker{&bigLock};
return globalAutoAcceptDir;
}
void Settings::setGlobalAutoAcceptDir(const QString& newValue)
{
QMutexLocker locker{&bigLock};
globalAutoAcceptDir = newValue;
}
void Settings::setWidgetData(const QString& uniqueName, const QByteArray& data)
{
QMutexLocker locker{&bigLock};
widgetSettings[uniqueName] = data;
}
QByteArray Settings::getWidgetData(const QString& uniqueName) const
{
QMutexLocker locker{&bigLock};
return widgetSettings.value(uniqueName);
}
bool Settings::isAnimationEnabled() const
{
QMutexLocker locker{&bigLock};
return enableSmoothAnimation;
}
void Settings::setAnimationEnabled(bool newValue)
{
QMutexLocker locker{&bigLock};
enableSmoothAnimation = newValue;
}
QString Settings::getSmileyPack() const
{
QMutexLocker locker{&bigLock};
return smileyPack;
}
void Settings::setSmileyPack(const QString &value)
{
QMutexLocker locker{&bigLock};
smileyPack = value;
emit smileyPackChanged();
}
bool Settings::isCurstomEmojiFont() const
{
QMutexLocker locker{&bigLock};
return customEmojiFont;
}
void Settings::setCurstomEmojiFont(bool value)
{
QMutexLocker locker{&bigLock};
customEmojiFont = value;
emit emojiFontChanged();
}
int Settings::getEmojiFontPointSize() const
{
QMutexLocker locker{&bigLock};
return emojiFontPointSize;
}
void Settings::setEmojiFontPointSize(int value)
{
QMutexLocker locker{&bigLock};
emojiFontPointSize = value;
emit emojiFontChanged();
}
int Settings::getFirstColumnHandlePos() const
{
QMutexLocker locker{&bigLock};
return firstColumnHandlePos;
}
void Settings::setFirstColumnHandlePos(const int pos)
{
QMutexLocker locker{&bigLock};
firstColumnHandlePos = pos;
}
int Settings::getSecondColumnHandlePosFromRight() const
{
QMutexLocker locker{&bigLock};
return secondColumnHandlePosFromRight;
}
void Settings::setSecondColumnHandlePosFromRight(const int pos)
{
QMutexLocker locker{&bigLock};
secondColumnHandlePosFromRight = pos;
}
const QString& Settings::getTimestampFormat() const
{
QMutexLocker locker{&bigLock};
return timestampFormat;
}
void Settings::setTimestampFormat(const QString &format)
{
QMutexLocker locker{&bigLock};
timestampFormat = format;
}
const QString& Settings::getDateFormat() const
{
QMutexLocker locker{&bigLock};
return dateFormat;
}
void Settings::setDateFormat(const QString &format)
{
QMutexLocker locker{&bigLock};
dateFormat = format;
}
QString Settings::getEmojiFontFamily() const
{
QMutexLocker locker{&bigLock};
return emojiFontFamily;
}
void Settings::setEmojiFontFamily(const QString &value)
{
QMutexLocker locker{&bigLock};
emojiFontFamily = value;
emit emojiFontChanged();
}
bool Settings::getUseNativeStyle() const
{
QMutexLocker locker{&bigLock};
return useNativeStyle;
}
void Settings::setUseNativeStyle(bool value)
{
QMutexLocker locker{&bigLock};
useNativeStyle = value;
}
QByteArray Settings::getWindowGeometry() const
{
QMutexLocker locker{&bigLock};
return windowGeometry;
}
void Settings::setWindowGeometry(const QByteArray &value)
{
QMutexLocker locker{&bigLock};
windowGeometry = value;
}
QByteArray Settings::getWindowState() const
{
QMutexLocker locker{&bigLock};
return windowState;
}
void Settings::setWindowState(const QByteArray &value)
{
QMutexLocker locker{&bigLock};
windowState = value;
}
bool Settings::getCheckUpdates() const
{
QMutexLocker locker{&bigLock};
return checkUpdates;
}
void Settings::setCheckUpdates(bool newValue)
{
QMutexLocker locker{&bigLock};
checkUpdates = newValue;
}
bool Settings::getShowWindow() const
{
QMutexLocker locker{&bigLock};
return showWindow;
}
void Settings::setShowWindow(bool newValue)
{
QMutexLocker locker{&bigLock};
showWindow = newValue;
}
QByteArray Settings::getSplitterState() const
{
QMutexLocker locker{&bigLock};
return splitterState;
}
void Settings::setSplitterState(const QByteArray &value)
{
QMutexLocker locker{&bigLock};
splitterState = value;
}
bool Settings::isMinimizeOnCloseEnabled() const
{
QMutexLocker locker{&bigLock};
return minimizeOnClose;
}
void Settings::setMinimizeOnClose(bool newValue)
{
QMutexLocker locker{&bigLock};
minimizeOnClose = newValue;
}
bool Settings::isTypingNotificationEnabled() const
{
QMutexLocker locker{&bigLock};
return typingNotification;
}
void Settings::setTypingNotification(bool enabled)
{
QMutexLocker locker{&bigLock};
typingNotification = enabled;
}
QString Settings::getInDev() const
{
QMutexLocker locker{&bigLock};
return inDev;
}
void Settings::setInDev(const QString& deviceSpecifier)
{
QMutexLocker locker{&bigLock};
inDev = deviceSpecifier;
}
QString Settings::getVideoDev() const
{
QMutexLocker locker{&bigLock};
return videoDev;
}
void Settings::setVideoDev(const QString& deviceSpecifier)
{
QMutexLocker locker{&bigLock};
videoDev = deviceSpecifier;
}
QString Settings::getOutDev() const
{
QMutexLocker locker{&bigLock};
return outDev;
}
void Settings::setOutDev(const QString& deviceSpecifier)
{
QMutexLocker locker{&bigLock};
outDev = deviceSpecifier;
}
bool Settings::getFilterAudio() const
{
QMutexLocker locker{&bigLock};
return filterAudio;
}
void Settings::setFilterAudio(bool newValue)
{
QMutexLocker locker{&bigLock};
filterAudio = newValue;
}
QSize Settings::getCamVideoRes() const
{
QMutexLocker locker{&bigLock};
return camVideoRes;
}
void Settings::setCamVideoRes(QSize newValue)
{
QMutexLocker locker{&bigLock};
camVideoRes = newValue;
}
QString Settings::getFriendAdress(const QString &publicKey) const
{
QMutexLocker locker{&bigLock};
QString key = ToxId(publicKey).publicKey;
auto it = friendLst.find(key);
if (it != friendLst.end())
@ -1046,6 +1153,7 @@ QString Settings::getFriendAdress(const QString &publicKey) const
void Settings::updateFriendAdress(const QString &newAddr)
{
QMutexLocker locker{&bigLock};
QString key = ToxId(newAddr).publicKey;
auto it = friendLst.find(key);
if (it != friendLst.end())
@ -1064,6 +1172,7 @@ void Settings::updateFriendAdress(const QString &newAddr)
QString Settings::getFriendAlias(const ToxId &id) const
{
QMutexLocker locker{&bigLock};
QString key = id.publicKey;
auto it = friendLst.find(key);
if (it != friendLst.end())
@ -1074,6 +1183,7 @@ QString Settings::getFriendAlias(const ToxId &id) const
void Settings::setFriendAlias(const ToxId &id, const QString &alias)
{
QMutexLocker locker{&bigLock};
QString key = id.publicKey;
auto it = friendLst.find(key);
if (it != friendLst.end())
@ -1092,50 +1202,71 @@ void Settings::setFriendAlias(const ToxId &id, const QString &alias)
void Settings::removeFriendSettings(const ToxId &id)
{
QMutexLocker locker{&bigLock};
QString key = id.publicKey;
friendLst.remove(key);
}
bool Settings::getFauxOfflineMessaging() const
{
QMutexLocker locker{&bigLock};
return fauxOfflineMessaging;
}
void Settings::setFauxOfflineMessaging(bool value)
{
QMutexLocker locker{&bigLock};
fauxOfflineMessaging = value;
}
bool Settings::getCompactLayout() const
{
QMutexLocker locker{&bigLock};
return compactLayout;
}
void Settings::setCompactLayout(bool value)
{
QMutexLocker locker{&bigLock};
compactLayout = value;
}
bool Settings::getGroupchatPosition() const
{
QMutexLocker locker{&bigLock};
return groupchatPosition;
}
void Settings::setGroupchatPosition(bool value)
{
QMutexLocker locker{&bigLock};
groupchatPosition = value;
}
int Settings::getThemeColor() const
{
QMutexLocker locker{&bigLock};
return themeColor;
}
void Settings::setThemeColor(const int &value)
{
QMutexLocker locker{&bigLock};
themeColor = value;
}
bool Settings::getAutoLogin() const
{
QMutexLocker locker{&bigLock};
return autoLogin;
}
void Settings::setAutoLogin(bool state)
{
QMutexLocker locker{&bigLock};
autoLogin = state;
}
void Settings::createPersonal(QString basename)
{
QString path = getSettingsDirPath() + QDir::separator() + basename + ".ini";
@ -1158,13 +1289,3 @@ void Settings::createSettingsDir()
if (!directory.exists() && !directory.mkpath(directory.absolutePath()))
qCritical() << "Error while creating directory " << dir;
}
bool Settings::getAutoLogin() const
{
return autoLogin;
}
void Settings::setAutoLogin(bool state)
{
autoLogin = state;
}

View File

@ -20,6 +20,7 @@
#include <QHash>
#include <QObject>
#include <QPixmap>
#include <QMutex>
#include "src/core/corestructs.h"
class ToxId;
@ -38,9 +39,9 @@ public:
void createSettingsDir(); ///< Creates a path to the settings dir, if it doesn't already exist
void createPersonal(QString basename); ///< Write a default personnal .ini settings file for a profile
void load();
void save(bool writePersonal = true);
void save(QString path, bool writePersonal = true);
void load();
signals:
void dhtServerListChanged();
@ -348,6 +349,7 @@ private:
int themeColor;
static QMutex bigLock;
static Settings* settings;
static const QString globalSettingsFile;
};