summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/libs/installer/packagemanagergui.cpp20
-rw-r--r--src/libs/installer/packagemanagergui.h21
-rw-r--r--src/libs/installer/scriptengine.cpp155
-rw-r--r--src/libs/installer/scriptengine.h2
-rw-r--r--src/libs/installer/scriptengine_p.h45
-rw-r--r--tests/auto/installer/scriptengine/data/dynamicpage.qs10
-rw-r--r--tests/auto/installer/scriptengine/tst_scriptengine.cpp2
7 files changed, 214 insertions, 41 deletions
diff --git a/src/libs/installer/packagemanagergui.cpp b/src/libs/installer/packagemanagergui.cpp
index fd92aaaaa..3447da6ce 100644
--- a/src/libs/installer/packagemanagergui.cpp
+++ b/src/libs/installer/packagemanagergui.cpp
@@ -699,26 +699,6 @@ void PackageManagerGui::setSettingsButtonEnabled(bool enabled)
btn->setEnabled(enabled);
}
-/**
- Returns the first descendant of \a parent that has \a objectName as name.
-
- This method is meant to be invoked from script.
- */
-QObject *PackageManagerGui::findChild(QObject *parent, const QString &objectName)
-{
- return parent->findChild<QObject*>(objectName);
-}
-
-/**
- Returns all descendants of \a parent that have \a objectName as name.
-
- This method is meant to be invoked from script.
- */
-QList<QObject *> PackageManagerGui::findChildren(QObject *parent, const QString &objectName)
-{
- return parent->findChildren<QObject*>(objectName);
-}
-
void PackageManagerGui::customButtonClicked(int which)
{
if (QWizard::WizardButton(which) == QWizard::CustomButton1 && d->m_showSettingsButton)
diff --git a/src/libs/installer/packagemanagergui.h b/src/libs/installer/packagemanagergui.h
index f99d65593..4aabc6514 100644
--- a/src/libs/installer/packagemanagergui.h
+++ b/src/libs/installer/packagemanagergui.h
@@ -77,21 +77,18 @@ public:
void loadControlScript(const QString& scriptPath);
void callControlScriptMethod(const QString& methodName);
- Q_INVOKABLE QWidget *pageById(int id) const;
- Q_INVOKABLE QWidget *pageByObjectName(const QString &name) const;
+ QWidget *pageById(int id) const;
+ QWidget *pageByObjectName(const QString &name) const;
- Q_INVOKABLE QWidget* currentPageWidget() const;
- Q_INVOKABLE QWidget* pageWidgetByObjectName(const QString &name) const;
+ QWidget *currentPageWidget() const;
+ QWidget *pageWidgetByObjectName(const QString &name) const;
- Q_INVOKABLE QString defaultButtonText(int wizardButton) const;
- Q_INVOKABLE void clickButton(int wizardButton, int delayInMs = 0);
- Q_INVOKABLE bool isButtonEnabled(int wizardButton);
+ QString defaultButtonText(int wizardButton) const;
+ void clickButton(int wizardButton, int delayInMs = 0);
+ bool isButtonEnabled(int wizardButton);
- Q_INVOKABLE void showSettingsButton(bool show);
- Q_INVOKABLE void setSettingsButtonEnabled(bool enable);
-
- Q_INVOKABLE QObject *findChild(QObject *parent, const QString &objectName);
- Q_INVOKABLE QList<QObject*> findChildren(QObject *parent, const QString &objectName);
+ void showSettingsButton(bool show);
+ void setSettingsButtonEnabled(bool enable);
void updateButtonLayout();
static QWizard::WizardStyle getStyle(const QString &name);
diff --git a/src/libs/installer/scriptengine.cpp b/src/libs/installer/scriptengine.cpp
index ba5edd1c0..2ab7c47f8 100644
--- a/src/libs/installer/scriptengine.cpp
+++ b/src/libs/installer/scriptengine.cpp
@@ -189,40 +189,139 @@ namespace QInstaller {
*/
/*!
+ \qmlsignal gui::interrupted()
+*/
+
+/*!
+ \qmlsignal gui::languageChanged()
+*/
+
+/*!
+ \qmlsignal gui::finishButtonClicked()
+*/
+
+/*!
+ \qmlsignal gui::gotRestarted()
+*/
+
+/*!
+ \qmlsignal gui::settingsButtonClicked();
+*/
+
+GuiProxy::GuiProxy(ScriptEngine *engine, QObject *parent) :
+ QObject(parent),
+ m_engine(engine),
+ m_gui(0)
+{
+}
+
+void GuiProxy::setPackageManagerGui(PackageManagerGui *gui)
+{
+ if (m_gui) {
+ disconnect(m_gui, &PackageManagerGui::interrupted, this, &GuiProxy::interrupted);
+ disconnect(m_gui, &PackageManagerGui::languageChanged, this, &GuiProxy::languageChanged);
+ disconnect(m_gui, &PackageManagerGui::finishButtonClicked, this, &GuiProxy::finishButtonClicked);
+ disconnect(m_gui, &PackageManagerGui::gotRestarted, this, &GuiProxy::gotRestarted);
+ disconnect(m_gui, &PackageManagerGui::settingsButtonClicked, this, &GuiProxy::settingsButtonClicked);
+ }
+
+ m_gui = gui;
+
+ if (m_gui) {
+ connect(m_gui, &PackageManagerGui::interrupted, this, &GuiProxy::interrupted);
+ connect(m_gui, &PackageManagerGui::languageChanged, this, &GuiProxy::languageChanged);
+ connect(m_gui, &PackageManagerGui::finishButtonClicked, this, &GuiProxy::finishButtonClicked);
+ connect(m_gui, &PackageManagerGui::gotRestarted, this, &GuiProxy::gotRestarted);
+ connect(m_gui, &PackageManagerGui::settingsButtonClicked, this, &GuiProxy::settingsButtonClicked);
+ }
+}
+
+/*!
\qmlmethod object gui::pageById(int id)
*/
+QJSValue GuiProxy::pageById(int id) const
+{
+ if (!m_gui)
+ return QJSValue();
+ return m_engine->newQObject(m_gui->pageById(id));
+}
/*!
\qmlmethod object gui::pageByObjectName(string name)
*/
+QJSValue GuiProxy::pageByObjectName(const QString &name) const
+{
+ if (!m_gui)
+ return QJSValue();
+ return m_engine->newQObject(m_gui->pageByObjectName(name));
+}
/*!
\qmlmethod object gui::currentPageWidget()
*/
+QJSValue GuiProxy::currentPageWidget() const
+{
+ if (!m_gui)
+ return QJSValue();
+ return m_engine->newQObject(m_gui->currentPageWidget());
+}
/*!
\qmlmethod object gui::pageWidgetByObjectName(string name)
*/
+QJSValue GuiProxy::pageWidgetByObjectName(const QString &name) const
+{
+ if (!m_gui)
+ return QJSValue();
+ return m_engine->newQObject(m_gui->pageWidgetByObjectName(name));
+}
/*!
\qmlmethod string gui::defaultButtonText(int wizardButton)
*/
+QString GuiProxy::defaultButtonText(int wizardButton) const
+{
+ if (!m_gui)
+ return QString();
+ return m_gui->defaultButtonText(wizardButton);
+}
/*!
\qmlmethod void gui::clickButton(int wizardButton, int delayInMs)
*/
+void GuiProxy::clickButton(int wizardButton, int delayInMs)
+{
+ if (m_gui)
+ m_gui->clickButton(wizardButton, delayInMs);
+}
/*!
\qmlmethod boolean gui::isButtonEnabled(int wizardButton)
*/
+bool GuiProxy::isButtonEnabled(int wizardButton)
+{
+ if (!m_gui)
+ return false;
+ return m_gui->isButtonEnabled(wizardButton);
+}
/*!
\qmlmethod void gui::showSettingsButton(boolean show)
*/
+void GuiProxy::showSettingsButton(bool show)
+{
+ if (m_gui)
+ m_gui->showSettingsButton(show);
+}
/*!
\qmlmethod void gui::setSettingsButtonEnabled(boolean enable)
*/
+void GuiProxy::setSettingsButtonEnabled(bool enable)
+{
+ if (m_gui)
+ m_gui->setSettingsButtonEnabled(enable);
+}
/*!
\qmlmethod object gui::findChild(object parent, string objectName)
@@ -231,6 +330,10 @@ namespace QInstaller {
\sa QObject::findChild
*/
+QJSValue GuiProxy::findChild(QObject *parent, const QString &objectName)
+{
+ return m_engine->newQObject(parent->findChild<QObject*>(objectName));
+}
/*!
\qmlmethod object[] gui::findChildren(object parent, string objectName)
@@ -239,32 +342,66 @@ namespace QInstaller {
\sa QObject::findChildren
*/
+QList<QJSValue> GuiProxy::findChildren(QObject *parent, const QString &objectName)
+{
+ QList<QJSValue> children;
+ foreach (QObject *child, parent->findChildren<QObject*>(objectName))
+ children.append(m_engine->newQObject(child));
+ return children;
+}
/*!
- \qmlsignal gui::interrupted()
+ \qmlmethod void gui::cancelButtonClicked()
*/
+void GuiProxy::cancelButtonClicked()
+{
+ if (m_gui)
+ m_gui->cancelButtonClicked();
+}
/*!
- \qmlsignal gui::languageChanged()
+ \qmlmethod void gui::reject()
*/
+void GuiProxy::reject()
+{
+ if (m_gui)
+ m_gui->reject();
+}
/*!
- \qmlsignal gui::finishButtonClicked()
+ \qmlmethod void gui::rejectWithoutPrompt()
*/
+void GuiProxy::rejectWithoutPrompt()
+{
+ if (m_gui)
+ m_gui->rejectWithoutPrompt();
+}
/*!
- \qmlsignal gui::gotRestarted()
+ \qmlmethod void gui::showFinishedPage()
*/
+void GuiProxy::showFinishedPage()
+{
+ if (m_gui)
+ m_gui->showFinishedPage();
+}
/*!
- \qmlsignal gui::settingsButtonClicked();
+ \qmlmethod void gui::setModified(boolean value)
*/
+void GuiProxy::setModified(bool value)
+{
+ if (m_gui)
+ m_gui->setModified(value);
+}
+
/*!
Constructs a script engine with \a core as parent.
*/
-ScriptEngine::ScriptEngine(PackageManagerCore *core)
- : QObject(core)
+ScriptEngine::ScriptEngine(PackageManagerCore *core) :
+ QObject(core),
+ m_guiProxy(new GuiProxy(this, this))
{
QJSValue global = m_engine.globalObject();
global.setProperty(QLatin1String("console"), m_engine.newQObject(new ConsoleProxy));
@@ -304,6 +441,7 @@ ScriptEngine::ScriptEngine(PackageManagerCore *core)
} else {
global.setProperty(QLatin1String("installer"), m_engine.newQObject(new QObject));
}
+ global.setProperty(QLatin1String("gui"), m_engine.newQObject(m_guiProxy));
global.property(QLatin1String("installer")).setProperty(QLatin1String("componentByName"),
proxy.property(QLatin1String("componentByName")));
@@ -452,8 +590,7 @@ QJSValue ScriptEngine::callScriptMethod(const QJSValue &scriptContext, const QSt
void ScriptEngine::setGuiQObject(QObject *guiQObject)
{
- QQmlEngine::setObjectOwnership(guiQObject, QQmlEngine::CppOwnership);
- m_engine.globalObject().setProperty(QLatin1String("gui"), m_engine.newQObject(guiQObject));
+ m_guiProxy->setPackageManagerGui(qobject_cast<PackageManagerGui*>(guiQObject));
}
diff --git a/src/libs/installer/scriptengine.h b/src/libs/installer/scriptengine.h
index c5219dc09..5b8a3a3ec 100644
--- a/src/libs/installer/scriptengine.h
+++ b/src/libs/installer/scriptengine.h
@@ -43,6 +43,7 @@
namespace QInstaller {
class PackageManagerCore;
+class GuiProxy;
class INSTALLER_EXPORT ScriptEngine : public QObject
{
@@ -77,6 +78,7 @@ private:
private:
QJSEngine m_engine;
QHash<QString, QStringList> m_callstack;
+ GuiProxy *m_guiProxy;
};
}
diff --git a/src/libs/installer/scriptengine_p.h b/src/libs/installer/scriptengine_p.h
index d207130d7..696073703 100644
--- a/src/libs/installer/scriptengine_p.h
+++ b/src/libs/installer/scriptengine_p.h
@@ -37,6 +37,7 @@
#include "component.h"
#include "packagemanagercore.h"
+#include "packagemanagergui.h"
#include <QDebug>
#include <QDesktopServices>
@@ -137,6 +138,50 @@ public slots:
};
#endif
+class GuiProxy : public QObject
+{
+ Q_OBJECT
+ Q_DISABLE_COPY(GuiProxy)
+
+public:
+ GuiProxy(ScriptEngine *engine, QObject *parent);
+ void setPackageManagerGui(PackageManagerGui *gui);
+
+ Q_INVOKABLE QJSValue pageById(int id) const;
+ Q_INVOKABLE QJSValue pageByObjectName(const QString &name) const;
+
+ Q_INVOKABLE QJSValue currentPageWidget() const;
+ Q_INVOKABLE QJSValue pageWidgetByObjectName(const QString &name) const;
+
+ Q_INVOKABLE QString defaultButtonText(int wizardButton) const;
+ Q_INVOKABLE void clickButton(int wizardButton, int delayInMs = 0);
+ Q_INVOKABLE bool isButtonEnabled(int wizardButton);
+
+ Q_INVOKABLE void showSettingsButton(bool show);
+ Q_INVOKABLE void setSettingsButtonEnabled(bool enable);
+
+ Q_INVOKABLE QJSValue findChild(QObject *parent, const QString &objectName);
+ Q_INVOKABLE QList<QJSValue> findChildren(QObject *parent, const QString &objectName);
+
+signals:
+ void interrupted();
+ void languageChanged();
+ void finishButtonClicked();
+ void gotRestarted();
+ void settingsButtonClicked();
+
+public slots:
+ void cancelButtonClicked();
+ void reject();
+ void rejectWithoutPrompt();
+ void showFinishedPage();
+ void setModified(bool value);
+
+private:
+ ScriptEngine *m_engine;
+ PackageManagerGui *m_gui;
+};
+
} // namespace QInstaller
Q_DECLARE_METATYPE(QInstaller::ConsoleProxy*)
diff --git a/tests/auto/installer/scriptengine/data/dynamicpage.qs b/tests/auto/installer/scriptengine/data/dynamicpage.qs
index 4ac1990c1..576d5816e 100644
--- a/tests/auto/installer/scriptengine/data/dynamicpage.qs
+++ b/tests/auto/installer/scriptengine/data/dynamicpage.qs
@@ -32,8 +32,18 @@
**
**************************************************************************/
+function assert(condition)
+{
+ if (!condition)
+ throw new Error("Assertion failed!");
+}
+
function Controller()
{
+ var widget = gui.pageWidgetByObjectName("DynamicWidget");
+ assert(typeof widget === 'object');
+ var button = widget.Button;
+ assert(typeof button === 'object');
}
Controller.prototype.ReadAndSetValues = function()
diff --git a/tests/auto/installer/scriptengine/tst_scriptengine.cpp b/tests/auto/installer/scriptengine/tst_scriptengine.cpp
index 370d7eef4..10fa9b79e 100644
--- a/tests/auto/installer/scriptengine/tst_scriptengine.cpp
+++ b/tests/auto/installer/scriptengine/tst_scriptengine.cpp
@@ -83,6 +83,8 @@ public:
void init() {
m_widget = new QWidget;
m_widget->setObjectName("Widget");
+ QWidget *button = new QWidget(m_widget);
+ button->setObjectName("Button");
packageManagerCore()->wizardPageInsertionRequested(m_widget,
PackageManagerCore::Introduction);