X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fclient%2Fclient.cpp;h=019c67c97f7a2e1d479b18d1e1658b6608edcffa;hp=2f308b9f0fc11f83a236a50ecd8da35c55fa0071;hb=fa00b68a21c777682d9feb37ade6b3904fc19d92;hpb=11444d0219a994969c633f62543f7ef302f43300 diff --git a/src/client/client.cpp b/src/client/client.cpp index 2f308b9f..019c67c9 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -36,6 +36,7 @@ #include "clientignorelistmanager.h" #include "clientuserinputhandler.h" #include "coreaccountmodel.h" +#include "coreconnection.h" #include "ircchannel.h" #include "ircuser.h" #include "message.h" @@ -51,7 +52,6 @@ #include QPointer Client::instanceptr = 0; -AccountId Client::_currentCoreAccount = 0; /*** Initialization/destruction ***/ @@ -97,9 +97,7 @@ Client::Client(QObject *parent) _messageModel(0), _messageProcessor(0), _coreAccountModel(new CoreAccountModel(this)), - _connectedToCore(false), - _syncedToCore(false), - _internalCore(false), + _coreConnection(new CoreConnection(_coreAccountModel, this)), _debugLog(&_debugLogBuffer) { _signalProxy->synchronize(_ircListHelper); @@ -110,7 +108,6 @@ Client::~Client() { } void Client::init() { - _currentCoreAccount = 0; _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); - _coreAccountModel->load(); 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))); - 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())); @@ -151,6 +145,11 @@ void Client::init() { // 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 ***/ @@ -159,20 +158,16 @@ AbstractUi *Client::mainUi() { return instance()->_mainUi; } -AccountId Client::currentCoreAccount() { - return _currentCoreAccount; -} - -void Client::setCurrentCoreAccount(const AccountId &id) { - _currentCoreAccount = id; -} - bool Client::isConnected() { - return instance()->_connectedToCore; + return coreConnection()->state() >= CoreConnection::Connected; } bool Client::isSynced() { - return instance()->_syncedToCore; + return coreConnection()->state() == CoreConnection::Synchronized; +} + +bool Client::internalCore() { + return currentCoreAccount().isInternal(); } /*** Network handling ***/ @@ -301,16 +296,17 @@ void Client::sendBufferedUserInput() { /*** 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() { @@ -349,7 +345,6 @@ void Client::setSyncedToCore() { // trigger backlog request once all active bufferviews are initialized connect(bufferViewOverlay(), SIGNAL(initDone()), this, SLOT(requestInitialBacklog())); - _syncedToCore = true; emit connected(); emit coreConnectionStateChanged(true); } @@ -376,15 +371,13 @@ void Client::createDefaultBufferView() { } void Client::disconnectFromCore() { - if(!isConnected()) + if(!coreConnection()->isConnected()) return; - signalProxy()->removeAllPeers(); + coreConnection()->disconnectFromCore(); } -void Client::disconnectedFromCore() { - _connectedToCore = false; - _syncedToCore = false; +void Client::setDisconnectedFromCore() { 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. - setCurrentCoreAccount(0); if(_bufferSyncer) { _bufferSyncer->deleteLater();