X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;f=src%2Fqtui%2Fqtuimessageprocessor.h;h=3f9d831a8cfe2ddc5f09e5f93ba9e51fece87a34;hb=4e51500401db3c85dbe5e92e5e5c15b6e3c87787;hp=d8559d362f8de405a0bf8d1ea8420bd1a684125c;hpb=54ebc1bf00f4f9a8376629925329f0e72be04662;p=quassel.git diff --git a/src/qtui/qtuimessageprocessor.h b/src/qtui/qtuimessageprocessor.h index d8559d36..3f9d831a 100644 --- a/src/qtui/qtuimessageprocessor.h +++ b/src/qtui/qtuimessageprocessor.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2018 by the Quassel Project * + * Copyright (C) 2005-2020 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -21,37 +21,50 @@ #ifndef QTUIMESSAGEPROCESSOR_H_ #define QTUIMESSAGEPROCESSOR_H_ +#include + #include #include "abstractmessageprocessor.h" #include "expressionmatch.h" +#include "nickhighlightmatcher.h" class QtUiMessageProcessor : public AbstractMessageProcessor { Q_OBJECT public: - enum Mode { + enum Mode + { TimerBased, Concurrent }; - QtUiMessageProcessor(QObject *parent); + QtUiMessageProcessor(QObject* parent); inline bool isProcessing() const { return _processing; } inline Mode processMode() const { return _processMode; } - void reset(); + void reset() override; public slots: - void process(Message &msg); - void process(QList &msgs); + void process(Message& msg) override; + void process(QList& msgs) override; + + /** + * Network removed from system + * + * Handles cleaning up cache from stale networks. + * + * @param id Network ID of removed network + */ + void networkRemoved(NetworkId id) override; private slots: void processNextMessage(); - void nicksCaseSensitiveChanged(const QVariant &variant); - void highlightListChanged(const QVariant &variant); - void highlightNickChanged(const QVariant &variant); + void nicksCaseSensitiveChanged(const QVariant& variant); + void highlightListChanged(const QVariant& variant); + void highlightNickChanged(const QVariant& variant); private: /** @@ -63,7 +76,7 @@ private: /** * Construct an empty highlight rule */ - LegacyHighlightRule() {} + LegacyHighlightRule() = default; /** * Construct a highlight rule with the given parameters @@ -74,10 +87,12 @@ private: * @param isEnabled True if enabled, otherwise false * @param chanName String representing a channel name expression to match */ - LegacyHighlightRule(QString contents, bool isRegEx, bool isCaseSensitive, bool isEnabled, - QString chanName) - : _contents(contents), _isRegEx(isRegEx), _isCaseSensitive(isCaseSensitive), - _isEnabled(isEnabled), _chanName(chanName) + LegacyHighlightRule(QString contents, bool isRegEx, bool isCaseSensitive, bool isEnabled, QString chanName) + : _contents(std::move(contents)) + , _isRegEx(isRegEx) + , _isCaseSensitive(isCaseSensitive) + , _isEnabled(isEnabled) + , _chanName(std::move(chanName)) { _cacheInvalid = true; // Cache expression matches on construction @@ -101,15 +116,14 @@ private: * * @return String representing a phrase or expression to match */ - inline QString contents() const { - return _contents; - } + inline QString contents() const { return _contents; } /** * Sets the message contents this rule matches * * @param contents String representing a phrase or expression to match */ - inline void setContents(const QString &contents) { + inline void setContents(const QString& contents) + { _contents = contents; _cacheInvalid = true; } @@ -119,15 +133,14 @@ private: * * @return True if regular expression, otherwise false */ - inline bool isRegEx() const { - return _isRegEx; - } + inline bool isRegEx() const { return _isRegEx; } /** * Sets if this rule is a regular expression rule * * @param isRegEx True if regular expression, otherwise false */ - inline void setIsRegEx(bool isRegEx) { + inline void setIsRegEx(bool isRegEx) + { _isRegEx = isRegEx; _cacheInvalid = true; } @@ -137,15 +150,14 @@ private: * * @return True if case sensitive, otherwise false */ - inline bool isCaseSensitive() const { - return _isCaseSensitive; - } + inline bool isCaseSensitive() const { return _isCaseSensitive; } /** * Sets if this rule is case sensitive * * @param isCaseSensitive True if case sensitive, otherwise false */ - inline void setIsCaseSensitive(bool isCaseSensitive) { + inline void setIsCaseSensitive(bool isCaseSensitive) + { _isCaseSensitive = isCaseSensitive; _cacheInvalid = true; } @@ -155,17 +167,13 @@ private: * * @return True if enabled, otherwise false */ - inline bool isEnabled() const { - return _isEnabled; - } + inline bool isEnabled() const { return _isEnabled; } /** * Sets if this rule is enabled and active * * @param isEnabled True if enabled, otherwise false */ - inline void setIsEnabled(bool isEnabled) { - _isEnabled = isEnabled; - } + inline void setIsEnabled(bool isEnabled) { _isEnabled = isEnabled; } /** * Gets the channel name this rule matches @@ -174,15 +182,14 @@ private: * * @return String representing a phrase or expression to match */ - inline QString chanName() const { - return _chanName; - } + inline QString chanName() const { return _chanName; } /** * Sets the channel name this rule matches * * @param chanName String representing a phrase or expression to match */ - inline void setChanName(const QString &chanName) { + inline void setChanName(const QString& chanName) + { _chanName = chanName; _cacheInvalid = true; } @@ -192,7 +199,8 @@ private: * * @return Expression matcher to compare with message contents */ - inline ExpressionMatch contentsMatcher() const { + inline ExpressionMatch contentsMatcher() const + { if (_cacheInvalid) { determineExpressions(); } @@ -204,14 +212,15 @@ private: * * @return Expression matcher to compare with channel name */ - inline ExpressionMatch chanNameMatcher() const { + inline ExpressionMatch chanNameMatcher() const + { if (_cacheInvalid) { determineExpressions(); } return _chanNameMatch; } - bool operator!=(const LegacyHighlightRule &other) const; + bool operator!=(const LegacyHighlightRule& other) const; private: /** @@ -227,52 +236,30 @@ private: // These represent internal cache and should be safe to mutate in 'const' functions // See https://stackoverflow.com/questions/3141087/what-is-meant-with-const-at-end-of-function-declaration - mutable bool _cacheInvalid = true; ///< If true, match cache needs redone - mutable ExpressionMatch _contentsMatch = {}; ///< Expression match cache for message content - mutable ExpressionMatch _chanNameMatch = {}; ///< Expression match cache for channel name + mutable bool _cacheInvalid = true; ///< If true, match cache needs redone + mutable ExpressionMatch _contentsMatch = {}; ///< Expression match cache for message content + mutable ExpressionMatch _chanNameMatch = {}; ///< Expression match cache for channel name }; using LegacyHighlightRuleList = QList; - void checkForHighlight(Message &msg); + void checkForHighlight(Message& msg); void startProcessing(); using HighlightNickType = NotificationSettings::HighlightNickType; - /** - * Update internal cache of expression matching if needed - */ - void determineNickExpressions(const QString ¤tNick, - const QStringList identityNicks) const; - - /** - * Check if nickname matching cache is invalid - * @param currentNick - * @param identityNicks - * @return - */ - bool cacheNickInvalid(const QString ¤tNick, const QStringList identityNicks) const { - if (_cacheNickConfigInvalid) return true; - if (_cachedNickCurrent != currentNick) return true; - if (_cachedIdentityNicks != identityNicks) return true; - } + LegacyHighlightRuleList _highlightRuleList; ///< Custom highlight rule list + NickHighlightMatcher _nickMatcher = {}; ///< Nickname highlight matcher - LegacyHighlightRuleList _highlightRuleList; + /// Nickname highlighting mode HighlightNickType _highlightNick = HighlightNickType::CurrentNick; - bool _nicksCaseSensitive = false; - - // These represent internal cache and should be safe to mutate in 'const' functions - mutable bool _cacheNickConfigInvalid = true; ///< If true, nick match cache needs redone - mutable QString _cachedNickCurrent = {}; ///< Last cached current nick - mutable QStringList _cachedIdentityNicks = {}; ///< Last cached identity nicks - mutable ExpressionMatch _cachedNickMatcher = {}; ///< Expression match cache for nicks + bool _nicksCaseSensitive = false; ///< If true, match nicknames with exact case - QList > _processQueue; + QList> _processQueue; QList _currentBatch; QTimer _processTimer; bool _processing; Mode _processMode; }; - #endif