Move checkForHighlight() from Client to QtUiMessageProcessor.
authorManuel Nickschas <sputnick@quassel-irc.org>
Wed, 6 Aug 2008 19:50:50 +0000 (21:50 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Wed, 6 Aug 2008 19:50:50 +0000 (21:50 +0200)
src/client/client.cpp
src/client/client.h
src/qtui/qtuimessageprocessor.cpp
src/qtui/qtuimessageprocessor.h

index db60bcb..d297263 100644 (file)
@@ -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) {
index fab9a99..112a6a2 100644 (file)
@@ -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);
 
index e110d61..54ee570 100644 (file)
 #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<Message> &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;
+      }
+    }
+  }
+}
index 91cc577..161385b 100644 (file)
@@ -30,10 +30,12 @@ class QtUiMessageProcessor : public AbstractMessageProcessor {
     QtUiMessageProcessor(QObject *parent);
 
 
-  protected:
+  private:
     void processMessage(Message &msg);
     void processMessages(QList<Message> &msgs);
 
+    void checkForHighlight(Message &msg);
+
 };
 
 #endif