From ecbca8f14279100aa0b787ff0085bd00d51dc769 Mon Sep 17 00:00:00 2001 From: Aaron Seigo Date: Fri, 3 Jun 2011 16:04:50 +0200 Subject: [PATCH] add bool isUsed() const and remove checkUsage() --- datacontainer.cpp | 17 +++++++++++------ datacontainer.h | 16 +++++----------- dataengine.cpp | 3 ++- private/datacontainer_p.h | 10 ++++++++++ 4 files changed, 28 insertions(+), 18 deletions(-) diff --git a/datacontainer.cpp b/datacontainer.cpp index 663c7ca97..c3dd9be28 100644 --- a/datacontainer.cpp +++ b/datacontainer.cpp @@ -287,7 +287,7 @@ void DataContainer::disconnectVisualization(QObject *visualization) } d->relayObjects.erase(objIt); - checkUsage(); + d->checkUsage(); } void DataContainer::checkForUpdate() @@ -328,13 +328,18 @@ void DataContainer::setNeedsUpdate(bool update) d->cached = update; } -void DataContainer::checkUsage() +bool DataContainer::isUsed() const { - if (d->relays.count() < 1 && - receivers(SIGNAL(dataUpdated(QString, Plasma::DataEngine::Data))) < 1) { + return !d->relays.isEmpty() && + receivers(SIGNAL(dataUpdated(QString, Plasma::DataEngine::Data))) > 0; +} + +void DataContainerPrivate::checkUsage() +{ + if (!q->isUsed()) { // DO NOT CALL ANYTHING AFTER THIS LINE AS IT MAY GET DELETED! - kDebug() << objectName() << "is unused"; - emit becameUnused(objectName()); + //kDebug() << q->objectName() << "is unused"; + emit q->becameUnused(q->objectName()); } } diff --git a/datacontainer.h b/datacontainer.h index 4bf4f667e..92a0bfed7 100644 --- a/datacontainer.h +++ b/datacontainer.h @@ -154,6 +154,11 @@ class PLASMA_EXPORT DataContainer : public QObject */ DataEngine* getDataEngine(); + /** + * @return true if one or more visualizations is connected to this DataContainer + */ + bool isUsed() const; + public Q_SLOTS: /** * Disconnects an object from this DataContainer. @@ -234,17 +239,6 @@ class PLASMA_EXPORT DataContainer : public QObject **/ void setNeedsUpdate(bool update = true); - protected Q_SLOTS: - /** - * Check if the DataContainer is still in use. - * - * If not the signal "becameUnused" will be emitted. - * - * Warning: The DataContainer may be invalid after calling this function, because a listener - * to becameUnused() may have deleted it. - **/ - void checkUsage(); - private: friend class SignalRelay; friend class DataContainerPrivate; diff --git a/dataengine.cpp b/dataengine.cpp index 5a26d8e38..1f7cadc62 100644 --- a/dataengine.cpp +++ b/dataengine.cpp @@ -39,6 +39,7 @@ #include "service.h" #include "scripting/dataenginescript.h" +#include "private/datacontainer_p.h" #include "private/dataengineservice_p.h" #include "private/remotedataengine_p.h" #include "private/service_p.h" @@ -146,7 +147,7 @@ DataEngine::Data DataEngine::query(const QString &source) const } DataEngine::Data data = s->data(); - s->checkUsage(); + s->d->checkUsage(); return data; } diff --git a/private/datacontainer_p.h b/private/datacontainer_p.h index 59054d624..9a616c864 100644 --- a/private/datacontainer_p.h +++ b/private/datacontainer_p.h @@ -46,6 +46,16 @@ public: { } + /** + * Check if the DataContainer is still in use. + * + * If not the signal "becameUnused" will be emitted. + * + * Warning: The DataContainer may be invalid after calling this function, because a listener + * to becameUnused() may have deleted it. + **/ + void checkUsage(); + SignalRelay *signalRelay(const DataContainer *dc, QObject *visualization, uint pollingInterval, Plasma::IntervalAlignment align, bool immediateUpdate);