Improve function interface

`SettingsStorage` methods require `QString` so make `SettingValue` follow it.
`Path::operator+` can use `QStringView` to accept wider audience.
This commit is contained in:
Chocobo1
2022-03-23 23:56:47 +08:00
parent 11cfe38d1c
commit c6b772da11
33 changed files with 222 additions and 239 deletions

View File

@@ -39,12 +39,12 @@
#include "uithememanager.h"
#include "utils.h"
#define SETTINGS_KEY(name) "AboutDialog/" name
#define SETTINGS_KEY(name) u"AboutDialog/" name
AboutDialog::AboutDialog(QWidget *parent)
: QDialog(parent)
, m_ui(new Ui::AboutDialog)
, m_storeDialogSize(SETTINGS_KEY("Size"))
, m_storeDialogSize(SETTINGS_KEY(u"Size"_qs))
{
m_ui->setupUi(this);
setAttribute(Qt::WA_DeleteOnClose);

View File

@@ -65,12 +65,12 @@
namespace
{
#define SETTINGS_KEY(name) "AddNewTorrentDialog/" name
const QString KEY_ENABLED = QStringLiteral(SETTINGS_KEY("Enabled"));
const QString KEY_TOPLEVEL = QStringLiteral(SETTINGS_KEY("TopLevel"));
const QString KEY_SAVEPATHHISTORY = QStringLiteral(SETTINGS_KEY("SavePathHistory"));
const QString KEY_DOWNLOADPATHHISTORY = QStringLiteral(SETTINGS_KEY("DownloadPathHistory"));
const QString KEY_SAVEPATHHISTORYLENGTH = QStringLiteral(SETTINGS_KEY("SavePathHistoryLength"));
#define SETTINGS_KEY(name) u"AddNewTorrentDialog/" name
const QString KEY_ENABLED = SETTINGS_KEY(u"Enabled"_qs);
const QString KEY_TOPLEVEL = SETTINGS_KEY(u"TopLevel"_qs);
const QString KEY_SAVEPATHHISTORY = SETTINGS_KEY(u"SavePathHistory"_qs);
const QString KEY_DOWNLOADPATHHISTORY = SETTINGS_KEY(u"DownloadPathHistory"_qs);
const QString KEY_SAVEPATHHISTORYLENGTH = SETTINGS_KEY(u"SavePathHistoryLength"_qs);
// just a shortcut
inline SettingsStorage *settings()
@@ -170,15 +170,15 @@ AddNewTorrentDialog::AddNewTorrentDialog(const BitTorrent::AddTorrentParams &inP
: QDialog(parent)
, m_ui(new Ui::AddNewTorrentDialog)
, m_torrentParams(inParams)
, m_storeDialogSize(SETTINGS_KEY("DialogSize"))
, m_storeDefaultCategory(SETTINGS_KEY("DefaultCategory"))
, m_storeRememberLastSavePath(SETTINGS_KEY("RememberLastSavePath"))
, m_storeDialogSize(SETTINGS_KEY(u"DialogSize"_qs))
, m_storeDefaultCategory(SETTINGS_KEY(u"DefaultCategory"_qs))
, m_storeRememberLastSavePath(SETTINGS_KEY(u"RememberLastSavePath"_qs))
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
, m_storeTreeHeaderState("GUI/Qt6/" SETTINGS_KEY("TreeHeaderState"))
, m_storeSplitterState("GUI/Qt6/" SETTINGS_KEY("SplitterState"))
, m_storeTreeHeaderState(u"GUI/Qt6/" SETTINGS_KEY(u"TreeHeaderState"_qs))
, m_storeSplitterState(u"GUI/Qt6/" SETTINGS_KEY(u"SplitterState"_qs))
#else
, m_storeTreeHeaderState(SETTINGS_KEY("TreeHeaderState"))
, m_storeSplitterState(SETTINGS_KEY("SplitterState"))
, m_storeTreeHeaderState(SETTINGS_KEY(u"TreeHeaderState"_qs))
, m_storeSplitterState(SETTINGS_KEY(u"SplitterState"_qs))
#endif
{
// TODO: set dialog file properties using m_torrentParams.filePriorities

View File

@@ -38,12 +38,12 @@
#include "ui_banlistoptionsdialog.h"
#include "utils.h"
#define SETTINGS_KEY(name) "BanListOptionsDialog/" name
#define SETTINGS_KEY(name) u"BanListOptionsDialog/" name
BanListOptionsDialog::BanListOptionsDialog(QWidget *parent)
: QDialog(parent)
, m_ui(new Ui::BanListOptionsDialog)
, m_storeDialogSize(SETTINGS_KEY("Size"))
, m_storeDialogSize(SETTINGS_KEY(u"Size"_qs))
, m_model(new QStringListModel(BitTorrent::Session::instance()->bannedIPs(), this))
{
m_ui->setupUi(this);

View File

@@ -37,17 +37,17 @@
#include "uithememanager.h"
#include "utils.h"
#define SETTINGS_KEY(name) "CookiesDialog/" name
#define SETTINGS_KEY(name) u"CookiesDialog/" name
CookiesDialog::CookiesDialog(QWidget *parent)
: QDialog(parent)
, m_ui(new Ui::CookiesDialog)
, m_cookiesModel(new CookiesModel(Net::DownloadManager::instance()->allCookies(), this))
, m_storeDialogSize(SETTINGS_KEY("Size"))
, m_storeDialogSize(SETTINGS_KEY(u"Size"_qs))
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
, m_storeViewState("GUI/Qt6/" SETTINGS_KEY("ViewState"))
, m_storeViewState("GUI/Qt6/" SETTINGS_KEY(u"ViewState"_qs))
#else
, m_storeViewState(SETTINGS_KEY("CookiesViewState"))
, m_storeViewState(SETTINGS_KEY(u"CookiesViewState"_qs))
#endif
{
m_ui->setupUi(this);

View File

@@ -39,7 +39,7 @@
#include "ui_downloadfromurldialog.h"
#include "utils.h"
#define SETTINGS_KEY(name) "DownloadFromURLDialog/" name
#define SETTINGS_KEY(name) u"DownloadFromURLDialog/" name
namespace
{
@@ -61,7 +61,7 @@ namespace
DownloadFromURLDialog::DownloadFromURLDialog(QWidget *parent)
: QDialog(parent)
, m_ui(new Ui::DownloadFromURLDialog)
, m_storeDialogSize(SETTINGS_KEY("Size"))
, m_storeDialogSize(SETTINGS_KEY(u"Size"_qs))
{
m_ui->setupUi(this);
setAttribute(Qt::WA_DeleteOnClose);

View File

@@ -38,12 +38,12 @@
#include "ui_ipsubnetwhitelistoptionsdialog.h"
#include "utils.h"
#define SETTINGS_KEY(name) "IPSubnetWhitelistOptionsDialog/" name
#define SETTINGS_KEY(name) u"IPSubnetWhitelistOptionsDialog/" name
IPSubnetWhitelistOptionsDialog::IPSubnetWhitelistOptionsDialog(QWidget *parent)
: QDialog(parent)
, m_ui(new Ui::IPSubnetWhitelistOptionsDialog)
, m_storeDialogSize(SETTINGS_KEY("Size"))
, m_storeDialogSize(SETTINGS_KEY(u"Size"_qs))
{
m_ui->setupUi(this);

View File

@@ -104,9 +104,9 @@ using namespace std::chrono_literals;
namespace
{
#define SETTINGS_KEY(name) "GUI/" name
#define EXECUTIONLOG_SETTINGS_KEY(name) (SETTINGS_KEY("Log/") name)
#define NOTIFICATIONS_SETTINGS_KEY(name) (SETTINGS_KEY("Notifications/") name)
#define SETTINGS_KEY(name) u"GUI/" name
#define EXECUTIONLOG_SETTINGS_KEY(name) (SETTINGS_KEY(u"Log/"_qs) name)
#define NOTIFICATIONS_SETTINGS_KEY(name) (SETTINGS_KEY(u"Notifications/"_qs) name)
const std::chrono::seconds PREVENT_SUSPEND_INTERVAL {60};
#if !defined(Q_OS_MACOS)
@@ -125,13 +125,13 @@ namespace
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, m_ui(new Ui::MainWindow)
, m_storeExecutionLogEnabled(EXECUTIONLOG_SETTINGS_KEY("Enabled"))
, m_storeDownloadTrackerFavicon(SETTINGS_KEY("DownloadTrackerFavicon"))
, m_storeNotificationEnabled(NOTIFICATIONS_SETTINGS_KEY("Enabled"))
, m_storeNotificationTorrentAdded(NOTIFICATIONS_SETTINGS_KEY("TorrentAdded"))
, m_storeExecutionLogTypes(EXECUTIONLOG_SETTINGS_KEY("Types"), Log::MsgType::ALL)
, m_storeExecutionLogEnabled(EXECUTIONLOG_SETTINGS_KEY(u"Enabled"_qs))
, m_storeDownloadTrackerFavicon(SETTINGS_KEY(u"DownloadTrackerFavicon"_qs))
, m_storeNotificationEnabled(NOTIFICATIONS_SETTINGS_KEY(u"Enabled"_qs))
, m_storeNotificationTorrentAdded(NOTIFICATIONS_SETTINGS_KEY(u"TorrentAdded"_qs))
, m_storeExecutionLogTypes(EXECUTIONLOG_SETTINGS_KEY(u"Types"_qs), Log::MsgType::ALL)
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) && defined(QT_DBUS_LIB)
, m_storeNotificationTimeOut(NOTIFICATIONS_SETTINGS_KEY("Timeout"))
, m_storeNotificationTimeOut(NOTIFICATIONS_SETTINGS_KEY(u"Timeout"_qs))
#endif
{
m_ui->setupUi(this);
@@ -2148,7 +2148,7 @@ void MainWindow::pythonDownloadFinished(const Net::DownloadResult &result)
QProcess installer;
qDebug("Launching Python installer in passive mode...");
const Path exePath = result.filePath + ".exe";
const Path exePath = result.filePath + u".exe";
Utils::Fs::renameFile(result.filePath, exePath);
installer.start(exePath.toString(), {u"/passive"_qs});

View File

@@ -71,7 +71,7 @@
#include "watchedfolderoptionsdialog.h"
#include "watchedfoldersmodel.h"
#define SETTINGS_KEY(name) "OptionsDialog/" name
#define SETTINGS_KEY(name) u"OptionsDialog/" name
namespace
{
@@ -179,9 +179,9 @@ private:
OptionsDialog::OptionsDialog(QWidget *parent)
: QDialog {parent}
, m_ui {new Ui::OptionsDialog}
, m_storeDialogSize {SETTINGS_KEY("Size")}
, m_storeHSplitterSize {SETTINGS_KEY("HorizontalSplitterSizes")}
, m_storeLastViewedPage {SETTINGS_KEY("LastViewedPage")}
, m_storeDialogSize {SETTINGS_KEY(u"Size"_qs)}
, m_storeHSplitterSize {SETTINGS_KEY(u"HorizontalSplitterSizes"_qs)}
, m_storeLastViewedPage {SETTINGS_KEY(u"LastViewedPage"_qs)}
{
qDebug("-> Constructing Options");
m_ui->setupUi(this);

View File

@@ -46,17 +46,17 @@
#include "ui_previewselectdialog.h"
#include "utils.h"
#define SETTINGS_KEY(name) "PreviewSelectDialog/" name
#define SETTINGS_KEY(name) u"PreviewSelectDialog/" name
PreviewSelectDialog::PreviewSelectDialog(QWidget *parent, const BitTorrent::Torrent *torrent)
: QDialog(parent)
, m_ui(new Ui::PreviewSelectDialog)
, m_torrent(torrent)
, m_storeDialogSize(SETTINGS_KEY("Size"))
, m_storeDialogSize(SETTINGS_KEY(u"Size"_qs))
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
, m_storeTreeHeaderState("GUI/Qt6/" SETTINGS_KEY("HeaderState"))
, m_storeTreeHeaderState(u"GUI/Qt6/" SETTINGS_KEY(u"HeaderState"_qs))
#else
, m_storeTreeHeaderState(SETTINGS_KEY("HeaderState"))
, m_storeTreeHeaderState(SETTINGS_KEY(u"HeaderState"_qs))
#endif
{
m_ui->setupUi(this);

View File

@@ -48,7 +48,7 @@
#include "searchwidget.h"
#include "ui_pluginselectdialog.h"
#define SETTINGS_KEY(name) "SearchPluginSelectDialog/" name
#define SETTINGS_KEY(name) u"SearchPluginSelectDialog/" name
enum PluginColumns
{
@@ -62,7 +62,7 @@ enum PluginColumns
PluginSelectDialog::PluginSelectDialog(SearchPluginManager *pluginManager, QWidget *parent)
: QDialog(parent)
, m_ui(new Ui::PluginSelectDialog)
, m_storeDialogSize(SETTINGS_KEY("Size"))
, m_storeDialogSize(SETTINGS_KEY(u"Size"_qs))
, m_pluginManager(pluginManager)
{
m_ui->setupUi(this);

View File

@@ -31,12 +31,12 @@
#include "gui/utils.h"
#include "ui_pluginsourcedialog.h"
#define SETTINGS_KEY(name) "SearchPluginSourceDialog/" name
#define SETTINGS_KEY(name) u"SearchPluginSourceDialog/" name
PluginSourceDialog::PluginSourceDialog(QWidget *parent)
: QDialog(parent)
, m_ui(new Ui::PluginSourceDialog)
, m_storeDialogSize(SETTINGS_KEY("Size"))
, m_storeDialogSize(SETTINGS_KEY(u"Size"_qs))
{
m_ui->setupUi(this);
setAttribute(Qt::WA_DeleteOnClose);

View File

@@ -547,7 +547,7 @@ void SearchJobWidget::appendSearchResults(const QVector<SearchResult> &results)
SettingValue<SearchJobWidget::NameFilteringMode> &SearchJobWidget::nameFilteringModeSetting()
{
static SettingValue<NameFilteringMode> setting {"Search/FilteringMode"};
static SettingValue<NameFilteringMode> setting {u"Search/FilteringMode"_qs};
return setting;
}

View File

@@ -37,7 +37,7 @@
#include "uithememanager.h"
#include "utils.h"
#define SETTINGS_KEY(name) "SpeedLimitDialog/" name
#define SETTINGS_KEY(name) u"SpeedLimitDialog/" name
namespace
{
@@ -52,7 +52,7 @@ namespace
SpeedLimitDialog::SpeedLimitDialog(QWidget *parent)
: QDialog {parent}
, m_ui {new Ui::SpeedLimitDialog}
, m_storeDialogSize {SETTINGS_KEY("Size")}
, m_storeDialogSize {SETTINGS_KEY(u"Size"_qs)}
{
m_ui->setupUi(this);

View File

@@ -40,12 +40,12 @@
#include "ui_statsdialog.h"
#include "utils.h"
#define SETTINGS_KEY(name) "StatisticsDialog/" name
#define SETTINGS_KEY(name) u"StatisticsDialog/" name
StatsDialog::StatsDialog(QWidget *parent)
: QDialog(parent)
, m_ui(new Ui::StatsDialog)
, m_storeDialogSize(SETTINGS_KEY("Size"))
, m_storeDialogSize(SETTINGS_KEY(u"Size"_qs))
{
m_ui->setupUi(this);
setAttribute(Qt::WA_DeleteOnClose);

View File

@@ -42,29 +42,29 @@
#include "ui_torrentcreatordialog.h"
#include "utils.h"
#define SETTINGS_KEY(name) "TorrentCreator/" name
#define SETTINGS_KEY(name) u"TorrentCreator/" name
TorrentCreatorDialog::TorrentCreatorDialog(QWidget *parent, const Path &defaultPath)
: QDialog(parent)
, m_ui(new Ui::TorrentCreatorDialog)
, m_creatorThread(new BitTorrent::TorrentCreatorThread(this))
, m_storeDialogSize(SETTINGS_KEY("Size"))
, m_storePieceSize(SETTINGS_KEY("PieceSize"))
, m_storePrivateTorrent(SETTINGS_KEY("PrivateTorrent"))
, m_storeStartSeeding(SETTINGS_KEY("StartSeeding"))
, m_storeIgnoreRatio(SETTINGS_KEY("IgnoreRatio"))
, m_storeDialogSize(SETTINGS_KEY(u"Size"_qs))
, m_storePieceSize(SETTINGS_KEY(u"PieceSize"_qs))
, m_storePrivateTorrent(SETTINGS_KEY(u"PrivateTorrent"_qs))
, m_storeStartSeeding(SETTINGS_KEY(u"StartSeeding"_qs))
, m_storeIgnoreRatio(SETTINGS_KEY(u"IgnoreRatio"_qs))
#ifdef QBT_USES_LIBTORRENT2
, m_storeTorrentFormat(SETTINGS_KEY("TorrentFormat"))
, m_storeTorrentFormat(SETTINGS_KEY(u"TorrentFormat"_qs))
#else
, m_storeOptimizeAlignment(SETTINGS_KEY("OptimizeAlignment"))
, m_paddedFileSizeLimit(SETTINGS_KEY("PaddedFileSizeLimit"))
, m_storeOptimizeAlignment(SETTINGS_KEY(u"OptimizeAlignment"_qs))
, m_paddedFileSizeLimit(SETTINGS_KEY(u"PaddedFileSizeLimit"_qs))
#endif
, m_storeLastAddPath(SETTINGS_KEY("LastAddPath"))
, m_storeTrackerList(SETTINGS_KEY("TrackerList"))
, m_storeWebSeedList(SETTINGS_KEY("WebSeedList"))
, m_storeComments(SETTINGS_KEY("Comments"))
, m_storeLastSavePath(SETTINGS_KEY("LastSavePath"))
, m_storeSource(SETTINGS_KEY("Source"))
, m_storeLastAddPath(SETTINGS_KEY(u"LastAddPath"_qs))
, m_storeTrackerList(SETTINGS_KEY(u"TrackerList"_qs))
, m_storeWebSeedList(SETTINGS_KEY(u"WebSeedList"_qs))
, m_storeComments(SETTINGS_KEY(u"Comments"_qs))
, m_storeLastSavePath(SETTINGS_KEY(u"LastSavePath"_qs))
, m_storeSource(SETTINGS_KEY(u"Source"_qs))
{
m_ui->setupUi(this);
setAttribute(Qt::WA_DeleteOnClose);

View File

@@ -45,7 +45,7 @@
#include "ui_torrentoptionsdialog.h"
#include "utils.h"
#define SETTINGS_KEY(name) "TorrentOptionsDialog/" name
#define SETTINGS_KEY(name) u"TorrentOptionsDialog/" name
namespace
{
@@ -62,7 +62,7 @@ namespace
TorrentOptionsDialog::TorrentOptionsDialog(QWidget *parent, const QVector<BitTorrent::Torrent *> &torrents)
: QDialog {parent}
, m_ui {new Ui::TorrentOptionsDialog}
, m_storeDialogSize {SETTINGS_KEY("Size")}
, m_storeDialogSize {SETTINGS_KEY(u"Size"_qs)}
, m_currentCategoriesString {QString::fromLatin1("--%1--").arg(tr("Currently used categories"))}
{
Q_ASSERT(!torrents.empty());

View File

@@ -37,12 +37,12 @@
#include "ui_trackerentriesdialog.h"
#include "utils.h"
#define SETTINGS_KEY(name) "TrackerEntriesDialog/" name
#define SETTINGS_KEY(name) u"TrackerEntriesDialog/" name
TrackerEntriesDialog::TrackerEntriesDialog(QWidget *parent)
: QDialog(parent)
, m_ui(new Ui::TrackerEntriesDialog)
, m_storeDialogSize(SETTINGS_KEY("Size"))
, m_storeDialogSize(SETTINGS_KEY(u"Size"_qs))
{
m_ui->setupUi(this);

View File

@@ -93,8 +93,8 @@ namespace
TransferListSortModel::TransferListSortModel(QObject *parent)
: QSortFilterProxyModel {parent}
, m_subSortColumn {"TransferList/SubSortColumn", TransferListModel::TR_NAME, adjustSubSortColumn}
, m_subSortOrder {"TransferList/SubSortOrder", 0}
, m_subSortColumn {u"TransferList/SubSortColumn"_qs, TransferListModel::TR_NAME, adjustSubSortColumn}
, m_subSortOrder {u"TransferList/SubSortOrder"_qs, 0}
{
setSortRole(TransferListModel::UnderlyingDataRole);
}

View File

@@ -37,7 +37,7 @@
#include "ui_watchedfolderoptionsdialog.h"
#include "utils.h"
#define SETTINGS_KEY(name) "WatchedFolderOptionsDialog/" name
#define SETTINGS_KEY(name) u"WatchedFolderOptionsDialog/" name
WatchedFolderOptionsDialog::WatchedFolderOptionsDialog(
const TorrentFilesWatcher::WatchedFolderOptions &watchedFolderOptions, QWidget *parent)
@@ -45,7 +45,7 @@ WatchedFolderOptionsDialog::WatchedFolderOptionsDialog(
, m_ui {new Ui::WatchedFolderOptionsDialog}
, m_savePath {watchedFolderOptions.addTorrentParams.savePath}
, m_downloadPath {watchedFolderOptions.addTorrentParams.downloadPath}
, m_storeDialogSize {SETTINGS_KEY("DialogSize")}
, m_storeDialogSize {SETTINGS_KEY(u"DialogSize"_qs)}
{
m_ui->setupUi(this);