Fixes #913 - Core backlog download does not start until main window is unhidden
authorMarcus Eggenberger <egs@quassel-irc.org>
Sat, 24 Apr 2010 22:11:57 +0000 (00:11 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Tue, 11 May 2010 21:06:19 +0000 (23:06 +0200)
src/client/bufferviewoverlay.cpp
src/client/bufferviewoverlay.h
src/client/client.cpp
src/client/client.h
src/client/clientbacklogmanager.cpp
src/client/clientbacklogmanager.h
src/client/clientbufferviewmanager.cpp
src/client/clientbufferviewmanager.h
src/client/clientsettings.cpp
src/client/clientsettings.h
src/qtui/mainwin.cpp

index f4b2985..ee5fab0 100644 (file)
@@ -24,6 +24,7 @@
 
 #include "bufferviewconfig.h"
 #include "client.h"
 
 #include "bufferviewconfig.h"
 #include "client.h"
+#include "clientbacklogmanager.h"
 #include "clientbufferviewmanager.h"
 #include "networkmodel.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<int> currentIds = _bufferViewIds;
+  reset();
+  currentIds += CoreAccountSettings().bufferViewOverlay();
+
+  QSet<int>::const_iterator iter;
+  for(iter = currentIds.constBegin(); iter != currentIds.constEnd(); iter++) {
+    addView(*iter);
+  }
+}
+
 void BufferViewOverlay::addView(int viewId) {
   if(_bufferViewIds.contains(viewId))
     return;
 void BufferViewOverlay::addView(int viewId) {
   if(_bufferViewIds.contains(viewId))
     return;
@@ -49,15 +80,36 @@ void BufferViewOverlay::addView(int viewId) {
   }
 
   _bufferViewIds << viewId;
   }
 
   _bufferViewIds << viewId;
+  bool wasInitialized = isInitialized();
   _uninitializedViewCount++;
   _uninitializedViewCount++;
+
   if(config->isInitialized()) {
     viewInitialized(config);
   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);
   }
   } 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) {
 }
 
 void BufferViewOverlay::removeView(int viewId) {
@@ -87,6 +139,7 @@ void BufferViewOverlay::removeView(int viewId) {
   update();
   if(!wasInitialized && isInitialized())
     emit initDone();
   update();
   if(!wasInitialized && isInitialized())
     emit initDone();
+  save();
 }
 
 void BufferViewOverlay::viewInitialized(BufferViewConfig *config) {
 }
 
 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()));
   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()))
 
   // check if the view was removed in the meantime...
   if(_bufferViewIds.contains(config->bufferViewId()))
index 204e553..313a2e3 100644 (file)
@@ -51,6 +51,10 @@ public slots:
   void addView(int viewId);
   void removeView(int viewId);
 
   void addView(int viewId);
   void removeView(int viewId);
 
+  void reset();
+  void save();
+  void restore();
+
   // updates propagated from the actual views
   void update();
 
   // updates propagated from the actual views
   void update();
 
index b1b28ee..228d4df 100644 (file)
@@ -328,7 +328,7 @@ void Client::setSyncedToCore() {
   // create a new BufferViewManager
   Q_ASSERT(!_bufferViewManager);
   _bufferViewManager = new ClientBufferViewManager(signalProxy(), this);
   // 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);
 
   // 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()) {
   // 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;
   }
     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() {
 }
 
 void Client::disconnectFromCore() {
@@ -404,6 +398,8 @@ void Client::setDisconnectedFromCore() {
     _bufferViewManager = 0;
   }
 
     _bufferViewManager = 0;
   }
 
+  _bufferViewOverlay->reset();
+
   if(_aliasManager) {
     _aliasManager->deleteLater();
     _aliasManager = 0;
   if(_aliasManager) {
     _aliasManager->deleteLater();
     _aliasManager = 0;
index 30ef2d9..ab413b8 100644 (file)
@@ -202,7 +202,6 @@ private slots:
   void coreNetworkRemoved(NetworkId);
 
   void requestInitialBacklog();
   void coreNetworkRemoved(NetworkId);
 
   void requestInitialBacklog();
-  void createDefaultBufferView();
 
   void sendBufferedUserInput();
 
 
   void sendBufferedUserInput();
 
index f851b8c..8b6e2e4 100644 (file)
@@ -32,7 +32,8 @@
 INIT_SYNCABLE_OBJECT(ClientBacklogManager)
 ClientBacklogManager::ClientBacklogManager(QObject *parent)
   : BacklogManager(parent),
 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() {
 }
 
 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;
   }
 
     return;
   }
 
@@ -98,6 +100,7 @@ void ClientBacklogManager::requestInitialBacklog() {
   };
 
   _requester->requestInitialBacklog();
   };
 
   _requester->requestInitialBacklog();
+  _initBacklogRequested = true;
   if(_requester->isBuffering()) {
     updateProgress(0, _requester->totalBuffers());
   }
   if(_requester->isBuffering()) {
     updateProgress(0, _requester->totalBuffers());
   }
