qa: Replace Qt module includes by class ones
[quassel.git] / src / common / ignorelistmanager.cpp
index 63750f6..24a26ec 100644 (file)
@@ -1,5 +1,5 @@
 /***************************************************************************
- *   Copyright (C) 2005-2018 by the Quassel Project                        *
+ *   Copyright (C) 2005-2019 by the Quassel Project                        *
  *   devel@quassel-irc.org                                                 *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
 
 #include "ignorelistmanager.h"
 
-#include <QtCore>
 #include <QDebug>
 #include <QStringList>
 
-INIT_SYNCABLE_OBJECT(IgnoreListManager)
-IgnoreListManager &IgnoreListManager::operator=(const IgnoreListManager &other)
+IgnoreListManager& IgnoreListManager::operator=(const IgnoreListManager& other)
 {
     if (this == &other)
         return *this;
@@ -35,8 +33,7 @@ IgnoreListManager &IgnoreListManager::operator=(const IgnoreListManager &other)
     return *this;
 }
 
-
-int IgnoreListManager::indexOf(const QString &ignore) const
+int IgnoreListManager::indexOf(const QString& ignore) const
 {
     for (int i = 0; i < _ignoreList.count(); i++) {
         if (_ignoreList[i].contents() == ignore)
@@ -45,7 +42,6 @@ int IgnoreListManager::indexOf(const QString &ignore) const
     return -1;
 }
 
-
 QVariantMap IgnoreListManager::initIgnoreList() const
 {
     QVariantMap ignoreListMap;
@@ -77,8 +73,7 @@ QVariantMap IgnoreListManager::initIgnoreList() const
     return ignoreListMap;
 }
 
-
-void IgnoreListManager::initSetIgnoreList(const QVariantMap &ignoreList)
+void IgnoreListManager::initSetIgnoreList(const QVariantMap& ignoreList)
 {
     QVariantList ignoreType = ignoreList["ignoreType"].toList();
     QStringList ignoreRule = ignoreList["ignoreRule"].toStringList();
@@ -89,42 +84,50 @@ void IgnoreListManager::initSetIgnoreList(const QVariantMap &ignoreList)
     QVariantList isActive = ignoreList["isActive"].toList();
 
     int count = ignoreRule.count();
-    if (count != scopeRule.count() || count != isRegEx.count() ||
-        count != scope.count() || count != strictness.count() || count != ignoreType.count() || count != isActive.count()) {
+    if (count != scopeRule.count() || count != isRegEx.count() || count != scope.count() || count != strictness.count()
+        || count != ignoreType.count() || count != isActive.count()) {
         qWarning() << "Corrupted IgnoreList settings! (Count mismatch)";
         return;
     }
 
     _ignoreList.clear();
     for (int i = 0; i < ignoreRule.count(); i++) {
-        _ignoreList << IgnoreListItem(static_cast<IgnoreType>(ignoreType[i].toInt()), ignoreRule[i], isRegEx[i].toBool(),
-            static_cast<StrictnessType>(strictness[i].toInt()), static_cast<ScopeType>(scope[i].toInt()),
-            scopeRule[i], isActive[i].toBool());
+        _ignoreList << IgnoreListItem(static_cast<IgnoreType>(ignoreType[i].toInt()),
+                                      ignoreRule[i],
+                                      isRegEx[i].toBool(),
+                                      static_cast<StrictnessType>(strictness[i].toInt()),
+                                      static_cast<ScopeType>(scope[i].toInt()),
+                                      scopeRule[i],
+                                      isActive[i].toBool());
     }
 }
 
-
 /* since overloaded methods aren't syncable (yet?) we can't use that anymore
 void IgnoreListManager::addIgnoreListItem(const IgnoreListItem &item) {
   addIgnoreListItem(item.type(), item.contents(), item.isRegEx(), item.strictness(), item.scope(), item.scopeRule(), item.isEnabled());
 }
 */
-void IgnoreListManager::addIgnoreListItem(int type, const QString &ignoreRule, bool isRegEx, int strictness,
-    int 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;
     }
 
-    IgnoreListItem newItem = IgnoreListItem(static_cast<IgnoreType>(type), ignoreRule, isRegEx, static_cast<StrictnessType>(strictness),
-        static_cast<ScopeType>(scope), scopeRule, isActive);
+    IgnoreListItem newItem = IgnoreListItem(static_cast<IgnoreType>(type),
+                                            ignoreRule,
+                                            isRegEx,
+                                            static_cast<StrictnessType>(strictness),
+                                            static_cast<ScopeType>(scope),
+                                            scopeRule,
+                                            isActive);
     _ignoreList << newItem;
 
     SYNC(ARG(type), ARG(ignoreRule), ARG(isRegEx), ARG(strictness), ARG(scope), ARG(scopeRule), ARG(isActive))
 }
 
