Handle client state a bit more sanely
authorManuel Nickschas <sputnick@quassel-irc.org>
Thu, 19 Nov 2009 23:10:08 +0000 (00:10 +0100)
committerManuel Nickschas <sputnick@quassel-irc.org>
Sat, 28 Nov 2009 23:39:41 +0000 (00:39 +0100)
Client can only be disconnected or connected. In the latter state, we guarantee
that the typical connection-specific (syncable) objects at least exist (but may not
be fully synced yet).

It doesn't make much sense API-wise to distinguish between "connected" and "synced" state
of the Client object, as vital objects are created after being connected. In any case,
more detailed information is available via Client::coreConnection().

src/client/client.cpp
src/client/client.h
src/qtui/chatview.cpp

index 019c67c..84d28ec 100644 (file)
@@ -98,6 +98,7 @@ Client::Client(QObject *parent)
     _messageProcessor(0),
     _coreAccountModel(new CoreAccountModel(this)),
     _coreConnection(new CoreConnection(_coreAccountModel, this)),
+    _connected(false),
     _debugLog(&_debugLogBuffer)
 {
   _signalProxy->synchronize(_ircListHelper);
@@ -159,11 +160,7 @@ AbstractUi *Client::mainUi() {
 }
 
 bool Client::isConnected() {
-  return coreConnection()->state() >= CoreConnection::Connected;
-}
-
-bool Client::isSynced() {
-  return coreConnection()->state() == CoreConnection::Synchronized;
+  return instance()->_connected;
 }
 
 bool Client::internalCore() {
@@ -345,6 +342,7 @@ void Client::setSyncedToCore() {
   // trigger backlog request once all active bufferviews are initialized
   connect(bufferViewOverlay(), SIGNAL(initDone()), this, SLOT(requestInitialBacklog()));
 
+  _connected = true;
   emit connected();
   emit coreConnectionStateChanged(true);
 }
@@ -378,6 +376,7 @@ void Client::disconnectFromCore() {
 }
 
 void Client::setDisconnectedFromCore() {
+  _connected = false;
   emit disconnected();
   emit coreConnectionStateChanged(false);
 
index a516e25..56083a9 100644 (file)
@@ -120,7 +120,6 @@ public:
   static inline CoreAccount currentCoreAccount() { return coreConnection()->currentAccount(); }
 
   static bool isConnected();
-  static bool isSynced();
   static bool internalCore();
 
   static void userInput(const BufferInfo &bufferInfo, const QString &message);
@@ -230,6 +229,8 @@ private:
   QHash<NetworkId, Network *> _networks;
   QHash<IdentityId, Identity *> _identities;
 
+  bool _connected;
+
   QString _debugLogBuffer;
   QTextStream _debugLog;
 
index f8fe6b8..e7386ef 100644 (file)
@@ -78,7 +78,7 @@ void ChatView::init(MessageFilter *filter) {
   connect(verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(verticalScrollbarChanged(int)));
 
   // only connect if client is synched with a core
-  if(Client::isSynced())
+  if(Client::isConnected())
     connect(Client::ignoreListManager(), SIGNAL(ignoreListChanged()), this, SLOT(invalidateFilter()));
 }
 
@@ -91,8 +91,8 @@ bool ChatView::event(QEvent *event) {
     case Qt::Key_PageUp:
     case Qt::Key_PageDown:
       if(!verticalScrollBar()->isVisible()) {
-       scene()->requestBacklog();
-       return true;
+        scene()->requestBacklog();
+        return true;
       }
     default:
       break;