Switch over to CoreConnection
authorManuel Nickschas <sputnick@quassel-irc.org>
Thu, 19 Nov 2009 17:34:36 +0000 (18:34 +0100)
committerManuel Nickschas <sputnick@quassel-irc.org>
Sat, 28 Nov 2009 23:39:41 +0000 (00:39 +0100)
Stop using ClientSyncer, and adapt to the new API introduced by
CoreConnection.

src/client/client.cpp
src/client/client.h
src/client/clientsettings.cpp
src/qtui/mainwin.cpp
src/qtui/qtuiapplication.cpp

index 2f308b9..019c67c 100644 (file)
@@ -36,6 +36,7 @@
 #include "clientignorelistmanager.h"
 #include "clientuserinputhandler.h"
 #include "coreaccountmodel.h"
 #include "clientignorelistmanager.h"
 #include "clientuserinputhandler.h"
 #include "coreaccountmodel.h"
+#include "coreconnection.h"
 #include "ircchannel.h"
 #include "ircuser.h"
 #include "message.h"
 #include "ircchannel.h"
 #include "ircuser.h"
 #include "message.h"
@@ -51,7 +52,6 @@
 #include <stdlib.h>
 
 QPointer<Client> Client::instanceptr = 0;
 #include <stdlib.h>
 
 QPointer<Client> Client::instanceptr = 0;
-AccountId Client::_currentCoreAccount = 0;
 
 /*** Initialization/destruction ***/
 
 
 /*** Initialization/destruction ***/
 
@@ -97,9 +97,7 @@ Client::Client(QObject *parent)
     _messageModel(0),
     _messageProcessor(0),
     _coreAccountModel(new CoreAccountModel(this)),
     _messageModel(0),
     _messageProcessor(0),
     _coreAccountModel(new CoreAccountModel(this)),