-
-IgnoreListManager::StrictnessType IgnoreListManager::_match(const QString &msgContents, const QString &msgSender, Message::Type msgType, const QString &network, const QString &bufferName)
+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
@@ -132,11 +135,10 @@ IgnoreListManager::StrictnessType IgnoreListManager::_match(const QString &msgCo
     if (!(msgType & (Message::Plain | Message::Notice | Message::Action)))
         return UnmatchedStrictness;
 
-    foreach(IgnoreListItem item, _ignoreList) {
+    foreach (IgnoreListItem item, _ignoreList) {
         if (!item.isEnabled() || item.type() == CtcpIgnore)
             continue;
-        if (item.scope() == GlobalScope
-            || (item.scope() == NetworkScope && item.scopeRuleMatcher().match(network))
+        if (item.scope() == GlobalScope || (item.scope() == NetworkScope && item.scopeRuleMatcher().match(network))
             || (item.scope() == ChannelScope && item.scopeRuleMatcher().match(bufferName))) {
             QString str;
             if (item.type() == MessageIgnore)
@@ -144,11 +146,11 @@ IgnoreListManager::StrictnessType IgnoreListManager::_match(const QString &msgCo
             else
                 str = msgSender;
 
-//      qDebug() << "IgnoreListManager::match: ";
-//      qDebug() << "string: " << str;
-//      qDebug() << "pattern: " << ruleRx.pattern();
-//      qDebug() << "scopeRule: " << item.scopeRule;
-//      qDebug() << "now testing";
+            //      qDebug() << "IgnoreListManager::match: ";
+            //      qDebug() << "string: " << str;
+            //      qDebug() << "pattern: " << ruleRx.pattern();
+            //      qDebug() << "scopeRule: " << item.scopeRule;
+            //      qDebug() << "now testing";
             if (item.contentsMatcher().match(str)) {
                 return item.strictness();
             }
@@ -157,15 +159,13 @@ IgnoreListManager::StrictnessType IgnoreListManager::_match(const QString &msgCo
     return UnmatchedStrictness;
 }
 
-
-void IgnoreListManager::removeIgnoreListItem(const QString &ignoreRule)
+void IgnoreListManager::removeIgnoreListItem(const QString& ignoreRule)
 {
     removeAt(indexOf(ignoreRule));
     SYNC(ARG(ignoreRule))
 }
 
-
-void IgnoreListManager::toggleIgnoreRule(const QString &ignoreRule)
+void IgnoreListManager::toggleIgnoreRule(const QString& ignoreRule)
 {
     int idx = indexOf(ignoreRule);
     if (idx == -1)
@@ -174,20 +174,16 @@ void IgnoreListManager::toggleIgnoreRule(const QString &ignoreRule)
     SYNC(ARG(ignoreRule))
 }
 
-
-bool IgnoreListManager::ctcpMatch(const QString sender, const QString &network, const QString &type)
+bool IgnoreListManager::ctcpMatch(const QString sender, const QString& network, const QString& type)
 {
-    foreach(IgnoreListItem item, _ignoreList) {
+    foreach (IgnoreListItem item, _ignoreList) {
         if (!item.isEnabled())
             continue;
-        if (item.scope() == GlobalScope
-                || (item.scope() == NetworkScope && item.scopeRuleMatcher().match(network))) {
-
+        if (item.scope() == GlobalScope || (item.scope() == NetworkScope && item.scopeRuleMatcher().match(network))) {
             // For CTCP ignore rules, use ctcpSender
             if (item.senderCTCPMatcher().match(sender)) {
                 // Sender matches, check types
-                if (item.ctcpTypes().isEmpty()
-                        || item.ctcpTypes().contains(type, Qt::CaseInsensitive)) {
+                if (item.ctcpTypes().isEmpty() || item.ctcpTypes().contains(type, Qt::CaseInsensitive)) {
                     // Either all types are blocked, or type matches
                     return true;
                 }
@@ -197,23 +193,16 @@ bool IgnoreListManager::ctcpMatch(const QString sender, const QString &network,
     return false;
 }
 
-
 /**************************************************************************
  * IgnoreListItem
  *************************************************************************/
-bool IgnoreListManager::IgnoreListItem::operator!=(const IgnoreListItem &other) const
+bool IgnoreListManager::IgnoreListItem::operator!=(const IgnoreListItemother) const
 {
-    return (_type != other._type ||
-            _contents != other._contents ||
-            _isRegEx != other._isRegEx ||
-            _strictness != other._strictness ||
-            _scope != other._scope ||
-            _scopeRule != other._scopeRule ||
-            _isEnabled != other._isEnabled);
+    return (_type != other._type || _contents != other._contents || _isRegEx != other._isRegEx || _strictness != other._strictness
+            || _scope != other._scope || _scopeRule != other._scopeRule || _isEnabled != other._isEnabled);
     // Don't compare ExpressionMatch objects as they are created as needed from the above
 }
 
-
 void IgnoreListManager::IgnoreListItem::determineExpressions() const
 {
     // Don't update if not needed
@@ -223,9 +212,7 @@ void IgnoreListManager::IgnoreListItem::determineExpressions() const
 
     // Set up matching rules
     // Message is either wildcard or regex
-    ExpressionMatch::MatchMode contentsMode =
-            _isRegEx ? ExpressionMatch::MatchMode::MatchRegEx :
-                       ExpressionMatch::MatchMode::MatchWildcard;
+    ExpressionMatch::MatchMode contentsMode = _isRegEx ? ExpressionMatch::MatchMode::MatchRegEx : ExpressionMatch::MatchMode::MatchWildcard;
 
     // Ignore rules are always case-insensitive
     // Scope matching is always wildcard
@@ -243,8 +230,7 @@ void IgnoreListManager::IgnoreListItem::determineExpressions() const
     }
     // Scope rules are always multiple wildcard entries
     // (Adding a regex option would be awesome, but requires a backwards-compatible protocol change)
-    _scopeRuleMatch = ExpressionMatch(_scopeRule,
-                                      ExpressionMatch::MatchMode::MatchMultiWildcard, false);
+    _scopeRuleMatch = ExpressionMatch(_scopeRule, ExpressionMatch::MatchMode::MatchMultiWildcard, false);
 
     _cacheInvalid = false;
 }