common: Empty highlight name matches all messages
authorShane Synan <digitalcircuit36939@gmail.com>
Tue, 17 Jul 2018 18:03:52 +0000 (13:03 -0500)
committerManuel Nickschas <sputnick@quassel-irc.org>
Tue, 17 Jul 2018 21:11:54 +0000 (23:11 +0200)
Don't force core-side highlight rules to have non-empty names,
allowing for matching all messages by leaving the name empty.

Requires core and client support, but as this has not been in a
released version, and it's near release, backwards-compatibility
shouldn't be required.

Update tooltips to note this.  (After cleanup, only a single change!)

This wasn't easily possible before as highlight names were the
identifier for the highlight rule.  Now that we have IDs for
highlight rules, there's no need to force names to be non-empty.

NOTE:  This could cause confusion, but the flexibility in not having
to use RegEx for the sake of matching every message seems worth the
risk of people unintentionally setting empty highlight rules that
match every message.

Local highlights are not changed as they don't have IDs.

src/common/highlightrulemanager.cpp
src/qtui/settingspages/corehighlightsettingspage.cpp

index 72bb611..ff60df6 100644 (file)
@@ -166,13 +166,22 @@ bool HighlightRuleManager::match(const QString &msgContents,
             continue;
         }
 
             continue;
         }
 
-        QRegExp rx;
-        if (rule.isRegEx) {
-            rx = QRegExp(rule.name, rule.isCaseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive);
+        bool nameMatch = false;
+        if (rule.name.isEmpty()) {
+            // Empty rule, matches any message
+            nameMatch = true;
         } else {
         } else {
-            rx = QRegExp("(^|\\W)" + QRegExp::escape(rule.name) + "(\\W|$)", rule.isCaseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive);
+            // Check according to specified rule
+            QRegExp rx;
+            if (rule.isRegEx) {
+                rx = QRegExp(rule.name,
+                             rule.isCaseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive);
+            } else {
+                rx = QRegExp("(^|\\W)" + QRegExp::escape(rule.name) + "(\\W|$)",
+                             rule.isCaseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive);
+            }
+            nameMatch = (rx.indexIn(stripFormatCodes(msgContents)) >= 0);
         }
         }
-        bool nameMatch = (rx.indexIn(stripFormatCodes(msgContents)) >= 0);
 
         bool senderMatch;
         if (rule.sender.isEmpty()) {
 
         bool senderMatch;
         if (rule.sender.isEmpty()) {
index 9ddb434..24c78c1 100644 (file)
@@ -161,7 +161,7 @@ QString CoreHighlightSettingsPage::getTableTooltip(column tableColumn) const
         return tr("Enable/disable this rule");
 
     case CoreHighlightSettingsPage::NameColumn:
         return tr("Enable/disable this rule");
 
     case CoreHighlightSettingsPage::NameColumn:
-        return tr("Phrase to match");
+        return tr("Phrase to match, leave blank to match any message");
 
     case CoreHighlightSettingsPage::RegExColumn:
         return tr("<b>RegEx</b>: This option determines if the highlight rule, <i>Sender</i>, and "
 
     case CoreHighlightSettingsPage::RegExColumn:
         return tr("<b>RegEx</b>: This option determines if the highlight rule, <i>Sender</i>, and "
@@ -550,8 +550,6 @@ void CoreHighlightSettingsPage::highlightTableChanged(QTableWidgetItem *item)
             highlightRule.isEnabled = (item->checkState() == Qt::Checked);
             break;
         case CoreHighlightSettingsPage::NameColumn:
             highlightRule.isEnabled = (item->checkState() == Qt::Checked);
             break;
         case CoreHighlightSettingsPage::NameColumn:
-            if (item->text() == "")
-                item->setText(tr("this shouldn't be empty"));
             highlightRule.name = item->text();
             break;
         case CoreHighlightSettingsPage::RegExColumn:
             highlightRule.name = item->text();
             break;
         case CoreHighlightSettingsPage::RegExColumn:
@@ -589,8 +587,6 @@ void CoreHighlightSettingsPage::ignoredTableChanged(QTableWidgetItem *item)
             ignoredRule.isEnabled = (item->checkState() == Qt::Checked);
             break;
         case CoreHighlightSettingsPage::NameColumn:
             ignoredRule.isEnabled = (item->checkState() == Qt::Checked);
             break;
         case CoreHighlightSettingsPage::NameColumn:
-            if (item->text() == "")
-                item->setText(tr("this shouldn't be empty"));
             ignoredRule.name = item->text();
             break;
         case CoreHighlightSettingsPage::RegExColumn:
             ignoredRule.name = item->text();
             break;
         case CoreHighlightSettingsPage::RegExColumn: