From 78798b58b23b543cee54a9fc307293f0f4e51afe 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_p.cpp | 30 +++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'src/libs/installer/packagemanagercore_p.cpp') diff --git a/src/libs/installer/packagemanagercore_p.cpp b/src/libs/installer/packagemanagercore_p.cpp index 5e4ee6ffb..1d4302e12 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(); -- cgit v1.2.3