20 #include "private/datacontainer_p.h" 21 #include "private/storage_p.h" 32 d(new DataContainerPrivate(this))
48 if (!value.isValid()) {
51 d->data.insert(key, value);
55 d->updateTimer.start();
62 d->storageTimer.start(180000,
this);
70 if (d->data.isEmpty()) {
77 d->updateTimer.start();
82 return d->relayObjects.contains(visualization);
90 QMap<QObject *, SignalRelay *>::iterator objIt = d->relayObjects.find(visualization);
91 bool connected = objIt != d->relayObjects.end();
99 if (relay->m_interval == pollingInterval) {
105 if (relay->receiverCount() == 1) {
107 d->relays.remove(relay->m_interval);
114 }
else if (pollingInterval < 1) {
125 connect(visualization, SIGNAL(destroyed(
QObject*)),
129 if (pollingInterval < 1) {
131 d->relayObjects[visualization] = 0;
139 bool immediateUpdate = connected || d->relayObjects.count() > 1;
140 SignalRelay *relay = d->signalRelay(
this, visualization, pollingInterval,
141 alignment, immediateUpdate);
149 QTime time = QTime::currentTime();
150 qsrand((uint)time.msec());
151 d->enableStorage = store;
153 QTimer::singleShot(qrand() % (2000 + 1) ,
this, SLOT(retrieve()));
159 return d->enableStorage;
169 d->isStored = !store;
178 o = dynamic_cast<QObject *> (o->parent());
182 de = dynamic_cast<DataEngine *> (o);
187 void DataContainerPrivate::store()
189 if (!q->needsToBeStored() || !q->isStorageEnabled()) {
193 DataEngine* de = q->getDataEngine();
198 q->setNeedsToBeStored(
false);
201 storage =
new Storage(q);
204 KConfigGroup op = storage->operationDescription(
"save");
205 op.writeEntry(
"group", q->objectName());
206 StorageJob *job = static_cast<StorageJob *>(storage->startOperationCall(op));
209 QObject::connect(job, SIGNAL(finished(
KJob*)), q, SLOT(storeJobFinished(
KJob*)));
212 void DataContainerPrivate::storeJobFinished(
KJob* )
215 if (storageCount < 1) {
216 storage->deleteLater();
221 void DataContainerPrivate::retrieve()
223 DataEngine* de = q->getDataEngine();
229 storage =
new Storage(q);
232 KConfigGroup retrieveGroup = storage->operationDescription(
"retrieve");
233 retrieveGroup.writeEntry(
"group", q->objectName());
234 ServiceJob* retrieveJob = storage->startOperationCall(retrieveGroup);
235 QObject::connect(retrieveJob, SIGNAL(result(
KJob*)), q,
236 SLOT(populateFromStoredData(
KJob*)));
239 void DataContainerPrivate::populateFromStoredData(
KJob *job)
245 StorageJob *ret = dynamic_cast<StorageJob*>(job);
252 if (data.isEmpty() && !ret->data().isEmpty()) {
255 q->forceImmediateUpdate();
258 KConfigGroup expireGroup = storage->operationDescription(
"expire");
260 expireGroup.writeEntry(
"age", 345600);
261 storage->startOperationCall(expireGroup);
266 QMap<QObject *, SignalRelay *>::iterator objIt = d->relayObjects.find(visualization);
267 disconnect(visualization, SIGNAL(destroyed(
QObject*)),
270 if (objIt == d->relayObjects.end() || !objIt.value()) {
277 if (relay->receiverCount() == 1) {
278 d->relays.remove(relay->m_interval);
286 d->relayObjects.erase(objIt);
297 relay->checkQueueing();
312 relay->forceImmediateUpdate();
318 return d->updateTimer.elapsed();
328 if (!d->checkUsageTimer.isActive()) {
329 d->checkUsageTimer.start(10,
this);
335 if (event->timerId() == d->checkUsageTimer.timerId()) {
336 if (d->relays.count() < 1 &&
339 kDebug() << objectName() <<
"is unused";
342 d->checkUsageTimer.stop();
343 }
else if (event->timerId() == d->storageTimer.timerId()) {
345 d->storageTimer.stop();
351 #include "datacontainer.moc" void disconnectVisualization(QObject *visualization)
Disconnects an object from this DataContainer.
void timerEvent(QTimerEvent *event)
bool visualizationIsConnected(QObject *visualization) const
void checkForUpdate()
Checks whether any data has changed and, if so, emits dataUpdated().
bool isStorageEnabled() const
uint timeSinceLastUpdate() const
Returns how long ago, in msecs, that the data in this container was last updated.
bool needsToBeStored() const
QHash< QString, QVariant > Data
void dataUpdated(const QString &source, const Plasma::DataEngine::Data &data)
Emitted when the data has been updated, allowing visualizations to reflect the new data.
Namespace for everything in libplasma.
void setNeedsToBeStored(bool store)
sets that the data container needs to be stored or not.
DataContainer(QObject *parent=0)
Constructs a default DataContainer that has no name or data associated with it.
void checkUsage()
Check if the DataContainer is still in use.
IntervalAlignment
Possible timing alignments.
Data provider for plasmoids (Plasma plugins)
void forceImmediateUpdate()
Forces immediate update signals to all visualizations.
void connectVisualization(QObject *visualization, uint pollingInterval, Plasma::IntervalAlignment alignment)
Connects an object to this DataContainer.
void setNeedsUpdate(bool update=true)
Indicates that the data should be treated as dirty the next time hasUpdates() is called.
const DataEngine::Data data() const
Returns the data for this DataContainer.
void setData(const QString &key, const QVariant &value)
Set a value for a key.
void becameUnused(const QString &source)
Emitted when the last visualization is disconnected.
void setStorageEnabled(bool store)
sets this data container to be automatically stored.
void removeAllData()
Removes all data currently associated with this source.
DataEngine * getDataEngine()