-    _connectedToCore(false),
-    _syncedToCore(false),
-    _internalCore(false),
+    _coreConnection(new CoreConnection(_coreAccountModel, this)),
     _debugLog(&_debugLogBuffer)
 {
   _signalProxy->synchronize(_ircListHelper);
     _debugLog(&_debugLogBuffer)
 {
   _signalProxy->synchronize(_ircListHelper);
@@ -110,7 +108,6 @@ Client::~Client() {
 }
 
 void Client::init() {
 }
 
 void Client::init() {
-  _currentCoreAccount = 0;
   _networkModel = new NetworkModel(this);
 
   connect(this, SIGNAL(networkRemoved(NetworkId)),
   _networkModel = new NetworkModel(this);
 
   connect(this, SIGNAL(networkRemoved(NetworkId)),
@@ -120,7 +117,6 @@ void Client::init() {
   _messageModel = mainUi()->createMessageModel(this);
   _messageProcessor = mainUi()->createMessageProcessor(this);
   _inputHandler = new ClientUserInputHandler(this);
   _messageModel = mainUi()->createMessageModel(this);
   _messageProcessor = mainUi()->createMessageProcessor(this);
   _inputHandler = new ClientUserInputHandler(this);
-  _coreAccountModel->load();
 
   SignalProxy *p = signalProxy();
 
 
   SignalProxy *p = signalProxy();
 
@@ -141,8 +137,6 @@ void Client::init() {
   p->attachSlot(SIGNAL(networkCreated(NetworkId)), this, SLOT(coreNetworkCreated(NetworkId)));
   p->attachSlot(SIGNAL(networkRemoved(NetworkId)), this, SLOT(coreNetworkRemoved(NetworkId)));
 
   p->attachSlot(SIGNAL(networkCreated(NetworkId)), this, SLOT(coreNetworkCreated(NetworkId)));
   p->attachSlot(SIGNAL(networkRemoved(NetworkId)), this, SLOT(coreNetworkRemoved(NetworkId)));
 
-  connect(p, SIGNAL(disconnected()), this, SLOT(disconnectedFromCore()));
-
   //connect(mainUi(), SIGNAL(connectToCore(const QVariantMap &)), this, SLOT(connectToCore(const QVariantMap &)));
   connect(mainUi(), SIGNAL(disconnectFromCore()), this, SLOT(disconnectFromCore()));
   connect(this, SIGNAL(connected()), mainUi(), SLOT(connectedToCore()));
   //connect(mainUi(), SIGNAL(connectToCore(const QVariantMap &)), this, SLOT(connectToCore(const QVariantMap &)));
   connect(mainUi(), SIGNAL(disconnectFromCore()), this, SLOT(disconnectFromCore()));
   connect(this, SIGNAL(connected()), mainUi(), SLOT(connectedToCore()));
@@ -151,6 +145,11 @@ void Client::init() {
   // attach backlog manager
   p->synchronize(backlogManager());
   connect(backlogManager(), SIGNAL(messagesReceived(BufferId, int)), _messageModel, SLOT(messagesReceived(BufferId, int)));
   // attach backlog manager
   p->synchronize(backlogManager());
   connect(backlogManager(), SIGNAL(messagesReceived(BufferId, int)), _messageModel, SLOT(messagesReceived(BufferId, int)));
+
+  coreAccountModel()->load();
+
+  connect(coreConnection(), SIGNAL(stateChanged(CoreConnection::ConnectionState)), SLOT(connectionStateChanged(CoreConnection::ConnectionState)));
+  coreConnection()->init();
 }
 
 /*** public static methods ***/
 }
 
 /*** public static methods ***/
@@ -159,20 +158,16 @@ AbstractUi *Client::mainUi() {
   return instance()->_mainUi;
 }
 
   return instance()->_mainUi;
 }
 
-AccountId Client::currentCoreAccount() {
-  return _currentCoreAccount;
-}
-
-void Client::setCurrentCoreAccount(const AccountId &id) {
-  _currentCoreAccount = id;
-}
-
 bool Client::isConnected() {
 bool Client::isConnected() {
-  return instance()->_connectedToCore;
+  return coreConnection()->state() >= CoreConnection::Connected;
 }
 
 bool Client::isSynced() {
 }
 
 bool Client::isSynced() {
-  return instance()->_syncedToCore;
+  return coreConnection()->state() == CoreConnection::Synchronized;
+}
+
+bool Client::internalCore() {
+  return currentCoreAccount().isInternal();
 }
 
 /*** Network handling ***/
 }
 
 /*** Network handling ***/
@@ -301,16 +296,17 @@ void Client::sendBufferedUserInput() {
 
 /*** core connection stuff ***/
 
 
 /*** core connection stuff ***/
 
-void Client::setConnectedToCore(AccountId id, QIODevice *socket) {
-  if(socket) { // external core
-    // if the socket is an orphan, the signalProxy adopts it.
-    // -> we don't need to care about it anymore
-    socket->setParent(0);
-    signalProxy()->addPeer(socket);
+void Client::connectionStateChanged(CoreConnection::ConnectionState state) {
+  switch(state) {
+  case CoreConnection::Disconnected:
+    setDisconnectedFromCore();
+    break;
+  case CoreConnection::Synchronized:
+    setSyncedToCore();
+    break;
+  default:
+    break;
   }
   }
-  _internalCore = !socket;
-  _connectedToCore = true;
-  setCurrentCoreAccount(id);
 }
 
 void Client::setSyncedToCore() {
 }
 
 void Client::setSyncedToCore() {
@@ -349,7 +345,6 @@ void Client::setSyncedToCore() {
   // trigger backlog request once all active bufferviews are initialized
   connect(bufferViewOverlay(), SIGNAL(initDone()), this, SLOT(requestInitialBacklog()));
 
   // trigger backlog request once all active bufferviews are initialized
   connect(bufferViewOverlay(), SIGNAL(initDone()), this, SLOT(requestInitialBacklog()));
 
-  _syncedToCore = true;
   emit connected();
   emit coreConnectionStateChanged(true);
 }
   emit connected();
   emit coreConnectionStateChanged(true);
 }
@@ -376,15 +371,13 @@ void Client::createDefaultBufferView() {
 }
 
 void Client::disconnectFromCore() {
 }
 
 void Client::disconnectFromCore() {
-  if(!isConnected())
+  if(!coreConnection()->isConnected())
     return;
 
     return;
 
-  signalProxy()->removeAllPeers();
+  coreConnection()->disconnectFromCore();
 }
 
 }
 
-void Client::disconnectedFromCore() {
-  _connectedToCore = false;
-  _syncedToCore = false;
+void Client::setDisconnectedFromCore() {
   emit disconnected();
   emit coreConnectionStateChanged(false);
 
   emit disconnected();
   emit coreConnectionStateChanged(false);
 
@@ -392,7 +385,6 @@ void Client::disconnectedFromCore() {
   messageProcessor()->reset();
 
   // Clear internal data. Hopefully nothing relies on it at this point.
   messageProcessor()->reset();
 
   // Clear internal data. Hopefully nothing relies on it at this point.
-  setCurrentCoreAccount(0);
 
   if(_bufferSyncer) {
     _bufferSyncer->deleteLater();
 
   if(_bufferSyncer) {
     _bufferSyncer->deleteLater();
index ff6b4d8..a516e25 100644 (file)
@@ -25,6 +25,7 @@
 #include <QPointer>
 
 #include "bufferinfo.h"
 #include <QPointer>
 
 #include "bufferinfo.h"
+#include "coreconnection.h"
 #include "types.h"
 
 class Message;
 #include "types.h"
 
 class Message;
@@ -46,9 +47,9 @@ class ClientBacklogManager;
 class ClientBufferViewManager;
 class ClientIgnoreListManager;
 class ClientIrcListHelper;
 class ClientBufferViewManager;
 class ClientIgnoreListManager;
 class ClientIrcListHelper;
-class ClientSyncer;
 class ClientUserInputHandler;
 class CoreAccountModel;
 class ClientUserInputHandler;
 class CoreAccountModel;
+class CoreConnection;
 class IrcUser;
 class IrcChannel;
 class NetworkConfig;
 class IrcUser;
 class IrcChannel;
 class NetworkConfig;
@@ -115,11 +116,12 @@ public:
   static inline ClientIgnoreListManager *ignoreListManager() { return instance()->_ignoreListManager; }
 
   static inline CoreAccountModel *coreAccountModel() { return instance()->_coreAccountModel; }
   static inline ClientIgnoreListManager *ignoreListManager() { return instance()->_ignoreListManager; }
 
   static inline CoreAccountModel *coreAccountModel() { return instance()->_coreAccountModel; }
-  static AccountId currentCoreAccount();
+  static inline CoreConnection *coreConnection() { return instance()->_coreConnection; }
+  static inline CoreAccount currentCoreAccount() { return coreConnection()->currentAccount(); }
 
   static bool isConnected();
   static bool isSynced();
 
   static bool isConnected();
   static bool isSynced();
-  static inline bool internalCore() { return instance()->_internalCore; }
+  static bool internalCore();
 
   static void userInput(const BufferInfo &bufferInfo, const QString &message);
 
 
   static void userInput(const BufferInfo &bufferInfo, const QString &message);
 
@@ -132,8 +134,6 @@ public:
   static void logMessage(QtMsgType type, const char *msg);
   static inline const QString &debugLog() { return instance()->_debugLogBuffer; }
 
   static void logMessage(QtMsgType type, const char *msg);
   static inline const QString &debugLog() { return instance()->_debugLogBuffer; }
 
-  static inline void registerClientSyncer(ClientSyncer *syncer) { emit instance()->newClientSyncer(syncer); }
-
 signals:
   void requestNetworkStates();
 
 signals:
   void requestNetworkStates();
 
@@ -167,8 +167,6 @@ signals:
   void requestCreateNetwork(const NetworkInfo &info, const QStringList &persistentChannels = QStringList());
   void requestRemoveNetwork(NetworkId);
 
   void requestCreateNetwork(const NetworkInfo &info, const QStringList &persistentChannels = QStringList());
   void requestRemoveNetwork(NetworkId);
 
-  void newClientSyncer(ClientSyncer *);
-
   void logUpdated(const QString &msg);
 
 public slots:
   void logUpdated(const QString &msg);
 
 public slots:
@@ -179,7 +177,9 @@ public slots:
   void buffersPermanentlyMerged(BufferId bufferId1, BufferId bufferId2);
 
 private slots:
   void buffersPermanentlyMerged(BufferId bufferId1, BufferId bufferId2);
 
 private slots:
-  void disconnectedFromCore();
+  void setSyncedToCore();
+  void setDisconnectedFromCore();
+  void connectionStateChanged(CoreConnection::ConnectionState);
 
   void recvMessage(const Message &message);
   void recvStatusMsg(QString network, QString message);
 
   void recvMessage(const Message &message);
   void recvStatusMsg(QString network, QString message);
@@ -190,8 +190,6 @@ private slots:
   void coreNetworkCreated(NetworkId);
   void coreNetworkRemoved(NetworkId);
 
   void coreNetworkCreated(NetworkId);
   void coreNetworkRemoved(NetworkId);
 
-  void setConnectedToCore(AccountId id, QIODevice *socket = 0);
-  void setSyncedToCore();
   void requestInitialBacklog();
   void createDefaultBufferView();
 
   void requestInitialBacklog();
   void createDefaultBufferView();
 
@@ -203,7 +201,6 @@ private:
   void init();
 
   static void addNetwork(Network *);
   void init();
 
   static void addNetwork(Network *);
-  static void setCurrentCoreAccount(const AccountId &);
   static inline BufferSyncer *bufferSyncer() { return instance()->_bufferSyncer; }
 
   static QPointer<Client> instanceptr;
   static inline BufferSyncer *bufferSyncer() { return instance()->_bufferSyncer; }
 
   static QPointer<Client> instanceptr;
@@ -226,23 +223,19 @@ private:
   AbstractMessageProcessor *_messageProcessor;
 
   CoreAccountModel *_coreAccountModel;
   AbstractMessageProcessor *_messageProcessor;
 
   CoreAccountModel *_coreAccountModel;
+  CoreConnection *_coreConnection;
 
   ClientMode clientMode;
 
 
   ClientMode clientMode;
 
-  bool _connectedToCore, _syncedToCore;
-  bool _internalCore;
-
   QHash<NetworkId, Network *> _networks;
   QHash<IdentityId, Identity *> _identities;
 
   QHash<NetworkId, Network *> _networks;
   QHash<IdentityId, Identity *> _identities;
 
-  static AccountId _currentCoreAccount;
-
   QString _debugLogBuffer;
   QTextStream _debugLog;
 
   QList<QPair<BufferInfo, QString> > _userInputBuffer;
 
   QString _debugLogBuffer;
   QTextStream _debugLog;
 
   QList<QPair<BufferInfo, QString> > _userInputBuffer;
 
-  friend class ClientSyncer;
+  friend class CoreConnection;
 };
 
 #endif
 };
 
 #endif
index 664ee4c..6f9961f 100644 (file)
@@ -47,7 +47,7 @@ CoreAccountSettings::CoreAccountSettings(const QString &subgroup)
 }
 
 void CoreAccountSettings::notify(const QString &key, QObject *receiver, const char *slot) {
 }
 
 void CoreAccountSettings::notify(const QString &key, QObject *receiver, const char *slot) {
-  ClientSettings::notify(QString("%1/%2/%3").arg(Client::currentCoreAccount().toInt()).arg(_subgroup).arg(key), receiver, slot);
+  ClientSettings::notify(QString("%1/%2/%3").arg(Client::currentCoreAccount().accountId().toInt()).arg(_subgroup).arg(key), receiver, slot);
 }
 
 QList<AccountId> CoreAccountSettings::knownAccounts() {
 }
 
 QList<AccountId> CoreAccountSettings::knownAccounts() {
@@ -120,13 +120,13 @@ QVariantMap CoreAccountSettings::retrieveAccountData(AccountId id) {
 void CoreAccountSettings::setAccountValue(const QString &key, const QVariant &value) {
   if(!Client::currentCoreAccount().isValid())
     return;
 void CoreAccountSettings::setAccountValue(const QString &key, const QVariant &value) {
   if(!Client::currentCoreAccount().isValid())
     return;
-  setLocalValue(QString("%1/%2/%3").arg(Client::currentCoreAccount().toInt()).arg(_subgroup).arg(key), value);
+  setLocalValue(QString("%1/%2/%3").arg(Client::currentCoreAccount().accountId().toInt()).arg(_subgroup).arg(key), value);
 }
 
 QVariant CoreAccountSettings::accountValue(const QString &key, const QVariant &def) {
   if(!Client::currentCoreAccount().isValid())
     return QVariant();
 }
 
 QVariant CoreAccountSettings::accountValue(const QString &key, const QVariant &def) {
   if(!Client::currentCoreAccount().isValid())
     return QVariant();
-  return localValue(QString("%1/%2/%3").arg(Client::currentCoreAccount().toInt()).arg(_subgroup).arg(key), def);
+  return localValue(QString("%1/%2/%3").arg(Client::currentCoreAccount().accountId().toInt()).arg(_subgroup).arg(key), def);
 }
 
 void CoreAccountSettings::setJumpKeyMap(const QHash<int, BufferId> &keyMap) {
 }
 
 void CoreAccountSettings::setJumpKeyMap(const QHash<int, BufferId> &keyMap) {
index df1a7dc..6e6b851 100644 (file)
 #include "chatmonitorview.h"
 #include "chatview.h"
 #include "client.h"
 #include "chatmonitorview.h"
 #include "chatview.h"
 #include "client.h"
-#include "clientsyncer.h"
 #include "clientbacklogmanager.h"
 #include "clientbufferviewconfig.h"
 #include "clientbufferviewmanager.h"
 #include "clientignorelistmanager.h"
 #include "clientbacklogmanager.h"
 #include "clientbufferviewconfig.h"
 #include "clientbufferviewmanager.h"
 #include "clientignorelistmanager.h"
+#include "coreconnection.h"
 #include "coreinfodlg.h"
 #include "contextmenuactionprovider.h"
 #include "debugbufferviewoverlay.h"
 #include "coreinfodlg.h"
 #include "contextmenuactionprovider.h"
 #include "debugbufferviewoverlay.h"
@@ -215,6 +215,7 @@ void MainWin::init() {
   } else {
     startInternalCore();
   }
   } else {
     startInternalCore();
   }
+  Client::coreConnection()->start();
 }
 
 MainWin::~MainWin() {
 }
 
 MainWin::~MainWin() {
@@ -646,6 +647,8 @@ void MainWin::setupStatusBar() {
 
   connect(showStatusbar, SIGNAL(toggled(bool)), statusBar(), SLOT(setVisible(bool)));
   connect(showStatusbar, SIGNAL(toggled(bool)), this, SLOT(saveStatusBarStatus(bool)));
 
   connect(showStatusbar, SIGNAL(toggled(bool)), statusBar(), SLOT(setVisible(bool)));
   connect(showStatusbar, SIGNAL(toggled(bool)), this, SLOT(saveStatusBarStatus(bool)));
+
+  connect(Client::coreConnection(), SIGNAL(connectionMsg(QString)), statusBar(), SLOT(showMessage(QString)));
 }
 
 void MainWin::setupHotList() {
 }
 
 void MainWin::setupHotList() {
@@ -746,7 +749,7 @@ void MainWin::setConnectedState() {
 
 void MainWin::loadLayout() {
   QtUiSettings s;
 
 void MainWin::loadLayout() {
   QtUiSettings s;
-  int accountId = Client::currentCoreAccount().toInt();
+  int accountId = Client::currentCoreAccount().accountId().toInt();
   QByteArray state = s.value(QString("MainWinState-%1").arg(accountId)).toByteArray();
   if(state.isEmpty()) {
     // Make sure that the default bufferview is shown
   QByteArray state = s.value(QString("MainWinState-%1").arg(accountId)).toByteArray();
   if(state.isEmpty()) {
     // Make sure that the default bufferview is shown
@@ -761,7 +764,7 @@ void MainWin::loadLayout() {
 
 void MainWin::saveLayout() {
   QtUiSettings s;
 
 void MainWin::saveLayout() {
   QtUiSettings s;
-  int accountId = Client::currentCoreAccount().toInt();
+  int accountId = Client::currentCoreAccount().accountId().toInt();
   if(accountId > 0) s.setValue(QString("MainWinState-%1").arg(accountId) , saveState(accountId));
 }
 
   if(accountId > 0) s.setValue(QString("MainWinState-%1").arg(accountId) , saveState(accountId));
 }
 
index de989bb..1d80204 100644 (file)
@@ -138,7 +138,7 @@ void QtUiApplication::commitData(QSessionManager &manager) {
 
 void QtUiApplication::saveState(QSessionManager & manager) {
   //qDebug() << QString("saving session state to id %1").arg(manager.sessionId());
 
 void QtUiApplication::saveState(QSessionManager & manager) {
   //qDebug() << QString("saving session state to id %1").arg(manager.sessionId());
-  AccountId activeCore = Client::currentCoreAccount(); // FIXME store this!
+  AccountId activeCore = Client::currentCoreAccount().accountId(); // FIXME store this!
   SessionSettings s(manager.sessionId());
   s.setSessionAge(0);
   QtUi::mainWindow()->saveStateToSettings(s);
   SessionSettings s(manager.sessionId());
   s.setSessionAge(0);
   QtUi::mainWindow()->saveStateToSettings(s);