@@ -190,8 +190,6 @@ GeneralSettings::GeneralSettings(QWidget *parent)
190190 });
191191
192192 loadMiscSettings ();
193- // updater info now set in: customizeStyle
194- // slotUpdateInfo();
195193
196194 // misc
197195 connect (_ui->monoIconsCheckBox , &QAbstractButton::toggled, this , &GeneralSettings::saveMiscSettings);
@@ -281,13 +279,22 @@ void GeneralSettings::loadMiscSettings()
281279 _ui->stopExistingFolderNowBigSyncCheckBox ->setChecked (_ui->existingFolderLimitCheckBox ->isChecked () && cfgFile.stopSyncingExistingFoldersOverLimit ());
282280 _ui->newExternalStorage ->setChecked (cfgFile.confirmExternalStorage ());
283281 _ui->monoIconsCheckBox ->setChecked (cfgFile.monoIcons ());
282+
283+ #if defined(BUILD_UPDATER)
284+ auto validUpdateChannels = cfgFile.validUpdateChannels ();
285+ _ui->updateChannel ->addItems (validUpdateChannels);
286+ const auto currentUpdateChannelIndex = validUpdateChannels.indexOf (cfgFile.currentUpdateChannel ());
287+ _ui->updateChannel ->setCurrentIndex (currentUpdateChannelIndex != -1 ? currentUpdateChannelIndex : 0 );
288+ connect (_ui->updateChannel , &QComboBox::currentTextChanged, this , &GeneralSettings::slotUpdateChannelChanged);
289+ #endif
284290}
285291
286292#if defined(BUILD_UPDATER)
287293void GeneralSettings::slotUpdateInfo ()
288294{
295+ ConfigFile config;
289296 const auto updater = Updater::instance ();
290- if (ConfigFile () .skipUpdateCheck () || !updater) {
297+ if (config .skipUpdateCheck () || !updater) {
291298 // updater disabled on compile
292299 _ui->updatesContainer ->setVisible (false );
293300 return ;
@@ -297,32 +304,28 @@ void GeneralSettings::slotUpdateInfo()
297304 connect (_ui->updateButton ,
298305 &QAbstractButton::clicked,
299306 this ,
300-
301307 &GeneralSettings::slotUpdateCheckNow,
302308 Qt::UniqueConnection);
303309 connect (_ui->autoCheckForUpdatesCheckBox , &QAbstractButton::toggled, this ,
304310 &GeneralSettings::slotToggleAutoUpdateCheck, Qt::UniqueConnection);
305- _ui->autoCheckForUpdatesCheckBox ->setChecked (ConfigFile () .autoUpdateCheck ());
311+ _ui->autoCheckForUpdatesCheckBox ->setChecked (config .autoUpdateCheck ());
306312 }
307313
308314 // Note: the sparkle-updater is not an OCUpdater
309- auto * ocupdater = qobject_cast<OCUpdater *>(updater);
315+ const auto ocupdater = qobject_cast<OCUpdater *>(updater);
310316 if (ocupdater) {
311317 connect (ocupdater, &OCUpdater::downloadStateChanged, this , &GeneralSettings::slotUpdateInfo, Qt::UniqueConnection);
312318 connect (_ui->restartButton , &QAbstractButton::clicked, ocupdater, &OCUpdater::slotStartInstaller, Qt::UniqueConnection);
313- // connect(_ui->restartButton, &QAbstractButton::clicked, qApp, &QApplication::quit, Qt::UniqueConnection);
314319
315- QString status = ocupdater->statusString (OCUpdater::UpdateStatusStringFormat::Html);
320+ auto status = ocupdater->statusString (OCUpdater::UpdateStatusStringFormat::Html);
316321 Theme::replaceLinkColorStringBackgroundAware (status);
317322
318323 _ui->updateStateLabel ->setOpenExternalLinks (false );
319324 connect (_ui->updateStateLabel , &QLabel::linkActivated, this , [](const QString &link) {
320325 Utility::openBrowser (QUrl (link));
321326 });
322327 _ui->updateStateLabel ->setText (status);
323-
324328 _ui->restartButton ->setVisible (ocupdater->downloadState () == OCUpdater::DownloadComplete);
325-
326329 _ui->updateButton ->setEnabled (ocupdater->downloadState () != OCUpdater::CheckingServer &&
327330 ocupdater->downloadState () != OCUpdater::Downloading &&
328331 ocupdater->downloadState () != OCUpdater::DownloadComplete);
@@ -339,57 +342,55 @@ void GeneralSettings::slotUpdateInfo()
339342 _ui->updateButton ->setEnabled (enableUpdateButton);
340343 }
341344#endif
342-
343- // Channel selection
344- _ui->updateChannel ->setCurrentIndex (ConfigFile ().updateChannel () == " beta" ? 1 : 0 );
345- connect (_ui->updateChannel , &QComboBox::currentTextChanged,
346- this , &GeneralSettings::slotUpdateChannelChanged, Qt::UniqueConnection);
347345}
348346
349347void GeneralSettings::slotUpdateChannelChanged ()
350348{
351349 const auto updateChannelToLocalized = [](const QString &channel) {
352- auto decodedTranslatedChannel = QString{};
353-
354350 if (channel == QStringLiteral (" stable" )) {
355- decodedTranslatedChannel = tr (" stable" );
356- } else if (channel == QStringLiteral (" beta" )) {
357- decodedTranslatedChannel = tr (" beta" );
351+ return tr (" stable" );
352+ }
353+
354+ if (channel == QStringLiteral (" beta" )) {
355+ return tr (" beta" );
358356 }
359357
360- return decodedTranslatedChannel;
358+ if (channel == QStringLiteral (" daily" )) {
359+ return tr (" daily" );
360+ }
361+
362+ return QString{};
361363 };
362364
363365 const auto updateChannelFromLocalized = [](const int index) {
364- if (index == 1 ) {
366+ switch (index) {
367+ case 1 :
365368 return QStringLiteral (" beta" );
369+ break ;
370+ case 2 :
371+ return QStringLiteral (" daily" );
372+ break ;
373+ default :
374+ return QStringLiteral (" stable" );
366375 }
367-
368- return QStringLiteral (" stable" );
369376 };
370377
371378 const auto channel = updateChannelFromLocalized (_ui->updateChannel ->currentIndex ());
372- if (channel == ConfigFile ().updateChannel ()) {
379+ if (channel == ConfigFile ().currentUpdateChannel ()) {
373380 return ;
374381 }
375382
376383 auto msgBox = new QMessageBox (
377384 QMessageBox::Warning,
378- tr (" Change update channel?" ),
379- tr (" The update channel determines which client updates will be offered "
380- " for installation. The \" stable\" channel contains only upgrades that "
381- " are considered reliable, while the versions in the \" beta\" channel "
382- " may contain newer features and bugfixes, but have not yet been tested "
383- " thoroughly."
384- " \n\n "
385- " Note that this selects only what pool upgrades are taken from, and that "
386- " there are no downgrades: So going back from the beta channel to "
387- " the stable channel usually cannot be done immediately and means waiting "
388- " for a stable version that is newer than the currently installed beta "
389- " version." ),
385+ tr (" Changing update channel?" ),
386+ tr (" The channel determines which upgrades will be offered to install:\n "
387+ " - stable: contains tested versions considered reliable\n "
388+ " - beta: contains versions with new features that may not be tested thoroughly\n "
389+ " - daily: contains versions created daily only for testing and development\n\n "
390+ " Downgrading versions is not possible immediately: changing from beta to stable means waiting for the new stable version." ),
390391 QMessageBox::NoButton,
391392 this );
392- auto acceptButton = msgBox->addButton (tr (" Change update channel" ), QMessageBox::AcceptRole);
393+ const auto acceptButton = msgBox->addButton (tr (" Change update channel" ), QMessageBox::AcceptRole);
393394 msgBox->addButton (tr (" Cancel" ), QMessageBox::RejectRole);
394395 connect (msgBox, &QMessageBox::finished, msgBox, [this , channel, msgBox, acceptButton, updateChannelToLocalized] {
395396 msgBox->deleteLater ();
@@ -406,7 +407,7 @@ void GeneralSettings::slotUpdateChannelChanged()
406407 }
407408#endif
408409 } else {
409- _ui->updateChannel ->setCurrentText (updateChannelToLocalized (ConfigFile ().updateChannel ()));
410+ _ui->updateChannel ->setCurrentText (updateChannelToLocalized (ConfigFile ().currentUpdateChannel ()));
410411 }
411412 });
412413 msgBox->open ();
0 commit comments