make DataEngineConsumer public API

this will become the prefered way to access DataEngines rather than
DataEngineManager which exposes implementation details that need to
be manually managed
This commit is contained in:
Aaron Seigo 2012-09-24 15:51:14 +02:00
parent 35590c27eb
commit 97a13a9dbe
19 changed files with 176 additions and 193 deletions

View File

@ -108,6 +108,7 @@ set(plasma_LIB_SRCS
coronabase.cpp
datacontainer.cpp
dataengine.cpp
dataengineconsumer.cpp
dataenginemanager.cpp
package.cpp
packagestructure.cpp
@ -120,7 +121,6 @@ set(plasma_LIB_SRCS
private/associatedapplicationmanager.cpp
private/componentinstaller.cpp
private/datacontainer_p.cpp
private/dataengineconsumer.cpp
private/dataengineservice.cpp
private/effects/halopainter.cpp
private/effectwatcher.cpp

View File

@ -395,11 +395,7 @@ ConfigLoader *Applet::configScheme() const
DataEngine *Applet::dataEngine(const QString &name) const
{
if (d->remoteLocation.isEmpty()) {
return d->dataEngine(name);
} else {
return d->remoteDataEngine(d->remoteLocation, name);
}
return d->dataEngine(name, d->remoteLocation);
}
Package Applet::package() const

View File

@ -20,7 +20,6 @@
#include "containmentactions.h"
#include "containment.h"
#include "private/dataengineconsumer_p.h"
#include "private/packages_p.h"
#include "private/containmentactions_p.h"
#include "private/containment_p.h"
@ -36,8 +35,8 @@
#include <klocalizedstring.h>
#include <kservicetypetrader.h>
#include <version.h>
#include "dataengineconsumer.h"
#include "version.h"
namespace Plasma
{

View File

@ -30,6 +30,7 @@
#include <kdebug.h>
#include <kplugininfo.h>
#include <kservice.h>
#include <kservicetypetrader.h>
#include <kstandarddirs.h>
#include <klocale.h>
@ -709,6 +710,48 @@ void DataEnginePrivate::setupScriptSupport()
}
}
QStringList DataEngine::listAllEngines(const QString &parentApp)
{
QString constraint;
if (parentApp.isEmpty()) {
constraint.append("(not exist [X-KDE-ParentApp] or [X-KDE-ParentApp] == '')");
} else {
constraint.append("[X-KDE-ParentApp] == '").append(parentApp).append("'");
}
KService::List offers = KServiceTypeTrader::self()->query("Plasma/DataEngine", constraint);
QStringList engines;
foreach (const KService::Ptr &service, offers) {
QString name = service->property("X-KDE-PluginInfo-Name").toString();
if (!name.isEmpty()) {
engines.append(name);
}
}
return engines;
}
KPluginInfo::List DataEngine::listEngineInfo(const QString &parentApp)
{
return PluginLoader::self()->listDataEngineInfo(parentApp);
}
KPluginInfo::List DataEngine::listEngineInfoByCategory(const QString &category, const QString &parentApp)
{
QString constraint = QString("[X-KDE-PluginInfo-Category] == '%1'").arg(category);
if (parentApp.isEmpty()) {
constraint.append(" and not exist [X-KDE-ParentApp]");
} else {
constraint.append(" and [X-KDE-ParentApp] == '").append(parentApp).append("'");
}
KService::List offers = KServiceTypeTrader::self()->query("Plasma/DataEngine", constraint);
return KPluginInfo::fromServices(offers);
}
}

View File

