Merge pull request #7967 from nextcloud/feature/restoredefaults

feat(generalsettings): add option to restore default update channel.
This commit is contained in:
Matthieu Gallien 2025-05-26 14:55:39 +02:00 committed by GitHub
commit 63f39a6bad
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 92 additions and 38 deletions

View File

@ -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<OCUpdater *>(Updater::instance())) {
updater->setUpdateUrl(Updater::updateUrl());
updater->checkForUpdate();
}
#if defined(Q_OS_MAC) && defined(HAVE_SPARKLE)
else if (auto updater = qobject_cast<SparkleUpdater *>(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<OCUpdater *>(Updater::instance())) {
updater->setUpdateUrl(Updater::updateUrl());
updater->checkForUpdate();
}
#if defined(Q_OS_MAC) && defined(HAVE_SPARKLE)
else if (auto updater = qobject_cast<SparkleUpdater *>(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()

View File

@ -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:

View File

@ -446,6 +446,16 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="restoreUpdateChannelButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Restore &amp;Default</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">

View File

@ -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.");
}
}
}