author | wazlaf <wazlaf> | 2002-09-21 23:59:08 (UTC) |
---|---|---|
committer | wazlaf <wazlaf> | 2002-09-21 23:59:08 (UTC) |
commit | d60625b5551f26cdc35f7b2497ab538de859537d (patch) (unidiff) | |
tree | 998c8d2e1f12a9c7ab9b55fa578f93d1a178ade6 | |
parent | 54238c669808ceccaa6fb0ab0dcbf4565b370196 (diff) | |
download | opie-d60625b5551f26cdc35f7b2497ab538de859537d.zip opie-d60625b5551f26cdc35f7b2497ab538de859537d.tar.gz opie-d60625b5551f26cdc35f7b2497ab538de859537d.tar.bz2 |
query windows and basic commands such as /me, /msg
-rw-r--r-- | noncore/net/opieirc/ircchanneltab.cpp | 7 | ||||
-rw-r--r-- | noncore/net/opieirc/ircmessage.cpp | 1 | ||||
-rw-r--r-- | noncore/net/opieirc/ircmessageparser.cpp | 10 | ||||
-rw-r--r-- | noncore/net/opieirc/ircmessageparser.h | 1 | ||||
-rw-r--r-- | noncore/net/opieirc/ircperson.cpp | 6 | ||||
-rw-r--r-- | noncore/net/opieirc/ircperson.h | 3 | ||||
-rw-r--r-- | noncore/net/opieirc/ircquerytab.cpp | 76 | ||||
-rw-r--r-- | noncore/net/opieirc/ircquerytab.h | 27 | ||||
-rw-r--r-- | noncore/net/opieirc/ircservertab.cpp | 54 | ||||
-rw-r--r-- | noncore/net/opieirc/ircservertab.h | 7 |
10 files changed, 182 insertions, 10 deletions
diff --git a/noncore/net/opieirc/ircchanneltab.cpp b/noncore/net/opieirc/ircchanneltab.cpp index 3267525..4675265 100644 --- a/noncore/net/opieirc/ircchanneltab.cpp +++ b/noncore/net/opieirc/ircchanneltab.cpp | |||
@@ -1,95 +1,94 @@ | |||
1 | #include <qhbox.h> | 1 | #include <qhbox.h> |
2 | #include "ircchanneltab.h" | 2 | #include "ircchanneltab.h" |
3 | #include "ircservertab.h" | 3 | #include "ircservertab.h" |
4 | 4 | ||
5 | IRCChannelTab::IRCChannelTab(IRCChannel *channel, IRCServerTab *parentTab, MainWindow *mainWindow, QWidget *parent, const char *name, WFlags f) : IRCTab(parent, name, f) { | 5 | IRCChannelTab::IRCChannelTab(IRCChannel *channel, IRCServerTab *parentTab, MainWindow *mainWindow, QWidget *parent, const char *name, WFlags f) : IRCTab(parent, name, f) { |
6 | m_mainWindow = mainWindow; | 6 | m_mainWindow = mainWindow; |
7 | m_parentTab = parentTab; | 7 | m_parentTab = parentTab; |
8 | m_channel = channel; | 8 | m_channel = channel; |
9 | m_description->setText(tr("Talking on channel") + " <b>" + channel->channelname() + "</b>"); | 9 | m_description->setText(tr("Talking on channel") + " <b>" + channel->channelname() + "</b>"); |
10 | QHBox *hbox = new QHBox(this); | 10 | QHBox *hbox = new QHBox(this); |
11 | m_textview = new QTextView(hbox); | 11 | m_textview = new QTextView(hbox); |
12 | m_textview->setHScrollBarMode(QScrollView::AlwaysOff); | 12 | m_textview->setHScrollBarMode(QScrollView::AlwaysOff); |
13 | m_textview->setVScrollBarMode(QScrollView::AlwaysOn); | 13 | m_textview->setVScrollBarMode(QScrollView::AlwaysOn); |
14 | m_listVisible = TRUE; | 14 | m_listVisible = TRUE; |
15 | m_listButton = new QPushButton(">", m_textview); | 15 | m_listButton = new QPushButton(">", m_textview); |
16 | m_textview->setCornerWidget(m_listButton); | 16 | m_textview->setCornerWidget(m_listButton); |
17 | m_textview->setTextFormat(RichText); | ||
17 | connect(m_listButton, SIGNAL(clicked()), this, SLOT(toggleList())); | 18 | connect(m_listButton, SIGNAL(clicked()), this, SLOT(toggleList())); |
18 | m_list = new IRCChannelList(m_channel, hbox); | 19 | m_list = new IRCChannelList(m_channel, hbox); |
19 | m_list->update(); | 20 | m_list->update(); |
20 | m_list->setMaximumWidth(LISTWIDTH); | 21 | m_list->setMaximumWidth(LISTWIDTH); |
21 | m_field = new QLineEdit(this); | 22 | m_field = new QLineEdit(this); |
22 | m_layout->add(hbox); | 23 | m_layout->add(hbox); |
23 | hbox->show(); | 24 | hbox->show(); |
24 | m_layout->add(m_field); | 25 | m_layout->add(m_field); |
25 | m_field->setFocus(); | 26 | m_field->setFocus(); |
26 | connect(m_field, SIGNAL(returnPressed()), this, SLOT(processCommand())); | 27 | connect(m_field, SIGNAL(returnPressed()), this, SLOT(processCommand())); |
27 | 28 | ||
28 | } | 29 | } |
29 | 30 | ||
30 | void IRCChannelTab::appendText(QString text) { | 31 | void IRCChannelTab::appendText(QString text) { |
31 | /* not using append because it creates layout problems */ | 32 | /* not using append because it creates layout problems */ |
32 | m_textview->setText(m_textview->text() + text); | 33 | m_textview->setText(m_textview->text() + text); |
33 | m_textview->ensureVisible(0, m_textview->contentsHeight()); | 34 | m_textview->ensureVisible(0, m_textview->contentsHeight()); |
34 | } | 35 | } |
35 | 36 | ||
36 | IRCChannelTab::~IRCChannelTab() { | 37 | IRCChannelTab::~IRCChannelTab() { |
37 | m_parentTab->removeChannelTab(this); | 38 | m_parentTab->removeChannelTab(this); |
38 | } | 39 | } |
39 | 40 | ||
40 | void IRCChannelTab::processCommand() { | 41 | void IRCChannelTab::processCommand() { |
41 | QString text = m_field->text(); | 42 | QString text = m_field->text(); |
42 | if (text.length()>0) { | 43 | if (text.length()>0) { |
43 | if (session()->isSessionActive()) { | 44 | if (session()->isSessionActive()) { |
44 | if (text.startsWith("/") && !text.startsWith("//")) { | 45 | if (text.startsWith("/") && !text.startsWith("//")) { |
45 | /* Command mode */ | 46 | /* Command mode */ |
46 | m_parentTab->executeCommand(this, text);; | 47 | m_parentTab->executeCommand(this, text);; |
47 | } else { | 48 | } else { |
48 | if (text.startsWith("//")) | 49 | if (text.startsWith("//")) |
49 | text = text.right(text.length()-1); | 50 | text = text.right(text.length()-1); |
50 | if (session()->isSessionActive()) { | 51 | session()->sendMessage(m_channel, m_field->text()); |
51 | session()->sendMessage(m_channel, m_field->text()); | 52 | appendText("<<font color=\"#dd0000\">"+m_parentTab->server()->nick()+"</font>> "+IRCOutput::toHTML(m_field->text())+"<br>"); |
52 | appendText("<<font color=\"#dd0000\">"+m_parentTab->server()->nick()+"</font>> "+IRCOutput::toHTML(m_field->text())+"<br>"); | ||
53 | } | ||
54 | } | 53 | } |
55 | } else { | 54 | } else { |
56 | appendText("<font color=\"#ff0000\">"+tr("Disconnected")+"</font><br>"); | 55 | appendText("<font color=\"#ff0000\">"+tr("Disconnected")+"</font><br>"); |
57 | } | 56 | } |
58 | } | 57 | } |
59 | m_field->clear(); | 58 | m_field->clear(); |
60 | } | 59 | } |
61 | 60 | ||
62 | void IRCChannelTab::toggleList() { | 61 | void IRCChannelTab::toggleList() { |
63 | if (m_listVisible) { | 62 | if (m_listVisible) { |
64 | m_list->setMaximumWidth(0); | 63 | m_list->setMaximumWidth(0); |
65 | m_listButton->setText("<"); | 64 | m_listButton->setText("<"); |
66 | } else { | 65 | } else { |
67 | m_list->setMaximumWidth(LISTWIDTH); | 66 | m_list->setMaximumWidth(LISTWIDTH); |
68 | m_listButton->setText(">"); | 67 | m_listButton->setText(">"); |
69 | } | 68 | } |
70 | m_listVisible = !m_listVisible; | 69 | m_listVisible = !m_listVisible; |
71 | } | 70 | } |
72 | 71 | ||
73 | QString IRCChannelTab::title() { | 72 | QString IRCChannelTab::title() { |
74 | return m_channel->channelname(); | 73 | return m_channel->channelname(); |
75 | } | 74 | } |
76 | 75 | ||
77 | IRCSession *IRCChannelTab::session() { | 76 | IRCSession *IRCChannelTab::session() { |
78 | return m_parentTab->session(); | 77 | return m_parentTab->session(); |
79 | } | 78 | } |
80 | 79 | ||
81 | void IRCChannelTab::remove() { | 80 | void IRCChannelTab::remove() { |
82 | if (session()->isSessionActive()) { | 81 | if (session()->isSessionActive()) { |
83 | session()->part(m_channel); | 82 | session()->part(m_channel); |
84 | } else { | 83 | } else { |
85 | m_mainWindow->killTab(this); | 84 | m_mainWindow->killTab(this); |
86 | } | 85 | } |
87 | } | 86 | } |
88 | 87 | ||
89 | IRCChannel *IRCChannelTab::channel() { | 88 | IRCChannel *IRCChannelTab::channel() { |
90 | return m_channel; | 89 | return m_channel; |
91 | } | 90 | } |
92 | 91 | ||
93 | IRCChannelList *IRCChannelTab::list() { | 92 | IRCChannelList *IRCChannelTab::list() { |
94 | return m_list; | 93 | return m_list; |
95 | } | 94 | } |
diff --git a/noncore/net/opieirc/ircmessage.cpp b/noncore/net/opieirc/ircmessage.cpp index 9c2869c..d823ad1 100644 --- a/noncore/net/opieirc/ircmessage.cpp +++ b/noncore/net/opieirc/ircmessage.cpp | |||
@@ -1,123 +1,122 @@ | |||
1 | #include <qtextstream.h> | 1 | #include <qtextstream.h> |
2 | #include "ircmessage.h" | 2 | #include "ircmessage.h" |
3 | 3 | ||
4 | /* | 4 | /* |
5 | * Create a new IRCMessage by evaluating | 5 | * Create a new IRCMessage by evaluating |
6 | * a received string | 6 | * a received string |
7 | */ | 7 | */ |
8 | 8 | ||
9 | IRCMessage::IRCMessage(QString line) { | 9 | IRCMessage::IRCMessage(QString line) { |
10 | /* Remove CRs from the message */ | 10 | /* Remove CRs from the message */ |
11 | while((line.right(1) == "\n") || (line.right(1) == "\r")) | 11 | while((line.right(1) == "\n") || (line.right(1) == "\r")) |
12 | line = line.left(line.length() - 1); | 12 | line = line.left(line.length() - 1); |
13 | QTextIStream stream(&line); | 13 | QTextIStream stream(&line); |
14 | QString temp; | 14 | QString temp; |
15 | 15 | ||
16 | stream >> temp; | 16 | stream >> temp; |
17 | if (temp.startsWith(":")) { | 17 | if (temp.startsWith(":")) { |
18 | /* extract the prefix */ | 18 | /* extract the prefix */ |
19 | m_prefix = temp.right(temp.length()-1); | 19 | m_prefix = temp.right(temp.length()-1); |
20 | stream >> temp; | 20 | stream >> temp; |
21 | m_command = temp.upper(); | 21 | m_command = temp.upper(); |
22 | m_allParameters = line.right(line.length() - m_prefix.length() - m_command.length() - 3); | 22 | m_allParameters = line.right(line.length() - m_prefix.length() - m_command.length() - 3); |
23 | } else { | 23 | } else { |
24 | m_command = temp.upper(); | 24 | m_command = temp.upper(); |
25 | m_allParameters = line.right(line.length() - m_command.length() - 1); | 25 | m_allParameters = line.right(line.length() - m_command.length() - 1); |
26 | } | 26 | } |
27 | 27 | ||
28 | /* Create a list of all parameters */ | 28 | /* Create a list of all parameters */ |
29 | while(!(stream.atEnd())) { | 29 | while(!(stream.atEnd())) { |
30 | stream >> temp; | 30 | stream >> temp; |
31 | if (temp.startsWith(":")) { | 31 | if (temp.startsWith(":")) { |
32 | /* last parameter */ | 32 | /* last parameter */ |
33 | m_trailing = line.right(line.length() - line.find(QChar(':'), 1) - 1); | 33 | m_trailing = line.right(line.length() - line.find(QChar(':'), 1) - 1); |
34 | m_parameters << m_trailing; | 34 | m_parameters << m_trailing; |
35 | break; | 35 | break; |
36 | } else { | 36 | } else { |
37 | m_parameters << temp; | 37 | m_parameters << temp; |
38 | } | 38 | } |
39 | } | 39 | } |
40 | 40 | ||
41 | 41 | ||
42 | m_commandNumber = m_command.toInt(&m_isNumerical); | 42 | m_commandNumber = m_command.toInt(&m_isNumerical); |
43 | /* Is this a CTCP command */ | 43 | /* Is this a CTCP command */ |
44 | if ((m_command == "PRIVMSG" || m_command == "NOTICE") && m_trailing.length()>0 && m_trailing.left(1) == QChar(1)) { | 44 | if ((m_command == "PRIVMSG" || m_command == "NOTICE") && m_trailing.length()>0 && m_trailing.left(1) == QChar(1)) { |
45 | m_ctcp = TRUE; | 45 | m_ctcp = TRUE; |
46 | /* Strip CTCP \001 characters */ | 46 | /* Strip CTCP \001 characters */ |
47 | m_allParameters = m_allParameters.replace(QRegExp(QChar(1)), ""); | 47 | m_allParameters = m_allParameters.replace(QRegExp(QChar(1)), ""); |
48 | QTextIStream ctcpStream(&m_allParameters); | 48 | QTextIStream ctcpStream(&m_allParameters); |
49 | if (m_command == "PRIVMSG") | 49 | if (m_command == "PRIVMSG") |
50 | ctcpStream >> m_ctcpDestination; | 50 | ctcpStream >> m_ctcpDestination; |
51 | ctcpStream >> temp; | 51 | ctcpStream >> temp; |
52 | m_ctcpCommand = temp.upper().right(temp.length()-1); | 52 | m_ctcpCommand = temp.upper().right(temp.length()-1); |
53 | m_parameters.clear(); | 53 | m_parameters.clear(); |
54 | int length = m_allParameters.length() - m_ctcpCommand.length() - 1; | 54 | int length = m_allParameters.length() - m_ctcpCommand.length() - 1; |
55 | if (m_command == "PRIVMSG") | 55 | if (m_command == "PRIVMSG") |
56 | length -= m_ctcpDestination.length() + 1; | 56 | length -= m_ctcpDestination.length() + 1; |
57 | if (length <= 0) { | 57 | if (length <= 0) { |
58 | m_allParameters = ""; | 58 | m_allParameters = ""; |
59 | } else { | 59 | } else { |
60 | m_allParameters = m_allParameters.right(length); | 60 | m_allParameters = m_allParameters.right(length); |
61 | m_parameters << m_allParameters; | 61 | m_parameters << m_allParameters; |
62 | } | 62 | } |
63 | } else { | 63 | } else { |
64 | m_ctcp = FALSE; | 64 | m_ctcp = FALSE; |
65 | } | 65 | } |
66 | 66 | ||
67 | /* | 67 | /* |
68 | -- Uncomment to debug -- | 68 | -- Uncomment to debug -- |
69 | 69 | ||
70 | printf("Parsed : '%s'\n", line.ascii()); | 70 | printf("Parsed : '%s'\n", line.ascii()); |
71 | printf("Prefix : '%s'\n", m_prefix.ascii()); | 71 | printf("Prefix : '%s'\n", m_prefix.ascii()); |
72 | printf("Command : '%s'\n", m_command.ascii()); | 72 | printf("Command : '%s'\n", m_command.ascii()); |
73 | printf("Allparameters : '%s'\n", m_allParameters.ascii()); | 73 | printf("Allparameters : '%s'\n", m_allParameters.ascii()); |
74 | for (unsigned int i=0; i<m_parameters.count(); i++) { | 74 | for (unsigned int i=0; i<m_parameters.count(); i++) { |
75 | printf("Parameter %i : '%s'\n", i, m_parameters[i].ascii()); | 75 | printf("Parameter %i : '%s'\n", i, m_parameters[i].ascii()); |
76 | } | 76 | } |
77 | printf("CTCP Command : '%s'\n", m_ctcpCommand.latin1()); | 77 | printf("CTCP Command : '%s'\n", m_ctcpCommand.latin1()); |
78 | printf("CTCP Destination : '%s'\n", m_ctcpDestination.latin1()); | 78 | printf("CTCP Destination : '%s'\n", m_ctcpDestination.latin1()); |
79 | printf("CTCP param count is : '%i'\n", m_parameters.count()); | 79 | printf("CTCP param count is : '%i'\n", m_parameters.count()); |
80 | |||
81 | */ | 80 | */ |
82 | } | 81 | } |
83 | 82 | ||
84 | QString IRCMessage::param(int param) { | 83 | QString IRCMessage::param(int param) { |
85 | return m_parameters[param]; | 84 | return m_parameters[param]; |
86 | } | 85 | } |
87 | 86 | ||
88 | QString IRCMessage::prefix() { | 87 | QString IRCMessage::prefix() { |
89 | return m_prefix; | 88 | return m_prefix; |
90 | } | 89 | } |
91 | 90 | ||
92 | QString IRCMessage::command() { | 91 | QString IRCMessage::command() { |
93 | return m_command; | 92 | return m_command; |
94 | } | 93 | } |
95 | 94 | ||
96 | QString IRCMessage::ctcpCommand() { | 95 | QString IRCMessage::ctcpCommand() { |
97 | return m_ctcpCommand; | 96 | return m_ctcpCommand; |
98 | } | 97 | } |
99 | 98 | ||
100 | QString IRCMessage::ctcpDestination() { | 99 | QString IRCMessage::ctcpDestination() { |
101 | return m_ctcpDestination; | 100 | return m_ctcpDestination; |
102 | } | 101 | } |
103 | 102 | ||
104 | unsigned short IRCMessage::commandNumber() { | 103 | unsigned short IRCMessage::commandNumber() { |
105 | return m_commandNumber; | 104 | return m_commandNumber; |
106 | } | 105 | } |
107 | 106 | ||
108 | bool IRCMessage::isNumerical() { | 107 | bool IRCMessage::isNumerical() { |
109 | return m_isNumerical; | 108 | return m_isNumerical; |
110 | } | 109 | } |
111 | 110 | ||
112 | bool IRCMessage::isCTCP() { | 111 | bool IRCMessage::isCTCP() { |
113 | return m_ctcp; | 112 | return m_ctcp; |
114 | } | 113 | } |
115 | 114 | ||
116 | QString IRCMessage::trailing() { | 115 | QString IRCMessage::trailing() { |
117 | return m_trailing; | 116 | return m_trailing; |
118 | } | 117 | } |
119 | 118 | ||
120 | QString IRCMessage::allParameters() { | 119 | QString IRCMessage::allParameters() { |
121 | return m_allParameters; | 120 | return m_allParameters; |
122 | } | 121 | } |
123 | 122 | ||
diff --git a/noncore/net/opieirc/ircmessageparser.cpp b/noncore/net/opieirc/ircmessageparser.cpp index 4038673..3063741 100644 --- a/noncore/net/opieirc/ircmessageparser.cpp +++ b/noncore/net/opieirc/ircmessageparser.cpp | |||
@@ -1,481 +1,487 @@ | |||
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 | #include <stdio.h> | 4 | #include <stdio.h> |
5 | 5 | ||
6 | /* Lookup table for literal commands */ | 6 | /* Lookup table for literal commands */ |
7 | IRCLiteralMessageParserStruct IRCMessageParser::literalParserProcTable[] = { | 7 | IRCLiteralMessageParserStruct IRCMessageParser::literalParserProcTable[] = { |
8 | { "PING", FUNC(parseLiteralPing) }, | 8 | { "PING", FUNC(parseLiteralPing) }, |
9 | { "NOTICE", FUNC(parseLiteralNotice) }, | 9 | { "NOTICE", FUNC(parseLiteralNotice) }, |
10 | { "JOIN", FUNC(parseLiteralJoin) }, | 10 | { "JOIN", FUNC(parseLiteralJoin) }, |
11 | { "PRIVMSG", FUNC(parseLiteralPrivMsg) }, | 11 | { "PRIVMSG", FUNC(parseLiteralPrivMsg) }, |
12 | { "NICK", FUNC(parseLiteralNick) }, | 12 | { "NICK", FUNC(parseLiteralNick) }, |
13 | { "PART", FUNC(parseLiteralPart) }, | 13 | { "PART", FUNC(parseLiteralPart) }, |
14 | { "QUIT", FUNC(parseLiteralQuit) }, | 14 | { "QUIT", FUNC(parseLiteralQuit) }, |
15 | { "ERROR", FUNC(parseLiteralError) }, | 15 | { "ERROR", FUNC(parseLiteralError) }, |
16 | { "ERROR:", FUNC(parseLiteralError) }, | 16 | { "ERROR:", FUNC(parseLiteralError) }, |
17 | { "MODE", FUNC(parseLiteralMode) }, | 17 | { "MODE", FUNC(parseLiteralMode) }, |
18 | { "KICK", FUNC(parseLiteralKick) }, | 18 | { "KICK", FUNC(parseLiteralKick) }, |
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(parseNumerical001) }, // RPL_WELCOME |
33 | { 2, FUNC(parseNumerical002) }, // RPL_YOURHOST | 33 | { 2, FUNC(parseNumerical002) }, // RPL_YOURHOST |
34 | { 3, FUNC(parseNumerical003) }, // RPL_CREATED | 34 | { 3, FUNC(parseNumerical003) }, // RPL_CREATED |
35 | { 4, FUNC(parseNumerical004) }, // RPL_MYINFO | 35 | { 4, FUNC(parseNumerical004) }, // RPL_MYINFO |
36 | { 5, FUNC(parseNumerical005) }, // RPL_BOUNCE, RPL_PROTOCTL | 36 | { 5, FUNC(parseNumerical005) }, // RPL_BOUNCE, RPL_PROTOCTL |
37 | { 251, FUNC(parseNumericalStats) }, // RPL_LUSERCLIENT | 37 | { 251, FUNC(parseNumericalStats) }, // RPL_LUSERCLIENT |
38 | { 254, FUNC(nullFunc)}, // RPL_LUSERCHANNELS | 38 | { 254, FUNC(nullFunc)}, // RPL_LUSERCHANNELS |
39 | { 255, FUNC(parseNumericalStats) }, // RPL_LUSERNAME | 39 | { 255, FUNC(parseNumericalStats) }, // RPL_LUSERNAME |
40 | { 353, FUNC(parseNumericalNames) }, // RPL_NAMREPLY | 40 | { 353, FUNC(parseNumericalNames) }, // RPL_NAMREPLY |
41 | { 366, FUNC(parseNumericalEndOfNames) }, // RPL_ENDOFNAMES | 41 | { 366, FUNC(parseNumericalEndOfNames) }, // RPL_ENDOFNAMES |
42 | { 375, FUNC(parseNumericalStats) }, // RPL_MOTDSTART | 42 | { 375, FUNC(parseNumericalStats) }, // RPL_MOTDSTART |
43 | { 372, FUNC(parseNumericalStats) }, // RPL_MOTD | 43 | { 372, FUNC(parseNumericalStats) }, // RPL_MOTD |
44 | { 376, FUNC(parseNumericalStats) }, // RPL_ENDOFMOTD | 44 | { 376, FUNC(parseNumericalStats) }, // RPL_ENDOFMOTD |
45 | { 377, FUNC(parseNumericalStats) }, // RPL_MOTD2 | 45 | { 377, FUNC(parseNumericalStats) }, // RPL_MOTD2 |
46 | { 378, FUNC(parseNumericalStats) }, // RPL_MOTD3 | 46 | { 378, FUNC(parseNumericalStats) }, // RPL_MOTD3 |
47 | { 412, FUNC(parseNumericalStats) }, // ERNOTEXTTOSEND | 47 | { 401, FUNC(parseNumericalNoSuchNick) }, // ERR_NOSUCHNICK |
48 | { 406, FUNC(parseNumericalNoSuchNick) }, // ERR_WASNOSUCHNICK | ||
49 | { 412, FUNC(parseNumericalStats) }, // ERR_NOTEXTTOSEND | ||
48 | { 433, FUNC(parseNumericalNicknameInUse) }, // ERR_NICKNAMEINUSE | 50 | { 433, FUNC(parseNumericalNicknameInUse) }, // ERR_NICKNAMEINUSE |
49 | { 0, 0 } | 51 | { 0, 0 } |
50 | }; | 52 | }; |
51 | 53 | ||
52 | IRCMessageParser::IRCMessageParser(IRCSession *session) { | 54 | IRCMessageParser::IRCMessageParser(IRCSession *session) { |
53 | m_session = session; | 55 | m_session = session; |
54 | } | 56 | } |
55 | 57 | ||
56 | void IRCMessageParser::parse(IRCMessage *message) { | 58 | void IRCMessageParser::parse(IRCMessage *message) { |
57 | /* Find out what kind of message we have here and call the appropriate handler using | 59 | /* Find out what kind of message we have here and call the appropriate handler using |
58 | the parser tables. If no handler can be found, print out an error message */ | 60 | the parser tables. If no handler can be found, print out an error message */ |
59 | if (message->isNumerical()) { | 61 | if (message->isNumerical()) { |
60 | for (int i=0; i<numericalParserProcTable[i].commandNumber; i++) { | 62 | for (int i=0; i<numericalParserProcTable[i].commandNumber; i++) { |
61 | if (message->commandNumber() == numericalParserProcTable[i].commandNumber) { | 63 | if (message->commandNumber() == numericalParserProcTable[i].commandNumber) { |
62 | (this->*(numericalParserProcTable[i].proc))(message); | 64 | (this->*(numericalParserProcTable[i].proc))(message); |
63 | return; | 65 | return; |
64 | } | 66 | } |
65 | } | 67 | } |
66 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received unhandled numeric command : ")+QString::number(message->commandNumber()))); | 68 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received unhandled numeric command : ")+QString::number(message->commandNumber()))); |
67 | } else if (message->isCTCP()) { | 69 | } else if (message->isCTCP()) { |
68 | for (int i=0; ctcpParserProcTable[i].commandName; i++) { | 70 | for (int i=0; ctcpParserProcTable[i].commandName; i++) { |
69 | if (message->ctcpCommand() == ctcpParserProcTable[i].commandName) { | 71 | if (message->ctcpCommand() == ctcpParserProcTable[i].commandName) { |
70 | (this->*(ctcpParserProcTable[i].proc))(message); | 72 | (this->*(ctcpParserProcTable[i].proc))(message); |
71 | return; | 73 | return; |
72 | } | 74 | } |
73 | } | 75 | } |
74 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received unhandled ctcp command : ")+message->ctcpCommand())); | 76 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received unhandled ctcp command : ")+message->ctcpCommand())); |
75 | } else { | 77 | } else { |
76 | for (int i=0; literalParserProcTable[i].commandName; i++) { | 78 | for (int i=0; literalParserProcTable[i].commandName; i++) { |
77 | if (message->command() == literalParserProcTable[i].commandName) { | 79 | if (message->command() == literalParserProcTable[i].commandName) { |
78 | (this->*(literalParserProcTable[i].proc))(message); | 80 | (this->*(literalParserProcTable[i].proc))(message); |
79 | return; | 81 | return; |
80 | } | 82 | } |
81 | } | 83 | } |
82 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received unhandled literal command : ")+message->command())); | 84 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received unhandled literal command : ")+message->command())); |
83 | } | 85 | } |
84 | } | 86 | } |
85 | 87 | ||
86 | void IRCMessageParser::nullFunc(IRCMessage *) { | 88 | void IRCMessageParser::nullFunc(IRCMessage *) { |
87 | /* Do nothing */ | 89 | /* Do nothing */ |
88 | } | 90 | } |
89 | 91 | ||
90 | void IRCMessageParser::parseLiteralPing(IRCMessage *message) { | 92 | void IRCMessageParser::parseLiteralPing(IRCMessage *message) { |
91 | m_session->m_connection->sendLine("PONG " + message->allParameters()); | 93 | m_session->m_connection->sendLine("PONG " + message->allParameters()); |
92 | } | 94 | } |
93 | 95 | ||
94 | void IRCMessageParser::parseLiteralNotice(IRCMessage *message) { | 96 | void IRCMessageParser::parseLiteralNotice(IRCMessage *message) { |
95 | emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, message->allParameters())); | 97 | emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, message->allParameters())); |
96 | } | 98 | } |
97 | 99 | ||
98 | void IRCMessageParser::parseLiteralJoin(IRCMessage *message) { | 100 | void IRCMessageParser::parseLiteralJoin(IRCMessage *message) { |
99 | QString channelName = message->param(0); | 101 | QString channelName = message->param(0); |
100 | IRCPerson mask(message->prefix()); | 102 | IRCPerson mask(message->prefix()); |
101 | IRCChannel *channel = m_session->getChannel(channelName); | 103 | IRCChannel *channel = m_session->getChannel(channelName); |
102 | if (!channel) { | 104 | if (!channel) { |
103 | /* We joined */ | 105 | /* We joined */ |
104 | if (mask.nick() == m_session->m_server->nick()) { | 106 | if (mask.nick() == m_session->m_server->nick()) { |
105 | channel = new IRCChannel(channelName); | 107 | channel = new IRCChannel(channelName); |
106 | m_session->addChannel(channel); | 108 | m_session->addChannel(channel); |
107 | } else { | 109 | } else { |
108 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Nonexistant channel join - desynchronized?"))); | 110 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Nonexistant channel join - desynchronized?"))); |
109 | } | 111 | } |
110 | } else { | 112 | } else { |
111 | /* Someone else joined */ | 113 | /* Someone else joined */ |
112 | if (mask.nick() != m_session->m_server->nick()) { | 114 | if (mask.nick() != m_session->m_server->nick()) { |
113 | if (!channel->getPerson(mask.nick())) { | 115 | if (!channel->getPerson(mask.nick())) { |
114 | IRCChannelPerson *chanperson = new IRCChannelPerson(); | 116 | IRCChannelPerson *chanperson = new IRCChannelPerson(); |
115 | IRCPerson *person = m_session->getPerson(mask.nick()); | 117 | IRCPerson *person = m_session->getPerson(mask.nick()); |
116 | if (!person) { | 118 | if (!person) { |
117 | person = new IRCPerson(message->prefix()); | 119 | person = new IRCPerson(message->prefix()); |
118 | m_session->addPerson(person); | 120 | m_session->addPerson(person); |
119 | } | 121 | } |
120 | chanperson->flags = 0; | 122 | chanperson->flags = 0; |
121 | chanperson->person = person; | 123 | chanperson->person = person; |
122 | channel->addPerson(chanperson); | 124 | channel->addPerson(chanperson); |
123 | IRCOutput output(OUTPUT_OTHERJOIN, mask.nick() + tr(" joined channel ") + channelName); | 125 | IRCOutput output(OUTPUT_OTHERJOIN, mask.nick() + tr(" joined channel ") + channelName); |
124 | output.addParam(channel); | 126 | output.addParam(channel); |
125 | output.addParam(chanperson); | 127 | output.addParam(chanperson); |
126 | emit outputReady(output); | 128 | emit outputReady(output); |
127 | } else { | 129 | } else { |
128 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Person has already joined the channel - desynchronized?"))); | 130 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Person has already joined the channel - desynchronized?"))); |
129 | } | 131 | } |
130 | } else { | 132 | } else { |
131 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("You already joined the channel - desynchronized?"))); | 133 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("You already joined the channel - desynchronized?"))); |
132 | } | 134 | } |
133 | } | 135 | } |
134 | } | 136 | } |
135 | 137 | ||
136 | void IRCMessageParser::parseLiteralPart(IRCMessage *message) { | 138 | void IRCMessageParser::parseLiteralPart(IRCMessage *message) { |
137 | QString channelName = message->param(0); | 139 | QString channelName = message->param(0); |
138 | IRCChannel *channel = m_session->getChannel(channelName); | 140 | IRCChannel *channel = m_session->getChannel(channelName); |
139 | IRCPerson mask(message->prefix()); | 141 | IRCPerson mask(message->prefix()); |
140 | if (channel) { | 142 | if (channel) { |
141 | if (mask.nick() == m_session->m_server->nick()) { | 143 | if (mask.nick() == m_session->m_server->nick()) { |
142 | m_session->removeChannel(channel); | 144 | m_session->removeChannel(channel); |
143 | IRCOutput output(OUTPUT_SELFPART, tr("You left channel ") + channelName); | 145 | IRCOutput output(OUTPUT_SELFPART, tr("You left channel ") + channelName); |
144 | output.addParam(channel); | 146 | output.addParam(channel); |
145 | emit outputReady(output); | 147 | emit outputReady(output); |
146 | delete channel; | 148 | delete channel; |
147 | } else { | 149 | } else { |
148 | IRCChannelPerson *person = channel->getPerson(mask.nick()); | 150 | IRCChannelPerson *person = channel->getPerson(mask.nick()); |
149 | if (person) { | 151 | if (person) { |
150 | channel->removePerson(person); | 152 | channel->removePerson(person); |
151 | IRCOutput output(OUTPUT_OTHERPART, mask.nick() + tr(" left channel ") + channelName); | 153 | IRCOutput output(OUTPUT_OTHERPART, mask.nick() + tr(" left channel ") + channelName); |
152 | output.addParam(channel); | 154 | output.addParam(channel); |
153 | output.addParam(person); | 155 | output.addParam(person); |
154 | emit outputReady(output); | 156 | emit outputReady(output); |
155 | delete person; | 157 | delete person; |
156 | } else { | 158 | } else { |
157 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Parting person not found - desynchronized?"))); | 159 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Parting person not found - desynchronized?"))); |
158 | } | 160 | } |
159 | } | 161 | } |
160 | } else { | 162 | } else { |
161 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Channel for part not found - desynchronized?"))); | 163 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Channel for part not found - desynchronized?"))); |
162 | } | 164 | } |
163 | } | 165 | } |
164 | 166 | ||
165 | void IRCMessageParser::parseLiteralPrivMsg(IRCMessage *message) { | 167 | void IRCMessageParser::parseLiteralPrivMsg(IRCMessage *message) { |
166 | if (m_session->m_server->nick() == message->param(0)) { | 168 | if (m_session->m_server->nick() == message->param(0)) { |
167 | /* IRC Query message detected, verify sender and display it */ | 169 | /* IRC Query message detected, verify sender and display it */ |
168 | IRCPerson mask(message->prefix()); | 170 | IRCPerson mask(message->prefix()); |
169 | IRCPerson *person = m_session->getPerson(mask.nick()); | 171 | IRCPerson *person = m_session->getPerson(mask.nick()); |
170 | if (!person) { | 172 | if (!person) { |
171 | /* Person not yet known, create and add to the current session */ | 173 | /* Person not yet known, create and add to the current session */ |
172 | person = new IRCPerson(message->prefix()); | 174 | person = new IRCPerson(message->prefix()); |
173 | m_session->addPerson(person); | 175 | m_session->addPerson(person); |
174 | } | 176 | } |
175 | IRCOutput output(OUTPUT_CHANPRIVMSG, message->param(1)); | 177 | IRCOutput output(OUTPUT_QUERYPRIVMSG, message->param(1)); |
176 | output.addParam(person); | 178 | output.addParam(person); |
177 | emit outputReady(output); | 179 | emit outputReady(output); |
178 | } else if (message->param(0).at(0) == '#') { | 180 | } else if (message->param(0).at(0) == '#') { |
179 | /* IRC Channel message detected, verify sender, channel and display it */ | 181 | /* IRC Channel message detected, verify sender, channel and display it */ |
180 | IRCChannel *channel = m_session->getChannel(message->param(0)); | 182 | IRCChannel *channel = m_session->getChannel(message->param(0)); |
181 | if (channel) { | 183 | if (channel) { |
182 | IRCPerson mask(message->prefix()); | 184 | IRCPerson mask(message->prefix()); |
183 | IRCChannelPerson *person = channel->getPerson(mask.nick()); | 185 | IRCChannelPerson *person = channel->getPerson(mask.nick()); |
184 | if (person) { | 186 | if (person) { |
185 | IRCOutput output(OUTPUT_CHANPRIVMSG, message->param(1)); | 187 | IRCOutput output(OUTPUT_CHANPRIVMSG, message->param(1)); |
186 | output.addParam(channel); | 188 | output.addParam(channel); |
187 | output.addParam(person); | 189 | output.addParam(person); |
188 | emit outputReady(output); | 190 | emit outputReady(output); |
189 | } else { | 191 | } else { |
190 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Channel message with unknown sender"))); | 192 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Channel message with unknown sender"))); |
191 | } | 193 | } |
192 | } else { | 194 | } else { |
193 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Channel message with unknown channel"))); | 195 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Channel message with unknown channel"))); |
194 | } | 196 | } |
195 | } else { | 197 | } else { |
196 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received PRIVMSG of unknown type"))); | 198 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received PRIVMSG of unknown type"))); |
197 | } | 199 | } |
198 | } | 200 | } |
199 | 201 | ||
200 | void IRCMessageParser::parseLiteralNick(IRCMessage *message) { | 202 | void IRCMessageParser::parseLiteralNick(IRCMessage *message) { |
201 | IRCPerson mask(message->prefix()); | 203 | IRCPerson mask(message->prefix()); |
202 | 204 | ||
203 | if (mask.nick() == m_session->m_server->nick()) { | 205 | if (mask.nick() == m_session->m_server->nick()) { |
204 | /* We are changing our nickname */ | 206 | /* We are changing our nickname */ |
205 | m_session->m_server->setNick(message->param(0)); | 207 | m_session->m_server->setNick(message->param(0)); |
206 | IRCOutput output(OUTPUT_NICKCHANGE, tr("You are now known as ")+message->param(0)); | 208 | IRCOutput output(OUTPUT_NICKCHANGE, tr("You are now known as ")+message->param(0)); |
207 | output.addParam(0); | 209 | output.addParam(0); |
208 | emit outputReady(output); | 210 | emit outputReady(output); |
209 | } else { | 211 | } else { |
210 | /* Someone else is */ | 212 | /* Someone else is */ |
211 | IRCPerson *person = m_session->getPerson(mask.nick()); | 213 | IRCPerson *person = m_session->getPerson(mask.nick()); |
212 | if (person) { | 214 | if (person) { |
213 | IRCOutput output(OUTPUT_NICKCHANGE, mask.nick() + tr(" is now known as ") + message->param(0)); | 215 | IRCOutput output(OUTPUT_NICKCHANGE, mask.nick() + tr(" is now known as ") + message->param(0)); |
214 | output.addParam(person); | 216 | output.addParam(person); |
215 | emit outputReady(output); | 217 | emit outputReady(output); |
216 | } else { | 218 | } else { |
217 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Nickname change of an unknown person"))); | 219 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Nickname change of an unknown person"))); |
218 | } | 220 | } |
219 | } | 221 | } |
220 | } | 222 | } |
221 | 223 | ||
222 | void IRCMessageParser::parseLiteralQuit(IRCMessage *message) { | 224 | void IRCMessageParser::parseLiteralQuit(IRCMessage *message) { |
223 | IRCPerson mask(message->prefix()); | 225 | IRCPerson mask(message->prefix()); |
224 | IRCPerson *person = m_session->getPerson(mask.nick()); | 226 | IRCPerson *person = m_session->getPerson(mask.nick()); |
225 | if (person) { | 227 | if (person) { |
226 | QList<IRCChannel> channels; | 228 | QList<IRCChannel> channels; |
227 | m_session->getChannelsByPerson(person, channels); | 229 | m_session->getChannelsByPerson(person, channels); |
228 | QListIterator<IRCChannel> it(channels); | 230 | QListIterator<IRCChannel> it(channels); |
229 | for (;it.current(); ++it) { | 231 | for (;it.current(); ++it) { |
230 | IRCChannelPerson *chanperson = it.current()->getPerson(mask.nick()); | 232 | IRCChannelPerson *chanperson = it.current()->getPerson(mask.nick()); |
231 | it.current()->removePerson(chanperson); | 233 | it.current()->removePerson(chanperson); |
232 | delete chanperson; | 234 | delete chanperson; |
233 | } | 235 | } |
234 | m_session->removePerson(person); | 236 | m_session->removePerson(person); |
235 | IRCOutput output(OUTPUT_QUIT, mask.nick() + tr(" has quit ") + "(" + message->param(0) + ")"); | 237 | IRCOutput output(OUTPUT_QUIT, mask.nick() + tr(" has quit ") + "(" + message->param(0) + ")"); |
236 | output.addParam(person); | 238 | output.addParam(person); |
237 | emit outputReady(output); | 239 | emit outputReady(output); |
238 | delete person; | 240 | delete person; |
239 | } else { | 241 | } else { |
240 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown person quit - desynchronized?"))); | 242 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown person quit - desynchronized?"))); |
241 | } | 243 | } |
242 | } | 244 | } |
243 | 245 | ||
244 | void IRCMessageParser::parseLiteralError(IRCMessage *message) { | 246 | void IRCMessageParser::parseLiteralError(IRCMessage *message) { |
245 | emit outputReady(IRCOutput(OUTPUT_ERROR, message->allParameters())); | 247 | emit outputReady(IRCOutput(OUTPUT_ERROR, message->allParameters())); |
246 | } | 248 | } |
247 | 249 | ||
248 | void IRCMessageParser::parseCTCPPing(IRCMessage *message) { | 250 | void IRCMessageParser::parseCTCPPing(IRCMessage *message) { |
249 | IRCPerson mask(message->prefix()); | 251 | IRCPerson mask(message->prefix()); |
250 | m_session->m_connection->sendCTCP(mask.nick(), "PING " + message->allParameters()); | 252 | m_session->m_connection->sendCTCP(mask.nick(), "PING " + message->allParameters()); |
251 | emit outputReady(IRCOutput(OUTPUT_CTCP, tr("Received a CTCP PING from ")+mask.nick())); | 253 | emit outputReady(IRCOutput(OUTPUT_CTCP, tr("Received a CTCP PING from ")+mask.nick())); |
252 | } | 254 | } |
253 | 255 | ||
254 | void IRCMessageParser::parseCTCPVersion(IRCMessage *message) { | 256 | void IRCMessageParser::parseCTCPVersion(IRCMessage *message) { |
255 | IRCPerson mask(message->prefix()); | 257 | IRCPerson mask(message->prefix()); |
256 | m_session->m_connection->sendCTCP(mask.nick(), APP_VERSION " " APP_COPYSTR); | 258 | m_session->m_connection->sendCTCP(mask.nick(), APP_VERSION " " APP_COPYSTR); |
257 | emit outputReady(IRCOutput(OUTPUT_CTCP, tr("Received a CTCP VERSION from ")+mask.nick())); | 259 | emit outputReady(IRCOutput(OUTPUT_CTCP, tr("Received a CTCP VERSION from ")+mask.nick())); |
258 | } | 260 | } |
259 | 261 | ||
260 | void IRCMessageParser::parseCTCPAction(IRCMessage *message) { | 262 | void IRCMessageParser::parseCTCPAction(IRCMessage *message) { |
261 | IRCPerson mask(message->prefix()); | 263 | IRCPerson mask(message->prefix()); |
262 | QString dest = message->ctcpDestination(); | 264 | QString dest = message->ctcpDestination(); |
263 | if (dest.startsWith("#")) { | 265 | if (dest.startsWith("#")) { |
264 | IRCChannel *channel = m_session->getChannel(dest); | 266 | IRCChannel *channel = m_session->getChannel(dest); |
265 | if (channel) { | 267 | if (channel) { |
266 | IRCChannelPerson *person = channel->getPerson(mask.nick()); | 268 | IRCChannelPerson *person = channel->getPerson(mask.nick()); |
267 | if (person) { | 269 | if (person) { |
268 | IRCOutput output(OUTPUT_CHANACTION, "*" + mask.nick() + message->param(0)); | 270 | IRCOutput output(OUTPUT_CHANACTION, "*" + mask.nick() + message->param(0)); |
269 | output.addParam(channel); | 271 | output.addParam(channel); |
270 | output.addParam(person); | 272 | output.addParam(person); |
271 | emit outputReady(output); | 273 | emit outputReady(output); |
272 | } else { | 274 | } else { |
273 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP ACTION with unknown person - Desynchronized?"))); | 275 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP ACTION with unknown person - Desynchronized?"))); |
274 | } | 276 | } |
275 | } else { | 277 | } else { |
276 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP ACTION with unknown channel - Desynchronized?"))); | 278 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP ACTION with unknown channel - Desynchronized?"))); |
277 | } | 279 | } |
278 | } else { | 280 | } else { |
279 | if (message->ctcpDestination() == m_session->m_server->nick()) { | 281 | if (message->ctcpDestination() == m_session->m_server->nick()) { |
280 | IRCPerson *person = m_session->getPerson(mask.nick()); | 282 | IRCPerson *person = m_session->getPerson(mask.nick()); |
281 | if (!person) { | 283 | if (!person) { |
282 | /* Person not yet known, create and add to the current session */ | 284 | /* Person not yet known, create and add to the current session */ |
283 | person = new IRCPerson(message->prefix()); | 285 | person = new IRCPerson(message->prefix()); |
284 | m_session->addPerson(person); | 286 | m_session->addPerson(person); |
285 | } | 287 | } |
286 | IRCOutput output(OUTPUT_QUERYACTION, "*" + mask.nick() + message->param(0)); | 288 | IRCOutput output(OUTPUT_QUERYACTION, "*" + mask.nick() + message->param(0)); |
287 | output.addParam(person); | 289 | output.addParam(person); |
288 | emit outputReady(output); | 290 | emit outputReady(output); |
289 | } else { | 291 | } else { |
290 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP ACTION with bad recipient"))); | 292 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP ACTION with bad recipient"))); |
291 | } | 293 | } |
292 | } | 294 | } |
293 | } | 295 | } |
294 | 296 | ||
295 | void IRCMessageParser::parseLiteralMode(IRCMessage *message) { | 297 | void IRCMessageParser::parseLiteralMode(IRCMessage *message) { |
296 | IRCPerson mask(message->prefix()); | 298 | IRCPerson mask(message->prefix()); |
297 | 299 | ||
298 | if (message->param(0).startsWith("#")) { | 300 | if (message->param(0).startsWith("#")) { |
299 | IRCChannel *channel = m_session->getChannel(message->param(0)); | 301 | IRCChannel *channel = m_session->getChannel(message->param(0)); |
300 | if (channel) { | 302 | if (channel) { |
301 | QString temp, parameters = message->allParameters().right(message->allParameters().length() - channel->channelname().length() - 1); | 303 | QString temp, parameters = message->allParameters().right(message->allParameters().length() - channel->channelname().length() - 1); |
302 | QTextIStream stream(¶meters); | 304 | QTextIStream stream(¶meters); |
303 | bool set = FALSE; | 305 | bool set = FALSE; |
304 | while (!stream.atEnd()) { | 306 | while (!stream.atEnd()) { |
305 | stream >> temp; | 307 | stream >> temp; |
306 | if (temp.startsWith("+")) { | 308 | if (temp.startsWith("+")) { |
307 | set = TRUE; | 309 | set = TRUE; |
308 | temp = temp.right(1); | 310 | temp = temp.right(1); |
309 | } else if (temp.startsWith("-")) { | 311 | } else if (temp.startsWith("-")) { |
310 | set = FALSE; | 312 | set = FALSE; |
311 | temp = temp.right(1); | 313 | temp = temp.right(1); |
312 | } else { | 314 | } else { |
313 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change has unknown type"))); | 315 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change has unknown type"))); |
314 | return; | 316 | return; |
315 | } | 317 | } |
316 | if (temp == "o") { | 318 | if (temp == "o") { |
317 | stream >> temp; | 319 | stream >> temp; |
318 | IRCChannelPerson *person = channel->getPerson(temp); | 320 | IRCChannelPerson *person = channel->getPerson(temp); |
319 | if (person) { | 321 | if (person) { |
320 | if (set) { | 322 | if (set) { |
321 | person->flags |= PERSON_FLAG_OP; | 323 | person->flags |= PERSON_FLAG_OP; |
322 | IRCOutput output(OUTPUT_CHANPERSONMODE, mask.nick() + tr(" gives channel operator status to " + person->person->nick())); | 324 | IRCOutput output(OUTPUT_CHANPERSONMODE, mask.nick() + tr(" gives channel operator status to " + person->person->nick())); |
323 | output.addParam(channel); | 325 | output.addParam(channel); |
324 | output.addParam(person); | 326 | output.addParam(person); |
325 | emit outputReady(output); | 327 | emit outputReady(output); |
326 | } else { | 328 | } else { |
327 | person->flags &= 0xFFFF - PERSON_FLAG_OP; | 329 | person->flags &= 0xFFFF - PERSON_FLAG_OP; |
328 | IRCOutput output(OUTPUT_CHANPERSONMODE, mask.nick() + tr(" removes channel operator status from " + person->person->nick())); | 330 | IRCOutput output(OUTPUT_CHANPERSONMODE, mask.nick() + tr(" removes channel operator status from " + person->person->nick())); |
329 | output.addParam(channel); | 331 | output.addParam(channel); |
330 | output.addParam(person); | 332 | output.addParam(person); |
331 | emit outputReady(output); | 333 | emit outputReady(output); |
332 | } | 334 | } |
333 | } else { | 335 | } else { |
334 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown person - Desynchronized?"))); | 336 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown person - Desynchronized?"))); |
335 | } | 337 | } |
336 | } else if (temp == "v") { | 338 | } else if (temp == "v") { |
337 | stream >> temp; | 339 | stream >> temp; |
338 | IRCChannelPerson *person = channel->getPerson(temp); | 340 | IRCChannelPerson *person = channel->getPerson(temp); |
339 | if (person) { | 341 | if (person) { |
340 | if (set) { | 342 | if (set) { |
341 | person->flags |= PERSON_FLAG_VOICE; | 343 | person->flags |= PERSON_FLAG_VOICE; |
342 | IRCOutput output(OUTPUT_CHANPERSONMODE, mask.nick() + tr(" gives voice to " + person->person->nick())); | 344 | IRCOutput output(OUTPUT_CHANPERSONMODE, mask.nick() + tr(" gives voice to " + person->person->nick())); |
343 | output.addParam(channel); | 345 | output.addParam(channel); |
344 | output.addParam(person); | 346 | output.addParam(person); |
345 | emit outputReady(output); | 347 | emit outputReady(output); |
346 | } else { | 348 | } else { |
347 | person->flags &= 0xFFFF - PERSON_FLAG_VOICE; | 349 | person->flags &= 0xFFFF - PERSON_FLAG_VOICE; |
348 | IRCOutput output(OUTPUT_CHANPERSONMODE, mask.nick() + tr(" removes voice from " + person->person->nick())); | 350 | IRCOutput output(OUTPUT_CHANPERSONMODE, mask.nick() + tr(" removes voice from " + person->person->nick())); |
349 | output.addParam(channel); | 351 | output.addParam(channel); |
350 | output.addParam(person); | 352 | output.addParam(person); |
351 | emit outputReady(output); | 353 | emit outputReady(output); |
352 | } | 354 | } |
353 | } else { | 355 | } else { |
354 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown person - Desynchronized?"))); | 356 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown person - Desynchronized?"))); |
355 | } | 357 | } |
356 | } else { | 358 | } else { |
357 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown flag"))); | 359 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown flag"))); |
358 | } | 360 | } |
359 | } | 361 | } |
360 | } else { | 362 | } else { |
361 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown kannel - Desynchronized?"))); | 363 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown kannel - Desynchronized?"))); |
362 | } | 364 | } |
363 | } else { | 365 | } else { |
364 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("User modes not supported yet"))); | 366 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("User modes not supported yet"))); |
365 | } | 367 | } |
366 | } | 368 | } |
367 | 369 | ||
368 | void IRCMessageParser::parseLiteralKick(IRCMessage *message) { | 370 | void IRCMessageParser::parseLiteralKick(IRCMessage *message) { |
369 | IRCPerson mask(message->prefix()); | 371 | IRCPerson mask(message->prefix()); |
370 | IRCChannel *channel = m_session->getChannel(message->param(0)); | 372 | IRCChannel *channel = m_session->getChannel(message->param(0)); |
371 | if (channel) { | 373 | if (channel) { |
372 | IRCChannelPerson *person = channel->getPerson(message->param(1)); | 374 | IRCChannelPerson *person = channel->getPerson(message->param(1)); |
373 | if (person) { | 375 | if (person) { |
374 | if (person->person->nick() == m_session->m_server->nick()) { | 376 | if (person->person->nick() == m_session->m_server->nick()) { |
375 | m_session->removeChannel(channel); | 377 | m_session->removeChannel(channel); |
376 | IRCOutput output(OUTPUT_SELFKICK, tr("You were kicked from ") + channel->channelname() + tr(" by ") + mask.nick() + " (" + message->param(2) + ")"); | 378 | IRCOutput output(OUTPUT_SELFKICK, tr("You were kicked from ") + channel->channelname() + tr(" by ") + mask.nick() + " (" + message->param(2) + ")"); |
377 | output.addParam(channel); | 379 | output.addParam(channel); |
378 | emit outputReady(output); | 380 | emit outputReady(output); |
379 | } else { | 381 | } else { |
380 | channel->removePerson(person); | 382 | channel->removePerson(person); |
381 | IRCOutput output(OUTPUT_OTHERKICK, person->person->nick() + tr(" was kicked from ") + channel->channelname() + tr(" by ") + mask.nick()+ " (" + message->param(2) + ")"); | 383 | IRCOutput output(OUTPUT_OTHERKICK, person->person->nick() + tr(" was kicked from ") + channel->channelname() + tr(" by ") + mask.nick()+ " (" + message->param(2) + ")"); |
382 | output.addParam(channel); | 384 | output.addParam(channel); |
383 | output.addParam(person); | 385 | output.addParam(person); |
384 | emit outputReady(output); | 386 | emit outputReady(output); |
385 | } | 387 | } |
386 | } else { | 388 | } else { |
387 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown person kick - desynchronized?"))); | 389 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown person kick - desynchronized?"))); |
388 | } | 390 | } |
389 | } else { | 391 | } else { |
390 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown channel kick - desynchronized?"))); | 392 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown channel kick - desynchronized?"))); |
391 | } | 393 | } |
392 | } | 394 | } |
393 | 395 | ||
394 | void IRCMessageParser::parseNumerical001(IRCMessage *message) { | 396 | void IRCMessageParser::parseNumerical001(IRCMessage *message) { |
395 | /* Welcome to IRC message, display */ | 397 | /* Welcome to IRC message, display */ |
396 | emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, message->param(1))); | 398 | emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, message->param(1))); |
397 | } | 399 | } |
398 | 400 | ||
399 | void IRCMessageParser::parseNumerical002(IRCMessage *message) { | 401 | void IRCMessageParser::parseNumerical002(IRCMessage *message) { |
400 | emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, message->param(1))); | 402 | emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, message->param(1))); |
401 | } | 403 | } |
402 | 404 | ||
403 | void IRCMessageParser::parseNumerical003(IRCMessage *message) { | 405 | void IRCMessageParser::parseNumerical003(IRCMessage *message) { |
404 | emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, message->param(1))); | 406 | emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, message->param(1))); |
405 | } | 407 | } |
406 | 408 | ||
407 | void IRCMessageParser::parseNumerical004(IRCMessage *message) { | 409 | void IRCMessageParser::parseNumerical004(IRCMessage *message) { |
408 | emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, message->allParameters())); | 410 | emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, message->allParameters())); |
409 | } | 411 | } |
410 | 412 | ||
411 | void IRCMessageParser::parseNumerical005(IRCMessage *message) { | 413 | void IRCMessageParser::parseNumerical005(IRCMessage *message) { |
412 | emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, message->allParameters())); | 414 | emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, message->allParameters())); |
413 | } | 415 | } |
414 | 416 | ||
415 | void IRCMessageParser::parseNumericalStats(IRCMessage *message) { | 417 | void IRCMessageParser::parseNumericalStats(IRCMessage *message) { |
416 | emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, message->param(1))); | 418 | emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, message->param(1))); |
417 | } | 419 | } |
418 | 420 | ||
419 | void IRCMessageParser::parseNumericalNames(IRCMessage *message) { | 421 | void IRCMessageParser::parseNumericalNames(IRCMessage *message) { |
420 | /* Name list sent when joining a channel */ | 422 | /* Name list sent when joining a channel */ |
421 | IRCChannel *channel = m_session->getChannel(message->param(2)); | 423 | IRCChannel *channel = m_session->getChannel(message->param(2)); |
422 | if (channel != 0) { | 424 | if (channel != 0) { |
423 | QString people = message->param(3); | 425 | QString people = message->param(3); |
424 | QTextIStream stream(&people); | 426 | QTextIStream stream(&people); |
425 | QString temp; | 427 | QString temp; |
426 | 428 | ||
427 | while (!stream.atEnd()) { | 429 | while (!stream.atEnd()) { |
428 | stream >> temp; | 430 | stream >> temp; |
429 | 431 | ||
430 | char flagch = temp.at(0).latin1(); | 432 | char flagch = temp.at(0).latin1(); |
431 | int flag = 0; | 433 | int flag = 0; |
432 | QString nick; | 434 | QString nick; |
433 | /* Parse person flags */ | 435 | /* Parse person flags */ |
434 | if (flagch == '@' || flagch == '+' || flagch=='%' || flagch == '*') { | 436 | if (flagch == '@' || flagch == '+' || flagch=='%' || flagch == '*') { |
435 | 437 | ||
436 | nick = temp.right(temp.length()-1); | 438 | nick = temp.right(temp.length()-1); |
437 | switch (flagch) { | 439 | switch (flagch) { |
438 | case '@': flag = PERSON_FLAG_OP; break; | 440 | case '@': flag = PERSON_FLAG_OP; break; |
439 | case '+': flag = PERSON_FLAG_VOICE; break; | 441 | case '+': flag = PERSON_FLAG_VOICE; break; |
440 | case '%': flag = PERSON_FLAG_HALFOP; break; | 442 | case '%': flag = PERSON_FLAG_HALFOP; break; |
441 | default : flag = 0; break; | 443 | default : flag = 0; break; |
442 | } | 444 | } |
443 | } else { | 445 | } else { |
444 | nick = temp; | 446 | nick = temp; |
445 | } | 447 | } |
446 | 448 | ||
447 | IRCChannelPerson *chan_person = new IRCChannelPerson(); | 449 | IRCChannelPerson *chan_person = new IRCChannelPerson(); |
448 | IRCPerson *person = m_session->getPerson(nick); | 450 | IRCPerson *person = m_session->getPerson(nick); |
449 | if (person == 0) { | 451 | if (person == 0) { |
450 | person = new IRCPerson(); | 452 | person = new IRCPerson(); |
451 | person->setNick(nick); | 453 | person->setNick(nick); |
452 | m_session->addPerson(person); | 454 | m_session->addPerson(person); |
453 | } | 455 | } |
454 | chan_person->person = person; | 456 | chan_person->person = person; |
455 | chan_person->flags = flag; | 457 | chan_person->flags = flag; |
456 | channel->addPerson(chan_person); | 458 | channel->addPerson(chan_person); |
457 | } | 459 | } |
458 | } else { | 460 | } else { |
459 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Server message with unknown channel"))); | 461 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Server message with unknown channel"))); |
460 | } | 462 | } |
461 | } | 463 | } |
462 | 464 | ||
463 | void IRCMessageParser::parseNumericalEndOfNames(IRCMessage *message) { | 465 | void IRCMessageParser::parseNumericalEndOfNames(IRCMessage *message) { |
464 | /* Done syncing to channel */ | 466 | /* Done syncing to channel */ |
465 | IRCChannel *channel = m_session->getChannel(message->param(1)); | 467 | IRCChannel *channel = m_session->getChannel(message->param(1)); |
466 | if (channel) { | 468 | if (channel) { |
467 | channel->setHasPeople(TRUE); | 469 | channel->setHasPeople(TRUE); |
468 | /* Yes, we want the names before anything happens inside the GUI */ | 470 | /* Yes, we want the names before anything happens inside the GUI */ |
469 | IRCOutput output(OUTPUT_SELFJOIN, tr("You joined channel ") + channel->channelname()); | 471 | IRCOutput output(OUTPUT_SELFJOIN, tr("You joined channel ") + channel->channelname()); |
470 | output.addParam(channel); | 472 | output.addParam(channel); |
471 | emit outputReady(output); | 473 | emit outputReady(output); |
472 | } else { | 474 | } else { |
473 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Server message with unknown channel"))); | 475 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Server message with unknown channel"))); |
474 | } | 476 | } |
475 | } | 477 | } |
476 | 478 | ||
477 | 479 | ||
478 | void IRCMessageParser::parseNumericalNicknameInUse(IRCMessage *) { | 480 | void IRCMessageParser::parseNumericalNicknameInUse(IRCMessage *) { |
479 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Nickname is in use, please reconnect with a different nickname"))); | 481 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Nickname is in use, please reconnect with a different nickname"))); |
480 | m_session->endSession(); | 482 | m_session->endSession(); |
481 | } | 483 | } |
484 | |||
485 | void IRCMessageParser::parseNumericalNoSuchNick(IRCMessage *) { | ||
486 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("No such nickname"))); | ||
487 | } | ||
diff --git a/noncore/net/opieirc/ircmessageparser.h b/noncore/net/opieirc/ircmessageparser.h index b45b8f0..f774047 100644 --- a/noncore/net/opieirc/ircmessageparser.h +++ b/noncore/net/opieirc/ircmessageparser.h | |||
@@ -1,95 +1,96 @@ | |||
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 | ||
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 parseNumerical001(IRCMessage *message); | 75 | void parseNumerical001(IRCMessage *message); |
76 | void parseNumerical002(IRCMessage *message); | 76 | void parseNumerical002(IRCMessage *message); |
77 | void parseNumerical003(IRCMessage *message); | 77 | void parseNumerical003(IRCMessage *message); |
78 | void parseNumerical004(IRCMessage *message); | 78 | void parseNumerical004(IRCMessage *message); |
79 | void parseNumerical005(IRCMessage *message); | 79 | void parseNumerical005(IRCMessage *message); |
80 | void parseNumericalStats(IRCMessage *message); | 80 | void parseNumericalStats(IRCMessage *message); |
81 | void parseNumericalNames(IRCMessage *message); | 81 | void parseNumericalNames(IRCMessage *message); |
82 | void parseNumericalEndOfNames(IRCMessage *message); | 82 | void parseNumericalEndOfNames(IRCMessage *message); |
83 | void parseNumericalNicknameInUse(IRCMessage *message); | 83 | void parseNumericalNicknameInUse(IRCMessage *message); |
84 | void parseNumericalNoSuchNick(IRCMessage *message); | ||
84 | void parseCTCPPing(IRCMessage *message); | 85 | void parseCTCPPing(IRCMessage *message); |
85 | void parseCTCPVersion(IRCMessage *message); | 86 | void parseCTCPVersion(IRCMessage *message); |
86 | void parseCTCPAction(IRCMessage *message); | 87 | void parseCTCPAction(IRCMessage *message); |
87 | protected: | 88 | protected: |
88 | IRCSession *m_session; | 89 | IRCSession *m_session; |
89 | /* Parser tables */ | 90 | /* Parser tables */ |
90 | static IRCLiteralMessageParserStruct literalParserProcTable[]; | 91 | static IRCLiteralMessageParserStruct literalParserProcTable[]; |
91 | static IRCNumericalMessageParserStruct numericalParserProcTable[]; | 92 | static IRCNumericalMessageParserStruct numericalParserProcTable[]; |
92 | static IRCCTCPMessageParserStruct ctcpParserProcTable[]; | 93 | static IRCCTCPMessageParserStruct ctcpParserProcTable[]; |
93 | }; | 94 | }; |
94 | 95 | ||
95 | #endif /* __IRCMESSAGEPARSER_H */ | 96 | #endif /* __IRCMESSAGEPARSER_H */ |
diff --git a/noncore/net/opieirc/ircperson.cpp b/noncore/net/opieirc/ircperson.cpp index bd6b8d6..bd341f1 100644 --- a/noncore/net/opieirc/ircperson.cpp +++ b/noncore/net/opieirc/ircperson.cpp | |||
@@ -1,50 +1,56 @@ | |||
1 | #include "ircperson.h" | 1 | #include "ircperson.h" |
2 | #include <stdio.h> | 2 | #include <stdio.h> |
3 | 3 | ||
4 | IRCPerson::IRCPerson() { | 4 | IRCPerson::IRCPerson() { |
5 | m_nick = ""; | 5 | m_nick = ""; |
6 | m_user = ""; | 6 | m_user = ""; |
7 | m_host = ""; | 7 | m_host = ""; |
8 | } | 8 | } |
9 | 9 | ||
10 | IRCPerson::IRCPerson(const IRCPerson &person) { | ||
11 | m_nick = person.m_nick; | ||
12 | m_user = person.m_user; | ||
13 | m_host = person.m_host; | ||
14 | } | ||
15 | |||
10 | IRCPerson::IRCPerson(QString mask) { | 16 | IRCPerson::IRCPerson(QString mask) { |
11 | IRCPerson(); | 17 | IRCPerson(); |
12 | fromMask(mask); | 18 | fromMask(mask); |
13 | } | 19 | } |
14 | 20 | ||
15 | void IRCPerson::fromMask(QString mask) { | 21 | void IRCPerson::fromMask(QString mask) { |
16 | int sep1 = mask.find("!"); | 22 | int sep1 = mask.find("!"); |
17 | int sep2 = mask.find("@"); | 23 | int sep2 = mask.find("@"); |
18 | 24 | ||
19 | m_nick = mask.left(sep1); | 25 | m_nick = mask.left(sep1); |
20 | m_user = mask.mid(sep1+1, sep2-sep1-1); | 26 | m_user = mask.mid(sep1+1, sep2-sep1-1); |
21 | m_host = mask.right(mask.length()-sep2-1); | 27 | m_host = mask.right(mask.length()-sep2-1); |
22 | } | 28 | } |
23 | 29 | ||
24 | QString IRCPerson::toMask() { | 30 | QString IRCPerson::toMask() { |
25 | return m_nick + "!" + m_user + "@" + m_host; | 31 | return m_nick + "!" + m_user + "@" + m_host; |
26 | } | 32 | } |
27 | 33 | ||
28 | void IRCPerson::setNick(QString nick) { | 34 | void IRCPerson::setNick(QString nick) { |
29 | m_nick = nick; | 35 | m_nick = nick; |
30 | } | 36 | } |
31 | 37 | ||
32 | void IRCPerson::setUser(QString user) { | 38 | void IRCPerson::setUser(QString user) { |
33 | m_user = user; | 39 | m_user = user; |
34 | } | 40 | } |
35 | 41 | ||
36 | void IRCPerson::setHost(QString host) { | 42 | void IRCPerson::setHost(QString host) { |
37 | m_host = host; | 43 | m_host = host; |
38 | } | 44 | } |
39 | 45 | ||
40 | QString IRCPerson::nick() { | 46 | QString IRCPerson::nick() { |
41 | return m_nick; | 47 | return m_nick; |
42 | } | 48 | } |
43 | 49 | ||
44 | QString IRCPerson::user() { | 50 | QString IRCPerson::user() { |
45 | return m_user; | 51 | return m_user; |
46 | } | 52 | } |
47 | 53 | ||
48 | QString IRCPerson::host() { | 54 | QString IRCPerson::host() { |
49 | return m_host; | 55 | return m_host; |
50 | } | 56 | } |
diff --git a/noncore/net/opieirc/ircperson.h b/noncore/net/opieirc/ircperson.h index 850f91b..38732c4 100644 --- a/noncore/net/opieirc/ircperson.h +++ b/noncore/net/opieirc/ircperson.h | |||
@@ -1,50 +1,53 @@ | |||
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 __IRCPERSON | 21 | #ifndef __IRCPERSON |
22 | #define __IRCPERSON | 22 | #define __IRCPERSON |
23 | 23 | ||
24 | #include <qstring.h> | 24 | #include <qstring.h> |
25 | 25 | ||
26 | /* This class requires all required information relating to a person | 26 | /* This class requires all required information relating to a person |
27 | on the IRC network. This class can be used as an input mask for | 27 | on the IRC network. This class can be used as an input mask for |
28 | IRCMessage-prefixes too | 28 | IRCMessage-prefixes too |
29 | */ | 29 | */ |
30 | 30 | ||
31 | class IRCPerson { | 31 | class IRCPerson { |
32 | public: | 32 | public: |
33 | IRCPerson(); | 33 | IRCPerson(); |
34 | /* Create an IRCPerson from an IRC style description (nick!user@host) */ | ||
34 | IRCPerson(QString mask); | 35 | IRCPerson(QString mask); |
36 | /* Copy constructor */ | ||
37 | IRCPerson(const IRCPerson &person); | ||
35 | 38 | ||
36 | void fromMask(QString mask); | 39 | void fromMask(QString mask); |
37 | void setNick(QString name); | 40 | void setNick(QString name); |
38 | void setUser(QString user); | 41 | void setUser(QString user); |
39 | void setHost(QString host); | 42 | void setHost(QString host); |
40 | QString toMask(); | 43 | QString toMask(); |
41 | QString nick(); | 44 | QString nick(); |
42 | QString user(); | 45 | QString user(); |
43 | QString host(); | 46 | QString host(); |
44 | protected: | 47 | protected: |
45 | QString m_nick; | 48 | QString m_nick; |
46 | QString m_user; | 49 | QString m_user; |
47 | QString m_host; | 50 | QString m_host; |
48 | }; | 51 | }; |
49 | 52 | ||
50 | #endif /* __IRCPERSON */ | 53 | #endif /* __IRCPERSON */ |
diff --git a/noncore/net/opieirc/ircquerytab.cpp b/noncore/net/opieirc/ircquerytab.cpp index 6d24845..642cc5b 100644 --- a/noncore/net/opieirc/ircquerytab.cpp +++ b/noncore/net/opieirc/ircquerytab.cpp | |||
@@ -1,2 +1,78 @@ | |||
1 | #include <qhbox.h> | ||
1 | #include "ircquerytab.h" | 2 | #include "ircquerytab.h" |
3 | #include "ircservertab.h" | ||
4 | |||
5 | IRCQueryTab::IRCQueryTab(IRCPerson *person, IRCServerTab *parentTab, MainWindow *mainWindow, QWidget *parent, const char *name, WFlags f) : IRCTab(parent, name, f) { | ||
6 | m_mainWindow = mainWindow; | ||
7 | m_parentTab = parentTab; | ||
8 | m_person = new IRCPerson(*person); /* We need this (the person might sign off and the original IRCPerson gets deleted) */ | ||
9 | m_description->setText(tr("Talking to ") + " <b>" + person->nick() + "</b>"); | ||
10 | QHBox *hbox = new QHBox(this); | ||
11 | m_textview = new QTextView(hbox); | ||
12 | m_textview->setHScrollBarMode(QScrollView::AlwaysOff); | ||
13 | m_textview->setVScrollBarMode(QScrollView::AlwaysOn); | ||
14 | m_textview->setTextFormat(RichText); | ||
15 | m_field = new QLineEdit(this); | ||
16 | m_layout->add(hbox); | ||
17 | hbox->show(); | ||
18 | m_layout->add(m_field); | ||
19 | m_field->setFocus(); | ||
20 | connect(m_field, SIGNAL(returnPressed()), this, SLOT(processCommand())); | ||
21 | |||
22 | } | ||
23 | |||
24 | void IRCQueryTab::appendText(QString text) { | ||
25 | /* not using append because it creates layout problems */ | ||
26 | m_textview->setText(m_textview->text() + text); | ||
27 | m_textview->ensureVisible(0, m_textview->contentsHeight()); | ||
28 | } | ||
29 | |||
30 | IRCQueryTab::~IRCQueryTab() { | ||
31 | m_parentTab->removeQueryTab(this); | ||
32 | delete m_person; | ||
33 | } | ||
34 | |||
35 | void IRCQueryTab::processCommand() { | ||
36 | QString text = m_field->text(); | ||
37 | if (text.length()>0) { | ||
38 | if (session()->isSessionActive()) { | ||
39 | if (text.startsWith("/") && !text.startsWith("//")) { | ||
40 | /* Command mode */ | ||
41 | m_parentTab->executeCommand(this, text);; | ||
42 | } else { | ||
43 | if (text.startsWith("//")) | ||
44 | text = text.right(text.length()-1); | ||
45 | session()->sendMessage(m_person, m_field->text()); | ||
46 | appendText("<<font color=\"#dd0000\">"+m_parentTab->server()->nick()+"</font>> "+IRCOutput::toHTML(m_field->text())+"<br>"); | ||
47 | } | ||
48 | } else { | ||
49 | appendText("<font color=\"#ff0000\">"+tr("Disconnected")+"</font><br>"); | ||
50 | } | ||
51 | } | ||
52 | m_field->clear(); | ||
53 | } | ||
54 | |||
55 | void IRCQueryTab::display(IRCOutput output) { | ||
56 | if (output.type() == OUTPUT_QUERYPRIVMSG) { | ||
57 | appendText("<<font color=\"#0000dd\">"+m_person->nick()+"</font>> " + output.htmlMessage() + "<br>"); | ||
58 | } else if (output.type() == OUTPUT_QUERYACTION) { | ||
59 | appendText("<font color=\"#0000dd\">" + output.htmlMessage() + "<br>"); | ||
60 | } | ||
61 | } | ||
62 | |||
63 | QString IRCQueryTab::title() { | ||
64 | return m_person->nick(); | ||
65 | } | ||
66 | |||
67 | IRCSession *IRCQueryTab::session() { | ||
68 | return m_parentTab->session(); | ||
69 | } | ||
70 | |||
71 | void IRCQueryTab::remove() { | ||
72 | m_mainWindow->killTab(this); | ||
73 | } | ||
74 | |||
75 | IRCPerson *IRCQueryTab::person() { | ||
76 | return m_person; | ||
77 | } | ||
2 | 78 | ||
diff --git a/noncore/net/opieirc/ircquerytab.h b/noncore/net/opieirc/ircquerytab.h index fac976d..ea777f4 100644 --- a/noncore/net/opieirc/ircquerytab.h +++ b/noncore/net/opieirc/ircquerytab.h | |||
@@ -1,24 +1,51 @@ | |||
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 __IRCQUERYTAB_H | 21 | #ifndef __IRCQUERYTAB_H |
22 | #define __IRCQUERYTAB_H | 22 | #define __IRCQUERYTAB_H |
23 | 23 | ||
24 | #include "ircsession.h" | ||
25 | #include "mainwindow.h" | ||
26 | |||
27 | class IRCServerTab; | ||
28 | class IRCQueryTab : public IRCTab { | ||
29 | Q_OBJECT | ||
30 | public: | ||
31 | /* IRCTab implementation */ | ||
32 | IRCQueryTab(IRCPerson *person, IRCServerTab *parentTab, MainWindow *mainWindow, QWidget *parent = 0, const char *name = 0, WFlags f = 0); | ||
33 | ~IRCQueryTab(); | ||
34 | QString title(); | ||
35 | IRCSession *session(); | ||
36 | IRCPerson *person(); | ||
37 | void appendText(QString text); | ||
38 | public slots: | ||
39 | void remove(); | ||
40 | void processCommand(); | ||
41 | void display(IRCOutput output); | ||
42 | protected: | ||
43 | bool m_close; | ||
44 | MainWindow *m_mainWindow; | ||
45 | IRCServerTab *m_parentTab; | ||
46 | IRCPerson *m_person; | ||
47 | QTextView *m_textview; | ||
48 | QLineEdit *m_field; | ||
49 | }; | ||
50 | |||
24 | #endif /* __IRCQUERYTAB_H */ | 51 | #endif /* __IRCQUERYTAB_H */ |
diff --git a/noncore/net/opieirc/ircservertab.cpp b/noncore/net/opieirc/ircservertab.cpp index 503a758..8b8771f 100644 --- a/noncore/net/opieirc/ircservertab.cpp +++ b/noncore/net/opieirc/ircservertab.cpp | |||
@@ -1,195 +1,243 @@ | |||
1 | #include <stdio.h> | 1 | #include <stdio.h> |
2 | #include <qtextstream.h> | 2 | #include <qtextstream.h> |
3 | #include "ircservertab.h" | 3 | #include "ircservertab.h" |
4 | 4 | ||
5 | IRCServerTab::IRCServerTab(IRCServer server, MainWindow *mainWindow, QWidget *parent, const char *name, WFlags f) : IRCTab(parent, name, f) { | 5 | IRCServerTab::IRCServerTab(IRCServer server, MainWindow *mainWindow, QWidget *parent, const char *name, WFlags f) : IRCTab(parent, name, f) { |
6 | m_server = server; | 6 | m_server = server; |
7 | m_session = new IRCSession(&m_server); | 7 | m_session = new IRCSession(&m_server); |
8 | m_mainWindow = mainWindow; | 8 | m_mainWindow = mainWindow; |
9 | m_close = FALSE; | 9 | m_close = FALSE; |
10 | m_description->setText(tr("Connection to")+" <b>" + server.hostname() + ":" + QString::number(server.port()) + "</b>"); | 10 | m_description->setText(tr("Connection to")+" <b>" + server.hostname() + ":" + QString::number(server.port()) + "</b>"); |
11 | m_textview = new QTextView(this); | 11 | m_textview = new QTextView(this); |
12 | m_textview->setHScrollBarMode(QScrollView::AlwaysOff); | 12 | m_textview->setHScrollBarMode(QScrollView::AlwaysOff); |
13 | m_textview->setVScrollBarMode(QScrollView::AlwaysOn); | 13 | m_textview->setVScrollBarMode(QScrollView::AlwaysOn); |
14 | m_textview->setTextFormat(RichText); | ||
14 | m_layout->add(m_textview); | 15 | m_layout->add(m_textview); |
15 | m_field = new QLineEdit(this); | 16 | m_field = new QLineEdit(this); |
16 | m_layout->add(m_field); | 17 | m_layout->add(m_field); |
17 | connect(m_field, SIGNAL(returnPressed()), this, SLOT(processCommand())); | 18 | connect(m_field, SIGNAL(returnPressed()), this, SLOT(processCommand())); |
18 | m_field->setFocus(); | 19 | m_field->setFocus(); |
19 | connect(m_session, SIGNAL(outputReady(IRCOutput)), this, SLOT(display(IRCOutput))); | 20 | connect(m_session, SIGNAL(outputReady(IRCOutput)), this, SLOT(display(IRCOutput))); |
20 | } | 21 | } |
21 | 22 | ||
22 | void IRCServerTab::appendText(QString text) { | 23 | void IRCServerTab::appendText(QString text) { |
23 | /* not using append because it creates layout problems */ | 24 | /* not using append because it creates layout problems */ |
24 | m_textview->setText(m_textview->text() + text); | 25 | m_textview->setText(m_textview->text() + text); |
25 | m_textview->ensureVisible(0, m_textview->contentsHeight()); | 26 | m_textview->ensureVisible(0, m_textview->contentsHeight()); |
26 | } | 27 | } |
27 | 28 | ||
28 | IRCServerTab::~IRCServerTab() { | 29 | IRCServerTab::~IRCServerTab() { |
29 | delete m_session; | 30 | delete m_session; |
30 | } | 31 | } |
31 | 32 | ||
32 | void IRCServerTab::removeChannelTab(IRCChannelTab *tab) { | 33 | void IRCServerTab::removeChannelTab(IRCChannelTab *tab) { |
33 | m_channelTabs.remove(tab); | 34 | m_channelTabs.remove(tab); |
34 | } | 35 | } |
35 | 36 | ||
37 | void IRCServerTab::removeQueryTab(IRCQueryTab *tab) { | ||
38 | m_queryTabs.remove(tab); | ||
39 | } | ||
40 | |||
36 | QString IRCServerTab::title() { | 41 | QString IRCServerTab::title() { |
37 | return "Server"; | 42 | return "Server"; |
38 | } | 43 | } |
39 | 44 | ||
40 | IRCSession *IRCServerTab::session() { | 45 | IRCSession *IRCServerTab::session() { |
41 | return m_session; | 46 | return m_session; |
42 | } | 47 | } |
43 | 48 | ||
44 | IRCServer *IRCServerTab::server() { | 49 | IRCServer *IRCServerTab::server() { |
45 | return &m_server; | 50 | return &m_server; |
46 | } | 51 | } |
47 | 52 | ||
48 | void IRCServerTab::executeCommand(IRCTab *tab, QString line) { | 53 | void IRCServerTab::executeCommand(IRCTab *tab, QString line) { |
49 | QTextIStream stream(&line); | 54 | QTextIStream stream(&line); |
50 | QString command; | 55 | QString command; |
51 | stream >> command; | 56 | stream >> command; |
52 | command = command.upper().right(command.length()-1); | 57 | command = command.upper().right(command.length()-1); |
53 | 58 | ||
54 | if (command == "JOIN") { | 59 | if (command == "JOIN") { |
55 | QString channel; | 60 | QString channel; |
56 | stream >> channel; | 61 | stream >> channel; |
57 | if (channel.length() > 0 && channel.startsWith("#")) { | 62 | if (channel.length() > 0 && channel.startsWith("#")) { |
58 | m_session->join(channel); | 63 | m_session->join(channel); |
59 | } else { | 64 | } else { |
60 | tab->appendText("<font color=\"#ff0000\">Unknown channel format!</font><br>"); | 65 | tab->appendText("<font color=\"#ff0000\">Unknown channel format!</font><br>"); |
61 | } | 66 | } |
62 | } else if (command == "ME") { | 67 | } else if (command == "ME") { |
63 | QString text = IRCOutput::toHTML(line.right(line.length()-4)); | 68 | QString text = line.right(line.length()-4); |
64 | if (text.length() > 0) { | 69 | if (text.length() > 0) { |
65 | if (tab->isA("IRCChannelTab")) { | 70 | if (tab->isA("IRCChannelTab")) { |
66 | tab->appendText("<font color=\"#cc0000\">*" + m_server.nick() + " " + text + "</font><br>"); | 71 | tab->appendText("<font color=\"#cc0000\">*" + IRCOutput::toHTML(m_server.nick()) + " " + IRCOutput::toHTML(text) + "</font><br>"); |
67 | m_session->sendAction(((IRCChannelTab *)tab)->channel(), text); | 72 | m_session->sendAction(((IRCChannelTab *)tab)->channel(), text); |
68 | } else if (tab->isA("IRCQueryTab")) { | 73 | } else if (tab->isA("IRCQueryTab")) { |
74 | tab->appendText("<font color=\"#cc0000\">*" + IRCOutput::toHTML(m_server.nick()) + " " + IRCOutput::toHTML(text) + "</font><br>"); | ||
75 | m_session->sendAction(((IRCQueryTab *)tab)->person(), text); | ||
69 | } else { | 76 | } else { |
70 | tab->appendText("<font color=\"#ff0000\">Invalid tab for this command</font><br>"); | 77 | tab->appendText("<font color=\"#ff0000\">Invalid tab for this command</font><br>"); |
71 | } | 78 | } |
72 | } | 79 | } |
80 | } else if (command == "MSG") { | ||
81 | QString nickname; | ||
82 | stream >> nickname; | ||
83 | if (nickname.length() > 0) { | ||
84 | if (line.length() > 6 + nickname.length()) { | ||
85 | QString text = line.right(line.length()-nickname.length()-6); | ||
86 | IRCPerson person; | ||
87 | person.setNick(nickname); | ||
88 | tab->appendText("><font color=\"#0000dd\">"+IRCOutput::toHTML(nickname)+"</font>< "+IRCOutput::toHTML(text)+"<br>"); | ||
89 | m_session->sendMessage(&person, text); | ||
90 | } | ||
91 | } | ||
73 | } else { | 92 | } else { |
74 | tab->appendText("<font color=\"#ff0000\">Unknown command</font><br>"); | 93 | tab->appendText("<font color=\"#ff0000\">Unknown command</font><br>"); |
75 | } | 94 | } |
76 | } | 95 | } |
77 | 96 | ||
78 | void IRCServerTab::processCommand() { | 97 | void IRCServerTab::processCommand() { |
79 | QString text = m_field->text(); | 98 | QString text = m_field->text(); |
80 | if (text.startsWith("/") && !text.startsWith("//")) { | 99 | if (text.startsWith("/") && !text.startsWith("//")) { |
81 | /* Command mode */ | 100 | /* Command mode */ |
82 | executeCommand(this, text); | 101 | executeCommand(this, text); |
83 | } | 102 | } |
84 | m_field->clear(); | 103 | m_field->clear(); |
85 | } | 104 | } |
86 | 105 | ||
87 | void IRCServerTab::doConnect() { | 106 | void IRCServerTab::doConnect() { |
88 | m_session->beginSession(); | 107 | m_session->beginSession(); |
89 | } | 108 | } |
90 | 109 | ||
91 | void IRCServerTab::remove() { | 110 | void IRCServerTab::remove() { |
92 | /* Close requested */ | 111 | /* Close requested */ |
93 | if (m_session->isSessionActive()) { | 112 | if (m_session->isSessionActive()) { |
94 | /* While there is a running session */ | 113 | /* While there is a running session */ |
95 | m_close = TRUE; | 114 | m_close = TRUE; |
96 | m_session->endSession(); | 115 | m_session->endSession(); |
97 | } else { | 116 | } else { |
98 | /* Session has previously been closed */ | 117 | /* Session has previously been closed */ |
99 | m_channelTabs.first(); | 118 | m_channelTabs.first(); |
100 | while (m_channelTabs.current() != 0) { | 119 | while (m_channelTabs.current() != 0) { |
101 | m_mainWindow->killTab(m_channelTabs.current()); | 120 | m_mainWindow->killTab(m_channelTabs.current()); |
102 | } | 121 | } |
122 | m_queryTabs.first(); | ||
123 | while (m_queryTabs.current() != 0) { | ||
124 | m_mainWindow->killTab(m_queryTabs.current()); | ||
125 | } | ||
103 | m_mainWindow->killTab(this); | 126 | m_mainWindow->killTab(this); |
104 | } | 127 | } |
105 | } | 128 | } |
106 | 129 | ||
107 | IRCChannelTab *IRCServerTab::getTabForChannel(IRCChannel *channel) { | 130 | IRCChannelTab *IRCServerTab::getTabForChannel(IRCChannel *channel) { |
108 | QListIterator<IRCChannelTab> it(m_channelTabs); | 131 | QListIterator<IRCChannelTab> it(m_channelTabs); |
109 | 132 | ||
110 | for (; it.current(); ++it) { | 133 | for (; it.current(); ++it) { |
111 | if (it.current()->channel() == channel) | 134 | if (it.current()->channel() == channel) |
112 | return it.current(); | 135 | return it.current(); |
113 | } | 136 | } |
114 | return 0; | 137 | return 0; |
115 | } | 138 | } |
116 | 139 | ||
140 | IRCQueryTab *IRCServerTab::getTabForQuery(IRCPerson *person) { | ||
141 | QListIterator<IRCQueryTab> it(m_queryTabs); | ||
142 | |||
143 | for (; it.current(); ++it) { | ||
144 | if (it.current()->person()->nick() == person->nick()) | ||
145 | return it.current(); | ||
146 | } | ||
147 | return 0; | ||
148 | } | ||
149 | |||
117 | void IRCServerTab::display(IRCOutput output) { | 150 | void IRCServerTab::display(IRCOutput output) { |
118 | 151 | ||
119 | /* All messages to be displayed inside the GUI get here */ | 152 | /* All messages to be displayed inside the GUI get here */ |
120 | switch (output.type()) { | 153 | switch (output.type()) { |
121 | case OUTPUT_CONNCLOSE: | 154 | case OUTPUT_CONNCLOSE: |
122 | if (m_close) { | 155 | if (m_close) { |
123 | m_channelTabs.first(); | 156 | m_channelTabs.first(); |
124 | while (m_channelTabs.current() != 0) { | 157 | while (m_channelTabs.current() != 0) { |
125 | m_mainWindow->killTab(m_channelTabs.current()); | 158 | m_mainWindow->killTab(m_channelTabs.current()); |
126 | } | 159 | } |
160 | m_queryTabs.first(); | ||
161 | while (m_queryTabs.current() != 0) { | ||
162 | m_mainWindow->killTab(m_queryTabs.current()); | ||
163 | } | ||
127 | m_mainWindow->killTab(this); | 164 | m_mainWindow->killTab(this); |
128 | } else { | 165 | } else { |
129 | appendText("<font color=\"#0000dd\">" + output.htmlMessage() +"</font><br>"); | 166 | appendText("<font color=\"#0000dd\">" + output.htmlMessage() +"</font><br>"); |
130 | QListIterator<IRCChannelTab> it(m_channelTabs); | 167 | QListIterator<IRCChannelTab> it(m_channelTabs); |
131 | for (; it.current(); ++it) { | 168 | for (; it.current(); ++it) { |
132 | it.current()->appendText("<font color=\"#0000dd\">" + output.htmlMessage() +"</font><br>"); | 169 | it.current()->appendText("<font color=\"#0000dd\">" + output.htmlMessage() +"</font><br>"); |
133 | } | 170 | } |
134 | } | 171 | } |
135 | break; | 172 | break; |
136 | case OUTPUT_SELFJOIN: { | 173 | case OUTPUT_SELFJOIN: { |
137 | IRCChannelTab *channeltab = new IRCChannelTab((IRCChannel *)output.getParam(0), this, m_mainWindow, (QWidget *)parent()); | 174 | IRCChannelTab *channeltab = new IRCChannelTab((IRCChannel *)output.getParam(0), this, m_mainWindow, (QWidget *)parent()); |
138 | m_channelTabs.append(channeltab); | 175 | m_channelTabs.append(channeltab); |
139 | m_mainWindow->addTab(channeltab); | 176 | m_mainWindow->addTab(channeltab); |
140 | } | 177 | } |
141 | break; | 178 | break; |
142 | case OUTPUT_CHANPRIVMSG: { | 179 | case OUTPUT_CHANPRIVMSG: { |
143 | IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0)); | 180 | IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0)); |
144 | channelTab->appendText("<<font color=\"#0000dd\">"+((IRCChannelPerson *)output.getParam(1))->person->nick()+"</font>> "+output.htmlMessage()+"<br>"); | 181 | channelTab->appendText("<<font color=\"#0000dd\">"+IRCOutput::toHTML(((IRCChannelPerson *)output.getParam(1))->person->nick())+"</font>> "+output.htmlMessage()+"<br>"); |
182 | } | ||
183 | break; | ||
184 | case OUTPUT_QUERYACTION: | ||
185 | case OUTPUT_QUERYPRIVMSG: { | ||
186 | IRCQueryTab *queryTab = getTabForQuery((IRCPerson *)output.getParam(0)); | ||
187 | if (!queryTab) { | ||
188 | queryTab = new IRCQueryTab((IRCPerson *)output.getParam(0), this, m_mainWindow, (QWidget *)parent()); | ||
189 | m_queryTabs.append(queryTab); | ||
190 | m_mainWindow->addTab(queryTab); | ||
191 | } | ||
192 | queryTab->display(output); | ||
145 | } | 193 | } |
146 | break; | 194 | break; |
147 | case OUTPUT_SELFPART: { | 195 | case OUTPUT_SELFPART: { |
148 | IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0)); | 196 | IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0)); |
149 | if (channelTab) | 197 | if (channelTab) |
150 | m_mainWindow->killTab(channelTab); | 198 | m_mainWindow->killTab(channelTab); |
151 | } | 199 | } |
152 | break; | 200 | break; |
153 | case OUTPUT_SELFKICK: { | 201 | case OUTPUT_SELFKICK: { |
154 | appendText("<font color=\"#ff0000\">" + output.htmlMessage() + "</font><br>"); | 202 | appendText("<font color=\"#ff0000\">" + output.htmlMessage() + "</font><br>"); |
155 | IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0)); | 203 | IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0)); |
156 | if (channelTab) | 204 | if (channelTab) |
157 | m_mainWindow->killTab(channelTab); | 205 | m_mainWindow->killTab(channelTab); |
158 | } | 206 | } |
159 | break; | 207 | break; |
160 | case OUTPUT_CHANACTION: { | 208 | case OUTPUT_CHANACTION: { |
161 | IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0)); | 209 | IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0)); |
162 | channelTab->appendText("<font color=\"#cc0000\">"+output.htmlMessage()+"</font><br>"); | 210 | channelTab->appendText("<font color=\"#cc0000\">"+output.htmlMessage()+"</font><br>"); |
163 | } | 211 | } |
164 | break; | 212 | break; |
165 | case OUTPUT_QUIT: { | 213 | case OUTPUT_QUIT: { |
166 | QString nick = ((IRCPerson *)output.getParam(0))->nick(); | 214 | QString nick = ((IRCPerson *)output.getParam(0))->nick(); |
167 | QListIterator<IRCChannelTab> it(m_channelTabs); | 215 | QListIterator<IRCChannelTab> it(m_channelTabs); |
168 | for (; it.current(); ++it) { | 216 | for (; it.current(); ++it) { |
169 | if (it.current()->list()->hasPerson(nick)) { | 217 | if (it.current()->list()->hasPerson(nick)) { |
170 | it.current()->appendText("<font color=\"#aa3e00\">"+output.htmlMessage()+"</font><br>"); | 218 | it.current()->appendText("<font color=\"#aa3e00\">"+output.htmlMessage()+"</font><br>"); |
171 | it.current()->list()->update(); | 219 | it.current()->list()->update(); |
172 | } | 220 | } |
173 | } | 221 | } |
174 | } | 222 | } |
175 | break; | 223 | break; |
176 | case OUTPUT_OTHERJOIN: | 224 | case OUTPUT_OTHERJOIN: |
177 | case OUTPUT_OTHERKICK: | 225 | case OUTPUT_OTHERKICK: |
178 | case OUTPUT_CHANPERSONMODE: | 226 | case OUTPUT_CHANPERSONMODE: |
179 | case OUTPUT_OTHERPART: { | 227 | case OUTPUT_OTHERPART: { |
180 | IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0)); | 228 | IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0)); |
181 | channelTab->appendText("<font color=\"#aa3e00\">"+output.htmlMessage()+"</font><br>"); | 229 | channelTab->appendText("<font color=\"#aa3e00\">"+output.htmlMessage()+"</font><br>"); |
182 | channelTab->list()->update(); | 230 | channelTab->list()->update(); |
183 | } | 231 | } |
184 | break; | 232 | break; |
185 | case OUTPUT_CTCP: | 233 | case OUTPUT_CTCP: |
186 | appendText("<font color=\"#00bb00\">" + output.htmlMessage() + "</font><br>"); | 234 | appendText("<font color=\"#00bb00\">" + output.htmlMessage() + "</font><br>"); |
187 | break; | 235 | break; |
188 | case OUTPUT_ERROR: | 236 | case OUTPUT_ERROR: |
189 | appendText("<font color=\"#ff0000\">" + output.htmlMessage() + "</font><br>"); | 237 | appendText("<font color=\"#ff0000\">" + output.htmlMessage() + "</font><br>"); |
190 | break; | 238 | break; |
191 | default: | 239 | default: |
192 | appendText("<font color=\"#0000dd\">" + output.htmlMessage() + "</font><br>"); | 240 | appendText("<font color=\"#0000dd\">" + output.htmlMessage() + "</font><br>"); |
193 | break; | 241 | break; |
194 | } | 242 | } |
195 | } | 243 | } |
diff --git a/noncore/net/opieirc/ircservertab.h b/noncore/net/opieirc/ircservertab.h index cfa0832..e439d84 100644 --- a/noncore/net/opieirc/ircservertab.h +++ b/noncore/net/opieirc/ircservertab.h | |||
@@ -1,63 +1,70 @@ | |||
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 __IRCSERVERTAB_H | 21 | #ifndef __IRCSERVERTAB_H |
22 | #define __IRCSERVERTAB_H | 22 | #define __IRCSERVERTAB_H |
23 | 23 | ||
24 | #include "irctab.h" | 24 | #include "irctab.h" |
25 | #include "ircsession.h" | 25 | #include "ircsession.h" |
26 | #include "mainwindow.h" | 26 | #include "mainwindow.h" |
27 | #include "ircchanneltab.h" | 27 | #include "ircchanneltab.h" |
28 | #include "ircquerytab.h" | ||
28 | 29 | ||
29 | class IRCServerTab : public IRCTab { | 30 | class IRCServerTab : public IRCTab { |
30 | Q_OBJECT | 31 | Q_OBJECT |
31 | public: | 32 | public: |
32 | /* IRCTab implementation */ | 33 | /* IRCTab implementation */ |
33 | IRCServerTab(IRCServer server, MainWindow *mainWindow, QWidget *parent = 0, const char *name = 0, WFlags f = 0); | 34 | IRCServerTab(IRCServer server, MainWindow *mainWindow, QWidget *parent = 0, const char *name = 0, WFlags f = 0); |
34 | ~IRCServerTab(); | 35 | ~IRCServerTab(); |
35 | QString title(); | 36 | QString title(); |
36 | IRCSession *session(); | 37 | IRCSession *session(); |
37 | IRCServer *server(); | 38 | IRCServer *server(); |
38 | 39 | ||
39 | /* Start the server session */ | 40 | /* Start the server session */ |
40 | void doConnect(); | 41 | void doConnect(); |
42 | /* Remove tabs from the internal tab lists */ | ||
41 | void removeChannelTab(IRCChannelTab *tab); | 43 | void removeChannelTab(IRCChannelTab *tab); |
44 | void removeQueryTab(IRCQueryTab *tab); | ||
42 | 45 | ||
43 | /* Execute a user command such as /join */ | 46 | /* Execute a user command such as /join */ |
44 | void executeCommand(IRCTab *tab, QString line); | 47 | void executeCommand(IRCTab *tab, QString line); |
45 | protected: | 48 | protected: |
46 | void appendText(QString text); | 49 | void appendText(QString text); |
47 | IRCChannelTab *getTabForChannel(IRCChannel *channel); | 50 | IRCChannelTab *getTabForChannel(IRCChannel *channel); |
51 | IRCQueryTab *getTabForQuery(IRCPerson *person); | ||
48 | public slots: | 52 | public slots: |
49 | void remove(); | 53 | void remove(); |
50 | void processCommand(); | 54 | void processCommand(); |
51 | protected slots: | 55 | protected slots: |
52 | void display(IRCOutput output); | 56 | void display(IRCOutput output); |
53 | protected: | 57 | protected: |
54 | bool m_close; | 58 | bool m_close; |
55 | IRCServer m_server; | 59 | IRCServer m_server; |
56 | IRCSession *m_session; | 60 | IRCSession *m_session; |
57 | MainWindow *m_mainWindow; | 61 | MainWindow *m_mainWindow; |
58 | QTextView *m_textview; | 62 | QTextView *m_textview; |
59 | QLineEdit *m_field; | 63 | QLineEdit *m_field; |
64 | /* Channel tabs associated with this server tab */ | ||
60 | QList<IRCChannelTab> m_channelTabs; | 65 | QList<IRCChannelTab> m_channelTabs; |
66 | /* Query tabs associated with this server tab */ | ||
67 | QList<IRCQueryTab> m_queryTabs; | ||
61 | }; | 68 | }; |
62 | 69 | ||
63 | #endif /* __IRCSERVERTAB_H */ | 70 | #endif /* __IRCSERVERTAB_H */ |