X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fqtuimessageprocessor.cpp;h=2466e15d7992d0e17dbaf8461adaf1ff954cd584;hp=e7fa198354509560579631bb91111be242964325;hb=7e20c659f88e26ccdfdc65f4894ed6ecf61ca8a9;hpb=6d55e659fa87565462d7f3e92da594fdcf9708a2 diff --git a/src/qtui/qtuimessageprocessor.cpp b/src/qtui/qtuimessageprocessor.cpp index e7fa1983..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 * @@ -31,17 +31,15 @@ const int progressUpdateDelay = 100; // ms between progress signal updates QtUiMessageProcessor::QtUiMessageProcessor(QObject *parent) : AbstractMessageProcessor(parent), _processing(false), - _processMode(TimerBased), - _msgsProcessed(0), - _msgCount(0) + _processMode(TimerBased) { NotificationSettings notificationSettings; _nicksCaseSensitive = notificationSettings.nicksCaseSensitive(); _highlightNick = notificationSettings.highlightNick(); highlightListChanged(notificationSettings.highlightList()); notificationSettings.notify("Highlights/NicksCaseSensitive", this, SLOT(nicksCaseSensitiveChanged(const QVariant &))); - notificationSettings.notify("highlightList", this, SLOT(highlightListChanged(const QVariant &))); - notificationSettings.notify("highlightNick", this, SLOT(highlightNickChanged(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())); @@ -58,8 +56,8 @@ void QtUiMessageProcessor::reset() { void QtUiMessageProcessor::process(Message &msg) { checkForHighlight(msg); + preProcess(msg); Client::messageModel()->insertMessage(msg); - postProcess(msg); } void QtUiMessageProcessor::process(QList &msgs) { @@ -67,7 +65,7 @@ void QtUiMessageProcessor::process(QList &msgs) { QList::iterator msgIterEnd = msgs.end(); while(msgIter != msgIterEnd) { checkForHighlight(*msgIter); - postProcess(*msgIter); + preProcess(*msgIter); msgIter++; } Client::messageModel()->insertMessages(msgs); @@ -76,20 +74,17 @@ void QtUiMessageProcessor::process(QList &msgs) { if(msgs.isEmpty()) return; _processQueue.append(msgs); - _msgCount += msgs.count(); - if(!isProcessing()) startProcessing(); - else updateProgress(); + if(!isProcessing()) + startProcessing(); } void QtUiMessageProcessor::startProcessing() { if(processMode() == TimerBased) { - if(_currentBatch.isEmpty() && _processQueue.isEmpty()) return; + if(_currentBatch.isEmpty() && _processQueue.isEmpty()) + return; _processing = true; - _msgsProcessed = 0; - _msgCount = _currentBatch.count(); - foreach(QList msglist, _processQueue) _msgCount += msglist.count(); - updateProgress(); - if(!_processTimer.isActive()) _processTimer.start(); + if(!_processTimer.isActive()) + _processTimer.start(); } } @@ -98,28 +93,12 @@ void QtUiMessageProcessor::processNextMessage() { if(_processQueue.isEmpty()) { _processTimer.stop(); _processing = false; - _msgsProcessed = _msgCount = 0; - updateProgress(); return; } _currentBatch = _processQueue.takeFirst(); } Message msg = _currentBatch.takeFirst(); process(msg); - _msgsProcessed++; - updateProgress(); -} - -void QtUiMessageProcessor::updateProgress(bool start) { - if(start) { - _progressTimer.start(); - emit progressUpdated(_msgsProcessed, _msgCount); - } else { - if(_msgCount == 0 || _progressTimer.elapsed() >= progressUpdateDelay) { - _progressTimer.restart(); - emit progressUpdated(_msgsProcessed, _msgCount); - } - } } void QtUiMessageProcessor::checkForHighlight(Message &msg) { @@ -138,7 +117,7 @@ void QtUiMessageProcessor::checkForHighlight(Message &msg) { nickList = myIdentity->nicks(); } foreach(QString nickname, nickList) { - QRegExp nickRegExp("\\b" + QRegExp::escape(nickname) + "\\b", + 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); @@ -151,13 +130,15 @@ void QtUiMessageProcessor::checkForHighlight(Message &msg) { if(!rule.isEnabled) continue; - QRegExp userRegExp; + bool match = false; if(rule.isRegExp) { - userRegExp = QRegExp(rule.name, rule.caseSensitive? Qt::CaseSensitive : Qt::CaseInsensitive); + QRegExp rx(rule.name, rule.caseSensitive? Qt::CaseSensitive : Qt::CaseInsensitive); + match = rx.exactMatch(msg.contents()); } else { - userRegExp = QRegExp("\\b" + QRegExp::escape(rule.name) + "\\b", rule.caseSensitive? Qt::CaseSensitive : Qt::CaseInsensitive); + 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; } @@ -174,13 +155,12 @@ void QtUiMessageProcessor::highlightListChanged(const QVariant &variant) { _highlightRules.clear(); QVariantList::const_iterator iter = varList.constBegin(); - QVariantList::const_iterator iterEnd = varList.constEnd(); - while(iter != iterEnd) { - QVariantMap rule; - _highlightRules << HighlightRule(rule["name"].toString(), - rule["enable"].toBool(), - rule["cs"].toBool() ? Qt::CaseSensitive : Qt::CaseInsensitive, - rule["regex"].toBool()); + 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++; } }