@ -24,6 +24,7 @@
#include <QtCore/QObject>
#include <QtCore/QStringList>
#include <kplugininfo.h>
#include <kservice.h>
#include <plasma/version.h>
@ -245,6 +246,47 @@ NoAlignment) const;
*/
Q_INVOKABLE Service* createDefaultService(QObject *parent = 0);
/**
* @return a listing of all known DataEngines by name
*
* @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.
*/
static QStringList listAllEngines(const QString &parentApp = QString());
/**
* Returns a list of all known DataEngines.
*
* @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 DataEngines
**/
static KPluginInfo::List listEngineInfo(const QString &parentApp = QString());
/**
* Returns a list of all known DataEngines filtering by category.
*
* @param category the category to filter applets on. Uses the
* X-KDE-PluginInfo-Category entry (if any) in the
* plugin info. The value of QString() will
* result in a list of engines with an empty category.
*
* @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 DataEngines
* @since 4.3
**/
static KPluginInfo::List listEngineInfoByCategory(const QString &category, const QString &parentApp = QString());
Q_SIGNALS:
/**
* Emitted when a new data source is created

View File

@ -19,30 +19,22 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "dataengineconsumer_p.h"
#include "dataengineconsumer.h"
#include "private/dataengineconsumer_p.h"
#include <QtCore/QSet>
#include <QSet>
#include <qurlpathinfo.h>
#include <kdebug.h>
#include "plasma/dataenginemanager.h"
#include "plasma/private/remotedataengine_p.h"
#include <servicejob.h>
#include <qurlpathinfo.h>
#include "dataenginemanager.h"
#include "private/remotedataengine_p.h"
#include "servicejob.h"
namespace Plasma
{
ServiceMonitor::ServiceMonitor(DataEngineConsumer *consumer)
: m_consumer(consumer)
{
}
ServiceMonitor::~ServiceMonitor()
{
}
void ServiceMonitor::slotJobFinished(Plasma::ServiceJob *job)
void DataEngineConsumerPrivate::slotJobFinished(Plasma::ServiceJob *job)
{
#ifndef NDEBUG
kDebug() << "engine ready!";
@ -53,7 +45,7 @@ void ServiceMonitor::slotJobFinished(Plasma::ServiceJob *job)
#ifndef NDEBUG
kDebug() << "pair = " << pair;
#endif
if (!m_consumer->m_remoteEngines.contains(pair)) {
if (!remoteEngines.contains(pair)) {
#ifndef NDEBUG
kDebug() << "engine does not exist yet!";
#endif
@ -63,25 +55,25 @@ void ServiceMonitor::slotJobFinished(Plasma::ServiceJob *job)
#ifndef NDEBUG
kDebug() << "setting location : " << engineLocation.url();
#endif
m_consumer->m_remoteEngines[pair]->setLocation(engineLocation.url());
remoteEngines[pair]->setLocation(engineLocation.url());
}
}
void ServiceMonitor::slotServiceReady(Plasma::Service *plasmoidService)
void DataEngineConsumerPrivate::slotServiceReady(Plasma::Service *plasmoidService)
{
#ifndef NDEBUG
kDebug() << "service ready!";
#endif
if (!m_consumer->m_engineNameForService.contains(plasmoidService)) {
if (!engineNameForService.contains(plasmoidService)) {
#ifndef NDEBUG
kDebug() << "no engine name for service!";
#endif
#ifndef NDEBUG
kDebug() << "amount of services in map: " << m_consumer->m_engineNameForService.count();
kDebug() << "amount of services in map: " << engineNameForService.count();
#endif
} else {
#ifndef NDEBUG
kDebug() << "value = " << m_consumer->m_engineNameForService.value(plasmoidService);
kDebug() << "value = " << engineNameForService.value(plasmoidService);
#endif
}
@ -89,77 +81,81 @@ void ServiceMonitor::slotServiceReady(Plasma::Service *plasmoidService)
kDebug() << "requesting dataengine!";
#endif
KConfigGroup op = plasmoidService->operationDescription("DataEngine");
op.writeEntry("EngineName", m_consumer->m_engineNameForService.value(plasmoidService));
op.writeEntry("EngineName", engineNameForService.value(plasmoidService));
plasmoidService->startOperationCall(op);
connect(plasmoidService, SIGNAL(finished(Plasma::ServiceJob*)),
this, SLOT(slotJobFinished(Plasma::ServiceJob*)));
}
DataEngineConsumer::DataEngineConsumer()
: m_monitor(new ServiceMonitor(this))
{
}
DataEngineConsumer::~DataEngineConsumer()
{
foreach (const QString &engine, m_loadedEngines) {
DataEngineManager::self()->unloadEngine(engine);
}
delete m_monitor;
}
DataEngine *DataEngineConsumer::dataEngine(const QString &name)
{
if (m_loadedEngines.contains(name)) {
DataEngine *engine = DataEngineManager::self()->engine(name);
if (engine->isValid()) {
return engine;
} else {
m_loadedEngines.remove(name);
}
}
DataEngine *engine = DataEngineManager::self()->loadEngine(name);
if (engine->isValid()) {
m_loadedEngines.insert(name);
}
return engine;
}
DataEngine *DataEngineConsumer::remoteDataEngine(const QUrl &location, const QString &name)
DataEngine *DataEngineConsumerPrivate::remoteDataEngine(const QString &name, const QUrl &location)
{
QPair<QString, QString> pair(location.toString(), name);
#ifndef NDEBUG
kDebug() << "pair = " << pair;
#endif
if (m_remoteEngines.contains(pair)) {
if (remoteEngines.contains(pair)) {
#ifndef NDEBUG
kDebug() << "existing remote dataengine at " << location;
#endif
return m_remoteEngines[pair];
return remoteEngines[pair];
}
#ifndef NDEBUG
kDebug() << "new remote dataengine at " << location;
#endif
RemoteDataEngine *engine = new RemoteDataEngine(QUrl());
m_remoteEngines[pair] = engine;
remoteEngines[pair] = engine;
Service *plasmoidService = Service::access(location);
plasmoidService->setDestination(location.toString());
m_engineNameForService[plasmoidService] = name;
engineNameForService[plasmoidService] = name;
#ifndef NDEBUG
kDebug() << "name = " << name;
#endif
QObject::connect(plasmoidService, SIGNAL(serviceReady(Plasma::Service*)),
m_monitor, SLOT(slotServiceReady(Plasma::Service*)));
connect(plasmoidService, SIGNAL(serviceReady(Plasma::Service*)),
this, SLOT(slotServiceReady(Plasma::Service*)));
return engine;
}
DataEngineConsumer::DataEngineConsumer()
: d(new DataEngineConsumerPrivate)
{
}
DataEngineConsumer::~DataEngineConsumer()
{
foreach (const QString &engine, d->loadedEngines) {
DataEngineManager::self()->unloadEngine(engine);
}
delete d;
}
DataEngine *DataEngineConsumer::dataEngine(const QString &name, const QUrl &location)
{
if (!location.isEmpty()) {
return d->remoteDataEngine(name, location);
}
if (d->loadedEngines.contains(name)) {
DataEngine *engine = DataEngineManager::self()->engine(name);
if (engine->isValid()) {
return engine;
} else {
d->loadedEngines.remove(name);
}
}
DataEngine *engine = DataEngineManager::self()->loadEngine(name);
if (engine->isValid()) {
d->loadedEngines.insert(name);
}
return engine;
}
} // namespace Plasma
#include "moc_dataengineconsumer_p.cpp"
#include "private/moc_dataengineconsumer_p.cpp"

View File

@ -158,48 +158,6 @@ void DataEngineManager::unloadEngine(const QString &name)
}
}
QStringList DataEngineManager::listAllEngines(const QString &parentApp)
{
QString constraint;
if (parentApp.isEmpty()) {
constraint.append("(not exist [X-KDE-ParentApp] or [X-KDE-ParentApp] == '')");
} else {
constraint.append("[X-KDE-ParentApp] == '").append(parentApp).append("'");
}
KService::List offers = KServiceTypeTrader::self()->query("Plasma/DataEngine", constraint);
QStringList engines;
foreach (const KService::Ptr &service, offers) {
QString name = service->property("X-KDE-PluginInfo-Name").toString();
if (!name.isEmpty()) {
engines.append(name);
}
}
return engines;
}
KPluginInfo::List DataEngineManager::listEngineInfo(const QString &parentApp)
{
return PluginLoader::self()->listDataEngineInfo(parentApp);
}
KPluginInfo::List DataEngineManager::listEngineInfoByCategory(const QString &category, const QString &parentApp)
{
QString constraint = QString("[X-KDE-PluginInfo-Category] == '%1'").arg(category);
if (parentApp.isEmpty()) {
constraint.append(" and not exist [X-KDE-ParentApp]");
} else {
constraint.append(" and [X-KDE-ParentApp] == '").append(parentApp).append("'");
}
KService::List offers = KServiceTypeTrader::self()->query("Plasma/DataEngine", constraint);
return KPluginInfo::fromServices(offers);
}
void DataEngineManager::timerEvent(QTimerEvent *)
{
#ifndef NDEBUG

View File

@ -74,46 +74,6 @@ class PLASMA_EXPORT DataEngineManager: public QObject
*/
void unloadEngine(const QString &name);
/**
* @return a listing of all known DataEngines by name
*
* @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.
*/
static QStringList listAllEngines(const QString &parentApp = QString());
/**
* Returns a list of all known DataEngines.
*
* @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 DataEngines
**/
static KPluginInfo::List listEngineInfo(const QString &parentApp = QString());
/**
* Returns a list of all known DataEngines filtering by category.
*
* @param category the category to filter applets on. Uses the
* X-KDE-PluginInfo-Category entry (if any) in the
* plugin info. The value of QString() will
* result in a list of engines with an empty category.
*
* @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 DataEngines
* @since 4.3
**/
static KPluginInfo::List listEngineInfoByCategory(const QString &category, const QString &parentApp = QString());
protected:
/**

View File

@ -35,6 +35,7 @@
#include "abstractrunner.h"
#include "containment.h"
#include "containmentactions.h"
#include "dataengine.h"
#include "package.h"
#include "popupapplet.h"
#include "private/applet_p.h"

View File

@ -295,7 +295,7 @@ protected:
/**
* A re-implementable method that allows subclasses to provide additional DataEngines
* for DataEngineManager::listDataEngines.
* for DataEngine::listDataEngines.
*
* @return list of DataEngines info, or an empty list if none
**/

