diff --git a/datacontainer.cpp b/datacontainer.cpp index a29bb1c36..a50153d73 100644 --- a/datacontainer.cpp +++ b/datacontainer.cpp @@ -115,7 +115,7 @@ void DataContainer::checkUsage() void DataContainer::connectVisualization(QObject* visualization, uint updateInterval, Plasma::IntervalAlignment alignment) { -// kDebug() << "connecting visualization" << (void*)visualization << "at interval of" << updateInterval; + //kDebug() << "connecting visualization" << visualization << "at interval of" << updateInterval; QMap::iterator objIt = d->relayObjects.find(visualization); bool connected = objIt != d->relayObjects.end(); if (connected) { @@ -124,14 +124,17 @@ void DataContainer::connectVisualization(QObject* visualization, uint updateInte SignalRelay *relay = objIt.value(); if (relay) { // connected to a relay - disconnect(relay, SIGNAL(dataUpdated(QString,Plasma::DataEngine::Data)), - visualization, SLOT(dataUpdated(QString,Plasma::DataEngine::Data))); + //kDebug() << " already connected, but to a relay"; - if (relay->isUnused()) { + if (relay->receiverCount() == 1) { + //kDebug() << " removing relay, as it is now unused"; d->relays.remove(relay->m_interval); delete relay; + } else { + disconnect(relay, SIGNAL(dataUpdated(QString,Plasma::DataEngine::Data)), + visualization, SLOT(dataUpdated(QString,Plasma::DataEngine::Data))); + //relay->isUnused(); } -// kDebug() << " already connected, but to a relay"; } else if (updateInterval < 1) { // the visualization was connected already, but not to a relay // and it still doesn't want to connect to a relay, so we have @@ -142,23 +145,21 @@ void DataContainer::connectVisualization(QObject* visualization, uint updateInte disconnect(this, SIGNAL(dataUpdated(QString,Plasma::DataEngine::Data)), visualization, SLOT(dataUpdated(QString,Plasma::DataEngine::Data))); } - } - - if (!connected) { + } else { connect(visualization, SIGNAL(destroyed(QObject*)), this, SLOT(disconnectVisualization(QObject*)));//, Qt::QueuedConnection); } - d->relayObjects[visualization] = 0; if (updateInterval < 1) { // kDebug() << " connecting directly"; + d->relayObjects[visualization] = 0; connect(this, SIGNAL(dataUpdated(QString,Plasma::DataEngine::Data)), visualization, SLOT(dataUpdated(QString,Plasma::DataEngine::Data))); } else { // kDebug() << " connecting to a relay"; - connect(d->signalRelay(this, visualization, updateInterval, alignment), - SIGNAL(dataUpdated(QString,Plasma::DataEngine::Data)), + SignalRelay *relay = d->signalRelay(this, visualization, updateInterval, alignment); + connect(relay, SIGNAL(dataUpdated(QString,Plasma::DataEngine::Data)), visualization, SLOT(dataUpdated(QString,Plasma::DataEngine::Data))); } } @@ -173,14 +174,14 @@ void DataContainer::disconnectVisualization(QObject* visualization) visualization, SLOT(dataUpdated(QString,Plasma::DataEngine::Data))); } else { SignalRelay *relay = objIt.value(); - disconnect(relay, SIGNAL(dataUpdated(QString,Plasma::DataEngine::Data)), - visualization, SLOT(dataUpdated(QString,Plasma::DataEngine::Data))); - if (relay->isUnused()) { + if (relay->receiverCount() == 1) { d->relays.remove(relay->m_interval); delete relay; + } else { + disconnect(relay, SIGNAL(dataUpdated(QString,Plasma::DataEngine::Data)), + visualization, SLOT(dataUpdated(QString,Plasma::DataEngine::Data))); } - } d->relayObjects.erase(objIt); diff --git a/datacontainer_p.h b/datacontainer_p.h index 818676ac0..4d231e3d7 100644 --- a/datacontainer_p.h +++ b/datacontainer_p.h @@ -35,8 +35,8 @@ public: : dirty(false), cached(false) {} - QObject* signalRelay(const DataContainer* dc, QObject *visualization, - uint updateInterval, Plasma::IntervalAlignment align); + SignalRelay* signalRelay(const DataContainer* dc, QObject *visualization, + uint updateInterval, Plasma::IntervalAlignment align); DataEngine::Data data; QMap relayObjects; @@ -67,6 +67,11 @@ public: } } + int receiverCount() const + { + return receivers(SIGNAL(dataUpdated(QString,Plasma::DataEngine::Data))); + } + bool isUnused() { return receivers(SIGNAL(dataUpdated(QString,Plasma::DataEngine::Data))) < 1; @@ -153,7 +158,7 @@ protected: } }; -QObject* DataContainer::Private::signalRelay(const DataContainer* dc, QObject *visualization, uint updateInterval, Plasma::IntervalAlignment align) +SignalRelay* DataContainer::Private::signalRelay(const DataContainer* dc, QObject *visualization, uint updateInterval, Plasma::IntervalAlignment align) { QMap::const_iterator relayIt = relays.find(updateInterval); SignalRelay *relay = 0;