From bb0d245d5b5724771655b505d3720adf1c812ac7 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Mon, 11 May 2015 13:47:15 +0200 Subject: [PATCH] support fallback to the multi engine require SingleEngine in X-Plasma-RequiredExtensions to share the engine Change-Id: I72873d2e370f98a069bb3dff0d58290277da1292 --- .../data/servicetypes/plasma-applet.desktop | 3 -- src/plasmaquick/appletquickitem.cpp | 32 +++++++++++++------ src/plasmaquick/packageurlinterceptor.cpp | 2 ++ 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/plasma/data/servicetypes/plasma-applet.desktop b/src/plasma/data/servicetypes/plasma-applet.desktop index fefd058c1..476c819d9 100644 --- a/src/plasma/data/servicetypes/plasma-applet.desktop +++ b/src/plasma/data/servicetypes/plasma-applet.desktop @@ -46,9 +46,6 @@ Comment[zh_TW]=Plasma 小程式 [PropertyDef::X-Plasma-API] Type=QString -[PropertyDef::X-Plasma-MinimumAPIVersion] -Type=int - [PropertyDef::X-Plasma-RootPath] Type=QString diff --git a/src/plasmaquick/appletquickitem.cpp b/src/plasmaquick/appletquickitem.cpp index e6720c2bb..20f7bd0be 100644 --- a/src/plasmaquick/appletquickitem.cpp +++ b/src/plasmaquick/appletquickitem.cpp @@ -385,8 +385,13 @@ AppletQuickItem::AppletQuickItem(Plasma::Applet *applet, QQuickItem *parent) connect(&d->compactRepresentationCheckTimer, SIGNAL(timeout()), this, SLOT(compactRepresentationCheck())); - QQmlContext *context = new QQmlContext(AppletQuickItemPrivate::s_engine->rootContext()); - d->qmlObject = new KDeclarative::QmlObject(AppletQuickItemPrivate::s_engine, context, this); + if (applet->pluginInfo().property("X-Plasma-RequiredExtensions").toStringList().contains("SharedEngine")) { + QQmlContext *context = new QQmlContext(AppletQuickItemPrivate::s_engine->rootContext()); + d->qmlObject = new KDeclarative::QmlObject(AppletQuickItemPrivate::s_engine, context, this); + } else { + d->qmlObject = new KDeclarative::QmlObject(this); + } + if (applet->pluginInfo().isValid()) { const QString rootPath = applet->pluginInfo().property("X-Plasma-RootPath").toString(); if (!rootPath.isEmpty()) { @@ -414,15 +419,22 @@ AppletQuickItem::~AppletQuickItem() AppletQuickItem *AppletQuickItem::qmlAttachedProperties(QObject *object) { - QQmlContext *context = QtQml::qmlContext(object); - //search the root context of the applet in which the object is in - while (context) { - //the rootcontext of an applet is a child of the engine root context - if (context->parentContext() == QtQml::qmlEngine(object)->rootContext()) { - break; - } + QQmlContext *context; + //is it using shared engine mode? + if (QtQml::qmlEngine(object) == AppletQuickItemPrivate::s_engine) { + context = QtQml::qmlContext(object); + //search the root context of the applet in which the object is in + while (context) { + //the rootcontext of an applet is a child of the engine root context + if (context->parentContext() == QtQml::qmlEngine(object)->rootContext()) { + break; + } - context = context->parentContext(); + context = context->parentContext(); + } + //otherwise index by root context + } else { + context = QtQml::qmlEngine(object)->rootContext(); } //at the moment of the attached object creation, the root item is the only one that hasn't a parent //only way to avoid creation of this attached for everybody but the root item diff --git a/src/plasmaquick/packageurlinterceptor.cpp b/src/plasmaquick/packageurlinterceptor.cpp index 4315f1066..9cbcb686e 100644 --- a/src/plasmaquick/packageurlinterceptor.cpp +++ b/src/plasmaquick/packageurlinterceptor.cpp @@ -43,6 +43,8 @@ public: QStringList allowedPaths; QQmlEngine *engine; + //FIXME: those are going to be stuffed here and stay.. + // they should probably be removed when the last applet of that type is removed static QHash s_packages; };