View File

@ -22,7 +22,7 @@
#include <QReadWriteLock>
#include "dataengineconsumer_p.h"
#include "dataengineconsumer.h"
namespace Plasma
{

View File

@ -30,7 +30,7 @@
#include "plasma/animator.h"
#include "plasma/private/applethandle_p.h"
#include "plasma/private/dataengineconsumer_p.h"
#include "plasma/dataengineconsumer.h"
#include "plasma/ui_publish.h"
class KKeySequenceWidget;
@ -44,6 +44,7 @@ class AppletScript;
class Wallpaper;
class BusyWidget;
class PushButton;
class Service;
class AppletConfigDialog : public KConfigDialog
{

View File

@ -20,7 +20,7 @@
#ifndef PLASMA_CONTAINMENTACTIONSPRIVATE_H
#define PLASMA_CONTAINMENTACTIONSPRIVATE_H
#include "plasma/private/dataengineconsumer_p.h"
#include "dataengineconsumer.h"
namespace Plasma
{

View File

@ -19,56 +19,38 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef PLASMA_DATAENGINECONSUMER_H
#define PLASMA_DATAENGINECONSUMER_H
#ifndef PLASMA_DATAENGINECONSUMER_P_H
#define PLASMA_DATAENGINECONSUMER_P_H
#include <QtCore/QSet>
#include <kdebug.h>
#include <QtCore/QUrl>
#include "plasma/dataenginemanager.h"
#include <servicejob.h>
#include "servicejob.h"
namespace Plasma
{
class DataEngineConsumer;
class RemoteDataEngine;
class ServiceMonitor;
class ServiceMonitor : public QObject
class DataEngineConsumerPrivate : public QObject
{
Q_OBJECT
public:
ServiceMonitor(DataEngineConsumer *consumer);
~ServiceMonitor();
QSet<QString> loadedEngines;
QMap<QPair<QString, QString>, RemoteDataEngine*> remoteEngines;
QMap<Service*, QString> engineNameForService;
DataEngine *remoteDataEngine(const QString &name, const QUrl &location);
public Q_SLOTS:
void slotJobFinished(Plasma::ServiceJob *job);
void slotServiceReady(Plasma::Service *service);
private:
DataEngineConsumer *m_consumer;
};
class DataEngineConsumer
{
public:
DataEngineConsumer();
~DataEngineConsumer();
DataEngine *dataEngine(const QString &name);
DataEngine *remoteDataEngine(const QUrl &location, const QString &name);
private:
QSet<QString> m_loadedEngines;
QMap<QPair<QString, QString>, RemoteDataEngine*> m_remoteEngines;
QMap<Service*, QString> m_engineNameForService;
ServiceMonitor *m_monitor;
friend class ServiceMonitor;
};
} // namespace Plasma
#endif

View File

@ -19,10 +19,11 @@
#include "plasmoidservice_p.h"
#include "authorizationmanager_p.h"
#include "dataengineconsumer_p.h"
#include "dataengine_p.h"
#include "dataengineconsumer.h"
#include <plasma/applet.h>
#include <plasma/dataengine.h>
#include <plasma/private/dataengine_p.h>
#include <plasma/remote/authorizationmanager.h>
#include <plasma/remote/authorizationrule.h>
#include <plasma/service.h>

View File

@ -19,7 +19,7 @@
#ifndef PLASMOIDSERVICE_H
#define PLASMOIDSERVICE_H
#include "dataengineconsumer_p.h"
#include "dataengineconsumer.h"
#include "../package.h"
#include "../service.h"

View File

@ -25,8 +25,8 @@
#include <QtCore/QRunnable>
#include <QtCore/QWeakPointer>
#include "plasma/dataengineconsumer.h"
#include "plasma/scripting/wallpaperscript.h"
#include "plasma/private/dataengineconsumer_p.h"
#include "plasma/private/wallpaperrenderthread_p.h"
namespace Plasma

View File

@ -30,6 +30,11 @@ namespace Plasma
class RunnerScriptPrivate
{
public:
RunnerScriptPrivate()
: runner(0)
{
}
AbstractRunner *runner;
};

View File

@ -47,7 +47,6 @@
#include "package.h"
#include "pluginloader.h"
#include "private/dataengineconsumer_p.h"
#include "private/packages_p.h"
#include "private/wallpaper_p.h"