2009-09-02 04:27:16 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2005 by Aaron Seigo <aseigo@kde.org>
|
|
|
|
* Copyright 2007 by Riccardo Iaconelli <riccardo@kde.org>
|
|
|
|
* Copyright 2008 by Ménard Alexis <darktears31@gmail.com>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2012-09-24 15:51:14 +02:00
|
|
|
#include "dataengineconsumer.h"
|
|
|
|
#include "private/dataengineconsumer_p.h"
|
2009-09-02 04:27:16 +02:00
|
|
|
|
2012-09-24 15:51:14 +02:00
|
|
|
#include <QSet>
|
|
|
|
#include <qurlpathinfo.h>
|
2009-09-02 04:27:16 +02:00
|
|
|
|
|
|
|
#include <kdebug.h>
|
|
|
|
|
2012-09-24 16:09:16 +02:00
|
|
|
#include "private/dataenginemanager_p.h"
|
2012-09-24 15:51:14 +02:00
|
|
|
#include "servicejob.h"
|
2009-09-02 04:27:16 +02:00
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
2012-09-24 15:51:14 +02:00
|
|
|
void DataEngineConsumerPrivate::slotJobFinished(Plasma::ServiceJob *job)
|
2009-09-03 02:12:57 +02:00
|
|
|
{
|
2011-07-29 15:46:52 +02:00
|
|
|
#ifndef NDEBUG
|
2009-09-03 02:12:57 +02:00
|
|
|
kDebug() << "engine ready!";
|
2011-07-29 15:46:52 +02:00
|
|
|
#endif
|
2009-09-03 02:12:57 +02:00
|
|
|
QString engineName = job->parameters()["EngineName"].toString();
|
|
|
|
QString location = job->destination();
|
|
|
|
QPair<QString, QString> pair(location, engineName);
|
2011-07-29 15:46:52 +02:00
|
|
|
#ifndef NDEBUG
|
2009-09-03 02:12:57 +02:00
|
|
|
kDebug() << "pair = " << pair;
|
2011-07-29 15:46:52 +02:00
|
|
|
#endif
|
2009-09-03 02:12:57 +02:00
|
|
|
}
|
|
|
|
|
2012-09-24 15:51:14 +02:00
|
|
|
void DataEngineConsumerPrivate::slotServiceReady(Plasma::Service *plasmoidService)
|
2009-09-03 02:12:57 +02:00
|
|
|
{
|
2011-07-29 15:46:52 +02:00
|
|
|
#ifndef NDEBUG
|
2009-09-03 02:12:57 +02:00
|
|
|
kDebug() << "service ready!";
|
2011-07-29 15:46:52 +02:00
|
|
|
#endif
|
2012-09-24 15:51:14 +02:00
|
|
|
if (!engineNameForService.contains(plasmoidService)) {
|
2011-07-29 15:46:52 +02:00
|
|
|
#ifndef NDEBUG
|
2009-09-03 02:12:57 +02:00
|
|
|
kDebug() << "no engine name for service!";
|
2011-07-29 15:46:52 +02:00
|
|
|
#endif
|
|
|
|
#ifndef NDEBUG
|
2012-09-24 15:51:14 +02:00
|
|
|
kDebug() << "amount of services in map: " << engineNameForService.count();
|
2011-07-29 15:46:52 +02:00
|
|
|
#endif
|
2009-09-03 02:12:57 +02:00
|
|
|
} else {
|
2011-07-29 15:46:52 +02:00
|
|
|
#ifndef NDEBUG
|
2012-09-24 15:51:14 +02:00
|
|
|
kDebug() << "value = " << engineNameForService.value(plasmoidService);
|
2011-07-29 15:46:52 +02:00
|
|
|
#endif
|
2009-09-03 02:12:57 +02:00
|
|
|
}
|
|
|
|
|
2011-07-29 15:46:52 +02:00
|
|
|
#ifndef NDEBUG
|
2009-09-03 02:12:57 +02:00
|
|
|
kDebug() << "requesting dataengine!";
|
2011-07-29 15:46:52 +02:00
|
|
|
#endif
|
2009-09-03 02:12:57 +02:00
|
|
|
KConfigGroup op = plasmoidService->operationDescription("DataEngine");
|
2012-09-24 15:51:14 +02:00
|
|
|
op.writeEntry("EngineName", engineNameForService.value(plasmoidService));
|
2009-09-03 02:12:57 +02:00
|
|
|
plasmoidService->startOperationCall(op);
|
|
|
|
connect(plasmoidService, SIGNAL(finished(Plasma::ServiceJob*)),
|
|
|
|
this, SLOT(slotJobFinished(Plasma::ServiceJob*)));
|
|
|
|
}
|
|
|
|
|
|
|
|
DataEngineConsumer::DataEngineConsumer()
|
2012-09-24 15:51:14 +02:00
|
|
|
: d(new DataEngineConsumerPrivate)
|
2009-09-03 02:12:57 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-09-02 04:27:16 +02:00
|
|
|
DataEngineConsumer::~DataEngineConsumer()
|
|
|
|
{
|
2012-09-24 15:51:14 +02:00
|
|
|
foreach (const QString &engine, d->loadedEngines) {
|
2009-09-02 04:27:16 +02:00
|
|
|
DataEngineManager::self()->unloadEngine(engine);
|
|
|
|
}
|
2009-11-19 20:05:50 +01:00
|
|
|
|
2012-09-24 15:51:14 +02:00
|
|
|
delete d;
|
2009-09-02 04:27:16 +02:00
|
|
|
}
|
|
|
|
|
2013-02-11 21:38:18 +01:00
|
|
|
DataEngine *DataEngineConsumer::dataEngine(const QString &name)
|
2009-09-02 04:27:16 +02:00
|
|
|
{
|
2012-09-24 15:51:14 +02:00
|
|
|
if (d->loadedEngines.contains(name)) {
|
2010-08-04 03:00:26 +02:00
|
|
|
DataEngine *engine = DataEngineManager::self()->engine(name);
|
|
|
|
if (engine->isValid()) {
|
|
|
|
return engine;
|
|
|
|
} else {
|
2012-09-24 15:51:14 +02:00
|
|
|
d->loadedEngines.remove(name);
|
2010-08-04 03:00:26 +02:00
|
|
|
}
|
2009-09-02 04:27:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
DataEngine *engine = DataEngineManager::self()->loadEngine(name);
|
|
|
|
if (engine->isValid()) {
|
2012-09-24 15:51:14 +02:00
|
|
|
d->loadedEngines.insert(name);
|
2009-09-02 04:27:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return engine;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Plasma
|
|
|
|
|
2012-09-24 15:51:14 +02:00
|
|
|
#include "private/moc_dataengineconsumer_p.cpp"
|
2009-09-02 04:27:16 +02:00
|
|
|
|
|
|
|
|