From d4871731bd1b2c623c7982c2496b0b3913112f71 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Thu, 10 Nov 2022 18:19:04 +0100 Subject: [PATCH] UpdateInfoPlugin: Reuse TaskProgress Change-Id: I35ad1005adb269d016b35fabfbccf27e92d3dfb9 Reviewed-by: Eike Ziller --- src/plugins/updateinfo/updateinfoplugin.cpp | 45 ++++++--------------- 1 file changed, 12 insertions(+), 33 deletions(-) diff --git a/src/plugins/updateinfo/updateinfoplugin.cpp b/src/plugins/updateinfo/updateinfoplugin.cpp index 31c0ef859ac..eec00e8d813 100644 --- a/src/plugins/updateinfo/updateinfoplugin.cpp +++ b/src/plugins/updateinfo/updateinfoplugin.cpp @@ -11,8 +11,7 @@ #include #include #include -#include -#include +#include #include #include #include @@ -22,7 +21,6 @@ #include #include #include -#include #include #include @@ -54,7 +52,7 @@ class UpdateInfoPluginPrivate public: FilePath m_maintenanceTool; std::unique_ptr m_taskTree; - QPointer m_progress; + QPointer m_progress; QString m_updateOutput; QString m_packagesOutput; QTimer *m_checkUpdatesTimer = nullptr; @@ -116,42 +114,18 @@ void UpdateInfoPlugin::startCheckForUpdates() if (d->m_taskTree) return; // do not trigger while update task is already running - QFutureInterface fi; - FutureProgress *futureProgress = ProgressManager::addTimedTask(fi, - tr("Checking for Updates"), Id("UpdateInfo.CheckingForUpdates"), 60); - futureProgress->setKeepOnFinish(FutureProgress::KeepOnFinishTillUserInteraction); - futureProgress->setSubtitleVisibleInStatusBar(true); - connect(futureProgress, &FutureProgress::canceled, this, [this, fi]() mutable { - fi.reportCanceled(); - fi.reportFinished(); - stopCheckForUpdates(); - }); - - fi.reportStarted(); emit checkForUpdatesRunningChanged(true); using namespace Tasking; const auto doSetup = [this](QtcProcess &process, const QStringList &args) { process.setCommand({d->m_maintenanceTool, args}); - process.setTimeoutS(3 * 60); // 3 minutes }; const auto doCleanup = [this] { d->m_taskTree.release()->deleteLater(); checkForUpdatesStopped(); }; - const OnGroupDone onTreeDone([this, fi, doCleanup]() mutable { - fi.reportFinished(); - checkForUpdatesFinished(); - doCleanup(); - }); - const OnGroupError onTreeError([fi, doCleanup]() mutable { - fi.reportCanceled(); // is used to indicate error - fi.reportFinished(); - doCleanup(); - }); - const auto setupUpdate = [doSetup](QtcProcess &process) { doSetup(process, {"ch", "-g", "*=false,ifw.package.*=true"}); }; @@ -169,9 +143,17 @@ void UpdateInfoPlugin::startCheckForUpdates() }; tasks << Process(setupPackages, packagesDone); } - tasks << onTreeDone << onTreeError; d->m_taskTree.reset(new TaskTree(Group{tasks})); + connect(d->m_taskTree.get(), &TaskTree::done, this, [this, doCleanup] { + checkForUpdatesFinished(); + doCleanup(); + }); + connect(d->m_taskTree.get(), &TaskTree::errorOccurred, this, doCleanup); + d->m_progress = new TaskProgress(d->m_taskTree.get()); + d->m_progress->setDisplayName(tr("Checking for Updates")); + d->m_progress->setKeepOnFinish(FutureProgress::KeepOnFinishTillUserInteraction); + d->m_progress->setSubtitleVisibleInStatusBar(true); d->m_taskTree->start(); } @@ -261,9 +243,6 @@ void UpdateInfoPlugin::checkForUpdatesFinished() std::optional qtToNag = qtToNagAbout(qtPackages, &d->m_lastMaxQtVersion); if (!updates.isEmpty() || qtToNag) { - // progress details are shown until user interaction for the "no updates" case, - // so we can show the "No updates found" text, but if we have updates we don't - // want to keep it around if (d->m_progress) d->m_progress->setKeepOnFinish(FutureProgress::HideOnFinish); emit newUpdatesAvailable(true); @@ -272,9 +251,9 @@ void UpdateInfoPlugin::checkForUpdatesFinished() if (qtToNag) showQtUpdateInfo(*qtToNag, [this] { startPackageManager(); }); } else { - emit newUpdatesAvailable(false); if (d->m_progress) d->m_progress->setSubtitle(tr("No updates found.")); + emit newUpdatesAvailable(false); } }