X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fclient%2Fbufferviewoverlay.cpp;h=b1938d1120f5ac131a65d1a68587f41fdf78f29a;hp=93af395e5d499236940e9822e412bb7f3722d2ea;hb=f6b9eeda207d42c99fc3e9085631722cf2ec83dc;hpb=71ef3ec0c4c4d02431aa560ed83b379c416798c5 diff --git a/src/client/bufferviewoverlay.cpp b/src/client/bufferviewoverlay.cpp index 93af395e..b1938d11 100644 --- a/src/client/bufferviewoverlay.cpp +++ b/src/client/bufferviewoverlay.cpp @@ -22,15 +22,17 @@ #include -#include "client.h" #include "bufferviewconfig.h" +#include "client.h" #include "clientbufferviewmanager.h" +#include "networkmodel.h" const int BufferViewOverlay::_updateEventId = QEvent::registerEventType(); BufferViewOverlay::BufferViewOverlay(QObject *parent) : QObject(parent), _aboutToUpdate(false), + _uninitializedViewCount(0), _addBuffersAutomatically(false), _hideInactiveBuffers(false), _allowedBufferTypes(0), @@ -49,11 +51,14 @@ void BufferViewOverlay::addView(int viewId) { } _bufferViewIds << viewId; + _uninitializedViewCount++; if(config->isInitialized()) { viewInitialized(config); } else { disconnect(config, SIGNAL(initDone()), this, SLOT(viewInitialized())); - connect(config, SIGNAL(initDone()), this, SLOT(viewInitialized())); + // we use a queued connection here since manipulating the connection list of a sending object + // doesn't seem to be such a good idea while executing a connected slots. + connect(config, SIGNAL(initDone()), this, SLOT(viewInitialized()), Qt::QueuedConnection); } } @@ -62,10 +67,28 @@ void BufferViewOverlay::removeView(int viewId) { return; _bufferViewIds.remove(viewId); - BufferViewConfig *config = qobject_cast(sender()); + BufferViewConfig *config = Client::bufferViewManager()->bufferViewConfig(viewId); if(config) disconnect(config, 0, this, 0); + + // update initialized State: + bool wasInitialized = isInitialized(); + _uninitializedViewCount = 0; + QSet::iterator viewIter = _bufferViewIds.begin(); + while(viewIter != _bufferViewIds.end()) { + config = Client::bufferViewManager()->bufferViewConfig(*viewIter); + if(!config) { + viewIter = _bufferViewIds.erase(viewIter); + } else { + if(!config->isInitialized()) + _uninitializedViewCount++; + viewIter++; + } + } + update(); + if(!wasInitialized && isInitialized()) + emit initDone(); } void BufferViewOverlay::viewInitialized(BufferViewConfig *config) { @@ -75,20 +98,25 @@ void BufferViewOverlay::viewInitialized(BufferViewConfig *config) { } disconnect(config, SIGNAL(initDone()), this, SLOT(viewInitialized())); - connect(config, SIGNAL(networkIdSet(const NetworkId &)), this, SLOT(update())); - connect(config, SIGNAL(addNewBuffersAutomaticallySet(bool)), this, SLOT(update())); - connect(config, SIGNAL(sortAlphabeticallySet(bool)), this, SLOT(update())); - connect(config, SIGNAL(hideInactiveBuffersSet(bool)), this, SLOT(update())); - connect(config, SIGNAL(allowedBufferTypesSet(int)), this, SLOT(update())); - connect(config, SIGNAL(minimumActivitySet(int)), this, SLOT(update())); - connect(config, SIGNAL(bufferListSet()), this, SLOT(update())); - connect(config, SIGNAL(bufferAdded(const BufferId &, int)), this, SLOT(update())); - connect(config, SIGNAL(bufferRemoved(const BufferId &)), this, SLOT(update())); - connect(config, SIGNAL(bufferPermanentlyRemoved(const BufferId &)), this, SLOT(update())); + connect(config, SIGNAL(configChanged()), this, SLOT(update())); +// connect(config, SIGNAL(networkIdSet(const NetworkId &)), this, SLOT(update())); +// connect(config, SIGNAL(addNewBuffersAutomaticallySet(bool)), this, SLOT(update())); +// connect(config, SIGNAL(sortAlphabeticallySet(bool)), this, SLOT(update())); +// connect(config, SIGNAL(hideInactiveBuffersSet(bool)), this, SLOT(update())); +// connect(config, SIGNAL(allowedBufferTypesSet(int)), this, SLOT(update())); +// connect(config, SIGNAL(minimumActivitySet(int)), this, SLOT(update())); +// connect(config, SIGNAL(bufferListSet()), this, SLOT(update())); +// connect(config, SIGNAL(bufferAdded(const BufferId &, int)), this, SLOT(update())); +// connect(config, SIGNAL(bufferRemoved(const BufferId &)), this, SLOT(update())); +// connect(config, SIGNAL(bufferPermanentlyRemoved(const BufferId &)), this, SLOT(update())); // check if the view was removed in the meantime... if(_bufferViewIds.contains(config->bufferViewId())) update(); + + _uninitializedViewCount--; + if(isInitialized()) + emit initDone(); } void BufferViewOverlay::viewInitialized() { @@ -107,6 +135,9 @@ void BufferViewOverlay::update() { } void BufferViewOverlay::updateHelper() { + if(!_aboutToUpdate) + return; + bool changed = false; bool addBuffersAutomatically = false; @@ -118,29 +149,52 @@ void BufferViewOverlay::updateHelper() { QSet removedBuffers; QSet tempRemovedBuffers; - BufferViewConfig *config = 0; - QSet::const_iterator viewIter; - for(viewIter = _bufferViewIds.constBegin(); viewIter != _bufferViewIds.constEnd(); viewIter++) { - config = Client::bufferViewManager()->bufferViewConfig(*viewIter); - if(!config) - continue; + if(Client::bufferViewManager()) { + BufferViewConfig *config = 0; + QSet::const_iterator viewIter; + for(viewIter = _bufferViewIds.constBegin(); viewIter != _bufferViewIds.constEnd(); viewIter++) { + config = Client::bufferViewManager()->bufferViewConfig(*viewIter); + if(!config) + continue; - networkIds << config->networkId(); - buffers += config->bufferList().toSet(); - tempRemovedBuffers += config->temporarilyRemovedBuffers(); + networkIds << config->networkId(); + if(config->networkId().isValid()) { + NetworkId networkId = config->networkId(); + // we have to filter out all the buffers that don't belong to this net... :/ + QSet bufferIds; + foreach(BufferId bufferId, config->bufferList()) { + if(Client::networkModel()->networkId(bufferId) == networkId) + bufferIds << bufferId; + } + buffers += bufferIds; - // in the overlay a buffer is removed it is removed from all views - if(removedBuffers.isEmpty()) - removedBuffers = config->removedBuffers(); - else - removedBuffers.intersect(config->removedBuffers()); + bufferIds.clear(); + foreach(BufferId bufferId, config->temporarilyRemovedBuffers()) { + if(Client::networkModel()->networkId(bufferId) == networkId) + bufferIds << bufferId; + } + tempRemovedBuffers += bufferIds; + } else { + buffers += config->bufferList().toSet(); + tempRemovedBuffers += config->temporarilyRemovedBuffers(); + } + // in the overlay a buffer is removed it is removed from all views + if(removedBuffers.isEmpty()) + removedBuffers = config->removedBuffers(); + else + removedBuffers.intersect(config->removedBuffers()); - addBuffersAutomatically |= config->addNewBuffersAutomatically(); - hideInactiveBuffers &= config->hideInactiveBuffers(); - allowedBufferTypes |= config->allowedBufferTypes(); - if(minimumActivity == -1 || config->minimumActivity() < minimumActivity) - minimumActivity = config->minimumActivity(); + + addBuffersAutomatically |= config->addNewBuffersAutomatically(); + hideInactiveBuffers &= config->hideInactiveBuffers(); + allowedBufferTypes |= config->allowedBufferTypes(); + if(minimumActivity == -1 || config->minimumActivity() < minimumActivity) + minimumActivity = config->minimumActivity(); + } + QSet availableBuffers = Client::networkModel()->allBufferIds().toSet(); + buffers.intersect(availableBuffers); + tempRemovedBuffers.intersect(availableBuffers); } changed |= (addBuffersAutomatically != _addBuffersAutomatically); @@ -161,6 +215,8 @@ void BufferViewOverlay::updateHelper() { _removedBuffers = removedBuffers; _tempRemovedBuffers = tempRemovedBuffers; + _aboutToUpdate = false; + if(changed) emit hasChanged(); } @@ -168,6 +224,50 @@ void BufferViewOverlay::updateHelper() { void BufferViewOverlay::customEvent(QEvent *event) { if(event->type() == _updateEventId) { updateHelper(); - _aboutToUpdate = false; } } + +bool BufferViewOverlay::allNetworks() { + updateHelper(); + return _networkIds.contains(NetworkId()); +} + +const QSet &BufferViewOverlay::networkIds() { + updateHelper(); + return _networkIds; +} + +const QSet &BufferViewOverlay::bufferIds() { + updateHelper(); + return _buffers; +} + +const QSet &BufferViewOverlay::removedBufferIds() { + updateHelper(); + return _removedBuffers; +} + +const QSet &BufferViewOverlay::tempRemovedBufferIds() { + updateHelper(); + return _tempRemovedBuffers; +} + +bool BufferViewOverlay::addBuffersAutomatically() { + updateHelper(); + return _addBuffersAutomatically; +} + +bool BufferViewOverlay::hideInactiveBuffers() { + updateHelper(); + return _hideInactiveBuffers; +} + +int BufferViewOverlay::allowedBufferTypes() { + updateHelper(); + return _allowedBufferTypes; +} + +int BufferViewOverlay::minimumActivity() { + updateHelper(); + return _minimumActivity; +}