X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;f=src%2Fcommon%2Fhighlightrulemanager.h;h=3d7407f26604271f81ff7d77e1a70760b8be15b4;hb=e9c0076ab1da4d613cf0ef97adbb1f45fed13d47;hp=427b65819a812f8bc6a59a53dcac4e5229d1ea82;hpb=ebe14ade2f3496aefc8926ce704a161c4451fedd;p=quassel.git diff --git a/src/common/highlightrulemanager.h b/src/common/highlightrulemanager.h index 427b6581..3d7407f2 100644 --- a/src/common/highlightrulemanager.h +++ b/src/common/highlightrulemanager.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2016 by the Quassel Project * + * Copyright (C) 2005-2018 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -18,20 +18,27 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ -#ifndef HIGHLIGHTRULELISTMANAGER_H -#define HIGHLIGHTRULELISTMANAGER_H +#pragma once -#include -#include #include +#include +#include +#include +#include +#include + #include "message.h" #include "syncableobject.h" class HighlightRuleManager : public SyncableObject { SYNCABLE_OBJECT - Q_OBJECT + Q_OBJECT + + Q_PROPERTY(int highlightNick READ highlightNick WRITE setHighlightNick) + Q_PROPERTY(bool nicksCaseSensitive READ nicksCaseSensitive WRITE setNicksCaseSensitive) + public: enum HighlightNickType { NoNick = 0x00, @@ -42,7 +49,9 @@ public: inline HighlightRuleManager(QObject *parent = nullptr) : SyncableObject(parent) { setAllowClientUpdates(true); } HighlightRuleManager &operator=(const HighlightRuleManager &other); - struct HighlightRule { + struct HighlightRule + { + int id; QString name; bool isRegEx = false; bool isCaseSensitive = false; @@ -51,14 +60,16 @@ public: QString sender; QString chanName; HighlightRule() {} - HighlightRule(QString name_, bool isRegEx_, bool isCaseSensitive_, bool isEnabled_, bool isInverse_, + HighlightRule(int id_, QString name_, bool isRegEx_, bool isCaseSensitive_, bool isEnabled_, bool isInverse_, QString sender_, QString chanName_) - : name(std::move(name_)), isRegEx(isRegEx_), isCaseSensitive(isCaseSensitive_), isEnabled(isEnabled_), - isInverse(isInverse_), sender(std::move(sender_)), chanName(std::move(chanName_)) { - } - bool operator!=(const HighlightRule &other) + : id(id_), name(std::move(name_)), isRegEx(isRegEx_), isCaseSensitive(isCaseSensitive_), + isEnabled(isEnabled_), isInverse(isInverse_), sender(std::move(sender_)), chanName(std::move(chanName_)) + {} + + bool operator!=(const HighlightRule &other) const { - return (name != other.name || + return (id != other.id || + name != other.name || isRegEx != other.isRegEx || isCaseSensitive != other.isCaseSensitive || isEnabled != other.isEnabled || @@ -67,10 +78,11 @@ public: chanName != other.chanName); } }; - typedef QList HighlightRuleList; - int indexOf(const QString &rule) const; - inline bool contains(const QString &rule) const { return indexOf(rule) != -1; } + using HighlightRuleList = QList; + + int indexOf(int rule) const; + inline bool contains(int rule) const { return indexOf(rule) != -1; } inline bool isEmpty() const { return _highlightRuleList.isEmpty(); } inline int count() const { return _highlightRuleList.count(); } inline void removeAt(int index) { _highlightRuleList.removeAt(index); } @@ -79,8 +91,10 @@ public: inline const HighlightRule &operator[](int i) const { return _highlightRuleList.at(i); } inline const HighlightRuleList &highlightRuleList() const { return _highlightRuleList; } - inline HighlightNickType highlightNick() { return _highlightNick; } - inline bool nicksCaseSensitive() { return _nicksCaseSensitive; } + int nextId(); + + inline int highlightNick() { return _highlightNick; } + inline bool nicksCaseSensitive() { return _nicksCaseSensitive; } //! Check if a message matches the HighlightRule /** This method checks if a message matches the users highlight rules. @@ -97,16 +111,16 @@ public slots: * and get that synced with the core immediately. * \param highlightRule A valid ignore rule */ - virtual inline void requestRemoveHighlightRule(const QString &highlightRule) { REQUEST(ARG(highlightRule)) } - virtual void removeHighlightRule(const QString &highlightRule); + virtual inline void requestRemoveHighlightRule(int highlightRule) { REQUEST(ARG(highlightRule)) } + virtual void removeHighlightRule(int highlightRule); //! Request toggling of "isEnabled" flag of a given ignore rule. /** Use this method if you want to toggle the "isEnabled" flag of a single ignore rule * and get that synced with the core immediately. * \param highlightRule A valid ignore rule */ - virtual inline void requestToggleHighlightRule(const QString &highlightRule) { REQUEST(ARG(highlightRule)) } - virtual void toggleHighlightRule(const QString &highlightRule); + virtual inline void requestToggleHighlightRule(int highlightRule) { REQUEST(ARG(highlightRule)) } + virtual void toggleHighlightRule(int highlightRule); //! Request an HighlightRule to be added to the ignore list /** Items added to the list with this method, get immediately synced with the core @@ -116,32 +130,41 @@ public slots: * \param isEnabled If the rule is active * @param chanName The channel in which the rule should apply */ - virtual inline void requestAddHighlightRule(const QString &name, bool isRegEx, bool isCaseSensitive, bool isEnabled, + virtual inline void requestAddHighlightRule(int id, const QString &name, bool isRegEx, bool isCaseSensitive, bool isEnabled, bool isInverse, const QString &sender, const QString &chanName) { - REQUEST(ARG(name), ARG(isRegEx), ARG(isCaseSensitive), ARG(isEnabled), ARG(isInverse), ARG(sender), ARG(chanName)) + REQUEST(ARG(id), ARG(name), ARG(isRegEx), ARG(isCaseSensitive), ARG(isEnabled), ARG(isInverse), ARG(sender), + ARG(chanName)) } - virtual void addHighlightRule(const QString &name, bool isRegEx, bool isCaseSensitive, bool isEnabled, + virtual void addHighlightRule(int id, const QString &name, bool isRegEx, bool isCaseSensitive, bool isEnabled, bool isInverse, const QString &sender, const QString &chanName); - virtual inline void requestSetHighlightNick(HighlightNickType highlightNick) + virtual inline void requestSetHighlightNick(int highlightNick) { REQUEST(ARG(highlightNick)) } - inline void setHighlightNick(HighlightNickType highlightNick) { _highlightNick = highlightNick; } + + inline void setHighlightNick(int highlightNick) { _highlightNick = static_cast(highlightNick); } virtual inline void requestSetNicksCaseSensitive(bool nicksCaseSensitive) { REQUEST(ARG(nicksCaseSensitive)) } + inline void setNicksCaseSensitive(bool nicksCaseSensitive) { _nicksCaseSensitive = nicksCaseSensitive; } protected: void setHighlightRuleList(const QList &HighlightRuleList) { _highlightRuleList = HighlightRuleList; } - bool _match(const QString &msgContents, const QString &msgSender, Message::Type msgType, Message::Flags msgFlags, const QString &bufferName, const QString ¤tNick, const QStringList identityNicks); + bool match(const QString &msgContents, + const QString &msgSender, + Message::Type msgType, + Message::Flags msgFlags, + const QString &bufferName, + const QString ¤tNick, + const QStringList identityNicks); signals: void ruleAdded(QString name, bool isRegEx, bool isCaseSensitive, bool isEnabled, bool isInverse, QString sender, QString chanName); @@ -151,6 +174,3 @@ private: HighlightNickType _highlightNick = HighlightNickType::CurrentNick; bool _nicksCaseSensitive = false; }; - - -#endif // HIGHLIGHTRULELISTMANAGER_H