X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fqtuimessageprocessor.cpp;h=ff59dde502e9b676e533d32819fc550a2690e8d3;hp=203397de5bea72ad4f69d2d46c695f699f4c216f;hb=c06d3ebf3abc0f098d6262e9bd9dd98d90edc136;hpb=5159e200a1c4c0998f302ae7c57325ed322c1e85 diff --git a/src/qtui/qtuimessageprocessor.cpp b/src/qtui/qtuimessageprocessor.cpp index 203397de..ff59dde5 100644 --- a/src/qtui/qtuimessageprocessor.cpp +++ b/src/qtui/qtuimessageprocessor.cpp @@ -26,13 +26,34 @@ #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), + _msgsProcessed(0), + _msgCount(0) +{ + NotificationSettings notificationSettings; + _highlightNick = notificationSettings.highlightNick(); + highlightListChanged(notificationSettings.highlightList()); + notificationSettings.notify("highlightList", this, SLOT(highlightListChanged(const QVariant &))); + notificationSettings.notify("highlightNick", this, SLOT(highlightNickChanged(const QVariant &))); + _processTimer.setInterval(0); connect(&_processTimer, SIGNAL(timeout()), this, SLOT(processNextMessage())); } +void QtUiMessageProcessor::reset() { + if(processMode() == TimerBased) { + if(_processTimer.isActive()) _processTimer.stop(); + _processing = false; + _currentBatch.clear(); + _processQueue.clear(); + } +} + void QtUiMessageProcessor::process(Message &msg) { checkForHighlight(msg); Client::messageModel()->insertMessage(msg); @@ -41,13 +62,19 @@ void QtUiMessageProcessor::process(Message &msg) { void QtUiMessageProcessor::process(QList &msgs) { _processQueue.append(msgs); + _msgCount += msgs.count(); if(!isProcessing()) startProcessing(); + else updateProgress(); } void QtUiMessageProcessor::startProcessing() { if(processMode() == TimerBased) { 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(); } } @@ -57,26 +84,41 @@ 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); + } + } } -// TODO optimize checkForHighlight void QtUiMessageProcessor::checkForHighlight(Message &msg) { if(!((msg.type() & (Message::Plain | Message::Notice | Message::Action)) && !(msg.flags() & Message::Self))) return; - NotificationSettings notificationSettings; + //NotificationSettings notificationSettings; 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(); @@ -89,17 +131,16 @@ void QtUiMessageProcessor::checkForHighlight(Message &msg) { } } - 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(); + for(int i = 0; i < _highlightRules.count(); i++) { + const HighlightRule &rule = _highlightRules[i]; + if(!rule.isEnabled) + continue; + QRegExp userRegExp; - if(highlightRule["regex"].toBool()) { - userRegExp = QRegExp(name, caseSensitivity); + if(rule.isRegExp) { + userRegExp = QRegExp(rule.name, rule.caseSensitive); } else { - userRegExp = QRegExp("^(.*\\W)?" + QRegExp::escape(name) + "(\\W.*)?$", caseSensitivity); + userRegExp = QRegExp("^(.*\\W)?" + QRegExp::escape(rule.name) + "(\\W.*)?$", rule.caseSensitive); } if(userRegExp.exactMatch(msg.contents())) { msg.setFlags(msg.flags() | Message::Highlight); @@ -108,3 +149,23 @@ void QtUiMessageProcessor::checkForHighlight(Message &msg) { } } } + +void QtUiMessageProcessor::highlightListChanged(const QVariant &variant) { + QVariantList varList = variant.toList(); + + _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()); + iter++; + } +} + +void QtUiMessageProcessor::highlightNickChanged(const QVariant &variant) { + _highlightNick = (NotificationSettings::HighlightNickType)variant.toInt(); +}