Browse Source

Migrate away from low-level `SettingsStorage` class

Also add `QFlags<T>` support to `SettingsStorage`.
PR #15693.
adaptive-webui-19844
Chocobo1 3 years ago committed by GitHub
parent
commit
32698fe0be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 52
      src/app/application.cpp
  2. 17
      src/app/application.h
  3. 14
      src/base/bittorrent/portforwarderimpl.cpp
  4. 3
      src/base/bittorrent/portforwarderimpl.h
  5. 59
      src/base/net/proxyconfigurationmanager.cpp
  6. 14
      src/base/net/proxyconfigurationmanager.h
  7. 45
      src/base/rss/rss_autodownloader.cpp
  8. 8
      src/base/rss/rss_autodownloader.h
  9. 47
      src/base/rss/rss_session.cpp
  10. 7
      src/base/rss/rss_session.h
  11. 13
      src/base/settingsstorage.h
  12. 45
      src/gui/addnewtorrentdialog.cpp
  13. 12
      src/gui/addnewtorrentdialog.h
  14. 108
      src/gui/mainwindow.cpp
  15. 24
      src/gui/mainwindow.h
  16. 1
      src/gui/watchedfolderoptionsdialog.cpp

52
src/app/application.cpp

@ -100,22 +100,10 @@ @@ -100,22 +100,10 @@
namespace
{
#define SETTINGS_KEY(name) "Application/" name
// FileLogger properties keys
#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");
const QString KEY_FILELOGGER_DELETEOLD = FILELOGGER_SETTINGS_KEY("DeleteOld");
const QString KEY_FILELOGGER_MAXSIZEBYTES = FILELOGGER_SETTINGS_KEY("MaxSizeBytes");
const QString KEY_FILELOGGER_AGE = FILELOGGER_SETTINGS_KEY("Age");
const QString KEY_FILELOGGER_AGETYPE = FILELOGGER_SETTINGS_KEY("AgeType");
// just a shortcut
inline SettingsStorage *settings() { return SettingsStorage::instance(); }
#define FILELOGGER_SETTINGS_KEY(name) (SETTINGS_KEY("FileLogger/") name)
const QString LOG_FOLDER = QStringLiteral("logs");
const QChar PARAMS_SEPARATOR = '|';
const QChar PARAMS_SEPARATOR = QLatin1Char('|');
const QString DEFAULT_PORTABLE_MODE_PROFILE_DIR = QStringLiteral("profile");
@ -133,6 +121,13 @@ Application::Application(int &argc, char **argv) @@ -133,6 +121,13 @@ Application::Application(int &argc, char **argv)
, m_running(false)
, m_shutdownAct(ShutdownDialogAction::Exit)
, m_commandLineArgs(parseCommandLine(this->arguments()))
, m_storeFileLoggerEnabled(FILELOGGER_SETTINGS_KEY("Enabled"))
, m_storeFileLoggerBackup(FILELOGGER_SETTINGS_KEY("Backup"))
, m_storeFileLoggerDeleteOld(FILELOGGER_SETTINGS_KEY("DeleteOld"))
, m_storeFileLoggerMaxSize(FILELOGGER_SETTINGS_KEY("MaxSizeBytes"))
, m_storeFileLoggerAge(FILELOGGER_SETTINGS_KEY("Age"))
, m_storeFileLoggerAgeType(FILELOGGER_SETTINGS_KEY("AgeType"))
, m_storeFileLoggerPath(FILELOGGER_SETTINGS_KEY("Path"))
{
qRegisterMetaType<Log::Msg>("Log::Msg");
qRegisterMetaType<Log::Peer>("Log::Peer");
@ -211,7 +206,7 @@ const QBtCommandLineParameters &Application::commandLineArgs() const @@ -211,7 +206,7 @@ const QBtCommandLineParameters &Application::commandLineArgs() const
bool Application::isFileLoggerEnabled() const
{
return settings()->loadValue(KEY_FILELOGGER_ENABLED, true);
return m_storeFileLoggerEnabled.get(true);
}
void Application::setFileLoggerEnabled(const bool value)
@ -220,49 +215,48 @@ void Application::setFileLoggerEnabled(const bool value) @@ -220,49 +215,48 @@ void Application::setFileLoggerEnabled(const bool value)
m_fileLogger = new FileLogger(fileLoggerPath(), isFileLoggerBackup(), fileLoggerMaxSize(), isFileLoggerDeleteOld(), fileLoggerAge(), static_cast<FileLogger::FileLogAgeType>(fileLoggerAgeType()));
else if (!value)
delete m_fileLogger;
settings()->storeValue(KEY_FILELOGGER_ENABLED, value);
m_storeFileLoggerEnabled = value;
}
QString Application::fileLoggerPath() const
{
return settings()->loadValue(KEY_FILELOGGER_PATH
, QString {specialFolderLocation(SpecialFolder::Data) + LOG_FOLDER});
return m_storeFileLoggerPath.get(specialFolderLocation(SpecialFolder::Data) + LOG_FOLDER);
}
void Application::setFileLoggerPath(const QString &path)
{
if (m_fileLogger)
m_fileLogger->changePath(path);
settings()->storeValue(KEY_FILELOGGER_PATH, path);
m_storeFileLoggerPath = path;
}
bool Application::isFileLoggerBackup() const
{
return settings()->loadValue(KEY_FILELOGGER_BACKUP, true);
return m_storeFileLoggerBackup.get(true);
}
void Application::setFileLoggerBackup(const bool value)
{
if (m_fileLogger)
m_fileLogger->setBackup(value);
settings()->storeValue(KEY_FILELOGGER_BACKUP, value);
m_storeFileLoggerBackup = value;
}
bool Application::isFileLoggerDeleteOld() const
{
return settings()->loadValue(KEY_FILELOGGER_DELETEOLD, true);
return m_storeFileLoggerDeleteOld.get(true);
}
void Application::setFileLoggerDeleteOld(const bool value)
{
if (value && m_fileLogger)
m_fileLogger->deleteOld(fileLoggerAge(), static_cast<FileLogger::FileLogAgeType>(fileLoggerAgeType()));
settings()->storeValue(KEY_FILELOGGER_DELETEOLD, value);
m_storeFileLoggerDeleteOld = value;
}
int Application::fileLoggerMaxSize() const
{
const int val = settings()->loadValue(KEY_FILELOGGER_MAXSIZEBYTES, DEFAULT_FILELOG_SIZE);
const int val = m_storeFileLoggerMaxSize.get(DEFAULT_FILELOG_SIZE);
return std::min(std::max(val, MIN_FILELOG_SIZE), MAX_FILELOG_SIZE);
}
@ -271,29 +265,29 @@ void Application::setFileLoggerMaxSize(const int bytes) @@ -271,29 +265,29 @@ void Application::setFileLoggerMaxSize(const int bytes)
const int clampedValue = std::min(std::max(bytes, MIN_FILELOG_SIZE), MAX_FILELOG_SIZE);
if (m_fileLogger)
m_fileLogger->setMaxSize(clampedValue);
settings()->storeValue(KEY_FILELOGGER_MAXSIZEBYTES, clampedValue);
m_storeFileLoggerMaxSize = clampedValue;
}
int Application::fileLoggerAge() const
{
const int val = settings()->loadValue(KEY_FILELOGGER_AGE, 1);
const int val = m_storeFileLoggerAge.get(1);
return std::min(std::max(val, 1), 365);
}
void Application::setFileLoggerAge(const int value)
{
settings()->storeValue(KEY_FILELOGGER_AGE, std::min(std::max(value, 1), 365));
m_storeFileLoggerAge = std::min(std::max(value, 1), 365);
}
int Application::fileLoggerAgeType() const
{
const int val = settings()->loadValue(KEY_FILELOGGER_AGETYPE, 1);
const int val = m_storeFileLoggerAgeType.get(1);
return ((val < 0) || (val > 2)) ? 1 : val;
}
void Application::setFileLoggerAgeType(const int value)
{
settings()->storeValue(KEY_FILELOGGER_AGETYPE, ((value < 0) || (value > 2)) ? 1 : value);
m_storeFileLoggerAgeType = ((value < 0) || (value > 2)) ? 1 : value;
}
void Application::processMessage(const QString &message)

