WebAPI: Add a way to download .torrent file using search plugin
[qBittorrent.git] / src / base / preferences.cpp
blob13c1c8b00b59e6e45ca48fe0bdc4a04f71693e0d
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::deleteTorrentFilesAsDefault() const
139 return value(u"Preferences/General/DeleteTorrentsFilesAsDefault"_s, false);
142 void Preferences::setDeleteTorrentFilesAsDefault(const bool del)
144 if (del == deleteTorrentFilesAsDefault())
145 return;
147 setValue(u"Preferences/General/DeleteTorrentsFilesAsDefault"_s, del);
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::isSplashScreenDisabled() const
364 return value(u"Preferences/General/NoSplashScreen"_s, true);
367 void Preferences::setSplashScreenDisabled(const bool b)
369 if (b == isSplashScreenDisabled())
370 return;
372 setValue(u"Preferences/General/NoSplashScreen"_s, b);
375 // Preventing from system suspend while active torrents are presented.
376 bool Preferences::preventFromSuspendWhenDownloading() const
378 return value(u"Preferences/General/PreventFromSuspendWhenDownloading"_s, false);
381 void Preferences::setPreventFromSuspendWhenDownloading(const bool b)
383 if (b == preventFromSuspendWhenDownloading())
384 return;
386 setValue(u"Preferences/General/PreventFromSuspendWhenDownloading"_s, b);
389 bool Preferences::preventFromSuspendWhenSeeding() const
391 return value(u"Preferences/General/PreventFromSuspendWhenSeeding"_s, false);
394 void Preferences::setPreventFromSuspendWhenSeeding(const bool b)
396 if (b == preventFromSuspendWhenSeeding())
397 return;
399 setValue(u"Preferences/General/PreventFromSuspendWhenSeeding"_s, b);
402 #ifdef Q_OS_WIN
403 bool Preferences::WinStartup() const
405 const QString profileName = Profile::instance()->profileName();
406 const Path profilePath = Profile::instance()->rootPath();
407 const QString profileID = makeProfileID(profilePath, profileName);
408 const QSettings settings {u"HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run"_s, QSettings::NativeFormat};
410 return settings.contains(profileID);
413 void Preferences::setWinStartup(const bool b)
415 const QString profileName = Profile::instance()->profileName();
416 const Path profilePath = Profile::instance()->rootPath();
417 const QString profileID = makeProfileID(profilePath, profileName);
418 QSettings settings {u"HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run"_s, QSettings::NativeFormat};
419 if (b)
421 const QString configuration = Profile::instance()->configurationName();
423 const auto cmd = uR"("%1" "--profile=%2" "--configuration=%3")"_s
424 .arg(Path(qApp->applicationFilePath()).toString(), profilePath.toString(), configuration);
425 settings.setValue(profileID, cmd);
427 else
429 settings.remove(profileID);
432 #endif // Q_OS_WIN
434 // Downloads
435 Path Preferences::getScanDirsLastPath() const
437 return value<Path>(u"Preferences/Downloads/ScanDirsLastPath"_s);
440 void Preferences::setScanDirsLastPath(const Path &path)
442 if (path == getScanDirsLastPath())
443 return;
445 setValue(u"Preferences/Downloads/ScanDirsLastPath"_s, path);
448 bool Preferences::isMailNotificationEnabled() const
450 return value(u"Preferences/MailNotification/enabled"_s, false);
453 void Preferences::setMailNotificationEnabled(const bool enabled)
455 if (enabled == isMailNotificationEnabled())
456 return;
458 setValue(u"Preferences/MailNotification/enabled"_s, enabled);
461 QString Preferences::getMailNotificationSender() const
463 return value<QString>(u"Preferences/MailNotification/sender"_s
464 , u"qBittorrent_notification@example.com"_s);
467 void Preferences::setMailNotificationSender(const QString &mail)
469 if (mail == getMailNotificationSender())
470 return;
472 setValue(u"Preferences/MailNotification/sender"_s, mail);
475 QString Preferences::getMailNotificationEmail() const
477 return value<QString>(u"Preferences/MailNotification/email"_s);
480 void Preferences::setMailNotificationEmail(const QString &mail)
482 if (mail == getMailNotificationEmail())
483 return;
485 setValue(u"Preferences/MailNotification/email"_s, mail);
488 QString Preferences::getMailNotificationSMTP() const
490 return value<QString>(u"Preferences/MailNotification/smtp_server"_s, u"smtp.changeme.com"_s);
493 void Preferences::setMailNotificationSMTP(const QString &smtpServer)
495 if (smtpServer == getMailNotificationSMTP())
496 return;
498 setValue(u"Preferences/MailNotification/smtp_server"_s, smtpServer);
501 bool Preferences::getMailNotificationSMTPSSL() const
503 return value(u"Preferences/MailNotification/req_ssl"_s, false);
506 void Preferences::setMailNotificationSMTPSSL(const bool use)
508 if (use == getMailNotificationSMTPSSL())
509 return;
511 setValue(u"Preferences/MailNotification/req_ssl"_s, use);
514 bool Preferences::getMailNotificationSMTPAuth() const
516 return value(u"Preferences/MailNotification/req_auth"_s, false);
519 void Preferences::setMailNotificationSMTPAuth(const bool use)
521 if (use == getMailNotificationSMTPAuth())
522 return;
524 setValue(u"Preferences/MailNotification/req_auth"_s, use);
527 QString Preferences::getMailNotificationSMTPUsername() const
529 return value<QString>(u"Preferences/MailNotification/username"_s);
532 void Preferences::setMailNotificationSMTPUsername(const QString &username)
534 if (username == getMailNotificationSMTPUsername())
535 return;
537 setValue(u"Preferences/MailNotification/username"_s, username);
540 QString Preferences::getMailNotificationSMTPPassword() const
542 return value<QString>(u"Preferences/MailNotification/password"_s);
545 void Preferences::setMailNotificationSMTPPassword(const QString &password)
547 if (password == getMailNotificationSMTPPassword())
548 return;
550 setValue(u"Preferences/MailNotification/password"_s, password);
553 int Preferences::getActionOnDblClOnTorrentDl() const
555 return value<int>(u"Preferences/Downloads/DblClOnTorDl"_s, 0);
558 void Preferences::setActionOnDblClOnTorrentDl(const int act)
560 if (act == getActionOnDblClOnTorrentDl())
561 return;
563 setValue(u"Preferences/Downloads/DblClOnTorDl"_s, act);
566 int Preferences::getActionOnDblClOnTorrentFn() const
568 return value<int>(u"Preferences/Downloads/DblClOnTorFn"_s, 1);
571 void Preferences::setActionOnDblClOnTorrentFn(const int act)
573 if (act == getActionOnDblClOnTorrentFn())
574 return;
576 setValue(u"Preferences/Downloads/DblClOnTorFn"_s, act);
579 QTime Preferences::getSchedulerStartTime() const
581 return value(u"Preferences/Scheduler/start_time"_s, QTime(8, 0));
584 void Preferences::setSchedulerStartTime(const QTime &time)
586 if (time == getSchedulerStartTime())
587 return;
589 setValue(u"Preferences/Scheduler/start_time"_s, time);
592 QTime Preferences::getSchedulerEndTime() const
594 return value(u"Preferences/Scheduler/end_time"_s, QTime(20, 0));
597 void Preferences::setSchedulerEndTime(const QTime &time)
599 if (time == getSchedulerEndTime())
600 return;
602 setValue(u"Preferences/Scheduler/end_time"_s, time);
605 Scheduler::Days Preferences::getSchedulerDays() const
607 return value(u"Preferences/Scheduler/days"_s, Scheduler::Days::EveryDay);
610 void Preferences::setSchedulerDays(const Scheduler::Days days)
612 if (days == getSchedulerDays())
613 return;
615 setValue(u"Preferences/Scheduler/days"_s, days);
618 // Search
619 bool Preferences::isSearchEnabled() const
621 return value(u"Preferences/Search/SearchEnabled"_s, false);
624 void Preferences::setSearchEnabled(const bool enabled)
626 if (enabled == isSearchEnabled())
627 return;
629 setValue(u"Preferences/Search/SearchEnabled"_s, enabled);
632 bool Preferences::isWebUIEnabled() const
634 #ifdef DISABLE_GUI
635 const bool defaultValue = true;
636 #else
637 const bool defaultValue = false;
638 #endif
639 return value(u"Preferences/WebUI/Enabled"_s, defaultValue);
642 void Preferences::setWebUIEnabled(const bool enabled)
644 if (enabled == isWebUIEnabled())
645 return;
647 setValue(u"Preferences/WebUI/Enabled"_s, enabled);
650 bool Preferences::isWebUILocalAuthEnabled() const
652 return value(u"Preferences/WebUI/LocalHostAuth"_s, true);
655 void Preferences::setWebUILocalAuthEnabled(const bool enabled)
657 if (enabled == isWebUILocalAuthEnabled())
658 return;
660 setValue(u"Preferences/WebUI/LocalHostAuth"_s, enabled);
663 bool Preferences::isWebUIAuthSubnetWhitelistEnabled() const
665 return value(u"Preferences/WebUI/AuthSubnetWhitelistEnabled"_s, false);
668 void Preferences::setWebUIAuthSubnetWhitelistEnabled(const bool enabled)
670 if (enabled == isWebUIAuthSubnetWhitelistEnabled())
671 return;
673 setValue(u"Preferences/WebUI/AuthSubnetWhitelistEnabled"_s, enabled);
676 QVector<Utils::Net::Subnet> Preferences::getWebUIAuthSubnetWhitelist() const
678 const auto subnets = value<QStringList>(u"Preferences/WebUI/AuthSubnetWhitelist"_s);
680 QVector<Utils::Net::Subnet> ret;
681 ret.reserve(subnets.size());
683 for (const QString &rawSubnet : subnets)
685 const std::optional<Utils::Net::Subnet> subnet = Utils::Net::parseSubnet(rawSubnet.trimmed());
686 if (subnet)
687 ret.append(subnet.value());
690 return ret;
693 void Preferences::setWebUIAuthSubnetWhitelist(QStringList subnets)
695 subnets.removeIf([](const QString &subnet)
697 return !Utils::Net::parseSubnet(subnet.trimmed()).has_value();
700 setValue(u"Preferences/WebUI/AuthSubnetWhitelist"_s, subnets);
703 QString Preferences::getServerDomains() const
705 return value<QString>(u"Preferences/WebUI/ServerDomains"_s, u"*"_s);
708 void Preferences::setServerDomains(const QString &str)
710 if (str == getServerDomains())
711 return;
713 setValue(u"Preferences/WebUI/ServerDomains"_s, str);
716 QString Preferences::getWebUIAddress() const
718 return value<QString>(u"Preferences/WebUI/Address"_s, u"*"_s).trimmed();
721 void Preferences::setWebUIAddress(const QString &addr)
723 if (addr == getWebUIAddress())
724 return;
726 setValue(u"Preferences/WebUI/Address"_s, addr.trimmed());
729 quint16 Preferences::getWebUIPort() const
731 return value<quint16>(u"Preferences/WebUI/Port"_s, 8080);
734 void Preferences::setWebUIPort(const quint16 port)
736 if (port == getWebUIPort())
737 return;
739 // cast to `int` type so it will show human readable unit in configuration file
740 setValue(u"Preferences/WebUI/Port"_s, static_cast<int>(port));
743 bool Preferences::useUPnPForWebUIPort() const
745 return value(u"Preferences/WebUI/UseUPnP"_s, false);
748 void Preferences::setUPnPForWebUIPort(const bool enabled)
750 if (enabled == useUPnPForWebUIPort())
751 return;
753 setValue(u"Preferences/WebUI/UseUPnP"_s, enabled);
756 QString Preferences::getWebUIUsername() const
758 return value<QString>(u"Preferences/WebUI/Username"_s, u"admin"_s);
761 void Preferences::setWebUIUsername(const QString &username)
763 if (username == getWebUIUsername())
764 return;
766 setValue(u"Preferences/WebUI/Username"_s, username);
769 QByteArray Preferences::getWebUIPassword() const
771 return value<QByteArray>(u"Preferences/WebUI/Password_PBKDF2"_s);
774 void Preferences::setWebUIPassword(const QByteArray &password)
776 if (password == getWebUIPassword())
777 return;
779 setValue(u"Preferences/WebUI/Password_PBKDF2"_s, password);
782 int Preferences::getWebUIMaxAuthFailCount() const
784 return value<int>(u"Preferences/WebUI/MaxAuthenticationFailCount"_s, 5);
787 void Preferences::setWebUIMaxAuthFailCount(const int count)
789 if (count == getWebUIMaxAuthFailCount())
790 return;
792 setValue(u"Preferences/WebUI/MaxAuthenticationFailCount"_s, count);
795 std::chrono::seconds Preferences::getWebUIBanDuration() const
797 return std::chrono::seconds(value<int>(u"Preferences/WebUI/BanDuration"_s, 3600));
800 void Preferences::setWebUIBanDuration(const std::chrono::seconds duration)
802 if (duration == getWebUIBanDuration())
803 return;
805 setValue(u"Preferences/WebUI/BanDuration"_s, static_cast<int>(duration.count()));
808 int Preferences::getWebUISessionTimeout() const
810 return value<int>(u"Preferences/WebUI/SessionTimeout"_s, 3600);
813 void Preferences::setWebUISessionTimeout(const int timeout)
815 if (timeout == getWebUISessionTimeout())
816 return;
818 setValue(u"Preferences/WebUI/SessionTimeout"_s, timeout);
821 QString Preferences::getWebAPISessionCookieName() const
823 return value<QString>(u"WebAPI/SessionCookieName"_s);
826 void Preferences::setWebAPISessionCookieName(const QString &cookieName)
828 if (cookieName == getWebAPISessionCookieName())
829 return;
831 setValue(u"WebAPI/SessionCookieName"_s, cookieName);
834 bool Preferences::isWebUIClickjackingProtectionEnabled() const
836 return value(u"Preferences/WebUI/ClickjackingProtection"_s, true);
839 void Preferences::setWebUIClickjackingProtectionEnabled(const bool enabled)
841 if (enabled == isWebUIClickjackingProtectionEnabled())
842 return;
844 setValue(u"Preferences/WebUI/ClickjackingProtection"_s, enabled);
847 bool Preferences::isWebUICSRFProtectionEnabled() const
849 return value(u"Preferences/WebUI/CSRFProtection"_s, true);
852 void Preferences::setWebUICSRFProtectionEnabled(const bool enabled)
854 if (enabled == isWebUICSRFProtectionEnabled())
855 return;
857 setValue(u"Preferences/WebUI/CSRFProtection"_s, enabled);
860 bool Preferences::isWebUISecureCookieEnabled() const
862 return value(u"Preferences/WebUI/SecureCookie"_s, true);
865 void Preferences::setWebUISecureCookieEnabled(const bool enabled)
867 if (enabled == isWebUISecureCookieEnabled())
868 return;
870 setValue(u"Preferences/WebUI/SecureCookie"_s, enabled);
873 bool Preferences::isWebUIHostHeaderValidationEnabled() const
875 return value(u"Preferences/WebUI/HostHeaderValidation"_s, true);
878 void Preferences::setWebUIHostHeaderValidationEnabled(const bool enabled)
880 if (enabled == isWebUIHostHeaderValidationEnabled())
881 return;
883 setValue(u"Preferences/WebUI/HostHeaderValidation"_s, enabled);
886 bool Preferences::isWebUIHttpsEnabled() const
888 return value(u"Preferences/WebUI/HTTPS/Enabled"_s, false);
891 void Preferences::setWebUIHttpsEnabled(const bool enabled)
893 if (enabled == isWebUIHttpsEnabled())
894 return;
896 setValue(u"Preferences/WebUI/HTTPS/Enabled"_s, enabled);
899 Path Preferences::getWebUIHttpsCertificatePath() const
901 return value<Path>(u"Preferences/WebUI/HTTPS/CertificatePath"_s);
904 void Preferences::setWebUIHttpsCertificatePath(const Path &path)
906 if (path == getWebUIHttpsCertificatePath())
907 return;
909 setValue(u"Preferences/WebUI/HTTPS/CertificatePath"_s, path);
912 Path Preferences::getWebUIHttpsKeyPath() const
914 return value<Path>(u"Preferences/WebUI/HTTPS/KeyPath"_s);
917 void Preferences::setWebUIHttpsKeyPath(const Path &path)
919 if (path == getWebUIHttpsKeyPath())
920 return;
922 setValue(u"Preferences/WebUI/HTTPS/KeyPath"_s, path);
925 bool Preferences::isAltWebUIEnabled() const
927 return value(u"Preferences/WebUI/AlternativeUIEnabled"_s, false);
930 void Preferences::setAltWebUIEnabled(const bool enabled)
932 if (enabled == isAltWebUIEnabled())
933 return;
935 setValue(u"Preferences/WebUI/AlternativeUIEnabled"_s, enabled);
938 Path Preferences::getWebUIRootFolder() const
940 return value<Path>(u"Preferences/WebUI/RootFolder"_s);
943 void Preferences::setWebUIRootFolder(const Path &path)
945 if (path == getWebUIRootFolder())
946 return;
948 setValue(u"Preferences/WebUI/RootFolder"_s, path);
951 bool Preferences::isWebUICustomHTTPHeadersEnabled() const
953 return value(u"Preferences/WebUI/CustomHTTPHeadersEnabled"_s, false);
956 void Preferences::setWebUICustomHTTPHeadersEnabled(const bool enabled)
958 if (enabled == isWebUICustomHTTPHeadersEnabled())
959 return;
961 setValue(u"Preferences/WebUI/CustomHTTPHeadersEnabled"_s, enabled);
964 QString Preferences::getWebUICustomHTTPHeaders() const
966 return value<QString>(u"Preferences/WebUI/CustomHTTPHeaders"_s);
969 void Preferences::setWebUICustomHTTPHeaders(const QString &headers)
971 if (headers == getWebUICustomHTTPHeaders())
972 return;
974 setValue(u"Preferences/WebUI/CustomHTTPHeaders"_s, headers);
977 bool Preferences::isWebUIReverseProxySupportEnabled() const
979 return value(u"Preferences/WebUI/ReverseProxySupportEnabled"_s, false);
982 void Preferences::setWebUIReverseProxySupportEnabled(const bool enabled)
984 if (enabled == isWebUIReverseProxySupportEnabled())
985 return;
987 setValue(u"Preferences/WebUI/ReverseProxySupportEnabled"_s, enabled);
990 QString Preferences::getWebUITrustedReverseProxiesList() const
992 return value<QString>(u"Preferences/WebUI/TrustedReverseProxiesList"_s);
995 void Preferences::setWebUITrustedReverseProxiesList(const QString &addr)
997 if (addr == getWebUITrustedReverseProxiesList())
998 return;
1000 setValue(u"Preferences/WebUI/TrustedReverseProxiesList"_s, addr);
1003 bool Preferences::isDynDNSEnabled() const
1005 return value(u"Preferences/DynDNS/Enabled"_s, false);
1008 void Preferences::setDynDNSEnabled(const bool enabled)
1010 if (enabled == isDynDNSEnabled())
1011 return;
1013 setValue(u"Preferences/DynDNS/Enabled"_s, enabled);
1016 DNS::Service Preferences::getDynDNSService() const
1018 return value(u"Preferences/DynDNS/Service"_s, DNS::Service::DynDNS);
1021 void Preferences::setDynDNSService(const DNS::Service service)
1023 if (service == getDynDNSService())
1024 return;
1026 setValue(u"Preferences/DynDNS/Service"_s, service);
1029 QString Preferences::getDynDomainName() const
1031 return value<QString>(u"Preferences/DynDNS/DomainName"_s, u"changeme.dyndns.org"_s);
1034 void Preferences::setDynDomainName(const QString &name)
1036 if (name == getDynDomainName())
1037 return;
1039 setValue(u"Preferences/DynDNS/DomainName"_s, name);
1042 QString Preferences::getDynDNSUsername() const
1044 return value<QString>(u"Preferences/DynDNS/Username"_s);
1047 void Preferences::setDynDNSUsername(const QString &username)
1049 if (username == getDynDNSUsername())
1050 return;
1052 setValue(u"Preferences/DynDNS/Username"_s, username);
1055 QString Preferences::getDynDNSPassword() const
1057 return value<QString>(u"Preferences/DynDNS/Password"_s);
1060 void Preferences::setDynDNSPassword(const QString &password)
1062 if (password == getDynDNSPassword())
1063 return;
1065 setValue(u"Preferences/DynDNS/Password"_s, password);
1068 // Advanced settings
1069 QByteArray Preferences::getUILockPassword() const
1071 return value<QByteArray>(u"Locking/password_PBKDF2"_s);
1074 void Preferences::setUILockPassword(const QByteArray &password)
1076 if (password == getUILockPassword())
1077 return;
1079 setValue(u"Locking/password_PBKDF2"_s, password);
1082 bool Preferences::isUILocked() const
1084 return value(u"Locking/locked"_s, false);
1087 void Preferences::setUILocked(const bool locked)
1089 if (locked == isUILocked())
1090 return;
1092 setValue(u"Locking/locked"_s, locked);
1095 bool Preferences::isAutoRunOnTorrentAddedEnabled() const
1097 return value(u"AutoRun/OnTorrentAdded/Enabled"_s, false);
1100 void Preferences::setAutoRunOnTorrentAddedEnabled(const bool enabled)
1102 if (enabled == isAutoRunOnTorrentAddedEnabled())
1103 return;
1105 setValue(u"AutoRun/OnTorrentAdded/Enabled"_s, enabled);
1108 QString Preferences::getAutoRunOnTorrentAddedProgram() const
1110 return value<QString>(u"AutoRun/OnTorrentAdded/Program"_s);
1113 void Preferences::setAutoRunOnTorrentAddedProgram(const QString &program)
1115 if (program == getAutoRunOnTorrentAddedProgram())
1116 return;
1118 setValue(u"AutoRun/OnTorrentAdded/Program"_s, program);
1121 bool Preferences::isAutoRunOnTorrentFinishedEnabled() const
1123 return value(u"AutoRun/enabled"_s, false);
1126 void Preferences::setAutoRunOnTorrentFinishedEnabled(const bool enabled)
1128 if (enabled == isAutoRunOnTorrentFinishedEnabled())
1129 return;
1131 setValue(u"AutoRun/enabled"_s, enabled);
1134 QString Preferences::getAutoRunOnTorrentFinishedProgram() const
1136 return value<QString>(u"AutoRun/program"_s);
1139 void Preferences::setAutoRunOnTorrentFinishedProgram(const QString &program)
1141 if (program == getAutoRunOnTorrentFinishedProgram())
1142 return;
1144 setValue(u"AutoRun/program"_s, program);
1147 #if defined(Q_OS_WIN)
1148 bool Preferences::isAutoRunConsoleEnabled() const
1150 return value(u"AutoRun/ConsoleEnabled"_s, false);
1153 void Preferences::setAutoRunConsoleEnabled(const bool enabled)
1155 if (enabled == isAutoRunConsoleEnabled())
1156 return;
1158 setValue(u"AutoRun/ConsoleEnabled"_s, enabled);
1160 #endif
1162 bool Preferences::shutdownWhenDownloadsComplete() const
1164 return value(u"Preferences/Downloads/AutoShutDownOnCompletion"_s, false);
1167 void Preferences::setShutdownWhenDownloadsComplete(const bool shutdown)
1169 if (shutdown == shutdownWhenDownloadsComplete())
1170 return;
1172 setValue(u"Preferences/Downloads/AutoShutDownOnCompletion"_s, shutdown);
1175 bool Preferences::suspendWhenDownloadsComplete() const
1177 return value(u"Preferences/Downloads/AutoSuspendOnCompletion"_s, false);
1180 void Preferences::setSuspendWhenDownloadsComplete(const bool suspend)
1182 if (suspend == suspendWhenDownloadsComplete())
1183 return;
1185 setValue(u"Preferences/Downloads/AutoSuspendOnCompletion"_s, suspend);
1188 bool Preferences::hibernateWhenDownloadsComplete() const
1190 return value(u"Preferences/Downloads/AutoHibernateOnCompletion"_s, false);
1193 void Preferences::setHibernateWhenDownloadsComplete(const bool hibernate)
1195 if (hibernate == hibernateWhenDownloadsComplete())
1196 return;
1198 setValue(u"Preferences/Downloads/AutoHibernateOnCompletion"_s, hibernate);
1201 bool Preferences::shutdownqBTWhenDownloadsComplete() const
1203 return value(u"Preferences/Downloads/AutoShutDownqBTOnCompletion"_s, false);
1206 void Preferences::setShutdownqBTWhenDownloadsComplete(const bool shutdown)
1208 if (shutdown == shutdownqBTWhenDownloadsComplete())
1209 return;
1211 setValue(u"Preferences/Downloads/AutoShutDownqBTOnCompletion"_s, shutdown);
1214 bool Preferences::dontConfirmAutoExit() const
1216 return value(u"ShutdownConfirmDlg/DontConfirmAutoExit"_s, false);
1219 void Preferences::setDontConfirmAutoExit(const bool dontConfirmAutoExit)
1221 if (dontConfirmAutoExit == this->dontConfirmAutoExit())
1222 return;
1224 setValue(u"ShutdownConfirmDlg/DontConfirmAutoExit"_s, dontConfirmAutoExit);
1227 bool Preferences::recheckTorrentsOnCompletion() const
1229 return value(u"Preferences/Advanced/RecheckOnCompletion"_s, false);
1232 void Preferences::recheckTorrentsOnCompletion(const bool recheck)
1234 if (recheck == recheckTorrentsOnCompletion())
1235 return;
1237 setValue(u"Preferences/Advanced/RecheckOnCompletion"_s, recheck);
1240 bool Preferences::resolvePeerCountries() const
1242 return value(u"Preferences/Connection/ResolvePeerCountries"_s, true);
1245 void Preferences::resolvePeerCountries(const bool resolve)
1247 if (resolve == resolvePeerCountries())
1248 return;
1250 setValue(u"Preferences/Connection/ResolvePeerCountries"_s, resolve);
1253 bool Preferences::resolvePeerHostNames() const
1255 return value(u"Preferences/Connection/ResolvePeerHostNames"_s, false);
1258 void Preferences::resolvePeerHostNames(const bool resolve)
1260 if (resolve == resolvePeerHostNames())
1261 return;
1263 setValue(u"Preferences/Connection/ResolvePeerHostNames"_s, resolve);
1266 #if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS))
1267 bool Preferences::useSystemIcons() const
1269 return value(u"Preferences/Advanced/useSystemIconTheme"_s, false);
1272 void Preferences::useSystemIcons(const bool enabled)
1274 if (enabled == useSystemIcons())
1275 return;
1277 setValue(u"Preferences/Advanced/useSystemIconTheme"_s, enabled);
1279 #endif
1281 bool Preferences::isRecursiveDownloadEnabled() const
1283 return !value(u"Preferences/Advanced/DisableRecursiveDownload"_s, false);
1286 void Preferences::setRecursiveDownloadEnabled(const bool enable)
1288 if (enable == isRecursiveDownloadEnabled())
1289 return;
1291 setValue(u"Preferences/Advanced/DisableRecursiveDownload"_s, !enable);
1294 int Preferences::getTrackerPort() const
1296 return value<int>(u"Preferences/Advanced/trackerPort"_s, 9000);
1299 void Preferences::setTrackerPort(const int port)
1301 if (port == getTrackerPort())
1302 return;
1304 setValue(u"Preferences/Advanced/trackerPort"_s, port);
1307 bool Preferences::isTrackerPortForwardingEnabled() const
1309 return value(u"Preferences/Advanced/trackerPortForwarding"_s, false);
1312 void Preferences::setTrackerPortForwardingEnabled(const bool enabled)
1314 if (enabled == isTrackerPortForwardingEnabled())
1315 return;
1317 setValue(u"Preferences/Advanced/trackerPortForwarding"_s, enabled);
1320 bool Preferences::isMarkOfTheWebEnabled() const
1322 return value(u"Preferences/Advanced/markOfTheWeb"_s, true);
1325 void Preferences::setMarkOfTheWebEnabled(const bool enabled)
1327 if (enabled == isMarkOfTheWebEnabled())
1328 return;
1330 setValue(u"Preferences/Advanced/markOfTheWeb"_s, enabled);
1333 Path Preferences::getPythonExecutablePath() const
1335 return value(u"Preferences/Search/pythonExecutablePath"_s, Path());
1338 void Preferences::setPythonExecutablePath(const Path &path)
1340 if (path == getPythonExecutablePath())
1341 return;
1343 setValue(u"Preferences/Search/pythonExecutablePath"_s, path);
1346 #if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
1347 bool Preferences::isUpdateCheckEnabled() const
1349 return value(u"Preferences/Advanced/updateCheck"_s, true);
1352 void Preferences::setUpdateCheckEnabled(const bool enabled)
1354 if (enabled == isUpdateCheckEnabled())
1355 return;
1357 setValue(u"Preferences/Advanced/updateCheck"_s, enabled);
1359 #endif
1361 bool Preferences::confirmTorrentDeletion() const
1363 return value(u"Preferences/Advanced/confirmTorrentDeletion"_s, true);
1366 void Preferences::setConfirmTorrentDeletion(const bool enabled)
1368 if (enabled == confirmTorrentDeletion())
1369 return;
1371 setValue(u"Preferences/Advanced/confirmTorrentDeletion"_s, enabled);
1374 bool Preferences::confirmTorrentRecheck() const
1376 return value(u"Preferences/Advanced/confirmTorrentRecheck"_s, true);
1379 void Preferences::setConfirmTorrentRecheck(const bool enabled)
1381 if (enabled == confirmTorrentRecheck())
1382 return;
1384 setValue(u"Preferences/Advanced/confirmTorrentRecheck"_s, enabled);
1387 bool Preferences::confirmRemoveAllTags() const
1389 return value(u"Preferences/Advanced/confirmRemoveAllTags"_s, true);
1392 void Preferences::setConfirmRemoveAllTags(const bool enabled)
1394 if (enabled == confirmRemoveAllTags())
1395 return;
1397 setValue(u"Preferences/Advanced/confirmRemoveAllTags"_s, enabled);
1400 bool Preferences::confirmMergeTrackers() const
1402 return value(u"GUI/ConfirmActions/MergeTrackers"_s, true);
1405 void Preferences::setConfirmMergeTrackers(const bool enabled)
1407 if (enabled == confirmMergeTrackers())
1408 return;
1410 setValue(u"GUI/ConfirmActions/MergeTrackers"_s, enabled);
1413 bool Preferences::confirmRemoveTrackerFromAllTorrents() const
1415 return value(u"GUI/ConfirmActions/RemoveTrackerFromAllTorrents"_s, true);
1418 void Preferences::setConfirmRemoveTrackerFromAllTorrents(const bool enabled)
1420 if (enabled == confirmRemoveTrackerFromAllTorrents())
1421 return;
1423 setValue(u"GUI/ConfirmActions/RemoveTrackerFromAllTorrents"_s, enabled);
1426 #ifndef Q_OS_MACOS
1427 TrayIcon::Style Preferences::trayIconStyle() const
1429 return value(u"Preferences/Advanced/TrayIconStyle"_s, TrayIcon::Style::Normal);
1432 void Preferences::setTrayIconStyle(const TrayIcon::Style style)
1434 if (style == trayIconStyle())
1435 return;
1437 setValue(u"Preferences/Advanced/TrayIconStyle"_s, style);
1439 #endif
1441 // Stuff that don't appear in the Options GUI but are saved
1442 // in the same file.
1444 QDateTime Preferences::getDNSLastUpd() const
1446 return value<QDateTime>(u"DNSUpdater/lastUpdateTime"_s);
1449 void Preferences::setDNSLastUpd(const QDateTime &date)
1451 if (date == getDNSLastUpd())
1452 return;
1454 setValue(u"DNSUpdater/lastUpdateTime"_s, date);
1457 QString Preferences::getDNSLastIP() const
1459 return value<QString>(u"DNSUpdater/lastIP"_s);
1462 void Preferences::setDNSLastIP(const QString &ip)
1464 if (ip == getDNSLastIP())
1465 return;
1467 setValue(u"DNSUpdater/lastIP"_s, ip);
1470 QByteArray Preferences::getMainGeometry() const
1472 return value<QByteArray>(u"MainWindow/geometry"_s);
1475 void Preferences::setMainGeometry(const QByteArray &geometry)
1477 if (geometry == getMainGeometry())
1478 return;
1480 setValue(u"MainWindow/geometry"_s, geometry);
1483 bool Preferences::isFiltersSidebarVisible() const
1485 return value(u"GUI/MainWindow/FiltersSidebarVisible"_s, true);
1488 void Preferences::setFiltersSidebarVisible(const bool value)
1490 if (value == isFiltersSidebarVisible())
1491 return;
1493 setValue(u"GUI/MainWindow/FiltersSidebarVisible"_s, value);
1496 int Preferences::getFiltersSidebarWidth() const
1498 return value(u"GUI/MainWindow/FiltersSidebarWidth"_s, 120);
1501 void Preferences::setFiltersSidebarWidth(const int value)
1503 if (value == getFiltersSidebarWidth())
1504 return;
1506 setValue(u"GUI/MainWindow/FiltersSidebarWidth"_s, value);
1509 Path Preferences::getMainLastDir() const
1511 return value(u"MainWindow/LastDir"_s, Utils::Fs::homePath());
1514 void Preferences::setMainLastDir(const Path &path)
1516 if (path == getMainLastDir())
1517 return;
1519 setValue(u"MainWindow/LastDir"_s, path);
1522 QByteArray Preferences::getPeerListState() const
1524 return value<QByteArray>(u"GUI/Qt6/TorrentProperties/PeerListState"_s);
1527 void Preferences::setPeerListState(const QByteArray &state)
1529 if (state == getPeerListState())
1530 return;
1532 setValue(u"GUI/Qt6/TorrentProperties/PeerListState"_s, state);
1535 QString Preferences::getPropSplitterSizes() const
1537 return value<QString>(u"TorrentProperties/SplitterSizes"_s);
1540 void Preferences::setPropSplitterSizes(const QString &sizes)
1542 if (sizes == getPropSplitterSizes())
1543 return;
1545 setValue(u"TorrentProperties/SplitterSizes"_s, sizes);
1548 QByteArray Preferences::getPropFileListState() const
1550 return value<QByteArray>(u"GUI/Qt6/TorrentProperties/FilesListState"_s);
1553 void Preferences::setPropFileListState(const QByteArray &state)
1555 if (state == getPropFileListState())
1556 return;
1558 setValue(u"GUI/Qt6/TorrentProperties/FilesListState"_s, state);
1561 int Preferences::getPropCurTab() const
1563 return value<int>(u"TorrentProperties/CurrentTab"_s, -1);
1566 void Preferences::setPropCurTab(const int tab)
1568 if (tab == getPropCurTab())
1569 return;
1571 setValue(u"TorrentProperties/CurrentTab"_s, tab);
1574 bool Preferences::getPropVisible() const
1576 return value(u"TorrentProperties/Visible"_s, false);
1579 void Preferences::setPropVisible(const bool visible)
1581 if (visible == getPropVisible())
1582 return;
1584 setValue(u"TorrentProperties/Visible"_s, visible);
1587 QByteArray Preferences::getTrackerListState() const
1589 return value<QByteArray>(u"GUI/Qt6/TorrentProperties/TrackerListState"_s);
1592 void Preferences::setTrackerListState(const QByteArray &state)
1594 if (state == getTrackerListState())
1595 return;
1597 setValue(u"GUI/Qt6/TorrentProperties/TrackerListState"_s, state);
1600 QStringList Preferences::getRssOpenFolders() const
1602 return value<QStringList>(u"GUI/RSSWidget/OpenedFolders"_s);
1605 void Preferences::setRssOpenFolders(const QStringList &folders)
1607 if (folders == getRssOpenFolders())
1608 return;
1610 setValue(u"GUI/RSSWidget/OpenedFolders"_s, folders);
1613 QByteArray Preferences::getRssSideSplitterState() const
1615 return value<QByteArray>(u"GUI/Qt6/RSSWidget/SideSplitterState"_s);
1618 void Preferences::setRssSideSplitterState(const QByteArray &state)
1620 if (state == getRssSideSplitterState())
1621 return;
1623 setValue(u"GUI/Qt6/RSSWidget/SideSplitterState"_s, state);
1626 QByteArray Preferences::getRssMainSplitterState() const
1628 return value<QByteArray>(u"GUI/Qt6/RSSWidget/MainSplitterState"_s);
1631 void Preferences::setRssMainSplitterState(const QByteArray &state)
1633 if (state == getRssMainSplitterState())
1634 return;
1636 setValue(u"GUI/Qt6/RSSWidget/MainSplitterState"_s, state);
1639 QByteArray Preferences::getSearchTabHeaderState() const
1641 return value<QByteArray>(u"GUI/Qt6/SearchTab/HeaderState"_s);
1644 void Preferences::setSearchTabHeaderState(const QByteArray &state)
1646 if (state == getSearchTabHeaderState())
1647 return;
1649 setValue(u"GUI/Qt6/SearchTab/HeaderState"_s, state);
1652 bool Preferences::getRegexAsFilteringPatternForSearchJob() const
1654 return value(u"SearchTab/UseRegexAsFilteringPattern"_s, false);
1657 void Preferences::setRegexAsFilteringPatternForSearchJob(const bool checked)
1659 if (checked == getRegexAsFilteringPatternForSearchJob())
1660 return;
1662 setValue(u"SearchTab/UseRegexAsFilteringPattern"_s, checked);
1665 QStringList Preferences::getSearchEngDisabled() const
1667 return value<QStringList>(u"SearchEngines/disabledEngines"_s);
1670 void Preferences::setSearchEngDisabled(const QStringList &engines)
1672 if (engines == getSearchEngDisabled())
1673 return;
1675 setValue(u"SearchEngines/disabledEngines"_s, engines);
1678 QString Preferences::getTorImportLastContentDir() const
1680 return value(u"TorrentImport/LastContentDir"_s, QDir::homePath());
1683 void Preferences::setTorImportLastContentDir(const QString &path)
1685 if (path == getTorImportLastContentDir())
1686 return;
1688 setValue(u"TorrentImport/LastContentDir"_s, path);
1691 QByteArray Preferences::getTorImportGeometry() const
1693 return value<QByteArray>(u"TorrentImportDlg/dimensions"_s);
1696 void Preferences::setTorImportGeometry(const QByteArray &geometry)
1698 if (geometry == getTorImportGeometry())
1699 return;
1701 setValue(u"TorrentImportDlg/dimensions"_s, geometry);
1704 bool Preferences::getStatusFilterState() const
1706 return value(u"TransferListFilters/statusFilterState"_s, true);
1709 void Preferences::setStatusFilterState(const bool checked)
1711 if (checked == getStatusFilterState())
1712 return;
1714 setValue(u"TransferListFilters/statusFilterState"_s, checked);
1717 bool Preferences::getCategoryFilterState() const
1719 return value(u"TransferListFilters/CategoryFilterState"_s, true);
1722 void Preferences::setCategoryFilterState(const bool checked)
1724 if (checked == getCategoryFilterState())
1725 return;
1727 setValue(u"TransferListFilters/CategoryFilterState"_s, checked);
1730 bool Preferences::getTagFilterState() const
1732 return value(u"TransferListFilters/TagFilterState"_s, true);
1735 void Preferences::setTagFilterState(const bool checked)
1737 if (checked == getTagFilterState())
1738 return;
1740 setValue(u"TransferListFilters/TagFilterState"_s, checked);
1743 bool Preferences::getTrackerFilterState() const
1745 return value(u"TransferListFilters/trackerFilterState"_s, true);
1748 void Preferences::setTrackerFilterState(const bool checked)
1750 if (checked == getTrackerFilterState())
1751 return;
1753 setValue(u"TransferListFilters/trackerFilterState"_s, checked);
1756 int Preferences::getTransSelFilter() const
1758 return value<int>(u"TransferListFilters/selectedFilterIndex"_s, 0);
1761 void Preferences::setTransSelFilter(const int index)
1763 if (index == getTransSelFilter())
1764 return;
1766 setValue(u"TransferListFilters/selectedFilterIndex"_s, index);
1769 bool Preferences::getHideZeroStatusFilters() const
1771 return value<bool>(u"TransferListFilters/HideZeroStatusFilters"_s, false);
1774 void Preferences::setHideZeroStatusFilters(const bool hide)
1776 if (hide == getHideZeroStatusFilters())
1777 return;
1779 setValue(u"TransferListFilters/HideZeroStatusFilters"_s, hide);
1782 QByteArray Preferences::getTransHeaderState() const
1784 return value<QByteArray>(u"GUI/Qt6/TransferList/HeaderState"_s);
1787 void Preferences::setTransHeaderState(const QByteArray &state)
1789 if (state == getTransHeaderState())
1790 return;
1792 setValue(u"GUI/Qt6/TransferList/HeaderState"_s, state);
1795 bool Preferences::getRegexAsFilteringPatternForTransferList() const
1797 return value(u"TransferList/UseRegexAsFilteringPattern"_s, false);
1800 void Preferences::setRegexAsFilteringPatternForTransferList(const bool checked)
1802 if (checked == getRegexAsFilteringPatternForTransferList())
1803 return;
1805 setValue(u"TransferList/UseRegexAsFilteringPattern"_s, checked);
1808 // From old RssSettings class
1809 bool Preferences::isRSSWidgetEnabled() const
1811 return value(u"GUI/RSSWidget/Enabled"_s, false);
1814 void Preferences::setRSSWidgetVisible(const bool enabled)
1816 if (enabled == isRSSWidgetEnabled())
1817 return;
1819 setValue(u"GUI/RSSWidget/Enabled"_s, enabled);
1822 int Preferences::getToolbarTextPosition() const
1824 return value<int>(u"Toolbar/textPosition"_s, -1);
1827 void Preferences::setToolbarTextPosition(const int position)
1829 if (position == getToolbarTextPosition())
1830 return;
1832 setValue(u"Toolbar/textPosition"_s, position);
1835 QList<QNetworkCookie> Preferences::getNetworkCookies() const
1837 const auto rawCookies = value<QStringList>(u"Network/Cookies"_s);
1838 QList<QNetworkCookie> cookies;
1839 cookies.reserve(rawCookies.size());
1840 for (const QString &rawCookie : rawCookies)
1841 cookies << QNetworkCookie::parseCookies(rawCookie.toUtf8());
1842 return cookies;
1845 void Preferences::setNetworkCookies(const QList<QNetworkCookie> &cookies)
1847 QStringList rawCookies;
1848 rawCookies.reserve(cookies.size());
1849 for (const QNetworkCookie &cookie : cookies)
1850 rawCookies << QString::fromLatin1(cookie.toRawForm());
1851 setValue(u"Network/Cookies"_s, rawCookies);
1854 bool Preferences::useProxyForBT() const
1856 return value<bool>(u"Network/Proxy/Profiles/BitTorrent"_s);
1859 void Preferences::setUseProxyForBT(const bool value)
1861 if (value == useProxyForBT())
1862 return;
1864 setValue(u"Network/Proxy/Profiles/BitTorrent"_s, value);
1867 bool Preferences::useProxyForRSS() const
1869 return value<bool>(u"Network/Proxy/Profiles/RSS"_s);
1872 void Preferences::setUseProxyForRSS(const bool value)
1874 if (value == useProxyForRSS())
1875 return;
1877 setValue(u"Network/Proxy/Profiles/RSS"_s, value);
1880 bool Preferences::useProxyForGeneralPurposes() const
1882 return value<bool>(u"Network/Proxy/Profiles/Misc"_s);
1885 void Preferences::setUseProxyForGeneralPurposes(const bool value)
1887 if (value == useProxyForGeneralPurposes())
1888 return;
1890 setValue(u"Network/Proxy/Profiles/Misc"_s, value);
1893 bool Preferences::isSpeedWidgetEnabled() const
1895 return value(u"SpeedWidget/Enabled"_s, true);
1898 void Preferences::setSpeedWidgetEnabled(const bool enabled)
1900 if (enabled == isSpeedWidgetEnabled())
1901 return;
1903 setValue(u"SpeedWidget/Enabled"_s, enabled);
1906 int Preferences::getSpeedWidgetPeriod() const
1908 return value<int>(u"SpeedWidget/period"_s, 1);
1911 void Preferences::setSpeedWidgetPeriod(const int period)
1913 if (period == getSpeedWidgetPeriod())
1914 return;
1916 setValue(u"SpeedWidget/period"_s, period);
1919 bool Preferences::getSpeedWidgetGraphEnable(const int id) const
1921 // UP and DOWN graphs enabled by default
1922 return value(u"SpeedWidget/graph_enable_%1"_s.arg(id), ((id == 0) || (id == 1)));
1925 void Preferences::setSpeedWidgetGraphEnable(const int id, const bool enable)
1927 if (enable == getSpeedWidgetGraphEnable(id))
1928 return;
1930 setValue(u"SpeedWidget/graph_enable_%1"_s.arg(id), enable);
1933 bool Preferences::isAddNewTorrentDialogEnabled() const
1935 return value(u"AddNewTorrentDialog/Enabled"_s, true);
1938 void Preferences::setAddNewTorrentDialogEnabled(const bool value)
1940 if (value == isAddNewTorrentDialogEnabled())
1941 return;
1943 setValue(u"AddNewTorrentDialog/Enabled"_s, value);
1946 bool Preferences::isAddNewTorrentDialogTopLevel() const
1948 return value(u"AddNewTorrentDialog/TopLevel"_s, true);
1951 void Preferences::setAddNewTorrentDialogTopLevel(const bool value)
1953 if (value == isAddNewTorrentDialogTopLevel())
1954 return;
1956 setValue(u"AddNewTorrentDialog/TopLevel"_s, value);
1959 int Preferences::addNewTorrentDialogSavePathHistoryLength() const
1961 const int defaultHistoryLength = 8;
1963 const int val = value(u"AddNewTorrentDialog/SavePathHistoryLength"_s, defaultHistoryLength);
1964 return std::clamp(val, 0, 99);
1967 void Preferences::setAddNewTorrentDialogSavePathHistoryLength(const int value)
1969 const int clampedValue = std::clamp(value, 0, 99);
1970 const int oldValue = addNewTorrentDialogSavePathHistoryLength();
1971 if (clampedValue == oldValue)
1972 return;
1974 setValue(u"AddNewTorrentDialog/SavePathHistoryLength"_s, clampedValue);
1977 void Preferences::apply()
1979 if (SettingsStorage::instance()->save())
1980 emit changed();