1 /***************************************************************************
2 * Copyright (C) 2005-08 by the Quassel Project *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) version 3. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #include "qtuimessageprocessor.h"
24 #include "clientsettings.h"
26 #include "messagemodel.h"
29 QtUiMessageProcessor::QtUiMessageProcessor(QObject *parent) : AbstractMessageProcessor(parent) {
34 void QtUiMessageProcessor::processMessage(Message &msg) {
35 checkForHighlight(msg);
36 Client::messageModel()->insertMessage(msg);
39 void QtUiMessageProcessor::processMessages(QList<Message> &msgs) {
40 foreach(Message msg, msgs) {
41 checkForHighlight(msg);
42 Client::messageModel()->insertMessage(msg);
46 // TODO optimize checkForHighlight
47 void QtUiMessageProcessor::checkForHighlight(Message &msg) {
48 if(!((msg.type() & (Message::Plain | Message::Notice | Message::Action)) && !(msg.flags() & Message::Self)))
51 NotificationSettings notificationSettings;
52 const Network *net = Client::network(msg.bufferInfo().networkId());
53 if(net && !net->myNick().isEmpty()) {
55 if(notificationSettings.highlightNick() == NotificationSettings::CurrentNick) {
56 nickList << net->myNick();
57 } else if(notificationSettings.highlightNick() == NotificationSettings::AllNicks) {
58 const Identity *myIdentity = Client::identity(net->identity());
60 nickList = myIdentity->nicks();
62 foreach(QString nickname, nickList) {
63 QRegExp nickRegExp("^(.*\\W)?" + QRegExp::escape(nickname) + "(\\W.*)?$");
64 if(nickRegExp.exactMatch(msg.contents())) {
65 msg.setFlags(msg.flags() | Message::Highlight);
70 foreach(QVariant highlight, notificationSettings.highlightList()) {
71 QVariantMap highlightRule = highlight.toMap();
72 if(!highlightRule["enable"].toBool())
74 Qt::CaseSensitivity caseSensitivity = highlightRule["cs"].toBool() ? Qt::CaseSensitive : Qt::CaseInsensitive;
75 QString name = highlightRule["name"].toString();
77 if(highlightRule["regex"].toBool()) {
78 userRegExp = QRegExp(name, caseSensitivity);
80 userRegExp = QRegExp("^(.*\\W)?" + QRegExp::escape(name) + "(\\W.*)?$", caseSensitivity);
82 if(userRegExp.exactMatch(msg.contents())) {
83 msg.setFlags(msg.flags() | Message::Highlight);