mirror of
https://github.com/c0re100/qBittorrent-Enhanced-Edition.git
synced 2025-01-08 11:57:51 +08:00
Store enum type in settings directly
Affected settings will be migrated to new keys so nothing should break. PR #15800.
This commit is contained in:
parent
ab5605d54b
commit
e3fe66d3ec
@ -33,6 +33,7 @@
|
||||
|
||||
#include "base/bittorrent/torrentcontentlayout.h"
|
||||
#include "base/logger.h"
|
||||
#include "base/preferences.h"
|
||||
#include "base/profile.h"
|
||||
#include "base/settingsstorage.h"
|
||||
#include "base/utils/fs.h"
|
||||
@ -110,6 +111,120 @@ namespace
|
||||
settingsStorage->removeValue(oldKey);
|
||||
}
|
||||
}
|
||||
|
||||
void upgradeSchedulerDaysSettings()
|
||||
{
|
||||
auto *settingsStorage = SettingsStorage::instance();
|
||||
const auto key = QString::fromLatin1("Preferences/Scheduler/days");
|
||||
const auto value = settingsStorage->loadValue<QString>(key);
|
||||
|
||||
bool ok = false;
|
||||
const auto number = value.toInt(&ok);
|
||||
|
||||
if (ok)
|
||||
{
|
||||
switch (number)
|
||||
{
|
||||
case 0:
|
||||
settingsStorage->storeValue(key, Scheduler::Days::EveryDay);
|
||||
break;
|
||||
case 1:
|
||||
settingsStorage->storeValue(key, Scheduler::Days::Weekday);
|
||||
break;
|
||||
case 2:
|
||||
settingsStorage->storeValue(key, Scheduler::Days::Weekend);
|
||||
break;
|
||||
case 3:
|
||||
settingsStorage->storeValue(key, Scheduler::Days::Monday);
|
||||
break;
|
||||
case 4:
|
||||
settingsStorage->storeValue(key, Scheduler::Days::Tuesday);
|
||||
break;
|
||||
case 5:
|
||||
settingsStorage->storeValue(key, Scheduler::Days::Wednesday);
|
||||
break;
|
||||
case 6:
|
||||
settingsStorage->storeValue(key, Scheduler::Days::Thursday);
|
||||
break;
|
||||
case 7:
|
||||
settingsStorage->storeValue(key, Scheduler::Days::Friday);
|
||||
break;
|
||||
case 8:
|
||||
settingsStorage->storeValue(key, Scheduler::Days::Saturday);
|
||||
break;
|
||||
case 9:
|
||||
settingsStorage->storeValue(key, Scheduler::Days::Sunday);
|
||||
break;
|
||||
default:
|
||||
LogMsg(QObject::tr("Invalid value found in configuration file, reverting it to default. Key: \"%1\". Invalid value: \"%2\".")
|
||||
.arg(key, QString::number(number)), Log::WARNING);
|
||||
settingsStorage->removeValue(key);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void upgradeDNSServiceSettings()
|
||||
{
|
||||
auto *settingsStorage = SettingsStorage::instance();
|
||||
const auto key = QString::fromLatin1("Preferences/DynDNS/Service");
|
||||
const auto value = settingsStorage->loadValue<QString>(key);
|
||||
|
||||
bool ok = false;
|
||||
const auto number = value.toInt(&ok);
|
||||
|
||||
if (ok)
|
||||
{
|
||||
switch (number)
|
||||
{
|
||||
case -1:
|
||||
settingsStorage->storeValue(key, DNS::Service::None);
|
||||
break;
|
||||
case 0:
|
||||
settingsStorage->storeValue(key, DNS::Service::DynDNS);
|
||||
break;
|
||||
case 1:
|
||||
settingsStorage->storeValue(key, DNS::Service::NoIP);
|
||||
break;
|
||||
default:
|
||||
LogMsg(QObject::tr("Invalid value found in configuration file, reverting it to default. Key: \"%1\". Invalid value: \"%2\".")
|
||||
.arg(key, QString::number(number)), Log::WARNING);
|
||||
settingsStorage->removeValue(key);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void upgradeTrayIconStyleSettings()
|
||||
{
|
||||
auto *settingsStorage = SettingsStorage::instance();
|
||||
const auto key = QString::fromLatin1("Preferences/Advanced/TrayIconStyle");
|
||||
const auto value = settingsStorage->loadValue<QString>(key);
|
||||
|
||||
bool ok = false;
|
||||
const auto number = value.toInt(&ok);
|
||||
|
||||
if (ok)
|
||||
{
|
||||
switch (number)
|
||||
{
|
||||
case 0:
|
||||
settingsStorage->storeValue(key, TrayIcon::Style::Normal);
|
||||
break;
|
||||
case 1:
|
||||
settingsStorage->storeValue(key, TrayIcon::Style::MonoDark);
|
||||
break;
|
||||
case 2:
|
||||
settingsStorage->storeValue(key, TrayIcon::Style::MonoLight);
|
||||
break;
|
||||
default:
|
||||
LogMsg(QObject::tr("Invalid value found in configuration file, reverting it to default. Key: \"%1\". Invalid value: \"%2\".")
|
||||
.arg(key, QString::number(number)), Log::WARNING);
|
||||
settingsStorage->removeValue(key);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool upgrade(const bool /*ask*/)
|
||||
@ -117,6 +232,9 @@ bool upgrade(const bool /*ask*/)
|
||||
exportWebUIHttpsFiles();
|
||||
upgradeTorrentContentLayout();
|
||||
upgradeListenPortSettings();
|
||||
upgradeSchedulerDaysSettings();
|
||||
upgradeDNSServiceSettings();
|
||||
upgradeTrayIconStyleSettings();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -61,7 +61,7 @@ bool BandwidthScheduler::isTimeForAlternative() const
|
||||
QTime start = pref->getSchedulerStartTime();
|
||||
QTime end = pref->getSchedulerEndTime();
|
||||
const QTime now = QTime::currentTime();
|
||||
const int schedulerDays = pref->getSchedulerDays();
|
||||
const Scheduler::Days schedulerDays = pref->getSchedulerDays();
|
||||
const int day = QDate::currentDate().dayOfWeek();
|
||||
bool alternative = false;
|
||||
|
||||
@ -75,20 +75,34 @@ bool BandwidthScheduler::isTimeForAlternative() const
|
||||
{
|
||||
switch (schedulerDays)
|
||||
{
|
||||
case EVERY_DAY:
|
||||
case Scheduler::Days::EveryDay:
|
||||
alternative = !alternative;
|
||||
break;
|
||||
case WEEK_ENDS:
|
||||
case Scheduler::Days::Monday:
|
||||
case Scheduler::Days::Tuesday:
|
||||
case Scheduler::Days::Wednesday:
|
||||
case Scheduler::Days::Thursday:
|
||||
case Scheduler::Days::Friday:
|
||||
case Scheduler::Days::Saturday:
|
||||
case Scheduler::Days::Sunday:
|
||||
{
|
||||
const int offset = static_cast<int>(Scheduler::Days::Monday) - 1;
|
||||
const int dayOfWeek = static_cast<int>(schedulerDays) - offset;
|
||||
if (day == dayOfWeek)
|
||||
alternative = !alternative;
|
||||
}
|
||||
break;
|
||||
case Scheduler::Days::Weekday:
|
||||
if ((day >= 1) && (day <= 5))
|
||||
alternative = !alternative;
|
||||
break;
|
||||
case Scheduler::Days::Weekend:
|
||||
if ((day == 6) || (day == 7))
|
||||
alternative = !alternative;
|
||||
break;
|
||||
case WEEK_DAYS:
|
||||
if ((day != 6) && (day != 7))
|
||||
alternative = !alternative;
|
||||
break;
|
||||
default:
|
||||
if (day == (schedulerDays - 2))
|
||||
alternative = !alternative;
|
||||
Q_ASSERT(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@ using namespace Net;
|
||||
DNSUpdater::DNSUpdater(QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_state(OK)
|
||||
, m_service(DNS::NONE)
|
||||
, m_service(DNS::Service::None)
|
||||
{
|
||||
updateCredentials();
|
||||
|
||||
@ -143,15 +143,16 @@ QString DNSUpdater::getUpdateUrl() const
|
||||
// Service specific
|
||||
switch (m_service)
|
||||
{
|
||||
case DNS::DYNDNS:
|
||||
case DNS::Service::DynDNS:
|
||||
url.setHost("members.dyndns.org");
|
||||
break;
|
||||
case DNS::NOIP:
|
||||
case DNS::Service::NoIP:
|
||||
url.setHost("dynupdate.no-ip.com");
|
||||
break;
|
||||
default:
|
||||
qWarning() << "Unrecognized Dynamic DNS service!";
|
||||
Q_ASSERT(0);
|
||||
Q_ASSERT(false);
|
||||
break;
|
||||
}
|
||||
url.setPath("/nic/update");
|
||||
|
||||
@ -295,16 +296,17 @@ void DNSUpdater::updateCredentials()
|
||||
}
|
||||
}
|
||||
|
||||
QUrl DNSUpdater::getRegistrationUrl(const int service)
|
||||
QUrl DNSUpdater::getRegistrationUrl(const DNS::Service service)
|
||||
{
|
||||
switch (service)
|
||||
{
|
||||
case DNS::DYNDNS:
|
||||
case DNS::Service::DynDNS:
|
||||
return {"https://account.dyn.com/entrance/"};
|
||||
case DNS::NOIP:
|
||||
case DNS::Service::NoIP:
|
||||
return {"https://www.noip.com/remote-access"};
|
||||
default:
|
||||
Q_ASSERT(0);
|
||||
Q_ASSERT(false);
|
||||
break;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ namespace Net
|
||||
explicit DNSUpdater(QObject *parent = nullptr);
|
||||
~DNSUpdater();
|
||||
|
||||
static QUrl getRegistrationUrl(int service);
|
||||
static QUrl getRegistrationUrl(DNS::Service service);
|
||||
|
||||
public slots:
|
||||
void updateCredentials();
|
||||
|
@ -493,14 +493,14 @@ void Preferences::setSchedulerEndTime(const QTime &time)
|
||||
setValue("Preferences/Scheduler/end_time", time);
|
||||
}
|
||||
|
||||
SchedulerDays Preferences::getSchedulerDays() const
|
||||
Scheduler::Days Preferences::getSchedulerDays() const
|
||||
{
|
||||
return static_cast<SchedulerDays>(value("Preferences/Scheduler/days", EVERY_DAY).toInt());
|
||||
return SettingsStorage::instance()->loadValue("Preferences/Scheduler/days", Scheduler::Days::EveryDay);
|
||||
}
|
||||
|
||||
void Preferences::setSchedulerDays(const SchedulerDays days)
|
||||
void Preferences::setSchedulerDays(const Scheduler::Days days)
|
||||
{
|
||||
setValue("Preferences/Scheduler/days", static_cast<int>(days));
|
||||
SettingsStorage::instance()->storeValue("Preferences/Scheduler/days", days);
|
||||
}
|
||||
|
||||
// Search
|
||||
@ -816,12 +816,12 @@ void Preferences::setDynDNSEnabled(const bool enabled)
|
||||
|
||||
DNS::Service Preferences::getDynDNSService() const
|
||||
{
|
||||
return DNS::Service(value("Preferences/DynDNS/Service", DNS::DYNDNS).toInt());
|
||||
return SettingsStorage::instance()->loadValue("Preferences/DynDNS/Service", DNS::Service::DynDNS);
|
||||
}
|
||||
|
||||
void Preferences::setDynDNSService(const int service)
|
||||
void Preferences::setDynDNSService(const DNS::Service service)
|
||||
{
|
||||
setValue("Preferences/DynDNS/Service", service);
|
||||
SettingsStorage::instance()->storeValue("Preferences/DynDNS/Service", service);
|
||||
}
|
||||
|
||||
QString Preferences::getDynDomainName() const
|
||||
@ -1211,12 +1211,12 @@ void Preferences::setConfirmRemoveAllTags(const bool enabled)
|
||||
#ifndef Q_OS_MACOS
|
||||
TrayIcon::Style Preferences::trayIconStyle() const
|
||||
{
|
||||
return TrayIcon::Style(value("Preferences/Advanced/TrayIconStyle", TrayIcon::NORMAL).toInt());
|
||||
return SettingsStorage::instance()->loadValue("Preferences/Advanced/TrayIconStyle", TrayIcon::Style::Normal);
|
||||
}
|
||||
|
||||
void Preferences::setTrayIconStyle(const TrayIcon::Style style)
|
||||
{
|
||||
setValue("Preferences/Advanced/TrayIconStyle", style);
|
||||
SettingsStorage::instance()->storeValue("Preferences/Advanced/TrayIconStyle", style);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -29,6 +29,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <QtContainerFwd>
|
||||
#include <QtGlobal>
|
||||
#include <QVariant>
|
||||
@ -40,38 +41,50 @@ class QNetworkCookie;
|
||||
class QSize;
|
||||
class QTime;
|
||||
|
||||
enum SchedulerDays
|
||||
namespace Scheduler
|
||||
{
|
||||
EVERY_DAY,
|
||||
WEEK_DAYS,
|
||||
WEEK_ENDS,
|
||||
MON,
|
||||
TUE,
|
||||
WED,
|
||||
THU,
|
||||
FRI,
|
||||
SAT,
|
||||
SUN
|
||||
};
|
||||
Q_NAMESPACE
|
||||
|
||||
namespace TrayIcon
|
||||
{
|
||||
enum Style
|
||||
enum class Days : int
|
||||
{
|
||||
NORMAL = 0,
|
||||
MONO_DARK,
|
||||
MONO_LIGHT
|
||||
EveryDay = 0,
|
||||
Weekday = 1,
|
||||
Weekend = 2,
|
||||
Monday = 3,
|
||||
Tuesday = 4,
|
||||
Wednesday = 5,
|
||||
Thursday = 6,
|
||||
Friday = 7,
|
||||
Saturday = 8,
|
||||
Sunday = 9
|
||||
};
|
||||
Q_ENUM_NS(Days)
|
||||
}
|
||||
|
||||
namespace DNS
|
||||
{
|
||||
enum Service
|
||||
Q_NAMESPACE
|
||||
|
||||
enum class Service : int
|
||||
{
|
||||
DYNDNS,
|
||||
NOIP,
|
||||
NONE = -1
|
||||
DynDNS = 0,
|
||||
NoIP = 1,
|
||||
None = -1
|
||||
};
|
||||
Q_ENUM_NS(Service)
|
||||
}
|
||||
|
||||
namespace TrayIcon
|
||||
{
|
||||
Q_NAMESPACE
|
||||
|
||||
enum class Style : int
|
||||
{
|
||||
Normal = 0,
|
||||
MonoDark = 1,
|
||||
MonoLight = 2
|
||||
};
|
||||
Q_ENUM_NS(Style)
|
||||
}
|
||||
|
||||
class Preferences : public QObject
|
||||
@ -161,8 +174,8 @@ public:
|
||||
void setSchedulerStartTime(const QTime &time);
|
||||
QTime getSchedulerEndTime() const;
|
||||
void setSchedulerEndTime(const QTime &time);
|
||||
SchedulerDays getSchedulerDays() const;
|
||||
void setSchedulerDays(SchedulerDays days);
|
||||
Scheduler::Days getSchedulerDays() const;
|
||||
void setSchedulerDays(Scheduler::Days days);
|
||||
|
||||
// Search
|
||||
bool isSearchEnabled() const;
|
||||
@ -236,7 +249,7 @@ public:
|
||||
bool isDynDNSEnabled() const;
|
||||
void setDynDNSEnabled(bool enabled);
|
||||
DNS::Service getDynDNSService() const;
|
||||
void setDynDNSService(int service);
|
||||
void setDynDNSService(DNS::Service service);
|
||||
QString getDynDomainName() const;
|
||||
void setDynDomainName(const QString &name);
|
||||
QString getDynDNSUsername() const;
|
||||
|
@ -2080,11 +2080,11 @@ QIcon MainWindow::getSystrayIcon() const
|
||||
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS))
|
||||
switch (style)
|
||||
{
|
||||
case TrayIcon::NORMAL:
|
||||
case TrayIcon::Style::Normal:
|
||||
return QIcon::fromTheme(QLatin1String("qbittorrent-tray"));
|
||||
case TrayIcon::MONO_DARK:
|
||||
case TrayIcon::Style::MonoDark:
|
||||
return QIcon::fromTheme(QLatin1String("qbittorrent-tray-dark"));
|
||||
case TrayIcon::MONO_LIGHT:
|
||||
case TrayIcon::Style::MonoLight:
|
||||
return QIcon::fromTheme(QLatin1String("qbittorrent-tray-light"));
|
||||
default:
|
||||
break;
|
||||
@ -2092,11 +2092,11 @@ QIcon MainWindow::getSystrayIcon() const
|
||||
#else
|
||||
switch (style)
|
||||
{
|
||||
case TrayIcon::NORMAL:
|
||||
case TrayIcon::Style::Normal:
|
||||
return UIThemeManager::instance()->getIcon(QLatin1String("qbittorrent-tray"));
|
||||
case TrayIcon::MONO_DARK:
|
||||
case TrayIcon::Style::MonoDark:
|
||||
return UIThemeManager::instance()->getIcon(QLatin1String("qbittorrent-tray-dark"));
|
||||
case TrayIcon::MONO_LIGHT:
|
||||
case TrayIcon::Style::MonoLight:
|
||||
return UIThemeManager::instance()->getIcon(QLatin1String("qbittorrent-tray-light"));
|
||||
default:
|
||||
break;
|
||||
|
@ -783,7 +783,7 @@ void OptionsDialog::saveOptions()
|
||||
session->setIgnoreLimitsOnLAN(!m_ui->checkLimitLocalPeerRate->isChecked());
|
||||
pref->setSchedulerStartTime(m_ui->timeEditScheduleFrom->time());
|
||||
pref->setSchedulerEndTime(m_ui->timeEditScheduleTo->time());
|
||||
pref->setSchedulerDays(static_cast<SchedulerDays>(m_ui->comboBoxScheduleDays->currentIndex()));
|
||||
pref->setSchedulerDays(static_cast<Scheduler::Days>(m_ui->comboBoxScheduleDays->currentIndex()));
|
||||
session->setBandwidthSchedulerEnabled(m_ui->groupBoxSchedule->isChecked());
|
||||
|
||||
auto proxyConfigManager = Net::ProxyConfigurationManager::instance();
|
||||
@ -867,7 +867,7 @@ void OptionsDialog::saveOptions()
|
||||
pref->setWebUIHostHeaderValidationEnabled(m_ui->groupHostHeaderValidation->isChecked());
|
||||
// DynDNS
|
||||
pref->setDynDNSEnabled(m_ui->checkDynDNS->isChecked());
|
||||
pref->setDynDNSService(m_ui->comboDNSService->currentIndex());
|
||||
pref->setDynDNSService(static_cast<DNS::Service>(m_ui->comboDNSService->currentIndex()));
|
||||
pref->setDynDomainName(m_ui->domainNameTxt->text());
|
||||
pref->setDynDNSUsername(m_ui->DNSUsernameTxt->text());
|
||||
pref->setDynDNSPassword(m_ui->DNSPasswordTxt->text());
|
||||
@ -941,7 +941,7 @@ void OptionsDialog::loadOptions()
|
||||
{
|
||||
m_ui->checkMinimizeToSysTray->setChecked(pref->minimizeToTray());
|
||||
m_ui->checkCloseToSystray->setChecked(pref->closeToTray());
|
||||
m_ui->comboTrayIcon->setCurrentIndex(pref->trayIconStyle());
|
||||
m_ui->comboTrayIcon->setCurrentIndex(static_cast<int>(pref->trayIconStyle()));
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -1832,7 +1832,8 @@ void OptionsDialog::showConnectionTab()
|
||||
|
||||
void OptionsDialog::on_registerDNSBtn_clicked()
|
||||
{
|
||||
QDesktopServices::openUrl(Net::DNSUpdater::getRegistrationUrl(m_ui->comboDNSService->currentIndex()));
|
||||
const auto service = static_cast<DNS::Service>(m_ui->comboDNSService->currentIndex());
|
||||
QDesktopServices::openUrl(Net::DNSUpdater::getRegistrationUrl(service));
|
||||
}
|
||||
|
||||
void OptionsDialog::on_IpFilterRefreshBtn_clicked()
|
||||
|
@ -198,7 +198,7 @@ void AppController::preferencesAction()
|
||||
const QTime end_time = pref->getSchedulerEndTime();
|
||||
data["schedule_to_hour"] = end_time.hour();
|
||||
data["schedule_to_min"] = end_time.minute();
|
||||
data["scheduler_days"] = pref->getSchedulerDays();
|
||||
data["scheduler_days"] = static_cast<int>(pref->getSchedulerDays());
|
||||
|
||||
// Bittorrent
|
||||
// Privacy
|
||||
@ -264,7 +264,7 @@ void AppController::preferencesAction()
|
||||
data["web_ui_reverse_proxies_list"] = pref->getWebUITrustedReverseProxiesList();
|
||||
// Update my dynamic domain name
|
||||
data["dyndns_enabled"] = pref->isDynDNSEnabled();
|
||||
data["dyndns_service"] = pref->getDynDNSService();
|
||||
data["dyndns_service"] = static_cast<int>(pref->getDynDNSService());
|
||||
data["dyndns_username"] = pref->getDynDNSUsername();
|
||||
data["dyndns_password"] = pref->getDynDNSPassword();
|
||||
data["dyndns_domain"] = pref->getDynDomainName();
|
||||
@ -560,7 +560,7 @@ void AppController::setPreferencesAction()
|
||||
if (m.contains("schedule_to_hour") && m.contains("schedule_to_min"))
|
||||
pref->setSchedulerEndTime(QTime(m["schedule_to_hour"].toInt(), m["schedule_to_min"].toInt()));
|
||||
if (hasKey("scheduler_days"))
|
||||
pref->setSchedulerDays(SchedulerDays(it.value().toInt()));
|
||||
pref->setSchedulerDays(static_cast<Scheduler::Days>(it.value().toInt()));
|
||||
|
||||
// Bittorrent
|
||||
// Privacy
|
||||
@ -698,7 +698,7 @@ void AppController::setPreferencesAction()
|
||||
if (hasKey("dyndns_enabled"))
|
||||
pref->setDynDNSEnabled(it.value().toBool());
|
||||
if (hasKey("dyndns_service"))
|
||||
pref->setDynDNSService(it.value().toInt());
|
||||
pref->setDynDNSService(static_cast<DNS::Service>(it.value().toInt()));
|
||||
if (hasKey("dyndns_username"))
|
||||
pref->setDynDNSUsername(it.value().toString());
|
||||
if (hasKey("dyndns_password"))
|
||||
|
@ -282,7 +282,8 @@ namespace
|
||||
}
|
||||
break;
|
||||
default:
|
||||
Q_ASSERT(0);
|
||||
Q_ASSERT(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user