-rw-r--r-- | noncore/net/opieirc/ircchannellist.cpp | 26 | ||||
-rw-r--r-- | noncore/net/opieirc/ircchannellist.h | 1 | ||||
-rw-r--r-- | noncore/net/opieirc/ircmessageparser.cpp | 61 | ||||
-rw-r--r-- | noncore/net/opieirc/ircmessageparser.h | 8 |
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 | ||
4 | IRCChannelList::IRCChannelList(IRCChannel *channel, QWidget *parent, const char *name, WFlags f) : QListBox(parent, name, f) { | 4 | IRCChannelList::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 | ||
8 | void IRCChannelList::update() { | 8 | void 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 | ||
30 | bool IRCChannelList::hasPerson(QString nick) { | 31 | bool 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 | ||
38 | bool IRCChannelList::removePerson(QString nick) { | 39 | bool 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 | ||
49 | void 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 | ||
27 | class IRCChannelList : public QListBox { | 27 | class IRCChannelList : public QListBox { |
28 | public: | 28 | public: |
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); |
33 | protected: | 34 | protected: |
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,107 +1,110 @@ | |||
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 */ |
6 | IRCLiteralMessageParserStruct IRCMessageParser::literalParserProcTable[] = { | 6 | IRCLiteralMessageParserStruct 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 */ |
23 | IRCCTCPMessageParserStruct IRCMessageParser::ctcpParserProcTable[] = { | 23 | IRCCTCPMessageParserStruct 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 */ |
31 | IRCNumericalMessageParserStruct IRCMessageParser::numericalParserProcTable[] = { | 31 | IRCNumericalMessageParserStruct 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 | |||
60 | IRCMessageParser::IRCMessageParser(IRCSession *session) { | 63 | IRCMessageParser::IRCMessageParser(IRCSession *session) { |
61 | m_session = session; | 64 | m_session = session; |
62 | } | 65 | } |
63 | 66 | ||
64 | void IRCMessageParser::parse(IRCMessage *message) { | 67 | void 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 | ||
94 | void IRCMessageParser::nullFunc(IRCMessage *) { | 97 | void IRCMessageParser::nullFunc(IRCMessage *) { |
95 | /* Do nothing */ | 98 | /* Do nothing */ |
96 | } | 99 | } |
97 | 100 | ||
98 | void IRCMessageParser::parseLiteralPing(IRCMessage *message) { | 101 | void 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 | ||
102 | void IRCMessageParser::parseLiteralNotice(IRCMessage *message) { | 105 | void IRCMessageParser::parseLiteralNotice(IRCMessage *message) { |
103 | emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, message->allParameters())); | 106 | emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, message->allParameters())); |
104 | } | 107 | } |
105 | 108 | ||
106 | void IRCMessageParser::parseLiteralJoin(IRCMessage *message) { | 109 | void IRCMessageParser::parseLiteralJoin(IRCMessage *message) { |
107 | QString channelName = message->param(0).lower(); | 110 | QString channelName = message->param(0).lower(); |
@@ -415,156 +418,142 @@ void IRCMessageParser::parseLiteralMode(IRCMessage *message) { | |||
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 | ||
436 | void IRCMessageParser::parseLiteralKick(IRCMessage *message) { | 439 | void 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 | ||
463 | void IRCMessageParser::parseNumerical001(IRCMessage *message) { | ||
464 | /* Welcome to IRC message, display */ | ||
465 | emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, message->param(1))); | ||
466 | } | ||
467 | 466 | ||
468 | void IRCMessageParser::parseNumerical002(IRCMessage *message) { | 467 | void 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 | ||
472 | void IRCMessageParser::parseNumerical003(IRCMessage *message) { | 471 | void IRCMessageParser::parseNumericalAllParams(IRCMessage *message) { |
473 | emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, message->param(1))); | ||
474 | } | ||
475 | |||
476 | void IRCMessageParser::parseNumerical004(IRCMessage *message) { | ||
477 | emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, message->allParameters())); | 472 | emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, message->allParameters())); |
478 | } | 473 | } |
479 | 474 | ||
480 | void IRCMessageParser::parseNumerical005(IRCMessage *message) { | ||
481 | emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, message->allParameters())); | ||
482 | } | ||
483 | |||
484 | void IRCMessageParser::parseNumericalStats(IRCMessage *message) { | ||
485 | emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, message->param(1))); | ||
486 | } | ||
487 | |||
488 | void IRCMessageParser::parseNumericalNames(IRCMessage *message) { | 475 | void 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 | ||
532 | void IRCMessageParser::parseNumericalEndOfNames(IRCMessage *message) { | 519 | void 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 | ||
547 | void IRCMessageParser::parseNumericalNicknameInUse(IRCMessage *) { | 534 | void 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 | ||
552 | void IRCMessageParser::parseNumericalNoSuchNick(IRCMessage *) { | 539 | void 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 | ||
556 | void IRCMessageParser::parseNumericalTopic(IRCMessage *message) { | 543 | void 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 | ||
569 | void IRCMessageParser::parseNumericalTopicWhoTime(IRCMessage *) { | 556 | void 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 | |||
@@ -28,72 +28,68 @@ | |||
28 | 28 | ||
29 | class IRCMessageParser; | 29 | class IRCMessageParser; |
30 | 30 | ||
31 | /* Typedef representing a parser function */ | 31 | /* Typedef representing a parser function */ |
32 | typedef void (IRCMessageParser::*IRCMessageParseProc)(IRCMessage *); | 32 | typedef void (IRCMessageParser::*IRCMessageParseProc)(IRCMessage *); |
33 | 33 | ||
34 | /* Struct representing a literal command handler */ | 34 | /* Struct representing a literal command handler */ |
35 | typedef struct IRCLiteralMessageParserStruct { | 35 | typedef 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 */ |
41 | typedef struct IRCCTCPMessageParserStruct { | 41 | typedef 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 */ |
47 | typedef struct IRCNumericalMessageParserStruct { | 47 | typedef struct IRCNumericalMessageParserStruct { |
48 | unsigned short commandNumber; | 48 | unsigned short commandNumber; |
49 | IRCMessageParseProc proc; | 49 | IRCMessageParseProc proc; |
50 | }; | 50 | }; |
51 | 51 | ||
52 | class IRCMessageParser : public QObject { | 52 | class IRCMessageParser : public QObject { |
53 | Q_OBJECT | 53 | Q_OBJECT |
54 | public: | 54 | public: |
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); |
59 | signals: | 59 | signals: |
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); |
62 | private: | 62 | private: |
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); |
91 | protected: | 87 | protected: |
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 */ |