summaryrefslogtreecommitdiffstats
path: root/src/libs/installer
diff options
context:
space:
mode:
authorTim Jenssen <tim.jenssen@digia.com>2013-11-06 12:45:23 +0100
committerTim Jenssen <tim.jenssen@digia.com>2013-11-06 16:51:35 +0100
commit016cdad413c878be9c669398cd707ff5d1d98255 (patch)
tree384a45a3ecd01fe5b071aca445dfca9cff59a731 /src/libs/installer
parent0e63df370ec23e793c0bfb27c469f2606fbf104a (diff)
Restart on the wizard needs to cleanup component left-overs
- use two different script engine instances - one which lives from the beginning -> the controlScriptEngine - the other one which will be reset if there are some new repositories loaded - now the core has a pointer to the gui object, but it should only be used by the script engine so a QObject type should be enough - engines are deleted as QObject children from the PackageManagerCore - registered downloaded archives are removed Change-Id: I60a4a32fb2e409059839ec11b10c57357454f57a Reviewed-by: Michal Klocek <michal.klocek@digia.com> Reviewed-by: Karsten Heimrich <karsten.heimrich@digia.com>
Diffstat (limited to 'src/libs/installer')
-rw-r--r--src/libs/installer/binaryformatenginehandler.cpp7
-rw-r--r--src/libs/installer/binaryformatenginehandler.h1
-rw-r--r--src/libs/installer/component.cpp21
-rw-r--r--src/libs/installer/component_p.cpp5
-rw-r--r--src/libs/installer/component_p.h3
-rw-r--r--src/libs/installer/packagemanagercore.cpp22
-rw-r--r--src/libs/installer/packagemanagercore.h8
-rw-r--r--src/libs/installer/packagemanagercore_p.cpp43
-rw-r--r--src/libs/installer/packagemanagercore_p.h10
-rw-r--r--src/libs/installer/packagemanagergui.cpp6
-rw-r--r--src/libs/installer/scriptengine.cpp3
11 files changed, 103 insertions, 26 deletions
diff --git a/src/libs/installer/binaryformatenginehandler.cpp b/src/libs/installer/binaryformatenginehandler.cpp
index d872ed229..1364ff431 100644
--- a/src/libs/installer/binaryformatenginehandler.cpp
+++ b/src/libs/installer/binaryformatenginehandler.cpp
@@ -122,3 +122,10 @@ void BinaryFormatEngineHandler::registerArchive(const QString &pathName, const Q
c.appendArchive(newArchive);
d->index.insertComponent(c);
}
+
+void BinaryFormatEngineHandler::resetRegisteredArchives()
+{
+ QVector<QInstallerCreator::Component> registeredComponents = d->index.components();
+ foreach (const QInstallerCreator::Component &component, registeredComponents)
+ d->index.removeComponent(component.name());
+}
diff --git a/src/libs/installer/binaryformatenginehandler.h b/src/libs/installer/binaryformatenginehandler.h
index cccc2f523..107f834f4 100644
--- a/src/libs/installer/binaryformatenginehandler.h
+++ b/src/libs/installer/binaryformatenginehandler.h
@@ -67,6 +67,7 @@ public:
static BinaryFormatEngineHandler *instance();
void registerArchive(const QString &fileName, const QString &path);
+ void resetRegisteredArchives();
private:
class Private;
diff --git a/src/libs/installer/component.cpp b/src/libs/installer/component.cpp
index 472f269fc..4fb390040 100644
--- a/src/libs/installer/component.cpp
+++ b/src/libs/installer/component.cpp
@@ -486,14 +486,12 @@ void Component::loadComponentScript()
*/
void Component::loadComponentScript(const QString &fileName)
{
- ScriptEngine *scriptEngine = d->m_core->scriptEngine();
-
// 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()));
- d->m_scriptContext = scriptEngine->loadInConext(QLatin1String("Component"), fileName, scriptInjection);
+ d->m_scriptContext = d->scriptEngine()->loadInConext(QLatin1String("Component"), fileName, scriptInjection);
emit loaded();
languageChanged();
@@ -506,7 +504,7 @@ void Component::loadComponentScript(const QString &fileName)
*/
void Component::languageChanged()
{
- d->m_core->scriptEngine()->callScriptMethod(d->m_scriptContext, QLatin1String("retranslateUi"));
+ d->scriptEngine()->callScriptMethod(d->m_scriptContext, QLatin1String("retranslateUi"));
}
/*!
@@ -661,7 +659,7 @@ void Component::createOperationsForPath(const QString &path)
return;
// the script can override this method
- if (d->m_core->scriptEngine()->callScriptMethod(d->m_scriptContext,
+ if (d->scriptEngine()->callScriptMethod(d->m_scriptContext,
QLatin1String("createOperationsForPath"), QScriptValueList() << path).isValid()) {
return;
}
@@ -706,7 +704,7 @@ void Component::createOperationsForArchive(const QString &archive)
return;
// the script can override this method
- if (d->m_core->scriptEngine()->callScriptMethod(d->m_scriptContext,
+ if (d->scriptEngine()->callScriptMethod(d->m_scriptContext,
QLatin1String("createOperationsForArchive"), QScriptValueList() << archive).isValid()) {
return;
}
@@ -740,7 +738,7 @@ void Component::createOperationsForArchive(const QString &archive)
void Component::beginInstallation()
{
// the script can override this method
- if (d->m_core->scriptEngine()->callScriptMethod(d->m_scriptContext,
+ if (d->scriptEngine()->callScriptMethod(d->m_scriptContext,
QLatin1String("beginInstallation")).isValid()) {
return;
}
@@ -759,7 +757,7 @@ void Component::beginInstallation()
void Component::createOperations()
{
// the script can override this method
- if (d->m_core->scriptEngine()->callScriptMethod(d->m_scriptContext,
+ if (d->scriptEngine()->callScriptMethod(d->m_scriptContext,
QLatin1String("createOperations")).isValid()) {
d->m_operationsCreated = true;
return;
@@ -1120,7 +1118,8 @@ void Component::setValidatorCallbackName(const QString &name)
bool Component::validatePage()
{
if (!validatorCallbackName.isEmpty())
- return d->m_core->scriptEngine()->callScriptMethod(d->m_scriptContext, validatorCallbackName).toBool();
+ return d->scriptEngine()->callScriptMethod(
+ d->m_scriptContext, validatorCallbackName).toBool();
return true;
}
@@ -1200,7 +1199,7 @@ bool Component::isAutoDependOn(const QSet<QString> &componentsToInstall) const
if (autoDependOnList.first().compare(QLatin1String("script"), Qt::CaseInsensitive) == 0) {
QScriptValue valueFromScript;
try {
- valueFromScript = d->m_core->scriptEngine()->callScriptMethod(d->m_scriptContext,
+ valueFromScript = d->scriptEngine()->callScriptMethod(d->m_scriptContext,
QLatin1String("isAutoDependOn"));
} catch (const Error &error) {
MessageBoxHandler::critical(MessageBoxHandler::currentBestSuitParent(),
@@ -1250,7 +1249,7 @@ bool Component::isDefault() const
if (d->m_vars.value(scDefault).compare(QLatin1String("script"), Qt::CaseInsensitive) == 0) {
QScriptValue valueFromScript;
try {
- valueFromScript = d->m_core->scriptEngine()->callScriptMethod(d->m_scriptContext,
+ valueFromScript = d->scriptEngine()->callScriptMethod(d->m_scriptContext,
QLatin1String("isDefault"));
} catch (const Error &error) {
MessageBoxHandler::critical(MessageBoxHandler::currentBestSuitParent(),
diff --git a/src/libs/installer/component_p.cpp b/src/libs/installer/component_p.cpp
index 560cd6544..ae4a149a5 100644
--- a/src/libs/installer/component_p.cpp
+++ b/src/libs/installer/component_p.cpp
@@ -87,6 +87,11 @@ ComponentPrivate::~ComponentPrivate()
delete widget.data();
}
+ScriptEngine *ComponentPrivate::scriptEngine() const
+{
+ return m_core->componentScriptEngine();
+}
+
// -- ComponentModelHelper
ComponentModelHelper::ComponentModelHelper()
diff --git a/src/libs/installer/component_p.h b/src/libs/installer/component_p.h
index 1da9eee1a..821e891d7 100644
--- a/src/libs/installer/component_p.h
+++ b/src/libs/installer/component_p.h
@@ -53,6 +53,7 @@ namespace QInstaller {
class Component;
class PackageManagerCore;
+class ScriptEngine;
class ComponentPrivate
{
@@ -62,6 +63,8 @@ public:
explicit ComponentPrivate(PackageManagerCore *core, Component *qq);
~ComponentPrivate();
+ ScriptEngine *scriptEngine() const;
+
PackageManagerCore *m_core;
Component *m_parentComponent;
OperationList m_operations;
diff --git a/src/libs/installer/packagemanagercore.cpp b/src/libs/installer/packagemanagercore.cpp
index 5a4deec3d..fc1ecff02 100644
--- a/src/libs/installer/packagemanagercore.cpp
+++ b/src/libs/installer/packagemanagercore.cpp
@@ -428,6 +428,19 @@ void PackageManagerCore::reset(const QHash<QString, QString> &params)
d->initialize(params);
}
+void PackageManagerCore::setGuiObject(QObject *gui)
+{
+ if (gui == d->m_guiObject)
+ return;
+ d->m_guiObject = gui;
+ emit guiObjectChanged(gui);
+}
+
+QObject *PackageManagerCore::guiObject() const
+{
+ return d->m_guiObject;
+}
+
/*!
\qmlmethod void QInstaller::setCompleteUninstallation(bool complete)
@@ -1090,9 +1103,14 @@ void PackageManagerCore::setTestChecksum(bool test)
d->m_testChecksum = test;
}
-ScriptEngine *PackageManagerCore::scriptEngine()
+ScriptEngine *PackageManagerCore::componentScriptEngine() const
+{
+ return d->componentScriptEngine();
+}
+
+ScriptEngine *PackageManagerCore::controlScriptEngine() const
{
- return d->scriptEngine();
+ return d->controlScriptEngine();
}
/*!
diff --git a/src/libs/installer/packagemanagercore.h b/src/libs/installer/packagemanagercore.h
index 557c4d9ed..392e5a018 100644
--- a/src/libs/installer/packagemanagercore.h
+++ b/src/libs/installer/packagemanagercore.h
@@ -125,6 +125,9 @@ public:
bool run();
void reset(const QHash<QString, QString> &params);
+ void setGuiObject(QObject *gui);
+ QObject *guiObject() const;
+
Q_INVOKABLE void setDependsOnLocalInstallerBinary();
Q_INVOKABLE bool localInstallerBinaryUsed();
@@ -177,7 +180,8 @@ public:
Q_INVOKABLE bool fileExists(const QString &filePath) const;
public:
- ScriptEngine *scriptEngine();
+ ScriptEngine *componentScriptEngine() const;
+ ScriptEngine *controlScriptEngine() const;
// component handling
@@ -301,6 +305,8 @@ Q_SIGNALS:
void setAutomatedPageSwitchEnabled(bool request);
void coreNetworkSettingsChanged();
+ void guiObjectChanged(QObject *gui);
+
private:
struct Data {
Package *package;
diff --git a/src/libs/installer/packagemanagercore_p.cpp b/src/libs/installer/packagemanagercore_p.cpp
index daa0158e8..b012cff3c 100644
--- a/src/libs/installer/packagemanagercore_p.cpp
+++ b/src/libs/installer/packagemanagercore_p.cpp
@@ -212,10 +212,12 @@ PackageManagerCorePrivate::PackageManagerCorePrivate(PackageManagerCore *core)
, m_repoFetched(false)
, m_updateSourcesAdded(false)
, m_componentsToInstallCalculated(false)
- , m_scriptEngine(0)
+ , m_componentScriptEngine(0)
+ , m_controlScriptEngine(0)
, m_proxyFactory(0)
, m_defaultModel(0)
, m_updaterModel(0)
+ , m_guiObject(0)
{
}
@@ -239,10 +241,12 @@ PackageManagerCorePrivate::PackageManagerCorePrivate(PackageManagerCore *core, q
, m_updateSourcesAdded(false)
, m_magicBinaryMarker(magicInstallerMaker)
, m_componentsToInstallCalculated(false)
- , m_scriptEngine(0)
+ , m_componentScriptEngine(0)
+ , m_controlScriptEngine(0)
, m_proxyFactory(0)
, m_defaultModel(0)
, m_updaterModel(0)
+ , m_guiObject(0)
{
connect(this, SIGNAL(installationStarted()), m_core, SIGNAL(installationStarted()));
connect(this, SIGNAL(installationFinished()), m_core, SIGNAL(installationFinished()));
@@ -265,11 +269,13 @@ PackageManagerCorePrivate::~PackageManagerCorePrivate()
m_FSEngineClientHandler->setActive(false);
delete m_updateFinder;
- delete m_scriptEngine;
delete m_proxyFactory;
delete m_defaultModel;
delete m_updaterModel;
+
+ // at the moment the tabcontroller deletes the m_gui, this needs to be changed in the future
+ // delete m_gui;
}
/*!
@@ -392,11 +398,30 @@ bool PackageManagerCorePrivate::buildComponentTree(QHash<QString, Component*> &c
return true;
}
-ScriptEngine *PackageManagerCorePrivate::scriptEngine()
+void PackageManagerCorePrivate::cleanUpComponentEnvironment()
+{
+ // clean up already downloaded data
+ if (QInstallerCreator::BinaryFormatEngineHandler::instance())
+ QInstallerCreator::BinaryFormatEngineHandler::instance()->resetRegisteredArchives();
+
+ // there could be still some references to already deleted components,
+ // so we need to remove the current component script engine
+ delete m_componentScriptEngine;
+ m_componentScriptEngine = 0;
+}
+
+ScriptEngine *PackageManagerCorePrivate::componentScriptEngine() const
{
- if (!m_scriptEngine)
- m_scriptEngine = new ScriptEngine(m_core);
- return m_scriptEngine;
+ if (!m_componentScriptEngine)
+ m_componentScriptEngine = new ScriptEngine(m_core);
+ return m_componentScriptEngine;
+}
+
+ScriptEngine *PackageManagerCorePrivate::controlScriptEngine() const
+{
+ if (!m_controlScriptEngine)
+ m_controlScriptEngine = new ScriptEngine(m_core);
+ return m_controlScriptEngine;
}
void PackageManagerCorePrivate::clearAllComponentLists()
@@ -411,6 +436,8 @@ void PackageManagerCorePrivate::clearAllComponentLists()
delete list.at(i).second;
m_componentsToReplaceAllMode.clear();
m_componentsToInstallCalculated = false;
+
+ cleanUpComponentEnvironment();
}
void PackageManagerCorePrivate::clearUpdaterComponentLists()
@@ -435,6 +462,8 @@ void PackageManagerCorePrivate::clearUpdaterComponentLists()
m_componentsToReplaceUpdaterMode.clear();
m_componentsToInstallCalculated = false;
+
+ cleanUpComponentEnvironment();
}
QList<Component *> &PackageManagerCorePrivate::replacementDependencyComponents()
diff --git a/src/libs/installer/packagemanagercore_p.h b/src/libs/installer/packagemanagercore_p.h
index 445235a0d..a6b9d4438 100644
--- a/src/libs/installer/packagemanagercore_p.h
+++ b/src/libs/installer/packagemanagercore_p.h
@@ -135,7 +135,10 @@ public:
bool buildComponentTree(QHash<QString, Component*> &components, bool loadScript);
- ScriptEngine *scriptEngine();
+ void cleanUpComponentEnvironment();
+ ScriptEngine *componentScriptEngine() const;
+ ScriptEngine *controlScriptEngine() const;
+
void clearAllComponentLists();
void clearUpdaterComponentLists();
QList<Component*> &replacementDependencyComponents();
@@ -263,7 +266,8 @@ private:
qint64 m_magicBinaryMarker;
bool m_componentsToInstallCalculated;
- ScriptEngine *m_scriptEngine;
+ mutable ScriptEngine *m_componentScriptEngine;
+ mutable ScriptEngine *m_controlScriptEngine;
// < name (component to replace), < replacement component, component to replace > >
QHash<QString, QPair<Component*, Component*> > m_componentsToReplaceAllMode;
QHash<QString, QPair<Component*, Component*> > m_componentsToReplaceUpdaterMode;
@@ -285,6 +289,8 @@ private:
ComponentModel *m_defaultModel;
ComponentModel *m_updaterModel;
+ QObject *m_guiObject;
+
private:
// remove once we deprecate isSelected, setSelected etc...
void resetComponentsToUserCheckedState();
diff --git a/src/libs/installer/packagemanagergui.cpp b/src/libs/installer/packagemanagergui.cpp
index fc81ad9ff..98abefe75 100644
--- a/src/libs/installer/packagemanagergui.cpp
+++ b/src/libs/installer/packagemanagergui.cpp
@@ -285,7 +285,7 @@ PackageManagerGui::PackageManagerGui(PackageManagerCore *core, QWidget *parent)
for (int i = QWizard::BackButton; i < QWizard::CustomButton1; ++i)
d->m_defaultButtonText.insert(i, buttonText(QWizard::WizardButton(i)));
- m_core->scriptEngine()->setGuiQObject(this);
+ m_core->setGuiObject(this);
}
PackageManagerGui::~PackageManagerGui()
@@ -354,7 +354,7 @@ void PackageManagerGui::setValidatorForCustomPageRequested(Component *component,
*/
void PackageManagerGui::loadControlScript(const QString &scriptPath)
{
- d->m_controlScriptContext = m_core->scriptEngine()->loadInConext(
+ d->m_controlScriptContext = m_core->controlScriptEngine()->loadInConext(
QLatin1String("Controller"), scriptPath);
qDebug() << "Loaded control script" << scriptPath;
}
@@ -364,7 +364,7 @@ void PackageManagerGui::callControlScriptMethod(const QString &methodName)
if (!d->m_controlScriptContext.isValid())
return;
try {
- QScriptValue returnValue = m_core->scriptEngine()->callScriptMethod(
+ QScriptValue returnValue = m_core->controlScriptEngine()->callScriptMethod(
d->m_controlScriptContext, methodName);
if (!returnValue.isValid()) {
diff --git a/src/libs/installer/scriptengine.cpp b/src/libs/installer/scriptengine.cpp
index 4e236be7f..9931d956e 100644
--- a/src/libs/installer/scriptengine.cpp
+++ b/src/libs/installer/scriptengine.cpp
@@ -212,6 +212,9 @@ ScriptEngine::ScriptEngine(PackageManagerCore *core)
.setProperty(QLatin1String("components"), scriptComponentsObject);
connect(this, SIGNAL(signalHandlerException(QScriptValue)), SLOT(handleException(QScriptValue)));
+
+ connect(core, SIGNAL(guiObjectChanged(QObject*)), this, SLOT(setGuiQObject(QObject*)));
+ setGuiQObject(core->guiObject());
}
ScriptEngine::~ScriptEngine()