support fallback to the multi engine

require SingleEngine in X-Plasma-RequiredExtensions to share the engine

Change-Id: I72873d2e370f98a069bb3dff0d58290277da1292
This commit is contained in:
Marco Martin 2015-05-11 13:47:15 +02:00
parent 509c5da619
commit bb0d245d5b
3 changed files with 24 additions and 13 deletions

View File

@ -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

View File

@ -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

View File

@ -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<QString, Plasma::Package> s_packages;
};