From a6f2df9ebdb965d38ea2c263e3b3bea17c7abffe Mon Sep 17 00:00:00 2001 From: Arttu Tarkiainen Date: Fri, 3 Jun 2022 18:51:17 +0300 Subject: Display progress for loading component install scripts Also process pending events for the main thread in the loop that calls Component::loadComponentScript() repeatedly, to not block the UI while busy loading the scripts. Task-number: QTIFW-2701 Change-Id: I4a1dd8e2441e21b5075b6fdffff8a47cd4bc7c80 Reviewed-by: Katja Marttila --- src/libs/installer/packagemanagercore.cpp | 10 +++++++--- src/libs/installer/packagemanagercore_p.cpp | 30 +++++++++++++++++++++++++---- src/libs/installer/packagemanagercore_p.h | 3 +++ 3 files changed, 36 insertions(+), 7 deletions(-) (limited to 'src/libs') diff --git a/src/libs/installer/packagemanagercore.cpp b/src/libs/installer/packagemanagercore.cpp index ae87b96f0..d85ed8c47 100644 --- a/src/libs/installer/packagemanagercore.cpp +++ b/src/libs/installer/packagemanagercore.cpp @@ -4262,21 +4262,25 @@ bool PackageManagerCore::fetchUpdaterPackages(const PackagesList &remotes, const } // after everything is set up, load the scripts + if (!d->loadComponentScripts(components)) + return false; + foreach (QInstaller::Component *component, components) { if (d->statusCanceledOrFailed()) return false; - component->loadComponentScript(); if (!component->isUnstable() && component->autoDependencies().isEmpty()) component->setCheckState(Qt::Checked); } + // even for possible dependencies we need to load the scripts for example to get archives + if (!d->loadComponentScripts(d->m_updaterComponentsDeps)) + return false; + // after everything is set up, check installed components foreach (QInstaller::Component *component, d->m_updaterComponentsDeps) { if (d->statusCanceledOrFailed()) return false; - // even for possible dependency we need to load the script for example to get archives - component->loadComponentScript(); if (component->isInstalled() && !component->autoDependencies().isEmpty()) { // since we do not put them into the model, which would force a update of e.g. tri state // components, we have to check all installed components ourselves diff --git a/src/libs/installer/packagemanagercore_p.cpp b/src/libs/installer/packagemanagercore_p.cpp index 66630b98d..2d61a351a 100644 --- a/src/libs/installer/packagemanagercore_p.cpp +++ b/src/libs/installer/packagemanagercore_p.cpp @@ -402,10 +402,9 @@ bool PackageManagerCorePrivate::buildComponentTree(QHash &c // after everything is set up, load the scripts if needed and create helper hashes // for autodependency and dependency components for quicker search later - foreach (QInstaller::Component *component, components) { - if (loadScript) - component->loadComponentScript(); - } + if (loadScript && !loadComponentScripts(components)) + return false; + // now we can preselect components in the tree foreach (QInstaller::Component *component, components) { // set the checked state for all components without child (means without tristate) @@ -458,6 +457,29 @@ bool PackageManagerCorePrivate::buildComponentTree(QHash &c return true; } +template +bool PackageManagerCorePrivate::loadComponentScripts(const T &components) +{ + infoMessage(nullptr, tr("Loading component scripts...")); + + quint64 loadedComponents = 0; + for (auto *component : components) { + if (statusCanceledOrFailed()) + return false; + + component->loadComponentScript(); + ++loadedComponents; + + const int currentProgress = qRound(double(loadedComponents) / components.count() * 100); + infoProgress(nullptr, currentProgress, 100); + qApp->processEvents(); + } + return true; +} + +template bool PackageManagerCorePrivate::loadComponentScripts>(const QList &); +template bool PackageManagerCorePrivate::loadComponentScripts>(const QHash &); + void PackageManagerCorePrivate::cleanUpComponentEnvironment() { m_componentReplaces.clear(); diff --git a/src/libs/installer/packagemanagercore_p.h b/src/libs/installer/packagemanagercore_p.h index 24782b598..0ce081774 100644 --- a/src/libs/installer/packagemanagercore_p.h +++ b/src/libs/installer/packagemanagercore_p.h @@ -106,6 +106,9 @@ public: bool buildComponentTree(QHash &components, bool loadScript); + template + bool loadComponentScripts(const T &components); + void cleanUpComponentEnvironment(); ScriptEngine *componentScriptEngine() const; ScriptEngine *controlScriptEngine() const; -- cgit v1.2.3