Browse Source

Merge pull request #14121 from Chocobo1/settingsStorage

Improve load data behavior of SettingsStorage class
adaptive-webui-19844
Mike Tzou 4 years ago committed by GitHub
parent
commit
586bdc0567
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      src/app/application.cpp
  2. 10
      src/app/upgrade.cpp
  3. 2
      src/base/bittorrent/portforwarderimpl.cpp
  4. 12
      src/base/net/proxyconfigurationmanager.cpp
  5. 6
      src/base/rss/rss_autodownloader.cpp
  6. 10
      src/base/rss/rss_session.cpp
  7. 13
      src/base/settingsstorage.cpp
  8. 40
      src/base/settingsstorage.h
  9. 16
      src/base/settingvalue.h
  10. 20
      src/gui/addnewtorrentdialog.cpp
  11. 4
      src/gui/cookiesdialog.cpp
  12. 10
      src/gui/mainwindow.cpp

16
src/app/application.cpp

@ -214,7 +214,7 @@ const QBtCommandLineParameters &Application::commandLineArgs() const
bool Application::isFileLoggerEnabled() const bool Application::isFileLoggerEnabled() const
{ {
return settings()->loadValue(KEY_FILELOGGER_ENABLED, true).toBool(); return settings()->loadValue(KEY_FILELOGGER_ENABLED, true);
} }
void Application::setFileLoggerEnabled(const bool value) void Application::setFileLoggerEnabled(const bool value)
@ -228,8 +228,8 @@ void Application::setFileLoggerEnabled(const bool value)
QString Application::fileLoggerPath() const QString Application::fileLoggerPath() const
{ {
return settings()->loadValue(KEY_FILELOGGER_PATH, return settings()->loadValue(KEY_FILELOGGER_PATH
{specialFolderLocation(SpecialFolder::Data) + LOG_FOLDER}).toString(); , QString {specialFolderLocation(SpecialFolder::Data) + LOG_FOLDER});
} }
void Application::setFileLoggerPath(const QString &path) void Application::setFileLoggerPath(const QString &path)
@ -241,7 +241,7 @@ void Application::setFileLoggerPath(const QString &path)
bool Application::isFileLoggerBackup() const bool Application::isFileLoggerBackup() const
{ {
return settings()->loadValue(KEY_FILELOGGER_BACKUP, true).toBool(); return settings()->loadValue(KEY_FILELOGGER_BACKUP, true);
} }
void Application::setFileLoggerBackup(const bool value) void Application::setFileLoggerBackup(const bool value)
@ -253,7 +253,7 @@ void Application::setFileLoggerBackup(const bool value)
bool Application::isFileLoggerDeleteOld() const bool Application::isFileLoggerDeleteOld() const
{ {
return settings()->loadValue(KEY_FILELOGGER_DELETEOLD, true).toBool(); return settings()->loadValue(KEY_FILELOGGER_DELETEOLD, true);
} }
void Application::setFileLoggerDeleteOld(const bool value) void Application::setFileLoggerDeleteOld(const bool value)
@ -265,7 +265,7 @@ void Application::setFileLoggerDeleteOld(const bool value)
int Application::fileLoggerMaxSize() const int Application::fileLoggerMaxSize() const
{ {
const int val = settings()->loadValue(KEY_FILELOGGER_MAXSIZEBYTES, DEFAULT_FILELOG_SIZE).toInt(); const int val = settings()->loadValue(KEY_FILELOGGER_MAXSIZEBYTES, DEFAULT_FILELOG_SIZE);
return std::min(std::max(val, MIN_FILELOG_SIZE), MAX_FILELOG_SIZE); return std::min(std::max(val, MIN_FILELOG_SIZE), MAX_FILELOG_SIZE);
} }
@ -279,7 +279,7 @@ void Application::setFileLoggerMaxSize(const int bytes)
int Application::fileLoggerAge() const int Application::fileLoggerAge() const
{ {
const int val = settings()->loadValue(KEY_FILELOGGER_AGE, 1).toInt(); const int val = settings()->loadValue(KEY_FILELOGGER_AGE, 1);
return std::min(std::max(val, 1), 365); return std::min(std::max(val, 1), 365);
} }
@ -290,7 +290,7 @@ void Application::setFileLoggerAge(const int value)
int Application::fileLoggerAgeType() const int Application::fileLoggerAgeType() const
{ {
const int val = settings()->loadValue(KEY_FILELOGGER_AGETYPE, 1).toInt(); const int val = settings()->loadValue(KEY_FILELOGGER_AGETYPE, 1);
return ((val < 0) || (val > 2)) ? 1 : val; return ((val < 0) || (val > 2)) ? 1 : val;
} }

