1 /* 2 * Bittorrent Client using Qt and libtorrent. 3 * Copyright (C) 2014 sledgehammer999 <hammered999@gmail.com> 4 * Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org> 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License 8 * as published by the Free Software Foundation; either version 2 9 * of the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 * 20 * In addition, as a special exception, the copyright holders give permission to 21 * link this program with the OpenSSL project's "OpenSSL" library (or with 22 * modified versions of it that use the same license as the "OpenSSL" library), 23 * and distribute the linked executables. You must obey the GNU General Public 24 * License in all respects for all of the code used other than "OpenSSL". If you 25 * modify file(s), you may extend this exception to your version of the file(s), 26 * but you are not obligated to do so. If you do not wish to do so, delete this 27 * exception statement from your version. 28 */ 29 30 #pragma once 31 32 #include <QtContainerFwd> 33 #include <QVariant> 34 35 #include "base/utils/net.h" 36 37 class QDateTime; 38 class QNetworkCookie; 39 class QSize; 40 class QTime; 41 42 enum SchedulerDays 43 { 44 EVERY_DAY, 45 WEEK_DAYS, 46 WEEK_ENDS, 47 MON, 48 TUE, 49 WED, 50 THU, 51 FRI, 52 SAT, 53 SUN 54 }; 55 56 namespace TrayIcon 57 { 58 enum Style 59 { 60 NORMAL = 0, 61 MONO_DARK, 62 MONO_LIGHT 63 }; 64 } 65 66 namespace DNS 67 { 68 enum Service 69 { 70 DYNDNS, 71 NOIP, 72 NONE = -1 73 }; 74 } 75 76 class Preferences : public QObject 77 { 78 Q_OBJECT 79 Q_DISABLE_COPY(Preferences) 80 81 Preferences(); 82 83 const QVariant value(const QString &key, const QVariant &defaultValue = {}) const; 84 void setValue(const QString &key, const QVariant &value); 85 86 static Preferences *m_instance; 87 88 signals: 89 void changed(); 90 91 public: 92 static void initInstance(); 93 static void freeInstance(); 94 static Preferences *instance(); 95 96 // General options 97 QString getLocale() const; 98 void setLocale(const QString &locale); 99 bool useCustomUITheme() const; 100 void setUseCustomUITheme(bool use); 101 QString customUIThemePath() const; 102 void setCustomUIThemePath(const QString &path); 103 bool deleteTorrentFilesAsDefault() const; 104 void setDeleteTorrentFilesAsDefault(bool del); 105 bool confirmOnExit() const; 106 void setConfirmOnExit(bool confirm); 107 bool speedInTitleBar() const; 108 void showSpeedInTitleBar(bool show); 109 bool useAlternatingRowColors() const; 110 void setAlternatingRowColors(bool b); 111 bool getHideZeroValues() const; 112 void setHideZeroValues(bool b); 113 int getHideZeroComboValues() const; 114 void setHideZeroComboValues(int n); 115 bool isStatusbarDisplayed() const; 116 void setStatusbarDisplayed(bool displayed); 117 bool isToolbarDisplayed() const; 118 void setToolbarDisplayed(bool displayed); 119 bool startMinimized() const; 120 void setStartMinimized(bool b); 121 bool isSplashScreenDisabled() const; 122 void setSplashScreenDisabled(bool b); 123 bool preventFromSuspendWhenDownloading() const; 124 void setPreventFromSuspendWhenDownloading(bool b); 125 bool preventFromSuspendWhenSeeding() const; 126 void setPreventFromSuspendWhenSeeding(bool b); 127 #ifdef Q_OS_WIN 128 bool WinStartup() const; 129 void setWinStartup(bool b); 130 #endif 131 132 // Downloads 133 QString lastLocationPath() const; 134 void setLastLocationPath(const QString &path); 135 QString getScanDirsLastPath() const; 136 void setScanDirsLastPath(const QString &path); 137 bool isMailNotificationEnabled() const; 138 void setMailNotificationEnabled(bool enabled); 139 QString getMailNotificationSender() const; 140 void setMailNotificationSender(const QString &mail); 141 QString getMailNotificationEmail() const; 142 void setMailNotificationEmail(const QString &mail); 143 QString getMailNotificationSMTP() const; 144 void setMailNotificationSMTP(const QString &smtp_server); 145 bool getMailNotificationSMTPSSL() const; 146 void setMailNotificationSMTPSSL(bool use); 147 bool getMailNotificationSMTPAuth() const; 148 void setMailNotificationSMTPAuth(bool use); 149 QString getMailNotificationSMTPUsername() const; 150 void setMailNotificationSMTPUsername(const QString &username); 151 QString getMailNotificationSMTPPassword() const; 152 void setMailNotificationSMTPPassword(const QString &password); 153 int getActionOnDblClOnTorrentDl() const; 154 void setActionOnDblClOnTorrentDl(int act); 155 int getActionOnDblClOnTorrentFn() const; 156 void setActionOnDblClOnTorrentFn(int act); 157 158 // Connection options 159 QTime getSchedulerStartTime() const; 160 void setSchedulerStartTime(const QTime &time); 161 QTime getSchedulerEndTime() const; 162 void setSchedulerEndTime(const QTime &time); 163 SchedulerDays getSchedulerDays() const; 164 void setSchedulerDays(SchedulerDays days); 165 166 // Search 167 bool isSearchEnabled() const; 168 void setSearchEnabled(bool enabled); 169 170 // HTTP Server 171 bool isWebUiEnabled() const; 172 void setWebUiEnabled(bool enabled); 173 QString getServerDomains() const; 174 void setServerDomains(const QString &str); 175 QString getWebUiAddress() const; 176 void setWebUiAddress(const QString &addr); 177 quint16 getWebUiPort() const; 178 void setWebUiPort(quint16 port); 179 bool useUPnPForWebUIPort() const; 180 void setUPnPForWebUIPort(bool enabled); 181 182 // Authentication 183 bool isWebUiLocalAuthEnabled() const; 184 void setWebUiLocalAuthEnabled(bool enabled); 185 bool isWebUiAuthSubnetWhitelistEnabled() const; 186 void setWebUiAuthSubnetWhitelistEnabled(bool enabled); 187 QVector<Utils::Net::Subnet> getWebUiAuthSubnetWhitelist() const; 188 void setWebUiAuthSubnetWhitelist(QStringList subnets); 189 QString getWebUiUsername() const; 190 void setWebUiUsername(const QString &username); 191 QByteArray getWebUIPassword() const; 192 void setWebUIPassword(const QByteArray &password); 193 int getWebUIMaxAuthFailCount() const; 194 void setWebUIMaxAuthFailCount(int count); 195 std::chrono::seconds getWebUIBanDuration() const; 196 void setWebUIBanDuration(std::chrono::seconds duration); 197 int getWebUISessionTimeout() const; 198 void setWebUISessionTimeout(int timeout); 199 200 // WebUI security 201 bool isWebUiClickjackingProtectionEnabled() const; 202 void setWebUiClickjackingProtectionEnabled(bool enabled); 203 bool isWebUiCSRFProtectionEnabled() const; 204 void setWebUiCSRFProtectionEnabled(bool enabled); 205 bool isWebUiSecureCookieEnabled () const; 206 void setWebUiSecureCookieEnabled(bool enabled); 207 bool isWebUIHostHeaderValidationEnabled() const; 208 void setWebUIHostHeaderValidationEnabled(bool enabled); 209 210 // HTTPS 211 bool isWebUiHttpsEnabled() const; 212 void setWebUiHttpsEnabled(bool enabled); 213 QString getWebUIHttpsCertificatePath() const; 214 void setWebUIHttpsCertificatePath(const QString &path); 215 QString getWebUIHttpsKeyPath() const; 216 void setWebUIHttpsKeyPath(const QString &path); 217 bool isAltWebUiEnabled() const; 218 void setAltWebUiEnabled(bool enabled); 219 QString getWebUiRootFolder() const; 220 void setWebUiRootFolder(const QString &path); 221 222 // WebUI custom HTTP headers 223 bool isWebUICustomHTTPHeadersEnabled() const; 224 void setWebUICustomHTTPHeadersEnabled(bool enabled); 225 QString getWebUICustomHTTPHeaders() const; 226 void setWebUICustomHTTPHeaders(const QString &headers); 227 228 // Dynamic DNS 229 bool isDynDNSEnabled() const; 230 void setDynDNSEnabled(bool enabled); 231 DNS::Service getDynDNSService() const; 232 void setDynDNSService(int service); 233 QString getDynDomainName() const; 234 void setDynDomainName(const QString &name); 235 QString getDynDNSUsername() const; 236 void setDynDNSUsername(const QString &username); 237 QString getDynDNSPassword() const; 238 void setDynDNSPassword(const QString &password); 239 240 // Advanced settings 241 QByteArray getUILockPassword() const; 242 void setUILockPassword(const QByteArray &password); 243 bool isUILocked() const; 244 void setUILocked(bool locked); 245 bool isAutoRunEnabled() const; 246 void setAutoRunEnabled(bool enabled); 247 QString getAutoRunProgram() const; 248 void setAutoRunProgram(const QString &program); 249 #if defined(Q_OS_WIN) 250 bool isAutoRunConsoleEnabled() const; 251 void setAutoRunConsoleEnabled(bool enabled); 252 #endif 253 bool shutdownWhenDownloadsComplete() const; 254 void setShutdownWhenDownloadsComplete(bool shutdown); 255 bool suspendWhenDownloadsComplete() const; 256 void setSuspendWhenDownloadsComplete(bool suspend); 257 bool hibernateWhenDownloadsComplete() const; 258 void setHibernateWhenDownloadsComplete(bool hibernate); 259 bool shutdownqBTWhenDownloadsComplete() const; 260 void setShutdownqBTWhenDownloadsComplete(bool shutdown); 261 bool dontConfirmAutoExit() const; 262 void setDontConfirmAutoExit(bool dontConfirmAutoExit); 263 bool recheckTorrentsOnCompletion() const; 264 void recheckTorrentsOnCompletion(bool recheck); 265 bool resolvePeerCountries() const; 266 void resolvePeerCountries(bool resolve); 267 bool resolvePeerHostNames() const; 268 void resolvePeerHostNames(bool resolve); 269 #if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) 270 bool useSystemIconTheme() const; 271 void useSystemIconTheme(bool enabled); 272 #endif 273 bool recursiveDownloadDisabled() const; 274 void disableRecursiveDownload(bool disable = true); 275 #ifdef Q_OS_WIN 276 bool neverCheckFileAssoc() const; 277 void setNeverCheckFileAssoc(bool check = true); 278 static bool isTorrentFileAssocSet(); 279 static bool isMagnetLinkAssocSet(); 280 static void setTorrentFileAssoc(bool set); 281 static void setMagnetLinkAssoc(bool set); 282 #endif 283 #ifdef Q_OS_MACOS 284 static bool isTorrentFileAssocSet(); 285 static bool isMagnetLinkAssocSet(); 286 static void setTorrentFileAssoc(); 287 static void setMagnetLinkAssoc(); 288 #endif 289 int getTrackerPort() const; 290 void setTrackerPort(int port); 291 #if defined(Q_OS_WIN) || defined(Q_OS_MACOS) 292 bool isUpdateCheckEnabled() const; 293 void setUpdateCheckEnabled(bool enabled); 294 #endif 295 bool confirmTorrentDeletion() const; 296 void setConfirmTorrentDeletion(bool enabled); 297 bool confirmTorrentRecheck() const; 298 void setConfirmTorrentRecheck(bool enabled); 299 bool confirmRemoveAllTags() const; 300 void setConfirmRemoveAllTags(bool enabled); 301 #ifndef Q_OS_MACOS 302 bool systrayIntegration() const; 303 void setSystrayIntegration(bool enabled); 304 bool minimizeToTrayNotified() const; 305 void setMinimizeToTrayNotified(bool b); 306 bool minimizeToTray() const; 307 void setMinimizeToTray(bool b); 308 bool closeToTray() const; 309 void setCloseToTray(bool b); 310 bool closeToTrayNotified() const; 311 void setCloseToTrayNotified(bool b); 312 TrayIcon::Style trayIconStyle() const; 313 void setTrayIconStyle(TrayIcon::Style style); 314 bool iconsInMenusEnabled() const; 315 void setIconsInMenusEnabled(bool enable); 316 #endif // Q_OS_MACOS 317 318 // Stuff that don't appear in the Options GUI but are saved 319 // in the same file. 320 QDateTime getDNSLastUpd() const; 321 void setDNSLastUpd(const QDateTime &date); 322 QString getDNSLastIP() const; 323 void setDNSLastIP(const QString &ip); 324 bool getAcceptedLegal() const; 325 void setAcceptedLegal(bool accepted); 326 QByteArray getMainGeometry() const; 327 void setMainGeometry(const QByteArray &geometry); 328 QByteArray getMainVSplitterState() const; 329 void setMainVSplitterState(const QByteArray &state); 330 QString getMainLastDir() const; 331 void setMainLastDir(const QString &path); 332 QByteArray getPeerListState() const; 333 void setPeerListState(const QByteArray &state); 334 QString getPropSplitterSizes() const; 335 void setPropSplitterSizes(const QString &sizes); 336 QByteArray getPropFileListState() const; 337 void setPropFileListState(const QByteArray &state); 338 int getPropCurTab() const; 339 void setPropCurTab(int tab); 340 bool getPropVisible() const; 341 void setPropVisible(bool visible); 342 QByteArray getPropTrackerListState() const; 343 void setPropTrackerListState(const QByteArray &state); 344 QSize getRssGeometrySize() const; 345 void setRssGeometrySize(const QSize &geometry); 346 QByteArray getRssHSplitterSizes() const; 347 void setRssHSplitterSizes(const QByteArray &sizes); 348 QStringList getRssOpenFolders() const; 349 void setRssOpenFolders(const QStringList &folders); 350 QByteArray getRssSideSplitterState() const; 351 void setRssSideSplitterState(const QByteArray &state); 352 QByteArray getRssMainSplitterState() const; 353 void setRssMainSplitterState(const QByteArray &state); 354 QByteArray getSearchTabHeaderState() const; 355 void setSearchTabHeaderState(const QByteArray &state); 356 bool getRegexAsFilteringPatternForSearchJob() const; 357 void setRegexAsFilteringPatternForSearchJob(bool checked); 358 QStringList getSearchEngDisabled() const; 359 void setSearchEngDisabled(const QStringList &engines); 360 QString getTorImportLastContentDir() const; 361 void setTorImportLastContentDir(const QString &path); 362 QByteArray getTorImportGeometry() const; 363 void setTorImportGeometry(const QByteArray &geometry); 364 bool getStatusFilterState() const; 365 bool getCategoryFilterState() const; 366 bool getTagFilterState() const; 367 bool getTrackerFilterState() const; 368 int getTransSelFilter() const; 369 void setTransSelFilter(int index); 370 QByteArray getTransHeaderState() const; 371 void setTransHeaderState(const QByteArray &state); 372 bool getRegexAsFilteringPatternForTransferList() const; 373 void setRegexAsFilteringPatternForTransferList(bool checked); 374 int getToolbarTextPosition() const; 375 void setToolbarTextPosition(int position); 376 377 // From old RssSettings class 378 bool isRSSWidgetEnabled() const; 379 void setRSSWidgetVisible(bool enabled); 380 381 // Network 382 QList<QNetworkCookie> getNetworkCookies() const; 383 void setNetworkCookies(const QList<QNetworkCookie> &cookies); 384 385 // SpeedWidget 386 bool isSpeedWidgetEnabled() const; 387 void setSpeedWidgetEnabled(bool enabled); 388 int getSpeedWidgetPeriod() const; 389 void setSpeedWidgetPeriod(int period); 390 bool getSpeedWidgetGraphEnable(int id) const; 391 void setSpeedWidgetGraphEnable(int id, bool enable); 392 393 public slots: 394 void setStatusFilterState(bool checked); 395 void setCategoryFilterState(bool checked); 396 void setTagFilterState(bool checked); 397 void setTrackerFilterState(bool checked); 398 399 void apply(); 400 }; 401