common: Port IgnoreListManager to ExpressionMatch
authorShane Synan <digitalcircuit36939@gmail.com>
Sat, 1 Sep 2018 21:40:21 +0000 (16:40 -0500)
committerManuel Nickschas <sputnick@quassel-irc.org>
Mon, 3 Sep 2018 20:12:02 +0000 (22:12 +0200)
Port IgnoreListItem objects to ExpressionMatch class, providing easy
caching and simplifying expression handling.

Migrate IgnoreListItem struct into a full-blown class for easier
management and greater assurance over automatic internal cache
management.

Add tons of documentation comments, too, and fix up line lengths.

Thanks to @sandsmark for the initial efforts towards the
QRegularExpression migration; it helped a lot!

src/client/clientignorelistmanager.cpp
src/common/ignorelistmanager.cpp
src/common/ignorelistmanager.h
src/core/coreignorelistmanager.cpp
src/qtui/settingspages/ignorelistmodel.cpp
src/qtui/settingspages/ignorelistsettingspage.cpp

index 2f112ef..461f629 100644 (file)
@@ -20,8 +20,6 @@
 
 #include "clientignorelistmanager.h"
 
-#include <QRegExp>
-
 INIT_SYNCABLE_OBJECT(ClientIgnoreListManager)
 
 ClientIgnoreListManager::ClientIgnoreListManager(QObject *parent)
@@ -33,15 +31,7 @@ ClientIgnoreListManager::ClientIgnoreListManager(QObject *parent)
 
 bool ClientIgnoreListManager::pureMatch(const IgnoreListItem &item, const QString &string) const
 {
-    QRegExp ruleRx = QRegExp(item.ignoreRule);
-    ruleRx.setCaseSensitivity(Qt::CaseInsensitive);
-    if (!item.isRegEx)
-        ruleRx.setPatternSyntax(QRegExp::Wildcard);
-
-    if ((!item.isRegEx && ruleRx.exactMatch(string)) ||
-        (item.isRegEx && ruleRx.indexIn(string) != -1))
-        return true;
-    return false;
+    return (item.contentsMatcher().match(string));
 }
 
 
