From e00a7b242284d2286bc59253f0bb6f1d723c551b Mon Sep 17 00:00:00 2001 From: Ryan James Rix Date: Thu, 15 Jul 2010 21:06:21 +0000 Subject: [PATCH] Adds ability for applications which embed plasma to specify a class which plasma will query for Applet, DataEngine, and Service creation, giving them the chance to create these objects internally. http://reviewboard.kde.org/r/4554/ svn path=/trunk/KDE/kdelibs/; revision=1150389 --- CMakeLists.txt | 2 + applet.cpp | 16 +++++++- dataenginemanager.cpp | 11 ++++- pluginloader.cpp | 64 +++++++++++++++++++++++++++++ pluginloader.h | 96 +++++++++++++++++++++++++++++++++++++++++++ service.cpp | 9 ++++ 6 files changed, 195 insertions(+), 3 deletions(-) create mode 100644 pluginloader.cpp create mode 100644 pluginloader.h diff --git a/CMakeLists.txt b/CMakeLists.txt index e029975f9..0cc3d054e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -108,6 +108,7 @@ set(plasma_LIB_SRCS extenders/extender.cpp extenders/extendergroup.cpp extenders/extenderitem.cpp + pluginloader.cpp paintutils.cpp framesvg.cpp plasma.cpp @@ -310,6 +311,7 @@ set(plasma_LIB_INCLUDES extenders/extender.h extenders/extendergroup.h extenders/extenderitem.h + pluginloader.h paintutils.h windoweffects.h framesvg.h diff --git a/applet.cpp b/applet.cpp index 27bf8e1b3..66e059d89 100644 --- a/applet.cpp +++ b/applet.cpp @@ -99,6 +99,7 @@ #include "wallpaper.h" #include "paintutils.h" #include "abstractdialogmanager.h" +#include "pluginloader.h" #include "private/associatedapplicationmanager_p.h" #include "private/authorizationmanager_p.h" @@ -2292,6 +2293,18 @@ Applet *Applet::loadPlasmoid(const QString &path, uint appletId, const QVariantL Applet *Applet::load(const QString &appletName, uint appletId, const QVariantList &args) { + Applet* applet = 0; + + // Get the plugin loader + if (PluginLoader::pluginLoader()) { + applet = PluginLoader::pluginLoader()->loadApplet(appletName, appletId, args); + if (applet) { + return applet; + } + } + + // the application-specific appletLoader failed to create an applet, here we try with our own logic. + if (appletName.isEmpty()) { return 0; } @@ -2320,7 +2333,7 @@ Applet *Applet::load(const QString &appletName, uint appletId, const QVariantLis } KService::Ptr offer = offers.first(); - + if (appletId == 0) { appletId = ++AppletPrivate::s_maxAppletId; } @@ -2351,7 +2364,6 @@ Applet *Applet::load(const QString &appletName, uint appletId, const QVariantLis QString error; - Applet *applet; if (appletName == "internal:extender") { applet = new ExtenderApplet(0, allArgs); diff --git a/dataenginemanager.cpp b/dataenginemanager.cpp index 810e3ea54..f4c2f126b 100644 --- a/dataenginemanager.cpp +++ b/dataenginemanager.cpp @@ -24,6 +24,7 @@ #include "private/dataengine_p.h" #include "scripting/scriptengine.h" +#include "pluginloader.h" namespace Plasma { @@ -113,7 +114,15 @@ Plasma::DataEngine *DataEngineManager::loadEngine(const QString &name) { Plasma::DataEngine *engine = 0; Plasma::DataEngine::Dict::const_iterator it = d->engines.constFind(name); - + + // Ask the application's plugin loader, if present + if (PluginLoader::pluginLoader()) { + engine = PluginLoader::pluginLoader()->loadEngine(name); + if (engine) { + return engine; + } + } + if (it != d->engines.constEnd()) { engine = *it; engine->d->ref(); diff --git a/pluginloader.cpp b/pluginloader.cpp new file mode 100644 index 000000000..d33125d5e --- /dev/null +++ b/pluginloader.cpp @@ -0,0 +1,64 @@ +/* + * Copyright 2010 Ryan Rix + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2, 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 Library 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 "pluginloader.h" +#include +#include + +namespace Plasma { + +class PluginLoaderPrivate +{ + // Placeholder for BC +}; + +static PluginLoader* s_pluginLoader = 0; + +PluginLoader::~PluginLoader() +{ +} + +void PluginLoader::setPluginLoader(PluginLoader* loader) +{ + if(!s_pluginLoader) { + s_pluginLoader = loader; + } else { + kDebug() << "Cannot set pluginLoader, already set!"; + } +} + +PluginLoader* PluginLoader::pluginLoader() +{ + return s_pluginLoader; +} + +Applet* PluginLoader::loadApplet(const QString &name, uint appletId, const QVariantList &args) +{ Q_UNUSED(name) Q_UNUSED(appletId) Q_UNUSED(args) return 0; +} + +DataEngine* PluginLoader::loadEngine(const QString &name) +{ Q_UNUSED(name) return 0; +} + +Service* PluginLoader::loadService(const QString &name, const QVariantList &args, QObject *parent) +{ Q_UNUSED(name) Q_UNUSED(args) Q_UNUSED(parent) return 0; +} + +} // Plasma Namespace + diff --git a/pluginloader.h b/pluginloader.h new file mode 100644 index 000000000..b570ab69b --- /dev/null +++ b/pluginloader.h @@ -0,0 +1,96 @@ +/* + * Copyright 2010 by Ryan Rix + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2, 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 Library 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 PLUGIN_LOADER_H +#define PLUGIN_LOADER_H + +#include + +namespace Plasma { + +class Applet; +class DataEngine; +class Service; + +class PluginLoaderPrivate; + +/** + * This is an abstract base class which defines an interface to which Plasma's + * Applet Loading logic can communicate with a parent application. + * + * @author Ryan Rix + * @since 4.6 + **/ +class PLASMA_EXPORT PluginLoader +{ +public: + virtual ~PluginLoader(); + + /** + * Load an external applet and supply it to Plasma. + * + * @param name the plugin name, as returned by KPluginInfo::pluginName() + * @param appletId unique ID to assign the applet, or zero to have one + * assigned automatically. + * @param args to send the applet extra arguments + * @return a pointer to the loaded applet, or 0 on load failure + **/ + virtual Applet* loadApplet(const QString &name, uint appletId = 0, + const QVariantList &args = QVariantList()); + + /** + * Load an external DataEngine and supply it to Plasma. + * + * @param name the name of the engine + * @return the data engine that was loaded, or the NullEngine on failure. + **/ + virtual DataEngine* loadEngine(const QString &name); + + /** + * Load an external Service and supply it to Plasma. + * + * @param name the plugin name of the service to load + * @param args a list of arguments to supply to the service plugin when loading it + * @param parent the parent object, if any, for the service + * + * @return a Service object, unlike Plasma::Service::loadService, this can return null. + **/ + virtual Service* loadService(const QString &name, const QVariantList &args, QObject *parent = 0); + + /** + * Set the plugin loader which will be queried for all loads. + * + * @param loader A subclass of PluginLoader which will be supplied + * by the application + **/ + static void setPluginLoader(PluginLoader* loader); + + /** + * Return the active plugin loader + **/ + static PluginLoader* pluginLoader(); + +private: + PluginLoaderPrivate* d; +}; + +} +Q_DECLARE_METATYPE( Plasma::PluginLoader* ) // so that it can be wrapped in QVariants, etc + +#endif diff --git a/service.cpp b/service.cpp index 298b8ab7d..863824bf0 100644 --- a/service.cpp +++ b/service.cpp @@ -40,6 +40,7 @@ #include "private/configloader_p.h" #include "private/remoteservice_p.h" #include "private/remoteservicejob_p.h" +#include "pluginloader.h" namespace Plasma { @@ -89,6 +90,14 @@ Service *Service::load(const QString &name, const QVariantList &args, QObject *p //args << name; Service *service = 0; + // Ask the application's plugin loader, if present + if (PluginLoader::pluginLoader()) { + service = PluginLoader::pluginLoader()->loadService(name, args, parent); + if (service) { + return service; + } + } + if (Plasma::isPluginVersionCompatible(KPluginLoader(*offer).pluginVersion())) { service = offer->createInstance(parent, args, &error); }