* implement the engine, source and visualization classes
* queue updates so that multiple calls to setData don't result in a storm of updated signals * some API cleanups, e.g. connect -> connectSource * provide and install a ServiceType .desktop; this adds the X-EngineName QString symbol. maybe that's too generic. svn path=/trunk/KDE/kdebase/workspace/plasma/lib/; revision=666241
This commit is contained in:
parent
3ccbf71b2d
commit
4c4b013b89
@ -55,3 +55,5 @@ install( FILES
|
|||||||
includes/Svg
|
includes/Svg
|
||||||
DESTINATION ${INCLUDE_INSTALL_DIR}/KDE/Plasma )
|
DESTINATION ${INCLUDE_INSTALL_DIR}/KDE/Plasma )
|
||||||
|
|
||||||
|
install( FILES plasma_dataengine.desktop DESTINATION ${SERVICETYPES_INSTALL_DIR} )
|
||||||
|
|
||||||
|
175
dataengine.cpp
175
dataengine.cpp
@ -16,25 +16,33 @@
|
|||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <kdebug.h>
|
#include <QTimer>
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
|
|
||||||
#include "dataengine.h"
|
#include <KDebug>
|
||||||
#include "dataengine.moc"
|
|
||||||
|
|
||||||
using namespace Plasma;
|
#include "dataengine.h"
|
||||||
|
#include "datavisualization.h"
|
||||||
|
|
||||||
|
namespace Plasma
|
||||||
|
{
|
||||||
|
|
||||||
class DataSource::Private
|
class DataSource::Private
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Private() {}
|
Private()
|
||||||
~Private() {}
|
: dirty(false)
|
||||||
|
{}
|
||||||
|
|
||||||
|
QString name;
|
||||||
|
Data data;
|
||||||
|
bool dirty;
|
||||||
};
|
};
|
||||||
|
|
||||||
DataSource::DataSource(QObject* parent)
|
DataSource::DataSource(QObject* parent)
|
||||||
: QObject(parent)
|
: QObject(parent),
|
||||||
|
d(new Private())
|
||||||
{
|
{
|
||||||
d = new Private();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DataSource::~DataSource()
|
DataSource::~DataSource()
|
||||||
@ -44,98 +52,189 @@ DataSource::~DataSource()
|
|||||||
|
|
||||||
QString DataSource::name()
|
QString DataSource::name()
|
||||||
{
|
{
|
||||||
kDebug() << k_funcinfo << " not implemented";
|
return objectName();
|
||||||
return QString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DataSource::setName(const QString& name)
|
||||||
|
{
|
||||||
|
setObjectName(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
const Plasma::DataSource::Data DataSource::data() const
|
||||||
|
{
|
||||||
|
return d->data;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DataSource::setData(const QString& key, const QVariant& value)
|
||||||
|
{
|
||||||
|
d->data[key] = value;
|
||||||
|
d->dirty = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DataSource::checkForUpdate()
|
||||||
|
{
|
||||||
|
if (d->dirty) {
|
||||||
|
emit updated(d->data);
|
||||||
|
d->dirty = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class DataEngine::Private
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Private(DataEngine* e)
|
||||||
|
: engine(e)
|
||||||
|
{
|
||||||
|
updateTimer = new QTimer(engine);
|
||||||
|
updateTimer->setSingleShot(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
DataSource* source(const QString& sourceName)
|
||||||
|
{
|
||||||
|
DataSource::Dict::const_iterator it = sources.find(sourceName);
|
||||||
|
if (it != sources.constEnd()) {
|
||||||
|
return it.value();
|
||||||
|
}
|
||||||
|
|
||||||
|
kDebug() << "DataEngine " << engine->objectName()
|
||||||
|
<< ": could not find DataSource " << sourceName
|
||||||
|
<< ", creating" << endl;
|
||||||
|
DataSource* s = new DataSource(engine);
|
||||||
|
s->setName(sourceName);
|
||||||
|
sources.insert(sourceName, s);
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
void queueUpdate()
|
||||||
|
{
|
||||||
|
if (updateTimer->isActive()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
updateTimer->start(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
QAtomic ref;
|
||||||
|
DataSource::Dict sources;
|
||||||
|
DataEngine* engine;
|
||||||
|
QTimer* updateTimer;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
DataEngine::DataEngine(QObject* parent)
|
DataEngine::DataEngine(QObject* parent)
|
||||||
: QObject(parent)
|
: QObject(parent),
|
||||||
|
d(new Private(this))
|
||||||
{
|
{
|
||||||
|
connect(d->updateTimer, SIGNAL(timeout()), this, SLOT(checkForUpdates()));
|
||||||
|
//FIXME: should we try and delay this call?
|
||||||
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
DataEngine::~DataEngine()
|
DataEngine::~DataEngine()
|
||||||
{
|
{
|
||||||
|
delete d;
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList DataEngine::dataSources()
|
QStringList DataEngine::dataSources()
|
||||||
{
|
{
|
||||||
kDebug() << k_funcinfo << " not implemented";
|
return d->sources.keys();
|
||||||
return QStringList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DataEngine::connect(const QString& source, DataVisualization* visualization)
|
void DataEngine::connectSource(const QString& source, DataVisualization* visualization)
|
||||||
{
|
{
|
||||||
Q_UNUSED(source)
|
Q_UNUSED(source)
|
||||||
Q_UNUSED(visualization)
|
Q_UNUSED(visualization)
|
||||||
|
|
||||||
kDebug() << k_funcinfo << " not implemented";
|
DataSource* s = d->source(source);
|
||||||
|
// if (!s) {
|
||||||
|
// kDebug() << "DataEngine " << objectName() << ": could not find DataSource " << source << endl;
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
|
connect(s, SIGNAL(updated(Plasma::DataSource::Data)),
|
||||||
|
visualization, SLOT(updated(Plasma::DataSource::Data)));
|
||||||
}
|
}
|
||||||
|
|
||||||
DataSource::Data DataEngine::query(const QString& source)
|
DataSource::Data DataEngine::query(const QString& source)
|
||||||
{
|
{
|
||||||
Q_UNUSED(source)
|
Q_UNUSED(source)
|
||||||
|
|
||||||
kDebug() << k_funcinfo << " not implemented";
|
DataSource* s = d->source(source);
|
||||||
return DataSource::Data();
|
return s->data();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DataEngine::init()
|
void DataEngine::init()
|
||||||
{
|
{
|
||||||
kDebug() << k_funcinfo << " not implemented";
|
// default implementation does nothing. this is for engines that have to
|
||||||
|
// start things in motion external to themselves before they can work
|
||||||
}
|
}
|
||||||
|
|
||||||
void DataEngine::cleanup()
|
void DataEngine::setData(const QString& source, const QVariant& value)
|
||||||
{
|
{
|
||||||
kDebug() << k_funcinfo << " not implemented";
|
setData(source, source, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DataEngine::setDataSource(const QString& source, const QVariant& value)
|
void DataEngine::setData(const QString& source, const QString& key, const QVariant& value)
|
||||||
{
|
{
|
||||||
Q_UNUSED(source)
|
DataSource* s = d->source(source);
|
||||||
Q_UNUSED(value)
|
s->setData(key, value);
|
||||||
|
d->queueUpdate();
|
||||||
kDebug() << k_funcinfo << " not implemented";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DataEngine::createDataSource(const QString& source, const QString& domain)
|
/*
|
||||||
|
Plasma::DataSource* DataEngine::createDataSource(const QString& source, const QString& domain)
|
||||||
{
|
{
|
||||||
Q_UNUSED(source)
|
|
||||||
Q_UNUSED(domain)
|
Q_UNUSED(domain)
|
||||||
|
//TODO: add support for domains of sources
|
||||||
kDebug() << k_funcinfo << " not implemented";
|
|
||||||
}
|
if (d->source(source)) {
|
||||||
|
kDebug() << "DataEngine " << objectName() << ": source " << source << " already exists " << endl;
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
|
||||||
void DataEngine::removeDataSource(const QString& source)
|
void DataEngine::removeDataSource(const QString& source)
|
||||||
{
|
{
|
||||||
Q_UNUSED(source)
|
DataSource::Dict::iterator it = d->sources.find(source);
|
||||||
|
if (it != d->sources.end()) {
|
||||||
kDebug() << k_funcinfo << " not implemented";
|
d->sources.erase(it);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DataEngine::clearAllDataSources()
|
void DataEngine::clearAllDataSources()
|
||||||
{
|
{
|
||||||
kDebug() << k_funcinfo << " not implemented";
|
QMutableHashIterator<QString, Plasma::DataSource*> it(d->sources);
|
||||||
|
while (it.hasNext()) {
|
||||||
|
it.next();
|
||||||
|
delete it.value();
|
||||||
|
it.remove();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DataEngine::ref()
|
void DataEngine::ref()
|
||||||
{
|
{
|
||||||
kDebug() << k_funcinfo << " not implemented";
|
d->ref.ref();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DataEngine::deref()
|
void DataEngine::deref()
|
||||||
{
|
{
|
||||||
kDebug() << k_funcinfo << " not implemented";
|
d->ref.deref();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DataEngine::isUsed()
|
bool DataEngine::isUsed()
|
||||||
{
|
{
|
||||||
kDebug() << k_funcinfo << " not implemented";
|
return d->ref != 0;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DataEngine::checkForUpdates()
|
||||||
|
{
|
||||||
|
QHashIterator<QString, Plasma::DataSource*> it(d->sources);
|
||||||
|
while (it.hasNext()) {
|
||||||
|
it.next();
|
||||||
|
it.value()->checkForUpdate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#include "dataengine.moc"
|
||||||
|
|
||||||
|
31
dataengine.h
31
dataengine.h
@ -45,13 +45,18 @@ class KDE_EXPORT DataSource : public QObject
|
|||||||
virtual ~DataSource();
|
virtual ~DataSource();
|
||||||
|
|
||||||
QString name();
|
QString name();
|
||||||
|
void setName(const QString&);
|
||||||
|
const Data data() const;
|
||||||
|
void setData(const QString& key, const QVariant& value);
|
||||||
|
|
||||||
|
void checkForUpdate();
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void data(const DataSource::Data&);
|
void updated(const Plasma::DataSource::Data&);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
class Private;
|
class Private;
|
||||||
Private* d;
|
Private* const d;
|
||||||
};
|
};
|
||||||
|
|
||||||
class KDE_EXPORT DataEngine : public QObject
|
class KDE_EXPORT DataEngine : public QObject
|
||||||
@ -65,7 +70,7 @@ class KDE_EXPORT DataEngine : public QObject
|
|||||||
virtual ~DataEngine();
|
virtual ~DataEngine();
|
||||||
|
|
||||||
virtual QStringList dataSources();
|
virtual QStringList dataSources();
|
||||||
void connect(const QString& source, DataVisualization* visualization);
|
void connectSource(const QString& source, DataVisualization* visualization);
|
||||||
DataSource::Data query(const QString& source);
|
DataSource::Data query(const QString& source);
|
||||||
|
|
||||||
void ref();
|
void ref();
|
||||||
@ -74,25 +79,27 @@ class KDE_EXPORT DataEngine : public QObject
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void init();
|
virtual void init();
|
||||||
virtual void cleanup();
|
void setData(const QString& source, const QVariant& value);
|
||||||
void setDataSource(const QString& source, const QVariant& value);
|
void setData(const QString& source, const QString& key, const QVariant& value);
|
||||||
void createDataSource(const QString& source,
|
/* void createDataSource(const QString& source,
|
||||||
const QString& domain = QString());
|
const QString& domain = QString());*/
|
||||||
void removeDataSource(const QString& source);
|
void removeDataSource(const QString& source);
|
||||||
void clearAllDataSources();
|
void clearAllDataSources();
|
||||||
|
|
||||||
|
protected slots:
|
||||||
|
void checkForUpdates();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QAtomic m_ref;
|
|
||||||
class Private;
|
class Private;
|
||||||
Private* d;
|
Private* const d;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // Plasma namespace
|
} // Plasma namespace
|
||||||
|
|
||||||
#define K_EXPORT_PLASMA_ENGINE(libname, classname) \
|
#define K_EXPORT_PLASMA_DATAENGINE(libname, classname) \
|
||||||
K_EXPORT_COMPONENT_FACTORY( \
|
K_EXPORT_COMPONENT_FACTORY( \
|
||||||
plasmaengine_##libname, \
|
plasma_##libname##_engine, \
|
||||||
KGenericFactory<classname>("libplasmaengine_" #libname))
|
KGenericFactory<classname>("plasma_" #libname "_engine"))
|
||||||
|
|
||||||
#endif // multiple inclusion guard
|
#endif // multiple inclusion guard
|
||||||
|
|
||||||
|
@ -29,13 +29,13 @@ namespace Plasma
|
|||||||
// this will end up being multiple-inherited?
|
// this will end up being multiple-inherited?
|
||||||
class KDE_EXPORT DataVisualization : public QObject
|
class KDE_EXPORT DataVisualization : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
DataVisualization(QObject* parent = 0);
|
DataVisualization(QObject* parent = 0);
|
||||||
virtual ~DataVisualization();
|
virtual ~DataVisualization();
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
virtual void data(const DataSource::Data&) = 0;
|
virtual void updated(const Plasma::DataSource::Data&) = 0;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
class Private;
|
class Private;
|
||||||
|
10
plasma_dataengine.desktop
Normal file
10
plasma_dataengine.desktop
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
[Desktop Entry]
|
||||||
|
Encoding=UTF-8
|
||||||
|
Type=ServiceType
|
||||||
|
X-KDE-ServiceType=Plasma/DataEngine
|
||||||
|
|
||||||
|
Comment=Plasma Data Engine
|
||||||
|
|
||||||
|
[PropertyDef::X-EngineName]
|
||||||
|
Type=QString
|
||||||
|
|
Loading…
Reference in New Issue
Block a user