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
29 #include "syncableobject.h"
31 class HighlightRuleManager : public SyncableObject
36 enum HighlightNickType {
42 inline HighlightRuleManager(QObject *parent = nullptr) : SyncableObject(parent) { setAllowClientUpdates(true); }
43 HighlightRuleManager &operator=(const HighlightRuleManager &other);
45 struct HighlightRule {
48 bool isCaseSensitive = false;
49 bool isEnabled = true;
50 bool isInverse = false;
54 HighlightRule(QString name_, bool isRegEx_, bool isCaseSensitive_, bool isEnabled_, bool isInverse_,
55 QString sender_, QString chanName_)
56 : name(std::move(name_)), isRegEx(isRegEx_), isCaseSensitive(isCaseSensitive_), isEnabled(isEnabled_),
57 isInverse(isInverse_), sender(std::move(sender_)), chanName(std::move(chanName_)) {
59 bool operator!=(const HighlightRule &other)
61 return (name != other.name ||
62 isRegEx != other.isRegEx ||
63 isCaseSensitive != other.isCaseSensitive ||
64 isEnabled != other.isEnabled ||
65 isInverse != other.isInverse ||
66 sender != other.sender ||
67 chanName != other.chanName);
70 typedef QList<HighlightRule> HighlightRuleList;
72 int indexOf(const QString &rule) const;
73 inline bool contains(const QString &rule) const { return indexOf(rule) != -1; }
74 inline bool isEmpty() const { return _highlightRuleList.isEmpty(); }
75 inline int count() const { return _highlightRuleList.count(); }
76 inline void removeAt(int index) { _highlightRuleList.removeAt(index); }
77 inline void clear() { _highlightRuleList.clear(); }
78 inline HighlightRule &operator[](int i) { return _highlightRuleList[i]; }
79 inline const HighlightRule &operator[](int i) const { return _highlightRuleList.at(i); }
80 inline const HighlightRuleList &highlightRuleList() const { return _highlightRuleList; }
82 inline HighlightNickType highlightNick() { return _highlightNick; }
83 inline bool nicksCaseSensitive() { return _nicksCaseSensitive; }
85 //! Check if a message matches the HighlightRule
86 /** This method checks if a message matches the users highlight rules.
87 * \param msg The Message that should be checked
89 bool match(const Message &msg, const QString ¤tNick, const QStringList &identityNicks);
92 virtual QVariantMap initHighlightRuleList() const;
93 virtual void initSetHighlightRuleList(const QVariantMap &HighlightRuleList);
95 //! Request removal of an ignore rule based on the rule itself.
96 /** Use this method if you want to remove a single ignore rule
97 * and get that synced with the core immediately.
98 * \param highlightRule A valid ignore rule
100 virtual inline void requestRemoveHighlightRule(const QString &highlightRule) { REQUEST(ARG(highlightRule)) }
101 virtual void removeHighlightRule(const QString &highlightRule);
103 //! Request toggling of "isEnabled" flag of a given ignore rule.
104 /** Use this method if you want to toggle the "isEnabled" flag of a single ignore rule
105 * and get that synced with the core immediately.
106 * \param highlightRule A valid ignore rule
108 virtual inline void requestToggleHighlightRule(const QString &highlightRule) { REQUEST(ARG(highlightRule)) }
109 virtual void toggleHighlightRule(const QString &highlightRule);
111 //! Request an HighlightRule to be added to the ignore list
112 /** Items added to the list with this method, get immediately synced with the core
113 * \param name The rule
114 * \param isRegEx If the rule should be interpreted as a nickname, or a regex
115 * \param isCaseSensitive If the rule should be interpreted as case-sensitive
116 * \param isEnabled If the rule is active
117 * @param chanName The channel in which the rule should apply
119 virtual inline void requestAddHighlightRule(const QString &name, bool isRegEx, bool isCaseSensitive, bool isEnabled,
120 bool isInverse, const QString &sender, const QString &chanName)
122 REQUEST(ARG(name), ARG(isRegEx), ARG(isCaseSensitive), ARG(isEnabled), ARG(isInverse), ARG(sender), ARG(chanName))
126 virtual void addHighlightRule(const QString &name, bool isRegEx, bool isCaseSensitive, bool isEnabled,
127 bool isInverse, const QString &sender, const QString &chanName);
129 virtual inline void requestSetHighlightNick(HighlightNickType highlightNick)
131 REQUEST(ARG(highlightNick))
133 inline void setHighlightNick(HighlightNickType highlightNick) { _highlightNick = highlightNick; }
135 virtual inline void requestSetNicksCaseSensitive(bool nicksCaseSensitive)
137 REQUEST(ARG(nicksCaseSensitive))
139 inline void setNicksCaseSensitive(bool nicksCaseSensitive) { _nicksCaseSensitive = nicksCaseSensitive; }
142 void setHighlightRuleList(const QList<HighlightRule> &HighlightRuleList) { _highlightRuleList = HighlightRuleList; }
144 bool _match(const QString &msgContents, const QString &msgSender, Message::Type msgType, Message::Flags msgFlags, const QString &bufferName, const QString ¤tNick, const QStringList identityNicks);
147 void ruleAdded(QString name, bool isRegEx, bool isCaseSensitive, bool isEnabled, bool isInverse, QString sender, QString chanName);
150 HighlightRuleList _highlightRuleList;
151 HighlightNickType _highlightNick = HighlightNickType::CurrentNick;
152 bool _nicksCaseSensitive = false;
156 #endif // HIGHLIGHTRULELISTMANAGER_H