From ef6bf3cb52b8fa5e95297e9b531f39c27dc4e9fb Mon Sep 17 00:00:00 2001
From: Eike Ziller
Date: Fri, 25 Nov 2022 14:25:57 +0100
Subject: [PATCH] UpdateInfo: Merge "new Qt" and "updates" available
if both are availabe. Instead of showing two info bars, show just one
with a combined title.
Change-Id: I31c1c53459209492c5f62277829bc761a36f63a1
Reviewed-by: Jarek Kobus
---
src/plugins/updateinfo/updateinfoplugin.cpp | 87 ++++++++++++---------
1 file changed, 48 insertions(+), 39 deletions(-)
diff --git a/src/plugins/updateinfo/updateinfoplugin.cpp b/src/plugins/updateinfo/updateinfoplugin.cpp
index c59aa539b02..83731448cd0 100644
--- a/src/plugins/updateinfo/updateinfoplugin.cpp
+++ b/src/plugins/updateinfo/updateinfoplugin.cpp
@@ -173,49 +173,60 @@ void UpdateInfoPlugin::checkForUpdatesStopped()
emit checkForUpdatesRunningChanged(false);
}
-static void showUpdateInfo(const QList &updates, const std::function &startUpdater)
+static QString infoTitle(const QList &updates, const std::optional &newQt)
{
- InfoBarEntry info(InstallUpdates,
- UpdateInfoPlugin::tr("New updates are available. Start the update?"));
- info.addCustomButton(UpdateInfoPlugin::tr("Start Update"), [startUpdater] {
- ICore::infoBar()->removeInfo(InstallUpdates);
- startUpdater();
- });
- info.setDetailsWidgetCreator([updates]() -> QWidget * {
- const QString updateText = Utils::transform(updates, [](const Update &u) {
- return u.version.isEmpty()
- ? u.name
- : UpdateInfoPlugin::tr("%1 (%2)",
- "Package name and version")
- .arg(u.name, u.version);
- }).join("");
- auto label = new QLabel;
- label->setText("" + UpdateInfoPlugin::tr("Available updates:") + "
");
- label->setContentsMargins(0, 0, 0, 8);
- return label;
- });
- ICore::infoBar()->removeInfo(InstallUpdates); // remove any existing notifications
- ICore::infoBar()->unsuppressInfo(InstallUpdates);
- ICore::infoBar()->addInfo(info);
+ static QString blogUrl("href=\"https://www.qt.io/blog/tag/releases\"");
+ if (!updates.isEmpty() && newQt) {
+ return UpdateInfoPlugin::tr(
+ "%1 and other updates are available. Check the Qt blog for details.")
+ .arg(newQt->displayName, blogUrl);
+ } else if (newQt) {
+ return UpdateInfoPlugin::tr("%1 is available. Check the Qt blog for details.")
+ .arg(newQt->displayName, blogUrl);
+ }
+ return UpdateInfoPlugin::tr("New updates are available. Start the update?");
}
-static void showQtUpdateInfo(const QtPackage &package,
- const std::function &startPackageManager)
+static void showUpdateInfo(const QList &updates,
+ const std::optional &newQt,
+ const std::function &startUpdater,
+ const std::function &startPackageManager)
{
- InfoBarEntry info(InstallQtUpdates, UpdateInfoPlugin::tr(
- "%1 is available. Check the Qt blog for details.")
- .arg(package.displayName, QString("href=\"https://www.qt.io/blog/tag/releases\"")));
- info.addCustomButton(UpdateInfoPlugin::tr("Start Package Manager"), [startPackageManager] {
- ICore::infoBar()->removeInfo(InstallQtUpdates);
- startPackageManager();
- });
+ InfoBarEntry info(InstallUpdates, infoTitle(updates, newQt));
info.addCustomButton(UpdateInfoPlugin::tr("Open Settings"), [] {
ICore::infoBar()->removeInfo(InstallQtUpdates);
ICore::showOptionsDialog(FILTER_OPTIONS_PAGE_ID);
});
- ICore::infoBar()->removeInfo(InstallQtUpdates); // remove any existing notifications
- ICore::infoBar()->unsuppressInfo(InstallQtUpdates);
+ if (newQt) {
+ info.addCustomButton(UpdateInfoPlugin::tr("Start Package Manager"), [startPackageManager] {
+ ICore::infoBar()->removeInfo(InstallQtUpdates);
+ startPackageManager();
+ });
+ } else {
+ info.addCustomButton(UpdateInfoPlugin::tr("Start Update"), [startUpdater] {
+ ICore::infoBar()->removeInfo(InstallUpdates);
+ startUpdater();
+ });
+ }
+ if (!updates.isEmpty()) {
+ info.setDetailsWidgetCreator([updates, newQt] {
+ const QString qtText = newQt ? (newQt->displayName + "") : QString();
+ const QStringList packageNames = Utils::transform(updates, [](const Update &u) {
+ if (u.version.isEmpty())
+ return u.name;
+ return UpdateInfoPlugin::tr("%1 (%2)", "Package name and version")
+ .arg(u.name, u.version);
+ });
+ const QString updateText = packageNames.join("");
+ auto label = new QLabel;
+ label->setText("" + UpdateInfoPlugin::tr("Available updates:") + "
- "
+ + qtText + updateText + "
");
+ label->setContentsMargins(0, 0, 0, 8);
+ return label;
+ });
+ }
+ ICore::infoBar()->removeInfo(InstallUpdates); // remove any existing notifications
+ ICore::infoBar()->unsuppressInfo(InstallUpdates);
ICore::infoBar()->addInfo(info);
}
@@ -249,10 +260,8 @@ void UpdateInfoPlugin::checkForUpdatesFinished()
if (d->m_progress)
d->m_progress->setKeepOnFinish(FutureProgress::HideOnFinish);
emit newUpdatesAvailable(true);
- if (!updates.isEmpty())
- showUpdateInfo(updates, [this] { startUpdater(); });
- if (qtToNag)
- showQtUpdateInfo(*qtToNag, [this] { startPackageManager(); });
+ showUpdateInfo(
+ updates, qtToNag, [this] { startUpdater(); }, [this] { startPackageManager(); });
} else {
if (d->m_progress)
d->m_progress->setSubtitle(tr("No updates found."));