27#include <kstandarddirs.h>
28#include <kservicetypetrader.h>
32#include "private/componentinstaller_p.h"
33#include "private/dataengine_p.h"
34#include "private/datacontainer_p.h"
40class NullEngine :
public DataEngine
53class DataEngineManagerPrivate
56 DataEngineManagerPrivate()
60 ~DataEngineManagerPrivate()
69 DataEngine *nullEngine()
72 nullEng =
new NullEngine;
82class DataEngineManagerSingleton
85 DataEngineManager self;
88K_GLOBAL_STATIC(DataEngineManagerSingleton, privateDataEngineManagerSelf)
92 return &privateDataEngineManagerSelf->
self;
95DataEngineManager::DataEngineManager()
96 : d(new DataEngineManagerPrivate)
101DataEngineManager::~DataEngineManager()
108 if (name.isEmpty()) {
109 return d->nullEngine();
112 Plasma::DataEngine::Dict::const_iterator it = d->engines.constFind(name);
113 if (it != d->engines.constEnd()) {
119 return d->nullEngine();
124 Plasma::DataEngine::Dict::const_iterator it = d->engines.constFind(name);
126 if (it != d->engines.constEnd()) {
135 ComponentInstaller::self()->installMissingComponent(
"dataengine", name);
137 return d->nullEngine();
141 d->engines[name] =
engine;
145void DataEngineManager::unloadEngine(
const QString &name)
147 Plasma::DataEngine::Dict::iterator it = d->engines.find(name);
149 if (it != d->engines.end()) {
153 if (!
engine->d->isUsed()) {
154 d->engines.erase(it);
160QStringList DataEngineManager::listAllEngines(
const QString &parentApp)
164 if (parentApp.isEmpty()) {
165 constraint.append(
"(not exist [X-KDE-ParentApp] or [X-KDE-ParentApp] == '')");
167 constraint.append(
"[X-KDE-ParentApp] == '").append(parentApp).append(
"'");
170 KService::List offers = KServiceTypeTrader::self()->
query(
"Plasma/DataEngine", constraint);
173 foreach (
const KService::Ptr &service, offers) {
174 QString name = service->property(
"X-KDE-PluginInfo-Name").toString();
175 if (!name.isEmpty()) {
176 engines.append(name);
183KPluginInfo::List DataEngineManager::listEngineInfo(
const QString &parentApp)
188KPluginInfo::List DataEngineManager::listEngineInfoByCategory(
const QString &category,
const QString &parentApp)
190 QString constraint = QString(
"[X-KDE-PluginInfo-Category] == '%1'").arg(category);
192 if (parentApp.isEmpty()) {
193 constraint.append(
" and not exist [X-KDE-ParentApp]");
195 constraint.append(
" and [X-KDE-ParentApp] == '").append(parentApp).append(
"'");
198 KService::List offers = KServiceTypeTrader::self()->query(
"Plasma/DataEngine", constraint);
199 return KPluginInfo::fromServices(offers);
202void DataEngineManager::timerEvent(QTimerEvent *)
205 QString path = KGlobal::dirs()->locateLocal(
"appdata",
"plasma_dataenginemanager_log");
207 if (!f.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text)) {
208 kDebug() <<
"faild to open" << path;
214 QHashIterator<QString, DataEngine*> it(d->engines);
215 out <<
"================================== " << KGlobal::locale()->formatDateTime(QDateTime::currentDateTime()) << endl;
216 while (it.hasNext()) {
219 out <<
"DataEngine: " << it.key() <<
' ' <<
engine << endl;
220 out <<
" Claimed # of sources: " <<
engine->
sources().count() << endl;
222 out << endl <<
" Source Details" << endl;
225 out <<
" * " << dc->objectName() << endl;
226 out <<
" Data count: " << dc->d->data.count() << endl;
230 out <<
" Direction Connections: " << directs <<
' ' << endl;
233 const int relays = dc->d->relays.count();
235 out <<
" Relays: " << dc->d->relays.count() << endl;
237 foreach (SignalRelay *relay, dc->d->relays) {
238 times.append(
' ').append(QString::number(relay->m_interval));
240 out <<
" Relay Timeouts: " << times <<
' ' << endl;
244 out << endl <<
"-----" << endl;
253#include "dataenginemanager.moc"
A set of data exported via a DataEngine.
bool isStorageEnabled() const
DataEngine loader and life time manager.
static DataEngineManager * self()
Singleton pattern accessor.
Plasma::DataEngine * engine(const QString &name) const
Returns a data engine object if one is loaded and available.
Data provider for plasmoids (Plasma plugins)
void setValid(bool valid)
Sets whether or not this engine is valid, e.g.
SourceDict containerDict() const
QHash< QString, DataEngine * > Dict
virtual void init()
This method is called when the DataEngine is started.
Q_INVOKABLE DataEngine::Data query(const QString &source) const
Gets the Data associated with a data source.
DataEngine(QObject *parent=0, KService::Ptr service=KService::Ptr(0))
Constructor.
QHash< QString, QVariant > Data
KPluginInfo::List listDataEngineInfo(const QString &parentApp=QString())
Returns a list of all known DataEngines.
DataEngine * loadDataEngine(const QString &name)
Load a DataEngine plugin.
static PluginLoader * pluginLoader()
Return the active plugin loader.
Namespace for everything in libplasma.