Plasma

dataengine.h
1 /*
2  * Copyright 2006-2007 Aaron Seigo <[email protected]>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Library General Public License as
6  * published by the Free Software Foundation; either version 2, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this program; if not, write to the
16  * Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  */
19 
20 #ifndef PLASMA_DATAENGINE_H
21 #define PLASMA_DATAENGINE_H
22 
23 #include <QHash>
24 #include <QObject>
25 #include <QStringList>
26 
27 #include <kplugininfo.h>
28 #include <kservice.h>
29 
30 #include <plasma/version.h>
31 #include <plasma/plasma.h>
32 #include <plasma/service.h>
33 
34 class QAbstractItemModel;
35 
36 namespace Plasma
37 {
38 
39 class DataContainer;
40 class DataEngineScript;
41 class Package;
42 class Service;
43 class DataEnginePrivate;
44 
60 class PLASMA_EXPORT DataEngine : public QObject
61 {
62  Q_OBJECT
63 
64 public:
69 
70 #if PLASMA_ENABLE_DEPRECATED_SINCE(5, 67)
71 
79  PLASMA_DEPRECATED_VERSION(5, 67, "Use KPluginMetaData")
80  explicit DataEngine(const KPluginInfo &plugin, QObject *parent = nullptr);
81 #endif
82 
91  explicit DataEngine(const KPluginMetaData &plugin, QObject *parent = nullptr);
92 
93  explicit DataEngine(QObject *parent = nullptr, const QVariantList &args = QVariantList());
94 
95  ~DataEngine() override;
96 
103  virtual QStringList sources() const;
104 
111  Q_INVOKABLE virtual Service *serviceForSource(const QString &source);
112 
113 #if PLASMA_ENABLE_DEPRECATED_SINCE(5, 67)
114 
119  PLASMA_DEPRECATED_VERSION(5, 67, "Use metadata()")
120  KPluginInfo pluginInfo() const;
121 #endif
122 
128  KPluginMetaData metadata() const;
129 
152  Q_INVOKABLE void connectSource(
153  const QString &source, QObject *visualization,
154  uint pollingInterval = 0,
155  Plasma::Types::IntervalAlignment intervalAlignment = Types::NoAlignment) const;
156 
185  Q_INVOKABLE void connectAllSources(QObject *visualization, uint pollingInterval = 0,
186  Plasma::Types::IntervalAlignment intervalAlignment =
187  Types::NoAlignment) const;
188 
195  Q_INVOKABLE void disconnectSource(const QString &source, QObject *visualization) const;
196 
207  Q_INVOKABLE DataContainer *containerForSource(const QString &source);
208 
213  QAbstractItemModel *modelForSource(const QString &source);
214 
220  bool isValid() const;
221 
228  bool isEmpty() const;
229 
234  QString icon() const;
235 
241  Package package() const;
242 
243 Q_SIGNALS:
254  void sourceAdded(const QString &source);
255 
266  void sourceRemoved(const QString &source);
267 
268 protected:
289  virtual bool sourceRequestEvent(const QString &source);
290 
301  virtual bool updateSourceEvent(const QString &source);
302 
310  void setData(const QString &source, const QVariant &value);
311 
320  void setData(const QString &source, const QString &key, const QVariant &value);
321 
329  void setData(const QString &source, const QVariantMap &data);
330 
336  void removeAllData(const QString &source);
337 
344  void removeData(const QString &source, const QString &key);
345 
359  void setModel(const QString &source, QAbstractItemModel *model);
360 
368  void addSource(DataContainer *source);
369 
383  void setMinimumPollingInterval(int minimumMs);
384 
388  int minimumPollingInterval() const;
389 
398  void setPollingInterval(uint frequency);
399 
403  void removeAllSources();
404 
412  void setValid(bool valid);
413 
417  QHash<QString, DataContainer *> containerDict() const;
418 
422  void timerEvent(QTimerEvent *event) override;
423 
427  void setIcon(const QString &icon);
428 
437  void setStorageEnabled(const QString &source, bool store);
438 
439 protected Q_SLOTS:
444  void removeSource(const QString &source);
445 
449  void updateAllSources();
450 
461  void forceImmediateUpdateOfAllVisualizations();
462 
463 private:
464  friend class DataEnginePrivate;
465  friend class DataEngineScript;
466  friend class DataEngineManager;
467  friend class PlasmoidServiceJob;
468  friend class NullEngine;
469 
470  Q_PRIVATE_SLOT(d, void internalUpdateSource(DataContainer *source))
471  Q_PRIVATE_SLOT(d, void sourceDestroyed(QObject *object))
472  Q_PRIVATE_SLOT(d, void scheduleSourcesUpdated())
473 
474  DataEnginePrivate *const d;
475 };
476 
477 } // Plasma namespace
478 
482 #define K_EXPORT_PLASMA_DATAENGINE(libname, classname) \
483  K_PLUGIN_FACTORY(factory, registerPlugin<classname>();) \
484  K_EXPORT_PLUGIN_VERSION(PLASMA_VERSION)
485 
486 #define K_EXPORT_PLASMA_DATAENGINE_WITH_JSON(libname, classname, jsonFile) \
487  K_PLUGIN_FACTORY_WITH_JSON(factory, jsonFile, registerPlugin<classname>();) \
488  K_EXPORT_PLUGIN_VERSION(PLASMA_VERSION)
489 
490 Q_DECLARE_METATYPE(Plasma::DataEngine *)
491 
492 #endif // multiple inclusion guard
Namespace for everything in libplasma.
Definition: datamodel.cpp:27
This class provides a generic API for write access to settings or services.
Definition: service.h:91
Data provider for plasmoids (Plasma plugins)
Definition: dataengine.h:60
Provides a restricted interface for scripting a DataEngine.
object representing an installed Plasma package
Definition: package.h:87
<Plasma/Version>
IntervalAlignment
Possible timing alignments.
Definition: plasma.h:204
A set of data exported via a DataEngine.
Definition: datacontainer.h:65
No alignment.
Definition: plasma.h:205
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Wed May 27 2020 23:05:21 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.