diff --git a/src/gui/generalsettings.cpp b/src/gui/generalsettings.cpp index dbc5d8051d..d21e6e531c 100644 --- a/src/gui/generalsettings.cpp +++ b/src/gui/generalsettings.cpp @@ -324,18 +324,25 @@ void GeneralSettings::loadUpdateChannelsList() { if (cfgFile.serverHasValidSubscription()) { _ui->updateChannel->hide(); _ui->updateChannelLabel->hide(); + _ui->restoreUpdateChannelButton->hide(); return; } const auto validUpdateChannels = cfgFile.validUpdateChannels(); + const auto currentUpdateChannel = cfgFile.currentUpdateChannel(); if (_currentUpdateChannelList.isEmpty() || _currentUpdateChannelList != validUpdateChannels){ _currentUpdateChannelList = validUpdateChannels; _ui->updateChannel->clear(); _ui->updateChannel->addItems(_currentUpdateChannelList); - const auto currentUpdateChannelIndex = _currentUpdateChannelList.indexOf(cfgFile.currentUpdateChannel()); + const auto currentUpdateChannelIndex = _currentUpdateChannelList.indexOf(currentUpdateChannel); _ui->updateChannel->setCurrentIndex(currentUpdateChannelIndex != -1 ? currentUpdateChannelIndex : 0); connect(_ui->updateChannel, &QComboBox::currentTextChanged, this, &GeneralSettings::slotUpdateChannelChanged); } + + const auto defaultUpdateChannel = cfgFile.defaultUpdateChannel(); + _ui->restoreUpdateChannelButton->setText(tr("Restore to &%1").arg(defaultUpdateChannel)); + _ui->restoreUpdateChannelButton->setEnabled(currentUpdateChannel != defaultUpdateChannel); + connect(_ui->restoreUpdateChannelButton, &QPushButton::clicked, this, &GeneralSettings::slotRestoreUpdateChannel); } void GeneralSettings::slotUpdateInfo() @@ -392,28 +399,43 @@ void GeneralSettings::slotUpdateInfo() #endif } +void GeneralSettings::setAndCheckNewUpdateChannel(const QString &newChannel) { + ConfigFile().setUpdateChannel(newChannel); + if (auto updater = qobject_cast(Updater::instance())) { + updater->setUpdateUrl(Updater::updateUrl()); + updater->checkForUpdate(); + } +#if defined(Q_OS_MAC) && defined(HAVE_SPARKLE) + else if (auto updater = qobject_cast(Updater::instance())) { + updater->setUpdateUrl(Updater::updateUrl()); + updater->checkForUpdate(); + } +#endif +} + +QString GeneralSettings::updateChannelToLocalized(const QString &channel) const +{ + if (channel == QStringLiteral("stable")) { + return tr("stable"); + } + + if (channel == QStringLiteral("beta")) { + return tr("beta"); + } + + if (channel == QStringLiteral("daily")) { + return tr("daily"); + } + + if (channel == QStringLiteral("enterprise")) { + return tr("enterprise"); + } + + return QString{}; +} + void GeneralSettings::slotUpdateChannelChanged() { - const auto updateChannelToLocalized = [](const QString &channel) { - if (channel == QStringLiteral("stable")) { - return tr("stable"); - } - - if (channel == QStringLiteral("beta")) { - return tr("beta"); - } - - if (channel == QStringLiteral("daily")) { - return tr("daily"); - } - - if (channel == QStringLiteral("enterprise")) { - return tr("enterprise"); - } - - return QString{}; - }; - const auto updateChannelFromLocalized = [](const int index) { switch(index) { case 1: @@ -431,11 +453,19 @@ void GeneralSettings::slotUpdateChannelChanged() }; ConfigFile configFile; - const auto channel = updateChannelFromLocalized(_ui->updateChannel->currentIndex()); - if (channel == configFile.currentUpdateChannel()) { + const auto newChannel = updateChannelFromLocalized(_ui->updateChannel->currentIndex()); + const auto currentUpdateChannel = configFile.currentUpdateChannel(); + if (newChannel == currentUpdateChannel) { return; } + if (newChannel == configFile.defaultUpdateChannel()) { + restoreUpdateChannel(); + return; + } + + _ui->restoreUpdateChannelButton->setEnabled(true); + const auto nonEnterpriseOptions = tr("- beta: contains versions with new features that may not be tested thoroughly\n" "- daily: contains versions created daily only for testing and development\n" "\n" @@ -457,22 +487,12 @@ void GeneralSettings::slotUpdateChannelChanged() this); const auto acceptButton = msgBox->addButton(tr("Change update channel"), QMessageBox::AcceptRole); msgBox->addButton(tr("Cancel"), QMessageBox::RejectRole); - connect(msgBox, &QMessageBox::finished, msgBox, [this, channel, msgBox, acceptButton, updateChannelToLocalized] { + connect(msgBox, &QMessageBox::finished, msgBox, [this, newChannel, currentUpdateChannel, msgBox, acceptButton] { msgBox->deleteLater(); if (msgBox->clickedButton() == acceptButton) { - ConfigFile().setUpdateChannel(channel); - if (auto updater = qobject_cast(Updater::instance())) { - updater->setUpdateUrl(Updater::updateUrl()); - updater->checkForUpdate(); - } -#if defined(Q_OS_MAC) && defined(HAVE_SPARKLE) - else if (auto updater = qobject_cast(Updater::instance())) { - updater->setUpdateUrl(Updater::updateUrl()); - updater->checkForUpdate(); - } -#endif + updateChannelToLocalized(newChannel); } else { - _ui->updateChannel->setCurrentText(updateChannelToLocalized(ConfigFile().currentUpdateChannel())); + _ui->updateChannel->setCurrentText(updateChannelToLocalized(currentUpdateChannel)); } }); msgBox->open(); @@ -502,6 +522,19 @@ void GeneralSettings::slotToggleAutoUpdateCheck() bool isChecked = _ui->autoCheckForUpdatesCheckBox->isChecked(); cfgFile.setAutoUpdateCheck(isChecked, QString()); } + +void GeneralSettings::restoreUpdateChannel() +{ + const auto defaultUpdateChannel = ConfigFile().defaultUpdateChannel(); + _ui->restoreUpdateChannelButton->setEnabled(false); + _ui->updateChannel->setCurrentText(updateChannelToLocalized(defaultUpdateChannel)); + setAndCheckNewUpdateChannel(defaultUpdateChannel); +} + +void GeneralSettings::slotRestoreUpdateChannel() +{ + restoreUpdateChannel(); +} #endif // defined(BUILD_UPDATER) void GeneralSettings::saveMiscSettings() diff --git a/src/gui/generalsettings.h b/src/gui/generalsettings.h index f971e97469..c8782a5857 100644 --- a/src/gui/generalsettings.h +++ b/src/gui/generalsettings.h @@ -38,6 +38,9 @@ public slots: void slotStyleChanged(); #if defined(BUILD_UPDATER) void loadUpdateChannelsList(); + QString updateChannelToLocalized(const QString &channel) const; + void setAndCheckNewUpdateChannel(const QString &newChannel); + void restoreUpdateChannel(); #endif private slots: @@ -58,6 +61,7 @@ private slots: void slotUpdateChannelChanged(); void slotUpdateCheckNow(); void slotToggleAutoUpdateCheck(); + void slotRestoreUpdateChannel(); #endif private: diff --git a/src/gui/generalsettings.ui b/src/gui/generalsettings.ui index 534f17e193..9ae68de1b6 100644 --- a/src/gui/generalsettings.ui +++ b/src/gui/generalsettings.ui @@ -446,6 +446,16 @@ + + + + false + + + Restore &Default + + + diff --git a/src/gui/updater/ocupdater.cpp b/src/gui/updater/ocupdater.cpp index febe136816..4d43357fa8 100644 --- a/src/gui/updater/ocupdater.cpp +++ b/src/gui/updater/ocupdater.cpp @@ -164,8 +164,15 @@ QString OCUpdater::statusString(UpdateStatusStringFormat format) const return tr("Update status is unknown: Did not check for new updates."); case UpToDate: // fall through - default: - return tr("No updates available. Your installation is at the latest version."); + default: { + ConfigFile configFile; + if (configFile.serverHasValidSubscription()) { + return tr("You are using the %1 update channel. Your installation is the latest version.") + .arg(configFile.currentUpdateChannel()); + } + + return tr("No updates available. Your installation is the latest version."); + } } }