X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;f=src%2Fcommon%2Fhighlightrulemanager.cpp;h=3fe3691c8a72da423f7d53dcd7b9da3559c36e53;hb=d261638f2e30aa47a08f1c3f43372da0c0e8d13f;hp=4d74deb0e9661b6e170c980b22325cd9ef0f32f6;hpb=ebe14ade2f3496aefc8926ce704a161c4451fedd;p=quassel.git diff --git a/src/common/highlightrulemanager.cpp b/src/common/highlightrulemanager.cpp index 4d74deb0..3fe3691c 100644 --- a/src/common/highlightrulemanager.cpp +++ b/src/common/highlightrulemanager.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2016 by the Quassel Project * + * Copyright (C) 2005-2018 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -19,11 +19,10 @@ ***************************************************************************/ #include "highlightrulemanager.h" + #include "util.h" -#include #include -#include INIT_SYNCABLE_OBJECT(HighlightRuleManager) HighlightRuleManager &HighlightRuleManager::operator=(const HighlightRuleManager &other) @@ -105,7 +104,11 @@ void HighlightRuleManager::initSetHighlightRuleList(const QVariantMap &highlight _highlightRuleList << HighlightRule(name[i], isRegEx[i].toBool(), isCaseSensitive[i].toBool(), isActive[i].toBool(), isInverse[i].toBool(), sender[i], channel[i]); } - _highlightNick = HighlightNickType(highlightRuleList["highlightNick"].toInt()); + + // Make sure the default for _highlightNick is "CurrentNick" if not set + _highlightNick = HighlightNickType( + highlightRuleList.value("highlightNick", HighlightNickType::CurrentNick).toInt()); + _nicksCaseSensitive = highlightRuleList["nicksCaseSensitive"].toBool(); } @@ -123,7 +126,13 @@ void HighlightRuleManager::addHighlightRule(const QString &name, bool isRegEx, b } -bool HighlightRuleManager::_match(const QString &msgContents, const QString &msgSender, Message::Type msgType, Message::Flags msgFlags, const QString &bufferName, const QString ¤tNick, const QStringList identityNicks) +bool HighlightRuleManager::match(const QString &msgContents, + const QString &msgSender, + Message::Type msgType, + Message::Flags msgFlags, + const QString &bufferName, + const QString ¤tNick, + const QStringList identityNicks) { if (!((msgType & (Message::Plain | Message::Notice | Message::Action)) && !(msgFlags & Message::Self))) { return false; @@ -136,17 +145,11 @@ bool HighlightRuleManager::_match(const QString &msgContents, const QString &msg if (!rule.isEnabled) 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(bufferName)) - continue; - } - else { - QRegExp rx(rule.chanName, Qt::CaseInsensitive); - if (!rx.exactMatch(bufferName)) - continue; - } + if (!rule.chanName.isEmpty() + && !scopeMatch(bufferName, rule.chanName, rule.isRegEx, rule.isCaseSensitive)) { + // A channel name rule is specified and does NOT match the current buffer name, skip + // this rule + continue; } QRegExp rx; @@ -161,12 +164,8 @@ bool HighlightRuleManager::_match(const QString &msgContents, const QString &msg if (rule.sender.isEmpty()) { senderMatch = true; } else { - if (rule.isRegEx) { - rx = QRegExp(rule.sender, rule.isCaseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive); - } else { - rx = QRegExp(rule.sender, Qt::CaseInsensitive, QRegExp::Wildcard); - } - senderMatch = rx.exactMatch(msgSender); + // A sender name rule is specified, match according to scope rules. + senderMatch = scopeMatch(msgSender, rule.sender, rule.isRegEx, rule.isCaseSensitive); } if (nameMatch && senderMatch) { @@ -222,5 +221,5 @@ void HighlightRuleManager::toggleHighlightRule(const QString &highlightRule) bool HighlightRuleManager::match(const Message &msg, const QString ¤tNick, const QStringList &identityNicks) { - return _match(msg.contents(), msg.sender(), msg.type(), msg.flags(), msg.bufferInfo().bufferName(), currentNick, identityNicks); + return match(msg.contents(), msg.sender(), msg.type(), msg.flags(), msg.bufferInfo().bufferName(), currentNick, identityNicks); }