X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fqtuimessageprocessor.cpp;h=fc269351f201062dcf7c389a9793483b70a30f56;hp=db038f8ce705f849b42b065b5f03a452177010ad;hb=c1cf157116de7fc3da96203aa6f03c38c7ebb650;hpb=30b159cb876a9495de42e9a3e70ca050516f0805 diff --git a/src/qtui/qtuimessageprocessor.cpp b/src/qtui/qtuimessageprocessor.cpp index db038f8c..fc269351 100644 --- a/src/qtui/qtuimessageprocessor.cpp +++ b/src/qtui/qtuimessageprocessor.cpp @@ -26,17 +26,16 @@ #include "messagemodel.h" #include "network.h" -QtUiMessageProcessor::QtUiMessageProcessor(QObject *parent) - : AbstractMessageProcessor(parent), - _processing(false), - _processMode(TimerBased) +QtUiMessageProcessor::QtUiMessageProcessor(QObject* parent) + : AbstractMessageProcessor(parent) + , _processing(false) + , _processMode(TimerBased) { NotificationSettings notificationSettings; _nicksCaseSensitive = notificationSettings.nicksCaseSensitive(); _nickMatcher.setCaseSensitive(_nicksCaseSensitive); _highlightNick = notificationSettings.highlightNick(); - _nickMatcher.setHighlightMode( - static_cast(_highlightNick)); + _nickMatcher.setHighlightMode(static_cast(_highlightNick)); highlightListChanged(notificationSettings.highlightList()); notificationSettings.notify("Highlights/NicksCaseSensitive", this, &QtUiMessageProcessor::nicksCaseSensitiveChanged); notificationSettings.notify("Highlights/CustomList", this, &QtUiMessageProcessor::highlightListChanged); @@ -46,27 +45,25 @@ QtUiMessageProcessor::QtUiMessageProcessor(QObject *parent) connect(&_processTimer, &QTimer::timeout, this, &QtUiMessageProcessor::processNextMessage); } - void QtUiMessageProcessor::reset() { if (processMode() == TimerBased) { - if (_processTimer.isActive()) _processTimer.stop(); + if (_processTimer.isActive()) + _processTimer.stop(); _processing = false; _currentBatch.clear(); _processQueue.clear(); } } - -void QtUiMessageProcessor::process(Message &msg) +void QtUiMessageProcessor::process(Message& msg) { checkForHighlight(msg); preProcess(msg); Client::messageModel()->insertMessage(msg); } - -void QtUiMessageProcessor::process(QList &msgs) +void QtUiMessageProcessor::process(QList& msgs) { QList::iterator msgIter = msgs.begin(); QList::iterator msgIterEnd = msgs.end(); @@ -78,13 +75,13 @@ void QtUiMessageProcessor::process(QList &msgs) Client::messageModel()->insertMessages(msgs); return; - if (msgs.isEmpty()) return; + if (msgs.isEmpty()) + return; _processQueue.append(msgs); if (!isProcessing()) startProcessing(); } - void QtUiMessageProcessor::startProcessing() { if (processMode() == TimerBased) { @@ -96,7 +93,6 @@ void QtUiMessageProcessor::startProcessing() } } - void QtUiMessageProcessor::processNextMessage() { if (_currentBatch.isEmpty()) { @@ -111,22 +107,21 @@ void QtUiMessageProcessor::processNextMessage() process(msg); } - -void QtUiMessageProcessor::checkForHighlight(Message &msg) +void QtUiMessageProcessor::checkForHighlight(Message& msg) { if (!((msg.type() & (Message::Plain | Message::Notice | Message::Action)) && !(msg.flags() & Message::Self))) return; // Cached per network - const NetworkId &netId = msg.bufferInfo().networkId(); - const Network *net = Client::network(netId); + const NetworkId& netId = msg.bufferInfo().networkId(); + const Network* net = Client::network(netId); if (net && !net->myNick().isEmpty()) { // Get current nick QString currentNick = net->myNick(); // Get identity nicks QStringList identityNicks = {}; - const Identity *myIdentity = Client::identity(net->identity()); + const Identity* myIdentity = Client::identity(net->identity()); if (myIdentity) { identityNicks = myIdentity->nicks(); } @@ -137,7 +132,7 @@ void QtUiMessageProcessor::checkForHighlight(Message &msg) bool matches = false; for (int i = 0; i < _highlightRuleList.count(); i++) { - auto &rule = _highlightRuleList.at(i); + auto& rule = _highlightRuleList.at(i); if (!rule.isEnabled()) continue; @@ -173,8 +168,7 @@ void QtUiMessageProcessor::checkForHighlight(Message &msg) if (_highlightNick != HighlightNickType::NoNick && !currentNick.isEmpty()) { // Nickname matching allowed and current nickname is known // Run the nickname matcher on the unformatted string - if (_nickMatcher.match(stripFormatCodes(msgContents), netId, currentNick, - identityNicks)) { + if (_nickMatcher.match(stripFormatCodes(msgContents), netId, currentNick, identityNicks)) { msg.setFlags(msg.flags() | Message::Highlight); return; } @@ -182,16 +176,14 @@ void QtUiMessageProcessor::checkForHighlight(Message &msg) } } - -void QtUiMessageProcessor::nicksCaseSensitiveChanged(const QVariant &variant) +void QtUiMessageProcessor::nicksCaseSensitiveChanged(const QVariant& variant) { _nicksCaseSensitive = variant.toBool(); // Update nickname matcher, too _nickMatcher.setCaseSensitive(_nicksCaseSensitive); } - -void QtUiMessageProcessor::highlightListChanged(const QVariant &variant) +void QtUiMessageProcessor::highlightListChanged(const QVariant& variant) { QVariantList varList = variant.toList(); @@ -200,46 +192,38 @@ void QtUiMessageProcessor::highlightListChanged(const QVariant &variant) while (iter != varList.constEnd()) { QVariantMap rule = iter->toMap(); _highlightRuleList << LegacyHighlightRule(rule["Name"].toString(), - rule["RegEx"].toBool(), - rule["CS"].toBool(), - rule["Enable"].toBool(), - rule["Channel"].toString()); + rule["RegEx"].toBool(), + rule["CS"].toBool(), + rule["Enable"].toBool(), + rule["Channel"].toString()); ++iter; } } - -void QtUiMessageProcessor::highlightNickChanged(const QVariant &variant) +void QtUiMessageProcessor::highlightNickChanged(const QVariant& variant) { _highlightNick = (HighlightNickType)variant.toInt(); // Convert from QtUiMessageProcessor::HighlightNickType (which is from NotificationSettings) to // NickHighlightMatcher::HighlightNickType - _nickMatcher.setHighlightMode( - static_cast(_highlightNick)); + _nickMatcher.setHighlightMode(static_cast(_highlightNick)); } - void QtUiMessageProcessor::networkRemoved(NetworkId id) { // Clean up nickname matching cache _nickMatcher.removeNetwork(id); } - /************************************************************************** * LegacyHighlightRule *************************************************************************/ -bool QtUiMessageProcessor::LegacyHighlightRule::operator!=(const LegacyHighlightRule &other) const +bool QtUiMessageProcessor::LegacyHighlightRule::operator!=(const LegacyHighlightRule& other) const { - return (_contents != other._contents || - _isRegEx != other._isRegEx || - _isCaseSensitive != other._isCaseSensitive || - _isEnabled != other._isEnabled || - _chanName != other._chanName); + return (_contents != other._contents || _isRegEx != other._isRegEx || _isCaseSensitive != other._isCaseSensitive + || _isEnabled != other._isEnabled || _chanName != other._chanName); // Don't compare ExpressionMatch objects as they are created as needed from the above } - void QtUiMessageProcessor::LegacyHighlightRule::determineExpressions() const { // Don't update if not needed @@ -249,13 +233,9 @@ void QtUiMessageProcessor::LegacyHighlightRule::determineExpressions() const // Set up matching rules // Message is either phrase or regex - ExpressionMatch::MatchMode contentsMode = - _isRegEx ? ExpressionMatch::MatchMode::MatchRegEx : - ExpressionMatch::MatchMode::MatchPhrase; + ExpressionMatch::MatchMode contentsMode = _isRegEx ? ExpressionMatch::MatchMode::MatchRegEx : ExpressionMatch::MatchMode::MatchPhrase; // Sender (when added) and channel are either multiple wildcard entries or regex - ExpressionMatch::MatchMode scopeMode = - _isRegEx ? ExpressionMatch::MatchMode::MatchRegEx : - ExpressionMatch::MatchMode::MatchMultiWildcard; + ExpressionMatch::MatchMode scopeMode = _isRegEx ? ExpressionMatch::MatchMode::MatchRegEx : ExpressionMatch::MatchMode::MatchMultiWildcard; _contentsMatch = ExpressionMatch(_contents, contentsMode, _isCaseSensitive); _chanNameMatch = ExpressionMatch(_chanName, scopeMode, _isCaseSensitive);