Merge branch 'mart/singleQmlEngineExperiment'
REVIEW:123736
This commit is contained in:
commit
13bd6703c0
@ -24,7 +24,7 @@
|
||||
#include <QDebug>
|
||||
#include <QPropertyAnimation>
|
||||
|
||||
#include <kdeclarative/qmlobject.h>
|
||||
#include <kdeclarative/qmlobjectsharedengine.h>
|
||||
|
||||
ToolTipDialog::ToolTipDialog(QQuickItem *parent)
|
||||
: Dialog(parent),
|
||||
@ -59,7 +59,7 @@ ToolTipDialog::~ToolTipDialog()
|
||||
QQuickItem *ToolTipDialog::loadDefaultItem()
|
||||
{
|
||||
if (!m_qmlObject) {
|
||||
m_qmlObject = new KDeclarative::QmlObject(this);
|
||||
m_qmlObject = new KDeclarative::QmlObjectSharedEngine(this);
|
||||
}
|
||||
|
||||
if (!m_qmlObject->rootObject()) {
|
||||
|
@ -20,6 +20,7 @@ set(plasmaquick_LIB_SRC
|
||||
dialog.cpp
|
||||
dialogshadows.cpp
|
||||
view.cpp
|
||||
containmentview.cpp
|
||||
configmodel.cpp
|
||||
shellpluginloader.cpp
|
||||
configview.cpp
|
||||
|
@ -33,7 +33,7 @@
|
||||
#include <Plasma/Applet>
|
||||
#include <Plasma/Containment>
|
||||
#include <Plasma/Corona>
|
||||
#include <kdeclarative/qmlobject.h>
|
||||
#include <kdeclarative/qmlobjectsharedengine.h>
|
||||
|
||||
#include <packageurlinterceptor.h>
|
||||
|
||||
@ -42,6 +42,10 @@ namespace PlasmaQuick
|
||||
|
||||
QHash<QObject *, AppletQuickItem *> AppletQuickItemPrivate::s_rootObjects = QHash<QObject *, AppletQuickItem *>();
|
||||
|
||||
//TODO: temporary
|
||||
QSet<QString> AppletQuickItemPrivate::s_legacyApplets = QSet<QString>({"org.kde.plasma.bluetooth", "org.kde.plasma.pager", "org.kde.desktopcontainment", "org.kde.plasma.folder", "org.kde.panel", "org.kde.plasma.analogclock", "org.kde.plasma.battery", "org.kde.plasma.notifications", "org.kde.plasma.systemtray"});
|
||||
|
||||
|
||||
AppletQuickItemPrivate::AppletQuickItemPrivate(Plasma::Applet *a, AppletQuickItem *item)
|
||||
: q(item),
|
||||
switchWidth(-1),
|
||||
@ -49,6 +53,22 @@ AppletQuickItemPrivate::AppletQuickItemPrivate(Plasma::Applet *a, AppletQuickIte
|
||||
applet(a),
|
||||
expanded(false)
|
||||
{
|
||||
//TODO: remove the legacy support at some point
|
||||
//use the shared engine only for applets that are nt in the legacy list
|
||||
//if they are, use the shared engine if their mayor version is at least 3
|
||||
const QStringList version = a->pluginInfo().version().split(".");
|
||||
if (!AppletQuickItemPrivate::s_legacyApplets.contains(a->pluginInfo().pluginName()) ||
|
||||
(!version.isEmpty() && version.first().toInt() >= 3)) {
|
||||
|
||||
qmlObject = new KDeclarative::QmlObjectSharedEngine(q);
|
||||
if (!qmlObject->engine()->urlInterceptor()) {
|
||||
PackageUrlInterceptor *interceptor = new PackageUrlInterceptor(qmlObject->engine(), Plasma::Package());
|
||||
qmlObject->engine()->setUrlInterceptor(interceptor);
|
||||
}
|
||||
} else {
|
||||
qWarning() << "Falling back to legacy separed QQmlEngine for applet" << a->pluginInfo().pluginName();
|
||||
qmlObject = new KDeclarative::QmlObject(q);
|
||||
}
|
||||
}
|
||||
|
||||
void AppletQuickItemPrivate::connectLayoutAttached(QObject *item)
|
||||
@ -378,7 +398,6 @@ AppletQuickItem::AppletQuickItem(Plasma::Applet *applet, QQuickItem *parent)
|
||||
connect(&d->compactRepresentationCheckTimer, SIGNAL(timeout()),
|
||||
this, SLOT(compactRepresentationCheck()));
|
||||
|
||||
d->qmlObject = new KDeclarative::QmlObject(this);
|
||||
if (applet->pluginInfo().isValid()) {
|
||||
const QString rootPath = applet->pluginInfo().property("X-Plasma-RootPath").toString();
|
||||
if (!rootPath.isEmpty()) {
|
||||
@ -401,16 +420,32 @@ AppletQuickItem::~AppletQuickItem()
|
||||
delete d->fullRepresentationItem;
|
||||
delete d->compactRepresentationExpanderItem;
|
||||
|
||||
AppletQuickItemPrivate::s_rootObjects.remove(d->qmlObject->engine());
|
||||
delete d;
|
||||
AppletQuickItemPrivate::s_rootObjects.remove(d->qmlObject->rootContext());
|
||||
}
|
||||
|
||||
AppletQuickItem *AppletQuickItem::qmlAttachedProperties(QObject *object)
|
||||
{
|
||||
QQmlContext *context;
|
||||
//is it using shared engine mode?
|
||||
if (!QtQml::qmlEngine(object)->parent()) {
|
||||
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();
|
||||
}
|
||||
//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
|
||||
if (!object->parent() && AppletQuickItemPrivate::s_rootObjects.contains(QtQml::qmlEngine(object))) {
|
||||
return AppletQuickItemPrivate::s_rootObjects.value(QtQml::qmlEngine(object));
|
||||
if (!object->parent() && AppletQuickItemPrivate::s_rootObjects.contains(context)) {
|
||||
return AppletQuickItemPrivate::s_rootObjects.value(context);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
@ -423,18 +458,22 @@ 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 (AppletQuickItemPrivate::s_rootObjects.contains(d->qmlObject->rootContext())) {
|
||||
return;
|
||||
}
|
||||
|
||||
AppletQuickItemPrivate::s_rootObjects[d->qmlObject->engine()] = this;
|
||||
AppletQuickItemPrivate::s_rootObjects[d->qmlObject->rootContext()] = this;
|
||||
|
||||
Q_ASSERT(d->applet);
|
||||
|
||||
//Initialize the main QML file
|
||||
QQmlEngine *engine = d->qmlObject->engine();
|
||||
|
||||
if (d->applet->package().isValid()) {
|
||||
//if the engine of the qmlObject is different from the static one, then we
|
||||
//are using an old version of the api in which every applet had one engine
|
||||
//so initialize a private url interceptor
|
||||
if (d->applet->package().isValid() && !qobject_cast<KDeclarative::QmlObjectSharedEngine *>(d->qmlObject)) {
|
||||
PackageUrlInterceptor *interceptor = new PackageUrlInterceptor(engine, d->applet->package());
|
||||
interceptor->addAllowedPath(d->coronaPackage.path());
|
||||
engine->setUrlInterceptor(interceptor);
|
||||
@ -481,7 +520,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;
|
||||
@ -499,7 +538,6 @@ void AppletQuickItem::init()
|
||||
setHeight(d->qmlObject->rootObject()->property("height").value<qreal>());
|
||||
}
|
||||
|
||||
|
||||
//default fullrepresentation is our root main component, if none specified
|
||||
if (!d->fullRepresentation) {
|
||||
d->fullRepresentation = d->qmlObject->mainComponent();
|
||||
|
275
src/plasmaquick/containmentview.cpp
Normal file
275
src/plasmaquick/containmentview.cpp
Normal file
@ -0,0 +1,275 @@
|
||||
/*
|
||||
* Copyright 2013 Marco Martin <mart@kde.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "containmentview.h"
|
||||
#include "configview.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QQuickItem>
|
||||
#include <QQmlContext>
|
||||
#include <QTimer>
|
||||
#include <QScreen>
|
||||
#include <QQmlEngine>
|
||||
|
||||
#include "plasma/pluginloader.h"
|
||||
#include <packageurlinterceptor.h>
|
||||
#include <kdeclarative/kdeclarative.h>
|
||||
|
||||
namespace PlasmaQuick
|
||||
{
|
||||
|
||||
class ContainmentViewPrivate
|
||||
{
|
||||
public:
|
||||
|
||||
ContainmentViewPrivate(Plasma::Corona *corona, ContainmentView *view);
|
||||
~ContainmentViewPrivate();
|
||||
|
||||
void setContainment(Plasma::Containment *cont);
|
||||
Plasma::Types::FormFactor formFactor() const;
|
||||
Plasma::Types::Location location() const;
|
||||
void showConfigurationInterface(Plasma::Applet *applet);
|
||||
void updateDestroyed(bool destroyed);
|
||||
|
||||
ContainmentView *q;
|
||||
friend class ContainmentView;
|
||||
Plasma::Corona *corona;
|
||||
QPointer<Plasma::Containment> containment;
|
||||
QPointer<ConfigView> configContainmentView;
|
||||
};
|
||||
|
||||
ContainmentViewPrivate::ContainmentViewPrivate(Plasma::Corona *cor, ContainmentView *view)
|
||||
: q(view),
|
||||
corona(cor)
|
||||
{
|
||||
}
|
||||
|
||||
ContainmentViewPrivate::~ContainmentViewPrivate()
|
||||
{
|
||||
}
|
||||
|
||||
void ContainmentViewPrivate::setContainment(Plasma::Containment *cont)
|
||||
{
|
||||
if (containment == cont) {
|
||||
return;
|
||||
}
|
||||
|
||||
Plasma::Types::Location oldLoc = location();
|
||||
Plasma::Types::FormFactor oldForm = formFactor();
|
||||
|
||||
if (containment) {
|
||||
QObject::disconnect(containment, 0, q, 0);
|
||||
QObject *oldGraphicObject = containment->property("_plasma_graphicObject").value<QObject *>();
|
||||
if (oldGraphicObject) {
|
||||
// qDebug() << "Old graphics Object:" << oldGraphicObject << "Old containment" << containment.data();
|
||||
//make sure the graphic object won't die with us
|
||||
//FIXME:we need a way to reparent to *NO* graphics item, but this makes Qt crash
|
||||
oldGraphicObject->setParent(containment);
|
||||
}
|
||||
containment->reactToScreenChange();
|
||||
}
|
||||
|
||||
containment = cont;
|
||||
|
||||
if (oldLoc != location()) {
|
||||
emit q->locationChanged(location());
|
||||
}
|
||||
if (oldForm != formFactor()) {
|
||||
emit q->formFactorChanged(formFactor());
|
||||
}
|
||||
|
||||
emit q->containmentChanged();
|
||||
|
||||
if (cont) {
|
||||
cont->reactToScreenChange();
|
||||
QObject::connect(cont, &Plasma::Containment::locationChanged,
|
||||
q, &ContainmentView::locationChanged);
|
||||
QObject::connect(cont, &Plasma::Containment::formFactorChanged,
|
||||
q, &ContainmentView::formFactorChanged);
|
||||
QObject::connect(cont, &Plasma::Containment::configureRequested,
|
||||
q, &ContainmentView::showConfigurationInterface);
|
||||
QObject::connect(cont, SIGNAL(destroyedChanged(bool)),
|
||||
q, SLOT(updateDestroyed(bool)));
|
||||
if (cont->containmentType() == Plasma::Types::PanelContainment ||
|
||||
cont->containmentType() == Plasma::Types::CustomPanelContainment) {
|
||||
q->setVisible(!cont->destroyed() && cont->isUiReady());
|
||||
}
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
QQuickItem *graphicObject = qobject_cast<QQuickItem *>(containment->property("_plasma_graphicObject").value<QObject *>());
|
||||
|
||||
if (graphicObject) {
|
||||
// qDebug() << "using as graphic containment" << graphicObject << containment.data();
|
||||
|
||||
//by resizing before adding, it will avoid some resizes in most cases
|
||||
graphicObject->setProperty("width", q->width());
|
||||
graphicObject->setProperty("height", q->height());
|
||||
graphicObject->setParentItem(q->rootObject());
|
||||
if (q->rootObject()) {
|
||||
q->rootObject()->setProperty("containment", QVariant::fromValue(graphicObject));
|
||||
QObject *wpGraphicObject = containment->property("wallpaperGraphicsObject").value<QObject *>();
|
||||
if (wpGraphicObject) {
|
||||
q->rootObject()->setProperty("wallpaper", QVariant::fromValue(wpGraphicObject));
|
||||
}
|
||||
} else {
|
||||
qWarning() << "Could not set containment property on rootObject";
|
||||
}
|
||||
} else {
|
||||
qWarning() << "Containment graphic object not valid";
|
||||
}
|
||||
}
|
||||
|
||||
Plasma::Types::Location ContainmentViewPrivate::location() const
|
||||
{
|
||||
if (!containment) {
|
||||
return Plasma::Types::Desktop;
|
||||
}
|
||||
return containment->location();
|
||||
}
|
||||
|
||||
Plasma::Types::FormFactor ContainmentViewPrivate::formFactor() const
|
||||
{
|
||||
if (!containment) {
|
||||
return Plasma::Types::Planar;
|
||||
}
|
||||
return containment->formFactor();
|
||||
}
|
||||
|
||||
void ContainmentViewPrivate::showConfigurationInterface(Plasma::Applet *applet)
|
||||
{
|
||||
if (configContainmentView) {
|
||||
if (configContainmentView->applet() != applet) {
|
||||
configContainmentView->hide();
|
||||
configContainmentView->deleteLater();
|
||||
} else {
|
||||
configContainmentView->requestActivate();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!applet || !applet->containment()) {
|
||||
return;
|
||||
}
|
||||
|
||||
configContainmentView = new ConfigView(applet);
|
||||
|
||||
configContainmentView->init();
|
||||
configContainmentView->show();
|
||||
}
|
||||
|
||||
void ContainmentViewPrivate::updateDestroyed(bool destroyed)
|
||||
{
|
||||
q->setVisible(!destroyed);
|
||||
}
|
||||
|
||||
ContainmentView::ContainmentView(Plasma::Corona *corona, QWindow *parent)
|
||||
: KQuickAddons::QuickViewSharedEngine(parent),
|
||||
d(new ContainmentViewPrivate(corona, this))
|
||||
{
|
||||
setColor(Qt::transparent);
|
||||
|
||||
QObject::connect(screen(), &QScreen::geometryChanged,
|
||||
this, &ContainmentView::screenGeometryChanged);
|
||||
|
||||
if (corona->package().isValid()) {
|
||||
KDeclarative::KDeclarative kdeclarative;
|
||||
kdeclarative.setDeclarativeEngine(engine());
|
||||
//binds things like kconfig and icons
|
||||
kdeclarative.setTranslationDomain("plasma_shell_" + corona->package().metadata().pluginName());
|
||||
kdeclarative.setupBindings();
|
||||
} else {
|
||||
qWarning() << "Invalid home screen package";
|
||||
}
|
||||
|
||||
//Force QtQuickControls to use the "Plasma" style for this engine.
|
||||
//this way is possible to mix QtQuickControls and plasma components in applets
|
||||
//while still having the desktop style in configuration dialogs
|
||||
QQmlComponent c(engine());
|
||||
c.setData("import QtQuick 2.1\n\
|
||||
import QtQuick.Controls 1.0\n\
|
||||
import QtQuick.Controls.Private 1.0\n \
|
||||
Item {\
|
||||
Component.onCompleted: {\
|
||||
Settings.styleName = \"Plasma\";\
|
||||
}\
|
||||
}", QUrl());
|
||||
QObject *o = c.create();
|
||||
o->deleteLater();
|
||||
|
||||
setResizeMode(ContainmentView::SizeRootObjectToView);
|
||||
}
|
||||
|
||||
ContainmentView::~ContainmentView()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
Plasma::Corona *ContainmentView::corona() const
|
||||
{
|
||||
return d->corona;
|
||||
}
|
||||
|
||||
KConfigGroup ContainmentView::config() const
|
||||
{
|
||||
if (!containment()) {
|
||||
return KConfigGroup();
|
||||
}
|
||||
KConfigGroup views(KSharedConfig::openConfig(), "PlasmaContainmentViews");
|
||||
return KConfigGroup(&views, QString::number(containment()->screen()));
|
||||
}
|
||||
|
||||
void ContainmentView::setContainment(Plasma::Containment *cont)
|
||||
{
|
||||
d->setContainment(cont);
|
||||
}
|
||||
|
||||
Plasma::Containment *ContainmentView::containment() const
|
||||
{
|
||||
return d->containment;
|
||||
}
|
||||
|
||||
void ContainmentView::setLocation(Plasma::Types::Location location)
|
||||
{
|
||||
d->containment->setLocation(location);
|
||||
}
|
||||
|
||||
Plasma::Types::Location ContainmentView::location() const
|
||||
{
|
||||
return d->location();
|
||||
}
|
||||
|
||||
Plasma::Types::FormFactor ContainmentView::formFactor() const
|
||||
{
|
||||
return d->formFactor();
|
||||
}
|
||||
|
||||
QRectF ContainmentView::screenGeometry()
|
||||
{
|
||||
return screen()->geometry();
|
||||
}
|
||||
|
||||
void ContainmentView::showConfigurationInterface(Plasma::Applet *applet)
|
||||
{
|
||||
d->showConfigurationInterface(applet);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#include "moc_containmentview.cpp"
|
136
src/plasmaquick/containmentview.h
Normal file
136
src/plasmaquick/containmentview.h
Normal file
@ -0,0 +1,136 @@
|
||||
/*
|
||||
* Copyright 2012 Marco Martin <mart@kde.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef PLASMAQUICKCONTAINMENTVIEW_H
|
||||
#define PLASMAQUICKCONTAINMENTVIEW_H
|
||||
|
||||
#include <kquickaddons/quickviewsharedengine.h>
|
||||
|
||||
#include <plasmaquick_export.h>
|
||||
#include "plasma/corona.h"
|
||||
#include "plasma/containment.h"
|
||||
|
||||
//
|
||||
// W A R N I N G
|
||||
// -------------
|
||||
//
|
||||
// This file is not part of the public Plasma API. It exists purely as an
|
||||
// implementation detail. This header file may change from version to
|
||||
// version without notice, or even be removed.
|
||||
//
|
||||
// We mean it.
|
||||
//
|
||||
|
||||
namespace PlasmaQuick
|
||||
{
|
||||
|
||||
class ContainmentViewPrivate;
|
||||
|
||||
class PLASMAQUICK_EXPORT ContainmentView : public KQuickAddons::QuickViewSharedEngine
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(Plasma::Types::Location location READ location WRITE setLocation NOTIFY locationChanged)
|
||||
Q_PROPERTY(Plasma::Types::FormFactor formFactor READ formFactor NOTIFY formFactorChanged)
|
||||
Q_PROPERTY(QRectF screenGeometry READ screenGeometry NOTIFY screenGeometryChanged)
|
||||
|
||||
public:
|
||||
/**
|
||||
* @param corona the corona of this view
|
||||
* @param parent the QWindow this ContainmentView is parented to
|
||||
**/
|
||||
explicit ContainmentView(Plasma::Corona *corona, QWindow *parent = 0);
|
||||
virtual ~ContainmentView();
|
||||
|
||||
/**
|
||||
* @return the corona of this view
|
||||
**/
|
||||
Plasma::Corona *corona() const;
|
||||
|
||||
/**
|
||||
* @return the KConfigGroup of this view
|
||||
**/
|
||||
virtual KConfigGroup config() const;
|
||||
|
||||
/**
|
||||
* sets the containment for this view
|
||||
* @param cont the containment of this view
|
||||
**/
|
||||
void setContainment(Plasma::Containment *cont);
|
||||
|
||||
/**
|
||||
* @return the containment of this ContainmentView
|
||||
**/
|
||||
Plasma::Containment *containment() const;
|
||||
|
||||
/**
|
||||
* @return the location of this ContainmentView
|
||||
**/
|
||||
Plasma::Types::Location location() const;
|
||||
|
||||
/**
|
||||
* Sets the location of the ContainmentView
|
||||
* @param location the location of the ContainmentView
|
||||
**/
|
||||
void setLocation(Plasma::Types::Location location);
|
||||
|
||||
/**
|
||||
* @return the formfactor of the ContainmentView
|
||||
**/
|
||||
Plasma::Types::FormFactor formFactor() const;
|
||||
|
||||
/**
|
||||
* @return the screenGeometry of the ContainmentView
|
||||
**/
|
||||
QRectF screenGeometry();
|
||||
|
||||
protected Q_SLOTS:
|
||||
/**
|
||||
* It will be called when the configuration is requested
|
||||
*/
|
||||
virtual void showConfigurationInterface(Plasma::Applet *applet);
|
||||
|
||||
Q_SIGNALS:
|
||||
/**
|
||||
* emitted when the location is changed
|
||||
**/
|
||||
void locationChanged(Plasma::Types::Location location);
|
||||
|
||||
/**
|
||||
* emitted when the formfactor is changed
|
||||
**/
|
||||
void formFactorChanged(Plasma::Types::FormFactor formFactor);
|
||||
|
||||
/**
|
||||
* emitted when the containment is changed
|
||||
**/
|
||||
void containmentChanged();
|
||||
|
||||
/**
|
||||
* emitted when the screenGeometry is changed
|
||||
**/
|
||||
void screenGeometryChanged();
|
||||
|
||||
private:
|
||||
ContainmentViewPrivate *const d;
|
||||
Q_PRIVATE_SLOT(d, void updateDestroyed(bool))
|
||||
friend class ContainmentViewPrivate;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // CONTAINMENTVIEW_H
|
@ -22,18 +22,40 @@
|
||||
#include <QDebug>
|
||||
#include <QQmlEngine>
|
||||
#include <QFile>
|
||||
#include <QStandardPaths>
|
||||
|
||||
#include <Plasma/PluginLoader>
|
||||
|
||||
#include <kdeclarative/kdeclarative.h>
|
||||
|
||||
namespace PlasmaQuick
|
||||
{
|
||||
|
||||
class PackageUrlInterceptorPrivate {
|
||||
public:
|
||||
PackageUrlInterceptorPrivate(QQmlEngine *engine, const Plasma::Package &p)
|
||||
: package(p),
|
||||
engine(engine)
|
||||
{
|
||||
}
|
||||
|
||||
Plasma::Package package;
|
||||
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;
|
||||
};
|
||||
|
||||
QHash<QString, Plasma::Package> PackageUrlInterceptorPrivate::s_packages = QHash<QString, Plasma::Package>();
|
||||
|
||||
|
||||
PackageUrlInterceptor::PackageUrlInterceptor(QQmlEngine *engine, const Plasma::Package &p)
|
||||
: QQmlAbstractUrlInterceptor(),
|
||||
m_package(p),
|
||||
m_engine(engine)
|
||||
d(new PackageUrlInterceptorPrivate(engine, p))
|
||||
{
|
||||
//m_allowedPaths << m_engine->importPathList();
|
||||
//d->allowedPaths << d->engine->importPathList();
|
||||
}
|
||||
|
||||
PackageUrlInterceptor::~PackageUrlInterceptor()
|
||||
@ -42,29 +64,52 @@ PackageUrlInterceptor::~PackageUrlInterceptor()
|
||||
|
||||
void PackageUrlInterceptor::addAllowedPath(const QString &path)
|
||||
{
|
||||
m_allowedPaths << path;
|
||||
d->allowedPaths << path;
|
||||
}
|
||||
|
||||
void PackageUrlInterceptor::removeAllowedPath(const QString &path)
|
||||
{
|
||||
m_allowedPaths.removeAll(path);
|
||||
d->allowedPaths.removeAll(path);
|
||||
}
|
||||
|
||||
QStringList PackageUrlInterceptor::allowedPaths() const
|
||||
{
|
||||
return m_allowedPaths;
|
||||
return d->allowedPaths;
|
||||
}
|
||||
|
||||
QUrl PackageUrlInterceptor::intercept(const QUrl &path, QQmlAbstractUrlInterceptor::DataType type)
|
||||
{
|
||||
//qDebug() << "Intercepted URL:" << path << type;
|
||||
QString pkgRoot;
|
||||
Plasma::Package package;
|
||||
if (d->package.isValid()) {
|
||||
package = d->package;
|
||||
} else {
|
||||
foreach (const QString &base, QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation)) {
|
||||
pkgRoot = base + "/plasma/plasmoids/";
|
||||
if (path.path().startsWith(pkgRoot)) {
|
||||
const QString pkgName = path.path().mid(pkgRoot.length()).split('/').first();
|
||||
if (PackageUrlInterceptorPrivate::s_packages.contains(pkgName)) {
|
||||
package = PackageUrlInterceptorPrivate::s_packages.value(pkgName);
|
||||
} else {
|
||||
package = Plasma::PluginLoader::self()->loadPackage("Plasma/Applet");
|
||||
package.setPath(pkgName);
|
||||
PackageUrlInterceptorPrivate::s_packages[pkgName] = package;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!package.isValid()) {
|
||||
return path;
|
||||
}
|
||||
|
||||
if (path.scheme() == QStringLiteral("plasmapackage")) {
|
||||
if (d->package.isValid() && path.scheme() == QStringLiteral("plasmapackage")) {
|
||||
//FIXME: this is incorrect but works around a bug in qml in resolution of urls of qmldir files
|
||||
if (type == QQmlAbstractUrlInterceptor::QmldirFile) {
|
||||
return QUrl(m_package.filePath(0, path.path()));
|
||||
return QUrl(d->package.filePath(0, path.path()));
|
||||
} else {
|
||||
return QUrl::fromLocalFile(m_package.filePath(0, path.path()));
|
||||
return QUrl::fromLocalFile(d->package.filePath(0, path.path()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -79,13 +124,13 @@ QUrl PackageUrlInterceptor::intercept(const QUrl &path, QQmlAbstractUrlIntercept
|
||||
}
|
||||
|
||||
//asked a file inside a package: let's rewrite the url!
|
||||
if (path.path().startsWith(m_package.path())) {
|
||||
if (path.path().startsWith(package.path())) {
|
||||
//qDebug() << "Found URL in package" << path;
|
||||
|
||||
//tries to isolate the relative path asked relative to the contentsPrefixPath: like ui/foo.qml
|
||||
QString relativePath;
|
||||
foreach (const QString &prefix, m_package.contentsPrefixPaths()) {
|
||||
QString root = m_package.path() + prefix;
|
||||
foreach (const QString &prefix, package.contentsPrefixPaths()) {
|
||||
QString root = package.path() + prefix;
|
||||
if (path.path().startsWith(root)) {
|
||||
//obtain a string in the form ui/foo/bar/baz.qml
|
||||
relativePath = path.path().mid(root.length());
|
||||
@ -104,9 +149,9 @@ QUrl PackageUrlInterceptor::intercept(const QUrl &path, QQmlAbstractUrlIntercept
|
||||
//obtain a string in the form foo/bar/baz.qml: ui/ gets discarded
|
||||
const QString &filename = components.join("/");
|
||||
|
||||
//qDebug() << "Returning" << QUrl::fromLocalFile(m_package.filePath(prefixForType(type, filename), filename));
|
||||
QUrl ret = QUrl::fromLocalFile(package.filePath(prefixForType(type, filename), filename));
|
||||
|
||||
QUrl ret = QUrl::fromLocalFile(m_package.filePath(prefixForType(type, filename), filename));
|
||||
//qDebug() << "Returning" << ret;
|
||||
|
||||
if (ret.path().isEmpty()) {
|
||||
return path;
|
||||
@ -114,41 +159,9 @@ QUrl PackageUrlInterceptor::intercept(const QUrl &path, QQmlAbstractUrlIntercept
|
||||
return ret;
|
||||
|
||||
//forbid to load random absolute paths
|
||||
} else {
|
||||
if (m_package.allowExternalPaths() || m_package.metadata().property("X-Plasma-RequiredExtensions").toString().contains(QStringLiteral("ExternalScripts"))) {
|
||||
return path;
|
||||
}
|
||||
|
||||
//NOTE: It's needed to build this on the fly because importPathList
|
||||
//can change at runtime
|
||||
QStringList allowedPaths;
|
||||
allowedPaths << m_engine->importPathList();
|
||||
allowedPaths << m_allowedPaths;
|
||||
|
||||
foreach (const QString &allowed, allowedPaths) {
|
||||
//It's a private import
|
||||
if (path.path().contains("org/kde/plasma/private")) {
|
||||
QString pathCheck(path.path());
|
||||
pathCheck = pathCheck.replace(QRegExp(".*org/kde/plasma/private/(.*)/.*"), "org.kde.plasma.\\1");
|
||||
|
||||
if (pathCheck == m_package.metadata().pluginName() || allowed.contains(pathCheck)) {
|
||||
return path;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
//it's from an allowed, good
|
||||
if (path.path().startsWith(allowed)) {
|
||||
//qDebug() << "Found allowed, access granted" << path;
|
||||
return path;
|
||||
}
|
||||
}
|
||||
qWarning() << "WARNING: Access denied for URL" << path << m_package.path();
|
||||
return QUrl::fromLocalFile( allowedPaths.first() + "/org/kde/plasma/accessdenied/qmldir");
|
||||
}
|
||||
|
||||
qWarning() << "WARNING: Access denied for URL" << path << m_package.path();
|
||||
return QUrl();
|
||||
return path;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -42,6 +42,8 @@ class QQmlEngine;
|
||||
namespace PlasmaQuick
|
||||
{
|
||||
|
||||
class PackageUrlInterceptorPrivate;
|
||||
|
||||
//depends from https://codereview.qt-project.org/#change,65626
|
||||
class PLASMAQUICK_EXPORT PackageUrlInterceptor: public QQmlAbstractUrlInterceptor
|
||||
{
|
||||
@ -85,9 +87,7 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
Plasma::Package m_package;
|
||||
QStringList m_allowedPaths;
|
||||
QQmlEngine *m_engine;
|
||||
PackageUrlInterceptorPrivate *const d;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -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 QSet<QString> s_legacyApplets;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -53,77 +53,77 @@ public:
|
||||
* @param corona the corona of this view
|
||||
* @param parent the QWindow this View is parented to
|
||||
**/
|
||||
explicit View(Plasma::Corona *corona, QWindow *parent = 0);
|
||||
virtual ~View();
|
||||
PLASMA_DEPRECATED explicit View(Plasma::Corona *corona, QWindow *parent = 0);
|
||||
PLASMA_DEPRECATED virtual ~View();
|
||||
|
||||
/**
|
||||
* @return the corona of this view
|
||||
**/
|
||||
Plasma::Corona *corona() const;
|
||||
PLASMA_DEPRECATED Plasma::Corona *corona() const;
|
||||
|
||||
/**
|
||||
* @return the KConfigGroup of this view
|
||||
**/
|
||||
virtual KConfigGroup config() const;
|
||||
PLASMA_DEPRECATED virtual KConfigGroup config() const;
|
||||
|
||||
/**
|
||||
* sets the containment for this view
|
||||
* @param cont the containment of this view
|
||||
**/
|
||||
void setContainment(Plasma::Containment *cont);
|
||||
PLASMA_DEPRECATED void setContainment(Plasma::Containment *cont);
|
||||
|
||||
/**
|
||||
* @return the containment of this View
|
||||
**/
|
||||
Plasma::Containment *containment() const;
|
||||
PLASMA_DEPRECATED Plasma::Containment *containment() const;
|
||||
|
||||
/**
|
||||
* @return the location of this View
|
||||
**/
|
||||
Plasma::Types::Location location() const;
|
||||
PLASMA_DEPRECATED Plasma::Types::Location location() const;
|
||||
|
||||
/**
|
||||
* Sets the location of the View
|
||||
* @param location the location of the View
|
||||
**/
|
||||
void setLocation(Plasma::Types::Location location);
|
||||
PLASMA_DEPRECATED void setLocation(Plasma::Types::Location location);
|
||||
|
||||
/**
|
||||
* @return the formfactor of the View
|
||||
**/
|
||||
Plasma::Types::FormFactor formFactor() const;
|
||||
PLASMA_DEPRECATED Plasma::Types::FormFactor formFactor() const;
|
||||
|
||||
/**
|
||||
* @return the screenGeometry of the View
|
||||
**/
|
||||
QRectF screenGeometry();
|
||||
PLASMA_DEPRECATED QRectF screenGeometry();
|
||||
|
||||
protected Q_SLOTS:
|
||||
/**
|
||||
* It will be called when the configuration is requested
|
||||
*/
|
||||
virtual void showConfigurationInterface(Plasma::Applet *applet);
|
||||
PLASMA_DEPRECATED virtual void showConfigurationInterface(Plasma::Applet *applet);
|
||||
|
||||
Q_SIGNALS:
|
||||
/**
|
||||
* emitted when the location is changed
|
||||
**/
|
||||
void locationChanged(Plasma::Types::Location location);
|
||||
PLASMA_DEPRECATED void locationChanged(Plasma::Types::Location location);
|
||||
|
||||
/**
|
||||
* emitted when the formfactor is changed
|
||||
**/
|
||||
void formFactorChanged(Plasma::Types::FormFactor formFactor);
|
||||
PLASMA_DEPRECATED void formFactorChanged(Plasma::Types::FormFactor formFactor);
|
||||
|
||||
/**
|
||||
* emitted when the containment is changed
|
||||
**/
|
||||
void containmentChanged();
|
||||
PLASMA_DEPRECATED void containmentChanged();
|
||||
|
||||
/**
|
||||
* emitted when the screenGeometry is changed
|
||||
**/
|
||||
void screenGeometryChanged();
|
||||
PLASMA_DEPRECATED void screenGeometryChanged();
|
||||
|
||||
private:
|
||||
ViewPrivate *const d;
|
||||
|
@ -21,7 +21,7 @@
|
||||
|
||||
#include "containmentinterface.h"
|
||||
#include <kdeclarative/configpropertymap.h>
|
||||
#include <kdeclarative/qmlobject.h>
|
||||
#include <kdeclarative/qmlobjectsharedengine.h>
|
||||
|
||||
#include <kactioncollection.h>
|
||||
#include <kdesktopfile.h>
|
||||
@ -127,7 +127,7 @@ void WallpaperInterface::syncWallpaperPackage()
|
||||
m_wallpaperPlugin = m_containmentInterface->containment()->wallpaper();
|
||||
|
||||
if (!m_qmlObject) {
|
||||
m_qmlObject = new KDeclarative::QmlObject(this);
|
||||
m_qmlObject = new KDeclarative::QmlObjectSharedEngine(this);
|
||||
s_rootObjects[m_qmlObject->engine()] = this;
|
||||
m_qmlObject->setInitializationDelayed(true);
|
||||
connect(m_qmlObject, &KDeclarative::QmlObject::finished, this, &WallpaperInterface::loadFinished);
|
||||
|
Loading…
Reference in New Issue
Block a user