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);
}
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,
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("</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 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 <a %2>Qt blog</a> for details.")
.arg(newQt->displayName, blogUrl);
} else if (newQt) {
return UpdateInfoPlugin::tr("%1 is available. Check the <a %2>Qt blog</a> for details.")
.arg(newQt->displayName, blogUrl);
}
return UpdateInfoPlugin::tr("New updates are available. Start the update?");
}
static void showQtUpdateInfo(const QtPackage &package,
static void showUpdateInfo(const QList<Update> &updates,
const std::optional<QtPackage> &newQt,
const std::function<void()> &startUpdater,
const std::function<void()> &startPackageManager)
{
InfoBarEntry info(InstallQtUpdates, UpdateInfoPlugin::tr(
"%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();
});
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 + "</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);
}
@@ -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."));