X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fclient%2Fclient.cpp;h=019c67c97f7a2e1d479b18d1e1658b6608edcffa;hp=733ba543459eaf34f19d732168742b2ddf4d0aa3;hb=fa00b68a21c777682d9feb37ade6b3904fc19d92;hpb=e2667bcfa59d0a3b7843235dd6235d912cc0c992 diff --git a/src/client/client.cpp b/src/client/client.cpp index 733ba543..019c67c9 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -33,12 +33,16 @@ #include "clientbufferviewmanager.h" #include "clientirclisthelper.h" #include "clientidentity.h" +#include "clientignorelistmanager.h" #include "clientuserinputhandler.h" +#include "coreaccountmodel.h" +#include "coreconnection.h" #include "ircchannel.h" #include "ircuser.h" #include "message.h" #include "messagemodel.h" #include "network.h" +#include "networkconfig.h" #include "networkmodel.h" #include "quassel.h" #include "signalproxy.h" @@ -48,7 +52,6 @@ #include QPointer Client::instanceptr = 0; -AccountId Client::_currentCoreAccount = 0; /*** Initialization/destruction ***/ @@ -89,11 +92,12 @@ Client::Client(QObject *parent) _bufferViewOverlay(new BufferViewOverlay(this)), _ircListHelper(new ClientIrcListHelper(this)), _inputHandler(0), + _networkConfig(0), + _ignoreListManager(0), _messageModel(0), _messageProcessor(0), - _connectedToCore(false), - _syncedToCore(false), - _internalCore(false), + _coreAccountModel(new CoreAccountModel(this)), + _coreConnection(new CoreConnection(_coreAccountModel, this)), _debugLog(&_debugLogBuffer) { _signalProxy->synchronize(_ircListHelper); @@ -104,7 +108,6 @@ Client::~Client() { } void Client::init() { - _currentCoreAccount = 0; _networkModel = new NetworkModel(this); connect(this, SIGNAL(networkRemoved(NetworkId)), @@ -134,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())); @@ -144,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 ***/ @@ -152,20 +158,16 @@ AbstractUi *Client::mainUi() { return instance()->_mainUi; } -AccountId Client::currentCoreAccount() { - return _currentCoreAccount; -} - -void Client::setCurrentCoreAccount(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 ***/ @@ -294,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() { @@ -329,10 +332,19 @@ void Client::setSyncedToCore() { connect(aliasManager(), SIGNAL(initDone()), SLOT(sendBufferedUserInput())); signalProxy()->synchronize(aliasManager()); + // create NetworkConfig + Q_ASSERT(!_networkConfig); + _networkConfig = new NetworkConfig("GlobalNetworkConfig", this); + signalProxy()->synchronize(networkConfig()); + + // create IgnoreListManager + Q_ASSERT(!_ignoreListManager); + _ignoreListManager = new ClientIgnoreListManager(this); + signalProxy()->synchronize(ignoreListManager()); + // trigger backlog request once all active bufferviews are initialized connect(bufferViewOverlay(), SIGNAL(initDone()), this, SLOT(requestInitialBacklog())); - _syncedToCore = true; emit connected(); emit coreConnectionStateChanged(true); } @@ -352,22 +364,20 @@ void Client::requestInitialBacklog() { void Client::createDefaultBufferView() { if(bufferViewManager()->bufferViewConfigs().isEmpty()) { BufferViewConfig config(-1); - config.setBufferViewName(tr("All Buffers")); + config.setBufferViewName(tr("All Chats")); config.initSetBufferList(networkModel()->allBufferIdsSorted()); bufferViewManager()->requestCreateBufferView(config.toVariantMap()); } } 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); @@ -375,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(); @@ -392,6 +401,10 @@ void Client::disconnectedFromCore() { _aliasManager = 0; } + if(_ignoreListManager) { + _ignoreListManager->deleteLater(); + _ignoreListManager = 0; + } // we probably don't want to save pending input for reconnect _userInputBuffer.clear(); @@ -417,6 +430,10 @@ void Client::disconnectedFromCore() { } Q_ASSERT(_identities.isEmpty()); + if(_networkConfig) { + _networkConfig->deleteLater(); + _networkConfig = 0; + } } /*** ***/ @@ -521,4 +538,3 @@ void Client::logMessage(QtMsgType type, const char *msg) { emit instance()->logUpdated(msgString); } } -