Avoid using QDateTime for announce timestamps
[qBittorrent.git] / src / base / preferences.cpp
blobed9ecd316dc1ec176bb2be11f3773126fbdedf46
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>
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.
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.
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.
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.
30 #include "preferences.h"
32 #include <algorithm>
33 #include <chrono>
35 #include <QCoreApplication>
36 #include <QDateTime>
37 #include <QDir>
38 #include <QList>
39 #include <QLocale>
40 #include <QNetworkCookie>
41 #include <QSettings>
42 #include <QTime>
44 #include "algorithm.h"
45 #include "global.h"
46 #include "path.h"
47 #include "profile.h"
48 #include "settingsstorage.h"
49 #include "utils/fs.h"
51 namespace
53 template <typename T>
54 T value(const QString &key, const T &defaultValue = {})
56 return SettingsStorage::instance()->loadValue(key, defaultValue);
59 template <typename T>
60 void setValue(const QString &key, const T &value)
62 SettingsStorage::instance()->storeValue(key, value);
65 #ifdef Q_OS_WIN
66 QString makeProfileID(const Path &profilePath, const QString &profileName)
68 return profilePath.isEmpty()
69 ? profileName
70 : profileName + u'@' + Utils::Fs::toValidFileName(profilePath.data(), {});
72 #endif
75 Preferences *Preferences::m_instance = nullptr;
77 Preferences::Preferences() = default;
79 Preferences *Preferences::instance()
81 return m_instance;
84 void Preferences::initInstance()
86 if (!m_instance)
87 m_instance = new Preferences;
90 void Preferences::freeInstance()
92 delete m_instance;
93 m_instance = nullptr;
96 // General options
97 QString Preferences::getLocale() const
99 const auto localeName = value<QString>(u"Preferences/General/Locale"_s);
100 return (localeName.isEmpty() ? QLocale::system().name() : localeName);
103 void Preferences::setLocale(const QString &locale)
105 if (locale == getLocale())
106 return;
108 setValue(u"Preferences/General/Locale"_s, locale);
111 bool Preferences::useCustomUITheme() const
113 return value(u"Preferences/General/UseCustomUITheme"_s, false) && !customUIThemePath().isEmpty();
116 void Preferences::setUseCustomUITheme(const bool use)
118 if (use == useCustomUITheme())
119 return;
121 setValue(u"Preferences/General/UseCustomUITheme"_s, use);
124 Path Preferences::customUIThemePath() const
126 return value<Path>(u"Preferences/General/CustomUIThemePath"_s);
129 void Preferences::setCustomUIThemePath(const Path &path)
131 if (path == customUIThemePath())
132 return;
134 setValue(u"Preferences/General/CustomUIThemePath"_s, path);
137 bool Preferences::removeTorrentContent() const
139 return value(u"Preferences/General/DeleteTorrentsFilesAsDefault"_s, false);
142 void Preferences::setRemoveTorrentContent(const bool remove)
144 if (remove == removeTorrentContent())
145 return;
147 setValue(u"Preferences/General/DeleteTorrentsFilesAsDefault"_s, remove);
150 bool Preferences::confirmOnExit() const
152 return value(u"Preferences/General/ExitConfirm"_s, true);
155 void Preferences::setConfirmOnExit(const bool confirm)
157 if (confirm == confirmOnExit())
158 return;
160 setValue(u"Preferences/General/ExitConfirm"_s, confirm);
163 bool Preferences::speedInTitleBar() const
165 return value(u"Preferences/General/SpeedInTitleBar"_s, false);
168 void Preferences::showSpeedInTitleBar(const bool show)
170 if (show == speedInTitleBar())
171 return;
173 setValue(u"Preferences/General/SpeedInTitleBar"_s, show);
176 bool Preferences::useAlternatingRowColors() const
178 return value(u"Preferences/General/AlternatingRowColors"_s, true);
181 void Preferences::setAlternatingRowColors(const bool b)
183 if (b == useAlternatingRowColors())
184 return;
186 setValue(u"Preferences/General/AlternatingRowColors"_s, b);
189 bool Preferences::getHideZeroValues() const
191 return value(u"Preferences/General/HideZeroValues"_s, false);
194 void Preferences::setHideZeroValues(const bool b)
196 if (b == getHideZeroValues())
197 return;
199 setValue(u"Preferences/General/HideZeroValues"_s, b);
202 int Preferences::getHideZeroComboValues() const
204 return value<int>(u"Preferences/General/HideZeroComboValues"_s, 0);
207 void Preferences::setHideZeroComboValues(const int n)
209 if (n == getHideZeroComboValues())
210 return;
212 setValue(u"Preferences/General/HideZeroComboValues"_s, n);
215 // In Mac OS X the dock is sufficient for our needs so we disable the sys tray functionality.
216 // See extensive discussion in https://github.com/qbittorrent/qBittorrent/pull/3018
217 #ifndef Q_OS_MACOS
218 bool Preferences::systemTrayEnabled() const
220 return value(u"Preferences/General/SystrayEnabled"_s, true);
223 void Preferences::setSystemTrayEnabled(const bool enabled)
225 if (enabled == systemTrayEnabled())
226 return;
228 setValue(u"Preferences/General/SystrayEnabled"_s, enabled);
231 bool Preferences::minimizeToTray() const
233 return value(u"Preferences/General/MinimizeToTray"_s, false);
236 void Preferences::setMinimizeToTray(const bool b)
238 if (b == minimizeToTray())
239 return;
241 setValue(u"Preferences/General/MinimizeToTray"_s, b);
244 bool Preferences::minimizeToTrayNotified() const
246 return value(u"Preferences/General/MinimizeToTrayNotified"_s, false);
249 void Preferences::setMinimizeToTrayNotified(const bool b)
251 if (b == minimizeToTrayNotified())
252 return;
254 setValue(u"Preferences/General/MinimizeToTrayNotified"_s, b);
257 bool Preferences::closeToTray() const
259 return value(u"Preferences/General/CloseToTray"_s, true);
262 void Preferences::setCloseToTray(const bool b)
264 if (b == closeToTray())
265 return;
267 setValue(u"Preferences/General/CloseToTray"_s, b);
270 bool Preferences::closeToTrayNotified() const
272 return value(u"Preferences/General/CloseToTrayNotified"_s, false);
275 void Preferences::setCloseToTrayNotified(const bool b)
277 if (b == closeToTrayNotified())
278 return;
280 setValue(u"Preferences/General/CloseToTrayNotified"_s, b);
283 bool Preferences::iconsInMenusEnabled() const
285 return value(u"Preferences/Advanced/EnableIconsInMenus"_s, true);
288 void Preferences::setIconsInMenusEnabled(const bool enable)
290 if (enable == iconsInMenusEnabled())
291 return;
293 setValue(u"Preferences/Advanced/EnableIconsInMenus"_s, enable);
295 #endif // Q_OS_MACOS
297 qint64 Preferences::getTorrentFileSizeLimit() const
299 return value(u"BitTorrent/TorrentFileSizeLimit"_s, (100 * 1024 * 1024));
302 void Preferences::setTorrentFileSizeLimit(const qint64 value)
304 if (value == getTorrentFileSizeLimit())
305 return;
307 setValue(u"BitTorrent/TorrentFileSizeLimit"_s, value);
310 int Preferences::getBdecodeDepthLimit() const
312 return value(u"BitTorrent/BdecodeDepthLimit"_s, 100);
315 void Preferences::setBdecodeDepthLimit(const int value)
317 if (value == getBdecodeDepthLimit())
318 return;
320 setValue(u"BitTorrent/BdecodeDepthLimit"_s, value);
323 int Preferences::getBdecodeTokenLimit() const
325 return value(u"BitTorrent/BdecodeTokenLimit"_s, 10'000'000);
328 void Preferences::setBdecodeTokenLimit(const int value)
330 if (value == getBdecodeTokenLimit())
331 return;
333 setValue(u"BitTorrent/BdecodeTokenLimit"_s, value);
336 bool Preferences::isToolbarDisplayed() const
338 return value(u"Preferences/General/ToolbarDisplayed"_s, true);
341 void Preferences::setToolbarDisplayed(const bool displayed)
343 if (displayed == isToolbarDisplayed())
344 return;
346 setValue(u"Preferences/General/ToolbarDisplayed"_s, displayed);
349 bool Preferences::isStatusbarDisplayed() const
351 return value(u"Preferences/General/StatusbarDisplayed"_s, true);
354 void Preferences::setStatusbarDisplayed(const bool displayed)
356 if (displayed == isStatusbarDisplayed())
357 return;
359 setValue(u"Preferences/General/StatusbarDisplayed"_s, displayed);
362 bool Preferences::isStatusbarExternalIPDisplayed() const
364 return value(u"Preferences/General/StatusbarExternalIPDisplayed"_s, false);
367 void Preferences::setStatusbarExternalIPDisplayed(const bool displayed)
369 if (displayed == isStatusbarExternalIPDisplayed())
370 return;
372 setValue(u"Preferences/General/StatusbarExternalIPDisplayed"_s, displayed);
375 bool Preferences::isSplashScreenDisabled() const
377 return value(u"Preferences/General/NoSplashScreen"_s, true);
380 void Preferences::setSplashScreenDisabled(const bool b)
382 if (b == isSplashScreenDisabled())
383 return;
385 setValue(u"Preferences/General/NoSplashScreen"_s, b);
388 // Preventing from system suspend while active torrents are presented.
389 bool Preferences::preventFromSuspendWhenDownloading() const
391 return value(u"Preferences/General/PreventFromSuspendWhenDownloading"_s, false);
394 void Preferences::setPreventFromSuspendWhenDownloading(const bool b)
396 if (b == preventFromSuspendWhenDownloading())
397 return;
399 setValue(u"Preferences/General/PreventFromSuspendWhenDownloading"_s, b);
402 bool Preferences::preventFromSuspendWhenSeeding() const
404 return value(u"Preferences/General/PreventFromSuspendWhenSeeding"_s, false);
407 void Preferences::setPreventFromSuspendWhenSeeding(const bool b)
409 if (b == preventFromSuspendWhenSeeding())
410 return;
412 setValue(u"Preferences/General/PreventFromSuspendWhenSeeding"_s, b);
415 #ifdef Q_OS_WIN
416 bool Preferences::WinStartup() const
418 const QString profileName = Profile::instance()->profileName();
419 const Path profilePath = Profile::instance()->rootPath();
420 const QString profileID = makeProfileID(profilePath, profileName);
421 const QSettings settings {u"HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run"_s, QSettings::NativeFormat};
423 return settings.contains(profileID);
426 void Preferences::setWinStartup(const bool b)
428 const QString profileName = Profile::instance()->profileName();
429 const Path profilePath = Profile::instance()->rootPath();
430 const QString profileID = makeProfileID(profilePath, profileName);
431 QSettings settings {u"HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run"_s, QSettings::NativeFormat};
432 if (b)
434 const QString configuration = Profile::instance()->configurationName();
436 const auto cmd = uR"("%1" "--profile=%2" "--configuration=%3")"_s
437 .arg(Path(qApp->applicationFilePath()).toString(), profilePath.toString(), configuration);
438 settings.setValue(profileID, cmd);
440 else
442 settings.remove(profileID);
446 QString Preferences::getStyle() const
448 return value<QString>(u"Appearance/Style"_s);
451 void Preferences::setStyle(const QString &styleName)
453 if (styleName == getStyle())
454 return;
456 setValue(u"Appearance/Style"_s, styleName);
458 #endif // Q_OS_WIN
460 // Downloads
461 Path Preferences::getScanDirsLastPath() const
463 return value<Path>(u"Preferences/Downloads/ScanDirsLastPath"_s);
466 void Preferences::setScanDirsLastPath(const Path &path)
468 if (path == getScanDirsLastPath())
469 return;
471 setValue(u"Preferences/Downloads/ScanDirsLastPath"_s, path);
474 bool Preferences::isMailNotificationEnabled() const
476 return value(u"Preferences/MailNotification/enabled"_s, false);
479 void Preferences::setMailNotificationEnabled(const bool enabled)
481 if (enabled == isMailNotificationEnabled())
482 return;
484 setValue(u"Preferences/MailNotification/enabled"_s, enabled);
487 QString Preferences::getMailNotificationSender() const
489 return value<QString>(u"Preferences/MailNotification/sender"_s
490 , u"qBittorrent_notification@example.com"_s);
493 void Preferences::setMailNotificationSender(const QString &mail)
495 if (mail == getMailNotificationSender())
496 return;
498 setValue(u"Preferences/MailNotification/sender"_s, mail);
501 QString Preferences::getMailNotificationEmail() const
503 return value<QString>(u"Preferences/MailNotification/email"_s);
506 void Preferences::setMailNotificationEmail(const QString &mail)
508 if (mail == getMailNotificationEmail())
509 return;
511 setValue(u"Preferences/MailNotification/email"_s, mail);
514 QString Preferences::getMailNotificationSMTP() const
516 return value<QString>(u"Preferences/MailNotification/smtp_server"_s, u"smtp.changeme.com"_s);
519 void Preferences::setMailNotificationSMTP(const QString &smtpServer)
521 if (smtpServer == getMailNotificationSMTP())
522 return;
524 setValue(u"Preferences/MailNotification/smtp_server"_s, smtpServer);
527 bool Preferences::getMailNotificationSMTPSSL() const
529 return value(u"Preferences/MailNotification/req_ssl"_s, false);
532 void Preferences::setMailNotificationSMTPSSL(const bool use)
534 if (use == getMailNotificationSMTPSSL())
535 return;
537 setValue(u"Preferences/MailNotification/req_ssl"_s, use);
540 bool Preferences::getMailNotificationSMTPAuth() const
542 return value(u"Preferences/MailNotification/req_auth"_s, false);
545 void Preferences::setMailNotificationSMTPAuth(const bool use)
547 if (use == getMailNotificationSMTPAuth())
548 return;
550 setValue(u"Preferences/MailNotification/req_auth"_s, use);
553 QString Preferences::getMailNotificationSMTPUsername() const
555 return value<QString>(u"Preferences/MailNotification/username"_s);
558 void Preferences::setMailNotificationSMTPUsername(const QString &username)
560 if (username == getMailNotificationSMTPUsername())
561 return;
563 setValue(u"Preferences/MailNotification/username"_s, username);
566 QString Preferences::getMailNotificationSMTPPassword() const
568 return value<QString>(u"Preferences/MailNotification/password"_s);
571 void Preferences::setMailNotificationSMTPPassword(const QString &password)
573 if (password == getMailNotificationSMTPPassword())
574 return;
576 setValue(u"Preferences/MailNotification/password"_s, password);
579 int Preferences::getActionOnDblClOnTorrentDl() const
581 return value<int>(u"Preferences/Downloads/DblClOnTorDl"_s, 0);
584 void Preferences::setActionOnDblClOnTorrentDl(const int act)
586 if (act == getActionOnDblClOnTorrentDl())
587 return;
589 setValue(u"Preferences/Downloads/DblClOnTorDl"_s, act);
592 int Preferences::getActionOnDblClOnTorrentFn() const
594 return value<int>(u"Preferences/Downloads/DblClOnTorFn"_s, 1);
597 void Preferences::setActionOnDblClOnTorrentFn(const int act)
599 if (act == getActionOnDblClOnTorrentFn())
600 return;
602 setValue(u"Preferences/Downloads/DblClOnTorFn"_s, act);
605 QTime Preferences::getSchedulerStartTime() const
607 return value(u"Preferences/Scheduler/start_time"_s, QTime(8, 0));
610 void Preferences::setSchedulerStartTime(const QTime &time)
612 if (time == getSchedulerStartTime())
613 return;
615 setValue(u"Preferences/Scheduler/start_time"_s, time);
618 QTime Preferences::getSchedulerEndTime() const
620 return value(u"Preferences/Scheduler/end_time"_s, QTime(20, 0));
623 void Preferences::setSchedulerEndTime(const QTime &time)
625 if (time == getSchedulerEndTime())
626 return;
628 setValue(u"Preferences/Scheduler/end_time"_s, time);
631 Scheduler::Days Preferences::getSchedulerDays() const
633 return value(u"Preferences/Scheduler/days"_s, Scheduler::Days::EveryDay);
636 void Preferences::setSchedulerDays(const Scheduler::Days days)
638 if (days == getSchedulerDays())
639 return;
641 setValue(u"Preferences/Scheduler/days"_s, days);
644 // Search
645 bool Preferences::isSearchEnabled() const
647 return value(u"Preferences/Search/SearchEnabled"_s, false);
650 void Preferences::setSearchEnabled(const bool enabled)
652 if (enabled == isSearchEnabled())
653 return;
655 setValue(u"Preferences/Search/SearchEnabled"_s, enabled);
658 bool Preferences::isWebUIEnabled() const
660 #ifdef DISABLE_GUI
661 const bool defaultValue = true;
662 #else
663 const bool defaultValue = false;
664 #endif
665 return value(u"Preferences/WebUI/Enabled"_s, defaultValue);
668 void Preferences::setWebUIEnabled(const bool enabled)
670 if (enabled == isWebUIEnabled())
671 return;
673 setValue(u"Preferences/WebUI/Enabled"_s, enabled);
676 bool Preferences::isWebUILocalAuthEnabled() const
678 return value(u"Preferences/WebUI/LocalHostAuth"_s, true);
681 void Preferences::setWebUILocalAuthEnabled(const bool enabled)
683 if (enabled == isWebUILocalAuthEnabled())
684 return;
686 setValue(u"Preferences/WebUI/LocalHostAuth"_s, enabled);
689 bool Preferences::isWebUIAuthSubnetWhitelistEnabled() const
691 return value(u"Preferences/WebUI/AuthSubnetWhitelistEnabled"_s, false);
694 void Preferences::setWebUIAuthSubnetWhitelistEnabled(const bool enabled)
696 if (enabled == isWebUIAuthSubnetWhitelistEnabled())
697 return;
699 setValue(u"Preferences/WebUI/AuthSubnetWhitelistEnabled"_s, enabled);
702 QList<Utils::Net::Subnet> Preferences::getWebUIAuthSubnetWhitelist() const
704 const auto subnets = value<QStringList>(u"Preferences/WebUI/AuthSubnetWhitelist"_s);
706 QList<Utils::Net::Subnet> ret;
707 ret.reserve(subnets.size());
709 for (const QString &rawSubnet : subnets)
711 const std::optional<Utils::Net::Subnet> subnet = Utils::Net::parseSubnet(rawSubnet.trimmed());
712 if (subnet)
713 ret.append(subnet.value());
716 return ret;
719 void Preferences::setWebUIAuthSubnetWhitelist(QStringList subnets)
721 subnets.removeIf([](const QString &subnet)
723 return !Utils::Net::parseSubnet(subnet.trimmed()).has_value();
726 setValue(u"Preferences/WebUI/AuthSubnetWhitelist"_s, subnets);
729 QString Preferences::getServerDomains() const
731 return value<QString>(u"Preferences/WebUI/ServerDomains"_s, u"*"_s);
734 void Preferences::setServerDomains(const QString &str)
736 if (str == getServerDomains())
737 return;
739 setValue(u"Preferences/WebUI/ServerDomains"_s, str);
742 QString Preferences::getWebUIAddress() const
744 return value<QString>(u"Preferences/WebUI/Address"_s, u"*"_s).trimmed();
747 void Preferences::setWebUIAddress(const QString &addr)
749 if (addr == getWebUIAddress())
750 return;
752 setValue(u"Preferences/WebUI/Address"_s, addr.trimmed());
755 quint16 Preferences::getWebUIPort() const
757 return value<quint16>(u"Preferences/WebUI/Port"_s, 8080);
760 void Preferences::setWebUIPort(const quint16 port)
762 if (port == getWebUIPort())
763 return;
765 // cast to `int` type so it will show human readable unit in configuration file
766 setValue(u"Preferences/WebUI/Port"_s, static_cast<int>(port));
769 bool Preferences::useUPnPForWebUIPort() const
771 return value(u"Preferences/WebUI/UseUPnP"_s, false);
774 void Preferences::setUPnPForWebUIPort(const bool enabled)
776 if (enabled == useUPnPForWebUIPort())
777 return;
779 setValue(u"Preferences/WebUI/UseUPnP"_s, enabled);
782 QString Preferences::getWebUIUsername() const
784 return value<QString>(u"Preferences/WebUI/Username"_s, u"admin"_s);
787 void Preferences::setWebUIUsername(const QString &username)
789 if (username == getWebUIUsername())
790 return;
792 setValue(u"Preferences/WebUI/Username"_s, username);
795 QByteArray Preferences::getWebUIPassword() const
797 return value<QByteArray>(u"Preferences/WebUI/Password_PBKDF2"_s);
800 void Preferences::setWebUIPassword(const QByteArray &password)
802 if (password == getWebUIPassword())
803 return;
805 setValue(u"Preferences/WebUI/Password_PBKDF2"_s, password);
808 int Preferences::getWebUIMaxAuthFailCount() const
810 return value<int>(u"Preferences/WebUI/MaxAuthenticationFailCount"_s, 5);
813 void Preferences::setWebUIMaxAuthFailCount(const int count)
815 if (count == getWebUIMaxAuthFailCount())
816 return;
818 setValue(u"Preferences/WebUI/MaxAuthenticationFailCount"_s, count);
821 std::chrono::seconds Preferences::getWebUIBanDuration() const
823 return std::chrono::seconds(value<int>(u"Preferences/WebUI/BanDuration"_s, 3600));
826 void Preferences::setWebUIBanDuration(const std::chrono::seconds duration)
828 if (duration == getWebUIBanDuration())
829 return;
831 setValue(u"Preferences/WebUI/BanDuration"_s, static_cast<int>(duration.count()));
834 int Preferences::getWebUISessionTimeout() const
836 return value<int>(u"Preferences/WebUI/SessionTimeout"_s, 3600);
839 void Preferences::setWebUISessionTimeout(const int timeout)
841 if (timeout == getWebUISessionTimeout())
842 return;
844 setValue(u"Preferences/WebUI/SessionTimeout"_s, timeout);
847 QString Preferences::getWebAPISessionCookieName() const
849 return value<QString>(u"WebAPI/SessionCookieName"_s);
852 void Preferences::setWebAPISessionCookieName(const QString &cookieName)
854 if (cookieName == getWebAPISessionCookieName())
855 return;
857 setValue(u"WebAPI/SessionCookieName"_s, cookieName);
860 bool Preferences::isWebUIClickjackingProtectionEnabled() const
862 return value(u"Preferences/WebUI/ClickjackingProtection"_s, true);
865 void Preferences::setWebUIClickjackingProtectionEnabled(const bool enabled)
867 if (enabled == isWebUIClickjackingProtectionEnabled())
868 return;
870 setValue(u"Preferences/WebUI/ClickjackingProtection"_s, enabled);
873 bool Preferences::isWebUICSRFProtectionEnabled() const
875 return value(u"Preferences/WebUI/CSRFProtection"_s, true);
878 void Preferences::setWebUICSRFProtectionEnabled(const bool enabled)
880 if (enabled == isWebUICSRFProtectionEnabled())
881 return;
883 setValue(u"Preferences/WebUI/CSRFProtection"_s, enabled);
886 bool Preferences::isWebUISecureCookieEnabled() const
888 return value(u"Preferences/WebUI/SecureCookie"_s, true);
891 void Preferences::setWebUISecureCookieEnabled(const bool enabled)
893 if (enabled == isWebUISecureCookieEnabled())
894 return;
896 setValue(u"Preferences/WebUI/SecureCookie"_s, enabled);
899 bool Preferences::isWebUIHostHeaderValidationEnabled() const
901 return value(u"Preferences/WebUI/HostHeaderValidation"_s, true);
904 void Preferences::setWebUIHostHeaderValidationEnabled(const bool enabled)
906 if (enabled == isWebUIHostHeaderValidationEnabled())
907 return;
909 setValue(u"Preferences/WebUI/HostHeaderValidation"_s, enabled);
912 bool Preferences::isWebUIHttpsEnabled() const
914 return value(u"Preferences/WebUI/HTTPS/Enabled"_s, false);
917 void Preferences::setWebUIHttpsEnabled(const bool enabled)
919 if (enabled == isWebUIHttpsEnabled())
920 return;
922 setValue(u"Preferences/WebUI/HTTPS/Enabled"_s, enabled);
925 Path Preferences::getWebUIHttpsCertificatePath() const
927 return value<Path>(u"Preferences/WebUI/HTTPS/CertificatePath"_s);
930 void Preferences::setWebUIHttpsCertificatePath(const Path &path)
932 if (path == getWebUIHttpsCertificatePath())
933 return;
935 setValue(u"Preferences/WebUI/HTTPS/CertificatePath"_s, path);
938 Path Preferences::getWebUIHttpsKeyPath() const
940 return value<Path>(u"Preferences/WebUI/HTTPS/KeyPath"_s);
943 void Preferences::setWebUIHttpsKeyPath(const Path &path)
945 if (path == getWebUIHttpsKeyPath())
946 return;
948 setValue(u"Preferences/WebUI/HTTPS/KeyPath"_s, path);
951 bool Preferences::isAltWebUIEnabled() const
953 return value(u"Preferences/WebUI/AlternativeUIEnabled"_s, false);
956 void Preferences::setAltWebUIEnabled(const bool enabled)
958 if (enabled == isAltWebUIEnabled())
959 return;
961 setValue(u"Preferences/WebUI/AlternativeUIEnabled"_s, enabled);
964 Path Preferences::getWebUIRootFolder() const
966 return value<Path>(u"Preferences/WebUI/RootFolder"_s);
969 void Preferences::setWebUIRootFolder(const Path &path)
971 if (path == getWebUIRootFolder())
972 return;
974 setValue(u"Preferences/WebUI/RootFolder"_s, path);
977 bool Preferences::isWebUICustomHTTPHeadersEnabled() const
979 return value(u"Preferences/WebUI/CustomHTTPHeadersEnabled"_s, false);
982 void Preferences::setWebUICustomHTTPHeadersEnabled(const bool enabled)
984 if (enabled == isWebUICustomHTTPHeadersEnabled())
985 return;
987 setValue(u"Preferences/WebUI/CustomHTTPHeadersEnabled"_s, enabled);
990 QString Preferences::getWebUICustomHTTPHeaders() const
992 return value<QString>(u"Preferences/WebUI/CustomHTTPHeaders"_s);
995 void Preferences::setWebUICustomHTTPHeaders(const QString &headers)
997 if (headers == getWebUICustomHTTPHeaders())
998 return;
1000 setValue(u"Preferences/WebUI/CustomHTTPHeaders"_s, headers);
1003 bool Preferences::isWebUIReverseProxySupportEnabled() const
1005 return value(u"Preferences/WebUI/ReverseProxySupportEnabled"_s, false);
1008 void Preferences::setWebUIReverseProxySupportEnabled(const bool enabled)
1010 if (enabled == isWebUIReverseProxySupportEnabled())
1011 return;
1013 setValue(u"Preferences/WebUI/ReverseProxySupportEnabled"_s, enabled);
1016 QString Preferences::getWebUITrustedReverseProxiesList() const
1018 return value<QString>(u"Preferences/WebUI/TrustedReverseProxiesList"_s);
1021 void Preferences::setWebUITrustedReverseProxiesList(const QString &addr)
1023 if (addr == getWebUITrustedReverseProxiesList())
1024 return;
1026 setValue(u"Preferences/WebUI/TrustedReverseProxiesList"_s, addr);
1029 bool Preferences::isDynDNSEnabled() const
1031 return value(u"Preferences/DynDNS/Enabled"_s, false);
1034 void Preferences::setDynDNSEnabled(const bool enabled)
1036 if (enabled == isDynDNSEnabled())
1037 return;
1039 setValue(u"Preferences/DynDNS/Enabled"_s, enabled);
1042 DNS::Service Preferences::getDynDNSService() const
1044 return value(u"Preferences/DynDNS/Service"_s, DNS::Service::DynDNS);
1047 void Preferences::setDynDNSService(const DNS::Service service)
1049 if (service == getDynDNSService())
1050 return;
1052 setValue(u"Preferences/DynDNS/Service"_s, service);
1055 QString Preferences::getDynDomainName() const
1057 return value<QString>(u"Preferences/DynDNS/DomainName"_s, u"changeme.dyndns.org"_s);
1060 void Preferences::setDynDomainName(const QString &name)
1062 if (name == getDynDomainName())
1063 return;
1065 setValue(u"Preferences/DynDNS/DomainName"_s, name);
1068 QString Preferences::getDynDNSUsername() const
1070 return value<QString>(u"Preferences/DynDNS/Username"_s);
1073 void Preferences::setDynDNSUsername(const QString &username)
1075 if (username == getDynDNSUsername())
1076 return;
1078 setValue(u"Preferences/DynDNS/Username"_s, username);
1081 QString Preferences::getDynDNSPassword() const
1083 return value<QString>(u"Preferences/DynDNS/Password"_s);
1086 void Preferences::setDynDNSPassword(const QString &password)
1088 if (password == getDynDNSPassword())
1089 return;
1091 setValue(u"Preferences/DynDNS/Password"_s, password);
1094 // Advanced settings
1095 QByteArray Preferences::getUILockPassword() const
1097 return value<QByteArray>(u"Locking/password_PBKDF2"_s);
1100 void Preferences::setUILockPassword(const QByteArray &password)
1102 if (password == getUILockPassword())
1103 return;
1105 setValue(u"Locking/password_PBKDF2"_s, password);
1108 bool Preferences::isUILocked() const
1110 return value(u"Locking/locked"_s, false);
1113 void Preferences::setUILocked(const bool locked)
1115 if (locked == isUILocked())
1116 return;
1118 setValue(u"Locking/locked"_s, locked);
1121 bool Preferences::isAutoRunOnTorrentAddedEnabled() const
1123 return value(u"AutoRun/OnTorrentAdded/Enabled"_s, false);
1126 void Preferences::setAutoRunOnTorrentAddedEnabled(const bool enabled)
1128 if (enabled == isAutoRunOnTorrentAddedEnabled())
1129 return;
1131 setValue(u"AutoRun/OnTorrentAdded/Enabled"_s, enabled);
1134 QString Preferences::getAutoRunOnTorrentAddedProgram() const
1136 return value<QString>(u"AutoRun/OnTorrentAdded/Program"_s);
1139 void Preferences::setAutoRunOnTorrentAddedProgram(const QString &program)
1141 if (program == getAutoRunOnTorrentAddedProgram())
1142 return;
1144 setValue(u"AutoRun/OnTorrentAdded/Program"_s, program);
1147 bool Preferences::isAutoRunOnTorrentFinishedEnabled() const
1149 return value(u"AutoRun/enabled"_s, false);
1152 void Preferences::setAutoRunOnTorrentFinishedEnabled(const bool enabled)
1154 if (enabled == isAutoRunOnTorrentFinishedEnabled())
1155 return;
1157 setValue(u"AutoRun/enabled"_s, enabled);
1160 QString Preferences::getAutoRunOnTorrentFinishedProgram() const
1162 return value<QString>(u"AutoRun/program"_s);
1165 void Preferences::setAutoRunOnTorrentFinishedProgram(const QString &program)
1167 if (program == getAutoRunOnTorrentFinishedProgram())
1168 return;
1170 setValue(u"AutoRun/program"_s, program);
1173 #if defined(Q_OS_WIN)
1174 bool Preferences::isAutoRunConsoleEnabled() const
1176 return value(u"AutoRun/ConsoleEnabled"_s, false);
1179 void Preferences::setAutoRunConsoleEnabled(const bool enabled)
1181 if (enabled == isAutoRunConsoleEnabled())
1182 return;
1184 setValue(u"AutoRun/ConsoleEnabled"_s, enabled);
1186 #endif
1188 bool Preferences::shutdownWhenDownloadsComplete() const
1190 return value(u"Preferences/Downloads/AutoShutDownOnCompletion"_s, false);
1193 void Preferences::setShutdownWhenDownloadsComplete(const bool shutdown)
1195 if (shutdown == shutdownWhenDownloadsComplete())
1196 return;
1198 setValue(u"Preferences/Downloads/AutoShutDownOnCompletion"_s, shutdown);
1201 bool Preferences::suspendWhenDownloadsComplete() const
1203 return value(u"Preferences/Downloads/AutoSuspendOnCompletion"_s, false);
1206 void Preferences::setSuspendWhenDownloadsComplete(const bool suspend)
1208 if (suspend == suspendWhenDownloadsComplete())
1209 return;
1211 setValue(u"Preferences/Downloads/AutoSuspendOnCompletion"_s, suspend);
1214 bool Preferences::hibernateWhenDownloadsComplete() const
1216 return value(u"Preferences/Downloads/AutoHibernateOnCompletion"_s, false);
1219 void Preferences::setHibernateWhenDownloadsComplete(const bool hibernate)
1221 if (hibernate == hibernateWhenDownloadsComplete())
1222 return;
1224 setValue(u"Preferences/Downloads/AutoHibernateOnCompletion"_s, hibernate);
1227 bool Preferences::shutdownqBTWhenDownloadsComplete() const
1229 return value(u"Preferences/Downloads/AutoShutDownqBTOnCompletion"_s, false);
1232 void Preferences::setShutdownqBTWhenDownloadsComplete(const bool shutdown)
1234 if (shutdown == shutdownqBTWhenDownloadsComplete())
1235 return;
1237 setValue(u"Preferences/Downloads/AutoShutDownqBTOnCompletion"_s, shutdown);
1240 bool Preferences::dontConfirmAutoExit() const
1242 return value(u"ShutdownConfirmDlg/DontConfirmAutoExit"_s, false);
1245 void Preferences::setDontConfirmAutoExit(const bool dontConfirmAutoExit)
1247 if (dontConfirmAutoExit == this->dontConfirmAutoExit())
1248 return;
1250 setValue(u"ShutdownConfirmDlg/DontConfirmAutoExit"_s, dontConfirmAutoExit);
1253 bool Preferences::recheckTorrentsOnCompletion() const
1255 return value(u"Preferences/Advanced/RecheckOnCompletion"_s, false);
1258 void Preferences::recheckTorrentsOnCompletion(const bool recheck)
1260 if (recheck == recheckTorrentsOnCompletion())
1261 return;
1263 setValue(u"Preferences/Advanced/RecheckOnCompletion"_s, recheck);
1266 bool Preferences::resolvePeerCountries() const
1268 return value(u"Preferences/Connection/ResolvePeerCountries"_s, true);
1271 void Preferences::resolvePeerCountries(const bool resolve)
1273 if (resolve == resolvePeerCountries())
1274 return;
1276 setValue(u"Preferences/Connection/ResolvePeerCountries"_s, resolve);
1279 bool Preferences::resolvePeerHostNames() const
1281 return value(u"Preferences/Connection/ResolvePeerHostNames"_s, false);
1284 void Preferences::resolvePeerHostNames(const bool resolve)
1286 if (resolve == resolvePeerHostNames())
1287 return;
1289 setValue(u"Preferences/Connection/ResolvePeerHostNames"_s, resolve);
1292 #if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS))
1293 bool Preferences::useSystemIcons() const
1295 return value(u"Preferences/Advanced/useSystemIconTheme"_s, false);
1298 void Preferences::useSystemIcons(const bool enabled)
1300 if (enabled == useSystemIcons())
1301 return;
1303 setValue(u"Preferences/Advanced/useSystemIconTheme"_s, enabled);
1305 #endif
1307 bool Preferences::isRecursiveDownloadEnabled() const
1309 return !value(u"Preferences/Advanced/DisableRecursiveDownload"_s, false);
1312 void Preferences::setRecursiveDownloadEnabled(const bool enable)
1314 if (enable == isRecursiveDownloadEnabled())
1315 return;
1317 setValue(u"Preferences/Advanced/DisableRecursiveDownload"_s, !enable);
1320 int Preferences::getTrackerPort() const
1322 return value<int>(u"Preferences/Advanced/trackerPort"_s, 9000);
1325 void Preferences::setTrackerPort(const int port)
1327 if (port == getTrackerPort())
1328 return;
1330 setValue(u"Preferences/Advanced/trackerPort"_s, port);
1333 bool Preferences::isTrackerPortForwardingEnabled() const
1335 return value(u"Preferences/Advanced/trackerPortForwarding"_s, false);
1338 void Preferences::setTrackerPortForwardingEnabled(const bool enabled)
1340 if (enabled == isTrackerPortForwardingEnabled())
1341 return;
1343 setValue(u"Preferences/Advanced/trackerPortForwarding"_s, enabled);
1346 bool Preferences::isMarkOfTheWebEnabled() const
1348 return value(u"Preferences/Advanced/markOfTheWeb"_s, true);
1351 void Preferences::setMarkOfTheWebEnabled(const bool enabled)
1353 if (enabled == isMarkOfTheWebEnabled())
1354 return;
1356 setValue(u"Preferences/Advanced/markOfTheWeb"_s, enabled);
1359 bool Preferences::isIgnoreSSLErrors() const
1361 return value(u"Preferences/Advanced/IgnoreSSLErrors"_s, false);
1364 void Preferences::setIgnoreSSLErrors(const bool enabled)
1366 if (enabled == isIgnoreSSLErrors())
1367 return;
1369 setValue(u"Preferences/Advanced/IgnoreSSLErrors"_s, enabled);
1372 Path Preferences::getPythonExecutablePath() const
1374 return value(u"Preferences/Search/pythonExecutablePath"_s, Path());
1377 void Preferences::setPythonExecutablePath(const Path &path)
1379 if (path == getPythonExecutablePath())
1380 return;
1382 setValue(u"Preferences/Search/pythonExecutablePath"_s, path);
1385 #if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
1386 bool Preferences::isUpdateCheckEnabled() const
1388 return value(u"Preferences/Advanced/updateCheck"_s, true);
1391 void Preferences::setUpdateCheckEnabled(const bool enabled)
1393 if (enabled == isUpdateCheckEnabled())
1394 return;
1396 setValue(u"Preferences/Advanced/updateCheck"_s, enabled);
1398 #endif
1400 bool Preferences::confirmTorrentDeletion() const
1402 return value(u"Preferences/Advanced/confirmTorrentDeletion"_s, true);
1405 void Preferences::setConfirmTorrentDeletion(const bool enabled)
1407 if (enabled == confirmTorrentDeletion())
1408 return;
1410 setValue(u"Preferences/Advanced/confirmTorrentDeletion"_s, enabled);
1413 bool Preferences::confirmTorrentRecheck() const
1415 return value(u"Preferences/Advanced/confirmTorrentRecheck"_s, true);
1418 void Preferences::setConfirmTorrentRecheck(const bool enabled)
1420 if (enabled == confirmTorrentRecheck())
1421 return;
1423 setValue(u"Preferences/Advanced/confirmTorrentRecheck"_s, enabled);
1426 bool Preferences::confirmRemoveAllTags() const
1428 return value(u"Preferences/Advanced/confirmRemoveAllTags"_s, true);
1431 void Preferences::setConfirmRemoveAllTags(const bool enabled)
1433 if (enabled == confirmRemoveAllTags())
1434 return;
1436 setValue(u"Preferences/Advanced/confirmRemoveAllTags"_s, enabled);
1439 bool Preferences::confirmMergeTrackers() const
1441 return value(u"GUI/ConfirmActions/MergeTrackers"_s, true);
1444 void Preferences::setConfirmMergeTrackers(const bool enabled)
1446 if (enabled == confirmMergeTrackers())
1447 return;
1449 setValue(u"GUI/ConfirmActions/MergeTrackers"_s, enabled);
1452 bool Preferences::confirmRemoveTrackerFromAllTorrents() const
1454 return value(u"GUI/ConfirmActions/RemoveTrackerFromAllTorrents"_s, true);
1457 void Preferences::setConfirmRemoveTrackerFromAllTorrents(const bool enabled)
1459 if (enabled == confirmRemoveTrackerFromAllTorrents())
1460 return;
1462 setValue(u"GUI/ConfirmActions/RemoveTrackerFromAllTorrents"_s, enabled);
1465 #ifndef Q_OS_MACOS
1466 TrayIcon::Style Preferences::trayIconStyle() const
1468 return value(u"Preferences/Advanced/TrayIconStyle"_s, TrayIcon::Style::Normal);
1471 void Preferences::setTrayIconStyle(const TrayIcon::Style style)
1473 if (style == trayIconStyle())
1474 return;
1476 setValue(u"Preferences/Advanced/TrayIconStyle"_s, style);
1478 #endif
1480 // Stuff that don't appear in the Options GUI but are saved
1481 // in the same file.
1483 QDateTime Preferences::getDNSLastUpd() const
1485 return value<QDateTime>(u"DNSUpdater/lastUpdateTime"_s);
1488 void Preferences::setDNSLastUpd(const QDateTime &date)
1490 if (date == getDNSLastUpd())
1491 return;
1493 setValue(u"DNSUpdater/lastUpdateTime"_s, date);
1496 QString Preferences::getDNSLastIP() const
1498 return value<QString>(u"DNSUpdater/lastIP"_s);
1501 void Preferences::setDNSLastIP(const QString &ip)
1503 if (ip == getDNSLastIP())
1504 return;
1506 setValue(u"DNSUpdater/lastIP"_s, ip);
1509 QByteArray Preferences::getMainGeometry() const
1511 return value<QByteArray>(u"MainWindow/geometry"_s);
1514 void Preferences::setMainGeometry(const QByteArray &geometry)
1516 if (geometry == getMainGeometry())
1517 return;
1519 setValue(u"MainWindow/geometry"_s, geometry);
1522 bool Preferences::isFiltersSidebarVisible() const
1524 return value(u"GUI/MainWindow/FiltersSidebarVisible"_s, true);
1527 void Preferences::setFiltersSidebarVisible(const bool value)
1529 if (value == isFiltersSidebarVisible())
1530 return;
1532 setValue(u"GUI/MainWindow/FiltersSidebarVisible"_s, value);
1535 int Preferences::getFiltersSidebarWidth() const
1537 return value(u"GUI/MainWindow/FiltersSidebarWidth"_s, 120);
1540 void Preferences::setFiltersSidebarWidth(const int value)
1542 if (value == getFiltersSidebarWidth())
1543 return;
1545 setValue(u"GUI/MainWindow/FiltersSidebarWidth"_s, value);
1548 Path Preferences::getMainLastDir() const
1550 return value(u"MainWindow/LastDir"_s, Utils::Fs::homePath());
1553 void Preferences::setMainLastDir(const Path &path)
1555 if (path == getMainLastDir())
1556 return;
1558 setValue(u"MainWindow/LastDir"_s, path);
1561 QByteArray Preferences::getPeerListState() const
1563 return value<QByteArray>(u"GUI/Qt6/TorrentProperties/PeerListState"_s);
1566 void Preferences::setPeerListState(const QByteArray &state)
1568 if (state == getPeerListState())
1569 return;
1571 setValue(u"GUI/Qt6/TorrentProperties/PeerListState"_s, state);
1574 QString Preferences::getPropSplitterSizes() const
1576 return value<QString>(u"TorrentProperties/SplitterSizes"_s);
1579 void Preferences::setPropSplitterSizes(const QString &sizes)
1581 if (sizes == getPropSplitterSizes())
1582 return;
1584 setValue(u"TorrentProperties/SplitterSizes"_s, sizes);
1587 QByteArray Preferences::getPropFileListState() const
1589 return value<QByteArray>(u"GUI/Qt6/TorrentProperties/FilesListState"_s);
1592 void Preferences::setPropFileListState(const QByteArray &state)
1594 if (state == getPropFileListState())
1595 return;
1597 setValue(u"GUI/Qt6/TorrentProperties/FilesListState"_s, state);
1600 int Preferences::getPropCurTab() const
1602 return value<int>(u"TorrentProperties/CurrentTab"_s, -1);
1605 void Preferences::setPropCurTab(const int tab)
1607 if (tab == getPropCurTab())
1608 return;
1610 setValue(u"TorrentProperties/CurrentTab"_s, tab);
1613 bool Preferences::getPropVisible() const
1615 return value(u"TorrentProperties/Visible"_s, false);
1618 void Preferences::setPropVisible(const bool visible)
1620 if (visible == getPropVisible())
1621 return;
1623 setValue(u"TorrentProperties/Visible"_s, visible);
1626 QByteArray Preferences::getTrackerListState() const
1628 return value<QByteArray>(u"GUI/Qt6/TorrentProperties/TrackerListState"_s);
1631 void Preferences::setTrackerListState(const QByteArray &state)
1633 if (state == getTrackerListState())
1634 return;
1636 setValue(u"GUI/Qt6/TorrentProperties/TrackerListState"_s, state);
1639 QStringList Preferences::getRssOpenFolders() const
1641 return value<QStringList>(u"GUI/RSSWidget/OpenedFolders"_s);
1644 void Preferences::setRssOpenFolders(const QStringList &folders)
1646 if (folders == getRssOpenFolders())
1647 return;
1649 setValue(u"GUI/RSSWidget/OpenedFolders"_s, folders);
1652 QByteArray Preferences::getRssSideSplitterState() const
1654 return value<QByteArray>(u"GUI/Qt6/RSSWidget/SideSplitterState"_s);
1657 void Preferences::setRssSideSplitterState(const QByteArray &state)
1659 if (state == getRssSideSplitterState())
1660 return;
1662 setValue(u"GUI/Qt6/RSSWidget/SideSplitterState"_s, state);
1665 QByteArray Preferences::getRssMainSplitterState() const
1667 return value<QByteArray>(u"GUI/Qt6/RSSWidget/MainSplitterState"_s);
1670 void Preferences::setRssMainSplitterState(const QByteArray &state)
1672 if (state == getRssMainSplitterState())
1673 return;
1675 setValue(u"GUI/Qt6/RSSWidget/MainSplitterState"_s, state);
1678 QByteArray Preferences::getSearchTabHeaderState() const
1680 return value<QByteArray>(u"GUI/Qt6/SearchTab/HeaderState"_s);
1683 void Preferences::setSearchTabHeaderState(const QByteArray &state)
1685 if (state == getSearchTabHeaderState())
1686 return;
1688 setValue(u"GUI/Qt6/SearchTab/HeaderState"_s, state);
1691 bool Preferences::getRegexAsFilteringPatternForSearchJob() const
1693 return value(u"SearchTab/UseRegexAsFilteringPattern"_s, false);
1696 void Preferences::setRegexAsFilteringPatternForSearchJob(const bool checked)
1698 if (checked == getRegexAsFilteringPatternForSearchJob())
1699 return;
1701 setValue(u"SearchTab/UseRegexAsFilteringPattern"_s, checked);
1704 QStringList Preferences::getSearchEngDisabled() const
1706 return value<QStringList>(u"SearchEngines/disabledEngines"_s);
1709 void Preferences::setSearchEngDisabled(const QStringList &engines)
1711 if (engines == getSearchEngDisabled())
1712 return;
1714 setValue(u"SearchEngines/disabledEngines"_s, engines);
1717 QString Preferences::getTorImportLastContentDir() const
1719 return value(u"TorrentImport/LastContentDir"_s, QDir::homePath());
1722 void Preferences::setTorImportLastContentDir(const QString &path)
1724 if (path == getTorImportLastContentDir())
1725 return;
1727 setValue(u"TorrentImport/LastContentDir"_s, path);
1730 QByteArray Preferences::getTorImportGeometry() const
1732 return value<QByteArray>(u"TorrentImportDlg/dimensions"_s);
1735 void Preferences::setTorImportGeometry(const QByteArray &geometry)
1737 if (geometry == getTorImportGeometry())
1738 return;
1740 setValue(u"TorrentImportDlg/dimensions"_s, geometry);
1743 bool Preferences::getStatusFilterState() const
1745 return value(u"TransferListFilters/statusFilterState"_s, true);
1748 void Preferences::setStatusFilterState(const bool checked)
1750 if (checked == getStatusFilterState())
1751 return;
1753 setValue(u"TransferListFilters/statusFilterState"_s, checked);
1756 bool Preferences::getCategoryFilterState() const
1758 return value(u"TransferListFilters/CategoryFilterState"_s, true);
1761 void Preferences::setCategoryFilterState(const bool checked)
1763 if (checked == getCategoryFilterState())
1764 return;
1766 setValue(u"TransferListFilters/CategoryFilterState"_s, checked);
1769 bool Preferences::getTagFilterState() const
1771 return value(u"TransferListFilters/TagFilterState"_s, true);
1774 void Preferences::setTagFilterState(const bool checked)
1776 if (checked == getTagFilterState())
1777 return;
1779 setValue(u"TransferListFilters/TagFilterState"_s, checked);
1782 bool Preferences::getTrackerFilterState() const
1784 return value(u"TransferListFilters/trackerFilterState"_s, true);
1787 void Preferences::setTrackerFilterState(const bool checked)
1789 if (checked == getTrackerFilterState())
1790 return;
1792 setValue(u"TransferListFilters/trackerFilterState"_s, checked);
1795 int Preferences::getTransSelFilter() const
1797 return value<int>(u"TransferListFilters/selectedFilterIndex"_s, 0);
1800 void Preferences::setTransSelFilter(const int index)
1802 if (index == getTransSelFilter())
1803 return;
1805 setValue(u"TransferListFilters/selectedFilterIndex"_s, index);
1808 bool Preferences::getHideZeroStatusFilters() const
1810 return value<bool>(u"TransferListFilters/HideZeroStatusFilters"_s, false);
1813 void Preferences::setHideZeroStatusFilters(const bool hide)
1815 if (hide == getHideZeroStatusFilters())
1816 return;
1818 setValue(u"TransferListFilters/HideZeroStatusFilters"_s, hide);
1821 QByteArray Preferences::getTransHeaderState() const
1823 return value<QByteArray>(u"GUI/Qt6/TransferList/HeaderState"_s);
1826 void Preferences::setTransHeaderState(const QByteArray &state)
1828 if (state == getTransHeaderState())
1829 return;
1831 setValue(u"GUI/Qt6/TransferList/HeaderState"_s, state);
1834 bool Preferences::getRegexAsFilteringPatternForTransferList() const
1836 return value(u"TransferList/UseRegexAsFilteringPattern"_s, false);
1839 void Preferences::setRegexAsFilteringPatternForTransferList(const bool checked)
1841 if (checked == getRegexAsFilteringPatternForTransferList())
1842 return;
1844 setValue(u"TransferList/UseRegexAsFilteringPattern"_s, checked);
1847 // From old RssSettings class
1848 bool Preferences::isRSSWidgetEnabled() const
1850 return value(u"GUI/RSSWidget/Enabled"_s, false);
1853 void Preferences::setRSSWidgetVisible(const bool enabled)
1855 if (enabled == isRSSWidgetEnabled())
1856 return;
1858 setValue(u"GUI/RSSWidget/Enabled"_s, enabled);
1861 int Preferences::getToolbarTextPosition() const
1863 return value<int>(u"Toolbar/textPosition"_s, -1);
1866 void Preferences::setToolbarTextPosition(const int position)
1868 if (position == getToolbarTextPosition())
1869 return;
1871 setValue(u"Toolbar/textPosition"_s, position);
1874 QList<QNetworkCookie> Preferences::getNetworkCookies() const
1876 const auto rawCookies = value<QStringList>(u"Network/Cookies"_s);
1877 QList<QNetworkCookie> cookies;
1878 cookies.reserve(rawCookies.size());
1879 for (const QString &rawCookie : rawCookies)
1880 cookies << QNetworkCookie::parseCookies(rawCookie.toUtf8());
1881 return cookies;
1884 void Preferences::setNetworkCookies(const QList<QNetworkCookie> &cookies)
1886 QStringList rawCookies;
1887 rawCookies.reserve(cookies.size());
1888 for (const QNetworkCookie &cookie : cookies)
1889 rawCookies << QString::fromLatin1(cookie.toRawForm());
1890 setValue(u"Network/Cookies"_s, rawCookies);
1893 bool Preferences::useProxyForBT() const
1895 return value<bool>(u"Network/Proxy/Profiles/BitTorrent"_s);
1898 void Preferences::setUseProxyForBT(const bool value)
1900 if (value == useProxyForBT())
1901 return;
1903 setValue(u"Network/Proxy/Profiles/BitTorrent"_s, value);
1906 bool Preferences::useProxyForRSS() const
1908 return value<bool>(u"Network/Proxy/Profiles/RSS"_s);
1911 void Preferences::setUseProxyForRSS(const bool value)
1913 if (value == useProxyForRSS())
1914 return;
1916 setValue(u"Network/Proxy/Profiles/RSS"_s, value);
1919 bool Preferences::useProxyForGeneralPurposes() const
1921 return value<bool>(u"Network/Proxy/Profiles/Misc"_s);
1924 void Preferences::setUseProxyForGeneralPurposes(const bool value)
1926 if (value == useProxyForGeneralPurposes())
1927 return;
1929 setValue(u"Network/Proxy/Profiles/Misc"_s, value);
1932 bool Preferences::isSpeedWidgetEnabled() const
1934 return value(u"SpeedWidget/Enabled"_s, true);
1937 void Preferences::setSpeedWidgetEnabled(const bool enabled)
1939 if (enabled == isSpeedWidgetEnabled())
1940 return;
1942 setValue(u"SpeedWidget/Enabled"_s, enabled);
1945 int Preferences::getSpeedWidgetPeriod() const
1947 return value<int>(u"SpeedWidget/period"_s, 1);
1950 void Preferences::setSpeedWidgetPeriod(const int period)
1952 if (period == getSpeedWidgetPeriod())
1953 return;
1955 setValue(u"SpeedWidget/period"_s, period);
1958 bool Preferences::getSpeedWidgetGraphEnable(const int id) const
1960 // UP and DOWN graphs enabled by default
1961 return value(u"SpeedWidget/graph_enable_%1"_s.arg(id), ((id == 0) || (id == 1)));
1964 void Preferences::setSpeedWidgetGraphEnable(const int id, const bool enable)
1966 if (enable == getSpeedWidgetGraphEnable(id))
1967 return;
1969 setValue(u"SpeedWidget/graph_enable_%1"_s.arg(id), enable);
1972 bool Preferences::isAddNewTorrentDialogEnabled() const
1974 return value(u"AddNewTorrentDialog/Enabled"_s, true);
1977 void Preferences::setAddNewTorrentDialogEnabled(const bool value)
1979 if (value == isAddNewTorrentDialogEnabled())
1980 return;
1982 setValue(u"AddNewTorrentDialog/Enabled"_s, value);
1985 bool Preferences::isAddNewTorrentDialogTopLevel() const
1987 return value(u"AddNewTorrentDialog/TopLevel"_s, true);
1990 void Preferences::setAddNewTorrentDialogTopLevel(const bool value)
1992 if (value == isAddNewTorrentDialogTopLevel())
1993 return;
1995 setValue(u"AddNewTorrentDialog/TopLevel"_s, value);
1998 int Preferences::addNewTorrentDialogSavePathHistoryLength() const
2000 const int defaultHistoryLength = 8;
2002 const int val = value(u"AddNewTorrentDialog/SavePathHistoryLength"_s, defaultHistoryLength);
2003 return std::clamp(val, 0, 99);
2006 void Preferences::setAddNewTorrentDialogSavePathHistoryLength(const int value)
2008 const int clampedValue = std::clamp(value, 0, 99);
2009 const int oldValue = addNewTorrentDialogSavePathHistoryLength();
2010 if (clampedValue == oldValue)
2011 return;
2013 setValue(u"AddNewTorrentDialog/SavePathHistoryLength"_s, clampedValue);
2016 void Preferences::apply()
2018 if (SettingsStorage::instance()->save())
2019 emit changed();