- add connectVisualization so now the DataContainer manages all connect/disconnecting
- keep track of objects that are connected even at interval == 0 - remove disconnectNotify due to these changes - allow multiple calls to connectVisualization to work properly without resulting in multiple connections to the same object and allowing the update interval to be adjusted for a given source/vis pair this makes it pretty important to use connectVisualization and disconnectVisualization rather than QObject::connect and QObject::disconnect for the updated signal stuff svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=711717
This commit is contained in:
parent
32948264d0
commit
8415f49e55
@ -90,22 +90,66 @@ void DataContainer::checkUsage()
|
||||
}
|
||||
}
|
||||
|
||||
void DataContainer::connectVisualization(QObject* visualization, uint updateInterval)
|
||||
{
|
||||
// kDebug() << "connecting visualization" << (void*)visualization << "at interval of" << updateInterval;
|
||||
QMap<QObject *, SignalRelay *>::iterator objIt = d->relayObjects.find(visualization);
|
||||
bool connected = objIt != d->relayObjects.end();
|
||||
if (connected) {
|
||||
// this visualization is already connected. just adjust the update
|
||||
// frequency if necessary
|
||||
SignalRelay *relay = objIt.value();
|
||||
if (relay) {
|
||||
// connected to a relay
|
||||
disconnect(relay, SIGNAL(updated(QString,Plasma::DataEngine::Data)),
|
||||
visualization, SLOT(updated(QString,Plasma::DataEngine::Data)));
|
||||
|
||||
if (relay->isUnused()) {
|
||||
d->relays.erase(d->relays.find(relay->interval));
|
||||
delete relay;
|
||||
}
|
||||
// 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
|
||||
// nothing to do!
|
||||
kDebug() << " already connected, nothing to do";
|
||||
return;
|
||||
} else {
|
||||
disconnect(this, SIGNAL(updated(QString,Plasma::DataEngine::Data)),
|
||||
visualization, SLOT(updated(QString,Plasma::DataEngine::Data)));
|
||||
}
|
||||
}
|
||||
|
||||
if (!connected) {
|
||||
connect(visualization, SIGNAL(destroyed(QObject*)),
|
||||
this, SLOT(disconnectVisualization(QObject*)), Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
d->relayObjects[visualization] = 0;
|
||||
|
||||
if (updateInterval < 1) {
|
||||
// kDebug() << " connecting directly";
|
||||
connect(this, SIGNAL(updated(QString,Plasma::DataEngine::Data)),
|
||||
visualization, SLOT(updated(QString,Plasma::DataEngine::Data)));
|
||||
} else {
|
||||
// kDebug() << " connecting to a relay";
|
||||
connect(signalRelay(visualization, updateInterval),
|
||||
SIGNAL(updated(QString,Plasma::DataEngine::Data)),
|
||||
visualization, SLOT(updated(QString,Plasma::DataEngine::Data)));
|
||||
}
|
||||
}
|
||||
|
||||
void DataContainer::disconnectVisualization(QObject* visualization)
|
||||
{
|
||||
QMap<QObject *, SignalRelay *>::iterator objIt = d->relayObjects.find(visualization);
|
||||
|
||||
if (objIt == d->relayObjects.end()) {
|
||||
// we will assume that it is connected directly to the DataContainer itself
|
||||
if (objIt == d->relayObjects.end() || !objIt.value()) {
|
||||
// it is connected directly to the DataContainer itself
|
||||
disconnect(this, SIGNAL(updated(QString,Plasma::DataEngine::Data)),
|
||||
visualization, SLOT(updated(QString,Plasma::DataEngine::Data)));
|
||||
|
||||
// NOTE: we don't need to call checkUsage here as it will happen in disconnectNotify
|
||||
// checkUsage()
|
||||
} else {
|
||||
SignalRelay *relay = objIt.value();
|
||||
d->relayObjects.erase(objIt);
|
||||
objIt = d->relayObjects.end(); //for safety's sake?
|
||||
|
||||
disconnect(relay, SIGNAL(updated(QString,Plasma::DataEngine::Data)),
|
||||
visualization, SLOT(updated(QString,Plasma::DataEngine::Data)));
|
||||
|
||||
@ -114,13 +158,9 @@ void DataContainer::disconnectVisualization(QObject* visualization)
|
||||
delete relay;
|
||||
}
|
||||
|
||||
checkUsage();
|
||||
}
|
||||
}
|
||||
|
||||
void DataContainer::disconnectNotify(const char *signal)
|
||||
{
|
||||
Q_UNUSED(signal)
|
||||
d->relayObjects.erase(objIt);
|
||||
checkUsage();
|
||||
}
|
||||
|
||||
|
@ -94,6 +94,15 @@ class PLASMA_EXPORT DataContainer : public QObject
|
||||
*/
|
||||
void checkUsage();
|
||||
|
||||
/**
|
||||
* 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
|
||||
**/
|
||||
void connectVisualization(QObject* visualization, uint updateInterval);
|
||||
|
||||
/**
|
||||
* Disconnects an object from this DataContainer.
|
||||
**/
|
||||
@ -117,9 +126,6 @@ class PLASMA_EXPORT DataContainer : public QObject
|
||||
**/
|
||||
void requestUpdate(const QString& source);
|
||||
|
||||
protected:
|
||||
void disconnectNotify(const char *signal);
|
||||
|
||||
private:
|
||||
friend class SignalRelay;
|
||||
class Private;
|
||||
|
Loading…
x
Reference in New Issue
Block a user