10
src/app/upgrade.cpp

@ -46,8 +46,8 @@ namespace
const auto migrate = [](const QString &oldKey, const QString &newKey, const QString &savePath) const auto migrate = [](const QString &oldKey, const QString &newKey, const QString &savePath)
{ {
SettingsStorage *settingsStorage {SettingsStorage::instance()}; SettingsStorage *settingsStorage {SettingsStorage::instance()};
const QByteArray oldData {settingsStorage->loadValue(oldKey).toByteArray()}; const auto oldData {settingsStorage->loadValue<QByteArray>(oldKey)};
const QString newData {settingsStorage->loadValue(newKey).toString()}; const auto newData {settingsStorage->loadValue<QString>(newKey)};
const QString errorMsgFormat {QObject::tr("Migrate preferences failed: WebUI https, file: \"%1\", error: \"%2\"")}; const QString errorMsgFormat {QObject::tr("Migrate preferences failed: WebUI https, file: \"%1\", error: \"%2\"")};
if (!newData.isEmpty() || oldData.isEmpty()) if (!newData.isEmpty() || oldData.isEmpty())
@ -89,8 +89,8 @@ namespace
const QString newKey {QLatin1String {"BitTorrent/Session/TorrentContentLayout"}}; const QString newKey {QLatin1String {"BitTorrent/Session/TorrentContentLayout"}};
SettingsStorage *settingsStorage {SettingsStorage::instance()}; SettingsStorage *settingsStorage {SettingsStorage::instance()};
const QVariant oldData {settingsStorage->loadValue(oldKey)}; const auto oldData {settingsStorage->loadValue<QVariant>(oldKey)};
const QString newData {settingsStorage->loadValue(newKey).toString()}; const auto newData {settingsStorage->loadValue<QString>(newKey)};
if (!newData.isEmpty() || !oldData.isValid()) if (!newData.isEmpty() || !oldData.isValid())
return; return;
@ -128,7 +128,7 @@ void handleChangedDefaults(const DefaultPreferencesMode mode)
SettingsStorage *settingsStorage {SettingsStorage::instance()}; SettingsStorage *settingsStorage {SettingsStorage::instance()};
for (auto it = changedDefaults.cbegin(); it != changedDefaults.cend(); ++it) for (auto it = changedDefaults.cbegin(); it != changedDefaults.cend(); ++it)
{ {
if (settingsStorage->loadValue(it->name).isNull()) if (settingsStorage->loadValue<QVariant>(it->name).isNull())
settingsStorage->storeValue(it->name, (mode == DefaultPreferencesMode::Legacy ? it->legacy : it->current)); settingsStorage->storeValue(it->name, (mode == DefaultPreferencesMode::Legacy ? it->legacy : it->current));
} }
} }

2
src/base/bittorrent/portforwarderimpl.cpp