17
src/app/application.h

@ -47,6 +47,7 @@ class QSessionManager; @@ -47,6 +47,7 @@ class QSessionManager;
using BaseApplication = QCoreApplication;
#endif // DISABLE_GUI
#include "base/settingvalue.h"
#include "base/types.h"
#include "cmdoptions.h"
@ -120,6 +121,11 @@ private slots: @@ -120,6 +121,11 @@ private slots:
#endif
private:
void initializeTranslation();
void processParams(const QStringList &params);
void runExternalProgram(const BitTorrent::Torrent *torrent) const;
void sendNotificationEmail(const BitTorrent::Torrent *torrent);
ApplicationInstanceManager *m_instanceManager = nullptr;
bool m_running;
ShutdownDialogAction m_shutdownAct;
@ -140,8 +146,11 @@ private: @@ -140,8 +146,11 @@ private:
QTranslator m_translator;
QStringList m_paramsQueue;
void initializeTranslation();
void processParams(const QStringList &params);
void runExternalProgram(const BitTorrent::Torrent *torrent) const;
void sendNotificationEmail(const BitTorrent::Torrent *torrent);
SettingValue<bool> m_storeFileLoggerEnabled;
SettingValue<bool> m_storeFileLoggerBackup;
SettingValue<bool> m_storeFileLoggerDeleteOld;
SettingValue<int> m_storeFileLoggerMaxSize;
SettingValue<int> m_storeFileLoggerAge;
SettingValue<int> m_storeFileLoggerAgeType;
SettingValue<QString> m_storeFileLoggerPath;
};

14
src/base/bittorrent/portforwarderimpl.cpp

@ -33,16 +33,13 @@ @@ -33,16 +33,13 @@
#include <QDebug>
#include "base/logger.h"
#include "base/settingsstorage.h"
const QString KEY_ENABLED = QStringLiteral("Network/PortForwardingEnabled");
PortForwarderImpl::PortForwarderImpl(lt::session *provider, QObject *parent)
: Net::PortForwarder {parent}
, m_active {SettingsStorage::instance()->loadValue(KEY_ENABLED, true)}
, m_storeActive {"Network/PortForwardingEnabled", true}
, m_provider {provider}
{
if (m_active)
if (isEnabled())
start();
}
@ -53,20 +50,19 @@ PortForwarderImpl::~PortForwarderImpl() @@ -53,20 +50,19 @@ PortForwarderImpl::~PortForwarderImpl()
bool PortForwarderImpl::isEnabled() const
{
return m_active;
return m_storeActive;
}
void PortForwarderImpl::setEnabled(const bool enabled)
{
if (m_active != enabled)
if (m_storeActive != enabled)
{
if (enabled)
start();
else
stop();
m_active = enabled;
SettingsStorage::instance()->storeValue(KEY_ENABLED, enabled);
m_storeActive = enabled;
}
}

3
src/base/bittorrent/portforwarderimpl.h

@ -36,6 +36,7 @@ @@ -36,6 +36,7 @@
#include <QHash>
#include "base/net/portforwarder.h"
#include "base/settingvalue.h"
class PortForwarderImpl final : public Net::PortForwarder
{
@ -56,7 +57,7 @@ private: @@ -56,7 +57,7 @@ private:
void start();
void stop();
bool m_active;
CachedSettingValue<bool> m_storeActive;
lt::session *m_provider;
QHash<quint16, std::vector<lt::port_mapping_t>> m_mappedPorts;
};

59
src/base/net/proxyconfigurationmanager.cpp

