2008-11-04 00:08:39 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2006-2007 Aaron Seigo <aseigo@kde.org>
|
|
|
|
*
|
|
|
|
* 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 "dataenginemanager.h"
|
|
|
|
|
2010-09-23 21:17:00 +02:00
|
|
|
#include <QFile>
|
|
|
|
#include <QTextStream>
|
|
|
|
|
2008-11-04 03:04:34 +01:00
|
|
|
#include <kdebug.h>
|
2010-09-23 21:17:00 +02:00
|
|
|
#include <kglobal.h>
|
|
|
|
#include <kstandarddirs.h>
|
2008-11-04 03:04:34 +01:00
|
|
|
#include <kservicetypetrader.h>
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2010-09-23 21:17:00 +02:00
|
|
|
#include "datacontainer.h"
|
|
|
|
#include "pluginloader.h"
|
2008-11-04 00:08:39 +01:00
|
|
|
#include "private/dataengine_p.h"
|
2010-09-23 21:17:00 +02:00
|
|
|
#include "private/datacontainer_p.h"
|
2008-11-04 00:08:39 +01:00
|
|
|
#include "scripting/scriptengine.h"
|
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
|
|
|
class NullEngine : public DataEngine
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NullEngine(QObject *parent = 0)
|
|
|
|
: DataEngine(parent)
|
|
|
|
{
|
|
|
|
setValid(false);
|
|
|
|
|
|
|
|
// ref() ourselves to ensure we never get deleted
|
|
|
|
d->ref();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class DataEngineManagerPrivate
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DataEngineManagerPrivate()
|
|
|
|
: nullEng(0)
|
|
|
|
{}
|
|
|
|
|
|
|
|
~DataEngineManagerPrivate()
|
|
|
|
{
|
|
|
|
foreach (Plasma::DataEngine *engine, engines) {
|
|
|
|
delete engine;
|
|
|
|
}
|
|
|
|
engines.clear();
|
|
|
|
delete nullEng;
|
|
|
|
}
|
|
|
|
|
|
|
|
DataEngine *nullEngine()
|
|
|
|
{
|
|
|
|
if (!nullEng) {
|
|
|
|
nullEng = new NullEngine;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullEng;
|
|
|
|
}
|
|
|
|
|
|
|
|
DataEngine::Dict engines;
|
|
|
|
DataEngine *nullEng;
|
|
|
|
};
|
|
|
|
|
|
|
|
class DataEngineManagerSingleton
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DataEngineManager self;
|
|
|
|
};
|
|
|
|
|
|
|
|
K_GLOBAL_STATIC(DataEngineManagerSingleton, privateDataEngineManagerSelf)
|
|
|
|
|
|
|
|
DataEngineManager *DataEngineManager::self()
|
|
|
|
{
|
|
|
|
return &privateDataEngineManagerSelf->self;
|
|
|
|
}
|
|
|
|
|
|
|
|
DataEngineManager::DataEngineManager()
|
|
|
|
: d(new DataEngineManagerPrivate)
|
|
|
|
{
|
2010-09-23 21:17:00 +02:00
|
|
|
//startTimer(30000);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
DataEngineManager::~DataEngineManager()
|
|
|
|
{
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
|
|
|
Plasma::DataEngine *DataEngineManager::engine(const QString &name) const
|
|
|
|
{
|
2009-11-19 01:17:29 +01:00
|
|
|
if (name.isEmpty()) {
|
|
|
|
return d->nullEngine();
|
|
|
|
}
|
|
|
|
|
2009-01-06 14:09:05 +01:00
|
|
|
Plasma::DataEngine::Dict::const_iterator it = d->engines.constFind(name);
|
|
|
|
if (it != d->engines.constEnd()) {
|
2008-11-04 00:08:39 +01:00
|
|
|
// ref and return the engine
|
|
|
|
//Plasma::DataEngine *engine = *it;
|
|
|
|
return *it;
|
|
|
|
}
|
|
|
|
|
|
|
|
return d->nullEngine();
|
|
|
|
}
|
|
|
|
|
|
|
|
Plasma::DataEngine *DataEngineManager::loadEngine(const QString &name)
|
|
|
|
{
|
2009-01-06 14:09:05 +01:00
|
|
|
Plasma::DataEngine::Dict::const_iterator it = d->engines.constFind(name);
|
2010-07-15 23:38:56 +02:00
|
|
|
|
2009-01-06 14:09:05 +01:00
|
|
|
if (it != d->engines.constEnd()) {
|
2010-07-15 23:38:56 +02:00
|
|
|
DataEngine *engine = *it;
|
2008-11-04 00:08:39 +01:00
|
|
|
engine->d->ref();
|
|
|
|
return engine;
|
|
|
|
}
|
|
|
|
|
2010-07-15 23:38:56 +02:00
|
|
|
DataEngine *engine = PluginLoader::pluginLoader()->loadDataEngine(name);
|
2008-11-04 00:08:39 +01:00
|
|
|
if (!engine) {
|
|
|
|
return d->nullEngine();
|
|
|
|
}
|
|
|
|
|
|
|
|
engine->init();
|
|
|
|
d->engines[name] = engine;
|
|
|
|
return engine;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DataEngineManager::unloadEngine(const QString &name)
|
|
|
|
{
|
|
|
|
Plasma::DataEngine::Dict::iterator it = d->engines.find(name);
|
|
|
|
|
|
|
|
if (it != d->engines.end()) {
|
|
|
|
Plasma::DataEngine *engine = *it;
|
|
|
|
engine->d->deref();
|
|
|
|
|
|
|
|
if (!engine->d->isUsed()) {
|
|
|
|
d->engines.erase(it);
|
|
|
|
delete engine;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-15 17:31:23 +01:00
|
|
|
QStringList DataEngineManager::listAllEngines(const QString &parentApp)
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
2009-01-15 17:31:23 +01:00
|
|
|
QString constraint;
|
|
|
|
|
|
|
|
if (parentApp.isEmpty()) {
|
2010-02-22 17:32:05 +01:00
|
|
|
constraint.append("(not exist [X-KDE-ParentApp] or [X-KDE-ParentApp] == '')");
|
2009-01-15 17:31:23 +01:00
|
|
|
} else {
|
|
|
|
constraint.append("[X-KDE-ParentApp] == '").append(parentApp).append("'");
|
|
|
|
}
|
|
|
|
|
|
|
|
KService::List offers = KServiceTypeTrader::self()->query("Plasma/DataEngine", constraint);
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2009-01-15 20:41:11 +01:00
|
|
|
KPluginInfo::List DataEngineManager::listEngineInfo(const QString &parentApp)
|
|
|
|
{
|
2010-07-28 20:18:13 +02:00
|
|
|
return PluginLoader::pluginLoader()->listDataEngineInfo(parentApp);
|
2009-01-15 20:41:11 +01:00
|
|
|
}
|
|
|
|
|
2009-05-12 18:13:51 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2011-04-28 14:54:20 +02:00
|
|
|
void DataEngineManager::timerEvent(QTimerEvent *)
|
2010-09-23 21:17:00 +02:00
|
|
|
{
|
|
|
|
#ifndef NDEBUG
|
|
|
|
QString path = KGlobal::dirs()->locateLocal("appdata", "plasma_dataenginemanager_log");
|
|
|
|
QFile f(path);
|
|
|
|
if (!f.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text)) {
|
|
|
|
kDebug() << "faild to open" << path;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QTextStream out(&f);
|
|
|
|
|
|
|
|
QHashIterator<QString, DataEngine*> it(d->engines);
|
|
|
|
out << "================================== " << KGlobal::locale()->formatDateTime(QDateTime::currentDateTime()) << endl;
|
|
|
|
while (it.hasNext()) {
|
|
|
|
it.next();
|
|
|
|
DataEngine *engine = it.value();
|
|
|
|
out << "DataEngine: " << it.key() << ' ' << engine << endl;
|
|
|
|
out << " Claimed # of sources: " << engine->sources().count() << endl;
|
|
|
|
out << " Actual # of sources: " << engine->containerDict().count() << endl;
|
|
|
|
out << endl << " Source Details" << endl;
|
|
|
|
|
|
|
|
foreach (DataContainer *dc, engine->containerDict()) {
|
|
|
|
out << " * " << dc->objectName() << endl;
|
|
|
|
out << " Data count: " << dc->d->data.count() << endl;
|
|
|
|
out << " Stored: " << dc->isStorageEnabled() << ' ' << endl;
|
|
|
|
const int directs = dc->receivers(SIGNAL(dataUpdated(QString, Plasma::DataEngine::Data)));
|
|
|
|
if (directs > 0) {
|
|
|
|
out << " Direction Connections: " << directs << ' ' << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
const int relays = dc->d->relays.count();
|
|
|
|
if (relays > 0) {
|
|
|
|
out << " Relays: " << dc->d->relays.count() << endl;
|
|
|
|
QString times;
|
|
|
|
foreach (SignalRelay *relay, dc->d->relays) {
|
|
|
|
times.append(' ').append(QString::number(relay->m_interval));
|
|
|
|
}
|
|
|
|
out << " Relay Timeouts: " << times << ' ' << endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
out << endl << "-----" << endl;
|
|
|
|
}
|
|
|
|
out << endl << endl;
|
|
|
|
#endif
|
|
|
|
// killTimer(event->timerId());
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
} // namespace Plasma
|
|
|
|
|
|
|
|
#include "dataenginemanager.moc"
|