X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fclient%2Fclient.cpp;h=ca008e907d77f715111f1543e0061b06e730613d;hp=db60bcbc7ec42aa47ac298b7e89c5169b5afd5d8;hb=167ef57a636052f8e18a206e84c3447552e84d2b;hpb=c7c0c7673942be376bbcab06dcc62b7f15e406a2 diff --git a/src/client/client.cpp b/src/client/client.cpp index db60bcbc..ca008e90 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -28,7 +28,6 @@ #include "bufferviewmanager.h" #include "clientbacklogmanager.h" #include "clientirclisthelper.h" -#include "global.h" #include "identity.h" #include "ircchannel.h" #include "ircuser.h" @@ -36,6 +35,7 @@ #include "messagemodel.h" #include "network.h" #include "networkmodel.h" +#include "quassel.h" #include "quasselui.h" #include "signalproxy.h" #include "util.h" @@ -52,8 +52,11 @@ Client *Client::instance() { } void Client::destroy() { - //delete instanceptr; - instanceptr->deleteLater(); + if(instanceptr) { + delete instanceptr->mainUi; + instanceptr->deleteLater(); + instanceptr = 0; + } } void Client::init(AbstractUi *ui) { @@ -63,7 +66,6 @@ void Client::init(AbstractUi *ui) { Client::Client(QObject *parent) : QObject(parent), - socket(0), _signalProxy(new SignalProxy(SignalProxy::Client, this)), mainUi(0), _networkModel(0), @@ -75,13 +77,10 @@ Client::Client(QObject *parent) _messageModel(0), _messageProcessor(0), _connectedToCore(false), - _syncedToCore(false) + _syncedToCore(false), + _debugLog(&_debugLogBuffer) { - _monitorBuffer = new Buffer(BufferInfo(), this); _signalProxy->synchronize(_ircListHelper); - - connect(_backlogManager, SIGNAL(backlog(BufferId, const QVariantList &)), - this, SLOT(receiveBacklog(BufferId, const QVariantList &))); } Client::~Client() { @@ -92,8 +91,6 @@ void Client::init() { _currentCoreAccount = 0; _networkModel = new NetworkModel(this); - connect(this, SIGNAL(bufferUpdated(BufferInfo)), - _networkModel, SLOT(bufferUpdated(BufferInfo))); connect(this, SIGNAL(networkRemoved(NetworkId)), _networkModel, SLOT(networkRemoved(NetworkId))); @@ -106,29 +103,30 @@ void Client::init() { p->attachSlot(SIGNAL(displayMsg(const Message &)), this, SLOT(recvMessage(const Message &))); p->attachSlot(SIGNAL(displayStatusMsg(QString, QString)), this, SLOT(recvStatusMsg(QString, QString))); - p->attachSlot(SIGNAL(bufferInfoUpdated(BufferInfo)), this, SLOT(updateBufferInfo(BufferInfo))); + p->attachSlot(SIGNAL(bufferInfoUpdated(BufferInfo)), _networkModel, SLOT(bufferUpdated(BufferInfo))); p->attachSignal(this, SIGNAL(sendInput(BufferInfo, QString))); p->attachSignal(this, SIGNAL(requestNetworkStates())); p->attachSignal(this, SIGNAL(requestCreateIdentity(const Identity &)), SIGNAL(createIdentity(const Identity &))); - p->attachSignal(this, SIGNAL(requestUpdateIdentity(const Identity &)), SIGNAL(updateIdentity(const Identity &))); p->attachSignal(this, SIGNAL(requestRemoveIdentity(IdentityId)), SIGNAL(removeIdentity(IdentityId))); p->attachSlot(SIGNAL(identityCreated(const Identity &)), this, SLOT(coreIdentityCreated(const Identity &))); p->attachSlot(SIGNAL(identityRemoved(IdentityId)), this, SLOT(coreIdentityRemoved(IdentityId))); p->attachSignal(this, SIGNAL(requestCreateNetwork(const NetworkInfo &)), SIGNAL(createNetwork(const NetworkInfo &))); - p->attachSignal(this, SIGNAL(requestUpdateNetwork(const NetworkInfo &)), SIGNAL(updateNetwork(const NetworkInfo &))); p->attachSignal(this, SIGNAL(requestRemoveNetwork(NetworkId)), SIGNAL(removeNetwork(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(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())); + // attach backlog manager + p->synchronize(backlogManager()); + connect(backlogManager(), SIGNAL(messagesReceived(BufferId, int)), _messageModel, SLOT(messagesReceived(BufferId, int))); } /*** public static methods ***/ @@ -141,56 +139,6 @@ void Client::setCurrentCoreAccount(AccountId id) { _currentCoreAccount = id; } -QList Client::allBufferInfos() { - QList bufferids; - foreach(Buffer *buffer, buffers()) { - bufferids << buffer->bufferInfo(); - } - return bufferids; -} - -QList Client::buffers() { - return instance()->_buffers.values(); -} - - -Buffer *Client::statusBuffer(const NetworkId &networkId) const { - if(_statusBuffers.contains(networkId)) - return _statusBuffers[networkId]; - else - return 0; -} - -Buffer *Client::buffer(BufferId bufferId) { - if(instance()->_buffers.contains(bufferId)) - return instance()->_buffers[bufferId]; - else - return 0; -} - -Buffer *Client::buffer(BufferInfo bufferInfo) { - Buffer *buff = buffer(bufferInfo.bufferId()); - - if(!buff) { - Client *client = Client::instance(); - buff = new Buffer(bufferInfo, client); - connect(buff, SIGNAL(destroyed()), client, SLOT(bufferDestroyed())); - client->_buffers[bufferInfo.bufferId()] = buff; - if(bufferInfo.type() == BufferInfo::StatusBuffer) - client->_statusBuffers[bufferInfo.networkId()] = buff; - - emit client->bufferUpdated(bufferInfo); - - // I don't like this: but currently there isn't really a prettier way: - if(isSynced()) { // this slows down syncing a lot, so disable it during sync - QModelIndex bufferIdx = networkModel()->bufferIndex(bufferInfo.bufferId()); - bufferModel()->setCurrentIndex(bufferModel()->mapFromSource(bufferIdx)); - } - } - Q_ASSERT(buff); - return buff; -} - bool Client::isConnected() { return instance()->_connectedToCore; } @@ -214,14 +162,19 @@ void Client::createNetwork(const NetworkInfo &info) { emit instance()->requestCreateNetwork(info); } -void Client::updateNetwork(const NetworkInfo &info) { - emit instance()->requestUpdateNetwork(info); -} - void Client::removeNetwork(NetworkId id) { emit instance()->requestRemoveNetwork(id); } +void Client::updateNetwork(const NetworkInfo &info) { + Network *netptr = instance()->_networks.value(info.networkId, 0); + if(!netptr) { + qWarning() << "Update for unknown network requested:" << info; + return; + } + netptr->requestSetNetworkInfo(info); +} + void Client::addNetwork(Network *net) { net->setProxy(signalProxy()); signalProxy()->synchronize(net); @@ -263,8 +216,13 @@ void Client::createIdentity(const Identity &id) { emit instance()->requestCreateIdentity(id); } -void Client::updateIdentity(const Identity &id) { - emit instance()->requestUpdateIdentity(id); +void Client::updateIdentity(IdentityId id, const QVariantMap &ser) { + Identity *idptr = instance()->_identities.value(id, 0); + if(!idptr) { + qWarning() << "Update for unknown identity requested:" << id; + return; + } + idptr->requestUpdate(ser); } void Client::removeIdentity(IdentityId id) { @@ -298,25 +256,29 @@ void Client::userInput(BufferInfo bufferInfo, QString message) { /*** core connection stuff ***/ -void Client::setConnectedToCore(QIODevice *sock, AccountId id) { - socket = sock; +void Client::setConnectedToCore(QIODevice *socket, AccountId id) { + // 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); } +void Client::setConnectedToInternalCore() { + _connectedToCore = true; + setCurrentCoreAccount(AccountId()); +} + void Client::setSyncedToCore() { // create buffersyncer Q_ASSERT(!_bufferSyncer); _bufferSyncer = new BufferSyncer(this); - connect(bufferSyncer(), SIGNAL(lastSeenMsgSet(BufferId, MsgId)), this, SLOT(updateLastSeenMsg(BufferId, MsgId))); + 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))); signalProxy()->synchronize(bufferSyncer()); - // attach backlog manager - signalProxy()->synchronize(backlogManager()); - // create a new BufferViewManager _bufferViewManager = new BufferViewManager(signalProxy(), this); @@ -332,16 +294,19 @@ 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); + backlogManager()->reset(); + messageProcessor()->reset(); + // Clear internal data. Hopefully nothing relies on it at this point. setCurrentCoreAccount(0); @@ -358,17 +323,6 @@ void Client::disconnectFromCore() { _messageModel->clear(); _networkModel->clear(); - QHash::iterator bufferIter = _buffers.begin(); - while(bufferIter != _buffers.end()) { - Buffer *buffer = bufferIter.value(); - disconnect(buffer, SIGNAL(destroyed()), this, 0); - bufferIter = _buffers.erase(bufferIter); - buffer->deleteLater(); - } - Q_ASSERT(_buffers.isEmpty()); - - _statusBuffers.clear(); - QHash::iterator netIter = _networks.begin(); while(netIter != _networks.end()) { Network *net = netIter.value(); @@ -390,37 +344,8 @@ void Client::disconnectFromCore() { } -void Client::setCoreConfiguration(const QVariantMap &settings) { - SignalProxy::writeDataToDevice(socket, settings); -} - /*** ***/ -void Client::updateBufferInfo(BufferInfo id) { - emit bufferUpdated(id); -} - -void Client::bufferDestroyed() { - Buffer *buffer = static_cast(sender()); - QHash::iterator iter = _buffers.begin(); - while(iter != _buffers.end()) { - if(iter.value() == buffer) { - iter = _buffers.erase(iter); - break; - } - iter++; - } - - QHash::iterator statusIter = _statusBuffers.begin(); - while(statusIter != _statusBuffers.end()) { - if(statusIter.value() == buffer) { - statusIter = _statusBuffers.erase(statusIter); - break; - } - statusIter++; - } -} - void Client::networkDestroyed() { Network *net = static_cast(sender()); QHash::iterator netIter = _networks.begin(); @@ -439,72 +364,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::receiveBacklog(BufferId bufferId, const QVariantList &msgs) { - //QTime start = QTime::currentTime(); - QList msglist; - foreach(QVariant v, msgs) { - msglist << v.value(); - } - messageProcessor()->process(msglist); - //qDebug() << "processed" << msgs.count() << "backlog lines in" << start.msecsTo(QTime::currentTime()); -} - -// TODO optimize checkForHighlight -void Client::checkForHighlight(Message &msg) { - if(!((msg.type() & (Message::Plain | Message::Notice | Message::Action)) && !(msg.flags() & Message::Self))) - return; - - NotificationSettings notificationSettings; - const Network *net = network(msg.bufferInfo().networkId()); - if(net && !net->myNick().isEmpty()) { - QStringList nickList; - if(notificationSettings.highlightNick() == NotificationSettings::CurrentNick) { - nickList << net->myNick(); - } else if(notificationSettings.highlightNick() == NotificationSettings::AllNicks) { - const Identity *myIdentity = identity(net->identity()); - if(myIdentity) - nickList = myIdentity->nicks(); - } - foreach(QString nickname, nickList) { - QRegExp nickRegExp("^(.*\\W)?" + QRegExp::escape(nickname) + "(\\W.*)?$"); - if(nickRegExp.exactMatch(msg.contents())) { - msg.setFlags(msg.flags() | Message::Highlight); - return; - } - } - - foreach(QVariant highlight, notificationSettings.highlightList()) { - QVariantMap highlightRule = highlight.toMap(); - if(!highlightRule["enable"].toBool()) - continue; - Qt::CaseSensitivity caseSensitivity = highlightRule["cs"].toBool() ? Qt::CaseSensitive : Qt::CaseInsensitive; - QString name = highlightRule["name"].toString(); - QRegExp userRegExp; - if(highlightRule["regex"].toBool()) { - userRegExp = QRegExp(name, caseSensitivity); - } else { - userRegExp = QRegExp("^(.*\\W)?" + QRegExp::escape(name) + "(\\W.*)?$", caseSensitivity); - } - if(userRegExp.exactMatch(msg.contents())) { - msg.setFlags(msg.flags() | Message::Highlight); - return; - } - } - } -} - -void Client::updateLastSeenMsg(BufferId id, const MsgId &msgId) { - Buffer *b = buffer(id); - if(!b) { - qWarning() << "Client::updateLastSeen(): Unknown buffer" << id; - return; - } - b->setLastSeenMsg(msgId); +void Client::recvMessage(const Message &msg) { + Message msg_ = msg; + messageProcessor()->process(msg_); } void Client::setBufferLastSeenMsg(BufferId id, const MsgId &msgId) { @@ -519,14 +381,7 @@ void Client::removeBuffer(BufferId id) { } void Client::bufferRemoved(BufferId bufferId) { - // first remove the buffer from hash. this prohibits further lastSeenUpdates - Buffer *buff = 0; - if(_buffers.contains(bufferId)) { - buff = _buffers.take(bufferId); - disconnect(buff, 0, this, 0); - } - - // then we select a sane buffer (status buffer) + // select a sane buffer (status buffer) /* we have to manually select a buffer because otherwise inconsitent changes * to the model might occur: * the result of a buffer removal triggers a change in the selection model. @@ -541,9 +396,6 @@ void Client::bufferRemoved(BufferId bufferId) { // and remove it from the model networkModel()->removeBuffer(bufferId); - - if(buff) - buff->deleteLater(); } void Client::bufferRenamed(BufferId bufferId, const QString &newName) { @@ -552,3 +404,25 @@ void Client::bufferRenamed(BufferId bufferId, const QString &newName) { networkModel()->setData(bufferIndex, newName, Qt::DisplayRole); } } + +void Client::logMessage(QtMsgType type, const char *msg) { + QString prefix; + switch (type) { + case QtDebugMsg: + prefix = "Debug"; + break; + case QtWarningMsg: + prefix = "Warning"; + break; + case QtCriticalMsg: + prefix = "Critical"; + break; + case QtFatalMsg: + Quassel::logFatalMessage(msg); + return; + } + QString msgString = QString("%1: %3\n").arg(prefix, msg); + instance()->_debugLog << msgString; + emit instance()->logUpdated(msgString); +} +