X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;f=src%2Fclient%2Fclient.cpp;h=48c471c5a07f7aed91c16ec02f9bb4f88f37477f;hb=6e50e532fa24b8e36237eb7ae9c5c9b21058519f;hp=eeb25d5847e4faf35f261b2025391f199955fa4f;hpb=bd37d2c94e49e791d2ba44baab4270e030442832;p=quassel.git diff --git a/src/client/client.cpp b/src/client/client.cpp index eeb25d58..48c471c5 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -20,6 +20,7 @@ #include "client.h" +#include "abstractmessageprocessor.h" #include "bufferinfo.h" #include "buffermodel.h" #include "buffersettings.h" @@ -72,10 +73,10 @@ Client::Client(QObject *parent) _bufferViewManager(0), _ircListHelper(new ClientIrcListHelper(this)), _messageModel(0), + _messageProcessor(0), _connectedToCore(false), _syncedToCore(false) { - _monitorBuffer = new Buffer(BufferInfo(), this); _signalProxy->synchronize(_ircListHelper); connect(_backlogManager, SIGNAL(backlog(BufferId, const QVariantList &)), @@ -97,6 +98,7 @@ void Client::init() { _bufferModel = new BufferModel(_networkModel); _messageModel = mainUi->createMessageModel(this); + _messageProcessor = mainUi->createMessageProcessor(this); SignalProxy *p = signalProxy(); @@ -126,11 +128,6 @@ void Client::init() { connect(this, SIGNAL(connected()), mainUi, SLOT(connectedToCore())); connect(this, SIGNAL(disconnected()), mainUi, SLOT(disconnectedFromCore())); - layoutTimer = new QTimer(this); - layoutTimer->setInterval(0); - layoutTimer->setSingleShot(false); - connect(layoutTimer, SIGNAL(timeout()), this, SLOT(layoutMsg())); - } /*** public static methods ***/ @@ -163,15 +160,10 @@ Buffer *Client::statusBuffer(const NetworkId &networkId) const { 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()); + Buffer *buff = 0; + if(instance()->_buffers.contains(bufferInfo.bufferId())) + buff = instance()->_buffers[bufferInfo.bufferId()]; if(!buff) { Client *client = Client::instance(); @@ -311,7 +303,7 @@ 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()); @@ -344,6 +336,8 @@ void Client::disconnectFromCore() { emit disconnected(); emit coreConnectionStateChanged(false); + messageProcessor()->reset(); + // Clear internal data. Hopefully nothing relies on it at this point. setCurrentCoreAccount(0); @@ -390,8 +384,6 @@ void Client::disconnectFromCore() { } Q_ASSERT(_identities.isEmpty()); - layoutQueue.clear(); - layoutTimer->stop(); } void Client::setCoreConfiguration(const QVariantMap &settings) { @@ -438,101 +430,28 @@ void Client::networkDestroyed() { } } -void Client::recvMessage(const Message &msg_) { - Message msg = msg_; - checkForHighlight(msg); - _messageModel->insertMessage(msg); - buffer(msg.bufferInfo())->updateActivityLevel(msg); -} - +// Hmm... we never used this... 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) { Message msg = v.value(); - checkForHighlight(msg); - _messageModel->insertMessage(msg); - buffer(msg.bufferInfo())->updateActivityLevel(msg); + msg.setFlags(msg.flags() | Message::Backlog); + msglist << msg; } + messageProcessor()->process(msglist); //qDebug() << "processed" << msgs.count() << "backlog lines in" << start.msecsTo(QTime::currentTime()); } -void Client::layoutMsg() { - if(layoutQueue.isEmpty()) { - 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(); -} - -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()) { - 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::setBufferLastSeenMsg(BufferId id, const MsgId &msgId) { if(!bufferSyncer()) return; @@ -549,7 +468,6 @@ void Client::bufferRemoved(BufferId bufferId) { Buffer *buff = 0; if(_buffers.contains(bufferId)) { buff = _buffers.take(bufferId); - layoutQueue.removeAll(buff); disconnect(buff, 0, this, 0); }