diff --git a/src/plugins/updateinfo/updateinfoplugin.cpp b/src/plugins/updateinfo/updateinfoplugin.cpp index d5838becfbf..8aa8fae6287 100644 --- a/src/plugins/updateinfo/updateinfoplugin.cpp +++ b/src/plugins/updateinfo/updateinfoplugin.cpp @@ -12,6 +12,9 @@ #include #include #include + +#include + #include #include #include @@ -25,8 +28,6 @@ #include #include -#include - Q_LOGGING_CATEGORY(updateLog, "qtc.updateinfo", QtWarningMsg) const char UpdaterGroup[] = "Updater"; @@ -53,7 +54,7 @@ class UpdateInfoPluginPrivate { public: FilePath m_maintenanceTool; - std::unique_ptr m_taskTree; + TaskTreeRunner m_taskTreeRunner; QPointer m_progress; QString m_updateOutput; QString m_packagesOutput; @@ -102,7 +103,7 @@ void UpdateInfoPlugin::stopAutoCheckForUpdates() void UpdateInfoPlugin::doAutoCheckForUpdates() { - if (d->m_taskTree) + if (d->m_taskTreeRunner.isRunning()) return; // update task is still running (might have been run manually just before) if (nextCheckDate().isValid() && nextCheckDate() > QDate::currentDate()) @@ -113,11 +114,24 @@ void UpdateInfoPlugin::doAutoCheckForUpdates() void UpdateInfoPlugin::startCheckForUpdates() { - if (d->m_taskTree) + if (d->m_taskTreeRunner.isRunning()) return; // do not trigger while update task is already running emit checkForUpdatesRunningChanged(true); + const auto onTreeSetup = [this](TaskTree *taskTree) { + d->m_progress = new TaskProgress(taskTree); + d->m_progress->setHalfLifeTimePerTask(30000); // 30 seconds + d->m_progress->setDisplayName(Tr::tr("Checking for Updates")); + d->m_progress->setKeepOnFinish(FutureProgress::KeepOnFinishTillUserInteraction); + d->m_progress->setSubtitleVisibleInStatusBar(true); + }; + const auto onTreeDone = [this](DoneWith result) { + if (result == DoneWith::Success) + checkForUpdatesFinished(); + checkForUpdatesStopped(); + }; + const auto doSetup = [this](Process &process, const QStringList &args) { process.setCommand({d->m_maintenanceTool, args}); process.setLowPriority(); @@ -140,28 +154,15 @@ void UpdateInfoPlugin::startCheckForUpdates() }; tasks << ProcessTask(onPackagesSetup, onPackagesDone, CallDoneIf::Success); } - - d->m_taskTree.reset(new TaskTree(Group{tasks})); - connect(d->m_taskTree.get(), &TaskTree::done, this, [this](DoneWith result) { - if (result == DoneWith::Success) - checkForUpdatesFinished(); - d->m_taskTree.release()->deleteLater(); - checkForUpdatesStopped(); - }); - d->m_progress = new TaskProgress(d->m_taskTree.get()); - d->m_progress->setHalfLifeTimePerTask(30000); // 30 seconds - d->m_progress->setDisplayName(Tr::tr("Checking for Updates")); - d->m_progress->setKeepOnFinish(FutureProgress::KeepOnFinishTillUserInteraction); - d->m_progress->setSubtitleVisibleInStatusBar(true); - d->m_taskTree->start(); + d->m_taskTreeRunner.start(tasks, onTreeSetup, onTreeDone); } void UpdateInfoPlugin::stopCheckForUpdates() { - if (!d->m_taskTree) + if (!d->m_taskTreeRunner.isRunning()) return; - d->m_taskTree.reset(); + d->m_taskTreeRunner.reset(); checkForUpdatesStopped(); } @@ -275,7 +276,7 @@ void UpdateInfoPlugin::checkForUpdatesFinished() bool UpdateInfoPlugin::isCheckForUpdatesRunning() const { - return d->m_taskTree.get() != nullptr; + return d->m_taskTreeRunner.isRunning(); } void UpdateInfoPlugin::extensionsInitialized()