@ -39,7 +39,7 @@ const QString KEY_ENABLED = QStringLiteral("Network/PortForwardingEnabled");
PortForwarderImpl::PortForwarderImpl(lt::session *provider, QObject *parent) PortForwarderImpl::PortForwarderImpl(lt::session *provider, QObject *parent)
: Net::PortForwarder {parent} : Net::PortForwarder {parent}
, m_active {SettingsStorage::instance()->loadValue(KEY_ENABLED, true).toBool()} , m_active {SettingsStorage::instance()->loadValue(KEY_ENABLED, true)}
, m_provider {provider} , m_provider {provider}
{ {
if (m_active) if (m_active)

12
src/base/net/proxyconfigurationmanager.cpp

@ -64,15 +64,15 @@ ProxyConfigurationManager *ProxyConfigurationManager::m_instance = nullptr;
ProxyConfigurationManager::ProxyConfigurationManager(QObject *parent) ProxyConfigurationManager::ProxyConfigurationManager(QObject *parent)
: QObject(parent) : QObject(parent)
{ {
m_isProxyOnlyForTorrents = settings()->loadValue(KEY_ONLY_FOR_TORRENTS, false).toBool(); m_isProxyOnlyForTorrents = settings()->loadValue(KEY_ONLY_FOR_TORRENTS, false);
m_config.type = static_cast<ProxyType>( m_config.type = static_cast<ProxyType>(
settings()->loadValue(KEY_TYPE, static_cast<int>(ProxyType::None)).toInt()); settings()->loadValue(KEY_TYPE, static_cast<int>(ProxyType::None)));
if ((m_config.type < ProxyType::None) || (m_config.type > ProxyType::SOCKS4)) if ((m_config.type < ProxyType::None) || (m_config.type > ProxyType::SOCKS4))
m_config.type = ProxyType::None; m_config.type = ProxyType::None;
m_config.ip = settings()->loadValue(KEY_IP, "0.0.0.0").toString(); m_config.ip = settings()->loadValue<QString>(KEY_IP, "0.0.0.0");
m_config.port = static_cast<ushort>(settings()->loadValue(KEY_PORT, 8080).toUInt()); m_config.port = settings()->loadValue<ushort>(KEY_PORT, 8080);
m_config.username = settings()->loadValue(KEY_USERNAME).toString(); m_config.username = settings()->loadValue<QString>(KEY_USERNAME);
m_config.password = settings()->loadValue(KEY_PASSWORD).toString(); m_config.password = settings()->loadValue<QString>(KEY_PASSWORD);
configureProxy(); configureProxy();
} }

6
src/base/rss/rss_autodownloader.cpp

@ -105,7 +105,7 @@ QString computeSmartFilterRegex(const QStringList &filters)
} }
AutoDownloader::AutoDownloader() AutoDownloader::AutoDownloader()
: m_processingEnabled(SettingsStorage::instance()->loadValue(SettingsKey_ProcessingEnabled, false).toBool()) : m_processingEnabled(SettingsStorage::instance()->loadValue(SettingsKey_ProcessingEnabled, false))
, m_processingTimer(new QTimer(this)) , m_processingTimer(new QTimer(this))
, m_ioThread(new QThread(this)) , m_ioThread(new QThread(this))
{ {
@ -290,7 +290,7 @@ void AutoDownloader::importRulesFromLegacyFormat(const QByteArray &data)
QStringList AutoDownloader::smartEpisodeFilters() const QStringList AutoDownloader::smartEpisodeFilters() const
{ {
const QVariant filtersSetting = SettingsStorage::instance()->loadValue(SettingsKey_SmartEpisodeFilter); const auto filtersSetting = SettingsStorage::instance()->loadValue<QVariant>(SettingsKey_SmartEpisodeFilter);
if (filtersSetting.isNull()) if (filtersSetting.isNull())
{ {
@ -323,7 +323,7 @@ void AutoDownloader::setSmartEpisodeFilters(const QStringList &filters)
bool AutoDownloader::downloadRepacks() const bool AutoDownloader::downloadRepacks() const
{ {
return SettingsStorage::instance()->loadValue(SettingsKey_DownloadRepacks, true).toBool(); return SettingsStorage::instance()->loadValue(SettingsKey_DownloadRepacks, true);
} }
void AutoDownloader::setDownloadRepacks(const bool downloadRepacks) void AutoDownloader::setDownloadRepacks(const bool downloadRepacks)

10
src/base/rss/rss_session.cpp

@ -63,10 +63,10 @@ using namespace RSS;
QPointer<Session> Session::m_instance = nullptr; QPointer<Session> Session::m_instance = nullptr;
Session::Session() Session::Session()
: m_processingEnabled(SettingsStorage::instance()->loadValue(SettingsKey_ProcessingEnabled, false).toBool()) : m_processingEnabled(SettingsStorage::instance()->loadValue(SettingsKey_ProcessingEnabled, false))
, m_workingThread(new QThread(this)) , m_workingThread(new QThread(this))
, m_refreshInterval(SettingsStorage::instance()->loadValue(SettingsKey_RefreshInterval, 30).toInt()) , m_refreshInterval(SettingsStorage::instance()->loadValue(SettingsKey_RefreshInterval, 30))
, m_maxArticlesPerFeed(SettingsStorage::instance()->loadValue(SettingsKey_MaxArticlesPerFeed, 50).toInt()) , m_maxArticlesPerFeed(SettingsStorage::instance()->loadValue(SettingsKey_MaxArticlesPerFeed, 50))
{ {
Q_ASSERT(!m_instance); // only one instance is allowed Q_ASSERT(!m_instance); // only one instance is allowed
m_instance = this; m_instance = this;
@ -362,8 +362,8 @@ void Session::loadFolder(const QJsonObject &jsonObj, Folder *folder)
void Session::loadLegacy() void Session::loadLegacy()
{ {
const QStringList legacyFeedPaths = SettingsStorage::instance()->loadValue("Rss/streamList").toStringList(); const auto legacyFeedPaths = SettingsStorage::instance()->loadValue<QStringList>("Rss/streamList");
const QStringList feedAliases = SettingsStorage::instance()->loadValue("Rss/streamAlias").toStringList(); const auto feedAliases = SettingsStorage::instance()->loadValue<QStringList>("Rss/streamAlias");
if (legacyFeedPaths.size() != feedAliases.size()) if (legacyFeedPaths.size() != feedAliases.size())
{ {
Logger::instance()->addMessage("Corrupted RSS list, not loading it.", Log::WARNING); Logger::instance()->addMessage("Corrupted RSS list, not loading it.", Log::WARNING);

13
src/base/settingsstorage.cpp

@ -153,8 +153,7 @@ namespace
SettingsStorage *SettingsStorage::m_instance = nullptr; SettingsStorage *SettingsStorage::m_instance = nullptr;
SettingsStorage::SettingsStorage() SettingsStorage::SettingsStorage()
: m_data{TransactionalSettings(QLatin1String("qBittorrent")).read()} : m_data {TransactionalSettings(QLatin1String("qBittorrent")).read()}
, m_dirty(false)
{ {
m_timer.setSingleShot(true); m_timer.setSingleShot(true);
m_timer.setInterval(5 * 1000); m_timer.setInterval(5 * 1000);
@ -200,14 +199,14 @@ bool SettingsStorage::save()
return true; return true;
} }
QVariant SettingsStorage::loadValue(const QString &key, const QVariant &defaultValue) const QVariant SettingsStorage::loadValueImpl(const QString &key, const QVariant &defaultValue) const
{ {
const QString realKey = mapKey(key); const QString realKey = mapKey(key);
const QReadLocker locker(&m_lock); const QReadLocker locker(&m_lock);
return m_data.value(realKey, defaultValue); return m_data.value(realKey, defaultValue);
} }
void SettingsStorage::storeValue(const QString &key, const QVariant &value) void SettingsStorage::storeValueImpl(const QString &key, const QVariant &value)
{ {
const QString realKey = mapKey(key); const QString realKey = mapKey(key);
const QWriteLocker locker(&m_lock); const QWriteLocker locker(&m_lock);
@ -295,7 +294,11 @@ QString TransactionalSettings::deserialize(const QString &name, QVariantHash &da
// or that we don't touch directly in this code (eg disabled by ifdef). This ensures // or that we don't touch directly in this code (eg disabled by ifdef). This ensures
// that they will be copied over when save our settings to disk. // that they will be copied over when save our settings to disk.
for (const QString &key : asConst(settings->allKeys())) for (const QString &key : asConst(settings->allKeys()))
data.insert(key, settings->value(key)); {
const QVariant value = settings->value(key);
if (value.isValid())
data[key] = value;
}
return settings->fileName(); return settings->fileName();
} }

40
src/base/settingsstorage.h

@ -29,11 +29,15 @@
#pragma once #pragma once
#include <type_traits>
#include <QObject> #include <QObject>
#include <QReadWriteLock> #include <QReadWriteLock>
#include <QTimer> #include <QTimer>
#include <QVariantHash> #include <QVariantHash>
#include "utils/string.h"
class SettingsStorage : public QObject class SettingsStorage : public QObject
{ {
Q_OBJECT Q_OBJECT
@ -45,18 +49,48 @@ public:
static void freeInstance(); static void freeInstance();
static SettingsStorage *instance(); static SettingsStorage *instance();
QVariant loadValue(const QString &key, const QVariant &defaultValue = {}) const; template <typename T>
void storeValue(const QString &key, const QVariant &value); T loadValue(const QString &key, const T &defaultValue = {}) const
{
if constexpr (std::is_enum_v<T>)
{
const auto value = loadValueImpl(key).toString();
return Utils::String::toEnum(value, defaultValue);
}
else if constexpr (std::is_same_v<T, QVariant>)
{
return loadValueImpl(key, defaultValue);
}
else
{
const QVariant value = loadValueImpl(key);
// check if retrieved value is convertible to T
return value.template canConvert<T>() ? value.template value<T>() : defaultValue;
}
}
template <typename T>
void storeValue(const QString &key, const T &value)
{
if constexpr (std::is_enum_v<T>)
storeValueImpl(key, Utils::String::fromEnum(value));
else
storeValueImpl(key, value);
}
void removeValue(const QString &key); void removeValue(const QString &key);
public slots: public slots:
bool save(); bool save();
private: private:
QVariant loadValueImpl(const QString &key, const QVariant &defaultValue = {}) const;
void storeValueImpl(const QString &key, const QVariant &value);
static SettingsStorage *m_instance; static SettingsStorage *m_instance;
bool m_dirty = false;
QVariantHash m_data; QVariantHash m_data;
bool m_dirty;
QTimer m_timer; QTimer m_timer;
mutable QReadWriteLock m_lock; mutable QReadWriteLock m_lock;
}; };

16
src/base/settingvalue.h

@ -28,12 +28,9 @@
#pragma once #pragma once
#include <type_traits>
#include <QString> #include <QString>
#include "settingsstorage.h" #include "settingsstorage.h"
#include "utils/string.h"
// This is a thin/handy wrapper over `SettingsStorage`. Use it when store/load value // This is a thin/handy wrapper over `SettingsStorage`. Use it when store/load value
// rarely occurs, otherwise use `CachedSettingValue`. // rarely occurs, otherwise use `CachedSettingValue`.
@ -48,13 +45,7 @@ public:
T get(const T &defaultValue = {}) const T get(const T &defaultValue = {}) const
{ {
if constexpr (std::is_enum_v<T>) { return SettingsStorage::instance()->loadValue(m_keyName, defaultValue);
const auto value = SettingsStorage::instance()->loadValue(m_keyName, {}).toString();
return Utils::String::toEnum(value, defaultValue);
}
else {
return SettingsStorage::instance()->loadValue(m_keyName, defaultValue).template value<T>();
}
} }
operator T() const operator T() const
@ -64,10 +55,7 @@ public:
SettingValue<T> &operator=(const T &value) SettingValue<T> &operator=(const T &value)
{ {
if constexpr (std::is_enum_v<T>) SettingsStorage::instance()->storeValue(m_keyName, value);
SettingsStorage::instance()->storeValue(m_keyName, Utils::String::fromEnum(value));
else
SettingsStorage::instance()->storeValue(m_keyName, value);
return *this; return *this;
} }

20
src/gui/addnewtorrentdialog.cpp

@ -120,7 +120,7 @@ AddNewTorrentDialog::AddNewTorrentDialog(const BitTorrent::AddTorrentParams &inP
populateSavePathComboBox(); populateSavePathComboBox();
connect(m_ui->savePath, &FileSystemPathEdit::selectedPathChanged, this, &AddNewTorrentDialog::onSavePathChanged); connect(m_ui->savePath, &FileSystemPathEdit::selectedPathChanged, this, &AddNewTorrentDialog::onSavePathChanged);
const bool rememberLastSavePath = settings()->loadValue(KEY_REMEMBERLASTSAVEPATH, false).toBool(); const bool rememberLastSavePath = settings()->loadValue(KEY_REMEMBERLASTSAVEPATH, false);
m_ui->checkBoxRememberLastSavePath->setChecked(rememberLastSavePath); m_ui->checkBoxRememberLastSavePath->setChecked(rememberLastSavePath);
m_ui->contentLayoutComboBox->setCurrentIndex( m_ui->contentLayoutComboBox->setCurrentIndex(
@ -135,7 +135,7 @@ AddNewTorrentDialog::AddNewTorrentDialog(const BitTorrent::AddTorrentParams &inP
// Load categories // Load categories
QStringList categories = session->categories().keys(); QStringList categories = session->categories().keys();
std::sort(categories.begin(), categories.end(), Utils::String::naturalLessThan<Qt::CaseInsensitive>); std::sort(categories.begin(), categories.end(), Utils::String::naturalLessThan<Qt::CaseInsensitive>);
QString defaultCategory = settings()->loadValue(KEY_DEFAULTCATEGORY).toString(); auto defaultCategory = settings()->loadValue<QString>(KEY_DEFAULTCATEGORY);
if (!m_torrentParams.category.isEmpty()) if (!m_torrentParams.category.isEmpty())
m_ui->categoryComboBox->addItem(m_torrentParams.category); m_ui->categoryComboBox->addItem(m_torrentParams.category);
@ -170,7 +170,7 @@ AddNewTorrentDialog::~AddNewTorrentDialog()
bool AddNewTorrentDialog::isEnabled() bool AddNewTorrentDialog::isEnabled()
{ {
return SettingsStorage::instance()->loadValue(KEY_ENABLED, true).toBool(); return SettingsStorage::instance()->loadValue(KEY_ENABLED, true);
} }
void AddNewTorrentDialog::setEnabled(bool value) void AddNewTorrentDialog::setEnabled(bool value)
@ -180,7 +180,7 @@ void AddNewTorrentDialog::setEnabled(bool value)
bool AddNewTorrentDialog::isTopLevel() bool AddNewTorrentDialog::isTopLevel()
{ {
return SettingsStorage::instance()->loadValue(KEY_TOPLEVEL, true).toBool(); return SettingsStorage::instance()->loadValue(KEY_TOPLEVEL, true);
} }
void AddNewTorrentDialog::setTopLevel(bool value) void AddNewTorrentDialog::setTopLevel(bool value)
@ -191,7 +191,7 @@ void AddNewTorrentDialog::setTopLevel(bool value)
int AddNewTorrentDialog::savePathHistoryLength() int AddNewTorrentDialog::savePathHistoryLength()
{ {
const int defaultHistoryLength = 8; const int defaultHistoryLength = 8;
const int value = settings()->loadValue(KEY_SAVEPATHHISTORYLENGTH, defaultHistoryLength).toInt(); const int value = settings()->loadValue(KEY_SAVEPATHHISTORYLENGTH, defaultHistoryLength);
return qBound(minPathHistoryLength, value, maxPathHistoryLength); return qBound(minPathHistoryLength, value, maxPathHistoryLength);
} }
@ -204,14 +204,14 @@ void AddNewTorrentDialog::setSavePathHistoryLength(int value)
settings()->storeValue(KEY_SAVEPATHHISTORYLENGTH, clampedValue); settings()->storeValue(KEY_SAVEPATHHISTORYLENGTH, clampedValue);
settings()->storeValue(KEY_SAVEPATHHISTORY settings()->storeValue(KEY_SAVEPATHHISTORY
, QStringList(settings()->loadValue(KEY_SAVEPATHHISTORY).toStringList().mid(0, clampedValue))); , QStringList(settings()->loadValue<QStringList>(KEY_SAVEPATHHISTORY).mid(0, clampedValue)));
} }
void AddNewTorrentDialog::loadState() void AddNewTorrentDialog::loadState()
{ {
Utils::Gui::resize(this, m_storeDialogSize); Utils::Gui::resize(this, m_storeDialogSize);
m_ui->splitter->restoreState(m_storeSplitterState); m_ui->splitter->restoreState(m_storeSplitterState);
m_headerState = settings()->loadValue(KEY_TREEHEADERSTATE).toByteArray(); m_headerState = settings()->loadValue<QByteArray>(KEY_TREEHEADERSTATE);
} }
void AddNewTorrentDialog::saveState() void AddNewTorrentDialog::saveState()
@ -371,7 +371,7 @@ void AddNewTorrentDialog::showEvent(QShowEvent *event)
void AddNewTorrentDialog::saveSavePathHistory() const void AddNewTorrentDialog::saveSavePathHistory() const
{ {
// Get current history // Get current history
QStringList history = settings()->loadValue(KEY_SAVEPATHHISTORY).toStringList(); auto history = settings()->loadValue<QStringList>(KEY_SAVEPATHHISTORY);
QVector<QDir> historyDirs; QVector<QDir> historyDirs;
for (const QString &path : asConst(history)) for (const QString &path : asConst(history))
historyDirs << QDir {path}; historyDirs << QDir {path};
@ -489,11 +489,11 @@ void AddNewTorrentDialog::populateSavePathComboBox()
m_ui->savePath->clear(); m_ui->savePath->clear();
// Load save path history // Load save path history
const QStringList savePathHistory {settings()->loadValue(KEY_SAVEPATHHISTORY).toStringList()}; const auto savePathHistory {settings()->loadValue<QStringList>(KEY_SAVEPATHHISTORY)};
for (const QString &savePath : savePathHistory) for (const QString &savePath : savePathHistory)
m_ui->savePath->addItem(savePath); m_ui->savePath->addItem(savePath);
const bool rememberLastSavePath {settings()->loadValue(KEY_REMEMBERLASTSAVEPATH, false).toBool()}; const bool rememberLastSavePath {settings()->loadValue(KEY_REMEMBERLASTSAVEPATH, false)};
const QString defSavePath {BitTorrent::Session::instance()->defaultSavePath()}; const QString defSavePath {BitTorrent::Session::instance()->defaultSavePath()};
if (!m_torrentParams.savePath.isEmpty()) if (!m_torrentParams.savePath.isEmpty())

4
src/gui/cookiesdialog.cpp

@ -61,9 +61,9 @@ CookiesDialog::CookiesDialog(QWidget *parent)
m_cookiesModel->index(0, 0), m_cookiesModel->index(0, 0),
QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows); QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
Utils::Gui::resize(this, SettingsStorage::instance()->loadValue(KEY_SIZE).toSize()); Utils::Gui::resize(this, SettingsStorage::instance()->loadValue<QSize>(KEY_SIZE));
m_ui->treeView->header()->restoreState( m_ui->treeView->header()->restoreState(
SettingsStorage::instance()->loadValue(KEY_COOKIESVIEWSTATE).toByteArray()); SettingsStorage::instance()->loadValue<QByteArray>(KEY_COOKIESVIEWSTATE));
} }
CookiesDialog::~CookiesDialog() CookiesDialog::~CookiesDialog()

10
src/gui/mainwindow.cpp

@ -489,7 +489,7 @@ MainWindow::~MainWindow()
bool MainWindow::isExecutionLogEnabled() const bool MainWindow::isExecutionLogEnabled() const
{ {
return settings()->loadValue(KEY_EXECUTIONLOG_ENABLED, false).toBool(); return settings()->loadValue(KEY_EXECUTIONLOG_ENABLED, false);
} }
void MainWindow::setExecutionLogEnabled(bool value) void MainWindow::setExecutionLogEnabled(bool value)
@ -501,7 +501,7 @@ int MainWindow::executionLogMsgTypes() const
{ {
// as default value we need all the bits set // as default value we need all the bits set
// -1 is considered the portable way to achieve that // -1 is considered the portable way to achieve that
return settings()->loadValue(KEY_EXECUTIONLOG_TYPES, -1).toInt(); return settings()->loadValue(KEY_EXECUTIONLOG_TYPES, -1);
} }
void MainWindow::setExecutionLogMsgTypes(const int value) void MainWindow::setExecutionLogMsgTypes(const int value)
@ -512,7 +512,7 @@ void MainWindow::setExecutionLogMsgTypes(const int value)
bool MainWindow::isNotificationsEnabled() const bool MainWindow::isNotificationsEnabled() const
{ {
return settings()->loadValue(KEY_NOTIFICATIONS_ENABLED, true).toBool(); return settings()->loadValue(KEY_NOTIFICATIONS_ENABLED, true);
} }
void MainWindow::setNotificationsEnabled(bool value) void MainWindow::setNotificationsEnabled(bool value)
@ -522,7 +522,7 @@ void MainWindow::setNotificationsEnabled(bool value)
bool MainWindow::isTorrentAddedNotificationsEnabled() const bool MainWindow::isTorrentAddedNotificationsEnabled() const
{ {
return settings()->loadValue(KEY_NOTIFICATIONS_TORRENTADDED, false).toBool(); return settings()->loadValue(KEY_NOTIFICATIONS_TORRENTADDED, false);
} }
void MainWindow::setTorrentAddedNotificationsEnabled(bool value) void MainWindow::setTorrentAddedNotificationsEnabled(bool value)
@ -532,7 +532,7 @@ void MainWindow::setTorrentAddedNotificationsEnabled(bool value)
bool MainWindow::isDownloadTrackerFavicon() const bool MainWindow::isDownloadTrackerFavicon() const
{ {
return settings()->loadValue(KEY_DOWNLOAD_TRACKER_FAVICON, false).toBool(); return settings()->loadValue(KEY_DOWNLOAD_TRACKER_FAVICON, false);
} }
void MainWindow::setDownloadTrackerFavicon(bool value) void MainWindow::setDownloadTrackerFavicon(bool value)

Loading…
Cancel
Save