@@ -49,11 +39,14 @@ QMap<QString, bool> ClientIgnoreListManager::matchingRulesForHostmask(const QStr
 {
     QMap<QString, bool> result;
     foreach(IgnoreListItem item, ignoreList()) {
-        if (item.type == SenderIgnore && pureMatch(item, hostmask)
-            && ((network.isEmpty() && channel.isEmpty()) || item.scope == GlobalScope || (item.scope == NetworkScope && scopeMatch(network, item.scopeRule))
-                || (item.scope == ChannelScope && scopeMatch(channel, item.scopeRule)))) {
-            result[item.ignoreRule] = item.isActive;
-//      qDebug() << "matchingRulesForHostmask found: " << item.ignoreRule << "is active: " << item.isActive;
+        if (item.type() == SenderIgnore && pureMatch(item, hostmask)
+            && ((network.isEmpty() && channel.isEmpty())
+                || item.scope() == GlobalScope
+                || (item.scope() == NetworkScope && item.scopeRuleMatcher().match(network))
+                || (item.scope() == ChannelScope && item.scopeRuleMatcher().match(channel)))) {
+            result[item.contents()] = item.isEnabled();
+            // qDebug() << "matchingRulesForHostmask found: " << item.contents()
+            //         << "is active: " << item.isActive;
         }
     }
     return result;
index b01273e..63750f6 100644 (file)
@@ -39,7 +39,7 @@ IgnoreListManager &IgnoreListManager::operator=(const IgnoreListManager &other)
 int IgnoreListManager::indexOf(const QString &ignore) const
 {
     for (int i = 0; i < _ignoreList.count(); i++) {
-        if (_ignoreList[i].ignoreRule == ignore)
+        if (_ignoreList[i].contents() == ignore)
             return i;
     }
     return -1;
@@ -58,13 +58,13 @@ QVariantMap IgnoreListManager::initIgnoreList() const
     QVariantList isActiveList;
 
     for (int i = 0; i < _ignoreList.count(); i++) {
-        ignoreTypeList << _ignoreList[i].type;
-        ignoreRuleList << _ignoreList[i].ignoreRule;
-        scopeRuleList << _ignoreList[i].scopeRule;
-        isRegExList << _ignoreList[i].isRegEx;
-        scopeList << _ignoreList[i].scope;
-        strictnessList << _ignoreList[i].strictness;
-        isActiveList << _ignoreList[i].isActive;
+        ignoreTypeList << _ignoreList[i].type();
+        ignoreRuleList << _ignoreList[i].contents();
+        scopeRuleList << _ignoreList[i].scopeRule();
+        isRegExList << _ignoreList[i].isRegEx();
+        scopeList << _ignoreList[i].scope();
+        strictnessList << _ignoreList[i].strictness();
+        isActiveList << _ignoreList[i].isEnabled();
     }
 
     ignoreListMap["ignoreType"] = ignoreTypeList;
@@ -106,7 +106,7 @@ 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);
+  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,
@@ -133,13 +133,13 @@ IgnoreListManager::StrictnessType IgnoreListManager::_match(const QString &msgCo
         return UnmatchedStrictness;
 
     foreach(IgnoreListItem item, _ignoreList) {
-        if (!item.isActive || item.type == CtcpIgnore)
+        if (!item.isEnabled() || item.type() == CtcpIgnore)
             continue;
-        if (item.scope == GlobalScope
-            || (item.scope == NetworkScope && scopeMatch(network, item.scopeRule))
-            || (item.scope == ChannelScope && scopeMatch(bufferName, item.scopeRule))) {
+        if (item.scope() == GlobalScope
+            || (item.scope() == NetworkScope && item.scopeRuleMatcher().match(network))
+            || (item.scope() == ChannelScope && item.scopeRuleMatcher().match(bufferName))) {
             QString str;
-            if (item.type == MessageIgnore)
+            if (item.type() == MessageIgnore)
                 str = msgContents;
             else
                 str = msgSender;
@@ -149,10 +149,8 @@ IgnoreListManager::StrictnessType IgnoreListManager::_match(const QString &msgCo
 //      qDebug() << "pattern: " << ruleRx.pattern();
 //      qDebug() << "scopeRule: " << item.scopeRule;
 //      qDebug() << "now testing";
-            if ((!item.isRegEx && item.regEx.exactMatch(str)) ||
-                (item.isRegEx && item.regEx.indexIn(str) != -1)) {
-//        qDebug() << "MATCHED!";
-                return item.strictness;
+            if (item.contentsMatcher().match(str)) {
+                return item.strictness();
             }
         }
     }
@@ -172,7 +170,7 @@ void IgnoreListManager::toggleIgnoreRule(const QString &ignoreRule)
     int idx = indexOf(ignoreRule);
     if (idx == -1)
         return;
-    _ignoreList[idx].isActive = !_ignoreList[idx].isActive;
+    _ignoreList[idx].setIsEnabled(!_ignoreList[idx].isEnabled());
     SYNC(ARG(ignoreRule))
 }
 
@@ -180,24 +178,73 @@ void IgnoreListManager::toggleIgnoreRule(const QString &ignoreRule)
 bool IgnoreListManager::ctcpMatch(const QString sender, const QString &network, const QString &type)
 {
     foreach(IgnoreListItem item, _ignoreList) {
-        if (!item.isActive)
+        if (!item.isEnabled())
             continue;
-        if (item.scope == GlobalScope || (item.scope == NetworkScope && scopeMatch(network, item.scopeRule))) {
-            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))
+        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)) {
+                    // Either all types are blocked, or type matches
                     return true;
+                }
             }
         }
     }
     return false;
 }
+
+
+/**************************************************************************
+ * IgnoreListItem
+ *************************************************************************/
+bool IgnoreListManager::IgnoreListItem::operator!=(const IgnoreListItem &other) const
+{
+    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
+    if (!_cacheInvalid) {
+        return;
+    }
+
+    // Set up matching rules
+    // Message is either wildcard or regex
+    ExpressionMatch::MatchMode contentsMode =
+            _isRegEx ? ExpressionMatch::MatchMode::MatchRegEx :
+                       ExpressionMatch::MatchMode::MatchWildcard;
+
+    // Ignore rules are always case-insensitive
+    // Scope matching is always wildcard
+    // TODO: Expand upon ignore rule handling with next protocol break
+
+    if (_type == CtcpIgnore) {
+        // Set up CTCP sender
+        _contentsMatch = {};
+        _ctcpSenderMatch = ExpressionMatch(_cacheCtcpSender, contentsMode, false);
+    }
+    else {
+        // Set up message contents
+        _contentsMatch = ExpressionMatch(_contents, contentsMode, false);
+        _ctcpSenderMatch = {};
+    }
+    // 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);
+
+    _cacheInvalid = false;
+}
index d5a1c8a..7bf4bab 100644 (file)
 #ifndef IGNORELISTMANAGER_H
 #define IGNORELISTMANAGER_H
 
+#include <QDebug>
 #include <QString>
+#include <QStringList>
 #include <QRegExp>
 
+#include "expressionmatch.h"
 #include "message.h"
 #include "syncableobject.h"
-// Scope matching
-#include "util.h"
 
 class IgnoreListManager : public SyncableObject
 {
@@ -55,35 +56,265 @@ public:
         ChannelScope,
     };
 
-    struct IgnoreListItem {
-        IgnoreType type;
-        QString ignoreRule;
-        bool isRegEx;
-        StrictnessType strictness;
-        ScopeType scope;
-        QString scopeRule;
-        bool isActive;
-        QRegExp regEx;
+    /**
+     * Individual ignore list rule
+     */
+    class IgnoreListItem {
+    public:
+        /**
+         * Construct an empty ignore rule
+         */
         IgnoreListItem() {}
-        IgnoreListItem(IgnoreType type_, const QString &ignoreRule_, bool isRegEx_, StrictnessType strictness_,
-            ScopeType scope_, const QString &scopeRule_, bool isActive_)
-            : type(type_), ignoreRule(ignoreRule_), isRegEx(isRegEx_), strictness(strictness_), scope(scope_), scopeRule(scopeRule_), isActive(isActive_), regEx(ignoreRule_) {
-            regEx.setCaseSensitivity(Qt::CaseInsensitive);
-            if (!isRegEx_) {
-                regEx.setPatternSyntax(QRegExp::Wildcard);
+
+        /**
+         * Construct an ignore rule with the given parameters
+         *
+         * CAUTION: For legacy reasons, "contents" doubles as the identifier for the ignore rule.
+         * Duplicate entries are not allowed.
+         *
+         * @param type             Type of ignore rule
+         * @param contents         String representing a message contents expression to match
+         * @param isRegEx          True if regular expression, otherwise false
+         * @param strictness       Strictness of ignore rule
+         * @param scope            What to match scope rule against
+         * @param scopeRule        String representing a scope rule expression to match
+         * @param isEnabled        True if enabled, otherwise false
+         */
+        IgnoreListItem(IgnoreType type, const QString &contents, bool isRegEx,
+                       StrictnessType strictness, ScopeType scope, const QString &scopeRule,
+                       bool isEnabled)
+            : _contents(contents), _isRegEx(isRegEx), _strictness(strictness),
+              _scope(scope), _scopeRule(scopeRule), _isEnabled(isEnabled)
+        {
+            // Allow passing empty "contents" as they can happen when editing an ignore rule
+
+            // Handle CTCP ignores
+            setType(type);
+
+            _cacheInvalid = true;
+            // Cache expression matches on construction
+            //
+            // This provides immediate feedback on errors when loading the rule.  If profiling shows
+            // this as a performance bottleneck, this can be removed in deference to caching on
+            // first use.
+            //
+            // Inversely, if needed for validity checks, caching can be done on every update below
+            // instead of on first use.
+            determineExpressions();
+        }
+
+        /**
+         * Gets the type of this ignore rule
+         *
+         * @return IgnoreType of the rule
+         */
+        inline IgnoreType type() const {
+            return _type;
+        }
+        /**
+         * Sets the type of this ignore rule
+         *
+         * @param type IgnoreType of the rule
+         */
+        inline void setType(IgnoreType type) {
+            // Handle CTCP ignores
+            if (type == CtcpIgnore) {
+                // This is not performance-intensive; sticking with QRegExp for Qt 4 is fine
+                // Split based on whitespace characters
+                QStringList split(contents().split(QRegExp("\\s+"), QString::SkipEmptyParts));
+                // Match on the first item
+                _cacheCtcpSender = split.takeFirst();
+                // Track the rest as CTCP types to ignore
+                _cacheCtcpTypes = split;
             }
+            _type = type;
         }
-        bool operator!=(const IgnoreListItem &other)
-        {
-            return (type != other.type ||
-                    ignoreRule != other.ignoreRule ||
-                    isRegEx != other.isRegEx ||
-                    strictness != other.strictness ||
-                    scope != other.scope ||
-                    scopeRule != other.scopeRule ||
-                    isActive != other.isActive);
+
+        /**
+         * Gets the message contents this rule matches
+         *
+         * NOTE: Use IgnoreListItem::contentsMatcher() for performing matches
+         *
+         * CAUTION: For legacy reasons, "contents" doubles as the identifier for the ignore rule.
+         * Duplicate entries are not allowed.
+         *
+         * @return String representing a phrase or expression to match
+         */
+        inline QString contents() const {
+            return _contents;
+        }
+        /**
+         * Sets the message contents this rule matches
+         *
+         * @param contents String representing a phrase or expression to match
+         */
+        inline void setContents(const QString &contents) {
+            // Allow passing empty "contents" as they can happen when editing an ignore rule
+            _contents = contents;
+            _cacheInvalid = true;
+        }
+
+        /**
+         * Gets if this is a regular expression rule
+         *
+         * @return True if regular expression, otherwise false
+         */
+        inline bool isRegEx() const {
+            return _isRegEx;
+        }
+        /**
+         * Sets if this rule is a regular expression rule
+         *
+         * @param isRegEx True if regular expression, otherwise false
+         */
+        inline void setIsRegEx(bool isRegEx) {
+            _isRegEx = isRegEx;
+            _cacheInvalid = true;
+        }
+
+        /**
+         * Gets the strictness of this ignore rule
+         *
+         * @return StrictnessType of the rule
+         */
+        inline StrictnessType strictness() const {
+            return _strictness;
+        }
+        /**
+         * Sets the strictness of this ignore rule
+         *
+         * @param strictness StrictnessType of the rule
+         */
+        inline void setStrictness(StrictnessType strictness) {
+            _strictness = strictness;
+        }
+
+        /**
+         * Gets what to match scope rule against
+         *
+         * @return ScopeType of the rule
+         */
+        inline ScopeType scope() const {
+            return _scope;
+        }
+        /**
+         * Sets what to match scope rule against
+         *
+         * @param type ScopeType of the rule
+         */
+        inline void setScope(ScopeType scope) {
+            _scope = scope;
+        }
+
+        /**
+         * Gets the scope rule this rule matches
+         *
+         * NOTE: Use IgnoreListItem::scopeRuleMatcher() for performing matches
+         *
+         * @return String representing a phrase or expression to match
+         */
+        inline QString scopeRule() const {
+            return _scopeRule;
         }
+        /**
+         * Sets the scope rule this rule matches
+         *
+         * @param scopeRule String representing a phrase or expression to match
+         */
+        inline void setScopeRule(const QString &scopeRule) {
+            _scopeRule = scopeRule;
+            _cacheInvalid = true;
+        }
+
+        /**
+         * Gets if this rule is enabled and active
+         *
+         * @return True if enabled, otherwise false
+         */
+        inline bool isEnabled() const {
+            return _isEnabled;
+        }
+        /**
+         * Sets if this rule is enabled and active
+         *
+         * @param isEnabled True if enabled, otherwise false
+         */
+        inline void setIsEnabled(bool isEnabled) {
+            _isEnabled = isEnabled;
+        }
+
+        /**
+         * Gets the ignored CTCP types for CTCP ignores
+         *
+         * @return List of CTCP types to ignore, or empty for all
+         */
+        inline QStringList ctcpTypes() const {
+            return _cacheCtcpTypes;
+        }
+
+        /**
+         * Gets the expression matcher for the message contents, caching if needed
+         *
+         * @return Expression matcher to compare with message contents
+         */
+        inline ExpressionMatch contentsMatcher() const {
+            if (_cacheInvalid) {
+                determineExpressions();
+            }
+            return _contentsMatch;
+        }
+
+        /**
+         * Gets the expression matcher for the scope, caching if needed
+         *
+         * @return Expression matcher to compare with scope
+         */
+        inline ExpressionMatch scopeRuleMatcher() const {
+            if (_cacheInvalid) {
+                determineExpressions();
+            }
+            return _scopeRuleMatch;
+        }
+
+        /**
+         * Gets the expression matcher for the message contents, caching if needed
+         *
+         * @return Expression matcher to compare with message contents
+         */
+        inline ExpressionMatch senderCTCPMatcher() const {
+            if (_cacheInvalid) {
+                determineExpressions();
+            }
+            return _ctcpSenderMatch;
+        }
+
+        bool operator!=(const IgnoreListItem &other) const;
+
+    private:
+        /**
+         * Update internal cache of expression matching if needed
+         */
+        void determineExpressions() const;
+
+        IgnoreType _type = {};
+        QString _contents = {};
+        bool _isRegEx = false;
+        StrictnessType _strictness = {};
+        ScopeType _scope = {};
+        QString _scopeRule = {};
+        bool _isEnabled = true;
+
+        QString _cacheCtcpSender = {};                    ///< For CTCP rules, precalculate sender
+        QStringList _cacheCtcpTypes = {};                 ///< For CTCP rules, precalculate types
+
+        // These represent internal cache and should be safe to mutate in 'const' functions
+        // See https://stackoverflow.com/questions/3141087/what-is-meant-with-const-at-end-of-function-declaration
+        mutable bool _cacheInvalid = true;                ///< If true, match cache needs redone
+        mutable ExpressionMatch _contentsMatch = {};      ///< Expression match cache for message
+        mutable ExpressionMatch _scopeRuleMatch = {};     ///< Expression match cache for scope rule
+        mutable ExpressionMatch _ctcpSenderMatch = {};    ///< Expression match cache for CTCP nick
     };
+
     typedef QList<IgnoreListItem> IgnoreList;
 
     int indexOf(const QString &ignore) const;
index 55c8452..3b38ea4 100644 (file)
@@ -65,6 +65,7 @@ void CoreIgnoreListManager::save() const
 
 //void CoreIgnoreListManager::loadDefaults() {
 //  foreach(IgnoreListItem item, IgnoreListManager::defaults()) {
-//    addIgnoreListItem(item.ignoreRule, item.isRegEx, item.strictness, item.scope, item.scopeRule);
+//    addIgnoreListItem(item.contents(), item.isRegEx(), item.strictness(), item.scope(),
+//                      item.scopeRule());
 //  }
 //}
index fb1b4fc..6f639bd 100644 (file)
@@ -87,7 +87,7 @@ QVariant IgnoreListModel::data(const QModelIndex &index, int role) const
     case Qt::DisplayRole:
         switch (index.column()) {
         case 1:
-            if (ignoreListManager()[index.row()].type == IgnoreListManager::SenderIgnore)
+            if (ignoreListManager()[index.row()].type() == IgnoreListManager::SenderIgnore)
                 return tr("By Sender");
             else
                 return tr("By Message");
@@ -95,11 +95,11 @@ QVariant IgnoreListModel::data(const QModelIndex &index, int role) const
     case Qt::EditRole:
         switch (index.column()) {
         case 0:
-            return ignoreListManager()[index.row()].isActive;
+            return ignoreListManager()[index.row()].isEnabled();
         case 1:
-            return ignoreListManager()[index.row()].type;
+            return ignoreListManager()[index.row()].type();
         case 2:
-            return ignoreListManager()[index.row()].ignoreRule;
+            return ignoreListManager()[index.row()].contents();
         default:
             return QVariant();
         }
@@ -123,17 +123,18 @@ bool IgnoreListModel::setData(const QModelIndex &index, const QVariant &value, i
 
     switch (index.column()) {
     case 0:
-        cloneIgnoreListManager()[index.row()].isActive = newValue.toBool();
+        cloneIgnoreListManager()[index.row()].setIsEnabled(newValue.toBool());
         return true;
     case 1:
-        cloneIgnoreListManager()[index.row()].type = (IgnoreListManager::IgnoreType)newValue.toInt();
+        cloneIgnoreListManager()[index.row()].setType(
+                    (IgnoreListManager::IgnoreType)newValue.toInt());
         return true;
     case 2:
         if (ignoreListManager().contains(newValue.toString())) {
             return false;
         }
         else {
-            cloneIgnoreListManager()[index.row()].ignoreRule = newValue.toString();
+            cloneIgnoreListManager()[index.row()].setContents(newValue.toString());
             return true;
         }
     default:
@@ -145,12 +146,12 @@ bool IgnoreListModel::setData(const QModelIndex &index, const QVariant &value, i
 bool IgnoreListModel::newIgnoreRule(const IgnoreListManager::IgnoreListItem &item)
 {
     IgnoreListManager &manager = cloneIgnoreListManager();
-    if (manager.contains(item.ignoreRule))
+    if (manager.contains(item.contents()))
         return false;
     beginInsertRows(QModelIndex(), rowCount(), rowCount());
     // manager.addIgnoreListItem(item);
-    manager.addIgnoreListItem(item.type, item.ignoreRule, item.isRegEx, item.strictness, item.scope,
-        item.scopeRule, item.isActive);
+    manager.addIgnoreListItem(item.type(), item.contents(), item.isRegEx(), item.strictness(),
+                              item.scope(), item.scopeRule(), item.isEnabled());
     endInsertRows();
     return true;
 }
@@ -173,7 +174,8 @@ void IgnoreListModel::loadDefaults()
     IgnoreListManager::IgnoreList defaults = IgnoreListModel::defaults();
     beginInsertRows(QModelIndex(), 0, defaults.count() - 1);
     foreach(IgnoreListManager::IgnoreListItem item, defaults) {
-      manager.addIgnoreListItem(item.ignoreRule, item.isRegEx, item.strictness, item.scope, item.scopeRule);
+      manager.addIgnoreListItem(item.contents(), item.isRegEx(), item.strictness(), item.scope(),
+                                item.scopeRule());
     }
     endInsertRows();*/
 }
index f2175be..50b978e 100644 (file)
@@ -127,15 +127,15 @@ void IgnoreListSettingsPage::deleteSelectedIgnoreRule()
 void IgnoreListSettingsPage::newIgnoreRule(QString rule)
 {
     IgnoreListManager::IgnoreListItem newItem = IgnoreListManager::IgnoreListItem();
-    newItem.strictness = IgnoreListManager::SoftStrictness;
-    newItem.scope = IgnoreListManager::GlobalScope;
-    newItem.isRegEx = false;
-    newItem.isActive = true;
+    newItem.setStrictness(IgnoreListManager::SoftStrictness);
+    newItem.setScope(IgnoreListManager::GlobalScope);
+    newItem.setIsRegEx(false);
+    newItem.setIsEnabled(true);
 
     bool enableOkButton = false;
     if (!rule.isEmpty()) {
         // we're called from contextmenu
-        newItem.ignoreRule = rule;
+        newItem.setContents(rule);
         enableOkButton = true;
     }
 
@@ -146,7 +146,7 @@ void IgnoreListSettingsPage::newIgnoreRule(QString rule)
             if (QMessageBox::warning(this,
                     tr("Rule already exists"),
                     tr("There is already a rule\n\"%1\"\nPlease choose another rule.")
-                    .arg(dlg->ignoreListItem().ignoreRule),
+                    .arg(dlg->ignoreListItem().contents()),
                     QMessageBox::Ok | QMessageBox::Cancel, QMessageBox::Ok)
                 == QMessageBox::Cancel)
                 break;
@@ -252,24 +252,24 @@ IgnoreListEditDlg::IgnoreListEditDlg(const IgnoreListManager::IgnoreListItem &it
 
     ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
 
-    ui.ignoreRuleLineEdit->setText(item.ignoreRule);
+    ui.ignoreRuleLineEdit->setText(item.contents());
 
-    if (item.type == IgnoreListManager::MessageIgnore)
+    if (item.type() == IgnoreListManager::MessageIgnore)
         ui.messageTypeButton->setChecked(true);
-    else if (item.type == IgnoreListManager::CtcpIgnore)
+    else if (item.type() == IgnoreListManager::CtcpIgnore)
         ui.ctcpTypeButton->setChecked(true);
     else
         ui.senderTypeButton->setChecked(true);
 
-    ui.isRegExCheckBox->setChecked(item.isRegEx);
-    ui.isActiveCheckBox->setChecked(item.isActive);
+    ui.isRegExCheckBox->setChecked(item.isRegEx());
+    ui.isActiveCheckBox->setChecked(item.isEnabled());
 
-    if (item.strictness == IgnoreListManager::HardStrictness)
+    if (item.strictness() == IgnoreListManager::HardStrictness)
         ui.permanentStrictnessButton->setChecked(true);
     else
         ui.dynamicStrictnessButton->setChecked(true);
 
-    switch (item.scope) {
+    switch (item.scope()) {
     case IgnoreListManager::NetworkScope:
         ui.networkScopeButton->setChecked(true);
         ui.scopeRuleTextEdit->setEnabled(true);
@@ -283,10 +283,10 @@ IgnoreListEditDlg::IgnoreListEditDlg(const IgnoreListManager::IgnoreListItem &it
         ui.scopeRuleTextEdit->setEnabled(false);
     }
 
-    if (item.scope == IgnoreListManager::GlobalScope)
+    if (item.scope() == IgnoreListManager::GlobalScope)
         ui.scopeRuleTextEdit->clear();
     else
-        ui.scopeRuleTextEdit->setPlainText(item.scopeRule);
+        ui.scopeRuleTextEdit->setPlainText(item.scopeRule());
 
     connect(ui.ignoreRuleLineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(widgetHasChanged()));
     connect(ui.scopeRuleTextEdit, SIGNAL(textChanged()), this, SLOT(widgetHasChanged()));
@@ -304,44 +304,45 @@ IgnoreListEditDlg::IgnoreListEditDlg(const IgnoreListManager::IgnoreListItem &it
 void IgnoreListEditDlg::widgetHasChanged()
 {
     if (ui.messageTypeButton->isChecked())
-        _clonedIgnoreListItem.type = IgnoreListManager::MessageIgnore;
+        _clonedIgnoreListItem.setType(IgnoreListManager::MessageIgnore);
     else if (ui.ctcpTypeButton->isChecked())
-        _clonedIgnoreListItem.type = IgnoreListManager::CtcpIgnore;
+        _clonedIgnoreListItem.setType(IgnoreListManager::CtcpIgnore);
     else
-        _clonedIgnoreListItem.type = IgnoreListManager::SenderIgnore;
+        _clonedIgnoreListItem.setType(IgnoreListManager::SenderIgnore);
 
     if (ui.permanentStrictnessButton->isChecked())
-        _clonedIgnoreListItem.strictness = IgnoreListManager::HardStrictness;
+        _clonedIgnoreListItem.setStrictness(IgnoreListManager::HardStrictness);
     else
-        _clonedIgnoreListItem.strictness = IgnoreListManager::SoftStrictness;
+        _clonedIgnoreListItem.setStrictness(IgnoreListManager::SoftStrictness);
 
     if (ui.networkScopeButton->isChecked()) {
-        _clonedIgnoreListItem.scope = IgnoreListManager::NetworkScope;
+        _clonedIgnoreListItem.setScope(IgnoreListManager::NetworkScope);
         ui.scopeRuleTextEdit->setEnabled(true);
     }
     else if (ui.channelScopeButton->isChecked()) {
-        _clonedIgnoreListItem.scope = IgnoreListManager::ChannelScope;
+        _clonedIgnoreListItem.setScope(IgnoreListManager::ChannelScope);
         ui.scopeRuleTextEdit->setEnabled(true);
     }
     else {
-        _clonedIgnoreListItem.scope = IgnoreListManager::GlobalScope;
+        _clonedIgnoreListItem.setScope(IgnoreListManager::GlobalScope);
         ui.scopeRuleTextEdit->setEnabled(false);
     }
 
-    if (_clonedIgnoreListItem.scope == IgnoreListManager::GlobalScope) {
-        _clonedIgnoreListItem.scopeRule = QString();
+    if (_clonedIgnoreListItem.scope() == IgnoreListManager::GlobalScope) {
+        _clonedIgnoreListItem.setScopeRule(QString());
     }
     else {
         // Trim the resulting MultiWildcard expression
-        _clonedIgnoreListItem.scopeRule =
-                ExpressionMatch::trimMultiWildcardWhitespace(ui.scopeRuleTextEdit->toPlainText());
+        _clonedIgnoreListItem.setScopeRule(
+                    ExpressionMatch::trimMultiWildcardWhitespace(
+                        ui.scopeRuleTextEdit->toPlainText()));
     }
 
-    _clonedIgnoreListItem.ignoreRule = ui.ignoreRuleLineEdit->text();
-    _clonedIgnoreListItem.isRegEx = ui.isRegExCheckBox->isChecked();
-    _clonedIgnoreListItem.isActive = ui.isActiveCheckBox->isChecked();
+    _clonedIgnoreListItem.setContents(ui.ignoreRuleLineEdit->text());
+    _clonedIgnoreListItem.setIsRegEx(ui.isRegExCheckBox->isChecked());
+    _clonedIgnoreListItem.setIsEnabled(ui.isActiveCheckBox->isChecked());
 
-    if (!_clonedIgnoreListItem.ignoreRule.isEmpty() && _clonedIgnoreListItem != _ignoreListItem)
+    if (!_clonedIgnoreListItem.contents().isEmpty() && _clonedIgnoreListItem != _ignoreListItem)
         _hasChanged = true;
     else
         _hasChanged = false;