Plasma
dataengine.h
Go to the documentation of this file.
00001 /* 00002 * Copyright 2006-2007 Aaron Seigo <aseigo@kde.org> 00003 * 00004 * This program is free software; you can redistribute it and/or modify 00005 * it under the terms of the GNU Library General Public License as 00006 * published by the Free Software Foundation; either version 2, or 00007 * (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details 00013 * 00014 * You should have received a copy of the GNU Library General Public 00015 * License along with this program; if not, write to the 00016 * Free Software Foundation, Inc., 00017 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00018 */ 00019 00020 #ifndef PLASMA_DATAENGINE_H 00021 #define PLASMA_DATAENGINE_H 00022 00023 #include <QtCore/QHash> 00024 #include <QtCore/QObject> 00025 #include <QtCore/QStringList> 00026 00027 #include <kgenericfactory.h> 00028 #include <kservice.h> 00029 00030 #include <plasma/version.h> 00031 #include <plasma/plasma.h> 00032 #include <plasma/service.h> 00033 00034 namespace Plasma 00035 { 00036 00037 class DataContainer; 00038 class DataEngineScript; 00039 class Package; 00040 class Service; 00041 class DataEnginePrivate; 00042 00058 class PLASMA_EXPORT DataEngine : public QObject 00059 { 00060 Q_OBJECT 00061 Q_PROPERTY(QStringList sources READ sources) 00062 Q_PROPERTY(bool valid READ isValid) 00063 Q_PROPERTY(QString icon READ icon WRITE setIcon) 00064 Q_PROPERTY(QString name READ name) 00065 00066 public: 00067 typedef QHash<QString, DataEngine*> Dict; 00068 typedef QHash<QString, QVariant> Data; 00069 typedef QHashIterator<QString, QVariant> DataIterator; 00070 typedef QHash<QString, DataContainer*> SourceDict; 00071 00078 explicit DataEngine(QObject *parent = 0, KService::Ptr service = KService::Ptr(0)); 00079 DataEngine(QObject *parent, const QVariantList &args); 00080 ~DataEngine(); 00081 00088 virtual void init(); 00089 00096 virtual QStringList sources() const; 00097 00104 Q_INVOKABLE virtual Service *serviceForSource(const QString &source); 00105 00109 QString name() const; 00110 00132 Q_INVOKABLE void connectSource( 00133 const QString &source, QObject *visualization, 00134 uint pollingInterval = 0, 00135 Plasma::IntervalAlignment intervalAlignment = NoAlignment) const; 00136 00164 Q_INVOKABLE void connectAllSources(QObject *visualization, uint pollingInterval = 0, 00165 Plasma::IntervalAlignment intervalAlignment = 00166 NoAlignment) const; 00167 00174 Q_INVOKABLE void disconnectSource(const QString &source, QObject *visualization) const; 00175 00186 Q_INVOKABLE DataContainer *containerForSource(const QString &source); 00187 00198 Q_INVOKABLE DataEngine::Data query(const QString &source) const; 00199 00205 bool isValid() const; 00206 00213 bool isEmpty() const; 00214 00221 uint maxSourceCount() const; 00222 00227 QString icon() const; 00228 00234 const Package *package() const; 00235 00239 QString pluginName() const; 00240 00252 Q_INVOKABLE Service* createDefaultService(QObject *parent = 0); 00253 00254 Q_SIGNALS: 00265 void sourceAdded(const QString &source); 00266 00277 void sourceRemoved(const QString &source); 00278 00279 protected: 00300 virtual bool sourceRequestEvent(const QString &source); 00301 00312 virtual bool updateSourceEvent(const QString &source); 00313 00321 void setData(const QString &source, const QVariant &value); 00322 00331 void setData(const QString &source, const QString &key, const QVariant &value); 00332 00340 void setData(const QString &source, const Data &data); 00341 00347 void removeAllData(const QString &source); 00348 00355 void removeData(const QString &source, const QString &key); 00356 00364 void addSource(DataContainer *source); 00365 00373 void setMaxSourceCount(uint limit); 00374 00388 void setMinimumPollingInterval(int minimumMs); 00389 00393 int minimumPollingInterval() const; 00394 00403 void setPollingInterval(uint frequency); 00404 00408 void removeAllSources(); 00409 00417 void setValid(bool valid); 00418 00422 SourceDict containerDict() const; 00423 00427 void timerEvent(QTimerEvent *event); 00428 00432 void setName(const QString &name); 00433 00437 void setIcon(const QString &icon); 00438 00453 void setDefaultService(const QString &serviceName); 00454 00463 void setStorageEnabled(const QString &source, bool store); 00464 00465 protected Q_SLOTS: 00471 void scheduleSourcesUpdated(); 00472 00477 void removeSource(const QString &source); 00478 00482 void updateAllSources(); 00483 00494 void forceImmediateUpdateOfAllVisualizations(); 00495 00496 private: 00497 friend class DataEnginePrivate; 00498 friend class DataEngineScript; 00499 friend class DataEngineManager; 00500 friend class PlasmoidServiceJob; 00501 friend class NullEngine; 00502 00503 Q_PRIVATE_SLOT(d, void internalUpdateSource(DataContainer *source)) 00504 Q_PRIVATE_SLOT(d, void sourceDestroyed(QObject *object)) 00505 00506 DataEnginePrivate *const d; 00507 }; 00508 00509 } // Plasma namespace 00510 00514 #define K_EXPORT_PLASMA_DATAENGINE(libname, classname) \ 00515 K_PLUGIN_FACTORY(factory, registerPlugin<classname>();) \ 00516 K_EXPORT_PLUGIN(factory("plasma_engine_" #libname)) \ 00517 K_EXPORT_PLUGIN_VERSION(PLASMA_VERSION) 00518 00519 Q_DECLARE_METATYPE(Plasma::DataEngine*) 00520 00521 #endif // multiple inclusion guard
KDE 4.6 API Reference