summaryrefslogtreecommitdiffstats
path: root/installerbuilder
diff options
context:
space:
mode:
authorkh1 <karsten.heimrich@nokia.com>2011-11-25 13:18:21 +0100
committerTim Jenssen <tim.jenssen@nokia.com>2011-11-25 13:27:10 +0100
commit6cbc6dc80d9a8f18c01cbf72291dfe033f9a6534 (patch)
tree43242e743552d3b3f56d6384576c3af30e3eb33d /installerbuilder
parentc76b61c0bcca31b56513b02c204ff633ffb75e0c (diff)
Refactor the code with the use of buildComponentTree.
Change-Id: Id50f324e04a5afbf17631efece7e10caa6d41244 Reviewed-by: Karsten Heimrich <karsten.heimrich@nokia.com> Reviewed-by: Tim Jenssen <tim.jenssen@nokia.com>
Diffstat (limited to 'installerbuilder')
-rw-r--r--installerbuilder/libinstaller/packagemanagercore.cpp87
-rw-r--r--installerbuilder/libinstaller/packagemanagercore_p.cpp56
-rw-r--r--installerbuilder/libinstaller/packagemanagercore_p.h3
3 files changed, 64 insertions, 82 deletions
diff --git a/installerbuilder/libinstaller/packagemanagercore.cpp b/installerbuilder/libinstaller/packagemanagercore.cpp
index 101b97e42..e32434a12 100644
--- a/installerbuilder/libinstaller/packagemanagercore.cpp
+++ b/installerbuilder/libinstaller/packagemanagercore.cpp
@@ -573,7 +573,7 @@ bool PackageManagerCore::fetchLocalPackagesTree()
emit startAllComponentsReset();
d->clearAllComponentLists();
- QMap<QString, QInstaller::Component*> components;
+ QHash<QString, QInstaller::Component*> components;
const QStringList &keys = installedPackages.keys();
foreach (const QString &key, keys) {
@@ -588,34 +588,8 @@ bool PackageManagerCore::fetchLocalPackagesTree()
components.insert(name, component.take());
}
- // now append all components to their respective parents
- QMap<QString, QInstaller::Component*>::const_iterator it;
- for (it = components.begin(); it != components.end(); ++it) {
- QString id = it.key();
- QInstaller::Component *component = it.value();
- while (!id.isEmpty() && component->parentComponent() == 0) {
- id = id.section(QLatin1Char('.'), 0, -2);
- if (components.contains(id))
- components[id]->appendComponent(component);
- }
- }
-
- // append all components w/o parent to the direct list
- foreach (QInstaller::Component *component, components) {
- if (component->parentComponent() == 0)
- appendRootComponent(component);
- }
-
- // now set the checked state for all components without child
- for (int i = 0; i < rootComponentCount(); ++i) {
- QList<Component*> children = rootComponent(i)->childs();
- foreach (Component *child, children) {
- if (child->isCheckable() && !child->isTristate()) {
- if (child->isInstalled())
- child->setCheckState(Qt::Checked);
- }
- }
- }
+ if (!d->buildComponentTree(components, false))
+ return false;
updateDisplayVersions(scDisplayVersion);
@@ -1587,55 +1561,8 @@ bool PackageManagerCore::fetchAllPackages(const PackagesList &remotes, const Loc
// store all components that got a replacement
storeReplacedComponents(components, data);
- try {
- // append all components to their respective parents
- for (QHash<QString, Component*>::const_iterator it = components.begin(); it != components.end(); ++it) {
- if (d->statusCanceledOrFailed())
- return false;
-
- QString id = it.key();
- QInstaller::Component *component = it.value();
- while (!id.isEmpty() && component->parentComponent() == 0) {
- id = id.section(QLatin1Char('.'), 0, -2);
- if (components.contains(id))
- components[id]->appendComponent(component);
- }
- }
-
- // append all components w/o parent to the direct list
- foreach (QInstaller::Component *component, components) {
- if (d->statusCanceledOrFailed())
- return false;
-
- if (component->parentComponent() == 0)
- appendRootComponent(component);
- }
-
- // after everything is set up, load the scripts
- foreach (QInstaller::Component *component, components) {
- if (d->statusCanceledOrFailed())
- return false;
-
- component->loadComponentScript();
-
- // set the checked state for all components without child (means without tristate)
- if (component->isCheckable() && !component->isTristate()) {
- if (component->isDefault() && isInstaller())
- component->setCheckState(Qt::Checked);
- else if (component->isInstalled())
- component->setCheckState(Qt::Checked);
- }
- }
- } catch (const Error &error) {
- d->clearAllComponentLists();
- emit finishAllComponentsReset();
- d->setStatus(Failure, error.message());
-
- // TODO: make sure we remove all message boxes inside the library at some point.
- MessageBoxHandler::critical(MessageBoxHandler::currentBestSuitParent(), QLatin1String("Error"),
- tr("Error"), error.message());
+ if (!d->buildComponentTree(components, true))
return false;
- }
emit finishAllComponentsReset();
return true;
@@ -1696,9 +1623,8 @@ bool PackageManagerCore::fetchUpdaterPackages(const PackagesList &remotes, const
if (localPackage.lastUpdateDate > updateDate)
continue;
- if (update->data(scEssential, scFalse).toString().toLower() == scTrue) {
+ if (update->data(scEssential, scFalse).toString().toLower() == scTrue)
foundEssentialUpdate = true;
- }
// this is not a dependency, it is a real update
components.insert(name, d->m_updaterComponentsDeps.takeLast());
@@ -1800,8 +1726,7 @@ void PackageManagerCore::updateDisplayVersions(const QString &displayKey)
}
QString PackageManagerCore::findDisplayVersion(const QString &componentName,
- const QHash<QString, QInstaller::Component *> &components,
- const QString &versionKey, QHash<QString, bool> &visited)
+ const QHash<QString, Component *> &components, const QString &versionKey, QHash<QString, bool> &visited)
{
const QString replaceWith = components.value(componentName)->value(scInheritVersion);
visited[componentName] = true;
diff --git a/installerbuilder/libinstaller/packagemanagercore_p.cpp b/installerbuilder/libinstaller/packagemanagercore_p.cpp
index 5b6a4f687..e17168745 100644
--- a/installerbuilder/libinstaller/packagemanagercore_p.cpp
+++ b/installerbuilder/libinstaller/packagemanagercore_p.cpp
@@ -267,6 +267,62 @@ QString PackageManagerCorePrivate::componentsXmlPath() const
.absoluteFilePath(configurationFileName()));
}
+bool PackageManagerCorePrivate::buildComponentTree(QHash<QString, Component*> &components, bool loadScript)
+{
+ try {
+ // append all components to their respective parents
+ QHash<QString, Component*>::const_iterator it;
+ for (it = components.begin(); it != components.end(); ++it) {
+ if (statusCanceledOrFailed())
+ return false;
+
+ QString id = it.key();
+ QInstaller::Component *component = it.value();
+ while (!id.isEmpty() && component->parentComponent() == 0) {
+ id = id.section(QLatin1Char('.'), 0, -2);
+ if (components.contains(id))
+ components[id]->appendComponent(component);
+ }
+ }
+
+ // append all components w/o parent to the direct list
+ foreach (QInstaller::Component *component, components) {
+ if (statusCanceledOrFailed())
+ return false;
+
+ if (component->parentComponent() == 0)
+ m_core->appendRootComponent(component);
+ }
+
+ // after everything is set up, load the scripts
+ foreach (QInstaller::Component *component, components) {
+ if (statusCanceledOrFailed())
+ return false;
+
+ if (loadScript)
+ component->loadComponentScript();
+
+ // set the checked state for all components without child (means without tristate)
+ if (component->isCheckable() && !component->isTristate()) {
+ if (component->isDefault() && isInstaller())
+ component->setCheckState(Qt::Checked);
+ else if (component->isInstalled())
+ component->setCheckState(Qt::Checked);
+ }
+ }
+ } catch (const Error &error) {
+ clearAllComponentLists();
+ emit m_core->finishAllComponentsReset();
+ setStatus(PackageManagerCore::Failure, error.message());
+
+ // TODO: make sure we remove all message boxes inside the library at some point.
+ MessageBoxHandler::critical(MessageBoxHandler::currentBestSuitParent(), QLatin1String("Error"),
+ tr("Error"), error.message());
+ return false;
+ }
+ return true;
+}
+
void PackageManagerCorePrivate::clearAllComponentLists()
{
qDeleteAll(m_rootComponents);
diff --git a/installerbuilder/libinstaller/packagemanagercore_p.h b/installerbuilder/libinstaller/packagemanagercore_p.h
index 2c92dee89..cc457857b 100644
--- a/installerbuilder/libinstaller/packagemanagercore_p.h
+++ b/installerbuilder/libinstaller/packagemanagercore_p.h
@@ -98,6 +98,8 @@ public:
QString componentsXmlPath() const;
QString configurationFileName() const;
+ bool buildComponentTree(QHash<QString, Component*> &components, bool loadScript);
+
void clearAllComponentLists();
void clearUpdaterComponentLists();
QList<Component*> &replacementDependencyComponents(RunMode mode);
@@ -194,7 +196,6 @@ private slots:
void handleMethodInvocationRequest(const QString &invokableMethodName);
-
private:
void deleteUninstaller();
void registerUninstaller();