diff --git a/src/app/application.cpp b/src/app/application.cpp index cd37f0a4c..88076b7f4 100644 --- a/src/app/application.cpp +++ b/src/app/application.cpp @@ -93,7 +93,7 @@ namespace #define SETTINGS_KEY(name) "Application/" name // FileLogger properties keys -#define FILELOGGER_SETTINGS_KEY(name) SETTINGS_KEY("FileLogger/") name +#define FILELOGGER_SETTINGS_KEY(name) QStringLiteral(SETTINGS_KEY("FileLogger/") name) const QString KEY_FILELOGGER_ENABLED = FILELOGGER_SETTINGS_KEY("Enabled"); const QString KEY_FILELOGGER_PATH = FILELOGGER_SETTINGS_KEY("Path"); const QString KEY_FILELOGGER_BACKUP = FILELOGGER_SETTINGS_KEY("Backup"); diff --git a/src/base/bittorrent/torrenthandle.cpp b/src/base/bittorrent/torrenthandle.cpp index cbe77267a..e54e08897 100644 --- a/src/base/bittorrent/torrenthandle.cpp +++ b/src/base/bittorrent/torrenthandle.cpp @@ -65,7 +65,7 @@ #include "session.h" #include "trackerentry.h" -const QString QB_EXT {".!qB"}; +const QString QB_EXT {QStringLiteral(".!qB")}; namespace libt = libtorrent; using namespace BitTorrent; diff --git a/src/base/net/portforwarder.cpp b/src/base/net/portforwarder.cpp index 44d350d29..3cf926eaa 100644 --- a/src/base/net/portforwarder.cpp +++ b/src/base/net/portforwarder.cpp @@ -36,7 +36,7 @@ #include "base/logger.h" #include "base/settingsstorage.h" -static const QString KEY_ENABLED = QLatin1String("Network/PortForwardingEnabled"); +static const QString KEY_ENABLED = QStringLiteral("Network/PortForwardingEnabled"); namespace libt = libtorrent; using namespace Net; diff --git a/src/base/net/proxyconfigurationmanager.cpp b/src/base/net/proxyconfigurationmanager.cpp index da55cc929..d06352792 100644 --- a/src/base/net/proxyconfigurationmanager.cpp +++ b/src/base/net/proxyconfigurationmanager.cpp @@ -30,7 +30,7 @@ #include "base/settingsstorage.h" -#define SETTINGS_KEY(name) "Network/Proxy/" name +#define SETTINGS_KEY(name) QStringLiteral("Network/Proxy/" name) const QString KEY_ONLY_FOR_TORRENTS = SETTINGS_KEY("OnlyForTorrents"); const QString KEY_TYPE = SETTINGS_KEY("Type"); const QString KEY_IP = SETTINGS_KEY("IP"); diff --git a/src/base/rss/rss_item.cpp b/src/base/rss/rss_item.cpp index 7c0917438..45c0ae8d1 100644 --- a/src/base/rss/rss_item.cpp +++ b/src/base/rss/rss_item.cpp @@ -36,7 +36,7 @@ using namespace RSS; -const QString Item::PathSeparator("\\"); +const QChar Item::PathSeparator('\\'); Item::Item(const QString &path) : m_path(path) diff --git a/src/base/rss/rss_item.h b/src/base/rss/rss_item.h index 273857257..ccc13ea3e 100644 --- a/src/base/rss/rss_item.h +++ b/src/base/rss/rss_item.h @@ -58,7 +58,7 @@ namespace RSS virtual QJsonValue toJsonValue(bool withData = false) const = 0; - static const QString PathSeparator; + static const QChar PathSeparator; static bool isValidPath(const QString &path); static QString joinPath(const QString &path1, const QString &path2); diff --git a/src/gui/addnewtorrentdialog.cpp b/src/gui/addnewtorrentdialog.cpp index aa0c16c11..76647f44d 100644 --- a/src/gui/addnewtorrentdialog.cpp +++ b/src/gui/addnewtorrentdialog.cpp @@ -46,7 +46,6 @@ #include "base/net/downloadmanager.h" #include "base/preferences.h" #include "base/settingsstorage.h" -#include "base/settingvalue.h" #include "base/torrentfileguard.h" #include "base/unicodestrings.h" #include "base/utils/fs.h" @@ -63,7 +62,7 @@ namespace { -#define SETTINGS_KEY(name) "AddNewTorrentDialog/" name +#define SETTINGS_KEY(name) QStringLiteral("AddNewTorrentDialog/" name) const QString KEY_ENABLED = SETTINGS_KEY("Enabled"); const QString KEY_DEFAULTCATEGORY = SETTINGS_KEY("DefaultCategory"); const QString KEY_TREEHEADERSTATE = SETTINGS_KEY("TreeHeaderState"); @@ -71,7 +70,7 @@ namespace const QString KEY_EXPANDED = SETTINGS_KEY("Expanded"); const QString KEY_TOPLEVEL = SETTINGS_KEY("TopLevel"); const QString KEY_SAVEPATHHISTORY = SETTINGS_KEY("SavePathHistory"); - const char KEY_SAVEPATHHISTORYLENGTH[] = SETTINGS_KEY("SavePathHistoryLength"); + const QString KEY_SAVEPATHHISTORYLENGTH = SETTINGS_KEY("SavePathHistoryLength"); const QString KEY_REMEMBERLASTSAVEPATH = SETTINGS_KEY("RememberLastSavePath"); // just a shortcut @@ -81,8 +80,8 @@ namespace } } -constexpr int AddNewTorrentDialog::minPathHistoryLength; -constexpr int AddNewTorrentDialog::maxPathHistoryLength; +const int AddNewTorrentDialog::minPathHistoryLength; +const int AddNewTorrentDialog::maxPathHistoryLength; AddNewTorrentDialog::AddNewTorrentDialog(const BitTorrent::AddTorrentParams &inParams, QWidget *parent) : QDialog(parent) @@ -188,30 +187,21 @@ void AddNewTorrentDialog::setTopLevel(bool value) int AddNewTorrentDialog::savePathHistoryLength() { - return savePathHistoryLengthSetting(); + const int defaultHistoryLength = 8; + const int value = settings()->loadValue(KEY_SAVEPATHHISTORYLENGTH, defaultHistoryLength).toInt(); + return qBound(minPathHistoryLength, value, maxPathHistoryLength); } void AddNewTorrentDialog::setSavePathHistoryLength(int value) { - Q_ASSERT(value >= minPathHistoryLength); - Q_ASSERT(value <= maxPathHistoryLength); + const int clampedValue = qBound(minPathHistoryLength, value, maxPathHistoryLength); const int oldValue = savePathHistoryLength(); - if (oldValue != value) { - savePathHistoryLengthSetting() = value; - settings()->storeValue(KEY_SAVEPATHHISTORY, - QStringList(settings()->loadValue(KEY_SAVEPATHHISTORY).toStringList().mid(0, value))); - } -} + if (clampedValue == oldValue) + return; -CachedSettingValue &AddNewTorrentDialog::savePathHistoryLengthSetting() -{ - const int defaultHistoryLength = 8; - static CachedSettingValue setting(KEY_SAVEPATHHISTORYLENGTH, defaultHistoryLength, - [](int v) - { - return std::max(minPathHistoryLength, std::min(maxPathHistoryLength, v)); - }); - return setting; + settings()->storeValue(KEY_SAVEPATHHISTORYLENGTH, clampedValue); + settings()->storeValue(KEY_SAVEPATHHISTORY + , QStringList(settings()->loadValue(KEY_SAVEPATHHISTORY).toStringList().mid(0, clampedValue))); } void AddNewTorrentDialog::loadState() diff --git a/src/gui/addnewtorrentdialog.h b/src/gui/addnewtorrentdialog.h index b52504232..c34cc5c65 100644 --- a/src/gui/addnewtorrentdialog.h +++ b/src/gui/addnewtorrentdialog.h @@ -51,15 +51,14 @@ namespace Ui class PropListDelegate; class TorrentContentFilterModel; class TorrentFileGuard; -template class CachedSettingValue; class AddNewTorrentDialog : public QDialog { Q_OBJECT public: - static constexpr int minPathHistoryLength = 0; - static constexpr int maxPathHistoryLength = 99; + static const int minPathHistoryLength = 0; + static const int maxPathHistoryLength = 99; ~AddNewTorrentDialog(); @@ -103,7 +102,6 @@ private: void setupTreeview(); void setCommentText(const QString &str) const; void setSavePath(const QString &newPath); - static CachedSettingValue &savePathHistoryLengthSetting(); void showEvent(QShowEvent *event) override; diff --git a/src/gui/cookiesdialog.cpp b/src/gui/cookiesdialog.cpp index da46fa7c8..23bf4a767 100644 --- a/src/gui/cookiesdialog.cpp +++ b/src/gui/cookiesdialog.cpp @@ -37,7 +37,7 @@ #include "ui_cookiesdialog.h" #include "utils.h" -#define SETTINGS_KEY(name) "CookiesDialog/" name +#define SETTINGS_KEY(name) QStringLiteral("CookiesDialog/" name) const QString KEY_SIZE = SETTINGS_KEY("Size"); const QString KEY_COOKIESVIEWSTATE = SETTINGS_KEY("CookiesViewState"); diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index fb18375a5..0d3f8214b 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -121,12 +121,12 @@ namespace #define SETTINGS_KEY(name) "GUI/" name // ExecutionLog properties keys -#define EXECUTIONLOG_SETTINGS_KEY(name) SETTINGS_KEY("Log/") name +#define EXECUTIONLOG_SETTINGS_KEY(name) QStringLiteral(SETTINGS_KEY("Log/") name) const QString KEY_EXECUTIONLOG_ENABLED = EXECUTIONLOG_SETTINGS_KEY("Enabled"); const QString KEY_EXECUTIONLOG_TYPES = EXECUTIONLOG_SETTINGS_KEY("Types"); // Notifications properties keys -#define NOTIFICATIONS_SETTINGS_KEY(name) SETTINGS_KEY("Notifications/") name +#define NOTIFICATIONS_SETTINGS_KEY(name) QStringLiteral(SETTINGS_KEY("Notifications/") name) const QString KEY_NOTIFICATIONS_ENABLED = NOTIFICATIONS_SETTINGS_KEY("Enabled"); const QString KEY_NOTIFICATIONS_TORRENTADDED = NOTIFICATIONS_SETTINGS_KEY("TorrentAdded"); diff --git a/src/gui/programupdater.cpp b/src/gui/programupdater.cpp index 933a500d9..e2d8c0fc1 100644 --- a/src/gui/programupdater.cpp +++ b/src/gui/programupdater.cpp @@ -41,14 +41,14 @@ namespace { - const QString RSS_URL("https://www.fosshub.com/software/feedqBittorent"); + const QString RSS_URL {QStringLiteral("https://www.fosshub.com/software/feedqBittorent")}; #ifdef Q_OS_MAC - const QString OS_TYPE("Mac OS X"); + const QString OS_TYPE {QStringLiteral("Mac OS X")}; #elif defined(Q_OS_WIN) && (defined(__x86_64__) || defined(_M_X64)) - const QString OS_TYPE("Windows x64"); + const QString OS_TYPE {QStringLiteral("Windows x64")}; #else - const QString OS_TYPE("Windows"); + const QString OS_TYPE {QStringLiteral("Windows")}; #endif QString getStringValue(QXmlStreamReader &xml); diff --git a/src/webui/webapplication.cpp b/src/webui/webapplication.cpp index 35e6d2fa9..401f7de04 100644 --- a/src/webui/webapplication.cpp +++ b/src/webui/webapplication.cpp @@ -68,12 +68,12 @@ constexpr int MAX_ALLOWED_FILESIZE = 10 * 1024 * 1024; -const QString PATH_PREFIX_IMAGES {"/images/"}; -const QString PATH_PREFIX_THEME {"/theme/"}; -const QString WWW_FOLDER {":/www"}; -const QString PUBLIC_FOLDER {"/public"}; -const QString PRIVATE_FOLDER {"/private"}; -const QString MAX_AGE_MONTH {"public, max-age=2592000"}; +const QString PATH_PREFIX_IMAGES {QStringLiteral("/images/")}; +const QString PATH_PREFIX_THEME {QStringLiteral("/theme/")}; +const QString WWW_FOLDER {QStringLiteral(":/www")}; +const QString PUBLIC_FOLDER {QStringLiteral("/public")}; +const QString PRIVATE_FOLDER {QStringLiteral("/private")}; +const QString MAX_AGE_MONTH {QStringLiteral("public, max-age=2592000")}; namespace {