forked from qt-creator/qt-creator
UpdateInfoPlugin: Reuse TaskTreeRunner
Change-Id: Ifc6ab7d17b2cb9569675e19e7493eacc35c8b9a5 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -12,6 +12,9 @@
|
|||||||
#include <coreplugin/coreconstants.h>
|
#include <coreplugin/coreconstants.h>
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
#include <coreplugin/progressmanager/taskprogress.h>
|
#include <coreplugin/progressmanager/taskprogress.h>
|
||||||
|
|
||||||
|
#include <solutions/tasking/tasktreerunner.h>
|
||||||
|
|
||||||
#include <utils/infobar.h>
|
#include <utils/infobar.h>
|
||||||
#include <utils/process.h>
|
#include <utils/process.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
@@ -25,8 +28,6 @@
|
|||||||
#include <QVersionNumber>
|
#include <QVersionNumber>
|
||||||
#include <QScrollArea>
|
#include <QScrollArea>
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
Q_LOGGING_CATEGORY(updateLog, "qtc.updateinfo", QtWarningMsg)
|
Q_LOGGING_CATEGORY(updateLog, "qtc.updateinfo", QtWarningMsg)
|
||||||
|
|
||||||
const char UpdaterGroup[] = "Updater";
|
const char UpdaterGroup[] = "Updater";
|
||||||
@@ -53,7 +54,7 @@ class UpdateInfoPluginPrivate
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FilePath m_maintenanceTool;
|
FilePath m_maintenanceTool;
|
||||||
std::unique_ptr<TaskTree> m_taskTree;
|
TaskTreeRunner m_taskTreeRunner;
|
||||||
QPointer<TaskProgress> m_progress;
|
QPointer<TaskProgress> m_progress;
|
||||||
QString m_updateOutput;
|
QString m_updateOutput;
|
||||||
QString m_packagesOutput;
|
QString m_packagesOutput;
|
||||||
@@ -102,7 +103,7 @@ void UpdateInfoPlugin::stopAutoCheckForUpdates()
|
|||||||
|
|
||||||
void UpdateInfoPlugin::doAutoCheckForUpdates()
|
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)
|
return; // update task is still running (might have been run manually just before)
|
||||||
|
|
||||||
if (nextCheckDate().isValid() && nextCheckDate() > QDate::currentDate())
|
if (nextCheckDate().isValid() && nextCheckDate() > QDate::currentDate())
|
||||||
@@ -113,11 +114,24 @@ void UpdateInfoPlugin::doAutoCheckForUpdates()
|
|||||||
|
|
||||||
void UpdateInfoPlugin::startCheckForUpdates()
|
void UpdateInfoPlugin::startCheckForUpdates()
|
||||||
{
|
{
|
||||||
if (d->m_taskTree)
|
if (d->m_taskTreeRunner.isRunning())
|
||||||
return; // do not trigger while update task is already running
|
return; // do not trigger while update task is already running
|
||||||
|
|
||||||
emit checkForUpdatesRunningChanged(true);
|
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) {
|
const auto doSetup = [this](Process &process, const QStringList &args) {
|
||||||
process.setCommand({d->m_maintenanceTool, args});
|
process.setCommand({d->m_maintenanceTool, args});
|
||||||
process.setLowPriority();
|
process.setLowPriority();
|
||||||
@@ -140,28 +154,15 @@ void UpdateInfoPlugin::startCheckForUpdates()
|
|||||||
};
|
};
|
||||||
tasks << ProcessTask(onPackagesSetup, onPackagesDone, CallDoneIf::Success);
|
tasks << ProcessTask(onPackagesSetup, onPackagesDone, CallDoneIf::Success);
|
||||||
}
|
}
|
||||||
|
d->m_taskTreeRunner.start(tasks, onTreeSetup, onTreeDone);
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateInfoPlugin::stopCheckForUpdates()
|
void UpdateInfoPlugin::stopCheckForUpdates()
|
||||||
{
|
{
|
||||||
if (!d->m_taskTree)
|
if (!d->m_taskTreeRunner.isRunning())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
d->m_taskTree.reset();
|
d->m_taskTreeRunner.reset();
|
||||||
checkForUpdatesStopped();
|
checkForUpdatesStopped();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -275,7 +276,7 @@ void UpdateInfoPlugin::checkForUpdatesFinished()
|
|||||||
|
|
||||||
bool UpdateInfoPlugin::isCheckForUpdatesRunning() const
|
bool UpdateInfoPlugin::isCheckForUpdatesRunning() const
|
||||||
{
|
{
|
||||||
return d->m_taskTree.get() != nullptr;
|
return d->m_taskTreeRunner.isRunning();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateInfoPlugin::extensionsInitialized()
|
void UpdateInfoPlugin::extensionsInitialized()
|
||||||
|
Reference in New Issue
Block a user