X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcommon%2Fignorelistmanager.cpp;h=b4831c072f6625678b583039828bc48a3cddbb30;hp=d6164b85d4145dc50422999664e32653a253e18c;hb=d8d9cc49774faf66170790ea687c37584e5e7a51;hpb=12feae2e4609b90c87d3c1857031909248143fd7 diff --git a/src/common/ignorelistmanager.cpp b/src/common/ignorelistmanager.cpp index d6164b85..b4831c07 100644 --- a/src/common/ignorelistmanager.cpp +++ b/src/common/ignorelistmanager.cpp @@ -24,10 +24,7 @@ #include #include -#include "message.h" - INIT_SYNCABLE_OBJECT(IgnoreListManager) - IgnoreListManager &IgnoreListManager::operator=(const IgnoreListManager &other) { if(this == &other) return *this; @@ -99,36 +96,43 @@ void IgnoreListManager::initSetIgnoreList(const QVariantMap &ignoreList) { } } +/* since overloaded methods aren't syncable (yet?) we can't use that anymore void IgnoreListManager::addIgnoreListItem(const IgnoreListItem &item) { addIgnoreListItem(item.type, item.ignoreRule, item.isRegEx, item.strictness, item.scope, item.scopeRule, item.isActive); } - -void IgnoreListManager::addIgnoreListItem(IgnoreType type, const QString &ignoreRule, bool isRegEx, StrictnessType strictness, - ScopeType scope, const QString &scopeRule, bool isActive) { +*/ +void IgnoreListManager::addIgnoreListItem(int type, const QString &ignoreRule, bool isRegEx, int strictness, + int scope, const QString &scopeRule, bool isActive) { if(contains(ignoreRule)) { return; } - _ignoreList << IgnoreListItem(type, ignoreRule, isRegEx, strictness, scope, scopeRule, isActive); + IgnoreListItem newItem = IgnoreListItem(static_cast(type), ignoreRule, isRegEx, static_cast(strictness), + static_cast(scope), scopeRule, isActive); + _ignoreList << newItem; - emit ignoreAdded(type, ignoreRule, isRegEx, strictness, scope, scopeRule, isActive); + SYNC(ARG(type), ARG(ignoreRule), ARG(isRegEx), ARG(strictness), ARG(scope), ARG(scopeRule), ARG(isActive)) } -IgnoreListManager::StrictnessType IgnoreListManager::match(const Message &msg, const QString &network) { - if(!(msg.type() & (Message::Plain | Message::Notice | Message::Action))) +IgnoreListManager::StrictnessType IgnoreListManager::_match(const QString &msgContents, const QString &msgSender, Message::Type msgType, const QString &network, const QString &bufferName) { + // We method don't rely on a proper Message object to make this method more versatile. + // This allows us to use it in the core with unprocessed Messages or in the Client + // with properly preprocessed Messages. + if(!(msgType & (Message::Plain | Message::Notice | Message::Action))) return UnmatchedStrictness; foreach(IgnoreListItem item, _ignoreList) { - if(!item.isActive) + if(!item.isActive || item.type == CtcpIgnore) continue; - if(item.scope == GlobalScope || (item.scope == NetworkScope && scopeMatch(item.scopeRule, network)) || - (item.scope == ChannelScope && scopeMatch(item.scopeRule, msg.bufferInfo().bufferName()))) { + if(item.scope == GlobalScope + || (item.scope == NetworkScope && scopeMatch(item.scopeRule, network)) + || (item.scope == ChannelScope && scopeMatch(item.scopeRule, bufferName))) { QString str; if(item.type == MessageIgnore) - str = msg.contents(); + str = msgContents; else - str = msg.sender(); + str = msgSender; QRegExp ruleRx = QRegExp(item.ignoreRule); ruleRx.setCaseSensitivity(Qt::CaseInsensitive); @@ -151,7 +155,8 @@ IgnoreListManager::StrictnessType IgnoreListManager::match(const Message &msg, c return UnmatchedStrictness; } -bool IgnoreListManager::scopeMatch(const QString &scopeRule, const QString &string) { + +bool IgnoreListManager::scopeMatch(const QString &scopeRule, const QString &string) const { foreach(QString rule, scopeRule.split(";")) { QRegExp ruleRx = QRegExp(rule.trimmed()); ruleRx.setCaseSensitivity(Qt::CaseInsensitive); @@ -162,3 +167,41 @@ bool IgnoreListManager::scopeMatch(const QString &scopeRule, const QString &stri } return false; } + +void IgnoreListManager::removeIgnoreListItem(const QString &ignoreRule) { + removeAt(indexOf(ignoreRule)); + SYNC(ARG(ignoreRule)) +} + +void IgnoreListManager::toggleIgnoreRule(const QString &ignoreRule) { + int idx = indexOf(ignoreRule); + if(idx == -1) + return; + _ignoreList[idx].isActive = !_ignoreList[idx].isActive; + SYNC(ARG(ignoreRule)) +} + +bool IgnoreListManager::ctcpMatch(const QString sender, const QString &network, const QString &type) { + foreach(IgnoreListItem item, _ignoreList) { + if(!item.isActive) + continue; + if(item.scope == GlobalScope || (item.scope == NetworkScope && scopeMatch(item.scopeRule, network))) { + QString sender_; + QStringList types = item.ignoreRule.split(QRegExp("\\s+"), QString::SkipEmptyParts); + + sender_ = types.takeAt(0); + + QRegExp ruleRx = QRegExp(sender_); + ruleRx.setCaseSensitivity(Qt::CaseInsensitive); + if(!item.isRegEx) + ruleRx.setPatternSyntax(QRegExp::Wildcard); + if((!item.isRegEx && ruleRx.exactMatch(sender)) || + (item.isRegEx && ruleRx.indexIn(sender) != -1)) { + + if(types.isEmpty() || types.contains(type, Qt::CaseInsensitive)) + return true; + } + } + } + return false; +}