From 2578c759ceec916e7e5e0861cac121999c012560 Mon Sep 17 00:00:00 2001 From: elecpower Date: Thu, 28 Jul 2022 08:07:38 +1000 Subject: [PATCH] Check if any components flagged as updateable --- companion/src/updates/updateinterface.cpp | 11 +++- companion/src/updates/updateinterface.h | 3 +- companion/src/updates/updates.cpp | 5 ++ companion/src/updates/updatesdialog.cpp | 62 +++++++++++------------ 4 files changed, 46 insertions(+), 35 deletions(-) diff --git a/companion/src/updates/updateinterface.cpp b/companion/src/updates/updateinterface.cpp index 99f121a3a..255a1ea1e 100644 --- a/companion/src/updates/updateinterface.cpp +++ b/companion/src/updates/updateinterface.cpp @@ -376,6 +376,11 @@ void UpdateInterface::initParamFolders(UpdateParameters * params) } } +bool UpdateInterface::isUpdateable() +{ + return g.component[settingsIdx].checkForUpdate(); +} + void UpdateInterface::resetRunEnvironment() { progress = nullptr; @@ -1459,11 +1464,13 @@ void UpdateFactories::setRunUpdate(const QString & name) } } -const QMap UpdateFactories::sortedComponentsList() +const QMap UpdateFactories::sortedComponentsList(bool updateableOnly) { QMap map; foreach (UpdateFactoryInterface * factory, registeredUpdateFactories) { + if (updateableOnly && !factory->instance()->isUpdateable()) + continue; map.insert(factory->name(), factory->instance()->settingsIdx); } @@ -1582,7 +1589,7 @@ const bool UpdateFactories::updatesAvailable(QStringList & names) names.clear(); foreach (UpdateFactoryInterface * factory, registeredUpdateFactories) { - if (factory->instance()->isUpdateAvailable()) { + if (factory->instance()->isUpdateable() && factory->instance()->isUpdateAvailable()) { names.append(factory->name()); ret = true; } diff --git a/companion/src/updates/updateinterface.h b/companion/src/updates/updateinterface.h index c93387b2a..963efcde4 100644 --- a/companion/src/updates/updateinterface.h +++ b/companion/src/updates/updateinterface.h @@ -169,6 +169,7 @@ class UpdateInterface : public QWidget UpdateParameters * getRunParams() { return runParams; } void resetRunEnvironment(); void setRunUpdate() { runParams->data.flags |= UPDFLG_Update; } + bool isUpdateable(); bool repoReleasesMetaData(); bool repoReleaseAssetsMetaData(); @@ -272,7 +273,7 @@ class UpdateFactories : public QWidget void resetRunEnvironment(const QString & name); void resetAllRunEnvironments(); void setRunUpdate(const QString & name); - const QMap sortedComponentsList(); + const QMap sortedComponentsList(bool updateableOnly = false); void clearRelease(const QString & name); const QString currentRelease(const QString & name); diff --git a/companion/src/updates/updates.cpp b/companion/src/updates/updates.cpp index 8332b2361..1465cd757 100644 --- a/companion/src/updates/updates.cpp +++ b/companion/src/updates/updates.cpp @@ -86,6 +86,11 @@ void Updates::autoUpdates() void Updates::manualUpdates() { + if (factories->sortedComponentsList(true).isEmpty()) { + QMessageBox::warning(this, CPN_STR_APP_NAME, tr("No components have been flagged to check in Update Settings!")); + return; + } + factories->resetAllRunEnvironments(); UpdatesDialog *dlg = new UpdatesDialog(this, factories); diff --git a/companion/src/updates/updatesdialog.cpp b/companion/src/updates/updatesdialog.cpp index deaa58ac5..5412731c7 100644 --- a/companion/src/updates/updatesdialog.cpp +++ b/companion/src/updates/updatesdialog.cpp @@ -36,7 +36,7 @@ UpdatesDialog::UpdatesDialog(QWidget * parent, UpdateFactories * factories) : { // downloading the release meta data takes a few seconds for each component so display progress QDialog *status = new QDialog(parent); - status->setWindowTitle(tr("Progress")); + status->setWindowTitle(tr("Downloading Release Metadata")); QVBoxLayout *layout = new QVBoxLayout(status); QLabel *msg = new QLabel(status); msg->setFixedWidth(400); @@ -141,7 +141,7 @@ UpdatesDialog::UpdatesDialog(QWidget * parent, UpdateFactories * factories) : QSpacerItem * spacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum ); grid->addItem(spacer, row, col++); - QMapIterator it(factories->sortedComponentsList()); + QMapIterator it(factories->sortedComponentsList(true)); while (it.hasNext()) { it.next(); @@ -149,44 +149,42 @@ UpdatesDialog::UpdatesDialog(QWidget * parent, UpdateFactories * factories) : const QString name = it.key(); - if (g.component[i].checkForUpdate()) { - row++; - col = 0; + row++; + col = 0; - msg->setText(tr("Retrieving latest release information for %1").arg(name)); - chkUpdate[i] = new QCheckBox(); - chkUpdate[i]->setProperty("index", i); - chkUpdate[i]->setChecked(!factories->isLatestRelease(name)); - grid->addWidget(chkUpdate[i], row, col++); - grid->setAlignment(chkUpdate[i], Qt::AlignHCenter); + msg->setText(tr("Retrieving latest release information for %1").arg(name)); + chkUpdate[i] = new QCheckBox(); + chkUpdate[i]->setProperty("index", i); + chkUpdate[i]->setChecked(!factories->isLatestRelease(name)); + grid->addWidget(chkUpdate[i], row, col++); + grid->setAlignment(chkUpdate[i], Qt::AlignHCenter); - QLabel *lblName = new QLabel(name); - grid->addWidget(lblName, row, col++); + QLabel *lblName = new QLabel(name); + grid->addWidget(lblName, row, col++); - QLabel *lblRC = new QLabel(ComponentData::releaseChannelsList().at(g.component[i].releaseChannel())); - grid->addWidget(lblRC, row, col++); + QLabel *lblRC = new QLabel(ComponentData::releaseChannelsList().at(g.component[i].releaseChannel())); + grid->addWidget(lblRC, row, col++); - lblCurrentRel[i] = new QLabel(factories->currentRelease(name)); - grid->addWidget(lblCurrentRel[i], row, col++); + lblCurrentRel[i] = new QLabel(factories->currentRelease(name)); + grid->addWidget(lblCurrentRel[i], row, col++); - lblUpdateRel[i] = new QLabel(factories->updateRelease(name)); - grid->addWidget(lblUpdateRel[i], row, col++); + lblUpdateRel[i] = new QLabel(factories->updateRelease(name)); + grid->addWidget(lblUpdateRel[i], row, col++); - btnOptions[i] = new QPushButton(tr("Options")); - connect(btnOptions[i], &QPushButton::clicked, [=]() { - UpdateOptionsDialog *dlg = new UpdateOptionsDialog(this, factories, i); - connect(dlg, &UpdateOptionsDialog::changed, [=](const int i) { - QString name = g.component[i].name(); - chkUpdate[i]->setChecked(!factories->isLatestRelease(name)); - lblCurrentRel[i]->setText(factories->currentRelease(name)); - lblUpdateRel[i]->setText(factories->updateRelease(name)); - }); - dlg->exec(); - dlg->deleteLater(); + btnOptions[i] = new QPushButton(tr("Options")); + connect(btnOptions[i], &QPushButton::clicked, [=]() { + UpdateOptionsDialog *dlg = new UpdateOptionsDialog(this, factories, i); + connect(dlg, &UpdateOptionsDialog::changed, [=](const int i) { + QString name = g.component[i].name(); + chkUpdate[i]->setChecked(!factories->isLatestRelease(name)); + lblCurrentRel[i]->setText(factories->currentRelease(name)); + lblUpdateRel[i]->setText(factories->updateRelease(name)); }); + dlg->exec(); + dlg->deleteLater(); + }); - grid->addWidget(btnOptions[i], row, col++); - } + grid->addWidget(btnOptions[i], row, col++); } ui->grpComponents->setLayout(grid);