Merge pull request #8944 from Chocobo1/literal

Make use of QStringLiteral
This commit is contained in:
Mike Tzou
2018-05-23 13:23:41 +08:00
committed by GitHub
12 changed files with 34 additions and 46 deletions

View File

@@ -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<int> &AddNewTorrentDialog::savePathHistoryLengthSetting()
{
const int defaultHistoryLength = 8;
static CachedSettingValue<int> 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()

View File

@@ -51,15 +51,14 @@ namespace Ui
class PropListDelegate;
class TorrentContentFilterModel;
class TorrentFileGuard;
template <typename T> 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<int> &savePathHistoryLengthSetting();
void showEvent(QShowEvent *event) override;

View File

@@ -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");

View File

@@ -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");

View File

@@ -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);