X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fclient%2Fclient.cpp;h=575314c113210b0b9a1163d64132168b8f3209a2;hp=9611f71b28fede4fa986d37c752db9bd378cdb76;hb=e5dafe372ae9283c9ecb8fbf9db92c7250fbbcad;hpb=5c6804f291a63f978e328aeddcc8448e3443b45e diff --git a/src/client/client.cpp b/src/client/client.cpp index 9611f71b..575314c1 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -35,10 +35,14 @@ #include "messagemodel.h" #include "network.h" #include "networkmodel.h" +#include "quassel.h" #include "quasselui.h" #include "signalproxy.h" #include "util.h" +#include +#include + QPointer Client::instanceptr = 0; AccountId Client::_currentCoreAccount = 0; @@ -52,22 +56,21 @@ Client *Client::instance() { void Client::destroy() { if(instanceptr) { - delete instanceptr->mainUi; + delete instanceptr->mainUi(); instanceptr->deleteLater(); instanceptr = 0; } } void Client::init(AbstractUi *ui) { - instance()->mainUi = ui; + instance()->_mainUi = ui; instance()->init(); } Client::Client(QObject *parent) : QObject(parent), - socket(0), _signalProxy(new SignalProxy(SignalProxy::Client, this)), - mainUi(0), + _mainUi(0), _networkModel(0), _bufferModel(0), _bufferSyncer(0), @@ -77,7 +80,8 @@ Client::Client(QObject *parent) _messageModel(0), _messageProcessor(0), _connectedToCore(false), - _syncedToCore(false) + _syncedToCore(false), + _debugLog(&_debugLogBuffer) { _signalProxy->synchronize(_ircListHelper); } @@ -94,8 +98,8 @@ void Client::init() { _networkModel, SLOT(networkRemoved(NetworkId))); _bufferModel = new BufferModel(_networkModel); - _messageModel = mainUi->createMessageModel(this); - _messageProcessor = mainUi->createMessageProcessor(this); + _messageModel = mainUi()->createMessageModel(this); + _messageProcessor = mainUi()->createMessageProcessor(this); SignalProxy *p = signalProxy(); @@ -116,17 +120,24 @@ 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(disconnectFromCore())); + 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(this, SIGNAL(disconnected()), mainUi, 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(this, SIGNAL(disconnected()), mainUi(), SLOT(disconnectedFromCore())); + // attach backlog manager + p->synchronize(backlogManager()); + connect(backlogManager(), SIGNAL(messagesReceived(BufferId, int)), _messageModel, SLOT(messagesReceived(BufferId, int))); } /*** public static methods ***/ +AbstractUi *Client::mainUi() { + return instance()->_mainUi; +} + AccountId Client::currentCoreAccount() { return _currentCoreAccount; } @@ -252,9 +263,13 @@ void Client::userInput(BufferInfo bufferInfo, QString message) { /*** core connection stuff ***/ -void Client::setConnectedToCore(QIODevice *sock, AccountId id) { - socket = sock; - signalProxy()->addPeer(socket); +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); + } _connectedToCore = true; setCurrentCoreAccount(id); } @@ -266,19 +281,25 @@ void Client::setSyncedToCore() { connect(bufferSyncer(), SIGNAL(lastSeenMsgSet(BufferId, MsgId)), _networkModel, SLOT(setLastSeenMsgId(BufferId, MsgId))); connect(bufferSyncer(), SIGNAL(bufferRemoved(BufferId)), this, SLOT(bufferRemoved(BufferId))); connect(bufferSyncer(), SIGNAL(bufferRenamed(BufferId, QString)), this, SLOT(bufferRenamed(BufferId, QString))); + connect(bufferSyncer(), SIGNAL(initDone()), this, SLOT(requestInitialBacklog())); + connect(networkModel(), SIGNAL(setLastSeenMsg(BufferId, MsgId)), bufferSyncer(), SLOT(requestSetLastSeenMsg(BufferId, const MsgId &))); signalProxy()->synchronize(bufferSyncer()); - // attach backlog manager - signalProxy()->synchronize(backlogManager()); - // create a new BufferViewManager + Q_ASSERT(!_bufferViewManager); _bufferViewManager = new BufferViewManager(signalProxy(), this); + connect(bufferViewManager(), SIGNAL(initDone()), this, SLOT(requestInitialBacklog())); _syncedToCore = true; emit connected(); emit coreConnectionStateChanged(true); } +void Client::requestInitialBacklog() { + if(bufferViewManager()->isInitialized() && bufferSyncer()->isInitialized()) + Client::backlogManager()->requestInitialBacklog(); +} + void Client::setSecuredConnection() { emit securedConnection(); } @@ -286,12 +307,12 @@ void Client::setSecuredConnection() { void Client::disconnectFromCore() { if(!isConnected()) return; - _connectedToCore = false; - if(socket) { - socket->close(); - socket->deleteLater(); - } + signalProxy()->removeAllPeers(); +} + +void Client::disconnectedFromCore() { + _connectedToCore = false; _syncedToCore = false; emit disconnected(); emit coreConnectionStateChanged(false); @@ -336,10 +357,6 @@ void Client::disconnectFromCore() { } -void Client::setCoreConfiguration(const QVariantMap &settings) { - SignalProxy::writeDataToDevice(socket, settings); -} - /*** ***/ void Client::networkDestroyed() { @@ -360,9 +377,9 @@ void Client::recvStatusMsg(QString /*net*/, QString /*msg*/) { //recvMessage(net, Message::server("", QString("[STATUS] %1").arg(msg))); } -void Client::recvMessage(const Message &msg_) { - Message msg = msg_; - messageProcessor()->process(msg); +void Client::recvMessage(const Message &msg) { + Message msg_ = msg; + messageProcessor()->process(msg_); } void Client::setBufferLastSeenMsg(BufferId id, const MsgId &msgId) { @@ -400,3 +417,16 @@ void Client::bufferRenamed(BufferId bufferId, const QString &newName) { networkModel()->setData(bufferIndex, newName, Qt::DisplayRole); } } + +void Client::logMessage(QtMsgType type, const char *msg) { + fprintf(stderr, "%s\n", msg); + fflush(stderr); + if(type == QtFatalMsg) { + Quassel::logFatalMessage(msg); + } else { + QString msgString = QString("%1\n").arg(msg); + instance()->_debugLog << msgString; + emit instance()->logUpdated(msgString); + } +} +