1 /*************************************************************************** 2 * * 3 * This program is free software; you can redistribute it and/or modify * 4 * it under the terms of the GNU General Public License as published by * 5 * the Free Software Foundation; either version 3 of the License, or * 6 * (at your option) any later version. * 7 * * 8 ***************************************************************************/ 9 10 #pragma once 11 12 #include <QObject> 13 #include <QMap> 14 #include <QTranslator> 15 #include <QFont> 16 #include <QSettings> 17 18 #include "dcpp/stdinc.h" 19 #include "dcpp/Singleton.h" 20 21 static const QString & WS_CHAT_OP_COLOR = "chat-op-color"; 22 static const QString & WS_CHAT_USER_COLOR = "chat-us-color"; 23 static const QString & WS_CHAT_CORE_COLOR = "chat-co-color"; 24 static const QString & WS_CHAT_BOT_COLOR = "chat-bt-color"; 25 static const QString & WS_CHAT_FIND_COLOR = "chat-find-color"; 26 static const QString & WS_CHAT_LOCAL_COLOR = "chat-lc-color"; 27 static const QString & WS_CHAT_STAT_COLOR = "chat-st-color"; 28 static const QString & WS_CHAT_TIME_COLOR = "chat-ts-color"; 29 static const QString & WS_CHAT_MSG_COLOR = "chat-msg-color"; 30 static const QString & WS_CHAT_PRIV_USER_COLOR = "chat-pr-us-color"; 31 static const QString & WS_CHAT_PRIV_LOCAL_COLOR = "chat-pr-lc-color"; 32 static const QString & WS_CHAT_FAVUSER_COLOR = "chat-fu-color"; 33 static const QString & WS_CHAT_SAY_NICK = "chat-say-mynick"; 34 static const QString & WS_CHAT_USERLIST_STATE = "chat-userlist-saved-state"; 35 static const QString & WS_CHAT_CMD_ALIASES = "chat-cmd-aliases"; 36 static const QString & WS_CHAT_FONT = "chat-font"; 37 static const QString & WS_CHAT_ULIST_FONT = "chat-userlist-font"; 38 static const QString & WS_CHAT_PM_FONT = "chat-pm-font"; 39 static const QString & WS_CHAT_SEPARATOR = "chat-separator"; 40 static const QString & WS_CHAT_TIMESTAMP = "chat-timestamp"; 41 static const QString & WS_QCONNECT_HISTORY = "qc-history"; 42 static const QString & WS_DEFAULT_LOCALE = "default_locale"; 43 static const QString & WS_DOWNLOAD_DIR_HISTORY = "download-directory-history"; 44 static const QString & WS_DQUEUE_STATE = "dqueue-state"; 45 static const QString & WS_SEARCH_STATE = "search-state"; 46 static const QString & WS_SEARCH_HISTORY = "search-history"; 47 static const QString & WS_TRANSLATION_FILE = "translation-file"; 48 static const QString & WS_TRANSFERS_STATE = "transfer-state"; 49 static const QString & WS_MAINWINDOW_STATE = "mainwindow-state"; 50 static const QString & WS_MAINWINDOW_TOOLBAR_ACTS = "mainwindow-toolbar-enabled-actions"; 51 static const QString & WS_SHARE_LPANE_STATE = "share-lpane-state"; 52 static const QString & WS_SHARE_RPANE_STATE = "share-rpane-state"; 53 static const QString & WS_FTRANSFERS_USERS_STATE = "finished-u-state"; 54 static const QString & WS_FTRANSFERS_FILES_STATE = "finished-f-state"; 55 static const QString & WS_FAV_HUBS_STATE = "fav-hubs-state"; 56 static const QString & WS_ADLS_STATE = "adls-state"; 57 static const QString & WS_APP_THEME = "app-theme-name"; 58 static const QString & WS_APP_FONT = "app-font-name"; 59 static const QString & WS_APP_ENABLED_SCRIPTS = "app-enabled-scripts"; 60 static const QString & WS_NOTIFY_SOUNDS = "notify-sound-files"; 61 static const QString & WS_NOTIFY_SND_CMD = "notify-sound-cmd"; 62 static const QString & WS_FAVUSERS_STATE = "favoriteusers-state"; 63 static const QString & WS_SHAREHEADER_STATE = "shareheader-state"; 64 static const QString & WS_DOWNLOADTO_ALIASES = "downloadto-aliases"; 65 static const QString & WS_DOWNLOADTO_PATHS = "downloadto-paths"; 66 static const QString & WS_APP_ICONTHEME = "app-theme-icons"; 67 static const QString & WS_APP_USERTHEME = "app-theme-users"; 68 static const QString & WS_APP_ASPELL_LANG = "app-aspell-lang"; 69 static const QString & WS_APP_EMOTICON_THEME = "app-emoticon-theme"; 70 static const QString & WS_APP_SHARED_FILES_COLOR = "app-already-shared-files-color"; 71 static const QString & WS_PUBLICHUBS_STATE = "publichubs-state"; 72 static const QString & WS_SETTINGS_GUI_FONTS_STATE= "settings-gui-fonts-state"; 73 static const QString & WB_APP_AUTOAWAY_BY_TIMER = "app-autoaway"; 74 static const QString & WB_CHAT_SHOW_TIMESTAMP = "chat-show-timestamp"; 75 static const QString & WB_SHOW_FREE_SPACE = "show-free-space"; 76 static const QString & WB_CHAT_SHOW_JOINS = "chat-show-joins"; 77 static const QString & WB_CHAT_SHOW_JOINS_FAV = "chat-show-joins-fav-only"; 78 static const QString & WB_CHAT_REDIRECT_BOT_PMS = "chat-redirect-pms-from-bot"; 79 static const QString & WB_CHAT_KEEPFOCUS = "chat-keep-focus"; 80 static const QString & WB_CHAT_HIGHLIGHT_FAVS = "chat-highlight-favs"; 81 static const QString & WB_CHAT_ROTATING_MSGS = "chat-support-rotating-messages"; 82 static const QString & WB_CHAT_USE_SMILE_PANEL = "chat-use-smile-panel"; 83 static const QString & WB_CHAT_HIDE_SMILE_PANEL = "chat-autohide-smile-panel"; 84 static const QString & WB_MAINWINDOW_MAXIMIZED = "mainwindow-maximized"; 85 static const QString & WB_MAINWINDOW_HIDE = "mainwindow-autohide"; 86 static const QString & WB_MAINWINDOW_REMEMBER = "mainwindow-remember-position-on-exit"; 87 static const QString & WB_MAINWINDOW_USE_M_TABBAR = "mainwindow-use-multi-line-tabbar"; 88 static const QString & WB_MAINWINDOW_USE_SIDEBAR = "mainwindow-use-sidebar"; 89 static const QString & WB_SEARCHFILTER_NOFREE = "search-filter-nofree"; 90 static const QString & WB_SEARCH_DONTHIDEPANEL = "search-panel-dont-hide"; 91 static const QString & WB_ANTISPAM_ENABLED = "antispam-enabled"; 92 static const QString & WB_ANTISPAM_AS_FILTER = "antispam-as-filter"; 93 static const QString & WB_ANTISPAM_FILTER_OPS = "antispam-filter-ops"; 94 static const QString & WB_IPFILTER_ENABLED = "ipfilter-enabled"; 95 static const QString & WB_TRAY_ENABLED = "systemtray-enabled"; 96 static const QString & WB_EXIT_CONFIRM = "exit-confirm"; 97 static const QString & WB_SHOW_IP_IN_CHAT = "show-ip-in-chat"; 98 static const QString & WB_SHOW_HIDDEN_USERS = "show-hidden-users"; 99 static const QString & WB_SHOW_JOINS = "show-joins"; 100 static const QString & WB_LAST_STATUS = "last-status"; 101 static const QString & WB_USERS_STATISTICS = "users-statistics"; 102 static const QString & WB_NOTIFY_ENABLED = "notify-enabled"; 103 static const QString & WB_NOTIFY_SND_ENABLED = "notify-sound-enabled"; 104 static const QString & WB_NOTIFY_SND_EXTERNAL = "notify-sound-use-external"; 105 static const QString & WB_NOTIFY_SHOW_ON_ACTIVE = "notify-show-on-active"; 106 static const QString & WB_NOTIFY_SHOW_ON_VISIBLE = "notify-show-on-visible"; 107 static const QString & WB_NOTIFY_CH_ICON_ALWAYS = "notify-change-icon-always"; 108 static const QString & WB_FAVUSERS_AUTOGRANT = "favusers-auto-grant"; 109 static const QString & WB_APP_ENABLE_EMOTICON = "app-enable-emoticon"; 110 static const QString & WB_APP_FORCE_EMOTICONS = "app-force-find-emoticons"; 111 static const QString & WB_APP_ENABLE_ASPELL = "app-enable-aspell"; 112 static const QString & WB_APP_AUTO_AWAY = "app-auto-away"; 113 static const QString & WB_APP_TBAR_SHOW_CL_BTNS = "app-toolbar-show-close-buttons"; 114 static const QString & WB_APP_REMOVE_NOT_EX_DIRS = "app-auto-rem-not-exsisting-dirs"; 115 static const QString & WB_WIDGETS_PANEL_VISIBLE = "widgets-panel-visible"; 116 static const QString & WB_TOOLS_PANEL_VISIBLE = "tools-panel-visible"; 117 static const QString & WB_SEARCH_PANEL_VISIBLE = "search-panel-visible"; 118 static const QString & WB_MAIN_MENU_VISIBLE = "main-menu-visible"; 119 static const QString & WB_USE_CTRL_ENTER = "use-ctrl-enter"; 120 static const QString & WB_SIMPLE_SHARE_MODE = "use-simple-share-mode"; 121 static const QString & WI_APP_UNIT_BASE = "app-unit-base"; 122 static const QString & WI_APP_AUTOAWAY_INTERVAL = "app-autoaway-interval"; 123 static const QString & WI_APP_SHARED_FILES_ALPHA = "app-already-shared-files-alpha"; 124 // 125 static const QString & WI_DEF_MAGNET_ACTION = "def-magnet-action"; 126 // 0 - ask, 1 - search, 2 - download 127 // 128 static const QString & WI_CHAT_MAXPARAGRAPHS = "chat-max-paragraph"; 129 static const QString & WI_CHAT_WIDTH = "chat-width"; 130 static const QString & WI_CHAT_USERLIST_WIDTH = "chat-userlist-width"; 131 static const QString & WI_CHAT_SORT_COLUMN = "chat-userlist-sort-column"; 132 static const QString & WI_CHAT_SORT_ORDER = "chat-userlist-sort-order"; 133 // 134 static const QString & WI_CHAT_DBLCLICK_ACT = "chat-dbl-click-action"; 135 static const QString & WI_CHAT_MDLCLICK_ACT = "chat-mdl-click-action"; 136 // 0 - insert nick into input widget, 1 - get file list, 2 - private message 137 // 138 static const QString & WI_CHAT_FIND_COLOR_ALPHA = "chat-find-color-alpha"; 139 static const QString & WI_CHAT_STATUS_HISTORY_SZ = "chat-status-history-size"; 140 static const QString & WI_STATUSBAR_HISTORY_SZ = "statusbar-history-size"; 141 static const QString & WI_CHAT_STATUS_MSG_MAX_LEN = "chat-status-msg-max-len"; 142 static const QString & WI_SEARCH_SORT_COLUMN = "search-sort-column"; 143 static const QString & WI_SEARCH_SORT_ORDER = "search-sort-order"; 144 static const QString & WI_SEARCH_SHARED_ACTION = "search-shared-action"; 145 static const QString & WI_SEARCH_LAST_TYPE = "search-last-search-type"; 146 static const QString & WI_TRANSFER_HEIGHT = "transfer-height"; 147 static const QString & WI_MAINWINDOW_WIDTH = "mainwindow-width"; 148 static const QString & WI_MAINWINDOW_HEIGHT = "mainwindow-height"; 149 static const QString & WI_MAINWINDOW_X = "mainwindow-x"; 150 static const QString & WI_MAINWINDOW_Y = "mainwindow-y"; 151 static const QString & WI_SHARE_RPANE_WIDTH = "sharebrowser-rp-width"; 152 static const QString & WI_SHARE_WIDTH = "sharebrowser-width"; 153 static const QString & WI_NOTIFY_EVENTMAP = "notify-event-map"; 154 static const QString & WI_NOTIFY_SNDMAP = "notify-snd-map"; 155 static const QString & WI_NOTIFY_MODULE = "notify-module"; 156 static const QString & WI_OUT_IN_HIST = "number-of-output-messages-in-history"; 157 158 class WulforSettings : 159 public QObject, 160 public dcpp::Singleton<WulforSettings> 161 { 162 Q_OBJECT 163 164 typedef QMap<QString, int> WIntMap; 165 typedef QMap<QString, QString> WStrMap; 166 167 friend class dcpp::Singleton<WulforSettings>; 168 169 public: 170 void load(); 171 void save(); 172 173 void loadTranslation(); 174 void loadTheme(); 175 176 void parseCmd(const QString &, QString &); 177 178 bool hasKey(const QString&) const; 179 180 public Q_SLOTS: 181 QString getStr(const QString&, const QString &default_value = "") ; 182 int getInt(const QString&, const int &default_value = -1) ; 183 bool getBool(const QString&, const bool &default_value = false); 184 QVariant getVar(const QString&, const QVariant &default_value = QVariant()); 185 186 void setStr (const QString&, const QString&); 187 void setInt (const QString&, int) ; 188 void setBool(const QString&, bool); 189 void setVar (const QString&, const QVariant &); 190 191 Q_SIGNALS: 192 void fontChanged(const QString &key, const QString &value); 193 void intValueChanged(const QString &key, int value); 194 void strValueChanged(const QString &key, const QString &value); 195 void varValueChanged(const QString &key, const QVariant &value); 196 197 private Q_SLOTS: 198 void slotFontChanged(const QString &key, const QString &value); 199 200 private: 201 WulforSettings(); 202 virtual ~WulforSettings(); 203 204 void loadOldConfig();//load old version of config 205 206 QSettings settings; 207 208 QString configFileOld; 209 210 QFont f; 211 212 WIntMap intmap; 213 WStrMap strmap; 214 215 QTranslator tor; 216 QTranslator qtTranslator; 217 }; 218 219 static const auto WSGET = [](const QString &key, const QString &default_value = "") -> QString { return WulforSettings::getInstance()->getStr(key, default_value); }; 220 static const auto WSSET = [](const QString &key, const QString &value) { WulforSettings::getInstance()->setStr(key, value); }; 221 222 static const auto WIGET = [](const QString &key, const int &default_value = -1) -> int { return WulforSettings::getInstance()->getInt(key, default_value); }; 223 static const auto WISET = [](const QString &key, const int &value) { WulforSettings::getInstance()->setInt(key, value); }; 224 225 static const auto WBGET = [](const QString &key, const bool &default_value = false) -> bool { return WulforSettings::getInstance()->getBool(key, default_value); }; 226 static const auto WBSET = [](const QString &key, const bool &value){ WulforSettings::getInstance()->setBool(key, value); }; 227 228 static const auto WVGET = [](const QString &key, const QVariant &default_value = QVariant()) -> QVariant { return WulforSettings::getInstance()->getVar(key, default_value); }; 229 static const auto WVSET = [](const QString &key, const QVariant &value){ WulforSettings::getInstance()->setVar(key, value); }; 230 231 static const auto WSCMD = [](const QString &cmd, QString &res){ WulforSettings::getInstance()->parseCmd(cmd,res); }; 232