2006-04-13 02:11:16 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2006 Aaron Seigo <aseigo@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 version 2 as
|
|
|
|
* published by the Free Software Foundation
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2007-05-20 22:36:59 +02:00
|
|
|
#ifndef PLASMA_DATAENGINE_H
|
|
|
|
#define PLASMA_DATAENGINE_H
|
2006-04-13 02:11:16 +02:00
|
|
|
|
2007-05-21 16:28:03 +02:00
|
|
|
#include <QtCore/QAtomic>
|
|
|
|
#include <QtCore/QHash>
|
|
|
|
#include <QtCore/QObject>
|
|
|
|
#include <QtCore/QStringList>
|
2006-04-13 02:11:16 +02:00
|
|
|
|
2007-05-24 22:01:12 +02:00
|
|
|
#include <KGenericFactory>
|
|
|
|
|
2007-05-20 22:13:46 +02:00
|
|
|
#include <plasma_export.h>
|
2007-03-01 00:35:26 +01:00
|
|
|
|
2006-04-13 02:11:16 +02:00
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
2007-05-23 08:38:44 +02:00
|
|
|
class DataSource;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @class DataEngine
|
|
|
|
* @brief Data provider for plasmoids (Plasma plugins)
|
|
|
|
*
|
|
|
|
* This is the base class for DataEngines, which provide access to bodies of
|
|
|
|
* data via a common and consistent interface. The common use of a DataEngine
|
|
|
|
* is to provide data to a widget for display. This allows a user interface
|
|
|
|
* element to show all sorts of data: as long as there is a DataEngine, the
|
|
|
|
* data is retrievable.
|
|
|
|
*
|
2007-05-23 09:13:00 +02:00
|
|
|
* DataEngines are loaded as plugins on demand and provide zero, one or more
|
|
|
|
* data sources which are identified by name. For instance, a network
|
|
|
|
* DataEngine might provide a data source for each network interface.
|
2007-05-23 08:38:44 +02:00
|
|
|
**/
|
2007-05-20 22:13:46 +02:00
|
|
|
class PLASMA_EXPORT DataEngine : public QObject
|
2006-04-13 02:11:16 +02:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
typedef QHash<QString, DataEngine*> Dict;
|
2007-05-20 22:36:59 +02:00
|
|
|
typedef QHash<QString, QVariant> Data;
|
2007-05-21 06:29:00 +02:00
|
|
|
typedef QHashIterator<QString, QVariant> DataIterator;
|
2006-04-13 02:11:16 +02:00
|
|
|
|
2007-05-23 08:38:44 +02:00
|
|
|
/**
|
|
|
|
* Default constructor.
|
|
|
|
*
|
|
|
|
* @param parent The parent object.
|
|
|
|
**/
|
2007-06-01 00:16:30 +02:00
|
|
|
explicit DataEngine(QObject* parent = 0);
|
2006-04-13 02:11:16 +02:00
|
|
|
virtual ~DataEngine();
|
|
|
|
|
2007-05-23 08:38:44 +02:00
|
|
|
/**
|
|
|
|
* @return a list of all the data sources currently available via this
|
|
|
|
* DataEngine
|
|
|
|
**/
|
2007-05-23 10:27:09 +02:00
|
|
|
virtual QStringList dataSources() const;
|
2007-05-23 08:38:44 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Connects a source to an object for data updates. The object must
|
|
|
|
* have a slot with the following signature:
|
|
|
|
*
|
|
|
|
* SLOT(updated(QString, Plasma::DataEngine::Data))
|
|
|
|
*
|
|
|
|
* The data is a QHash of QVariants keyed by QString names, allowing
|
|
|
|
* one data source to provide sets of related data.
|
|
|
|
*
|
|
|
|
* @param source the name of the data source
|
|
|
|
* @param visualization the object to connect the data source to
|
|
|
|
**/
|
2007-05-23 10:27:09 +02:00
|
|
|
void connectSource(const QString& source, QObject* visualization) const;
|
2007-05-23 08:38:44 +02:00
|
|
|
|
2007-05-28 07:43:54 +02:00
|
|
|
/**
|
|
|
|
* Connects all sources to an object for data updates. The object must
|
|
|
|
* have a slot with the following signature:
|
|
|
|
*
|
|
|
|
* SLOT(updated(QString, Plasma::DataEngine::Data))
|
|
|
|
*
|
|
|
|
* The data is a QHash of QVariants keyed by QString names, allowing
|
|
|
|
* one data source to provide sets of related data.
|
|
|
|
*
|
|
|
|
* @param visualization the object to connect the data source to
|
|
|
|
**/
|
|
|
|
void connectAllSources(QObject* viualization) const;
|
|
|
|
|
2007-05-23 08:38:44 +02:00
|
|
|
/**
|
|
|
|
* Gets the Data associated with a data source.
|
|
|
|
*
|
|
|
|
* The data is a QHash of QVariants keyed by QString names, allowing
|
|
|
|
* one data source to provide sets of related data.
|
|
|
|
*
|
|
|
|
* @param source the data source to retrieve the data for
|
|
|
|
* @return the Data associated with the source; if the source doesn't
|
|
|
|
* exist an empty data set is returned
|
|
|
|
**/
|
2007-05-23 10:27:09 +02:00
|
|
|
Data query(const QString& source) const;
|
2006-04-13 02:11:16 +02:00
|
|
|
|
2007-05-23 08:38:44 +02:00
|
|
|
/**
|
|
|
|
* Reference counting method. Calling this method increases the count
|
|
|
|
* by one.
|
|
|
|
**/
|
2006-04-13 02:11:16 +02:00
|
|
|
void ref();
|
2007-05-23 08:38:44 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Reference counting method. Calling this method decreases the count
|
|
|
|
* by one.
|
|
|
|
**/
|
2006-04-13 02:11:16 +02:00
|
|
|
void deref();
|
|
|
|
|
2007-05-23 08:38:44 +02:00
|
|
|
/**
|
|
|
|
* Reference counting method. Used to determine if this DataEngine is
|
|
|
|
* used.
|
|
|
|
* @return true if the reference count is zero
|
|
|
|
**/
|
2007-05-23 10:27:09 +02:00
|
|
|
bool isUsed() const;
|
2007-05-22 04:49:54 +02:00
|
|
|
|
2007-05-23 09:13:00 +02:00
|
|
|
/**
|
|
|
|
* Sets the icon for this data engine
|
|
|
|
**/
|
|
|
|
void setIcon(const QString& icon);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the name of the icon for this data engine; and empty string
|
|
|
|
* is returned if there is no associated icon.
|
|
|
|
**/
|
2007-05-23 10:27:09 +02:00
|
|
|
QString icon() const;
|
|
|
|
|
2007-05-22 04:49:54 +02:00
|
|
|
Q_SIGNALS:
|
2007-05-23 08:38:44 +02:00
|
|
|
/**
|
|
|
|
* Emitted when a new data source is created
|
|
|
|
* @param source the name of the new data source
|
|
|
|
**/
|
2007-05-22 04:49:54 +02:00
|
|
|
void newDataSource(const QString& source);
|
2007-05-23 08:38:44 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Emitted when a data source is removed.
|
|
|
|
* @param source the name of the data source that was removed
|
|
|
|
**/
|
2007-05-22 04:49:54 +02:00
|
|
|
void dataSourceRemoved(const QString& source);
|
|
|
|
|
2006-04-13 02:11:16 +02:00
|
|
|
protected:
|
2007-05-23 08:38:44 +02:00
|
|
|
/**
|
|
|
|
* This method is called when the DataEngine is started. When this
|
|
|
|
* method is called the DataEngine is fully constructed and ready to be
|
|
|
|
* used. This method should be reimplemented by DataEngine subclasses
|
|
|
|
* which have the need to perform a startup routine.
|
|
|
|
**/
|
2006-04-13 02:11:16 +02:00
|
|
|
virtual void init();
|
2007-05-23 08:38:44 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets a value for a data source. If the source
|
|
|
|
* doesn't exist then it is created.
|
|
|
|
*
|
|
|
|
* @param source the name of the data source
|
|
|
|
* @param value the data to associated with the source
|
|
|
|
**/
|
2007-05-19 10:38:46 +02:00
|
|
|
void setData(const QString& source, const QVariant& value);
|
2007-05-23 08:38:44 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets a value for a data source. If the source
|
|
|
|
* doesn't exist then it is created.
|
|
|
|
*
|
|
|
|
* @param source the name of the data source
|
|
|
|
* @param key the key to use for the data
|
|
|
|
* @param value the data to associated with the source
|
|
|
|
**/
|
2007-05-19 10:38:46 +02:00
|
|
|
void setData(const QString& source, const QString& key, const QVariant& value);
|
2007-05-23 08:38:44 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds an already constructed data source. The DataEngine takes
|
|
|
|
* ownership of the DataSource object.
|
|
|
|
* @param source the DataSource to add to the DataEngine
|
|
|
|
**/
|
|
|
|
void addSource(DataSource* source);
|
|
|
|
|
2007-05-28 07:43:54 +02:00
|
|
|
/**
|
|
|
|
* Sets an upper limit on the number of data sources to keep in this engine.
|
|
|
|
* If the limit is exceeded, then the oldest data source, as defined by last
|
|
|
|
* update, is dropped.
|
|
|
|
*
|
|
|
|
* @param limit the maximum number of sources to keep active
|
|
|
|
**/
|
|
|
|
void setSourceLimit(uint limit);
|
|
|
|
|
|
|
|
/* DataSource* domain(const QString &domain);
|
|
|
|
void createDataSource(const QString& source,
|
2007-05-19 10:38:46 +02:00
|
|
|
const QString& domain = QString());*/
|
2007-05-23 08:38:44 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes a data source.
|
|
|
|
* @param source the name of the data source to remove
|
|
|
|
**/
|
2006-12-17 00:04:44 +01:00
|
|
|
void removeDataSource(const QString& source);
|
2007-05-23 08:38:44 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes all data sources
|
|
|
|
**/
|
2006-12-17 00:04:44 +01:00
|
|
|
void clearAllDataSources();
|
2006-04-13 02:11:16 +02:00
|
|
|
|
2007-05-23 08:38:44 +02:00
|
|
|
private Q_SLOTS:
|
2007-05-19 10:38:46 +02:00
|
|
|
void checkForUpdates();
|
|
|
|
|
2006-04-13 02:11:16 +02:00
|
|
|
private:
|
|
|
|
class Private;
|
2007-05-19 10:38:46 +02:00
|
|
|
Private* const d;
|
2006-04-13 02:11:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // Plasma namespace
|
|
|
|
|
2007-05-20 22:36:59 +02:00
|
|
|
#define K_EXPORT_PLASMA_DATAENGINE(libname, classname) \
|
|
|
|
K_EXPORT_COMPONENT_FACTORY( \
|
2007-05-24 22:01:12 +02:00
|
|
|
plasma_engine_##libname, \
|
|
|
|
KGenericFactory<classname>("plasma_engine_" #libname))
|
2006-04-13 02:11:16 +02:00
|
|
|
|
|
|
|
#endif // multiple inclusion guard
|
|
|
|
|