diff options
author | Katja Marttila <katja.marttila@qt.io> | 2018-02-28 09:54:22 +0200 |
---|---|---|
committer | Katja Marttila <katja.marttila@qt.io> | 2018-04-05 06:54:21 +0000 |
commit | d2ae9c16c3427c272d41e9a471f705ad8947a97a (patch) | |
tree | 4ed6b3cafd28b11f02ef4f4faa6164bcfbd85b63 /src | |
parent | 6664ca85f09d6ae195ac30f83a60d53c2355da0f (diff) |
Add attribute to mark parts of install tree unstable
This commit adds new AllowUnstableComponents configuration. Setting
AllowUnstablecomponents to true in config.xml will
* allow installing other components when there are errors in scripts
* allow installing other components when there are missing dependencies
* will mark the 'broken' components uninstallable in treeview
Task-number: QTIFW-930
Change-Id: I8d28cf9c4b0401e0bb76795e87d581f39b64f128
Reviewed-by: Iikka Eklund <iikka.eklund@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/libs/installer/component.cpp | 71 | ||||
-rw-r--r-- | src/libs/installer/component.h | 4 | ||||
-rw-r--r-- | src/libs/installer/component_p.h | 1 | ||||
-rw-r--r-- | src/libs/installer/componentmodel.cpp | 7 | ||||
-rw-r--r-- | src/libs/installer/constants.h | 1 | ||||
-rw-r--r-- | src/libs/installer/installercalculator.cpp | 11 | ||||
-rw-r--r-- | src/libs/installer/settings.cpp | 15 | ||||
-rw-r--r-- | src/libs/installer/settings.h | 3 |
8 files changed, 101 insertions, 12 deletions
diff --git a/src/libs/installer/component.cpp b/src/libs/installer/component.cpp index 9be2357cd..65dfbbc8d 100644 --- a/src/libs/installer/component.cpp +++ b/src/libs/installer/component.cpp @@ -67,6 +67,7 @@ static const QLatin1String scCurrentState("CurrentState"); static const QLatin1String scForcedInstallation("ForcedInstallation"); static const QLatin1String scCheckable("Checkable"); static const QLatin1String scExpandedByDefault("ExpandedByDefault"); +static const QLatin1String scUnstable("Unstable"); /*! \inmodule QtInstallerFramework @@ -511,9 +512,29 @@ void Component::loadComponentScript(const QString &fileName) { // introduce the component object as javascript value and call the name to check that it // was successful - d->m_scriptContext = d->scriptEngine()->loadInContext(QLatin1String("Component"), fileName, - QString::fromLatin1("var component = installer.componentByName('%1'); component.name;") - .arg(name())); + try { + d->m_scriptContext = d->scriptEngine()->loadInContext(QLatin1String("Component"), fileName, + QString::fromLatin1("var component = installer.componentByName('%1'); component.name;") + .arg(name())); + if (packageManagerCore()->settings().allowUnstableComponents()) { + // Check if component has dependency to a broken component. Dependencies to broken + // components are checked if error is thrown but if dependency to a broken + // component is added in script, the script might not be loaded yet + foreach (QString dependency, dependencies()) { + Component *dependencyComponent = packageManagerCore()->componentByName + (PackageManagerCore::checkableName(dependency)); + if (dependencyComponent && dependencyComponent->isUnstable()) + setUnstable(); + } + } + } catch (const Error &error) { + if (packageManagerCore()->settings().allowUnstableComponents()) { + setUnstable(); + qWarning() << error.message(); + } else { + throw error; + } + } emit loaded(); languageChanged(); @@ -1008,6 +1029,13 @@ Operation *Component::createOperation(const QString &operationName, const QStrin return operation; } +void Component::markComponentUnstable() +{ + setValue(scDefault, scFalse); + setCheckState(Qt::Unchecked); + setValue(scUnstable, scTrue); +} + namespace { inline bool convert(QQmlV4Function *func, QStringList *toArgs) @@ -1339,6 +1367,31 @@ bool Component::isUninstalled() const return scUninstalled == d->m_vars.value(scCurrentState); } +bool Component::isUnstable() const +{ + return scTrue == d->m_vars.value(scUnstable); +} + +void Component::setUnstable() +{ + QList<Component*> dependencies = d->m_core->dependees(this); + // Mark this component unstable + markComponentUnstable(); + + // Marks all components unstable that depend on the unstable component + foreach (Component *dependency, dependencies) { + dependency->markComponentUnstable(); + foreach (Component *descendant, dependency->descendantComponents()) { + descendant->markComponentUnstable(); + } + } + + // Marks all child components unstable + foreach (Component *descendant, this->descendantComponents()) { + descendant->markComponentUnstable(); + } +} + /*! Returns whether the user wants to uninstall the component. @@ -1424,13 +1477,21 @@ void Component::updateModelData(const QString &key, const QString &data) const QString &updateInfo = d->m_vars.value(scUpdateText); if (!d->m_core->isUpdater() || updateInfo.isEmpty()) { - const QString tooltipText + QString tooltipText = QString::fromLatin1("<html><body>%1</body></html>").arg(d->m_vars.value(scDescription)); + if (isUnstable()) { + tooltipText += QLatin1String("<br>") + tr("There was an error loading the selected component. " + "This component can not be installed."); + } setData(tooltipText, Qt::ToolTipRole); } else { - const QString tooltipText + QString tooltipText = d->m_vars.value(scDescription) + QLatin1String("<br><br>") + tr("Update Info: ") + updateInfo; + if (isUnstable()) { + tooltipText += QLatin1String("<br>") + tr("There was an error loading the selected component. " + "This component can not be updated."); + } setData(tooltipText, Qt::ToolTipRole); } diff --git a/src/libs/installer/component.h b/src/libs/installer/component.h index b11fd4cef..574117b6d 100644 --- a/src/libs/installer/component.h +++ b/src/libs/installer/component.h @@ -62,6 +62,7 @@ class INSTALLER_EXPORT Component : public QObject, public ComponentModelHelper Q_PROPERTY(bool default READ isDefault) Q_PROPERTY(bool installed READ isInstalled) Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled) + Q_PROPERTY(bool unstable READ isUnstable) public: explicit Component(PackageManagerCore *core); @@ -182,6 +183,8 @@ public: Q_INVOKABLE bool componentChangeRequested(); + bool isUnstable() const; + void setUnstable(); bool isVirtual() const; bool isSelected() const; @@ -212,6 +215,7 @@ private: const QString ¶meter8 = QString(), const QString ¶meter9 = QString(), const QString ¶meter10 = QString()); Operation *createOperation(const QString &operationName, const QStringList ¶meters); + void markComponentUnstable(); private: QString validatorCallbackName; diff --git a/src/libs/installer/component_p.h b/src/libs/installer/component_p.h index 60cbd8075..b9f50b557 100644 --- a/src/libs/installer/component_p.h +++ b/src/libs/installer/component_p.h @@ -63,6 +63,7 @@ public: bool m_autoCreateOperations; bool m_operationsCreatedSuccessfully; bool m_updateIsAvailable; + bool m_unstable; QString m_componentName; QUrl m_repositoryUrl; diff --git a/src/libs/installer/componentmodel.cpp b/src/libs/installer/componentmodel.cpp index 0f8a47c38..078afc50a 100644 --- a/src/libs/installer/componentmodel.cpp +++ b/src/libs/installer/componentmodel.cpp @@ -222,14 +222,15 @@ QVariant ComponentModel::data(const QModelIndex &index, int role) const return component->data(Qt::UserRole + index.column()); } if (role == Qt::CheckStateRole) { - if (!component->isCheckable()) - return QVariant(); - if (!component->autoDependencies().isEmpty()) + if (!component->isCheckable() || !component->autoDependencies().isEmpty() || component->isUnstable()) return QVariant(); } if (role == ComponentModelHelper::ExpandedByDefault) { return component->isExpandedByDefault(); } + if (component->isUnstable() && role == Qt::ForegroundRole) { + return QVariant(QColor(Qt::lightGray)); + } return component->data(role); } return QVariant(); diff --git a/src/libs/installer/constants.h b/src/libs/installer/constants.h index 7f44acbe7..ddfa8c555 100644 --- a/src/libs/installer/constants.h +++ b/src/libs/installer/constants.h @@ -89,6 +89,7 @@ static const QLatin1String scUrlQueryString("UrlQueryString"); static const QLatin1String scProductUUID("ProductUUID"); static const QLatin1String scAllUsers("AllUsers"); static const QLatin1String scSupportsModify("SupportsModify"); +static const QLatin1String scAllowUnstableComponents("AllowUnstableComponents"); const char scRelocatable[] = "@RELOCATABLE_PATH@"; diff --git a/src/libs/installer/installercalculator.cpp b/src/libs/installer/installercalculator.cpp index d44450eb2..4e0d7fdfa 100644 --- a/src/libs/installer/installercalculator.cpp +++ b/src/libs/installer/installercalculator.cpp @@ -30,6 +30,7 @@ #include "component.h" #include "packagemanagercore.h" +#include "settings.h" #include <QDebug> @@ -94,7 +95,8 @@ QString InstallerCalculator::componentsToInstallError() const void InstallerCalculator::realAppendToInstallComponents(Component *component, const QString &version) { - if (!component->isInstalled(version) || component->updateRequested()) { + if (!component->isUnstable() && + (!component->isInstalled(version) || component->updateRequested())) { m_orderedComponentsToInstall.append(component); m_toInstallComponentIds.insert(component->name()); } @@ -169,7 +171,12 @@ bool InstallerCalculator::appendComponentToInstall(Component *component, const Q component->name()); qWarning().noquote() << errorMessage; m_componentsToInstallError.append(errorMessage); - return false; + if (component->packageManagerCore()->settings().allowUnstableComponents()) { + component->setUnstable(); + return true; + } else { + return false; + } } //Check if component requires higher version than what might be already installed bool isUpdateRequired = false; diff --git a/src/libs/installer/settings.cpp b/src/libs/installer/settings.cpp index 79d4bcddc..3d5d4b858 100644 --- a/src/libs/installer/settings.cpp +++ b/src/libs/installer/settings.cpp @@ -256,7 +256,7 @@ Settings Settings::fromFileAndPrefix(const QString &path, const QString &prefix, << scWizardDefaultWidth << scWizardDefaultHeight << scRepositorySettingsPageVisible << scTargetConfigurationFile << scRemoteRepositories << scTranslations << scUrlQueryString << QLatin1String(scControlScript) - << scCreateLocalRepository << scInstallActionColumnVisible << scSupportsModify; + << scCreateLocalRepository << scInstallActionColumnVisible << scSupportsModify << scAllowUnstableComponents; Settings s; s.d->m_data.insert(scPrefix, prefix); @@ -325,7 +325,8 @@ Settings Settings::fromFileAndPrefix(const QString &path, const QString &prefix, s.d->m_data.insert(scCreateLocalRepository, false); if (!s.d->m_data.contains(scInstallActionColumnVisible)) s.d->m_data.insert(scInstallActionColumnVisible, false); - + if (!s.d->m_data.contains(scAllowUnstableComponents)) + s.d->m_data.insert(scAllowUnstableComponents, false); return s; } @@ -743,3 +744,13 @@ bool Settings::supportsModify() const { return d->m_data.value(scSupportsModify, true).toBool(); } + +bool Settings::allowUnstableComponents() const +{ + return d->m_data.value(scAllowUnstableComponents, true).toBool(); +} + +void Settings::setAllowUnstableComponents(bool allow) +{ + d->m_data.insert(scAllowUnstableComponents, allow); +} diff --git a/src/libs/installer/settings.h b/src/libs/installer/settings.h index 3dc1c99c3..45c4fbcc3 100644 --- a/src/libs/installer/settings.h +++ b/src/libs/installer/settings.h @@ -154,6 +154,9 @@ public: bool supportsModify() const; + bool allowUnstableComponents() const; + void setAllowUnstableComponents(bool allow); + private: class Private; QSharedDataPointer<Private> d; |