mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-23 18:32:49 +00:00
plasma: drop redundant Plasma::PluginLoader class
not finished either Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
95340211ee
commit
1f11147bd4
8 changed files with 74 additions and 253 deletions
|
@ -477,7 +477,6 @@ install(
|
|||
Plasma/PackageStructure
|
||||
Plasma/PaintUtils
|
||||
Plasma/Plasma
|
||||
Plasma/PluginLoader
|
||||
Plasma/PopupApplet
|
||||
Plasma/PushButton
|
||||
Plasma/QueryMatch
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
#include "../../plasma/pluginloader.h"
|
|
@ -43,7 +43,6 @@ set(plasma_LIB_SRCS
|
|||
extenders/extender.cpp
|
||||
extenders/extendergroup.cpp
|
||||
extenders/extenderitem.cpp
|
||||
pluginloader.cpp
|
||||
paintutils.cpp
|
||||
framesvg.cpp
|
||||
plasma.cpp
|
||||
|
@ -156,7 +155,6 @@ install(
|
|||
extenders/extender.h
|
||||
extenders/extendergroup.h
|
||||
extenders/extenderitem.h
|
||||
pluginloader.h
|
||||
paintutils.h
|
||||
windoweffects.h
|
||||
framesvg.h
|
||||
|
|
|
@ -41,7 +41,6 @@
|
|||
#include "tooltipmanager.h"
|
||||
#include "wallpaper.h"
|
||||
#include "paintutils.h"
|
||||
#include "pluginloader.h"
|
||||
#include "animations/animation.h"
|
||||
#include "private/applet_p.h"
|
||||
#include "private/applethandle_p.h"
|
||||
|
@ -1953,7 +1952,21 @@ QString AppletPrivate::parentAppConstraint(const QString &parentApp)
|
|||
|
||||
KPluginInfo::List Applet::listAppletInfo(const QString &category, const QString &parentApp)
|
||||
{
|
||||
return PluginLoader::listAppletInfo(category, parentApp);
|
||||
QString constraint = AppletPrivate::parentAppConstraint(parentApp);
|
||||
|
||||
if (!category.isEmpty()) {
|
||||
// specific category
|
||||
constraint.append(" and [X-KDE-PluginInfo-Category] == '").append(category).append("'");
|
||||
if (category == "Miscellaneous") {
|
||||
constraint.append(" or (not exist [X-KDE-PluginInfo-Category] or [X-KDE-PluginInfo-Category] == '')");
|
||||
}
|
||||
}
|
||||
|
||||
KService::List offers = KServiceTypeTrader::self()->query("Plasma/Applet", constraint);
|
||||
|
||||
//kDebug() << "Applet::listAppletInfo constraint was '" << constraint
|
||||
// << "' which got us " << offers.count() << " matches";
|
||||
return KPluginInfo::fromServices(offers);
|
||||
}
|
||||
|
||||
KPluginInfo::List Applet::listAppletInfoForMimetype(const QString &mimetype)
|
||||
|
@ -2026,13 +2039,54 @@ QStringList Applet::listCategories(const QString &parentApp, bool visibleOnly)
|
|||
|
||||
Applet *Applet::load(const QString &appletName, uint appletId, const QVariantList &args)
|
||||
{
|
||||
return PluginLoader::loadApplet(appletName, appletId, args);
|
||||
if (appletName.isEmpty()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const QString constraint = QString("[X-KDE-PluginInfo-Name] == '%1'").arg(appletName);
|
||||
KService::List offers = KServiceTypeTrader::self()->query("Plasma/Applet", constraint);
|
||||
|
||||
if (offers.isEmpty()) {
|
||||
offers = KServiceTypeTrader::self()->query("Plasma/Containment", constraint);
|
||||
}
|
||||
|
||||
if (offers.count() > 1) {
|
||||
kDebug() << "got more than one! blindly taking the first one";
|
||||
}
|
||||
|
||||
if (offers.isEmpty()) {
|
||||
kDebug() << "applet offers is empty for " << appletName;
|
||||
return 0;
|
||||
}
|
||||
|
||||
KService::Ptr offer = offers.first();
|
||||
|
||||
if (appletId == 0) {
|
||||
appletId = ++AppletPrivate::s_maxAppletId;
|
||||
}
|
||||
|
||||
QVariantList allArgs;
|
||||
allArgs << offer->storageId() << appletId << args;
|
||||
|
||||
Applet* applet = nullptr;
|
||||
QString error;
|
||||
if (appletName == "internal:extender") {
|
||||
applet = new ExtenderApplet(nullptr, allArgs);
|
||||
} else {
|
||||
applet = offer->createInstance<Plasma::Applet>(nullptr, allArgs, &error);
|
||||
}
|
||||
|
||||
if (!applet) {
|
||||
kWarning() << "Could not load applet" << appletName << "! reason given:" << error;
|
||||
}
|
||||
|
||||
return applet;
|
||||
}
|
||||
|
||||
Applet *Applet::load(const KPluginInfo &info, uint appletId, const QVariantList &args)
|
||||
Applet* Applet::load(const KPluginInfo &info, uint appletId, const QVariantList &args)
|
||||
{
|
||||
if (!info.isValid()) {
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return load(info.pluginName(), appletId, args);
|
||||
|
|
|
@ -979,7 +979,6 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
|
|||
friend class ContainmentPrivate;
|
||||
friend class AppletHandle;
|
||||
friend class AppletPrivate;
|
||||
friend class PluginLoader;
|
||||
friend class PopupApplet;
|
||||
friend class PopupAppletPrivate;
|
||||
friend class AssociatedApplicationManager;
|
||||
|
|
|
@ -1,125 +0,0 @@
|
|||
/*
|
||||
* 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 <kdebug.h>
|
||||
#include <kglobal.h>
|
||||
#include <kservice.h>
|
||||
#include <kservicetypetrader.h>
|
||||
#include <kstandarddirs.h>
|
||||
#include <kplugininfo.h>
|
||||
|
||||
#include "applet.h"
|
||||
#include "abstractrunner.h"
|
||||
#include "containment.h"
|
||||
#include "popupapplet.h"
|
||||
#include "private/applet_p.h"
|
||||
#include "private/extenderapplet_p.h"
|
||||
|
||||
namespace Plasma {
|
||||
|
||||
Applet *PluginLoader::loadApplet(const QString &name, uint appletId, const QVariantList &args)
|
||||
{
|
||||
// the application-specific appletLoader failed to create an applet, here we try with our own logic.
|
||||
if (name.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const QString constraint = QString("[X-KDE-PluginInfo-Name] == '%1'").arg(name);
|
||||
KService::List offers = KServiceTypeTrader::self()->query("Plasma/Applet", constraint);
|
||||
|
||||
if (offers.isEmpty()) {
|
||||
offers = KServiceTypeTrader::self()->query("Plasma/Containment", constraint);
|
||||
}
|
||||
|
||||
/* if (offers.count() > 1) {
|
||||
kDebug() << "hey! we got more than one! let's blindly take the first one";
|
||||
} */
|
||||
|
||||
if (offers.isEmpty()) {
|
||||
kDebug() << "offers is empty for " << name;
|
||||
return 0;
|
||||
}
|
||||
|
||||
KService::Ptr offer = offers.first();
|
||||
|
||||
if (appletId == 0) {
|
||||
appletId = ++AppletPrivate::s_maxAppletId;
|
||||
}
|
||||
|
||||
QVariantList allArgs;
|
||||
allArgs << offer->storageId() << appletId << args;
|
||||
|
||||
Applet *applet = 0;
|
||||
QString error;
|
||||
if (name == "internal:extender") {
|
||||
applet = new ExtenderApplet(0, allArgs);
|
||||
} else {
|
||||
applet = offer->createInstance<Plasma::Applet>(0, allArgs, &error);
|
||||
}
|
||||
|
||||
if (!applet) {
|
||||
kWarning() << "Could not load applet" << name << "! reason given:" << error;
|
||||
}
|
||||
|
||||
return applet;
|
||||
}
|
||||
|
||||
AbstractRunner *PluginLoader::loadRunner(const QString &name)
|
||||
{
|
||||
// FIXME: RunnerManager is all wrapped around runner loading; that should be sorted out
|
||||
// and the actual plugin loading added here
|
||||
return 0;
|
||||
}
|
||||
|
||||
KPluginInfo::List PluginLoader::listAppletInfo(const QString &category, const QString &parentApp)
|
||||
{
|
||||
QString constraint = AppletPrivate::parentAppConstraint(parentApp);
|
||||
|
||||
if (!category.isEmpty()) {
|
||||
// specific category
|
||||
constraint.append(" and [X-KDE-PluginInfo-Category] == '").append(category).append("'");
|
||||
if (category == "Miscellaneous") {
|
||||
constraint.append(" or (not exist [X-KDE-PluginInfo-Category] or [X-KDE-PluginInfo-Category] == '')");
|
||||
}
|
||||
}
|
||||
|
||||
KService::List offers = KServiceTypeTrader::self()->query("Plasma/Applet", constraint);
|
||||
|
||||
//kDebug() << "Applet::listAppletInfo constraint was '" << constraint
|
||||
// << "' which got us " << offers.count() << " matches";
|
||||
return KPluginInfo::fromServices(offers);
|
||||
}
|
||||
|
||||
KPluginInfo::List PluginLoader::listRunnerInfo(const QString &parentApp)
|
||||
{
|
||||
QString constraint;
|
||||
if (parentApp.isEmpty()) {
|
||||
constraint.append("not exist [X-KDE-ParentApp]");
|
||||
} else {
|
||||
constraint.append("[X-KDE-ParentApp] == '").append(parentApp).append("'");
|
||||
}
|
||||
|
||||
KService::List offers = KServiceTypeTrader::self()->query("Plasma/Runner", constraint);
|
||||
return KPluginInfo::fromServices(offers);
|
||||
}
|
||||
|
||||
} // Plasma Namespace
|
||||
|
|
@ -1,102 +0,0 @@
|
|||
/*
|
||||
* 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>
|
||||
#include <kplugininfo.h>
|
||||
|
||||
namespace Plasma {
|
||||
|
||||
class Applet;
|
||||
class AbstractRunner;
|
||||
|
||||
//TODO:
|
||||
// * add support for ContainmentActions plugins
|
||||
// * add KPluginInfo listing support for Containments (already loaded via the applet loading code)
|
||||
|
||||
/**
|
||||
* This is an abstract base class which defines an interface to which Plasma's
|
||||
* Applet Loading logic can communicate with a parent application. The plugin loader
|
||||
* must be set before any plugins are loaded, otherwise (for safety reasons), the
|
||||
* default PluginLoader implementation will be used. The reimplemented version should
|
||||
* not do more than simply returning a loaded plugin. It should not init() it, and it should not
|
||||
* hang on to it. The associated methods will be called only when a component of Plasma
|
||||
* needs to load a _new_ plugin.
|
||||
*
|
||||
* @author Ryan Rix <ry@n.rix.si>
|
||||
* @since 4.6
|
||||
**/
|
||||
class PLASMA_EXPORT PluginLoader
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Load an Applet plugin.
|
||||
*
|
||||
* @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
|
||||
**/
|
||||
static Applet *loadApplet(const QString &name, uint appletId = 0,
|
||||
const QVariantList &args = QVariantList());
|
||||
|
||||
/**
|
||||
* Load a Runner plugin
|
||||
*
|
||||
* @return the Runner that was loaded, or 0 on failure.
|
||||
*/
|
||||
static AbstractRunner *loadRunner(const QString &name);
|
||||
|
||||
/**
|
||||
* Returns a list of all known applets.
|
||||
*
|
||||
* @param category Only applets matchin this category will be returned.
|
||||
* Useful in conjunction with knownCategories.
|
||||
* If "Misc" is passed in, then applets without a
|
||||
* Categories= entry are also returned.
|
||||
* If an empty string is passed in, all applets are
|
||||
* returned.
|
||||
* @param parentApp the application to filter applets on. Uses the
|
||||
* X-KDE-ParentApp entry (if any) in the plugin info.
|
||||
* The default value of QString() will result in a
|
||||
* list containing only applets not specifically
|
||||
* registered to an application.
|
||||
* @return list of applets
|
||||
**/
|
||||
static KPluginInfo::List listAppletInfo(const QString &category, const QString &parentApp = QString());
|
||||
|
||||
/**
|
||||
* Returns a list of all known Runner implementations
|
||||
*
|
||||
* @param parentApp the application to filter applets on. Uses the
|
||||
* X-KDE-ParentApp entry (if any) in the plugin info.
|
||||
* The default value of QString() will result in a
|
||||
* list containing only applets not specifically
|
||||
* registered to an application.
|
||||
* @return list of AbstractRunners
|
||||
**/
|
||||
static KPluginInfo::List listRunnerInfo(const QString &parentApp = QString());
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -21,7 +21,6 @@
|
|||
|
||||
#include "runnermanager.h"
|
||||
#include "private/runnerjobs_p.h"
|
||||
#include "pluginloader.h"
|
||||
#include "querymatch.h"
|
||||
|
||||
#include <QTimer>
|
||||
|
@ -224,21 +223,13 @@ public:
|
|||
return 0;
|
||||
}
|
||||
|
||||
AbstractRunner *runner = PluginLoader::loadRunner(service->property("X-KDE-PluginInfo-Name", QVariant::String).toString());
|
||||
|
||||
if (runner) {
|
||||
runner->setParent(q);
|
||||
QVariantList args;
|
||||
args << service->storageId();
|
||||
QString error;
|
||||
AbstractRunner *runner = service->createInstance<AbstractRunner>(q, args, &error);
|
||||
if (!runner) {
|
||||
kWarning() << "Failed to load runner:" << service->name() << ". error reported:" << error;
|
||||
} else {
|
||||
QVariantList args;
|
||||
args << service->storageId();
|
||||
QString error;
|
||||
runner = service->createInstance<AbstractRunner>(q, args, &error);
|
||||
if (!runner) {
|
||||
kWarning() << "Failed to load runner:" << service->name() << ". error reported:" << error;
|
||||
}
|
||||
}
|
||||
|
||||
if (runner) {
|
||||
kDebug() << "================= loading runner:" << service->name() << "=================";
|
||||
QObject::connect(runner, SIGNAL(matchingSuspended(bool)), q, SLOT(runnerMatchingSuspended(bool)));
|
||||
QMetaObject::invokeMethod(runner, "init");
|
||||
|
@ -512,7 +503,15 @@ QMimeData * RunnerManager::mimeDataForMatch(const QueryMatch &match) const
|
|||
|
||||
KPluginInfo::List RunnerManager::listRunnerInfo(const QString &parentApp)
|
||||
{
|
||||
return PluginLoader::listRunnerInfo(parentApp);
|
||||
QString constraint;
|
||||
if (parentApp.isEmpty()) {
|
||||
constraint.append("not exist [X-KDE-ParentApp]");
|
||||
} else {
|
||||
constraint.append("[X-KDE-ParentApp] == '").append(parentApp).append("'");
|
||||
}
|
||||
|
||||
KService::List offers = KServiceTypeTrader::self()->query("Plasma/Runner", constraint);
|
||||
return KPluginInfo::fromServices(offers);
|
||||
}
|
||||
|
||||
void RunnerManager::setupMatchSession()
|
||||
|
|
Loading…
Add table
Reference in a new issue