X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fqtuimessageprocessor.cpp;h=095b3e62763ae3ebb7ebcf08a9088f43d358b336;hp=46a7f61da1f4574c638bbcbb4ae5446c7954c5cf;hb=01ed2953cbad3f2de3df262dc1601e82d903b4a8;hpb=dbe74e993bcad57c15feb30d9bed30b6d43a3332 diff --git a/src/qtui/qtuimessageprocessor.cpp b/src/qtui/qtuimessageprocessor.cpp index 46a7f61d..095b3e62 100644 --- a/src/qtui/qtuimessageprocessor.cpp +++ b/src/qtui/qtuimessageprocessor.cpp @@ -36,11 +36,13 @@ QtUiMessageProcessor::QtUiMessageProcessor(QObject *parent) _msgCount(0) { NotificationSettings notificationSettings; + _nicksCaseSensitive = notificationSettings.nicksCaseSensitive(); _highlightNick = notificationSettings.highlightNick(); highlightListChanged(notificationSettings.highlightList()); - notificationSettings.notify("highlightList", this, SLOT(highlightListChanged(const QVariant &))); - notificationSettings.notify("highlightNick", this, SLOT(highlightNickChanged(const QVariant &))); - + 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())); } @@ -61,6 +63,17 @@ void QtUiMessageProcessor::process(Message &msg) { } void QtUiMessageProcessor::process(QList &msgs) { + QList::iterator msgIter = msgs.begin(); + QList::iterator msgIterEnd = msgs.end(); + while(msgIter != msgIterEnd) { + checkForHighlight(*msgIter); + postProcess(*msgIter); + msgIter++; + } + Client::messageModel()->insertMessages(msgs); + return; + + if(msgs.isEmpty()) return; _processQueue.append(msgs); _msgCount += msgs.count(); @@ -113,7 +126,7 @@ 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; @@ -125,23 +138,24 @@ void QtUiMessageProcessor::checkForHighlight(Message &msg) { 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) + "\\b", + _nicksCaseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive); + if(nickRegExp.indexIn(msg.contents()) >= 0) { msg.setFlags(msg.flags() | Message::Highlight); return; } } for(int i = 0; i < _highlightRules.count(); i++) { - const HighlightRule &rule = _highlightRules[i]; + const HighlightRule &rule = _highlightRules.at(i); if(!rule.isEnabled) continue; QRegExp userRegExp; if(rule.isRegExp) { - userRegExp = QRegExp(rule.name, rule.caseSensitive); + userRegExp = QRegExp(rule.name, rule.caseSensitive? Qt::CaseSensitive : Qt::CaseInsensitive); } else { - userRegExp = QRegExp("^(.*\\W)?" + QRegExp::escape(rule.name) + "(\\W.*)?$", rule.caseSensitive); + userRegExp = QRegExp("\\b" + QRegExp::escape(rule.name) + "\\b", rule.caseSensitive? Qt::CaseSensitive : Qt::CaseInsensitive); } if(userRegExp.exactMatch(msg.contents())) { msg.setFlags(msg.flags() | Message::Highlight); @@ -151,18 +165,21 @@ void QtUiMessageProcessor::checkForHighlight(Message &msg) { } } +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(); - 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++; } }