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
This commit is contained in:
Marco Martin 2015-02-12 18:14:45 +01:00
parent edc767740e
commit 462ad8a6ca
3 changed files with 25 additions and 3 deletions

View File

@ -201,8 +201,8 @@ Applet *PluginLoader::loadApplet(const QString &name, uint appletId, const QVari
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";

View File

@ -63,6 +63,7 @@ AppletInterface::AppletInterface(DeclarativeAppletScript *script, const QVariant
m_busy(false),
m_hideOnDeactivate(true),
m_oldKeyboardShortcut(0),
m_dummyNativeInterface(0),
m_positionBeforeRemoval(QPointF(-1, -1))
{
qmlRegisterType<QAction>();
@ -118,7 +119,8 @@ AppletInterface::AppletInterface(Plasma::Applet *a, const QVariantList &args, QQ
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,18 @@ void AppletInterface::setGlobalShortcut(const QKeySequence &sequence)
applet()->setGlobalShortcut(sequence);
}
QObject *AppletInterface::nativeInterface()
{
if (applet()->metaObject()->className() != "Plasma::Applet") {
return applet();
} else {
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() + '/';

View File

@ -192,6 +192,11 @@ class AppletInterface : public PlasmaQuick::AppletQuickItem
*/
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 @@ public:
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 @@ private:
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