* move DataEngineManager into libplasma and the Plasma namespace

* add CamelCaseIncludes for DataSource and DataEngineManager

svn path=/trunk/KDE/kdebase/workspace/plasma/lib/; revision=667603
This commit is contained in:
Aaron J. Seigo 2007-05-23 07:51:28 +00:00
parent 22015aa3c9
commit 19169e84ea
5 changed files with 166 additions and 0 deletions

View File

@ -6,6 +6,7 @@ set(plasma_LIB_SRCS
abstractrunner.cpp
applet.cpp
dataengine.cpp
dataenginemanager.cpp
datasource.cpp
datavisualization.cpp
plasma.cpp
@ -38,6 +39,7 @@ install( FILES
abstractrunner.h
applet.h
dataengine.h
dataenginemanager.h
datasource.h
datavisualization.h
interface.h
@ -59,6 +61,8 @@ install( FILES
includes/Theme
includes/Interface
includes/DataEngine
includes/DataEngineManager
includes/DataSource
includes/DataVisualization
includes/Svg
DESTINATION ${INCLUDE_INSTALL_DIR}/KDE/Plasma )

111
dataenginemanager.cpp Normal file
View File

@ -0,0 +1,111 @@
/*
* Copyright (C) 2006 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 version 2 as
* published by the Free Software Foundation
*
* 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"
#include <KDebug>
#include <KServiceTypeTrader>
#include <KParts/ComponentFactory>
namespace Plasma
{
DataEngineManager::DataEngineManager()
{
}
DataEngineManager::~DataEngineManager()
{
foreach (Plasma::DataEngine* engine, m_engines) {
delete engine;
}
m_engines.clear();
}
Plasma::DataEngine* DataEngineManager::dataEngine(const QString& name) const
{
Plasma::DataEngine::Dict::const_iterator it = m_engines.find(name);
if (it != m_engines.end()) {
// ref and return the engine
//Plasma::DataEngine *engine = *it;
return *it;
}
return 0;
}
Plasma::DataEngine* DataEngineManager::loadDataEngine(const QString& name)
{
Plasma::DataEngine* engine = dataEngine(name);
if (engine) {
engine->ref();
return engine;
}
// load the engine, add it to the engines
QString constraint = QString("[X-EngineName] == '%1'").arg(name);
KService::List offers = KServiceTypeTrader::self()->query("Plasma/DataEngine",
constraint);
if (offers.isEmpty()) {
kDebug() << "offers are empty for " << name << " with constraint " << constraint << endl;
return 0;
}
int errorCode = 0;
engine = KService::createInstance<Plasma::DataEngine>(offers.first(), 0);
if (!engine) {
kDebug() << errorCode << " couldn't load engine! " << name << endl;
return 0;
}
engine->ref();
engine->setObjectName(offers.first()->name());
engine->setIcon(offers.first()->icon());
m_engines[name] = engine;
return engine;
}
void DataEngineManager::unloadDataEngine(const QString& name)
{
Plasma::DataEngine* engine = dataEngine(name);
if (engine) {
engine->deref();
if (!engine->isUsed()) {
m_engines.remove(name);
delete engine;
}
}
}
QStringList DataEngineManager::knownEngines() const
{
QStringList engines;
KService::List offers = KServiceTypeTrader::self()->query("Plasma/DataEngine");
foreach (KService::Ptr service, offers) {
engines.append(service->property("X-EngineName").toString());
}
return engines;
}
} // namespace Plasma

49
dataenginemanager.h Normal file
View File

@ -0,0 +1,49 @@
/*
* Copyright (C) 2006 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 version 2 as
* published by the Free Software Foundation
*
* 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 PLASMA_ENGINE_MANAGER_H
#define PLASMA_ENGINE_MANAGER_H
#include <QHash>
#include "dataengine.h"
namespace Plasma
{
class PLASMA_EXPORT DataEngineManager
{
public:
typedef QHash<QString, Plasma::DataEngine*> Dict;
public:
DataEngineManager();
~DataEngineManager();
Plasma::DataEngine* dataEngine(const QString& name) const;
Plasma::DataEngine* loadDataEngine(const QString& name);
void unloadDataEngine(const QString& name);
QStringList knownEngines() const;
private:
Plasma::DataEngine::Dict m_engines;
};
} // namespace Plasma
#endif // multiple inclusion guard

View File

@ -0,0 +1 @@
#include "../../plasma/dataenginemanager.h"

1
includes/DataSource Normal file
View File

@ -0,0 +1 @@
#include "../../plasma/datasource.h"