summaryrefslogtreecommitdiff
authorwimpie <wimpie>2005-01-08 15:16:37 (UTC)
committer wimpie <wimpie>2005-01-08 15:16:37 (UTC)
commit955213d274c2f0c11d0f153e2fed5df5170e50f6 (patch) (unidiff)
tree5bf19444380a734ae5c184ba83aeb093e6ae4113
parent9acc68823f95f62367813dbb42387ad5ee094aae (diff)
downloadopie-955213d274c2f0c11d0f153e2fed5df5170e50f6.zip
opie-955213d274c2f0c11d0f153e2fed5df5170e50f6.tar.gz
opie-955213d274c2f0c11d0f153e2fed5df5170e50f6.tar.bz2
Changes in this patch:
*Added some irc numerical codes (253, 422) *Reordered codes *Unified some functions which did exactly the same in two functions *Changed nick ordering in channel list, now nicks get ordered first by flags and then by name.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/opieirc/ircchannellist.cpp26
-rw-r--r--noncore/net/opieirc/ircchannellist.h1
-rw-r--r--noncore/net/opieirc/ircmessageparser.cpp61
-rw-r--r--noncore/net/opieirc/ircmessageparser.h8
4 files changed, 50 insertions, 46 deletions
diff --git a/noncore/net/opieirc/ircchannellist.cpp b/noncore/net/opieirc/ircchannellist.cpp
index 4e13dee..6bef318 100644
--- a/noncore/net/opieirc/ircchannellist.cpp
+++ b/noncore/net/opieirc/ircchannellist.cpp
@@ -1,47 +1,65 @@
1#include <qpe/resource.h> 1#include <qpe/resource.h>
2#include "ircchannellist.h" 2#include "ircchannellist.h"
3 3
4IRCChannelList::IRCChannelList(IRCChannel *channel, QWidget *parent, const char *name, WFlags f) : QListBox(parent, name, f) { 4IRCChannelList::IRCChannelList(IRCChannel *channel, QWidget *parent, const char *name, WFlags f) : QListBox(parent, name, f) {
5 m_channel = channel; 5 m_channel = channel;
6} 6}
7 7
8void IRCChannelList::update() { 8void IRCChannelList::update() {
9 QPixmap op = Resource::loadPixmap("opieirc/op"); 9 QPixmap op = Resource::loadPixmap("opieirc/op");
10 QPixmap hop = Resource::loadPixmap("opieirc/hop"); 10 QPixmap hop = Resource::loadPixmap("opieirc/hop");
11 QPixmap voice = Resource::loadPixmap("opieirc/voice"); 11 QPixmap voice = Resource::loadPixmap("opieirc/voice");
12 QListIterator<IRCChannelPerson> it = m_channel->people(); 12 QListIterator<IRCChannelPerson> it = m_channel->people();
13 clear(); 13 clear();
14 for (; it.current(); ++it) { 14 for (; it.current(); ++it) {
15 IRCChannelPerson *person = it.current(); 15 IRCChannelPerson *person = it.current();
16 if (person->flags & PERSON_FLAG_OP) { 16 if (person->flags & PERSON_FLAG_OP) {
17 insertItem(op, person->person->nick()); 17 insertItem(op, "1" + person->person->nick());
18 } else if (person->flags & PERSON_FLAG_HALFOP) { 18 } else if (person->flags & PERSON_FLAG_HALFOP) {
19 insertItem(op, person->person->nick()); 19 insertItem(op, "2" + person->person->nick());
20 } else if (person->flags & PERSON_FLAG_VOICE) { 20 } else if (person->flags & PERSON_FLAG_VOICE) {
21 insertItem(voice, person->person->nick()); 21 insertItem(voice, "3" + person->person->nick());
22 } else { 22 } else {
23 insertItem(person->person->nick()); 23 insertItem("4" + person->person->nick());
24 } 24 }
25 } 25 }
26 sort(); 26 sort();
27 adjustNicks();
27} 28}
28 29
29 30
30bool IRCChannelList::hasPerson(QString nick) { 31bool IRCChannelList::hasPerson(QString nick) {
31 for (unsigned int i=0; i<count(); i++) { 32 for (unsigned int i=0; i<count(); i++) {
32 if (text(i) == nick) 33 if (text(i) == nick)
33 return TRUE; 34 return TRUE;
34 } 35 }
35 return FALSE; 36 return FALSE;
36} 37}
37 38
38bool IRCChannelList::removePerson(QString nick) { 39bool IRCChannelList::removePerson(QString nick) {
39 for (unsigned int i=0; i<count(); i++) { 40 for (unsigned int i=0; i<count(); i++) {
40 if (text(i) == nick){ 41 if (text(i) == nick){
41 removeItem(i); 42 removeItem(i);
42 return TRUE; 43 return TRUE;
43 } 44 }
44 } 45 }
45 return FALSE; 46 return FALSE;
46} 47}
47 48
49void IRCChannelList::adjustNicks() {
50 QString txt;
51 QPixmap pm;
52
53 for(unsigned int i=0; i<count(); i++) {
54 txt = text(i).remove(0,1);
55 if(pixmap(i)) {
56 pm = *pixmap(i);
57 removeItem(i);
58 insertItem(pm, txt, i);
59 }
60 else {
61 removeItem(i);
62 insertItem(txt,i);
63 }
64 }
65}
diff --git a/noncore/net/opieirc/ircchannellist.h b/noncore/net/opieirc/ircchannellist.h
index deab649..b4e46eb 100644
--- a/noncore/net/opieirc/ircchannellist.h
+++ b/noncore/net/opieirc/ircchannellist.h
@@ -1,37 +1,38 @@
1/* 1/*
2 OpieIRC - An embedded IRC client 2 OpieIRC - An embedded IRC client
3 Copyright (C) 2002 Wenzel Jakob 3 Copyright (C) 2002 Wenzel Jakob
4 4
5 This program is free software; you can redistribute it and/or modify 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 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 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18
19*/ 19*/
20 20
21#ifndef __IRCCHANNELLIST_H 21#ifndef __IRCCHANNELLIST_H
22#define __IRCCHANNELLIST_H 22#define __IRCCHANNELLIST_H
23 23
24#include <qlistbox.h> 24#include <qlistbox.h>
25#include "ircchannel.h" 25#include "ircchannel.h"
26 26
27class IRCChannelList : public QListBox { 27class IRCChannelList : public QListBox {
28public: 28public:
29 IRCChannelList(IRCChannel *channel, QWidget *parent = 0, const char *name = 0, WFlags f = 0); 29 IRCChannelList(IRCChannel *channel, QWidget *parent = 0, const char *name = 0, WFlags f = 0);
30 void update(); 30 void update();
31 void adjustNicks();
31 bool hasPerson(QString nick); 32 bool hasPerson(QString nick);
32 bool removePerson(QString nick); 33 bool removePerson(QString nick);
33protected: 34protected:
34 IRCChannel *m_channel; 35 IRCChannel *m_channel;
35}; 36};
36 37
37#endif /* __IRCCHANNELLIST_H */ 38#endif /* __IRCCHANNELLIST_H */
diff --git a/noncore/net/opieirc/ircmessageparser.cpp b/noncore/net/opieirc/ircmessageparser.cpp
index ecc7e9a..f8ccbb6 100644
--- a/noncore/net/opieirc/ircmessageparser.cpp
+++ b/noncore/net/opieirc/ircmessageparser.cpp
@@ -1,570 +1,559 @@
1#include <qtextstream.h> 1#include <qtextstream.h>
2#include "ircmessageparser.h" 2#include "ircmessageparser.h"
3#include "ircversion.h" 3#include "ircversion.h"
4 4
5/* Lookup table for literal commands */ 5/* Lookup table for literal commands */
6IRCLiteralMessageParserStruct IRCMessageParser::literalParserProcTable[] = { 6IRCLiteralMessageParserStruct IRCMessageParser::literalParserProcTable[] = {
7 { "PING", FUNC(parseLiteralPing) }, 7 { "PING", FUNC(parseLiteralPing) },
8 { "NOTICE", FUNC(parseLiteralNotice) }, 8 { "NOTICE", FUNC(parseLiteralNotice) },
9 { "JOIN", FUNC(parseLiteralJoin) }, 9 { "JOIN", FUNC(parseLiteralJoin) },
10 { "PRIVMSG", FUNC(parseLiteralPrivMsg) }, 10 { "PRIVMSG", FUNC(parseLiteralPrivMsg) },
11 { "NICK", FUNC(parseLiteralNick) }, 11 { "NICK", FUNC(parseLiteralNick) },
12 { "PART", FUNC(parseLiteralPart) }, 12 { "PART", FUNC(parseLiteralPart) },
13 { "QUIT", FUNC(parseLiteralQuit) }, 13 { "QUIT", FUNC(parseLiteralQuit) },
14 { "ERROR", FUNC(parseLiteralError) }, 14 { "ERROR", FUNC(parseLiteralError) },
15 { "ERROR:", FUNC(parseLiteralError) }, 15 { "ERROR:", FUNC(parseLiteralError) },
16 { "MODE", FUNC(parseLiteralMode) }, 16 { "MODE", FUNC(parseLiteralMode) },
17 { "KICK", FUNC(parseLiteralKick) }, 17 { "KICK", FUNC(parseLiteralKick) },
18 { "TOPIC", FUNC(parseLiteralTopic) }, 18 { "TOPIC", FUNC(parseLiteralTopic) },
19 { 0 , 0 } 19 { 0 , 0 }
20}; 20};
21 21
22/* Lookup table for literal commands */ 22/* Lookup table for literal commands */
23IRCCTCPMessageParserStruct IRCMessageParser::ctcpParserProcTable[] = { 23IRCCTCPMessageParserStruct IRCMessageParser::ctcpParserProcTable[] = {
24 { "PING", FUNC(parseCTCPPing) }, 24 { "PING", FUNC(parseCTCPPing) },
25 { "VERSION", FUNC(parseCTCPVersion) }, 25 { "VERSION", FUNC(parseCTCPVersion) },
26 { "ACTION", FUNC(parseCTCPAction) }, 26 { "ACTION", FUNC(parseCTCPAction) },
27 { 0 , 0 } 27 { 0 , 0 }
28}; 28};
29 29
30/* Lookup table for numerical commands */ 30/* Lookup table for numerical commands */
31IRCNumericalMessageParserStruct IRCMessageParser::numericalParserProcTable[] = { 31IRCNumericalMessageParserStruct IRCMessageParser::numericalParserProcTable[] = {
32 { 1, FUNC(parseNumerical001) }, // RPL_WELCOME 32 { 1, FUNC(parseNumericalSecondParam) }, // RPL_WELCOME
33 { 2, FUNC(parseNumerical002) }, // RPL_YOURHOST 33 { 2, FUNC(parseNumericalSecondParam) }, // RPL_YOURHOST
34 { 3, FUNC(parseNumerical003) }, // RPL_CREATED 34 { 3, FUNC(parseNumericalSecondParam) }, // RPL_CREATED
35 { 4, FUNC(parseNumerical004) }, // RPL_MYINFO 35 { 4, FUNC(parseNumericalAllParams) }, // RPL_MYINFO
36 { 5, FUNC(parseNumerical005) }, // RPL_BOUNCE, RPL_PROTOCTL 36 { 5, FUNC(parseNumericalSecondParam) }, // RPL_BOUNCE, RPL_PROTOCTL
37 { 251, FUNC(parseNumericalStats) }, // RPL_LUSERCLIENT 37 { 250, FUNC(parseNumericalAllParams) }, // RPL_STATSCONN
38 { 252, FUNC(parseNumericalStats) }, // RPL_LUSEROP 38 { 251, FUNC(parseNumericalSecondParam) }, // RPL_LUSERCLIENT
39 { 265, FUNC(parseNumericalStats) }, // RPL_LOCALUSERS 39 { 252, FUNC(parseNumericalAllParams) }, // RPL_LUSEROP
40 { 266, FUNC(parseNumericalStats) }, // RPL_GLOBALUSERS 40 { 253, FUNC(parseNumericalAllParams) }, // RPL_LUSERUNKNOWN
41 { 250, FUNC(parseNumericalStats) }, // RPL_STATSCONN 41 { 254, FUNC(parseNumericalAllParams) }, // RPL_LUSERCHANNELS
42 { 254, FUNC(nullFunc)}, // RPL_LUSERCHANNELS 42 { 255, FUNC(parseNumericalSecondParam) }, // RPL_LUSERME
43 { 255, FUNC(parseNumericalStats) }, // RPL_LUSERNAME 43 { 265, FUNC(parseNumericalAllParams) }, // RPL_LOCALUSERS
44 { 266, FUNC(parseNumericalAllParams) }, // RPL_GLOBALUSERS
44 { 332, FUNC(parseNumericalTopic) }, // RPL_TOPIC 45 { 332, FUNC(parseNumericalTopic) }, // RPL_TOPIC
45 { 333, FUNC(parseNumericalTopicWhoTime) }, // RPL_TOPICWHOTIME 46 { 333, FUNC(parseNumericalTopicWhoTime) }, // RPL_TOPICWHOTIME
46 { 353, FUNC(parseNumericalNames) }, // RPL_NAMREPLY 47 { 353, FUNC(parseNumericalNames) }, // RPL_NAMREPLY
47 { 366, FUNC(parseNumericalEndOfNames) }, // RPL_ENDOFNAMES 48 { 366, FUNC(parseNumericalEndOfNames) }, // RPL_ENDOFNAMES
48 { 375, FUNC(parseNumericalStats) }, // RPL_MOTDSTART 49 { 372, FUNC(parseNumericalSecondParam) }, // RPL_MOTD
49 { 372, FUNC(parseNumericalStats) }, // RPL_MOTD 50 { 375, FUNC(parseNumericalSecondParam) }, // RPL_MOTDSTART
50 { 376, FUNC(parseNumericalStats) }, // RPL_ENDOFMOTD 51 { 376, FUNC(parseNumericalSecondParam) }, // RPL_ENDOFMOTD
51 { 377, FUNC(parseNumericalStats) }, // RPL_MOTD2 52 { 377, FUNC(parseNumericalSecondParam) }, // RPL_MOTD2
52 { 378, FUNC(parseNumericalStats) }, // RPL_MOTD3 53 { 378, FUNC(parseNumericalSecondParam) }, // RPL_MOTD3
53 { 401, FUNC(parseNumericalNoSuchNick) }, // ERR_NOSUCHNICK 54 { 401, FUNC(parseNumericalNoSuchNick) }, // ERR_NOSUCHNICK
54 { 406, FUNC(parseNumericalNoSuchNick) }, // ERR_WASNOSUCHNICK 55 { 406, FUNC(parseNumericalNoSuchNick) }, // ERR_WASNOSUCHNICK
55 { 412, FUNC(parseNumericalStats) }, // ERR_NOTEXTTOSEND 56 { 412, FUNC(parseNumericalSecondParam) }, // ERR_NOTEXTTOSEND
57 { 422, FUNC(parseNumericalSecondParam) }, // ERR_NOMOTD
56 { 433, FUNC(parseNumericalNicknameInUse) }, // ERR_NICKNAMEINUSE 58 { 433, FUNC(parseNumericalNicknameInUse) }, // ERR_NICKNAMEINUSE
57 { 0, 0 } 59 { 0, 0 }
58}; 60};
59 61
62
60IRCMessageParser::IRCMessageParser(IRCSession *session) { 63IRCMessageParser::IRCMessageParser(IRCSession *session) {
61 m_session = session; 64 m_session = session;
62} 65}
63 66
64void IRCMessageParser::parse(IRCMessage *message) { 67void IRCMessageParser::parse(IRCMessage *message) {
65 /* Find out what kind of message we have here and call the appropriate handler using 68 /* Find out what kind of message we have here and call the appropriate handler using
66 the parser tables. If no handler can be found, print out an error message */ 69 the parser tables. If no handler can be found, print out an error message */
67 if (message->isNumerical()) { 70 if (message->isNumerical()) {
68 for (int i=0; i<numericalParserProcTable[i].commandNumber; i++) { 71 for (int i=0; i<numericalParserProcTable[i].commandNumber; i++) {
69 if (message->commandNumber() == numericalParserProcTable[i].commandNumber) { 72 if (message->commandNumber() == numericalParserProcTable[i].commandNumber) {
70 (this->*(numericalParserProcTable[i].proc))(message); 73 (this->*(numericalParserProcTable[i].proc))(message);
71 return; 74 return;
72 } 75 }
73 } 76 }
74 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received unhandled numeric command: %1").arg( QString::number(message->commandNumber()) ))); 77 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received unhandled numeric command: %1").arg( QString::number(message->commandNumber()) )));
75 } else if (message->isCTCP()) { 78 } else if (message->isCTCP()) {
76 for (int i=0; ctcpParserProcTable[i].commandName; i++) { 79 for (int i=0; ctcpParserProcTable[i].commandName; i++) {
77 if (message->ctcpCommand() == ctcpParserProcTable[i].commandName) { 80 if (message->ctcpCommand() == ctcpParserProcTable[i].commandName) {
78 (this->*(ctcpParserProcTable[i].proc))(message); 81 (this->*(ctcpParserProcTable[i].proc))(message);
79 return; 82 return;
80 } 83 }
81 } 84 }
82 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received unhandled ctcp command: %1").arg( message->ctcpCommand())) ); 85 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received unhandled ctcp command: %1").arg( message->ctcpCommand())) );
83 } else { 86 } else {
84 for (int i=0; literalParserProcTable[i].commandName; i++) { 87 for (int i=0; literalParserProcTable[i].commandName; i++) {
85 if (message->command() == literalParserProcTable[i].commandName) { 88 if (message->command() == literalParserProcTable[i].commandName) {
86 (this->*(literalParserProcTable[i].proc))(message); 89 (this->*(literalParserProcTable[i].proc))(message);
87 return; 90 return;
88 } 91 }
89 } 92 }
90 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received unhandled literal command: %1").arg( message->command()) )); 93 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received unhandled literal command: %1").arg( message->command()) ));
91 } 94 }
92} 95}
93 96
94void IRCMessageParser::nullFunc(IRCMessage *) { 97void IRCMessageParser::nullFunc(IRCMessage *) {
95 /* Do nothing */ 98 /* Do nothing */
96} 99}
97 100
98void IRCMessageParser::parseLiteralPing(IRCMessage *message) { 101void IRCMessageParser::parseLiteralPing(IRCMessage *message) {
99 m_session->m_connection->sendLine("PONG " + message->allParameters()); 102 m_session->m_connection->sendLine("PONG " + message->allParameters());
100} 103}
101 104
102void IRCMessageParser::parseLiteralNotice(IRCMessage *message) { 105void IRCMessageParser::parseLiteralNotice(IRCMessage *message) {
103 emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, message->allParameters())); 106 emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, message->allParameters()));
104} 107}
105 108
106void IRCMessageParser::parseLiteralJoin(IRCMessage *message) { 109void IRCMessageParser::parseLiteralJoin(IRCMessage *message) {
107 QString channelName = message->param(0).lower(); 110 QString channelName = message->param(0).lower();
108 IRCPerson mask(message->prefix()); 111 IRCPerson mask(message->prefix());
109 IRCChannel *channel = m_session->getChannel(channelName); 112 IRCChannel *channel = m_session->getChannel(channelName);
110 if (!channel) { 113 if (!channel) {
111 /* We joined */ 114 /* We joined */
112 if (mask.nick() == m_session->m_server->nick()) { 115 if (mask.nick() == m_session->m_server->nick()) {
113 channel = new IRCChannel(channelName); 116 channel = new IRCChannel(channelName);
114 m_session->addChannel(channel); 117 m_session->addChannel(channel);
115 } else { 118 } else {
116 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Nonexistant channel join - desynchronized?"))); 119 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Nonexistant channel join - desynchronized?")));
117 } 120 }
118 } else { 121 } else {
119 /* Someone else joined */ 122 /* Someone else joined */
120 if (mask.nick() != m_session->m_server->nick()) { 123 if (mask.nick() != m_session->m_server->nick()) {
121 if (!channel->getPerson(mask.nick())) { 124 if (!channel->getPerson(mask.nick())) {
122 IRCChannelPerson *chanperson = new IRCChannelPerson(); 125 IRCChannelPerson *chanperson = new IRCChannelPerson();
123 IRCPerson *person = m_session->getPerson(mask.nick()); 126 IRCPerson *person = m_session->getPerson(mask.nick());
124 if (!person) { 127 if (!person) {
125 person = new IRCPerson(message->prefix()); 128 person = new IRCPerson(message->prefix());
126 m_session->addPerson(person); 129 m_session->addPerson(person);
127 } 130 }
128 chanperson->flags = 0; 131 chanperson->flags = 0;
129 chanperson->person = person; 132 chanperson->person = person;
130 channel->addPerson(chanperson); 133 channel->addPerson(chanperson);
131 IRCOutput output(OUTPUT_OTHERJOIN ,tr("%1 joined channel %2").arg( mask.nick() ).arg( channelName )); 134 IRCOutput output(OUTPUT_OTHERJOIN ,tr("%1 joined channel %2").arg( mask.nick() ).arg( channelName ));
132 output.addParam(channel); 135 output.addParam(channel);
133 output.addParam(chanperson); 136 output.addParam(chanperson);
134 emit outputReady(output); 137 emit outputReady(output);
135 } else { 138 } else {
136 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Person has already joined the channel - desynchronized?"))); 139 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Person has already joined the channel - desynchronized?")));
137 } 140 }
138 } else { 141 } else {
139 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("You already joined the channel - desynchronized?"))); 142 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("You already joined the channel - desynchronized?")));
140 } 143 }
141 } 144 }
142} 145}
143 146
144void IRCMessageParser::parseLiteralPart(IRCMessage *message) { 147void IRCMessageParser::parseLiteralPart(IRCMessage *message) {
145 QString channelName = message->param(0).lower(); 148 QString channelName = message->param(0).lower();
146 IRCChannel *channel = m_session->getChannel(channelName); 149 IRCChannel *channel = m_session->getChannel(channelName);
147 IRCPerson mask(message->prefix()); 150 IRCPerson mask(message->prefix());
148 if (channel) { 151 if (channel) {
149 if (mask.nick() == m_session->m_server->nick()) { 152 if (mask.nick() == m_session->m_server->nick()) {
150 m_session->removeChannel(channel); 153 m_session->removeChannel(channel);
151 IRCOutput output(OUTPUT_SELFPART, tr("You left channel %1").arg( channelName )); 154 IRCOutput output(OUTPUT_SELFPART, tr("You left channel %1").arg( channelName ));
152 output.addParam(channel); 155 output.addParam(channel);
153 emit outputReady(output); 156 emit outputReady(output);
154 delete channel; 157 delete channel;
155 } else { 158 } else {
156 IRCChannelPerson *person = channel->getPerson(mask.nick()); 159 IRCChannelPerson *person = channel->getPerson(mask.nick());
157 if (person) { 160 if (person) {
158 channel->removePerson(person); 161 channel->removePerson(person);
159 IRCOutput output(OUTPUT_OTHERPART, tr("%1 left channel %2").arg( mask.nick() ).arg( channelName) ); 162 IRCOutput output(OUTPUT_OTHERPART, tr("%1 left channel %2").arg( mask.nick() ).arg( channelName) );
160 output.addParam(channel); 163 output.addParam(channel);
161 output.addParam(person); 164 output.addParam(person);
162 emit outputReady(output); 165 emit outputReady(output);
163 delete person; 166 delete person;
164 } else { 167 } else {
165 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Parting person not found - desynchronized?"))); 168 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Parting person not found - desynchronized?")));
166 } 169 }
167 } 170 }
168 } else { 171 } else {
169 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Channel for part not found - desynchronized?"))); 172 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Channel for part not found - desynchronized?")));
170 } 173 }
171} 174}
172 175
173void IRCMessageParser::parseLiteralPrivMsg(IRCMessage *message) { 176void IRCMessageParser::parseLiteralPrivMsg(IRCMessage *message) {
174 if (m_session->m_server->nick().lower() == message->param(0).lower() ) { 177 if (m_session->m_server->nick().lower() == message->param(0).lower() ) {
175 /* IRC Query message detected, verify sender and display it */ 178 /* IRC Query message detected, verify sender and display it */
176 IRCPerson mask(message->prefix()); 179 IRCPerson mask(message->prefix());
177 IRCPerson *person = m_session->getPerson(mask.nick()); 180 IRCPerson *person = m_session->getPerson(mask.nick());
178 if (!person) { 181 if (!person) {
179 /* Person not yet known, create and add to the current session */ 182 /* Person not yet known, create and add to the current session */
180 person = new IRCPerson(message->prefix()); 183 person = new IRCPerson(message->prefix());
181 m_session->addPerson(person); 184 m_session->addPerson(person);
182 } 185 }
183 IRCOutput output(OUTPUT_QUERYPRIVMSG, message->param(1)); 186 IRCOutput output(OUTPUT_QUERYPRIVMSG, message->param(1));
184 output.addParam(person); 187 output.addParam(person);
185 emit outputReady(output); 188 emit outputReady(output);
186 } else if (message->param(0).at(0) == '#' || message->param(0).at(0) == '+') { 189 } else if (message->param(0).at(0) == '#' || message->param(0).at(0) == '+') {
187 /* IRC Channel message detected, verify sender, channel and display it */ 190 /* IRC Channel message detected, verify sender, channel and display it */
188 IRCChannel *channel = m_session->getChannel(message->param(0).lower()); 191 IRCChannel *channel = m_session->getChannel(message->param(0).lower());
189 if (channel) { 192 if (channel) {
190 IRCPerson mask(message->prefix()); 193 IRCPerson mask(message->prefix());
191 IRCChannelPerson *person = channel->getPerson(mask.nick()); 194 IRCChannelPerson *person = channel->getPerson(mask.nick());
192 if (person) { 195 if (person) {
193 IRCOutput output(OUTPUT_CHANPRIVMSG, message->param(1)); 196 IRCOutput output(OUTPUT_CHANPRIVMSG, message->param(1));
194 output.addParam(channel); 197 output.addParam(channel);
195 output.addParam(person); 198 output.addParam(person);
196 emit outputReady(output); 199 emit outputReady(output);
197 } else { 200 } else {
198 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Channel message with unknown sender"))); 201 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Channel message with unknown sender")));
199 } 202 }
200 } else { 203 } else {
201 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Channel message with unknown channel %1").arg(message->param(0).lower()) )); 204 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Channel message with unknown channel %1").arg(message->param(0).lower()) ));
202 } 205 }
203 } else { 206 } else {
204 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received PRIVMSG of unknown type"))); 207 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received PRIVMSG of unknown type")));
205 } 208 }
206} 209}
207 210
208void IRCMessageParser::parseLiteralNick(IRCMessage *message) { 211void IRCMessageParser::parseLiteralNick(IRCMessage *message) {
209 212
210 IRCPerson mask(message->prefix()); 213 IRCPerson mask(message->prefix());
211 /* this way of handling nick changes really sucks */ 214 /* this way of handling nick changes really sucks */
212 if (mask.nick() == m_session->m_server->nick()) { 215 if (mask.nick() == m_session->m_server->nick()) {
213 /* We are changing our nickname */ 216 /* We are changing our nickname */
214 m_session->m_server->setNick(message->param(0)); 217 m_session->m_server->setNick(message->param(0));
215 IRCOutput output(OUTPUT_NICKCHANGE, tr("You are now known as %1").arg( message->param(0))); 218 IRCOutput output(OUTPUT_NICKCHANGE, tr("You are now known as %1").arg( message->param(0)));
216 output.addParam(0); 219 output.addParam(0);
217 emit outputReady(output); 220 emit outputReady(output);
218 } else { 221 } else {
219 /* Someone else is */ 222 /* Someone else is */
220 IRCPerson *person = m_session->getPerson(mask.nick()); 223 IRCPerson *person = m_session->getPerson(mask.nick());
221 if (person) { 224 if (person) {
222 //IRCOutput output(OUTPUT_NICKCHANGE, tr("%1 is now known as %2").arg( mask.nick() ).arg( message->param(0))); 225 //IRCOutput output(OUTPUT_NICKCHANGE, tr("%1 is now known as %2").arg( mask.nick() ).arg( message->param(0)));
223 226
224 /* new code starts here -- this removes the person from all channels */ 227 /* new code starts here -- this removes the person from all channels */
225 QList<IRCChannel> channels; 228 QList<IRCChannel> channels;
226 m_session->getChannelsByPerson(person, channels); 229 m_session->getChannelsByPerson(person, channels);
227 QListIterator<IRCChannel> it(channels); 230 QListIterator<IRCChannel> it(channels);
228 for (;it.current(); ++it) { 231 for (;it.current(); ++it) {
229 IRCChannelPerson *chanperson = it.current()->getPerson(mask.nick()); 232 IRCChannelPerson *chanperson = it.current()->getPerson(mask.nick());
230 it.current()->removePerson(chanperson); 233 it.current()->removePerson(chanperson);
231 chanperson->person->setNick(message->param(0)); 234 chanperson->person->setNick(message->param(0));
232 it.current()->addPerson(chanperson); 235 it.current()->addPerson(chanperson);
233 IRCOutput output(OUTPUT_NICKCHANGE, tr("%1 is now known as %2").arg( mask.nick() ).arg( message->param(0))); 236 IRCOutput output(OUTPUT_NICKCHANGE, tr("%1 is now known as %2").arg( mask.nick() ).arg( message->param(0)));
234 output.addParam(person); 237 output.addParam(person);
235 emit outputReady(output); 238 emit outputReady(output);
236 } 239 }
237 /* new code ends here */ 240 /* new code ends here */
238 } else { 241 } else {
239 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Nickname change of an unknown person"))); 242 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Nickname change of an unknown person")));
240 } 243 }
241 } 244 }
242} 245}
243 246
244void IRCMessageParser::parseLiteralQuit(IRCMessage *message) { 247void IRCMessageParser::parseLiteralQuit(IRCMessage *message) {
245 IRCPerson mask(message->prefix()); 248 IRCPerson mask(message->prefix());
246 IRCPerson *person = m_session->getPerson(mask.nick()); 249 IRCPerson *person = m_session->getPerson(mask.nick());
247 if (person) { 250 if (person) {
248 QList<IRCChannel> channels; 251 QList<IRCChannel> channels;
249 m_session->getChannelsByPerson(person, channels); 252 m_session->getChannelsByPerson(person, channels);
250 QListIterator<IRCChannel> it(channels); 253 QListIterator<IRCChannel> it(channels);
251 for (;it.current(); ++it) { 254 for (;it.current(); ++it) {
252 IRCChannelPerson *chanperson = it.current()->getPerson(mask.nick()); 255 IRCChannelPerson *chanperson = it.current()->getPerson(mask.nick());
253 it.current()->removePerson(chanperson); 256 it.current()->removePerson(chanperson);
254 delete chanperson; 257 delete chanperson;
255 } 258 }
256 m_session->removePerson(person); 259 m_session->removePerson(person);
257 IRCOutput output(OUTPUT_QUIT, tr("%1 has quit (%2)" ).arg( mask.nick() ).arg( message->param(0) )); 260 IRCOutput output(OUTPUT_QUIT, tr("%1 has quit (%2)" ).arg( mask.nick() ).arg( message->param(0) ));
258 output.addParam(person); 261 output.addParam(person);
259 emit outputReady(output); 262 emit outputReady(output);
260 delete person; 263 delete person;
261 } else { 264 } else {
262 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown person quit - desynchronized?"))); 265 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown person quit - desynchronized?")));
263 } 266 }
264} 267}
265 268
266void IRCMessageParser::parseLiteralTopic(IRCMessage *message) { 269void IRCMessageParser::parseLiteralTopic(IRCMessage *message) {
267 IRCPerson mask(message->prefix()); 270 IRCPerson mask(message->prefix());
268 IRCChannel *channel = m_session->getChannel(message->param(0).lower()); 271 IRCChannel *channel = m_session->getChannel(message->param(0).lower());
269 if (channel) { 272 if (channel) {
270 IRCOutput output(OUTPUT_TOPIC, mask.nick() + tr(" changed topic to ") + "\"" + message->param(1) + "\""); 273 IRCOutput output(OUTPUT_TOPIC, mask.nick() + tr(" changed topic to ") + "\"" + message->param(1) + "\"");
271 output.addParam(channel); 274 output.addParam(channel);
272 emit outputReady(output); 275 emit outputReady(output);
273 } else { 276 } else {
274 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown channel topic - desynchronized?"))); 277 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown channel topic - desynchronized?")));
275 } 278 }
276} 279}
277 280
278void IRCMessageParser::parseLiteralError(IRCMessage *message) { 281void IRCMessageParser::parseLiteralError(IRCMessage *message) {
279 emit outputReady(IRCOutput(OUTPUT_ERROR, message->allParameters())); 282 emit outputReady(IRCOutput(OUTPUT_ERROR, message->allParameters()));
280} 283}
281 284
282void IRCMessageParser::parseCTCPPing(IRCMessage *message) { 285void IRCMessageParser::parseCTCPPing(IRCMessage *message) {
283 IRCPerson mask(message->prefix()); 286 IRCPerson mask(message->prefix());
284 m_session->m_connection->sendCTCP(mask.nick(), "PING " + message->allParameters()); 287 m_session->m_connection->sendCTCP(mask.nick(), "PING " + message->allParameters());
285 emit outputReady(IRCOutput(OUTPUT_CTCP, tr("Received a CTCP PING from ")+mask.nick())); 288 emit outputReady(IRCOutput(OUTPUT_CTCP, tr("Received a CTCP PING from ")+mask.nick()));
286 289
287 //IRCPerson mask(message->prefix()); 290 //IRCPerson mask(message->prefix());
288 QString dest = message->ctcpDestination(); 291 QString dest = message->ctcpDestination();
289 if (dest.startsWith("#")) { 292 if (dest.startsWith("#")) {
290 IRCChannel *channel = m_session->getChannel(dest.lower()); 293 IRCChannel *channel = m_session->getChannel(dest.lower());
291 if (channel) { 294 if (channel) {
292 IRCChannelPerson *person = channel->getPerson(mask.nick()); 295 IRCChannelPerson *person = channel->getPerson(mask.nick());
293 if (person) { 296 if (person) {
294 IRCOutput output(OUTPUT_CHANACTION, tr("Received a CTCP PING from ")+ mask.nick()) ; 297 IRCOutput output(OUTPUT_CHANACTION, tr("Received a CTCP PING from ")+ mask.nick()) ;
295 output.addParam(channel); 298 output.addParam(channel);
296 output.addParam(person); 299 output.addParam(person);
297 emit outputReady(output); 300 emit outputReady(output);
298 } else { 301 } else {
299 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP PING with unknown person - Desynchronized?"))); 302 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP PING with unknown person - Desynchronized?")));
300 } 303 }
301 } else { 304 } else {
302 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP PING with unknown channel - Desynchronized?"))); 305 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP PING with unknown channel - Desynchronized?")));
303 } 306 }
304 } else { 307 } else {
305 if (message->ctcpDestination() == m_session->m_server->nick()) { 308 if (message->ctcpDestination() == m_session->m_server->nick()) {
306 IRCPerson *person = m_session->getPerson(mask.nick()); 309 IRCPerson *person = m_session->getPerson(mask.nick());
307 if (!person) { 310 if (!person) {
308 /* Person not yet known, create and add to the current session */ 311 /* Person not yet known, create and add to the current session */
309 person = new IRCPerson(message->prefix()); 312 person = new IRCPerson(message->prefix());
310 m_session->addPerson(person); 313 m_session->addPerson(person);
311 } 314 }
312 IRCOutput output(OUTPUT_QUERYACTION, tr("Received a CTCP PING from ")+ mask.nick() ); 315 IRCOutput output(OUTPUT_QUERYACTION, tr("Received a CTCP PING from ")+ mask.nick() );
313 output.addParam(person); 316 output.addParam(person);
314 emit outputReady(output); 317 emit outputReady(output);
315 } else { 318 } else {
316 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP PING with bad recipient"))); 319 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP PING with bad recipient")));
317 } 320 }
318 } 321 }
319 322
320} 323}
321 324
322void IRCMessageParser::parseCTCPVersion(IRCMessage *message) { 325void IRCMessageParser::parseCTCPVersion(IRCMessage *message) {
323 IRCPerson mask(message->prefix()); 326 IRCPerson mask(message->prefix());
324 m_session->m_connection->sendCTCP(mask.nick(), APP_VERSION " " APP_COPYSTR); 327 m_session->m_connection->sendCTCP(mask.nick(), APP_VERSION " " APP_COPYSTR);
325 emit outputReady(IRCOutput(OUTPUT_CTCP, tr("Received a CTCP VERSION from ")+mask.nick())); 328 emit outputReady(IRCOutput(OUTPUT_CTCP, tr("Received a CTCP VERSION from ")+mask.nick()));
326} 329}
327 330
328void IRCMessageParser::parseCTCPAction(IRCMessage *message) { 331void IRCMessageParser::parseCTCPAction(IRCMessage *message) {
329 IRCPerson mask(message->prefix()); 332 IRCPerson mask(message->prefix());
330 QString dest = message->ctcpDestination(); 333 QString dest = message->ctcpDestination();
331 if (dest.startsWith("#")) { 334 if (dest.startsWith("#")) {
332 IRCChannel *channel = m_session->getChannel(dest.lower()); 335 IRCChannel *channel = m_session->getChannel(dest.lower());
333 if (channel) { 336 if (channel) {
334 IRCChannelPerson *person = channel->getPerson(mask.nick()); 337 IRCChannelPerson *person = channel->getPerson(mask.nick());
335 if (person) { 338 if (person) {
336 IRCOutput output(OUTPUT_CHANACTION, "*" + mask.nick() + message->param(0)); 339 IRCOutput output(OUTPUT_CHANACTION, "*" + mask.nick() + message->param(0));
337 output.addParam(channel); 340 output.addParam(channel);
338 output.addParam(person); 341 output.addParam(person);
339 emit outputReady(output); 342 emit outputReady(output);
340 } else { 343 } else {
341 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP ACTION with unknown person - Desynchronized?"))); 344 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP ACTION with unknown person - Desynchronized?")));
342 } 345 }
343 } else { 346 } else {
344 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP ACTION with unknown channel - Desynchronized?"))); 347 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP ACTION with unknown channel - Desynchronized?")));
345 } 348 }
346 } else { 349 } else {
347 if (message->ctcpDestination() == m_session->m_server->nick()) { 350 if (message->ctcpDestination() == m_session->m_server->nick()) {
348 IRCPerson *person = m_session->getPerson(mask.nick()); 351 IRCPerson *person = m_session->getPerson(mask.nick());
349 if (!person) { 352 if (!person) {
350 /* Person not yet known, create and add to the current session */ 353 /* Person not yet known, create and add to the current session */
351 person = new IRCPerson(message->prefix()); 354 person = new IRCPerson(message->prefix());
352 m_session->addPerson(person); 355 m_session->addPerson(person);
353 } 356 }
354 IRCOutput output(OUTPUT_QUERYACTION, "*" + mask.nick() + message->param(0)); 357 IRCOutput output(OUTPUT_QUERYACTION, "*" + mask.nick() + message->param(0));
355 output.addParam(person); 358 output.addParam(person);
356 emit outputReady(output); 359 emit outputReady(output);
357 } else { 360 } else {
358 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP ACTION with bad recipient"))); 361 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP ACTION with bad recipient")));
359 } 362 }
360 } 363 }
361} 364}
362 365
363void IRCMessageParser::parseLiteralMode(IRCMessage *message) { 366void IRCMessageParser::parseLiteralMode(IRCMessage *message) {
364 IRCPerson mask(message->prefix()); 367 IRCPerson mask(message->prefix());
365 368
366 if (message->param(0).startsWith("#")) { 369 if (message->param(0).startsWith("#")) {
367 IRCChannel *channel = m_session->getChannel(message->param(0).lower()); 370 IRCChannel *channel = m_session->getChannel(message->param(0).lower());
368 if (channel) { 371 if (channel) {
369 QString temp, parameters = message->allParameters().right(message->allParameters().length() - channel->channelname().length() - 1); 372 QString temp, parameters = message->allParameters().right(message->allParameters().length() - channel->channelname().length() - 1);
370 QTextIStream stream(&parameters); 373 QTextIStream stream(&parameters);
371 bool set = FALSE; 374 bool set = FALSE;
372 while (!stream.atEnd()) { 375 while (!stream.atEnd()) {
373 stream >> temp; 376 stream >> temp;
374 if (temp.startsWith("+")) { 377 if (temp.startsWith("+")) {
375 set = TRUE; 378 set = TRUE;
376 temp = temp.right(1); 379 temp = temp.right(1);
377 } else if (temp.startsWith("-")) { 380 } else if (temp.startsWith("-")) {
378 set = FALSE; 381 set = FALSE;
379 temp = temp.right(1); 382 temp = temp.right(1);
380 } else { 383 } else {
381 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change has unknown type"))); 384 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change has unknown type")));
382 return; 385 return;
383 } 386 }
384 if (temp == "o") { 387 if (temp == "o") {
385 stream >> temp; 388 stream >> temp;
386 IRCChannelPerson *person = channel->getPerson(temp); 389 IRCChannelPerson *person = channel->getPerson(temp);
387 if (person) { 390 if (person) {
388 if (set) { 391 if (set) {
389 person->flags |= PERSON_FLAG_OP; 392 person->flags |= PERSON_FLAG_OP;
390 IRCOutput output(OUTPUT_CHANPERSONMODE, mask.nick() + tr(" gives channel operator status to " + person->person->nick())); 393 IRCOutput output(OUTPUT_CHANPERSONMODE, mask.nick() + tr(" gives channel operator status to " + person->person->nick()));
391 output.addParam(channel); 394 output.addParam(channel);
392 output.addParam(person); 395 output.addParam(person);
393 emit outputReady(output); 396 emit outputReady(output);
394 } else { 397 } else {
395 person->flags &= 0xFFFF - PERSON_FLAG_OP; 398 person->flags &= 0xFFFF - PERSON_FLAG_OP;
396 IRCOutput output(OUTPUT_CHANPERSONMODE, mask.nick() + tr(" removes channel operator status from " + person->person->nick())); 399 IRCOutput output(OUTPUT_CHANPERSONMODE, mask.nick() + tr(" removes channel operator status from " + person->person->nick()));
397 output.addParam(channel); 400 output.addParam(channel);
398 output.addParam(person); 401 output.addParam(person);
399 emit outputReady(output); 402 emit outputReady(output);
400 } 403 }
401 } else { 404 } else {
402 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown person - Desynchronized?"))); 405 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown person - Desynchronized?")));
403 } 406 }
404 } else if (temp == "v") { 407 } else if (temp == "v") {
405 stream >> temp; 408 stream >> temp;
406 IRCChannelPerson *person = channel->getPerson(temp); 409 IRCChannelPerson *person = channel->getPerson(temp);
407 if (person) { 410 if (person) {
408 if (set) { 411 if (set) {
409 person->flags |= PERSON_FLAG_VOICE; 412 person->flags |= PERSON_FLAG_VOICE;
410 IRCOutput output(OUTPUT_CHANPERSONMODE, mask.nick() + tr(" gives voice to " + person->person->nick())); 413 IRCOutput output(OUTPUT_CHANPERSONMODE, mask.nick() + tr(" gives voice to " + person->person->nick()));
411 output.addParam(channel); 414 output.addParam(channel);
412 output.addParam(person); 415 output.addParam(person);
413 emit outputReady(output); 416 emit outputReady(output);
414 } else { 417 } else {
415 person->flags &= 0xFFFF - PERSON_FLAG_VOICE; 418 person->flags &= 0xFFFF - PERSON_FLAG_VOICE;
416 IRCOutput output(OUTPUT_CHANPERSONMODE, mask.nick() + tr(" removes voice from " + person->person->nick())); 419 IRCOutput output(OUTPUT_CHANPERSONMODE, mask.nick() + tr(" removes voice from " + person->person->nick()));
417 output.addParam(channel); 420 output.addParam(channel);
418 output.addParam(person); 421 output.addParam(person);
419 emit outputReady(output); 422 emit outputReady(output);
420 } 423 }
421 } else { 424 } else {
422 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown person - Desynchronized?"))); 425 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown person - Desynchronized?")));
423 } 426 }
424 } else { 427 } else {
425 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown flag"))); 428 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown flag")));
426 } 429 }
427 } 430 }
428 } else { 431 } else {
429 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown kannel - Desynchronized?"))); 432 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown kannel - Desynchronized?")));
430 } 433 }
431 } else { 434 } else {
432 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("User modes not supported yet"))); 435 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("User modes not supported yet")));
433 } 436 }
434} 437}
435 438
436void IRCMessageParser::parseLiteralKick(IRCMessage *message) { 439void IRCMessageParser::parseLiteralKick(IRCMessage *message) {
437 IRCPerson mask(message->prefix()); 440 IRCPerson mask(message->prefix());
438 IRCChannel *channel = m_session->getChannel(message->param(0).lower()); 441 IRCChannel *channel = m_session->getChannel(message->param(0).lower());
439 if (channel) { 442 if (channel) {
440 IRCChannelPerson *person = channel->getPerson(message->param(1)); 443 IRCChannelPerson *person = channel->getPerson(message->param(1));
441 if (person) { 444 if (person) {
442 if (person->person->nick() == m_session->m_server->nick()) { 445 if (person->person->nick() == m_session->m_server->nick()) {
443 m_session->removeChannel(channel); 446 m_session->removeChannel(channel);
444 IRCOutput output(OUTPUT_SELFKICK, tr("You were kicked from ") + channel->channelname() + tr(" by ") + mask.nick() + " (" + message->param(2) + ")"); 447 IRCOutput output(OUTPUT_SELFKICK, tr("You were kicked from ") + channel->channelname() + tr(" by ") + mask.nick() + " (" + message->param(2) + ")");
445 output.addParam(channel); 448 output.addParam(channel);
446 emit outputReady(output); 449 emit outputReady(output);
447 } else { 450 } else {
448 /* someone else got kicked */ 451 /* someone else got kicked */
449 channel->removePerson(person); 452 channel->removePerson(person);
450 IRCOutput output(OUTPUT_OTHERKICK, person->person->nick() + tr(" was kicked from ") + channel->channelname() + tr(" by ") + mask.nick()+ " (" + message->param(2) + ")"); 453 IRCOutput output(OUTPUT_OTHERKICK, person->person->nick() + tr(" was kicked from ") + channel->channelname() + tr(" by ") + mask.nick()+ " (" + message->param(2) + ")");
451 output.addParam(channel); 454 output.addParam(channel);
452 output.addParam(person); 455 output.addParam(person);
453 emit outputReady(output); 456 emit outputReady(output);
454 } 457 }
455 } else { 458 } else {
456 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown person kick - desynchronized?"))); 459 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown person kick - desynchronized?")));
457 } 460 }
458 } else { 461 } else {
459 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown channel kick - desynchronized?"))); 462 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown channel kick - desynchronized?")));
460 } 463 }
461} 464}
462 465
463void IRCMessageParser::parseNumerical001(IRCMessage *message) {
464 /* Welcome to IRC message, display */
465 emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, message->param(1)));
466}
467 466
468void IRCMessageParser::parseNumerical002(IRCMessage *message) { 467void IRCMessageParser::parseNumericalSecondParam(IRCMessage *message) {
469 emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, message->param(1))); 468 emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, message->param(1)));
470} 469}
471 470
472void IRCMessageParser::parseNumerical003(IRCMessage *message) { 471void IRCMessageParser::parseNumericalAllParams(IRCMessage *message) {
473 emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, message->param(1)));
474}
475
476void IRCMessageParser::parseNumerical004(IRCMessage *message) {
477 emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, message->allParameters())); 472 emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, message->allParameters()));
478} 473}
479 474
480void IRCMessageParser::parseNumerical005(IRCMessage *message) {
481 emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, message->allParameters()));
482}
483
484void IRCMessageParser::parseNumericalStats(IRCMessage *message) {
485 emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, message->param(1)));
486}
487
488void IRCMessageParser::parseNumericalNames(IRCMessage *message) { 475void IRCMessageParser::parseNumericalNames(IRCMessage *message) {
489 /* Name list sent when joining a channel */ 476 /* Name list sent when joining a channel */
490 IRCChannel *channel = m_session->getChannel(message->param(2).lower()); 477 IRCChannel *channel = m_session->getChannel(message->param(2).lower());
491 if (channel != 0) { 478 if (channel != 0) {
492 QString people = message->param(3); 479 QString people = message->param(3);
493 QTextIStream stream(&people); 480 QTextIStream stream(&people);
494 QString temp; 481 QString temp;
495 482
496 while (!stream.atEnd()) { 483 while (!stream.atEnd()) {
497 stream >> temp; 484 stream >> temp;
498 485
499 char flagch = temp.at(0).latin1(); 486 char flagch = temp.at(0).latin1();
500 int flag = 0; 487 int flag = 0;
501 QString nick; 488 QString nick;
502 /* Parse person flags */ 489 /* Parse person flags */
503 if (flagch == '@' || flagch == '+' || flagch=='%' || flagch == '*') { 490 if (flagch == '@' || flagch == '+' || flagch=='%' || flagch == '*') {
504 491
505 nick = temp.right(temp.length()-1); 492 nick = temp.right(temp.length()-1);
506 switch (flagch) { 493 switch (flagch) {
507 case '@': flag = PERSON_FLAG_OP; break; 494 case '@': flag = PERSON_FLAG_OP; break;
508 case '+': flag = PERSON_FLAG_VOICE; break; 495 case '+': flag = PERSON_FLAG_VOICE; break;
509 case '%': flag = PERSON_FLAG_HALFOP; break; 496 case '%': flag = PERSON_FLAG_HALFOP; break;
510 default : flag = 0; break; 497 default : flag = 0; break;
511 } 498 }
512 } else { 499 } else {
513 nick = temp; 500 nick = temp;
514 } 501 }
515 502
516 IRCChannelPerson *chan_person = new IRCChannelPerson(); 503 IRCChannelPerson *chan_person = new IRCChannelPerson();
517 IRCPerson *person = m_session->getPerson(nick); 504 IRCPerson *person = m_session->getPerson(nick);
518 if (person == 0) { 505 if (person == 0) {
519 person = new IRCPerson(); 506 person = new IRCPerson();
520 person->setNick(nick); 507 person->setNick(nick);
521 m_session->addPerson(person); 508 m_session->addPerson(person);
522 } 509 }
523 chan_person->person = person; 510 chan_person->person = person;
524 chan_person->flags = flag; 511 chan_person->flags = flag;
525 channel->addPerson(chan_person); 512 channel->addPerson(chan_person);
526 } 513 }
527 } else { 514 } else {
528 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Server message with unknown channel"))); 515 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Server message with unknown channel")));
529 } 516 }
530} 517}
531 518
532void IRCMessageParser::parseNumericalEndOfNames(IRCMessage *message) { 519void IRCMessageParser::parseNumericalEndOfNames(IRCMessage *message) {
533 /* Done syncing to channel */ 520 /* Done syncing to channel */
534 IRCChannel *channel = m_session->getChannel(message->param(1).lower()); 521 IRCChannel *channel = m_session->getChannel(message->param(1).lower());
535 if (channel) { 522 if (channel) {
536 channel->setHasPeople(TRUE); 523 channel->setHasPeople(TRUE);
537 /* Yes, we want the names before anything happens inside the GUI */ 524 /* Yes, we want the names before anything happens inside the GUI */
538 IRCOutput output(OUTPUT_SELFJOIN, tr("You joined channel ") + channel->channelname()); 525 IRCOutput output(OUTPUT_SELFJOIN, tr("You joined channel ") + channel->channelname());
539 output.addParam(channel); 526 output.addParam(channel);
540 emit outputReady(output); 527 emit outputReady(output);
541 } else { 528 } else {
542 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Server message with unknown channel"))); 529 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Server message with unknown channel")));
543 } 530 }
544} 531}
545 532
546 533
547void IRCMessageParser::parseNumericalNicknameInUse(IRCMessage *) { 534void IRCMessageParser::parseNumericalNicknameInUse(IRCMessage *) {
548 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Nickname is in use, please reconnect with a different nickname"))); 535 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Nickname is in use, please reconnect with a different nickname")));
549 m_session->endSession(); 536 m_session->endSession();
550} 537}
551 538
552void IRCMessageParser::parseNumericalNoSuchNick(IRCMessage *) { 539void IRCMessageParser::parseNumericalNoSuchNick(IRCMessage *) {
553 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("No such nickname"))); 540 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("No such nickname")));
554} 541}
555 542
556void IRCMessageParser::parseNumericalTopic(IRCMessage *message) { 543void IRCMessageParser::parseNumericalTopic(IRCMessage *message) {
557 IRCChannel *channel = m_session->getChannel(message->param(1).lower()); 544 IRCChannel *channel = m_session->getChannel(message->param(1).lower());
558 if (channel) { 545 if (channel) {
559 IRCOutput output(OUTPUT_TOPIC, tr("Topic for channel " + channel->channelname() + " is \"" + message->param(2) + "\"")); 546 IRCOutput output(OUTPUT_TOPIC, tr("Topic for channel " + channel->channelname() + " is \"" + message->param(2) + "\""));
560 output.addParam(channel); 547 output.addParam(channel);
561 emit outputReady(output); 548 emit outputReady(output);
562 } else { 549 } else {
563 IRCOutput output(OUTPUT_TOPIC, tr("Topic for channel " + message->param(1) + " is \"" + message->param(2) + "\"")); 550 IRCOutput output(OUTPUT_TOPIC, tr("Topic for channel " + message->param(1) + " is \"" + message->param(2) + "\""));
564 output.addParam(0); 551 output.addParam(0);
565 emit outputReady(output); 552 emit outputReady(output);
566 } 553 }
567} 554}
568 555
569void IRCMessageParser::parseNumericalTopicWhoTime(IRCMessage *) { 556void IRCMessageParser::parseNumericalTopicWhoTime(IRCMessage *) {
570} 557}
558
559
diff --git a/noncore/net/opieirc/ircmessageparser.h b/noncore/net/opieirc/ircmessageparser.h
index c4dd96c..5412f5f 100644
--- a/noncore/net/opieirc/ircmessageparser.h
+++ b/noncore/net/opieirc/ircmessageparser.h
@@ -1,99 +1,95 @@
1/* 1/*
2 OpieIRC - An embedded IRC client 2 OpieIRC - An embedded IRC client
3 Copyright (C) 2002 Wenzel Jakob 3 Copyright (C) 2002 Wenzel Jakob
4 4
5 This program is free software; you can redistribute it and/or modify 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 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 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18
19*/ 19*/
20 20
21#ifndef __IRCMESSAGEPARSER_H 21#ifndef __IRCMESSAGEPARSER_H
22#define __IRCMESSAGEPARSER_H 22#define __IRCMESSAGEPARSER_H
23 23
24#include "ircsession.h" 24#include "ircsession.h"
25 25
26/* Macro to facilitate the parser table's creation */ 26/* Macro to facilitate the parser table's creation */
27#define FUNC(__proc) &IRCMessageParser::__proc 27#define FUNC(__proc) &IRCMessageParser::__proc
28 28
29class IRCMessageParser; 29class IRCMessageParser;
30 30
31/* Typedef representing a parser function */ 31/* Typedef representing a parser function */
32typedef void (IRCMessageParser::*IRCMessageParseProc)(IRCMessage *); 32typedef void (IRCMessageParser::*IRCMessageParseProc)(IRCMessage *);
33 33
34/* Struct representing a literal command handler */ 34/* Struct representing a literal command handler */
35typedef struct IRCLiteralMessageParserStruct { 35typedef struct IRCLiteralMessageParserStruct {
36 char *commandName; 36 char *commandName;
37 IRCMessageParseProc proc; 37 IRCMessageParseProc proc;
38}; 38};
39 39
40/* Struct representing a ctcp command handler */ 40/* Struct representing a ctcp command handler */
41typedef struct IRCCTCPMessageParserStruct { 41typedef struct IRCCTCPMessageParserStruct {
42 char *commandName; 42 char *commandName;
43 IRCMessageParseProc proc; 43 IRCMessageParseProc proc;
44}; 44};
45 45
46/* Struct representing a numerical command handler */ 46/* Struct representing a numerical command handler */
47typedef struct IRCNumericalMessageParserStruct { 47typedef struct IRCNumericalMessageParserStruct {
48 unsigned short commandNumber; 48 unsigned short commandNumber;
49 IRCMessageParseProc proc; 49 IRCMessageParseProc proc;
50}; 50};
51 51
52class IRCMessageParser : public QObject { 52class IRCMessageParser : public QObject {
53 Q_OBJECT 53 Q_OBJECT
54public: 54public:
55 /* Create an IRCMessageParser object */ 55 /* Create an IRCMessageParser object */
56 IRCMessageParser(IRCSession *session); 56 IRCMessageParser(IRCSession *session);
57 /* Parse a server message and take the appropriate actions */ 57 /* Parse a server message and take the appropriate actions */
58 void parse(IRCMessage *message); 58 void parse(IRCMessage *message);
59signals: 59signals:
60 /* Used to send commands to the UI (such as displaying text etc) */ 60 /* Used to send commands to the UI (such as displaying text etc) */
61 void outputReady(IRCOutput output); 61 void outputReady(IRCOutput output);
62private: 62private:
63 /* Parser functions */ 63 /* Parser functions */
64 void nullFunc(IRCMessage *message); 64 void nullFunc(IRCMessage *message);
65 void parseLiteralPing(IRCMessage *message); 65 void parseLiteralPing(IRCMessage *message);
66 void parseLiteralNotice(IRCMessage *message); 66 void parseLiteralNotice(IRCMessage *message);
67 void parseLiteralJoin(IRCMessage *message); 67 void parseLiteralJoin(IRCMessage *message);
68 void parseLiteralPrivMsg(IRCMessage *message); 68 void parseLiteralPrivMsg(IRCMessage *message);
69 void parseLiteralNick(IRCMessage *message); 69 void parseLiteralNick(IRCMessage *message);
70 void parseLiteralPart(IRCMessage *message); 70 void parseLiteralPart(IRCMessage *message);
71 void parseLiteralQuit(IRCMessage *message); 71 void parseLiteralQuit(IRCMessage *message);
72 void parseLiteralError(IRCMessage *message); 72 void parseLiteralError(IRCMessage *message);
73 void parseLiteralMode(IRCMessage *message); 73 void parseLiteralMode(IRCMessage *message);
74 void parseLiteralKick(IRCMessage *message); 74 void parseLiteralKick(IRCMessage *message);
75 void parseLiteralTopic(IRCMessage *message); 75 void parseLiteralTopic(IRCMessage *message);
76 void parseNumerical001(IRCMessage *message); 76 void parseNumericalSecondParam(IRCMessage *message);
77 void parseNumerical002(IRCMessage *message); 77 void parseNumericalAllParams(IRCMessage *message);
78 void parseNumerical003(IRCMessage *message);
79 void parseNumerical004(IRCMessage *message);
80 void parseNumerical005(IRCMessage *message);
81 void parseNumericalStats(IRCMessage *message);
82 void parseNumericalNames(IRCMessage *message); 78 void parseNumericalNames(IRCMessage *message);
83 void parseNumericalEndOfNames(IRCMessage *message); 79 void parseNumericalEndOfNames(IRCMessage *message);
84 void parseNumericalNicknameInUse(IRCMessage *message); 80 void parseNumericalNicknameInUse(IRCMessage *message);
85 void parseNumericalNoSuchNick(IRCMessage *message); 81 void parseNumericalNoSuchNick(IRCMessage *message);
86 void parseNumericalTopic(IRCMessage *message); 82 void parseNumericalTopic(IRCMessage *message);
87 void parseNumericalTopicWhoTime(IRCMessage *message); 83 void parseNumericalTopicWhoTime(IRCMessage *message);
88 void parseCTCPPing(IRCMessage *message); 84 void parseCTCPPing(IRCMessage *message);
89 void parseCTCPVersion(IRCMessage *message); 85 void parseCTCPVersion(IRCMessage *message);
90 void parseCTCPAction(IRCMessage *message); 86 void parseCTCPAction(IRCMessage *message);
91protected: 87protected:
92 IRCSession *m_session; 88 IRCSession *m_session;
93 /* Parser tables */ 89 /* Parser tables */
94 static IRCLiteralMessageParserStruct literalParserProcTable[]; 90 static IRCLiteralMessageParserStruct literalParserProcTable[];
95 static IRCNumericalMessageParserStruct numericalParserProcTable[]; 91 static IRCNumericalMessageParserStruct numericalParserProcTable[];
96 static IRCCTCPMessageParserStruct ctcpParserProcTable[]; 92 static IRCCTCPMessageParserStruct ctcpParserProcTable[];
97}; 93};
98 94
99#endif /* __IRCMESSAGEPARSER_H */ 95#endif /* __IRCMESSAGEPARSER_H */