X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fqtuimessageprocessor.cpp;h=2466e15d7992d0e17dbaf8461adaf1ff954cd584;hp=f06030d3bf89101e8555661e5647731fb01445c1;hb=7e20c659f88e26ccdfdc65f4894ed6ecf61ca8a9;hpb=019a59ffca44ddc32fc6b16fd6cdcc8f3e1c93c6 diff --git a/src/qtui/qtuimessageprocessor.cpp b/src/qtui/qtuimessageprocessor.cpp index f06030d3..2466e15d 100644 --- a/src/qtui/qtuimessageprocessor.cpp +++ b/src/qtui/qtuimessageprocessor.cpp @@ -1,5 +1,5 @@ /*************************************************************************** -* Copyright (C) 2005-08 by the Quassel Project * +* Copyright (C) 2005-09 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -26,9 +26,21 @@ #include "messagemodel.h" #include "network.h" -QtUiMessageProcessor::QtUiMessageProcessor(QObject *parent) : AbstractMessageProcessor(parent) { - _processing = false; - _processMode = TimerBased; +const int progressUpdateDelay = 100; // ms between progress signal updates + +QtUiMessageProcessor::QtUiMessageProcessor(QObject *parent) + : AbstractMessageProcessor(parent), + _processing(false), + _processMode(TimerBased) +{ + NotificationSettings notificationSettings; + _nicksCaseSensitive = notificationSettings.nicksCaseSensitive(); + _highlightNick = notificationSettings.highlightNick(); + highlightListChanged(notificationSettings.highlightList()); + notificationSettings.notify("Highlights/NicksCaseSensitive", this, SLOT(nicksCaseSensitiveChanged(const QVariant &))); + notificationSettings.notify("Highlights/CustomList", this, SLOT(highlightListChanged(const QVariant &))); + notificationSettings.notify("Highlights/HighlightNick", this, SLOT(highlightNickChanged(const QVariant &))); + _processTimer.setInterval(0); connect(&_processTimer, SIGNAL(timeout()), this, SLOT(processNextMessage())); } @@ -44,20 +56,35 @@ void QtUiMessageProcessor::reset() { void QtUiMessageProcessor::process(Message &msg) { checkForHighlight(msg); + preProcess(msg); Client::messageModel()->insertMessage(msg); - postProcess(msg); } void QtUiMessageProcessor::process(QList &msgs) { + QList::iterator msgIter = msgs.begin(); + QList::iterator msgIterEnd = msgs.end(); + while(msgIter != msgIterEnd) { + checkForHighlight(*msgIter); + preProcess(*msgIter); + msgIter++; + } + Client::messageModel()->insertMessages(msgs); + return; + + + if(msgs.isEmpty()) return; _processQueue.append(msgs); - if(!isProcessing()) startProcessing(); + if(!isProcessing()) + startProcessing(); } void QtUiMessageProcessor::startProcessing() { if(processMode() == TimerBased) { - if(_currentBatch.isEmpty() && _processQueue.isEmpty()) return; + if(_currentBatch.isEmpty() && _processQueue.isEmpty()) + return; _processing = true; - if(!_processTimer.isActive()) _processTimer.start(); + if(!_processTimer.isActive()) + _processTimer.start(); } } @@ -74,46 +101,70 @@ void QtUiMessageProcessor::processNextMessage() { process(msg); } -// TODO optimize checkForHighlight void QtUiMessageProcessor::checkForHighlight(Message &msg) { if(!((msg.type() & (Message::Plain | Message::Notice | Message::Action)) && !(msg.flags() & Message::Self))) return; - NotificationSettings notificationSettings; + // TODO: Cache this (per network) const Network *net = Client::network(msg.bufferInfo().networkId()); if(net && !net->myNick().isEmpty()) { QStringList nickList; - if(notificationSettings.highlightNick() == NotificationSettings::CurrentNick) { + if(_highlightNick == NotificationSettings::CurrentNick) { nickList << net->myNick(); - } else if(notificationSettings.highlightNick() == NotificationSettings::AllNicks) { + } else if(_highlightNick == NotificationSettings::AllNicks) { const Identity *myIdentity = Client::identity(net->identity()); if(myIdentity) nickList = myIdentity->nicks(); } foreach(QString nickname, nickList) { - QRegExp nickRegExp("^(.*\\W)?" + QRegExp::escape(nickname) + "(\\W.*)?$"); - if(nickRegExp.exactMatch(msg.contents())) { + QRegExp nickRegExp("\\b" + QRegExp::escape(nickname) + "(\\W|\\b|$)", // + "\\b", this does not seem to work for trailing ` -> upstream bug? + _nicksCaseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive); + if(nickRegExp.indexIn(msg.contents()) >= 0) { msg.setFlags(msg.flags() | Message::Highlight); return; } } - foreach(QVariant highlight, notificationSettings.highlightList()) { - QVariantMap highlightRule = highlight.toMap(); - if(!highlightRule["enable"].toBool()) - continue; - Qt::CaseSensitivity caseSensitivity = highlightRule["cs"].toBool() ? Qt::CaseSensitive : Qt::CaseInsensitive; - QString name = highlightRule["name"].toString(); - QRegExp userRegExp; - if(highlightRule["regex"].toBool()) { - userRegExp = QRegExp(name, caseSensitivity); + for(int i = 0; i < _highlightRules.count(); i++) { + const HighlightRule &rule = _highlightRules.at(i); + if(!rule.isEnabled) + continue; + + bool match = false; + if(rule.isRegExp) { + QRegExp rx(rule.name, rule.caseSensitive? Qt::CaseSensitive : Qt::CaseInsensitive); + match = rx.exactMatch(msg.contents()); } else { - userRegExp = QRegExp("^(.*\\W)?" + QRegExp::escape(name) + "(\\W.*)?$", caseSensitivity); + QRegExp rx("\\b" + QRegExp::escape(rule.name) + "\\b", rule.caseSensitive? Qt::CaseSensitive : Qt::CaseInsensitive); + match = (rx.indexIn(msg.contents()) >= 0); } - if(userRegExp.exactMatch(msg.contents())) { + if(match) { msg.setFlags(msg.flags() | Message::Highlight); return; } } } } + +void QtUiMessageProcessor::nicksCaseSensitiveChanged(const QVariant &variant) { + _nicksCaseSensitive = variant.toBool(); +} + +void QtUiMessageProcessor::highlightListChanged(const QVariant &variant) { + QVariantList varList = variant.toList(); + + _highlightRules.clear(); + QVariantList::const_iterator iter = varList.constBegin(); + while(iter != varList.constEnd()) { + QVariantMap rule = iter->toMap(); + _highlightRules << HighlightRule(rule["Name"].toString(), + rule["Enable"].toBool(), + rule["CS"].toBool() ? Qt::CaseSensitive : Qt::CaseInsensitive, + rule["RegEx"].toBool()); + iter++; + } +} + +void QtUiMessageProcessor::highlightNickChanged(const QVariant &variant) { + _highlightNick = (NotificationSettings::HighlightNickType)variant.toInt(); +}