From 6f5816fc575927201a1aa9cc1fdb0c75a1a3ab69 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Wed, 15 Jun 2016 11:00:57 +0200 Subject: [PATCH] ensure the scriptengine is here ensure the scriptengine gets created also for c++ applets that have a valid scriptengine, move the script init out of applet::init that can be reimplemented. remove the second appletscript constructor that is not necessary anymore REVIEWED-BY: Kai Uwe Broulik --- src/plasma/applet.cpp | 6 +- src/plasma/containment.cpp | 2 + src/plasma/private/applet_p.cpp | 9 +++ src/plasma/private/applet_p.h | 1 + .../qml/plasmoid/appletinterface.cpp | 57 ------------------- .../qml/plasmoid/appletinterface.h | 1 - .../qml/plasmoid/containmentinterface.cpp | 5 +- 7 files changed, 15 insertions(+), 66 deletions(-) diff --git a/src/plasma/applet.cpp b/src/plasma/applet.cpp index 5480d3a0c..58c794fa3 100644 --- a/src/plasma/applet.cpp +++ b/src/plasma/applet.cpp @@ -123,11 +123,7 @@ Applet::~Applet() void Applet::init() { - if (d->script) { - if (!d->script->init() && !d->failed) { - setLaunchErrorMessage(i18n("Script initialization failed")); - } - } + //Don't implement anything here, it will be overridden by subclasses } uint Applet::id() const diff --git a/src/plasma/containment.cpp b/src/plasma/containment.cpp index c7a8b7d48..31b83927a 100644 --- a/src/plasma/containment.cpp +++ b/src/plasma/containment.cpp @@ -97,6 +97,7 @@ Containment::~Containment() void Containment::init() { Applet::init(); + static_cast(this)->d->setupScripting(); if (d->type == Types::NoContainmentType) { //setContainmentType(Plasma::Types::DesktopContainment); @@ -449,6 +450,7 @@ void Containment::addApplet(Applet *applet) } applet->init(); + applet->d->setupScripting(); if (isNew) { applet->save(*applet->d->mainConfigGroup()); diff --git a/src/plasma/private/applet_p.cpp b/src/plasma/private/applet_p.cpp index 67b423ce6..b0f9edb56 100644 --- a/src/plasma/private/applet_p.cpp +++ b/src/plasma/private/applet_p.cpp @@ -462,6 +462,15 @@ void AppletPrivate::setupPackage() } } +void AppletPrivate::setupScripting() +{ + if (script) { + if (!script->init() && !failed) { + q->setLaunchErrorMessage(i18n("Script initialization failed")); + } + } +} + QString AppletPrivate::globalName() const { if (!appletDescription.isValid()) { diff --git a/src/plasma/private/applet_p.h b/src/plasma/private/applet_p.h index 157fb1fee..7a7dc3d4b 100644 --- a/src/plasma/private/applet_p.h +++ b/src/plasma/private/applet_p.h @@ -57,6 +57,7 @@ public: // put all setup routines for script here. at this point we can assume that // package exists and that we have a script engin void setupPackage(); + void setupScripting(); QString globalName() const; void scheduleConstraintsUpdate(Plasma::Types::Constraints c); diff --git a/src/scriptengines/qml/plasmoid/appletinterface.cpp b/src/scriptengines/qml/plasmoid/appletinterface.cpp index df2d64244..e122db1fa 100644 --- a/src/scriptengines/qml/plasmoid/appletinterface.cpp +++ b/src/scriptengines/qml/plasmoid/appletinterface.cpp @@ -119,63 +119,6 @@ AppletInterface::AppletInterface(DeclarativeAppletScript *script, const QVariant }); } -AppletInterface::AppletInterface(Plasma::Applet *a, const QVariantList &args, QQuickItem *parent) - : AppletQuickItem(a, parent), - m_actionSignals(0), - m_configuration(0), - m_appletScriptEngine(0), - m_toolTipTextFormat(0), - m_args(args), - m_backgroundHints(Plasma::Types::StandardBackground), - m_hideOnDeactivate(true), - m_oldKeyboardShortcut(0), - m_dummyNativeInterface(0), - m_positionBeforeRemoval(QPointF(-1, -1)) -{ - qmlRegisterType(); - - connect(this, &AppletInterface::configNeedsSaving, - applet(), &Plasma::Applet::configNeedsSaving); - connect(applet(), &Plasma::Applet::immutabilityChanged, - this, &AppletInterface::immutabilityChanged); - connect(applet(), &Plasma::Applet::userConfiguringChanged, - this, &AppletInterface::userConfiguringChanged); - connect(applet(), &Plasma::Applet::configurationRequiredChanged, - this, [this](bool needsConfig, const QString &reason) { - emit configurationRequiredChanged(); - emit configurationRequiredReasonChanged(); - }); - - connect(applet(), &Plasma::Applet::statusChanged, - this, &AppletInterface::statusChanged); - - connect(applet(), &Plasma::Applet::destroyedChanged, - this, &AppletInterface::destroyedChanged); - - connect(applet(), &Plasma::Applet::titleChanged, - this, &AppletInterface::titleChanged); - - connect(applet(), &Plasma::Applet::iconChanged, - this, &AppletInterface::iconChanged); - - connect(applet(), &Plasma::Applet::busyChanged, - this, &AppletInterface::busyChanged); - - if (appletScript()) { - connect(appletScript(), &DeclarativeAppletScript::formFactorChanged, - this, &AppletInterface::formFactorChanged); - connect(appletScript(), &DeclarativeAppletScript::locationChanged, - this, &AppletInterface::locationChanged); - connect(appletScript(), &DeclarativeAppletScript::contextChanged, - this, &AppletInterface::contextChanged); - } - - if (applet()->containment()) { - connect(applet()->containment(), &Plasma::Containment::screenChanged, - this, &ContainmentInterface::screenChanged); - } -} - AppletInterface::~AppletInterface() { } diff --git a/src/scriptengines/qml/plasmoid/appletinterface.h b/src/scriptengines/qml/plasmoid/appletinterface.h index 6a64594cd..a215ddd82 100644 --- a/src/scriptengines/qml/plasmoid/appletinterface.h +++ b/src/scriptengines/qml/plasmoid/appletinterface.h @@ -229,7 +229,6 @@ class AppletInterface : public PlasmaQuick::AppletQuickItem public: AppletInterface(DeclarativeAppletScript *script, const QVariantList &args = QVariantList(), QQuickItem *parent = 0); - AppletInterface(Plasma::Applet *applet, const QVariantList &args = QVariantList(), QQuickItem *parent = 0); ~AppletInterface(); //API not intended for the QML part diff --git a/src/scriptengines/qml/plasmoid/containmentinterface.cpp b/src/scriptengines/qml/plasmoid/containmentinterface.cpp index 3a24b3aa7..db77db9ab 100644 --- a/src/scriptengines/qml/plasmoid/containmentinterface.cpp +++ b/src/scriptengines/qml/plasmoid/containmentinterface.cpp @@ -758,10 +758,9 @@ void ContainmentInterface::appletAddedForward(Plasma::Applet *applet) // qDebug() << "Applet added on containment:" << m_containment->title() << contGraphicObject // << "Applet: " << applet << applet->title() << appletGraphicObject; + //Every applet should have a graphics object, otherwise don't disaplay anything if (!appletGraphicObject) { - appletGraphicObject = new AppletInterface(applet, QVariantList(), this); - applet->setProperty("_plasma_graphicObject", QVariant::fromValue(appletGraphicObject)); - static_cast(appletGraphicObject)->init(); + return; } if (contGraphicObject) {