mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-11 15:27:54 +00:00
Migrate away from low-level SettingsStorage
class
Also add `QFlags<T>` support to `SettingsStorage`. PR #15693.
This commit is contained in:
parent
e33c4086b9
commit
32698fe0be
@ -100,22 +100,10 @@
|
|||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
#define SETTINGS_KEY(name) "Application/" name
|
#define SETTINGS_KEY(name) "Application/" name
|
||||||
|
#define FILELOGGER_SETTINGS_KEY(name) (SETTINGS_KEY("FileLogger/") 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(); }
|
|
||||||
|
|
||||||
const QString LOG_FOLDER = QStringLiteral("logs");
|
const QString LOG_FOLDER = QStringLiteral("logs");
|
||||||
const QChar PARAMS_SEPARATOR = '|';
|
const QChar PARAMS_SEPARATOR = QLatin1Char('|');
|
||||||
|
|
||||||
const QString DEFAULT_PORTABLE_MODE_PROFILE_DIR = QStringLiteral("profile");
|
const QString DEFAULT_PORTABLE_MODE_PROFILE_DIR = QStringLiteral("profile");
|
||||||
|
|
||||||
@ -133,6 +121,13 @@ Application::Application(int &argc, char **argv)
|
|||||||
, m_running(false)
|
, m_running(false)
|
||||||
, m_shutdownAct(ShutdownDialogAction::Exit)
|
, m_shutdownAct(ShutdownDialogAction::Exit)
|
||||||
, m_commandLineArgs(parseCommandLine(this->arguments()))
|
, 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::Msg>("Log::Msg");
|
||||||
qRegisterMetaType<Log::Peer>("Log::Peer");
|
qRegisterMetaType<Log::Peer>("Log::Peer");
|
||||||
@ -211,7 +206,7 @@ const QBtCommandLineParameters &Application::commandLineArgs() const
|
|||||||
|
|
||||||
bool Application::isFileLoggerEnabled() const
|
bool Application::isFileLoggerEnabled() const
|
||||||
{
|
{
|
||||||
return settings()->loadValue(KEY_FILELOGGER_ENABLED, true);
|
return m_storeFileLoggerEnabled.get(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::setFileLoggerEnabled(const bool value)
|
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()));
|
m_fileLogger = new FileLogger(fileLoggerPath(), isFileLoggerBackup(), fileLoggerMaxSize(), isFileLoggerDeleteOld(), fileLoggerAge(), static_cast<FileLogger::FileLogAgeType>(fileLoggerAgeType()));
|
||||||
else if (!value)
|
else if (!value)
|
||||||
delete m_fileLogger;
|
delete m_fileLogger;
|
||||||
settings()->storeValue(KEY_FILELOGGER_ENABLED, value);
|
m_storeFileLoggerEnabled = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Application::fileLoggerPath() const
|
QString Application::fileLoggerPath() const
|
||||||
{
|
{
|
||||||
return settings()->loadValue(KEY_FILELOGGER_PATH
|
return m_storeFileLoggerPath.get(specialFolderLocation(SpecialFolder::Data) + LOG_FOLDER);
|
||||||
, QString {specialFolderLocation(SpecialFolder::Data) + LOG_FOLDER});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::setFileLoggerPath(const QString &path)
|
void Application::setFileLoggerPath(const QString &path)
|
||||||
{
|
{
|
||||||
if (m_fileLogger)
|
if (m_fileLogger)
|
||||||
m_fileLogger->changePath(path);
|
m_fileLogger->changePath(path);
|
||||||
settings()->storeValue(KEY_FILELOGGER_PATH, path);
|
m_storeFileLoggerPath = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Application::isFileLoggerBackup() const
|
bool Application::isFileLoggerBackup() const
|
||||||
{
|
{
|
||||||
return settings()->loadValue(KEY_FILELOGGER_BACKUP, true);
|
return m_storeFileLoggerBackup.get(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::setFileLoggerBackup(const bool value)
|
void Application::setFileLoggerBackup(const bool value)
|
||||||
{
|
{
|
||||||
if (m_fileLogger)
|
if (m_fileLogger)
|
||||||
m_fileLogger->setBackup(value);
|
m_fileLogger->setBackup(value);
|
||||||
settings()->storeValue(KEY_FILELOGGER_BACKUP, value);
|
m_storeFileLoggerBackup = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Application::isFileLoggerDeleteOld() const
|
bool Application::isFileLoggerDeleteOld() const
|
||||||
{
|
{
|
||||||
return settings()->loadValue(KEY_FILELOGGER_DELETEOLD, true);
|
return m_storeFileLoggerDeleteOld.get(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::setFileLoggerDeleteOld(const bool value)
|
void Application::setFileLoggerDeleteOld(const bool value)
|
||||||
{
|
{
|
||||||
if (value && m_fileLogger)
|
if (value && m_fileLogger)
|
||||||
m_fileLogger->deleteOld(fileLoggerAge(), static_cast<FileLogger::FileLogAgeType>(fileLoggerAgeType()));
|
m_fileLogger->deleteOld(fileLoggerAge(), static_cast<FileLogger::FileLogAgeType>(fileLoggerAgeType()));
|
||||||
settings()->storeValue(KEY_FILELOGGER_DELETEOLD, value);
|
m_storeFileLoggerDeleteOld = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Application::fileLoggerMaxSize() const
|
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);
|
return std::min(std::max(val, MIN_FILELOG_SIZE), MAX_FILELOG_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -271,29 +265,29 @@ void Application::setFileLoggerMaxSize(const int bytes)
|
|||||||
const int clampedValue = std::min(std::max(bytes, MIN_FILELOG_SIZE), MAX_FILELOG_SIZE);
|
const int clampedValue = std::min(std::max(bytes, MIN_FILELOG_SIZE), MAX_FILELOG_SIZE);
|
||||||
if (m_fileLogger)
|
if (m_fileLogger)
|
||||||
m_fileLogger->setMaxSize(clampedValue);
|
m_fileLogger->setMaxSize(clampedValue);
|
||||||
settings()->storeValue(KEY_FILELOGGER_MAXSIZEBYTES, clampedValue);
|
m_storeFileLoggerMaxSize = clampedValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Application::fileLoggerAge() const
|
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);
|
return std::min(std::max(val, 1), 365);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::setFileLoggerAge(const int value)
|
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
|
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;
|
return ((val < 0) || (val > 2)) ? 1 : val;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::setFileLoggerAgeType(const int value)
|
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)
|
void Application::processMessage(const QString &message)
|
||||||
|
@ -47,6 +47,7 @@ class QSessionManager;
|
|||||||
using BaseApplication = QCoreApplication;
|
using BaseApplication = QCoreApplication;
|
||||||
#endif // DISABLE_GUI
|
#endif // DISABLE_GUI
|
||||||
|
|
||||||
|
#include "base/settingvalue.h"
|
||||||
#include "base/types.h"
|
#include "base/types.h"
|
||||||
#include "cmdoptions.h"
|
#include "cmdoptions.h"
|
||||||
|
|
||||||
@ -120,6 +121,11 @@ private slots:
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void initializeTranslation();
|
||||||
|
void processParams(const QStringList ¶ms);
|
||||||
|
void runExternalProgram(const BitTorrent::Torrent *torrent) const;
|
||||||
|
void sendNotificationEmail(const BitTorrent::Torrent *torrent);
|
||||||
|
|
||||||
ApplicationInstanceManager *m_instanceManager = nullptr;
|
ApplicationInstanceManager *m_instanceManager = nullptr;
|
||||||
bool m_running;
|
bool m_running;
|
||||||
ShutdownDialogAction m_shutdownAct;
|
ShutdownDialogAction m_shutdownAct;
|
||||||
@ -140,8 +146,11 @@ private:
|
|||||||
QTranslator m_translator;
|
QTranslator m_translator;
|
||||||
QStringList m_paramsQueue;
|
QStringList m_paramsQueue;
|
||||||
|
|
||||||
void initializeTranslation();
|
SettingValue<bool> m_storeFileLoggerEnabled;
|
||||||
void processParams(const QStringList ¶ms);
|
SettingValue<bool> m_storeFileLoggerBackup;
|
||||||
void runExternalProgram(const BitTorrent::Torrent *torrent) const;
|
SettingValue<bool> m_storeFileLoggerDeleteOld;
|
||||||
void sendNotificationEmail(const BitTorrent::Torrent *torrent);
|
SettingValue<int> m_storeFileLoggerMaxSize;
|
||||||
|
SettingValue<int> m_storeFileLoggerAge;
|
||||||
|
SettingValue<int> m_storeFileLoggerAgeType;
|
||||||
|
SettingValue<QString> m_storeFileLoggerPath;
|
||||||
};
|
};
|
||||||
|
@ -33,16 +33,13 @@
|
|||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
#include "base/logger.h"
|
#include "base/logger.h"
|
||||||
#include "base/settingsstorage.h"
|
|
||||||
|
|
||||||
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)}
|
, m_storeActive {"Network/PortForwardingEnabled", true}
|
||||||
, m_provider {provider}
|
, m_provider {provider}
|
||||||
{
|
{
|
||||||
if (m_active)
|
if (isEnabled())
|
||||||
start();
|
start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,20 +50,19 @@ PortForwarderImpl::~PortForwarderImpl()
|
|||||||
|
|
||||||
bool PortForwarderImpl::isEnabled() const
|
bool PortForwarderImpl::isEnabled() const
|
||||||
{
|
{
|
||||||
return m_active;
|
return m_storeActive;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PortForwarderImpl::setEnabled(const bool enabled)
|
void PortForwarderImpl::setEnabled(const bool enabled)
|
||||||
{
|
{
|
||||||
if (m_active != enabled)
|
if (m_storeActive != enabled)
|
||||||
{
|
{
|
||||||
if (enabled)
|
if (enabled)
|
||||||
start();
|
start();
|
||||||
else
|
else
|
||||||
stop();
|
stop();
|
||||||
|
|
||||||
m_active = enabled;
|
m_storeActive = enabled;
|
||||||
SettingsStorage::instance()->storeValue(KEY_ENABLED, enabled);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,6 +36,7 @@
|
|||||||
#include <QHash>
|
#include <QHash>
|
||||||
|
|
||||||
#include "base/net/portforwarder.h"
|
#include "base/net/portforwarder.h"
|
||||||
|
#include "base/settingvalue.h"
|
||||||
|
|
||||||
class PortForwarderImpl final : public Net::PortForwarder
|
class PortForwarderImpl final : public Net::PortForwarder
|
||||||
{
|
{
|
||||||
@ -56,7 +57,7 @@ private:
|
|||||||
void start();
|
void start();
|
||||||
void stop();
|
void stop();
|
||||||
|
|
||||||
bool m_active;
|
CachedSettingValue<bool> m_storeActive;
|
||||||
lt::session *m_provider;
|
lt::session *m_provider;
|
||||||
QHash<quint16, std::vector<lt::port_mapping_t>> m_mappedPorts;
|
QHash<quint16, std::vector<lt::port_mapping_t>> m_mappedPorts;
|
||||||
};
|
};
|
||||||
|
@ -28,20 +28,7 @@
|
|||||||
|
|
||||||
#include "proxyconfigurationmanager.h"
|
#include "proxyconfigurationmanager.h"
|
||||||
|
|
||||||
#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");
|
|
||||||
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(); }
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Net::operator==(const ProxyConfiguration &left, const ProxyConfiguration &right)
|
bool Net::operator==(const ProxyConfiguration &left, const ProxyConfiguration &right)
|
||||||
{
|
{
|
||||||
@ -62,17 +49,21 @@ using namespace Net;
|
|||||||
ProxyConfigurationManager *ProxyConfigurationManager::m_instance = nullptr;
|
ProxyConfigurationManager *ProxyConfigurationManager::m_instance = nullptr;
|
||||||
|
|
||||||
ProxyConfigurationManager::ProxyConfigurationManager(QObject *parent)
|
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 = m_storeProxyType.get(ProxyType::None);
|
||||||
m_config.type = static_cast<ProxyType>(
|
|
||||||
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<QString>(KEY_IP, "0.0.0.0");
|
m_config.ip = m_storeProxyIP.get(QLatin1String("0.0.0.0"));
|
||||||
m_config.port = settings()->loadValue<ushort>(KEY_PORT, 8080);
|
m_config.port = m_storeProxyPort.get(8080);
|
||||||
m_config.username = settings()->loadValue<QString>(KEY_USERNAME);
|
m_config.username = m_storeProxyUsername;
|
||||||
m_config.password = settings()->loadValue<QString>(KEY_PASSWORD);
|
m_config.password = m_storeProxyPassword;
|
||||||
configureProxy();
|
configureProxy();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,14 +91,14 @@ ProxyConfiguration ProxyConfigurationManager::proxyConfiguration() const
|
|||||||
|
|
||||||
void ProxyConfigurationManager::setProxyConfiguration(const ProxyConfiguration &config)
|
void ProxyConfigurationManager::setProxyConfiguration(const ProxyConfiguration &config)
|
||||||
{
|
{
|
||||||
if (config != m_config)
|
if (m_config != config)
|
||||||
{
|
{
|
||||||
m_config = config;
|
m_config = config;
|
||||||
settings()->storeValue(KEY_TYPE, static_cast<int>(config.type));
|
m_storeProxyType = config.type;
|
||||||
settings()->storeValue(KEY_IP, config.ip);
|
m_storeProxyIP = config.ip;
|
||||||
settings()->storeValue(KEY_PORT, config.port);
|
m_storeProxyPort = config.port;
|
||||||
settings()->storeValue(KEY_USERNAME, config.username);
|
m_storeProxyUsername = config.username;
|
||||||
settings()->storeValue(KEY_PASSWORD, config.password);
|
m_storeProxyPassword = config.password;
|
||||||
configureProxy();
|
configureProxy();
|
||||||
|
|
||||||
emit proxyConfigurationChanged();
|
emit proxyConfigurationChanged();
|
||||||
@ -116,16 +107,12 @@ void ProxyConfigurationManager::setProxyConfiguration(const ProxyConfiguration &
|
|||||||
|
|
||||||
bool ProxyConfigurationManager::isProxyOnlyForTorrents() const
|
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)
|
m_storeProxyOnlyForTorrents = onlyForTorrents;
|
||||||
{
|
|
||||||
settings()->storeValue(KEY_ONLY_FOR_TORRENTS, onlyForTorrents);
|
|
||||||
m_isProxyOnlyForTorrents = onlyForTorrents;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ProxyConfigurationManager::isAuthenticationRequired() const
|
bool ProxyConfigurationManager::isAuthenticationRequired() const
|
||||||
@ -138,7 +125,7 @@ void ProxyConfigurationManager::configureProxy()
|
|||||||
{
|
{
|
||||||
// Define environment variables for urllib in search engine plugins
|
// Define environment variables for urllib in search engine plugins
|
||||||
QString proxyStrHTTP, proxyStrSOCK;
|
QString proxyStrHTTP, proxyStrSOCK;
|
||||||
if (!m_isProxyOnlyForTorrents)
|
if (!isProxyOnlyForTorrents())
|
||||||
{
|
{
|
||||||
switch (m_config.type)
|
switch (m_config.type)
|
||||||
{
|
{
|
||||||
|
@ -30,8 +30,12 @@
|
|||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
|
#include "base/settingvalue.h"
|
||||||
|
|
||||||
namespace Net
|
namespace Net
|
||||||
{
|
{
|
||||||
|
Q_NAMESPACE
|
||||||
|
|
||||||
enum class ProxyType
|
enum class ProxyType
|
||||||
{
|
{
|
||||||
None = 0,
|
None = 0,
|
||||||
@ -41,6 +45,7 @@ namespace Net
|
|||||||
SOCKS5_PW = 4,
|
SOCKS5_PW = 4,
|
||||||
SOCKS4 = 5
|
SOCKS4 = 5
|
||||||
};
|
};
|
||||||
|
Q_ENUM_NS(ProxyType)
|
||||||
|
|
||||||
struct ProxyConfiguration
|
struct ProxyConfiguration
|
||||||
{
|
{
|
||||||
@ -53,7 +58,7 @@ namespace Net
|
|||||||
bool operator==(const ProxyConfiguration &left, const ProxyConfiguration &right);
|
bool operator==(const ProxyConfiguration &left, const ProxyConfiguration &right);
|
||||||
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_OBJECT
|
||||||
Q_DISABLE_COPY_MOVE(ProxyConfigurationManager)
|
Q_DISABLE_COPY_MOVE(ProxyConfigurationManager)
|
||||||
@ -81,6 +86,11 @@ namespace Net
|
|||||||
|
|
||||||
static ProxyConfigurationManager *m_instance;
|
static ProxyConfigurationManager *m_instance;
|
||||||
ProxyConfiguration m_config;
|
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,7 +45,6 @@
|
|||||||
#include "../global.h"
|
#include "../global.h"
|
||||||
#include "../logger.h"
|
#include "../logger.h"
|
||||||
#include "../profile.h"
|
#include "../profile.h"
|
||||||
#include "../settingsstorage.h"
|
|
||||||
#include "../utils/fs.h"
|
#include "../utils/fs.h"
|
||||||
#include "rss_article.h"
|
#include "rss_article.h"
|
||||||
#include "rss_autodownloadrule.h"
|
#include "rss_autodownloadrule.h"
|
||||||
@ -62,10 +61,6 @@ struct ProcessingJob
|
|||||||
const QString ConfFolderName(QStringLiteral("rss"));
|
const QString ConfFolderName(QStringLiteral("rss"));
|
||||||
const QString RulesFileName(QStringLiteral("download_rules.json"));
|
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
|
namespace
|
||||||
{
|
{
|
||||||
QVector<RSS::AutoDownloadRule> rulesFromJSON(const QByteArray &jsonData)
|
QVector<RSS::AutoDownloadRule> rulesFromJSON(const QByteArray &jsonData)
|
||||||
@ -103,7 +98,9 @@ QString computeSmartFilterRegex(const QStringList &filters)
|
|||||||
}
|
}
|
||||||
|
|
||||||
AutoDownloader::AutoDownloader()
|
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_processingTimer(new QTimer(this))
|
||||||
, m_ioThread(new QThread(this))
|
, m_ioThread(new QThread(this))
|
||||||
{
|
{
|
||||||
@ -142,7 +139,7 @@ AutoDownloader::AutoDownloader()
|
|||||||
m_processingTimer->setSingleShot(true);
|
m_processingTimer->setSingleShot(true);
|
||||||
connect(m_processingTimer, &QTimer::timeout, this, &AutoDownloader::process);
|
connect(m_processingTimer, &QTimer::timeout, this, &AutoDownloader::process);
|
||||||
|
|
||||||
if (m_processingEnabled)
|
if (isProcessingEnabled())
|
||||||
startProcessing();
|
startProcessing();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -288,22 +285,19 @@ void AutoDownloader::importRulesFromLegacyFormat(const QByteArray &data)
|
|||||||
|
|
||||||
QStringList AutoDownloader::smartEpisodeFilters() const
|
QStringList AutoDownloader::smartEpisodeFilters() const
|
||||||
{
|
{
|
||||||
const auto filtersSetting = SettingsStorage::instance()->loadValue<QVariant>(SettingsKey_SmartEpisodeFilter);
|
const QVariant filter = m_storeSmartEpisodeFilter.get();
|
||||||
|
if (filter.isNull())
|
||||||
if (filtersSetting.isNull())
|
|
||||||
{
|
{
|
||||||
QStringList filters =
|
const QStringList defaultFilters =
|
||||||
{
|
{
|
||||||
"s(\\d+)e(\\d+)", // Format 1: s01e01
|
"s(\\d+)e(\\d+)", // Format 1: s01e01
|
||||||
"(\\d+)x(\\d+)", // Format 2: 01x01
|
"(\\d+)x(\\d+)", // Format 2: 01x01
|
||||||
"(\\d{4}[.\\-]\\d{1,2}[.\\-]\\d{1,2})", // Format 3: 2017.01.01
|
"(\\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
|
"(\\d{1,2}[.\\-]\\d{1,2}[.\\-]\\d{4})" // Format 4: 01.01.2017
|
||||||
};
|
};
|
||||||
|
return defaultFilters;
|
||||||
return filters;
|
|
||||||
}
|
}
|
||||||
|
return filter.toStringList();
|
||||||
return filtersSetting.toStringList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QRegularExpression AutoDownloader::smartEpisodeRegex() const
|
QRegularExpression AutoDownloader::smartEpisodeRegex() const
|
||||||
@ -313,7 +307,7 @@ QRegularExpression AutoDownloader::smartEpisodeRegex() const
|
|||||||
|
|
||||||
void AutoDownloader::setSmartEpisodeFilters(const QStringList &filters)
|
void AutoDownloader::setSmartEpisodeFilters(const QStringList &filters)
|
||||||
{
|
{
|
||||||
SettingsStorage::instance()->storeValue(SettingsKey_SmartEpisodeFilter, filters);
|
m_storeSmartEpisodeFilter = filters;
|
||||||
|
|
||||||
const QString regex = computeSmartFilterRegex(filters);
|
const QString regex = computeSmartFilterRegex(filters);
|
||||||
m_smartEpisodeRegex.setPattern(regex);
|
m_smartEpisodeRegex.setPattern(regex);
|
||||||
@ -321,12 +315,12 @@ void AutoDownloader::setSmartEpisodeFilters(const QStringList &filters)
|
|||||||
|
|
||||||
bool AutoDownloader::downloadRepacks() const
|
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()
|
void AutoDownloader::process()
|
||||||
@ -480,13 +474,13 @@ void AutoDownloader::storeDeferred()
|
|||||||
|
|
||||||
bool AutoDownloader::isProcessingEnabled() const
|
bool AutoDownloader::isProcessingEnabled() const
|
||||||
{
|
{
|
||||||
return m_processingEnabled;
|
return m_storeProcessingEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AutoDownloader::resetProcessingQueue()
|
void AutoDownloader::resetProcessingQueue()
|
||||||
{
|
{
|
||||||
m_processingQueue.clear();
|
m_processingQueue.clear();
|
||||||
if (!m_processingEnabled) return;
|
if (!isProcessingEnabled()) return;
|
||||||
|
|
||||||
for (Article *article : asConst(Session::instance()->rootFolder()->articles()))
|
for (Article *article : asConst(Session::instance()->rootFolder()->articles()))
|
||||||
{
|
{
|
||||||
@ -503,11 +497,10 @@ void AutoDownloader::startProcessing()
|
|||||||
|
|
||||||
void AutoDownloader::setProcessingEnabled(const bool enabled)
|
void AutoDownloader::setProcessingEnabled(const bool enabled)
|
||||||
{
|
{
|
||||||
if (m_processingEnabled != enabled)
|
if (m_storeProcessingEnabled != enabled)
|
||||||
{
|
{
|
||||||
m_processingEnabled = enabled;
|
m_storeProcessingEnabled = enabled;
|
||||||
SettingsStorage::instance()->storeValue(SettingsKey_ProcessingEnabled, m_processingEnabled);
|
if (enabled)
|
||||||
if (m_processingEnabled)
|
|
||||||
{
|
{
|
||||||
startProcessing();
|
startProcessing();
|
||||||
}
|
}
|
||||||
@ -517,7 +510,7 @@ void AutoDownloader::setProcessingEnabled(const bool enabled)
|
|||||||
disconnect(Session::instance()->rootFolder(), &Folder::newArticle, this, &AutoDownloader::handleNewArticle);
|
disconnect(Session::instance()->rootFolder(), &Folder::newArticle, this, &AutoDownloader::handleNewArticle);
|
||||||
}
|
}
|
||||||
|
|
||||||
emit processingStateChanged(m_processingEnabled);
|
emit processingStateChanged(enabled);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,6 +37,7 @@
|
|||||||
#include <QSharedPointer>
|
#include <QSharedPointer>
|
||||||
|
|
||||||
#include "base/exceptions.h"
|
#include "base/exceptions.h"
|
||||||
|
#include "base/settingvalue.h"
|
||||||
|
|
||||||
class QThread;
|
class QThread;
|
||||||
class QTimer;
|
class QTimer;
|
||||||
@ -86,7 +87,7 @@ namespace RSS
|
|||||||
QRegularExpression smartEpisodeRegex() const;
|
QRegularExpression smartEpisodeRegex() const;
|
||||||
|
|
||||||
bool downloadRepacks() const;
|
bool downloadRepacks() const;
|
||||||
void setDownloadRepacks(bool downloadRepacks);
|
void setDownloadRepacks(bool enabled);
|
||||||
|
|
||||||
bool hasRule(const QString &ruleName) const;
|
bool hasRule(const QString &ruleName) const;
|
||||||
AutoDownloadRule ruleByName(const QString &ruleName) const;
|
AutoDownloadRule ruleByName(const QString &ruleName) const;
|
||||||
@ -131,7 +132,10 @@ namespace RSS
|
|||||||
|
|
||||||
static QPointer<AutoDownloader> m_instance;
|
static QPointer<AutoDownloader> m_instance;
|
||||||
|
|
||||||
bool m_processingEnabled;
|
CachedSettingValue<bool> m_storeProcessingEnabled;
|
||||||
|
SettingValue<QVariant> m_storeSmartEpisodeFilter;
|
||||||
|
SettingValue<bool> m_storeDownloadRepacks;
|
||||||
|
|
||||||
QTimer *m_processingTimer;
|
QTimer *m_processingTimer;
|
||||||
QThread *m_ioThread;
|
QThread *m_ioThread;
|
||||||
AsyncFileStorage *m_fileStorage;
|
AsyncFileStorage *m_fileStorage;
|
||||||
|
@ -53,19 +53,15 @@ const QString ConfFolderName(QStringLiteral("rss"));
|
|||||||
const QString DataFolderName(QStringLiteral("rss/articles"));
|
const QString DataFolderName(QStringLiteral("rss/articles"));
|
||||||
const QString FeedsFileName(QStringLiteral("feeds.json"));
|
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;
|
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))
|
: m_storeProcessingEnabled("RSS/Session/EnableProcessing")
|
||||||
|
, m_storeRefreshInterval("RSS/Session/RefreshInterval", 30)
|
||||||
|
, m_storeMaxArticlesPerFeed("RSS/Session/MaxArticlesPerFeed", 50)
|
||||||
, m_workingThread(new QThread(this))
|
, 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
|
Q_ASSERT(!m_instance); // only one instance is allowed
|
||||||
m_instance = this;
|
m_instance = this;
|
||||||
@ -96,9 +92,9 @@ Session::Session()
|
|||||||
load();
|
load();
|
||||||
|
|
||||||
connect(&m_refreshTimer, &QTimer::timeout, this, &Session::refresh);
|
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();
|
refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,7 +162,7 @@ nonstd::expected<void, QString> Session::addFeed(const QString &url, const QStri
|
|||||||
const auto destFolder = result.value();
|
const auto destFolder = result.value();
|
||||||
addItem(new Feed(generateUID(), url, path, this), destFolder);
|
addItem(new Feed(generateUID(), url, path, this), destFolder);
|
||||||
store();
|
store();
|
||||||
if (m_processingEnabled)
|
if (isProcessingEnabled())
|
||||||
feedByURL(url)->refresh();
|
feedByURL(url)->refresh();
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
@ -429,18 +425,17 @@ void Session::addItem(Item *item, Folder *destFolder)
|
|||||||
|
|
||||||
bool Session::isProcessingEnabled() const
|
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;
|
m_storeProcessingEnabled = enabled;
|
||||||
SettingsStorage::instance()->storeValue(SettingsKey_ProcessingEnabled, m_processingEnabled);
|
if (enabled)
|
||||||
if (m_processingEnabled)
|
|
||||||
{
|
{
|
||||||
m_refreshTimer.start(m_refreshInterval * MsecsPerMin);
|
m_refreshTimer.start(refreshInterval() * MsecsPerMin);
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -448,7 +443,7 @@ void Session::setProcessingEnabled(bool enabled)
|
|||||||
m_refreshTimer.stop();
|
m_refreshTimer.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
emit processingStateChanged(m_processingEnabled);
|
emit processingStateChanged(enabled);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -479,16 +474,15 @@ Feed *Session::feedByURL(const QString &url) const
|
|||||||
|
|
||||||
int Session::refreshInterval() const
|
int Session::refreshInterval() const
|
||||||
{
|
{
|
||||||
return m_refreshInterval;
|
return m_storeRefreshInterval;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Session::setRefreshInterval(const int refreshInterval)
|
void Session::setRefreshInterval(const int refreshInterval)
|
||||||
{
|
{
|
||||||
if (m_refreshInterval != refreshInterval)
|
if (m_storeRefreshInterval != refreshInterval)
|
||||||
{
|
{
|
||||||
SettingsStorage::instance()->storeValue(SettingsKey_RefreshInterval, refreshInterval);
|
m_storeRefreshInterval = refreshInterval;
|
||||||
m_refreshInterval = refreshInterval;
|
m_refreshTimer.start(m_storeRefreshInterval * MsecsPerMin);
|
||||||
m_refreshTimer.start(m_refreshInterval * MsecsPerMin);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -527,15 +521,14 @@ QUuid Session::generateUID() const
|
|||||||
|
|
||||||
int Session::maxArticlesPerFeed() const
|
int Session::maxArticlesPerFeed() const
|
||||||
{
|
{
|
||||||
return m_maxArticlesPerFeed;
|
return m_storeMaxArticlesPerFeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Session::setMaxArticlesPerFeed(const int n)
|
void Session::setMaxArticlesPerFeed(const int n)
|
||||||
{
|
{
|
||||||
if (m_maxArticlesPerFeed != n)
|
if (m_storeMaxArticlesPerFeed != n)
|
||||||
{
|
{
|
||||||
m_maxArticlesPerFeed = n;
|
m_storeMaxArticlesPerFeed = n;
|
||||||
SettingsStorage::instance()->storeValue(SettingsKey_MaxArticlesPerFeed, n);
|
|
||||||
emit maxArticlesPerFeedChanged(n);
|
emit maxArticlesPerFeedChanged(n);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -74,6 +74,7 @@
|
|||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
#include "base/3rdparty/expected.hpp"
|
#include "base/3rdparty/expected.hpp"
|
||||||
|
#include "base/settingvalue.h"
|
||||||
|
|
||||||
class QThread;
|
class QThread;
|
||||||
|
|
||||||
@ -154,13 +155,13 @@ namespace RSS
|
|||||||
|
|
||||||
static QPointer<Session> m_instance;
|
static QPointer<Session> m_instance;
|
||||||
|
|
||||||
bool m_processingEnabled;
|
CachedSettingValue<bool> m_storeProcessingEnabled;
|
||||||
|
CachedSettingValue<int> m_storeRefreshInterval;
|
||||||
|
CachedSettingValue<int> m_storeMaxArticlesPerFeed;
|
||||||
QThread *m_workingThread;
|
QThread *m_workingThread;
|
||||||
AsyncFileStorage *m_confFileStorage;
|
AsyncFileStorage *m_confFileStorage;
|
||||||
AsyncFileStorage *m_dataFileStorage;
|
AsyncFileStorage *m_dataFileStorage;
|
||||||
QTimer m_refreshTimer;
|
QTimer m_refreshTimer;
|
||||||
int m_refreshInterval;
|
|
||||||
int m_maxArticlesPerFeed;
|
|
||||||
QHash<QString, Item *> m_itemsByPath;
|
QHash<QString, Item *> m_itemsByPath;
|
||||||
QHash<QUuid, Feed *> m_feedsByUID;
|
QHash<QUuid, Feed *> m_feedsByUID;
|
||||||
QHash<QString, Feed *> m_feedsByURL;
|
QHash<QString, Feed *> m_feedsByURL;
|
||||||
|
@ -38,6 +38,12 @@
|
|||||||
|
|
||||||
#include "utils/string.h"
|
#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
|
class SettingsStorage : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -61,6 +67,11 @@ public:
|
|||||||
{
|
{
|
||||||
return loadValueImpl(key, defaultValue);
|
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
|
else
|
||||||
{
|
{
|
||||||
const QVariant value = loadValueImpl(key);
|
const QVariant value = loadValueImpl(key);
|
||||||
@ -74,6 +85,8 @@ public:
|
|||||||
{
|
{
|
||||||
if constexpr (std::is_enum_v<T>)
|
if constexpr (std::is_enum_v<T>)
|
||||||
storeValueImpl(key, Utils::String::fromEnum(value));
|
storeValueImpl(key, Utils::String::fromEnum(value));
|
||||||
|
else if constexpr (IsQFlags<T>::value)
|
||||||
|
storeValueImpl(key, static_cast<typename T::Int>(value));
|
||||||
else
|
else
|
||||||
storeValueImpl(key, value);
|
storeValueImpl(key, value);
|
||||||
}
|
}
|
||||||
|
@ -63,12 +63,9 @@ namespace
|
|||||||
{
|
{
|
||||||
#define SETTINGS_KEY(name) "AddNewTorrentDialog/" name
|
#define SETTINGS_KEY(name) "AddNewTorrentDialog/" name
|
||||||
const QString KEY_ENABLED = QStringLiteral(SETTINGS_KEY("Enabled"));
|
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_TOPLEVEL = QStringLiteral(SETTINGS_KEY("TopLevel"));
|
||||||
const QString KEY_SAVEPATHHISTORY = QStringLiteral(SETTINGS_KEY("SavePathHistory"));
|
const QString KEY_SAVEPATHHISTORY = QStringLiteral(SETTINGS_KEY("SavePathHistory"));
|
||||||
const QString KEY_SAVEPATHHISTORYLENGTH = QStringLiteral(SETTINGS_KEY("SavePathHistoryLength"));
|
const QString KEY_SAVEPATHHISTORYLENGTH = QStringLiteral(SETTINGS_KEY("SavePathHistoryLength"));
|
||||||
const QString KEY_REMEMBERLASTSAVEPATH = QStringLiteral(SETTINGS_KEY("RememberLastSavePath"));
|
|
||||||
|
|
||||||
// just a shortcut
|
// just a shortcut
|
||||||
inline SettingsStorage *settings()
|
inline SettingsStorage *settings()
|
||||||
@ -83,13 +80,12 @@ const int AddNewTorrentDialog::maxPathHistoryLength;
|
|||||||
AddNewTorrentDialog::AddNewTorrentDialog(const BitTorrent::AddTorrentParams &inParams, QWidget *parent)
|
AddNewTorrentDialog::AddNewTorrentDialog(const BitTorrent::AddTorrentParams &inParams, QWidget *parent)
|
||||||
: QDialog(parent)
|
: QDialog(parent)
|
||||||
, m_ui(new Ui::AddNewTorrentDialog)
|
, m_ui(new Ui::AddNewTorrentDialog)
|
||||||
, m_contentModel(nullptr)
|
|
||||||
, m_contentDelegate(nullptr)
|
|
||||||
, m_hasMetadata(false)
|
|
||||||
, m_oldIndex(0)
|
|
||||||
, m_torrentParams(inParams)
|
, m_torrentParams(inParams)
|
||||||
, m_storeDialogSize(SETTINGS_KEY("DialogSize"))
|
, m_storeDialogSize(SETTINGS_KEY("DialogSize"))
|
||||||
, m_storeSplitterState(SETTINGS_KEY("SplitterState"))
|
, 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
|
// TODO: set dialog file properties using m_torrentParams.filePriorities
|
||||||
m_ui->setupUi(this);
|
m_ui->setupUi(this);
|
||||||
@ -114,8 +110,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);
|
m_ui->checkBoxRememberLastSavePath->setChecked(m_storeRememberLastSavePath);
|
||||||
m_ui->checkBoxRememberLastSavePath->setChecked(rememberLastSavePath);
|
|
||||||
|
|
||||||
m_ui->contentLayoutComboBox->setCurrentIndex(
|
m_ui->contentLayoutComboBox->setCurrentIndex(
|
||||||
static_cast<int>(m_torrentParams.contentLayout.value_or(session->torrentContentLayout())));
|
static_cast<int>(m_torrentParams.contentLayout.value_or(session->torrentContentLayout())));
|
||||||
@ -129,7 +124,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::Compare::NaturalLessThan<Qt::CaseInsensitive>());
|
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())
|
if (!m_torrentParams.category.isEmpty())
|
||||||
m_ui->categoryComboBox->addItem(m_torrentParams.category);
|
m_ui->categoryComboBox->addItem(m_torrentParams.category);
|
||||||
@ -164,22 +159,22 @@ AddNewTorrentDialog::~AddNewTorrentDialog()
|
|||||||
|
|
||||||
bool AddNewTorrentDialog::isEnabled()
|
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()
|
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()
|
int AddNewTorrentDialog::savePathHistoryLength()
|
||||||
@ -189,7 +184,7 @@ int AddNewTorrentDialog::savePathHistoryLength()
|
|||||||
return qBound(minPathHistoryLength, value, maxPathHistoryLength);
|
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 clampedValue = qBound(minPathHistoryLength, value, maxPathHistoryLength);
|
||||||
const int oldValue = savePathHistoryLength();
|
const int oldValue = savePathHistoryLength();
|
||||||
@ -204,8 +199,7 @@ void AddNewTorrentDialog::setSavePathHistoryLength(int value)
|
|||||||
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<QByteArray>(KEY_TREEHEADERSTATE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddNewTorrentDialog::saveState()
|
void AddNewTorrentDialog::saveState()
|
||||||
@ -213,7 +207,7 @@ void AddNewTorrentDialog::saveState()
|
|||||||
m_storeDialogSize = size();
|
m_storeDialogSize = size();
|
||||||
m_storeSplitterState = m_ui->splitter->saveState();
|
m_storeSplitterState = m_ui->splitter->saveState();
|
||||||
if (m_contentModel)
|
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)
|
void AddNewTorrentDialog::show(const QString &source, const BitTorrent::AddTorrentParams &inParams, QWidget *parent)
|
||||||
@ -489,12 +483,11 @@ void AddNewTorrentDialog::populateSavePathComboBox()
|
|||||||
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)};
|
|
||||||
const QString defSavePath {BitTorrent::Session::instance()->defaultSavePath()};
|
const QString defSavePath {BitTorrent::Session::instance()->defaultSavePath()};
|
||||||
|
|
||||||
if (!m_torrentParams.savePath.isEmpty())
|
if (!m_torrentParams.savePath.isEmpty())
|
||||||
setSavePath(m_torrentParams.savePath);
|
setSavePath(m_torrentParams.savePath);
|
||||||
else if (!rememberLastSavePath)
|
else if (!m_storeRememberLastSavePath)
|
||||||
setSavePath(defSavePath);
|
setSavePath(defSavePath);
|
||||||
// else last used save path will be selected since it is the first in the list
|
// else last used save path will be selected since it is the first in the list
|
||||||
}
|
}
|
||||||
@ -607,9 +600,9 @@ void AddNewTorrentDialog::accept()
|
|||||||
// Category
|
// Category
|
||||||
m_torrentParams.category = m_ui->categoryComboBox->currentText();
|
m_torrentParams.category = m_ui->categoryComboBox->currentText();
|
||||||
if (m_ui->defaultCategoryCheckbox->isChecked())
|
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
|
// Save file priorities
|
||||||
if (m_contentModel)
|
if (m_contentModel)
|
||||||
@ -722,8 +715,8 @@ void AddNewTorrentDialog::setupTreeview()
|
|||||||
|
|
||||||
// List files in torrent
|
// List files in torrent
|
||||||
m_contentModel->model()->setupModelData(m_torrentInfo);
|
m_contentModel->model()->setupModelData(m_torrentInfo);
|
||||||
if (!m_headerState.isEmpty())
|
if (!m_storeTreeHeaderState.get().isEmpty())
|
||||||
m_ui->contentTreeView->header()->restoreState(m_headerState);
|
m_ui->contentTreeView->header()->restoreState(m_storeTreeHeaderState);
|
||||||
|
|
||||||
// Hide useless columns after loading the header state
|
// Hide useless columns after loading the header state
|
||||||
m_ui->contentTreeView->hideColumn(PROGRESS);
|
m_ui->contentTreeView->hideColumn(PROGRESS);
|
||||||
|
@ -108,16 +108,18 @@ private:
|
|||||||
void showEvent(QShowEvent *event) override;
|
void showEvent(QShowEvent *event) override;
|
||||||
|
|
||||||
Ui::AddNewTorrentDialog *m_ui;
|
Ui::AddNewTorrentDialog *m_ui;
|
||||||
TorrentContentFilterModel *m_contentModel;
|
TorrentContentFilterModel *m_contentModel = nullptr;
|
||||||
PropListDelegate *m_contentDelegate;
|
PropListDelegate *m_contentDelegate = nullptr;
|
||||||
bool m_hasMetadata;
|
bool m_hasMetadata = false;
|
||||||
BitTorrent::MagnetUri m_magnetURI;
|
BitTorrent::MagnetUri m_magnetURI;
|
||||||
BitTorrent::TorrentInfo m_torrentInfo;
|
BitTorrent::TorrentInfo m_torrentInfo;
|
||||||
QByteArray m_headerState;
|
int m_oldIndex = 0;
|
||||||
int m_oldIndex;
|
|
||||||
std::unique_ptr<TorrentFileGuard> m_torrentGuard;
|
std::unique_ptr<TorrentFileGuard> m_torrentGuard;
|
||||||
BitTorrent::AddTorrentParams m_torrentParams;
|
BitTorrent::AddTorrentParams m_torrentParams;
|
||||||
|
|
||||||
SettingValue<QSize> m_storeDialogSize;
|
SettingValue<QSize> m_storeDialogSize;
|
||||||
SettingValue<QByteArray> m_storeSplitterState;
|
SettingValue<QByteArray> m_storeSplitterState;
|
||||||
|
SettingValue<QString> m_storeDefaultCategory;
|
||||||
|
SettingValue<bool> m_storeRememberLastSavePath;
|
||||||
|
CachedSettingValue<QByteArray> m_storeTreeHeaderState;
|
||||||
};
|
};
|
||||||
|
@ -56,12 +56,10 @@
|
|||||||
#include "base/bittorrent/session.h"
|
#include "base/bittorrent/session.h"
|
||||||
#include "base/bittorrent/sessionstatus.h"
|
#include "base/bittorrent/sessionstatus.h"
|
||||||
#include "base/global.h"
|
#include "base/global.h"
|
||||||
#include "base/logger.h"
|
|
||||||
#include "base/net/downloadmanager.h"
|
#include "base/net/downloadmanager.h"
|
||||||
#include "base/preferences.h"
|
#include "base/preferences.h"
|
||||||
#include "base/rss/rss_folder.h"
|
#include "base/rss/rss_folder.h"
|
||||||
#include "base/rss/rss_session.h"
|
#include "base/rss/rss_session.h"
|
||||||
#include "base/settingsstorage.h"
|
|
||||||
#include "base/utils/foreignapps.h"
|
#include "base/utils/foreignapps.h"
|
||||||
#include "base/utils/fs.h"
|
#include "base/utils/fs.h"
|
||||||
#include "base/utils/misc.h"
|
#include "base/utils/misc.h"
|
||||||
@ -105,34 +103,14 @@ using namespace std::chrono_literals;
|
|||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
#define SETTINGS_KEY(name) "GUI/" name
|
#define SETTINGS_KEY(name) "GUI/" name
|
||||||
|
#define EXECUTIONLOG_SETTINGS_KEY(name) (SETTINGS_KEY("Log/") name)
|
||||||
// ExecutionLog properties keys
|
#define NOTIFICATIONS_SETTINGS_KEY(name) (SETTINGS_KEY("Notifications/") 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) 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"));
|
|
||||||
|
|
||||||
const std::chrono::seconds PREVENT_SUSPEND_INTERVAL {60};
|
const std::chrono::seconds PREVENT_SUSPEND_INTERVAL {60};
|
||||||
#if !defined(Q_OS_MACOS)
|
#if !defined(Q_OS_MACOS)
|
||||||
const int TIME_TRAY_BALLOON = 5000;
|
const int TIME_TRAY_BALLOON = 5000;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// just a shortcut
|
|
||||||
inline SettingsStorage *settings()
|
|
||||||
{
|
|
||||||
return SettingsStorage::instance();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isTorrentLink(const QString &str)
|
bool isTorrentLink(const QString &str)
|
||||||
{
|
{
|
||||||
return str.startsWith(QLatin1String("magnet:"), Qt::CaseInsensitive)
|
return str.startsWith(QLatin1String("magnet:"), Qt::CaseInsensitive)
|
||||||
@ -145,10 +123,14 @@ namespace
|
|||||||
MainWindow::MainWindow(QWidget *parent)
|
MainWindow::MainWindow(QWidget *parent)
|
||||||
: QMainWindow(parent)
|
: QMainWindow(parent)
|
||||||
, m_ui(new Ui::MainWindow)
|
, m_ui(new Ui::MainWindow)
|
||||||
, m_posInitialized(false)
|
, m_storeExecutionLogEnabled(EXECUTIONLOG_SETTINGS_KEY("Enabled"))
|
||||||
, m_forceExit(false)
|
, m_storeDownloadTrackerFavicon(SETTINGS_KEY("DownloadTrackerFavicon"))
|
||||||
, m_unlockDlgShowing(false)
|
, m_storeNotificationEnabled(NOTIFICATIONS_SETTINGS_KEY("Enabled"))
|
||||||
, m_hasPython(false)
|
, 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);
|
m_ui->setupUi(this);
|
||||||
|
|
||||||
@ -358,11 +340,11 @@ MainWindow::MainWindow(QWidget *parent)
|
|||||||
m_ui->actionSearchWidget->setChecked(pref->isSearchEnabled());
|
m_ui->actionSearchWidget->setChecked(pref->isSearchEnabled());
|
||||||
m_ui->actionExecutionLogs->setChecked(isExecutionLogEnabled());
|
m_ui->actionExecutionLogs->setChecked(isExecutionLogEnabled());
|
||||||
|
|
||||||
Log::MsgTypes flags(executionLogMsgTypes());
|
const Log::MsgTypes flags = executionLogMsgTypes();
|
||||||
m_ui->actionNormalMessages->setChecked(flags & Log::NORMAL);
|
m_ui->actionNormalMessages->setChecked(flags.testFlag(Log::NORMAL));
|
||||||
m_ui->actionInformationMessages->setChecked(flags & Log::INFO);
|
m_ui->actionInformationMessages->setChecked(flags.testFlag(Log::INFO));
|
||||||
m_ui->actionWarningMessages->setChecked(flags & Log::WARNING);
|
m_ui->actionWarningMessages->setChecked(flags.testFlag(Log::WARNING));
|
||||||
m_ui->actionCriticalMessages->setChecked(flags & Log::CRITICAL);
|
m_ui->actionCriticalMessages->setChecked(flags.testFlag(Log::CRITICAL));
|
||||||
|
|
||||||
displayRSSTab(m_ui->actionRSSReader->isChecked());
|
displayRSSTab(m_ui->actionRSSReader->isChecked());
|
||||||
on_actionExecutionLogs_triggered(m_ui->actionExecutionLogs->isChecked());
|
on_actionExecutionLogs_triggered(m_ui->actionExecutionLogs->isChecked());
|
||||||
@ -485,68 +467,66 @@ MainWindow::~MainWindow()
|
|||||||
|
|
||||||
bool MainWindow::isExecutionLogEnabled() const
|
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
|
return m_storeExecutionLogTypes;
|
||||||
// -1 is considered the portable way to achieve that
|
|
||||||
return settings()->loadValue(KEY_EXECUTIONLOG_TYPES, -1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::setExecutionLogMsgTypes(const int value)
|
void MainWindow::setExecutionLogMsgTypes(const Log::MsgTypes value)
|
||||||
{
|
{
|
||||||
m_executionLog->setMessageTypes(static_cast<Log::MsgTypes>(value));
|
m_executionLog->setMessageTypes(value);
|
||||||
settings()->storeValue(KEY_EXECUTIONLOG_TYPES, value);
|
m_storeExecutionLogTypes = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MainWindow::isNotificationsEnabled() const
|
bool MainWindow::isNotificationsEnabled() const
|
||||||
{
|
{
|
||||||
return settings()->loadValue(KEY_NOTIFICATIONS_ENABLED, true);
|
return m_storeNotificationEnabled.get(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::setNotificationsEnabled(bool value)
|
void MainWindow::setNotificationsEnabled(bool value)
|
||||||
{
|
{
|
||||||
settings()->storeValue(KEY_NOTIFICATIONS_ENABLED, value);
|
m_storeNotificationEnabled = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MainWindow::isTorrentAddedNotificationsEnabled() const
|
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)
|
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) && defined(QT_DBUS_LIB)
|
||||||
int MainWindow::getNotificationTimeout() const
|
int MainWindow::getNotificationTimeout() const
|
||||||
{
|
{
|
||||||
return settings()->loadValue(KEY_NOTIFICATION_TIMEOUT, -1);
|
return m_storeNotificationTimeOut.get(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::setNotificationTimeout(const int value)
|
void MainWindow::setNotificationTimeout(const int value)
|
||||||
{
|
{
|
||||||
settings()->storeValue(KEY_NOTIFICATION_TIMEOUT, value);
|
m_storeNotificationTimeOut = value;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool MainWindow::isDownloadTrackerFavicon() const
|
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);
|
m_transferListFiltersWidget->setDownloadTrackerFavicon(value);
|
||||||
settings()->storeValue(KEY_DOWNLOAD_TRACKER_FAVICON, value);
|
m_storeDownloadTrackerFavicon = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::addToolbarContextMenu()
|
void MainWindow::addToolbarContextMenu()
|
||||||
@ -2005,7 +1985,7 @@ void MainWindow::on_actionExecutionLogs_triggered(bool checked)
|
|||||||
if (checked)
|
if (checked)
|
||||||
{
|
{
|
||||||
Q_ASSERT(!m_executionLog);
|
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
|
#ifdef Q_OS_MACOS
|
||||||
m_tabs->addTab(m_executionLog, tr("Execution Log"));
|
m_tabs->addTab(m_executionLog, tr("Execution Log"));
|
||||||
#else
|
#else
|
||||||
@ -2025,43 +2005,39 @@ void MainWindow::on_actionExecutionLogs_triggered(bool checked)
|
|||||||
setExecutionLogEnabled(checked);
|
setExecutionLogEnabled(checked);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_actionNormalMessages_triggered(bool checked)
|
void MainWindow::on_actionNormalMessages_triggered(const bool checked)
|
||||||
{
|
{
|
||||||
if (!m_executionLog)
|
if (!m_executionLog)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Log::MsgTypes flags(executionLogMsgTypes());
|
const Log::MsgTypes flags = executionLogMsgTypes().setFlag(Log::NORMAL, checked);
|
||||||
checked ? (flags |= Log::NORMAL) : (flags &= ~Log::NORMAL);
|
|
||||||
setExecutionLogMsgTypes(flags);
|
setExecutionLogMsgTypes(flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_actionInformationMessages_triggered(bool checked)
|
void MainWindow::on_actionInformationMessages_triggered(const bool checked)
|
||||||
{
|
{
|
||||||
if (!m_executionLog)
|
if (!m_executionLog)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Log::MsgTypes flags(executionLogMsgTypes());
|
const Log::MsgTypes flags = executionLogMsgTypes().setFlag(Log::INFO, checked);
|
||||||
checked ? (flags |= Log::INFO) : (flags &= ~Log::INFO);
|
|
||||||
setExecutionLogMsgTypes(flags);
|
setExecutionLogMsgTypes(flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_actionWarningMessages_triggered(bool checked)
|
void MainWindow::on_actionWarningMessages_triggered(const bool checked)
|
||||||
{
|
{
|
||||||
if (!m_executionLog)
|
if (!m_executionLog)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Log::MsgTypes flags(executionLogMsgTypes());
|
const Log::MsgTypes flags = executionLogMsgTypes().setFlag(Log::WARNING, checked);
|
||||||
checked ? (flags |= Log::WARNING) : (flags &= ~Log::WARNING);
|
|
||||||
setExecutionLogMsgTypes(flags);
|
setExecutionLogMsgTypes(flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_actionCriticalMessages_triggered(bool checked)
|
void MainWindow::on_actionCriticalMessages_triggered(const bool checked)
|
||||||
{
|
{
|
||||||
if (!m_executionLog)
|
if (!m_executionLog)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Log::MsgTypes flags(executionLogMsgTypes());
|
const Log::MsgTypes flags = executionLogMsgTypes().setFlag(Log::CRITICAL, checked);
|
||||||
checked ? (flags |= Log::CRITICAL) : (flags &= ~Log::CRITICAL);
|
|
||||||
setExecutionLogMsgTypes(flags);
|
setExecutionLogMsgTypes(flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,6 +36,8 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "base/bittorrent/torrent.h"
|
#include "base/bittorrent/torrent.h"
|
||||||
|
#include "base/logger.h"
|
||||||
|
#include "base/settingvalue.h"
|
||||||
|
|
||||||
class QCloseEvent;
|
class QCloseEvent;
|
||||||
class QFileSystemWatcher;
|
class QFileSystemWatcher;
|
||||||
@ -85,8 +87,8 @@ public:
|
|||||||
// ExecutionLog properties
|
// ExecutionLog properties
|
||||||
bool isExecutionLogEnabled() const;
|
bool isExecutionLogEnabled() const;
|
||||||
void setExecutionLogEnabled(bool value);
|
void setExecutionLogEnabled(bool value);
|
||||||
int executionLogMsgTypes() const;
|
Log::MsgTypes executionLogMsgTypes() const;
|
||||||
void setExecutionLogMsgTypes(int value);
|
void setExecutionLogMsgTypes(Log::MsgTypes value);
|
||||||
|
|
||||||
// Notifications properties
|
// Notifications properties
|
||||||
bool isNotificationsEnabled() const;
|
bool isNotificationsEnabled() const;
|
||||||
@ -217,7 +219,7 @@ private:
|
|||||||
|
|
||||||
QFileSystemWatcher *m_executableWatcher;
|
QFileSystemWatcher *m_executableWatcher;
|
||||||
// GUI related
|
// GUI related
|
||||||
bool m_posInitialized;
|
bool m_posInitialized = false;
|
||||||
QPointer<QTabWidget> m_tabs;
|
QPointer<QTabWidget> m_tabs;
|
||||||
QPointer<StatusBar> m_statusBar;
|
QPointer<StatusBar> m_statusBar;
|
||||||
QPointer<OptionsDialog> m_options;
|
QPointer<OptionsDialog> m_options;
|
||||||
@ -234,9 +236,9 @@ private:
|
|||||||
TransferListFiltersWidget *m_transferListFiltersWidget;
|
TransferListFiltersWidget *m_transferListFiltersWidget;
|
||||||
PropertiesWidget *m_propertiesWidget;
|
PropertiesWidget *m_propertiesWidget;
|
||||||
bool m_displaySpeedInTitle;
|
bool m_displaySpeedInTitle;
|
||||||
bool m_forceExit;
|
bool m_forceExit = false;
|
||||||
bool m_uiLocked;
|
bool m_uiLocked;
|
||||||
bool m_unlockDlgShowing;
|
bool m_unlockDlgShowing = false;
|
||||||
LineEdit *m_searchFilter;
|
LineEdit *m_searchFilter;
|
||||||
QAction *m_searchFilterAction;
|
QAction *m_searchFilterAction;
|
||||||
// Widgets
|
// Widgets
|
||||||
@ -249,9 +251,19 @@ private:
|
|||||||
// Power Management
|
// Power Management
|
||||||
PowerManagement *m_pwr;
|
PowerManagement *m_pwr;
|
||||||
QTimer *m_preventTimer;
|
QTimer *m_preventTimer;
|
||||||
bool m_hasPython;
|
bool m_hasPython = false;
|
||||||
QMenu *m_toolbarMenu;
|
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)
|
#if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
|
||||||
void checkProgramUpdate(bool invokedByUser);
|
void checkProgramUpdate(bool invokedByUser);
|
||||||
void handleUpdateCheckFinished(ProgramUpdater *updater, bool invokedByUser);
|
void handleUpdateCheckFinished(ProgramUpdater *updater, bool invokedByUser);
|
||||||
|
@ -33,7 +33,6 @@
|
|||||||
|
|
||||||
#include "base/bittorrent/session.h"
|
#include "base/bittorrent/session.h"
|
||||||
#include "base/global.h"
|
#include "base/global.h"
|
||||||
#include "base/settingsstorage.h"
|
|
||||||
#include "base/utils/fs.h"
|
#include "base/utils/fs.h"
|
||||||
#include "ui_watchedfolderoptionsdialog.h"
|
#include "ui_watchedfolderoptionsdialog.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
Loading…
Reference in New Issue
Block a user