summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/opieirc/ircchannel.cpp3
-rw-r--r--noncore/net/opieirc/ircchannel.h15
-rw-r--r--noncore/net/opieirc/ircchannellist.cpp16
-rw-r--r--noncore/net/opieirc/ircchannelperson.cpp62
-rw-r--r--noncore/net/opieirc/ircchannelperson.h34
-rw-r--r--noncore/net/opieirc/ircchanneltab.cpp18
-rw-r--r--noncore/net/opieirc/ircconnection.cpp24
-rw-r--r--noncore/net/opieirc/ircconnection.h6
-rw-r--r--noncore/net/opieirc/ircmessageparser.cpp132
-rw-r--r--noncore/net/opieirc/ircmessageparser.h2
-rw-r--r--noncore/net/opieirc/ircservertab.cpp3
-rw-r--r--noncore/net/opieirc/ircsession.cpp20
-rw-r--r--noncore/net/opieirc/ircsession.h4
-rw-r--r--noncore/net/opieirc/mainwindow.cpp4
-rw-r--r--noncore/net/opieirc/opieirc.pro6
15 files changed, 258 insertions, 91 deletions
diff --git a/noncore/net/opieirc/ircchannel.cpp b/noncore/net/opieirc/ircchannel.cpp
index 5c380e5..5d81596 100644
--- a/noncore/net/opieirc/ircchannel.cpp
+++ b/noncore/net/opieirc/ircchannel.cpp
@@ -1,9 +1,10 @@
1#include "ircchannel.h" 1#include "ircchannel.h"
2#include "ircchannelperson.h"
2 3
3IRCChannel::IRCChannel(QString channelname) { 4IRCChannel::IRCChannel(QString channelname) {
4 m_hasPeople = FALSE; 5 m_hasPeople = FALSE;
5 m_channelname = channelname; 6 m_channelname = channelname;
6} 7}
7 8
8IRCChannel::~IRCChannel() { 9IRCChannel::~IRCChannel() {
9 /* We want this to get deleted */ 10 /* We want this to get deleted */
@@ -33,15 +34,15 @@ void IRCChannel::removePerson(IRCChannelPerson *person) {
33QListIterator<IRCChannelPerson> IRCChannel::people() { 34QListIterator<IRCChannelPerson> IRCChannel::people() {
34 QListIterator<IRCChannelPerson> it(m_people); 35 QListIterator<IRCChannelPerson> it(m_people);
35 return it; 36 return it;
36} 37}
37 38
38IRCChannelPerson *IRCChannel::getPerson(QString nickname) { 39IRCChannelPerson *IRCChannel::getPerson(QString nickname) {
39 QListIterator<IRCChannelPerson> it(m_people); 40 QListIterator<IRCChannelPerson> it(m_people);
40 for (; it.current(); ++it) { 41 for (; it.current(); ++it) {
41 if (it.current()->person->nick() == nickname) { 42 if (it.current()->nick() == nickname) {
42 return it.current(); 43 return it.current();
43 } 44 }
44 } 45 }
45 return 0; 46 return 0;
46} 47}
47 48
diff --git a/noncore/net/opieirc/ircchannel.h b/noncore/net/opieirc/ircchannel.h
index e78f182..a276f10 100644
--- a/noncore/net/opieirc/ircchannel.h
+++ b/noncore/net/opieirc/ircchannel.h
@@ -19,31 +19,20 @@
19*/ 19*/
20 20
21#ifndef __IRCCHANNEL_H 21#ifndef __IRCCHANNEL_H
22#define __IRCCHANNEL_H 22#define __IRCCHANNEL_H
23 23
24#include <qobject.h> 24#include <qobject.h>
25#include <qlist.h> 25#include <qlist.h>
26#include <qstring.h> 26#include <qstring.h>
27#include "ircperson.h"
28 27
29/* Flags which a person can have inside a channel */ 28#include "ircperson.h"
30enum IRCChannelPersonFlag {
31 PERSON_FLAG_OP = 0x01,
32 PERSON_FLAG_VOICE = 0x02,
33 PERSON_FLAG_HALFOP = 0x04
34};
35 29
36/* This struct encapsulates a IRCPerson and adds 30class IRCChannelPerson;
37 channel specific information */
38typedef struct IRCChannelPerson {
39 IRCPerson *person;
40 unsigned int flags;
41};
42 31
43/* IRCChannel is the object-oriented representation 32/* IRCChannel is the object-oriented representation
44 of an IRC channel. It basically acts as a container 33 of an IRC channel. It basically acts as a container
45 for IRCChannelPersons */ 34 for IRCChannelPersons */
46class IRCChannel : public QObject { 35class IRCChannel : public QObject {
47 Q_OBJECT 36 Q_OBJECT
48public: 37public:
49 IRCChannel(QString channelname); 38 IRCChannel(QString channelname);
diff --git a/noncore/net/opieirc/ircchannellist.cpp b/noncore/net/opieirc/ircchannellist.cpp
index c32c535..8cf144e 100644
--- a/noncore/net/opieirc/ircchannellist.cpp
+++ b/noncore/net/opieirc/ircchannellist.cpp
@@ -1,31 +1,33 @@
1#include <qpe/resource.h> 1#include <qpe/resource.h>
2
2#include "ircchannellist.h" 3#include "ircchannellist.h"
4#include "ircchannelperson.h"
3 5
4IRCChannelList::IRCChannelList(IRCChannel *channel, QWidget *parent, const char *name, WFlags f) : QListBox(parent, name, f) { 6IRCChannelList::IRCChannelList(IRCChannel *channel, QWidget *parent, const char *name, WFlags f) : QListBox(parent, name, f) {
5 m_channel = channel; 7 m_channel = channel;
6} 8}
7 9
8void IRCChannelList::update() { 10void IRCChannelList::update() {
9 QPixmap op = Resource::loadPixmap("opieirc/op"); 11 QPixmap op = Resource::loadPixmap("opieirc/op");
10 QPixmap hop = Resource::loadPixmap("opieirc/hop"); 12 QPixmap hop = Resource::loadPixmap("opieirc/hop");
11 QPixmap voice = Resource::loadPixmap("opieirc/voice"); 13 QPixmap voice = Resource::loadPixmap("opieirc/voice");
12 QListIterator<IRCChannelPerson> it = m_channel->people(); 14 QListIterator<IRCChannelPerson> it = m_channel->people();
13 clear(); 15 clear();
14 for (; it.current(); ++it) { 16 for (; it.current(); ++it) {
15 IRCChannelPerson *person = it.current(); 17 IRCChannelPerson *person = it.current();
16 if (person->flags & PERSON_FLAG_OP) { 18 if (person->flags() & IRCChannelPerson::PERSON_FLAG_OP) {
17 insertItem(op, "1" + person->person->nick()); 19 insertItem(op, "1" + person->nick());
18 } else if (person->flags & PERSON_FLAG_HALFOP) { 20 } else if (person->flags() & IRCChannelPerson::PERSON_FLAG_HALFOP) {
19 insertItem(op, "2" + person->person->nick()); 21 insertItem(op, "2" + person->nick());
20 } else if (person->flags & PERSON_FLAG_VOICE) { 22 } else if (person->flags() & IRCChannelPerson::PERSON_FLAG_VOICE) {
21 insertItem(voice, "3" + person->person->nick()); 23 insertItem(voice, "3" + person->nick());
22 } else { 24 } else {
23 insertItem("4" + person->person->nick()); 25 insertItem("4" + person->nick());
24 } 26 }
25 } 27 }
26 sort(); 28 sort();
27 adjustNicks(); 29 adjustNicks();
28} 30}
29 31
30 32
31bool IRCChannelList::hasPerson(QString nick) { 33bool IRCChannelList::hasPerson(QString nick) {
diff --git a/noncore/net/opieirc/ircchannelperson.cpp b/noncore/net/opieirc/ircchannelperson.cpp
new file mode 100644
index 0000000..1e8ebe4
--- a/dev/null
+++ b/noncore/net/opieirc/ircchannelperson.cpp
@@ -0,0 +1,62 @@
1#include "ircperson.h"
2#include "ircchannelperson.h"
3
4#include <qstring.h>
5#include <qobject.h>
6
7IRCChannelPerson::IRCChannelPerson(IRCPerson *person)
8{
9 m_person = person;
10 m_flags = 0;
11}
12
13IRCChannelPerson::~IRCChannelPerson()
14{
15 //if(m_person)
16 // delete m_person;
17}
18
19QString IRCChannelPerson::setOp(const QString &nickname, bool set)
20{
21 if(set) {
22 m_flags |= PERSON_FLAG_OP;
23 return ( nickname + QObject::tr(" gives channel operator status to ") + nick());
24 }
25
26 m_flags &= 0xFFFF - PERSON_FLAG_OP;
27 return ( nickname + QObject::tr(" removes channel operator status from ") + nick());
28}
29
30QString IRCChannelPerson::setVoice(const QString &nickname, bool set)
31{
32 if(set) {
33 m_flags |= PERSON_FLAG_VOICE;
34 return ( nickname + QObject::tr(" gives voice to ") + nick() );
35 }
36
37 m_flags &= 0xFFFF - PERSON_FLAG_VOICE;
38 return ( nickname + QObject::tr(" removes voice from ") + nick());
39}
40
41QString IRCChannelPerson::nick()
42{
43 if(m_person)
44 return m_person->nick();
45
46 return QString::null;
47}
48
49void IRCChannelPerson::setFlags(int flags)
50{
51 m_flags = flags;
52}
53
54void IRCChannelPerson::setNick(const QString &nickname)
55{
56 m_person->setNick(nickname);
57}
58
59const unsigned int IRCChannelPerson::flags()
60{
61 return m_flags;
62}
diff --git a/noncore/net/opieirc/ircchannelperson.h b/noncore/net/opieirc/ircchannelperson.h
new file mode 100644
index 0000000..a8c4791
--- a/dev/null
+++ b/noncore/net/opieirc/ircchannelperson.h
@@ -0,0 +1,34 @@
1#ifndef IRCCHANNELPERSON_H
2#define IRCCHANNELPERSON_H
3
4class QString;
5class IRCPerson;
6
7/* This class encapsulates a IRCPerson and adds
8 * channel specific information */
9class IRCChannelPerson {
10
11public:
12 /* Flags which a person can have inside a channel */
13 enum IRCChannelPersonFlag {
14 PERSON_FLAG_OP = 0x01,
15 PERSON_FLAG_VOICE = 0x02,
16 PERSON_FLAG_HALFOP = 0x04
17 };
18
19 IRCChannelPerson(IRCPerson *person = 0);
20 ~IRCChannelPerson();
21
22 QString setOp(const QString &nickname, bool set);
23 QString setVoice(const QString &nickname, bool set);
24 QString nick();
25 const unsigned int flags();
26 void setFlags(int flags);
27 void setNick(const QString &nickname);
28
29protected:
30 IRCPerson *m_person;
31 unsigned int m_flags;
32};
33
34#endif
diff --git a/noncore/net/opieirc/ircchanneltab.cpp b/noncore/net/opieirc/ircchanneltab.cpp
index 4a35929..3272a8a 100644
--- a/noncore/net/opieirc/ircchanneltab.cpp
+++ b/noncore/net/opieirc/ircchanneltab.cpp
@@ -2,16 +2,17 @@
2#include <qwhatsthis.h> 2#include <qwhatsthis.h>
3#include <qhbox.h> 3#include <qhbox.h>
4#include <qdict.h> 4#include <qdict.h>
5 5
6#include "ircchanneltab.h" 6#include "ircchanneltab.h"
7#include "ircservertab.h" 7#include "ircservertab.h"
8#include "ircmessageparser.h" 8#include "ircmessageparser.h"
9 9
10#include <opie2/odebug.h>
10QDict<QString> IRCChannelTab::m_queuedMessages (17); 11QDict<QString> IRCChannelTab::m_queuedMessages (17);
11 12
12IRCChannelTab::IRCChannelTab(IRCChannel *channel, IRCServerTab *parentTab, MainWindow *mainWindow, QWidget *parent, const char *name, WFlags f) : IRCTab(parent, name, f) { 13IRCChannelTab::IRCChannelTab(IRCChannel *channel, IRCServerTab *parentTab, MainWindow *mainWindow, QWidget *parent, const char *name, WFlags f) : IRCTab(parent, name, f) {
13 m_mainWindow = mainWindow; 14 m_mainWindow = mainWindow;
14 m_parentTab = parentTab; 15 m_parentTab = parentTab;
15 m_channel = channel; 16 m_channel = channel;
16 m_description->setText(tr("Talking on channel") + " <b>" + channel->channelname() + "</b>"); 17 m_description->setText(tr("Talking on channel") + " <b>" + channel->channelname() + "</b>");
17 QHBox *hbox = new QHBox(this); 18 QHBox *hbox = new QHBox(this);
@@ -36,21 +37,23 @@ IRCChannelTab::IRCChannelTab(IRCChannel *channel, IRCServerTab *parentTab, MainW
36 37
37 QWhatsThis::add(m_field, tr("Type your message here to participate in the channel discussion")); 38 QWhatsThis::add(m_field, tr("Type your message here to participate in the channel discussion"));
38 m_popup = new QPopupMenu(m_list); 39 m_popup = new QPopupMenu(m_list);
39 m_lines = 0; 40 m_lines = 0;
40 /* Required so that embedded-style "right" clicks work */ 41 /* Required so that embedded-style "right" clicks work */
41 QPEApplication::setStylusOperation(m_list->viewport(), QPEApplication::RightOnHold); 42 QPEApplication::setStylusOperation(m_list->viewport(), QPEApplication::RightOnHold);
42 connect(m_list, SIGNAL(mouseButtonPressed(int,QListBoxItem*,const QPoint&)), this, SLOT(mouseButtonPressed(int,QListBoxItem*,const QPoint&))); 43 connect(m_list, SIGNAL(mouseButtonPressed(int,QListBoxItem*,const QPoint&)), this, SLOT(mouseButtonPressed(int,QListBoxItem*,const QPoint&)));
43 /* Construct the popup menu */ 44 /* Construct the popup menu */
44 QPopupMenu *ctcpMenu = new QPopupMenu(m_list); 45 //QPopupMenu *ctcpMenu = new QPopupMenu(m_list);
45 m_popup->insertItem(Resource::loadPixmap("opieirc/query"), tr("Query"), this, SLOT(popupQuery())); 46 m_popup->insertItem(Resource::loadPixmap("opieirc/query"), tr("Query"), this, SLOT(popupQuery()));
46 ctcpMenu->insertItem(Resource::loadPixmap("opieirc/ping"), tr("Ping"), this, SLOT(popupPing())); 47 m_popup->insertSeparator();
47 ctcpMenu->insertItem(Resource::loadPixmap("opieirc/version"), tr("Version"), this, SLOT(popupVersion())); 48 m_popup->insertItem(Resource::loadPixmap("opieirc/ping"), tr("Ping"), this, SLOT(popupPing()));
48 ctcpMenu->insertItem(Resource::loadPixmap("opieirc/whois"), tr("Whois"), this, SLOT(popupWhois())); 49 m_popup->insertItem(Resource::loadPixmap("opieirc/version"), tr("Version"), this, SLOT(popupVersion()));
50 m_popup->insertItem(Resource::loadPixmap("opieirc/whois"), tr("Whois"), this, SLOT(popupWhois()));
51 //m_popup->insertItem(ctcpMenu, "CTCP");
49 connect(m_mainWindow, SIGNAL(updateScroll()), this, SLOT(scrolling())); 52 connect(m_mainWindow, SIGNAL(updateScroll()), this, SLOT(scrolling()));
50 m_layout->add(hbox); 53 m_layout->add(hbox);
51 hbox->show(); 54 hbox->show();
52 m_layout->add(m_field); 55 m_layout->add(m_field);
53 m_field->setFocus(); 56 m_field->setFocus();
54 m_field->setActiveWindow(); 57 m_field->setActiveWindow();
55 58
56 connect(m_field, SIGNAL(returnPressed()), this, SLOT(processCommand())); 59 connect(m_field, SIGNAL(returnPressed()), this, SLOT(processCommand()));
@@ -161,23 +164,28 @@ void IRCChannelTab::popupQuery( QListBoxItem *item) {
161} 164}
162 165
163void IRCChannelTab::popupQuery() { 166void IRCChannelTab::popupQuery() {
164 if ( m_list->currentItem() != -1 ) 167 if ( m_list->currentItem() != -1 )
165 popupQuery( m_list->item(m_list->currentItem())); 168 popupQuery( m_list->item(m_list->currentItem()));
166} 169}
167 170
168void IRCChannelTab::popupPing() { 171void IRCChannelTab::popupPing() {
169 //HAHA, no wonder these don't work 172 if(m_list->currentItem() != -1)
173 m_parentTab->session()->sendCTCPPing(m_list->text(m_list->currentItem()));
170} 174}
171 175
172void IRCChannelTab::popupVersion() { 176void IRCChannelTab::popupVersion() {
177 if(m_list->currentItem() != -1)
178 m_parentTab->session()->sendCTCPRequest(m_list->text(m_list->currentItem()), "VERSION", "");
173} 179}
174 180
175void IRCChannelTab::popupWhois() { 181void IRCChannelTab::popupWhois() {
182 if(m_list->currentItem() != -1)
183 m_parentTab->session()->whois(m_list->text(m_list->currentItem()));
176} 184}
177 185
178QString IRCChannelTab::title() { 186QString IRCChannelTab::title() {
179 return m_channel->channelname(); 187 return m_channel->channelname();
180} 188}
181 189
182IRCSession *IRCChannelTab::session() { 190IRCSession *IRCChannelTab::session() {
183 return m_parentTab->session(); 191 return m_parentTab->session();
diff --git a/noncore/net/opieirc/ircconnection.cpp b/noncore/net/opieirc/ircconnection.cpp
index 2325cca..88e63f7 100644
--- a/noncore/net/opieirc/ircconnection.cpp
+++ b/noncore/net/opieirc/ircconnection.cpp
@@ -1,10 +1,14 @@
1#include <unistd.h> 1#include <unistd.h>
2#include <string.h> 2#include <string.h>
3
4#include <qstringlist.h>
5#include <qdatetime.h>
6
3#include "ircconnection.h" 7#include "ircconnection.h"
4 8
5IRCConnection::IRCConnection(IRCServer *server) { 9IRCConnection::IRCConnection(IRCServer *server) {
6 m_server = server; 10 m_server = server;
7 m_socket = new QSocket(this); 11 m_socket = new QSocket(this);
8 m_connected = FALSE; 12 m_connected = FALSE;
9 m_loggedIn = FALSE; 13 m_loggedIn = FALSE;
10 connect(m_socket, SIGNAL(connected()), this, SLOT(login())); 14 connect(m_socket, SIGNAL(connected()), this, SLOT(login()));
@@ -23,18 +27,33 @@ void IRCConnection::doConnect() {
23/* Send commands to the IRC server */ 27/* Send commands to the IRC server */
24void IRCConnection::sendLine(QString line) { 28void IRCConnection::sendLine(QString line) {
25 while((line.right(1) == "\n") || (line.right(1) == "\r")) 29 while((line.right(1) == "\n") || (line.right(1) == "\r"))
26 line = line.left(line.length() - 1); 30 line = line.left(line.length() - 1);
27 line.append("\r\n"); 31 line.append("\r\n");
28 m_socket->writeBlock(line, line.length()); 32 m_socket->writeBlock(line, line.length());
29} 33}
30 34
31void IRCConnection::sendCTCP(QString nick, QString line) { 35void IRCConnection::sendCTCPReply(const QString &nickname, const QString &type, const QString &args) {
32 sendLine("NOTICE " + nick + " :\001"+line+"\001"); 36 sendLine("NOTICE " + nickname + " :\001" + type + " " + args + "\001");
37}
38
39void IRCConnection::sendCTCPRequest(const QString &nickname, const QString &type, const QString &args) {
40 sendLine("PRIVMSG " + nickname + " :\001" + type + " " + args + "\001");
41}
42
43void IRCConnection::sendCTCPPing(const QString &nickname) {
44 QDateTime tm;
45 tm.setTime_t(0);
46 QString strtime = QString::number(tm.secsTo(QDateTime::currentDateTime()));
47 sendCTCPRequest(nickname, "PING", strtime);
48}
49
50void IRCConnection::whois(const QString &nickname) {
51 sendLine("WHOIS " + nickname);
33} 52}
34 53
35/* 54/*
36 * login() is called right after the connection 55 * login() is called right after the connection
37 * to the IRC server has been established 56 * to the IRC server has been established
38 */ 57 */
39void IRCConnection::login() { 58void IRCConnection::login() {
40 char hostname[256]; 59 char hostname[256];
@@ -95,8 +114,9 @@ bool IRCConnection::isLoggedIn() {
95} 114}
96 115
97void IRCConnection::close() { 116void IRCConnection::close() {
98 m_socket->close(); 117 m_socket->close();
99 if (m_socket->state()==QSocket::Idle) { 118 if (m_socket->state()==QSocket::Idle) {
100 disconnect(); 119 disconnect();
101 } 120 }
102} 121}
122
diff --git a/noncore/net/opieirc/ircconnection.h b/noncore/net/opieirc/ircconnection.h
index 75cdf6d..382b1c0 100644
--- a/noncore/net/opieirc/ircconnection.h
+++ b/noncore/net/opieirc/ircconnection.h
@@ -32,17 +32,21 @@
32class IRCConnection : public QObject { 32class IRCConnection : public QObject {
33 Q_OBJECT 33 Q_OBJECT
34public: 34public:
35 IRCConnection(IRCServer *server); 35 IRCConnection(IRCServer *server);
36 void doConnect(); 36 void doConnect();
37 /* used to send commands to the IRC server */ 37 /* used to send commands to the IRC server */
38 void sendLine(QString line); 38 void sendLine(QString line);
39 /* used to send CTCP commands to the IRC server */ 39 /* used to send CTCP commands to the IRC server */
40 void sendCTCP(QString nick, QString line); 40 void sendCTCPReply(const QString &nickname, const QString &type, const QString &args);
41 void sendCTCPRequest(const QString &nickname, const QString &type, const QString &args);
42 void sendCTCPPing(const QString &nickname);
43 void whois(const QString &nickname);
44 void sendCTCPping(const QString &nickname);
41 void close(); 45 void close();
42 bool isConnected(); 46 bool isConnected();
43 bool isLoggedIn(); 47 bool isLoggedIn();
44signals: 48signals:
45 /* triggered when the server sent us a message */ 49 /* triggered when the server sent us a message */
46 void messageArrived(IRCMessage *message); 50 void messageArrived(IRCMessage *message);
47 /* Used to send commands to the UI (such as displaying text etc) */ 51 /* Used to send commands to the UI (such as displaying text etc) */
48 void outputReady(IRCOutput output); 52 void outputReady(IRCOutput output);
diff --git a/noncore/net/opieirc/ircmessageparser.cpp b/noncore/net/opieirc/ircmessageparser.cpp
index cfad2c1..9c1492c 100644
--- a/noncore/net/opieirc/ircmessageparser.cpp
+++ b/noncore/net/opieirc/ircmessageparser.cpp
@@ -1,13 +1,15 @@
1#include <qtextstream.h> 1#include <qtextstream.h>
2#include <qdatetime.h> 2#include <qdatetime.h>
3 3
4#include "ircmessageparser.h" 4#include "ircmessageparser.h"
5#include "ircversion.h" 5#include "ircversion.h"
6#include "ircchannelperson.h"
7//#include "transferreceiver.h"
6 8
7/* Lookup table for literal commands */ 9/* Lookup table for literal commands */
8IRCLiteralMessageParserStruct IRCMessageParser::literalParserProcTable[] = { 10IRCLiteralMessageParserStruct IRCMessageParser::literalParserProcTable[] = {
9 { "PING", FUNC(parseLiteralPing) }, 11 { "PING", FUNC(parseLiteralPing) },
10 { "NOTICE", FUNC(parseLiteralNotice) }, 12 { "NOTICE", FUNC(parseLiteralNotice) },
11 { "JOIN", FUNC(parseLiteralJoin) }, 13 { "JOIN", FUNC(parseLiteralJoin) },
12 { "PRIVMSG", FUNC(parseLiteralPrivMsg) }, 14 { "PRIVMSG", FUNC(parseLiteralPrivMsg) },
13 { "NICK", FUNC(parseLiteralNick) }, 15 { "NICK", FUNC(parseLiteralNick) },
@@ -21,16 +23,17 @@ IRCLiteralMessageParserStruct IRCMessageParser::literalParserProcTable[] = {
21 { 0 , 0 } 23 { 0 , 0 }
22}; 24};
23 25
24/* Lookup table for literal commands */ 26/* Lookup table for literal commands */
25IRCCTCPMessageParserStruct IRCMessageParser::ctcpParserProcTable[] = { 27IRCCTCPMessageParserStruct IRCMessageParser::ctcpParserProcTable[] = {
26 { "PING", FUNC(parseCTCPPing) }, 28 { "PING", FUNC(parseCTCPPing) },
27 { "VERSION", FUNC(parseCTCPVersion) }, 29 { "VERSION", FUNC(parseCTCPVersion) },
28 { "ACTION", FUNC(parseCTCPAction) }, 30 { "ACTION", FUNC(parseCTCPAction) },
31 { "DCC", FUNC(parseCTCPDCC) },
29 { 0 , 0 } 32 { 0 , 0 }
30}; 33};
31 34
32/* Lookup table for numerical commands 35/* Lookup table for numerical commands
33 * According to: 36 * According to:
34 * http://www.faqs.org/rfcs/rfc1459.html 37 * http://www.faqs.org/rfcs/rfc1459.html
35 * http://www.faqs.org/rfcs/rfc2812.html 38 * http://www.faqs.org/rfcs/rfc2812.html
36*/ 39*/
@@ -45,34 +48,35 @@ IRCNumericalMessageParserStruct IRCMessageParser::numericalParserProcTable[] = {
45 { 251, "%1", "1", 0 }, // RPL_LUSERCLIENT 48 { 251, "%1", "1", 0 }, // RPL_LUSERCLIENT
46 { 252, QT_TR_NOOP("There are %1 operators connected"), "1", 0 }, // RPL_LUSEROP 49 { 252, QT_TR_NOOP("There are %1 operators connected"), "1", 0 }, // RPL_LUSEROP
47 { 253, QT_TR_NOOP("There are %1 unknown connection(s)"), "1", 0 }, // RPL_LUSERUNKNOWN 50 { 253, QT_TR_NOOP("There are %1 unknown connection(s)"), "1", 0 }, // RPL_LUSERUNKNOWN
48 { 254, QT_TR_NOOP("There are %1 channels formed"), "1", 0 }, // RPL_LUSERCHANNELS 51 { 254, QT_TR_NOOP("There are %1 channels formed"), "1", 0 }, // RPL_LUSERCHANNELS
49 { 255, "%1", "1", 0 }, // RPL_LUSERME 52 { 255, "%1", "1", 0 }, // RPL_LUSERME
50 { 263, QT_TR_NOOP("Please wait a while and try again"), 0, 0 }, // RPL_TRYAGAIN 53 { 263, QT_TR_NOOP("Please wait a while and try again"), 0, 0 }, // RPL_TRYAGAIN
51 { 265, "%1", "1", 0 }, // RPL_LOCALUSERS 54 { 265, "%1", "1", 0 }, // RPL_LOCALUSERS
52 { 266, "%1", "1", 0 }, // RPL_GLOBALUSERS 55 { 266, "%1", "1", 0 }, // RPL_GLOBALUSERS
53 { 311, QT_TR_NOOP("Whois %1 (%2@%3)\nReal name: %4"), "1:3,5" }, // RPL_WHOISUSER 56 { 311, QT_TR_NOOP("Whois %1 (%2@%3)\nReal name: %4"), "1:3,5", 0 }, // RPL_WHOISUSER
54 { 312, QT_TR_NOOP("%1 is using server %2"), "1,2", 0 }, // RPL_WHOISSERVER 57 { 312, QT_TR_NOOP("%1 is using server %2"), "1,2", 0 }, // RPL_WHOISSERVER
55 { 317, 0, 0, FUNC(parseNumericalWhoisIdle) }, // RPL_WHOISIDLE 58 { 317, 0, 0, FUNC(parseNumericalWhoisIdle) }, // RPL_WHOISIDLE
56 { 318, "%1 :%2", "1,2", 0 }, // RPL_ENDOFWHOIS 59 { 318, "%1 :%2", "1,2", 0 }, // RPL_ENDOFWHOIS
60 { 319, QT_TR_NOOP("%1 is on channels: %2"), "1,2", 0 }, // RPL_WHOISCHANNELS
57 { 320, "%1 %2", "1,2", 0}, // RPL_WHOISVIRT 61 { 320, "%1 %2", "1,2", 0}, // RPL_WHOISVIRT
58 { 332, 0, 0, FUNC(parseNumericalTopic) }, // RPL_TOPIC 62 { 332, 0, 0, FUNC(parseNumericalTopic) }, // RPL_TOPIC
59 { 333, 0, 0, FUNC(parseNumericalTopicWhoTime) }, // RPL_TOPICWHOTIME*/ 63 { 333, 0, 0, FUNC(parseNumericalTopicWhoTime) }, // RPL_TOPICWHOTIME*/
60 { 353, QT_TR_NOOP("Names for %1: %2"), "2,3", FUNC(parseNumericalNames) }, // RPL_NAMREPLY 64 { 353, QT_TR_NOOP("Names for %1: %2"), "2,3", FUNC(parseNumericalNames) }, // RPL_NAMREPLY
61 { 366, "%1 :%2", "1,2", FUNC(parseNumericalEndOfNames) }, // RPL_ENDOFNAMES 65 { 366, "%1 :%2", "1,2", FUNC(parseNumericalEndOfNames) }, // RPL_ENDOFNAMES
62 { 369, "%1 :%2", "1,2", 0 }, // RPL_ENDOFWHOWAS 66 { 369, "%1 :%2", "1,2", 0 }, // RPL_ENDOFWHOWAS
63 { 372, "%1", "1", 0 }, // RPL_MOTD 67 { 372, "%1", "1", 0 }, // RPL_MOTD
64 { 375, "%1", "1", 0 }, // RPL_MOTDSTART 68 { 375, "%1", "1", 0 }, // RPL_MOTDSTART
65 { 376, "%1", "1", 0 }, // RPL_ENDOFMOTD 69 { 376, "%1", "1", 0 }, // RPL_ENDOFMOTD
66 { 377, "%1", "1", 0 }, // RPL_MOTD2 70 { 377, "%1", "1", 0 }, // RPL_MOTD2
67 { 378, "%1", "1", 0 }, // RPL_MOTD3 71 { 378, "%1", "1", 0 }, // RPL_MOTD3
68 { 391, QT_TR_NOOP("Time on server %1 is %2"), "1,2", 0 }, // RPL_TIME 72 { 391, QT_TR_NOOP("Time on server %1 is %2"), "1,2", 0 }, // RPL_TIME
69 { 401, QT_TR_NOOP("Channel or nick %1 doesn't exists"), "1", 0 }, // ERR_NOSUCHNICK 73 { 401, QT_TR_NOOP("Channel or nick %1 doesn't exists"), "1", 0 }, // ERR_NOSUCHNICK
70 { 406, QT_TR_NOOP("There is no history information for %1"), "1" }, // ERR_WASNOSUCHNICK 74 { 406, QT_TR_NOOP("There is no history information for %1"), "1", 0 }, // ERR_WASNOSUCHNICK
71 { 409, "%1", "1", 0 }, // ERR_NOORIGIN 75 { 409, "%1", "1", 0 }, // ERR_NOORIGIN
72 { 411, "%1", "1", 0 }, // ERR_NORECIPIENT 76 { 411, "%1", "1", 0 }, // ERR_NORECIPIENT
73 { 412, "%1", "1", 0 }, // ERR_NOTEXTTOSEND 77 { 412, "%1", "1", 0 }, // ERR_NOTEXTTOSEND
74 { 421, QT_TR_NOOP("Unknown command: %1"), "1", 0 }, // ERR_ERR_UNKNOWNCOMMAND 78 { 421, QT_TR_NOOP("Unknown command: %1"), "1", 0 }, // ERR_ERR_UNKNOWNCOMMAND
75 { 422, "%1", "1", 0 }, // ERR_NOMOTD 79 { 422, "%1", "1", 0 }, // ERR_NOMOTD
76 { 433, QT_TR_NOOP("Can't change nick to %1: %2"), "1,2", FUNC(parseNumericalNicknameInUse) }, // ERR_NICKNAMEINUSE 80 { 433, QT_TR_NOOP("Can't change nick to %1: %2"), "1,2", FUNC(parseNumericalNicknameInUse) }, // ERR_NICKNAMEINUSE
77 { 442, QT_TR_NOOP("You're not on channel %1"), "1", 0}, // ERR_NOTONCHANNEL 81 { 442, QT_TR_NOOP("You're not on channel %1"), "1", 0}, // ERR_NOTONCHANNEL
78 { 477, "%1", "1", 0 }, // ERR_NOCHANMODES || ERR_NEEDREGGEDNICK 82 { 477, "%1", "1", 0 }, // ERR_NOCHANMODES || ERR_NEEDREGGEDNICK
@@ -94,17 +98,17 @@ void IRCMessageParser::parse(IRCMessage *message) {
94 parseNumerical(message, i); 98 parseNumerical(message, i);
95 return; 99 return;
96 } 100 }
97 } 101 }
98 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received unhandled numeric command: %1").arg( QString::number(message->commandNumber()) ))); 102 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received unhandled numeric command: %1").arg( QString::number(message->commandNumber()) )));
99 } else if (message->isCTCP()) { 103 } else if (message->isCTCP()) {
100 for (int i=0; ctcpParserProcTable[i].commandName; i++) { 104 for (int i=0; ctcpParserProcTable[i].commandName; i++) {
101 if (message->ctcpCommand() == ctcpParserProcTable[i].commandName) { 105 if (message->ctcpCommand() == ctcpParserProcTable[i].commandName) {
102 (this->*(ctcpParserProcTable[i].proc))(message); 106 parseCTCP(message, i);
103 return; 107 return;
104 } 108 }
105 } 109 }
106 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received unhandled ctcp command: %1").arg( message->ctcpCommand())) ); 110 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received unhandled ctcp command: %1").arg( message->ctcpCommand())) );
107 } else { 111 } else {
108 for (int i=0; literalParserProcTable[i].commandName; i++) { 112 for (int i=0; literalParserProcTable[i].commandName; i++) {
109 if (message->command() == literalParserProcTable[i].commandName) { 113 if (message->command() == literalParserProcTable[i].commandName) {
110 (this->*(literalParserProcTable[i].proc))(message); 114 (this->*(literalParserProcTable[i].proc))(message);
@@ -129,19 +133,26 @@ void IRCMessageParser::parseNumerical(IRCMessage *message, int position) {
129 133
130 emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, out)); 134 emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, out));
131 } 135 }
132 136
133 if(numericalParserProcTable[position].proc) 137 if(numericalParserProcTable[position].proc)
134 (this->*(numericalParserProcTable[position].proc))(message); 138 (this->*(numericalParserProcTable[position].proc))(message);
135} 139}
136 140
141void IRCMessageParser::parseCTCP(IRCMessage *message, int position) {
142 if(ctcpParserProcTable[position].proc)
143 (this->*(ctcpParserProcTable[position].proc))(message);
144}
145
146
147
137void IRCMessageParser::parseNumericalServerName(IRCMessage *message) { 148void IRCMessageParser::parseNumericalServerName(IRCMessage *message) {
138 emit outputReady(IRCOutput(OUTPUT_TITLE, tr("Connected to")+" <b>" + message->prefix() + "</b>")); 149 emit outputReady(IRCOutput(OUTPUT_TITLE, tr("Connected to")+" <b>" + message->prefix() + "</b>"));
139 /* Register EFFECTIVE nickname, some networks (as irc-hispano) uses nick:password 150 /* Register EFFECTIVE nickname, some networks (as irc-hispano) use nick:password
140 * for authentication and the parser gets confused */ 151 * for authentication and the parser gets confused */
141 m_session->m_server->setNick(message->param(0)); 152 m_session->m_server->setNick(message->param(0));
142 153
143} 154}
144 155
145void IRCMessageParser::parseNumericalServerFeatures(IRCMessage *message) { 156void IRCMessageParser::parseNumericalServerFeatures(IRCMessage *message) {
146 m_session->setValidUsermodes(message->param(2)); 157 m_session->setValidUsermodes(message->param(2));
147 m_session->setValidChannelmodes(message->param(3)); 158 m_session->setValidChannelmodes(message->param(3));
@@ -184,24 +195,22 @@ void IRCMessageParser::parseLiteralJoin(IRCMessage *message) {
184 m_session->addChannel(channel); 195 m_session->addChannel(channel);
185 } else { 196 } else {
186 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Nonexistant channel join - desynchronized?"))); 197 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Nonexistant channel join - desynchronized?")));
187 } 198 }
188 } else { 199 } else {
189 /* Someone else joined */ 200 /* Someone else joined */
190 if (mask.nick() != m_session->m_server->nick()) { 201 if (mask.nick() != m_session->m_server->nick()) {
191 if (!channel->getPerson(mask.nick())) { 202 if (!channel->getPerson(mask.nick())) {
192 IRCChannelPerson *chanperson = new IRCChannelPerson();
193 IRCPerson *person = m_session->getPerson(mask.nick()); 203 IRCPerson *person = m_session->getPerson(mask.nick());
194 if (!person) { 204 if (!person) {
195 person = new IRCPerson(message->prefix()); 205 person = new IRCPerson(message->prefix());
196 m_session->addPerson(person); 206 m_session->addPerson(person);
197 } 207 }
198 chanperson->flags = 0; 208 IRCChannelPerson *chanperson = new IRCChannelPerson(person);
199 chanperson->person = person;
200 channel->addPerson(chanperson); 209 channel->addPerson(chanperson);
201 IRCOutput output(OUTPUT_OTHERJOIN ,tr("%1 joined channel %2").arg( mask.nick() ).arg( channelName )); 210 IRCOutput output(OUTPUT_OTHERJOIN ,tr("%1 joined channel %2").arg( mask.nick() ).arg( channelName ));
202 output.addParam(channel); 211 output.addParam(channel);
203 output.addParam(chanperson); 212 output.addParam(chanperson);
204 emit outputReady(output); 213 emit outputReady(output);
205 } else { 214 } else {
206 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Person has already joined the channel - desynchronized?"))); 215 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Person has already joined the channel - desynchronized?")));
207 } 216 }
@@ -350,18 +359,18 @@ void IRCMessageParser::parseLiteralTopic(IRCMessage *message) {
350} 359}
351 360
352void IRCMessageParser::parseLiteralError(IRCMessage *message) { 361void IRCMessageParser::parseLiteralError(IRCMessage *message) {
353 emit outputReady(IRCOutput(OUTPUT_ERROR, message->allParameters())); 362 emit outputReady(IRCOutput(OUTPUT_ERROR, message->allParameters()));
354} 363}
355 364
356void IRCMessageParser::parseCTCPPing(IRCMessage *message) { 365void IRCMessageParser::parseCTCPPing(IRCMessage *message) {
357 IRCPerson mask(message->prefix()); 366 IRCPerson mask(message->prefix());
358 m_session->m_connection->sendCTCP(mask.nick(), "PING " + message->allParameters()); 367 m_session->m_connection->sendCTCPReply(mask.nick(), "PING", message->allParameters());
359 emit outputReady(IRCOutput(OUTPUT_CTCP, tr("Received a CTCP PING from ")+mask.nick())); 368 emit outputReady(IRCOutput(OUTPUT_CTCP, tr("Received a CTCP PING from ") + mask.nick()));
360 369
361 //IRCPerson mask(message->prefix()); 370 //IRCPerson mask(message->prefix());
362 QString dest = message->ctcpDestination(); 371 QString dest = message->ctcpDestination();
363 if (dest.startsWith("#")) { 372 if (dest.startsWith("#")) {
364 IRCChannel *channel = m_session->getChannel(dest.lower()); 373 IRCChannel *channel = m_session->getChannel(dest.lower());
365 if (channel) { 374 if (channel) {
366 IRCChannelPerson *person = channel->getPerson(mask.nick()); 375 IRCChannelPerson *person = channel->getPerson(mask.nick());
367 if (person) { 376 if (person) {
@@ -390,18 +399,26 @@ void IRCMessageParser::parseCTCPPing(IRCMessage *message) {
390 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP PING with bad recipient"))); 399 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP PING with bad recipient")));
391 } 400 }
392 } 401 }
393 402
394} 403}
395 404
396void IRCMessageParser::parseCTCPVersion(IRCMessage *message) { 405void IRCMessageParser::parseCTCPVersion(IRCMessage *message) {
397 IRCPerson mask(message->prefix()); 406 IRCPerson mask(message->prefix());
398 m_session->m_connection->sendCTCP(mask.nick(), "VERSION " APP_VERSION " " APP_COPYSTR); 407 IRCOutput output(OUTPUT_CTCP);
399 emit outputReady(IRCOutput(OUTPUT_CTCP, tr("Received a CTCP VERSION from ")+mask.nick())); 408 if(message->isCTCPRequest()) {
409 m_session->m_connection->sendCTCPReply(mask.nick(), "VERSION", APP_VERSION " " APP_COPYSTR);
410 output.setMessage(tr("Received a CTCP VERSION request from ") + mask.nick());
411 }
412
413 else {
414 output.setMessage("Received CTCP VERSION reply from " + mask.nick() + ":" + message->param(0));
415 }
416 emit outputReady(output);
400} 417}
401 418
402void IRCMessageParser::parseCTCPAction(IRCMessage *message) { 419void IRCMessageParser::parseCTCPAction(IRCMessage *message) {
403 IRCPerson mask(message->prefix()); 420 IRCPerson mask(message->prefix());
404 QString dest = message->ctcpDestination(); 421 QString dest = message->ctcpDestination();
405 if (dest.startsWith("#")) { 422 if (dest.startsWith("#")) {
406 IRCChannel *channel = m_session->getChannel(dest.lower()); 423 IRCChannel *channel = m_session->getChannel(dest.lower());
407 if (channel) { 424 if (channel) {
@@ -429,104 +446,104 @@ void IRCMessageParser::parseCTCPAction(IRCMessage *message) {
429 output.addParam(person); 446 output.addParam(person);
430 emit outputReady(output); 447 emit outputReady(output);
431 } else { 448 } else {
432 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP ACTION with bad recipient"))); 449 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP ACTION with bad recipient")));
433 } 450 }
434 } 451 }
435} 452}
436 453
454void IRCMessageParser::parseCTCPDCC(IRCMessage *message) {
455 QStringList params = QStringList::split(' ', message->param(0).stripWhiteSpace());
456 if( params.count() != 5) {
457 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Malformed DCC request from ") + IRCPerson(message->prefix()).nick()));
458 return;
459 }
460
461 //TransferReceiver *foo = new TransferReceiver(params[2].toUInt(), params[3].toUInt(), params[1], params[4].toUInt());
462}
463
437void IRCMessageParser::parseLiteralMode(IRCMessage *message) { 464void IRCMessageParser::parseLiteralMode(IRCMessage *message) {
438 IRCPerson mask(message->prefix()); 465 IRCPerson mask(message->prefix());
439 466
440 if (message->param(0).startsWith("#")) { 467 if (message->param(0).startsWith("#")) {
441 IRCChannel *channel = m_session->getChannel(message->param(0).lower()); 468 IRCChannel *channel = m_session->getChannel(message->param(0).lower());
442 if (channel) { 469 if (channel) {
443 QString temp, parameters = message->allParameters().right(message->allParameters().length() - channel->channelname().length() - 1); 470 QString temp, parameters = message->allParameters().right(message->allParameters().length() - channel->channelname().length() - 1);
444 QTextIStream stream(&parameters); 471 QTextIStream stream(&parameters);
445 bool set = FALSE; 472 bool set = FALSE;
446 while (!stream.atEnd()) { 473 while (!stream.atEnd()) {
447 stream >> temp; 474 stream >> temp;
448 if (temp.startsWith("+")) { 475 if (temp.startsWith("+")) {
449 set = TRUE; 476 set = TRUE;
450 temp = temp.right(1); 477 temp = temp.right(1);
451 } else if (temp.startsWith("-")) { 478 }
452 set = FALSE; 479 else
453 temp = temp.right(1); 480 if (temp.startsWith("-")) {
454 } else { 481 set = FALSE;
455 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change has unknown type"))); 482 temp = temp.right(1);
456 return; 483 }
457 } 484 else {
485 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change has unknown type")));
486 return;
487 }
458 if (temp == "o") { 488 if (temp == "o") {
459 stream >> temp; 489 stream >> temp;
460 IRCChannelPerson *person = channel->getPerson(temp); 490 IRCChannelPerson *person = channel->getPerson(temp);
461 if (person) { 491 if (person) {
462 if (set) { 492 IRCOutput output(OUTPUT_CHANPERSONMODE, person->setOp(mask.nick(), set));
463 person->flags |= PERSON_FLAG_OP; 493 output.addParam(channel);
464 IRCOutput output(OUTPUT_CHANPERSONMODE, mask.nick() + tr(" gives channel operator status to " + person->person->nick())); 494 output.addParam(person);
465 output.addParam(channel); 495 emit outputReady(output);
466 output.addParam(person); 496 }
467 emit outputReady(output); 497 else {
468 } else {
469 person->flags &= 0xFFFF - PERSON_FLAG_OP;
470 IRCOutput output(OUTPUT_CHANPERSONMODE, mask.nick() + tr(" removes channel operator status from " + person->person->nick()));
471 output.addParam(channel);
472 output.addParam(person);
473 emit outputReady(output);
474 }
475 } else {
476 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown person - Desynchronized?"))); 498 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown person - Desynchronized?")));
477 } 499 }
478 } else if (temp == "v") { 500 }
479 stream >> temp; 501 else
480 IRCChannelPerson *person = channel->getPerson(temp); 502 if (temp == "v") {
481 if (person) { 503 stream >> temp;
482 if (set) { 504 IRCChannelPerson *person = channel->getPerson(temp);
483 person->flags |= PERSON_FLAG_VOICE; 505 if (person) {
484 IRCOutput output(OUTPUT_CHANPERSONMODE, mask.nick() + tr(" gives voice to " + person->person->nick())); 506 IRCOutput output(OUTPUT_CHANPERSONMODE, person->setVoice(mask.nick(), set));
485 output.addParam(channel);
486 output.addParam(person);
487 emit outputReady(output);
488 } else {
489 person->flags &= 0xFFFF - PERSON_FLAG_VOICE;
490 IRCOutput output(OUTPUT_CHANPERSONMODE, mask.nick() + tr(" removes voice from " + person->person->nick()));
491 output.addParam(channel); 507 output.addParam(channel);
492 output.addParam(person); 508 output.addParam(person);
493 emit outputReady(output); 509 emit outputReady(output);
494 } 510 }
495 } else { 511 else {
496 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown person - Desynchronized?"))); 512 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown person - Desynchronized?")));
513 }
514 }
515 else {
516 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown flag")));
497 } 517 }
498 } else {
499 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown flag")));
500 } 518 }
501 }
502 } else { 519 } else {
503 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown kannel - Desynchronized?"))); 520 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown kannel - Desynchronized?")));
504 } 521 }
505 } else { 522 } else {
506 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("User modes not supported yet"))); 523 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("User modes not supported yet")));
507 } 524 }
508} 525}
509 526
510void IRCMessageParser::parseLiteralKick(IRCMessage *message) { 527void IRCMessageParser::parseLiteralKick(IRCMessage *message) {
511 IRCPerson mask(message->prefix()); 528 IRCPerson mask(message->prefix());
512 IRCChannel *channel = m_session->getChannel(message->param(0).lower()); 529 IRCChannel *channel = m_session->getChannel(message->param(0).lower());
513 if (channel) { 530 if (channel) {
514 IRCChannelPerson *person = channel->getPerson(message->param(1)); 531 IRCChannelPerson *person = channel->getPerson(message->param(1));
515 if (person) { 532 if (person) {
516 if (person->person->nick() == m_session->m_server->nick()) { 533 if (person->nick() == m_session->m_server->nick()) {
517 m_session->removeChannel(channel); 534 m_session->removeChannel(channel);
518 IRCOutput output(OUTPUT_SELFKICK, tr("You were kicked from ") + channel->channelname() + tr(" by ") + mask.nick() + " (" + message->param(2) + ")"); 535 IRCOutput output(OUTPUT_SELFKICK, tr("You were kicked from ") + channel->channelname() + tr(" by ") + mask.nick() + " (" + message->param(2) + ")");
519 output.addParam(channel); 536 output.addParam(channel);
520 emit outputReady(output); 537 emit outputReady(output);
521 } else { 538 } else {
522 /* someone else got kicked */ 539 /* someone else got kicked */
523 channel->removePerson(person); 540 channel->removePerson(person);
524 IRCOutput output(OUTPUT_OTHERKICK, person->person->nick() + tr(" was kicked from ") + channel->channelname() + tr(" by ") + mask.nick()+ " (" + message->param(2) + ")"); 541 IRCOutput output(OUTPUT_OTHERKICK, person->nick() + tr(" was kicked from ") + channel->channelname() + tr(" by ") + mask.nick()+ " (" + message->param(2) + ")");
525 output.addParam(channel); 542 output.addParam(channel);
526 output.addParam(person); 543 output.addParam(person);
527 emit outputReady(output); 544 emit outputReady(output);
528 } 545 }
529 } else { 546 } else {
530 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown person kick - desynchronized?"))); 547 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown person kick - desynchronized?")));
531 } 548 }
532 } else { 549 } else {
@@ -548,34 +565,33 @@ void IRCMessageParser::parseNumericalNames(IRCMessage *message) {
548 char flagch = temp.at(0).latin1(); 565 char flagch = temp.at(0).latin1();
549 int flag = 0; 566 int flag = 0;
550 QString nick; 567 QString nick;
551 /* Parse person flags */ 568 /* Parse person flags */
552 if (flagch == '@' || flagch == '+' || flagch=='%' || flagch == '*') { 569 if (flagch == '@' || flagch == '+' || flagch=='%' || flagch == '*') {
553 570
554 nick = temp.right(temp.length()-1); 571 nick = temp.right(temp.length()-1);
555 switch (flagch) { 572 switch (flagch) {
556 case '@': flag = PERSON_FLAG_OP; break; 573 case '@': flag = IRCChannelPerson::PERSON_FLAG_OP; break;
557 case '+': flag = PERSON_FLAG_VOICE; break; 574 case '+': flag = IRCChannelPerson::PERSON_FLAG_VOICE; break;
558 case '%': flag = PERSON_FLAG_HALFOP; break; 575 case '%': flag = IRCChannelPerson::PERSON_FLAG_HALFOP; break;
559 default : flag = 0; break; 576 default : flag = 0; break;
560 } 577 }
561 } else { 578 } else {
562 nick = temp; 579 nick = temp;
563 } 580 }
564 581
565 IRCChannelPerson *chan_person = new IRCChannelPerson();
566 IRCPerson *person = m_session->getPerson(nick); 582 IRCPerson *person = m_session->getPerson(nick);
567 if (person == 0) { 583 if (person == 0) {
568 person = new IRCPerson(); 584 person = new IRCPerson();
569 person->setNick(nick); 585 person->setNick(nick);
570 m_session->addPerson(person); 586 m_session->addPerson(person);
571 } 587 }
572 chan_person->person = person; 588 IRCChannelPerson *chan_person = new IRCChannelPerson(person);
573 chan_person->flags = flag; 589 chan_person->setFlags(flag);
574 channel->addPerson(chan_person); 590 channel->addPerson(chan_person);
575 } 591 }
576 } else { 592 } else {
577 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Server message with unknown channel"))); 593 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Server message with unknown channel")));
578 } 594 }
579} 595}
580 596
581void IRCMessageParser::parseNumericalEndOfNames(IRCMessage *message) { 597void IRCMessageParser::parseNumericalEndOfNames(IRCMessage *message) {
diff --git a/noncore/net/opieirc/ircmessageparser.h b/noncore/net/opieirc/ircmessageparser.h
index 2fca61e..4ebbddd 100644
--- a/noncore/net/opieirc/ircmessageparser.h
+++ b/noncore/net/opieirc/ircmessageparser.h
@@ -70,29 +70,31 @@ private:
70 void parseLiteralNick(IRCMessage *message); 70 void parseLiteralNick(IRCMessage *message);
71 void parseLiteralPart(IRCMessage *message); 71 void parseLiteralPart(IRCMessage *message);
72 void parseLiteralQuit(IRCMessage *message); 72 void parseLiteralQuit(IRCMessage *message);
73 void parseLiteralError(IRCMessage *message); 73 void parseLiteralError(IRCMessage *message);
74 void parseLiteralMode(IRCMessage *message); 74 void parseLiteralMode(IRCMessage *message);
75 void parseLiteralKick(IRCMessage *message); 75 void parseLiteralKick(IRCMessage *message);
76 void parseLiteralTopic(IRCMessage *message); 76 void parseLiteralTopic(IRCMessage *message);
77 void parseNumerical(IRCMessage *message, int position); 77 void parseNumerical(IRCMessage *message, int position);
78 void parseCTCP(IRCMessage *message, int position);
78 void parseNumericalServerName(IRCMessage *message); 79 void parseNumericalServerName(IRCMessage *message);
79 void parseNumericalServerFeatures(IRCMessage *message); 80 void parseNumericalServerFeatures(IRCMessage *message);
80 void parseNumericalServerProtocol(IRCMessage *message); 81 void parseNumericalServerProtocol(IRCMessage *message);
81 void parseNumericalWhoisIdle(IRCMessage *message); 82 void parseNumericalWhoisIdle(IRCMessage *message);
82 void parseNumericalNames(IRCMessage *message); 83 void parseNumericalNames(IRCMessage *message);
83 void parseNumericalEndOfNames(IRCMessage *message); 84 void parseNumericalEndOfNames(IRCMessage *message);
84 void parseNumericalNicknameInUse(IRCMessage *message); 85 void parseNumericalNicknameInUse(IRCMessage *message);
85 void parseNumericalNoSuchNick(IRCMessage *message); 86 void parseNumericalNoSuchNick(IRCMessage *message);
86 void parseNumericalTopic(IRCMessage *message); 87 void parseNumericalTopic(IRCMessage *message);
87 void parseNumericalTopicWhoTime(IRCMessage *message); 88 void parseNumericalTopicWhoTime(IRCMessage *message);
88 void parseCTCPPing(IRCMessage *message); 89 void parseCTCPPing(IRCMessage *message);
89 void parseCTCPVersion(IRCMessage *message); 90 void parseCTCPVersion(IRCMessage *message);
90 void parseCTCPAction(IRCMessage *message); 91 void parseCTCPAction(IRCMessage *message);
92 void parseCTCPDCC(IRCMessage *message);
91protected: 93protected:
92 IRCSession *m_session; 94 IRCSession *m_session;
93 /* Parser tables */ 95 /* Parser tables */
94 static IRCLiteralMessageParserStruct literalParserProcTable[]; 96 static IRCLiteralMessageParserStruct literalParserProcTable[];
95 static IRCNumericalMessageParserStruct numericalParserProcTable[]; 97 static IRCNumericalMessageParserStruct numericalParserProcTable[];
96 static IRCCTCPMessageParserStruct ctcpParserProcTable[]; 98 static IRCCTCPMessageParserStruct ctcpParserProcTable[];
97}; 99};
98 100
diff --git a/noncore/net/opieirc/ircservertab.cpp b/noncore/net/opieirc/ircservertab.cpp
index 90353f2..bddc37e 100644
--- a/noncore/net/opieirc/ircservertab.cpp
+++ b/noncore/net/opieirc/ircservertab.cpp
@@ -1,13 +1,14 @@
1#include <qtextstream.h> 1#include <qtextstream.h>
2#include <qwhatsthis.h> 2#include <qwhatsthis.h>
3 3
4#include "ircservertab.h" 4#include "ircservertab.h"
5#include "ircmessageparser.h" 5#include "ircmessageparser.h"
6#include "ircchannelperson.h"
6 7
7 8
8bool IRCServerTab::containsPing( const QString& text, IRCServerTab* tab ) { 9bool IRCServerTab::containsPing( const QString& text, IRCServerTab* tab ) {
9 return (text.contains(IRCMessageParser::tr("Received a CTCP PING from "))) || 10 return (text.contains(IRCMessageParser::tr("Received a CTCP PING from "))) ||
10 (text.find("ping") != -1 && text.find( tab->server()->nick() != -1)); 11 (text.find("ping") != -1 && text.find( tab->server()->nick() != -1));
11} 12}
12 13
13 14
@@ -306,17 +307,17 @@ void IRCServerTab::display(IRCOutput output) {
306 case OUTPUT_SELFJOIN: { 307 case OUTPUT_SELFJOIN: {
307 IRCChannelTab *channeltab = new IRCChannelTab((IRCChannel *)output.getParam(0), this, m_mainWindow, (QWidget *)parent()); 308 IRCChannelTab *channeltab = new IRCChannelTab((IRCChannel *)output.getParam(0), this, m_mainWindow, (QWidget *)parent());
308 m_channelTabs.append(channeltab); 309 m_channelTabs.append(channeltab);
309 m_mainWindow->addTab(channeltab); 310 m_mainWindow->addTab(channeltab);
310 } 311 }
311 break; 312 break;
312 case OUTPUT_CHANPRIVMSG: { 313 case OUTPUT_CHANPRIVMSG: {
313 IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0)); 314 IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0));
314 channelTab->appendText("<font color=\"" + m_textColor + "\">&lt;</font><font color=\"" + m_otherColor + "\">"+IRCOutput::toHTML(((IRCChannelPerson *)output.getParam(1))->person->nick())+"</font><font color=\"" + m_textColor + "\">&gt; " + output.htmlMessage()+"</font><br>"); 315 channelTab->appendText("<font color=\"" + m_textColor + "\">&lt;</font><font color=\"" + m_otherColor + "\">"+IRCOutput::toHTML(((IRCChannelPerson *)output.getParam(1))->nick())+"</font><font color=\"" + m_textColor + "\">&gt; " + output.htmlMessage()+"</font><br>");
315 } 316 }
316 break; 317 break;
317 case OUTPUT_QUERYACTION: 318 case OUTPUT_QUERYACTION:
318 case OUTPUT_QUERYPRIVMSG: { 319 case OUTPUT_QUERYPRIVMSG: {
319 IRCQueryTab *queryTab = getTabForQuery((IRCPerson *)output.getParam(0)); 320 IRCQueryTab *queryTab = getTabForQuery((IRCPerson *)output.getParam(0));
320 if (!queryTab) { 321 if (!queryTab) {
321 queryTab = new IRCQueryTab((IRCPerson *)output.getParam(0), this, m_mainWindow, (QWidget *)parent()); 322 queryTab = new IRCQueryTab((IRCPerson *)output.getParam(0), this, m_mainWindow, (QWidget *)parent());
322 m_queryTabs.append(queryTab); 323 m_queryTabs.append(queryTab);
diff --git a/noncore/net/opieirc/ircsession.cpp b/noncore/net/opieirc/ircsession.cpp
index ca0df50..80a327a 100644
--- a/noncore/net/opieirc/ircsession.cpp
+++ b/noncore/net/opieirc/ircsession.cpp
@@ -1,10 +1,12 @@
1
1#include "ircsession.h" 2#include "ircsession.h"
2#include "ircmessageparser.h" 3#include "ircmessageparser.h"
4#include "ircchannelperson.h"
3#include "ircversion.h" 5#include "ircversion.h"
4 6
5IRCSession::IRCSession(IRCServer *server) { 7IRCSession::IRCSession(IRCServer *server) {
6 m_server = server; 8 m_server = server;
7 m_connection = new IRCConnection(m_server); 9 m_connection = new IRCConnection(m_server);
8 m_parser = new IRCMessageParser(this); 10 m_parser = new IRCMessageParser(this);
9 connect(m_connection, SIGNAL(messageArrived(IRCMessage*)), this, SLOT(handleMessage(IRCMessage*))); 11 connect(m_connection, SIGNAL(messageArrived(IRCMessage*)), this, SLOT(handleMessage(IRCMessage*)));
10 connect(m_parser, SIGNAL(outputReady(IRCOutput)), this, SIGNAL(outputReady(IRCOutput))); 12 connect(m_parser, SIGNAL(outputReady(IRCOutput)), this, SIGNAL(outputReady(IRCOutput)));
@@ -132,17 +134,17 @@ void IRCSession::updateNickname(const QString &oldNickname, const QString &newNi
132 getChannelsByPerson(person, channels); 134 getChannelsByPerson(person, channels);
133 output = IRCOutput(OUTPUT_NICKCHANGE, tr("%1 is now known as %2").arg(oldNickname).arg(newNickname)); 135 output = IRCOutput(OUTPUT_NICKCHANGE, tr("%1 is now known as %2").arg(oldNickname).arg(newNickname));
134 } 136 }
135 137
136 QListIterator<IRCChannel> it(channels); 138 QListIterator<IRCChannel> it(channels);
137 for (;it.current(); ++it) { 139 for (;it.current(); ++it) {
138 IRCChannelPerson *chanperson = it.current()->getPerson(oldNickname); 140 IRCChannelPerson *chanperson = it.current()->getPerson(oldNickname);
139 it.current()->removePerson(chanperson); 141 it.current()->removePerson(chanperson);
140 chanperson->person->setNick(newNickname); 142 chanperson->setNick(newNickname);
141 it.current()->addPerson(chanperson); 143 it.current()->addPerson(chanperson);
142 } 144 }
143 145
144 emit updateChannels(); 146 emit updateChannels();
145 output.addParam(new QString(newNickname)); 147 output.addParam(new QString(newNickname));
146 emit outputReady(output); 148 emit outputReady(output);
147} 149}
148 150
@@ -189,8 +191,24 @@ void IRCSession::removeChannel(IRCChannel *channel) {
189 191
190void IRCSession::removePerson(IRCPerson *person) { 192void IRCSession::removePerson(IRCPerson *person) {
191 m_people.remove(person); 193 m_people.remove(person);
192} 194}
193 195
194void IRCSession::handleMessage(IRCMessage *message) { 196void IRCSession::handleMessage(IRCMessage *message) {
195 m_parser->parse(message); 197 m_parser->parse(message);
196} 198}
199
200void IRCSession::whois(const QString &nickname) {
201 m_connection->whois(nickname);
202}
203
204void IRCSession::sendCTCPPing(const QString &nickname) {
205 m_connection->sendCTCPPing(nickname);
206}
207
208void IRCSession::sendCTCPRequest(const QString &nickname, const QString &type, const QString &args) {
209 m_connection->sendCTCPRequest(nickname, type, args);
210}
211
212void IRCSession::sendCTCPReply(const QString &nickname, const QString &type, const QString &args) {
213 m_connection->sendCTCPReply(nickname, type, args);
214}
diff --git a/noncore/net/opieirc/ircsession.h b/noncore/net/opieirc/ircsession.h
index 96de3e4..3859b68 100644
--- a/noncore/net/opieirc/ircsession.h
+++ b/noncore/net/opieirc/ircsession.h
@@ -60,16 +60,20 @@ public:
60 bool isLoggedIn(); 60 bool isLoggedIn();
61 void sendMessage(IRCPerson *person, QString message); 61 void sendMessage(IRCPerson *person, QString message);
62 void sendMessage(IRCChannel *channel, QString message); 62 void sendMessage(IRCChannel *channel, QString message);
63 void sendAction(IRCPerson *person, QString message); 63 void sendAction(IRCPerson *person, QString message);
64 void sendAction(IRCChannel *channel, QString message); 64 void sendAction(IRCChannel *channel, QString message);
65 void updateNickname(const QString &oldNickname, const QString &newNickname); 65 void updateNickname(const QString &oldNickname, const QString &newNickname);
66 void setValidUsermodes(const QString &modes); 66 void setValidUsermodes(const QString &modes);
67 void setValidChannelmodes(const QString &modes); 67 void setValidChannelmodes(const QString &modes);
68 void whois(const QString &nickname);
69 void sendCTCPPing(const QString &nickname);
70 void sendCTCPRequest(const QString &nickname, const QString &type, const QString &args);
71 void sendCTCPReply(const QString &nickname, const QString &type, const QString &args);
68 IRCChannel *getChannel(QString channelname); 72 IRCChannel *getChannel(QString channelname);
69 IRCPerson *getPerson(QString nickname); 73 IRCPerson *getPerson(QString nickname);
70protected: 74protected:
71 void addPerson(IRCPerson *person); 75 void addPerson(IRCPerson *person);
72 void addChannel(IRCChannel *channel); 76 void addChannel(IRCChannel *channel);
73 void removeChannel(IRCChannel *channel); 77 void removeChannel(IRCChannel *channel);
74 void removePerson(IRCPerson *person); 78 void removePerson(IRCPerson *person);
75 void getChannelsByPerson(IRCPerson *person, QList<IRCChannel> &channels); 79 void getChannelsByPerson(IRCPerson *person, QList<IRCChannel> &channels);
diff --git a/noncore/net/opieirc/mainwindow.cpp b/noncore/net/opieirc/mainwindow.cpp
index 2562f33..1811a0c 100644
--- a/noncore/net/opieirc/mainwindow.cpp
+++ b/noncore/net/opieirc/mainwindow.cpp
@@ -1,10 +1,13 @@
1#include <qmenubar.h> 1#include <qmenubar.h>
2#include <qpe/resource.h> 2#include <qpe/resource.h>
3
4#include <opie2/odebug.h>
5
3#include <qwhatsthis.h> 6#include <qwhatsthis.h>
4 7
5#include "mainwindow.h" 8#include "mainwindow.h"
6#include "ircservertab.h" 9#include "ircservertab.h"
7#include "ircserverlist.h" 10#include "ircserverlist.h"
8#include "ircsettings.h" 11#include "ircsettings.h"
9 12
10QString MainWindow::appCaption() { 13QString MainWindow::appCaption() {
@@ -80,16 +83,17 @@ void MainWindow::killTab(IRCTab *tab, bool imediate) {
80 slotKillTabsLater(); 83 slotKillTabsLater();
81 else 84 else
82 QTimer::singleShot(0, this, SLOT(slotKillTabsLater()) ); 85 QTimer::singleShot(0, this, SLOT(slotKillTabsLater()) );
83} 86}
84 87
85void MainWindow::slotKillTabsLater() { 88void MainWindow::slotKillTabsLater() {
86 for ( QListIterator<IRCTab> it(m_toDelete); it.current(); ++it ) { 89 for ( QListIterator<IRCTab> it(m_toDelete); it.current(); ++it ) {
87 m_tabWidget->removePage( it.current() ); 90 m_tabWidget->removePage( it.current() );
91 odebug << it.current() << oendl;
88 m_tabs.remove( it.current() ); 92 m_tabs.remove( it.current() );
89 } 93 }
90 94
91 m_toDelete.setAutoDelete( true ); 95 m_toDelete.setAutoDelete( true );
92 m_toDelete.clear(); 96 m_toDelete.clear();
93 m_toDelete.setAutoDelete( false ); 97 m_toDelete.setAutoDelete( false );
94} 98}
95 99
diff --git a/noncore/net/opieirc/opieirc.pro b/noncore/net/opieirc/opieirc.pro
index db89fa6..1ef9be2 100644
--- a/noncore/net/opieirc/opieirc.pro
+++ b/noncore/net/opieirc/opieirc.pro
@@ -1,26 +1,28 @@
1 CONFIG = qt warn_on quick-app 1 CONFIG = qt warn_on quick-app
2HEADERS = ircchannel.h ircconnection.h \ 2HEADERS = ircchannel.h ircconnection.h \
3 ircmessage.h \ 3 ircmessage.h \
4 ircmessageparser.h ircoutput.h \ 4 ircmessageparser.h ircoutput.h \
5 ircperson.h ircserver.h ircsession.h \ 5 ircperson.h ircserver.h ircsession.h \
6 mainwindow.h irctab.h ircservertab.h \ 6 mainwindow.h irctab.h ircservertab.h \
7 ircchanneltab.h ircchannellist.h \ 7 ircchanneltab.h ircchannellist.h \
8 ircserverlist.h ircservereditor.h \ 8 ircserverlist.h ircservereditor.h \
9 ircquerytab.h ircsettings.h ircmisc.h 9 ircquerytab.h ircsettings.h ircmisc.h \
10 ircchannelperson.h
10 SOURCES = ircchannel.cpp ircconnection.cpp \ 11 SOURCES = ircchannel.cpp ircconnection.cpp \
11 ircmessage.cpp \ 12 ircmessage.cpp \
12 ircmessageparser.cpp ircoutput.cpp \ 13 ircmessageparser.cpp ircoutput.cpp \
13 ircperson.cpp ircserver.cpp \ 14 ircperson.cpp ircserver.cpp \
14 ircsession.cpp main.cpp mainwindow.cpp \ 15 ircsession.cpp main.cpp mainwindow.cpp \
15 irctab.cpp ircservertab.cpp \ 16 irctab.cpp ircservertab.cpp \
16 ircchanneltab.cpp ircchannellist.cpp \ 17 ircchanneltab.cpp ircchannellist.cpp \
17 ircserverlist.cpp ircservereditor.cpp \ 18 ircserverlist.cpp ircservereditor.cpp \
18 ircquerytab.cpp ircsettings.cpp ircmisc.cpp 19 ircquerytab.cpp ircsettings.cpp ircmisc.cpp \
20 ircchannelperson.cpp
19INCLUDEPATH += $(OPIEDIR)/include 21INCLUDEPATH += $(OPIEDIR)/include
20DEPENDPATH += $(OPIEDIR)/include 22DEPENDPATH += $(OPIEDIR)/include
21 23
22PRECOMPILED_HEADER = stable.h 24PRECOMPILED_HEADER = stable.h
23 25
24LIBS += -lqpe -lopiecore2 -lopieui2 -lqtaux2 26LIBS += -lqpe -lopiecore2 -lopieui2 -lqtaux2
25TARGET = opieirc 27TARGET = opieirc
26 28