2010-10-12 21:51:57 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2009 by Alan Alpert <alan.alpert@nokia.com>
|
|
|
|
* Copyright 2010 by Ménard Alexis <menard@kde.org>
|
|
|
|
* Copyright 2010 by Marco MArtin <mart@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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef DATASOURCE_H
|
|
|
|
#define DATASOURCE_H
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
|
|
|
|
|
|
|
|
#include <QDeclarativePropertyMap>
|
|
|
|
|
|
|
|
#include "dataengineconsumer_p.h"
|
|
|
|
#include <Plasma/DataEngine>
|
|
|
|
#include <qdeclarative.h>
|
|
|
|
|
|
|
|
|
|
|
|
class QDeclarativePropertyMap;
|
|
|
|
|
2010-10-26 14:01:59 +02:00
|
|
|
|
2010-10-12 21:51:57 +02:00
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
class DataEngine;
|
2010-10-26 14:01:59 +02:00
|
|
|
class DataModel;
|
2010-10-12 21:51:57 +02:00
|
|
|
|
|
|
|
class DataSource : public QObject, DataEngineConsumer
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
typedef QHash<QString, QVariant> Data;
|
|
|
|
DataSource(QObject* parent=0);
|
|
|
|
|
2010-10-16 15:53:51 +02:00
|
|
|
Q_PROPERTY(bool valid READ valid)
|
2010-10-12 21:51:57 +02:00
|
|
|
bool valid() const {return m_dataEngine != 0;}
|
|
|
|
|
2010-10-16 15:53:51 +02:00
|
|
|
Q_PROPERTY(int interval READ interval WRITE setInterval NOTIFY intervalChanged)
|
2010-10-12 21:51:57 +02:00
|
|
|
int interval() const {return m_interval;}
|
|
|
|
void setInterval(int i) {if(i==m_interval) return; m_interval=i; emit intervalChanged();}
|
|
|
|
|
2010-10-16 15:53:51 +02:00
|
|
|
Q_PROPERTY(QString engine READ engine WRITE setEngine NOTIFY engineChanged)
|
2010-10-12 21:51:57 +02:00
|
|
|
QString engine() const {return m_engine;}
|
|
|
|
void setEngine(const QString &e) {if(e==m_engine) return; m_engine=e; emit engineChanged();}
|
|
|
|
|
2010-10-16 15:53:51 +02:00
|
|
|
Q_PROPERTY(QString source READ source WRITE setSource NOTIFY sourceChanged)
|
2010-10-12 21:51:57 +02:00
|
|
|
QString source() const {return m_source;}
|
|
|
|
void setSource(const QString &s);
|
|
|
|
|
2010-10-16 15:53:51 +02:00
|
|
|
Q_PROPERTY(QStringList keys READ keys NOTIFY keysChanged)
|
2010-10-12 21:51:57 +02:00
|
|
|
QStringList keys() const {return m_keys;}
|
|
|
|
|
2010-10-16 15:53:51 +02:00
|
|
|
Q_PROPERTY(QStringList allSources READ allSources NOTIFY sourcesChanged)
|
2010-10-12 21:51:57 +02:00
|
|
|
QStringList allSources() const {if (m_dataEngine) return m_dataEngine->sources(); else return QStringList();}
|
|
|
|
|
|
|
|
Q_PROPERTY(QObject *data READ data NOTIFY dataChanged);
|
|
|
|
QObject *data() const {return m_data;}
|
|
|
|
|
2010-10-16 15:53:51 +02:00
|
|
|
Q_PROPERTY(Plasma::Service *service READ service CONSTANT)
|
2010-10-12 21:51:57 +02:00
|
|
|
Plasma::Service *service();
|
|
|
|
|
|
|
|
public Q_SLOTS:
|
|
|
|
void dataUpdated(const QString &sourceName, const Plasma::DataEngine::Data &data);
|
|
|
|
void setupData();
|
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
void intervalChanged();
|
|
|
|
void engineChanged();
|
|
|
|
void sourceChanged();
|
|
|
|
void keysChanged();
|
|
|
|
void dataChanged();
|
|
|
|
void sourcesChanged();
|
|
|
|
|
2010-10-26 14:01:59 +02:00
|
|
|
protected:
|
|
|
|
inline DataModel *modelFromKey(const QString &key);
|
2010-10-12 21:51:57 +02:00
|
|
|
|
2010-10-26 14:01:59 +02:00
|
|
|
private:
|
2010-10-12 21:51:57 +02:00
|
|
|
QString m_id;
|
|
|
|
int m_interval;
|
|
|
|
QString m_source;
|
|
|
|
QString m_engine;
|
|
|
|
QStringList m_keys;
|
|
|
|
QDeclarativePropertyMap *m_data;
|
|
|
|
Plasma::DataEngine* m_dataEngine;
|
|
|
|
Plasma::Service *m_service;
|
|
|
|
QString m_connectedSource;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
#endif
|