Plasma

datasource.h
1 /*
2  SPDX-FileCopyrightText: 2009 Alan Alpert <[email protected]>
3  SPDX-FileCopyrightText: 2010 Ménard Alexis <[email protected]>
4  SPDX-FileCopyrightText: 2010 Marco MArtin <[email protected]>
5  SPDX-FileCopyrightText: 2013 Sebastian Kügler <[email protected]>
6 
7  SPDX-License-Identifier: LGPL-2.0-or-later
8 */
9 
10 #ifndef DATASOURCE_H
11 #define DATASOURCE_H
12 
13 #include <QObject>
14 #include <QQmlParserStatus>
15 #include <QQmlPropertyMap>
16 #include <QScopedPointer>
17 #include <QtQml>
18 
19 #include <Plasma/DataEngine>
20 #include <Plasma/DataEngineConsumer>
21 
22 class QQmlPropertyMap;
23 
24 // This class will hopefully be removed in KF6 (along with DataEngines in general)
25 
26 namespace Plasma
27 {
28 class DataEngine;
29 
30 /**
31  * @class DataSource
32  * @short Provides data from a range of plugins
33  */
35 {
36  Q_OBJECT
38 
39 public:
40  enum Change {
41  NoChange = 0,
42  DataEngineChanged = 1,
43  SourcesChanged = 2,
44  };
45  Q_DECLARE_FLAGS(Changes, Change)
46 
48 
49  explicit DataSource(QObject *parent = nullptr);
50 
51  void classBegin() override;
52  void componentComplete() override;
53 
54  /**
55  * true if the connection to the Plasma DataEngine is valid
56  */
57  Q_PROPERTY(bool valid READ valid)
58  bool valid() const
59  {
60  return m_dataEngine && m_dataEngine->isValid();
61  }
62 
63  /**
64  * Polling interval in milliseconds when the data will be fetched again. If 0 no polling will be done.
65  */
66  Q_PROPERTY(int interval READ interval WRITE setInterval NOTIFY intervalChanged)
67  int interval() const
68  {
69  return m_interval;
70  }
71  void setInterval(const int interval);
72 
73  /**
74  * The interval to align polling to
75  */
76  Q_PROPERTY(Plasma::Types::IntervalAlignment intervalAlignment READ intervalAlignment WRITE setIntervalAlignment NOTIFY intervalAlignmentChanged)
78  {
79  return m_intervalAlignment;
80  }
81  void setIntervalAlignment(Plasma::Types::IntervalAlignment intervalAlignment);
82 
83  /**
84  * Plugin name of the Plasma DataEngine
85  */
86  Q_PROPERTY(QString dataEngine READ engine WRITE setEngine NOTIFY engineChanged)
87  Q_PROPERTY(QString engine READ engine WRITE setEngine NOTIFY engineChanged)
88  QString engine() const
89  {
90  return m_engine;
91  }
92  void setEngine(const QString &e);
93 
94  /**
95  * String array of all the source names connected to the DataEngine
96  */
97  Q_PROPERTY(QStringList connectedSources READ connectedSources WRITE setConnectedSources NOTIFY connectedSourcesChanged)
99  {
100  return m_connectedSources;
101  }
102  void setConnectedSources(const QStringList &s);
103 
104  /**
105  * Read only string array of all the sources available from the DataEngine (connected or not)
106  */
107  Q_PROPERTY(QStringList sources READ sources NOTIFY sourcesChanged)
108  QStringList sources() const
109  {
110  return m_sources;
111  }
112 
113  /**
114  * All the data fetched by this dataengine.
115  * This is a map of maps. At the first level, there are the source names, at the second, they keys set by the DataEngine
116  */
117  Q_PROPERTY(QQmlPropertyMap *data READ data CONSTANT)
118  QQmlPropertyMap *data() const
119  {
120  return m_data;
121  }
122 
123  /**
124  * All the models associated to this DataEngine, indexed by source.
125  * In order for a model to be present, besides being implemented in the DataEngine,
126  * The user has to be connected to its source, so the source name has to be present in the connectedSources property.
127  */
128  Q_PROPERTY(QQmlPropertyMap *models READ models CONSTANT)
129  QQmlPropertyMap *models() const
130  {
131  return m_models;
132  }
133 
134  /**
135  * @returns a Plasma::Service given a source name
136  * @param source source name we want a service of
137  */
139 
140  /**
141  * Connect a new source. It adds it to connectedSources
142  */
143  Q_INVOKABLE void connectSource(const QString &source);
144 
145  /**
146  * Disconnects from a DataEngine Source. It also removes it from connectedSources
147  */
148  Q_INVOKABLE void disconnectSource(const QString &source);
149 
150 public Q_SLOTS:
151  void dataUpdated(const QString &sourceName, const Plasma::DataEngine::Data &data);
152  void modelChanged(const QString &sourceName, QAbstractItemModel *model);
153 
154 protected Q_SLOTS:
155  void removeSource(const QString &source);
156  void setupData();
157  void updateSources();
158 
159 Q_SIGNALS:
160  void newData(const QString &sourceName, const QVariantMap &data);
161  void sourceAdded(const QString &source);
162  void sourceRemoved(const QString &source);
163  void sourceConnected(const QString &source);
164  void sourceDisconnected(const QString &source);
165  void intervalChanged();
166  void intervalAlignmentChanged();
167  void engineChanged();
168  void dataChanged();
169  void connectedSourcesChanged();
170  void sourcesChanged();
171 
172 private:
173  bool m_ready;
174  QString m_id;
175  int m_interval;
176  Plasma::Types::IntervalAlignment m_intervalAlignment;
177  QString m_engine;
178  QQmlPropertyMap *m_data = nullptr;
179  QQmlPropertyMap *m_models = nullptr;
180  Plasma::DataEngine *m_dataEngine = nullptr;
181  QScopedPointer<Plasma::DataEngineConsumer> m_dataEngineConsumer;
182  QStringList m_sources;
183  QStringList m_connectedSources;
184  QStringList m_oldSources;
185  QStringList m_newSources;
186  Changes m_changes;
188 };
189 Q_DECLARE_OPERATORS_FOR_FLAGS(DataSource::Changes)
190 }
191 #endif
QQmlPropertyMap models
All the models associated to this DataEngine, indexed by source.
Definition: datasource.h:128
QStringList sources
Read only string array of all the sources available from the DataEngine (connected or not) ...
Definition: datasource.h:107
Plasma::Types::IntervalAlignment intervalAlignment
The interval to align polling to.
Definition: datasource.h:76
Q_SIGNALSQ_SIGNALS
Namespace for everything in libplasma.
Definition: datamodel.cpp:14
bool valid
true if the connection to the Plasma DataEngine is valid
Definition: datasource.h:57
Q_INVOKABLE void connectSource(const QString &source)
Connect a new source.
Definition: datasource.cpp:216
QStringList connectedSources
String array of all the source names connected to the DataEngine.
Definition: datasource.h:97
Q_OBJECTQ_OBJECT
Data provider for plasmoids (Plasma plugins)
Definition: dataengine.h:46
bool isValid() const
Returns true if this engine is valid, otherwise returns false.
Definition: dataengine.cpp:311
Q_PROPERTY(...)
QString dataEngine
Plugin name of the Plasma DataEngine.
Definition: datasource.h:86
IntervalAlignment
Possible timing alignments.
Definition: plasma.h:223
Q_INVOKABLEQ_INVOKABLE
Q_INTERFACES(...)
Q_INVOKABLE QObject * serviceForSource(const QString &source)
Definition: datasource.cpp:203
A class that makes it safe and easy to use DataEngines.
QQmlPropertyMap data
All the data fetched by this dataengine.
Definition: datasource.h:117
Provides data from a range of plugins.
Definition: datasource.h:34
Q_SLOTSQ_SLOTS
Q_INVOKABLE void disconnectSource(const QString &source)
Disconnects from a DataEngine Source.
Definition: datasource.cpp:230
QObject * parent() const const
int interval
Polling interval in milliseconds when the data will be fetched again.
Definition: datasource.h:66
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue May 11 2021 22:41:04 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.