rough experiment on giving all applets the same engine

it has a couple of big problems
Plasmoid attached property (should be easily fixable)
url interceptor (more tricky)

Change-Id: Ie75dfa97e097f43e8e5778f9b47fdff29224e5fc
This commit is contained in:
Marco Martin 2015-05-08 19:44:22 +02:00
parent 662adbb41b
commit dc288044ef
3 changed files with 14 additions and 4 deletions

View File

@ -42,6 +42,8 @@ namespace PlasmaQuick
QHash<QObject *, AppletQuickItem *> AppletQuickItemPrivate::s_rootObjects = QHash<QObject *, AppletQuickItem *>();
QQmlEngine *AppletQuickItemPrivate::s_engine = 0;
AppletQuickItemPrivate::AppletQuickItemPrivate(Plasma::Applet *a, AppletQuickItem *item)
: q(item),
switchWidth(-1),
@ -49,6 +51,9 @@ AppletQuickItemPrivate::AppletQuickItemPrivate(Plasma::Applet *a, AppletQuickIte
applet(a),
expanded(false)
{
if (!s_engine) {
s_engine = new QQmlEngine;
}
}
void AppletQuickItemPrivate::connectLayoutAttached(QObject *item)
@ -378,7 +383,8 @@ AppletQuickItem::AppletQuickItem(Plasma::Applet *applet, QQuickItem *parent)
connect(&d->compactRepresentationCheckTimer, SIGNAL(timeout()),
this, SLOT(compactRepresentationCheck()));
d->qmlObject = new KDeclarative::QmlObject(this);
QQmlContext *context = new QQmlContext(AppletQuickItemPrivate::s_engine->rootContext());
d->qmlObject = new KDeclarative::QmlObject(AppletQuickItemPrivate::s_engine, context, this);
if (applet->pluginInfo().isValid()) {
const QString rootPath = applet->pluginInfo().property("X-Plasma-RootPath").toString();
if (!rootPath.isEmpty()) {
@ -402,7 +408,6 @@ AppletQuickItem::~AppletQuickItem()
delete d->compactRepresentationExpanderItem;
AppletQuickItemPrivate::s_rootObjects.remove(d->qmlObject->engine());
delete d;
}
AppletQuickItem *AppletQuickItem::qmlAttachedProperties(QObject *object)
@ -423,7 +428,8 @@ Plasma::Applet *AppletQuickItem::applet() const
void AppletQuickItem::init()
{
if (AppletQuickItemPrivate::s_rootObjects.contains(d->qmlObject->engine())) {
//FIXME: Plasmoid attached property should be fixed since can't be indexed by engine anymore
if (0&&AppletQuickItemPrivate::s_rootObjects.contains(d->qmlObject->engine())) {
return;
}
@ -481,7 +487,7 @@ void AppletQuickItem::init()
d->applet->setLaunchErrorMessage(reason);
}
engine->rootContext()->setContextProperty("plasmoid", this);
d->qmlObject->rootContext()->setContextProperty("plasmoid", this);
//initialize size, so an useless resize less
QVariantHash initialProperties;

View File

@ -22,6 +22,7 @@
#include <QDebug>
#include <QQmlEngine>
#include <QFile>
#include <QStandardPaths>
#include <kdeclarative/kdeclarative.h>
@ -144,6 +145,7 @@ QUrl PackageUrlInterceptor::intercept(const QUrl &path, QQmlAbstractUrlIntercept
}
}
qWarning() << "WARNING: Access denied for URL" << path << m_package.path();
return path;
return QUrl::fromLocalFile( allowedPaths.first() + "/org/kde/plasma/accessdenied/qmldir");
}

View File

@ -22,6 +22,7 @@
#include <QQmlComponent>
#include <qquickitem.h>
#include <QQmlEngine>
//
// W A R N I N G
@ -103,6 +104,7 @@ public:
bool expanded : 1;
static QHash<QObject *, AppletQuickItem *> s_rootObjects;
static QQmlEngine *s_engine;
};
}