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

372 lines
9.8 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.
*/
#ifndef SETTINGS_HPP
#define SETTINGS_HPP
#include <QHash>
2014-09-11 21:44:34 +08:00
#include <QObject>
2014-09-24 22:51:16 +08:00
#include <QPixmap>
2014-06-25 04:11:11 +08:00
struct ToxID;
2014-11-12 20:56:24 +08:00
namespace Db { enum class syncType; }
2014-12-28 20:32:25 +08:00
enum ProxyType {ptNone, ptSOCKS5, ptHTTP};
2014-06-25 04:11:11 +08:00
class Settings : public QObject
{
Q_OBJECT
public:
static Settings& getInstance();
void switchProfile(const QString& profile);
QString detectProfile();
QList<QString> searchProfiles();
QString askProfiles();
2014-11-02 16:00:05 +08:00
~Settings() = default;
2014-06-25 04:11:11 +08:00
void executeSettingsDialog(QWidget* parent);
static QString getSettingsDirPath();
struct DhtServer
{
QString name;
QString userId;
QString address;
quint16 port;
2014-06-25 04:11:11 +08:00
};
const QList<DhtServer>& getDhtServerList() const;
void setDhtServerList(const QList<DhtServer>& newDhtServerList);
2014-07-02 06:47:06 +08:00
bool getEnableIPv6() const;
void setEnableIPv6(bool newValue);
2014-07-13 04:58:58 +08:00
bool getMakeToxPortable() const;
void setMakeToxPortable(bool newValue);
2014-12-17 21:44:23 +08:00
bool getAutorun() const;
void setAutorun(bool newValue);
bool getAutostartInTray() const;
void setAutostartInTray(bool newValue);
2014-10-20 03:47:06 +08:00
bool getCloseToTray() const;
void setCloseToTray(bool newValue);
2014-10-20 19:50:12 +08:00
bool getMinimizeToTray() const;
void setMinimizeToTray(bool newValue);
2014-12-12 03:34:12 +08:00
bool getLightTrayIcon() const;
void setLightTrayIcon(bool newValue);
2014-10-20 19:50:12 +08:00
QString getStyle() const;
void setStyle(const QString& newValue);
bool getShowSystemTray() const;
void setShowSystemTray(const bool& newValue);
bool getUseEmoticons() const;
void setUseEmoticons(bool newValue);
QString getCurrentProfile() const;
uint32_t getCurrentProfileId() const;
void setCurrentProfile(QString profile);
QString getTranslation() const;
void setTranslation(QString newValue);
void setAutoSaveEnabled(bool newValue);
bool getAutoSaveEnabled() const;
2014-07-05 01:22:43 +08:00
2014-10-06 04:49:44 +08:00
bool getForceTCP() const;
void setForceTCP(bool newValue);
2014-10-06 04:49:44 +08:00
QString getProxyAddr() const;
void setProxyAddr(const QString& newValue);
2014-12-28 20:32:25 +08:00
ProxyType getProxyType() const;
void setProxyType(int newValue);
2014-10-07 10:09:15 +08:00
2014-10-06 04:49:44 +08:00
int getProxyPort() const;
void setProxyPort(int newValue);
2014-06-25 04:11:11 +08:00
bool getEnableLogging() const;
void setEnableLogging(bool newValue);
bool getEncryptLogs() const;
void setEncryptLogs(bool newValue);
2014-10-12 15:31:48 +08:00
bool getEncryptTox() const;
void setEncryptTox(bool newValue);
2014-11-12 20:56:24 +08:00
Db::syncType getDbSyncType() const;
void setDbSyncType(int newValue);
2014-10-16 17:47:58 +08:00
int getAutoAwayTime() const;
void setAutoAwayTime(int newValue);
bool getCheckUpdates() const;
void setCheckUpdates(bool newValue);
bool getShowWindow() const;
void setShowWindow(bool newValue);
bool getShowInFront() const;
void setShowInFront(bool newValue);
bool getNotifySound() const;
void setNotifySound(bool newValue);
bool getGroupAlwaysNotify() const;
void setGroupAlwaysNotify(bool newValue);
2014-09-24 23:55:54 +08:00
QPixmap getSavedAvatar(const QString& ownerId);
void saveAvatar(QPixmap& pic, const QString& ownerId);
2014-09-24 22:51:16 +08:00
QByteArray getAvatarHash(const QString& ownerId);
void saveAvatarHash(const QByteArray& hash, const QString& ownerId);
2014-10-29 04:21:37 +08:00
QString getInDev() const;
void setInDev(const QString& deviceSpecifier);
QString getOutDev() const;
void setOutDev(const QString& deviceSpecifier);
bool getFilterAudio() const;
void setFilterAudio(bool newValue);
QSize getCamVideoRes() const;
void setCamVideoRes(QSize newValue);
2014-06-25 04:11:11 +08:00
// Assume all widgets have unique names
// 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.
QByteArray getWidgetData(const QString& uniqueName) const;
void setWidgetData(const QString& uniqueName, const QByteArray& data);
// Wrappers around getWidgetData() and setWidgetData()
// Assume widget has a unique objectName set
template <class T>
void restoreGeometryState(T* widget) const
{
widget->restoreGeometry(getWidgetData(widget->objectName() + "Geometry"));
widget->restoreState(getWidgetData(widget->objectName() + "State"));
}
template <class T>
void saveGeometryState(const T* widget)
{
setWidgetData(widget->objectName() + "Geometry", widget->saveGeometry());
setWidgetData(widget->objectName() + "State", widget->saveState());
}
bool isAnimationEnabled() const;
void setAnimationEnabled(bool newValue);
2014-07-25 20:52:14 +08:00
QString getSmileyPack() const;
void setSmileyPack(const QString &value);
2014-06-25 04:11:11 +08:00
2014-11-16 04:30:20 +08:00
int getThemeColor() const;
void setThemeColor(const int& value);
2014-06-25 04:11:11 +08:00
bool isCurstomEmojiFont() const;
void setCurstomEmojiFont(bool value);
QString getEmojiFontFamily() const;
void setEmojiFontFamily(const QString &value);
int getEmojiFontPointSize() const;
void setEmojiFontPointSize(int value);
2014-11-17 18:10:38 +08:00
QString getAutoAcceptDir(const ToxID& id) const;
void setAutoAcceptDir(const ToxID&id, const QString& dir);
2014-10-18 11:02:13 +08:00
2014-10-20 12:25:52 +08:00
QString getGlobalAutoAcceptDir() const;
void setGlobalAutoAcceptDir(const QString& dir);
2014-06-25 04:11:11 +08:00
// ChatView
int getFirstColumnHandlePos() const;
void setFirstColumnHandlePos(const int pos);
int getSecondColumnHandlePosFromRight() const;
void setSecondColumnHandlePosFromRight(const int pos);
const QString &getTimestampFormat() const;
void setTimestampFormat(const QString &format);
const QString &getDateFormat() const;
void setDateFormat(const QString &format);
2014-06-25 04:11:11 +08:00
bool isMinimizeOnCloseEnabled() const;
void setMinimizeOnClose(bool newValue);
bool getStatusChangeNotificationEnabled() const;
void setStatusChangeNotificationEnabled(bool newValue);
2014-06-25 04:11:11 +08:00
// Privacy
bool isTypingNotificationEnabled() const;
void setTypingNotification(bool enabled);
// State
2014-08-11 00:14:50 +08:00
bool getUseNativeStyle() const;
void setUseNativeStyle(bool value);
QByteArray getWindowGeometry() const;
void setWindowGeometry(const QByteArray &value);
QByteArray getWindowState() const;
void setWindowState(const QByteArray &value);
2014-08-11 20:07:27 +08:00
QByteArray getSplitterState() const;
void setSplitterState(const QByteArray &value);
QString getFriendAdress(const QString &publicKey) const;
void updateFriendAdress(const QString &newAddr);
QString getFriendAlias(const ToxID &id) const;
void setFriendAlias(const ToxID &id, const QString &alias);
void removeFriendSettings(const ToxID &id);
2014-11-10 21:06:35 +08:00
bool getFauxOfflineMessaging() const;
void setFauxOfflineMessaging(bool value);
bool getCompactLayout() const;
void setCompactLayout(bool compact);
bool getGroupchatPosition() const;
void setGroupchatPosition(bool value);
2014-09-01 04:26:45 +08:00
public:
void save(bool writePersonal = true);
void save(QString path, bool writePersonal = true);
2014-06-25 04:11:11 +08:00
void load();
2014-09-01 04:26:45 +08:00
private:
static Settings* settings;
2014-09-01 04:26:45 +08:00
Settings();
Settings(Settings &settings) = delete;
Settings& operator=(const Settings&) = delete;
static uint32_t makeProfileId(const QString& profile);
void saveGlobal(QString path);
void savePersonal(QString path);
2014-06-25 04:11:11 +08:00
static const QString FILENAME;
2014-12-03 06:47:55 +08:00
static const QString OLDFILENAME;
2014-06-25 04:11:11 +08:00
bool loaded;
bool useCustomDhtList;
2014-06-25 04:11:11 +08:00
QList<DhtServer> dhtServerList;
int dhtServerId;
bool dontShowDhtDialog;
2014-11-10 21:06:35 +08:00
bool fauxOfflineMessaging;
bool compactLayout;
bool groupchatPosition;
2014-07-02 06:47:06 +08:00
bool enableIPv6;
QString translation;
2014-07-13 04:58:58 +08:00
static bool makeToxPortable;
bool autostartInTray;
2014-10-20 03:47:06 +08:00
bool closeToTray;
2014-10-20 19:50:12 +08:00
bool minimizeToTray;
2014-12-12 03:34:12 +08:00
bool lightTrayIcon;
bool useEmoticons;
bool checkUpdates;
bool showWindow;
bool showInFront;
bool notifySound;
bool groupAlwaysNotify;
2014-10-06 04:49:44 +08:00
bool forceTCP;
2014-10-07 10:09:15 +08:00
2014-12-28 20:32:25 +08:00
ProxyType proxyType;
2014-10-06 04:49:44 +08:00
QString proxyAddr;
int proxyPort;
2014-07-02 06:47:06 +08:00
QString currentProfile;
uint32_t currentProfileId;
2014-07-02 06:47:06 +08:00
2014-06-25 04:11:11 +08:00
bool enableLogging;
bool encryptLogs;
2015-03-12 11:02:10 +08:00
bool encryptTox = false;
2014-06-25 04:11:11 +08:00
2014-10-16 17:47:58 +08:00
int autoAwayTime;
2014-06-25 04:11:11 +08:00
QHash<QString, QByteArray> widgetSettings;
2014-10-18 11:02:13 +08:00
QHash<QString, QString> autoAccept;
2014-11-06 05:59:29 +08:00
bool autoSaveEnabled;
2014-10-20 12:25:52 +08:00
QString globalAutoAcceptDir;
2014-06-25 04:11:11 +08:00
// GUI
bool enableSmoothAnimation;
2014-07-25 20:52:14 +08:00
QString smileyPack;
2014-06-25 04:11:11 +08:00
bool customEmojiFont;
QString emojiFontFamily;
int emojiFontPointSize;
bool minimizeOnClose;
2014-08-11 00:14:50 +08:00
bool useNativeStyle;
QByteArray windowGeometry;
QByteArray windowState;
2014-08-11 20:07:27 +08:00
QByteArray splitterState;
QString style;
bool showSystemTray;
2014-06-25 04:11:11 +08:00
// ChatView
int firstColumnHandlePos;
int secondColumnHandlePosFromRight;
QString timestampFormat;
QString dateFormat;
bool statusChangeNotificationEnabled;
2014-06-25 04:11:11 +08:00
// Privacy
bool typingNotification;
2014-11-12 20:56:24 +08:00
Db::syncType dbSyncType;
2014-06-25 04:11:11 +08:00
2014-10-29 04:21:37 +08:00
// Audio
QString inDev;
QString outDev;
bool filterAudio;
2014-10-29 04:21:37 +08:00
// Video
QSize camVideoRes;
struct friendProp
{
QString alias;
QString addr;
2014-11-17 18:10:38 +08:00
QString autoAcceptDir;
};
QHash<QString, friendProp> friendLst;
2014-11-16 04:30:20 +08:00
int themeColor;
2014-11-10 21:06:35 +08:00
2014-06-25 04:11:11 +08:00
signals:
//void dataChanged();
void dhtServerListChanged();
void logStorageOptsChanged();
void smileyPackChanged();
void emojiFontChanged();
void timestampFormatChanged();
void dateFormatChanged();
void compactLayoutChanged();
2014-06-25 04:11:11 +08:00
};
#endif // SETTINGS_HPP