- 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, handling empty rules/matches
+ if (!split.isEmpty()) {
+ // Take the first item as the sender
+ _cacheCtcpSender = split.takeFirst();
+ // Track the rest as CTCP types to ignore
+ _cacheCtcpTypes = split;
+ }
+ else {
+ // No match found - this can happen if a pure whitespace CTCP ignore rule is
+ // created. Fall back to matching all senders.
+ if (_isRegEx) {
+ // RegEx match everything
+ _cacheCtcpSender = ".*";
+ }
+ else {
+ // Wildcard match everything
+ _cacheCtcpSender = "*";
+ }
+ // Clear the types (split is already empty)
+ _cacheCtcpTypes = split;
+ }