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 {
41 Q_ENUM(HighlightNickType);
43 inline HighlightRuleManager(QObject *parent = nullptr) : SyncableObject(parent) { setAllowClientUpdates(true); }
44 HighlightRuleManager &operator=(const HighlightRuleManager &other);
46 struct HighlightRule {
49 bool isCaseSensitive = false;
50 bool isEnabled = true;
51 bool isInverse = false;
55 HighlightRule(QString name_, bool isRegEx_, bool isCaseSensitive_, bool isEnabled_, bool isInverse_,
56 QString sender_, QString chanName_)
57 : name(std::move(name_)), isRegEx(isRegEx_), isCaseSensitive(isCaseSensitive_), isEnabled(isEnabled_),
58 isInverse(isInverse_), sender(std::move(sender_)), chanName(std::move(chanName_)) {
60 bool operator!=(const HighlightRule &other)
62 return (name != other.name ||
63 isRegEx != other.isRegEx ||
64 isCaseSensitive != other.isCaseSensitive ||
65 isEnabled != other.isEnabled ||
66 isInverse != other.isInverse ||
67 sender != other.sender ||
68 chanName != other.chanName);
71 typedef QList<HighlightRule> HighlightRuleList;
73 int indexOf(const QString &rule) const;
74 inline bool contains(const QString &rule) const { return indexOf(rule) != -1; }
75 inline bool isEmpty() const { return _highlightRuleList.isEmpty(); }
76 inline int count() const { return _highlightRuleList.count(); }
77 inline void removeAt(int index) { _highlightRuleList.removeAt(index); }
78 inline void clear() { _highlightRuleList.clear(); }
79 inline HighlightRule &operator[](int i) { return _highlightRuleList[i]; }
80 inline const HighlightRule &operator[](int i) const { return _highlightRuleList.at(i); }
81 inline const HighlightRuleList &highlightRuleList() const { return _highlightRuleList; }
83 inline HighlightNickType highlightNick() { return _highlightNick; }
84 inline bool nicksCaseSensitive() { return _nicksCaseSensitive; }
86 //! Check if a message matches the HighlightRule
87 /** This method checks if a message matches the users highlight rules.
88 * \param msg The Message that should be checked
90 bool match(const Message &msg, const QString ¤tNick, const QStringList &identityNicks);
93 virtual QVariantMap initHighlightRuleList() const;
94 virtual void initSetHighlightRuleList(const QVariantMap &HighlightRuleList);
96 //! Request removal of an ignore rule based on the rule itself.
97 /** Use this method if you want to remove a single ignore rule
98 * and get that synced with the core immediately.
99 * \param highlightRule A valid ignore rule
101 virtual inline void requestRemoveHighlightRule(const QString &highlightRule) { REQUEST(ARG(highlightRule)) }
102 virtual void removeHighlightRule(const QString &highlightRule);
104 //! Request toggling of "isEnabled" flag of a given ignore rule.
105 /** Use this method if you want to toggle the "isEnabled" flag of a single ignore rule
106 * and get that synced with the core immediately.
107 * \param highlightRule A valid ignore rule
109 virtual inline void requestToggleHighlightRule(const QString &highlightRule) { REQUEST(ARG(highlightRule)) }
110 virtual void toggleHighlightRule(const QString &highlightRule);
112 //! Request an HighlightRule to be added to the ignore list
113 /** Items added to the list with this method, get immediately synced with the core
114 * \param name The rule
115 * \param isRegEx If the rule should be interpreted as a nickname, or a regex
116 * \param isCaseSensitive If the rule should be interpreted as case-sensitive
117 * \param isEnabled If the rule is active
118 * @param chanName The channel in which the rule should apply
120 virtual inline void requestAddHighlightRule(const QString &name, bool isRegEx, bool isCaseSensitive, bool isEnabled,
121 bool isInverse, const QString &sender, const QString &chanName)
123 REQUEST(ARG(name), ARG(isRegEx), ARG(isCaseSensitive), ARG(isEnabled), ARG(isInverse), ARG(sender), ARG(chanName))
127 virtual void addHighlightRule(const QString &name, bool isRegEx, bool isCaseSensitive, bool isEnabled,
128 bool isInverse, const QString &sender, const QString &chanName);
130 virtual inline void requestSetHighlightNick(HighlightNickType highlightNick)
132 REQUEST(ARG(highlightNick))
134 inline void setHighlightNick(HighlightNickType highlightNick) { _highlightNick = highlightNick; }
136 virtual inline void requestSetNicksCaseSensitive(bool nicksCaseSensitive)
138 REQUEST(ARG(nicksCaseSensitive))
140 inline void setNicksCaseSensitive(bool nicksCaseSensitive) { _nicksCaseSensitive = nicksCaseSensitive; }
143 void setHighlightRuleList(const QList<HighlightRule> &HighlightRuleList) { _highlightRuleList = HighlightRuleList; }
145 bool _match(const QString &msgContents, const QString &msgSender, Message::Type msgType, Message::Flags msgFlags, const QString &bufferName, const QString ¤tNick, const QStringList identityNicks);
148 void ruleAdded(QString name, bool isRegEx, bool isCaseSensitive, bool isEnabled, bool isInverse, QString sender, QString chanName);
151 HighlightRuleList _highlightRuleList;
152 HighlightNickType _highlightNick = HighlightNickType::CurrentNick;
153 bool _nicksCaseSensitive = false;
157 #endif // HIGHLIGHTRULELISTMANAGER_H