author | wazlaf <wazlaf> | 2002-09-10 23:12:17 (UTC) |
---|---|---|
committer | wazlaf <wazlaf> | 2002-09-10 23:12:17 (UTC) |
commit | d478be344e2ba383a1e38d2a1705de1cdbe2e838 (patch) (unidiff) | |
tree | 9daf7b496c74c695ed8bd72a6ccd321f770b043c | |
parent | 2d6c8bd7290b766c31c100cd2d66ef0d1d0c407c (diff) | |
download | opie-d478be344e2ba383a1e38d2a1705de1cdbe2e838.zip opie-d478be344e2ba383a1e38d2a1705de1cdbe2e838.tar.gz opie-d478be344e2ba383a1e38d2a1705de1cdbe2e838.tar.bz2 |
initial import of OpieIRC v0.1
33 files changed, 2376 insertions, 0 deletions
diff --git a/noncore/net/opieirc/ircchannel.cpp b/noncore/net/opieirc/ircchannel.cpp new file mode 100644 index 0000000..71ec03b --- a/dev/null +++ b/noncore/net/opieirc/ircchannel.cpp | |||
@@ -0,0 +1,43 @@ | |||
1 | #include "ircchannel.h" | ||
2 | #include <stdio.h> | ||
3 | |||
4 | IRCChannel::IRCChannel(QString channelname) { | ||
5 | m_hasPeople = FALSE; | ||
6 | m_channelname = channelname; | ||
7 | } | ||
8 | |||
9 | QString IRCChannel::channelname() { | ||
10 | return m_channelname; | ||
11 | } | ||
12 | |||
13 | bool IRCChannel::hasPeople() { | ||
14 | return m_hasPeople; | ||
15 | } | ||
16 | |||
17 | void IRCChannel::setHasPeople(bool hasPeople) { | ||
18 | m_hasPeople = hasPeople; | ||
19 | } | ||
20 | |||
21 | void IRCChannel::addPerson(IRCChannelPerson *person) { | ||
22 | m_people.append(person); | ||
23 | } | ||
24 | |||
25 | void IRCChannel::removePerson(IRCChannelPerson *person) { | ||
26 | m_people.remove(person); | ||
27 | } | ||
28 | |||
29 | QListIterator<IRCChannelPerson> IRCChannel::people() { | ||
30 | QListIterator<IRCChannelPerson> it(m_people); | ||
31 | return it; | ||
32 | } | ||
33 | |||
34 | IRCChannelPerson *IRCChannel::getPerson(QString nickname) { | ||
35 | QListIterator<IRCChannelPerson> it(m_people); | ||
36 | for (; it.current(); ++it) { | ||
37 | if (it.current()->person->nick() == nickname) { | ||
38 | return it.current(); | ||
39 | } | ||
40 | } | ||
41 | return 0; | ||
42 | } | ||
43 | |||
diff --git a/noncore/net/opieirc/ircchannel.h b/noncore/net/opieirc/ircchannel.h new file mode 100644 index 0000000..c800b99 --- a/dev/null +++ b/noncore/net/opieirc/ircchannel.h | |||
@@ -0,0 +1,68 @@ | |||
1 | /* | ||
2 | OpieIRC - An embedded IRC client | ||
3 | Copyright (C) 2002 Wenzel Jakob | ||
4 | |||
5 | This program is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published by | ||
7 | the Free Software Foundation; either version 2 of the License, or | ||
8 | (at your option) any later version. | ||
9 | |||
10 | This program is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | ||
14 | |||
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 | ||
17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | |||
19 | */ | ||
20 | |||
21 | #ifndef __IRCCHANNEL_H | ||
22 | #define __IRCCHANNEL_H | ||
23 | |||
24 | #include <qobject.h> | ||
25 | #include <qlist.h> | ||
26 | #include <qstring.h> | ||
27 | #include "ircperson.h" | ||
28 | |||
29 | /* Flags which a person can have inside a channel */ | ||
30 | enum IRCChannelPersonFlag { | ||
31 | PERSON_FLAG_OP = 0x01, | ||
32 | PERSON_FLAG_VOICE = 0x02, | ||
33 | PERSON_FLAG_HALFOP = 0x04 | ||
34 | }; | ||
35 | |||
36 | /* This struct encapsulates a IRCPerson and adds | ||
37 | channel specific information */ | ||
38 | typedef struct IRCChannelPerson { | ||
39 | IRCPerson *person; | ||
40 | unsigned int flags; | ||
41 | }; | ||
42 | |||
43 | /* IRCChannel is the object-oriented representation | ||
44 | of an IRC channel. It basically acts as a container | ||
45 | for IRCChannelPersons */ | ||
46 | class IRCChannel : public QObject { | ||
47 | Q_OBJECT | ||
48 | public: | ||
49 | IRCChannel(QString channelname); | ||
50 | |||
51 | void addPerson(IRCChannelPerson *person); | ||
52 | void removePerson(IRCChannelPerson *person); | ||
53 | IRCChannelPerson *getPerson(QString nickname); | ||
54 | QListIterator<IRCChannelPerson> people(); | ||
55 | |||
56 | /* hasPeople identifies whether the irc channel is | ||
57 | done synchronizing with the current state - | ||
58 | this is only relevant when joining a channel */ | ||
59 | void setHasPeople(bool hasPeople); | ||
60 | QString channelname(); | ||
61 | bool hasPeople(); | ||
62 | protected: | ||
63 | QList<IRCChannelPerson> m_people; | ||
64 | QString m_channelname; | ||
65 | bool m_hasPeople; | ||
66 | }; | ||
67 | |||
68 | #endif /* __IRCCHANNEL_H */ | ||
diff --git a/noncore/net/opieirc/ircchannellist.cpp b/noncore/net/opieirc/ircchannellist.cpp new file mode 100644 index 0000000..e592d05 --- a/dev/null +++ b/noncore/net/opieirc/ircchannellist.cpp | |||
@@ -0,0 +1,37 @@ | |||
1 | #include <qpe/resource.h> | ||
2 | #include <qpixmap.h> | ||
3 | #include "ircchannellist.h" | ||
4 | |||
5 | IRCChannelList::IRCChannelList(IRCChannel *channel, QWidget *parent, const char *name, WFlags f) : QListBox(parent, name, f) { | ||
6 | m_channel = channel; | ||
7 | } | ||
8 | |||
9 | void IRCChannelList::update() { | ||
10 | QPixmap op = Resource::loadPixmap("opieirc/op"); | ||
11 | QPixmap hop = Resource::loadPixmap("opieirc/hop"); | ||
12 | QPixmap voice = Resource::loadPixmap("opieirc/voice"); | ||
13 | QListIterator<IRCChannelPerson> it = m_channel->people(); | ||
14 | clear(); | ||
15 | for (; it.current(); ++it) { | ||
16 | IRCChannelPerson *person = it.current(); | ||
17 | if (person->flags & PERSON_FLAG_OP) { | ||
18 | insertItem(op, person->person->nick()); | ||
19 | } else if (person->flags & PERSON_FLAG_HALFOP) { | ||
20 | insertItem(op, person->person->nick()); | ||
21 | } else if (person->flags & PERSON_FLAG_VOICE) { | ||
22 | insertItem(voice, person->person->nick()); | ||
23 | } else { | ||
24 | insertItem(person->person->nick()); | ||
25 | } | ||
26 | } | ||
27 | sort(); | ||
28 | } | ||
29 | |||
30 | |||
31 | bool IRCChannelList::hasPerson(QString nick) { | ||
32 | for (unsigned int i=0; i<count(); i++) { | ||
33 | if (text(i) == nick) | ||
34 | return TRUE; | ||
35 | } | ||
36 | return FALSE; | ||
37 | } | ||
diff --git a/noncore/net/opieirc/ircchannellist.h b/noncore/net/opieirc/ircchannellist.h new file mode 100644 index 0000000..fa3c8cd --- a/dev/null +++ b/noncore/net/opieirc/ircchannellist.h | |||
@@ -0,0 +1,36 @@ | |||
1 | /* | ||
2 | OpieIRC - An embedded IRC client | ||
3 | Copyright (C) 2002 Wenzel Jakob | ||
4 | |||
5 | This program is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published by | ||
7 | the Free Software Foundation; either version 2 of the License, or | ||
8 | (at your option) any later version. | ||
9 | |||
10 | This program is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | ||
14 | |||
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 | ||
17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | |||
19 | */ | ||
20 | |||
21 | #ifndef __IRCCHANNELLIST_H | ||
22 | #define __IRCCHANNELLIST_H | ||
23 | |||
24 | #include <qlistbox.h> | ||
25 | #include "ircchannel.h" | ||
26 | |||
27 | class IRCChannelList : public QListBox { | ||
28 | public: | ||
29 | IRCChannelList(IRCChannel *channel, QWidget *parent = 0, const char *name = 0, WFlags f = 0); | ||
30 | void update(); | ||
31 | bool hasPerson(QString nick); | ||
32 | protected: | ||
33 | IRCChannel *m_channel; | ||
34 | }; | ||
35 | |||
36 | #endif /* __IRCCHANNELLIST_H */ | ||
diff --git a/noncore/net/opieirc/ircchanneltab.cpp b/noncore/net/opieirc/ircchanneltab.cpp new file mode 100644 index 0000000..c96a365 --- a/dev/null +++ b/noncore/net/opieirc/ircchanneltab.cpp | |||
@@ -0,0 +1,77 @@ | |||
1 | #include <qhbox.h> | ||
2 | #include "ircchanneltab.h" | ||
3 | #include "ircservertab.h" | ||
4 | |||
5 | IRCChannelTab::IRCChannelTab(IRCChannel *channel, 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_channel = channel; | ||
9 | m_description->setText(tr("Talking on channel") + " <b>" + channel->channelname() + "</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_listVisible = TRUE; | ||
15 | m_listButton = new QPushButton(">", m_textview); | ||
16 | m_textview->setCornerWidget(m_listButton); | ||
17 | connect(m_listButton, SIGNAL(clicked()), this, SLOT(toggleList())); | ||
18 | m_list = new IRCChannelList(m_channel, hbox); | ||
19 | m_list->update(); | ||
20 | m_list->setMaximumWidth(LISTWIDTH); | ||
21 | m_field = new QLineEdit(this); | ||
22 | m_layout->add(hbox); | ||
23 | hbox->show(); | ||
24 | m_layout->add(m_field); | ||
25 | m_field->setFocus(); | ||
26 | connect(m_field, SIGNAL(returnPressed()), this, SLOT(processCommand())); | ||
27 | |||
28 | } | ||
29 | |||
30 | void IRCChannelTab::appendText(QString text) { | ||
31 | /* not using append because it creates layout problems */ | ||
32 | m_textview->setText(m_textview->text() + text); | ||
33 | m_textview->ensureVisible(0, m_textview->contentsHeight()); | ||
34 | } | ||
35 | |||
36 | IRCChannelTab::~IRCChannelTab() { | ||
37 | m_parentTab->removeChannelTab(this); | ||
38 | } | ||
39 | |||
40 | void IRCChannelTab::processCommand() { | ||
41 | if (m_field->text().length()>0) { | ||
42 | session()->sendMessage(m_channel, m_field->text()); | ||
43 | appendText("<<font color=\"#dd0000\">"+m_parentTab->server()->nick()+"</font>> "+m_field->text()+"<br>"); | ||
44 | m_field->clear(); | ||
45 | } | ||
46 | } | ||
47 | |||
48 | void IRCChannelTab::toggleList() { | ||
49 | if (m_listVisible) { | ||
50 | m_list->setMaximumWidth(0); | ||
51 | m_listButton->setText("<"); | ||
52 | } else { | ||
53 | m_list->setMaximumWidth(LISTWIDTH); | ||
54 | m_listButton->setText(">"); | ||
55 | } | ||
56 | m_listVisible = !m_listVisible; | ||
57 | } | ||
58 | |||
59 | QString IRCChannelTab::title() { | ||
60 | return m_channel->channelname(); | ||
61 | } | ||
62 | |||
63 | IRCSession *IRCChannelTab::session() { | ||
64 | return m_parentTab->session(); | ||
65 | } | ||
66 | |||
67 | void IRCChannelTab::remove() { | ||
68 | session()->part(m_channel); | ||
69 | } | ||
70 | |||
71 | IRCChannel *IRCChannelTab::channel() { | ||
72 | return m_channel; | ||
73 | } | ||
74 | |||
75 | IRCChannelList *IRCChannelTab::list() { | ||
76 | return m_list; | ||
77 | } | ||
diff --git a/noncore/net/opieirc/ircchanneltab.h b/noncore/net/opieirc/ircchanneltab.h new file mode 100644 index 0000000..2127c4d --- a/dev/null +++ b/noncore/net/opieirc/ircchanneltab.h | |||
@@ -0,0 +1,60 @@ | |||
1 | /* | ||
2 | OpieIRC - An embedded IRC client | ||
3 | Copyright (C) 2002 Wenzel Jakob | ||
4 | |||
5 | This program is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published by | ||
7 | the Free Software Foundation; either version 2 of the License, or | ||
8 | (at your option) any later version. | ||
9 | |||
10 | This program is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | ||
14 | |||
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 | ||
17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | |||
19 | */ | ||
20 | |||
21 | #ifndef __IRCCHANNELTAB_H | ||
22 | #define __IRCCHANNELTAB_H | ||
23 | |||
24 | #include <qpushbutton.h> | ||
25 | #include "irctab.h" | ||
26 | #include "ircsession.h" | ||
27 | #include "mainwindow.h" | ||
28 | #include "ircchannellist.h" | ||
29 | |||
30 | #define LISTWIDTH 70 | ||
31 | |||
32 | class IRCServerTab; | ||
33 | class IRCChannelTab : public IRCTab { | ||
34 | Q_OBJECT | ||
35 | public: | ||
36 | /* IRCTab implementation */ | ||
37 | IRCChannelTab(IRCChannel *channel, IRCServerTab *parentTab, MainWindow *mainWindow, QWidget *parent = 0, const char *name = 0, WFlags f = 0); | ||
38 | ~IRCChannelTab(); | ||
39 | QString title(); | ||
40 | IRCSession *session(); | ||
41 | IRCChannel *channel(); | ||
42 | IRCChannelList *list(); | ||
43 | public: | ||
44 | void appendText(QString text); | ||
45 | public slots: | ||
46 | void remove(); | ||
47 | void processCommand(); | ||
48 | void toggleList(); | ||
49 | protected: | ||
50 | IRCServerTab *m_parentTab; | ||
51 | IRCChannel *m_channel; | ||
52 | IRCChannelList *m_list; | ||
53 | QPushButton *m_listButton; | ||
54 | MainWindow *m_mainWindow; | ||
55 | QTextView *m_textview; | ||
56 | QLineEdit *m_field; | ||
57 | bool m_listVisible; | ||
58 | }; | ||
59 | |||
60 | #endif /* __IRCCHANNELTAB_H */ | ||
diff --git a/noncore/net/opieirc/ircconnection.cpp b/noncore/net/opieirc/ircconnection.cpp new file mode 100644 index 0000000..02c4897 --- a/dev/null +++ b/noncore/net/opieirc/ircconnection.cpp | |||
@@ -0,0 +1,94 @@ | |||
1 | #include <unistd.h> | ||
2 | #include <string.h> | ||
3 | #include "ircconnection.h" | ||
4 | |||
5 | IRCConnection::IRCConnection(IRCServer *server) { | ||
6 | m_server = server; | ||
7 | m_socket = new QSocket(this); | ||
8 | m_connected = FALSE; | ||
9 | m_loggedIn = FALSE; | ||
10 | connect(m_socket, SIGNAL(connected()), this, SLOT(login())); | ||
11 | connect(m_socket, SIGNAL(readyRead()), this, SLOT(dataReady())); | ||
12 | connect(m_socket, SIGNAL(error(int)), this, SLOT(error(int))); | ||
13 | connect(m_socket, SIGNAL(connectionClosed()), this, SLOT(disconnect())); | ||
14 | connect(m_socket, SIGNAL(delayedCloseFinished()), this, SLOT(disconnect())); | ||
15 | } | ||
16 | |||
17 | /* Connect to the IRC server */ | ||
18 | void IRCConnection::doConnect() { | ||
19 | ASSERT(!m_connected); | ||
20 | m_socket->connectToHost(m_server->hostname(), m_server->port()); | ||
21 | } | ||
22 | |||
23 | /* Send commands to the IRC server */ | ||
24 | void IRCConnection::sendLine(QString line) { | ||
25 | while((line.right(1) == "\n") || (line.right(1) == "\r")) | ||
26 | line = line.left(line.length() - 1); | ||
27 | line.append("\r\n"); | ||
28 | m_socket->writeBlock(line, line.length()); | ||
29 | } | ||
30 | |||
31 | void IRCConnection::sendCTCP(QString nick, QString line) { | ||
32 | sendLine("NOTICE " + nick + " :\001"+line+"\001"); | ||
33 | } | ||
34 | |||
35 | /* | ||
36 | * login() is called right after the connection | ||
37 | * to the IRC server has been established | ||
38 | */ | ||
39 | void IRCConnection::login() { | ||
40 | char hostname[256]; | ||
41 | QString loginString; | ||
42 | |||
43 | emit outputReady(IRCOutput(OUTPUT_CLIENTMESSAGE, tr("Connected, logging in .."))); | ||
44 | m_connected = TRUE; | ||
45 | gethostname(hostname, sizeof(hostname)-1); | ||
46 | hostname[sizeof (hostname) - 1] = 0; | ||
47 | |||
48 | /* Create a logon string and send it */ | ||
49 | if (m_server->password().length()>0) { | ||
50 | loginString += "PASS " + m_server->password() + "\r\n"; | ||
51 | } | ||
52 | loginString += "NICK " + m_server->nick() + "\r\n" + | ||
53 | "USER " + m_server->username() + " " + hostname + | ||
54 | " " + m_server->hostname() + " :" + m_server->realname() + "\r\n"; | ||
55 | sendLine(loginString); | ||
56 | } | ||
57 | |||
58 | /* Called when data arrives on the socket */ | ||
59 | void IRCConnection::dataReady() { | ||
60 | while(m_socket->canReadLine()) { | ||
61 | IRCMessage message(m_socket->readLine()); | ||
62 | if (!m_loggedIn && message.isNumerical() && message.commandNumber() == 1) { | ||
63 | m_loggedIn = TRUE; | ||
64 | emit outputReady(IRCOutput(OUTPUT_CLIENTMESSAGE, tr("Successfully logged in."))); | ||
65 | } | ||
66 | emit messageArrived(&message); | ||
67 | } | ||
68 | } | ||
69 | |||
70 | /* Called if any type of socket error occurs */ | ||
71 | void IRCConnection::error(int num) { | ||
72 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Socket error : ") + strerror(num))); | ||
73 | } | ||
74 | |||
75 | void IRCConnection::disconnect() { | ||
76 | m_connected = FALSE; | ||
77 | m_loggedIn = FALSE; | ||
78 | emit outputReady(IRCOutput(OUTPUT_CONNCLOSE, tr("Connection closed"))); | ||
79 | } | ||
80 | |||
81 | bool IRCConnection::isConnected() { | ||
82 | return m_connected; | ||
83 | } | ||
84 | |||
85 | bool IRCConnection::isLoggedIn() { | ||
86 | return m_loggedIn; | ||
87 | } | ||
88 | |||
89 | void IRCConnection::close() { | ||
90 | m_socket->close(); | ||
91 | if (m_socket->state()==QSocket::Idle) { | ||
92 | disconnect(); | ||
93 | } | ||
94 | } | ||
diff --git a/noncore/net/opieirc/ircconnection.h b/noncore/net/opieirc/ircconnection.h new file mode 100644 index 0000000..75cdf6d --- a/dev/null +++ b/noncore/net/opieirc/ircconnection.h | |||
@@ -0,0 +1,65 @@ | |||
1 | /* | ||
2 | OpieIRC - An embedded IRC client | ||
3 | Copyright (C) 2002 Wenzel Jakob | ||
4 | |||
5 | This program is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published by | ||
7 | the Free Software Foundation; either version 2 of the License, or | ||
8 | (at your option) any later version. | ||
9 | |||
10 | This program is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | ||
14 | |||
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 | ||
17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | |||
19 | */ | ||
20 | |||
21 | #ifndef __IRCCONNECTION_H | ||
22 | #define __IRCCONNECTION_H | ||
23 | |||
24 | #include <qsocket.h> | ||
25 | #include "ircserver.h" | ||
26 | #include "ircmessage.h" | ||
27 | #include "ircoutput.h" | ||
28 | |||
29 | /* IRCConnection acts as a wrapper around QSocket | ||
30 | and is responsible for the communication with the | ||
31 | IRC server */ | ||
32 | class IRCConnection : public QObject { | ||
33 | Q_OBJECT | ||
34 | public: | ||
35 | IRCConnection(IRCServer *server); | ||
36 | void doConnect(); | ||
37 | /* used to send commands to the IRC server */ | ||
38 | void sendLine(QString line); | ||
39 | /* used to send CTCP commands to the IRC server */ | ||
40 | void sendCTCP(QString nick, QString line); | ||
41 | void close(); | ||
42 | bool isConnected(); | ||
43 | bool isLoggedIn(); | ||
44 | signals: | ||
45 | /* triggered when the server sent us a message */ | ||
46 | void messageArrived(IRCMessage *message); | ||
47 | /* Used to send commands to the UI (such as displaying text etc) */ | ||
48 | void outputReady(IRCOutput output); | ||
49 | protected slots: | ||
50 | /* automatically executed after the connection is established */ | ||
51 | void login(); | ||
52 | /* called when there are socket errors */ | ||
53 | void error(int num); | ||
54 | /* called when data arrived on m_socket (triggers messageArrived) */ | ||
55 | void dataReady(); | ||
56 | /* called when the IRC server closes the connection */ | ||
57 | void disconnect(); | ||
58 | protected: | ||
59 | IRCServer *m_server; | ||
60 | QSocket *m_socket; | ||
61 | bool m_connected; | ||
62 | bool m_loggedIn; | ||
63 | }; | ||
64 | |||
65 | #endif /* __IRCCONNECTION_H */ | ||
diff --git a/noncore/net/opieirc/ircmessage.cpp b/noncore/net/opieirc/ircmessage.cpp new file mode 100644 index 0000000..74e9c6f --- a/dev/null +++ b/noncore/net/opieirc/ircmessage.cpp | |||
@@ -0,0 +1,120 @@ | |||
1 | #include <qtextstream.h> | ||
2 | #include "ircmessage.h" | ||
3 | |||
4 | /* | ||
5 | * Create a new IRCMessage by evaluating | ||
6 | * a received string | ||
7 | */ | ||
8 | |||
9 | IRCMessage::IRCMessage(QString line) { | ||
10 | /* Remove CRs from the message */ | ||
11 | while((line.right(1) == "\n") || (line.right(1) == "\r")) | ||
12 | line = line.left(line.length() - 1); | ||
13 | QTextIStream stream(&line); | ||
14 | QString temp; | ||
15 | |||
16 | stream >> temp; | ||
17 | if (temp.startsWith(":")) { | ||
18 | /* extract the prefix */ | ||
19 | m_prefix = temp.right(temp.length()-1); | ||
20 | stream >> temp; | ||
21 | m_command = temp.upper(); | ||
22 | m_allParameters = line.right(line.length() - m_prefix.length() - m_command.length() - 3); | ||
23 | } else { | ||
24 | m_command = temp.upper(); | ||
25 | m_allParameters = line.right(line.length() - m_command.length() - 1); | ||
26 | } | ||
27 | /* Create a list of all parameters */ | ||
28 | while(!(stream.atEnd())) { | ||
29 | stream >> temp; | ||
30 | if (temp.startsWith(":")) { | ||
31 | /* last parameter */ | ||
32 | m_trailing = line.right(line.length() - line.find(QChar(':'), 1) - 1); | ||
33 | m_parameters << m_trailing; | ||
34 | break; | ||
35 | } else { | ||
36 | m_parameters << temp; | ||
37 | } | ||
38 | } | ||
39 | m_commandNumber = m_command.toInt(&m_isNumerical); | ||
40 | /* Is this a CTCP command */ | ||
41 | if ((m_command == "PRIVMSG" || m_command == "NOTICE") && m_trailing.length()>0 && m_trailing.left(1) == QChar(1)) { | ||
42 | m_ctcp = TRUE; | ||
43 | /* Strip CTCP \001 characters */ | ||
44 | m_allParameters = m_allParameters.replace(QRegExp(QChar(1)), ""); | ||
45 | QTextIStream ctcpStream(&m_allParameters); | ||
46 | if (m_command == "PRIVMSG") | ||
47 | ctcpStream >> m_ctcpDestination; | ||
48 | ctcpStream >> temp; | ||
49 | m_ctcpCommand = temp.upper().right(temp.length()-1); | ||
50 | m_parameters.clear(); | ||
51 | int length = m_allParameters.length() - m_ctcpCommand.length() - 1; | ||
52 | if (m_command == "PRIVMSG") | ||
53 | length -= m_ctcpDestination.length() + 1; | ||
54 | if (length <= 0) { | ||
55 | m_allParameters = ""; | ||
56 | } else { | ||
57 | m_allParameters = m_allParameters.right(length); | ||
58 | m_parameters << m_allParameters; | ||
59 | } | ||
60 | } else { | ||
61 | m_ctcp = FALSE; | ||
62 | } | ||
63 | |||
64 | /* | ||
65 | -- Uncomment to debug -- | ||
66 | |||
67 | printf("Parsed : '%s'\n", line.ascii()); | ||
68 | printf("Prefix : '%s'\n", m_prefix.ascii()); | ||
69 | printf("Command : '%s'\n", m_command.ascii()); | ||
70 | printf("Allparameters : '%s'\n", m_allParameters.ascii()); | ||
71 | for (unsigned int i=0; i<m_parameters.count(); i++) { | ||
72 | printf("Parameter %i : '%s'\n", i, m_parameters[i].ascii()); | ||
73 | } | ||
74 | printf("CTCP Command : '%s'\n", m_ctcpCommand.latin1()); | ||
75 | printf("CTCP Destination : '%s'\n", m_ctcpDestination.latin1()); | ||
76 | printf("CTCP param count is : '%i'\n", m_parameters.count()); | ||
77 | |||
78 | */ | ||
79 | } | ||
80 | |||
81 | QString IRCMessage::param(int param) { | ||
82 | return m_parameters[param]; | ||
83 | } | ||
84 | |||
85 | QString IRCMessage::prefix() { | ||
86 | return m_prefix; | ||
87 | } | ||
88 | |||
89 | QString IRCMessage::command() { | ||
90 | return m_command; | ||
91 | } | ||
92 | |||
93 | QString IRCMessage::ctcpCommand() { | ||
94 | return m_ctcpCommand; | ||
95 | } | ||
96 | |||
97 | QString IRCMessage::ctcpDestination() { | ||
98 | return m_ctcpDestination; | ||
99 | } | ||
100 | |||
101 | unsigned short IRCMessage::commandNumber() { | ||
102 | return m_commandNumber; | ||
103 | } | ||
104 | |||
105 | bool IRCMessage::isNumerical() { | ||
106 | return m_isNumerical; | ||
107 | } | ||
108 | |||
109 | bool IRCMessage::isCTCP() { | ||
110 | return m_ctcp; | ||
111 | } | ||
112 | |||
113 | QString IRCMessage::trailing() { | ||
114 | return m_trailing; | ||
115 | } | ||
116 | |||
117 | QString IRCMessage::allParameters() { | ||
118 | return m_allParameters; | ||
119 | } | ||
120 | |||
diff --git a/noncore/net/opieirc/ircmessage.h b/noncore/net/opieirc/ircmessage.h new file mode 100644 index 0000000..0c5c879 --- a/dev/null +++ b/noncore/net/opieirc/ircmessage.h | |||
@@ -0,0 +1,68 @@ | |||
1 | /* | ||
2 | OpieIRC - An embedded IRC client | ||
3 | Copyright (C) 2002 Wenzel Jakob | ||
4 | |||
5 | This program is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published by | ||
7 | the Free Software Foundation; either version 2 of the License, or | ||
8 | (at your option) any later version. | ||
9 | |||
10 | This program is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | ||
14 | |||
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 | ||
17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | |||
19 | */ | ||
20 | |||
21 | #ifndef __IRCMESSAGE_H | ||
22 | #define __IRCMESSAGE_H | ||
23 | |||
24 | #include <qstring.h> | ||
25 | #include <qstringlist.h> | ||
26 | |||
27 | /* IRCMessage objects are used to encapsulate information | ||
28 | which the IRC server sent to us. */ | ||
29 | |||
30 | class IRCMessage { | ||
31 | public: | ||
32 | /* Parse an IRC message and create the IRCMessage object */ | ||
33 | IRCMessage(QString line); | ||
34 | |||
35 | /* Return the IRC message prefix (usually sender etc) */ | ||
36 | QString prefix(); | ||
37 | /* Check if this IRCMessage's command is literal or numerical */ | ||
38 | bool isNumerical(); | ||
39 | /* CHeck if this IRCMessage is a CTCP message */ | ||
40 | bool isCTCP(); | ||
41 | /* Return the IRC command (literal commands) */ | ||
42 | QString command(); | ||
43 | /* Return the CTCP command */ | ||
44 | QString ctcpCommand(); | ||
45 | /* Return the CTCP destination if applicable (channel/person) */ | ||
46 | QString ctcpDestination(); | ||
47 | /* Return the IRC command (numerical commands) */ | ||
48 | unsigned short commandNumber(); | ||
49 | /* Return the trailing parameter string */ | ||
50 | QString trailing(); | ||
51 | /* Return the complete parameter string */ | ||
52 | QString allParameters(); | ||
53 | /* Return one parameter */ | ||
54 | QString param(int param); | ||
55 | protected: | ||
56 | QString m_prefix; | ||
57 | QString m_command; | ||
58 | QString m_ctcpCommand; | ||
59 | QString m_ctcpDestination; | ||
60 | unsigned short m_commandNumber; | ||
61 | QString m_allParameters; | ||
62 | QString m_trailing; | ||
63 | QStringList m_parameters; | ||
64 | bool m_isNumerical; | ||
65 | bool m_ctcp; | ||
66 | }; | ||
67 | |||
68 | #endif | ||
diff --git a/noncore/net/opieirc/ircmessageparser.cpp b/noncore/net/opieirc/ircmessageparser.cpp new file mode 100644 index 0000000..a2be5a4 --- a/dev/null +++ b/noncore/net/opieirc/ircmessageparser.cpp | |||
@@ -0,0 +1,478 @@ | |||
1 | #include <qtextstream.h> | ||
2 | #include "ircmessageparser.h" | ||
3 | #include "ircversion.h" | ||
4 | #include <stdio.h> | ||
5 | |||
6 | /* Lookup table for literal commands */ | ||
7 | IRCLiteralMessageParserStruct IRCMessageParser::literalParserProcTable[] = { | ||
8 | { "PING", FUNC(parseLiteralPing) }, | ||
9 | { "NOTICE", FUNC(parseLiteralNotice) }, | ||
10 | { "JOIN", FUNC(parseLiteralJoin) }, | ||
11 | { "PRIVMSG", FUNC(parseLiteralPrivMsg) }, | ||
12 | { "NICK", FUNC(parseLiteralNick) }, | ||
13 | { "PART", FUNC(parseLiteralPart) }, | ||
14 | { "QUIT", FUNC(parseLiteralQuit) }, | ||
15 | { "ERROR", FUNC(parseLiteralError) }, | ||
16 | { "ERROR:", FUNC(parseLiteralError) }, | ||
17 | { "MODE", FUNC(parseLiteralMode) }, | ||
18 | { "KICK", FUNC(parseLiteralKick) }, | ||
19 | { 0 , 0 } | ||
20 | }; | ||
21 | |||
22 | /* Lookup table for literal commands */ | ||
23 | IRCCTCPMessageParserStruct IRCMessageParser::ctcpParserProcTable[] = { | ||
24 | { "PING", FUNC(parseCTCPPing) }, | ||
25 | { "VERSION", FUNC(parseCTCPVersion) }, | ||
26 | { "ACTION", FUNC(parseCTCPAction) }, | ||
27 | { 0 , 0 } | ||
28 | }; | ||
29 | /* Lookup table for numerical commands */ | ||
30 | IRCNumericalMessageParserStruct IRCMessageParser::numericalParserProcTable[] = { | ||
31 | { 1, FUNC(parseNumerical001) }, // RPL_WELCOME | ||
32 | { 2, FUNC(parseNumerical002) }, // RPL_YOURHOST | ||
33 | { 3, FUNC(parseNumerical003) }, // RPL_CREATED | ||
34 | { 4, FUNC(parseNumerical004) }, // RPL_MYINFO | ||
35 | { 5, FUNC(parseNumerical005) }, // RPL_BOUNCE, RPL_PROTOCTL | ||
36 | { 251, FUNC(parseNumericalStats) }, // RPL_LUSERCLIENT | ||
37 | { 254, FUNC(nullFunc)}, // RPL_LUSERCHANNELS | ||
38 | { 255, FUNC(parseNumericalStats) }, // RPL_LUSERNAME | ||
39 | { 353, FUNC(parseNumericalNames) }, // RPL_NAMREPLY | ||
40 | { 366, FUNC(parseNumericalEndOfNames) }, // RPL_ENDOFNAMES | ||
41 | { 375, FUNC(parseNumericalStats) }, // RPL_MOTDSTART | ||
42 | { 372, FUNC(parseNumericalStats) }, // RPL_MOTD | ||
43 | { 376, FUNC(parseNumericalStats) }, // RPL_ENDOFMOTD | ||
44 | { 377, FUNC(parseNumericalStats) }, // RPL_MOTD2 | ||
45 | { 378, FUNC(parseNumericalStats) }, // RPL_MOTD3 | ||
46 | { 412, FUNC(parseNumericalStats) }, // ERNOTEXTTOSEND | ||
47 | { 433, FUNC(parseNumericalNicknameInUse) }, // ERR_NICKNAMEINUSE | ||
48 | { 0, 0 } | ||
49 | }; | ||
50 | |||
51 | IRCMessageParser::IRCMessageParser(IRCSession *session) { | ||
52 | m_session = session; | ||
53 | } | ||
54 | |||
55 | void IRCMessageParser::parse(IRCMessage *message) { | ||
56 | /* Find out what kind of message we have here and call the appropriate handler using | ||
57 | the parser tables. If no handler can be found, print out an error message */ | ||
58 | if (message->isNumerical()) { | ||
59 | for (int i=0; i<numericalParserProcTable[i].commandNumber; i++) { | ||
60 | if (message->commandNumber() == numericalParserProcTable[i].commandNumber) { | ||
61 | (this->*(numericalParserProcTable[i].proc))(message); | ||
62 | return; | ||
63 | } | ||
64 | } | ||
65 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received unhandled numeric command : ")+QString::number(message->commandNumber()))); | ||
66 | } else if (message->isCTCP()) { | ||
67 | for (int i=0; ctcpParserProcTable[i].commandName; i++) { | ||
68 | if (message->ctcpCommand() == ctcpParserProcTable[i].commandName) { | ||
69 | (this->*(ctcpParserProcTable[i].proc))(message); | ||
70 | return; | ||
71 | } | ||
72 | } | ||
73 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received unhandled ctcp command : ")+message->ctcpCommand())); | ||
74 | } else { | ||
75 | for (int i=0; literalParserProcTable[i].commandName; i++) { | ||
76 | if (message->command() == literalParserProcTable[i].commandName) { | ||
77 | (this->*(literalParserProcTable[i].proc))(message); | ||
78 | return; | ||
79 | } | ||
80 | } | ||
81 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received unhandled literal command : ")+message->command())); | ||
82 | } | ||
83 | } | ||
84 | |||
85 | void IRCMessageParser::nullFunc(IRCMessage *) { | ||
86 | /* Do nothing */ | ||
87 | } | ||
88 | |||
89 | void IRCMessageParser::parseLiteralPing(IRCMessage *message) { | ||
90 | m_session->m_connection->sendLine("PONG " + message->allParameters()); | ||
91 | } | ||
92 | |||
93 | void IRCMessageParser::parseLiteralNotice(IRCMessage *message) { | ||
94 | emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, message->allParameters())); | ||
95 | } | ||
96 | |||
97 | void IRCMessageParser::parseLiteralJoin(IRCMessage *message) { | ||
98 | QString channelName = message->param(0); | ||
99 | IRCPerson mask(message->prefix()); | ||
100 | IRCChannel *channel = m_session->getChannel(channelName); | ||
101 | if (!channel) { | ||
102 | /* We joined */ | ||
103 | if (mask.nick() == m_session->m_server->nick()) { | ||
104 | channel = new IRCChannel(channelName); | ||
105 | m_session->addChannel(channel); | ||
106 | } else { | ||
107 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Nonexistant channel join - desynchronized?"))); | ||
108 | } | ||
109 | } else { | ||
110 | /* Someone else joined */ | ||
111 | if (mask.nick() != m_session->m_server->nick()) { | ||
112 | if (!channel->getPerson(mask.nick())) { | ||
113 | IRCChannelPerson *chanperson = new IRCChannelPerson(); | ||
114 | IRCPerson *person = m_session->getPerson(mask.nick()); | ||
115 | if (!person) { | ||
116 | person = new IRCPerson(message->prefix()); | ||
117 | m_session->addPerson(person); | ||
118 | } | ||
119 | chanperson->flags = 0; | ||
120 | chanperson->person = person; | ||
121 | channel->addPerson(chanperson); | ||
122 | IRCOutput output(OUTPUT_OTHERJOIN, mask.nick() + tr(" joined channel ") + channelName); | ||
123 | output.addParam(channel); | ||
124 | output.addParam(chanperson); | ||
125 | emit outputReady(output); | ||
126 | } else { | ||
127 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Person has already joined the channel - desynchronized?"))); | ||
128 | } | ||
129 | } else { | ||
130 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("You already joined the channel - desynchronized?"))); | ||
131 | } | ||
132 | } | ||
133 | } | ||
134 | |||
135 | void IRCMessageParser::parseLiteralPart(IRCMessage *message) { | ||
136 | QString channelName = message->param(0); | ||
137 | IRCChannel *channel = m_session->getChannel(channelName); | ||
138 | IRCPerson mask(message->prefix()); | ||
139 | if (channel) { | ||
140 | if (mask.nick() == m_session->m_server->nick()) { | ||
141 | m_session->removeChannel(channel); | ||
142 | IRCOutput output(OUTPUT_SELFPART, tr("You left channel ") + channelName); | ||
143 | output.addParam(channel); | ||
144 | emit outputReady(output); | ||
145 | delete channel; | ||
146 | } else { | ||
147 | IRCChannelPerson *person = channel->getPerson(mask.nick()); | ||
148 | if (person) { | ||
149 | channel->removePerson(person); | ||
150 | IRCOutput output(OUTPUT_OTHERPART, mask.nick() + tr(" left channel ") + channelName); | ||
151 | output.addParam(channel); | ||
152 | output.addParam(person); | ||
153 | emit outputReady(output); | ||
154 | delete person; | ||
155 | } else { | ||
156 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Parting person not found - desynchronized?"))); | ||
157 | } | ||
158 | } | ||
159 | } else { | ||
160 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Channel for part not found - desynchronized?"))); | ||
161 | } | ||
162 | } | ||
163 | |||
164 | void IRCMessageParser::parseLiteralPrivMsg(IRCMessage *message) { | ||
165 | if (m_session->m_server->nick() == message->param(0)) { | ||
166 | /* IRC Query message detected, verify sender and display it */ | ||
167 | IRCPerson mask(message->prefix()); | ||
168 | IRCPerson *person = m_session->getPerson(mask.nick()); | ||
169 | if (!person) { | ||
170 | /* Person not yet known, create and add to the current session */ | ||
171 | person = new IRCPerson(message->prefix()); | ||
172 | m_session->addPerson(person); | ||
173 | } | ||
174 | IRCOutput output(OUTPUT_CHANPRIVMSG, message->param(1)); | ||
175 | output.addParam(person); | ||
176 | emit outputReady(output); | ||
177 | } else if (message->param(0).at(0) == '#') { | ||
178 | /* IRC Channel message detected, verify sender, channel and display it */ | ||
179 | IRCChannel *channel = m_session->getChannel(message->param(0)); | ||
180 | if (channel) { | ||
181 | IRCPerson mask(message->prefix()); | ||
182 | IRCChannelPerson *person = channel->getPerson(mask.nick()); | ||
183 | if (person) { | ||
184 | IRCOutput output(OUTPUT_CHANPRIVMSG, message->param(1)); | ||
185 | output.addParam(channel); | ||
186 | output.addParam(person); | ||
187 | emit outputReady(output); | ||
188 | } else { | ||
189 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Channel message with unknown sender"))); | ||
190 | } | ||
191 | } else { | ||
192 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Channel message with unknown channel"))); | ||
193 | } | ||
194 | } else { | ||
195 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received PRIVMSG of unknown type"))); | ||
196 | } | ||
197 | } | ||
198 | |||
199 | void IRCMessageParser::parseLiteralNick(IRCMessage *message) { | ||
200 | IRCPerson mask(message->prefix()); | ||
201 | |||
202 | if (mask.nick() == m_session->m_server->nick()) { | ||
203 | /* We are changing our nickname */ | ||
204 | m_session->m_server->setNick(message->param(0)); | ||
205 | IRCOutput output(OUTPUT_NICKCHANGE, tr("You are now known as ")+message->param(0)); | ||
206 | output.addParam(0); | ||
207 | emit outputReady(output); | ||
208 | } else { | ||
209 | /* Someone else is */ | ||
210 | IRCPerson *person = m_session->getPerson(mask.nick()); | ||
211 | if (person) { | ||
212 | IRCOutput output(OUTPUT_NICKCHANGE, mask.nick() + tr(" is now known as ") + message->param(0)); | ||
213 | output.addParam(person); | ||
214 | emit outputReady(output); | ||
215 | } else { | ||
216 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Nickname change of an unknown person"))); | ||
217 | } | ||
218 | } | ||
219 | } | ||
220 | |||
221 | void IRCMessageParser::parseLiteralQuit(IRCMessage *message) { | ||
222 | IRCPerson mask(message->prefix()); | ||
223 | IRCPerson *person = m_session->getPerson(mask.nick()); | ||
224 | if (person) { | ||
225 | QList<IRCChannel> channels; | ||
226 | m_session->getChannelsByPerson(person, channels); | ||
227 | QListIterator<IRCChannel> it(channels); | ||
228 | for (;it.current(); ++it) { | ||
229 | IRCChannelPerson *chanperson = it.current()->getPerson(mask.nick()); | ||
230 | it.current()->removePerson(chanperson); | ||
231 | } | ||
232 | m_session->removePerson(person); | ||
233 | IRCOutput output(OUTPUT_QUIT, mask.nick() + tr(" has quit ") + "(" + message->param(0) + ")"); | ||
234 | output.addParam(person); | ||
235 | emit outputReady(output); | ||
236 | } else { | ||
237 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown person quit - desynchronized?"))); | ||
238 | } | ||
239 | } | ||
240 | |||
241 | void IRCMessageParser::parseLiteralError(IRCMessage *message) { | ||
242 | emit outputReady(IRCOutput(OUTPUT_ERROR, message->allParameters())); | ||
243 | } | ||
244 | |||
245 | void IRCMessageParser::parseCTCPPing(IRCMessage *message) { | ||
246 | IRCPerson mask(message->prefix()); | ||
247 | m_session->m_connection->sendCTCP(mask.nick(), "PING " + message->allParameters()); | ||
248 | emit outputReady(IRCOutput(OUTPUT_CTCP, tr("Received a CTCP PING from ")+mask.nick())); | ||
249 | } | ||
250 | |||
251 | void IRCMessageParser::parseCTCPVersion(IRCMessage *message) { | ||
252 | IRCPerson mask(message->prefix()); | ||
253 | m_session->m_connection->sendCTCP(mask.nick(), APP_VERSION " " APP_COPYSTR); | ||
254 | emit outputReady(IRCOutput(OUTPUT_CTCP, tr("Received a CTCP VERSION from ")+mask.nick())); | ||
255 | } | ||
256 | |||
257 | void IRCMessageParser::parseCTCPAction(IRCMessage *message) { | ||
258 | IRCPerson mask(message->prefix()); | ||
259 | QString dest = message->ctcpDestination(); | ||
260 | if (dest.startsWith("#")) { | ||
261 | IRCChannel *channel = m_session->getChannel(dest); | ||
262 | if (channel) { | ||
263 | IRCChannelPerson *person = channel->getPerson(mask.nick()); | ||
264 | if (person) { | ||
265 | IRCOutput output(OUTPUT_CHANACTION, "*" + mask.nick() + message->param(0)); | ||
266 | output.addParam(channel); | ||
267 | output.addParam(person); | ||
268 | emit outputReady(output); | ||
269 | } else { | ||
270 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP ACTION with unknown person - Desynchronized?"))); | ||
271 | } | ||
272 | } else { | ||
273 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP ACTION with unknown channel - Desynchronized?"))); | ||
274 | } | ||
275 | } else { | ||
276 | if (message->ctcpDestination() == m_session->m_server->nick()) { | ||
277 | IRCPerson *person = m_session->getPerson(mask.nick()); | ||
278 | if (!person) { | ||
279 | /* Person not yet known, create and add to the current session */ | ||
280 | person = new IRCPerson(message->prefix()); | ||
281 | m_session->addPerson(person); | ||
282 | } | ||
283 | IRCOutput output(OUTPUT_QUERYACTION, "*" + mask.nick() + message->param(0)); | ||
284 | output.addParam(person); | ||
285 | emit outputReady(output); | ||
286 | } else { | ||
287 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP ACTION with bad recipient"))); | ||
288 | } | ||
289 | } | ||
290 | } | ||
291 | |||
292 | void IRCMessageParser::parseLiteralMode(IRCMessage *message) { | ||
293 | IRCPerson mask(message->prefix()); | ||
294 | |||
295 | if (message->param(0).startsWith("#")) { | ||
296 | IRCChannel *channel = m_session->getChannel(message->param(0)); | ||
297 | if (channel) { | ||
298 | QString temp, parameters = message->allParameters().right(message->allParameters().length() - channel->channelname().length() - 1); | ||
299 | QTextIStream stream(¶meters); | ||
300 | bool set = FALSE; | ||
301 | while (!stream.atEnd()) { | ||
302 | stream >> temp; | ||
303 | if (temp.startsWith("+")) { | ||
304 | set = TRUE; | ||
305 | temp = temp.right(1); | ||
306 | } else if (temp.startsWith("-")) { | ||
307 | set = FALSE; | ||
308 | temp = temp.right(1); | ||
309 | } else { | ||
310 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change has unknown type"))); | ||
311 | return; | ||
312 | } | ||
313 | if (temp == "o") { | ||
314 | stream >> temp; | ||
315 | IRCChannelPerson *person = channel->getPerson(temp); | ||
316 | if (person) { | ||
317 | if (set) { | ||
318 | person->flags |= PERSON_FLAG_OP; | ||
319 | IRCOutput output(OUTPUT_CHANPERSONMODE, mask.nick() + tr(" gives channel operator status to " + person->person->nick())); | ||
320 | output.addParam(channel); | ||
321 | output.addParam(person); | ||
322 | emit outputReady(output); | ||
323 | } else { | ||
324 | person->flags &= 0xFFFF - PERSON_FLAG_OP; | ||
325 | IRCOutput output(OUTPUT_CHANPERSONMODE, mask.nick() + tr(" removes channel operator status from " + person->person->nick())); | ||
326 | output.addParam(channel); | ||
327 | output.addParam(person); | ||
328 | emit outputReady(output); | ||
329 | } | ||
330 | } else { | ||
331 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown person - Desynchronized?"))); | ||
332 | } | ||
333 | } else if (temp == "v") { | ||
334 | stream >> temp; | ||
335 | IRCChannelPerson *person = channel->getPerson(temp); | ||
336 | if (person) { | ||
337 | if (set) { | ||
338 | person->flags |= PERSON_FLAG_VOICE; | ||
339 | IRCOutput output(OUTPUT_CHANPERSONMODE, mask.nick() + tr(" gives voice to " + person->person->nick())); | ||
340 | output.addParam(channel); | ||
341 | output.addParam(person); | ||
342 | emit outputReady(output); | ||
343 | } else { | ||
344 | person->flags &= 0xFFFF - PERSON_FLAG_VOICE; | ||
345 | IRCOutput output(OUTPUT_CHANPERSONMODE, mask.nick() + tr(" removes voice from " + person->person->nick())); | ||
346 | output.addParam(channel); | ||
347 | output.addParam(person); | ||
348 | emit outputReady(output); | ||
349 | } | ||
350 | } else { | ||
351 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown person - Desynchronized?"))); | ||
352 | } | ||
353 | } else { | ||
354 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown flag"))); | ||
355 | } | ||
356 | } | ||
357 | } else { | ||
358 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown kannel - Desynchronized?"))); | ||
359 | } | ||
360 | } else { | ||
361 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("User modes not supported yet"))); | ||
362 | } | ||
363 | } | ||
364 | |||
365 | void IRCMessageParser::parseLiteralKick(IRCMessage *message) { | ||
366 | IRCPerson mask(message->prefix()); | ||
367 | IRCChannel *channel = m_session->getChannel(message->param(0)); | ||
368 | if (channel) { | ||
369 | IRCChannelPerson *person = channel->getPerson(message->param(1)); | ||
370 | if (person) { | ||
371 | if (person->person->nick() == m_session->m_server->nick()) { | ||
372 | m_session->removeChannel(channel); | ||
373 | IRCOutput output(OUTPUT_SELFKICK, tr("You were kicked from ") + channel->channelname() + tr(" by ") + mask.nick() + " (" + message->param(2) + ")"); | ||
374 | output.addParam(channel); | ||
375 | emit outputReady(output); | ||
376 | } else { | ||
377 | channel->removePerson(person); | ||
378 | IRCOutput output(OUTPUT_OTHERKICK, person->person->nick() + tr(" was kicked from ") + channel->channelname() + tr(" by ") + mask.nick()+ " (" + message->param(2) + ")"); | ||
379 | output.addParam(channel); | ||
380 | output.addParam(person); | ||
381 | emit outputReady(output); | ||
382 | } | ||
383 | } else { | ||
384 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown person kick - desynchronized?"))); | ||
385 | } | ||
386 | } else { | ||
387 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown channel kick - desynchronized?"))); | ||
388 | } | ||
389 | } | ||
390 | |||
391 | void IRCMessageParser::parseNumerical001(IRCMessage *message) { | ||
392 | /* Welcome to IRC message, display */ | ||
393 | emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, message->param(1))); | ||
394 | } | ||
395 | |||
396 | void IRCMessageParser::parseNumerical002(IRCMessage *message) { | ||
397 | emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, message->param(1))); | ||
398 | } | ||
399 | |||
400 | void IRCMessageParser::parseNumerical003(IRCMessage *message) { | ||
401 | emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, message->param(1))); | ||
402 | } | ||
403 | |||
404 | void IRCMessageParser::parseNumerical004(IRCMessage *message) { | ||
405 | emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, message->allParameters())); | ||
406 | } | ||
407 | |||
408 | void IRCMessageParser::parseNumerical005(IRCMessage *message) { | ||
409 | emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, message->allParameters())); | ||
410 | } | ||
411 | |||
412 | void IRCMessageParser::parseNumericalStats(IRCMessage *message) { | ||
413 | emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, message->param(1))); | ||
414 | } | ||
415 | |||
416 | void IRCMessageParser::parseNumericalNames(IRCMessage *message) { | ||
417 | /* Name list sent when joining a channel */ | ||
418 | IRCChannel *channel = m_session->getChannel(message->param(2)); | ||
419 | if (channel != 0) { | ||
420 | QString people = message->param(3); | ||
421 | QTextIStream stream(&people); | ||
422 | QString temp; | ||
423 | |||
424 | while (!stream.atEnd()) { | ||
425 | stream >> temp; | ||
426 | |||
427 | char flagch = temp.at(0).latin1(); | ||
428 | int flag = 0; | ||
429 | QString nick; | ||
430 | /* Parse person flags */ | ||
431 | if (flagch == '@' || flagch == '+' || flagch=='%' || flagch == '*') { | ||
432 | |||
433 | nick = temp.right(temp.length()-1); | ||
434 | switch (flagch) { | ||
435 | case '@': flag = PERSON_FLAG_OP; break; | ||
436 | case '+': flag = PERSON_FLAG_VOICE; break; | ||
437 | case '%': flag = PERSON_FLAG_HALFOP; break; | ||
438 | default : flag = 0; break; | ||
439 | } | ||
440 | } else { | ||
441 | nick = temp; | ||
442 | } | ||
443 | |||
444 | IRCChannelPerson *chan_person = new IRCChannelPerson(); | ||
445 | IRCPerson *person = m_session->getPerson(nick); | ||
446 | if (person == 0) { | ||
447 | person = new IRCPerson(); | ||
448 | person->setNick(nick); | ||
449 | m_session->addPerson(person); | ||
450 | } | ||
451 | chan_person->person = person; | ||
452 | chan_person->flags = flag; | ||
453 | channel->addPerson(chan_person); | ||
454 | } | ||
455 | } else { | ||
456 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Server message with unknown channel"))); | ||
457 | } | ||
458 | } | ||
459 | |||
460 | void IRCMessageParser::parseNumericalEndOfNames(IRCMessage *message) { | ||
461 | /* Done syncing to channel */ | ||
462 | IRCChannel *channel = m_session->getChannel(message->param(1)); | ||
463 | if (channel) { | ||
464 | channel->setHasPeople(TRUE); | ||
465 | /* Yes, we want the names before anything happens inside the GUI */ | ||
466 | IRCOutput output(OUTPUT_SELFJOIN, tr("You joined channel ") + channel->channelname()); | ||
467 | output.addParam(channel); | ||
468 | emit outputReady(output); | ||
469 | } else { | ||
470 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Server message with unknown channel"))); | ||
471 | } | ||
472 | } | ||
473 | |||
474 | |||
475 | void IRCMessageParser::parseNumericalNicknameInUse(IRCMessage *) { | ||
476 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Nickname is in use, please reconnect with a different nickname"))); | ||
477 | m_session->endSession(); | ||
478 | } | ||
diff --git a/noncore/net/opieirc/ircmessageparser.h b/noncore/net/opieirc/ircmessageparser.h new file mode 100644 index 0000000..b45b8f0 --- a/dev/null +++ b/noncore/net/opieirc/ircmessageparser.h | |||
@@ -0,0 +1,95 @@ | |||
1 | /* | ||
2 | OpieIRC - An embedded IRC client | ||
3 | Copyright (C) 2002 Wenzel Jakob | ||
4 | |||
5 | This program is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published by | ||
7 | the Free Software Foundation; either version 2 of the License, or | ||
8 | (at your option) any later version. | ||
9 | |||
10 | This program is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | ||
14 | |||
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 | ||
17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | |||
19 | */ | ||
20 | |||
21 | #ifndef __IRCMESSAGEPARSER_H | ||
22 | #define __IRCMESSAGEPARSER_H | ||
23 | |||
24 | #include "ircsession.h" | ||
25 | |||
26 | /* Macro to facilitate the parser table's creation */ | ||
27 | #define FUNC(__proc) &IRCMessageParser::__proc | ||
28 | |||
29 | class IRCMessageParser; | ||
30 | |||
31 | /* Typedef representing a parser function */ | ||
32 | typedef void (IRCMessageParser::*IRCMessageParseProc)(IRCMessage *); | ||
33 | |||
34 | /* Struct representing a literal command handler */ | ||
35 | typedef struct IRCLiteralMessageParserStruct { | ||
36 | char *commandName; | ||
37 | IRCMessageParseProc proc; | ||
38 | }; | ||
39 | |||
40 | /* Struct representing a ctcp command handler */ | ||
41 | typedef struct IRCCTCPMessageParserStruct { | ||
42 | char *commandName; | ||
43 | IRCMessageParseProc proc; | ||
44 | }; | ||
45 | |||
46 | /* Struct representing a numerical command handler */ | ||
47 | typedef struct IRCNumericalMessageParserStruct { | ||
48 | unsigned short commandNumber; | ||
49 | IRCMessageParseProc proc; | ||
50 | }; | ||
51 | |||
52 | class IRCMessageParser : public QObject { | ||
53 | Q_OBJECT | ||
54 | public: | ||
55 | /* Create an IRCMessageParser object */ | ||
56 | IRCMessageParser(IRCSession *session); | ||
57 | /* Parse a server message and take the appropriate actions */ | ||
58 | void parse(IRCMessage *message); | ||
59 | signals: | ||
60 | /* Used to send commands to the UI (such as displaying text etc) */ | ||
61 | void outputReady(IRCOutput output); | ||
62 | private: | ||
63 | /* Parser functions */ | ||
64 | void nullFunc(IRCMessage *message); | ||
65 | void parseLiteralPing(IRCMessage *message); | ||
66 | void parseLiteralNotice(IRCMessage *message); | ||
67 | void parseLiteralJoin(IRCMessage *message); | ||
68 | void parseLiteralPrivMsg(IRCMessage *message); | ||
69 | void parseLiteralNick(IRCMessage *message); | ||
70 | void parseLiteralPart(IRCMessage *message); | ||
71 | void parseLiteralQuit(IRCMessage *message); | ||
72 | void parseLiteralError(IRCMessage *message); | ||
73 | void parseLiteralMode(IRCMessage *message); | ||
74 | void parseLiteralKick(IRCMessage *message); | ||
75 | void parseNumerical001(IRCMessage *message); | ||
76 | void parseNumerical002(IRCMessage *message); | ||
77 | void parseNumerical003(IRCMessage *message); | ||
78 | void parseNumerical004(IRCMessage *message); | ||
79 | void parseNumerical005(IRCMessage *message); | ||
80 | void parseNumericalStats(IRCMessage *message); | ||
81 | void parseNumericalNames(IRCMessage *message); | ||
82 | void parseNumericalEndOfNames(IRCMessage *message); | ||
83 | void parseNumericalNicknameInUse(IRCMessage *message); | ||
84 | void parseCTCPPing(IRCMessage *message); | ||
85 | void parseCTCPVersion(IRCMessage *message); | ||
86 | void parseCTCPAction(IRCMessage *message); | ||
87 | protected: | ||
88 | IRCSession *m_session; | ||
89 | /* Parser tables */ | ||
90 | static IRCLiteralMessageParserStruct literalParserProcTable[]; | ||
91 | static IRCNumericalMessageParserStruct numericalParserProcTable[]; | ||
92 | static IRCCTCPMessageParserStruct ctcpParserProcTable[]; | ||
93 | }; | ||
94 | |||
95 | #endif /* __IRCMESSAGEPARSER_H */ | ||
diff --git a/noncore/net/opieirc/ircoutput.cpp b/noncore/net/opieirc/ircoutput.cpp new file mode 100644 index 0000000..aa57d86 --- a/dev/null +++ b/noncore/net/opieirc/ircoutput.cpp | |||
@@ -0,0 +1,22 @@ | |||
1 | #include "ircoutput.h" | ||
2 | |||
3 | IRCOutput::IRCOutput(IRCOutputType type, QString message) { | ||
4 | m_type = type; | ||
5 | m_message = message; | ||
6 | } | ||
7 | |||
8 | IRCOutputType IRCOutput::type() { | ||
9 | return m_type; | ||
10 | } | ||
11 | |||
12 | QString IRCOutput::message() { | ||
13 | return m_message; | ||
14 | } | ||
15 | |||
16 | void IRCOutput::addParam(void *data) { | ||
17 | m_parameters.append(data); | ||
18 | } | ||
19 | |||
20 | void *IRCOutput::getParam(int index) { | ||
21 | return m_parameters.at(index); | ||
22 | } | ||
diff --git a/noncore/net/opieirc/ircoutput.h b/noncore/net/opieirc/ircoutput.h new file mode 100644 index 0000000..4b757ed --- a/dev/null +++ b/noncore/net/opieirc/ircoutput.h | |||
@@ -0,0 +1,70 @@ | |||
1 | /* | ||
2 | OpieIRC - An embedded IRC client | ||
3 | Copyright (C) 2002 Wenzel Jakob | ||
4 | |||
5 | This program is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published by | ||
7 | the Free Software Foundation; either version 2 of the License, or | ||
8 | (at your option) any later version. | ||
9 | |||
10 | This program is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | ||
14 | |||
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 | ||
17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | |||
19 | */ | ||
20 | |||
21 | #ifndef __IRCOUTPUT_H | ||
22 | #define __IRCOUTPUT_H | ||
23 | |||
24 | #include <qstring.h> | ||
25 | #include <qlist.h> | ||
26 | #include "ircchannel.h" | ||
27 | |||
28 | /* Types of possible IRC output */ | ||
29 | enum IRCOutputType { | ||
30 | OUTPUT_ERROR = -1, /* parameters : none */ | ||
31 | OUTPUT_SERVERMESSAGE = 0, /* parameters : none */ | ||
32 | OUTPUT_CLIENTMESSAGE = 1, /* parameters : none */ | ||
33 | OUTPUT_CHANPRIVMSG = 2, /* parameters : channel (IRCChannel), person (IRCChannelPerson) */ | ||
34 | OUTPUT_QUERYPRIVMSG = 3, /* parameters : person (IRCPerson) */ | ||
35 | OUTPUT_NICKCHANGE = 4, /* parameters : person (IRCPerson) */ | ||
36 | OUTPUT_SELFJOIN = 5, /* parameters : channel (IRCChannel) */ | ||
37 | OUTPUT_OTHERJOIN = 6, /* parameters : channel (IRCChannel), person (IRCChannelPerson) */ | ||
38 | OUTPUT_SELFPART = 7, /* parameters : channel (IRCChannel) */ | ||
39 | OUTPUT_OTHERPART = 8, /* parameters : channel (IRCChannel), person (IRCChannelPerson) */ | ||
40 | OUTPUT_QUIT = 9, /* parameters : person (IRCPerson) */ | ||
41 | OUTPUT_CONNCLOSE = 10, /* parameters : none */ | ||
42 | OUTPUT_CTCP = 11, /* parameters : none */ | ||
43 | OUTPUT_SELFKICK = 12, /* parameters : channel (IRCChannel) */ | ||
44 | OUTPUT_OTHERKICK = 13, /* parameters : channel (IRCChannel) person (IRCChannelPerson) */ | ||
45 | OUTPUT_CHANACTION = 14, /* parameters : channel (IRCChannel) person (IRCChannelPerson) */ | ||
46 | OUTPUT_QUERYACTION = 15, /* parameters : person (IRCPerson) */ | ||
47 | OUTPUT_CHANPERSONMODE = 16 /* parameters : channel (IRCCHannel) person (IRCChannelPerson) */ | ||
48 | }; | ||
49 | |||
50 | /* The IRCOutput class is used as a kind of message which is sent by the | ||
51 | IRC parser to inform the GUI of changes. This could for example be a | ||
52 | channel message or a nickname change */ | ||
53 | |||
54 | class IRCOutput { | ||
55 | public: | ||
56 | IRCOutput(IRCOutputType type, QString message); | ||
57 | /* Used to add a parameter to this IRCOutput. Parameters are dependent | ||
58 | on which IRCOutputType we are using (see above) */ | ||
59 | void addParam(void *data); | ||
60 | |||
61 | IRCOutputType type(); | ||
62 | QString message(); | ||
63 | void *getParam(int index); | ||
64 | protected: | ||
65 | IRCOutputType m_type; | ||
66 | QString m_message; | ||
67 | QList<void> m_parameters; | ||
68 | }; | ||
69 | |||
70 | #endif | ||
diff --git a/noncore/net/opieirc/ircperson.cpp b/noncore/net/opieirc/ircperson.cpp new file mode 100644 index 0000000..bd6b8d6 --- a/dev/null +++ b/noncore/net/opieirc/ircperson.cpp | |||
@@ -0,0 +1,50 @@ | |||
1 | #include "ircperson.h" | ||
2 | #include <stdio.h> | ||
3 | |||
4 | IRCPerson::IRCPerson() { | ||
5 | m_nick = ""; | ||
6 | m_user = ""; | ||
7 | m_host = ""; | ||
8 | } | ||
9 | |||
10 | IRCPerson::IRCPerson(QString mask) { | ||
11 | IRCPerson(); | ||
12 | fromMask(mask); | ||
13 | } | ||
14 | |||
15 | void IRCPerson::fromMask(QString mask) { | ||
16 | int sep1 = mask.find("!"); | ||
17 | int sep2 = mask.find("@"); | ||
18 | |||
19 | m_nick = mask.left(sep1); | ||
20 | m_user = mask.mid(sep1+1, sep2-sep1-1); | ||
21 | m_host = mask.right(mask.length()-sep2-1); | ||
22 | } | ||
23 | |||
24 | QString IRCPerson::toMask() { | ||
25 | return m_nick + "!" + m_user + "@" + m_host; | ||
26 | } | ||
27 | |||
28 | void IRCPerson::setNick(QString nick) { | ||
29 | m_nick = nick; | ||
30 | } | ||
31 | |||
32 | void IRCPerson::setUser(QString user) { | ||
33 | m_user = user; | ||
34 | } | ||
35 | |||
36 | void IRCPerson::setHost(QString host) { | ||
37 | m_host = host; | ||
38 | } | ||
39 | |||
40 | QString IRCPerson::nick() { | ||
41 | return m_nick; | ||
42 | } | ||
43 | |||
44 | QString IRCPerson::user() { | ||
45 | return m_user; | ||
46 | } | ||
47 | |||
48 | QString IRCPerson::host() { | ||
49 | return m_host; | ||
50 | } | ||
diff --git a/noncore/net/opieirc/ircperson.h b/noncore/net/opieirc/ircperson.h new file mode 100644 index 0000000..850f91b --- a/dev/null +++ b/noncore/net/opieirc/ircperson.h | |||
@@ -0,0 +1,50 @@ | |||
1 | /* | ||
2 | OpieIRC - An embedded IRC client | ||
3 | Copyright (C) 2002 Wenzel Jakob | ||
4 | |||
5 | This program is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published by | ||
7 | the Free Software Foundation; either version 2 of the License, or | ||
8 | (at your option) any later version. | ||
9 | |||
10 | This program is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | ||
14 | |||
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 | ||
17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | |||
19 | */ | ||
20 | |||
21 | #ifndef __IRCPERSON | ||
22 | #define __IRCPERSON | ||
23 | |||
24 | #include <qstring.h> | ||
25 | |||
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 | ||
28 | IRCMessage-prefixes too | ||
29 | */ | ||
30 | |||
31 | class IRCPerson { | ||
32 | public: | ||
33 | IRCPerson(); | ||
34 | IRCPerson(QString mask); | ||
35 | |||
36 | void fromMask(QString mask); | ||
37 | void setNick(QString name); | ||
38 | void setUser(QString user); | ||
39 | void setHost(QString host); | ||
40 | QString toMask(); | ||
41 | QString nick(); | ||
42 | QString user(); | ||
43 | QString host(); | ||
44 | protected: | ||
45 | QString m_nick; | ||
46 | QString m_user; | ||
47 | QString m_host; | ||
48 | }; | ||
49 | |||
50 | #endif /* __IRCPERSON */ | ||
diff --git a/noncore/net/opieirc/ircserver.cpp b/noncore/net/opieirc/ircserver.cpp new file mode 100644 index 0000000..33a788b --- a/dev/null +++ b/noncore/net/opieirc/ircserver.cpp | |||
@@ -0,0 +1,62 @@ | |||
1 | #include "ircserver.h" | ||
2 | |||
3 | IRCServer::IRCServer() { | ||
4 | m_port = 0; | ||
5 | } | ||
6 | |||
7 | void IRCServer::setHostname(QString hostname) { | ||
8 | m_hostname = hostname; | ||
9 | } | ||
10 | |||
11 | void IRCServer::setDescription(QString description) { | ||
12 | m_description = description; | ||
13 | } | ||
14 | |||
15 | void IRCServer::setPort(int port) { | ||
16 | m_port = port; | ||
17 | } | ||
18 | |||
19 | void IRCServer::setUsername(QString username) { | ||
20 | m_username = username; | ||
21 | } | ||
22 | |||
23 | void IRCServer::setPassword(QString password) { | ||
24 | m_password = password; | ||
25 | } | ||
26 | |||
27 | void IRCServer::setNick(QString nick) { | ||
28 | m_nick = nick; | ||
29 | } | ||
30 | |||
31 | void IRCServer::setRealname(QString realname) { | ||
32 | m_realname = realname; | ||
33 | } | ||
34 | |||
35 | QString IRCServer::hostname() { | ||
36 | return m_hostname; | ||
37 | } | ||
38 | |||
39 | QString IRCServer::description() { | ||
40 | return m_description; | ||
41 | } | ||
42 | |||
43 | unsigned short int IRCServer::port() { | ||
44 | return m_port; | ||
45 | } | ||
46 | |||
47 | QString IRCServer::username() { | ||
48 | return m_username; | ||
49 | } | ||
50 | |||
51 | QString IRCServer::password() { | ||
52 | return m_password; | ||
53 | } | ||
54 | |||
55 | QString IRCServer::nick() { | ||
56 | return m_nick; | ||
57 | } | ||
58 | |||
59 | QString IRCServer::realname() { | ||
60 | return m_realname; | ||
61 | } | ||
62 | |||
diff --git a/noncore/net/opieirc/ircserver.h b/noncore/net/opieirc/ircserver.h new file mode 100644 index 0000000..5f06c73 --- a/dev/null +++ b/noncore/net/opieirc/ircserver.h | |||
@@ -0,0 +1,58 @@ | |||
1 | /* | ||
2 | OpieIRC - An embedded IRC client | ||
3 | Copyright (C) 2002 Wenzel Jakob | ||
4 | |||
5 | This program is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published by | ||
7 | the Free Software Foundation; either version 2 of the License, or | ||
8 | (at your option) any later version. | ||
9 | |||
10 | This program is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | ||
14 | |||
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 | ||
17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | |||
19 | */ | ||
20 | |||
21 | #ifndef __IRCSERVER_H | ||
22 | #define __IRCSERVER_H | ||
23 | |||
24 | #include <qstring.h> | ||
25 | |||
26 | /* IRCServer stores all information required to | ||
27 | establish a connection to a server. */ | ||
28 | |||
29 | class IRCServer { | ||
30 | public: | ||
31 | IRCServer(); | ||
32 | |||
33 | void setHostname(QString hostname); | ||
34 | void setDescription(QString description); | ||
35 | void setPort(int port); | ||
36 | void setUsername(QString username); | ||
37 | void setPassword(QString password); | ||
38 | void setNick(QString nick); | ||
39 | void setRealname(QString realname); | ||
40 | |||
41 | QString hostname(); | ||
42 | QString description(); | ||
43 | unsigned short int port(); | ||
44 | QString username(); | ||
45 | QString password(); | ||
46 | QString nick(); | ||
47 | QString realname(); | ||
48 | protected: | ||
49 | QString m_hostname; | ||
50 | QString m_description; | ||
51 | unsigned short int m_port; | ||
52 | QString m_username; | ||
53 | QString m_password; | ||
54 | QString m_nick; | ||
55 | QString m_realname; | ||
56 | }; | ||
57 | |||
58 | #endif /* __IRCSERVER_H */ | ||
diff --git a/noncore/net/opieirc/ircservereditor.cpp b/noncore/net/opieirc/ircservereditor.cpp new file mode 100644 index 0000000..1b157d6 --- a/dev/null +++ b/noncore/net/opieirc/ircservereditor.cpp | |||
@@ -0,0 +1,49 @@ | |||
1 | #include <qlayout.h> | ||
2 | #include <qlabel.h> | ||
3 | #include "ircservereditor.h" | ||
4 | |||
5 | IRCServerEditor::IRCServerEditor(IRCServer server, QWidget* parent, const char* name, bool modal = FALSE, WFlags f) : QDialog(parent, name, modal, f) { | ||
6 | QGridLayout *layout = new QGridLayout(this, 6, 2, 5, 5); | ||
7 | QLabel *label = new QLabel(tr("Hostname :"), this); | ||
8 | m_hostname = new QLineEdit(server.hostname(), this); | ||
9 | layout->addWidget(label, 0, 0); | ||
10 | layout->addWidget(m_hostname, 0, 1); | ||
11 | label = new QLabel(tr("Port :"), this); | ||
12 | m_port = new QLineEdit(QString::number(server.port()), this); | ||
13 | layout->addWidget(label, 1, 0); | ||
14 | layout->addWidget(m_port, 1, 1); | ||
15 | label = new QLabel(tr("Nickname :"), this); | ||
16 | m_nickname = new QLineEdit(server.nick(), this); | ||
17 | layout->addWidget(label, 2, 0); | ||
18 | layout->addWidget(m_nickname, 2, 1); | ||
19 | label = new QLabel(tr("Description :"), this); | ||
20 | m_description = new QLineEdit(server.description(), this); | ||
21 | layout->addWidget(label, 3, 0); | ||
22 | layout->addWidget(m_description, 3, 1); | ||
23 | label = new QLabel(tr("Realname :"), this); | ||
24 | m_realname = new QLineEdit(server.realname(), this); | ||
25 | layout->addWidget(label, 4, 0); | ||
26 | layout->addWidget(m_realname, 4, 1); | ||
27 | label = new QLabel(tr("Username :"), this); | ||
28 | m_username = new QLineEdit(server.username(), this); | ||
29 | layout->addWidget(label, 3, 0); | ||
30 | layout->addWidget(m_username, 3, 1); | ||
31 | label = new QLabel(tr("Password :"), this); | ||
32 | m_password = new QLineEdit(server.password(), this); | ||
33 | layout->addWidget(label, 5, 0); | ||
34 | layout->addWidget(m_password, 5, 1); | ||
35 | showMaximized(); | ||
36 | } | ||
37 | |||
38 | |||
39 | IRCServer IRCServerEditor::getServer() { | ||
40 | IRCServer server; | ||
41 | server.setHostname(m_hostname->text()); | ||
42 | server.setPort(m_port->text().toInt()); | ||
43 | server.setNick(m_nickname->text()); | ||
44 | server.setDescription(m_description->text()); | ||
45 | server.setRealname(m_realname->text()); | ||
46 | server.setUsername(m_username->text()); | ||
47 | server.setPassword(m_password->text()); | ||
48 | return server; | ||
49 | } | ||
diff --git a/noncore/net/opieirc/ircservereditor.h b/noncore/net/opieirc/ircservereditor.h new file mode 100644 index 0000000..86cdf32 --- a/dev/null +++ b/noncore/net/opieirc/ircservereditor.h | |||
@@ -0,0 +1,43 @@ | |||
1 | /* | ||
2 | OpieIRC - An embedded IRC client | ||
3 | Copyright (C) 2002 Wenzel Jakob | ||
4 | |||
5 | This program is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published by | ||
7 | the Free Software Foundation; either version 2 of the License, or | ||
8 | (at your option) any later version. | ||
9 | |||
10 | This program is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | ||
14 | |||
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 | ||
17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | |||
19 | */ | ||
20 | |||
21 | #ifndef __IRCSERVEREDITOR | ||
22 | #define __IRCSERVEREDITOR | ||
23 | |||
24 | #include <qdialog.h> | ||
25 | #include <qlineedit.h> | ||
26 | #include "ircserver.h" | ||
27 | |||
28 | class IRCServerEditor : public QDialog { | ||
29 | Q_OBJECT | ||
30 | public: | ||
31 | IRCServerEditor(IRCServer server, QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags f = 0); | ||
32 | IRCServer getServer(); | ||
33 | protected: | ||
34 | QLineEdit *m_hostname; | ||
35 | QLineEdit *m_port; | ||
36 | QLineEdit *m_description; | ||
37 | QLineEdit *m_nickname; | ||
38 | QLineEdit *m_username; | ||
39 | QLineEdit *m_password; | ||
40 | QLineEdit *m_realname; | ||
41 | }; | ||
42 | |||
43 | #endif /* __IRCSERVEREDITOR_H */ | ||
diff --git a/noncore/net/opieirc/ircserverlist.cpp b/noncore/net/opieirc/ircserverlist.cpp new file mode 100644 index 0000000..964fa13 --- a/dev/null +++ b/noncore/net/opieirc/ircserverlist.cpp | |||
@@ -0,0 +1,55 @@ | |||
1 | #include <qlayout.h> | ||
2 | #include <qlabel.h> | ||
3 | #include <qhbox.h> | ||
4 | #include <qpushbutton.h> | ||
5 | #include "ircserverlist.h" | ||
6 | #include "ircservereditor.h" | ||
7 | |||
8 | class IRCListBoxServer : public QListBoxText { | ||
9 | public: | ||
10 | IRCListBoxServer(IRCServer server); | ||
11 | QString text(); | ||
12 | }; | ||
13 | |||
14 | IRCServerList::IRCServerList(QWidget* parent, const char *name, bool modal, WFlags f) : QDialog(parent, name, modal, f) { | ||
15 | QVBoxLayout *layout = new QVBoxLayout(this, 5, 5); | ||
16 | setCaption(tr("Serverlist Browser")); | ||
17 | m_config = new Config("OpieIRC"); | ||
18 | m_config->setGroup("OpieIRC"); | ||
19 | QLabel *label = new QLabel(tr("Please choose a server profile"), this); | ||
20 | layout->addWidget(label); | ||
21 | m_list = new QListBox(this); | ||
22 | layout->addWidget(m_list); | ||
23 | QHBox *buttons = new QHBox(this); | ||
24 | QPushButton *del = new QPushButton(tr("Delete"), buttons); | ||
25 | QPushButton *edit = new QPushButton(tr("Edit"), buttons); | ||
26 | QPushButton *add = new QPushButton(tr("Add"), buttons); | ||
27 | connect(del, SIGNAL(clicked()), this, SLOT(delServer())); | ||
28 | connect(edit, SIGNAL(clicked()), this, SLOT(editServer())); | ||
29 | connect(add, SIGNAL(clicked()), this, SLOT(addServer())); | ||
30 | layout->addWidget(buttons); | ||
31 | showMaximized(); | ||
32 | } | ||
33 | |||
34 | void IRCServerList::addServer() { | ||
35 | IRCServer server; | ||
36 | IRCServerEditor editor(server, this, "ServerEditor", TRUE); | ||
37 | if (editor.exec() == QDialog::Accepted) { | ||
38 | server = editor.getServer(); | ||
39 | //m_servers->append(server); | ||
40 | update(); | ||
41 | } | ||
42 | } | ||
43 | |||
44 | void IRCServerList::delServer() { | ||
45 | } | ||
46 | |||
47 | void IRCServerList::editServer() { | ||
48 | } | ||
49 | |||
50 | void IRCServerList::update() { | ||
51 | } | ||
52 | |||
53 | IRCServerList::~IRCServerList() { | ||
54 | delete m_config; | ||
55 | } | ||
diff --git a/noncore/net/opieirc/ircserverlist.h b/noncore/net/opieirc/ircserverlist.h new file mode 100644 index 0000000..ad9231d --- a/dev/null +++ b/noncore/net/opieirc/ircserverlist.h | |||
@@ -0,0 +1,46 @@ | |||
1 | /* | ||
2 | OpieIRC - An embedded IRC client | ||
3 | Copyright (C) 2002 Wenzel Jakob | ||
4 | |||
5 | This program is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published by | ||
7 | the Free Software Foundation; either version 2 of the License, or | ||
8 | (at your option) any later version. | ||
9 | |||
10 | This program is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | ||
14 | |||
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 | ||
17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | |||
19 | */ | ||
20 | |||
21 | #ifndef __IRCSERVERLIST_H | ||
22 | #define __IRCSERVERLIST_H | ||
23 | |||
24 | #include <qdialog.h> | ||
25 | #include <qpe/config.h> | ||
26 | #include <qlistbox.h> | ||
27 | #include <qlist.h> | ||
28 | #include "ircserver.h" | ||
29 | |||
30 | class IRCServerList : public QDialog { | ||
31 | Q_OBJECT | ||
32 | public: | ||
33 | IRCServerList(QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags f = 0); | ||
34 | ~IRCServerList(); | ||
35 | public slots: | ||
36 | void addServer(); | ||
37 | void delServer(); | ||
38 | void editServer(); | ||
39 | protected: | ||
40 | void update(); | ||
41 | protected: | ||
42 | Config *m_config; | ||
43 | QListBox *m_list; | ||
44 | }; | ||
45 | |||
46 | #endif /* __IRCSERVERLIST_H */ | ||
diff --git a/noncore/net/opieirc/ircservertab.cpp b/noncore/net/opieirc/ircservertab.cpp new file mode 100644 index 0000000..1f377aa --- a/dev/null +++ b/noncore/net/opieirc/ircservertab.cpp | |||
@@ -0,0 +1,147 @@ | |||
1 | #include <stdio.h> | ||
2 | #include "ircservertab.h" | ||
3 | |||
4 | IRCServerTab::IRCServerTab(IRCServer *server, MainWindow *mainWindow, QWidget *parent, const char *name, WFlags f) : IRCTab(parent, name, f) { | ||
5 | m_server = server; | ||
6 | m_session = new IRCSession(m_server); | ||
7 | m_mainWindow = mainWindow; | ||
8 | m_close = FALSE; | ||
9 | m_description->setText(tr("Connection to")+" <b>" + server->hostname() + ":" + QString::number(server->port()) + "</b>"); | ||
10 | m_textview = new QTextView(this); | ||
11 | m_textview->setHScrollBarMode(QScrollView::AlwaysOff); | ||
12 | m_textview->setVScrollBarMode(QScrollView::AlwaysOn); | ||
13 | m_layout->add(m_textview); | ||
14 | m_field = new QLineEdit(this); | ||
15 | m_layout->add(m_field); | ||
16 | connect(m_field, SIGNAL(returnPressed()), this, SLOT(processCommand())); | ||
17 | m_field->setFocus(); | ||
18 | connect(m_session, SIGNAL(outputReady(IRCOutput)), this, SLOT(display(IRCOutput))); | ||
19 | } | ||
20 | |||
21 | void IRCServerTab::appendText(QString text) { | ||
22 | /* not using append because it creates layout problems */ | ||
23 | m_textview->setText(m_textview->text() + text); | ||
24 | m_textview->ensureVisible(0, m_textview->contentsHeight()); | ||
25 | } | ||
26 | |||
27 | IRCServerTab::~IRCServerTab() { | ||
28 | QListIterator<IRCChannelTab> it(m_channelTabs); | ||
29 | for (; it.current(); ++it) { | ||
30 | m_mainWindow->killTab(it.current()); | ||
31 | } | ||
32 | delete m_session; | ||
33 | delete m_server; | ||
34 | } | ||
35 | |||
36 | void IRCServerTab::removeChannelTab(IRCChannelTab *tab) { | ||
37 | m_channelTabs.remove(tab); | ||
38 | } | ||
39 | |||
40 | QString IRCServerTab::title() { | ||
41 | return "Server"; | ||
42 | } | ||
43 | |||
44 | IRCSession *IRCServerTab::session() { | ||
45 | return m_session; | ||
46 | } | ||
47 | |||
48 | IRCServer *IRCServerTab::server() { | ||
49 | return m_server; | ||
50 | } | ||
51 | |||
52 | void IRCServerTab::processCommand() { | ||
53 | m_field->clear(); | ||
54 | appendText("<font color=\"#ff0000\">Not supported yet</font><br>"); | ||
55 | } | ||
56 | |||
57 | void IRCServerTab::doConnect() { | ||
58 | m_session->beginSession(); | ||
59 | } | ||
60 | |||
61 | void IRCServerTab::remove() { | ||
62 | if (m_session->isSessionActive()) { | ||
63 | m_close = TRUE; | ||
64 | m_session->endSession(); | ||
65 | } else { | ||
66 | m_mainWindow->killTab(this); | ||
67 | } | ||
68 | } | ||
69 | |||
70 | IRCChannelTab *IRCServerTab::getTabForChannel(IRCChannel *channel) { | ||
71 | QListIterator<IRCChannelTab> it(m_channelTabs); | ||
72 | |||
73 | for (; it.current(); ++it) { | ||
74 | if (it.current()->channel() == channel) | ||
75 | return it.current(); | ||
76 | } | ||
77 | return 0; | ||
78 | } | ||
79 | |||
80 | void IRCServerTab::display(IRCOutput output) { | ||
81 | switch (output.type()) { | ||
82 | case OUTPUT_CONNCLOSE: | ||
83 | if (m_close) | ||
84 | m_mainWindow->killTab(this); | ||
85 | else | ||
86 | appendText("<font color=\"#0000dd\">" + output.message() +"</font><br>"); | ||
87 | break; | ||
88 | case OUTPUT_SELFJOIN: { | ||
89 | IRCChannelTab *channeltab = new IRCChannelTab((IRCChannel *)output.getParam(0), this, m_mainWindow, (QWidget *)parent()); | ||
90 | m_channelTabs.append(channeltab); | ||
91 | m_mainWindow->addTab(channeltab); | ||
92 | } | ||
93 | break; | ||
94 | case OUTPUT_CHANPRIVMSG: { | ||
95 | IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0)); | ||
96 | channelTab->appendText("<<font color=\"#0000dd\">"+((IRCChannelPerson *)output.getParam(1))->person->nick()+"</font>> "+output.message()+"<br>"); | ||
97 | } | ||
98 | break; | ||
99 | case OUTPUT_SELFPART: { | ||
100 | IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0)); | ||
101 | if (channelTab) | ||
102 | m_mainWindow->killTab(channelTab); | ||
103 | } | ||
104 | break; | ||
105 | case OUTPUT_SELFKICK: { | ||
106 | appendText("<font color=\"#ff0000\">" + output.message() + "</font><br>"); | ||
107 | IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0)); | ||
108 | if (channelTab) | ||
109 | m_mainWindow->killTab(channelTab); | ||
110 | } | ||
111 | break; | ||
112 | case OUTPUT_CHANACTION: { | ||
113 | IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0)); | ||
114 | channelTab->appendText("<font color=\"#cc0000\">"+output.message()+"</font><br>"); | ||
115 | } | ||
116 | break; | ||
117 | case OUTPUT_QUIT: { | ||
118 | QString nick = ((IRCPerson *)output.getParam(0))->nick(); | ||
119 | QListIterator<IRCChannelTab> it(m_channelTabs); | ||
120 | for (; it.current(); ++it) { | ||
121 | if (it.current()->list()->hasPerson(nick)) { | ||
122 | it.current()->appendText("<font color=\"#aa3e00\">"+output.message()+"</font><br>"); | ||
123 | it.current()->list()->update(); | ||
124 | } | ||
125 | } | ||
126 | } | ||
127 | break; | ||
128 | case OUTPUT_OTHERJOIN: | ||
129 | case OUTPUT_OTHERKICK: | ||
130 | case OUTPUT_CHANPERSONMODE: | ||
131 | case OUTPUT_OTHERPART: { | ||
132 | IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0)); | ||
133 | channelTab->appendText("<font color=\"#aa3e00\">"+output.message()+"</font><br>"); | ||
134 | channelTab->list()->update(); | ||
135 | } | ||
136 | break; | ||
137 | case OUTPUT_CTCP: | ||
138 | appendText("<font color=\"#00bb00\">" + output.message() + "</font><br>"); | ||
139 | break; | ||
140 | case OUTPUT_ERROR: | ||
141 | appendText("<font color=\"#ff0000\">" + output.message() + "</font><br>"); | ||
142 | break; | ||
143 | default: | ||
144 | appendText("<font color=\"#0000dd\">" + output.message() + "</font><br>"); | ||
145 | break; | ||
146 | } | ||
147 | } | ||
diff --git a/noncore/net/opieirc/ircservertab.h b/noncore/net/opieirc/ircservertab.h new file mode 100644 index 0000000..79b5876 --- a/dev/null +++ b/noncore/net/opieirc/ircservertab.h | |||
@@ -0,0 +1,60 @@ | |||
1 | /* | ||
2 | OpieIRC - An embedded IRC client | ||
3 | Copyright (C) 2002 Wenzel Jakob | ||
4 | |||
5 | This program is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published by | ||
7 | the Free Software Foundation; either version 2 of the License, or | ||
8 | (at your option) any later version. | ||
9 | |||
10 | This program is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | ||
14 | |||
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 | ||
17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | |||
19 | */ | ||
20 | |||
21 | #ifndef __IRCSERVERTAB_H | ||
22 | #define __IRCSERVERTAB_H | ||
23 | |||
24 | #include "irctab.h" | ||
25 | #include "ircsession.h" | ||
26 | #include "mainwindow.h" | ||
27 | #include "ircchanneltab.h" | ||
28 | |||
29 | class IRCServerTab : public IRCTab { | ||
30 | Q_OBJECT | ||
31 | public: | ||
32 | /* IRCTab implementation */ | ||
33 | IRCServerTab(IRCServer *server, MainWindow *mainWindow, QWidget *parent = 0, const char *name = 0, WFlags f = 0); | ||
34 | ~IRCServerTab(); | ||
35 | QString title(); | ||
36 | IRCSession *session(); | ||
37 | IRCServer *server(); | ||
38 | |||
39 | /* Start the server session */ | ||
40 | void doConnect(); | ||
41 | void removeChannelTab(IRCChannelTab *tab); | ||
42 | protected: | ||
43 | void appendText(QString text); | ||
44 | IRCChannelTab *getTabForChannel(IRCChannel *channel); | ||
45 | public slots: | ||
46 | void remove(); | ||
47 | void processCommand(); | ||
48 | protected slots: | ||
49 | void display(IRCOutput output); | ||
50 | protected: | ||
51 | bool m_close; | ||
52 | IRCServer *m_server; | ||
53 | IRCSession *m_session; | ||
54 | MainWindow *m_mainWindow; | ||
55 | QTextView *m_textview; | ||
56 | QLineEdit *m_field; | ||
57 | QList<IRCChannelTab> m_channelTabs; | ||
58 | }; | ||
59 | |||
60 | #endif /* __IRCSERVERTAB_H */ | ||
diff --git a/noncore/net/opieirc/ircsession.cpp b/noncore/net/opieirc/ircsession.cpp new file mode 100644 index 0000000..b81038f --- a/dev/null +++ b/noncore/net/opieirc/ircsession.cpp | |||
@@ -0,0 +1,99 @@ | |||
1 | #include "ircsession.h" | ||
2 | #include "ircmessageparser.h" | ||
3 | #include "ircversion.h" | ||
4 | |||
5 | IRCSession::IRCSession(IRCServer *server) { | ||
6 | m_server = server; | ||
7 | m_connection = new IRCConnection(m_server); | ||
8 | m_parser = new IRCMessageParser(this); | ||
9 | connect(m_connection, SIGNAL(messageArrived(IRCMessage *)), this, SLOT(handleMessage(IRCMessage *))); | ||
10 | connect(m_parser, SIGNAL(outputReady(IRCOutput)), this, SIGNAL(outputReady(IRCOutput))); | ||
11 | connect(m_connection, SIGNAL(outputReady(IRCOutput)), this, SIGNAL(outputReady(IRCOutput))); | ||
12 | } | ||
13 | |||
14 | IRCSession::~IRCSession() { | ||
15 | delete m_parser; | ||
16 | delete m_connection; | ||
17 | } | ||
18 | |||
19 | void IRCSession::beginSession() { | ||
20 | m_connection->doConnect(); | ||
21 | } | ||
22 | |||
23 | void IRCSession::join(QString channelname) { | ||
24 | m_connection->sendLine("JOIN "+channelname); | ||
25 | } | ||
26 | |||
27 | void IRCSession::sendMessage(IRCPerson *person, QString message) { | ||
28 | m_connection->sendLine("PRIVMSG " + person->nick() + " :" + message); | ||
29 | } | ||
30 | |||
31 | void IRCSession::sendMessage(IRCChannel *channel, QString message) { | ||
32 | m_connection->sendLine("PRIVMSG " + channel->channelname() + " :" + message); | ||
33 | } | ||
34 | |||
35 | bool IRCSession::isSessionActive() { | ||
36 | return m_connection->isConnected(); | ||
37 | } | ||
38 | |||
39 | void IRCSession::endSession() { | ||
40 | if (m_connection->isLoggedIn()) | ||
41 | m_connection->sendLine("QUIT :" APP_VERSION); | ||
42 | else | ||
43 | m_connection->close(); | ||
44 | } | ||
45 | |||
46 | void IRCSession::part(IRCChannel *channel) { | ||
47 | m_connection->sendLine("PART " + channel->channelname() + " :" + APP_VERSION); | ||
48 | } | ||
49 | |||
50 | |||
51 | IRCChannel *IRCSession::getChannel(QString channelname) { | ||
52 | QListIterator<IRCChannel> it(m_channels); | ||
53 | for (; it.current(); ++it) { | ||
54 | if (it.current()->channelname() == channelname) { | ||
55 | return it.current(); | ||
56 | } | ||
57 | } | ||
58 | return 0; | ||
59 | } | ||
60 | |||
61 | IRCPerson *IRCSession::getPerson(QString nickname) { | ||
62 | QListIterator<IRCPerson> it(m_people); | ||
63 | for (; it.current(); ++it) { | ||
64 | if (it.current()->nick() == nickname) { | ||
65 | return it.current(); | ||
66 | } | ||
67 | } | ||
68 | return 0; | ||
69 | } | ||
70 | |||
71 | void IRCSession::getChannelsByPerson(IRCPerson *person, QList<IRCChannel> &channels) { | ||
72 | QListIterator<IRCChannel> it(m_channels); | ||
73 | for (; it.current(); ++it) { | ||
74 | if (it.current()->getPerson(person->nick()) != 0) { | ||
75 | channels.append(it.current()); | ||
76 | } | ||
77 | } | ||
78 | } | ||
79 | |||
80 | void IRCSession::addPerson(IRCPerson *person) { | ||
81 | m_people.append(person); | ||
82 | } | ||
83 | |||
84 | void IRCSession::addChannel(IRCChannel *channel) { | ||
85 | m_channels.append(channel); | ||
86 | } | ||
87 | |||
88 | void IRCSession::removeChannel(IRCChannel *channel) { | ||
89 | m_channels.remove(channel); | ||
90 | } | ||
91 | |||
92 | void IRCSession::removePerson(IRCPerson *person) { | ||
93 | m_people.remove(person); | ||
94 | } | ||
95 | |||
96 | void IRCSession::handleMessage(IRCMessage *message) { | ||
97 | m_parser->parse(message); | ||
98 | } | ||
99 | |||
diff --git a/noncore/net/opieirc/ircsession.h b/noncore/net/opieirc/ircsession.h new file mode 100644 index 0000000..59c26aa --- a/dev/null +++ b/noncore/net/opieirc/ircsession.h | |||
@@ -0,0 +1,73 @@ | |||
1 | /* | ||
2 | OpieIRC - An embedded IRC client | ||
3 | Copyright (C) 2002 Wenzel Jakob | ||
4 | |||
5 | This program is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published by | ||
7 | the Free Software Foundation; either version 2 of the License, or | ||
8 | (at your option) any later version. | ||
9 | |||
10 | This program is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | ||
14 | |||
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 | ||
17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | |||
19 | */ | ||
20 | |||
21 | #ifndef __IRCSESSION_H | ||
22 | #define __IRCSESSION_H | ||
23 | |||
24 | #include <qstring.h> | ||
25 | #include <qlist.h> | ||
26 | #include "ircserver.h" | ||
27 | #include "ircconnection.h" | ||
28 | #include "ircmessage.h" | ||
29 | #include "ircchannel.h" | ||
30 | #include "ircoutput.h" | ||
31 | |||
32 | class IRCMessageParser; | ||
33 | |||
34 | /* The IRCSession stores all information relating to the connection | ||
35 | to one IRC server. IRCSession makes it possible to run multiple | ||
36 | IRC server connections from within the same program */ | ||
37 | |||
38 | class IRCSession : public QObject { | ||
39 | friend class IRCMessageParser; | ||
40 | Q_OBJECT | ||
41 | public: | ||
42 | IRCSession(IRCServer *server); | ||
43 | ~IRCSession(); | ||
44 | |||
45 | void join(QString channel); | ||
46 | void part(IRCChannel *channel); | ||
47 | void beginSession(); | ||
48 | bool isSessionActive(); | ||
49 | void endSession(); | ||
50 | |||
51 | void sendMessage(IRCPerson *person, QString message); | ||
52 | void sendMessage(IRCChannel *channel, QString message); | ||
53 | IRCChannel *getChannel(QString channelname); | ||
54 | IRCPerson *getPerson(QString nickname); | ||
55 | protected: | ||
56 | void addPerson(IRCPerson *person); | ||
57 | void addChannel(IRCChannel *channel); | ||
58 | void removeChannel(IRCChannel *channel); | ||
59 | void removePerson(IRCPerson *person); | ||
60 | void getChannelsByPerson(IRCPerson *person, QList<IRCChannel> &channels); | ||
61 | protected slots: | ||
62 | void handleMessage(IRCMessage *message); | ||
63 | signals: | ||
64 | void outputReady(IRCOutput output); | ||
65 | protected: | ||
66 | IRCServer *m_server; | ||
67 | IRCConnection *m_connection; | ||
68 | IRCMessageParser *m_parser; | ||
69 | QList<IRCChannel> m_channels; | ||
70 | QList<IRCPerson> m_people; | ||
71 | }; | ||
72 | |||
73 | #endif /* __IRCSESSION_H */ | ||
diff --git a/noncore/net/opieirc/irctab.cpp b/noncore/net/opieirc/irctab.cpp new file mode 100644 index 0000000..36976ab --- a/dev/null +++ b/noncore/net/opieirc/irctab.cpp | |||
@@ -0,0 +1,19 @@ | |||
1 | #include <qpe/resource.h> | ||
2 | #include <qpixmap.h> | ||
3 | #include <qpushbutton.h> | ||
4 | #include "irctab.h" | ||
5 | |||
6 | IRCTab::IRCTab(QWidget *parent, const char *name, WFlags f) : QWidget(parent, name, f) { | ||
7 | m_layout = new QVBoxLayout(this); | ||
8 | QHBoxLayout *descLayout = new QHBoxLayout(m_layout); | ||
9 | descLayout->setMargin(5); | ||
10 | m_description = new QLabel(tr("Missing description"), this); | ||
11 | descLayout->addWidget(m_description); | ||
12 | descLayout->setStretchFactor(m_description, 5); | ||
13 | QPushButton *close = new QPushButton(this); | ||
14 | close->setPixmap(Resource::loadPixmap("opieirc/close")); | ||
15 | connect(close, SIGNAL(clicked()), this, SLOT(remove())); | ||
16 | descLayout->addWidget(close); | ||
17 | descLayout->setStretchFactor(m_description, 1); | ||
18 | } | ||
19 | |||
diff --git a/noncore/net/opieirc/irctab.h b/noncore/net/opieirc/irctab.h new file mode 100644 index 0000000..3124980 --- a/dev/null +++ b/noncore/net/opieirc/irctab.h | |||
@@ -0,0 +1,47 @@ | |||
1 | /* | ||
2 | OpieIRC - An embedded IRC client | ||
3 | Copyright (C) 2002 Wenzel Jakob | ||
4 | |||
5 | This program is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published by | ||
7 | the Free Software Foundation; either version 2 of the License, or | ||
8 | (at your option) any later version. | ||
9 | |||
10 | This program is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | ||
14 | |||
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 | ||
17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | |||
19 | */ | ||
20 | |||
21 | #ifndef __IRCTAB_H | ||
22 | #define __IRCTAB_H | ||
23 | |||
24 | #include <qwidget.h> | ||
25 | #include <qtextview.h> | ||
26 | #include <qlineedit.h> | ||
27 | #include <qlabel.h> | ||
28 | #include <qlayout.h> | ||
29 | #include "ircsession.h" | ||
30 | |||
31 | /* This is the base class for any tabs which need to be integrated into | ||
32 | the main GUI tab widget */ | ||
33 | |||
34 | class IRCTab : public QWidget { | ||
35 | Q_OBJECT | ||
36 | public: | ||
37 | IRCTab(QWidget *parent = 0, const char *name = 0, WFlags f = 0); | ||
38 | virtual QString title() = 0; | ||
39 | virtual IRCSession *session() = 0; | ||
40 | public slots: | ||
41 | virtual void remove() = 0; | ||
42 | protected: | ||
43 | QLabel *m_description; | ||
44 | QVBoxLayout *m_layout; | ||
45 | }; | ||
46 | |||
47 | #endif /* __IRCTAB_H */ | ||
diff --git a/noncore/net/opieirc/ircversion.h b/noncore/net/opieirc/ircversion.h new file mode 100644 index 0000000..0ef0d2f --- a/dev/null +++ b/noncore/net/opieirc/ircversion.h | |||
@@ -0,0 +1,27 @@ | |||
1 | /* | ||
2 | OpieIRC - An embedded IRC client | ||
3 | Copyright (C) 2002 Wenzel Jakob | ||
4 | |||
5 | This program is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published by | ||
7 | the Free Software Foundation; either version 2 of the License, or | ||
8 | (at your option) any later version. | ||
9 | |||
10 | This program is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | ||
14 | |||
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 | ||
17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | |||
19 | */ | ||
20 | |||
21 | #ifndef __IRCVERSION_H | ||
22 | #define __IRCVERSION_H | ||
23 | |||
24 | #define APP_VERSION "OpieIRC 0.1" | ||
25 | #define APP_COPYSTR "(c) 2002 by Wenzel Jakob" | ||
26 | |||
27 | #endif /* __IRCVERSION_H */ | ||
diff --git a/noncore/net/opieirc/main.cpp b/noncore/net/opieirc/main.cpp new file mode 100644 index 0000000..43e63af --- a/dev/null +++ b/noncore/net/opieirc/main.cpp | |||
@@ -0,0 +1,10 @@ | |||
1 | #include <qpe/qpeapplication.h> | ||
2 | #include "mainwindow.h" | ||
3 | |||
4 | int main(int argc, char **argv) { | ||
5 | QPEApplication a(argc, argv); | ||
6 | MainWindow mw; | ||
7 | a.showMainWidget(&mw); | ||
8 | return a.exec(); | ||
9 | } | ||
10 | |||
diff --git a/noncore/net/opieirc/mainwindow.cpp b/noncore/net/opieirc/mainwindow.cpp new file mode 100644 index 0000000..bc0b0d1 --- a/dev/null +++ b/noncore/net/opieirc/mainwindow.cpp | |||
@@ -0,0 +1,79 @@ | |||
1 | #include <qpe/qpemenubar.h> | ||
2 | #include <qpe/resource.h> | ||
3 | #include <qpe/config.h> | ||
4 | #include <qpopupmenu.h> | ||
5 | |||
6 | #include "mainwindow.h" | ||
7 | #include "ircservertab.h" | ||
8 | #include "ircserverlist.h" | ||
9 | |||
10 | MainWindow::MainWindow(QWidget *parent, const char *name, WFlags f) : QMainWindow(parent, name, f) { | ||
11 | setCaption(tr("IRC Client")); | ||
12 | m_tabWidget = new QTabWidget(this); | ||
13 | connect(m_tabWidget, SIGNAL(currentChanged(QWidget *)), this, SLOT(tabSelected(QWidget *))); | ||
14 | setCentralWidget(m_tabWidget); | ||
15 | setToolBarsMovable(FALSE); | ||
16 | QPEMenuBar *menuBar = new QPEMenuBar(this); | ||
17 | QPopupMenu *irc = new QPopupMenu(this); | ||
18 | menuBar->insertItem(tr("IRC"), irc); | ||
19 | QAction *a = new QAction(tr("New connection"), Resource::loadPixmap("pass"), QString::null, 0, this, 0); | ||
20 | connect(a, SIGNAL(activated()), this, SLOT(newConnection())); | ||
21 | a->addTo(irc); | ||
22 | |||
23 | m_joinAction = new QAction(tr("Join channel"), Resource::loadPixmap("forward"), QString::null, 0, this, 0); | ||
24 | m_joinAction->setEnabled(FALSE); | ||
25 | connect(m_joinAction, SIGNAL(activated()), this, SLOT(join())); | ||
26 | m_joinAction->addTo(irc); | ||
27 | } | ||
28 | |||
29 | void MainWindow::tabSelected(QWidget *) { | ||
30 | m_joinAction->setEnabled(TRUE); | ||
31 | } | ||
32 | |||
33 | void MainWindow::closeTab() { | ||
34 | /* Does not directly close the tab but triggers an action | ||
35 | which at some point will close the tab using a callback */ | ||
36 | IRCTab *tab = (IRCTab *)m_tabWidget->currentPage(); | ||
37 | if (tab) { | ||
38 | tab->remove(); | ||
39 | } | ||
40 | } | ||
41 | |||
42 | void MainWindow::join() { | ||
43 | IRCTab *tab = (IRCTab *)m_tabWidget->currentPage(); | ||
44 | if (tab) { | ||
45 | tab->session()->join("#opie.de"); | ||
46 | } | ||
47 | } | ||
48 | |||
49 | void MainWindow::addTab(IRCTab *tab) { | ||
50 | m_tabWidget->addTab(tab, tab->title()); | ||
51 | m_tabWidget->showPage(tab); | ||
52 | tabSelected(tab); | ||
53 | } | ||
54 | |||
55 | void MainWindow::killTab(IRCTab *tab) { | ||
56 | m_tabWidget->removePage(tab); | ||
57 | /* there might be nicer ways to do this .. */ | ||
58 | delete tab; | ||
59 | } | ||
60 | |||
61 | void MainWindow::newConnection() { | ||
62 | IRCServer *server = new IRCServer(); | ||
63 | server->setHostname("irc.openprojects.net"); | ||
64 | server->setPort(6667); | ||
65 | server->setDescription("OpenProjects"); | ||
66 | server->setNick("opie-irc"); | ||
67 | server->setUsername("opie-irc"); | ||
68 | server->setRealname("opie-irc"); | ||
69 | IRCServerTab *serverTab = new IRCServerTab(server, this, m_tabWidget); | ||
70 | addTab(serverTab); | ||
71 | serverTab->doConnect(); | ||
72 | |||
73 | /* | ||
74 | * Serverlist : not functional yet | ||
75 | IRCServerList *list = new IRCServerList(this, "ServerList", TRUE); | ||
76 | list->exec(); | ||
77 | delete list; | ||
78 | */ | ||
79 | } | ||
diff --git a/noncore/net/opieirc/mainwindow.h b/noncore/net/opieirc/mainwindow.h new file mode 100644 index 0000000..c197f5b --- a/dev/null +++ b/noncore/net/opieirc/mainwindow.h | |||
@@ -0,0 +1,47 @@ | |||
1 | /* | ||
2 | OpieIRC - An embedded IRC client | ||
3 | Copyright (C) 2002 Wenzel Jakob | ||
4 | |||
5 | This program is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published by | ||
7 | the Free Software Foundation; either version 2 of the License, or | ||
8 | (at your option) any later version. | ||
9 | |||
10 | This program is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | ||
14 | |||
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 | ||
17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | |||
19 | */ | ||
20 | |||
21 | #ifndef __MAINWINDOW_H | ||
22 | #define __MAINWINDOW_H | ||
23 | |||
24 | #include <qmainwindow.h> | ||
25 | #include <qaction.h> | ||
26 | #include <qtabwidget.h> | ||
27 | #include "mainwindow.h" | ||
28 | #include "irctab.h" | ||
29 | |||
30 | class MainWindow : public QMainWindow { | ||
31 | Q_OBJECT | ||
32 | public: | ||
33 | MainWindow(QWidget *parent = 0, const char *name = 0, WFlags f = 0); | ||
34 | |||
35 | void addTab(IRCTab *tab); | ||
36 | void killTab(IRCTab *tab); | ||
37 | protected slots: | ||
38 | void newConnection(); | ||
39 | void closeTab(); | ||
40 | void join(); | ||
41 | void tabSelected(QWidget *widget); | ||
42 | protected: | ||
43 | QTabWidget *m_tabWidget; | ||
44 | QAction *m_joinAction; | ||
45 | }; | ||
46 | |||
47 | #endif /* __MAINWINDOW_H */ | ||
diff --git a/noncore/net/opieirc/opieirc.pro b/noncore/net/opieirc/opieirc.pro new file mode 100644 index 0000000..d24535b --- a/dev/null +++ b/noncore/net/opieirc/opieirc.pro | |||
@@ -0,0 +1,22 @@ | |||
1 | TEMPLATE= app | ||
2 | CONFIG = qt warn_on release | ||
3 | DESTDIR = $(OPIEDIR)/bin | ||
4 | HEADERS = ircchannel.h ircconnection.h \ | ||
5 | ircmessage.h \ | ||
6 | ircmessageparser.h ircoutput.h \ | ||
7 | ircperson.h ircserver.h ircsession.h \ | ||
8 | mainwindow.h irctab.h ircservertab.h \ | ||
9 | ircchanneltab.h ircchannellist.h \ | ||
10 | ircserverlist.h ircservereditor.h | ||
11 | SOURCES = ircchannel.cpp ircconnection.cpp \ | ||
12 | ircmessage.cpp \ | ||
13 | ircmessageparser.cpp ircoutput.cpp \ | ||
14 | ircperson.cpp ircserver.cpp \ | ||
15 | ircsession.cpp main.cpp mainwindow.cpp \ | ||
16 | irctab.cpp ircservertab.cpp \ | ||
17 | ircchanneltab.cpp ircchannellist.cpp \ | ||
18 | ircserverlist.cpp ircservereditor.cpp | ||
19 | INCLUDEPATH += $(OPIEDIR)/include | ||
20 | DEPENDPATH+= $(OPIEDIR)/include | ||
21 | LIBS += -lqpe | ||
22 | |||