X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;f=src%2Fclient%2Fbufferviewoverlay.cpp;h=66dec133f941989e783761f613b30a983f8a3cd9;hb=8aa25a7c1526915741a7da989cc0a663bd84eb31;hp=f07c4a3afe54142155769a6f85fd639f8d9ecfaa;hpb=f48d855945219c3a1897a17bf15830dfee104f0b;p=quassel.git diff --git a/src/client/bufferviewoverlay.cpp b/src/client/bufferviewoverlay.cpp index f07c4a3a..66dec133 100644 --- a/src/client/bufferviewoverlay.cpp +++ b/src/client/bufferviewoverlay.cpp @@ -22,9 +22,10 @@ #include -#include "client.h" #include "bufferviewconfig.h" +#include "client.h" #include "clientbufferviewmanager.h" +#include "networkmodel.h" const int BufferViewOverlay::_updateEventId = QEvent::registerEventType(); @@ -50,7 +51,7 @@ void BufferViewOverlay::addView(int viewId) { _bufferViewIds << viewId; if(config->isInitialized()) { - update(); + viewInitialized(config); } else { disconnect(config, SIGNAL(initDone()), this, SLOT(viewInitialized())); connect(config, SIGNAL(initDone()), this, SLOT(viewInitialized())); @@ -62,25 +63,48 @@ void BufferViewOverlay::removeView(int viewId) { return; _bufferViewIds.remove(viewId); + BufferViewConfig *config = qobject_cast(sender()); + if(config) + disconnect(config, 0, this, 0); update(); } -void BufferViewOverlay::viewInitialized() { - BufferViewConfig *config = qobject_cast(sender()); - Q_ASSERT(config); - +void BufferViewOverlay::viewInitialized(BufferViewConfig *config) { + if(!config) { + qWarning() << "BufferViewOverlay::viewInitialized() received invalid view!"; + return; + } 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())); + // check if the view was removed in the meantime... if(_bufferViewIds.contains(config->bufferViewId())) update(); } +void BufferViewOverlay::viewInitialized() { + BufferViewConfig *config = qobject_cast(sender()); + Q_ASSERT(config); + + viewInitialized(config); +} + void BufferViewOverlay::update() { if(_aboutToUpdate) { return; } _aboutToUpdate = true; + QCoreApplication::postEvent(this, new QEvent((QEvent::Type)_updateEventId)); } void BufferViewOverlay::updateHelper() { @@ -94,24 +118,50 @@ void BufferViewOverlay::updateHelper() { QSet buffers; 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; - - networkIds << config->networkId(); - buffers += config->bufferList().toSet(); - removedBuffers += config->removedBuffers(); - tempRemovedBuffers += config->temporarilyRemovedBuffers(); - - addBuffersAutomatically |= config->addNewBuffersAutomatically(); - hideInactiveBuffers &= config->hideInactiveBuffers(); - allowedBufferTypes |= config->allowedBufferTypes(); - if(minimumActivity == -1 || config->minimumActivity() < minimumActivity) - minimumActivity = config->minimumActivity(); + + 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(); + 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(); + } } changed |= (addBuffersAutomatically != _addBuffersAutomatically); @@ -131,7 +181,7 @@ void BufferViewOverlay::updateHelper() { _buffers = buffers; _removedBuffers = removedBuffers; _tempRemovedBuffers = tempRemovedBuffers; - + if(changed) emit hasChanged(); }