2007-05-20 22:36:59 +02:00
|
|
|
/*
|
2007-08-06 13:20:02 +02:00
|
|
|
* Copyright 2006-2007 Aaron Seigo <aseigo@kde.org>
|
2007-05-20 22:36:59 +02:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
2007-09-14 21:06:18 +02:00
|
|
|
* 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.
|
2007-05-20 22:36:59 +02:00
|
|
|
*
|
|
|
|
* 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-07-23 02:22:16 +02:00
|
|
|
#ifndef PLASMA_DATACONTAINER_H
|
|
|
|
#define PLASMA_DATACONTAINER_H
|
2007-05-20 22:36:59 +02:00
|
|
|
|
|
|
|
#include <QtCore/QHash>
|
|
|
|
#include <QtCore/QObject>
|
|
|
|
|
2007-06-02 19:29:39 +02:00
|
|
|
#include <plasma/plasma_export.h>
|
|
|
|
#include <plasma/dataengine.h>
|
2007-05-20 22:36:59 +02:00
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
2007-05-27 10:00:46 +02:00
|
|
|
/**
|
2007-06-01 01:40:39 +02:00
|
|
|
* @brief A set of data exported via a DataEngine
|
2007-05-27 10:00:46 +02:00
|
|
|
*
|
2007-07-23 02:22:16 +02:00
|
|
|
* Plasma::DataContainer wraps the data exported by a DataEngine
|
2007-05-27 10:00:46 +02:00
|
|
|
* implementation, providing a generic wrapper for the data.
|
|
|
|
*
|
2007-07-23 02:22:16 +02:00
|
|
|
* A DataContainer may have zero or more associated pieces of data which
|
2007-05-27 10:00:46 +02:00
|
|
|
* are keyed by strings. The data itself is stored as QVariants. This allows
|
|
|
|
* easy and flexible retrieval of the information associated with this object
|
2007-07-23 02:22:16 +02:00
|
|
|
* without writing DataContainer or DataEngine specific code in visualizations.
|
2007-05-27 10:00:46 +02:00
|
|
|
**/
|
2007-07-23 02:22:16 +02:00
|
|
|
class PLASMA_EXPORT DataContainer : public QObject
|
2007-05-20 22:36:59 +02:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2007-06-10 06:03:50 +02:00
|
|
|
//typedef QHash<QString, DataEngine::SourceDict> Grouping;
|
2007-05-20 22:36:59 +02:00
|
|
|
|
2007-05-27 10:00:46 +02:00
|
|
|
/**
|
2007-07-23 02:22:16 +02:00
|
|
|
* Constructs a default DataContainer, which has no name or data
|
2007-05-27 10:00:46 +02:00
|
|
|
* associated with it
|
|
|
|
**/
|
2007-07-23 02:22:16 +02:00
|
|
|
explicit DataContainer(QObject* parent = 0);
|
|
|
|
virtual ~DataContainer();
|
2007-05-20 22:36:59 +02:00
|
|
|
|
2007-05-27 10:00:46 +02:00
|
|
|
/**
|
2007-07-23 02:22:16 +02:00
|
|
|
* Returns the data for this DataContainer
|
2007-05-27 10:00:46 +02:00
|
|
|
**/
|
2007-05-20 22:36:59 +02:00
|
|
|
const DataEngine::Data data() const;
|
2007-05-27 10:00:46 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a value for a key. This also marks this source as needing
|
|
|
|
* to signal an update. After calling this, a call to checkForUpdate()
|
|
|
|
* is done by the engine. This allows for batching updates.
|
|
|
|
*
|
|
|
|
* @param key a string used as the key for the data
|
2007-06-17 19:38:54 +02:00
|
|
|
* @param value a QVariant holding the actual data. If a null or invalid
|
|
|
|
* QVariant is passed in and the key currently exists in the
|
|
|
|
* data, then the data entry is removed
|
2007-05-27 10:00:46 +02:00
|
|
|
**/
|
2007-05-20 22:36:59 +02:00
|
|
|
void setData(const QString& key, const QVariant& value);
|
|
|
|
|
2007-07-09 11:33:15 +02:00
|
|
|
/**
|
|
|
|
* Clears all data currently associated with this source
|
|
|
|
**/
|
|
|
|
void clearData();
|
|
|
|
|
2007-05-27 10:00:46 +02:00
|
|
|
/**
|
|
|
|
* Checks for whether the data has changed and therefore an update
|
|
|
|
* signal needs to be emitted.
|
|
|
|
**/
|
2007-05-20 22:36:59 +02:00
|
|
|
void checkForUpdate();
|
|
|
|
|
2007-09-13 22:34:17 +02:00
|
|
|
/**
|
|
|
|
* Returns how long ago, in msecs, that the data in this container was last updated
|
|
|
|
**/
|
2007-09-16 18:25:59 +02:00
|
|
|
int timeSinceLastUpdate() const;
|
2007-09-13 22:34:17 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
**/
|
|
|
|
bool hasUpdates() const;
|
|
|
|
|
2007-09-02 00:23:03 +02:00
|
|
|
public Q_SLOTS:
|
|
|
|
/**
|
|
|
|
* Check if the DataContainer is still in use.
|
|
|
|
* If not the signal "unused" will be emitted.
|
|
|
|
* Warning: The DataContainer may be invalid after calling this function.
|
|
|
|
*/
|
|
|
|
void checkUsage();
|
|
|
|
|
2007-09-12 19:03:06 +02:00
|
|
|
/**
|
|
|
|
* Connects an object to this DataContainer. May be called repeatedly
|
|
|
|
* for the same visualization without side effects
|
|
|
|
*
|
|
|
|
* @param visualization the object to connect to this DataContainer
|
|
|
|
* @param updateInterval the time in milliseconds between updates
|
|
|
|
**/
|
2007-09-12 19:53:54 +02:00
|
|
|
void connectVisualization(QObject* visualization, uint updateInterval, Plasma::IntervalAlignment alignment);
|
2007-09-12 19:03:06 +02:00
|
|
|
|
2007-09-11 02:49:51 +02:00
|
|
|
/**
|
|
|
|
* Disconnects an object from this DataContainer.
|
|
|
|
**/
|
|
|
|
void disconnectVisualization(QObject* visualization);
|
|
|
|
|
2007-05-20 22:36:59 +02:00
|
|
|
Q_SIGNALS:
|
2007-05-27 10:00:46 +02:00
|
|
|
/**
|
|
|
|
* Emitted when the data has been updated, allowing visualization to
|
|
|
|
* reflect the new data.
|
|
|
|
**/
|
2007-11-06 08:20:08 +01:00
|
|
|
void dataUpdated(const QString& source, const Plasma::DataEngine::Data& data);
|
2007-05-20 22:36:59 +02:00
|
|
|
|
2007-06-10 07:39:27 +02:00
|
|
|
/**
|
|
|
|
* Emitted when this source becomes unused
|
|
|
|
**/
|
|
|
|
void unused(const QString& source);
|
|
|
|
|
2007-09-11 02:49:51 +02:00
|
|
|
/**
|
|
|
|
* Emitted when the source, usually due to an internal timer firing,
|
|
|
|
* requests to be updated.
|
|
|
|
**/
|
2007-09-13 22:34:17 +02:00
|
|
|
void requestUpdate(DataContainer *source);
|
2007-09-11 02:49:51 +02:00
|
|
|
|
2007-05-20 22:36:59 +02:00
|
|
|
private:
|
2007-09-11 02:49:51 +02:00
|
|
|
friend class SignalRelay;
|
2007-05-20 22:36:59 +02:00
|
|
|
class Private;
|
|
|
|
Private* const d;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // Plasma namespace
|
|
|
|
|
|
|
|
#endif // multiple inclusion guard
|