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 <jaroslaw.kobus@qt.io>
This commit is contained in:
Eike Ziller
2022-11-25 14:25:57 +01:00
parent d15c102af8
commit ef6bf3cb52

View File

@@ -173,49 +173,60 @@ void UpdateInfoPlugin::checkForUpdatesStopped()
emit checkForUpdatesRunningChanged(false); emit checkForUpdatesRunningChanged(false);
} }
static void showUpdateInfo(const QList<Update> &updates, const std::function<void()> &startUpdater) static QString infoTitle(const QList<Update> &updates, const std::optional<QtPackage> &newQt)
{ {
InfoBarEntry info(InstallUpdates, static QString blogUrl("href=\"https://www.qt.io/blog/tag/releases\"");
UpdateInfoPlugin::tr("New updates are available. Start the update?")); if (!updates.isEmpty() && newQt) {
info.addCustomButton(UpdateInfoPlugin::tr("Start Update"), [startUpdater] { return UpdateInfoPlugin::tr(
ICore::infoBar()->removeInfo(InstallUpdates); "%1 and other updates are available. Check the <a %2>Qt blog</a> for details.")
startUpdater(); .arg(newQt->displayName, blogUrl);
}); } else if (newQt) {
info.setDetailsWidgetCreator([updates]() -> QWidget * { return UpdateInfoPlugin::tr("%1 is available. Check the <a %2>Qt blog</a> for details.")
const QString updateText = Utils::transform(updates, [](const Update &u) { .arg(newQt->displayName, blogUrl);
return u.version.isEmpty() }
? u.name return UpdateInfoPlugin::tr("New updates are available. Start the update?");
: UpdateInfoPlugin::tr("%1 (%2)",
"Package name and version")
.arg(u.name, u.version);
}).join("</li><li>");
auto label = new QLabel;
label->setText("<qt><p>" + UpdateInfoPlugin::tr("Available updates:") + "<ul><li>"
+ updateText + "</li></ul></p></qt>");
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 void showQtUpdateInfo(const QtPackage &package, static void showUpdateInfo(const QList<Update> &updates,
const std::function<void()> &startPackageManager) const std::optional<QtPackage> &newQt,
const std::function<void()> &startUpdater,
const std::function<void()> &startPackageManager)
{ {
InfoBarEntry info(InstallQtUpdates, UpdateInfoPlugin::tr( InfoBarEntry info(InstallUpdates, infoTitle(updates, newQt));
"%1 is available. Check the <a %2>Qt blog</a> 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();
});
info.addCustomButton(UpdateInfoPlugin::tr("Open Settings"), [] { info.addCustomButton(UpdateInfoPlugin::tr("Open Settings"), [] {
ICore::infoBar()->removeInfo(InstallQtUpdates); ICore::infoBar()->removeInfo(InstallQtUpdates);
ICore::showOptionsDialog(FILTER_OPTIONS_PAGE_ID); ICore::showOptionsDialog(FILTER_OPTIONS_PAGE_ID);
}); });
ICore::infoBar()->removeInfo(InstallQtUpdates); // remove any existing notifications if (newQt) {
ICore::infoBar()->unsuppressInfo(InstallQtUpdates); 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 + "</li><li>") : 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("</li><li>");
auto label = new QLabel;
label->setText("<qt><p>" + UpdateInfoPlugin::tr("Available updates:") + "<ul><li>"
+ qtText + updateText + "</li></ul></p></qt>");
label->setContentsMargins(0, 0, 0, 8);
return label;
});
}
ICore::infoBar()->removeInfo(InstallUpdates); // remove any existing notifications
ICore::infoBar()->unsuppressInfo(InstallUpdates);
ICore::infoBar()->addInfo(info); ICore::infoBar()->addInfo(info);
} }
@@ -249,10 +260,8 @@ void UpdateInfoPlugin::checkForUpdatesFinished()
if (d->m_progress) if (d->m_progress)
d->m_progress->setKeepOnFinish(FutureProgress::HideOnFinish); d->m_progress->setKeepOnFinish(FutureProgress::HideOnFinish);
emit newUpdatesAvailable(true); emit newUpdatesAvailable(true);
if (!updates.isEmpty()) showUpdateInfo(
showUpdateInfo(updates, [this] { startUpdater(); }); updates, qtToNag, [this] { startUpdater(); }, [this] { startPackageManager(); });
if (qtToNag)
showQtUpdateInfo(*qtToNag, [this] { startPackageManager(); });
} else { } else {
if (d->m_progress) if (d->m_progress)
d->m_progress->setSubtitle(tr("No updates found.")); d->m_progress->setSubtitle(tr("No updates found."));