summaryrefslogtreecommitdiff
authorskyhusker <skyhusker>2005-01-26 22:45:53 (UTC)
committer skyhusker <skyhusker>2005-01-26 22:45:53 (UTC)
commitf85af28663814f3262f5ecfcd20a4b4f67c23067 (patch) (unidiff)
tree994bd8c5a9f361ca7eff8ef9fb404f89f6f90f78
parentcbaf2c1c6eb42bc8a283a40fe922603a44c29304 (diff)
downloadopie-f85af28663814f3262f5ecfcd20a4b4f67c23067.zip
opie-f85af28663814f3262f5ecfcd20a4b4f67c23067.tar.gz
opie-f85af28663814f3262f5ecfcd20a4b4f67c23067.tar.bz2
* Created new class for IRCChannelPerson.
* Added whois, ping and version entries to channel popup menu. * Fixed action on CTCP PING reply (was interpreted as a request).
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/opieirc/ircchannel.cpp3
-rw-r--r--noncore/net/opieirc/ircchannel.h15
-rw-r--r--noncore/net/opieirc/ircchannellist.cpp16
-rw-r--r--noncore/net/opieirc/ircchannelperson.cpp62
-rw-r--r--noncore/net/opieirc/ircchannelperson.h34
-rw-r--r--noncore/net/opieirc/ircchanneltab.cpp18
-rw-r--r--noncore/net/opieirc/ircconnection.cpp24
-rw-r--r--noncore/net/opieirc/ircconnection.h6
-rw-r--r--noncore/net/opieirc/ircmessageparser.cpp132
-rw-r--r--noncore/net/opieirc/ircmessageparser.h2
-rw-r--r--noncore/net/opieirc/ircservertab.cpp3
-rw-r--r--noncore/net/opieirc/ircsession.cpp20
-rw-r--r--noncore/net/opieirc/ircsession.h4
-rw-r--r--noncore/net/opieirc/mainwindow.cpp4
-rw-r--r--noncore/net/opieirc/opieirc.pro6
15 files changed, 258 insertions, 91 deletions
diff --git a/noncore/net/opieirc/ircchannel.cpp b/noncore/net/opieirc/ircchannel.cpp
index 5c380e5..5d81596 100644
--- a/noncore/net/opieirc/ircchannel.cpp
+++ b/noncore/net/opieirc/ircchannel.cpp
@@ -1,47 +1,48 @@
1#include "ircchannel.h" 1#include "ircchannel.h"
2#include "ircchannelperson.h"
2 3
3IRCChannel::IRCChannel(QString channelname) { 4IRCChannel::IRCChannel(QString channelname) {
4 m_hasPeople = FALSE; 5 m_hasPeople = FALSE;
5 m_channelname = channelname; 6 m_channelname = channelname;
6} 7}
7 8
8IRCChannel::~IRCChannel() { 9IRCChannel::~IRCChannel() {
9 /* We want this to get deleted */ 10 /* We want this to get deleted */
10 m_people.setAutoDelete(TRUE); 11 m_people.setAutoDelete(TRUE);
11} 12}
12 13
13QString IRCChannel::channelname() { 14QString IRCChannel::channelname() {
14 return m_channelname; 15 return m_channelname;
15} 16}
16 17
17bool IRCChannel::hasPeople() { 18bool IRCChannel::hasPeople() {
18 return m_hasPeople; 19 return m_hasPeople;
19} 20}
20 21
21void IRCChannel::setHasPeople(bool hasPeople) { 22void IRCChannel::setHasPeople(bool hasPeople) {
22 m_hasPeople = hasPeople; 23 m_hasPeople = hasPeople;
23} 24}
24 25
25void IRCChannel::addPerson(IRCChannelPerson *person) { 26void IRCChannel::addPerson(IRCChannelPerson *person) {
26 m_people.append(person); 27 m_people.append(person);
27} 28}
28 29
29void IRCChannel::removePerson(IRCChannelPerson *person) { 30void IRCChannel::removePerson(IRCChannelPerson *person) {
30 m_people.remove(person); 31 m_people.remove(person);
31} 32}
32 33
33QListIterator<IRCChannelPerson> IRCChannel::people() { 34QListIterator<IRCChannelPerson> IRCChannel::people() {
34 QListIterator<IRCChannelPerson> it(m_people); 35 QListIterator<IRCChannelPerson> it(m_people);
35 return it; 36 return it;
36} 37}
37 38
38IRCChannelPerson *IRCChannel::getPerson(QString nickname) { 39IRCChannelPerson *IRCChannel::getPerson(QString nickname) {
39 QListIterator<IRCChannelPerson> it(m_people); 40 QListIterator<IRCChannelPerson> it(m_people);
40 for (; it.current(); ++it) { 41 for (; it.current(); ++it) {
41 if (it.current()->person->nick() == nickname) { 42 if (it.current()->nick() == nickname) {
42 return it.current(); 43 return it.current();
43 } 44 }
44 } 45 }
45 return 0; 46 return 0;
46} 47}
47 48
diff --git a/noncore/net/opieirc/ircchannel.h b/noncore/net/opieirc/ircchannel.h
index e78f182..a276f10 100644
--- a/noncore/net/opieirc/ircchannel.h
+++ b/noncore/net/opieirc/ircchannel.h
@@ -1,69 +1,58 @@
1/* 1/*
2 OpieIRC - An embedded IRC client 2 OpieIRC - An embedded IRC client
3 Copyright (C) 2002 Wenzel Jakob 3 Copyright (C) 2002 Wenzel Jakob
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18
19*/ 19*/
20 20
21#ifndef __IRCCHANNEL_H 21#ifndef __IRCCHANNEL_H
22#define __IRCCHANNEL_H 22#define __IRCCHANNEL_H
23 23
24#include <qobject.h> 24#include <qobject.h>
25#include <qlist.h> 25#include <qlist.h>
26#include <qstring.h> 26#include <qstring.h>
27#include "ircperson.h"
28 27
29/* Flags which a person can have inside a channel */ 28#include "ircperson.h"
30enum IRCChannelPersonFlag {
31 PERSON_FLAG_OP = 0x01,
32 PERSON_FLAG_VOICE = 0x02,
33 PERSON_FLAG_HALFOP = 0x04
34};
35 29
36/* This struct encapsulates a IRCPerson and adds 30class IRCChannelPerson;
37 channel specific information */
38typedef struct IRCChannelPerson {
39 IRCPerson *person;
40 unsigned int flags;
41};
42 31
43/* IRCChannel is the object-oriented representation 32/* IRCChannel is the object-oriented representation
44 of an IRC channel. It basically acts as a container 33 of an IRC channel. It basically acts as a container
45 for IRCChannelPersons */ 34 for IRCChannelPersons */
46class IRCChannel : public QObject { 35class IRCChannel : public QObject {
47 Q_OBJECT 36 Q_OBJECT
48public: 37public:
49 IRCChannel(QString channelname); 38 IRCChannel(QString channelname);
50 ~IRCChannel(); 39 ~IRCChannel();
51 40
52 void addPerson(IRCChannelPerson *person); 41 void addPerson(IRCChannelPerson *person);
53 void removePerson(IRCChannelPerson *person); 42 void removePerson(IRCChannelPerson *person);
54 IRCChannelPerson *getPerson(QString nickname); 43 IRCChannelPerson *getPerson(QString nickname);
55 QListIterator<IRCChannelPerson> people(); 44 QListIterator<IRCChannelPerson> people();
56 45
57 /* hasPeople identifies whether the irc channel is 46 /* hasPeople identifies whether the irc channel is
58 done synchronizing with the current state - 47 done synchronizing with the current state -
59 this is only relevant when joining a channel */ 48 this is only relevant when joining a channel */
60 void setHasPeople(bool hasPeople); 49 void setHasPeople(bool hasPeople);
61 QString channelname(); 50 QString channelname();
62 bool hasPeople(); 51 bool hasPeople();
63protected: 52protected:
64 QList<IRCChannelPerson> m_people; 53 QList<IRCChannelPerson> m_people;
65 QString m_channelname; 54 QString m_channelname;
66 bool m_hasPeople; 55 bool m_hasPeople;
67}; 56};
68 57
69#endif /* __IRCCHANNEL_H */ 58#endif /* __IRCCHANNEL_H */
diff --git a/noncore/net/opieirc/ircchannellist.cpp b/noncore/net/opieirc/ircchannellist.cpp
index c32c535..8cf144e 100644
--- a/noncore/net/opieirc/ircchannellist.cpp
+++ b/noncore/net/opieirc/ircchannellist.cpp
@@ -1,65 +1,67 @@
1#include <qpe/resource.h> 1#include <qpe/resource.h>
2
2#include "ircchannellist.h" 3#include "ircchannellist.h"
4#include "ircchannelperson.h"
3 5
4IRCChannelList::IRCChannelList(IRCChannel *channel, QWidget *parent, const char *name, WFlags f) : QListBox(parent, name, f) { 6IRCChannelList::IRCChannelList(IRCChannel *channel, QWidget *parent, const char *name, WFlags f) : QListBox(parent, name, f) {
5 m_channel = channel; 7 m_channel = channel;
6} 8}
7 9
8void IRCChannelList::update() { 10void IRCChannelList::update() {
9 QPixmap op = Resource::loadPixmap("opieirc/op"); 11 QPixmap op = Resource::loadPixmap("opieirc/op");
10 QPixmap hop = Resource::loadPixmap("opieirc/hop"); 12 QPixmap hop = Resource::loadPixmap("opieirc/hop");
11 QPixmap voice = Resource::loadPixmap("opieirc/voice"); 13 QPixmap voice = Resource::loadPixmap("opieirc/voice");
12 QListIterator<IRCChannelPerson> it = m_channel->people(); 14 QListIterator<IRCChannelPerson> it = m_channel->people();
13 clear(); 15 clear();
14 for (; it.current(); ++it) { 16 for (; it.current(); ++it) {
15 IRCChannelPerson *person = it.current(); 17 IRCChannelPerson *person = it.current();
16 if (person->flags & PERSON_FLAG_OP) { 18 if (person->flags() & IRCChannelPerson::PERSON_FLAG_OP) {
17 insertItem(op, "1" + person->person->nick()); 19 insertItem(op, "1" + person->nick());
18 } else if (person->flags & PERSON_FLAG_HALFOP) { 20 } else if (person->flags() & IRCChannelPerson::PERSON_FLAG_HALFOP) {
19 insertItem(op, "2" + person->person->nick()); 21 insertItem(op, "2" + person->nick());
20 } else if (person->flags & PERSON_FLAG_VOICE) { 22 } else if (person->flags() & IRCChannelPerson::PERSON_FLAG_VOICE) {
21 insertItem(voice, "3" + person->person->nick()); 23 insertItem(voice, "3" + person->nick());
22 } else { 24 } else {
23 insertItem("4" + person->person->nick()); 25 insertItem("4" + person->nick());
24 } 26 }
25 } 27 }
26 sort(); 28 sort();
27 adjustNicks(); 29 adjustNicks();
28} 30}
29 31
30 32
31bool IRCChannelList::hasPerson(QString nick) { 33bool IRCChannelList::hasPerson(QString nick) {
32 for (unsigned int i=0; i<count(); i++) { 34 for (unsigned int i=0; i<count(); i++) {
33 if (text(i) == nick) 35 if (text(i) == nick)
34 return TRUE; 36 return TRUE;
35 } 37 }
36 return FALSE; 38 return FALSE;
37} 39}
38 40
39bool IRCChannelList::removePerson(QString nick) { 41bool IRCChannelList::removePerson(QString nick) {
40 for (unsigned int i=0; i<count(); i++) { 42 for (unsigned int i=0; i<count(); i++) {
41 if (text(i) == nick){ 43 if (text(i) == nick){
42 removeItem(i); 44 removeItem(i);
43 return TRUE; 45 return TRUE;
44 } 46 }
45 } 47 }
46 return FALSE; 48 return FALSE;
47} 49}
48 50
49void IRCChannelList::adjustNicks() { 51void IRCChannelList::adjustNicks() {
50 QString txt; 52 QString txt;
51 QPixmap pm; 53 QPixmap pm;
52 54
53 for(unsigned int i=0; i<count(); i++) { 55 for(unsigned int i=0; i<count(); i++) {
54 txt = text(i).remove(0,1); 56 txt = text(i).remove(0,1);
55 if(pixmap(i)) { 57 if(pixmap(i)) {
56 pm = *pixmap(i); 58 pm = *pixmap(i);
57 removeItem(i); 59 removeItem(i);
58 insertItem(pm, txt, i); 60 insertItem(pm, txt, i);
59 } 61 }
60 else { 62 else {
61 removeItem(i); 63 removeItem(i);
62 insertItem(txt, i); 64 insertItem(txt, i);
63 } 65 }
64 } 66 }
65} 67}
diff --git a/noncore/net/opieirc/ircchannelperson.cpp b/noncore/net/opieirc/ircchannelperson.cpp
new file mode 100644
index 0000000..1e8ebe4
--- a/dev/null
+++ b/noncore/net/opieirc/ircchannelperson.cpp
@@ -0,0 +1,62 @@
1#include "ircperson.h"
2#include "ircchannelperson.h"
3
4#include <qstring.h>
5#include <qobject.h>
6
7IRCChannelPerson::IRCChannelPerson(IRCPerson *person)
8{
9 m_person = person;
10 m_flags = 0;
11}
12
13IRCChannelPerson::~IRCChannelPerson()
14{
15 //if(m_person)
16 // delete m_person;
17}
18
19QString IRCChannelPerson::setOp(const QString &nickname, bool set)
20{
21 if(set) {
22 m_flags |= PERSON_FLAG_OP;
23 return ( nickname + QObject::tr(" gives channel operator status to ") + nick());
24 }
25
26 m_flags &= 0xFFFF - PERSON_FLAG_OP;
27 return ( nickname + QObject::tr(" removes channel operator status from ") + nick());
28}
29
30QString IRCChannelPerson::setVoice(const QString &nickname, bool set)
31{
32 if(set) {
33 m_flags |= PERSON_FLAG_VOICE;
34 return ( nickname + QObject::tr(" gives voice to ") + nick() );
35 }
36
37 m_flags &= 0xFFFF - PERSON_FLAG_VOICE;
38 return ( nickname + QObject::tr(" removes voice from ") + nick());
39}
40
41QString IRCChannelPerson::nick()
42{
43 if(m_person)
44 return m_person->nick();
45
46 return QString::null;
47}
48
49void IRCChannelPerson::setFlags(int flags)
50{
51 m_flags = flags;
52}
53
54void IRCChannelPerson::setNick(const QString &nickname)
55{
56 m_person->setNick(nickname);
57}
58
59const unsigned int IRCChannelPerson::flags()
60{
61 return m_flags;
62}
diff --git a/noncore/net/opieirc/ircchannelperson.h b/noncore/net/opieirc/ircchannelperson.h
new file mode 100644
index 0000000..a8c4791
--- a/dev/null
+++ b/noncore/net/opieirc/ircchannelperson.h
@@ -0,0 +1,34 @@
1#ifndef IRCCHANNELPERSON_H
2#define IRCCHANNELPERSON_H
3
4class QString;
5class IRCPerson;
6
7/* This class encapsulates a IRCPerson and adds
8 * channel specific information */
9class IRCChannelPerson {
10
11public:
12 /* Flags which a person can have inside a channel */
13 enum IRCChannelPersonFlag {
14 PERSON_FLAG_OP = 0x01,
15 PERSON_FLAG_VOICE = 0x02,
16 PERSON_FLAG_HALFOP = 0x04
17 };
18
19 IRCChannelPerson(IRCPerson *person = 0);
20 ~IRCChannelPerson();
21
22 QString setOp(const QString &nickname, bool set);
23 QString setVoice(const QString &nickname, bool set);
24 QString nick();
25 const unsigned int flags();
26 void setFlags(int flags);
27 void setNick(const QString &nickname);
28
29protected:
30 IRCPerson *m_person;
31 unsigned int m_flags;
32};
33
34#endif
diff --git a/noncore/net/opieirc/ircchanneltab.cpp b/noncore/net/opieirc/ircchanneltab.cpp
index 4a35929..3272a8a 100644
--- a/noncore/net/opieirc/ircchanneltab.cpp
+++ b/noncore/net/opieirc/ircchanneltab.cpp
@@ -1,208 +1,216 @@
1#include <qpe/resource.h> 1#include <qpe/resource.h>
2#include <qwhatsthis.h> 2#include <qwhatsthis.h>
3#include <qhbox.h> 3#include <qhbox.h>
4#include <qdict.h> 4#include <qdict.h>
5 5
6#include "ircchanneltab.h" 6#include "ircchanneltab.h"
7#include "ircservertab.h" 7#include "ircservertab.h"
8#include "ircmessageparser.h" 8#include "ircmessageparser.h"
9 9
10#include <opie2/odebug.h>
10QDict<QString> IRCChannelTab::m_queuedMessages (17); 11QDict<QString> IRCChannelTab::m_queuedMessages (17);
11 12
12IRCChannelTab::IRCChannelTab(IRCChannel *channel, IRCServerTab *parentTab, MainWindow *mainWindow, QWidget *parent, const char *name, WFlags f) : IRCTab(parent, name, f) { 13IRCChannelTab::IRCChannelTab(IRCChannel *channel, IRCServerTab *parentTab, MainWindow *mainWindow, QWidget *parent, const char *name, WFlags f) : IRCTab(parent, name, f) {
13 m_mainWindow = mainWindow; 14 m_mainWindow = mainWindow;
14 m_parentTab = parentTab; 15 m_parentTab = parentTab;
15 m_channel = channel; 16 m_channel = channel;
16 m_description->setText(tr("Talking on channel") + " <b>" + channel->channelname() + "</b>"); 17 m_description->setText(tr("Talking on channel") + " <b>" + channel->channelname() + "</b>");
17 QHBox *hbox = new QHBox(this); 18 QHBox *hbox = new QHBox(this);
18 m_textview = new QTextView(hbox); 19 m_textview = new QTextView(hbox);
19 m_textview->setHScrollBarMode(QScrollView::AlwaysOff); 20 m_textview->setHScrollBarMode(QScrollView::AlwaysOff);
20 m_textview->setVScrollBarMode(QScrollView::AlwaysOn); 21 m_textview->setVScrollBarMode(QScrollView::AlwaysOn);
21 m_listVisible = TRUE; 22 m_listVisible = TRUE;
22 m_listButton = new QPushButton(">", m_textview); 23 m_listButton = new QPushButton(">", m_textview);
23 m_listButton->setFlat( true ); 24 m_listButton->setFlat( true );
24 m_textview->setCornerWidget(m_listButton); 25 m_textview->setCornerWidget(m_listButton);
25 m_textview->setTextFormat(RichText); 26 m_textview->setTextFormat(RichText);
26 QWhatsThis::add(m_textview, tr("Channel discussion")); 27 QWhatsThis::add(m_textview, tr("Channel discussion"));
27 connect(m_listButton, SIGNAL(clicked()), this, SLOT(toggleList())); 28 connect(m_listButton, SIGNAL(clicked()), this, SLOT(toggleList()));
28 m_list = new IRCChannelList(m_channel, hbox); 29 m_list = new IRCChannelList(m_channel, hbox);
29 m_list->update(); 30 m_list->update();
30 m_list->setMaximumWidth(LISTWIDTH); 31 m_list->setMaximumWidth(LISTWIDTH);
31 m_field = new IRCHistoryLineEdit(this); 32 m_field = new IRCHistoryLineEdit(this);
32 connect(m_field, SIGNAL(nextTab()), this, SIGNAL(nextTab())); 33 connect(m_field, SIGNAL(nextTab()), this, SIGNAL(nextTab()));
33 connect(m_field, SIGNAL(prevTab()), this, SIGNAL(prevTab())); 34 connect(m_field, SIGNAL(prevTab()), this, SIGNAL(prevTab()));
34 connect(m_field, SIGNAL(closeTab()), this, SLOT(remove())); 35 connect(m_field, SIGNAL(closeTab()), this, SLOT(remove()));
35 connect(this, SIGNAL(editFocus()), m_field, SLOT(setEditFocus())); 36 connect(this, SIGNAL(editFocus()), m_field, SLOT(setEditFocus()));
36 37
37 QWhatsThis::add(m_field, tr("Type your message here to participate in the channel discussion")); 38 QWhatsThis::add(m_field, tr("Type your message here to participate in the channel discussion"));
38 m_popup = new QPopupMenu(m_list); 39 m_popup = new QPopupMenu(m_list);
39 m_lines = 0; 40 m_lines = 0;
40 /* Required so that embedded-style "right" clicks work */ 41 /* Required so that embedded-style "right" clicks work */
41 QPEApplication::setStylusOperation(m_list->viewport(), QPEApplication::RightOnHold); 42 QPEApplication::setStylusOperation(m_list->viewport(), QPEApplication::RightOnHold);
42 connect(m_list, SIGNAL(mouseButtonPressed(int,QListBoxItem*,const QPoint&)), this, SLOT(mouseButtonPressed(int,QListBoxItem*,const QPoint&))); 43 connect(m_list, SIGNAL(mouseButtonPressed(int,QListBoxItem*,const QPoint&)), this, SLOT(mouseButtonPressed(int,QListBoxItem*,const QPoint&)));
43 /* Construct the popup menu */ 44 /* Construct the popup menu */
44 QPopupMenu *ctcpMenu = new QPopupMenu(m_list); 45 //QPopupMenu *ctcpMenu = new QPopupMenu(m_list);
45 m_popup->insertItem(Resource::loadPixmap("opieirc/query"), tr("Query"), this, SLOT(popupQuery())); 46 m_popup->insertItem(Resource::loadPixmap("opieirc/query"), tr("Query"), this, SLOT(popupQuery()));
46 ctcpMenu->insertItem(Resource::loadPixmap("opieirc/ping"), tr("Ping"), this, SLOT(popupPing())); 47 m_popup->insertSeparator();
47 ctcpMenu->insertItem(Resource::loadPixmap("opieirc/version"), tr("Version"), this, SLOT(popupVersion())); 48 m_popup->insertItem(Resource::loadPixmap("opieirc/ping"), tr("Ping"), this, SLOT(popupPing()));
48 ctcpMenu->insertItem(Resource::loadPixmap("opieirc/whois"), tr("Whois"), this, SLOT(popupWhois())); 49 m_popup->insertItem(Resource::loadPixmap("opieirc/version"), tr("Version"), this, SLOT(popupVersion()));
50 m_popup->insertItem(Resource::loadPixmap("opieirc/whois"), tr("Whois"), this, SLOT(popupWhois()));
51 //m_popup->insertItem(ctcpMenu, "CTCP");
49 connect(m_mainWindow, SIGNAL(updateScroll()), this, SLOT(scrolling())); 52 connect(m_mainWindow, SIGNAL(updateScroll()), this, SLOT(scrolling()));
50 m_layout->add(hbox); 53 m_layout->add(hbox);
51 hbox->show(); 54 hbox->show();
52 m_layout->add(m_field); 55 m_layout->add(m_field);
53 m_field->setFocus(); 56 m_field->setFocus();
54 m_field->setActiveWindow(); 57 m_field->setActiveWindow();
55 58
56 connect(m_field, SIGNAL(returnPressed()), this, SLOT(processCommand())); 59 connect(m_field, SIGNAL(returnPressed()), this, SLOT(processCommand()));
57 connect(m_list, SIGNAL(doubleClicked ( QListBoxItem * ) ), this, SLOT(popupQuery( QListBoxItem * ) )); 60 connect(m_list, SIGNAL(doubleClicked ( QListBoxItem * ) ), this, SLOT(popupQuery( QListBoxItem * ) ));
58 settingsChanged(); 61 settingsChanged();
59 62
60 if(m_queuedMessages[m_channel->channelname()]) { 63 if(m_queuedMessages[m_channel->channelname()]) {
61 appendText(*m_queuedMessages[m_channel->channelname()]); 64 appendText(*m_queuedMessages[m_channel->channelname()]);
62 delete m_queuedMessages[m_channel->channelname()]; 65 delete m_queuedMessages[m_channel->channelname()];
63 m_queuedMessages.remove(m_channel->channelname()); 66 m_queuedMessages.remove(m_channel->channelname());
64 } 67 }
65} 68}
66 69
67void IRCChannelTab::scrolling(){ 70void IRCChannelTab::scrolling(){
68 m_textview->ensureVisible(0, m_textview->contentsHeight()); 71 m_textview->ensureVisible(0, m_textview->contentsHeight());
69} 72}
70 73
71void IRCChannelTab::appendText(QString text) { 74void IRCChannelTab::appendText(QString text) {
72 /* not using append because it creates layout problems */ 75 /* not using append because it creates layout problems */
73 QString txt = m_textview->text() + IRCTab::appendTimestamp( text ); 76 QString txt = m_textview->text() + IRCTab::appendTimestamp( text );
74 if (m_maxLines > 0 && m_lines >= m_maxLines) { 77 if (m_maxLines > 0 && m_lines >= m_maxLines) {
75 int firstBreak = txt.find('\n'); 78 int firstBreak = txt.find('\n');
76 if (firstBreak != -1) { 79 if (firstBreak != -1) {
77 txt = "<qt bgcolor=\"" + m_backgroundColor + "\"/>" + txt.right(txt.length() - (firstBreak + 1)); 80 txt = "<qt bgcolor=\"" + m_backgroundColor + "\"/>" + txt.right(txt.length() - (firstBreak + 1));
78 } 81 }
79 } else { 82 } else {
80 m_lines++; 83 m_lines++;
81 } 84 }
82 m_textview->ensureVisible(0, m_textview->contentsHeight()); 85 m_textview->ensureVisible(0, m_textview->contentsHeight());
83 m_textview->setText(txt); 86 m_textview->setText(txt);
84 m_textview->ensureVisible(0, m_textview->contentsHeight()); 87 m_textview->ensureVisible(0, m_textview->contentsHeight());
85 88
86 int p1, p2; 89 int p1, p2;
87 if ( text.contains( IRCMessageParser::tr("Received a CTCP PING from ") ) ) 90 if ( text.contains( IRCMessageParser::tr("Received a CTCP PING from ") ) )
88 emit ping( title() ); 91 emit ping( title() );
89 else if ( (p1 = text.find("ping", 0, false) )!= -1 && (p2 = text.find( m_parentTab->server()->nick(), 0,false )) != -1 ) { 92 else if ( (p1 = text.find("ping", 0, false) )!= -1 && (p2 = text.find( m_parentTab->server()->nick(), 0,false )) != -1 ) {
90 int col = text.findRev("color", -1, false); 93 int col = text.findRev("color", -1, false);
91 if ( col < p2 ) 94 if ( col < p2 )
92 emit ping( title() ); 95 emit ping( title() );
93 96
94 } 97 }
95 98
96 emit changed(this); 99 emit changed(this);
97} 100}
98 101
99IRCChannelTab::~IRCChannelTab() { 102IRCChannelTab::~IRCChannelTab() {
100 m_parentTab->removeChannelTab(this); 103 m_parentTab->removeChannelTab(this);
101} 104}
102 105
103void IRCChannelTab::processCommand() { 106void IRCChannelTab::processCommand() {
104 QString text = m_field->text(); 107 QString text = m_field->text();
105 if (text.length()>0) { 108 if (text.length()>0) {
106 if (session()->isSessionActive()) { 109 if (session()->isSessionActive()) {
107 if (text.startsWith("/") && !text.startsWith("//")) { 110 if (text.startsWith("/") && !text.startsWith("//")) {
108 /* Command mode */ 111 /* Command mode */
109 m_parentTab->executeCommand(this, text);; 112 m_parentTab->executeCommand(this, text);;
110 } else { 113 } else {
111 if (text.startsWith("//")) 114 if (text.startsWith("//"))
112 text = text.right(text.length()-1); 115 text = text.right(text.length()-1);
113 session()->sendMessage(m_channel, m_field->text()); 116 session()->sendMessage(m_channel, m_field->text());
114 appendText("<font color=\"" + m_textColor + "\">&lt;</font><font color=\"" + m_selfColor + "\">"+m_parentTab->server()->nick()+"</font><font color=\"" + m_textColor + "\">&gt; "+IRCOutput::toHTML(m_field->text())+"</font><br>"); 117 appendText("<font color=\"" + m_textColor + "\">&lt;</font><font color=\"" + m_selfColor + "\">"+m_parentTab->server()->nick()+"</font><font color=\"" + m_textColor + "\">&gt; "+IRCOutput::toHTML(m_field->text())+"</font><br>");
115 } 118 }
116 } else { 119 } else {
117 appendText("<font color=\"" + m_errorColor + "\">"+tr("Disconnected")+"</font><br>"); 120 appendText("<font color=\"" + m_errorColor + "\">"+tr("Disconnected")+"</font><br>");
118 } 121 }
119 } 122 }
120 m_field->clear(); 123 m_field->clear();
121} 124}
122 125
123void IRCChannelTab::settingsChanged() { 126void IRCChannelTab::settingsChanged() {
124 m_textview->setText("<qt bgcolor=\"" + m_backgroundColor + "\"/>"); 127 m_textview->setText("<qt bgcolor=\"" + m_backgroundColor + "\"/>");
125 m_lines = 0; 128 m_lines = 0;
126} 129}
127 130
128void IRCChannelTab::toggleList() { 131void IRCChannelTab::toggleList() {
129 if (m_listVisible) { 132 if (m_listVisible) {
130 m_list->setMaximumWidth(0); 133 m_list->setMaximumWidth(0);
131 m_listButton->setText("<"); 134 m_listButton->setText("<");
132 } else { 135 } else {
133 m_list->setMaximumWidth(LISTWIDTH); 136 m_list->setMaximumWidth(LISTWIDTH);
134 m_listButton->setText(">"); 137 m_listButton->setText(">");
135 } 138 }
136 m_listVisible = !m_listVisible; 139 m_listVisible = !m_listVisible;
137} 140}
138 141
139void IRCChannelTab::mouseButtonPressed(int mouse, QListBoxItem *, const QPoint &point) { 142void IRCChannelTab::mouseButtonPressed(int mouse, QListBoxItem *, const QPoint &point) {
140 switch (mouse) { 143 switch (mouse) {
141 case 1: 144 case 1:
142 break; 145 break;
143 case 2: 146 case 2:
144 m_popup->popup(point); 147 m_popup->popup(point);
145 break; 148 break;
146 }; 149 };
147} 150}
148 151
149void IRCChannelTab::popupQuery( QListBoxItem *item) { 152void IRCChannelTab::popupQuery( QListBoxItem *item) {
150 if (item) { 153 if (item) {
151 IRCPerson *person = session()->getPerson(item->text()); 154 IRCPerson *person = session()->getPerson(item->text());
152 if (person) { 155 if (person) {
153 IRCQueryTab *tab = m_parentTab->getTabForQuery(person); 156 IRCQueryTab *tab = m_parentTab->getTabForQuery(person);
154 if (!tab) { 157 if (!tab) {
155 tab = new IRCQueryTab(person, m_parentTab, m_mainWindow, (QWidget *)parent()); 158 tab = new IRCQueryTab(person, m_parentTab, m_mainWindow, (QWidget *)parent());
156 m_parentTab->addQueryTab(tab); 159 m_parentTab->addQueryTab(tab);
157 m_mainWindow->addTab(tab); 160 m_mainWindow->addTab(tab);
158 } 161 }
159 } 162 }
160 } 163 }
161} 164}
162 165
163void IRCChannelTab::popupQuery() { 166void IRCChannelTab::popupQuery() {
164 if ( m_list->currentItem() != -1 ) 167 if ( m_list->currentItem() != -1 )
165 popupQuery( m_list->item(m_list->currentItem())); 168 popupQuery( m_list->item(m_list->currentItem()));
166} 169}
167 170
168void IRCChannelTab::popupPing() { 171void IRCChannelTab::popupPing() {
169 //HAHA, no wonder these don't work 172 if(m_list->currentItem() != -1)
173 m_parentTab->session()->sendCTCPPing(m_list->text(m_list->currentItem()));
170} 174}
171 175
172void IRCChannelTab::popupVersion() { 176void IRCChannelTab::popupVersion() {
177 if(m_list->currentItem() != -1)
178 m_parentTab->session()->sendCTCPRequest(m_list->text(m_list->currentItem()), "VERSION", "");
173} 179}
174 180
175void IRCChannelTab::popupWhois() { 181void IRCChannelTab::popupWhois() {
182 if(m_list->currentItem() != -1)
183 m_parentTab->session()->whois(m_list->text(m_list->currentItem()));
176} 184}
177 185
178QString IRCChannelTab::title() { 186QString IRCChannelTab::title() {
179 return m_channel->channelname(); 187 return m_channel->channelname();
180} 188}
181 189
182IRCSession *IRCChannelTab::session() { 190IRCSession *IRCChannelTab::session() {
183 return m_parentTab->session(); 191 return m_parentTab->session();
184} 192}
185 193
186void IRCChannelTab::remove() { 194void IRCChannelTab::remove() {
187 if (session()->isSessionActive()) { 195 if (session()->isSessionActive()) {
188 session()->part(m_channel); 196 session()->part(m_channel);
189 } else { 197 } else {
190 m_mainWindow->killTab(this); 198 m_mainWindow->killTab(this);
191 } 199 }
192} 200}
193 201
194void IRCChannelTab::enqueue(const QString &channel, const QString &message) { 202void IRCChannelTab::enqueue(const QString &channel, const QString &message) {
195 if (m_queuedMessages.count() == (m_queuedMessages.size() - 1) ) 203 if (m_queuedMessages.count() == (m_queuedMessages.size() - 1) )
196 /* 17 messages max */ 204 /* 17 messages max */
197 return; 205 return;
198 m_queuedMessages.insert(channel, new QString(message)); 206 m_queuedMessages.insert(channel, new QString(message));
199} 207}
200 208
201IRCChannel *IRCChannelTab::channel() { 209IRCChannel *IRCChannelTab::channel() {
202 return m_channel; 210 return m_channel;
203} 211}
204 212
205IRCChannelList *IRCChannelTab::list() { 213IRCChannelList *IRCChannelTab::list() {
206 return m_list; 214 return m_list;
207} 215}
208 216
diff --git a/noncore/net/opieirc/ircconnection.cpp b/noncore/net/opieirc/ircconnection.cpp
index 2325cca..88e63f7 100644
--- a/noncore/net/opieirc/ircconnection.cpp
+++ b/noncore/net/opieirc/ircconnection.cpp
@@ -1,102 +1,122 @@
1#include <unistd.h> 1#include <unistd.h>
2#include <string.h> 2#include <string.h>
3
4#include <qstringlist.h>
5#include <qdatetime.h>
6
3#include "ircconnection.h" 7#include "ircconnection.h"
4 8
5IRCConnection::IRCConnection(IRCServer *server) { 9IRCConnection::IRCConnection(IRCServer *server) {
6 m_server = server; 10 m_server = server;
7 m_socket = new QSocket(this); 11 m_socket = new QSocket(this);
8 m_connected = FALSE; 12 m_connected = FALSE;
9 m_loggedIn = FALSE; 13 m_loggedIn = FALSE;
10 connect(m_socket, SIGNAL(connected()), this, SLOT(login())); 14 connect(m_socket, SIGNAL(connected()), this, SLOT(login()));
11 connect(m_socket, SIGNAL(readyRead()), this, SLOT(dataReady())); 15 connect(m_socket, SIGNAL(readyRead()), this, SLOT(dataReady()));
12 connect(m_socket, SIGNAL(error(int)), this, SLOT(error(int))); 16 connect(m_socket, SIGNAL(error(int)), this, SLOT(error(int)));
13 connect(m_socket, SIGNAL(connectionClosed()), this, SLOT(disconnect())); 17 connect(m_socket, SIGNAL(connectionClosed()), this, SLOT(disconnect()));
14 connect(m_socket, SIGNAL(delayedCloseFinished()), this, SLOT(disconnect())); 18 connect(m_socket, SIGNAL(delayedCloseFinished()), this, SLOT(disconnect()));
15} 19}
16 20
17/* Connect to the IRC server */ 21/* Connect to the IRC server */
18void IRCConnection::doConnect() { 22void IRCConnection::doConnect() {
19 ASSERT(!m_connected); 23 ASSERT(!m_connected);
20 m_socket->connectToHost(m_server->hostname(), m_server->port()); 24 m_socket->connectToHost(m_server->hostname(), m_server->port());
21} 25}
22 26
23/* Send commands to the IRC server */ 27/* Send commands to the IRC server */
24void IRCConnection::sendLine(QString line) { 28void IRCConnection::sendLine(QString line) {
25 while((line.right(1) == "\n") || (line.right(1) == "\r")) 29 while((line.right(1) == "\n") || (line.right(1) == "\r"))
26 line = line.left(line.length() - 1); 30 line = line.left(line.length() - 1);
27 line.append("\r\n"); 31 line.append("\r\n");
28 m_socket->writeBlock(line, line.length()); 32 m_socket->writeBlock(line, line.length());
29} 33}
30 34
31void IRCConnection::sendCTCP(QString nick, QString line) { 35void IRCConnection::sendCTCPReply(const QString &nickname, const QString &type, const QString &args) {
32 sendLine("NOTICE " + nick + " :\001"+line+"\001"); 36 sendLine("NOTICE " + nickname + " :\001" + type + " " + args + "\001");
37}
38
39void IRCConnection::sendCTCPRequest(const QString &nickname, const QString &type, const QString &args) {
40 sendLine("PRIVMSG " + nickname + " :\001" + type + " " + args + "\001");
41}
42
43void IRCConnection::sendCTCPPing(const QString &nickname) {
44 QDateTime tm;
45 tm.setTime_t(0);
46 QString strtime = QString::number(tm.secsTo(QDateTime::currentDateTime()));
47 sendCTCPRequest(nickname, "PING", strtime);
48}
49
50void IRCConnection::whois(const QString &nickname) {
51 sendLine("WHOIS " + nickname);
33} 52}
34 53
35/* 54/*
36 * login() is called right after the connection 55 * login() is called right after the connection
37 * to the IRC server has been established 56 * to the IRC server has been established
38 */ 57 */
39void IRCConnection::login() { 58void IRCConnection::login() {
40 char hostname[256]; 59 char hostname[256];
41 QString loginString; 60 QString loginString;
42 61
43 emit outputReady(IRCOutput(OUTPUT_CLIENTMESSAGE, tr("Connected, logging in .."))); 62 emit outputReady(IRCOutput(OUTPUT_CLIENTMESSAGE, tr("Connected, logging in ..")));
44 m_connected = TRUE; 63 m_connected = TRUE;
45 gethostname(hostname, sizeof(hostname)-1); 64 gethostname(hostname, sizeof(hostname)-1);
46 hostname[sizeof (hostname) - 1] = 0; 65 hostname[sizeof (hostname) - 1] = 0;
47 66
48 /* Create a logon string and send it */ 67 /* Create a logon string and send it */
49 if (m_server->password().length()>0) { 68 if (m_server->password().length()>0) {
50 loginString += "PASS " + m_server->password() + "\r\n"; 69 loginString += "PASS " + m_server->password() + "\r\n";
51 } 70 }
52 loginString += "NICK " + m_server->nick() + "\r\n" + 71 loginString += "NICK " + m_server->nick() + "\r\n" +
53 "USER " + m_server->username() + " " + hostname + 72 "USER " + m_server->username() + " " + hostname +
54 " " + m_server->hostname() + " :" + m_server->realname() + "\r\n"; 73 " " + m_server->hostname() + " :" + m_server->realname() + "\r\n";
55 sendLine(loginString); 74 sendLine(loginString);
56} 75}
57 76
58/* Called when data arrives on the socket */ 77/* Called when data arrives on the socket */
59void IRCConnection::dataReady() { 78void IRCConnection::dataReady() {
60 while(m_socket->canReadLine()) { 79 while(m_socket->canReadLine()) {
61 IRCMessage message(m_socket->readLine()); 80 IRCMessage message(m_socket->readLine());
62 if (!m_loggedIn && message.isNumerical() && message.commandNumber() == 1) { 81 if (!m_loggedIn && message.isNumerical() && message.commandNumber() == 1) {
63 /* Now autojoin all channels specified inside the server profile */ 82 /* Now autojoin all channels specified inside the server profile */
64 QStringList channels = QStringList::split(QChar(','), m_server->channels()); 83 QStringList channels = QStringList::split(QChar(','), m_server->channels());
65 for (QStringList::Iterator it = channels.begin(); it != channels.end(); ++it) { 84 for (QStringList::Iterator it = channels.begin(); it != channels.end(); ++it) {
66 QString channelName = (*it).stripWhiteSpace(); 85 QString channelName = (*it).stripWhiteSpace();
67 if (channelName.startsWith("#") || channelName.startsWith("+")) { 86 if (channelName.startsWith("#") || channelName.startsWith("+")) {
68 sendLine("JOIN "+ channelName); 87 sendLine("JOIN "+ channelName);
69 } 88 }
70 } 89 }
71 m_loggedIn = TRUE; 90 m_loggedIn = TRUE;
72 emit outputReady(IRCOutput(OUTPUT_CLIENTMESSAGE, tr("Successfully logged in."))); 91 emit outputReady(IRCOutput(OUTPUT_CLIENTMESSAGE, tr("Successfully logged in.")));
73 } 92 }
74 emit messageArrived(&message); 93 emit messageArrived(&message);
75 } 94 }
76} 95}
77 96
78/* Called if any type of socket error occurs */ 97/* Called if any type of socket error occurs */
79void IRCConnection::error(int num) { 98void IRCConnection::error(int num) {
80 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Socket error : ") + strerror(num))); 99 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Socket error : ") + strerror(num)));
81} 100}
82 101
83void IRCConnection::disconnect() { 102void IRCConnection::disconnect() {
84 m_connected = FALSE; 103 m_connected = FALSE;
85 m_loggedIn = FALSE; 104 m_loggedIn = FALSE;
86 emit outputReady(IRCOutput(OUTPUT_CONNCLOSE, tr("Connection closed"))); 105 emit outputReady(IRCOutput(OUTPUT_CONNCLOSE, tr("Connection closed")));
87} 106}
88 107
89bool IRCConnection::isConnected() { 108bool IRCConnection::isConnected() {
90 return m_connected; 109 return m_connected;
91} 110}
92 111
93bool IRCConnection::isLoggedIn() { 112bool IRCConnection::isLoggedIn() {
94 return m_loggedIn; 113 return m_loggedIn;
95} 114}
96 115
97void IRCConnection::close() { 116void IRCConnection::close() {
98 m_socket->close(); 117 m_socket->close();
99 if (m_socket->state()==QSocket::Idle) { 118 if (m_socket->state()==QSocket::Idle) {
100 disconnect(); 119 disconnect();
101 } 120 }
102} 121}
122
diff --git a/noncore/net/opieirc/ircconnection.h b/noncore/net/opieirc/ircconnection.h
index 75cdf6d..382b1c0 100644
--- a/noncore/net/opieirc/ircconnection.h
+++ b/noncore/net/opieirc/ircconnection.h
@@ -1,65 +1,69 @@
1/* 1/*
2 OpieIRC - An embedded IRC client 2 OpieIRC - An embedded IRC client
3 Copyright (C) 2002 Wenzel Jakob 3 Copyright (C) 2002 Wenzel Jakob
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18
19*/ 19*/
20 20
21#ifndef __IRCCONNECTION_H 21#ifndef __IRCCONNECTION_H
22#define __IRCCONNECTION_H 22#define __IRCCONNECTION_H
23 23
24#include <qsocket.h> 24#include <qsocket.h>
25#include "ircserver.h" 25#include "ircserver.h"
26#include "ircmessage.h" 26#include "ircmessage.h"
27#include "ircoutput.h" 27#include "ircoutput.h"
28 28
29/* IRCConnection acts as a wrapper around QSocket 29/* IRCConnection acts as a wrapper around QSocket
30 and is responsible for the communication with the 30 and is responsible for the communication with the
31 IRC server */ 31 IRC server */
32class IRCConnection : public QObject { 32class IRCConnection : public QObject {
33 Q_OBJECT 33 Q_OBJECT
34public: 34public:
35 IRCConnection(IRCServer *server); 35 IRCConnection(IRCServer *server);
36 void doConnect(); 36 void doConnect();
37 /* used to send commands to the IRC server */ 37 /* used to send commands to the IRC server */
38 void sendLine(QString line); 38 void sendLine(QString line);
39 /* used to send CTCP commands to the IRC server */ 39 /* used to send CTCP commands to the IRC server */
40 void sendCTCP(QString nick, QString line); 40 void sendCTCPReply(const QString &nickname, const QString &type, const QString &args);
41 void sendCTCPRequest(const QString &nickname, const QString &type, const QString &args);
42 void sendCTCPPing(const QString &nickname);
43 void whois(const QString &nickname);
44 void sendCTCPping(const QString &nickname);
41 void close(); 45 void close();
42 bool isConnected(); 46 bool isConnected();
43 bool isLoggedIn(); 47 bool isLoggedIn();
44signals: 48signals:
45 /* triggered when the server sent us a message */ 49 /* triggered when the server sent us a message */
46 void messageArrived(IRCMessage *message); 50 void messageArrived(IRCMessage *message);
47 /* Used to send commands to the UI (such as displaying text etc) */ 51 /* Used to send commands to the UI (such as displaying text etc) */
48 void outputReady(IRCOutput output); 52 void outputReady(IRCOutput output);
49protected slots: 53protected slots:
50 /* automatically executed after the connection is established */ 54 /* automatically executed after the connection is established */
51 void login(); 55 void login();
52 /* called when there are socket errors */ 56 /* called when there are socket errors */
53 void error(int num); 57 void error(int num);
54 /* called when data arrived on m_socket (triggers messageArrived) */ 58 /* called when data arrived on m_socket (triggers messageArrived) */
55 void dataReady(); 59 void dataReady();
56 /* called when the IRC server closes the connection */ 60 /* called when the IRC server closes the connection */
57 void disconnect(); 61 void disconnect();
58protected: 62protected:
59 IRCServer *m_server; 63 IRCServer *m_server;
60 QSocket *m_socket; 64 QSocket *m_socket;
61 bool m_connected; 65 bool m_connected;
62 bool m_loggedIn; 66 bool m_loggedIn;
63}; 67};
64 68
65#endif /* __IRCCONNECTION_H */ 69#endif /* __IRCCONNECTION_H */
diff --git a/noncore/net/opieirc/ircmessageparser.cpp b/noncore/net/opieirc/ircmessageparser.cpp
index cfad2c1..9c1492c 100644
--- a/noncore/net/opieirc/ircmessageparser.cpp
+++ b/noncore/net/opieirc/ircmessageparser.cpp
@@ -1,625 +1,641 @@
1#include <qtextstream.h> 1#include <qtextstream.h>
2#include <qdatetime.h> 2#include <qdatetime.h>
3 3
4#include "ircmessageparser.h" 4#include "ircmessageparser.h"
5#include "ircversion.h" 5#include "ircversion.h"
6#include "ircchannelperson.h"
7//#include "transferreceiver.h"
6 8
7/* Lookup table for literal commands */ 9/* Lookup table for literal commands */
8IRCLiteralMessageParserStruct IRCMessageParser::literalParserProcTable[] = { 10IRCLiteralMessageParserStruct IRCMessageParser::literalParserProcTable[] = {
9 { "PING", FUNC(parseLiteralPing) }, 11 { "PING", FUNC(parseLiteralPing) },
10 { "NOTICE", FUNC(parseLiteralNotice) }, 12 { "NOTICE", FUNC(parseLiteralNotice) },
11 { "JOIN", FUNC(parseLiteralJoin) }, 13 { "JOIN", FUNC(parseLiteralJoin) },
12 { "PRIVMSG", FUNC(parseLiteralPrivMsg) }, 14 { "PRIVMSG", FUNC(parseLiteralPrivMsg) },
13 { "NICK", FUNC(parseLiteralNick) }, 15 { "NICK", FUNC(parseLiteralNick) },
14 { "PART", FUNC(parseLiteralPart) }, 16 { "PART", FUNC(parseLiteralPart) },
15 { "QUIT", FUNC(parseLiteralQuit) }, 17 { "QUIT", FUNC(parseLiteralQuit) },
16 { "ERROR", FUNC(parseLiteralError) }, 18 { "ERROR", FUNC(parseLiteralError) },
17 { "ERROR:", FUNC(parseLiteralError) }, 19 { "ERROR:", FUNC(parseLiteralError) },
18 { "MODE", FUNC(parseLiteralMode) }, 20 { "MODE", FUNC(parseLiteralMode) },
19 { "KICK", FUNC(parseLiteralKick) }, 21 { "KICK", FUNC(parseLiteralKick) },
20 { "TOPIC", FUNC(parseLiteralTopic) }, 22 { "TOPIC", FUNC(parseLiteralTopic) },
21 { 0 , 0 } 23 { 0 , 0 }
22}; 24};
23 25
24/* Lookup table for literal commands */ 26/* Lookup table for literal commands */
25IRCCTCPMessageParserStruct IRCMessageParser::ctcpParserProcTable[] = { 27IRCCTCPMessageParserStruct IRCMessageParser::ctcpParserProcTable[] = {
26 { "PING", FUNC(parseCTCPPing) }, 28 { "PING", FUNC(parseCTCPPing) },
27 { "VERSION", FUNC(parseCTCPVersion) }, 29 { "VERSION", FUNC(parseCTCPVersion) },
28 { "ACTION", FUNC(parseCTCPAction) }, 30 { "ACTION", FUNC(parseCTCPAction) },
31 { "DCC", FUNC(parseCTCPDCC) },
29 { 0 , 0 } 32 { 0 , 0 }
30}; 33};
31 34
32/* Lookup table for numerical commands 35/* Lookup table for numerical commands
33 * According to: 36 * According to:
34 * http://www.faqs.org/rfcs/rfc1459.html 37 * http://www.faqs.org/rfcs/rfc1459.html
35 * http://www.faqs.org/rfcs/rfc2812.html 38 * http://www.faqs.org/rfcs/rfc2812.html
36*/ 39*/
37 40
38IRCNumericalMessageParserStruct IRCMessageParser::numericalParserProcTable[] = { 41IRCNumericalMessageParserStruct IRCMessageParser::numericalParserProcTable[] = {
39 { 1, "%1", "1", FUNC(parseNumericalServerName) }, // RPL_WELCOME 42 { 1, "%1", "1", FUNC(parseNumericalServerName) }, // RPL_WELCOME
40 { 2, "%1", "1", 0 }, // RPL_YOURHOST 43 { 2, "%1", "1", 0 }, // RPL_YOURHOST
41 { 3, "%1", "1", 0 }, // RPL_CREATED 44 { 3, "%1", "1", 0 }, // RPL_CREATED
42 { 4, QT_TR_NOOP("Server %1 version %2 supports usermodes '%3' and channelmodes '%4'"), "1:4", FUNC(parseNumericalServerFeatures) }, // RPL_MYINFO 45 { 4, QT_TR_NOOP("Server %1 version %2 supports usermodes '%3' and channelmodes '%4'"), "1:4", FUNC(parseNumericalServerFeatures) }, // RPL_MYINFO
43 { 5, 0, 0, FUNC(parseNumericalServerProtocol) }, // RPL_BOUNCE, RPL_PROTOCTL 46 { 5, 0, 0, FUNC(parseNumericalServerProtocol) }, // RPL_BOUNCE, RPL_PROTOCTL
44 { 250, "%1", "1", 0 }, // RPL_STATSCONN 47 { 250, "%1", "1", 0 }, // RPL_STATSCONN
45 { 251, "%1", "1", 0 }, // RPL_LUSERCLIENT 48 { 251, "%1", "1", 0 }, // RPL_LUSERCLIENT
46 { 252, QT_TR_NOOP("There are %1 operators connected"), "1", 0 }, // RPL_LUSEROP 49 { 252, QT_TR_NOOP("There are %1 operators connected"), "1", 0 }, // RPL_LUSEROP
47 { 253, QT_TR_NOOP("There are %1 unknown connection(s)"), "1", 0 }, // RPL_LUSERUNKNOWN 50 { 253, QT_TR_NOOP("There are %1 unknown connection(s)"), "1", 0 }, // RPL_LUSERUNKNOWN
48 { 254, QT_TR_NOOP("There are %1 channels formed"), "1", 0 }, // RPL_LUSERCHANNELS 51 { 254, QT_TR_NOOP("There are %1 channels formed"), "1", 0 }, // RPL_LUSERCHANNELS
49 { 255, "%1", "1", 0 }, // RPL_LUSERME 52 { 255, "%1", "1", 0 }, // RPL_LUSERME
50 { 263, QT_TR_NOOP("Please wait a while and try again"), 0, 0 }, // RPL_TRYAGAIN 53 { 263, QT_TR_NOOP("Please wait a while and try again"), 0, 0 }, // RPL_TRYAGAIN
51 { 265, "%1", "1", 0 }, // RPL_LOCALUSERS 54 { 265, "%1", "1", 0 }, // RPL_LOCALUSERS
52 { 266, "%1", "1", 0 }, // RPL_GLOBALUSERS 55 { 266, "%1", "1", 0 }, // RPL_GLOBALUSERS
53 { 311, QT_TR_NOOP("Whois %1 (%2@%3)\nReal name: %4"), "1:3,5" }, // RPL_WHOISUSER 56 { 311, QT_TR_NOOP("Whois %1 (%2@%3)\nReal name: %4"), "1:3,5", 0 }, // RPL_WHOISUSER
54 { 312, QT_TR_NOOP("%1 is using server %2"), "1,2", 0 }, // RPL_WHOISSERVER 57 { 312, QT_TR_NOOP("%1 is using server %2"), "1,2", 0 }, // RPL_WHOISSERVER
55 { 317, 0, 0, FUNC(parseNumericalWhoisIdle) }, // RPL_WHOISIDLE 58 { 317, 0, 0, FUNC(parseNumericalWhoisIdle) }, // RPL_WHOISIDLE
56 { 318, "%1 :%2", "1,2", 0 }, // RPL_ENDOFWHOIS 59 { 318, "%1 :%2", "1,2", 0 }, // RPL_ENDOFWHOIS
60 { 319, QT_TR_NOOP("%1 is on channels: %2"), "1,2", 0 }, // RPL_WHOISCHANNELS
57 { 320, "%1 %2", "1,2", 0}, // RPL_WHOISVIRT 61 { 320, "%1 %2", "1,2", 0}, // RPL_WHOISVIRT
58 { 332, 0, 0, FUNC(parseNumericalTopic) }, // RPL_TOPIC 62 { 332, 0, 0, FUNC(parseNumericalTopic) }, // RPL_TOPIC
59 { 333, 0, 0, FUNC(parseNumericalTopicWhoTime) }, // RPL_TOPICWHOTIME*/ 63 { 333, 0, 0, FUNC(parseNumericalTopicWhoTime) }, // RPL_TOPICWHOTIME*/
60 { 353, QT_TR_NOOP("Names for %1: %2"), "2,3", FUNC(parseNumericalNames) }, // RPL_NAMREPLY 64 { 353, QT_TR_NOOP("Names for %1: %2"), "2,3", FUNC(parseNumericalNames) }, // RPL_NAMREPLY
61 { 366, "%1 :%2", "1,2", FUNC(parseNumericalEndOfNames) }, // RPL_ENDOFNAMES 65 { 366, "%1 :%2", "1,2", FUNC(parseNumericalEndOfNames) }, // RPL_ENDOFNAMES
62 { 369, "%1 :%2", "1,2", 0 }, // RPL_ENDOFWHOWAS 66 { 369, "%1 :%2", "1,2", 0 }, // RPL_ENDOFWHOWAS
63 { 372, "%1", "1", 0 }, // RPL_MOTD 67 { 372, "%1", "1", 0 }, // RPL_MOTD
64 { 375, "%1", "1", 0 }, // RPL_MOTDSTART 68 { 375, "%1", "1", 0 }, // RPL_MOTDSTART
65 { 376, "%1", "1", 0 }, // RPL_ENDOFMOTD 69 { 376, "%1", "1", 0 }, // RPL_ENDOFMOTD
66 { 377, "%1", "1", 0 }, // RPL_MOTD2 70 { 377, "%1", "1", 0 }, // RPL_MOTD2
67 { 378, "%1", "1", 0 }, // RPL_MOTD3 71 { 378, "%1", "1", 0 }, // RPL_MOTD3
68 { 391, QT_TR_NOOP("Time on server %1 is %2"), "1,2", 0 }, // RPL_TIME 72 { 391, QT_TR_NOOP("Time on server %1 is %2"), "1,2", 0 }, // RPL_TIME
69 { 401, QT_TR_NOOP("Channel or nick %1 doesn't exists"), "1", 0 }, // ERR_NOSUCHNICK 73 { 401, QT_TR_NOOP("Channel or nick %1 doesn't exists"), "1", 0 }, // ERR_NOSUCHNICK
70 { 406, QT_TR_NOOP("There is no history information for %1"), "1" }, // ERR_WASNOSUCHNICK 74 { 406, QT_TR_NOOP("There is no history information for %1"), "1", 0 }, // ERR_WASNOSUCHNICK
71 { 409, "%1", "1", 0 }, // ERR_NOORIGIN 75 { 409, "%1", "1", 0 }, // ERR_NOORIGIN
72 { 411, "%1", "1", 0 }, // ERR_NORECIPIENT 76 { 411, "%1", "1", 0 }, // ERR_NORECIPIENT
73 { 412, "%1", "1", 0 }, // ERR_NOTEXTTOSEND 77 { 412, "%1", "1", 0 }, // ERR_NOTEXTTOSEND
74 { 421, QT_TR_NOOP("Unknown command: %1"), "1", 0 }, // ERR_ERR_UNKNOWNCOMMAND 78 { 421, QT_TR_NOOP("Unknown command: %1"), "1", 0 }, // ERR_ERR_UNKNOWNCOMMAND
75 { 422, "%1", "1", 0 }, // ERR_NOMOTD 79 { 422, "%1", "1", 0 }, // ERR_NOMOTD
76 { 433, QT_TR_NOOP("Can't change nick to %1: %2"), "1,2", FUNC(parseNumericalNicknameInUse) }, // ERR_NICKNAMEINUSE 80 { 433, QT_TR_NOOP("Can't change nick to %1: %2"), "1,2", FUNC(parseNumericalNicknameInUse) }, // ERR_NICKNAMEINUSE
77 { 442, QT_TR_NOOP("You're not on channel %1"), "1", 0}, // ERR_NOTONCHANNEL 81 { 442, QT_TR_NOOP("You're not on channel %1"), "1", 0}, // ERR_NOTONCHANNEL
78 { 477, "%1", "1", 0 }, // ERR_NOCHANMODES || ERR_NEEDREGGEDNICK 82 { 477, "%1", "1", 0 }, // ERR_NOCHANMODES || ERR_NEEDREGGEDNICK
79 { 482, QT_TR_NOOP("[%1] Operation not permitted, you don't have enough channel privileges"), "1", 0 }, //ERR_CHANOPRIVSNEEDED 83 { 482, QT_TR_NOOP("[%1] Operation not permitted, you don't have enough channel privileges"), "1", 0 }, //ERR_CHANOPRIVSNEEDED
80 { 0, 0, 0, 0 } 84 { 0, 0, 0, 0 }
81}; 85};
82 86
83 87
84IRCMessageParser::IRCMessageParser(IRCSession *session) { 88IRCMessageParser::IRCMessageParser(IRCSession *session) {
85 m_session = session; 89 m_session = session;
86} 90}
87 91
88void IRCMessageParser::parse(IRCMessage *message) { 92void IRCMessageParser::parse(IRCMessage *message) {
89 /* Find out what kind of message we have here and call the appropriate handler using 93 /* Find out what kind of message we have here and call the appropriate handler using
90 the parser tables. If no handler can be found, print out an error message */ 94 the parser tables. If no handler can be found, print out an error message */
91 if (message->isNumerical()) { 95 if (message->isNumerical()) {
92 for (int i=0; i<numericalParserProcTable[i].commandNumber; i++) { 96 for (int i=0; i<numericalParserProcTable[i].commandNumber; i++) {
93 if (message->commandNumber() == numericalParserProcTable[i].commandNumber) { 97 if (message->commandNumber() == numericalParserProcTable[i].commandNumber) {
94 parseNumerical(message, i); 98 parseNumerical(message, i);
95 return; 99 return;
96 } 100 }
97 } 101 }
98 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received unhandled numeric command: %1").arg( QString::number(message->commandNumber()) ))); 102 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received unhandled numeric command: %1").arg( QString::number(message->commandNumber()) )));
99 } else if (message->isCTCP()) { 103 } else if (message->isCTCP()) {
100 for (int i=0; ctcpParserProcTable[i].commandName; i++) { 104 for (int i=0; ctcpParserProcTable[i].commandName; i++) {
101 if (message->ctcpCommand() == ctcpParserProcTable[i].commandName) { 105 if (message->ctcpCommand() == ctcpParserProcTable[i].commandName) {
102 (this->*(ctcpParserProcTable[i].proc))(message); 106 parseCTCP(message, i);
103 return; 107 return;
104 } 108 }
105 } 109 }
106 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received unhandled ctcp command: %1").arg( message->ctcpCommand())) ); 110 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received unhandled ctcp command: %1").arg( message->ctcpCommand())) );
107 } else { 111 } else {
108 for (int i=0; literalParserProcTable[i].commandName; i++) { 112 for (int i=0; literalParserProcTable[i].commandName; i++) {
109 if (message->command() == literalParserProcTable[i].commandName) { 113 if (message->command() == literalParserProcTable[i].commandName) {
110 (this->*(literalParserProcTable[i].proc))(message); 114 (this->*(literalParserProcTable[i].proc))(message);
111 return; 115 return;
112 } 116 }
113 } 117 }
114 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received unhandled literal command: %1").arg( message->command()) )); 118 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received unhandled literal command: %1").arg( message->command()) ));
115 } 119 }
116} 120}
117 121
118void IRCMessageParser::parseNumerical(IRCMessage *message, int position) { 122void IRCMessageParser::parseNumerical(IRCMessage *message, int position) {
119 QString out = tr(numericalParserProcTable[position].message); 123 QString out = tr(numericalParserProcTable[position].message);
120 QString paramString = numericalParserProcTable[position].params; 124 QString paramString = numericalParserProcTable[position].params;
121 125
122 if(!out.isEmpty() && !paramString.isEmpty()) { 126 if(!out.isEmpty() && !paramString.isEmpty()) {
123 QStringList params = message->params(numericalParserProcTable[position].params); 127 QStringList params = message->params(numericalParserProcTable[position].params);
124 128
125 QStringList::Iterator end = params.end(); 129 QStringList::Iterator end = params.end();
126 for (QStringList::Iterator it = params.begin(); it != end; ++it) { 130 for (QStringList::Iterator it = params.begin(); it != end; ++it) {
127 out = out.arg(*it); 131 out = out.arg(*it);
128 } 132 }
129 133
130 emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, out)); 134 emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, out));
131 } 135 }
132 136
133 if(numericalParserProcTable[position].proc) 137 if(numericalParserProcTable[position].proc)
134 (this->*(numericalParserProcTable[position].proc))(message); 138 (this->*(numericalParserProcTable[position].proc))(message);
135} 139}
136 140
141void IRCMessageParser::parseCTCP(IRCMessage *message, int position) {
142 if(ctcpParserProcTable[position].proc)
143 (this->*(ctcpParserProcTable[position].proc))(message);
144}
145
146
147
137void IRCMessageParser::parseNumericalServerName(IRCMessage *message) { 148void IRCMessageParser::parseNumericalServerName(IRCMessage *message) {
138 emit outputReady(IRCOutput(OUTPUT_TITLE, tr("Connected to")+" <b>" + message->prefix() + "</b>")); 149 emit outputReady(IRCOutput(OUTPUT_TITLE, tr("Connected to")+" <b>" + message->prefix() + "</b>"));
139 /* Register EFFECTIVE nickname, some networks (as irc-hispano) uses nick:password 150 /* Register EFFECTIVE nickname, some networks (as irc-hispano) use nick:password
140 * for authentication and the parser gets confused */ 151 * for authentication and the parser gets confused */
141 m_session->m_server->setNick(message->param(0)); 152 m_session->m_server->setNick(message->param(0));
142 153
143} 154}
144 155
145void IRCMessageParser::parseNumericalServerFeatures(IRCMessage *message) { 156void IRCMessageParser::parseNumericalServerFeatures(IRCMessage *message) {
146 m_session->setValidUsermodes(message->param(2)); 157 m_session->setValidUsermodes(message->param(2));
147 m_session->setValidChannelmodes(message->param(3)); 158 m_session->setValidChannelmodes(message->param(3));
148 159
149} 160}
150 161
151void IRCMessageParser::parseNumericalServerProtocol(IRCMessage *message) { 162void IRCMessageParser::parseNumericalServerProtocol(IRCMessage *message) {
152 /* XXX: Add some usefull features here */ 163 /* XXX: Add some usefull features here */
153 QString out = message->allParameters(); 164 QString out = message->allParameters();
154 out = out.mid(out.find(' ')+1); 165 out = out.mid(out.find(' ')+1);
155 emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, out)); 166 emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, out));
156} 167}
157void IRCMessageParser::parseNumericalWhoisIdle(IRCMessage *message) { 168void IRCMessageParser::parseNumericalWhoisIdle(IRCMessage *message) {
158 QDateTime dt; 169 QDateTime dt;
159 QTime t; 170 QTime t;
160 t = t.addSecs(message->param(2).toInt()); 171 t = t.addSecs(message->param(2).toInt());
161 dt.setTime_t(message->param(3).toInt()); 172 dt.setTime_t(message->param(3).toInt());
162 173
163 emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, tr("%1 has been idle for %2").arg(message->param(1)).arg(t.toString()))); 174 emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, tr("%1 has been idle for %2").arg(message->param(1)).arg(t.toString())));
164 emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, tr("%1 signed on %2").arg(message->param(1)).arg(dt.toString()))); 175 emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, tr("%1 signed on %2").arg(message->param(1)).arg(dt.toString())));
165 176
166} 177}
167 178
168void IRCMessageParser::parseLiteralPing(IRCMessage *message) { 179void IRCMessageParser::parseLiteralPing(IRCMessage *message) {
169 m_session->m_connection->sendLine("PONG " + message->allParameters()); 180 m_session->m_connection->sendLine("PONG " + message->allParameters());
170} 181}
171 182
172void IRCMessageParser::parseLiteralNotice(IRCMessage *message) { 183void IRCMessageParser::parseLiteralNotice(IRCMessage *message) {
173 emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, message->allParameters())); 184 emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, message->allParameters()));
174} 185}
175 186
176void IRCMessageParser::parseLiteralJoin(IRCMessage *message) { 187void IRCMessageParser::parseLiteralJoin(IRCMessage *message) {
177 QString channelName = message->param(0).lower(); 188 QString channelName = message->param(0).lower();
178 IRCPerson mask(message->prefix()); 189 IRCPerson mask(message->prefix());
179 IRCChannel *channel = m_session->getChannel(channelName); 190 IRCChannel *channel = m_session->getChannel(channelName);
180 if (!channel) { 191 if (!channel) {
181 /* We joined */ 192 /* We joined */
182 if (mask.nick() == m_session->m_server->nick()) { 193 if (mask.nick() == m_session->m_server->nick()) {
183 channel = new IRCChannel(channelName); 194 channel = new IRCChannel(channelName);
184 m_session->addChannel(channel); 195 m_session->addChannel(channel);
185 } else { 196 } else {
186 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Nonexistant channel join - desynchronized?"))); 197 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Nonexistant channel join - desynchronized?")));
187 } 198 }
188 } else { 199 } else {
189 /* Someone else joined */ 200 /* Someone else joined */
190 if (mask.nick() != m_session->m_server->nick()) { 201 if (mask.nick() != m_session->m_server->nick()) {
191 if (!channel->getPerson(mask.nick())) { 202 if (!channel->getPerson(mask.nick())) {
192 IRCChannelPerson *chanperson = new IRCChannelPerson();
193 IRCPerson *person = m_session->getPerson(mask.nick()); 203 IRCPerson *person = m_session->getPerson(mask.nick());
194 if (!person) { 204 if (!person) {
195 person = new IRCPerson(message->prefix()); 205 person = new IRCPerson(message->prefix());
196 m_session->addPerson(person); 206 m_session->addPerson(person);
197 } 207 }
198 chanperson->flags = 0; 208 IRCChannelPerson *chanperson = new IRCChannelPerson(person);
199 chanperson->person = person;
200 channel->addPerson(chanperson); 209 channel->addPerson(chanperson);
201 IRCOutput output(OUTPUT_OTHERJOIN ,tr("%1 joined channel %2").arg( mask.nick() ).arg( channelName )); 210 IRCOutput output(OUTPUT_OTHERJOIN ,tr("%1 joined channel %2").arg( mask.nick() ).arg( channelName ));
202 output.addParam(channel); 211 output.addParam(channel);
203 output.addParam(chanperson); 212 output.addParam(chanperson);
204 emit outputReady(output); 213 emit outputReady(output);
205 } else { 214 } else {
206 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Person has already joined the channel - desynchronized?"))); 215 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Person has already joined the channel - desynchronized?")));
207 } 216 }
208 } else { 217 } else {
209 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("You already joined the channel - desynchronized?"))); 218 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("You already joined the channel - desynchronized?")));
210 } 219 }
211 } 220 }
212} 221}
213 222
214void IRCMessageParser::parseLiteralPart(IRCMessage *message) { 223void IRCMessageParser::parseLiteralPart(IRCMessage *message) {
215 QString channelName = message->param(0).lower(); 224 QString channelName = message->param(0).lower();
216 IRCChannel *channel = m_session->getChannel(channelName); 225 IRCChannel *channel = m_session->getChannel(channelName);
217 IRCPerson mask(message->prefix()); 226 IRCPerson mask(message->prefix());
218 if (channel) { 227 if (channel) {
219 if (mask.nick() == m_session->m_server->nick()) { 228 if (mask.nick() == m_session->m_server->nick()) {
220 m_session->removeChannel(channel); 229 m_session->removeChannel(channel);
221 IRCOutput output(OUTPUT_SELFPART, tr("You left channel %1").arg( channelName )); 230 IRCOutput output(OUTPUT_SELFPART, tr("You left channel %1").arg( channelName ));
222 output.addParam(channel); 231 output.addParam(channel);
223 emit outputReady(output); 232 emit outputReady(output);
224 delete channel; 233 delete channel;
225 } else { 234 } else {
226 IRCChannelPerson *person = channel->getPerson(mask.nick()); 235 IRCChannelPerson *person = channel->getPerson(mask.nick());
227 if (person) { 236 if (person) {
228 channel->removePerson(person); 237 channel->removePerson(person);
229 IRCOutput output(OUTPUT_OTHERPART, tr("%1 left channel %2").arg( mask.nick() ).arg( channelName) ); 238 IRCOutput output(OUTPUT_OTHERPART, tr("%1 left channel %2").arg( mask.nick() ).arg( channelName) );
230 output.addParam(channel); 239 output.addParam(channel);
231 output.addParam(person); 240 output.addParam(person);
232 emit outputReady(output); 241 emit outputReady(output);
233 delete person; 242 delete person;
234 } else { 243 } else {
235 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Parting person not found - desynchronized?"))); 244 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Parting person not found - desynchronized?")));
236 } 245 }
237 } 246 }
238 } else { 247 } else {
239 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Channel for part not found - desynchronized?"))); 248 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Channel for part not found - desynchronized?")));
240 } 249 }
241} 250}
242 251
243void IRCMessageParser::parseLiteralPrivMsg(IRCMessage *message) { 252void IRCMessageParser::parseLiteralPrivMsg(IRCMessage *message) {
244 if (m_session->m_server->nick().lower() == message->param(0).lower() ) { 253 if (m_session->m_server->nick().lower() == message->param(0).lower() ) {
245 /* IRC Query message detected, verify sender and display it */ 254 /* IRC Query message detected, verify sender and display it */
246 IRCPerson mask(message->prefix()); 255 IRCPerson mask(message->prefix());
247 IRCPerson *person = m_session->getPerson(mask.nick()); 256 IRCPerson *person = m_session->getPerson(mask.nick());
248 if (!person) { 257 if (!person) {
249 /* Person not yet known, create and add to the current session */ 258 /* Person not yet known, create and add to the current session */
250 person = new IRCPerson(message->prefix()); 259 person = new IRCPerson(message->prefix());
251 m_session->addPerson(person); 260 m_session->addPerson(person);
252 } 261 }
253 IRCOutput output(OUTPUT_QUERYPRIVMSG, message->param(1)); 262 IRCOutput output(OUTPUT_QUERYPRIVMSG, message->param(1));
254 output.addParam(person); 263 output.addParam(person);
255 emit outputReady(output); 264 emit outputReady(output);
256 } 265 }
257 else 266 else
258 if (message->param(0).at(0) == '#' || message->param(0).at(0) == '+') { 267 if (message->param(0).at(0) == '#' || message->param(0).at(0) == '+') {
259 /* IRC Channel message detected, verify sender, channel and display it */ 268 /* IRC Channel message detected, verify sender, channel and display it */
260 IRCChannel *channel = m_session->getChannel(message->param(0).lower()); 269 IRCChannel *channel = m_session->getChannel(message->param(0).lower());
261 if (channel) { 270 if (channel) {
262 IRCPerson mask(message->prefix()); 271 IRCPerson mask(message->prefix());
263 IRCChannelPerson *person = channel->getPerson(mask.nick()); 272 IRCChannelPerson *person = channel->getPerson(mask.nick());
264 if (person) { 273 if (person) {
265 IRCOutput output(OUTPUT_CHANPRIVMSG, message->param(1)); 274 IRCOutput output(OUTPUT_CHANPRIVMSG, message->param(1));
266 output.addParam(channel); 275 output.addParam(channel);
267 output.addParam(person); 276 output.addParam(person);
268 emit outputReady(output); 277 emit outputReady(output);
269 } 278 }
270 else { 279 else {
271 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Channel message with unknown sender"))); 280 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Channel message with unknown sender")));
272 } 281 }
273 } 282 }
274 else { 283 else {
275 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Channel message with unknown channel %1").arg(message->param(0).lower()) )); 284 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Channel message with unknown channel %1").arg(message->param(0).lower()) ));
276 } 285 }
277 } 286 }
278 else {emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received PRIVMSG of unknown type"))); 287 else {emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received PRIVMSG of unknown type")));
279 } 288 }
280} 289}
281 290
282void IRCMessageParser::parseLiteralNick(IRCMessage *message) { 291void IRCMessageParser::parseLiteralNick(IRCMessage *message) {
283 IRCPerson mask(message->prefix()); 292 IRCPerson mask(message->prefix());
284 m_session->updateNickname(mask.nick(), message->param(0)); 293 m_session->updateNickname(mask.nick(), message->param(0));
285 /* this way of handling nick changes really sucks 294 /* this way of handling nick changes really sucks
286 if (mask.nick() == m_session->m_server->nick()) { 295 if (mask.nick() == m_session->m_server->nick()) {
287 We are changing our nickname 296 We are changing our nickname
288 m_session->m_server->setNick(message->param(0)); 297 m_session->m_server->setNick(message->param(0));
289 IRCOutput output(OUTPUT_NICKCHANGE, tr("You are now known as %1").arg( message->param(0))); 298 IRCOutput output(OUTPUT_NICKCHANGE, tr("You are now known as %1").arg( message->param(0)));
290 output.addParam(0); 299 output.addParam(0);
291 emit outputReady(output); 300 emit outputReady(output);
292 } else { 301 } else {
293 Someone else is 302 Someone else is
294 RCPerson *person = m_session->getPerson(mask.nick()); 303 RCPerson *person = m_session->getPerson(mask.nick());
295 if (person) { 304 if (person) {
296 //IRCOutput output(OUTPUT_NICKCHANGE, tr("%1 is now known as %2").arg( mask.nick() ).arg( message->param(0))); 305 //IRCOutput output(OUTPUT_NICKCHANGE, tr("%1 is now known as %2").arg( mask.nick() ).arg( message->param(0)));
297 306
298 new code starts here -- this removes the person from all channels 307 new code starts here -- this removes the person from all channels
299 QList<IRCChannel> channels; 308 QList<IRCChannel> channels;
300 m_session->getChannelsByPerson(person, channels); 309 m_session->getChannelsByPerson(person, channels);
301 QListIterator<IRCChannel> it(channels); 310 QListIterator<IRCChannel> it(channels);
302 for (;it.current(); ++it) { 311 for (;it.current(); ++it) {
303 IRCChannelPerson *chanperson = it.current()->getPerson(mask.nick()); 312 IRCChannelPerson *chanperson = it.current()->getPerson(mask.nick());
304 it.current()->removePerson(chanperson); 313 it.current()->removePerson(chanperson);
305 chanperson->person->setNick(message->param(0)); 314 chanperson->person->setNick(message->param(0));
306 it.current()->addPerson(chanperson); 315 it.current()->addPerson(chanperson);
307 IRCOutput output(OUTPUT_NICKCHANGE, tr("%1 is now known as %2").arg( mask.nick() ).arg( message->param(0))); 316 IRCOutput output(OUTPUT_NICKCHANGE, tr("%1 is now known as %2").arg( mask.nick() ).arg( message->param(0)));
308 output.addParam(person); 317 output.addParam(person);
309 emit outputReady(output); 318 emit outputReady(output);
310 } 319 }
311 new code ends here 320 new code ends here
312 } else { 321 } else {
313 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Nickname change of an unknown person"))); 322 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Nickname change of an unknown person")));
314 } 323 }
315 }*/ 324 }*/
316} 325}
317 326
318void IRCMessageParser::parseLiteralQuit(IRCMessage *message) { 327void IRCMessageParser::parseLiteralQuit(IRCMessage *message) {
319 IRCPerson mask(message->prefix()); 328 IRCPerson mask(message->prefix());
320 IRCPerson *person = m_session->getPerson(mask.nick()); 329 IRCPerson *person = m_session->getPerson(mask.nick());
321 if (person) { 330 if (person) {
322 QList<IRCChannel> channels; 331 QList<IRCChannel> channels;
323 m_session->getChannelsByPerson(person, channels); 332 m_session->getChannelsByPerson(person, channels);
324 QListIterator<IRCChannel> it(channels); 333 QListIterator<IRCChannel> it(channels);
325 for (;it.current(); ++it) { 334 for (;it.current(); ++it) {
326 IRCChannelPerson *chanperson = it.current()->getPerson(mask.nick()); 335 IRCChannelPerson *chanperson = it.current()->getPerson(mask.nick());
327 it.current()->removePerson(chanperson); 336 it.current()->removePerson(chanperson);
328 delete chanperson; 337 delete chanperson;
329 } 338 }
330 m_session->removePerson(person); 339 m_session->removePerson(person);
331 IRCOutput output(OUTPUT_QUIT, tr("%1 has quit (%2)" ).arg( mask.nick() ).arg( message->param(0) )); 340 IRCOutput output(OUTPUT_QUIT, tr("%1 has quit (%2)" ).arg( mask.nick() ).arg( message->param(0) ));
332 output.addParam(person); 341 output.addParam(person);
333 emit outputReady(output); 342 emit outputReady(output);
334 delete person; 343 delete person;
335 } else { 344 } else {
336 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown person quit - desynchronized?"))); 345 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown person quit - desynchronized?")));
337 } 346 }
338} 347}
339 348
340void IRCMessageParser::parseLiteralTopic(IRCMessage *message) { 349void IRCMessageParser::parseLiteralTopic(IRCMessage *message) {
341 IRCPerson mask(message->prefix()); 350 IRCPerson mask(message->prefix());
342 IRCChannel *channel = m_session->getChannel(message->param(0).lower()); 351 IRCChannel *channel = m_session->getChannel(message->param(0).lower());
343 if (channel) { 352 if (channel) {
344 IRCOutput output(OUTPUT_TOPIC, mask.nick() + tr(" changed topic to ") + "\"" + message->param(1) + "\""); 353 IRCOutput output(OUTPUT_TOPIC, mask.nick() + tr(" changed topic to ") + "\"" + message->param(1) + "\"");
345 output.addParam(channel); 354 output.addParam(channel);
346 emit outputReady(output); 355 emit outputReady(output);
347 } else { 356 } else {
348 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown channel topic - desynchronized?"))); 357 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown channel topic - desynchronized?")));
349 } 358 }
350} 359}
351 360
352void IRCMessageParser::parseLiteralError(IRCMessage *message) { 361void IRCMessageParser::parseLiteralError(IRCMessage *message) {
353 emit outputReady(IRCOutput(OUTPUT_ERROR, message->allParameters())); 362 emit outputReady(IRCOutput(OUTPUT_ERROR, message->allParameters()));
354} 363}
355 364
356void IRCMessageParser::parseCTCPPing(IRCMessage *message) { 365void IRCMessageParser::parseCTCPPing(IRCMessage *message) {
357 IRCPerson mask(message->prefix()); 366 IRCPerson mask(message->prefix());
358 m_session->m_connection->sendCTCP(mask.nick(), "PING " + message->allParameters()); 367 m_session->m_connection->sendCTCPReply(mask.nick(), "PING", message->allParameters());
359 emit outputReady(IRCOutput(OUTPUT_CTCP, tr("Received a CTCP PING from ")+mask.nick())); 368 emit outputReady(IRCOutput(OUTPUT_CTCP, tr("Received a CTCP PING from ") + mask.nick()));
360 369
361 //IRCPerson mask(message->prefix()); 370 //IRCPerson mask(message->prefix());
362 QString dest = message->ctcpDestination(); 371 QString dest = message->ctcpDestination();
363 if (dest.startsWith("#")) { 372 if (dest.startsWith("#")) {
364 IRCChannel *channel = m_session->getChannel(dest.lower()); 373 IRCChannel *channel = m_session->getChannel(dest.lower());
365 if (channel) { 374 if (channel) {
366 IRCChannelPerson *person = channel->getPerson(mask.nick()); 375 IRCChannelPerson *person = channel->getPerson(mask.nick());
367 if (person) { 376 if (person) {
368 IRCOutput output(OUTPUT_CHANACTION, tr("Received a CTCP PING from ")+ mask.nick()) ; 377 IRCOutput output(OUTPUT_CHANACTION, tr("Received a CTCP PING from ")+ mask.nick()) ;
369 output.addParam(channel); 378 output.addParam(channel);
370 output.addParam(person); 379 output.addParam(person);
371 emit outputReady(output); 380 emit outputReady(output);
372 } else { 381 } else {
373 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP PING with unknown person - Desynchronized?"))); 382 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP PING with unknown person - Desynchronized?")));
374 } 383 }
375 } else { 384 } else {
376 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP PING with unknown channel - Desynchronized?"))); 385 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP PING with unknown channel - Desynchronized?")));
377 } 386 }
378 } else { 387 } else {
379 if (message->ctcpDestination() == m_session->m_server->nick()) { 388 if (message->ctcpDestination() == m_session->m_server->nick()) {
380 IRCPerson *person = m_session->getPerson(mask.nick()); 389 IRCPerson *person = m_session->getPerson(mask.nick());
381 if (!person) { 390 if (!person) {
382 /* Person not yet known, create and add to the current session */ 391 /* Person not yet known, create and add to the current session */
383 person = new IRCPerson(message->prefix()); 392 person = new IRCPerson(message->prefix());
384 m_session->addPerson(person); 393 m_session->addPerson(person);
385 } 394 }
386 IRCOutput output(OUTPUT_QUERYACTION, tr("Received a CTCP PING from ")+ mask.nick() ); 395 IRCOutput output(OUTPUT_QUERYACTION, tr("Received a CTCP PING from ")+ mask.nick() );
387 output.addParam(person); 396 output.addParam(person);
388 emit outputReady(output); 397 emit outputReady(output);
389 } else { 398 } else {
390 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP PING with bad recipient"))); 399 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP PING with bad recipient")));
391 } 400 }
392 } 401 }
393 402
394} 403}
395 404
396void IRCMessageParser::parseCTCPVersion(IRCMessage *message) { 405void IRCMessageParser::parseCTCPVersion(IRCMessage *message) {
397 IRCPerson mask(message->prefix()); 406 IRCPerson mask(message->prefix());
398 m_session->m_connection->sendCTCP(mask.nick(), "VERSION " APP_VERSION " " APP_COPYSTR); 407 IRCOutput output(OUTPUT_CTCP);
399 emit outputReady(IRCOutput(OUTPUT_CTCP, tr("Received a CTCP VERSION from ")+mask.nick())); 408 if(message->isCTCPRequest()) {
409 m_session->m_connection->sendCTCPReply(mask.nick(), "VERSION", APP_VERSION " " APP_COPYSTR);
410 output.setMessage(tr("Received a CTCP VERSION request from ") + mask.nick());
411 }
412
413 else {
414 output.setMessage("Received CTCP VERSION reply from " + mask.nick() + ":" + message->param(0));
415 }
416 emit outputReady(output);
400} 417}
401 418
402void IRCMessageParser::parseCTCPAction(IRCMessage *message) { 419void IRCMessageParser::parseCTCPAction(IRCMessage *message) {
403 IRCPerson mask(message->prefix()); 420 IRCPerson mask(message->prefix());
404 QString dest = message->ctcpDestination(); 421 QString dest = message->ctcpDestination();
405 if (dest.startsWith("#")) { 422 if (dest.startsWith("#")) {
406 IRCChannel *channel = m_session->getChannel(dest.lower()); 423 IRCChannel *channel = m_session->getChannel(dest.lower());
407 if (channel) { 424 if (channel) {
408 IRCChannelPerson *person = channel->getPerson(mask.nick()); 425 IRCChannelPerson *person = channel->getPerson(mask.nick());
409 if (person) { 426 if (person) {
410 IRCOutput output(OUTPUT_CHANACTION, "*" + mask.nick() + message->param(0)); 427 IRCOutput output(OUTPUT_CHANACTION, "*" + mask.nick() + message->param(0));
411 output.addParam(channel); 428 output.addParam(channel);
412 output.addParam(person); 429 output.addParam(person);
413 emit outputReady(output); 430 emit outputReady(output);
414 } else { 431 } else {
415 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP ACTION with unknown person - Desynchronized?"))); 432 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP ACTION with unknown person - Desynchronized?")));
416 } 433 }
417 } else { 434 } else {
418 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP ACTION with unknown channel - Desynchronized?"))); 435 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP ACTION with unknown channel - Desynchronized?")));
419 } 436 }
420 } else { 437 } else {
421 if (message->ctcpDestination() == m_session->m_server->nick()) { 438 if (message->ctcpDestination() == m_session->m_server->nick()) {
422 IRCPerson *person = m_session->getPerson(mask.nick()); 439 IRCPerson *person = m_session->getPerson(mask.nick());
423 if (!person) { 440 if (!person) {
424 /* Person not yet known, create and add to the current session */ 441 /* Person not yet known, create and add to the current session */
425 person = new IRCPerson(message->prefix()); 442 person = new IRCPerson(message->prefix());
426 m_session->addPerson(person); 443 m_session->addPerson(person);
427 } 444 }
428 IRCOutput output(OUTPUT_QUERYACTION, "*" + mask.nick() + message->param(0)); 445 IRCOutput output(OUTPUT_QUERYACTION, "*" + mask.nick() + message->param(0));
429 output.addParam(person); 446 output.addParam(person);
430 emit outputReady(output); 447 emit outputReady(output);
431 } else { 448 } else {
432 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP ACTION with bad recipient"))); 449 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP ACTION with bad recipient")));
433 } 450 }
434 } 451 }
435} 452}
436 453
454void IRCMessageParser::parseCTCPDCC(IRCMessage *message) {
455 QStringList params = QStringList::split(' ', message->param(0).stripWhiteSpace());
456 if( params.count() != 5) {
457 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Malformed DCC request from ") + IRCPerson(message->prefix()).nick()));
458 return;
459 }
460
461 //TransferReceiver *foo = new TransferReceiver(params[2].toUInt(), params[3].toUInt(), params[1], params[4].toUInt());
462}
463
437void IRCMessageParser::parseLiteralMode(IRCMessage *message) { 464void IRCMessageParser::parseLiteralMode(IRCMessage *message) {
438 IRCPerson mask(message->prefix()); 465 IRCPerson mask(message->prefix());
439 466
440 if (message->param(0).startsWith("#")) { 467 if (message->param(0).startsWith("#")) {
441 IRCChannel *channel = m_session->getChannel(message->param(0).lower()); 468 IRCChannel *channel = m_session->getChannel(message->param(0).lower());
442 if (channel) { 469 if (channel) {
443 QString temp, parameters = message->allParameters().right(message->allParameters().length() - channel->channelname().length() - 1); 470 QString temp, parameters = message->allParameters().right(message->allParameters().length() - channel->channelname().length() - 1);
444 QTextIStream stream(&parameters); 471 QTextIStream stream(&parameters);
445 bool set = FALSE; 472 bool set = FALSE;
446 while (!stream.atEnd()) { 473 while (!stream.atEnd()) {
447 stream >> temp; 474 stream >> temp;
448 if (temp.startsWith("+")) { 475 if (temp.startsWith("+")) {
449 set = TRUE; 476 set = TRUE;
450 temp = temp.right(1); 477 temp = temp.right(1);
451 } else if (temp.startsWith("-")) { 478 }
452 set = FALSE; 479 else
453 temp = temp.right(1); 480 if (temp.startsWith("-")) {
454 } else { 481 set = FALSE;
455 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change has unknown type"))); 482 temp = temp.right(1);
456 return; 483 }
457 } 484 else {
485 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change has unknown type")));
486 return;
487 }
458 if (temp == "o") { 488 if (temp == "o") {
459 stream >> temp; 489 stream >> temp;
460 IRCChannelPerson *person = channel->getPerson(temp); 490 IRCChannelPerson *person = channel->getPerson(temp);
461 if (person) { 491 if (person) {
462 if (set) { 492 IRCOutput output(OUTPUT_CHANPERSONMODE, person->setOp(mask.nick(), set));
463 person->flags |= PERSON_FLAG_OP; 493 output.addParam(channel);
464 IRCOutput output(OUTPUT_CHANPERSONMODE, mask.nick() + tr(" gives channel operator status to " + person->person->nick())); 494 output.addParam(person);
465 output.addParam(channel); 495 emit outputReady(output);
466 output.addParam(person); 496 }
467 emit outputReady(output); 497 else {
468 } else {
469 person->flags &= 0xFFFF - PERSON_FLAG_OP;
470 IRCOutput output(OUTPUT_CHANPERSONMODE, mask.nick() + tr(" removes channel operator status from " + person->person->nick()));
471 output.addParam(channel);
472 output.addParam(person);
473 emit outputReady(output);
474 }
475 } else {
476 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown person - Desynchronized?"))); 498 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown person - Desynchronized?")));
477 } 499 }
478 } else if (temp == "v") { 500 }
479 stream >> temp; 501 else
480 IRCChannelPerson *person = channel->getPerson(temp); 502 if (temp == "v") {
481 if (person) { 503 stream >> temp;
482 if (set) { 504 IRCChannelPerson *person = channel->getPerson(temp);
483 person->flags |= PERSON_FLAG_VOICE; 505 if (person) {
484 IRCOutput output(OUTPUT_CHANPERSONMODE, mask.nick() + tr(" gives voice to " + person->person->nick())); 506 IRCOutput output(OUTPUT_CHANPERSONMODE, person->setVoice(mask.nick(), set));
485 output.addParam(channel);
486 output.addParam(person);
487 emit outputReady(output);
488 } else {
489 person->flags &= 0xFFFF - PERSON_FLAG_VOICE;
490 IRCOutput output(OUTPUT_CHANPERSONMODE, mask.nick() + tr(" removes voice from " + person->person->nick()));
491 output.addParam(channel); 507 output.addParam(channel);
492 output.addParam(person); 508 output.addParam(person);
493 emit outputReady(output); 509 emit outputReady(output);
494 } 510 }
495 } else { 511 else {
496 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown person - Desynchronized?"))); 512 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown person - Desynchronized?")));
513 }
514 }
515 else {
516 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown flag")));
497 } 517 }
498 } else {
499 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown flag")));
500 } 518 }
501 }
502 } else { 519 } else {
503 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown kannel - Desynchronized?"))); 520 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown kannel - Desynchronized?")));
504 } 521 }
505 } else { 522 } else {
506 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("User modes not supported yet"))); 523 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("User modes not supported yet")));
507 } 524 }
508} 525}
509 526
510void IRCMessageParser::parseLiteralKick(IRCMessage *message) { 527void IRCMessageParser::parseLiteralKick(IRCMessage *message) {
511 IRCPerson mask(message->prefix()); 528 IRCPerson mask(message->prefix());
512 IRCChannel *channel = m_session->getChannel(message->param(0).lower()); 529 IRCChannel *channel = m_session->getChannel(message->param(0).lower());
513 if (channel) { 530 if (channel) {
514 IRCChannelPerson *person = channel->getPerson(message->param(1)); 531 IRCChannelPerson *person = channel->getPerson(message->param(1));
515 if (person) { 532 if (person) {
516 if (person->person->nick() == m_session->m_server->nick()) { 533 if (person->nick() == m_session->m_server->nick()) {
517 m_session->removeChannel(channel); 534 m_session->removeChannel(channel);
518 IRCOutput output(OUTPUT_SELFKICK, tr("You were kicked from ") + channel->channelname() + tr(" by ") + mask.nick() + " (" + message->param(2) + ")"); 535 IRCOutput output(OUTPUT_SELFKICK, tr("You were kicked from ") + channel->channelname() + tr(" by ") + mask.nick() + " (" + message->param(2) + ")");
519 output.addParam(channel); 536 output.addParam(channel);
520 emit outputReady(output); 537 emit outputReady(output);
521 } else { 538 } else {
522 /* someone else got kicked */ 539 /* someone else got kicked */
523 channel->removePerson(person); 540 channel->removePerson(person);
524 IRCOutput output(OUTPUT_OTHERKICK, person->person->nick() + tr(" was kicked from ") + channel->channelname() + tr(" by ") + mask.nick()+ " (" + message->param(2) + ")"); 541 IRCOutput output(OUTPUT_OTHERKICK, person->nick() + tr(" was kicked from ") + channel->channelname() + tr(" by ") + mask.nick()+ " (" + message->param(2) + ")");
525 output.addParam(channel); 542 output.addParam(channel);
526 output.addParam(person); 543 output.addParam(person);
527 emit outputReady(output); 544 emit outputReady(output);
528 } 545 }
529 } else { 546 } else {
530 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown person kick - desynchronized?"))); 547 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown person kick - desynchronized?")));
531 } 548 }
532 } else { 549 } else {
533 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown channel kick - desynchronized?"))); 550 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown channel kick - desynchronized?")));
534 } 551 }
535} 552}
536 553
537void IRCMessageParser::parseNumericalNames(IRCMessage *message) { 554void IRCMessageParser::parseNumericalNames(IRCMessage *message) {
538 /* Name list sent when joining a channel */ 555 /* Name list sent when joining a channel */
539 IRCChannel *channel = m_session->getChannel(message->param(2).lower()); 556 IRCChannel *channel = m_session->getChannel(message->param(2).lower());
540 if (channel != 0) { 557 if (channel != 0) {
541 QString people = message->param(3); 558 QString people = message->param(3);
542 QTextIStream stream(&people); 559 QTextIStream stream(&people);
543 QString temp; 560 QString temp;
544 561
545 while (!stream.atEnd()) { 562 while (!stream.atEnd()) {
546 stream >> temp; 563 stream >> temp;
547 564
548 char flagch = temp.at(0).latin1(); 565 char flagch = temp.at(0).latin1();
549 int flag = 0; 566 int flag = 0;
550 QString nick; 567 QString nick;
551 /* Parse person flags */ 568 /* Parse person flags */
552 if (flagch == '@' || flagch == '+' || flagch=='%' || flagch == '*') { 569 if (flagch == '@' || flagch == '+' || flagch=='%' || flagch == '*') {
553 570
554 nick = temp.right(temp.length()-1); 571 nick = temp.right(temp.length()-1);
555 switch (flagch) { 572 switch (flagch) {
556 case '@': flag = PERSON_FLAG_OP; break; 573 case '@': flag = IRCChannelPerson::PERSON_FLAG_OP; break;
557 case '+': flag = PERSON_FLAG_VOICE; break; 574 case '+': flag = IRCChannelPerson::PERSON_FLAG_VOICE; break;
558 case '%': flag = PERSON_FLAG_HALFOP; break; 575 case '%': flag = IRCChannelPerson::PERSON_FLAG_HALFOP; break;
559 default : flag = 0; break; 576 default : flag = 0; break;
560 } 577 }
561 } else { 578 } else {
562 nick = temp; 579 nick = temp;
563 } 580 }
564 581
565 IRCChannelPerson *chan_person = new IRCChannelPerson();
566 IRCPerson *person = m_session->getPerson(nick); 582 IRCPerson *person = m_session->getPerson(nick);
567 if (person == 0) { 583 if (person == 0) {
568 person = new IRCPerson(); 584 person = new IRCPerson();
569 person->setNick(nick); 585 person->setNick(nick);
570 m_session->addPerson(person); 586 m_session->addPerson(person);
571 } 587 }
572 chan_person->person = person; 588 IRCChannelPerson *chan_person = new IRCChannelPerson(person);
573 chan_person->flags = flag; 589 chan_person->setFlags(flag);
574 channel->addPerson(chan_person); 590 channel->addPerson(chan_person);
575 } 591 }
576 } else { 592 } else {
577 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Server message with unknown channel"))); 593 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Server message with unknown channel")));
578 } 594 }
579} 595}
580 596
581void IRCMessageParser::parseNumericalEndOfNames(IRCMessage *message) { 597void IRCMessageParser::parseNumericalEndOfNames(IRCMessage *message) {
582 /* Done syncing to channel */ 598 /* Done syncing to channel */
583 IRCChannel *channel = m_session->getChannel(message->param(1).lower()); 599 IRCChannel *channel = m_session->getChannel(message->param(1).lower());
584 if (channel) { 600 if (channel) {
585 channel->setHasPeople(TRUE); 601 channel->setHasPeople(TRUE);
586 /* Yes, we want the names before anything happens inside the GUI */ 602 /* Yes, we want the names before anything happens inside the GUI */
587 IRCOutput output(OUTPUT_SELFJOIN, tr("You joined channel ") + channel->channelname()); 603 IRCOutput output(OUTPUT_SELFJOIN, tr("You joined channel ") + channel->channelname());
588 output.addParam(channel); 604 output.addParam(channel);
589 emit outputReady(output); 605 emit outputReady(output);
590 } else { 606 } else {
591 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Server message with unknown channel"))); 607 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Server message with unknown channel")));
592 } 608 }
593} 609}
594 610
595 611
596void IRCMessageParser::parseNumericalNicknameInUse(IRCMessage *) { 612void IRCMessageParser::parseNumericalNicknameInUse(IRCMessage *) {
597 /* If we are connnected this error is not critical */ 613 /* If we are connnected this error is not critical */
598 if(m_session->isLoggedIn()) 614 if(m_session->isLoggedIn())
599 return; 615 return;
600 616
601 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Nickname is in use, please reconnect with a different nickname"))); 617 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Nickname is in use, please reconnect with a different nickname")));
602 m_session->endSession(); 618 m_session->endSession();
603} 619}
604 620
605void IRCMessageParser::parseNumericalNoSuchNick(IRCMessage *) { 621void IRCMessageParser::parseNumericalNoSuchNick(IRCMessage *) {
606 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("No such nickname"))); 622 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("No such nickname")));
607} 623}
608 624
609void IRCMessageParser::parseNumericalTopic(IRCMessage *message) { 625void IRCMessageParser::parseNumericalTopic(IRCMessage *message) {
610 IRCChannel *channel = m_session->getChannel(message->param(1).lower()); 626 IRCChannel *channel = m_session->getChannel(message->param(1).lower());
611 if (channel) { 627 if (channel) {
612 IRCOutput output(OUTPUT_TOPIC, tr("Topic for channel " + channel->channelname() + " is \"" + message->param(2) + "\"")); 628 IRCOutput output(OUTPUT_TOPIC, tr("Topic for channel " + channel->channelname() + " is \"" + message->param(2) + "\""));
613 output.addParam(channel); 629 output.addParam(channel);
614 emit outputReady(output); 630 emit outputReady(output);
615 } else { 631 } else {
616 IRCOutput output(OUTPUT_TOPIC, tr("Topic for channel " + message->param(1) + " is \"" + message->param(2) + "\"")); 632 IRCOutput output(OUTPUT_TOPIC, tr("Topic for channel " + message->param(1) + " is \"" + message->param(2) + "\""));
617 output.addParam(0); 633 output.addParam(0);
618 emit outputReady(output); 634 emit outputReady(output);
619 } 635 }
620} 636}
621 637
622void IRCMessageParser::parseNumericalTopicWhoTime(IRCMessage *) { 638void IRCMessageParser::parseNumericalTopicWhoTime(IRCMessage *) {
623} 639}
624 640
625 641
diff --git a/noncore/net/opieirc/ircmessageparser.h b/noncore/net/opieirc/ircmessageparser.h
index 2fca61e..4ebbddd 100644
--- a/noncore/net/opieirc/ircmessageparser.h
+++ b/noncore/net/opieirc/ircmessageparser.h
@@ -1,99 +1,101 @@
1/* 1/*
2 OpieIRC - An embedded IRC client 2 OpieIRC - An embedded IRC client
3 Copyright (C) 2002 Wenzel Jakob 3 Copyright (C) 2002 Wenzel Jakob
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18
19*/ 19*/
20 20
21#ifndef __IRCMESSAGEPARSER_H 21#ifndef __IRCMESSAGEPARSER_H
22#define __IRCMESSAGEPARSER_H 22#define __IRCMESSAGEPARSER_H
23 23
24#include "ircsession.h" 24#include "ircsession.h"
25 25
26/* Macro to facilitate the parser table's creation */ 26/* Macro to facilitate the parser table's creation */
27#define FUNC(__proc) &IRCMessageParser::__proc 27#define FUNC(__proc) &IRCMessageParser::__proc
28 28
29class IRCMessageParser; 29class IRCMessageParser;
30 30
31/* Typedef representing a parser function */ 31/* Typedef representing a parser function */
32typedef void (IRCMessageParser::*IRCMessageParseProc)(IRCMessage *); 32typedef void (IRCMessageParser::*IRCMessageParseProc)(IRCMessage *);
33 33
34/* Struct representing a literal command handler */ 34/* Struct representing a literal command handler */
35typedef struct IRCLiteralMessageParserStruct { 35typedef struct IRCLiteralMessageParserStruct {
36 char *commandName; 36 char *commandName;
37 IRCMessageParseProc proc; 37 IRCMessageParseProc proc;
38}; 38};
39 39
40/* Struct representing a ctcp command handler */ 40/* Struct representing a ctcp command handler */
41typedef struct IRCCTCPMessageParserStruct { 41typedef struct IRCCTCPMessageParserStruct {
42 char *commandName; 42 char *commandName;
43 IRCMessageParseProc proc; 43 IRCMessageParseProc proc;
44}; 44};
45 45
46/* Struct representing a numerical command handler */ 46/* Struct representing a numerical command handler */
47typedef struct IRCNumericalMessageParserStruct { 47typedef struct IRCNumericalMessageParserStruct {
48 unsigned short commandNumber; 48 unsigned short commandNumber;
49 char *message; 49 char *message;
50 char *params; 50 char *params;
51 IRCMessageParseProc proc; 51 IRCMessageParseProc proc;
52}; 52};
53 53
54class IRCMessageParser : public QObject { 54class IRCMessageParser : public QObject {
55 Q_OBJECT 55 Q_OBJECT
56public: 56public:
57 /* Create an IRCMessageParser object */ 57 /* Create an IRCMessageParser object */
58 IRCMessageParser(IRCSession *session); 58 IRCMessageParser(IRCSession *session);
59 /* Parse a server message and take the appropriate actions */ 59 /* Parse a server message and take the appropriate actions */
60 void parse(IRCMessage *message); 60 void parse(IRCMessage *message);
61signals: 61signals:
62 /* Used to send commands to the UI (such as displaying text etc) */ 62 /* Used to send commands to the UI (such as displaying text etc) */
63 void outputReady(IRCOutput output); 63 void outputReady(IRCOutput output);
64private: 64private:
65 /* Parser functions */ 65 /* Parser functions */
66 void parseLiteralPing(IRCMessage *message); 66 void parseLiteralPing(IRCMessage *message);
67 void parseLiteralNotice(IRCMessage *message); 67 void parseLiteralNotice(IRCMessage *message);
68 void parseLiteralJoin(IRCMessage *message); 68 void parseLiteralJoin(IRCMessage *message);
69 void parseLiteralPrivMsg(IRCMessage *message); 69 void parseLiteralPrivMsg(IRCMessage *message);
70 void parseLiteralNick(IRCMessage *message); 70 void parseLiteralNick(IRCMessage *message);
71 void parseLiteralPart(IRCMessage *message); 71 void parseLiteralPart(IRCMessage *message);
72 void parseLiteralQuit(IRCMessage *message); 72 void parseLiteralQuit(IRCMessage *message);
73 void parseLiteralError(IRCMessage *message); 73 void parseLiteralError(IRCMessage *message);
74 void parseLiteralMode(IRCMessage *message); 74 void parseLiteralMode(IRCMessage *message);
75 void parseLiteralKick(IRCMessage *message); 75 void parseLiteralKick(IRCMessage *message);
76 void parseLiteralTopic(IRCMessage *message); 76 void parseLiteralTopic(IRCMessage *message);
77 void parseNumerical(IRCMessage *message, int position); 77 void parseNumerical(IRCMessage *message, int position);
78 void parseCTCP(IRCMessage *message, int position);
78 void parseNumericalServerName(IRCMessage *message); 79 void parseNumericalServerName(IRCMessage *message);
79 void parseNumericalServerFeatures(IRCMessage *message); 80 void parseNumericalServerFeatures(IRCMessage *message);
80 void parseNumericalServerProtocol(IRCMessage *message); 81 void parseNumericalServerProtocol(IRCMessage *message);
81 void parseNumericalWhoisIdle(IRCMessage *message); 82 void parseNumericalWhoisIdle(IRCMessage *message);
82 void parseNumericalNames(IRCMessage *message); 83 void parseNumericalNames(IRCMessage *message);
83 void parseNumericalEndOfNames(IRCMessage *message); 84 void parseNumericalEndOfNames(IRCMessage *message);
84 void parseNumericalNicknameInUse(IRCMessage *message); 85 void parseNumericalNicknameInUse(IRCMessage *message);
85 void parseNumericalNoSuchNick(IRCMessage *message); 86 void parseNumericalNoSuchNick(IRCMessage *message);
86 void parseNumericalTopic(IRCMessage *message); 87 void parseNumericalTopic(IRCMessage *message);
87 void parseNumericalTopicWhoTime(IRCMessage *message); 88 void parseNumericalTopicWhoTime(IRCMessage *message);
88 void parseCTCPPing(IRCMessage *message); 89 void parseCTCPPing(IRCMessage *message);
89 void parseCTCPVersion(IRCMessage *message); 90 void parseCTCPVersion(IRCMessage *message);
90 void parseCTCPAction(IRCMessage *message); 91 void parseCTCPAction(IRCMessage *message);
92 void parseCTCPDCC(IRCMessage *message);
91protected: 93protected:
92 IRCSession *m_session; 94 IRCSession *m_session;
93 /* Parser tables */ 95 /* Parser tables */
94 static IRCLiteralMessageParserStruct literalParserProcTable[]; 96 static IRCLiteralMessageParserStruct literalParserProcTable[];
95 static IRCNumericalMessageParserStruct numericalParserProcTable[]; 97 static IRCNumericalMessageParserStruct numericalParserProcTable[];
96 static IRCCTCPMessageParserStruct ctcpParserProcTable[]; 98 static IRCCTCPMessageParserStruct ctcpParserProcTable[];
97}; 99};
98 100
99#endif /* __IRCMESSAGEPARSER_H */ 101#endif /* __IRCMESSAGEPARSER_H */
diff --git a/noncore/net/opieirc/ircservertab.cpp b/noncore/net/opieirc/ircservertab.cpp
index 90353f2..bddc37e 100644
--- a/noncore/net/opieirc/ircservertab.cpp
+++ b/noncore/net/opieirc/ircservertab.cpp
@@ -1,414 +1,415 @@
1#include <qtextstream.h> 1#include <qtextstream.h>
2#include <qwhatsthis.h> 2#include <qwhatsthis.h>
3 3
4#include "ircservertab.h" 4#include "ircservertab.h"
5#include "ircmessageparser.h" 5#include "ircmessageparser.h"
6#include "ircchannelperson.h"
6 7
7 8
8bool IRCServerTab::containsPing( const QString& text, IRCServerTab* tab ) { 9bool IRCServerTab::containsPing( const QString& text, IRCServerTab* tab ) {
9 return (text.contains(IRCMessageParser::tr("Received a CTCP PING from "))) || 10 return (text.contains(IRCMessageParser::tr("Received a CTCP PING from "))) ||
10 (text.find("ping") != -1 && text.find( tab->server()->nick() != -1)); 11 (text.find("ping") != -1 && text.find( tab->server()->nick() != -1));
11} 12}
12 13
13 14
14IRCServerTab::IRCServerTab(IRCServer server, MainWindow *mainWindow, QWidget *parent, const char *name, WFlags f) : IRCTab(parent, name, f) { 15IRCServerTab::IRCServerTab(IRCServer server, MainWindow *mainWindow, QWidget *parent, const char *name, WFlags f) : IRCTab(parent, name, f) {
15 m_server = server; 16 m_server = server;
16 m_session = new IRCSession(&m_server); 17 m_session = new IRCSession(&m_server);
17 m_mainWindow = mainWindow; 18 m_mainWindow = mainWindow;
18 m_close = FALSE; 19 m_close = FALSE;
19 m_lines = 0; 20 m_lines = 0;
20 m_description->setText(tr("Connecting to")+" <b>" + server.hostname() + ":" + QString::number(server.port()) + "</b>"); 21 m_description->setText(tr("Connecting to")+" <b>" + server.hostname() + ":" + QString::number(server.port()) + "</b>");
21 m_textview = new QTextView(this); 22 m_textview = new QTextView(this);
22 m_textview->setHScrollBarMode(QScrollView::AlwaysOff); 23 m_textview->setHScrollBarMode(QScrollView::AlwaysOff);
23 m_textview->setVScrollBarMode(QScrollView::AlwaysOn); 24 m_textview->setVScrollBarMode(QScrollView::AlwaysOn);
24 m_textview->setTextFormat(RichText); 25 m_textview->setTextFormat(RichText);
25 QWhatsThis::add(m_textview, tr("Server messages")); 26 QWhatsThis::add(m_textview, tr("Server messages"));
26 m_layout->add(m_textview); 27 m_layout->add(m_textview);
27 m_field = new IRCHistoryLineEdit(this); 28 m_field = new IRCHistoryLineEdit(this);
28 connect(m_field, SIGNAL(nextTab()), this, SIGNAL(nextTab())); 29 connect(m_field, SIGNAL(nextTab()), this, SIGNAL(nextTab()));
29 connect(m_field, SIGNAL(prevTab()), this, SIGNAL(prevTab())); 30 connect(m_field, SIGNAL(prevTab()), this, SIGNAL(prevTab()));
30 connect(m_field, SIGNAL(closeTab()), this, SIGNAL(closeTab())); 31 connect(m_field, SIGNAL(closeTab()), this, SIGNAL(closeTab()));
31 connect(this, SIGNAL(editFocus()), m_field, SLOT(setEditFocus())); 32 connect(this, SIGNAL(editFocus()), m_field, SLOT(setEditFocus()));
32 33
33 QWhatsThis::add(m_field, tr("Type commands here. A list of available commands can be found inside the OpieIRC help")); 34 QWhatsThis::add(m_field, tr("Type commands here. A list of available commands can be found inside the OpieIRC help"));
34 m_layout->add(m_field); 35 m_layout->add(m_field);
35 connect(m_field, SIGNAL(returnPressed()), this, SLOT(processCommand())); 36 connect(m_field, SIGNAL(returnPressed()), this, SLOT(processCommand()));
36 connect(m_session, SIGNAL(outputReady(IRCOutput)), this, SLOT(display(IRCOutput))); 37 connect(m_session, SIGNAL(outputReady(IRCOutput)), this, SLOT(display(IRCOutput)));
37 connect(m_mainWindow, SIGNAL(updateScroll()), this, SLOT(scrolling())); 38 connect(m_mainWindow, SIGNAL(updateScroll()), this, SLOT(scrolling()));
38 connect(m_session, SIGNAL(updateChannels()), this, SLOT(slotUpdateChannels())); 39 connect(m_session, SIGNAL(updateChannels()), this, SLOT(slotUpdateChannels()));
39 settingsChanged(); 40 settingsChanged();
40 41
41 m_field->setFocus(); 42 m_field->setFocus();
42 m_field->setActiveWindow(); 43 m_field->setActiveWindow();
43 44
44} 45}
45 46
46void IRCServerTab::scrolling(){ 47void IRCServerTab::scrolling(){
47 m_textview->ensureVisible(0, m_textview->contentsHeight()); 48 m_textview->ensureVisible(0, m_textview->contentsHeight());
48} 49}
49 50
50 51
51void IRCServerTab::appendText(QString text) { 52void IRCServerTab::appendText(QString text) {
52 /* not using append because it creates layout problems */ 53 /* not using append because it creates layout problems */
53 QString txt = m_textview->text() + IRCTab::appendTimestamp( text ); 54 QString txt = m_textview->text() + IRCTab::appendTimestamp( text );
54 55
55 56
56 57
57 if (m_maxLines > 0 && m_lines >= m_maxLines) { 58 if (m_maxLines > 0 && m_lines >= m_maxLines) {
58 int firstBreak = txt.find('\n'); 59 int firstBreak = txt.find('\n');
59 if (firstBreak != -1) { 60 if (firstBreak != -1) {
60 txt = "<qt bgcolor=\"" + m_backgroundColor + "\"/>" + txt.right(txt.length() - (firstBreak + 1)); 61 txt = "<qt bgcolor=\"" + m_backgroundColor + "\"/>" + txt.right(txt.length() - (firstBreak + 1));
61 } 62 }
62 } else { 63 } else {
63 m_lines++; 64 m_lines++;
64 } 65 }
65 m_textview->setText(txt); 66 m_textview->setText(txt);
66 m_textview->ensureVisible(0, m_textview->contentsHeight()); 67 m_textview->ensureVisible(0, m_textview->contentsHeight());
67 emit changed(this); 68 emit changed(this);
68} 69}
69 70
70IRCServerTab::~IRCServerTab() { 71IRCServerTab::~IRCServerTab() {
71 delete m_session; 72 delete m_session;
72} 73}
73 74
74void IRCServerTab::removeChannelTab(IRCChannelTab *tab) { 75void IRCServerTab::removeChannelTab(IRCChannelTab *tab) {
75 m_channelTabs.remove(tab); 76 m_channelTabs.remove(tab);
76} 77}
77 78
78void IRCServerTab::removeQueryTab(IRCQueryTab *tab) { 79void IRCServerTab::removeQueryTab(IRCQueryTab *tab) {
79 m_queryTabs.remove(tab); 80 m_queryTabs.remove(tab);
80} 81}
81 82
82void IRCServerTab::addQueryTab(IRCQueryTab *tab) { 83void IRCServerTab::addQueryTab(IRCQueryTab *tab) {
83 m_queryTabs.append(tab); 84 m_queryTabs.append(tab);
84} 85}
85 86
86QString IRCServerTab::title() { 87QString IRCServerTab::title() {
87 return "Server"; 88 return "Server";
88} 89}
89 90
90IRCSession *IRCServerTab::session() { 91IRCSession *IRCServerTab::session() {
91 return m_session; 92 return m_session;
92} 93}
93/* 94/*
94QString *IRCServerTab::mynick() { 95QString *IRCServerTab::mynick() {
95 return (*m_server->nick()); 96 return (*m_server->nick());
96} */ 97} */
97 98
98IRCServer *IRCServerTab::server() { 99IRCServer *IRCServerTab::server() {
99 return &m_server; 100 return &m_server;
100} 101}
101 102
102void IRCServerTab::settingsChanged() { 103void IRCServerTab::settingsChanged() {
103 m_textview->setText("<qt bgcolor=\"" + m_backgroundColor + "\"/>"); 104 m_textview->setText("<qt bgcolor=\"" + m_backgroundColor + "\"/>");
104 m_lines = 0; 105 m_lines = 0;
105} 106}
106 107
107void IRCServerTab::executeCommand(IRCTab *tab, QString line) { 108void IRCServerTab::executeCommand(IRCTab *tab, QString line) {
108 QTextIStream stream(&line); 109 QTextIStream stream(&line);
109 QString command; 110 QString command;
110 stream >> command; 111 stream >> command;
111 command = command.upper().right(command.length()-1); 112 command = command.upper().right(command.length()-1);
112 113
113 //JOIN 114 //JOIN
114 if (command == "JOIN" || command == "J") { 115 if (command == "JOIN" || command == "J") {
115 QString channel; 116 QString channel;
116 stream >> channel; 117 stream >> channel;
117 /* According to RFC 1459 */ 118 /* According to RFC 1459 */
118 if (channel.length() > 0 && channel.length() < 200 && 119 if (channel.length() > 0 && channel.length() < 200 &&
119 channel.find(",") == -1 && channel.find("") == -1) { 120 channel.find(",") == -1 && channel.find("") == -1) {
120 121
121 if (!channel.startsWith("#") && !channel.startsWith("&")) { 122 if (!channel.startsWith("#") && !channel.startsWith("&")) {
122 channel = channel.prepend("#"); 123 channel = channel.prepend("#");
123 } 124 }
124 m_session->join(channel); 125 m_session->join(channel);
125 } else { 126 } else {
126 tab->appendText("<font color=\"" + m_errorColor + "\">Unknown channel format!</font><br>"); 127 tab->appendText("<font color=\"" + m_errorColor + "\">Unknown channel format!</font><br>");
127 } 128 }
128 } 129 }
129 130
130 //KICK 131 //KICK
131 else if (command == "KICK"){ 132 else if (command == "KICK"){
132 QString nickname; 133 QString nickname;
133 stream >> nickname; 134 stream >> nickname;
134 if (nickname.length() > 0) { 135 if (nickname.length() > 0) {
135 if (line.length() > 7 + nickname.length()) { 136 if (line.length() > 7 + nickname.length()) {
136 QString text = line.right(line.length()-nickname.length()-7); 137 QString text = line.right(line.length()-nickname.length()-7);
137 IRCPerson person; 138 IRCPerson person;
138 person.setNick(nickname); 139 person.setNick(nickname);
139 m_session->kick(((IRCChannelTab *)tab)->channel(), &person, text); 140 m_session->kick(((IRCChannelTab *)tab)->channel(), &person, text);
140 } else { 141 } else {
141 IRCPerson person; 142 IRCPerson person;
142 person.setNick(nickname); 143 person.setNick(nickname);
143 m_session->kick(((IRCChannelTab *)tab)->channel(), &person); 144 m_session->kick(((IRCChannelTab *)tab)->channel(), &person);
144 } 145 }
145 } 146 }
146 } 147 }
147 148
148 else if (command == "OP"){ 149 else if (command == "OP"){
149 QString nickname; 150 QString nickname;
150 stream >> nickname; 151 stream >> nickname;
151 if (nickname.length() > 0) { 152 if (nickname.length() > 0) {
152 QString text = line.right(line.length()-nickname.length()-5); 153 QString text = line.right(line.length()-nickname.length()-5);
153 IRCPerson person; 154 IRCPerson person;
154 person.setNick(nickname); 155 person.setNick(nickname);
155 m_session->op(((IRCChannelTab *)tab)->channel(), &person); 156 m_session->op(((IRCChannelTab *)tab)->channel(), &person);
156 } 157 }
157 } 158 }
158 159
159 //SEND MODES 160 //SEND MODES
160 else if (command == "MODE"){ 161 else if (command == "MODE"){
161 QString text = line.right(line.length()-6); 162 QString text = line.right(line.length()-6);
162 if (text.length() > 0) { 163 if (text.length() > 0) {
163 m_session->mode(text); 164 m_session->mode(text);
164 } else { 165 } else {
165 tab->appendText("<font color=\"" + m_errorColor + "\">/mode channel {[+|-]|o|p|s|i|t|n|b|v} [limit] [user] [ban mask]<br>/mode nickname {[+|-]|i|w|s|o}</font><br>"); 166 tab->appendText("<font color=\"" + m_errorColor + "\">/mode channel {[+|-]|o|p|s|i|t|n|b|v} [limit] [user] [ban mask]<br>/mode nickname {[+|-]|i|w|s|o}</font><br>");
166 } 167 }
167 } 168 }
168 //SEND RAW MESSAGE TO SERVER, COMPLETELY UNCHECKED - anything in the RFC...or really anything you want 169 //SEND RAW MESSAGE TO SERVER, COMPLETELY UNCHECKED - anything in the RFC...or really anything you want
169 else if (command == "RAW"){ 170 else if (command == "RAW"){
170 QString text = line.right(line.length()-5); 171 QString text = line.right(line.length()-5);
171 if (text.length() > 0) { 172 if (text.length() > 0) {
172 m_session->raw(text); 173 m_session->raw(text);
173 } 174 }
174 } 175 }
175 else if (command == "SUSPEND"){ 176 else if (command == "SUSPEND"){
176 QString text = line.right(line.length()-9); 177 QString text = line.right(line.length()-9);
177 if (text.upper() == "ON") { 178 if (text.upper() == "ON") {
178 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; 179 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
179 } 180 }
180 else if (text.upper() == "OFF"){ 181 else if (text.upper() == "OFF"){
181 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Disable; 182 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Disable;
182 } else { 183 } else {
183 tab->appendText("<font color=\"" + m_errorColor + "\">Line: "+ line +"</font><br>Text: "+text); 184 tab->appendText("<font color=\"" + m_errorColor + "\">Line: "+ line +"</font><br>Text: "+text);
184 } 185 }
185 } 186 }
186 187
187 else if (command == "QUIT"){ 188 else if (command == "QUIT"){
188 QString text = line.right(line.length()-6); 189 QString text = line.right(line.length()-6);
189 if (text.length() > 0) { 190 if (text.length() > 0) {
190 m_session->quit(text); 191 m_session->quit(text);
191 } else { 192 } else {
192 m_session->quit(); 193 m_session->quit();
193 } 194 }
194 } 195 }
195 196
196 //SEND ACTION 197 //SEND ACTION
197 else if (command == "ME") { 198 else if (command == "ME") {
198 QString text = line.right(line.length()-4); 199 QString text = line.right(line.length()-4);
199 if (text.length() > 0) { 200 if (text.length() > 0) {
200 if (tab->isA("IRCChannelTab")) { 201 if (tab->isA("IRCChannelTab")) {
201 tab->appendText("<font color=\"" + m_selfColor + "\">*" + IRCOutput::toHTML(m_server.nick()) + " " + IRCOutput::toHTML(text) + "</font><br>"); 202 tab->appendText("<font color=\"" + m_selfColor + "\">*" + IRCOutput::toHTML(m_server.nick()) + " " + IRCOutput::toHTML(text) + "</font><br>");
202 m_session->sendAction(((IRCChannelTab *)tab)->channel(), text); 203 m_session->sendAction(((IRCChannelTab *)tab)->channel(), text);
203 } else if (tab->isA("IRCQueryTab")) { 204 } else if (tab->isA("IRCQueryTab")) {
204 tab->appendText("<font color=\"" + m_selfColor + "\">*" + IRCOutput::toHTML(m_server.nick()) + " " + IRCOutput::toHTML(text) + "</font><br>"); 205 tab->appendText("<font color=\"" + m_selfColor + "\">*" + IRCOutput::toHTML(m_server.nick()) + " " + IRCOutput::toHTML(text) + "</font><br>");
205 m_session->sendAction(((IRCQueryTab *)tab)->person(), text); 206 m_session->sendAction(((IRCQueryTab *)tab)->person(), text);
206 } else { 207 } else {
207 tab->appendText("<font color=\"" + m_errorColor + "\">Invalid tab for this command</font><br>"); 208 tab->appendText("<font color=\"" + m_errorColor + "\">Invalid tab for this command</font><br>");
208 } 209 }
209 } 210 }
210 } 211 }
211 //SEND PRIVMSG 212 //SEND PRIVMSG
212 else if (command == "MSG") { 213 else if (command == "MSG") {
213 QString nickname; 214 QString nickname;
214 stream >> nickname; 215 stream >> nickname;
215 if (nickname.length() > 0) { 216 if (nickname.length() > 0) {
216 if (line.length() > 6 + nickname.length()) { 217 if (line.length() > 6 + nickname.length()) {
217 QString text = line.right(line.length()-nickname.length()-6); 218 QString text = line.right(line.length()-nickname.length()-6);
218 IRCPerson person; 219 IRCPerson person;
219 person.setNick(nickname); 220 person.setNick(nickname);
220 tab->appendText("<font color=\"" + m_textColor + "\">&gt;</font><font color=\"" + m_otherColor + "\">"+IRCOutput::toHTML(nickname)+"</font><font color=\"" + m_textColor + "\">&lt; "+IRCOutput::toHTML(text)+"</font><br>"); 221 tab->appendText("<font color=\"" + m_textColor + "\">&gt;</font><font color=\"" + m_otherColor + "\">"+IRCOutput::toHTML(nickname)+"</font><font color=\"" + m_textColor + "\">&lt; "+IRCOutput::toHTML(text)+"</font><br>");
221 m_session->sendMessage(&person, text); 222 m_session->sendMessage(&person, text);
222 } 223 }
223 } 224 }
224 } 225 }
225 else { 226 else {
226 tab->appendText("<font color=\"" + m_errorColor + "\">Unknown command</font><br>"); 227 tab->appendText("<font color=\"" + m_errorColor + "\">Unknown command</font><br>");
227 } 228 }
228} 229}
229 230
230void IRCServerTab::processCommand() { 231void IRCServerTab::processCommand() {
231 QString text = m_field->text(); 232 QString text = m_field->text();
232 if (text.startsWith("/") && !text.startsWith("//")) { 233 if (text.startsWith("/") && !text.startsWith("//")) {
233 /* Command mode */ 234 /* Command mode */
234 executeCommand(this, text); 235 executeCommand(this, text);
235 } 236 }
236 m_field->clear(); 237 m_field->clear();
237} 238}
238 239
239void IRCServerTab::doConnect() { 240void IRCServerTab::doConnect() {
240 m_session->beginSession(); 241 m_session->beginSession();
241} 242}
242 243
243void IRCServerTab::remove() { 244void IRCServerTab::remove() {
244 /* Close requested */ 245 /* Close requested */
245 if (m_session->isSessionActive()) { 246 if (m_session->isSessionActive()) {
246 /* While there is a running session */ 247 /* While there is a running session */
247 m_close = TRUE; 248 m_close = TRUE;
248 m_session->endSession(); 249 m_session->endSession();
249 } else { 250 } else {
250 /* Session has previously been closed */ 251 /* Session has previously been closed */
251 m_channelTabs.first(); 252 m_channelTabs.first();
252 while (m_channelTabs.current() != 0) { 253 while (m_channelTabs.current() != 0) {
253 m_mainWindow->killTab(m_channelTabs.current(), true); 254 m_mainWindow->killTab(m_channelTabs.current(), true);
254 } 255 }
255 m_queryTabs.first(); 256 m_queryTabs.first();
256 while (m_queryTabs.current() != 0) { 257 while (m_queryTabs.current() != 0) {
257 m_mainWindow->killTab(m_queryTabs.current(), true); 258 m_mainWindow->killTab(m_queryTabs.current(), true);
258 } 259 }
259 m_mainWindow->killTab(this); 260 m_mainWindow->killTab(this);
260 } 261 }
261} 262}
262 263
263IRCChannelTab *IRCServerTab::getTabForChannel(IRCChannel *channel) { 264IRCChannelTab *IRCServerTab::getTabForChannel(IRCChannel *channel) {
264 QListIterator<IRCChannelTab> it(m_channelTabs); 265 QListIterator<IRCChannelTab> it(m_channelTabs);
265 266
266 for (; it.current(); ++it) { 267 for (; it.current(); ++it) {
267 if (it.current()->channel() == channel) 268 if (it.current()->channel() == channel)
268 return it.current(); 269 return it.current();
269 } 270 }
270 return 0; 271 return 0;
271} 272}
272 273
273IRCQueryTab *IRCServerTab::getTabForQuery(IRCPerson *person) { 274IRCQueryTab *IRCServerTab::getTabForQuery(IRCPerson *person) {
274 QListIterator<IRCQueryTab> it(m_queryTabs); 275 QListIterator<IRCQueryTab> it(m_queryTabs);
275 276
276 for (; it.current(); ++it) { 277 for (; it.current(); ++it) {
277 if (it.current()->person()->nick() == person->nick()) 278 if (it.current()->person()->nick() == person->nick())
278 return it.current(); 279 return it.current();
279 } 280 }
280 return 0; 281 return 0;
281} 282}
282 283
283void IRCServerTab::display(IRCOutput output) { 284void IRCServerTab::display(IRCOutput output) {
284 285
285 /* All messages to be displayed inside the GUI get here */ 286 /* All messages to be displayed inside the GUI get here */
286 switch (output.type()) { 287 switch (output.type()) {
287 case OUTPUT_CONNCLOSE: 288 case OUTPUT_CONNCLOSE:
288 if (m_close) { 289 if (m_close) {
289 m_channelTabs.first(); 290 m_channelTabs.first();
290 while (m_channelTabs.current() != 0) { 291 while (m_channelTabs.current() != 0) {
291 m_mainWindow->killTab(m_channelTabs.current(), true); 292 m_mainWindow->killTab(m_channelTabs.current(), true);
292 } 293 }
293 m_queryTabs.first(); 294 m_queryTabs.first();
294 while (m_queryTabs.current() != 0) { 295 while (m_queryTabs.current() != 0) {
295 m_mainWindow->killTab(m_queryTabs.current(), true); 296 m_mainWindow->killTab(m_queryTabs.current(), true);
296 } 297 }
297 m_mainWindow->killTab(this); 298 m_mainWindow->killTab(this);
298 } else { 299 } else {
299 appendText("<font color=\"" + m_errorColor + "\">" + output.htmlMessage() +"</font><br>"); 300 appendText("<font color=\"" + m_errorColor + "\">" + output.htmlMessage() +"</font><br>");
300 QListIterator<IRCChannelTab> it(m_channelTabs); 301 QListIterator<IRCChannelTab> it(m_channelTabs);
301 for (; it.current(); ++it) { 302 for (; it.current(); ++it) {
302 it.current()->appendText("<font color=\"" + m_serverColor + "\">" + output.htmlMessage() +"</font><br>"); 303 it.current()->appendText("<font color=\"" + m_serverColor + "\">" + output.htmlMessage() +"</font><br>");
303 } 304 }
304 } 305 }
305 break; 306 break;
306 case OUTPUT_SELFJOIN: { 307 case OUTPUT_SELFJOIN: {
307 IRCChannelTab *channeltab = new IRCChannelTab((IRCChannel *)output.getParam(0), this, m_mainWindow, (QWidget *)parent()); 308 IRCChannelTab *channeltab = new IRCChannelTab((IRCChannel *)output.getParam(0), this, m_mainWindow, (QWidget *)parent());
308 m_channelTabs.append(channeltab); 309 m_channelTabs.append(channeltab);
309 m_mainWindow->addTab(channeltab); 310 m_mainWindow->addTab(channeltab);
310 } 311 }
311 break; 312 break;
312 case OUTPUT_CHANPRIVMSG: { 313 case OUTPUT_CHANPRIVMSG: {
313 IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0)); 314 IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0));
314 channelTab->appendText("<font color=\"" + m_textColor + "\">&lt;</font><font color=\"" + m_otherColor + "\">"+IRCOutput::toHTML(((IRCChannelPerson *)output.getParam(1))->person->nick())+"</font><font color=\"" + m_textColor + "\">&gt; " + output.htmlMessage()+"</font><br>"); 315 channelTab->appendText("<font color=\"" + m_textColor + "\">&lt;</font><font color=\"" + m_otherColor + "\">"+IRCOutput::toHTML(((IRCChannelPerson *)output.getParam(1))->nick())+"</font><font color=\"" + m_textColor + "\">&gt; " + output.htmlMessage()+"</font><br>");
315 } 316 }
316 break; 317 break;
317 case OUTPUT_QUERYACTION: 318 case OUTPUT_QUERYACTION:
318 case OUTPUT_QUERYPRIVMSG: { 319 case OUTPUT_QUERYPRIVMSG: {
319 IRCQueryTab *queryTab = getTabForQuery((IRCPerson *)output.getParam(0)); 320 IRCQueryTab *queryTab = getTabForQuery((IRCPerson *)output.getParam(0));
320 if (!queryTab) { 321 if (!queryTab) {
321 queryTab = new IRCQueryTab((IRCPerson *)output.getParam(0), this, m_mainWindow, (QWidget *)parent()); 322 queryTab = new IRCQueryTab((IRCPerson *)output.getParam(0), this, m_mainWindow, (QWidget *)parent());
322 m_queryTabs.append(queryTab); 323 m_queryTabs.append(queryTab);
323 m_mainWindow->addTab(queryTab); 324 m_mainWindow->addTab(queryTab);
324 } 325 }
325 queryTab->display(output); 326 queryTab->display(output);
326 } 327 }
327 break; 328 break;
328 case OUTPUT_SELFPART: { 329 case OUTPUT_SELFPART: {
329 IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0)); 330 IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0));
330 if (channelTab) 331 if (channelTab)
331 m_mainWindow->killTab(channelTab, true); 332 m_mainWindow->killTab(channelTab, true);
332 } 333 }
333 break; 334 break;
334 case OUTPUT_SELFKICK: { 335 case OUTPUT_SELFKICK: {
335 appendText("<font color=\"" + m_errorColor + "\">" + output.htmlMessage() + "</font><br>"); 336 appendText("<font color=\"" + m_errorColor + "\">" + output.htmlMessage() + "</font><br>");
336 IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0)); 337 IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0));
337 if (channelTab) 338 if (channelTab)
338 m_mainWindow->killTab(channelTab, true); 339 m_mainWindow->killTab(channelTab, true);
339 } 340 }
340 break; 341 break;
341 case OUTPUT_CHANACTION: { 342 case OUTPUT_CHANACTION: {
342 IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0)); 343 IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0));
343 channelTab->appendText("<font color=\"" + m_otherColor + "\">"+output.htmlMessage()+"</font><br>"); 344 channelTab->appendText("<font color=\"" + m_otherColor + "\">"+output.htmlMessage()+"</font><br>");
344 } 345 }
345 break; 346 break;
346 case OUTPUT_TOPIC: { 347 case OUTPUT_TOPIC: {
347 IRCChannel *channel = (IRCChannel *) output.getParam(0); 348 IRCChannel *channel = (IRCChannel *) output.getParam(0);
348 if (channel) { 349 if (channel) {
349 IRCChannelTab *channelTab = getTabForChannel(channel); 350 IRCChannelTab *channelTab = getTabForChannel(channel);
350 if (channelTab) { 351 if (channelTab) {
351 channelTab->appendText("<font color=\"" + m_notificationColor + "\">"+output.htmlMessage()+"</font><br>"); 352 channelTab->appendText("<font color=\"" + m_notificationColor + "\">"+output.htmlMessage()+"</font><br>");
352 return; 353 return;
353 } 354 }
354 } 355 }
355 IRCChannelTab::enqueue(channel->channelname(), "<font color=\"" + m_notificationColor + "\">"+output.htmlMessage()+"</font><br>"); 356 IRCChannelTab::enqueue(channel->channelname(), "<font color=\"" + m_notificationColor + "\">"+output.htmlMessage()+"</font><br>");
356 } 357 }
357 break; 358 break;
358 case OUTPUT_QUIT: { 359 case OUTPUT_QUIT: {
359 QString nick = ((IRCPerson *)output.getParam(0))->nick(); 360 QString nick = ((IRCPerson *)output.getParam(0))->nick();
360 QListIterator<IRCChannelTab> it(m_channelTabs); 361 QListIterator<IRCChannelTab> it(m_channelTabs);
361 for (; it.current(); ++it) { 362 for (; it.current(); ++it) {
362 if (it.current()->list()->hasPerson(nick)) { 363 if (it.current()->list()->hasPerson(nick)) {
363 it.current()->appendText("<font color=\"" + m_notificationColor + "\">"+output.htmlMessage()+"</font><br>"); 364 it.current()->appendText("<font color=\"" + m_notificationColor + "\">"+output.htmlMessage()+"</font><br>");
364 it.current()->list()->update(); 365 it.current()->list()->update();
365 } 366 }
366 } 367 }
367 } 368 }
368 break; 369 break;
369 case OUTPUT_NICKCHANGE: { 370 case OUTPUT_NICKCHANGE: {
370 QString *nick = static_cast<QString*>(output.getParam(0)); 371 QString *nick = static_cast<QString*>(output.getParam(0));
371 if(!nick) { 372 if(!nick) {
372 appendText("<font color=\"" + m_notificationColor + "\">"+output.htmlMessage()+"</font><br>"); 373 appendText("<font color=\"" + m_notificationColor + "\">"+output.htmlMessage()+"</font><br>");
373 break; 374 break;
374 } 375 }
375 QListIterator<IRCChannelTab> it(m_channelTabs); 376 QListIterator<IRCChannelTab> it(m_channelTabs);
376 for (; it.current(); ++it) { 377 for (; it.current(); ++it) {
377 if (it.current()->list()->hasPerson(*nick)) { 378 if (it.current()->list()->hasPerson(*nick)) {
378 it.current()->appendText("<font color=\"" + m_notificationColor + "\">"+output.htmlMessage()+"</font><br>"); 379 it.current()->appendText("<font color=\"" + m_notificationColor + "\">"+output.htmlMessage()+"</font><br>");
379 } 380 }
380 } 381 }
381 delete nick; 382 delete nick;
382 } 383 }
383 break; 384 break;
384 case OUTPUT_OTHERJOIN: 385 case OUTPUT_OTHERJOIN:
385 case OUTPUT_OTHERKICK: 386 case OUTPUT_OTHERKICK:
386 case OUTPUT_CHANPERSONMODE: 387 case OUTPUT_CHANPERSONMODE:
387 case OUTPUT_OTHERPART: { 388 case OUTPUT_OTHERPART: {
388 IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0)); 389 IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0));
389 channelTab->appendText("<font color=\"" + m_notificationColor + "\">"+output.htmlMessage()+"</font><br>"); 390 channelTab->appendText("<font color=\"" + m_notificationColor + "\">"+output.htmlMessage()+"</font><br>");
390 channelTab->list()->update(); 391 channelTab->list()->update();
391 } 392 }
392 break; 393 break;
393 case OUTPUT_CTCP: 394 case OUTPUT_CTCP:
394 appendText("<font color=\"" + m_notificationColor + "\">" + output.htmlMessage() + "</font><br>"); 395 appendText("<font color=\"" + m_notificationColor + "\">" + output.htmlMessage() + "</font><br>");
395 break; 396 break;
396 case OUTPUT_ERROR: 397 case OUTPUT_ERROR:
397 appendText("<font color=\"" + m_errorColor + "\">" + output.htmlMessage() + "</font><br>"); 398 appendText("<font color=\"" + m_errorColor + "\">" + output.htmlMessage() + "</font><br>");
398 break; 399 break;
399 case OUTPUT_TITLE: 400 case OUTPUT_TITLE:
400 m_description->setText(output.message()); 401 m_description->setText(output.message());
401 break; 402 break;
402 default: 403 default:
403 appendText("<font color=\"" + m_serverColor + "\">" + output.htmlMessage() + "</font><br>"); 404 appendText("<font color=\"" + m_serverColor + "\">" + output.htmlMessage() + "</font><br>");
404 break; 405 break;
405 } 406 }
406} 407}
407 408
408void IRCServerTab::slotUpdateChannels() { 409void IRCServerTab::slotUpdateChannels() {
409 QListIterator<IRCChannelTab> it(m_channelTabs); 410 QListIterator<IRCChannelTab> it(m_channelTabs);
410 for (; it.current(); ++it) { 411 for (; it.current(); ++it) {
411 it.current()->list()->update(); 412 it.current()->list()->update();
412 } 413 }
413} 414}
414 415
diff --git a/noncore/net/opieirc/ircsession.cpp b/noncore/net/opieirc/ircsession.cpp
index ca0df50..80a327a 100644
--- a/noncore/net/opieirc/ircsession.cpp
+++ b/noncore/net/opieirc/ircsession.cpp
@@ -1,196 +1,214 @@
1
1#include "ircsession.h" 2#include "ircsession.h"
2#include "ircmessageparser.h" 3#include "ircmessageparser.h"
4#include "ircchannelperson.h"
3#include "ircversion.h" 5#include "ircversion.h"
4 6
5IRCSession::IRCSession(IRCServer *server) { 7IRCSession::IRCSession(IRCServer *server) {
6 m_server = server; 8 m_server = server;
7 m_connection = new IRCConnection(m_server); 9 m_connection = new IRCConnection(m_server);
8 m_parser = new IRCMessageParser(this); 10 m_parser = new IRCMessageParser(this);
9 connect(m_connection, SIGNAL(messageArrived(IRCMessage*)), this, SLOT(handleMessage(IRCMessage*))); 11 connect(m_connection, SIGNAL(messageArrived(IRCMessage*)), this, SLOT(handleMessage(IRCMessage*)));
10 connect(m_parser, SIGNAL(outputReady(IRCOutput)), this, SIGNAL(outputReady(IRCOutput))); 12 connect(m_parser, SIGNAL(outputReady(IRCOutput)), this, SIGNAL(outputReady(IRCOutput)));
11 connect(m_connection, SIGNAL(outputReady(IRCOutput)), this, SIGNAL(outputReady(IRCOutput))); 13 connect(m_connection, SIGNAL(outputReady(IRCOutput)), this, SIGNAL(outputReady(IRCOutput)));
12} 14}
13 15
14IRCSession::~IRCSession() { 16IRCSession::~IRCSession() {
15 /* We want this to get deleted automatically */ 17 /* We want this to get deleted automatically */
16 m_channels.setAutoDelete(TRUE); 18 m_channels.setAutoDelete(TRUE);
17 m_people.setAutoDelete(TRUE); 19 m_people.setAutoDelete(TRUE);
18 20
19 delete m_parser; 21 delete m_parser;
20 delete m_connection; 22 delete m_connection;
21} 23}
22 24
23void IRCSession::beginSession() { 25void IRCSession::beginSession() {
24 m_connection->doConnect(); 26 m_connection->doConnect();
25} 27}
26 28
27void IRCSession::join(QString channelname) { 29void IRCSession::join(QString channelname) {
28 m_connection->sendLine("JOIN " + channelname); 30 m_connection->sendLine("JOIN " + channelname);
29} 31}
30 32
31void IRCSession::quit(){ 33void IRCSession::quit(){
32 m_connection->sendLine("QUIT :[OI] I'm too good to need a reason"); 34 m_connection->sendLine("QUIT :[OI] I'm too good to need a reason");
33} 35}
34 36
35void IRCSession::quit(QString message){ 37void IRCSession::quit(QString message){
36 m_connection->sendLine("QUIT :" + message); 38 m_connection->sendLine("QUIT :" + message);
37} 39}
38 40
39void IRCSession::topic(IRCChannel *channel, QString message){ 41void IRCSession::topic(IRCChannel *channel, QString message){
40 m_connection->sendLine("TOPIC :" + channel->channelname() + " " + message); 42 m_connection->sendLine("TOPIC :" + channel->channelname() + " " + message);
41} 43}
42 44
43void IRCSession::mode(IRCChannel *channel, QString message){ 45void IRCSession::mode(IRCChannel *channel, QString message){
44 m_connection->sendLine("MODE " + channel->channelname() + " " + message); 46 m_connection->sendLine("MODE " + channel->channelname() + " " + message);
45} 47}
46 48
47void IRCSession::mode(IRCPerson *person, QString message){ 49void IRCSession::mode(IRCPerson *person, QString message){
48 m_connection->sendLine("MODE " + person->nick() + " " + message); 50 m_connection->sendLine("MODE " + person->nick() + " " + message);
49} 51}
50 52
51void IRCSession::mode(QString message){ 53void IRCSession::mode(QString message){
52 m_connection->sendLine("MODE " + message); 54 m_connection->sendLine("MODE " + message);
53} 55}
54 56
55void IRCSession::raw(QString message){ 57void IRCSession::raw(QString message){
56 m_connection->sendLine(message); 58 m_connection->sendLine(message);
57} 59}
58 60
59void IRCSession::kick(IRCChannel *channel, IRCPerson *person) { 61void IRCSession::kick(IRCChannel *channel, IRCPerson *person) {
60 m_connection->sendLine("KICK " + channel->channelname() + " " + person->nick() +" :0wn3d - no reason"); 62 m_connection->sendLine("KICK " + channel->channelname() + " " + person->nick() +" :0wn3d - no reason");
61} 63}
62 64
63void IRCSession::op(IRCChannel *channel, IRCPerson *person) { 65void IRCSession::op(IRCChannel *channel, IRCPerson *person) {
64 m_connection->sendLine("MODE " + channel->channelname() + " +ooo " + person->nick()); 66 m_connection->sendLine("MODE " + channel->channelname() + " +ooo " + person->nick());
65} 67}
66 68
67void IRCSession::kick(IRCChannel *channel, IRCPerson *person, QString message) { 69void IRCSession::kick(IRCChannel *channel, IRCPerson *person, QString message) {
68 m_connection->sendLine("KICK " + channel->channelname() + " " + person->nick() +" :" + message); 70 m_connection->sendLine("KICK " + channel->channelname() + " " + person->nick() +" :" + message);
69} 71}
70 72
71void IRCSession::sendMessage(IRCPerson *person, QString message) { 73void IRCSession::sendMessage(IRCPerson *person, QString message) {
72 m_connection->sendLine("PRIVMSG " + person->nick() + " :" + message); 74 m_connection->sendLine("PRIVMSG " + person->nick() + " :" + message);
73} 75}
74 76
75void IRCSession::sendMessage(IRCChannel *channel, QString message) { 77void IRCSession::sendMessage(IRCChannel *channel, QString message) {
76 m_connection->sendLine("PRIVMSG " + channel->channelname() + " :" + message); 78 m_connection->sendLine("PRIVMSG " + channel->channelname() + " :" + message);
77} 79}
78 80
79void IRCSession::sendAction(IRCChannel *channel, QString message) { 81void IRCSession::sendAction(IRCChannel *channel, QString message) {
80 m_connection->sendLine("PRIVMSG " + channel->channelname() + " :\001ACTION " + message + "\001"); 82 m_connection->sendLine("PRIVMSG " + channel->channelname() + " :\001ACTION " + message + "\001");
81} 83}
82 84
83void IRCSession::sendAction(IRCPerson *person, QString message) { 85void IRCSession::sendAction(IRCPerson *person, QString message) {
84 m_connection->sendLine("PRIVMSG " + person->nick() + " :\001ACTION " + message + "\001"); 86 m_connection->sendLine("PRIVMSG " + person->nick() + " :\001ACTION " + message + "\001");
85} 87}
86 88
87bool IRCSession::isSessionActive() { 89bool IRCSession::isSessionActive() {
88 return m_connection->isConnected(); 90 return m_connection->isConnected();
89} 91}
90 92
91bool IRCSession::isLoggedIn() { 93bool IRCSession::isLoggedIn() {
92 return m_connection->isLoggedIn(); 94 return m_connection->isLoggedIn();
93} 95}
94 96
95void IRCSession::endSession() { 97void IRCSession::endSession() {
96 if (m_connection->isLoggedIn()) 98 if (m_connection->isLoggedIn())
97 quit(APP_VERSION); 99 quit(APP_VERSION);
98 else 100 else
99 m_connection->close(); 101 m_connection->close();
100} 102}
101 103
102void IRCSession::part(IRCChannel *channel) { 104void IRCSession::part(IRCChannel *channel) {
103 m_connection->sendLine("PART " + channel->channelname() + " :" + APP_VERSION); 105 m_connection->sendLine("PART " + channel->channelname() + " :" + APP_VERSION);
104} 106}
105 107
106void IRCSession::setValidUsermodes(const QString &modes) { 108void IRCSession::setValidUsermodes(const QString &modes) {
107 m_validUsermodes = modes; 109 m_validUsermodes = modes;
108} 110}
109 111
110void IRCSession::setValidChannelmodes(const QString &modes) { 112void IRCSession::setValidChannelmodes(const QString &modes) {
111 m_validChannelmodes = modes; 113 m_validChannelmodes = modes;
112} 114}
113 115
114void IRCSession::updateNickname(const QString &oldNickname, const QString &newNickname) { 116void IRCSession::updateNickname(const QString &oldNickname, const QString &newNickname) {
115 QList<IRCChannel> channels; 117 QList<IRCChannel> channels;
116 IRCOutput output; 118 IRCOutput output;
117 119
118 if (oldNickname == m_server->nick()) { 120 if (oldNickname == m_server->nick()) {
119 m_server->setNick(newNickname); 121 m_server->setNick(newNickname);
120 output = IRCOutput(OUTPUT_NICKCHANGE, tr("You are now known as %1").arg(newNickname)); 122 output = IRCOutput(OUTPUT_NICKCHANGE, tr("You are now known as %1").arg(newNickname));
121 channels = m_channels; 123 channels = m_channels;
122 } 124 }
123 125
124 else { 126 else {
125 IRCPerson *person = getPerson(oldNickname); 127 IRCPerson *person = getPerson(oldNickname);
126 128
127 if(!person) { 129 if(!person) {
128 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Nickname change of an unknown person"))); 130 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Nickname change of an unknown person")));
129 return; 131 return;
130 } 132 }
131 133
132 getChannelsByPerson(person, channels); 134 getChannelsByPerson(person, channels);
133 output = IRCOutput(OUTPUT_NICKCHANGE, tr("%1 is now known as %2").arg(oldNickname).arg(newNickname)); 135 output = IRCOutput(OUTPUT_NICKCHANGE, tr("%1 is now known as %2").arg(oldNickname).arg(newNickname));
134 } 136 }
135 137
136 QListIterator<IRCChannel> it(channels); 138 QListIterator<IRCChannel> it(channels);
137 for (;it.current(); ++it) { 139 for (;it.current(); ++it) {
138 IRCChannelPerson *chanperson = it.current()->getPerson(oldNickname); 140 IRCChannelPerson *chanperson = it.current()->getPerson(oldNickname);
139 it.current()->removePerson(chanperson); 141 it.current()->removePerson(chanperson);
140 chanperson->person->setNick(newNickname); 142 chanperson->setNick(newNickname);
141 it.current()->addPerson(chanperson); 143 it.current()->addPerson(chanperson);
142 } 144 }
143 145
144 emit updateChannels(); 146 emit updateChannels();
145 output.addParam(new QString(newNickname)); 147 output.addParam(new QString(newNickname));
146 emit outputReady(output); 148 emit outputReady(output);
147} 149}
148 150
149IRCChannel *IRCSession::getChannel(QString channelname) { 151IRCChannel *IRCSession::getChannel(QString channelname) {
150 QListIterator<IRCChannel> it(m_channels); 152 QListIterator<IRCChannel> it(m_channels);
151 for (; it.current(); ++it) { 153 for (; it.current(); ++it) {
152 if (it.current()->channelname() == channelname) { 154 if (it.current()->channelname() == channelname) {
153 return it.current(); 155 return it.current();
154 } 156 }
155 } 157 }
156 return 0; 158 return 0;
157} 159}
158 160
159IRCPerson *IRCSession::getPerson(QString nickname) { 161IRCPerson *IRCSession::getPerson(QString nickname) {
160 QListIterator<IRCPerson> it(m_people); 162 QListIterator<IRCPerson> it(m_people);
161 for (; it.current(); ++it) { 163 for (; it.current(); ++it) {
162 if (it.current()->nick() == nickname) { 164 if (it.current()->nick() == nickname) {
163 return it.current(); 165 return it.current();
164 } 166 }
165 } 167 }
166 return 0; 168 return 0;
167} 169}
168 170
169void IRCSession::getChannelsByPerson(IRCPerson *person, QList<IRCChannel> &channels) { 171void IRCSession::getChannelsByPerson(IRCPerson *person, QList<IRCChannel> &channels) {
170 QListIterator<IRCChannel> it(m_channels); 172 QListIterator<IRCChannel> it(m_channels);
171 for (; it.current(); ++it) { 173 for (; it.current(); ++it) {
172 if (it.current()->getPerson(person->nick()) != 0) { 174 if (it.current()->getPerson(person->nick()) != 0) {
173 channels.append(it.current()); 175 channels.append(it.current());
174 } 176 }
175 } 177 }
176} 178}
177 179
178void IRCSession::addPerson(IRCPerson *person) { 180void IRCSession::addPerson(IRCPerson *person) {
179 m_people.append(person); 181 m_people.append(person);
180} 182}
181 183
182void IRCSession::addChannel(IRCChannel *channel) { 184void IRCSession::addChannel(IRCChannel *channel) {
183 m_channels.append(channel); 185 m_channels.append(channel);
184} 186}
185 187
186void IRCSession::removeChannel(IRCChannel *channel) { 188void IRCSession::removeChannel(IRCChannel *channel) {
187 m_channels.remove(channel); 189 m_channels.remove(channel);
188} 190}
189 191
190void IRCSession::removePerson(IRCPerson *person) { 192void IRCSession::removePerson(IRCPerson *person) {
191 m_people.remove(person); 193 m_people.remove(person);
192} 194}
193 195
194void IRCSession::handleMessage(IRCMessage *message) { 196void IRCSession::handleMessage(IRCMessage *message) {
195 m_parser->parse(message); 197 m_parser->parse(message);
196} 198}
199
200void IRCSession::whois(const QString &nickname) {
201 m_connection->whois(nickname);
202}
203
204void IRCSession::sendCTCPPing(const QString &nickname) {
205 m_connection->sendCTCPPing(nickname);
206}
207
208void IRCSession::sendCTCPRequest(const QString &nickname, const QString &type, const QString &args) {
209 m_connection->sendCTCPRequest(nickname, type, args);
210}
211
212void IRCSession::sendCTCPReply(const QString &nickname, const QString &type, const QString &args) {
213 m_connection->sendCTCPReply(nickname, type, args);
214}
diff --git a/noncore/net/opieirc/ircsession.h b/noncore/net/opieirc/ircsession.h
index 96de3e4..3859b68 100644
--- a/noncore/net/opieirc/ircsession.h
+++ b/noncore/net/opieirc/ircsession.h
@@ -1,91 +1,95 @@
1/* 1/*
2 OpieIRC - An embedded IRC client 2 OpieIRC - An embedded IRC client
3 Copyright (C) 2002 Wenzel Jakob 3 Copyright (C) 2002 Wenzel Jakob
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18
19*/ 19*/
20 20
21#ifndef __IRCSESSION_H 21#ifndef __IRCSESSION_H
22#define __IRCSESSION_H 22#define __IRCSESSION_H
23 23
24#include <qstring.h> 24#include <qstring.h>
25#include <qlist.h> 25#include <qlist.h>
26#include "ircserver.h" 26#include "ircserver.h"
27#include "ircconnection.h" 27#include "ircconnection.h"
28#include "ircmessage.h" 28#include "ircmessage.h"
29#include "ircchannel.h" 29#include "ircchannel.h"
30#include "ircoutput.h" 30#include "ircoutput.h"
31 31
32class IRCMessageParser; 32class IRCMessageParser;
33 33
34/* The IRCSession stores all information relating to the connection 34/* The IRCSession stores all information relating to the connection
35 to one IRC server. IRCSession makes it possible to run multiple 35 to one IRC server. IRCSession makes it possible to run multiple
36 IRC server connections from within the same program */ 36 IRC server connections from within the same program */
37 37
38class IRCSession : public QObject { 38class IRCSession : public QObject {
39friend class IRCMessageParser; 39friend class IRCMessageParser;
40 Q_OBJECT 40 Q_OBJECT
41public: 41public:
42 IRCSession(IRCServer *server); 42 IRCSession(IRCServer *server);
43 ~IRCSession(); 43 ~IRCSession();
44 44
45 void join(QString channel); 45 void join(QString channel);
46 void quit(QString message); 46 void quit(QString message);
47 void quit(); 47 void quit();
48 void raw(QString message); 48 void raw(QString message);
49 void topic(IRCChannel *channel, QString message); 49 void topic(IRCChannel *channel, QString message);
50 void mode(IRCChannel *channel, QString message); 50 void mode(IRCChannel *channel, QString message);
51 void mode(IRCPerson *person, QString message); 51 void mode(IRCPerson *person, QString message);
52 void mode(QString message); 52 void mode(QString message);
53 void part(IRCChannel *channel); 53 void part(IRCChannel *channel);
54 void op(IRCChannel *channel, IRCPerson *person); 54 void op(IRCChannel *channel, IRCPerson *person);
55 void kick(IRCChannel *channel, IRCPerson *person); 55 void kick(IRCChannel *channel, IRCPerson *person);
56 void kick(IRCChannel *channel, IRCPerson *person, QString message); 56 void kick(IRCChannel *channel, IRCPerson *person, QString message);
57 void beginSession(); 57 void beginSession();
58 bool isSessionActive(); 58 bool isSessionActive();
59 void endSession(); 59 void endSession();
60 bool isLoggedIn(); 60 bool isLoggedIn();
61 void sendMessage(IRCPerson *person, QString message); 61 void sendMessage(IRCPerson *person, QString message);
62 void sendMessage(IRCChannel *channel, QString message); 62 void sendMessage(IRCChannel *channel, QString message);
63 void sendAction(IRCPerson *person, QString message); 63 void sendAction(IRCPerson *person, QString message);
64 void sendAction(IRCChannel *channel, QString message); 64 void sendAction(IRCChannel *channel, QString message);
65 void updateNickname(const QString &oldNickname, const QString &newNickname); 65 void updateNickname(const QString &oldNickname, const QString &newNickname);
66 void setValidUsermodes(const QString &modes); 66 void setValidUsermodes(const QString &modes);
67 void setValidChannelmodes(const QString &modes); 67 void setValidChannelmodes(const QString &modes);
68 void whois(const QString &nickname);
69 void sendCTCPPing(const QString &nickname);
70 void sendCTCPRequest(const QString &nickname, const QString &type, const QString &args);
71 void sendCTCPReply(const QString &nickname, const QString &type, const QString &args);
68 IRCChannel *getChannel(QString channelname); 72 IRCChannel *getChannel(QString channelname);
69 IRCPerson *getPerson(QString nickname); 73 IRCPerson *getPerson(QString nickname);
70protected: 74protected:
71 void addPerson(IRCPerson *person); 75 void addPerson(IRCPerson *person);
72 void addChannel(IRCChannel *channel); 76 void addChannel(IRCChannel *channel);
73 void removeChannel(IRCChannel *channel); 77 void removeChannel(IRCChannel *channel);
74 void removePerson(IRCPerson *person); 78 void removePerson(IRCPerson *person);
75 void getChannelsByPerson(IRCPerson *person, QList<IRCChannel> &channels); 79 void getChannelsByPerson(IRCPerson *person, QList<IRCChannel> &channels);
76protected slots: 80protected slots:
77 void handleMessage(IRCMessage *message); 81 void handleMessage(IRCMessage *message);
78signals: 82signals:
79 void outputReady(IRCOutput output); 83 void outputReady(IRCOutput output);
80 void updateChannels(); 84 void updateChannels();
81protected: 85protected:
82 IRCServer *m_server; 86 IRCServer *m_server;
83 IRCConnection *m_connection; 87 IRCConnection *m_connection;
84 IRCMessageParser *m_parser; 88 IRCMessageParser *m_parser;
85 QList<IRCChannel> m_channels; 89 QList<IRCChannel> m_channels;
86 QList<IRCPerson> m_people; 90 QList<IRCPerson> m_people;
87 QString m_validUsermodes; 91 QString m_validUsermodes;
88 QString m_validChannelmodes; 92 QString m_validChannelmodes;
89}; 93};
90 94
91#endif /* __IRCSESSION_H */ 95#endif /* __IRCSESSION_H */
diff --git a/noncore/net/opieirc/mainwindow.cpp b/noncore/net/opieirc/mainwindow.cpp
index 2562f33..1811a0c 100644
--- a/noncore/net/opieirc/mainwindow.cpp
+++ b/noncore/net/opieirc/mainwindow.cpp
@@ -1,135 +1,139 @@
1#include <qmenubar.h> 1#include <qmenubar.h>
2#include <qpe/resource.h> 2#include <qpe/resource.h>
3
4#include <opie2/odebug.h>
5
3#include <qwhatsthis.h> 6#include <qwhatsthis.h>
4 7
5#include "mainwindow.h" 8#include "mainwindow.h"
6#include "ircservertab.h" 9#include "ircservertab.h"
7#include "ircserverlist.h" 10#include "ircserverlist.h"
8#include "ircsettings.h" 11#include "ircsettings.h"
9 12
10QString MainWindow::appCaption() { 13QString MainWindow::appCaption() {
11 return QObject::tr("Opie IRC"); 14 return QObject::tr("Opie IRC");
12} 15}
13 16
14 17
15MainWindow::MainWindow(QWidget *parent, const char *name, WFlags) : QMainWindow(parent, name, WStyle_ContextHelp) { 18MainWindow::MainWindow(QWidget *parent, const char *name, WFlags) : QMainWindow(parent, name, WStyle_ContextHelp) {
16 setCaption(tr("IRC Client")); 19 setCaption(tr("IRC Client"));
17 m_tabWidget = new IRCTabWidget(this); 20 m_tabWidget = new IRCTabWidget(this);
18 QWhatsThis::add(m_tabWidget, tr("Server connections, channels, queries and other things will be placed here")); 21 QWhatsThis::add(m_tabWidget, tr("Server connections, channels, queries and other things will be placed here"));
19 connect(m_tabWidget, SIGNAL(currentChanged(QWidget*)), this, SLOT(selected(QWidget*))); 22 connect(m_tabWidget, SIGNAL(currentChanged(QWidget*)), this, SLOT(selected(QWidget*)));
20 setCentralWidget(m_tabWidget); 23 setCentralWidget(m_tabWidget);
21 setToolBarsMovable(FALSE); 24 setToolBarsMovable(FALSE);
22 QMenuBar *menuBar = new QMenuBar(this); 25 QMenuBar *menuBar = new QMenuBar(this);
23 QPopupMenu *irc = new QPopupMenu(this); 26 QPopupMenu *irc = new QPopupMenu(this);
24 menuBar->insertItem(tr("IRC"), irc); 27 menuBar->insertItem(tr("IRC"), irc);
25 QAction *a = new QAction(tr("New connection"), Resource::loadPixmap("pass"), QString::null, 0, this, 0); 28 QAction *a = new QAction(tr("New connection"), Resource::loadPixmap("pass"), QString::null, 0, this, 0);
26 connect(a, SIGNAL(activated()), this, SLOT(newConnection())); 29 connect(a, SIGNAL(activated()), this, SLOT(newConnection()));
27 a->setWhatsThis(tr("Create a new connection to an IRC server")); 30 a->setWhatsThis(tr("Create a new connection to an IRC server"));
28 a->addTo(irc); 31 a->addTo(irc);
29 a = new QAction(tr("Settings"), Resource::loadPixmap("SettingsIcon"), QString::null, 0, this, 0); 32 a = new QAction(tr("Settings"), Resource::loadPixmap("SettingsIcon"), QString::null, 0, this, 0);
30 a->setWhatsThis(tr("Configure OpieIRC's behavior and appearance")); 33 a->setWhatsThis(tr("Configure OpieIRC's behavior and appearance"));
31 connect(a, SIGNAL(activated()), this, SLOT(settings())); 34 connect(a, SIGNAL(activated()), this, SLOT(settings()));
32 a->addTo(irc); 35 a->addTo(irc);
33 loadSettings(); 36 loadSettings();
34} 37}
35 38
36/*IRCTabWidget MainWindow::getTabWidget(){ 39/*IRCTabWidget MainWindow::getTabWidget(){
37 return m_tabWidget; 40 return m_tabWidget;
38} */ 41} */
39 42
40void MainWindow::loadSettings() { 43void MainWindow::loadSettings() {
41 Config config("OpieIRC"); 44 Config config("OpieIRC");
42 config.setGroup("OpieIRC"); 45 config.setGroup("OpieIRC");
43 IRCTab::m_backgroundColor = config.readEntry("BackgroundColor", "#FFFFFF"); 46 IRCTab::m_backgroundColor = config.readEntry("BackgroundColor", "#FFFFFF");
44 IRCTab::m_textColor = config.readEntry("TextColor", "#000000"); 47 IRCTab::m_textColor = config.readEntry("TextColor", "#000000");
45 IRCTab::m_errorColor = config.readEntry("ErrorColor", "#FF0000"); 48 IRCTab::m_errorColor = config.readEntry("ErrorColor", "#FF0000");
46 IRCTab::m_selfColor = config.readEntry("SelfColor", "#CC0000"); 49 IRCTab::m_selfColor = config.readEntry("SelfColor", "#CC0000");
47 IRCTab::m_otherColor = config.readEntry("OtherColor", "#0000BB"); 50 IRCTab::m_otherColor = config.readEntry("OtherColor", "#0000BB");
48 IRCTab::m_serverColor = config.readEntry("ServerColor", "#0000FF"); 51 IRCTab::m_serverColor = config.readEntry("ServerColor", "#0000FF");
49 IRCTab::m_notificationColor = config.readEntry("NotificationColor", "#AA3300"); 52 IRCTab::m_notificationColor = config.readEntry("NotificationColor", "#AA3300");
50 IRCTab::m_maxLines = config.readNumEntry("Lines", 100); 53 IRCTab::m_maxLines = config.readNumEntry("Lines", 100);
51 IRCTab::setUseTimeStamps( config.readBoolEntry("DisplayTime", false ) ); 54 IRCTab::setUseTimeStamps( config.readBoolEntry("DisplayTime", false ) );
52} 55}
53 56
54void MainWindow::selected(QWidget *) { 57void MainWindow::selected(QWidget *) {
55 m_tabWidget->setTabColor(m_tabWidget->currentPageIndex(), black); 58 m_tabWidget->setTabColor(m_tabWidget->currentPageIndex(), black);
56 emit updateScroll(); 59 emit updateScroll();
57} 60}
58 61
59void MainWindow::addTab(IRCTab *tab) { 62void MainWindow::addTab(IRCTab *tab) {
60 connect(tab, SIGNAL(changed(IRCTab*)), this, SLOT(changeEvent(IRCTab*))); 63 connect(tab, SIGNAL(changed(IRCTab*)), this, SLOT(changeEvent(IRCTab*)));
61 connect(tab, SIGNAL(ping (const QString&)), this, SLOT(slotPing(const QString&))); 64 connect(tab, SIGNAL(ping (const QString&)), this, SLOT(slotPing(const QString&)));
62 connect(tab, SIGNAL(nextTab()), this, SLOT(slotNextTab())); 65 connect(tab, SIGNAL(nextTab()), this, SLOT(slotNextTab()));
63 connect(tab, SIGNAL(prevTab()), this, SLOT(slotPrevTab())); 66 connect(tab, SIGNAL(prevTab()), this, SLOT(slotPrevTab()));
64 67
65 m_tabWidget->addTab(tab, tab->title()); 68 m_tabWidget->addTab(tab, tab->title());
66 m_tabWidget->showPage(tab); 69 m_tabWidget->showPage(tab);
67 tab->setID(m_tabWidget->currentPageIndex()); 70 tab->setID(m_tabWidget->currentPageIndex());
68 m_tabs.append(tab); 71 m_tabs.append(tab);
69} 72}
70 73
71void MainWindow::changeEvent(IRCTab *tab) { 74void MainWindow::changeEvent(IRCTab *tab) {
72 if (tab->id() != m_tabWidget->currentPageIndex()) 75 if (tab->id() != m_tabWidget->currentPageIndex())
73 m_tabWidget->setTabColor(tab->id(), blue); 76 m_tabWidget->setTabColor(tab->id(), blue);
74} 77}
75 78
76void MainWindow::killTab(IRCTab *tab, bool imediate) { 79void MainWindow::killTab(IRCTab *tab, bool imediate) {
77 m_toDelete.append( tab ); 80 m_toDelete.append( tab );
78 81
79 if ( imediate ) 82 if ( imediate )
80 slotKillTabsLater(); 83 slotKillTabsLater();
81 else 84 else
82 QTimer::singleShot(0, this, SLOT(slotKillTabsLater()) ); 85 QTimer::singleShot(0, this, SLOT(slotKillTabsLater()) );
83} 86}
84 87
85void MainWindow::slotKillTabsLater() { 88void MainWindow::slotKillTabsLater() {
86 for ( QListIterator<IRCTab> it(m_toDelete); it.current(); ++it ) { 89 for ( QListIterator<IRCTab> it(m_toDelete); it.current(); ++it ) {
87 m_tabWidget->removePage( it.current() ); 90 m_tabWidget->removePage( it.current() );
91 odebug << it.current() << oendl;
88 m_tabs.remove( it.current() ); 92 m_tabs.remove( it.current() );
89 } 93 }
90 94
91 m_toDelete.setAutoDelete( true ); 95 m_toDelete.setAutoDelete( true );
92 m_toDelete.clear(); 96 m_toDelete.clear();
93 m_toDelete.setAutoDelete( false ); 97 m_toDelete.setAutoDelete( false );
94} 98}
95 99
96void MainWindow::newConnection() { 100void MainWindow::newConnection() {
97 IRCServerList list(this, "ServerList", TRUE); 101 IRCServerList list(this, "ServerList", TRUE);
98 if (list.exec() == QDialog::Accepted && list.hasServer()) { 102 if (list.exec() == QDialog::Accepted && list.hasServer()) {
99 IRCServerTab *serverTab = new IRCServerTab(list.server(), this, m_tabWidget); 103 IRCServerTab *serverTab = new IRCServerTab(list.server(), this, m_tabWidget);
100 addTab(serverTab); 104 addTab(serverTab);
101 serverTab->doConnect(); 105 serverTab->doConnect();
102 } 106 }
103} 107}
104 108
105void MainWindow::settings() { 109void MainWindow::settings() {
106 IRCSettings settings(this, "Settings", TRUE); 110 IRCSettings settings(this, "Settings", TRUE);
107 if (settings.exec() == QDialog::Accepted) { 111 if (settings.exec() == QDialog::Accepted) {
108 QListIterator<IRCTab> it(m_tabs); 112 QListIterator<IRCTab> it(m_tabs);
109 for (; it.current(); ++it) { 113 for (; it.current(); ++it) {
110 /* Inform all tabs about the new settings */ 114 /* Inform all tabs about the new settings */
111 it.current()->settingsChanged(); 115 it.current()->settingsChanged();
112 } 116 }
113 } 117 }
114} 118}
115 119
116 120
117void MainWindow::slotNextTab() { 121void MainWindow::slotNextTab() {
118 int i = m_tabWidget->currentPageIndex (); 122 int i = m_tabWidget->currentPageIndex ();
119 m_tabWidget->setCurrentPage ( i+1 ); 123 m_tabWidget->setCurrentPage ( i+1 );
120 124
121 int j = m_tabWidget->currentPageIndex (); 125 int j = m_tabWidget->currentPageIndex ();
122 if ( i == j ) 126 if ( i == j )
123 m_tabWidget->setCurrentPage ( 1 ); 127 m_tabWidget->setCurrentPage ( 1 );
124} 128}
125 129
126void MainWindow::slotPrevTab() { 130void MainWindow::slotPrevTab() {
127 int i = m_tabWidget->currentPageIndex (); 131 int i = m_tabWidget->currentPageIndex ();
128 if ( i > 1 ) 132 if ( i > 1 )
129 m_tabWidget->setCurrentPage ( i-1 ); 133 m_tabWidget->setCurrentPage ( i-1 );
130} 134}
131 135
132void MainWindow::slotPing( const QString& /*channel*/ ) { 136void MainWindow::slotPing( const QString& /*channel*/ ) {
133 raise(); 137 raise();
134} 138}
135 139
diff --git a/noncore/net/opieirc/opieirc.pro b/noncore/net/opieirc/opieirc.pro
index db89fa6..1ef9be2 100644
--- a/noncore/net/opieirc/opieirc.pro
+++ b/noncore/net/opieirc/opieirc.pro
@@ -1,28 +1,30 @@
1 CONFIG = qt warn_on quick-app 1 CONFIG = qt warn_on quick-app
2HEADERS = ircchannel.h ircconnection.h \ 2HEADERS = ircchannel.h ircconnection.h \
3 ircmessage.h \ 3 ircmessage.h \
4 ircmessageparser.h ircoutput.h \ 4 ircmessageparser.h ircoutput.h \
5 ircperson.h ircserver.h ircsession.h \ 5 ircperson.h ircserver.h ircsession.h \
6 mainwindow.h irctab.h ircservertab.h \ 6 mainwindow.h irctab.h ircservertab.h \
7 ircchanneltab.h ircchannellist.h \ 7 ircchanneltab.h ircchannellist.h \
8 ircserverlist.h ircservereditor.h \ 8 ircserverlist.h ircservereditor.h \
9 ircquerytab.h ircsettings.h ircmisc.h 9 ircquerytab.h ircsettings.h ircmisc.h \
10 ircchannelperson.h
10 SOURCES = ircchannel.cpp ircconnection.cpp \ 11 SOURCES = ircchannel.cpp ircconnection.cpp \
11 ircmessage.cpp \ 12 ircmessage.cpp \
12 ircmessageparser.cpp ircoutput.cpp \ 13 ircmessageparser.cpp ircoutput.cpp \
13 ircperson.cpp ircserver.cpp \ 14 ircperson.cpp ircserver.cpp \
14 ircsession.cpp main.cpp mainwindow.cpp \ 15 ircsession.cpp main.cpp mainwindow.cpp \
15 irctab.cpp ircservertab.cpp \ 16 irctab.cpp ircservertab.cpp \
16 ircchanneltab.cpp ircchannellist.cpp \ 17 ircchanneltab.cpp ircchannellist.cpp \
17 ircserverlist.cpp ircservereditor.cpp \ 18 ircserverlist.cpp ircservereditor.cpp \
18 ircquerytab.cpp ircsettings.cpp ircmisc.cpp 19 ircquerytab.cpp ircsettings.cpp ircmisc.cpp \
20 ircchannelperson.cpp
19INCLUDEPATH += $(OPIEDIR)/include 21INCLUDEPATH += $(OPIEDIR)/include
20DEPENDPATH += $(OPIEDIR)/include 22DEPENDPATH += $(OPIEDIR)/include
21 23
22PRECOMPILED_HEADER = stable.h 24PRECOMPILED_HEADER = stable.h
23 25
24LIBS += -lqpe -lopiecore2 -lopieui2 -lqtaux2 26LIBS += -lqpe -lopiecore2 -lopieui2 -lqtaux2
25TARGET = opieirc 27TARGET = opieirc
26 28
27 29
28include( $(OPIEDIR)/include.pro ) 30include( $(OPIEDIR)/include.pro )