/***************************************************************************
- * 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 *
***************************************************************************/
#include "highlightrulemanager.h"
+
#include "util.h"
-#include <QtCore>
#include <QDebug>
-#include <QStringList>
INIT_SYNCABLE_OBJECT(HighlightRuleManager)
HighlightRuleManager &HighlightRuleManager::operator=(const HighlightRuleManager &other)
QVariantList isCaseSensitive;
QVariantList isActive;
QVariantList isInverse;
+ QStringList sender;
QStringList channel;
for (int i = 0; i < _highlightRuleList.count(); i++) {
isCaseSensitive << _highlightRuleList[i].isCaseSensitive;
isActive << _highlightRuleList[i].isEnabled;
isInverse << _highlightRuleList[i].isInverse;
+ sender << _highlightRuleList[i].sender;
channel << _highlightRuleList[i].chanName;
}
highlightRuleListMap["isCaseSensitive"] = isCaseSensitive;
highlightRuleListMap["isEnabled"] = isActive;
highlightRuleListMap["isInverse"] = isInverse;
+ highlightRuleListMap["sender"] = sender;
highlightRuleListMap["channel"] = channel;
highlightRuleListMap["highlightNick"] = _highlightNick;
highlightRuleListMap["nicksCaseSensitive"] = _nicksCaseSensitive;
QVariantList isCaseSensitive = highlightRuleList["isCaseSensitive"].toList();
QVariantList isActive = highlightRuleList["isEnabled"].toList();
QVariantList isInverse = highlightRuleList["isInverse"].toList();
+ QStringList sender = highlightRuleList["sender"].toStringList();
QStringList channel = highlightRuleList["channel"].toStringList();
int count = name.count();
- if (count != isRegEx.count() || count != isCaseSensitive.count() ||
- count != isActive.count() || count != channel.count()) {
+ if (count != isRegEx.count() || count != isCaseSensitive.count() || count != isActive.count() ||
+ count != isInverse.count() || count != sender.count() || count != channel.count()) {
qWarning() << "Corrupted HighlightRuleList settings! (Count mismatch)";
return;
}
_highlightRuleList.clear();
for (int i = 0; i < name.count(); i++) {
_highlightRuleList << HighlightRule(name[i], isRegEx[i].toBool(), isCaseSensitive[i].toBool(),
- isActive[i].toBool(), isInverse[i].toBool(), channel[i]);
+ 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();
}
void HighlightRuleManager::addHighlightRule(const QString &name, bool isRegEx, bool isCaseSensitive, bool isActive,
- bool isInverse, const QString &channel)
+ bool isInverse, const QString &sender, const QString &channel)
{
if (contains(name)) {
return;
}
- HighlightRule newItem = HighlightRule(name, isRegEx, isCaseSensitive, isActive, isInverse, channel);
+ HighlightRule newItem = HighlightRule(name, isRegEx, isCaseSensitive, isActive, isInverse, sender, channel);
_highlightRuleList << newItem;
- SYNC(ARG(name), ARG(isRegEx), ARG(isCaseSensitive), ARG(isActive), ARG(isInverse), ARG(channel))
+ SYNC(ARG(name), ARG(isRegEx), ARG(isCaseSensitive), ARG(isActive), ARG(isInverse), ARG(sender), ARG(channel))
}
-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;
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;
if (rule.isRegEx) {
rx = QRegExp(rule.name, rule.isCaseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive);
- }
- else {
+ } else {
rx = QRegExp("(^|\\W)" + QRegExp::escape(rule.name) + "(\\W|$)", rule.isCaseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive);
}
- bool match = (rx.indexIn(stripFormatCodes(msgContents)) >= 0);
- if (match) {
+ bool nameMatch = (rx.indexIn(stripFormatCodes(msgContents)) >= 0);
+
+ bool senderMatch;
+ if (rule.sender.isEmpty()) {
+ senderMatch = true;
+ } else {
+ // A sender name rule is specified, match according to scope rules.
+ senderMatch = scopeMatch(msgSender, rule.sender, rule.isRegEx, rule.isCaseSensitive);
+ }
+
+ if (nameMatch && senderMatch) {
// If an inverse rule matches, then we know that we never want to return a highlight.
if (rule.isInverse) {
return false;
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);
}