From 9950dd55446bedbccba1e7a27c4d042fb896d3c6 Mon Sep 17 00:00:00 2001 From: Manuel Nickschas Date: Wed, 6 Aug 2008 21:50:50 +0200 Subject: [PATCH] Move checkForHighlight() from Client to QtUiMessageProcessor. --- src/client/client.cpp | 44 -------------------------- src/client/client.h | 8 +++-- src/qtui/qtuimessageprocessor.cpp | 51 +++++++++++++++++++++++++++++-- src/qtui/qtuimessageprocessor.h | 4 ++- 4 files changed, 57 insertions(+), 50 deletions(-) diff --git a/src/client/client.cpp b/src/client/client.cpp index db60bcbc..d2972634 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -454,50 +454,6 @@ void Client::receiveBacklog(BufferId bufferId, const QVariantList &msgs) { //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) { diff --git a/src/client/client.h b/src/client/client.h index fab9a999..112a6a26 100644 --- a/src/client/client.h +++ b/src/client/client.h @@ -53,6 +53,11 @@ class Client : public QObject { Q_OBJECT public: + enum ClientMode { + LocalCore, + RemoteCore + }; + static Client *instance(); static void destroy(); static void init(AbstractUi *); @@ -108,9 +113,6 @@ public: static void userInput(BufferInfo bufferInfo, QString message); - enum ClientMode { LocalCore, RemoteCore }; - - static void checkForHighlight(Message &msg); static void setBufferLastSeenMsg(BufferId id, const MsgId &msgId); // this is synced to core and other clients static void removeBuffer(BufferId id); diff --git a/src/qtui/qtuimessageprocessor.cpp b/src/qtui/qtuimessageprocessor.cpp index e110d61e..54ee5702 100644 --- a/src/qtui/qtuimessageprocessor.cpp +++ b/src/qtui/qtuimessageprocessor.cpp @@ -21,7 +21,10 @@ #include "qtuimessageprocessor.h" #include "client.h" +#include "clientsettings.h" +#include "identity.h" #include "messagemodel.h" +#include "network.h" QtUiMessageProcessor::QtUiMessageProcessor(QObject *parent) : AbstractMessageProcessor(parent) { @@ -29,13 +32,57 @@ QtUiMessageProcessor::QtUiMessageProcessor(QObject *parent) : AbstractMessagePro } void QtUiMessageProcessor::processMessage(Message &msg) { - Client::checkForHighlight(msg); + checkForHighlight(msg); Client::messageModel()->insertMessage(msg); } void QtUiMessageProcessor::processMessages(QList &msgs) { foreach(Message msg, msgs) { - Client::checkForHighlight(msg); + checkForHighlight(msg); Client::messageModel()->insertMessage(msg); } } + +// TODO optimize checkForHighlight +void QtUiMessageProcessor::checkForHighlight(Message &msg) { + if(!((msg.type() & (Message::Plain | Message::Notice | Message::Action)) && !(msg.flags() & Message::Self))) + return; + + NotificationSettings notificationSettings; + const Network *net = Client::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 = Client::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; + } + } + } +} diff --git a/src/qtui/qtuimessageprocessor.h b/src/qtui/qtuimessageprocessor.h index 91cc5770..161385b0 100644 --- a/src/qtui/qtuimessageprocessor.h +++ b/src/qtui/qtuimessageprocessor.h @@ -30,10 +30,12 @@ class QtUiMessageProcessor : public AbstractMessageProcessor { QtUiMessageProcessor(QObject *parent); - protected: + private: void processMessage(Message &msg); void processMessages(QList &msgs); + void checkForHighlight(Message &msg); + }; #endif -- 2.20.1