1 /***************************************************************************
2 * Copyright (C) 2005-2016 by the Quassel Project *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) version 3. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
21 #ifndef HIGHLIGHTRULELISTMANAGER_H
22 #define HIGHLIGHTRULELISTMANAGER_H
28 #include "syncableobject.h"
30 class HighlightRuleManager : public SyncableObject
35 enum HighlightNickType {
41 inline HighlightRuleManager(QObject *parent = nullptr) : SyncableObject(parent) { setAllowClientUpdates(true); }
42 HighlightRuleManager &operator=(const HighlightRuleManager &other);
44 struct HighlightRule {
47 bool isCaseSensitive = false;
48 bool isEnabled = true;
49 bool isInverse = false;
52 HighlightRule(const QString &name_, bool isRegEx_, bool isCaseSensitive_,
53 bool isEnabled_, bool isInverse_, const QString &chanName_)
54 : name(name_), isRegEx(isRegEx_), isCaseSensitive(isCaseSensitive_), isEnabled(isEnabled_),
55 isInverse(isInverse_), chanName(chanName_) {
57 bool operator!=(const HighlightRule &other)
59 return (name != other.name ||
60 isRegEx != other.isRegEx ||
61 isCaseSensitive != other.isCaseSensitive ||
62 isEnabled != other.isEnabled ||
63 isInverse != other.isInverse ||
64 chanName != other.chanName);
67 typedef QList<HighlightRule> HighlightRuleList;
69 int indexOf(const QString &rule) const;
70 inline bool contains(const QString &rule) const { return indexOf(rule) != -1; }
71 inline bool isEmpty() const { return _highlightRuleList.isEmpty(); }
72 inline int count() const { return _highlightRuleList.count(); }
73 inline void removeAt(int index) { _highlightRuleList.removeAt(index); }
74 inline void clear() { _highlightRuleList.clear(); }
75 inline HighlightRule &operator[](int i) { return _highlightRuleList[i]; }
76 inline const HighlightRule &operator[](int i) const { return _highlightRuleList.at(i); }
77 inline const HighlightRuleList &highlightRuleList() const { return _highlightRuleList; }
79 inline HighlightNickType highlightNick() { return _highlightNick; }
80 inline bool nicksCaseSensitive() { return _nicksCaseSensitive; }
82 //! Check if a message matches the HighlightRule
83 /** This method checks if a message matches the users highlight rules.
84 * \param msg The Message that should be checked
86 bool match(const Message &msg, const QString ¤tNick, const QStringList &identityNicks);
89 virtual QVariantMap initHighlightRuleList() const;
90 virtual void initSetHighlightRuleList(const QVariantMap &HighlightRuleList);
92 //! Request removal of an ignore rule based on the rule itself.
93 /** Use this method if you want to remove a single ignore rule
94 * and get that synced with the core immediately.
95 * \param highlightRule A valid ignore rule
97 virtual inline void requestRemoveHighlightRule(const QString &highlightRule) { REQUEST(ARG(highlightRule)) }
98 virtual void removeHighlightRule(const QString &highlightRule);
100 //! Request toggling of "isEnabled" flag of a given ignore rule.
101 /** Use this method if you want to toggle the "isEnabled" flag of a single ignore rule
102 * and get that synced with the core immediately.
103 * \param highlightRule A valid ignore rule
105 virtual inline void requestToggleHighlightRule(const QString &highlightRule) { REQUEST(ARG(highlightRule)) }
106 virtual void toggleHighlightRule(const QString &highlightRule);
108 //! Request an HighlightRule to be added to the ignore list
109 /** Items added to the list with this method, get immediately synced with the core
110 * \param name The rule
111 * \param isRegEx If the rule should be interpreted as a nickname, or a regex
112 * \param isCaseSensitive If the rule should be interpreted as case-sensitive
113 * \param isEnabled If the rule is active
114 * @param chanName The channel in which the rule should apply
116 virtual inline void requestAddHighlightRule(const QString &name, bool isRegEx, bool isCaseSensitive, bool isEnabled,
117 bool isInverse, const QString &chanName)
119 REQUEST(ARG(name), ARG(isRegEx), ARG(isCaseSensitive), ARG(isEnabled), ARG(isInverse), ARG(chanName))
123 virtual void addHighlightRule(const QString &name, bool isRegEx, bool isCaseSensitive,
124 bool isEnabled, bool isInverse, const QString &chanName);
126 virtual inline void requestSetHighlightNick(HighlightNickType highlightNick)
128 REQUEST(ARG(highlightNick))
130 inline void setHighlightNick(HighlightNickType highlightNick) { _highlightNick = highlightNick; }
132 virtual inline void requestSetNicksCaseSensitive(bool nicksCaseSensitive)
134 REQUEST(ARG(nicksCaseSensitive))
136 inline void setNicksCaseSensitive(bool nicksCaseSensitive) { _nicksCaseSensitive = nicksCaseSensitive; }
139 void setHighlightRuleList(const QList<HighlightRule> &HighlightRuleList) { _highlightRuleList = HighlightRuleList; }
141 bool _match(const QString &msgContents, const QString &msgSender, Message::Type msgType, Message::Flags msgFlags, const QString &bufferName, const QString ¤tNick, const QStringList identityNicks);
144 void ruleAdded(QString name, bool isRegEx, bool isCaseSensitive, bool isEnabled, bool isInverse, QString chanName);
147 HighlightRuleList _highlightRuleList;
148 HighlightNickType _highlightNick = HighlightNickType::CurrentNick;
149 bool _nicksCaseSensitive = false;
153 #endif // HIGHLIGHTRULELISTMANAGER_H