UpdateInfoPlugin: Reuse TaskProgress

Change-Id: I35ad1005adb269d016b35fabfbccf27e92d3dfb9
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Jarek Kobus
2022-11-10 18:19:04 +01:00
parent 7afe536a5c
commit d4871731bd

View File

@@ -11,8 +11,7 @@
#include <coreplugin/actionmanager/actionmanager.h> #include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/coreconstants.h> #include <coreplugin/coreconstants.h>
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <coreplugin/progressmanager/futureprogress.h> #include <coreplugin/progressmanager/taskprogress.h>
#include <coreplugin/progressmanager/progressmanager.h>
#include <utils/infobar.h> #include <utils/infobar.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <utils/qtcprocess.h> #include <utils/qtcprocess.h>
@@ -22,7 +21,6 @@
#include <QLoggingCategory> #include <QLoggingCategory>
#include <QMenu> #include <QMenu>
#include <QMetaEnum> #include <QMetaEnum>
#include <QPointer>
#include <QTimer> #include <QTimer>
#include <QVersionNumber> #include <QVersionNumber>
@@ -54,7 +52,7 @@ class UpdateInfoPluginPrivate
public: public:
FilePath m_maintenanceTool; FilePath m_maintenanceTool;
std::unique_ptr<TaskTree> m_taskTree; std::unique_ptr<TaskTree> m_taskTree;
QPointer<FutureProgress> m_progress; QPointer<TaskProgress> m_progress;
QString m_updateOutput; QString m_updateOutput;
QString m_packagesOutput; QString m_packagesOutput;
QTimer *m_checkUpdatesTimer = nullptr; QTimer *m_checkUpdatesTimer = nullptr;
@@ -116,42 +114,18 @@ void UpdateInfoPlugin::startCheckForUpdates()
if (d->m_taskTree) if (d->m_taskTree)
return; // do not trigger while update task is already running return; // do not trigger while update task is already running
QFutureInterface<void> 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); emit checkForUpdatesRunningChanged(true);
using namespace Tasking; using namespace Tasking;
const auto doSetup = [this](QtcProcess &process, const QStringList &args) { const auto doSetup = [this](QtcProcess &process, const QStringList &args) {
process.setCommand({d->m_maintenanceTool, args}); process.setCommand({d->m_maintenanceTool, args});
process.setTimeoutS(3 * 60); // 3 minutes
}; };
const auto doCleanup = [this] { const auto doCleanup = [this] {
d->m_taskTree.release()->deleteLater(); d->m_taskTree.release()->deleteLater();
checkForUpdatesStopped(); 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) { const auto setupUpdate = [doSetup](QtcProcess &process) {
doSetup(process, {"ch", "-g", "*=false,ifw.package.*=true"}); doSetup(process, {"ch", "-g", "*=false,ifw.package.*=true"});
}; };
@@ -169,9 +143,17 @@ void UpdateInfoPlugin::startCheckForUpdates()
}; };
tasks << Process(setupPackages, packagesDone); tasks << Process(setupPackages, packagesDone);
} }
tasks << onTreeDone << onTreeError;
d->m_taskTree.reset(new TaskTree(Group{tasks})); 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(); d->m_taskTree->start();
} }
@@ -261,9 +243,6 @@ void UpdateInfoPlugin::checkForUpdatesFinished()
std::optional<QtPackage> qtToNag = qtToNagAbout(qtPackages, &d->m_lastMaxQtVersion); std::optional<QtPackage> qtToNag = qtToNagAbout(qtPackages, &d->m_lastMaxQtVersion);
if (!updates.isEmpty() || qtToNag) { 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) if (d->m_progress)
d->m_progress->setKeepOnFinish(FutureProgress::HideOnFinish); d->m_progress->setKeepOnFinish(FutureProgress::HideOnFinish);
emit newUpdatesAvailable(true); emit newUpdatesAvailable(true);
@@ -272,9 +251,9 @@ void UpdateInfoPlugin::checkForUpdatesFinished()
if (qtToNag) if (qtToNag)
showQtUpdateInfo(*qtToNag, [this] { startPackageManager(); }); showQtUpdateInfo(*qtToNag, [this] { startPackageManager(); });
} else { } else {
emit newUpdatesAvailable(false);
if (d->m_progress) if (d->m_progress)
d->m_progress->setSubtitle(tr("No updates found.")); d->m_progress->setSubtitle(tr("No updates found."));
emit newUpdatesAvailable(false);
} }
} }