@ -28,20 +28,7 @@ @@ -28,20 +28,7 @@
#include "proxyconfigurationmanager.h"
#include "base/settingsstorage.h"
#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");
const QString KEY_PORT = SETTINGS_KEY("Port");
const QString KEY_USERNAME = SETTINGS_KEY("Username");
const QString KEY_PASSWORD = SETTINGS_KEY("Password");
namespace
{
inline SettingsStorage *settings() { return SettingsStorage::instance(); }
}
#define SETTINGS_KEY(name) ("Network/Proxy/" name)
bool Net::operator==(const ProxyConfiguration &left, const ProxyConfiguration &right)
{
@ -62,17 +49,21 @@ using namespace Net; @@ -62,17 +49,21 @@ using namespace Net;
ProxyConfigurationManager *ProxyConfigurationManager::m_instance = nullptr;
ProxyConfigurationManager::ProxyConfigurationManager(QObject *parent)
: QObject(parent)
: QObject {parent}
, m_storeProxyOnlyForTorrents {SETTINGS_KEY("OnlyForTorrents")}
, m_storeProxyType {SETTINGS_KEY("Type")}
, m_storeProxyIP {SETTINGS_KEY("IP")}
, m_storeProxyPort {SETTINGS_KEY("Port")}
, m_storeProxyUsername {SETTINGS_KEY("Username")}
, m_storeProxyPassword {SETTINGS_KEY("Password")}
{
m_isProxyOnlyForTorrents = settings()->loadValue(KEY_ONLY_FOR_TORRENTS, false);
m_config.type = static_cast<ProxyType>(
settings()->loadValue(KEY_TYPE, static_cast<int>(ProxyType::None)));
m_config.type = m_storeProxyType.get(ProxyType::None);
if ((m_config.type < ProxyType::None) || (m_config.type > ProxyType::SOCKS4))
m_config.type = ProxyType::None;
m_config.ip = settings()->loadValue<QString>(KEY_IP, "0.0.0.0");
m_config.port = settings()->loadValue<ushort>(KEY_PORT, 8080);
m_config.username = settings()->loadValue<QString>(KEY_USERNAME);
m_config.password = settings()->loadValue<QString>(KEY_PASSWORD);
m_config.ip = m_storeProxyIP.get(QLatin1String("0.0.0.0"));
m_config.port = m_storeProxyPort.get(8080);
m_config.username = m_storeProxyUsername;
m_config.password = m_storeProxyPassword;
configureProxy();
}
@ -100,14 +91,14 @@ ProxyConfiguration ProxyConfigurationManager::proxyConfiguration() const @@ -100,14 +91,14 @@ ProxyConfiguration ProxyConfigurationManager::proxyConfiguration() const
void ProxyConfigurationManager::setProxyConfiguration(const ProxyConfiguration &config)
{
if (config != m_config)
if (m_config != config)
{
m_config = config;
settings()->storeValue(KEY_TYPE, static_cast<int>(config.type));
settings()->storeValue(KEY_IP, config.ip);
settings()->storeValue(KEY_PORT, config.port);
settings()->storeValue(KEY_USERNAME, config.username);
settings()->storeValue(KEY_PASSWORD, config.password);
m_storeProxyType = config.type;
m_storeProxyIP = config.ip;
m_storeProxyPort = config.port;
m_storeProxyUsername = config.username;
m_storeProxyPassword = config.password;
configureProxy();
emit proxyConfigurationChanged();
@ -116,16 +107,12 @@ void ProxyConfigurationManager::setProxyConfiguration(const ProxyConfiguration & @@ -116,16 +107,12 @@ void ProxyConfigurationManager::setProxyConfiguration(const ProxyConfiguration &
bool ProxyConfigurationManager::isProxyOnlyForTorrents() const
{
return m_isProxyOnlyForTorrents || (m_config.type == ProxyType::SOCKS4);
return m_storeProxyOnlyForTorrents || (m_config.type == ProxyType::SOCKS4);
}
void ProxyConfigurationManager::setProxyOnlyForTorrents(bool onlyForTorrents)
void ProxyConfigurationManager::setProxyOnlyForTorrents(const bool onlyForTorrents)
{
if (m_isProxyOnlyForTorrents != onlyForTorrents)
{
settings()->storeValue(KEY_ONLY_FOR_TORRENTS, onlyForTorrents);
m_isProxyOnlyForTorrents = onlyForTorrents;
}
m_storeProxyOnlyForTorrents = onlyForTorrents;
}
bool ProxyConfigurationManager::isAuthenticationRequired() const
@ -138,7 +125,7 @@ void ProxyConfigurationManager::configureProxy() @@ -138,7 +125,7 @@ void ProxyConfigurationManager::configureProxy()
{
// Define environment variables for urllib in search engine plugins
QString proxyStrHTTP, proxyStrSOCK;
if (!m_isProxyOnlyForTorrents)
if (!isProxyOnlyForTorrents())
{
switch (m_config.type)
{

14
src/base/net/proxyconfigurationmanager.h

@ -30,8 +30,12 @@ @@ -30,8 +30,12 @@
#include <QObject>
#include "base/settingvalue.h"
namespace Net
{
Q_NAMESPACE
enum class ProxyType
{
None = 0,
@ -41,6 +45,7 @@ namespace Net @@ -41,6 +45,7 @@ namespace Net
SOCKS5_PW = 4,
SOCKS4 = 5
};
Q_ENUM_NS(ProxyType)
struct ProxyConfiguration
{
@ -53,7 +58,7 @@ namespace Net @@ -53,7 +58,7 @@ namespace Net
bool operator==(const ProxyConfiguration &left, const ProxyConfiguration &right);
bool operator!=(const ProxyConfiguration &left, const ProxyConfiguration &right);
class ProxyConfigurationManager : public QObject
class ProxyConfigurationManager final : public QObject
{
Q_OBJECT
Q_DISABLE_COPY_MOVE(ProxyConfigurationManager)
@ -81,6 +86,11 @@ namespace Net @@ -81,6 +86,11 @@ namespace Net
static ProxyConfigurationManager *m_instance;
ProxyConfiguration m_config;
bool m_isProxyOnlyForTorrents;
SettingValue<bool> m_storeProxyOnlyForTorrents;
SettingValue<ProxyType> m_storeProxyType;
SettingValue<QString> m_storeProxyIP;
SettingValue<ushort> m_storeProxyPort;
SettingValue<QString> m_storeProxyUsername;
SettingValue<QString> m_storeProxyPassword;
};
}

45
src/base/rss/rss_autodownloader.cpp

@ -45,7 +45,6 @@ @@ -45,7 +45,6 @@
#include "../global.h"
#include "../logger.h"
#include "../profile.h"
#include "../settingsstorage.h"
#include "../utils/fs.h"
#include "rss_article.h"
#include "rss_autodownloadrule.h"
@ -62,10 +61,6 @@ struct ProcessingJob @@ -62,10 +61,6 @@ struct ProcessingJob
const QString ConfFolderName(QStringLiteral("rss"));
const QString RulesFileName(QStringLiteral("download_rules.json"));
const QString SettingsKey_ProcessingEnabled(QStringLiteral("RSS/AutoDownloader/EnableProcessing"));
const QString SettingsKey_SmartEpisodeFilter(QStringLiteral("RSS/AutoDownloader/SmartEpisodeFilter"));
const QString SettingsKey_DownloadRepacks(QStringLiteral("RSS/AutoDownloader/DownloadRepacks"));
namespace
{
QVector<RSS::AutoDownloadRule> rulesFromJSON(const QByteArray &jsonData)
@ -103,7 +98,9 @@ QString computeSmartFilterRegex(const QStringList &filters) @@ -103,7 +98,9 @@ QString computeSmartFilterRegex(const QStringList &filters)
}
AutoDownloader::AutoDownloader()
: m_processingEnabled(SettingsStorage::instance()->loadValue(SettingsKey_ProcessingEnabled, false))
: m_storeProcessingEnabled("RSS/AutoDownloader/EnableProcessing", false)
, m_storeSmartEpisodeFilter("RSS/AutoDownloader/SmartEpisodeFilter")
, m_storeDownloadRepacks("RSS/AutoDownloader/DownloadRepacks")
, m_processingTimer(new QTimer(this))
, m_ioThread(new QThread(this))
{
@ -142,7 +139,7 @@ AutoDownloader::AutoDownloader() @@ -142,7 +139,7 @@ AutoDownloader::AutoDownloader()
m_processingTimer->setSingleShot(true);
connect(m_processingTimer, &QTimer::timeout, this, &AutoDownloader::process);
if (m_processingEnabled)
if (isProcessingEnabled())
startProcessing();
}
@ -288,22 +285,19 @@ void AutoDownloader::importRulesFromLegacyFormat(const QByteArray &data) @@ -288,22 +285,19 @@ void AutoDownloader::importRulesFromLegacyFormat(const QByteArray &data)
QStringList AutoDownloader::smartEpisodeFilters() const
{
const auto filtersSetting = SettingsStorage::instance()->loadValue<QVariant>(SettingsKey_SmartEpisodeFilter);
if (filtersSetting.isNull())
const QVariant filter = m_storeSmartEpisodeFilter.get();
if (filter.isNull())
{
QStringList filters =
const QStringList defaultFilters =
{
"s(\\d+)e(\\d+)", // Format 1: s01e01
"(\\d+)x(\\d+)", // Format 2: 01x01
"(\\d{4}[.\\-]\\d{1,2}[.\\-]\\d{1,2})", // Format 3: 2017.01.01
"(\\d{1,2}[.\\-]\\d{1,2}[.\\-]\\d{4})" // Format 4: 01.01.2017
};
return filters;
return defaultFilters;
}
return filtersSetting.toStringList();
return filter.toStringList();
}
QRegularExpression AutoDownloader::smartEpisodeRegex() const
@ -313,7 +307,7 @@ QRegularExpression AutoDownloader::smartEpisodeRegex() const @@ -313,7 +307,7 @@ QRegularExpression AutoDownloader::smartEpisodeRegex() const
void AutoDownloader::setSmartEpisodeFilters(const QStringList &filters)
{
SettingsStorage::instance()->storeValue(SettingsKey_SmartEpisodeFilter, filters);
m_storeSmartEpisodeFilter = filters;
const QString regex = computeSmartFilterRegex(filters);
m_smartEpisodeRegex.setPattern(regex);
@ -321,12 +315,12 @@ void AutoDownloader::setSmartEpisodeFilters(const QStringList &filters) @@ -321,12 +315,12 @@ void AutoDownloader::setSmartEpisodeFilters(const QStringList &filters)
bool AutoDownloader::downloadRepacks() const
{
return SettingsStorage::instance()->loadValue(SettingsKey_DownloadRepacks, true);
return m_storeDownloadRepacks.get(true);
}
void AutoDownloader::setDownloadRepacks(const bool downloadRepacks)
void AutoDownloader::setDownloadRepacks(const bool enabled)
{
SettingsStorage::instance()->storeValue(SettingsKey_DownloadRepacks, downloadRepacks);
m_storeDownloadRepacks = enabled;
}
void AutoDownloader::process()
@ -480,13 +474,13 @@ void AutoDownloader::storeDeferred() @@ -480,13 +474,13 @@ void AutoDownloader::storeDeferred()
bool AutoDownloader::isProcessingEnabled() const
{
return m_processingEnabled;
return m_storeProcessingEnabled;
}
void AutoDownloader::resetProcessingQueue()
{
m_processingQueue.clear();
if (!m_processingEnabled) return;
if (!isProcessingEnabled()) return;
for (Article *article : asConst(Session::instance()->rootFolder()->articles()))
{
@ -503,11 +497,10 @@ void AutoDownloader::startProcessing() @@ -503,11 +497,10 @@ void AutoDownloader::startProcessing()
void AutoDownloader::setProcessingEnabled(const bool enabled)
{
if (m_processingEnabled != enabled)
if (m_storeProcessingEnabled != enabled)
{
m_processingEnabled = enabled;
SettingsStorage::instance()->storeValue(SettingsKey_ProcessingEnabled, m_processingEnabled);
if (m_processingEnabled)
m_storeProcessingEnabled = enabled;
if (enabled)
{
startProcessing();
}
@ -517,7 +510,7 @@ void AutoDownloader::setProcessingEnabled(const bool enabled) @@ -517,7 +510,7 @@ void AutoDownloader::setProcessingEnabled(const bool enabled)
disconnect(Session::instance()->rootFolder(), &Folder::newArticle, this, &AutoDownloader::handleNewArticle);
}
emit processingStateChanged(m_processingEnabled);
emit processingStateChanged(enabled);
}
}

8
src/base/rss/rss_autodownloader.h

@ -37,6 +37,7 @@ @@ -37,6 +37,7 @@
#include <QSharedPointer>
#include "base/exceptions.h"
#include "base/settingvalue.h"
class QThread;
class QTimer;
@ -86,7 +87,7 @@ namespace RSS @@ -86,7 +87,7 @@ namespace RSS
QRegularExpression smartEpisodeRegex() const;
bool downloadRepacks() const;
void setDownloadRepacks(bool downloadRepacks);
void setDownloadRepacks(bool enabled);
bool hasRule(const QString &ruleName) const;
AutoDownloadRule ruleByName(const QString &ruleName) const;
@ -131,7 +132,10 @@ namespace RSS @@ -131,7 +132,10 @@ namespace RSS
static QPointer<AutoDownloader> m_instance;
bool m_processingEnabled;
CachedSettingValue<bool> m_storeProcessingEnabled;
SettingValue<QVariant> m_storeSmartEpisodeFilter;
SettingValue<bool> m_storeDownloadRepacks;
QTimer *m_processingTimer;
QThread *m_ioThread;
AsyncFileStorage *m_fileStorage;

47
src/base/rss/rss_session.cpp

@ -53,19 +53,15 @@ const QString ConfFolderName(QStringLiteral("rss")); @@ -53,19 +53,15 @@ const QString ConfFolderName(QStringLiteral("rss"));
const QString DataFolderName(QStringLiteral("rss/articles"));
const QString FeedsFileName(QStringLiteral("feeds.json"));
const QString SettingsKey_ProcessingEnabled(QStringLiteral("RSS/Session/EnableProcessing"));
const QString SettingsKey_RefreshInterval(QStringLiteral("RSS/Session/RefreshInterval"));
const QString SettingsKey_MaxArticlesPerFeed(QStringLiteral("RSS/Session/MaxArticlesPerFeed"));
using namespace RSS;
QPointer<Session> Session::m_instance = nullptr;
Session::Session()
: m_processingEnabled(SettingsStorage::instance()->loadValue(SettingsKey_ProcessingEnabled, false))
: m_storeProcessingEnabled("RSS/Session/EnableProcessing")
, m_storeRefreshInterval("RSS/Session/RefreshInterval", 30)
, m_storeMaxArticlesPerFeed("RSS/Session/MaxArticlesPerFeed", 50)
, m_workingThread(new QThread(this))
, m_refreshInterval(SettingsStorage::instance()->loadValue(SettingsKey_RefreshInterval, 30))
, m_maxArticlesPerFeed(SettingsStorage::instance()->loadValue(SettingsKey_MaxArticlesPerFeed, 50))
{
Q_ASSERT(!m_instance); // only one instance is allowed
m_instance = this;
@ -96,9 +92,9 @@ Session::Session() @@ -96,9 +92,9 @@ Session::Session()
load();
connect(&m_refreshTimer, &QTimer::timeout, this, &Session::refresh);
if (m_processingEnabled)
if (isProcessingEnabled())
{
m_refreshTimer.start(m_refreshInterval * MsecsPerMin);
m_refreshTimer.start(refreshInterval() * MsecsPerMin);
refresh();
}
@ -166,7 +162,7 @@ nonstd::expected<void, QString> Session::addFeed(const QString &url, const QStri @@ -166,7 +162,7 @@ nonstd::expected<void, QString> Session::addFeed(const QString &url, const QStri
const auto destFolder = result.value();
addItem(new Feed(generateUID(), url, path, this), destFolder);
store();
if (m_processingEnabled)
if (isProcessingEnabled())
feedByURL(url)->refresh();
return {};
@ -429,18 +425,17 @@ void Session::addItem(Item *item, Folder *destFolder) @@ -429,18 +425,17 @@ void Session::addItem(Item *item, Folder *destFolder)
bool Session::isProcessingEnabled() const
{
return m_processingEnabled;
return m_storeProcessingEnabled;
}
void Session::setProcessingEnabled(bool enabled)
void Session::setProcessingEnabled(const bool enabled)
{
if (m_processingEnabled != enabled)
if (m_storeProcessingEnabled != enabled)
{
m_processingEnabled = enabled;
SettingsStorage::instance()->storeValue(SettingsKey_ProcessingEnabled, m_processingEnabled);
if (m_processingEnabled)
m_storeProcessingEnabled = enabled;
if (enabled)
{
m_refreshTimer.start(m_refreshInterval * MsecsPerMin);
m_refreshTimer.start(refreshInterval() * MsecsPerMin);
refresh();
}
else
@ -448,7 +443,7 @@ void Session::setProcessingEnabled(bool enabled) @@ -448,7 +443,7 @@ void Session::setProcessingEnabled(bool enabled)
m_refreshTimer.stop();
}
emit processingStateChanged(m_processingEnabled);
emit processingStateChanged(enabled);
}
}
@ -479,16 +474,15 @@ Feed *Session::feedByURL(const QString &url) const @@ -479,16 +474,15 @@ Feed *Session::feedByURL(const QString &url) const
int Session::refreshInterval() const
{
return m_refreshInterval;
return m_storeRefreshInterval;
}
void Session::setRefreshInterval(const int refreshInterval)
{
if (m_refreshInterval != refreshInterval)
if (m_storeRefreshInterval != refreshInterval)
{
SettingsStorage::instance()->storeValue(SettingsKey_RefreshInterval, refreshInterval);
m_refreshInterval = refreshInterval;
m_refreshTimer.start(m_refreshInterval * MsecsPerMin);
m_storeRefreshInterval = refreshInterval;
m_refreshTimer.start(m_storeRefreshInterval * MsecsPerMin);
}
}
@ -527,15 +521,14 @@ QUuid Session::generateUID() const @@ -527,15 +521,14 @@ QUuid Session::generateUID() const
int Session::maxArticlesPerFeed() const
{
return m_maxArticlesPerFeed;
return m_storeMaxArticlesPerFeed;
}
void Session::setMaxArticlesPerFeed(const int n)
{
if (m_maxArticlesPerFeed != n)
if (m_storeMaxArticlesPerFeed != n)
{
m_maxArticlesPerFeed = n;
SettingsStorage::instance()->storeValue(SettingsKey_MaxArticlesPerFeed, n);
m_storeMaxArticlesPerFeed = n;
emit maxArticlesPerFeedChanged(n);
}
}

7
src/base/rss/rss_session.h

@ -74,6 +74,7 @@ @@ -74,6 +74,7 @@
#include <QTimer>
#include "base/3rdparty/expected.hpp"
#include "base/settingvalue.h"
class QThread;
@ -154,13 +155,13 @@ namespace RSS @@ -154,13 +155,13 @@ namespace RSS
static QPointer<Session> m_instance;
bool m_processingEnabled;
CachedSettingValue<bool> m_storeProcessingEnabled;
CachedSettingValue<int> m_storeRefreshInterval;
CachedSettingValue<int> m_storeMaxArticlesPerFeed;
QThread *m_workingThread;
AsyncFileStorage *m_confFileStorage;
AsyncFileStorage *m_dataFileStorage;
QTimer m_refreshTimer;
int m_refreshInterval;
int m_maxArticlesPerFeed;
QHash<QString, Item *> m_itemsByPath;
QHash<QUuid, Feed *> m_feedsByUID;
QHash<QString, Feed *> m_feedsByURL;

13
src/base/settingsstorage.h

@ -38,6 +38,12 @@ @@ -38,6 +38,12 @@
#include "utils/string.h"
template <typename T>
struct IsQFlags : std::false_type {};
template <typename T>
struct IsQFlags<QFlags<T>> : std::true_type {};
class SettingsStorage : public QObject
{
Q_OBJECT
@ -61,6 +67,11 @@ public: @@ -61,6 +67,11 @@ public:
{
return loadValueImpl(key, defaultValue);
}
else if constexpr (IsQFlags<T>::value)
{
const QVariant value = loadValueImpl(key, static_cast<typename T::Int>(defaultValue));
return T {value.template value<typename T::Int>()};
}
else
{
const QVariant value = loadValueImpl(key);
@ -74,6 +85,8 @@ public: @@ -74,6 +85,8 @@ public:
{
if constexpr (std::is_enum_v<T>)
storeValueImpl(key, Utils::String::fromEnum(value));
else if constexpr (IsQFlags<T>::value)
storeValueImpl(key, static_cast<typename T::Int>(value));
else
storeValueImpl(key, value);
}

45
src/gui/addnewtorrentdialog.cpp

@ -63,12 +63,9 @@ namespace @@ -63,12 +63,9 @@ namespace
{
#define SETTINGS_KEY(name) "AddNewTorrentDialog/" name
const QString KEY_ENABLED = QStringLiteral(SETTINGS_KEY("Enabled"));
const QString KEY_DEFAULTCATEGORY = QStringLiteral(SETTINGS_KEY("DefaultCategory"));
const QString KEY_TREEHEADERSTATE = QStringLiteral(SETTINGS_KEY("TreeHeaderState"));
const QString KEY_TOPLEVEL = QStringLiteral(SETTINGS_KEY("TopLevel"));
const QString KEY_SAVEPATHHISTORY = QStringLiteral(SETTINGS_KEY("SavePathHistory"));
const QString KEY_SAVEPATHHISTORYLENGTH = QStringLiteral(SETTINGS_KEY("SavePathHistoryLength"));
const QString KEY_REMEMBERLASTSAVEPATH = QStringLiteral(SETTINGS_KEY("RememberLastSavePath"));
// just a shortcut
inline SettingsStorage *settings()
@ -83,13 +80,12 @@ const int AddNewTorrentDialog::maxPathHistoryLength; @@ -83,13 +80,12 @@ const int AddNewTorrentDialog::maxPathHistoryLength;
AddNewTorrentDialog::AddNewTorrentDialog(const BitTorrent::AddTorrentParams &inParams, QWidget *parent)
: QDialog(parent)
, m_ui(new Ui::AddNewTorrentDialog)
, m_contentModel(nullptr)
, m_contentDelegate(nullptr)
, m_hasMetadata(false)
, m_oldIndex(0)
, m_torrentParams(inParams)
, m_storeDialogSize(SETTINGS_KEY("DialogSize"))
, m_storeSplitterState(SETTINGS_KEY("SplitterState"))
, m_storeDefaultCategory(SETTINGS_KEY("DefaultCategory"))
, m_storeRememberLastSavePath(SETTINGS_KEY("RememberLastSavePath"))
, m_storeTreeHeaderState(SETTINGS_KEY("TreeHeaderState"))
{
// TODO: set dialog file properties using m_torrentParams.filePriorities
m_ui->setupUi(this);
@ -114,8 +110,7 @@ AddNewTorrentDialog::AddNewTorrentDialog(const BitTorrent::AddTorrentParams &inP @@ -114,8 +110,7 @@ AddNewTorrentDialog::AddNewTorrentDialog(const BitTorrent::AddTorrentParams &inP
populateSavePathComboBox();
connect(m_ui->savePath, &FileSystemPathEdit::selectedPathChanged, this, &AddNewTorrentDialog::onSavePathChanged);
const bool rememberLastSavePath = settings()->loadValue(KEY_REMEMBERLASTSAVEPATH, false);
m_ui->checkBoxRememberLastSavePath->setChecked(rememberLastSavePath);
m_ui->checkBoxRememberLastSavePath->setChecked(m_storeRememberLastSavePath);
m_ui->contentLayoutComboBox->setCurrentIndex(
static_cast<int>(m_torrentParams.contentLayout.value_or(session->torrentContentLayout())));
@ -129,7 +124,7 @@ AddNewTorrentDialog::AddNewTorrentDialog(const BitTorrent::AddTorrentParams &inP @@ -129,7 +124,7 @@ AddNewTorrentDialog::AddNewTorrentDialog(const BitTorrent::AddTorrentParams &inP
// Load categories
QStringList categories = session->categories().keys();
std::sort(categories.begin(), categories.end(), Utils::Compare::NaturalLessThan<Qt::CaseInsensitive>());
auto defaultCategory = settings()->loadValue<QString>(KEY_DEFAULTCATEGORY);
const QString defaultCategory = m_storeDefaultCategory;
if (!m_torrentParams.category.isEmpty())
m_ui->categoryComboBox->addItem(m_torrentParams.category);
@ -164,22 +159,22 @@ AddNewTorrentDialog::~AddNewTorrentDialog() @@ -164,22 +159,22 @@ AddNewTorrentDialog::~AddNewTorrentDialog()
bool AddNewTorrentDialog::isEnabled()
{
return SettingsStorage::instance()->loadValue(KEY_ENABLED, true);
return settings()->loadValue(KEY_ENABLED, true);
}
void AddNewTorrentDialog::setEnabled(bool value)
void AddNewTorrentDialog::setEnabled(const bool value)
{
SettingsStorage::instance()->storeValue(KEY_ENABLED, value);
settings()->storeValue(KEY_ENABLED, value);
}
bool AddNewTorrentDialog::isTopLevel()
{
return SettingsStorage::instance()->loadValue(KEY_TOPLEVEL, true);
return settings()->loadValue(KEY_TOPLEVEL, true);
}
void AddNewTorrentDialog::setTopLevel(bool value)
void AddNewTorrentDialog::setTopLevel(const bool value)
{
SettingsStorage::instance()->storeValue(KEY_TOPLEVEL, value);
settings()->storeValue(KEY_TOPLEVEL, value);
}
int AddNewTorrentDialog::savePathHistoryLength()
@ -189,7 +184,7 @@ int AddNewTorrentDialog::savePathHistoryLength() @@ -189,7 +184,7 @@ int AddNewTorrentDialog::savePathHistoryLength()
return qBound(minPathHistoryLength, value, maxPathHistoryLength);
}
void AddNewTorrentDialog::setSavePathHistoryLength(int value)
void AddNewTorrentDialog::setSavePathHistoryLength(const int value)
{
const int clampedValue = qBound(minPathHistoryLength, value, maxPathHistoryLength);
const int oldValue = savePathHistoryLength();
@ -204,8 +199,7 @@ void AddNewTorrentDialog::setSavePathHistoryLength(int value) @@ -204,8 +199,7 @@ void AddNewTorrentDialog::setSavePathHistoryLength(int value)
void AddNewTorrentDialog::loadState()
{
Utils::Gui::resize(this, m_storeDialogSize);
m_ui->splitter->restoreState(m_storeSplitterState);
m_headerState = settings()->loadValue<QByteArray>(KEY_TREEHEADERSTATE);
m_ui->splitter->restoreState(m_storeSplitterState);;
}
void AddNewTorrentDialog::saveState()
@ -213,7 +207,7 @@ void AddNewTorrentDialog::saveState() @@ -213,7 +207,7 @@ void AddNewTorrentDialog::saveState()
m_storeDialogSize = size();
m_storeSplitterState = m_ui->splitter->saveState();
if (m_contentModel)
settings()->storeValue(KEY_TREEHEADERSTATE, m_ui->contentTreeView->header()->saveState());
m_storeTreeHeaderState = m_ui->contentTreeView->header()->saveState();
}
void AddNewTorrentDialog::show(const QString &source, const BitTorrent::AddTorrentParams &inParams, QWidget *parent)
@ -489,12 +483,11 @@ void AddNewTorrentDialog::populateSavePathComboBox() @@ -489,12 +483,11 @@ void AddNewTorrentDialog::populateSavePathComboBox()
for (const QString &savePath : savePathHistory)
m_ui->savePath->addItem(savePath);
const bool rememberLastSavePath {settings()->loadValue(KEY_REMEMBERLASTSAVEPATH, false)};
const QString defSavePath {BitTorrent::Session::instance()->defaultSavePath()};
if (!m_torrentParams.savePath.isEmpty())
setSavePath(m_torrentParams.savePath);
else if (!rememberLastSavePath)
else if (!m_storeRememberLastSavePath)
setSavePath(defSavePath);
// else last used save path will be selected since it is the first in the list
}
@ -607,9 +600,9 @@ void AddNewTorrentDialog::accept() @@ -607,9 +600,9 @@ void AddNewTorrentDialog::accept()
// Category
m_torrentParams.category = m_ui->categoryComboBox->currentText();
if (m_ui->defaultCategoryCheckbox->isChecked())
settings()->storeValue(KEY_DEFAULTCATEGORY, m_torrentParams.category);
m_storeDefaultCategory = m_torrentParams.category;
settings()->storeValue(KEY_REMEMBERLASTSAVEPATH, m_ui->checkBoxRememberLastSavePath->isChecked());
m_storeRememberLastSavePath = m_ui->checkBoxRememberLastSavePath->isChecked();
// Save file priorities
if (m_contentModel)
@ -722,8 +715,8 @@ void AddNewTorrentDialog::setupTreeview() @@ -722,8 +715,8 @@ void AddNewTorrentDialog::setupTreeview()
// List files in torrent
m_contentModel->model()->setupModelData(m_torrentInfo);
if (!m_headerState.isEmpty())
m_ui->contentTreeView->header()->restoreState(m_headerState);
if (!m_storeTreeHeaderState.get().isEmpty())
m_ui->contentTreeView->header()->restoreState(m_storeTreeHeaderState);
// Hide useless columns after loading the header state
m_ui->contentTreeView->hideColumn(PROGRESS);

12
src/gui/addnewtorrentdialog.h

@ -108,16 +108,18 @@ private: @@ -108,16 +108,18 @@ private:
void showEvent(QShowEvent *event) override;
Ui::AddNewTorrentDialog *m_ui;
TorrentContentFilterModel *m_contentModel;
PropListDelegate *m_contentDelegate;
bool m_hasMetadata;
TorrentContentFilterModel *m_contentModel = nullptr;
PropListDelegate *m_contentDelegate = nullptr;
bool m_hasMetadata = false;
BitTorrent::MagnetUri m_magnetURI;
BitTorrent::TorrentInfo m_torrentInfo;
QByteArray m_headerState;
int m_oldIndex;
int m_oldIndex = 0;
std::unique_ptr<TorrentFileGuard> m_torrentGuard;
BitTorrent::AddTorrentParams m_torrentParams;
SettingValue<QSize> m_storeDialogSize;
SettingValue<QByteArray> m_storeSplitterState;
SettingValue<QString> m_storeDefaultCategory;
SettingValue<bool> m_storeRememberLastSavePath;
CachedSettingValue<QByteArray> m_storeTreeHeaderState;
};

108
src/gui/mainwindow.cpp

@ -56,12 +56,10 @@ @@ -56,12 +56,10 @@
#include "base/bittorrent/session.h"
#include "base/bittorrent/sessionstatus.h"
#include "base/global.h"
#include "base/logger.h"
#include "base/net/downloadmanager.h"
#include "base/preferences.h"
#include "base/rss/rss_folder.h"
#include "base/rss/rss_session.h"
#include "base/settingsstorage.h"
#include "base/utils/foreignapps.h"
#include "base/utils/fs.h"
#include "base/utils/misc.h"
@ -105,34 +103,14 @@ using namespace std::chrono_literals; @@ -105,34 +103,14 @@ using namespace std::chrono_literals;
namespace
{
#define SETTINGS_KEY(name) "GUI/" name
// ExecutionLog properties keys
#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) QStringLiteral(SETTINGS_KEY("Notifications/") name)
const QString KEY_NOTIFICATIONS_ENABLED = NOTIFICATIONS_SETTINGS_KEY("Enabled");
const QString KEY_NOTIFICATIONS_TORRENTADDED = NOTIFICATIONS_SETTINGS_KEY("TorrentAdded");
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) && defined(QT_DBUS_LIB)
const QString KEY_NOTIFICATION_TIMEOUT = NOTIFICATIONS_SETTINGS_KEY("Timeout");
#endif
// Misc
const QString KEY_DOWNLOAD_TRACKER_FAVICON = QStringLiteral(SETTINGS_KEY("DownloadTrackerFavicon"));
#define EXECUTIONLOG_SETTINGS_KEY(name) (SETTINGS_KEY("Log/") name)
#define NOTIFICATIONS_SETTINGS_KEY(name) (SETTINGS_KEY("Notifications/") name)
const std::chrono::seconds PREVENT_SUSPEND_INTERVAL {60};
#if !defined(Q_OS_MACOS)
const int TIME_TRAY_BALLOON = 5000;
#endif
// just a shortcut
inline SettingsStorage *settings()
{
return SettingsStorage::instance();
}
bool isTorrentLink(const QString &str)
{
return str.startsWith(QLatin1String("magnet:"), Qt::CaseInsensitive)
@ -145,10 +123,14 @@ namespace @@ -145,10 +123,14 @@ namespace
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, m_ui(new Ui::MainWindow)
, m_posInitialized(false)
, m_forceExit(false)
, m_unlockDlgShowing(false)
, m_hasPython(false)
, 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)
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) && defined(QT_DBUS_LIB)
, m_storeNotificationTimeOut(NOTIFICATIONS_SETTINGS_KEY("Timeout"))
#endif
{
m_ui->setupUi(this);
@ -358,11 +340,11 @@ MainWindow::MainWindow(QWidget *parent) @@ -358,11 +340,11 @@ MainWindow::MainWindow(QWidget *parent)
m_ui->actionSearchWidget->setChecked(pref->isSearchEnabled());
m_ui->actionExecutionLogs->setChecked(isExecutionLogEnabled());
Log::MsgTypes flags(executionLogMsgTypes());
m_ui->actionNormalMessages->setChecked(flags & Log::NORMAL);
m_ui->actionInformationMessages->setChecked(flags & Log::INFO);
m_ui->actionWarningMessages->setChecked(flags & Log::WARNING);
m_ui->actionCriticalMessages->setChecked(flags & Log::CRITICAL);
const Log::MsgTypes flags = executionLogMsgTypes();
m_ui->actionNormalMessages->setChecked(flags.testFlag(Log::NORMAL));
m_ui->actionInformationMessages->setChecked(flags.testFlag(Log::INFO));
m_ui->actionWarningMessages->setChecked(flags.testFlag(Log::WARNING));
m_ui->actionCriticalMessages->setChecked(flags.testFlag(Log::CRITICAL));
displayRSSTab(m_ui->actionRSSReader->isChecked());
on_actionExecutionLogs_triggered(m_ui->actionExecutionLogs->isChecked());
@ -485,68 +467,66 @@ MainWindow::~MainWindow() @@ -485,68 +467,66 @@ MainWindow::~MainWindow()
bool MainWindow::isExecutionLogEnabled() const
{
return settings()->loadValue(KEY_EXECUTIONLOG_ENABLED, false);
return m_storeExecutionLogEnabled;
}
void MainWindow::setExecutionLogEnabled(bool value)
void MainWindow::setExecutionLogEnabled(const bool value)
{
settings()->storeValue(KEY_EXECUTIONLOG_ENABLED, value);
m_storeExecutionLogEnabled = value;
}
int MainWindow::executionLogMsgTypes() const
Log::MsgTypes MainWindow::executionLogMsgTypes() const
{
// as default value we need all the bits set
// -1 is considered the portable way to achieve that
return settings()->loadValue(KEY_EXECUTIONLOG_TYPES, -1);
return m_storeExecutionLogTypes;
}
void MainWindow::setExecutionLogMsgTypes(const int value)
void MainWindow::setExecutionLogMsgTypes(const Log::MsgTypes value)
{
m_executionLog->setMessageTypes(static_cast<Log::MsgTypes>(value));
settings()->storeValue(KEY_EXECUTIONLOG_TYPES, value);
m_executionLog->setMessageTypes(value);
m_storeExecutionLogTypes = value;
}
bool MainWindow::isNotificationsEnabled() const
{
return settings()->loadValue(KEY_NOTIFICATIONS_ENABLED, true);
return m_storeNotificationEnabled.get(true);
}
void MainWindow::setNotificationsEnabled(bool value)
{
settings()->storeValue(KEY_NOTIFICATIONS_ENABLED, value);
m_storeNotificationEnabled = value;
}
bool MainWindow::isTorrentAddedNotificationsEnabled() const
{
return settings()->loadValue(KEY_NOTIFICATIONS_TORRENTADDED, false);
return m_storeNotificationTorrentAdded;
}
void MainWindow::setTorrentAddedNotificationsEnabled(bool value)
void MainWindow::setTorrentAddedNotificationsEnabled(const bool value)
{
settings()->storeValue(KEY_NOTIFICATIONS_TORRENTADDED, value);
m_storeNotificationTorrentAdded = value;
}
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) && defined(QT_DBUS_LIB)
int MainWindow::getNotificationTimeout() const
{
return settings()->loadValue(KEY_NOTIFICATION_TIMEOUT, -1);
return m_storeNotificationTimeOut.get(-1);
}
void MainWindow::setNotificationTimeout(const int value)
{
settings()->storeValue(KEY_NOTIFICATION_TIMEOUT, value);
m_storeNotificationTimeOut = value;
}
#endif
bool MainWindow::isDownloadTrackerFavicon() const
{
return settings()->loadValue(KEY_DOWNLOAD_TRACKER_FAVICON, false);
return m_storeDownloadTrackerFavicon;
}
void MainWindow::setDownloadTrackerFavicon(bool value)
void MainWindow::setDownloadTrackerFavicon(const bool value)
{
m_transferListFiltersWidget->setDownloadTrackerFavicon(value);
settings()->storeValue(KEY_DOWNLOAD_TRACKER_FAVICON, value);
m_storeDownloadTrackerFavicon = value;
}
void MainWindow::addToolbarContextMenu()
@ -2005,7 +1985,7 @@ void MainWindow::on_actionExecutionLogs_triggered(bool checked) @@ -2005,7 +1985,7 @@ void MainWindow::on_actionExecutionLogs_triggered(bool checked)
if (checked)
{
Q_ASSERT(!m_executionLog);
m_executionLog = new ExecutionLogWidget(static_cast<Log::MsgType>(executionLogMsgTypes()), m_tabs);
m_executionLog = new ExecutionLogWidget(executionLogMsgTypes(), m_tabs);
#ifdef Q_OS_MACOS
m_tabs->addTab(m_executionLog, tr("Execution Log"));
#else
@ -2025,43 +2005,39 @@ void MainWindow::on_actionExecutionLogs_triggered(bool checked) @@ -2025,43 +2005,39 @@ void MainWindow::on_actionExecutionLogs_triggered(bool checked)
setExecutionLogEnabled(checked);
}
void MainWindow::on_actionNormalMessages_triggered(bool checked)
void MainWindow::on_actionNormalMessages_triggered(const bool checked)
{
if (!m_executionLog)
return;
Log::MsgTypes flags(executionLogMsgTypes());
checked ? (flags |= Log::NORMAL) : (flags &= ~Log::NORMAL);
const Log::MsgTypes flags = executionLogMsgTypes().setFlag(Log::NORMAL, checked);
setExecutionLogMsgTypes(flags);
}
void MainWindow::on_actionInformationMessages_triggered(bool checked)
void MainWindow::on_actionInformationMessages_triggered(const bool checked)
{
if (!m_executionLog)
return;
Log::MsgTypes flags(executionLogMsgTypes());
checked ? (flags |= Log::INFO) : (flags &= ~Log::INFO);
const Log::MsgTypes flags = executionLogMsgTypes().setFlag(Log::INFO, checked);
setExecutionLogMsgTypes(flags);
}
void MainWindow::on_actionWarningMessages_triggered(bool checked)
void MainWindow::on_actionWarningMessages_triggered(const bool checked)
{
if (!m_executionLog)
return;
Log::MsgTypes flags(executionLogMsgTypes());
checked ? (flags |= Log::WARNING) : (flags &= ~Log::WARNING);
const Log::MsgTypes flags = executionLogMsgTypes().setFlag(Log::WARNING, checked);
setExecutionLogMsgTypes(flags);
}
void MainWindow::on_actionCriticalMessages_triggered(bool checked)
void MainWindow::on_actionCriticalMessages_triggered(const bool checked)
{
if (!m_executionLog)
return;
Log::MsgTypes flags(executionLogMsgTypes());
checked ? (flags |= Log::CRITICAL) : (flags &= ~Log::CRITICAL);
const Log::MsgTypes flags = executionLogMsgTypes().setFlag(Log::CRITICAL, checked);
setExecutionLogMsgTypes(flags);
}

24
src/gui/mainwindow.h

@ -36,6 +36,8 @@ @@ -36,6 +36,8 @@
#endif
#include "base/bittorrent/torrent.h"
#include "base/logger.h"
#include "base/settingvalue.h"
class QCloseEvent;
class QFileSystemWatcher;
@ -85,8 +87,8 @@ public: @@ -85,8 +87,8 @@ public:
// ExecutionLog properties
bool isExecutionLogEnabled() const;
void setExecutionLogEnabled(bool value);
int executionLogMsgTypes() const;
void setExecutionLogMsgTypes(int value);
Log::MsgTypes executionLogMsgTypes() const;
void setExecutionLogMsgTypes(Log::MsgTypes value);
// Notifications properties
bool isNotificationsEnabled() const;
@ -217,7 +219,7 @@ private: @@ -217,7 +219,7 @@ private:
QFileSystemWatcher *m_executableWatcher;
// GUI related
bool m_posInitialized;
bool m_posInitialized = false;
QPointer<QTabWidget> m_tabs;
QPointer<StatusBar> m_statusBar;
QPointer<OptionsDialog> m_options;
@ -234,9 +236,9 @@ private: @@ -234,9 +236,9 @@ private:
TransferListFiltersWidget *m_transferListFiltersWidget;
PropertiesWidget *m_propertiesWidget;
bool m_displaySpeedInTitle;
bool m_forceExit;
bool m_forceExit = false;
bool m_uiLocked;
bool m_unlockDlgShowing;
bool m_unlockDlgShowing = false;
LineEdit *m_searchFilter;
QAction *m_searchFilterAction;
// Widgets
@ -249,9 +251,19 @@ private: @@ -249,9 +251,19 @@ private:
// Power Management
PowerManagement *m_pwr;
QTimer *m_preventTimer;
bool m_hasPython;
bool m_hasPython = false;
QMenu *m_toolbarMenu;
SettingValue<bool> m_storeExecutionLogEnabled;
SettingValue<bool> m_storeDownloadTrackerFavicon;
SettingValue<bool> m_storeNotificationEnabled;
SettingValue<bool> m_storeNotificationTorrentAdded;
CachedSettingValue<Log::MsgTypes> m_storeExecutionLogTypes;
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) && defined(QT_DBUS_LIB)
SettingValue<int> m_storeNotificationTimeOut;
#endif
#if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
void checkProgramUpdate(bool invokedByUser);
void handleUpdateCheckFinished(ProgramUpdater *updater, bool invokedByUser);

1
src/gui/watchedfolderoptionsdialog.cpp

@ -33,7 +33,6 @@ @@ -33,7 +33,6 @@
#include "base/bittorrent/session.h"
#include "base/global.h"
#include "base/settingsstorage.h"
#include "base/utils/fs.h"
#include "ui_watchedfolderoptionsdialog.h"
#include "utils.h"

Loading…
Cancel
Save