Change in plasma-framework[master]: support for C++ applets
Marco Martin (Code Review)
noreply at kde.org
Thu Feb 12 17:23:13 UTC 2015
Marco Martin has uploaded a new change for review.
https://gerrit.vesnicky.cesnet.cz/r/374
Change subject: support for C++ applets
......................................................................
support for C++ applets
make possible for an applet to be implemented in c++ but still
have the qml package with the usual api, this was supposed to
be supported from the beginning.
if a c++ applet has been loaded, make available the property
plasmoid.nativeInterface to the qml part, exposing the subclasses
Applet instance with all eventual extra propertiels/slots.
if no c++ plugin is present, appletInterface will be dummy/not available
this (besides limiting a bit the qml import rabbit procreation)
makes available some things not available to normal private imports:
* access to applet config() to save more complex things compared to what kconfigxt allows
or save/load stuff from the c++ part
* access to containment()/corona(), may be useful for containment implementations
* easier port for old very big applets such as comics/weather
Change-Id: I65117660043de3a60ad58c77b086f686683d4d8c
---
M src/plasma/pluginloader.cpp
M src/scriptengines/qml/plasmoid/appletinterface.cpp
M src/scriptengines/qml/plasmoid/appletinterface.h
3 files changed, 26 insertions(+), 3 deletions(-)
git pull ssh://gerrit.vesnicky.cesnet.cz:29418/plasma-framework refs/changes/74/374/1
diff --git a/src/plasma/pluginloader.cpp b/src/plasma/pluginloader.cpp
index 48cd46c..7ecdd15 100644
--- a/src/plasma/pluginloader.cpp
+++ b/src/plasma/pluginloader.cpp
@@ -201,8 +201,8 @@
QVariantList allArgs;
allArgs << offer->storageId() << appletId << args;
-
- if (!offer->property("X-Plasma-API").toString().isEmpty()) {
+ if (!offer->property("X-Plasma-API").toString().isEmpty() &&
+ offer->property("Library").toString().isEmpty()) {
#ifndef NDEBUG
// qDebug() << "we have a script using the"
// << offer->property("X-Plasma-API").toString() << "API";
diff --git a/src/scriptengines/qml/plasmoid/appletinterface.cpp b/src/scriptengines/qml/plasmoid/appletinterface.cpp
index 0ec2c34..ab8056b 100644
--- a/src/scriptengines/qml/plasmoid/appletinterface.cpp
+++ b/src/scriptengines/qml/plasmoid/appletinterface.cpp
@@ -63,6 +63,7 @@
m_busy(false),
m_hideOnDeactivate(true),
m_oldKeyboardShortcut(0),
+ m_dummyNativeInterface(0),
m_positionBeforeRemoval(QPointF(-1, -1))
{
qmlRegisterType<QAction>();
@@ -118,7 +119,8 @@
m_appletScriptEngine(0),
m_backgroundHints(Plasma::Types::StandardBackground),
m_busy(false),
- m_hideOnDeactivate(true)
+ m_hideOnDeactivate(true),
+ m_dummyNativeInterface(0)
{
qmlRegisterType<QAction>();
@@ -585,6 +587,19 @@
applet()->setGlobalShortcut(sequence);
}
+QObject *AppletInterface::nativeInterface()
+{
+ if (applet()->metaObject()->className() != "Plasma::Applet") {
+ return applet();
+ } else {
+ //This being CONSTANT is guaranteed to be called only once
+ if (!m_dummyNativeInterface) {
+ m_dummyNativeInterface = new QObject(this);
+ }
+ return m_dummyNativeInterface;
+ }
+}
+
QString AppletInterface::downloadPath(const QString &file)
{
const QString downloadDir = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation) + "/Plasma/" + applet()->pluginInfo().pluginName() + '/';
diff --git a/src/scriptengines/qml/plasmoid/appletinterface.h b/src/scriptengines/qml/plasmoid/appletinterface.h
index 457f5df..32a72ee 100644
--- a/src/scriptengines/qml/plasmoid/appletinterface.h
+++ b/src/scriptengines/qml/plasmoid/appletinterface.h
@@ -192,6 +192,11 @@
*/
Q_PROPERTY(QKeySequence globalShortcut READ globalShortcut WRITE setGlobalShortcut NOTIFY globalShortcutChanged)
+ /**
+ * An interface to the native C++ plasmoid, if implemented
+ */
+ Q_PROPERTY(QObject *nativeInterface READ nativeInterface CONSTANT)
+
public:
AppletInterface(DeclarativeAppletScript *script, const QVariantList &args = QVariantList(), QQuickItem *parent = 0);
AppletInterface(Plasma::Applet *applet, const QVariantList &args = QVariantList(), QQuickItem *parent = 0);
@@ -318,6 +323,8 @@
QKeySequence globalShortcut() const;
void setGlobalShortcut(const QKeySequence &keySequence);
+ QObject *nativeInterface();
+
Q_SIGNALS:
/**
* somebody else, usually the containment sent some data to the applet
@@ -390,6 +397,7 @@
bool m_hideOnDeactivate : 1;
//this is used to build an emacs style shortcut
int m_oldKeyboardShortcut;
+ QObject *m_dummyNativeInterface;
friend class ContainmentInterface;
//This is used by ContainmentInterface
--
To view, visit https://gerrit.vesnicky.cesnet.cz/r/374
To unsubscribe, visit https://gerrit.vesnicky.cesnet.cz/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I65117660043de3a60ad58c77b086f686683d4d8c
Gerrit-PatchSet: 1
Gerrit-Project: plasma-framework
Gerrit-Branch: master
Gerrit-Owner: Marco Martin <notmart at gmail.com>
Gerrit-Reviewer: Aaron J. Seigo <aseigo at kde.org>
More information about the Plasma-devel
mailing list