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
This commit is contained in:
parent
ab688e2471
commit
e00a7b2422
@ -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
|
||||
|
14
applet.cpp
14
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;
|
||||
}
|
||||
@ -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);
|
||||
|
@ -24,6 +24,7 @@
|
||||
|
||||
#include "private/dataengine_p.h"
|
||||
#include "scripting/scriptengine.h"
|
||||
#include "pluginloader.h"
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
@ -114,6 +115,14 @@ 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();
|
||||
|
64
pluginloader.cpp
Normal file
64
pluginloader.cpp
Normal file
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright 2010 Ryan Rix <ry@n.rix.si>
|
||||
*
|
||||
* 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 <kglobal.h>
|
||||
#include <kdebug.h>
|
||||
|
||||
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
|
||||
|
96
pluginloader.h
Normal file
96
pluginloader.h
Normal file
@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Copyright 2010 by Ryan Rix <ry@n.rix.si>
|
||||
*
|
||||
* 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 <plasma/plasma.h>
|
||||
|
||||
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 <ry@n.rix.si>
|
||||
* @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
|
@ -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<Plasma::Service>(parent, args, &error);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user