From: Shane Synan Date: Tue, 17 Jul 2018 18:03:52 +0000 (-0500) Subject: common: Empty highlight name matches all messages X-Git-Tag: 0.13-rc1~4 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=824852f39114a70b69f71ac154650b71a9394f3c;hp=b3eaa1aaef22f680e4f7950b1349e7744735504c common: Empty highlight name matches all messages 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. --- diff --git a/src/common/highlightrulemanager.cpp b/src/common/highlightrulemanager.cpp index 72bb6113..ff60df62 100644 --- a/src/common/highlightrulemanager.cpp +++ b/src/common/highlightrulemanager.cpp @@ -166,13 +166,22 @@ bool HighlightRuleManager::match(const QString &msgContents, 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 { - 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()) { diff --git a/src/qtui/settingspages/corehighlightsettingspage.cpp b/src/qtui/settingspages/corehighlightsettingspage.cpp index 9ddb4347..24c78c1c 100644 --- a/src/qtui/settingspages/corehighlightsettingspage.cpp +++ b/src/qtui/settingspages/corehighlightsettingspage.cpp @@ -161,7 +161,7 @@ QString CoreHighlightSettingsPage::getTableTooltip(column tableColumn) const 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("RegEx: This option determines if the highlight rule, Sender, and " @@ -550,8 +550,6 @@ void CoreHighlightSettingsPage::highlightTableChanged(QTableWidgetItem *item) 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: @@ -589,8 +587,6 @@ void CoreHighlightSettingsPage::ignoredTableChanged(QTableWidgetItem *item) 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: