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>
|
|
|
|
|
|
|
|
|
2013-02-01 17:26:26 +01:00
|
|
|
#include <QQmlPropertyMap>
|
2010-10-12 21:51:57 +02:00
|
|
|
|
|
|
|
#include "dataengineconsumer_p.h"
|
|
|
|
#include <Plasma/DataEngine>
|
|
|
|
#include <qdeclarative.h>
|
|
|
|
|
|
|
|
|
2013-02-01 17:26:26 +01:00
|
|
|
class QQmlPropertyMap;
|
2010-10-12 21:51:57 +02:00
|
|
|
|
2010-10-26 14:01:59 +02:00
|
|
|
|
2010-10-12 21:51:57 +02:00
|
|
|
namespace Plasma
|
|
|
|
{
|
2010-11-08 11:27:36 +01:00
|
|
|
class DataEngine;
|
|
|
|
|
|
|
|
class DataSource : public QObject, DataEngineConsumer
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
enum Change {
|
|
|
|
NoChange = 0,
|
|
|
|
DataEngineChanged = 1,
|
|
|
|
SourcesChanged = 2
|
|
|
|
};
|
|
|
|
Q_DECLARE_FLAGS(Changes, Change)
|
2010-11-08 21:50:09 +01:00
|
|
|
|
2010-11-08 11:27:36 +01:00
|
|
|
typedef QHash<QString, QVariant> Data;
|
2010-11-08 21:50:09 +01:00
|
|
|
|
2010-11-08 11:27:36 +01:00
|
|
|
DataSource(QObject* parent=0);
|
|
|
|
|
2011-12-23 13:28:02 +01:00
|
|
|
/**
|
|
|
|
* true if the connection to the Plasma DataEngine is valid
|
|
|
|
*/
|
2010-11-08 11:27:36 +01:00
|
|
|
Q_PROPERTY(bool valid READ valid)
|
2011-07-15 13:18:21 +02:00
|
|
|
bool valid() const {return m_dataEngine && m_dataEngine->isValid();}
|
2010-11-08 11:27:36 +01:00
|
|
|
|
2011-12-23 13:28:02 +01:00
|
|
|
/**
|
|
|
|
* Polling interval in milliseconds when the data will be fetched again. If 0 no polling will be done.
|
|
|
|
*/
|
2010-11-08 11:27:36 +01:00
|
|
|
Q_PROPERTY(int interval READ interval WRITE setInterval NOTIFY intervalChanged)
|
|
|
|
int interval() const {return m_interval;}
|
2010-11-08 21:50:09 +01:00
|
|
|
void setInterval(const int interval);
|
2010-11-08 11:27:36 +01:00
|
|
|
|
2011-12-23 13:28:02 +01:00
|
|
|
/**
|
|
|
|
* Plugin name of the Plasma DataEngine
|
|
|
|
*/
|
2011-06-14 10:35:01 +02:00
|
|
|
Q_PROPERTY(QString dataEngine READ engine WRITE setEngine NOTIFY engineChanged)
|
2010-11-08 11:27:36 +01:00
|
|
|
Q_PROPERTY(QString engine READ engine WRITE setEngine NOTIFY engineChanged)
|
|
|
|
QString engine() const {return m_engine;}
|
|
|
|
void setEngine(const QString &e);
|
|
|
|
|
2011-12-23 13:28:02 +01:00
|
|
|
/**
|
|
|
|
* String array of all the source names connected to the DataEngine
|
|
|
|
*/
|
2010-11-08 11:27:36 +01:00
|
|
|
Q_PROPERTY(QStringList connectedSources READ connectedSources WRITE setConnectedSources NOTIFY connectedSourcesChanged)
|
|
|
|
QStringList connectedSources() const {return m_connectedSources;}
|
|
|
|
void setConnectedSources(const QStringList &s);
|
|
|
|
|
2011-12-23 13:28:02 +01:00
|
|
|
/**
|
|
|
|
* Read only string array of all the sources available from the DataEngine (connected or not)
|
|
|
|
*/
|
2010-11-08 11:27:36 +01:00
|
|
|
Q_PROPERTY(QStringList sources READ sources NOTIFY sourcesChanged)
|
|
|
|
QStringList sources() const {if (m_dataEngine) return m_dataEngine->sources(); else return QStringList();}
|
|
|
|
|
2011-12-23 13:28:02 +01:00
|
|
|
/**
|
|
|
|
* All the data fetched by this dataengine.
|
|
|
|
* This is an hash of hashes. At the first level, there are the source names, at the secons, they keys set by the DataEngine
|
|
|
|
*/
|
2011-09-22 22:43:32 +02:00
|
|
|
Q_PROPERTY(QVariantHash data READ data NOTIFY dataChanged);
|
|
|
|
QVariantHash data() const {return m_data;}
|
2010-11-08 11:27:36 +01:00
|
|
|
|
2011-12-23 13:28:02 +01:00
|
|
|
/**
|
|
|
|
* @returns a Plasma::Service given a source name
|
|
|
|
* @arg QString source source name we want a service of
|
|
|
|
*/
|
2010-11-08 11:27:36 +01:00
|
|
|
Q_INVOKABLE Plasma::Service *serviceForSource(const QString &source);
|
|
|
|
|
2011-12-23 13:28:02 +01:00
|
|
|
/**
|
|
|
|
* Connect a new source. It adds it to connectedSources
|
|
|
|
*/
|
2010-11-08 11:27:36 +01:00
|
|
|
Q_INVOKABLE void connectSource(const QString &source);
|
2011-12-23 13:28:02 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Disconnects from a DataEngine Source. It also removes it from connectedSources
|
|
|
|
*/
|
2010-11-08 11:27:36 +01:00
|
|
|
Q_INVOKABLE void disconnectSource(const QString &source);
|
|
|
|
|
|
|
|
protected Q_SLOTS:
|
|
|
|
void dataUpdated(const QString &sourceName, const Plasma::DataEngine::Data &data);
|
2010-11-09 00:07:25 +01:00
|
|
|
void removeSource(const QString &source);
|
2010-11-08 11:27:36 +01:00
|
|
|
void setupData();
|
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
void newData(const QString &sourceName, const Plasma::DataEngine::Data &data);
|
|
|
|
void sourceAdded(const QString &source);
|
2010-11-09 00:07:25 +01:00
|
|
|
void sourceRemoved(const QString &source);
|
|
|
|
void sourceConnected(const QString &source);
|
|
|
|
void sourceDisconnected(const QString &source);
|
2010-11-08 11:27:36 +01:00
|
|
|
void intervalChanged();
|
|
|
|
void engineChanged();
|
|
|
|
void dataChanged();
|
|
|
|
void connectedSourcesChanged();
|
|
|
|
void sourcesChanged();
|
|
|
|
|
|
|
|
private:
|
|
|
|
QString m_id;
|
|
|
|
int m_interval;
|
|
|
|
QString m_engine;
|
2011-09-22 22:43:32 +02:00
|
|
|
QVariantHash m_data;
|
2010-11-08 11:27:36 +01:00
|
|
|
Plasma::DataEngine* m_dataEngine;
|
|
|
|
QStringList m_connectedSources;
|
|
|
|
QStringList m_oldSources;
|
|
|
|
QStringList m_newSources;
|
|
|
|
Changes m_changes;
|
2011-04-12 22:12:17 +02:00
|
|
|
QHash<QString, Plasma::Service *> m_services;
|
2010-11-08 11:27:36 +01:00
|
|
|
};
|
|
|
|
Q_DECLARE_OPERATORS_FOR_FLAGS(DataSource::Changes)
|
2010-10-12 21:51:57 +02:00
|
|
|
}
|
|
|
|
#endif
|