minor refactoring on how backlog requests are triggered
[quassel.git] / src / client / client.cpp
index ca219bb..733ba54 100644 (file)
@@ -27,6 +27,7 @@
 #include "buffersettings.h"
 #include "buffersyncer.h"
 #include "bufferviewconfig.h"
+#include "bufferviewoverlay.h"
 #include "clientaliasmanager.h"
 #include "clientbacklogmanager.h"
 #include "clientbufferviewmanager.h"
@@ -85,6 +86,7 @@ Client::Client(QObject *parent)
     _aliasManager(0),
     _backlogManager(new ClientBacklogManager(this)),
     _bufferViewManager(0),
+    _bufferViewOverlay(new BufferViewOverlay(this)),
     _ircListHelper(new ClientIrcListHelper(this)),
     _inputHandler(0),
     _messageModel(0),
@@ -313,14 +315,12 @@ void Client::setSyncedToCore() {
   connect(bufferSyncer(), SIGNAL(bufferRenamed(BufferId, QString)), this, SLOT(bufferRenamed(BufferId, QString)));
   connect(bufferSyncer(), SIGNAL(buffersPermanentlyMerged(BufferId, BufferId)), this, SLOT(buffersPermanentlyMerged(BufferId, BufferId)));
   connect(bufferSyncer(), SIGNAL(buffersPermanentlyMerged(BufferId, BufferId)), _messageModel, SLOT(buffersPermanentlyMerged(BufferId, BufferId)));
-  connect(bufferSyncer(), SIGNAL(initDone()), this, SLOT(requestInitialBacklog()));
   connect(networkModel(), SIGNAL(setLastSeenMsg(BufferId, MsgId)), bufferSyncer(), SLOT(requestSetLastSeenMsg(BufferId, const MsgId &)));
   signalProxy()->synchronize(bufferSyncer());
 
   // create a new BufferViewManager
   Q_ASSERT(!_bufferViewManager);
   _bufferViewManager = new ClientBufferViewManager(signalProxy(), this);
-  connect(bufferViewManager(), SIGNAL(initDone()), this, SLOT(requestInitialBacklog()));
   connect(bufferViewManager(), SIGNAL(initDone()), this, SLOT(createDefaultBufferView()));
 
   // create AliasManager
@@ -329,14 +329,24 @@ void Client::setSyncedToCore() {
   connect(aliasManager(), SIGNAL(initDone()), SLOT(sendBufferedUserInput()));
   signalProxy()->synchronize(aliasManager());
 
+  // trigger backlog request once all active bufferviews are initialized
+  connect(bufferViewOverlay(), SIGNAL(initDone()), this, SLOT(requestInitialBacklog()));
+
   _syncedToCore = true;
   emit connected();
   emit coreConnectionStateChanged(true);
 }
 
 void Client::requestInitialBacklog() {
-  if(bufferViewManager()->isInitialized() && bufferSyncer()->isInitialized())
-    Client::backlogManager()->requestInitialBacklog();
+  // usually it _should_ take longer until the bufferViews are initialized, so that's what
+  // 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()));
+    connect(bufferSyncer(), SIGNAL(initDone()), this, SLOT(requestInitialBacklog()));
+    return;
+  }
+  _backlogManager->requestInitialBacklog();
 }
 
 void Client::createDefaultBufferView() {