X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;f=src%2Fclient%2Fbufferviewoverlay.cpp;h=b1938d1120f5ac131a65d1a68587f41fdf78f29a;hb=e81c540673301a969cd8265c67334c4bd2b8f2ab;hp=4ec4123914701c2b0f7b10318ba8a611201fed3d;hpb=92f256c9ef102ef5af61164bb17b63e501510541;p=quassel.git diff --git a/src/client/bufferviewoverlay.cpp b/src/client/bufferviewoverlay.cpp index 4ec41239..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; @@ -125,9 +156,28 @@ void BufferViewOverlay::updateHelper() { config = Client::bufferViewManager()->bufferViewConfig(*viewIter); if(!config) continue; + networkIds << config->networkId(); - buffers += config->bufferList().toSet(); - tempRemovedBuffers += config->temporarilyRemovedBuffers(); + 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; + + 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()) @@ -142,6 +192,9 @@ void BufferViewOverlay::updateHelper() { if(minimumActivity == -1 || config->minimumActivity() < minimumActivity) minimumActivity = config->minimumActivity(); } + QSet availableBuffers = Client::networkModel()->allBufferIds().toSet(); + buffers.intersect(availableBuffers); + tempRemovedBuffers.intersect(availableBuffers); } changed |= (addBuffersAutomatically != _addBuffersAutomatically); @@ -162,6 +215,8 @@ void BufferViewOverlay::updateHelper() { _removedBuffers = removedBuffers; _tempRemovedBuffers = tempRemovedBuffers; + _aboutToUpdate = false; + if(changed) emit hasChanged(); } @@ -169,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; +}