QTfrontend/ui/widget/chatwidget.cpp
changeset 6214 c06b7e2eb7a4
parent 6205 7764cbe4ddd7
child 6215 efe2e2f7cabf
--- a/QTfrontend/ui/widget/chatwidget.cpp	Wed Oct 26 02:21:44 2011 +0200
+++ b/QTfrontend/ui/widget/chatwidget.cpp	Wed Oct 26 05:57:00 2011 +0200
@@ -136,6 +136,8 @@
                 style.append(in.readLine()+"\n");
             }
             orgStyleSheet = style;
+
+            file.close();
         }
     }
 
@@ -483,7 +485,8 @@
 
     // check first character for color code and set color properly
     char c = str[0].toAscii();
-    switch (c) {
+    switch (c)
+    {
         case 3:
             cssClass = (isFriend ? "msg_FriendJoin" : "msg_UserJoin");
             break;
@@ -495,9 +498,21 @@
                 cssClass = "msg_FriendChat";
     }
 
-    bool isHL = (!nick.isEmpty() &&
-                (nick != m_userNick) &&
-                str.toLower().contains(m_hlRegExp));
+    bool isHL = false;
+
+    if ((!nick.isEmpty()) && (nick != m_userNick))
+    {
+        QString lcStr = str.toLower();
+
+        foreach (const QRegExp & hl, m_highlights)
+        {
+            if (lcStr.contains(hl))
+            {
+                isHL = true;
+                break;
+            }
+        }
+    }
 
     addLine(cssClass, formattedStr, isHL);
 }
@@ -584,8 +599,48 @@
     chatStrings.clear();
     chatNicks->clear();
     m_userNick = gameSettings->value("net/nick","").toString();
-    m_hlRegExp = QRegExp(QString("^(.* )?%1(( |[^-a-z0-9_]( |$)).*)?$").
-                            arg(QRegExp::escape(m_userNick).toLower()));
+
+    // clear and re compile regexp for highlighting
+    m_highlights.clear();
+
+    QString hlRegExp("^(.* )?%1(( |[^-a-z0-9_]( |$)).*)?$");
+    QRegExp whitespace("\\s");
+
+    m_highlights.append(QRegExp(hlRegExp.arg(m_userNick)));
+
+    QFile file(cfgdir->absolutePath() + "/" + m_userNick + "_highlight.txt");
+
+    if (file.exists() && (file.open(QIODevice::ReadOnly | QIODevice::Text)))
+    {
+        QTextStream in(&file);
+        while (!in.atEnd())
+        {
+            QString line = in.readLine();
+            QStringList list = line.split(whitespace);
+            foreach (QString word, list)
+            {
+                m_highlights.append(QRegExp(
+                                hlRegExp.arg(QRegExp::escape(word.toLower()))));
+            }
+        }
+
+        if (file.isOpen())
+            file.close();
+    }
+
+    QFile file2(cfgdir->absolutePath() + "/" + m_userNick + "_hlregexp.txt");
+
+    if (file2.exists() && (file2.open(QIODevice::ReadOnly | QIODevice::Text)))
+    {
+        QTextStream in(&file2);
+        while (!in.atEnd())
+        {
+            m_highlights.append(QRegExp(in.readLine().toLower()));
+        }
+
+        if (file2.isOpen())
+            file2.close();
+    }
 }
 
 void HWChatWidget::onKick()
@@ -788,6 +843,9 @@
         displayNotice(tr("Stylesheet imported from %1").arg(path));
         displayNotice(tr("Enter %1 if you want to use the current styleSheet in future, enter %2 to reset!").arg("/saveStyleSheet").arg("/discaredStyleSheet"));
 
+        if (file.isOpen())
+            file.close();
+
         event->acceptProposedAction();
     }
     else