X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fclient%2Fclient.cpp;h=019c67c97f7a2e1d479b18d1e1658b6608edcffa;hp=de3b5d1bd200db3e14bd866988b10e3b3eadb2fd;hb=fa00b68a21c777682d9feb37ade6b3904fc19d92;hpb=a540a0285feef171e16fd6225b0e045fc5fc52e4 diff --git a/src/client/client.cpp b/src/client/client.cpp index de3b5d1b..019c67c9 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -27,15 +27,22 @@ #include "buffersettings.h" #include "buffersyncer.h" #include "bufferviewconfig.h" -#include "bufferviewmanager.h" +#include "bufferviewoverlay.h" +#include "clientaliasmanager.h" #include "clientbacklogmanager.h" +#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" @@ -45,10 +52,14 @@ #include QPointer Client::instanceptr = 0; -AccountId Client::_currentCoreAccount = 0; /*** Initialization/destruction ***/ +bool Client::instanceExists() +{ + return instanceptr; +} + Client *Client::instance() { if(!instanceptr) instanceptr = new Client(); @@ -75,14 +86,18 @@ Client::Client(QObject *parent) _networkModel(0), _bufferModel(0), _bufferSyncer(0), + _aliasManager(0), _backlogManager(new ClientBacklogManager(this)), _bufferViewManager(0), + _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); @@ -93,7 +108,6 @@ Client::~Client() { } void Client::init() { - _currentCoreAccount = 0; _networkModel = new NetworkModel(this); connect(this, SIGNAL(networkRemoved(NetworkId)), @@ -102,6 +116,7 @@ void Client::init() { _bufferModel = new BufferModel(_networkModel); _messageModel = mainUi()->createMessageModel(this); _messageProcessor = mainUi()->createMessageProcessor(this); + _inputHandler = new ClientUserInputHandler(this); SignalProxy *p = signalProxy(); @@ -109,7 +124,7 @@ void Client::init() { p->attachSlot(SIGNAL(displayStatusMsg(QString, QString)), this, SLOT(recvStatusMsg(QString, QString))); p->attachSlot(SIGNAL(bufferInfoUpdated(BufferInfo)), _networkModel, SLOT(bufferUpdated(BufferInfo))); - p->attachSignal(this, SIGNAL(sendInput(BufferInfo, QString))); + p->attachSignal(inputHandler(), SIGNAL(sendInput(BufferInfo, QString))); p->attachSignal(this, SIGNAL(requestNetworkStates())); p->attachSignal(this, SIGNAL(requestCreateIdentity(const Identity &, const QVariantMap &)), SIGNAL(createIdentity(const Identity &, const QVariantMap &))); @@ -122,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())); @@ -132,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 ***/ @@ -140,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 ***/ @@ -263,23 +277,36 @@ void Client::coreIdentityRemoved(IdentityId id) { } } -/*** ***/ -void Client::userInput(BufferInfo bufferInfo, QString message) { - emit instance()->sendInput(bufferInfo, message); +/*** User input handling ***/ + +void Client::userInput(const BufferInfo &bufferInfo, const QString &message) { + // we need to make sure that AliasManager is ready before processing input + if(aliasManager() && aliasManager()->isInitialized()) + inputHandler()->handleUserInput(bufferInfo, message); + else + instance()-> _userInputBuffer.append(qMakePair(bufferInfo, message)); +} + +void Client::sendBufferedUserInput() { + for(int i = 0; i < _userInputBuffer.count(); i++) + userInput(_userInputBuffer.at(i).first, _userInputBuffer.at(i).second); + + _userInputBuffer.clear(); } /*** 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() { @@ -291,70 +318,66 @@ 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 BufferViewManager(signalProxy(), this); - connect(bufferViewManager(), SIGNAL(initDone()), this, SLOT(requestInitialBacklog())); + _bufferViewManager = new ClientBufferViewManager(signalProxy(), this); connect(bufferViewManager(), SIGNAL(initDone()), this, SLOT(createDefaultBufferView())); - createDefaultIdentity(); - createDefaultNetworks(); + // create AliasManager + Q_ASSERT(!_aliasManager); + _aliasManager = new ClientAliasManager(this); + 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); } 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() { 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::createDefaultIdentity() { - if(_identities.isEmpty()) { - Identity identity; - identity.setToDefaults(); - identity.setIdentityName(tr("Default Identity")); - createIdentity(identity); - } -} - -void Client::createDefaultNetworks() { - if(_networks.isEmpty()) { - QStringList defaultNets = Network::presetNetworks(true); - foreach(QString net, defaultNets) { - NetworkInfo info = Network::networkInfoFromPreset(net); - if(info.networkName.isEmpty()) - continue; - QStringList defaultChans = Network::presetDefaultChannels(net); - createNetwork(info, defaultChans); - } - } -} - 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); @@ -362,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(); @@ -374,6 +396,18 @@ void Client::disconnectedFromCore() { _bufferViewManager = 0; } + if(_aliasManager) { + _aliasManager->deleteLater(); + _aliasManager = 0; + } + + if(_ignoreListManager) { + _ignoreListManager->deleteLater(); + _ignoreListManager = 0; + } + // we probably don't want to save pending input for reconnect + _userInputBuffer.clear(); + _messageModel->clear(); _networkModel->clear(); @@ -396,6 +430,10 @@ void Client::disconnectedFromCore() { } Q_ASSERT(_identities.isEmpty()); + if(_networkConfig) { + _networkConfig->deleteLater(); + _networkConfig = 0; + } } /*** ***/ @@ -446,6 +484,12 @@ void Client::mergeBuffersPermanently(BufferId bufferId1, BufferId bufferId2) { bufferSyncer()->requestMergeBuffersPermanently(bufferId1, bufferId2); } +void Client::purgeKnownBufferIds() { + if(!bufferSyncer()) + return; + bufferSyncer()->requestPurgeBufferIds(); +} + void Client::bufferRemoved(BufferId bufferId) { // select a sane buffer (status buffer) /* we have to manually select a buffer because otherwise inconsitent changes @@ -484,8 +528,13 @@ void Client::logMessage(QtMsgType type, const char *msg) { Quassel::logFatalMessage(msg); } else { QString msgString = QString("%1\n").arg(msg); + + //Check to see if there is an instance around, else we risk recursions + //when calling instance() and creating new ones. + if (!instanceExists()) + return; + instance()->_debugLog << msgString; emit instance()->logUpdated(msgString); } } -