1 /***************************************************************************
2 * Copyright (C) 2005-2010 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 "eventstringifier.h"
23 #include "coresession.h"
24 #include "messageevent.h"
26 EventStringifier::EventStringifier(CoreSession *parent) : QObject(parent),
33 void EventStringifier::displayMsg(NetworkEvent *event, Message::Type msgType, const QString &msg, const QString &sender,
34 const QString &target, Message::Flags msgFlags) {
35 MessageEvent *msgEvent = createMessageEvent(event, msgType, msg, sender, target, msgFlags);
36 sendMessageEvent(msgEvent);
39 MessageEvent *EventStringifier::createMessageEvent(NetworkEvent *event, Message::Type msgType, const QString &msg, const QString &sender,
40 const QString &target, Message::Flags msgFlags) {
41 MessageEvent *msgEvent = new MessageEvent(msgType, event->network(), msg, sender, target, msgFlags);
45 void EventStringifier::sendMessageEvent(MessageEvent *event) { qDebug() << event->text();
46 coreSession()->eventManager()->sendEvent(event);
49 void EventStringifier::processIrcEventNumeric(IrcEventNumeric *e) {
50 //qDebug() << e->number();
52 // Welcome, status, info messages. Just display these.
53 case 2: case 3: case 4: case 5: case 251: case 252: case 253: case 254: case 255: case 372: case 375:
54 displayMsg(e, Message::Server, e->params().join(" "), e->prefix());
57 // Server error messages without param, just display them
58 case 409: case 411: case 412: case 422: case 424: case 445: case 446: case 451: case 462:
59 case 463: case 464: case 465: case 466: case 472: case 481: case 483: case 485: case 491: case 501: case 502:
60 case 431: // ERR_NONICKNAMEGIVEN
61 displayMsg(e, Message::Error, e->params().join(" "), e->prefix());
64 // Server error messages, display them in red. First param will be appended.
66 QString target = e->params().takeFirst();
67 displayMsg(e, Message::Error, e->params().join(" ") + " " + target, e->prefix(), target, Message::Redirected);
71 case 402: case 403: case 404: case 406: case 408: case 415: case 421: case 442: {
72 QString channelName = e->params().takeFirst();
73 displayMsg(e, Message::Error, e->params().join(" ") + " " + channelName, e->prefix());
77 // Server error messages which will be displayed with a colon between the first param and the rest
78 case 413: case 414: case 423: case 441: case 444: case 461: // FIXME see below for the 47x codes
79 case 467: case 471: case 473: case 474: case 475: case 476: case 477: case 478: case 482:
80 case 436: // ERR_NICKCOLLISION
82 QString p = e->params().takeFirst();
83 displayMsg(e, Message::Error, p + ": " + e->params().join(" "));
87 // Ignore these commands.
88 case 321: case 366: case 376:
92 case 903: case 904: case 905: case 906: case 907:
94 displayMsg(e, Message::Info, "CAP: " + e->params().join(""));
98 // Everything else will be marked in red, so we can add them somewhere.
101 // many nets define their own WHOIS fields. we fetch those not in need of special attention here:
102 displayMsg(e, Message::Server, "[Whois] " + e->params().join(" "), e->prefix());
104 // FIXME figure out how/where to do this in the future
105 //if(coreSession()->ircListHelper()->requestInProgress(network()->networkId()))
106 // coreSession()->ircListHelper()->reportError(params.join(" "));
108 displayMsg(e, Message::Error, QString("%1 %2").arg(e->number(), 3, 10, QLatin1Char('0')).arg(e->params().join(" ")), e->prefix());