X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fqtuimessageprocessor.cpp;h=46a7f61da1f4574c638bbcbb4ae5446c7954c5cf;hp=a9209ae7b751d9aecc83af045a290e3da35b6b2c;hb=dbe74e993bcad57c15feb30d9bed30b6d43a3332;hpb=0d3d7a861472313710b51c8d19e81af56e2208a1 diff --git a/src/qtui/qtuimessageprocessor.cpp b/src/qtui/qtuimessageprocessor.cpp index a9209ae7..46a7f61d 100644 --- a/src/qtui/qtuimessageprocessor.cpp +++ b/src/qtui/qtuimessageprocessor.cpp @@ -28,10 +28,19 @@ const int progressUpdateDelay = 100; // ms between progress signal updates -QtUiMessageProcessor::QtUiMessageProcessor(QObject *parent) : AbstractMessageProcessor(parent) { - _msgsProcessed = _msgCount = 0; - _processing = false; - _processMode = TimerBased; +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())); } @@ -52,6 +61,7 @@ void QtUiMessageProcessor::process(Message &msg) { } void QtUiMessageProcessor::process(QList &msgs) { + if(msgs.isEmpty()) return; _processQueue.append(msgs); _msgCount += msgs.count(); if(!isProcessing()) startProcessing(); @@ -99,18 +109,17 @@ void QtUiMessageProcessor::updateProgress(bool start) { } } -// 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(); @@ -123,17 +132,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); @@ -142,3 +150,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(); +}