summaryrefslogtreecommitdiffstats
path: root/src/libs/installer/component.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/libs/installer/component.cpp')
-rw-r--r--src/libs/installer/component.cpp511
1 files changed, 352 insertions, 159 deletions
diff --git a/src/libs/installer/component.cpp b/src/libs/installer/component.cpp
index f9e809565..ed815d18a 100644
--- a/src/libs/installer/component.cpp
+++ b/src/libs/installer/component.cpp
@@ -39,14 +39,16 @@
**
**************************************************************************/
#include "component.h"
+#include "scriptengine.h"
#include "errors.h"
#include "fileutils.h"
#include "fsengineclient.h"
+#include "globals.h"
#include "lib7z_facade.h"
-#include "packagemanagercore.h"
-#include "qinstallerglobal.h"
#include "messageboxhandler.h"
+#include "packagemanagercore.h"
+#include "settings.h"
#include <kdupdaterupdatesourcesinfo.h>
#include <kdupdaterupdateoperationfactory.h>
@@ -75,11 +77,132 @@ static const QLatin1String scCurrentState("CurrentState");
static const QLatin1String scForcedInstallation("ForcedInstallation");
/*!
- \class QInstaller::Component
- Component describes a component within the installer.
+ \qmltype Component
+ \inqmlmodule scripting
+
+ \brief Represents an installer component in Qt Script.
+
+ The object represents the component an install script belongs to. It is accessible through the
+ global \c component variable:
+
+ \code
+ function Component()
+ {
+ print("component: " + component.displayName);
+ }
+ \endcode
+*/
+
+/*!
+ \qmlproperty string Component::name
+
+ Returns the name of the component as set in the \c <Name> tag of the package
+ information file.
+*/
+
+/*!
+ \qmlproperty string Component::displayName
+
+ Returns the name of the component as shown in the user interface.
+*/
+
+/*!
+ \qmlproperty boolean Component::selected
+
+ Indicates whether the component is currently selected.
+*/
+
+/*!
+ \qmlproperty boolean Component::autoCreateOperations
+
+ Specifies whether some standard operations for the component should be
+ automatically created when the installation starts. The default is \c true.
+*/
+
+/*!
+ \qmlproperty stringlist Component::archives
+
+ Returns the list of archive URL's (prefixed with \c installer://) registered
+ for the component.
+
+ \sa addDownloadableArchive, removeDownloadableArchive
+*/
+
+/*!
+ \qmlproperty stringlist Component::dependencies
+
+ This read-only property contains components this component depends on.
+*/
+
+/*!
+ \qmlproperty stringlist Component::autoDependencies
+
+ Returns the value of the \c <AutoDependsOn> tag in the package information file.
+*/
+
+/*!
+ \qmlproperty boolean Component::fromOnlineRepository
+
+ Returns whether this component has been loaded from an online repository.
+
+ \sa isFromOnlineRepository
+*/
+
+/*!
+ \qmlproperty url Component::repositoryUrl
+
+ Returns the repository URL the component is downloaded from.
+ When this component is not downloaded from an online repository, returns an empty #QUrl.
+
+*/
+
+/*!
+ \qmlproperty boolean Component::default
+
+ This read-only property indicates if the component is a default one.
+
+ \note Always \c false for virtual components.
+
+ \sa isDefault
*/
/*!
+ \qmlproperty boolean Component::installed
+
+ This read-only property returns if the component is installed.
+
+ \sa isInstalled
+*/
+
+/*!
+ \qmlproperty boolean Component::enabled
+
+ Indicates whether the component is currently enabled. The property is both readable and writable.
+*/
+
+/*!
+ \qmlsignal Component::loaded()
+
+ Emitted when the component has been loaded.
+*/
+
+
+/*!
+ \qmlsignal Component::selectedChanged(boolean isSelected)
+
+ Emitted when the component selection has changed to \a isSelected.
+*/
+
+/*!
+ \qmlsignal Component::valueChanged(string key, string value)
+
+ Emitted when the variable with name \a key has changed to \a value.
+
+ \sa setValue
+*/
+
+
+/*!
Constructor. Creates a new Component inside of \a installer.
*/
Component::Component(PackageManagerCore *core)
@@ -146,15 +269,14 @@ void Component::loadDataFromPackage(const LocalPackage &package)
void Component::loadDataFromPackage(const Package &package)
{
Q_ASSERT(&package);
- Q_ASSERT(!package.name().isEmpty());
setValue(scName, package.data(scName).toString());
setValue(scDisplayName, package.data(scDisplayName).toString());
setValue(scDescription, package.data(scDescription).toString());
setValue(scDefault, package.data(scDefault).toString());
setValue(scAutoDependOn, package.data(scAutoDependOn).toString());
- setValue(scCompressedSize, QString::number(package.compressedSize()));
- setValue(scUncompressedSize, QString::number(package.uncompressedSize()));
+ setValue(scCompressedSize, package.data(scCompressedSize).toString());
+ setValue(scUncompressedSize, package.data(scUncompressedSize).toString());
setValue(scRemoteVersion, package.data(scRemoteVersion).toString());
setValue(scInheritVersion, package.data(scInheritVersion).toString());
setValue(scDependencies, package.data(scDependencies).toString());
@@ -181,14 +303,14 @@ void Component::loadDataFromPackage(const Package &package)
setCheckState(Qt::Checked);
}
- setLocalTempPath(QInstaller::pathFromUrl(package.sourceInfo().url));
- const QStringList uis = package.data(QLatin1String("UserInterfaces")).toString().split(scCommaRegExp,
- QString::SkipEmptyParts);
+ setLocalTempPath(QInstaller::pathFromUrl(package.sourceInfoUrl()));
+ const QStringList uis = package.data(QLatin1String("UserInterfaces")).toString()
+ .split(QInstaller::commaRegExp(), QString::SkipEmptyParts);
if (!uis.isEmpty())
loadUserInterfaces(QDir(QString::fromLatin1("%1/%2").arg(localTempPath(), name())), uis);
- const QStringList qms = package.data(QLatin1String("Translations")).toString().split(scCommaRegExp,
- QString::SkipEmptyParts);
+ const QStringList qms = package.data(QLatin1String("Translations")).toString()
+ .split(QInstaller::commaRegExp(), QString::SkipEmptyParts);
if (!qms.isEmpty())
loadTranslations(QDir(QString::fromLatin1("%1/%2").arg(localTempPath(), name())), qms);
@@ -227,9 +349,11 @@ QHash<QString,QString> Component::variables() const
}
/*!
+ \qmlmethod string Component::value(string key, string value = "")
+
Returns the value of variable name \a key. If \a key is not known yet, \a defaultValue is returned.
Note: If a component is virtual and you ask for the component value with key "Default", it will always
- return false.
+ return \c false.
*/
QString Component::value(const QString &key, const QString &defaultValue) const
{
@@ -239,6 +363,8 @@ QString Component::value(const QString &key, const QString &defaultValue) const
}
/*!
+ \qmlmethod void Component::setValue(string key, string value)
+
Sets the value of the variable with \a key to \a value.
*/
void Component::setValue(const QString &key, const QString &value)
@@ -264,8 +390,8 @@ PackageManagerCore *Component::packageManagerCore() const
}
/*!
- Returns the parent of this component. If this component is com.nokia.sdk.qt, its
- parent is com.nokia.sdk, as far as this exists.
+ Returns the parent of this component. If this component is org.qt-project.sdk.qt, its
+ parent is org.qt-project.sdk, as far as this exists.
*/
Component *Component::parentComponent() const
{
@@ -308,23 +434,22 @@ void Component::removeComponent(Component *component)
}
/*!
- Returns a list of child components. If \a recursive is set to true, the returned list
- contains not only the direct children, but all ancestors. Note: The returned list does include ALL
- children, non virtual components as well as virtual components.
+ Returns a list of child components. If \a kind is set to DirectChildrenOnly, the returned list contains
+ only the direct children, if set to Descendants it will also include all descendants of the components
+ children. Note: The returned list does include ALL children, non virtual components as well as virtual
+ components.
*/
-QList<Component*> Component::childComponents(bool recursive, RunMode runMode) const
+QList<Component *> Component::childComponents(Kind kind) const
{
- QList<Component*> result;
- if (runMode == UpdaterMode)
- return result;
+ if (d->m_core->isUpdater())
+ return QList<Component*>();
- if (!recursive)
- return d->m_allChildComponents;
+ QList<Component *> result = d->m_allChildComponents;
+ if (kind == DirectChildrenOnly)
+ return result;
- foreach (Component *component, d->m_allChildComponents) {
- result.append(component);
- result += component->childComponents(true, runMode);
- }
+ foreach (Component *component, d->m_allChildComponents)
+ result += component->childComponents(kind);
return result;
}
@@ -352,50 +477,25 @@ void Component::loadComponentScript()
}
/*!
- Loads the script at \a fileName into this component's script engine. The installer and all its
+ Loads the script at \a fileName into ScriptEngine. The installer and all its
components as well as other useful stuff are being exported into the script.
Read \link componentscripting Component Scripting \endlink for details.
- \throws Error when either the script at \a fileName couldn't be opened, or the QScriptEngine
+ Throws an error when either the script at \a fileName couldn't be opened, or the QScriptEngine
couldn't evaluate the script.
*/
void Component::loadComponentScript(const QString &fileName)
{
- QFile file(fileName);
- if (!file.open(QIODevice::ReadOnly)) {
- throw Error(tr("Could not open the requested script file at %1: %2.").arg(fileName, file.errorString()));
- }
+ ScriptEngine *scriptEngine = d->m_core->scriptEngine();
- d->scriptEngine()->evaluate(QLatin1String(file.readAll()), fileName);
- if (d->scriptEngine()->hasUncaughtException()) {
- throw Error(tr("Exception while loading the component script: %1")
- .arg(uncaughtExceptionString(d->scriptEngine()/*, QFileInfo(file).absoluteFilePath()*/)));
- }
-
- const QList<Component*> components = d->m_core->availableComponents();
- QScriptValue comps = d->scriptEngine()->newArray(components.count());
- for (int i = 0; i < components.count(); ++i)
- comps.setProperty(i, d->scriptEngine()->newQObject(components[i]));
-
- d->scriptEngine()->globalObject().property(QLatin1String("installer"))
- .setProperty(QLatin1String("components"), comps);
+ // introduce the component object as javascript value and call the name to check that it
+ // was successful
+ QString scriptInjection(QString::fromLatin1(
+ "var component = installer.componentByName('%1'); component.name;").arg(name()));
- QScriptValue comp = d->scriptEngine()->evaluate(QLatin1String("Component"), fileName);
- if (!d->scriptEngine()->hasUncaughtException()) {
- d->m_scriptComponent = comp;
- d->m_scriptComponent.construct();
- }
-
- //evaluate("Component") and construct can have an exception
- if (d->scriptEngine()->hasUncaughtException()) {
- throw Error(tr("Exception while loading the component script: %1")
- .arg(uncaughtExceptionString(d->scriptEngine(), QFileInfo(file).absoluteFilePath())));
- }
+ d->m_scriptContext = scriptEngine->loadInConext(QLatin1String("Component"), fileName, scriptInjection);
emit loaded();
languageChanged();
-
- //Solves a freeze seen on updater/ package manger restart.
- QCoreApplication::processEvents();
}
/*!
@@ -405,58 +505,38 @@ void Component::loadComponentScript(const QString &fileName)
*/
void Component::languageChanged()
{
- callScriptMethod(QLatin1String("retranslateUi"));
-}
-
-/*!
- Tries to call the method with \a name within the script and returns the result. If the method
- doesn't exist, an invalid result is returned. If the method has an uncaught exception, its
- string representation is thrown as an Error exception.
-
- \note The method is not called, if the current script context is the same method, to avoid
- infinite recursion.
-*/
-QScriptValue Component::callScriptMethod(const QString &methodName, const QScriptValueList &arguments) const
-{
- if (!d->m_unexistingScriptMethods.value(methodName, true))
- return QScriptValue();
-
- // don't allow such a recursion
- if (d->scriptEngine()->currentContext()->backtrace().first().startsWith(methodName))
- return QScriptValue();
-
- QScriptValue method = d->m_scriptComponent.property(QString::fromLatin1("prototype"))
- .property(methodName);
- if (!method.isValid()) // this marks the method to be called not any longer
- d->m_unexistingScriptMethods[methodName] = false;
-
- const QScriptValue result = method.call(d->m_scriptComponent, arguments);
- if (!result.isValid())
- return result;
-
- if (d->scriptEngine()->hasUncaughtException())
- throw Error(uncaughtExceptionString(d->scriptEngine()/*, name()*/));
-
- return result;
+ d->m_core->scriptEngine()->callScriptMethod(d->m_scriptContext, QLatin1String("retranslateUi"));
}
/*!
Loads the translations matching the name filters \a qms inside \a directory. Only translations
with a \link QFileInfo::baseName() baseName \endlink matching the current locales \link
QLocale::name() name \endlink are loaded.
- Read \ref componenttranslation for details.
+ Read \l componenttranslation for details.
*/
void Component::loadTranslations(const QDir &directory, const QStringList &qms)
{
QDirIterator it(directory.path(), qms, QDir::Files);
+ const QStringList translations = d->m_core->settings().translations();
+ const QString uiLanguage = QLocale().uiLanguages().value(0, QLatin1String("en_us"))
+ .replace(QLatin1Char('-'), QLatin1Char('_'));
while (it.hasNext()) {
const QString filename = it.next();
- if (QFileInfo(filename).baseName().toLower() != QLocale().name().toLower())
- continue;
+ const QString basename = QFileInfo(filename).baseName();
+ if (!uiLanguage.startsWith(QFileInfo(filename).baseName(), Qt::CaseInsensitive))
+ continue; // do not load the file if it does not match the UI language
+
+ if (!translations.isEmpty()) {
+ bool found = false;
+ foreach (const QString &translation, translations)
+ found |= translation.startsWith(basename, Qt::CaseInsensitive);
+ if (!found) // don't load the file if it does match the UI language but is not allowed to be used
+ continue;
+ }
QScopedPointer<QTranslator> translator(new QTranslator(this));
if (!translator->load(filename))
- throw Error(tr("Could not open the requested translation file at %1").arg(filename));
+ throw Error(tr("Could not open the requested translation file '%1'.").arg(filename));
qApp->installTranslator(translator.take());
}
}
@@ -464,7 +544,7 @@ void Component::loadTranslations(const QDir &directory, const QStringList &qms)
/*!
Loads the user interface files matching the name filters \a uis inside \a directory. The loaded
interface can be accessed via userInterfaces by using the class name set in the ui file.
- Read \ref componentuserinterfaces for details.
+ Read \l componentuserinterfaces for details.
*/
void Component::loadUserInterfaces(const QDir &directory, const QStringList &uis)
{
@@ -480,15 +560,23 @@ 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 at %1: %2").arg(it.fileName(),
+ throw Error(tr("Could not open the requested UI file '%1'. Error: %2").arg(it.fileName(),
file.errorString()));
}
static QUiLoader loader;
loader.setTranslationEnabled(true);
loader.setLanguageChangeEnabled(true);
- QWidget *const w = loader.load(&file, MessageBoxHandler::currentBestSuitParent());
- d->m_userInterfaces.insert(w->objectName(), w);
+ 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(),
+#if QT_VERSION < 0x050000
+ tr("An error has occurred while reading the UI file.")));
+#else
+ loader.errorString()));
+#endif
+ }
+ d->m_userInterfaces.insert(widget->objectName(), widget);
}
}
@@ -502,7 +590,7 @@ void Component::loadLicenses(const QString &directory, const QHash<QString, QVar
for (it = licenseHash.begin(); it != licenseHash.end(); ++it) {
const QString &fileName = it.value().toString();
- if (!ProductKeyCheck::instance()->isValidLicense(fileName))
+ if (!ProductKeyCheck::instance(d->m_core)->isValidLicenseTextFile(fileName))
continue;
QFileInfo fileInfo(fileName);
@@ -513,7 +601,7 @@ void Component::loadLicenses(const QString &directory, const QHash<QString, QVar
qDebug("Unable to open translated license file. Using untranslated fallback.");
file.setFileName(directory + fileName);
if (!file.open(QIODevice::ReadOnly)) {
- throw Error(tr("Could not open the requested license file at %1: %2").arg(fileName,
+ throw Error(tr("Could not open the requested license file '%1'. Error: %2").arg(fileName,
file.errorString()));
}
}
@@ -523,8 +611,11 @@ void Component::loadLicenses(const QString &directory, const QHash<QString, QVar
}
}
+
/*!
- Contains a list of all user interface class names known to this component.
+ \qmlproperty stringlist Component::userInterfaces
+
+ Returns a list of all user interface class names known to this component.
*/
QStringList Component::userInterfaces() const
{
@@ -537,6 +628,8 @@ QHash<QString, QPair<QString, QString> > Component::licenses() const
}
/*!
+ \qmlmethod QWidget Component::userInterface(string name)
+
Returns the QWidget created for \a name or 0 if the widget already has been deleted or cannot be found.
*/
QWidget *Component::userInterface(const QString &name) const
@@ -545,9 +638,11 @@ QWidget *Component::userInterface(const QString &name) const
}
/*!
+ \qmlmethod void Component::createOperationsForPath(string path)
+
Creates all operations needed to install this component's \a path. \a path is a full qualified
- filename including the component's name. This methods gets called from
- Component::createOperationsForArchive. You can override this method by providing a method with
+ filename including the component's name. This method gets called from
+ Component::createOperationsForArchive. You can override it by providing a method with
the same name in the component script.
\note RSA signature files are omitted by this method.
@@ -565,8 +660,10 @@ void Component::createOperationsForPath(const QString &path)
return;
// the script can override this method
- if (callScriptMethod(QLatin1String("createOperationsForPath"), QScriptValueList() << path).isValid())
+ if (d->m_core->scriptEngine()->callScriptMethod(d->m_scriptContext,
+ QLatin1String("createOperationsForPath"), QScriptValueList() << path).isValid()) {
return;
+ }
QString target;
static const QString prefix = QString::fromLatin1("installer://");
@@ -587,6 +684,8 @@ void Component::createOperationsForPath(const QString &path)
}
/*!
+ \qmlmethod void Component::createOperationsForArchive(string archive)
+
Creates all operations needed to install this component's \a archive. This method gets called
from Component::createOperations. You can override this method by providing a method with the
same name in the component script.
@@ -606,8 +705,10 @@ void Component::createOperationsForArchive(const QString &archive)
return;
// the script can override this method
- if (callScriptMethod(QLatin1String("createOperationsForArchive"), QScriptValueList() << archive).isValid())
+ if (d->m_core->scriptEngine()->callScriptMethod(d->m_scriptContext,
+ QLatin1String("createOperationsForArchive"), QScriptValueList() << archive).isValid()) {
return;
+ }
const bool isZip = Lib7z::isSupportedArchive(archive);
@@ -619,15 +720,34 @@ void Component::createOperationsForArchive(const QString &archive)
}
}
+/*!
+ \qmlmethod void Component::beginInstallation()
+
+ Starts the component installation.
+ You can override this method by providing a method with the same name in the component script.
+
+ \code
+ Component.prototype.beginInstallation = function()
+ {
+ // call default implementation
+ component.beginInstallation();
+ // ...
+ }
+ \endcode
+
+*/
void Component::beginInstallation()
{
// the script can override this method
- if (callScriptMethod(QLatin1String("beginInstallation")).isValid()) {
+ if (d->m_core->scriptEngine()->callScriptMethod(d->m_scriptContext,
+ QLatin1String("beginInstallation")).isValid()) {
return;
}
}
/*!
+ \qmlmethod void Component::createOperations()
+
Creates all operations needed to install this component.
You can override this method by providing a method with the same name in the component script.
@@ -638,7 +758,8 @@ void Component::beginInstallation()
void Component::createOperations()
{
// the script can override this method
- if (callScriptMethod(QLatin1String("createOperations")).isValid()) {
+ if (d->m_core->scriptEngine()->callScriptMethod(d->m_scriptContext,
+ QLatin1String("createOperations")).isValid()) {
d->m_operationsCreated = true;
return;
}
@@ -650,8 +771,10 @@ void Component::createOperations()
}
/*!
+ \qmlmethod void Component::registerPathForUninstallation(string path, boolean wipe = false)
+
Registers the file or directory at \a path for being removed when this component gets uninstalled.
- In case of a directory, this will be recursive. If \a wipe is set to true, the directory will
+ In case of a directory, this will be recursive. If \a wipe is set to \c true, the directory will
also be deleted if it contains changes done by the user after installation.
*/
void Component::registerPathForUninstallation(const QString &path, bool wipe)
@@ -660,6 +783,8 @@ void Component::registerPathForUninstallation(const QString &path, bool wipe)
}
/*!
+ \qmlmethod QList<QPair<string, boolean> > Component::pathesForUninstallation()
+
Returns the list of paths previously registered for uninstallation with
#registerPathForUninstallation.
*/
@@ -682,11 +807,13 @@ QStringList Component::archives() const
}
/*!
+ \qmlmethod void Component::addDownloadableArchive(string path)
+
Adds the archive \a path to this component. This can only be called when this component was
downloaded from an online repository. When adding \a path, it will be downloaded from the
repository when the installation starts.
- Read \ref sec_repogen for details. \sa fromOnlineRepository
+ \sa removeDownloadableArchive, fromOnlineRepository, archives
*/
void Component::addDownloadableArchive(const QString &path)
{
@@ -697,10 +824,12 @@ void Component::addDownloadableArchive(const QString &path)
}
/*!
+ \qmlmethod void Component::removeDownloadableArchive(string path)
+
Removes the archive \a path previously added via addDownloadableArchive from this component.
This can only be called when this component was downloaded from an online repository.
- Read \ref sec_repogen for details.
+ \sa addDownloadableArchive, fromOnlineRepository, archives
*/
void Component::removeDownloadableArchive(const QString &path)
{
@@ -717,7 +846,9 @@ QStringList Component::downloadableArchives() const
}
/*!
- Adds a request for quitting the process @p process before installing/updating/uninstalling the
+ \qmlmethod void Component::addStopProcessForUpdateRequest(string process)
+
+ Adds a request for quitting the process \a process before installing/updating/uninstalling the
component.
*/
void Component::addStopProcessForUpdateRequest(const QString &process)
@@ -726,7 +857,9 @@ void Component::addStopProcessForUpdateRequest(const QString &process)
}
/*!
- Removes the request for quitting the process @p process again.
+ \qmlmethod void Component::removeStopProcessForUpdateRequest(string process)
+
+ Removes the request for quitting the process \a process again.
*/
void Component::removeStopProcessForUpdateRequest(const QString &process)
{
@@ -734,7 +867,9 @@ void Component::removeStopProcessForUpdateRequest(const QString &process)
}
/*!
- Convenience: Add/remove request depending on @p requested (add if @p true, remove if @p false).
+ \qmlmethod void Component::setStopProcessForUpdateRequest(string process, boolean requested)
+
+ Convenience: Add/remove request depending on \a requested (add if \c true, remove if \c false).
*/
void Component::setStopProcessForUpdateRequest(const QString &process, bool requested)
{
@@ -753,7 +888,7 @@ QStringList Component::stopProcessForUpdateRequests() const
}
/*!
- Returns the operations needed to install this component. If autoCreateOperations is true,
+ Returns the operations needed to install this component. If autoCreateOperations is \c true,
createOperations is called, if no operations have been auto-created yet.
*/
OperationList Component::operations() const
@@ -812,7 +947,7 @@ bool Component::operationsCreatedSuccessfully() const
return d->m_operationsCreatedSuccessfully;
}
-Operation *Component::createOperation(const QString &operation, const QString &parameter1,
+Operation *Component::createOperation(const QString &operationName, const QString &parameter1,
const QString &parameter2, const QString &parameter3, const QString &parameter4, const QString &parameter5,
const QString &parameter6, const QString &parameter7, const QString &parameter8, const QString &parameter9,
const QString &parameter10)
@@ -839,36 +974,35 @@ Operation *Component::createOperation(const QString &operation, const QString &p
if (!parameter10.isNull())
arguments.append(parameter10);
- return createOperation(operation, arguments);
+ return createOperation(operationName, arguments);
}
-Operation *Component::createOperation(const QString &operation, const QStringList &parameters)
+Operation *Component::createOperation(const QString &operationName, const QStringList &parameters)
{
- Operation *op = KDUpdater::UpdateOperationFactory::instance().create(operation);
- if (op == 0) {
+ Operation *operation = KDUpdater::UpdateOperationFactory::instance().create(operationName);
+ if (operation == 0) {
const QMessageBox::StandardButton button =
MessageBoxHandler::critical(MessageBoxHandler::currentBestSuitParent(),
QLatin1String("OperationDoesNotExistError"), tr("Error"), tr("Error: Operation %1 does not exist")
- .arg(operation), QMessageBox::Abort | QMessageBox::Ignore);
+ .arg(operationName), QMessageBox::Abort | QMessageBox::Ignore);
if (button == QMessageBox::Abort)
d->m_operationsCreatedSuccessfully = false;
- return op;
+ return operation;
}
- if (op->name() == QLatin1String("Delete"))
- op->setValue(QLatin1String("performUndo"), false);
- op->setValue(QLatin1String("installer"), qVariantFromValue(d->m_core));
-
- op->setArguments(d->m_core->replaceVariables(parameters));
+ if (operation->name() == QLatin1String("Delete"))
+ operation->setValue(QLatin1String("performUndo"), false);
+ operation->setValue(QLatin1String("installer"), qVariantFromValue(d->m_core));
- return op;
+ operation->setArguments(d->m_core->replaceVariables(parameters));
+ operation->setValue(QLatin1String("component"), name());
+ return operation;
}
/*!
- Creates and adds an installation operation for \a operation. Add any number of \a parameter1,
- \a parameter2, \a parameter3, \a parameter4, \a parameter5 and \a parameter6. The contents of
- the parameters get variables like "@TargetDir@" replaced with their values, if contained.
- \sa installeroperations
+ \qmlmethod boolean Component::addOperation(string operation, string parameter1 = "", string parameter2 = "", ..., string parameter10 = "")
+
+ Convenience method for calling addOperation(string, stringlist) with up to 10 arguments.
*/
bool Component::addOperation(const QString &operation, const QString &parameter1, const QString &parameter2,
const QString &parameter3, const QString &parameter4, const QString &parameter5, const QString &parameter6,
@@ -883,6 +1017,13 @@ bool Component::addOperation(const QString &operation, const QString &parameter1
return false;
}
+/*!
+ \qmlmethod boolean Component::addOperation(string operation, stringlist parameters)
+
+ Creates and adds an installation operation for \a operation. Add any number of parameters.
+ The contents of the parameters get variables like "@TargetDir@" replaced with their values,
+ if contained.
+*/
bool Component::addOperation(const QString &operation, const QStringList &parameters)
{
if (Operation *op = createOperation(operation, parameters)) {
@@ -894,11 +1035,9 @@ bool Component::addOperation(const QString &operation, const QStringList &parame
}
/*!
- Creates and adds an installation operation for \a operation. Add any number of \a parameter1,
- \a parameter2, \a parameter3, \a parameter4, \a parameter5 and \a parameter6. The contents of
- the parameters get variables like "@TargetDir@" replaced with their values, if contained.
- \a operation is executed with elevated rights.
- \sa installeroperations
+ \qmlmethod boolean Component::addElevatedOperation(string operation, string parameter1 = "", string parameter2 = "", ..., string parameter10 = "")
+
+ Convenience method for calling addElevatedOperation(string, stringlist) with up to 10 arguments.
*/
bool Component::addElevatedOperation(const QString &operation, const QString &parameter1,
const QString &parameter2, const QString &parameter3, const QString &parameter4, const QString &parameter5,
@@ -914,6 +1053,14 @@ bool Component::addElevatedOperation(const QString &operation, const QString &pa
return false;
}
+/*!
+ \qmlmethod boolean Component::addElevatedOperation(string operation, stringlist parameters)
+
+ Creates and adds an installation operation for \a operation. Add any number of parameters.
+ The contents of the parameters get variables like "@TargetDir@" replaced with their values,
+ if contained. \a operation is executed with elevated rights.
+
+*/
bool Component::addElevatedOperation(const QString &operation, const QStringList &parameters)
{
if (Operation *op = createOperation(operation, parameters)) {
@@ -926,7 +1073,7 @@ bool Component::addElevatedOperation(const QString &operation, const QStringList
/*!
Specifies whether operations should be automatically created when the installation starts. This
- would be done by calling #createOperations. If you set this to false, it's completely up to the
+ 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.
*/
bool Component::autoCreateOperations() const
@@ -934,6 +1081,11 @@ bool Component::autoCreateOperations() const
return d->m_autoCreateOperations;
}
+/*!
+ \qmlmethod void Component::setAutoCreateOperations(boolean autoCreateOperations)
+
+ Setter for the \l autoCreateOperations property.
+ */
void Component::setAutoCreateOperations(bool autoCreateOperations)
{
d->m_autoCreateOperations = autoCreateOperations;
@@ -945,9 +1097,7 @@ bool Component::isVirtual() const
}
/*!
- \property Component::selected
- Specifies whether this component is selected for installation. Get this property's value by using
- %isSelected(), and set it using %setSelected().
+ Specifies whether this component is selected for installation.
*/
bool Component::isSelected() const
{
@@ -967,19 +1117,31 @@ void Component::setValidatorCallbackName(const QString &name)
bool Component::validatePage()
{
if (!validatorCallbackName.isEmpty())
- return callScriptMethod(validatorCallbackName).toBool();
+ return d->m_core->scriptEngine()->callScriptMethod(d->m_scriptContext, validatorCallbackName).toBool();
return true;
}
/*!
+ \qmlmethod void Component::setSelected(boolean selected)
+
Marks the component for installation. Emits the selectedChanged() signal if the check state changes.
+
+ \note This method does not do anything and is deprecated since 1.3.
*/
void Component::setSelected(bool selected)
{
Q_UNUSED(selected)
- qDebug() << Q_FUNC_INFO << QString::fromLatin1("on \"%1\" is deprecated!!!").arg(d->m_componentName);
+ qDebug() << Q_FUNC_INFO << QString::fromLatin1("on '%1' is deprecated.").arg(d->m_componentName);
}
+/*!
+ \qmlmethod void Component::addDependency(string newDependency)
+
+ Adds a new component \a newDependency to the list of dependencies.
+
+ \sa dependencies
+*/
+
void Component::addDependency(const QString &newDependency)
{
QString oldDependencies = d->m_vars.value(scDependencies);
@@ -992,22 +1154,24 @@ void Component::addDependency(const QString &newDependency)
/*!
Contains this component dependencies.
- Read \ref componentdependencies for details.
+ Read \l componentdependencies for details.
*/
QStringList Component::dependencies() const
{
- return d->m_vars.value(scDependencies).split(scCommaRegExp, QString::SkipEmptyParts);
+ return d->m_vars.value(scDependencies).split(QInstaller::commaRegExp(), QString::SkipEmptyParts);
}
QStringList Component::autoDependencies() const
{
QStringList autoDependencyStringList =
- d->m_vars.value(scAutoDependOn).split(scCommaRegExp, QString::SkipEmptyParts);
+ d->m_vars.value(scAutoDependOn).split(QInstaller::commaRegExp(), QString::SkipEmptyParts);
autoDependencyStringList.removeAll(QLatin1String("script"));
return autoDependencyStringList;
}
/*!
+ \qmlmethod void Component::setInstalled()
+
Set's the components state to installed.
*/
void Component::setInstalled()
@@ -1016,8 +1180,10 @@ void Component::setInstalled()
}
/*!
- Determines if the component comes as an auto dependency. Returns true if the component needs to be
- installed.
+ \qmlmethod boolean Component::isAutoDependOn(QSet<string> componentsToInstall)
+
+ Determines if the component comes as an auto dependency. Returns \c true if the component needs
+ to be installed.
*/
bool Component::isAutoDependOn(const QSet<QString> &componentsToInstall) const
{
@@ -1031,7 +1197,8 @@ bool Component::isAutoDependOn(const QSet<QString> &componentsToInstall) const
if (autoDependOnList.first().compare(QLatin1String("script"), Qt::CaseInsensitive) == 0) {
QScriptValue valueFromScript;
try {
- valueFromScript = callScriptMethod(QLatin1String("isAutoDependOn"));
+ valueFromScript = d->m_core->scriptEngine()->callScriptMethod(d->m_scriptContext,
+ QLatin1String("isAutoDependOn"));
} catch (const Error &error) {
MessageBoxHandler::critical(MessageBoxHandler::currentBestSuitParent(),
QLatin1String("isAutoDependOnError"), tr("Can't resolve isAutoDependOn in %1"
@@ -1063,8 +1230,13 @@ bool Component::isAutoDependOn(const QSet<QString> &componentsToInstall) const
}
/*!
- Determines if the component is a default one. Note: if a component is virtual, this function will always
- return false.
+ \qmlmethod boolean Component::isDefault()
+
+ Indicates if the component is a default one.
+
+ \note Always returns \c false for virtual components.
+
+ \sa default
*/
bool Component::isDefault() const
{
@@ -1075,7 +1247,8 @@ bool Component::isDefault() const
if (d->m_vars.value(scDefault).compare(QLatin1String("script"), Qt::CaseInsensitive) == 0) {
QScriptValue valueFromScript;
try {
- valueFromScript = callScriptMethod(QLatin1String("isDefault"));
+ valueFromScript = d->m_core->scriptEngine()->callScriptMethod(d->m_scriptContext,
+ QLatin1String("isDefault"));
} catch (const Error &error) {
MessageBoxHandler::critical(MessageBoxHandler::currentBestSuitParent(),
QLatin1String("isDefaultError"), tr("Can't resolve isDefault in %1").arg(name()),
@@ -1092,6 +1265,8 @@ bool Component::isDefault() const
}
/*!
+ \qmlmethod boolean Component::isInstalled()
+
Determines if the component is installed.
*/
bool Component::isInstalled() const
@@ -1100,6 +1275,8 @@ bool Component::isInstalled() const
}
/*!
+ \qmlmethod boolean Component::installationRequested()
+
Determines if the user wants to install the component
*/
bool Component::installationRequested() const
@@ -1108,6 +1285,8 @@ bool Component::installationRequested() const
}
/*!
+ \qmlmethod void Component::setUpdateAvailable(boolean isUpdateAvailable)
+
Sets a flag that the core found an update
*/
void Component::setUpdateAvailable(bool isUpdateAvailable)
@@ -1116,6 +1295,8 @@ void Component::setUpdateAvailable(bool isUpdateAvailable)
}
/*!
+ \qmlmethod boolean Component::updateRequested()
+
Determines if the user wants to install the update for this component
*/
bool Component::updateRequested()
@@ -1124,7 +1305,9 @@ bool Component::updateRequested()
}
/*!
- Returns true if that component will be changed (update/installation/uninstallation)
+ \qmlmethod boolean Component::componentChangeRequested()
+
+ Returns \c true if that component will be changed (update/installation/uninstallation).
*/
bool Component::componentChangeRequested()
{
@@ -1133,6 +1316,8 @@ bool Component::componentChangeRequested()
/*!
+ \qmlmethod void Component::setUninstalled()
+
Sets the component state to uninstalled.
*/
void Component::setUninstalled()
@@ -1141,6 +1326,8 @@ void Component::setUninstalled()
}
/*!
+ \qmlmethod boolean Component::isUninstalled()
+
Determines if the component is uninstalled.
*/
bool Component::isUninstalled() const
@@ -1149,6 +1336,8 @@ bool Component::isUninstalled() const
}
/*!
+ \qmlmethod boolean Component::uninstallationRequested()
+
Determines if the user wants to uninstall the component.
*/
bool Component::uninstallationRequested() const
@@ -1159,10 +1348,11 @@ bool Component::uninstallationRequested() const
}
/*!
- \property Component::fromOnlineRepository
+ \qmlmethod boolean Component::isFromOnlineRepository()
- Determines whether this component has been loaded from an online repository. Get this property's
- value by using %isFromOnlineRepository. \sa addDownloadableArchive
+ Determines whether this component has been loaded from an online repository.
+
+ \sa addDownloadableArchive, fromOnlineRepository
*/
bool Component::isFromOnlineRepository() const
{
@@ -1213,6 +1403,9 @@ void Component::updateModelData(const QString &key, const QString &data)
if (key == scDisplayVersion)
setData(data, LocalDisplayVersion);
+ if (key == scReleaseDate)
+ setData(data, ReleaseDate);
+
if (key == scUncompressedSize) {
quint64 size = d->m_vars.value(scUncompressedSizeSum).toLongLong();
setData(humanReadableSize(size), UncompressedSize);