From: Marcus Eggenberger Date: Sat, 24 Apr 2010 22:11:57 +0000 (+0200) Subject: Fixes #913 - Core backlog download does not start until main window is unhidden X-Git-Tag: 0.6.2~17 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=02b4f33429788d35500454bfb5a8a9ab0a2a2b49;ds=sidebyside Fixes #913 - Core backlog download does not start until main window is unhidden --- diff --git a/src/client/bufferviewoverlay.cpp b/src/client/bufferviewoverlay.cpp index f4b29857..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" @@ -38,6 +39,36 @@ BufferViewOverlay::BufferViewOverlay(QObject *parent) { } +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; @@ -49,15 +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())); // 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) { @@ -87,6 +139,7 @@ void BufferViewOverlay::removeView(int viewId) { update(); if(!wasInitialized && isInitialized()) emit initDone(); + save(); } void BufferViewOverlay::viewInitialized(BufferViewConfig *config) { @@ -97,14 +150,6 @@ void BufferViewOverlay::viewInitialized(BufferViewConfig *config) { disconnect(config, SIGNAL(initDone()), this, SLOT(viewInitialized())); connect(config, SIGNAL(configChanged()), this, SLOT(update())); -// connect(config, SIGNAL(networkIdSet(const NetworkId &)), this, SLOT(update())); -// connect(config, SIGNAL(sortAlphabeticallySet(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())) diff --git a/src/client/bufferviewoverlay.h b/src/client/bufferviewoverlay.h index 204e5530..313a2e30 100644 --- a/src/client/bufferviewoverlay.h +++ b/src/client/bufferviewoverlay.h @@ -51,6 +51,10 @@ public slots: void addView(int viewId); void removeView(int viewId); + void reset(); + void save(); + void restore(); + // updates propagated from the actual views void update(); diff --git a/src/client/client.cpp b/src/client/client.cpp index b1b28ee2..228d4df3 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -328,7 +328,7 @@ void Client::setSyncedToCore() { // create a new BufferViewManager Q_ASSERT(!_bufferViewManager); _bufferViewManager = new ClientBufferViewManager(signalProxy(), this); - connect(bufferViewManager(), SIGNAL(initDone()), this, SLOT(createDefaultBufferView())); + connect(_bufferViewManager, SIGNAL(initDone()), _bufferViewOverlay, SLOT(restore())); // create AliasManager Q_ASSERT(!_aliasManager); @@ -359,20 +359,14 @@ void Client::requestInitialBacklog() { // triggers this slot. But we have to make sure that we know all buffers yet. // so we check the BufferSyncer and in case it wasn't initialized we wait for that instead if(!bufferSyncer()->isInitialized()) { - connect(bufferViewOverlay(), SIGNAL(initDone()), this, SLOT(requestInitialBacklog())); + disconnect(bufferViewOverlay(), SIGNAL(initDone()), this, SLOT(requestInitialBacklog())); connect(bufferSyncer(), SIGNAL(initDone()), this, SLOT(requestInitialBacklog())); return; } - _backlogManager->requestInitialBacklog(); -} + disconnect(bufferViewOverlay(), SIGNAL(initDone()), this, SLOT(requestInitialBacklog())); + disconnect(bufferSyncer(), SIGNAL(initDone()), this, SLOT(requestInitialBacklog())); -void Client::createDefaultBufferView() { - if(bufferViewManager()->bufferViewConfigs().isEmpty()) { - BufferViewConfig config(-1); - config.setBufferViewName(tr("All Chats")); - config.initSetBufferList(networkModel()->allBufferIdsSorted()); - bufferViewManager()->requestCreateBufferView(config.toVariantMap()); - } + _backlogManager->requestInitialBacklog(); } void Client::disconnectFromCore() { @@ -404,6 +398,8 @@ void Client::setDisconnectedFromCore() { _bufferViewManager = 0; } + _bufferViewOverlay->reset(); + if(_aliasManager) { _aliasManager->deleteLater(); _aliasManager = 0; diff --git a/src/client/client.h b/src/client/client.h index 30ef2d9f..ab413b80 100644 --- a/src/client/client.h +++ b/src/client/client.h @@ -202,7 +202,6 @@ private slots: void coreNetworkRemoved(NetworkId); void requestInitialBacklog(); - void createDefaultBufferView(); void sendBufferedUserInput(); diff --git a/src/client/clientbacklogmanager.cpp b/src/client/clientbacklogmanager.cpp index f851b8ca..8b6e2e47 100644 --- a/src/client/clientbacklogmanager.cpp +++ b/src/client/clientbacklogmanager.cpp @@ -32,7 +32,8 @@ INIT_SYNCABLE_OBJECT(ClientBacklogManager) ClientBacklogManager::ClientBacklogManager(QObject *parent) : BacklogManager(parent), - _requester(0) + _requester(0), + _initBacklogRequested(false) { } @@ -79,8 +80,9 @@ void ClientBacklogManager::receiveBacklogAll(MsgId first, MsgId last, int limit, } void ClientBacklogManager::requestInitialBacklog() { - if(_requester && !_buffersRequested.isEmpty()) { - // qWarning() << "ClientBacklogManager::requestInitialBacklog() called twice in the same session! (Backlog has already been requested)"; + if(_initBacklogRequested) { + Q_ASSERT(_requester); + qWarning() << "ClientBacklogManager::requestInitialBacklog() called twice in the same session! (Backlog has already been requested)"; return; } @@ -98,6 +100,7 @@ void ClientBacklogManager::requestInitialBacklog() { }; _requester->requestInitialBacklog(); + _initBacklogRequested = true; if(_requester->isBuffering()) { updateProgress(0, _requester->totalBuffers()); } @@ -115,9 +118,14 @@ BufferIdList ClientBacklogManager::filterNewBufferIds(const BufferIdList &buffer } void ClientBacklogManager::checkForBacklog(const QList &bufferIds) { + // we ingore all backlogrequests until we had our initial request + if(!_initBacklogRequested) { + return; + } + if(!_requester) { // during client start up this message is to be expected in some situations. - qDebug() << "ClientBacklogManager::checkForBacklog(): no active backlog requester (yet?)."; + qDebug() << "ClientBacklogManager::checkForBacklog(): no active backlog requester."; return; } switch(_requester->type()) { @@ -156,5 +164,6 @@ void ClientBacklogManager::dispatchMessages(const MessageList &messages, bool so void ClientBacklogManager::reset() { delete _requester; _requester = 0; + _initBacklogRequested = false; _buffersRequested.clear(); } diff --git a/src/client/clientbacklogmanager.h b/src/client/clientbacklogmanager.h index f52eb164..f4a7b905 100644 --- a/src/client/clientbacklogmanager.h +++ b/src/client/clientbacklogmanager.h @@ -62,6 +62,7 @@ private: void dispatchMessages(const MessageList &messages, bool sort = false); BacklogRequester *_requester; + bool _initBacklogRequested; QSet _buffersRequested; }; diff --git a/src/client/clientbufferviewmanager.cpp b/src/client/clientbufferviewmanager.cpp index 166cda1f..504604f5 100644 --- a/src/client/clientbufferviewmanager.cpp +++ b/src/client/clientbufferviewmanager.cpp @@ -21,6 +21,8 @@ #include "clientbufferviewmanager.h" #include "clientbufferviewconfig.h" +#include "client.h" +#include "networkmodel.h" INIT_SYNCABLE_OBJECT(ClientBufferViewManager) ClientBufferViewManager::ClientBufferViewManager(SignalProxy *proxy, QObject *parent) @@ -43,3 +45,13 @@ QList ClientBufferViewManager::clientBufferViewConfigs ClientBufferViewConfig *ClientBufferViewManager::clientBufferViewConfig(int bufferViewId) const { return static_cast(bufferViewConfig(bufferViewId)); } + +void ClientBufferViewManager::setInitialized() { + if(bufferViewConfigs().isEmpty()) { + BufferViewConfig config(-1); + config.setBufferViewName(tr("All Chats")); + config.initSetBufferList(Client::networkModel()->allBufferIdsSorted()); + requestCreateBufferView(config.toVariantMap()); + } + BufferViewManager::setInitialized(); +} diff --git a/src/client/clientbufferviewmanager.h b/src/client/clientbufferviewmanager.h index 912c5405..a413a8f6 100644 --- a/src/client/clientbufferviewmanager.h +++ b/src/client/clientbufferviewmanager.h @@ -36,6 +36,9 @@ public: QList clientBufferViewConfigs() const; ClientBufferViewConfig *clientBufferViewConfig(int bufferViewId) const; +public slots: + virtual void setInitialized(); + protected: virtual BufferViewConfig *bufferViewConfigFactory(int bufferViewConfigId); }; diff --git a/src/client/clientsettings.cpp b/src/client/clientsettings.cpp index dc03468d..a7d42b5d 100644 --- a/src/client/clientsettings.cpp +++ b/src/client/clientsettings.cpp @@ -167,6 +167,24 @@ QHash CoreAccountSettings::jumpKeyMap() { return keyMap; } +void CoreAccountSettings::setBufferViewOverlay(const QSet &viewIds) { + QVariantList variants; + foreach(int viewId, viewIds) { + variants << qVariantFromValue(viewId); + } + setAccountValue("BufferViewOverlay", variants); +} + +QSet CoreAccountSettings::bufferViewOverlay() { + QSet viewIds; + QVariantList variants = accountValue("BufferViewOverlay").toList(); + QVariantList::const_iterator iter = variants.constBegin(); + for(QVariantList::const_iterator iter = variants.constBegin(); iter != variants.constEnd(); iter++) { + viewIds << iter->toInt(); + } + return viewIds; +} + void CoreAccountSettings::removeAccount(AccountId id) { removeLocalKey(QString("%1").arg(id.toInt())); } diff --git a/src/client/clientsettings.h b/src/client/clientsettings.h index 3ae5ae43..40e890db 100644 --- a/src/client/clientsettings.h +++ b/src/client/clientsettings.h @@ -73,6 +73,9 @@ public: void setJumpKeyMap(const QHash &keyMap); QHash jumpKeyMap(); + void setBufferViewOverlay(const QSet &viewIds); + QSet bufferViewOverlay(); + void setAccountValue(const QString &key, const QVariant &data); QVariant accountValue(const QString &key, const QVariant &def = QVariant()); diff --git a/src/qtui/mainwin.cpp b/src/qtui/mainwin.cpp index e1d961cd..9c58f75f 100644 --- a/src/qtui/mainwin.cpp +++ b/src/qtui/mainwin.cpp @@ -491,6 +491,11 @@ void MainWin::removeBufferView(int bufferViewConfigId) { } void MainWin::bufferViewToggled(bool enabled) { + if(!enabled && !isVisible()) { + // hiding the mainwindow triggers a toggle of the bufferview (which pretty much sucks big time) + // since this isn't our fault and we can't do anything about it, we suppress the resulting calls + return; + } QAction *action = qobject_cast(sender()); Q_ASSERT(action); BufferViewDock *dock = qobject_cast(action->parent()); @@ -502,23 +507,6 @@ void MainWin::bufferViewToggled(bool enabled) { if(enabled) { Client::bufferViewOverlay()->addView(dock->bufferViewId()); - BufferViewConfig *config = dock->config(); - if(config && config->isInitialized()) { - 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 { Client::bufferViewOverlay()->removeView(dock->bufferViewId()); } @@ -801,7 +789,6 @@ void MainWin::disconnectedFromCore() { if(dock && actionData.toInt() != -1) { removeAction(action); _bufferViews.removeAll(dock); - Client::bufferViewOverlay()->removeView(dock->bufferViewId()); dock->deleteLater(); } }