X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fclient%2Fbufferviewoverlay.cpp;h=ee5fab0b87972e5cff38bf2e60f8553287d4c7aa;hp=cba8035a7389d7de9a12ef12d99d147e9c00f404;hb=02b4f33429788d35500454bfb5a8a9ab0a2a2b49;hpb=7fc418e5841a1633f651e08a34ccd2123ba6e0db diff --git a/src/client/bufferviewoverlay.cpp b/src/client/bufferviewoverlay.cpp index cba8035a..ee5fab0b 100644 --- a/src/client/bufferviewoverlay.cpp +++ b/src/client/bufferviewoverlay.cpp @@ -24,6 +24,7 @@ #include "bufferviewconfig.h" #include "client.h" +#include "clientbacklogmanager.h" #include "clientbufferviewmanager.h" #include "networkmodel.h" @@ -32,13 +33,42 @@ const int BufferViewOverlay::_updateEventId = QEvent::registerEventType(); BufferViewOverlay::BufferViewOverlay(QObject *parent) : QObject(parent), _aboutToUpdate(false), - _addBuffersAutomatically(false), - _hideInactiveBuffers(false), + _uninitializedViewCount(0), _allowedBufferTypes(0), _minimumActivity(0) { } +void BufferViewOverlay::reset() { + _aboutToUpdate = false; + + _bufferViewIds.clear(); + _uninitializedViewCount = 0; + + _networkIds.clear(); + _allowedBufferTypes = 0; + _minimumActivity = 0; + + _buffers.clear(); + _removedBuffers.clear(); + _tempRemovedBuffers.clear(); +} + +void BufferViewOverlay::save() { + CoreAccountSettings().setBufferViewOverlay(_bufferViewIds); +} + +void BufferViewOverlay::restore() { + QSet currentIds = _bufferViewIds; + reset(); + currentIds += CoreAccountSettings().bufferViewOverlay(); + + QSet::const_iterator iter; + for(iter = currentIds.constBegin(); iter != currentIds.constEnd(); iter++) { + addView(*iter); + } +} + void BufferViewOverlay::addView(int viewId) { if(_bufferViewIds.contains(viewId)) return; @@ -50,12 +80,36 @@ void BufferViewOverlay::addView(int viewId) { } _bufferViewIds << viewId; + bool wasInitialized = isInitialized(); + _uninitializedViewCount++; + if(config->isInitialized()) { viewInitialized(config); + + if(wasInitialized) { + BufferIdList buffers; + if(config->networkId().isValid()) { + foreach(BufferId bufferId, config->bufferList()) { + if(Client::networkModel()->networkId(bufferId) == config->networkId()) + buffers << bufferId; + } + foreach(BufferId bufferId, config->temporarilyRemovedBuffers().toList()) { + if(Client::networkModel()->networkId(bufferId) == config->networkId()) + buffers << bufferId; + } + } else { + buffers = BufferIdList::fromSet(config->bufferList().toSet() + config->temporarilyRemovedBuffers()); + } + Client::backlogManager()->checkForBacklog(buffers); + } + } 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); } + save(); } void BufferViewOverlay::removeView(int viewId) { @@ -63,10 +117,29 @@ 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(); + save(); } void BufferViewOverlay::viewInitialized(BufferViewConfig *config) { @@ -76,20 +149,15 @@ 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())); // check if the view was removed in the meantime... if(_bufferViewIds.contains(config->bufferViewId())) update(); + + _uninitializedViewCount--; + if(isInitialized()) + emit initDone(); } void BufferViewOverlay::viewInitialized() { @@ -113,8 +181,6 @@ void BufferViewOverlay::updateHelper() { bool changed = false; - bool addBuffersAutomatically = false; - bool hideInactiveBuffers = true; int allowedBufferTypes = 0; int minimumActivity = -1; QSet networkIds; @@ -130,48 +196,32 @@ void BufferViewOverlay::updateHelper() { if(!config) continue; - 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; - - 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(); + + networkIds << config->networkId(); + + + // we have to apply several filters before we can add a buffer to a category (visible, removed, ...) + buffers += filterBuffersByConfig(config->bufferList(), config); + tempRemovedBuffers += filterBuffersByConfig(config->temporarilyRemovedBuffers().toList(), config); + removedBuffers += config->removedBuffers(); } + + // prune the sets from overlap QSet availableBuffers = Client::networkModel()->allBufferIds().toSet(); + buffers.intersect(availableBuffers); + tempRemovedBuffers.intersect(availableBuffers); + tempRemovedBuffers.subtract(buffers); + + removedBuffers.intersect(availableBuffers); + removedBuffers.subtract(tempRemovedBuffers); + removedBuffers.subtract(buffers); } - changed |= (addBuffersAutomatically != _addBuffersAutomatically); - changed |= (hideInactiveBuffers != _hideInactiveBuffers); changed |= (allowedBufferTypes != _allowedBufferTypes); changed |= (minimumActivity != _minimumActivity); changed |= (networkIds != _networkIds); @@ -179,8 +229,6 @@ void BufferViewOverlay::updateHelper() { changed |= (removedBuffers != _removedBuffers); changed |= (tempRemovedBuffers != _tempRemovedBuffers); - _addBuffersAutomatically = addBuffersAutomatically; - _hideInactiveBuffers = hideInactiveBuffers; _allowedBufferTypes = allowedBufferTypes; _minimumActivity = minimumActivity; _networkIds = networkIds; @@ -194,6 +242,24 @@ void BufferViewOverlay::updateHelper() { emit hasChanged(); } +QSet BufferViewOverlay::filterBuffersByConfig(const QList &buffers, const BufferViewConfig *config) { + Q_ASSERT(config); + + QSet bufferIds; + BufferInfo bufferInfo; + foreach(BufferId bufferId, buffers) { + bufferInfo = Client::networkModel()->bufferInfo(bufferId); + if(!(bufferInfo.type() & config->allowedBufferTypes())) + continue; + if(config->networkId().isValid() && bufferInfo.networkId() != config->networkId()) + continue; + bufferIds << bufferId; + } + + return bufferIds; +} + + void BufferViewOverlay::customEvent(QEvent *event) { if(event->type() == _updateEventId) { updateHelper(); @@ -225,16 +291,6 @@ const QSet &BufferViewOverlay::tempRemovedBufferIds() { return _tempRemovedBuffers; } -bool BufferViewOverlay::addBuffersAutomatically() { - updateHelper(); - return _addBuffersAutomatically; -} - -bool BufferViewOverlay::hideInactiveBuffers() { - updateHelper(); - return _hideInactiveBuffers; -} - int BufferViewOverlay::allowedBufferTypes() { updateHelper(); return _allowedBufferTypes;