X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fclient%2Fclient.cpp;h=eeb25d5847e4faf35f261b2025391f199955fa4f;hp=8c7a043068cd68bd937e9b5e5a49ed549ad04e7c;hb=bd37d2c94e49e791d2ba44baab4270e030442832;hpb=9ced25191b84390d1867cf3ee19f5aec741795a8 diff --git a/src/client/client.cpp b/src/client/client.cpp index 8c7a0430..eeb25d58 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -21,21 +21,23 @@ #include "client.h" #include "bufferinfo.h" +#include "buffermodel.h" +#include "buffersettings.h" #include "buffersyncer.h" -#include "clientbacklogmanager.h" #include "bufferviewmanager.h" +#include "clientbacklogmanager.h" +#include "clientirclisthelper.h" #include "global.h" #include "identity.h" #include "ircchannel.h" #include "ircuser.h" #include "message.h" +#include "messagemodel.h" #include "network.h" #include "networkmodel.h" -#include "buffermodel.h" #include "quasselui.h" #include "signalproxy.h" #include "util.h" -#include "buffersettings.h" QPointer Client::instanceptr = 0; AccountId Client::_currentCoreAccount = 0; @@ -68,10 +70,14 @@ Client::Client(QObject *parent) _bufferSyncer(0), _backlogManager(new ClientBacklogManager(this)), _bufferViewManager(0), + _ircListHelper(new ClientIrcListHelper(this)), + _messageModel(0), _connectedToCore(false), _syncedToCore(false) { _monitorBuffer = new Buffer(BufferInfo(), this); + _signalProxy->synchronize(_ircListHelper); + connect(_backlogManager, SIGNAL(backlog(BufferId, const QVariantList &)), this, SLOT(receiveBacklog(BufferId, const QVariantList &))); } @@ -83,12 +89,14 @@ Client::~Client() { 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))); + _networkModel, SLOT(networkRemoved(NetworkId))); _bufferModel = new BufferModel(_networkModel); + _messageModel = mainUi->createMessageModel(this); SignalProxy *p = signalProxy(); @@ -235,7 +243,8 @@ void Client::coreNetworkCreated(NetworkId id) { } void Client::coreNetworkRemoved(NetworkId id) { - if(!_networks.contains(id)) return; + if(!_networks.contains(id)) + return; Network *net = _networks.take(id); emit networkRemoved(net->networkId()); net->deleteLater(); @@ -312,27 +321,32 @@ void Client::setSyncedToCore() { // create a new BufferViewManager _bufferViewManager = new BufferViewManager(signalProxy(), this); - + _syncedToCore = true; emit connected(); emit coreConnectionStateChanged(true); } +void Client::setSecuredConnection() { + emit securedConnection(); +} + void Client::disconnectFromCore() { if(!isConnected()) return; - + _connectedToCore = false; + if(socket) { socket->close(); socket->deleteLater(); } - _connectedToCore = false; _syncedToCore = false; - setCurrentCoreAccount(0); emit disconnected(); emit coreConnectionStateChanged(false); // Clear internal data. Hopefully nothing relies on it at this point. + setCurrentCoreAccount(0); + if(_bufferSyncer) { _bufferSyncer->deleteLater(); _bufferSyncer = 0; @@ -342,7 +356,8 @@ void Client::disconnectFromCore() { _bufferViewManager->deleteLater(); _bufferViewManager = 0; } - + + _messageModel->clear(); _networkModel->clear(); QHash::iterator bufferIter = _buffers.begin(); @@ -423,71 +438,11 @@ void Client::networkDestroyed() { } } -void Client::recvMessage(const Message &message) { - Message msg = message; - Buffer *b; - +void Client::recvMessage(const Message &msg_) { + Message msg = msg_; checkForHighlight(msg); - - // FIXME clean up code! (dup) - - if(msg.flags() & Message::Redirected) { - BufferSettings bufferSettings; - bool inStatus = bufferSettings.value("UserMessagesInStatusBuffer", QVariant(true)).toBool(); - bool inQuery = bufferSettings.value("UserMessagesInQueryBuffer", QVariant(false)).toBool(); - bool inCurrent = bufferSettings.value("UserMessagesInCurrentBuffer", QVariant(false)).toBool(); - - if(inStatus) { - b = statusBuffer(msg.bufferInfo().networkId()); - if(b) { - b->appendMsg(msg); - } else if(!inQuery && !inCurrent) { // make sure the message get's shown somewhere - b = buffer(msg.bufferInfo()); - b->appendMsg(msg); - } - } - - if(inQuery) { - b = buffer(msg.bufferInfo().bufferId()); - if(b) { - b->appendMsg(msg); - } else if(!inStatus && !inCurrent) { // make sure the message get's shown somewhere - b = statusBuffer(msg.bufferInfo().networkId()); - if(!b) b = buffer(msg.bufferInfo()); // seems like we have to create the buffer anyways... - b->appendMsg(msg); - } - } - - if(inCurrent) { - BufferId currentId = bufferModel()->currentIndex().data(NetworkModel::BufferIdRole).value(); - b = buffer(currentId); - if(b && currentId != msg.bufferInfo().bufferId() && !inQuery) { - b->appendMsg(msg); - } else if(!inStatus && !inQuery) { // make sure the message get's shown somewhere - b = statusBuffer(msg.bufferInfo().networkId()); - if(!b) b = buffer(msg.bufferInfo()); // seems like we have to create the buffer anyways... - b->appendMsg(msg); - } - } - } else { - // the regular case: we can deliver where it was supposed to go - b = buffer(msg.bufferInfo()); - b->appendMsg(msg); - } - - //bufferModel()->updateBufferActivity(msg); - - if(msg.type() == Message::Plain || msg.type() == Message::Notice || msg.type() == Message::Action) { - const Network *net = network(msg.bufferInfo().networkId()); - QString networkName = net != 0 - ? net->networkName() + ":" - : QString(); - QString sender = networkName + msg.bufferInfo().bufferName() + ":" + msg.sender(); - Message mmsg = Message(msg.timestamp(), msg.bufferInfo(), msg.type(), msg.text(), sender, msg.flags()); - monitorBuffer()->appendMsg(mmsg); - } - - emit messageReceived(msg); + _messageModel->insertMessage(msg); + buffer(msg.bufferInfo())->updateActivityLevel(msg); } void Client::recvStatusMsg(QString /*net*/, QString /*msg*/) { @@ -495,31 +450,14 @@ void Client::recvStatusMsg(QString /*net*/, QString /*msg*/) { } void Client::receiveBacklog(BufferId bufferId, const QVariantList &msgs) { - Buffer *buffer_ = buffer(bufferId); - if(!buffer_) { - qWarning() << "Client::recvBacklogData(): received Backlog for unknown Buffer:" << bufferId; - return; - } - - if(msgs.isEmpty()) - return; // no work to be done... - - QVariantList::const_iterator msgIter = msgs.constBegin(); - QVariantList::const_iterator msgIterEnd = msgs.constEnd(); - Message msg; - while(msgIter != msgIterEnd) { - msg = (*msgIter).value(); + //QTime start = QTime::currentTime(); + foreach(QVariant v, msgs) { + Message msg = v.value(); checkForHighlight(msg); - buffer_->prependMsg(msg); - msgIter++; - } - - if(!layoutQueue.contains(buffer_)) - layoutQueue.append(buffer_); - - if(!layoutTimer->isActive()) { - layoutTimer->start(); + _messageModel->insertMessage(msg); + buffer(msg.bufferInfo())->updateActivityLevel(msg); } + //qDebug() << "processed" << msgs.count() << "backlog lines in" << start.msecsTo(QTime::currentTime()); } void Client::layoutMsg() { @@ -527,12 +465,12 @@ void Client::layoutMsg() { layoutTimer->stop(); return; } - + Buffer *buffer = layoutQueue.takeFirst(); if(buffer->layoutMsg()) { layoutQueue.append(buffer); // Buffer has more messages in its queue --> Round Robin return; - } + } if(layoutQueue.isEmpty()) layoutTimer->stop(); @@ -542,7 +480,11 @@ AbstractUiMsg *Client::layoutMsg(const Message &msg) { return instance()->mainUi->layoutMsg(msg); } +// 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()) { @@ -550,13 +492,13 @@ void Client::checkForHighlight(Message &msg) { if(notificationSettings.highlightNick() == NotificationSettings::CurrentNick) { nickList << net->myNick(); } else if(notificationSettings.highlightNick() == NotificationSettings::AllNicks) { - nickList = identity(net->identity())->nicks(); + const Identity *myIdentity = identity(net->identity()); + if(myIdentity) + nickList = myIdentity->nicks(); } foreach(QString nickname, nickList) { QRegExp nickRegExp("^(.*\\W)?" + QRegExp::escape(nickname) + "(\\W.*)?$"); - if((msg.type() & (Message::Plain | Message::Notice | Message::Action)) - && !(msg.flags() & Message::Self) - && nickRegExp.exactMatch(msg.text())) { + if(nickRegExp.exactMatch(msg.contents())) { msg.setFlags(msg.flags() | Message::Highlight); return; } @@ -574,9 +516,7 @@ void Client::checkForHighlight(Message &msg) { } else { userRegExp = QRegExp("^(.*\\W)?" + QRegExp::escape(name) + "(\\W.*)?$", caseSensitivity); } - if((msg.type() & (Message::Plain | Message::Notice | Message::Action)) - && !(msg.flags() & Message::Self) - && userRegExp.exactMatch(msg.text())) { + if(userRegExp.exactMatch(msg.contents())) { msg.setFlags(msg.flags() | Message::Highlight); return; } @@ -605,10 +545,11 @@ void Client::removeBuffer(BufferId id) { } void Client::bufferRemoved(BufferId bufferId) { - // first remove the buffer from has. this prohibits further lastSeenUpdates + // first remove the buffer from hash. this prohibits further lastSeenUpdates Buffer *buff = 0; if(_buffers.contains(bufferId)) { buff = _buffers.take(bufferId); + layoutQueue.removeAll(buff); disconnect(buff, 0, this, 0); }