Initial Channel specific highlights feature implementation
[quassel.git] / src / qtui / qtuimessageprocessor.cpp
index 353928a..aa24f08 100644 (file)
@@ -119,8 +119,7 @@ void QtUiMessageProcessor::checkForHighlight(Message &msg) {
         nickList.prepend(net->myNick());
     }
     foreach(QString nickname, nickList) {
-      QRegExp nickRegExp("\\b" + QRegExp::escape(nickname) + "(\\W|\\b|$)", // + "\\b", this does not seem to work for trailing ` -> upstream bug?
-                          _nicksCaseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive);
+      QRegExp nickRegExp("(^|\\W)" + QRegExp::escape(nickname) + "(\\W|$)", _nicksCaseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive);
       if(nickRegExp.indexIn(msg.contents()) >= 0) {
         msg.setFlags(msg.flags() | Message::Highlight);
         return;
@@ -130,16 +129,27 @@ void QtUiMessageProcessor::checkForHighlight(Message &msg) {
     for(int i = 0; i < _highlightRules.count(); i++) {
       const HighlightRule &rule = _highlightRules.at(i);
       if(!rule.isEnabled)
-       continue;
+        continue;
+
+      if(rule.chanName.size() > 0 && rule.chanName.compare(".*") != 0) {
+        if(rule.chanName.startsWith("!")) {
+          QRegExp rx(rule.chanName.mid(1), Qt::CaseInsensitive);
+          if(rx.exactMatch(msg.bufferInfo().bufferName()))
+            continue;
+        } else {
+          QRegExp rx(rule.chanName, Qt::CaseInsensitive);
+          if(!rx.exactMatch(msg.bufferInfo().bufferName()))
+            continue;
+        }
+      }
 
-      bool match = false;
+      QRegExp rx;
       if(rule.isRegExp) {
-        QRegExp rx(rule.name, rule.caseSensitive? Qt::CaseSensitive : Qt::CaseInsensitive);
-        match = rx.exactMatch(msg.contents());
+        rx = QRegExp(rule.name, rule.caseSensitive? Qt::CaseSensitive : Qt::CaseInsensitive);
       } else {
-        QRegExp rx("\\b" + QRegExp::escape(rule.name) + "\\b", rule.caseSensitive? Qt::CaseSensitive : Qt::CaseInsensitive);
-        match = (rx.indexIn(msg.contents()) >= 0);
+        rx = QRegExp("(^|\\W)" + QRegExp::escape(rule.name) + "(\\W|$)", rule.caseSensitive? Qt::CaseSensitive : Qt::CaseInsensitive);
       }
+      bool match = (rx.indexIn(msg.contents()) >= 0);
       if(match) {
         msg.setFlags(msg.flags() | Message::Highlight);
         return;
@@ -162,7 +172,8 @@ void QtUiMessageProcessor::highlightListChanged(const QVariant &variant) {
     _highlightRules << HighlightRule(rule["Name"].toString(),
                                      rule["Enable"].toBool(),
                                      rule["CS"].toBool() ? Qt::CaseSensitive : Qt::CaseInsensitive,
-                                     rule["RegEx"].toBool());
+                                     rule["RegEx"].toBool(),
+                                     rule["Chan"].toString());
     iter++;
   }
 }