diff options
Diffstat (limited to 'src/libs/installer/component.cpp')
-rw-r--r-- | src/libs/installer/component.cpp | 141 |
1 files changed, 72 insertions, 69 deletions
diff --git a/src/libs/installer/component.cpp b/src/libs/installer/component.cpp index ac0cf97ec..db9f2689d 100644 --- a/src/libs/installer/component.cpp +++ b/src/libs/installer/component.cpp @@ -38,8 +38,7 @@ #include "settings.h" #include "utils.h" -#include <kdupdaterupdatesourcesinfo.h> -#include <kdupdaterupdateoperationfactory.h> +#include "updateoperationfactory.h" #include <productkeycheck.h> @@ -50,18 +49,22 @@ #include <QtUiTools/QUiLoader> +#include <private/qv8engine_p.h> +#include <private/qv4scopedvalue_p.h> +#include <private/qv4object_p.h> + #include <algorithm> using namespace QInstaller; static const QLatin1String scScriptTag("Script"); -static const QLatin1String scAutoDependOn("AutoDependOn"); static const QLatin1String scVirtual("Virtual"); static const QLatin1String scInstalled("Installed"); static const QLatin1String scUpdateText("UpdateText"); static const QLatin1String scUninstalled("Uninstalled"); static const QLatin1String scCurrentState("CurrentState"); static const QLatin1String scForcedInstallation("ForcedInstallation"); +static const QLatin1String scCheckable("Checkable"); /*! \inmodule QtInstallerFramework @@ -207,7 +210,7 @@ Component::Component(PackageManagerCore *core) { setPrivate(d); - connect(this, SIGNAL(valueChanged(QString, QString)), this, SLOT(updateModelData(QString, QString))); + connect(this, &Component::valueChanged, this, &Component::updateModelData); qRegisterMetaType<QList<QInstaller::Component*> >("QList<QInstaller::Component*>"); } @@ -236,10 +239,9 @@ Component::~Component() /*! Sets variables according to the values set in the package.xml file of a local \a package. */ -void Component::loadDataFromPackage(const LocalPackage &package) +void Component::loadDataFromPackage(const KDUpdater::LocalPackage &package) { setValue(scName, package.name); - // pixmap ??? setValue(scDisplayName, package.title); setValue(scDescription, package.description); setValue(scVersion, package.version); @@ -248,14 +250,8 @@ void Component::loadDataFromPackage(const LocalPackage &package) setValue(QLatin1String("LastUpdateDate"), package.lastUpdateDate.toString()); setValue(QLatin1String("InstallDate"), package.installDate.toString()); setValue(scUncompressedSize, QString::number(package.uncompressedSize)); - - QString dependstr; - foreach (const QString &val, package.dependencies) - dependstr += val + QLatin1String(","); - - if (package.dependencies.count() > 0) - dependstr.chop(1); - setValue(scDependencies, dependstr); + setValue(scDependencies, package.dependencies.join(QLatin1String(","))); + setValue(scAutoDependOn, package.autoDependencies.join(QLatin1String(","))); setValue(scForcedInstallation, package.forcedInstallation ? scTrue : scFalse); if (package.forcedInstallation & !PackageManagerCore::noForceInstallation()) { @@ -264,6 +260,7 @@ void Component::loadDataFromPackage(const LocalPackage &package) } setValue(scVirtual, package.virtualComp ? scTrue : scFalse); setValue(scCurrentState, scInstalled); + setValue(scCheckable, package.checkable ? scTrue : scFalse); } /*! @@ -281,7 +278,7 @@ void Component::loadDataFromPackage(const Package &package) setValue(scAutoDependOn, package.data(scAutoDependOn).toString()); setValue(scCompressedSize, package.data(scCompressedSize).toString()); setValue(scUncompressedSize, package.data(scUncompressedSize).toString()); - setValue(scRemoteVersion, package.data(scRemoteVersion).toString()); + setValue(scVersion, package.data(scVersion).toString()); setValue(scInheritVersion, package.data(scInheritVersion).toString()); setValue(scDependencies, package.data(scDependencies).toString()); setValue(scDownloadableArchives, package.data(scDownloadableArchives).toString()); @@ -296,6 +293,7 @@ void Component::loadDataFromPackage(const Package &package) setValue(scScriptTag, package.data(scScriptTag).toString()); setValue(scReplaces, package.data(scReplaces).toString()); setValue(scReleaseDate, package.data(scReleaseDate).toString()); + setValue(scCheckable, package.data(scCheckable).toString()); QString forced = package.data(scForcedInstallation, scFalse).toString().toLower(); if (PackageManagerCore::noForceInstallation()) @@ -306,7 +304,7 @@ void Component::loadDataFromPackage(const Package &package) setCheckState(Qt::Checked); } - setLocalTempPath(QInstaller::pathFromUrl(package.sourceInfoUrl())); + setLocalTempPath(QInstaller::pathFromUrl(package.packageSource().url)); const QStringList uis = package.data(QLatin1String("UserInterfaces")).toString() .split(QInstaller::commaRegExp(), QString::SkipEmptyParts); if (!uis.isEmpty()) @@ -387,6 +385,8 @@ void Component::setValue(const QString &key, const QString &value) if (key == scName) d->m_componentName = normalizedValue; + if (key == scCheckable) + this->setCheckable(normalizedValue.toLower() == scTrue); d->m_vars[key] = normalizedValue; emit valueChanged(key, normalizedValue); @@ -569,8 +569,8 @@ void Component::loadUserInterfaces(const QDir &directory, const QStringList &uis while (it.hasNext()) { QFile file(it.next()); if (!file.open(QIODevice::ReadOnly)) { - throw Error(tr("Could not open the requested UI file '%1'. Error: %2").arg(it.fileName(), - file.errorString())); + throw Error(tr("Cannot open the requested UI file \"%1\": %2").arg( + it.fileName(), file.errorString())); } static QUiLoader loader; @@ -578,8 +578,8 @@ void Component::loadUserInterfaces(const QDir &directory, const QStringList &uis loader.setLanguageChangeEnabled(true); QWidget *const widget = loader.load(&file, 0); if (!widget) { - throw Error(tr("Could not load the requested UI file '%1'. Error: %2").arg(it.fileName(), - loader.errorString())); + throw Error(tr("Cannot load the requested UI file \"%1\": %2").arg( + it.fileName(), loader.errorString())); } d->scriptEngine()->newQObject(widget); d->m_userInterfaces.insert(widget->objectName(), widget); @@ -623,7 +623,7 @@ void Component::loadLicenses(const QString &directory, const QHash<QString, QVar QFile file(fileInfo.filePath()); if (!file.open(QIODevice::ReadOnly)) { - throw Error(tr("Could not open the requested license file '%1'. Error: %2").arg( + throw Error(tr("Cannot open the requested license file \"%1\": %2").arg( file.fileName(), file.errorString())); } QTextStream stream(&file); @@ -697,11 +697,11 @@ void Component::createOperationsForPath(const QString &path) if (fi.isFile()) { static const QString copy = QString::fromLatin1("Copy"); - addOperation(copy, fi.filePath(), target); + addOperation(copy, QStringList() << fi.filePath() << target); } else if (fi.isDir()) { qApp->processEvents(); static const QString mkdir = QString::fromLatin1("Mkdir"); - addOperation(mkdir, target); + addOperation(mkdir, QStringList(target)); QDirIterator it(fi.filePath()); while (it.hasNext()) @@ -741,7 +741,7 @@ void Component::createOperationsForArchive(const QString &archive) if (isZip) { // archives get completely extracted per default (if the script isn't doing other stuff) - addOperation(QLatin1String("Extract"), archive, QLatin1String("@TargetDir@")); + addOperation(QLatin1String("Extract"), QStringList() << archive << QLatin1String("@TargetDir@")); } else { createOperationsForPath(archive); } @@ -822,7 +822,7 @@ void Component::addDownloadableArchive(const QString &path) Q_ASSERT(isFromOnlineRepository()); qDebug() << "addDownloadable" << path; - d->m_downloadableArchives.append(d->m_vars.value(scRemoteVersion) + path); + d->m_downloadableArchives.append(d->m_vars.value(scVersion) + path); } /*! @@ -901,15 +901,14 @@ OperationList Component::operations() const if (!d->m_minimumProgressOperation) { d->m_minimumProgressOperation = KDUpdater::UpdateOperationFactory::instance() - .create(QLatin1String("MinimumProgress")); + .create(QLatin1String("MinimumProgress"), d->m_core); d->m_minimumProgressOperation->setValue(QLatin1String("component"), name()); d->m_operations.append(d->m_minimumProgressOperation); } if (!d->m_licenses.isEmpty()) { d->m_licenseOperation = KDUpdater::UpdateOperationFactory::instance() - .create(QLatin1String("License")); - d->m_licenseOperation->setValue(QLatin1String("installer"), QVariant::fromValue(d->m_core)); + .create(QLatin1String("License"), d->m_core); d->m_licenseOperation->setValue(QLatin1String("component"), name()); QVariantMap licenses; @@ -983,11 +982,12 @@ Operation *Component::createOperation(const QString &operationName, const QStrin Operation *Component::createOperation(const QString &operationName, const QStringList ¶meters) { - Operation *operation = KDUpdater::UpdateOperationFactory::instance().create(operationName); + Operation *operation = KDUpdater::UpdateOperationFactory::instance().create(operationName, + d->m_core); if (operation == 0) { const QMessageBox::StandardButton button = MessageBoxHandler::critical(MessageBoxHandler::currentBestSuitParent(), - QLatin1String("OperationDoesNotExistError"), tr("Error"), tr("Error: Operation %1 does not exist") + QLatin1String("OperationDoesNotExistError"), tr("Error"), tr("Error: Operation %1 does not exist.") .arg(operationName), QMessageBox::Abort | QMessageBox::Ignore); if (button == QMessageBox::Abort) d->m_operationsCreatedSuccessfully = false; @@ -996,33 +996,50 @@ Operation *Component::createOperation(const QString &operationName, const QStrin if (operation->name() == QLatin1String("Delete")) operation->setValue(QLatin1String("performUndo"), false); - operation->setValue(QLatin1String("installer"), qVariantFromValue(d->m_core)); operation->setArguments(d->m_core->replaceVariables(parameters)); operation->setValue(QLatin1String("component"), name()); return operation; } -/*! - Convenience method for calling the operation \a operation with up to ten parameters: - \a parameter1, \a parameter2, \a parameter3, \a parameter4, \a parameter5, \a parameter6, - \a parameter7, \a parameter8, \a parameter9, and \a parameter10. - - Returns \c true if the operation succeeds, otherwise returns \c false. +namespace { - \sa {component::addOperation}{component.addOperation} -*/ -bool Component::addOperation(const QString &operation, const QString ¶meter1, const QString ¶meter2, - const QString ¶meter3, const QString ¶meter4, const QString ¶meter5, const QString ¶meter6, - const QString ¶meter7, const QString ¶meter8, const QString ¶meter9, const QString ¶meter10) +inline bool convert(QQmlV4Function *func, QStringList *toArgs) { + if (func->length() < 2) + return false; - if (Operation *op = createOperation(operation, parameter1, parameter2, parameter3, parameter4, parameter5, - parameter6, parameter7, parameter8, parameter9, parameter10)) { - addOperation(op); - return true; + QV4::Scope scope(func->v4engine()); + QV4::ScopedValue val(scope); + val = (*func)[0]; + + *toArgs << val->toQString(); + for (int i = 1; i < func->length(); i++) { + val = (*func)[i]; + if (val->isObject() && val->as<QV4::Object>()->isArrayObject()) { + QV4::ScopedValue valtmp(scope); + QV4::Object *array = val->as<QV4::Object>(); + uint length = array->getLength(); + for (uint ii = 0; ii < length; ++ii) { + valtmp = array->getIndexed(ii); + *toArgs << valtmp->toQStringNoThrow(); + } + } else { + *toArgs << val->toQString(); + } } + return true; +} +} +/*! + \internal +*/ +bool Component::addOperation(QQmlV4Function *func) +{ + QStringList args; + if (convert(func, &args)) + return addOperation(args[0], args.mid(1)); return false; } @@ -1031,7 +1048,7 @@ bool Component::addOperation(const QString &operation, const QString ¶meter1 The variables that the parameters contain, such as \c @TargetDir@, are replaced with their values. - Returns \c true if the operation succeeds, otherwise returns \c false. + \sa {component::addOperation}{component.addOperation} */ bool Component::addOperation(const QString &operation, const QStringList ¶meters) { @@ -1044,25 +1061,13 @@ bool Component::addOperation(const QString &operation, const QStringList ¶me } /*! - Convenience method for calling the elevated operation \a operation with up to ten parameters: - \a parameter1, \a parameter2, \a parameter3, \a parameter4, \a parameter5, \a parameter6, - \a parameter7, \a parameter8, \a parameter9, and \a parameter10. - - \sa {component::addElevatedOperation}{component.addElevatedOperation} - - Returns \c true if the operation succeeds, otherwise returns \c false. + \internal */ -bool Component::addElevatedOperation(const QString &operation, const QString ¶meter1, - const QString ¶meter2, const QString ¶meter3, const QString ¶meter4, const QString ¶meter5, - const QString ¶meter6, const QString ¶meter7, const QString ¶meter8, const QString ¶meter9, - const QString ¶meter10) +bool Component::addElevatedOperation(QQmlV4Function *func) { - if (Operation *op = createOperation(operation, parameter1, parameter2, parameter3, parameter4, parameter5, - parameter6, parameter7, parameter8, parameter9, parameter10)) { - addElevatedOperation(op); - return true; - } - + QStringList args; + if (convert(func, &args)) + return addElevatedOperation(args[0], args.mid(1)); return false; } @@ -1071,8 +1076,7 @@ bool Component::addElevatedOperation(const QString &operation, const QString &pa The variables that the parameters contain, such as \c @TargetDir@, are replaced with their values. The operation is executed with elevated rights. - Returns \c true if the operation succeeds, otherwise returns \c false. - + \sa {component::addElevatedOperation}{component.addElevatedOperation} */ bool Component::addElevatedOperation(const QString &operation, const QStringList ¶meters) { @@ -1085,9 +1089,8 @@ bool Component::addElevatedOperation(const QString &operation, const QStringList } /*! - Returns whether operations should be automatically created when the - installation starts and createOperations() is called. If you set this to - \c false, it is completely up + Specifies whether operations should be automatically created when the installation starts. This + would be done by calling createOperations(). If you set this to \c false, it is completely up to the component's script to create all operations. \sa {component::autoCreateOperations}{component.autoCreateOperations} |