@@ -115,9 +118,14 @@ BufferIdList ClientBacklogManager::filterNewBufferIds(const BufferIdList &buffer
 }
 
 void ClientBacklogManager::checkForBacklog(const QList<BufferId> &bufferIds) {
 }
 
 void ClientBacklogManager::checkForBacklog(const QList<BufferId> &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.
   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()) {
     return;
   }
   switch(_requester->type()) {
@@ -156,5 +164,6 @@ void ClientBacklogManager::dispatchMessages(const MessageList &messages, bool so
 void ClientBacklogManager::reset() {
   delete _requester;
   _requester = 0;
 void ClientBacklogManager::reset() {
   delete _requester;
   _requester = 0;
+  _initBacklogRequested = false;
   _buffersRequested.clear();
 }
   _buffersRequested.clear();
 }
index f52eb16..f4a7b90 100644 (file)
@@ -62,6 +62,7 @@ private:
   void dispatchMessages(const MessageList &messages, bool sort = false);
 
   BacklogRequester *_requester;
   void dispatchMessages(const MessageList &messages, bool sort = false);
 
   BacklogRequester *_requester;
+  bool _initBacklogRequested;
   QSet<BufferId> _buffersRequested;
 };
 
   QSet<BufferId> _buffersRequested;
 };
 
index 166cda1..504604f 100644 (file)
@@ -21,6 +21,8 @@
 #include "clientbufferviewmanager.h"
 
 #include "clientbufferviewconfig.h"
 #include "clientbufferviewmanager.h"
 
 #include "clientbufferviewconfig.h"
+#include "client.h"
+#include "networkmodel.h"
 
 INIT_SYNCABLE_OBJECT(ClientBufferViewManager)
 ClientBufferViewManager::ClientBufferViewManager(SignalProxy *proxy, QObject *parent)
 
 INIT_SYNCABLE_OBJECT(ClientBufferViewManager)
 ClientBufferViewManager::ClientBufferViewManager(SignalProxy *proxy, QObject *parent)
@@ -43,3 +45,13 @@ QList<ClientBufferViewConfig *> ClientBufferViewManager::clientBufferViewConfigs
 ClientBufferViewConfig *ClientBufferViewManager::clientBufferViewConfig(int bufferViewId) const {
   return static_cast<ClientBufferViewConfig *>(bufferViewConfig(bufferViewId));
 }
 ClientBufferViewConfig *ClientBufferViewManager::clientBufferViewConfig(int bufferViewId) const {
   return static_cast<ClientBufferViewConfig *>(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();
+}
index 912c540..a413a8f 100644 (file)
@@ -36,6 +36,9 @@ public:
   QList<ClientBufferViewConfig *> clientBufferViewConfigs() const;
   ClientBufferViewConfig *clientBufferViewConfig(int bufferViewId) const;
 
   QList<ClientBufferViewConfig *> clientBufferViewConfigs() const;
   ClientBufferViewConfig *clientBufferViewConfig(int bufferViewId) const;
 
+public slots:
+  virtual void setInitialized();
+
 protected:
   virtual BufferViewConfig *bufferViewConfigFactory(int bufferViewConfigId);
 };
 protected:
   virtual BufferViewConfig *bufferViewConfigFactory(int bufferViewConfigId);
 };
index dc03468..a7d42b5 100644 (file)
@@ -167,6 +167,24 @@ QHash<int, BufferId> CoreAccountSettings::jumpKeyMap() {
   return keyMap;
 }
 
   return keyMap;
 }
 
+void CoreAccountSettings::setBufferViewOverlay(const QSet<int> &viewIds) {
+  QVariantList variants;
+  foreach(int viewId, viewIds) {
+    variants << qVariantFromValue(viewId);
+  }
+  setAccountValue("BufferViewOverlay", variants);
+}
+
+QSet<int> CoreAccountSettings::bufferViewOverlay() {
+  QSet<int> 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()));
 }
 void CoreAccountSettings::removeAccount(AccountId id) {
   removeLocalKey(QString("%1").arg(id.toInt()));
 }
index 3ae5ae4..40e890d 100644 (file)
@@ -73,6 +73,9 @@ public:
   void setJumpKeyMap(const QHash<int, BufferId> &keyMap);
   QHash<int, BufferId> jumpKeyMap();
 
   void setJumpKeyMap(const QHash<int, BufferId> &keyMap);
   QHash<int, BufferId> jumpKeyMap();
 
+  void setBufferViewOverlay(const QSet<int> &viewIds);
+  QSet<int> bufferViewOverlay();
+
   void setAccountValue(const QString &key, const QVariant &data);
   QVariant accountValue(const QString &key, const QVariant &def = QVariant());
 
   void setAccountValue(const QString &key, const QVariant &data);
   QVariant accountValue(const QString &key, const QVariant &def = QVariant());
 
index e1d961c..9c58f75 100644 (file)
@@ -491,6 +491,11 @@ void MainWin::removeBufferView(int bufferViewConfigId) {
 }
 
 void MainWin::bufferViewToggled(bool enabled) {
 }
 
 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<QAction *>(sender());
   Q_ASSERT(action);
   BufferViewDock *dock = qobject_cast<BufferViewDock *>(action->parent());
   QAction *action = qobject_cast<QAction *>(sender());
   Q_ASSERT(action);
   BufferViewDock *dock = qobject_cast<BufferViewDock *>(action->parent());
@@ -502,23 +507,6 @@ void MainWin::bufferViewToggled(bool enabled) {
 
   if(enabled) {
     Client::bufferViewOverlay()->addView(dock->bufferViewId());
 
   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());
   }
   } else {
     Client::bufferViewOverlay()->removeView(dock->bufferViewId());
   }
@@ -801,7 +789,6 @@ void MainWin::disconnectedFromCore() {
     if(dock && actionData.toInt() != -1) {
       removeAction(action);
       _bufferViews.removeAll(dock);
     if(dock && actionData.toInt() != -1) {
       removeAction(action);
       _bufferViews.removeAll(dock);
-      Client::bufferViewOverlay()->removeView(dock->bufferViewId());
       dock->deleteLater();
     }
   }
       dock->deleteLater();
     }
   }