summaryrefslogtreecommitdiff
authorskyhusker <skyhusker>2005-02-03 21:47:50 (UTC)
committer skyhusker <skyhusker>2005-02-03 21:47:50 (UTC)
commit8aaae9e3eca7853e9c693d2401f721d75209acf7 (patch) (unidiff)
tree6f700d154fac8510b322242496604d0ad7589377
parent875b3b63624308f4e50f82e17db27edeb9609d6c (diff)
downloadopie-8aaae9e3eca7853e9c693d2401f721d75209acf7.zip
opie-8aaae9e3eca7853e9c693d2401f721d75209acf7.tar.gz
opie-8aaae9e3eca7853e9c693d2401f721d75209acf7.tar.bz2
Added DCC receive support
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/opieirc/dccprogress.cpp75
-rw-r--r--noncore/net/opieirc/dccprogress.h35
-rw-r--r--noncore/net/opieirc/dcctransfer.cpp41
-rw-r--r--noncore/net/opieirc/dcctransfer.h44
-rw-r--r--noncore/net/opieirc/dcctransferrecv.cpp53
-rw-r--r--noncore/net/opieirc/dcctransferrecv.h21
-rw-r--r--noncore/net/opieirc/dcctransfertab.cpp81
-rw-r--r--noncore/net/opieirc/dcctransfertab.h41
-rw-r--r--noncore/net/opieirc/ircmessageparser.cpp30
-rw-r--r--noncore/net/opieirc/ircservertab.cpp4
-rw-r--r--noncore/net/opieirc/ircservertab.h1
-rw-r--r--noncore/net/opieirc/ircsession.cpp5
-rw-r--r--noncore/net/opieirc/ircsession.h4
-rw-r--r--noncore/net/opieirc/mainwindow.cpp20
-rw-r--r--noncore/net/opieirc/mainwindow.h8
-rw-r--r--noncore/net/opieirc/opieirc.pro9
16 files changed, 459 insertions, 13 deletions
diff --git a/noncore/net/opieirc/dccprogress.cpp b/noncore/net/opieirc/dccprogress.cpp
new file mode 100644
index 0000000..28277f7
--- a/dev/null
+++ b/noncore/net/opieirc/dccprogress.cpp
@@ -0,0 +1,75 @@
1#include <qprogressbar.h>
2#include <qlabel.h>
3#include <qvbox.h>
4
5#include "dcctransfer.h"
6#include "dcctransferrecv.h"
7#include "dccprogress.h"
8
9DCCProgress::DCCProgress(DCCTransfer::Type type, Q_UINT32 ip4Addr, Q_UINT16 port,
10 const QString &filename, const QString &nickname, unsigned int size, QWidget *parent, char *name, WFlags f)
11 : QWidget(parent, name, f), m_vbox(new QVBox(this)),
12 m_label(new QLabel(m_vbox)),
13 m_bar(new QProgressBar(m_vbox))
14{
15
16 if (DCCTransfer::Recv == type)
17 m_transfer = new DCCTransferRecv(ip4Addr, port, filename, size);
18
19
20 connect(m_transfer, SIGNAL(progress(int)), this, SLOT(slotSetProgress(int)));
21 connect(m_transfer, SIGNAL(finished(DCCTransfer *, DCCTransfer::EndCode)),
22 this, SLOT(slotFinished(DCCTransfer *, DCCTransfer::EndCode)));
23
24 m_label->setText(tr("Receiving file %1 from %2...").arg(m_transfer->filename()).arg(nickname));
25
26 m_label->show();
27 m_bar->show();
28 show();
29
30}
31
32bool DCCProgress::finished()
33{
34 return ( m_transfer == 0);
35}
36
37void DCCProgress::cancel()
38{
39 if (m_transfer)
40 m_transfer->cancel();
41}
42
43void DCCProgress::slotSetProgress(int progress)
44{
45 m_bar->setProgress(progress);
46}
47
48void DCCProgress::slotFinished(DCCTransfer *transfer, DCCTransfer::EndCode code)
49{
50 if(transfer != m_transfer)
51 // WTF!!
52 return;
53
54 QString msg;
55
56 switch(code) {
57 case DCCTransfer::Successfull:
58 msg = tr("Successfully received %1").arg(m_transfer->filename());
59 break;
60 case DCCTransfer::SelfAborted:
61 msg = tr("Aborted");
62 break;
63 case DCCTransfer::PeerAborted:
64 msg = tr("Peer Aborted");
65 break;
66 case DCCTransfer::Timeout:
67 msg = tr("Timeout");
68 break;
69 }
70
71 m_label->setText(msg);
72 delete m_transfer;
73 m_transfer = 0;
74}
75
diff --git a/noncore/net/opieirc/dccprogress.h b/noncore/net/opieirc/dccprogress.h
new file mode 100644
index 0000000..81b922e
--- a/dev/null
+++ b/noncore/net/opieirc/dccprogress.h
@@ -0,0 +1,35 @@
1#ifndef DCCPROGRESS_H
2#define DCCPROGRESS_H
3
4
5#include <qwidget.h>
6
7#include "dcctransfer.h"
8
9class QProgressBar;
10class QLabel;
11class QVBox;
12
13class DCCProgress: public QWidget {
14
15 Q_OBJECT
16public:
17 DCCProgress(DCCTransfer::Type type, Q_UINT32 ip4Addr, Q_UINT16 port,
18 const QString &filename, const QString &nickname, unsigned int size,
19 QWidget *parent = 0, char *name = 0, WFlags f = 0);
20
21 bool finished();
22 void cancel();
23
24public slots:
25 void slotSetProgress(int progress);
26 void slotFinished(DCCTransfer *transfer, DCCTransfer::EndCode code);
27
28private:
29 QVBox *m_vbox;
30 QLabel *m_label;
31 QProgressBar *m_bar;
32 DCCTransfer *m_transfer;
33};
34
35#endif
diff --git a/noncore/net/opieirc/dcctransfer.cpp b/noncore/net/opieirc/dcctransfer.cpp
new file mode 100644
index 0000000..cfa9f74
--- a/dev/null
+++ b/noncore/net/opieirc/dcctransfer.cpp
@@ -0,0 +1,41 @@
1#include <qsocket.h>
2#include <qfile.h>
3
4#include "dcctransfer.h"
5
6
7DCCTransfer::DCCTransfer(Q_UINT32 ip4Addr, Q_UINT16 port, const QString &filename, unsigned int size)
8 : m_socket(new QSocket), m_file(new QFile), m_bufSize(4096), m_buffer(new char[m_bufSize]),
9 m_ip4Addr(ip4Addr), m_port(port), m_totalSize(size), m_processedSize(0)
10{
11 m_file->setName(filename);
12}
13
14DCCTransfer::~DCCTransfer()
15{
16 if(m_socket)
17 delete m_socket;
18 if(m_file) {
19 m_file->close();
20 delete m_file;
21 }
22 if(m_buffer)
23 delete []m_buffer;
24}
25
26
27void DCCTransfer::cancel()
28{
29 if(m_socket)
30 m_socket->close();
31
32 emit(finished(DCCTransfer::SelfAborted));
33}
34
35QString DCCTransfer::filename()
36{
37 if(!m_file)
38 return QString::null;
39
40 return m_file->name().mid(m_file->name().findRev('/') + 1);
41}
diff --git a/noncore/net/opieirc/dcctransfer.h b/noncore/net/opieirc/dcctransfer.h
new file mode 100644
index 0000000..775ed24
--- a/dev/null
+++ b/noncore/net/opieirc/dcctransfer.h
@@ -0,0 +1,44 @@
1#ifndef DCCTRANSFER_H
2#define DCCTRANSFER_H
3
4#include <qobject.h>
5
6class QSocket;
7class QFile;
8class QString;
9
10class DCCTransfer: public QObject {
11 Q_OBJECT
12public:
13 enum Type { Send, Recv };
14 enum EndCode { Successfull, SelfAborted, PeerAborted, Timeout };
15
16 DCCTransfer(Q_UINT32 ip4Addr, Q_UINT16 port, const QString &filename, unsigned int size);
17 virtual ~DCCTransfer();
18
19 void cancel();
20
21 QString filename();
22
23signals:
24 virtual void finished(DCCTransfer *transfer, EndCode code);
25 virtual void progress(int progress);
26
27protected slots:
28 virtual void slotProcess() = 0;
29 virtual void slotFinished() = 0;
30
31protected:
32 QSocket *m_socket;
33 QFile *m_file;
34 unsigned int m_bufSize;
35 char *m_buffer;
36 Q_UINT32 m_ip4Addr;
37 Q_UINT16 m_port;
38 unsigned int m_totalSize;
39 unsigned int m_processedSize;
40 bool m_cancel;
41 bool m_timeout;
42};
43
44#endif
diff --git a/noncore/net/opieirc/dcctransferrecv.cpp b/noncore/net/opieirc/dcctransferrecv.cpp
new file mode 100644
index 0000000..58e8d09
--- a/dev/null
+++ b/noncore/net/opieirc/dcctransferrecv.cpp
@@ -0,0 +1,53 @@
1#include <netinet/in.h>
2
3#include <qfile.h>
4#include <qsocket.h>
5#include <qhostaddress.h>
6
7#include <opie2/odebug.h>
8
9
10#include "dcctransferrecv.h"
11
12
13DCCTransferRecv::DCCTransferRecv(Q_UINT32 ip4Addr, Q_UINT16 port, const QString &filename, unsigned int size)
14 : DCCTransfer(ip4Addr, port, filename, size)
15{
16 QHostAddress ip(ip4Addr);
17 m_socket->connectToHost(ip.toString(), m_port);
18 connect(m_socket, SIGNAL(readyRead()), this, SLOT(slotProcess()));
19 connect(m_socket, SIGNAL(connectionClosed()), this, SLOT(slotFinished()));
20
21 m_file->open(IO_WriteOnly);
22}
23
24
25void DCCTransferRecv::slotProcess()
26{
27 int availableBytes = m_socket->bytesAvailable();
28 int receivedBytes = 0;
29
30 while(receivedBytes < availableBytes) {
31 int bytes = m_socket->readBlock(m_buffer, m_bufSize);
32 receivedBytes += bytes;
33 m_file->writeBlock(m_buffer, bytes);
34 }
35
36 m_file->flush();
37 m_processedSize += availableBytes;
38 unsigned long value = htonl(m_processedSize);
39 m_socket->writeBlock((char*)&value, sizeof(unsigned long));
40
41 emit (progress((m_processedSize * 100) / m_totalSize));
42}
43
44void DCCTransferRecv::slotFinished()
45{
46 m_file->close();
47
48 if(m_processedSize == m_totalSize)
49 emit(finished(this, DCCTransfer::Successfull));
50 else
51 emit(finished(this, DCCTransfer::PeerAborted));
52}
53
diff --git a/noncore/net/opieirc/dcctransferrecv.h b/noncore/net/opieirc/dcctransferrecv.h
new file mode 100644
index 0000000..bfc55ef
--- a/dev/null
+++ b/noncore/net/opieirc/dcctransferrecv.h
@@ -0,0 +1,21 @@
1#ifndef DCCTRANSFERRECV_H
2#define DCCTRANSFERRECV_H
3
4#include "dcctransfer.h"
5
6
7class DCCTransferRecv: public DCCTransfer {
8 Q_OBJECT
9public:
10 DCCTransferRecv(Q_UINT32 ip4Addr, Q_UINT16 port, const QString &filename, unsigned int size);
11
12signals:
13 void finished(DCCTransfer *transfer, DCCTransfer::EndCode code);
14
15public slots:
16 void slotProcess();
17 void slotFinished();
18};
19
20#endif
21
diff --git a/noncore/net/opieirc/dcctransfertab.cpp b/noncore/net/opieirc/dcctransfertab.cpp
new file mode 100644
index 0000000..ea0ff1f
--- a/dev/null
+++ b/noncore/net/opieirc/dcctransfertab.cpp
@@ -0,0 +1,81 @@
1#include <qlist.h>
2#include <qlabel.h>
3#include <qstring.h>
4#include <qvbox.h>
5#include <qmessagebox.h>
6
7#include "dcctransfer.h"
8#include "dccprogress.h"
9#include "mainwindow.h"
10#include "dcctransfertab.h"
11
12#include <stdio.h>
13
14DCCTransferTab::DCCTransferTab(QWidget *parent, const char *name, WFlags f)
15 :IRCTab(parent, name, f), m_hbox(new QHBox(this)), m_parent(static_cast<MainWindow*>(parent))
16{
17 m_description->setText("");
18 m_layout->add(m_hbox);
19 m_hbox->show();
20}
21
22DCCTransferTab::~DCCTransferTab()
23{
24 if(m_hbox)
25 delete m_hbox;
26}
27
28QString DCCTransferTab::title()
29{
30 return "DCC";
31}
32
33void DCCTransferTab::remove()
34{
35 //Clean finished transfers
36 for(QListIterator <DCCProgress> it(m_progressList); it.current(); ++it) {
37 DCCProgress *current = it.current();
38 if (current->finished()) {
39 m_progressList.remove(current);
40 current->hide();
41 delete current;
42 }
43 }
44
45 if (m_progressList.count() > 0) {
46 int retval = QMessageBox::information( parentWidget() , tr("DCC Transfers in Progress"),
47 tr( "There are transfers in progress. <br>If you close this tab, they will be canceled."
48 "<br>Do you want to close it anyway?"),
49 tr("&Close"), tr("&Don't Close"));
50 if ( retval != 0 ) {
51 return;
52 }
53 //Cancel active transfers (user accepted)
54 for(QListIterator <DCCProgress> itr(m_progressList); itr.current(); ++itr) {
55 DCCProgress *current = itr.current();
56 m_progressList.remove(current);
57 current->hide();
58 current->cancel();
59 delete current;
60 }
61 }
62
63 //Remove
64 m_parent->killTab(this);
65}
66
67bool DCCTransferTab::confirm(QWidget *parent, const QString &nickname, const QString &filename, unsigned int size)
68{
69 int retval = QMessageBox::information(parent, tr("DCC Transfer from %1").arg(nickname),
70 tr( "%1 is trying to send you the file %2\n(%3 bytes)").arg(nickname).arg(filename).arg(size),
71 tr("&Accept"), tr("&Reject"));
72
73 return ( 0 == retval);
74
75}
76
77void DCCTransferTab::addTransfer(DCCTransfer::Type type, Q_UINT32 ip4Addr, Q_UINT16 port,
78 const QString &filename, const QString &nickname, unsigned int size)
79{
80 m_progressList.append(new DCCProgress(type, ip4Addr, port, filename, nickname, size, this));
81}
diff --git a/noncore/net/opieirc/dcctransfertab.h b/noncore/net/opieirc/dcctransfertab.h
new file mode 100644
index 0000000..a21323d
--- a/dev/null
+++ b/noncore/net/opieirc/dcctransfertab.h
@@ -0,0 +1,41 @@
1#ifndef DCCTRANSFERTAB_H
2#define DCCTRANSFERTAB_H
3
4#include "dcctransfer.h"
5#include "irctab.h"
6
7template <class T> class QList;
8
9class DCCProgress;
10class IRCSession;
11class QString;
12class QHBox;
13class MainWindow;
14
15class DCCTransferTab: public IRCTab {
16 Q_OBJECT
17public:
18
19 DCCTransferTab(QWidget *parent = 0, const char *name = 0, WFlags f = 0);
20 ~DCCTransferTab();
21 virtual QString DCCTransferTab::title();
22 virtual IRCSession* DCCTransferTab::session(){return 0;};
23 virtual void DCCTransferTab::appendText(QString){};
24 virtual void DCCTransferTab::remove();
25 virtual void DCCTransferTab::settingsChanged() {};
26 void addTransfer(DCCTransfer::Type type, Q_UINT32 ip4Addr,
27 Q_UINT16 port, const QString &filename,
28 const QString &nickname, unsigned int size);
29 static bool confirm(QWidget *parent = 0,
30 const QString &nickname = QString::null,
31 const QString &filename = QString::null,
32 unsigned int size = 0);
33private:
34 QHBox *m_hbox;
35 QList <DCCProgress> m_progressList;
36 MainWindow *m_parent;
37
38};
39
40#endif
41
diff --git a/noncore/net/opieirc/ircmessageparser.cpp b/noncore/net/opieirc/ircmessageparser.cpp
index ad9de2b..939cdae 100644
--- a/noncore/net/opieirc/ircmessageparser.cpp
+++ b/noncore/net/opieirc/ircmessageparser.cpp
@@ -1,649 +1,667 @@
1#include <qtextstream.h> 1#include <qtextstream.h>
2#include <qdatetime.h> 2#include <qdatetime.h>
3 3
4#include <opie2/ofiledialog.h>
5#include <opie2/ofileselector.h>
6#include <opie2/odebug.h>
7
4#include "ircmessageparser.h" 8#include "ircmessageparser.h"
5#include "ircversion.h" 9#include "ircversion.h"
6#include "ircchannelperson.h" 10#include "ircchannelperson.h"
7//#include "transferreceiver.h" 11#include "dcctransfertab.h"
12#include "ircservertab.h"
8 13
9/* Lookup table for literal commands */ 14/* Lookup table for literal commands */
10IRCLiteralMessageParserStruct IRCMessageParser::literalParserProcTable[] = { 15IRCLiteralMessageParserStruct IRCMessageParser::literalParserProcTable[] = {
11 { "PING", FUNC(parseLiteralPing) }, 16 { "PING", FUNC(parseLiteralPing) },
12 { "NOTICE", FUNC(parseLiteralNotice) }, 17 { "NOTICE", FUNC(parseLiteralNotice) },
13 { "JOIN", FUNC(parseLiteralJoin) }, 18 { "JOIN", FUNC(parseLiteralJoin) },
14 { "PRIVMSG", FUNC(parseLiteralPrivMsg) }, 19 { "PRIVMSG", FUNC(parseLiteralPrivMsg) },
15 { "NICK", FUNC(parseLiteralNick) }, 20 { "NICK", FUNC(parseLiteralNick) },
16 { "PART", FUNC(parseLiteralPart) }, 21 { "PART", FUNC(parseLiteralPart) },
17 { "QUIT", FUNC(parseLiteralQuit) }, 22 { "QUIT", FUNC(parseLiteralQuit) },
18 { "ERROR", FUNC(parseLiteralError) }, 23 { "ERROR", FUNC(parseLiteralError) },
19 { "ERROR:", FUNC(parseLiteralError) }, 24 { "ERROR:", FUNC(parseLiteralError) },
20 { "MODE", FUNC(parseLiteralMode) }, 25 { "MODE", FUNC(parseLiteralMode) },
21 { "KICK", FUNC(parseLiteralKick) }, 26 { "KICK", FUNC(parseLiteralKick) },
22 { "TOPIC", FUNC(parseLiteralTopic) }, 27 { "TOPIC", FUNC(parseLiteralTopic) },
23 { 0 , 0 } 28 { 0 , 0 }
24}; 29};
25 30
26/* Lookup table for literal commands */ 31/* Lookup table for literal commands */
27IRCCTCPMessageParserStruct IRCMessageParser::ctcpParserProcTable[] = { 32IRCCTCPMessageParserStruct IRCMessageParser::ctcpParserProcTable[] = {
28 { "PING", FUNC(parseCTCPPing) }, 33 { "PING", FUNC(parseCTCPPing) },
29 { "VERSION", FUNC(parseCTCPVersion) }, 34 { "VERSION", FUNC(parseCTCPVersion) },
30 { "ACTION", FUNC(parseCTCPAction) }, 35 { "ACTION", FUNC(parseCTCPAction) },
31 { "DCC", FUNC(parseCTCPDCC) }, 36 { "DCC", FUNC(parseCTCPDCC) },
32 { 0 , 0 } 37 { 0 , 0 }
33}; 38};
34 39
35/* Lookup table for numerical commands 40/* Lookup table for numerical commands
36 * According to: 41 * According to:
37 * http://www.faqs.org/rfcs/rfc1459.html 42 * http://www.faqs.org/rfcs/rfc1459.html
38 * http://www.faqs.org/rfcs/rfc2812.html 43 * http://www.faqs.org/rfcs/rfc2812.html
39*/ 44*/
40 45
41IRCNumericalMessageParserStruct IRCMessageParser::numericalParserProcTable[] = { 46IRCNumericalMessageParserStruct IRCMessageParser::numericalParserProcTable[] = {
42 { 1, "%1", "1", FUNC(parseNumericalServerName) }, // RPL_WELCOME 47 { 1, "%1", "1", FUNC(parseNumericalServerName) }, // RPL_WELCOME
43 { 2, "%1", "1", 0 }, // RPL_YOURHOST 48 { 2, "%1", "1", 0 }, // RPL_YOURHOST
44 { 3, "%1", "1", 0 }, // RPL_CREATED 49 { 3, "%1", "1", 0 }, // RPL_CREATED
45 { 4, QT_TR_NOOP("Server %1 version %2 supports usermodes '%3' and channelmodes '%4'"), "1:4", FUNC(parseNumericalServerFeatures) }, // RPL_MYINFO 50 { 4, QT_TR_NOOP("Server %1 version %2 supports usermodes '%3' and channelmodes '%4'"), "1:4", FUNC(parseNumericalServerFeatures) }, // RPL_MYINFO
46 { 5, 0, 0, FUNC(parseNumericalServerProtocol) }, // RPL_BOUNCE, RPL_PROTOCTL 51 { 5, 0, 0, FUNC(parseNumericalServerProtocol) }, // RPL_BOUNCE, RPL_PROTOCTL
47 { 250, "%1", "1", 0 }, // RPL_STATSCONN 52 { 250, "%1", "1", 0 }, // RPL_STATSCONN
48 { 251, "%1", "1", 0 }, // RPL_LUSERCLIENT 53 { 251, "%1", "1", 0 }, // RPL_LUSERCLIENT
49 { 252, QT_TR_NOOP("There are %1 operators connected"), "1", 0 }, // RPL_LUSEROP 54 { 252, QT_TR_NOOP("There are %1 operators connected"), "1", 0 }, // RPL_LUSEROP
50 { 253, QT_TR_NOOP("There are %1 unknown connection(s)"), "1", 0 }, // RPL_LUSERUNKNOWN 55 { 253, QT_TR_NOOP("There are %1 unknown connection(s)"), "1", 0 }, // RPL_LUSERUNKNOWN
51 { 254, QT_TR_NOOP("There are %1 channels formed"), "1", 0 }, // RPL_LUSERCHANNELS 56 { 254, QT_TR_NOOP("There are %1 channels formed"), "1", 0 }, // RPL_LUSERCHANNELS
52 { 255, "%1", "1", 0 }, // RPL_LUSERME 57 { 255, "%1", "1", 0 }, // RPL_LUSERME
53 { 263, QT_TR_NOOP("Please wait a while and try again"), 0, 0 }, // RPL_TRYAGAIN 58 { 263, QT_TR_NOOP("Please wait a while and try again"), 0, 0 }, // RPL_TRYAGAIN
54 { 265, "%1", "1", 0 }, // RPL_LOCALUSERS 59 { 265, "%1", "1", 0 }, // RPL_LOCALUSERS
55 { 266, "%1", "1", 0 }, // RPL_GLOBALUSERS 60 { 266, "%1", "1", 0 }, // RPL_GLOBALUSERS
56 { 311, QT_TR_NOOP("Whois %1 (%2@%3)\nReal name: %4"), "1:3,5", 0 }, // RPL_WHOISUSER 61 { 311, QT_TR_NOOP("Whois %1 (%2@%3)\nReal name: %4"), "1:3,5", 0 }, // RPL_WHOISUSER
57 { 312, QT_TR_NOOP("%1 is using server %2"), "1,2", 0 }, // RPL_WHOISSERVER 62 { 312, QT_TR_NOOP("%1 is using server %2"), "1,2", 0 }, // RPL_WHOISSERVER
58 { 317, 0, 0, FUNC(parseNumericalWhoisIdle) }, // RPL_WHOISIDLE 63 { 317, 0, 0, FUNC(parseNumericalWhoisIdle) }, // RPL_WHOISIDLE
59 { 318, "%1 :%2", "1,2", 0 }, // RPL_ENDOFWHOIS 64 { 318, "%1 :%2", "1,2", 0 }, // RPL_ENDOFWHOIS
60 { 319, QT_TR_NOOP("%1 is on channels: %2"), "1,2", 0 }, // RPL_WHOISCHANNELS 65 { 319, QT_TR_NOOP("%1 is on channels: %2"), "1,2", 0 }, // RPL_WHOISCHANNELS
61 { 320, "%1 %2", "1,2", 0}, // RPL_WHOISVIRT 66 { 320, "%1 %2", "1,2", 0}, // RPL_WHOISVIRT
62 { 332, 0, 0, FUNC(parseNumericalTopic) }, // RPL_TOPIC 67 { 332, 0, 0, FUNC(parseNumericalTopic) }, // RPL_TOPIC
63 { 333, 0, 0, FUNC(parseNumericalTopicWhoTime) }, // RPL_TOPICWHOTIME*/ 68 { 333, 0, 0, FUNC(parseNumericalTopicWhoTime) }, // RPL_TOPICWHOTIME*/
64 { 353, QT_TR_NOOP("Names for %1: %2"), "2,3", FUNC(parseNumericalNames) }, // RPL_NAMREPLY 69 { 353, QT_TR_NOOP("Names for %1: %2"), "2,3", FUNC(parseNumericalNames) }, // RPL_NAMREPLY
65 { 366, "%1 :%2", "1,2", FUNC(parseNumericalEndOfNames) }, // RPL_ENDOFNAMES 70 { 366, "%1 :%2", "1,2", FUNC(parseNumericalEndOfNames) }, // RPL_ENDOFNAMES
66 { 369, "%1 :%2", "1,2", 0 }, // RPL_ENDOFWHOWAS 71 { 369, "%1 :%2", "1,2", 0 }, // RPL_ENDOFWHOWAS
67 { 372, "%1", "1", 0 }, // RPL_MOTD 72 { 372, "%1", "1", 0 }, // RPL_MOTD
68 { 375, "%1", "1", 0 }, // RPL_MOTDSTART 73 { 375, "%1", "1", 0 }, // RPL_MOTDSTART
69 { 376, "%1", "1", 0 }, // RPL_ENDOFMOTD 74 { 376, "%1", "1", 0 }, // RPL_ENDOFMOTD
70 { 377, "%1", "1", 0 }, // RPL_MOTD2 75 { 377, "%1", "1", 0 }, // RPL_MOTD2
71 { 378, "%1", "1", 0 }, // RPL_MOTD3 76 { 378, "%1", "1", 0 }, // RPL_MOTD3
72 { 391, QT_TR_NOOP("Time on server %1 is %2"), "1,2", 0 }, // RPL_TIME 77 { 391, QT_TR_NOOP("Time on server %1 is %2"), "1,2", 0 }, // RPL_TIME
73 { 401, QT_TR_NOOP("Channel or nick %1 doesn't exists"), "1", 0 }, // ERR_NOSUCHNICK 78 { 401, QT_TR_NOOP("Channel or nick %1 doesn't exists"), "1", 0 }, // ERR_NOSUCHNICK
74 { 406, QT_TR_NOOP("There is no history information for %1"), "1", 0 }, // ERR_WASNOSUCHNICK 79 { 406, QT_TR_NOOP("There is no history information for %1"), "1", 0 }, // ERR_WASNOSUCHNICK
75 { 409, "%1", "1", 0 }, // ERR_NOORIGIN 80 { 409, "%1", "1", 0 }, // ERR_NOORIGIN
76 { 411, "%1", "1", 0 }, // ERR_NORECIPIENT 81 { 411, "%1", "1", 0 }, // ERR_NORECIPIENT
77 { 412, "%1", "1", 0 }, // ERR_NOTEXTTOSEND 82 { 412, "%1", "1", 0 }, // ERR_NOTEXTTOSEND
78 { 421, QT_TR_NOOP("Unknown command: %1"), "1", 0 }, // ERR_ERR_UNKNOWNCOMMAND 83 { 421, QT_TR_NOOP("Unknown command: %1"), "1", 0 }, // ERR_ERR_UNKNOWNCOMMAND
79 { 422, "%1", "1", 0 }, // ERR_NOMOTD 84 { 422, "%1", "1", 0 }, // ERR_NOMOTD
80 { 433, QT_TR_NOOP("Can't change nick to %1: %2"), "1,2", FUNC(parseNumericalNicknameInUse) }, // ERR_NICKNAMEINUSE 85 { 433, QT_TR_NOOP("Can't change nick to %1: %2"), "1,2", FUNC(parseNumericalNicknameInUse) }, // ERR_NICKNAMEINUSE
81 { 442, QT_TR_NOOP("You're not on channel %1"), "1", 0}, // ERR_NOTONCHANNEL 86 { 442, QT_TR_NOOP("You're not on channel %1"), "1", 0}, // ERR_NOTONCHANNEL
82 { 477, "%1", "1", 0 }, // ERR_NOCHANMODES || ERR_NEEDREGGEDNICK 87 { 477, "%1", "1", 0 }, // ERR_NOCHANMODES || ERR_NEEDREGGEDNICK
83 { 482, QT_TR_NOOP("[%1] Operation not permitted, you don't have enough channel privileges"), "1", 0 }, //ERR_CHANOPRIVSNEEDED 88 { 482, QT_TR_NOOP("[%1] Operation not permitted, you don't have enough channel privileges"), "1", 0 }, //ERR_CHANOPRIVSNEEDED
84 { 0, 0, 0, 0 } 89 { 0, 0, 0, 0 }
85}; 90};
86 91
87 92
88IRCMessageParser::IRCMessageParser(IRCSession *session) { 93IRCMessageParser::IRCMessageParser(IRCSession *session) {
89 m_session = session; 94 m_session = session;
90} 95}
91 96
92void IRCMessageParser::parse(IRCMessage *message) { 97void IRCMessageParser::parse(IRCMessage *message) {
93 /* Find out what kind of message we have here and call the appropriate handler using 98 /* Find out what kind of message we have here and call the appropriate handler using
94 the parser tables. If no handler can be found, print out an error message */ 99 the parser tables. If no handler can be found, print out an error message */
95 if (message->isNumerical()) { 100 if (message->isNumerical()) {
96 for (int i=0; i<numericalParserProcTable[i].commandNumber; i++) { 101 for (int i=0; i<numericalParserProcTable[i].commandNumber; i++) {
97 if (message->commandNumber() == numericalParserProcTable[i].commandNumber) { 102 if (message->commandNumber() == numericalParserProcTable[i].commandNumber) {
98 parseNumerical(message, i); 103 parseNumerical(message, i);
99 return; 104 return;
100 } 105 }
101 } 106 }
102 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received unhandled numeric command: %1").arg( QString::number(message->commandNumber()) ))); 107 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received unhandled numeric command: %1").arg( QString::number(message->commandNumber()) )));
103 } else if (message->isCTCP()) { 108 } else if (message->isCTCP()) {
104 for (int i=0; ctcpParserProcTable[i].commandName; i++) { 109 for (int i=0; ctcpParserProcTable[i].commandName; i++) {
105 if (message->ctcpCommand() == ctcpParserProcTable[i].commandName) { 110 if (message->ctcpCommand() == ctcpParserProcTable[i].commandName) {
106 parseCTCP(message, i); 111 parseCTCP(message, i);
107 return; 112 return;
108 } 113 }
109 } 114 }
110 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received unhandled ctcp command: %1").arg( message->ctcpCommand())) ); 115 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received unhandled ctcp command: %1").arg( message->ctcpCommand())) );
111 } else { 116 } else {
112 for (int i=0; literalParserProcTable[i].commandName; i++) { 117 for (int i=0; literalParserProcTable[i].commandName; i++) {
113 if (message->command() == literalParserProcTable[i].commandName) { 118 if (message->command() == literalParserProcTable[i].commandName) {
114 (this->*(literalParserProcTable[i].proc))(message); 119 (this->*(literalParserProcTable[i].proc))(message);
115 return; 120 return;
116 } 121 }
117 } 122 }
118 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received unhandled literal command: %1").arg( message->command()) )); 123 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received unhandled literal command: %1").arg( message->command()) ));
119 } 124 }
120} 125}
121 126
122void IRCMessageParser::parseNumerical(IRCMessage *message, int position) { 127void IRCMessageParser::parseNumerical(IRCMessage *message, int position) {
123 QString out = tr(numericalParserProcTable[position].message); 128 QString out = tr(numericalParserProcTable[position].message);
124 QString paramString = numericalParserProcTable[position].params; 129 QString paramString = numericalParserProcTable[position].params;
125 130
126 if(!out.isEmpty() && !paramString.isEmpty()) { 131 if(!out.isEmpty() && !paramString.isEmpty()) {
127 QStringList params = message->params(numericalParserProcTable[position].params); 132 QStringList params = message->params(numericalParserProcTable[position].params);
128 133
129 QStringList::Iterator end = params.end(); 134 QStringList::Iterator end = params.end();
130 for (QStringList::Iterator it = params.begin(); it != end; ++it) { 135 for (QStringList::Iterator it = params.begin(); it != end; ++it) {
131 out = out.arg(*it); 136 out = out.arg(*it);
132 } 137 }
133 138
134 emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, out)); 139 emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, out));
135 } 140 }
136 141
137 if(numericalParserProcTable[position].proc) 142 if(numericalParserProcTable[position].proc)
138 (this->*(numericalParserProcTable[position].proc))(message); 143 (this->*(numericalParserProcTable[position].proc))(message);
139} 144}
140 145
141void IRCMessageParser::parseCTCP(IRCMessage *message, int position) { 146void IRCMessageParser::parseCTCP(IRCMessage *message, int position) {
142 if(ctcpParserProcTable[position].proc) 147 if(ctcpParserProcTable[position].proc)
143 (this->*(ctcpParserProcTable[position].proc))(message); 148 (this->*(ctcpParserProcTable[position].proc))(message);
144} 149}
145 150
146 151
147 152
148void IRCMessageParser::parseNumericalServerName(IRCMessage *message) { 153void IRCMessageParser::parseNumericalServerName(IRCMessage *message) {
149 emit outputReady(IRCOutput(OUTPUT_TITLE, tr("Connected to")+" <b>" + message->prefix() + "</b>")); 154 emit outputReady(IRCOutput(OUTPUT_TITLE, tr("Connected to")+" <b>" + message->prefix() + "</b>"));
150 /* Register EFFECTIVE nickname, some networks (as irc-hispano) use nick:password 155 /* Register EFFECTIVE nickname, some networks (as irc-hispano) use nick:password
151 * for authentication and the parser gets confused */ 156 * for authentication and the parser gets confused */
152 m_session->m_server->setNick(message->param(0)); 157 m_session->m_server->setNick(message->param(0));
153 158
154} 159}
155 160
156void IRCMessageParser::parseNumericalServerFeatures(IRCMessage *message) { 161void IRCMessageParser::parseNumericalServerFeatures(IRCMessage *message) {
157 m_session->setValidUsermodes(message->param(2)); 162 m_session->setValidUsermodes(message->param(2));
158 m_session->setValidChannelmodes(message->param(3)); 163 m_session->setValidChannelmodes(message->param(3));
159 164
160} 165}
161 166
162void IRCMessageParser::parseNumericalServerProtocol(IRCMessage *message) { 167void IRCMessageParser::parseNumericalServerProtocol(IRCMessage *message) {
163 /* XXX: Add some usefull features here */ 168 /* XXX: Add some usefull features here */
164 QString out = message->allParameters(); 169 QString out = message->allParameters();
165 out = out.mid(out.find(' ')+1); 170 out = out.mid(out.find(' ')+1);
166 emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, out)); 171 emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, out));
167} 172}
168void IRCMessageParser::parseNumericalWhoisIdle(IRCMessage *message) { 173void IRCMessageParser::parseNumericalWhoisIdle(IRCMessage *message) {
169 QDateTime dt; 174 QDateTime dt;
170 QTime t; 175 QTime t;
171 t = t.addSecs(message->param(2).toInt()); 176 t = t.addSecs(message->param(2).toInt());
172 dt.setTime_t(message->param(3).toInt()); 177 dt.setTime_t(message->param(3).toInt());
173 178
174 emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, tr("%1 has been idle for %2").arg(message->param(1)).arg(t.toString()))); 179 emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, tr("%1 has been idle for %2").arg(message->param(1)).arg(t.toString())));
175 emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, tr("%1 signed on %2").arg(message->param(1)).arg(dt.toString()))); 180 emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, tr("%1 signed on %2").arg(message->param(1)).arg(dt.toString())));
176 181
177} 182}
178 183
179void IRCMessageParser::parseLiteralPing(IRCMessage *message) { 184void IRCMessageParser::parseLiteralPing(IRCMessage *message) {
180 m_session->m_connection->sendLine("PONG " + message->allParameters()); 185 m_session->m_connection->sendLine("PONG " + message->allParameters());
181} 186}
182 187
183void IRCMessageParser::parseLiteralNotice(IRCMessage *message) { 188void IRCMessageParser::parseLiteralNotice(IRCMessage *message) {
184 emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, message->allParameters())); 189 emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, message->allParameters()));
185} 190}
186 191
187void IRCMessageParser::parseLiteralJoin(IRCMessage *message) { 192void IRCMessageParser::parseLiteralJoin(IRCMessage *message) {
188 QString channelName = message->param(0).lower(); 193 QString channelName = message->param(0).lower();
189 IRCPerson mask(message->prefix()); 194 IRCPerson mask(message->prefix());
190 IRCChannel *channel = m_session->getChannel(channelName); 195 IRCChannel *channel = m_session->getChannel(channelName);
191 if (!channel) { 196 if (!channel) {
192 /* We joined */ 197 /* We joined */
193 if (mask.nick() == m_session->m_server->nick()) { 198 if (mask.nick() == m_session->m_server->nick()) {
194 channel = new IRCChannel(channelName); 199 channel = new IRCChannel(channelName);
195 m_session->addChannel(channel); 200 m_session->addChannel(channel);
196 } else { 201 } else {
197 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Nonexistant channel join - desynchronized?"))); 202 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Nonexistant channel join - desynchronized?")));
198 } 203 }
199 } else { 204 } else {
200 /* Someone else joined */ 205 /* Someone else joined */
201 if (mask.nick() != m_session->m_server->nick()) { 206 if (mask.nick() != m_session->m_server->nick()) {
202 if (!channel->getPerson(mask.nick())) { 207 if (!channel->getPerson(mask.nick())) {
203 IRCPerson *person = m_session->getPerson(mask.nick()); 208 IRCPerson *person = m_session->getPerson(mask.nick());
204 if (!person) { 209 if (!person) {
205 person = new IRCPerson(message->prefix()); 210 person = new IRCPerson(message->prefix());
206 m_session->addPerson(person); 211 m_session->addPerson(person);
207 } 212 }
208 IRCChannelPerson *chanperson = new IRCChannelPerson(person); 213 IRCChannelPerson *chanperson = new IRCChannelPerson(person);
209 channel->addPerson(chanperson); 214 channel->addPerson(chanperson);
210 IRCOutput output(OUTPUT_OTHERJOIN ,tr("%1 joined channel %2").arg( mask.nick() ).arg( channelName )); 215 IRCOutput output(OUTPUT_OTHERJOIN ,tr("%1 joined channel %2").arg( mask.nick() ).arg( channelName ));
211 output.addParam(channel); 216 output.addParam(channel);
212 output.addParam(chanperson); 217 output.addParam(chanperson);
213 emit outputReady(output); 218 emit outputReady(output);
214 } else { 219 } else {
215 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Person has already joined the channel - desynchronized?"))); 220 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Person has already joined the channel - desynchronized?")));
216 } 221 }
217 } else { 222 } else {
218 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("You already joined the channel - desynchronized?"))); 223 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("You already joined the channel - desynchronized?")));
219 } 224 }
220 } 225 }
221} 226}
222 227
223void IRCMessageParser::parseLiteralPart(IRCMessage *message) { 228void IRCMessageParser::parseLiteralPart(IRCMessage *message) {
224 QString channelName = message->param(0).lower(); 229 QString channelName = message->param(0).lower();
225 IRCChannel *channel = m_session->getChannel(channelName); 230 IRCChannel *channel = m_session->getChannel(channelName);
226 IRCPerson mask(message->prefix()); 231 IRCPerson mask(message->prefix());
227 if (channel) { 232 if (channel) {
228 if (mask.nick() == m_session->m_server->nick()) { 233 if (mask.nick() == m_session->m_server->nick()) {
229 m_session->removeChannel(channel); 234 m_session->removeChannel(channel);
230 IRCOutput output(OUTPUT_SELFPART, tr("You left channel %1").arg( channelName )); 235 IRCOutput output(OUTPUT_SELFPART, tr("You left channel %1").arg( channelName ));
231 output.addParam(channel); 236 output.addParam(channel);
232 emit outputReady(output); 237 emit outputReady(output);
233 delete channel; 238 delete channel;
234 } else { 239 } else {
235 IRCChannelPerson *person = channel->getPerson(mask.nick()); 240 IRCChannelPerson *person = channel->getPerson(mask.nick());
236 if (person) { 241 if (person) {
237 channel->removePerson(person); 242 channel->removePerson(person);
238 IRCOutput output(OUTPUT_OTHERPART, tr("%1 left channel %2").arg( mask.nick() ).arg( channelName) ); 243 IRCOutput output(OUTPUT_OTHERPART, tr("%1 left channel %2").arg( mask.nick() ).arg( channelName) );
239 output.addParam(channel); 244 output.addParam(channel);
240 output.addParam(person); 245 output.addParam(person);
241 emit outputReady(output); 246 emit outputReady(output);
242 delete person; 247 delete person;
243 } else { 248 } else {
244 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Parting person not found - desynchronized?"))); 249 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Parting person not found - desynchronized?")));
245 } 250 }
246 } 251 }
247 } else { 252 } else {
248 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Channel for part not found - desynchronized?"))); 253 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Channel for part not found - desynchronized?")));
249 } 254 }
250} 255}
251 256
252void IRCMessageParser::parseLiteralPrivMsg(IRCMessage *message) { 257void IRCMessageParser::parseLiteralPrivMsg(IRCMessage *message) {
253 if (m_session->m_server->nick().lower() == message->param(0).lower() ) { 258 if (m_session->m_server->nick().lower() == message->param(0).lower() ) {
254 /* IRC Query message detected, verify sender and display it */ 259 /* IRC Query message detected, verify sender and display it */
255 IRCPerson mask(message->prefix()); 260 IRCPerson mask(message->prefix());
256 IRCPerson *person = m_session->getPerson(mask.nick()); 261 IRCPerson *person = m_session->getPerson(mask.nick());
257 if (!person) { 262 if (!person) {
258 /* Person not yet known, create and add to the current session */ 263 /* Person not yet known, create and add to the current session */
259 person = new IRCPerson(message->prefix()); 264 person = new IRCPerson(message->prefix());
260 m_session->addPerson(person); 265 m_session->addPerson(person);
261 } 266 }
262 IRCOutput output(OUTPUT_QUERYPRIVMSG, message->param(1)); 267 IRCOutput output(OUTPUT_QUERYPRIVMSG, message->param(1));
263 output.addParam(person); 268 output.addParam(person);
264 emit outputReady(output); 269 emit outputReady(output);
265 } 270 }
266 else 271 else
267 if (message->param(0).at(0) == '#' || message->param(0).at(0) == '+') { 272 if (message->param(0).at(0) == '#' || message->param(0).at(0) == '+') {
268 /* IRC Channel message detected, verify sender, channel and display it */ 273 /* IRC Channel message detected, verify sender, channel and display it */
269 IRCChannel *channel = m_session->getChannel(message->param(0).lower()); 274 IRCChannel *channel = m_session->getChannel(message->param(0).lower());
270 if (channel) { 275 if (channel) {
271 IRCPerson mask(message->prefix()); 276 IRCPerson mask(message->prefix());
272 IRCChannelPerson *person = channel->getPerson(mask.nick()); 277 IRCChannelPerson *person = channel->getPerson(mask.nick());
273 if (person) { 278 if (person) {
274 IRCOutput output(OUTPUT_CHANPRIVMSG, message->param(1)); 279 IRCOutput output(OUTPUT_CHANPRIVMSG, message->param(1));
275 output.addParam(channel); 280 output.addParam(channel);
276 output.addParam(person); 281 output.addParam(person);
277 emit outputReady(output); 282 emit outputReady(output);
278 } 283 }
279 else { 284 else {
280 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Channel message with unknown sender"))); 285 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Channel message with unknown sender")));
281 } 286 }
282 } 287 }
283 else { 288 else {
284 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Channel message with unknown channel %1").arg(message->param(0).lower()) )); 289 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Channel message with unknown channel %1").arg(message->param(0).lower()) ));
285 } 290 }
286 } 291 }
287 else {emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received PRIVMSG of unknown type"))); 292 else {emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received PRIVMSG of unknown type")));
288 } 293 }
289} 294}
290 295
291void IRCMessageParser::parseLiteralNick(IRCMessage *message) { 296void IRCMessageParser::parseLiteralNick(IRCMessage *message) {
292 IRCPerson mask(message->prefix()); 297 IRCPerson mask(message->prefix());
293 m_session->updateNickname(mask.nick(), message->param(0)); 298 m_session->updateNickname(mask.nick(), message->param(0));
294 /* this way of handling nick changes really sucks 299 /* this way of handling nick changes really sucks
295 if (mask.nick() == m_session->m_server->nick()) { 300 if (mask.nick() == m_session->m_server->nick()) {
296 We are changing our nickname 301 We are changing our nickname
297 m_session->m_server->setNick(message->param(0)); 302 m_session->m_server->setNick(message->param(0));
298 IRCOutput output(OUTPUT_NICKCHANGE, tr("You are now known as %1").arg( message->param(0))); 303 IRCOutput output(OUTPUT_NICKCHANGE, tr("You are now known as %1").arg( message->param(0)));
299 output.addParam(0); 304 output.addParam(0);
300 emit outputReady(output); 305 emit outputReady(output);
301 } else { 306 } else {
302 Someone else is 307 Someone else is
303 RCPerson *person = m_session->getPerson(mask.nick()); 308 RCPerson *person = m_session->getPerson(mask.nick());
304 if (person) { 309 if (person) {
305 //IRCOutput output(OUTPUT_NICKCHANGE, tr("%1 is now known as %2").arg( mask.nick() ).arg( message->param(0))); 310 //IRCOutput output(OUTPUT_NICKCHANGE, tr("%1 is now known as %2").arg( mask.nick() ).arg( message->param(0)));
306 311
307 new code starts here -- this removes the person from all channels 312 new code starts here -- this removes the person from all channels
308 QList<IRCChannel> channels; 313 QList<IRCChannel> channels;
309 m_session->getChannelsByPerson(person, channels); 314 m_session->getChannelsByPerson(person, channels);
310 QListIterator<IRCChannel> it(channels); 315 QListIterator<IRCChannel> it(channels);
311 for (;it.current(); ++it) { 316 for (;it.current(); ++it) {
312 IRCChannelPerson *chanperson = it.current()->getPerson(mask.nick()); 317 IRCChannelPerson *chanperson = it.current()->getPerson(mask.nick());
313 it.current()->removePerson(chanperson); 318 it.current()->removePerson(chanperson);
314 chanperson->person->setNick(message->param(0)); 319 chanperson->person->setNick(message->param(0));
315 it.current()->addPerson(chanperson); 320 it.current()->addPerson(chanperson);
316 IRCOutput output(OUTPUT_NICKCHANGE, tr("%1 is now known as %2").arg( mask.nick() ).arg( message->param(0))); 321 IRCOutput output(OUTPUT_NICKCHANGE, tr("%1 is now known as %2").arg( mask.nick() ).arg( message->param(0)));
317 output.addParam(person); 322 output.addParam(person);
318 emit outputReady(output); 323 emit outputReady(output);
319 } 324 }
320 new code ends here 325 new code ends here
321 } else { 326 } else {
322 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Nickname change of an unknown person"))); 327 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Nickname change of an unknown person")));
323 } 328 }
324 }*/ 329 }*/
325} 330}
326 331
327void IRCMessageParser::parseLiteralQuit(IRCMessage *message) { 332void IRCMessageParser::parseLiteralQuit(IRCMessage *message) {
328 IRCPerson mask(message->prefix()); 333 IRCPerson mask(message->prefix());
329 IRCPerson *person = m_session->getPerson(mask.nick()); 334 IRCPerson *person = m_session->getPerson(mask.nick());
330 if (person) { 335 if (person) {
331 QList<IRCChannel> channels; 336 QList<IRCChannel> channels;
332 m_session->getChannelsByPerson(person, channels); 337 m_session->getChannelsByPerson(person, channels);
333 QListIterator<IRCChannel> it(channels); 338 QListIterator<IRCChannel> it(channels);
334 for (;it.current(); ++it) { 339 for (;it.current(); ++it) {
335 IRCChannelPerson *chanperson = it.current()->getPerson(mask.nick()); 340 IRCChannelPerson *chanperson = it.current()->getPerson(mask.nick());
336 it.current()->removePerson(chanperson); 341 it.current()->removePerson(chanperson);
337 delete chanperson; 342 delete chanperson;
338 } 343 }
339 m_session->removePerson(person); 344 m_session->removePerson(person);
340 IRCOutput output(OUTPUT_QUIT, tr("%1 has quit (%2)" ).arg( mask.nick() ).arg( message->param(0) )); 345 IRCOutput output(OUTPUT_QUIT, tr("%1 has quit (%2)" ).arg( mask.nick() ).arg( message->param(0) ));
341 output.addParam(person); 346 output.addParam(person);
342 emit outputReady(output); 347 emit outputReady(output);
343 delete person; 348 delete person;
344 } else { 349 } else {
345 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown person quit - desynchronized?"))); 350 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown person quit - desynchronized?")));
346 } 351 }
347} 352}
348 353
349void IRCMessageParser::parseLiteralTopic(IRCMessage *message) { 354void IRCMessageParser::parseLiteralTopic(IRCMessage *message) {
350 IRCPerson mask(message->prefix()); 355 IRCPerson mask(message->prefix());
351 IRCChannel *channel = m_session->getChannel(message->param(0).lower()); 356 IRCChannel *channel = m_session->getChannel(message->param(0).lower());
352 if (channel) { 357 if (channel) {
353 IRCOutput output(OUTPUT_TOPIC, mask.nick() + tr(" changed topic to ") + "\"" + message->param(1) + "\""); 358 IRCOutput output(OUTPUT_TOPIC, mask.nick() + tr(" changed topic to ") + "\"" + message->param(1) + "\"");
354 output.addParam(channel); 359 output.addParam(channel);
355 emit outputReady(output); 360 emit outputReady(output);
356 } else { 361 } else {
357 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown channel topic - desynchronized?"))); 362 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown channel topic - desynchronized?")));
358 } 363 }
359} 364}
360 365
361void IRCMessageParser::parseLiteralError(IRCMessage *message) { 366void IRCMessageParser::parseLiteralError(IRCMessage *message) {
362 emit outputReady(IRCOutput(OUTPUT_ERROR, message->allParameters())); 367 emit outputReady(IRCOutput(OUTPUT_ERROR, message->allParameters()));
363} 368}
364 369
365void IRCMessageParser::parseCTCPPing(IRCMessage *message) { 370void IRCMessageParser::parseCTCPPing(IRCMessage *message) {
366 IRCPerson mask(message->prefix()); 371 IRCPerson mask(message->prefix());
367 if(message->isCTCPReply()) { 372 if(message->isCTCPReply()) {
368 unsigned int sentTime = message->param(0).toUInt(); 373 unsigned int sentTime = message->param(0).toUInt();
369 QDateTime tm; 374 QDateTime tm;
370 tm.setTime_t(0); 375 tm.setTime_t(0);
371 unsigned int receivedTime = tm.secsTo(QDateTime::currentDateTime()); 376 unsigned int receivedTime = tm.secsTo(QDateTime::currentDateTime());
372 emit outputReady(IRCOutput(OUTPUT_CTCP, tr("Received a CTCP PING reply from %1: %2 seconds").arg(mask.nick()).arg(receivedTime-sentTime))); 377 emit outputReady(IRCOutput(OUTPUT_CTCP, tr("Received a CTCP PING reply from %1: %2 seconds").arg(mask.nick()).arg(receivedTime-sentTime)));
373 return; 378 return;
374 } 379 }
375 m_session->m_connection->sendCTCPReply(mask.nick(), "PING", message->allParameters()); 380 m_session->m_connection->sendCTCPReply(mask.nick(), "PING", message->allParameters());
376 emit outputReady(IRCOutput(OUTPUT_CTCP, tr("Received a CTCP PING request from %1").arg(mask.nick()))); 381 emit outputReady(IRCOutput(OUTPUT_CTCP, tr("Received a CTCP PING request from %1").arg(mask.nick())));
377 382
378 //IRCPerson mask(message->prefix()); 383 //IRCPerson mask(message->prefix());
379 QString dest = message->ctcpDestination(); 384 QString dest = message->ctcpDestination();
380 if (dest.startsWith("#")) { 385 if (dest.startsWith("#")) {
381 IRCChannel *channel = m_session->getChannel(dest.lower()); 386 IRCChannel *channel = m_session->getChannel(dest.lower());
382 if (channel) { 387 if (channel) {
383 IRCChannelPerson *person = channel->getPerson(mask.nick()); 388 IRCChannelPerson *person = channel->getPerson(mask.nick());
384 if (person) { 389 if (person) {
385 IRCOutput output(OUTPUT_CHANACTION, tr("Received a CTCP PING from ")+ mask.nick()) ; 390 IRCOutput output(OUTPUT_CHANACTION, tr("Received a CTCP PING from ")+ mask.nick()) ;
386 output.addParam(channel); 391 output.addParam(channel);
387 output.addParam(person); 392 output.addParam(person);
388 emit outputReady(output); 393 emit outputReady(output);
389 } else { 394 } else {
390 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP PING with unknown person - Desynchronized?"))); 395 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP PING with unknown person - Desynchronized?")));
391 } 396 }
392 } else { 397 } else {
393 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP PING with unknown channel - Desynchronized?"))); 398 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP PING with unknown channel - Desynchronized?")));
394 } 399 }
395 } else { 400 } else {
396 if (message->ctcpDestination() == m_session->m_server->nick()) { 401 if (message->ctcpDestination() == m_session->m_server->nick()) {
397 IRCPerson *person = m_session->getPerson(mask.nick()); 402 IRCPerson *person = m_session->getPerson(mask.nick());
398 if (!person) { 403 if (!person) {
399 /* Person not yet known, create and add to the current session */ 404 /* Person not yet known, create and add to the current session */
400 person = new IRCPerson(message->prefix()); 405 person = new IRCPerson(message->prefix());
401 m_session->addPerson(person); 406 m_session->addPerson(person);
402 } 407 }
403 IRCOutput output(OUTPUT_QUERYACTION, tr("Received a CTCP PING from ")+ mask.nick() ); 408 IRCOutput output(OUTPUT_QUERYACTION, tr("Received a CTCP PING from ")+ mask.nick() );
404 output.addParam(person); 409 output.addParam(person);
405 emit outputReady(output); 410 emit outputReady(output);
406 } else { 411 } else {
407 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP PING with bad recipient"))); 412 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP PING with bad recipient")));
408 } 413 }
409 } 414 }
410 415
411} 416}
412 417
413void IRCMessageParser::parseCTCPVersion(IRCMessage *message) { 418void IRCMessageParser::parseCTCPVersion(IRCMessage *message) {
414 IRCPerson mask(message->prefix()); 419 IRCPerson mask(message->prefix());
415 IRCOutput output(OUTPUT_CTCP); 420 IRCOutput output(OUTPUT_CTCP);
416 if(message->isCTCPRequest()) { 421 if(message->isCTCPRequest()) {
417 m_session->m_connection->sendCTCPReply(mask.nick(), "VERSION", APP_VERSION " " APP_COPYSTR); 422 m_session->m_connection->sendCTCPReply(mask.nick(), "VERSION", APP_VERSION " " APP_COPYSTR);
418 output.setMessage(tr("Received a CTCP VERSION request from ") + mask.nick()); 423 output.setMessage(tr("Received a CTCP VERSION request from ") + mask.nick());
419 } 424 }
420 425
421 else { 426 else {
422 output.setMessage("Received CTCP VERSION reply from " + mask.nick() + ":" + message->param(0)); 427 output.setMessage("Received CTCP VERSION reply from " + mask.nick() + ":" + message->param(0));
423 } 428 }
424 emit outputReady(output); 429 emit outputReady(output);
425} 430}
426 431
427void IRCMessageParser::parseCTCPAction(IRCMessage *message) { 432void IRCMessageParser::parseCTCPAction(IRCMessage *message) {
428 IRCPerson mask(message->prefix()); 433 IRCPerson mask(message->prefix());
429 QString dest = message->ctcpDestination(); 434 QString dest = message->ctcpDestination();
430 if (dest.startsWith("#")) { 435 if (dest.startsWith("#")) {
431 IRCChannel *channel = m_session->getChannel(dest.lower()); 436 IRCChannel *channel = m_session->getChannel(dest.lower());
432 if (channel) { 437 if (channel) {
433 IRCChannelPerson *person = channel->getPerson(mask.nick()); 438 IRCChannelPerson *person = channel->getPerson(mask.nick());
434 if (person) { 439 if (person) {
435 IRCOutput output(OUTPUT_CHANACTION, "*" + mask.nick() + message->param(0)); 440 IRCOutput output(OUTPUT_CHANACTION, "*" + mask.nick() + message->param(0));
436 output.addParam(channel); 441 output.addParam(channel);
437 output.addParam(person); 442 output.addParam(person);
438 emit outputReady(output); 443 emit outputReady(output);
439 } else { 444 } else {
440 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP ACTION with unknown person - Desynchronized?"))); 445 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP ACTION with unknown person - Desynchronized?")));
441 } 446 }
442 } else { 447 } else {
443 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP ACTION with unknown channel - Desynchronized?"))); 448 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP ACTION with unknown channel - Desynchronized?")));
444 } 449 }
445 } else { 450 } else {
446 if (message->ctcpDestination() == m_session->m_server->nick()) { 451 if (message->ctcpDestination() == m_session->m_server->nick()) {
447 IRCPerson *person = m_session->getPerson(mask.nick()); 452 IRCPerson *person = m_session->getPerson(mask.nick());
448 if (!person) { 453 if (!person) {
449 /* Person not yet known, create and add to the current session */ 454 /* Person not yet known, create and add to the current session */
450 person = new IRCPerson(message->prefix()); 455 person = new IRCPerson(message->prefix());
451 m_session->addPerson(person); 456 m_session->addPerson(person);
452 } 457 }
453 IRCOutput output(OUTPUT_QUERYACTION, "*" + mask.nick() + message->param(0)); 458 IRCOutput output(OUTPUT_QUERYACTION, "*" + mask.nick() + message->param(0));
454 output.addParam(person); 459 output.addParam(person);
455 emit outputReady(output); 460 emit outputReady(output);
456 } else { 461 } else {
457 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP ACTION with bad recipient"))); 462 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP ACTION with bad recipient")));
458 } 463 }
459 } 464 }
460} 465}
461 466
462void IRCMessageParser::parseCTCPDCC(IRCMessage *message) { 467void IRCMessageParser::parseCTCPDCC(IRCMessage *message) {
463 QStringList params = QStringList::split(' ', message->param(0).stripWhiteSpace()); 468 QStringList params = QStringList::split(' ', message->param(0).stripWhiteSpace());
464 if( params.count() != 5) { 469
465 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Malformed DCC request from ") + IRCPerson(message->prefix()).nick())); 470 if(params[0] == "SEND") {
466 return; 471 QString nickname = IRCPerson(message->prefix()).nick();
472 if( params.count() != 5) {
473 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Malformed DCC request from %1").arg(nickname)));
474 return;
475 }
476 bool accepted = DCCTransferTab::confirm(static_cast<QWidget*>(m_session->parent()), nickname, params[1], params[4].toUInt());
477 if(!accepted)
478 return;
479 QString filename = Opie::Ui::OFileDialog::getSaveFileName(Opie::Ui::OFileSelector::EXTENDED_ALL,
480 QString::null, params[1], MimeTypes(), 0, tr("Save As"));
481 if(filename.isEmpty())
482 return;
483
484 odebug << "Receiving file " << filename << " from " << nickname << oendl;
485 static_cast<IRCServerTab*>(m_session->parent())->mainwindow()->addDCC(DCCTransfer::Recv, params[2].toUInt(), params[3].toUInt(),
486 filename, nickname, params[4].toUInt());
467 } 487 }
468
469 //TransferReceiver *foo = new TransferReceiver(params[2].toUInt(), params[3].toUInt(), params[1], params[4].toUInt());
470} 488}
471 489
472void IRCMessageParser::parseLiteralMode(IRCMessage *message) { 490void IRCMessageParser::parseLiteralMode(IRCMessage *message) {
473 IRCPerson mask(message->prefix()); 491 IRCPerson mask(message->prefix());
474 492
475 if (message->param(0).startsWith("#")) { 493 if (message->param(0).startsWith("#")) {
476 IRCChannel *channel = m_session->getChannel(message->param(0).lower()); 494 IRCChannel *channel = m_session->getChannel(message->param(0).lower());
477 if (channel) { 495 if (channel) {
478 QString temp, parameters = message->allParameters().right(message->allParameters().length() - channel->channelname().length() - 1); 496 QString temp, parameters = message->allParameters().right(message->allParameters().length() - channel->channelname().length() - 1);
479 QTextIStream stream(&parameters); 497 QTextIStream stream(&parameters);
480 bool set = FALSE; 498 bool set = FALSE;
481 while (!stream.atEnd()) { 499 while (!stream.atEnd()) {
482 stream >> temp; 500 stream >> temp;
483 if (temp.startsWith("+")) { 501 if (temp.startsWith("+")) {
484 set = TRUE; 502 set = TRUE;
485 temp = temp.right(1); 503 temp = temp.right(1);
486 } 504 }
487 else 505 else
488 if (temp.startsWith("-")) { 506 if (temp.startsWith("-")) {
489 set = FALSE; 507 set = FALSE;
490 temp = temp.right(1); 508 temp = temp.right(1);
491 } 509 }
492 else { 510 else {
493 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change has unknown type"))); 511 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change has unknown type")));
494 return; 512 return;
495 } 513 }
496 if (temp == "o") { 514 if (temp == "o") {
497 stream >> temp; 515 stream >> temp;
498 IRCChannelPerson *person = channel->getPerson(temp); 516 IRCChannelPerson *person = channel->getPerson(temp);
499 if (person) { 517 if (person) {
500 IRCOutput output(OUTPUT_CHANPERSONMODE, person->setOp(mask.nick(), set)); 518 IRCOutput output(OUTPUT_CHANPERSONMODE, person->setOp(mask.nick(), set));
501 output.addParam(channel); 519 output.addParam(channel);
502 output.addParam(person); 520 output.addParam(person);
503 emit outputReady(output); 521 emit outputReady(output);
504 } 522 }
505 else { 523 else {
506 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown person - Desynchronized?"))); 524 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown person - Desynchronized?")));
507 } 525 }
508 } 526 }
509 else 527 else
510 if (temp == "v") { 528 if (temp == "v") {
511 stream >> temp; 529 stream >> temp;
512 IRCChannelPerson *person = channel->getPerson(temp); 530 IRCChannelPerson *person = channel->getPerson(temp);
513 if (person) { 531 if (person) {
514 IRCOutput output(OUTPUT_CHANPERSONMODE, person->setVoice(mask.nick(), set)); 532 IRCOutput output(OUTPUT_CHANPERSONMODE, person->setVoice(mask.nick(), set));
515 output.addParam(channel); 533 output.addParam(channel);
516 output.addParam(person); 534 output.addParam(person);
517 emit outputReady(output); 535 emit outputReady(output);
518 } 536 }
519 else { 537 else {
520 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown person - Desynchronized?"))); 538 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown person - Desynchronized?")));
521 } 539 }
522 } 540 }
523 else { 541 else {
524 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown flag"))); 542 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown flag")));
525 } 543 }
526 } 544 }
527 } else { 545 } else {
528 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown kannel - Desynchronized?"))); 546 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown kannel - Desynchronized?")));
529 } 547 }
530 } else { 548 } else {
531 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("User modes not supported yet"))); 549 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("User modes not supported yet")));
532 } 550 }
533} 551}
534 552
535void IRCMessageParser::parseLiteralKick(IRCMessage *message) { 553void IRCMessageParser::parseLiteralKick(IRCMessage *message) {
536 IRCPerson mask(message->prefix()); 554 IRCPerson mask(message->prefix());
537 IRCChannel *channel = m_session->getChannel(message->param(0).lower()); 555 IRCChannel *channel = m_session->getChannel(message->param(0).lower());
538 if (channel) { 556 if (channel) {
539 IRCChannelPerson *person = channel->getPerson(message->param(1)); 557 IRCChannelPerson *person = channel->getPerson(message->param(1));
540 if (person) { 558 if (person) {
541 if (person->nick() == m_session->m_server->nick()) { 559 if (person->nick() == m_session->m_server->nick()) {
542 m_session->removeChannel(channel); 560 m_session->removeChannel(channel);
543 IRCOutput output(OUTPUT_SELFKICK, tr("You were kicked from ") + channel->channelname() + tr(" by ") + mask.nick() + " (" + message->param(2) + ")"); 561 IRCOutput output(OUTPUT_SELFKICK, tr("You were kicked from ") + channel->channelname() + tr(" by ") + mask.nick() + " (" + message->param(2) + ")");
544 output.addParam(channel); 562 output.addParam(channel);
545 emit outputReady(output); 563 emit outputReady(output);
546 } else { 564 } else {
547 /* someone else got kicked */ 565 /* someone else got kicked */
548 channel->removePerson(person); 566 channel->removePerson(person);
549 IRCOutput output(OUTPUT_OTHERKICK, person->nick() + tr(" was kicked from ") + channel->channelname() + tr(" by ") + mask.nick()+ " (" + message->param(2) + ")"); 567 IRCOutput output(OUTPUT_OTHERKICK, person->nick() + tr(" was kicked from ") + channel->channelname() + tr(" by ") + mask.nick()+ " (" + message->param(2) + ")");
550 output.addParam(channel); 568 output.addParam(channel);
551 output.addParam(person); 569 output.addParam(person);
552 emit outputReady(output); 570 emit outputReady(output);
553 } 571 }
554 } else { 572 } else {
555 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown person kick - desynchronized?"))); 573 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown person kick - desynchronized?")));
556 } 574 }
557 } else { 575 } else {
558 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown channel kick - desynchronized?"))); 576 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown channel kick - desynchronized?")));
559 } 577 }
560} 578}
561 579
562void IRCMessageParser::parseNumericalNames(IRCMessage *message) { 580void IRCMessageParser::parseNumericalNames(IRCMessage *message) {
563 /* Name list sent when joining a channel */ 581 /* Name list sent when joining a channel */
564 IRCChannel *channel = m_session->getChannel(message->param(2).lower()); 582 IRCChannel *channel = m_session->getChannel(message->param(2).lower());
565 if (channel != 0) { 583 if (channel != 0) {
566 QString people = message->param(3); 584 QString people = message->param(3);
567 QTextIStream stream(&people); 585 QTextIStream stream(&people);
568 QString temp; 586 QString temp;
569 587
570 while (!stream.atEnd()) { 588 while (!stream.atEnd()) {
571 stream >> temp; 589 stream >> temp;
572 590
573 char flagch = temp.at(0).latin1(); 591 char flagch = temp.at(0).latin1();
574 int flag = 0; 592 int flag = 0;
575 QString nick; 593 QString nick;
576 /* Parse person flags */ 594 /* Parse person flags */
577 if (flagch == '@' || flagch == '+' || flagch=='%' || flagch == '*') { 595 if (flagch == '@' || flagch == '+' || flagch=='%' || flagch == '*') {
578 596
579 nick = temp.right(temp.length()-1); 597 nick = temp.right(temp.length()-1);
580 switch (flagch) { 598 switch (flagch) {
581 case '@': flag = IRCChannelPerson::PERSON_FLAG_OP; break; 599 case '@': flag = IRCChannelPerson::PERSON_FLAG_OP; break;
582 case '+': flag = IRCChannelPerson::PERSON_FLAG_VOICE; break; 600 case '+': flag = IRCChannelPerson::PERSON_FLAG_VOICE; break;
583 case '%': flag = IRCChannelPerson::PERSON_FLAG_HALFOP; break; 601 case '%': flag = IRCChannelPerson::PERSON_FLAG_HALFOP; break;
584 default : flag = 0; break; 602 default : flag = 0; break;
585 } 603 }
586 } else { 604 } else {
587 nick = temp; 605 nick = temp;
588 } 606 }
589 607
590 IRCPerson *person = m_session->getPerson(nick); 608 IRCPerson *person = m_session->getPerson(nick);
591 if (person == 0) { 609 if (person == 0) {
592 person = new IRCPerson(); 610 person = new IRCPerson();
593 person->setNick(nick); 611 person->setNick(nick);
594 m_session->addPerson(person); 612 m_session->addPerson(person);
595 } 613 }
596 IRCChannelPerson *chan_person = new IRCChannelPerson(person); 614 IRCChannelPerson *chan_person = new IRCChannelPerson(person);
597 chan_person->setFlags(flag); 615 chan_person->setFlags(flag);
598 channel->addPerson(chan_person); 616 channel->addPerson(chan_person);
599 } 617 }
600 } else { 618 } else {
601 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Server message with unknown channel"))); 619 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Server message with unknown channel")));
602 } 620 }
603} 621}
604 622
605void IRCMessageParser::parseNumericalEndOfNames(IRCMessage *message) { 623void IRCMessageParser::parseNumericalEndOfNames(IRCMessage *message) {
606 /* Done syncing to channel */ 624 /* Done syncing to channel */
607 IRCChannel *channel = m_session->getChannel(message->param(1).lower()); 625 IRCChannel *channel = m_session->getChannel(message->param(1).lower());
608 if (channel) { 626 if (channel) {
609 channel->setHasPeople(TRUE); 627 channel->setHasPeople(TRUE);
610 /* Yes, we want the names before anything happens inside the GUI */ 628 /* Yes, we want the names before anything happens inside the GUI */
611 IRCOutput output(OUTPUT_SELFJOIN, tr("You joined channel ") + channel->channelname()); 629 IRCOutput output(OUTPUT_SELFJOIN, tr("You joined channel ") + channel->channelname());
612 output.addParam(channel); 630 output.addParam(channel);
613 emit outputReady(output); 631 emit outputReady(output);
614 } else { 632 } else {
615 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Server message with unknown channel"))); 633 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Server message with unknown channel")));
616 } 634 }
617} 635}
618 636
619 637
620void IRCMessageParser::parseNumericalNicknameInUse(IRCMessage *) { 638void IRCMessageParser::parseNumericalNicknameInUse(IRCMessage *) {
621 /* If we are connnected this error is not critical */ 639 /* If we are connnected this error is not critical */
622 if(m_session->isLoggedIn()) 640 if(m_session->isLoggedIn())
623 return; 641 return;
624 642
625 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Nickname is in use, please reconnect with a different nickname"))); 643 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Nickname is in use, please reconnect with a different nickname")));
626 m_session->endSession(); 644 m_session->endSession();
627} 645}
628 646
629void IRCMessageParser::parseNumericalNoSuchNick(IRCMessage *) { 647void IRCMessageParser::parseNumericalNoSuchNick(IRCMessage *) {
630 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("No such nickname"))); 648 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("No such nickname")));
631} 649}
632 650
633void IRCMessageParser::parseNumericalTopic(IRCMessage *message) { 651void IRCMessageParser::parseNumericalTopic(IRCMessage *message) {
634 IRCChannel *channel = m_session->getChannel(message->param(1).lower()); 652 IRCChannel *channel = m_session->getChannel(message->param(1).lower());
635 if (channel) { 653 if (channel) {
636 IRCOutput output(OUTPUT_TOPIC, tr("Topic for channel " + channel->channelname() + " is \"" + message->param(2) + "\"")); 654 IRCOutput output(OUTPUT_TOPIC, tr("Topic for channel " + channel->channelname() + " is \"" + message->param(2) + "\""));
637 output.addParam(channel); 655 output.addParam(channel);
638 emit outputReady(output); 656 emit outputReady(output);
639 } else { 657 } else {
640 IRCOutput output(OUTPUT_TOPIC, tr("Topic for channel " + message->param(1) + " is \"" + message->param(2) + "\"")); 658 IRCOutput output(OUTPUT_TOPIC, tr("Topic for channel " + message->param(1) + " is \"" + message->param(2) + "\""));
641 output.addParam(0); 659 output.addParam(0);
642 emit outputReady(output); 660 emit outputReady(output);
643 } 661 }
644} 662}
645 663
646void IRCMessageParser::parseNumericalTopicWhoTime(IRCMessage *) { 664void IRCMessageParser::parseNumericalTopicWhoTime(IRCMessage *) {
647} 665}
648 666
649 667
diff --git a/noncore/net/opieirc/ircservertab.cpp b/noncore/net/opieirc/ircservertab.cpp
index 62a06e8..d3c0448 100644
--- a/noncore/net/opieirc/ircservertab.cpp
+++ b/noncore/net/opieirc/ircservertab.cpp
@@ -1,415 +1,419 @@
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#include "ircchannelperson.h"
7 7
8 8
9bool IRCServerTab::containsPing( const QString& text, IRCServerTab* tab ) { 9bool IRCServerTab::containsPing( const QString& text, IRCServerTab* tab ) {
10 return (text.contains(IRCMessageParser::tr("Received a CTCP PING from "))) || 10 return (text.contains(IRCMessageParser::tr("Received a CTCP PING from "))) ||
11 (text.find("ping") != -1 && text.find( tab->server()->nick() != -1)); 11 (text.find("ping") != -1 && text.find( tab->server()->nick() != -1));
12} 12}
13 13
14 14
15IRCServerTab::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) {
16 m_server = server; 16 m_server = server;
17 m_session = new IRCSession(this, &m_server); 17 m_session = new IRCSession(this, &m_server);
18 m_mainWindow = mainWindow; 18 m_mainWindow = mainWindow;
19 m_close = FALSE; 19 m_close = FALSE;
20 m_lines = 0; 20 m_lines = 0;
21 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>");
22 m_textview = new QTextView(this); 22 m_textview = new QTextView(this);
23 m_textview->setHScrollBarMode(QScrollView::AlwaysOff); 23 m_textview->setHScrollBarMode(QScrollView::AlwaysOff);
24 m_textview->setVScrollBarMode(QScrollView::AlwaysOn); 24 m_textview->setVScrollBarMode(QScrollView::AlwaysOn);
25 m_textview->setTextFormat(RichText); 25 m_textview->setTextFormat(RichText);
26 QWhatsThis::add(m_textview, tr("Server messages")); 26 QWhatsThis::add(m_textview, tr("Server messages"));
27 m_layout->add(m_textview); 27 m_layout->add(m_textview);
28 m_field = new IRCHistoryLineEdit(this); 28 m_field = new IRCHistoryLineEdit(this);
29 connect(m_field, SIGNAL(nextTab()), this, SIGNAL(nextTab())); 29 connect(m_field, SIGNAL(nextTab()), this, SIGNAL(nextTab()));
30 connect(m_field, SIGNAL(prevTab()), this, SIGNAL(prevTab())); 30 connect(m_field, SIGNAL(prevTab()), this, SIGNAL(prevTab()));
31 connect(m_field, SIGNAL(closeTab()), this, SIGNAL(closeTab())); 31 connect(m_field, SIGNAL(closeTab()), this, SIGNAL(closeTab()));
32 connect(this, SIGNAL(editFocus()), m_field, SLOT(setEditFocus())); 32 connect(this, SIGNAL(editFocus()), m_field, SLOT(setEditFocus()));
33 33
34 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"));
35 m_layout->add(m_field); 35 m_layout->add(m_field);
36 connect(m_field, SIGNAL(returnPressed()), this, SLOT(processCommand())); 36 connect(m_field, SIGNAL(returnPressed()), this, SLOT(processCommand()));
37 connect(m_session, SIGNAL(outputReady(IRCOutput)), this, SLOT(display(IRCOutput))); 37 connect(m_session, SIGNAL(outputReady(IRCOutput)), this, SLOT(display(IRCOutput)));
38 connect(m_mainWindow, SIGNAL(updateScroll()), this, SLOT(scrolling())); 38 connect(m_mainWindow, SIGNAL(updateScroll()), this, SLOT(scrolling()));
39 connect(m_session, SIGNAL(updateChannels()), this, SLOT(slotUpdateChannels())); 39 connect(m_session, SIGNAL(updateChannels()), this, SLOT(slotUpdateChannels()));
40 settingsChanged(); 40 settingsChanged();
41 41
42 m_field->setFocus(); 42 m_field->setFocus();
43 m_field->setActiveWindow(); 43 m_field->setActiveWindow();
44 44
45} 45}
46 46
47void IRCServerTab::scrolling(){ 47void IRCServerTab::scrolling(){
48 m_textview->ensureVisible(0, m_textview->contentsHeight()); 48 m_textview->ensureVisible(0, m_textview->contentsHeight());
49} 49}
50 50
51 51
52void IRCServerTab::appendText(QString text) { 52void IRCServerTab::appendText(QString text) {
53 /* not using append because it creates layout problems */ 53 /* not using append because it creates layout problems */
54 QString txt = m_textview->text() + IRCTab::appendTimestamp( text ); 54 QString txt = m_textview->text() + IRCTab::appendTimestamp( text );
55 55
56 56
57 57
58 if (m_maxLines > 0 && m_lines >= m_maxLines) { 58 if (m_maxLines > 0 && m_lines >= m_maxLines) {
59 int firstBreak = txt.find('\n'); 59 int firstBreak = txt.find('\n');
60 if (firstBreak != -1) { 60 if (firstBreak != -1) {
61 txt = "<qt bgcolor=\"" + m_backgroundColor + "\"/>" + txt.right(txt.length() - (firstBreak + 1)); 61 txt = "<qt bgcolor=\"" + m_backgroundColor + "\"/>" + txt.right(txt.length() - (firstBreak + 1));
62 } 62 }
63 } else { 63 } else {
64 m_lines++; 64 m_lines++;
65 } 65 }
66 m_textview->setText(txt); 66 m_textview->setText(txt);
67 m_textview->ensureVisible(0, m_textview->contentsHeight()); 67 m_textview->ensureVisible(0, m_textview->contentsHeight());
68 emit changed(this); 68 emit changed(this);
69} 69}
70 70
71IRCServerTab::~IRCServerTab() { 71IRCServerTab::~IRCServerTab() {
72 delete m_session; 72 delete m_session;
73} 73}
74 74
75void IRCServerTab::removeChannelTab(IRCChannelTab *tab) { 75void IRCServerTab::removeChannelTab(IRCChannelTab *tab) {
76 m_channelTabs.remove(tab); 76 m_channelTabs.remove(tab);
77} 77}
78 78
79void IRCServerTab::removeQueryTab(IRCQueryTab *tab) { 79void IRCServerTab::removeQueryTab(IRCQueryTab *tab) {
80 m_queryTabs.remove(tab); 80 m_queryTabs.remove(tab);
81} 81}
82 82
83void IRCServerTab::addQueryTab(IRCQueryTab *tab) { 83void IRCServerTab::addQueryTab(IRCQueryTab *tab) {
84 m_queryTabs.append(tab); 84 m_queryTabs.append(tab);
85} 85}
86 86
87QString IRCServerTab::title() { 87QString IRCServerTab::title() {
88 return "Server"; 88 return "Server";
89} 89}
90 90
91IRCSession *IRCServerTab::session() { 91IRCSession *IRCServerTab::session() {
92 return m_session; 92 return m_session;
93} 93}
94/* 94/*
95QString *IRCServerTab::mynick() { 95QString *IRCServerTab::mynick() {
96 return (*m_server->nick()); 96 return (*m_server->nick());
97} */ 97} */
98 98
99IRCServer *IRCServerTab::server() { 99IRCServer *IRCServerTab::server() {
100 return &m_server; 100 return &m_server;
101} 101}
102 102
103void IRCServerTab::settingsChanged() { 103void IRCServerTab::settingsChanged() {
104 m_textview->setText("<qt bgcolor=\"" + m_backgroundColor + "\"/>"); 104 m_textview->setText("<qt bgcolor=\"" + m_backgroundColor + "\"/>");
105 m_lines = 0; 105 m_lines = 0;
106} 106}
107 107
108void IRCServerTab::executeCommand(IRCTab *tab, QString line) { 108void IRCServerTab::executeCommand(IRCTab *tab, QString line) {
109 QTextIStream stream(&line); 109 QTextIStream stream(&line);
110 QString command; 110 QString command;
111 stream >> command; 111 stream >> command;
112 command = command.upper().right(command.length()-1); 112 command = command.upper().right(command.length()-1);
113 113
114 //JOIN 114 //JOIN
115 if (command == "JOIN" || command == "J") { 115 if (command == "JOIN" || command == "J") {
116 QString channel; 116 QString channel;
117 stream >> channel; 117 stream >> channel;
118 /* According to RFC 1459 */ 118 /* According to RFC 1459 */
119 if (channel.length() > 0 && channel.length() < 200 && 119 if (channel.length() > 0 && channel.length() < 200 &&
120 channel.find(",") == -1 && channel.find("") == -1) { 120 channel.find(",") == -1 && channel.find("") == -1) {
121 121
122 if (!channel.startsWith("#") && !channel.startsWith("&")) { 122 if (!channel.startsWith("#") && !channel.startsWith("&")) {
123 channel = channel.prepend("#"); 123 channel = channel.prepend("#");
124 } 124 }
125 m_session->join(channel); 125 m_session->join(channel);
126 } else { 126 } else {
127 tab->appendText("<font color=\"" + m_errorColor + "\">Unknown channel format!</font><br>"); 127 tab->appendText("<font color=\"" + m_errorColor + "\">Unknown channel format!</font><br>");
128 } 128 }
129 } 129 }
130 130
131 //KICK 131 //KICK
132 else if (command == "KICK"){ 132 else if (command == "KICK"){
133 QString nickname; 133 QString nickname;
134 stream >> nickname; 134 stream >> nickname;
135 if (nickname.length() > 0) { 135 if (nickname.length() > 0) {
136 if (line.length() > 7 + nickname.length()) { 136 if (line.length() > 7 + nickname.length()) {
137 QString text = line.right(line.length()-nickname.length()-7); 137 QString text = line.right(line.length()-nickname.length()-7);
138 IRCPerson person; 138 IRCPerson person;
139 person.setNick(nickname); 139 person.setNick(nickname);
140 m_session->kick(((IRCChannelTab *)tab)->channel(), &person, text); 140 m_session->kick(((IRCChannelTab *)tab)->channel(), &person, text);
141 } else { 141 } else {
142 IRCPerson person; 142 IRCPerson person;
143 person.setNick(nickname); 143 person.setNick(nickname);
144 m_session->kick(((IRCChannelTab *)tab)->channel(), &person); 144 m_session->kick(((IRCChannelTab *)tab)->channel(), &person);
145 } 145 }
146 } 146 }
147 } 147 }
148 148
149 else if (command == "OP"){ 149 else if (command == "OP"){
150 QString nickname; 150 QString nickname;
151 stream >> nickname; 151 stream >> nickname;
152 if (nickname.length() > 0) { 152 if (nickname.length() > 0) {
153 QString text = line.right(line.length()-nickname.length()-5); 153 QString text = line.right(line.length()-nickname.length()-5);
154 IRCPerson person; 154 IRCPerson person;
155 person.setNick(nickname); 155 person.setNick(nickname);
156 m_session->op(((IRCChannelTab *)tab)->channel(), &person); 156 m_session->op(((IRCChannelTab *)tab)->channel(), &person);
157 } 157 }
158 } 158 }
159 159
160 //SEND MODES 160 //SEND MODES
161 else if (command == "MODE"){ 161 else if (command == "MODE"){
162 QString text = line.right(line.length()-6); 162 QString text = line.right(line.length()-6);
163 if (text.length() > 0) { 163 if (text.length() > 0) {
164 m_session->mode(text); 164 m_session->mode(text);
165 } else { 165 } else {
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 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>");
167 } 167 }
168 } 168 }
169 //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
170 else if (command == "RAW"){ 170 else if (command == "RAW"){
171 QString text = line.right(line.length()-5); 171 QString text = line.right(line.length()-5);
172 if (text.length() > 0) { 172 if (text.length() > 0) {
173 m_session->raw(text); 173 m_session->raw(text);
174 } 174 }
175 } 175 }
176 else if (command == "SUSPEND"){ 176 else if (command == "SUSPEND"){
177 QString text = line.right(line.length()-9); 177 QString text = line.right(line.length()-9);
178 if (text.upper() == "ON") { 178 if (text.upper() == "ON") {
179 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; 179 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
180 } 180 }
181 else if (text.upper() == "OFF"){ 181 else if (text.upper() == "OFF"){
182 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Disable; 182 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Disable;
183 } else { 183 } else {
184 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);
185 } 185 }
186 } 186 }
187 187
188 else if (command == "QUIT"){ 188 else if (command == "QUIT"){
189 QString text = line.right(line.length()-6); 189 QString text = line.right(line.length()-6);
190 if (text.length() > 0) { 190 if (text.length() > 0) {
191 m_session->quit(text); 191 m_session->quit(text);
192 } else { 192 } else {
193 m_session->quit(); 193 m_session->quit();
194 } 194 }
195 } 195 }
196 196
197 //SEND ACTION 197 //SEND ACTION
198 else if (command == "ME") { 198 else if (command == "ME") {
199 QString text = line.right(line.length()-4); 199 QString text = line.right(line.length()-4);
200 if (text.length() > 0) { 200 if (text.length() > 0) {
201 if (tab->isA("IRCChannelTab")) { 201 if (tab->isA("IRCChannelTab")) {
202 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>");
203 m_session->sendAction(((IRCChannelTab *)tab)->channel(), text); 203 m_session->sendAction(((IRCChannelTab *)tab)->channel(), text);
204 } else if (tab->isA("IRCQueryTab")) { 204 } else if (tab->isA("IRCQueryTab")) {
205 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>");
206 m_session->sendAction(((IRCQueryTab *)tab)->person(), text); 206 m_session->sendAction(((IRCQueryTab *)tab)->person(), text);
207 } else { 207 } else {
208 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>");
209 } 209 }
210 } 210 }
211 } 211 }
212 //SEND PRIVMSG 212 //SEND PRIVMSG
213 else if (command == "MSG") { 213 else if (command == "MSG") {
214 QString nickname; 214 QString nickname;
215 stream >> nickname; 215 stream >> nickname;
216 if (nickname.length() > 0) { 216 if (nickname.length() > 0) {
217 if (line.length() > 6 + nickname.length()) { 217 if (line.length() > 6 + nickname.length()) {
218 QString text = line.right(line.length()-nickname.length()-6); 218 QString text = line.right(line.length()-nickname.length()-6);
219 IRCPerson person; 219 IRCPerson person;
220 person.setNick(nickname); 220 person.setNick(nickname);
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 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>");
222 m_session->sendMessage(&person, text); 222 m_session->sendMessage(&person, text);
223 } 223 }
224 } 224 }
225 } 225 }
226 else { 226 else {
227 tab->appendText("<font color=\"" + m_errorColor + "\">Unknown command</font><br>"); 227 tab->appendText("<font color=\"" + m_errorColor + "\">Unknown command</font><br>");
228 } 228 }
229} 229}
230 230
231void IRCServerTab::processCommand() { 231void IRCServerTab::processCommand() {
232 QString text = m_field->text(); 232 QString text = m_field->text();
233 if (text.startsWith("/") && !text.startsWith("//")) { 233 if (text.startsWith("/") && !text.startsWith("//")) {
234 /* Command mode */ 234 /* Command mode */
235 executeCommand(this, text); 235 executeCommand(this, text);
236 } 236 }
237 m_field->clear(); 237 m_field->clear();
238} 238}
239 239
240void IRCServerTab::doConnect() { 240void IRCServerTab::doConnect() {
241 m_session->beginSession(); 241 m_session->beginSession();
242} 242}
243 243
244void IRCServerTab::remove() { 244void IRCServerTab::remove() {
245 /* Close requested */ 245 /* Close requested */
246 if (m_session->isSessionActive()) { 246 if (m_session->isSessionActive()) {
247 /* While there is a running session */ 247 /* While there is a running session */
248 m_close = TRUE; 248 m_close = TRUE;
249 m_session->endSession(); 249 m_session->endSession();
250 } else { 250 } else {
251 /* Session has previously been closed */ 251 /* Session has previously been closed */
252 m_channelTabs.first(); 252 m_channelTabs.first();
253 while (m_channelTabs.current() != 0) { 253 while (m_channelTabs.current() != 0) {
254 m_mainWindow->killTab(m_channelTabs.current(), true); 254 m_mainWindow->killTab(m_channelTabs.current(), true);
255 } 255 }
256 m_queryTabs.first(); 256 m_queryTabs.first();
257 while (m_queryTabs.current() != 0) { 257 while (m_queryTabs.current() != 0) {
258 m_mainWindow->killTab(m_queryTabs.current(), true); 258 m_mainWindow->killTab(m_queryTabs.current(), true);
259 } 259 }
260 m_mainWindow->killTab(this); 260 m_mainWindow->killTab(this);
261 } 261 }
262} 262}
263 263
264IRCChannelTab *IRCServerTab::getTabForChannel(IRCChannel *channel) { 264IRCChannelTab *IRCServerTab::getTabForChannel(IRCChannel *channel) {
265 QListIterator<IRCChannelTab> it(m_channelTabs); 265 QListIterator<IRCChannelTab> it(m_channelTabs);
266 266
267 for (; it.current(); ++it) { 267 for (; it.current(); ++it) {
268 if (it.current()->channel() == channel) 268 if (it.current()->channel() == channel)
269 return it.current(); 269 return it.current();
270 } 270 }
271 return 0; 271 return 0;
272} 272}
273 273
274IRCQueryTab *IRCServerTab::getTabForQuery(IRCPerson *person) { 274IRCQueryTab *IRCServerTab::getTabForQuery(IRCPerson *person) {
275 QListIterator<IRCQueryTab> it(m_queryTabs); 275 QListIterator<IRCQueryTab> it(m_queryTabs);
276 276
277 for (; it.current(); ++it) { 277 for (; it.current(); ++it) {
278 if (it.current()->person()->nick() == person->nick()) 278 if (it.current()->person()->nick() == person->nick())
279 return it.current(); 279 return it.current();
280 } 280 }
281 return 0; 281 return 0;
282} 282}
283 283
284void IRCServerTab::display(IRCOutput output) { 284void IRCServerTab::display(IRCOutput output) {
285 285
286 /* All messages to be displayed inside the GUI get here */ 286 /* All messages to be displayed inside the GUI get here */
287 switch (output.type()) { 287 switch (output.type()) {
288 case OUTPUT_CONNCLOSE: 288 case OUTPUT_CONNCLOSE:
289 if (m_close) { 289 if (m_close) {
290 m_channelTabs.first(); 290 m_channelTabs.first();
291 while (m_channelTabs.current() != 0) { 291 while (m_channelTabs.current() != 0) {
292 m_mainWindow->killTab(m_channelTabs.current(), true); 292 m_mainWindow->killTab(m_channelTabs.current(), true);
293 } 293 }
294 m_queryTabs.first(); 294 m_queryTabs.first();
295 while (m_queryTabs.current() != 0) { 295 while (m_queryTabs.current() != 0) {
296 m_mainWindow->killTab(m_queryTabs.current(), true); 296 m_mainWindow->killTab(m_queryTabs.current(), true);
297 } 297 }
298 m_mainWindow->killTab(this); 298 m_mainWindow->killTab(this);
299 } else { 299 } else {
300 appendText("<font color=\"" + m_errorColor + "\">" + output.htmlMessage() +"</font><br>"); 300 appendText("<font color=\"" + m_errorColor + "\">" + output.htmlMessage() +"</font><br>");
301 QListIterator<IRCChannelTab> it(m_channelTabs); 301 QListIterator<IRCChannelTab> it(m_channelTabs);
302 for (; it.current(); ++it) { 302 for (; it.current(); ++it) {
303 it.current()->appendText("<font color=\"" + m_serverColor + "\">" + output.htmlMessage() +"</font><br>"); 303 it.current()->appendText("<font color=\"" + m_serverColor + "\">" + output.htmlMessage() +"</font><br>");
304 } 304 }
305 } 305 }
306 break; 306 break;
307 case OUTPUT_SELFJOIN: { 307 case OUTPUT_SELFJOIN: {
308 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());
309 m_channelTabs.append(channeltab); 309 m_channelTabs.append(channeltab);
310 m_mainWindow->addTab(channeltab); 310 m_mainWindow->addTab(channeltab);
311 } 311 }
312 break; 312 break;
313 case OUTPUT_CHANPRIVMSG: { 313 case OUTPUT_CHANPRIVMSG: {
314 IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0)); 314 IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0));
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 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>");
316 } 316 }
317 break; 317 break;
318 case OUTPUT_QUERYACTION: 318 case OUTPUT_QUERYACTION:
319 case OUTPUT_QUERYPRIVMSG: { 319 case OUTPUT_QUERYPRIVMSG: {
320 IRCQueryTab *queryTab = getTabForQuery((IRCPerson *)output.getParam(0)); 320 IRCQueryTab *queryTab = getTabForQuery((IRCPerson *)output.getParam(0));
321 if (!queryTab) { 321 if (!queryTab) {
322 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());
323 m_queryTabs.append(queryTab); 323 m_queryTabs.append(queryTab);
324 m_mainWindow->addTab(queryTab); 324 m_mainWindow->addTab(queryTab);
325 } 325 }
326 queryTab->display(output); 326 queryTab->display(output);
327 } 327 }
328 break; 328 break;
329 case OUTPUT_SELFPART: { 329 case OUTPUT_SELFPART: {
330 IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0)); 330 IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0));
331 if (channelTab) 331 if (channelTab)
332 m_mainWindow->killTab(channelTab, true); 332 m_mainWindow->killTab(channelTab, true);
333 } 333 }
334 break; 334 break;
335 case OUTPUT_SELFKICK: { 335 case OUTPUT_SELFKICK: {
336 appendText("<font color=\"" + m_errorColor + "\">" + output.htmlMessage() + "</font><br>"); 336 appendText("<font color=\"" + m_errorColor + "\">" + output.htmlMessage() + "</font><br>");
337 IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0)); 337 IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0));
338 if (channelTab) 338 if (channelTab)
339 m_mainWindow->killTab(channelTab, true); 339 m_mainWindow->killTab(channelTab, true);
340 } 340 }
341 break; 341 break;
342 case OUTPUT_CHANACTION: { 342 case OUTPUT_CHANACTION: {
343 IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0)); 343 IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0));
344 channelTab->appendText("<font color=\"" + m_otherColor + "\">"+output.htmlMessage()+"</font><br>"); 344 channelTab->appendText("<font color=\"" + m_otherColor + "\">"+output.htmlMessage()+"</font><br>");
345 } 345 }
346 break; 346 break;
347 case OUTPUT_TOPIC: { 347 case OUTPUT_TOPIC: {
348 IRCChannel *channel = (IRCChannel *) output.getParam(0); 348 IRCChannel *channel = (IRCChannel *) output.getParam(0);
349 if (channel) { 349 if (channel) {
350 IRCChannelTab *channelTab = getTabForChannel(channel); 350 IRCChannelTab *channelTab = getTabForChannel(channel);
351 if (channelTab) { 351 if (channelTab) {
352 channelTab->appendText("<font color=\"" + m_notificationColor + "\">"+output.htmlMessage()+"</font><br>"); 352 channelTab->appendText("<font color=\"" + m_notificationColor + "\">"+output.htmlMessage()+"</font><br>");
353 return; 353 return;
354 } 354 }
355 } 355 }
356 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>");
357 } 357 }
358 break; 358 break;
359 case OUTPUT_QUIT: { 359 case OUTPUT_QUIT: {
360 QString nick = ((IRCPerson *)output.getParam(0))->nick(); 360 QString nick = ((IRCPerson *)output.getParam(0))->nick();
361 QListIterator<IRCChannelTab> it(m_channelTabs); 361 QListIterator<IRCChannelTab> it(m_channelTabs);
362 for (; it.current(); ++it) { 362 for (; it.current(); ++it) {
363 if (it.current()->list()->hasPerson(nick)) { 363 if (it.current()->list()->hasPerson(nick)) {
364 it.current()->appendText("<font color=\"" + m_notificationColor + "\">"+output.htmlMessage()+"</font><br>"); 364 it.current()->appendText("<font color=\"" + m_notificationColor + "\">"+output.htmlMessage()+"</font><br>");
365 it.current()->list()->update(); 365 it.current()->list()->update();
366 } 366 }
367 } 367 }
368 } 368 }
369 break; 369 break;
370 case OUTPUT_NICKCHANGE: { 370 case OUTPUT_NICKCHANGE: {
371 QString *nick = static_cast<QString*>(output.getParam(0)); 371 QString *nick = static_cast<QString*>(output.getParam(0));
372 if(!nick) { 372 if(!nick) {
373 appendText("<font color=\"" + m_notificationColor + "\">"+output.htmlMessage()+"</font><br>"); 373 appendText("<font color=\"" + m_notificationColor + "\">"+output.htmlMessage()+"</font><br>");
374 break; 374 break;
375 } 375 }
376 QListIterator<IRCChannelTab> it(m_channelTabs); 376 QListIterator<IRCChannelTab> it(m_channelTabs);
377 for (; it.current(); ++it) { 377 for (; it.current(); ++it) {
378 if (it.current()->list()->hasPerson(*nick)) { 378 if (it.current()->list()->hasPerson(*nick)) {
379 it.current()->appendText("<font color=\"" + m_notificationColor + "\">"+output.htmlMessage()+"</font><br>"); 379 it.current()->appendText("<font color=\"" + m_notificationColor + "\">"+output.htmlMessage()+"</font><br>");
380 } 380 }
381 } 381 }
382 delete nick; 382 delete nick;
383 } 383 }
384 break; 384 break;
385 case OUTPUT_OTHERJOIN: 385 case OUTPUT_OTHERJOIN:
386 case OUTPUT_OTHERKICK: 386 case OUTPUT_OTHERKICK:
387 case OUTPUT_CHANPERSONMODE: 387 case OUTPUT_CHANPERSONMODE:
388 case OUTPUT_OTHERPART: { 388 case OUTPUT_OTHERPART: {
389 IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0)); 389 IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0));
390 channelTab->appendText("<font color=\"" + m_notificationColor + "\">"+output.htmlMessage()+"</font><br>"); 390 channelTab->appendText("<font color=\"" + m_notificationColor + "\">"+output.htmlMessage()+"</font><br>");
391 channelTab->list()->update(); 391 channelTab->list()->update();
392 } 392 }
393 break; 393 break;
394 case OUTPUT_CTCP: 394 case OUTPUT_CTCP:
395 appendText("<font color=\"" + m_notificationColor + "\">" + output.htmlMessage() + "</font><br>"); 395 appendText("<font color=\"" + m_notificationColor + "\">" + output.htmlMessage() + "</font><br>");
396 break; 396 break;
397 case OUTPUT_ERROR: 397 case OUTPUT_ERROR:
398 appendText("<font color=\"" + m_errorColor + "\">" + output.htmlMessage() + "</font><br>"); 398 appendText("<font color=\"" + m_errorColor + "\">" + output.htmlMessage() + "</font><br>");
399 break; 399 break;
400 case OUTPUT_TITLE: 400 case OUTPUT_TITLE:
401 m_description->setText(output.message()); 401 m_description->setText(output.message());
402 break; 402 break;
403 default: 403 default:
404 appendText("<font color=\"" + m_serverColor + "\">" + output.htmlMessage() + "</font><br>"); 404 appendText("<font color=\"" + m_serverColor + "\">" + output.htmlMessage() + "</font><br>");
405 break; 405 break;
406 } 406 }
407} 407}
408 408
409void IRCServerTab::slotUpdateChannels() { 409void IRCServerTab::slotUpdateChannels() {
410 QListIterator<IRCChannelTab> it(m_channelTabs); 410 QListIterator<IRCChannelTab> it(m_channelTabs);
411 for (; it.current(); ++it) { 411 for (; it.current(); ++it) {
412 it.current()->list()->update(); 412 it.current()->list()->update();
413 } 413 }
414} 414}
415
416MainWindow *IRCServerTab::mainwindow() {
417 return m_mainWindow;
418}
415 419
diff --git a/noncore/net/opieirc/ircservertab.h b/noncore/net/opieirc/ircservertab.h
index 42f6f57..fe48a3b 100644
--- a/noncore/net/opieirc/ircservertab.h
+++ b/noncore/net/opieirc/ircservertab.h
@@ -1,82 +1,83 @@
1/* 1/*
2 OpieIRC - An embedded IRC client 2 OpieIRC - An embedded IRC client
3 Copyright (C) 2002 Wenzel Jakob 3 Copyright (C) 2002 Wenzel Jakob
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18
19*/ 19*/
20 20
21#ifndef __IRCSERVERTAB_H 21#ifndef __IRCSERVERTAB_H
22#define __IRCSERVERTAB_H 22#define __IRCSERVERTAB_H
23#include <qpe/qpeapplication.h> 23#include <qpe/qpeapplication.h>
24#include <qpe/qcopenvelope_qws.h> 24#include <qpe/qcopenvelope_qws.h>
25#include "irctab.h" 25#include "irctab.h"
26#include "ircsession.h" 26#include "ircsession.h"
27#include "mainwindow.h" 27#include "mainwindow.h"
28#include "ircchanneltab.h" 28#include "ircchanneltab.h"
29#include "ircquerytab.h" 29#include "ircquerytab.h"
30#include "ircmisc.h" 30#include "ircmisc.h"
31 31
32 32
33class IRCServerTab : public IRCTab { 33class IRCServerTab : public IRCTab {
34 Q_OBJECT 34 Q_OBJECT
35public: 35public:
36 static bool containsPing(const QString& text, IRCServerTab *tab); 36 static bool containsPing(const QString& text, IRCServerTab *tab);
37 37
38 /* IRCTab implementation */ 38 /* IRCTab implementation */
39 IRCServerTab(IRCServer server, MainWindow *mainWindow, QWidget *parent = 0, const char *name = 0, WFlags f = 0); 39 IRCServerTab(IRCServer server, MainWindow *mainWindow, QWidget *parent = 0, const char *name = 0, WFlags f = 0);
40 ~IRCServerTab(); 40 ~IRCServerTab();
41 QString title(); 41 QString title();
42 IRCSession *session(); 42 IRCSession *session();
43 IRCServer *server(); 43 IRCServer *server();
44 MainWindow *mainwindow();
44 45
45 /* Start the server session */ 46 /* Start the server session */
46 void doConnect(); 47 void doConnect();
47// QString *mynick(); 48// QString *mynick();
48 /* Remove tabs from the internal tab lists */ 49 /* Remove tabs from the internal tab lists */
49 void removeChannelTab(IRCChannelTab *tab); 50 void removeChannelTab(IRCChannelTab *tab);
50 void removeQueryTab(IRCQueryTab *tab); 51 void removeQueryTab(IRCQueryTab *tab);
51 /* Return tabs from the internal tab lists */ 52 /* Return tabs from the internal tab lists */
52 IRCChannelTab *getTabForChannel(IRCChannel *channel); 53 IRCChannelTab *getTabForChannel(IRCChannel *channel);
53 IRCQueryTab *getTabForQuery(IRCPerson *person); 54 IRCQueryTab *getTabForQuery(IRCPerson *person);
54 /* Add tabs to the internal tab lists */ 55 /* Add tabs to the internal tab lists */
55 void addQueryTab(IRCQueryTab *tab); 56 void addQueryTab(IRCQueryTab *tab);
56 /* Execute a user command such as /join, /msg etc */ 57 /* Execute a user command such as /join, /msg etc */
57 void executeCommand(IRCTab *tab, QString line); 58 void executeCommand(IRCTab *tab, QString line);
58protected: 59protected:
59 void appendText(QString text); 60 void appendText(QString text);
60public slots: 61public slots:
61 void scrolling(); 62 void scrolling();
62 void remove(); 63 void remove();
63 void processCommand(); 64 void processCommand();
64 void settingsChanged(); 65 void settingsChanged();
65 void slotUpdateChannels(); 66 void slotUpdateChannels();
66protected slots: 67protected slots:
67 void display(IRCOutput output); 68 void display(IRCOutput output);
68protected: 69protected:
69 int m_lines; 70 int m_lines;
70 bool m_close; 71 bool m_close;
71 IRCServer m_server; 72 IRCServer m_server;
72 IRCSession *m_session; 73 IRCSession *m_session;
73 MainWindow *m_mainWindow; 74 MainWindow *m_mainWindow;
74 QTextView *m_textview; 75 QTextView *m_textview;
75 IRCHistoryLineEdit *m_field; 76 IRCHistoryLineEdit *m_field;
76 /* Channel tabs associated with this server tab */ 77 /* Channel tabs associated with this server tab */
77 QList<IRCChannelTab> m_channelTabs; 78 QList<IRCChannelTab> m_channelTabs;
78 /* Query tabs associated with this server tab */ 79 /* Query tabs associated with this server tab */
79 QList<IRCQueryTab> m_queryTabs; 80 QList<IRCQueryTab> m_queryTabs;
80}; 81};
81 82
82#endif /* __IRCSERVERTAB_H */ 83#endif /* __IRCSERVERTAB_H */
diff --git a/noncore/net/opieirc/ircsession.cpp b/noncore/net/opieirc/ircsession.cpp
index fd8ba72..c8d7869 100644
--- a/noncore/net/opieirc/ircsession.cpp
+++ b/noncore/net/opieirc/ircsession.cpp
@@ -1,215 +1,216 @@
1 1
2#include "ircsession.h" 2#include "ircsession.h"
3#include "ircmessageparser.h" 3#include "ircmessageparser.h"
4#include "ircchannelperson.h" 4#include "ircchannelperson.h"
5#include "ircversion.h" 5#include "ircversion.h"
6 6
7IRCSession::IRCSession(QWidget *parent, IRCServer *server) { 7IRCSession::IRCSession(QObject *parent, IRCServer *server)
8 : QObject(parent)
9{
8 m_server = server; 10 m_server = server;
9 m_connection = new IRCConnection(m_server); 11 m_connection = new IRCConnection(m_server);
10 m_parser = new IRCMessageParser(this); 12 m_parser = new IRCMessageParser(this);
11 m_parent = parent;
12 connect(m_connection, SIGNAL(messageArrived(IRCMessage*)), this, SLOT(handleMessage(IRCMessage*))); 13 connect(m_connection, SIGNAL(messageArrived(IRCMessage*)), this, SLOT(handleMessage(IRCMessage*)));
13 connect(m_parser, SIGNAL(outputReady(IRCOutput)), this, SIGNAL(outputReady(IRCOutput))); 14 connect(m_parser, SIGNAL(outputReady(IRCOutput)), this, SIGNAL(outputReady(IRCOutput)));
14 connect(m_connection, SIGNAL(outputReady(IRCOutput)), this, SIGNAL(outputReady(IRCOutput))); 15 connect(m_connection, SIGNAL(outputReady(IRCOutput)), this, SIGNAL(outputReady(IRCOutput)));
15} 16}
16 17
17IRCSession::~IRCSession() { 18IRCSession::~IRCSession() {
18 /* We want this to get deleted automatically */ 19 /* We want this to get deleted automatically */
19 m_channels.setAutoDelete(TRUE); 20 m_channels.setAutoDelete(TRUE);
20 m_people.setAutoDelete(TRUE); 21 m_people.setAutoDelete(TRUE);
21 22
22 delete m_parser; 23 delete m_parser;
23 delete m_connection; 24 delete m_connection;
24} 25}
25 26
26void IRCSession::beginSession() { 27void IRCSession::beginSession() {
27 m_connection->doConnect(); 28 m_connection->doConnect();
28} 29}
29 30
30void IRCSession::join(QString channelname) { 31void IRCSession::join(QString channelname) {
31 m_connection->sendLine("JOIN " + channelname); 32 m_connection->sendLine("JOIN " + channelname);
32} 33}
33 34
34void IRCSession::quit(){ 35void IRCSession::quit(){
35 m_connection->sendLine("QUIT :[OI] I'm too good to need a reason"); 36 m_connection->sendLine("QUIT :[OI] I'm too good to need a reason");
36} 37}
37 38
38void IRCSession::quit(QString message){ 39void IRCSession::quit(QString message){
39 m_connection->sendLine("QUIT :" + message); 40 m_connection->sendLine("QUIT :" + message);
40} 41}
41 42
42void IRCSession::topic(IRCChannel *channel, QString message){ 43void IRCSession::topic(IRCChannel *channel, QString message){
43 m_connection->sendLine("TOPIC :" + channel->channelname() + " " + message); 44 m_connection->sendLine("TOPIC :" + channel->channelname() + " " + message);
44} 45}
45 46
46void IRCSession::mode(IRCChannel *channel, QString message){ 47void IRCSession::mode(IRCChannel *channel, QString message){
47 m_connection->sendLine("MODE " + channel->channelname() + " " + message); 48 m_connection->sendLine("MODE " + channel->channelname() + " " + message);
48} 49}
49 50
50void IRCSession::mode(IRCPerson *person, QString message){ 51void IRCSession::mode(IRCPerson *person, QString message){
51 m_connection->sendLine("MODE " + person->nick() + " " + message); 52 m_connection->sendLine("MODE " + person->nick() + " " + message);
52} 53}
53 54
54void IRCSession::mode(QString message){ 55void IRCSession::mode(QString message){
55 m_connection->sendLine("MODE " + message); 56 m_connection->sendLine("MODE " + message);
56} 57}
57 58
58void IRCSession::raw(QString message){ 59void IRCSession::raw(QString message){
59 m_connection->sendLine(message); 60 m_connection->sendLine(message);
60} 61}
61 62
62void IRCSession::kick(IRCChannel *channel, IRCPerson *person) { 63void IRCSession::kick(IRCChannel *channel, IRCPerson *person) {
63 m_connection->sendLine("KICK " + channel->channelname() + " " + person->nick() +" :0wn3d - no reason"); 64 m_connection->sendLine("KICK " + channel->channelname() + " " + person->nick() +" :0wn3d - no reason");
64} 65}
65 66
66void IRCSession::op(IRCChannel *channel, IRCPerson *person) { 67void IRCSession::op(IRCChannel *channel, IRCPerson *person) {
67 m_connection->sendLine("MODE " + channel->channelname() + " +ooo " + person->nick()); 68 m_connection->sendLine("MODE " + channel->channelname() + " +ooo " + person->nick());
68} 69}
69 70
70void IRCSession::kick(IRCChannel *channel, IRCPerson *person, QString message) { 71void IRCSession::kick(IRCChannel *channel, IRCPerson *person, QString message) {
71 m_connection->sendLine("KICK " + channel->channelname() + " " + person->nick() +" :" + message); 72 m_connection->sendLine("KICK " + channel->channelname() + " " + person->nick() +" :" + message);
72} 73}
73 74
74void IRCSession::sendMessage(IRCPerson *person, QString message) { 75void IRCSession::sendMessage(IRCPerson *person, QString message) {
75 m_connection->sendLine("PRIVMSG " + person->nick() + " :" + message); 76 m_connection->sendLine("PRIVMSG " + person->nick() + " :" + message);
76} 77}
77 78
78void IRCSession::sendMessage(IRCChannel *channel, QString message) { 79void IRCSession::sendMessage(IRCChannel *channel, QString message) {
79 m_connection->sendLine("PRIVMSG " + channel->channelname() + " :" + message); 80 m_connection->sendLine("PRIVMSG " + channel->channelname() + " :" + message);
80} 81}
81 82
82void IRCSession::sendAction(IRCChannel *channel, QString message) { 83void IRCSession::sendAction(IRCChannel *channel, QString message) {
83 m_connection->sendLine("PRIVMSG " + channel->channelname() + " :\001ACTION " + message + "\001"); 84 m_connection->sendLine("PRIVMSG " + channel->channelname() + " :\001ACTION " + message + "\001");
84} 85}
85 86
86void IRCSession::sendAction(IRCPerson *person, QString message) { 87void IRCSession::sendAction(IRCPerson *person, QString message) {
87 m_connection->sendLine("PRIVMSG " + person->nick() + " :\001ACTION " + message + "\001"); 88 m_connection->sendLine("PRIVMSG " + person->nick() + " :\001ACTION " + message + "\001");
88} 89}
89 90
90bool IRCSession::isSessionActive() { 91bool IRCSession::isSessionActive() {
91 return m_connection->isConnected(); 92 return m_connection->isConnected();
92} 93}
93 94
94bool IRCSession::isLoggedIn() { 95bool IRCSession::isLoggedIn() {
95 return m_connection->isLoggedIn(); 96 return m_connection->isLoggedIn();
96} 97}
97 98
98void IRCSession::endSession() { 99void IRCSession::endSession() {
99 if (m_connection->isLoggedIn()) 100 if (m_connection->isLoggedIn())
100 quit(APP_VERSION); 101 quit(APP_VERSION);
101 else 102 else
102 m_connection->close(); 103 m_connection->close();
103} 104}
104 105
105void IRCSession::part(IRCChannel *channel) { 106void IRCSession::part(IRCChannel *channel) {
106 m_connection->sendLine("PART " + channel->channelname() + " :" + APP_VERSION); 107 m_connection->sendLine("PART " + channel->channelname() + " :" + APP_VERSION);
107} 108}
108 109
109void IRCSession::setValidUsermodes(const QString &modes) { 110void IRCSession::setValidUsermodes(const QString &modes) {
110 m_validUsermodes = modes; 111 m_validUsermodes = modes;
111} 112}
112 113
113void IRCSession::setValidChannelmodes(const QString &modes) { 114void IRCSession::setValidChannelmodes(const QString &modes) {
114 m_validChannelmodes = modes; 115 m_validChannelmodes = modes;
115} 116}
116 117
117void IRCSession::updateNickname(const QString &oldNickname, const QString &newNickname) { 118void IRCSession::updateNickname(const QString &oldNickname, const QString &newNickname) {
118 QList<IRCChannel> channels; 119 QList<IRCChannel> channels;
119 IRCOutput output; 120 IRCOutput output;
120 121
121 if (oldNickname == m_server->nick()) { 122 if (oldNickname == m_server->nick()) {
122 m_server->setNick(newNickname); 123 m_server->setNick(newNickname);
123 output = IRCOutput(OUTPUT_NICKCHANGE, tr("You are now known as %1").arg(newNickname)); 124 output = IRCOutput(OUTPUT_NICKCHANGE, tr("You are now known as %1").arg(newNickname));
124 channels = m_channels; 125 channels = m_channels;
125 } 126 }
126 127
127 else { 128 else {
128 IRCPerson *person = getPerson(oldNickname); 129 IRCPerson *person = getPerson(oldNickname);
129 130
130 if(!person) { 131 if(!person) {
131 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Nickname change of an unknown person"))); 132 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Nickname change of an unknown person")));
132 return; 133 return;
133 } 134 }
134 135
135 getChannelsByPerson(person, channels); 136 getChannelsByPerson(person, channels);
136 output = IRCOutput(OUTPUT_NICKCHANGE, tr("%1 is now known as %2").arg(oldNickname).arg(newNickname)); 137 output = IRCOutput(OUTPUT_NICKCHANGE, tr("%1 is now known as %2").arg(oldNickname).arg(newNickname));
137 } 138 }
138 139
139 QListIterator<IRCChannel> it(channels); 140 QListIterator<IRCChannel> it(channels);
140 for (;it.current(); ++it) { 141 for (;it.current(); ++it) {
141 IRCChannelPerson *chanperson = it.current()->getPerson(oldNickname); 142 IRCChannelPerson *chanperson = it.current()->getPerson(oldNickname);
142 it.current()->removePerson(chanperson); 143 it.current()->removePerson(chanperson);
143 chanperson->setNick(newNickname); 144 chanperson->setNick(newNickname);
144 it.current()->addPerson(chanperson); 145 it.current()->addPerson(chanperson);
145 } 146 }
146 147
147 emit updateChannels(); 148 emit updateChannels();
148 output.addParam(new QString(newNickname)); 149 output.addParam(new QString(newNickname));
149 emit outputReady(output); 150 emit outputReady(output);
150} 151}
151 152
152IRCChannel *IRCSession::getChannel(QString channelname) { 153IRCChannel *IRCSession::getChannel(QString channelname) {
153 QListIterator<IRCChannel> it(m_channels); 154 QListIterator<IRCChannel> it(m_channels);
154 for (; it.current(); ++it) { 155 for (; it.current(); ++it) {
155 if (it.current()->channelname() == channelname) { 156 if (it.current()->channelname() == channelname) {
156 return it.current(); 157 return it.current();
157 } 158 }
158 } 159 }
159 return 0; 160 return 0;
160} 161}
161 162
162IRCPerson *IRCSession::getPerson(QString nickname) { 163IRCPerson *IRCSession::getPerson(QString nickname) {
163 QListIterator<IRCPerson> it(m_people); 164 QListIterator<IRCPerson> it(m_people);
164 for (; it.current(); ++it) { 165 for (; it.current(); ++it) {
165 if (it.current()->nick() == nickname) { 166 if (it.current()->nick() == nickname) {
166 return it.current(); 167 return it.current();
167 } 168 }
168 } 169 }
169 return 0; 170 return 0;
170} 171}
171 172
172void IRCSession::getChannelsByPerson(IRCPerson *person, QList<IRCChannel> &channels) { 173void IRCSession::getChannelsByPerson(IRCPerson *person, QList<IRCChannel> &channels) {
173 QListIterator<IRCChannel> it(m_channels); 174 QListIterator<IRCChannel> it(m_channels);
174 for (; it.current(); ++it) { 175 for (; it.current(); ++it) {
175 if (it.current()->getPerson(person->nick()) != 0) { 176 if (it.current()->getPerson(person->nick()) != 0) {
176 channels.append(it.current()); 177 channels.append(it.current());
177 } 178 }
178 } 179 }
179} 180}
180 181
181void IRCSession::addPerson(IRCPerson *person) { 182void IRCSession::addPerson(IRCPerson *person) {
182 m_people.append(person); 183 m_people.append(person);
183} 184}
184 185
185void IRCSession::addChannel(IRCChannel *channel) { 186void IRCSession::addChannel(IRCChannel *channel) {
186 m_channels.append(channel); 187 m_channels.append(channel);
187} 188}
188 189
189void IRCSession::removeChannel(IRCChannel *channel) { 190void IRCSession::removeChannel(IRCChannel *channel) {
190 m_channels.remove(channel); 191 m_channels.remove(channel);
191} 192}
192 193
193void IRCSession::removePerson(IRCPerson *person) { 194void IRCSession::removePerson(IRCPerson *person) {
194 m_people.remove(person); 195 m_people.remove(person);
195} 196}
196 197
197void IRCSession::handleMessage(IRCMessage *message) { 198void IRCSession::handleMessage(IRCMessage *message) {
198 m_parser->parse(message); 199 m_parser->parse(message);
199} 200}
200 201
201void IRCSession::whois(const QString &nickname) { 202void IRCSession::whois(const QString &nickname) {
202 m_connection->whois(nickname); 203 m_connection->whois(nickname);
203} 204}
204 205
205void IRCSession::sendCTCPPing(const QString &nickname) { 206void IRCSession::sendCTCPPing(const QString &nickname) {
206 m_connection->sendCTCPPing(nickname); 207 m_connection->sendCTCPPing(nickname);
207} 208}
208 209
209void IRCSession::sendCTCPRequest(const QString &nickname, const QString &type, const QString &args) { 210void IRCSession::sendCTCPRequest(const QString &nickname, const QString &type, const QString &args) {
210 m_connection->sendCTCPRequest(nickname, type, args); 211 m_connection->sendCTCPRequest(nickname, type, args);
211} 212}
212 213
213void IRCSession::sendCTCPReply(const QString &nickname, const QString &type, const QString &args) { 214void IRCSession::sendCTCPReply(const QString &nickname, const QString &type, const QString &args) {
214 m_connection->sendCTCPReply(nickname, type, args); 215 m_connection->sendCTCPReply(nickname, type, args);
215} 216}
diff --git a/noncore/net/opieirc/ircsession.h b/noncore/net/opieirc/ircsession.h
index 7c91893..23a2540 100644
--- a/noncore/net/opieirc/ircsession.h
+++ b/noncore/net/opieirc/ircsession.h
@@ -1,96 +1,96 @@
1/* 1/*
2 OpieIRC - An embedded IRC client 2 OpieIRC - An embedded IRC client
3 Copyright (C) 2002 Wenzel Jakob 3 Copyright (C) 2002 Wenzel Jakob
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18
19*/ 19*/
20 20
21#ifndef __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;
33class IRCServerTab;
33 34
34/* The IRCSession stores all information relating to the connection 35/* The IRCSession stores all information relating to the connection
35 to one IRC server. IRCSession makes it possible to run multiple 36 to one IRC server. IRCSession makes it possible to run multiple
36 IRC server connections from within the same program */ 37 IRC server connections from within the same program */
37 38
38class IRCSession : public QObject { 39class IRCSession : public QObject {
39friend class IRCMessageParser; 40friend class IRCMessageParser;
40 Q_OBJECT 41 Q_OBJECT
41public: 42public:
42 IRCSession(QWidget *parent, IRCServer *server); 43 IRCSession(QObject *parent, IRCServer *server);
43 ~IRCSession(); 44 ~IRCSession();
44 45
45 void join(QString channel); 46 void join(QString channel);
46 void quit(QString message); 47 void quit(QString message);
47 void quit(); 48 void quit();
48 void raw(QString message); 49 void raw(QString message);
49 void topic(IRCChannel *channel, QString message); 50 void topic(IRCChannel *channel, QString message);
50 void mode(IRCChannel *channel, QString message); 51 void mode(IRCChannel *channel, QString message);
51 void mode(IRCPerson *person, QString message); 52 void mode(IRCPerson *person, QString message);
52 void mode(QString message); 53 void mode(QString message);
53 void part(IRCChannel *channel); 54 void part(IRCChannel *channel);
54 void op(IRCChannel *channel, IRCPerson *person); 55 void op(IRCChannel *channel, IRCPerson *person);
55 void kick(IRCChannel *channel, IRCPerson *person); 56 void kick(IRCChannel *channel, IRCPerson *person);
56 void kick(IRCChannel *channel, IRCPerson *person, QString message); 57 void kick(IRCChannel *channel, IRCPerson *person, QString message);
57 void beginSession(); 58 void beginSession();
58 bool isSessionActive(); 59 bool isSessionActive();
59 void endSession(); 60 void endSession();
60 bool isLoggedIn(); 61 bool isLoggedIn();
61 void sendMessage(IRCPerson *person, QString message); 62 void sendMessage(IRCPerson *person, QString message);
62 void sendMessage(IRCChannel *channel, QString message); 63 void sendMessage(IRCChannel *channel, QString message);
63 void sendAction(IRCPerson *person, QString message); 64 void sendAction(IRCPerson *person, QString message);
64 void sendAction(IRCChannel *channel, QString message); 65 void sendAction(IRCChannel *channel, QString message);
65 void updateNickname(const QString &oldNickname, const QString &newNickname); 66 void updateNickname(const QString &oldNickname, const QString &newNickname);
66 void setValidUsermodes(const QString &modes); 67 void setValidUsermodes(const QString &modes);
67 void setValidChannelmodes(const QString &modes); 68 void setValidChannelmodes(const QString &modes);
68 void whois(const QString &nickname); 69 void whois(const QString &nickname);
69 void sendCTCPPing(const QString &nickname); 70 void sendCTCPPing(const QString &nickname);
70 void sendCTCPRequest(const QString &nickname, const QString &type, const QString &args); 71 void sendCTCPRequest(const QString &nickname, const QString &type, const QString &args);
71 void sendCTCPReply(const QString &nickname, const QString &type, const QString &args); 72 void sendCTCPReply(const QString &nickname, const QString &type, const QString &args);
72 IRCChannel *getChannel(QString channelname); 73 IRCChannel *getChannel(QString channelname);
73 IRCPerson *getPerson(QString nickname); 74 IRCPerson *getPerson(QString nickname);
74protected: 75protected:
75 void addPerson(IRCPerson *person); 76 void addPerson(IRCPerson *person);
76 void addChannel(IRCChannel *channel); 77 void addChannel(IRCChannel *channel);
77 void removeChannel(IRCChannel *channel); 78 void removeChannel(IRCChannel *channel);
78 void removePerson(IRCPerson *person); 79 void removePerson(IRCPerson *person);
79 void getChannelsByPerson(IRCPerson *person, QList<IRCChannel> &channels); 80 void getChannelsByPerson(IRCPerson *person, QList<IRCChannel> &channels);
80protected slots: 81protected slots:
81 void handleMessage(IRCMessage *message); 82 void handleMessage(IRCMessage *message);
82signals: 83signals:
83 void outputReady(IRCOutput output); 84 void outputReady(IRCOutput output);
84 void updateChannels(); 85 void updateChannels();
85protected: 86protected:
86 IRCServer *m_server; 87 IRCServer *m_server;
87 IRCConnection *m_connection; 88 IRCConnection *m_connection;
88 IRCMessageParser *m_parser; 89 IRCMessageParser *m_parser;
89 QList<IRCChannel> m_channels; 90 QList<IRCChannel> m_channels;
90 QList<IRCPerson> m_people; 91 QList<IRCPerson> m_people;
91 QString m_validUsermodes; 92 QString m_validUsermodes;
92 QString m_validChannelmodes; 93 QString m_validChannelmodes;
93 QWidget *m_parent;
94}; 94};
95 95
96#endif /* __IRCSESSION_H */ 96#endif /* __IRCSESSION_H */
diff --git a/noncore/net/opieirc/mainwindow.cpp b/noncore/net/opieirc/mainwindow.cpp
index 1811a0c..3d60107 100644
--- a/noncore/net/opieirc/mainwindow.cpp
+++ b/noncore/net/opieirc/mainwindow.cpp
@@ -1,139 +1,159 @@
1#include <qmenubar.h> 1#include <qmenubar.h>
2#include <qpe/resource.h> 2#include <qpe/resource.h>
3 3
4#include <opie2/odebug.h> 4#include <opie2/odebug.h>
5 5
6#include <qwhatsthis.h> 6#include <qwhatsthis.h>
7 7
8#include "mainwindow.h" 8#include "mainwindow.h"
9#include "ircservertab.h" 9#include "ircservertab.h"
10#include "dcctransfertab.h"
10#include "ircserverlist.h" 11#include "ircserverlist.h"
11#include "ircsettings.h" 12#include "ircsettings.h"
12 13
14#include <stdio.h>
15
16
13QString MainWindow::appCaption() { 17QString MainWindow::appCaption() {
14 return QObject::tr("Opie IRC"); 18 return QObject::tr("Opie IRC");
15} 19}
16 20
17 21
18MainWindow::MainWindow(QWidget *parent, const char *name, WFlags) : QMainWindow(parent, name, WStyle_ContextHelp) { 22MainWindow::MainWindow(QWidget *parent, const char *name, WFlags) : QMainWindow(parent, name, WStyle_ContextHelp) {
19 setCaption(tr("IRC Client")); 23 setCaption(tr("IRC Client"));
20 m_tabWidget = new IRCTabWidget(this); 24 m_tabWidget = new IRCTabWidget(this);
21 QWhatsThis::add(m_tabWidget, tr("Server connections, channels, queries and other things will be placed here")); 25 QWhatsThis::add(m_tabWidget, tr("Server connections, channels, queries and other things will be placed here"));
22 connect(m_tabWidget, SIGNAL(currentChanged(QWidget*)), this, SLOT(selected(QWidget*))); 26 connect(m_tabWidget, SIGNAL(currentChanged(QWidget*)), this, SLOT(selected(QWidget*)));
23 setCentralWidget(m_tabWidget); 27 setCentralWidget(m_tabWidget);
24 setToolBarsMovable(FALSE); 28 setToolBarsMovable(FALSE);
25 QMenuBar *menuBar = new QMenuBar(this); 29 QMenuBar *menuBar = new QMenuBar(this);
26 QPopupMenu *irc = new QPopupMenu(this); 30 QPopupMenu *irc = new QPopupMenu(this);
27 menuBar->insertItem(tr("IRC"), irc); 31 menuBar->insertItem(tr("IRC"), irc);
28 QAction *a = new QAction(tr("New connection"), Resource::loadPixmap("pass"), QString::null, 0, this, 0); 32 QAction *a = new QAction(tr("New connection"), Resource::loadPixmap("pass"), QString::null, 0, this, 0);
29 connect(a, SIGNAL(activated()), this, SLOT(newConnection())); 33 connect(a, SIGNAL(activated()), this, SLOT(newConnection()));
30 a->setWhatsThis(tr("Create a new connection to an IRC server")); 34 a->setWhatsThis(tr("Create a new connection to an IRC server"));
31 a->addTo(irc); 35 a->addTo(irc);
32 a = new QAction(tr("Settings"), Resource::loadPixmap("SettingsIcon"), QString::null, 0, this, 0); 36 a = new QAction(tr("Settings"), Resource::loadPixmap("SettingsIcon"), QString::null, 0, this, 0);
33 a->setWhatsThis(tr("Configure OpieIRC's behavior and appearance")); 37 a->setWhatsThis(tr("Configure OpieIRC's behavior and appearance"));
34 connect(a, SIGNAL(activated()), this, SLOT(settings())); 38 connect(a, SIGNAL(activated()), this, SLOT(settings()));
35 a->addTo(irc); 39 a->addTo(irc);
40 m_dccTab = 0;
36 loadSettings(); 41 loadSettings();
37} 42}
38 43
39/*IRCTabWidget MainWindow::getTabWidget(){ 44/*IRCTabWidget MainWindow::getTabWidget(){
40 return m_tabWidget; 45 return m_tabWidget;
41} */ 46} */
42 47
43void MainWindow::loadSettings() { 48void MainWindow::loadSettings() {
44 Config config("OpieIRC"); 49 Config config("OpieIRC");
45 config.setGroup("OpieIRC"); 50 config.setGroup("OpieIRC");
46 IRCTab::m_backgroundColor = config.readEntry("BackgroundColor", "#FFFFFF"); 51 IRCTab::m_backgroundColor = config.readEntry("BackgroundColor", "#FFFFFF");
47 IRCTab::m_textColor = config.readEntry("TextColor", "#000000"); 52 IRCTab::m_textColor = config.readEntry("TextColor", "#000000");
48 IRCTab::m_errorColor = config.readEntry("ErrorColor", "#FF0000"); 53 IRCTab::m_errorColor = config.readEntry("ErrorColor", "#FF0000");
49 IRCTab::m_selfColor = config.readEntry("SelfColor", "#CC0000"); 54 IRCTab::m_selfColor = config.readEntry("SelfColor", "#CC0000");
50 IRCTab::m_otherColor = config.readEntry("OtherColor", "#0000BB"); 55 IRCTab::m_otherColor = config.readEntry("OtherColor", "#0000BB");
51 IRCTab::m_serverColor = config.readEntry("ServerColor", "#0000FF"); 56 IRCTab::m_serverColor = config.readEntry("ServerColor", "#0000FF");
52 IRCTab::m_notificationColor = config.readEntry("NotificationColor", "#AA3300"); 57 IRCTab::m_notificationColor = config.readEntry("NotificationColor", "#AA3300");
53 IRCTab::m_maxLines = config.readNumEntry("Lines", 100); 58 IRCTab::m_maxLines = config.readNumEntry("Lines", 100);
54 IRCTab::setUseTimeStamps( config.readBoolEntry("DisplayTime", false ) ); 59 IRCTab::setUseTimeStamps( config.readBoolEntry("DisplayTime", false ) );
55} 60}
56 61
57void MainWindow::selected(QWidget *) { 62void MainWindow::selected(QWidget *) {
58 m_tabWidget->setTabColor(m_tabWidget->currentPageIndex(), black); 63 m_tabWidget->setTabColor(m_tabWidget->currentPageIndex(), black);
59 emit updateScroll(); 64 emit updateScroll();
60} 65}
61 66
62void MainWindow::addTab(IRCTab *tab) { 67void MainWindow::addTab(IRCTab *tab) {
63 connect(tab, SIGNAL(changed(IRCTab*)), this, SLOT(changeEvent(IRCTab*))); 68 connect(tab, SIGNAL(changed(IRCTab*)), this, SLOT(changeEvent(IRCTab*)));
64 connect(tab, SIGNAL(ping (const QString&)), this, SLOT(slotPing(const QString&))); 69 connect(tab, SIGNAL(ping (const QString&)), this, SLOT(slotPing(const QString&)));
65 connect(tab, SIGNAL(nextTab()), this, SLOT(slotNextTab())); 70 connect(tab, SIGNAL(nextTab()), this, SLOT(slotNextTab()));
66 connect(tab, SIGNAL(prevTab()), this, SLOT(slotPrevTab())); 71 connect(tab, SIGNAL(prevTab()), this, SLOT(slotPrevTab()));
67 72
68 m_tabWidget->addTab(tab, tab->title()); 73 m_tabWidget->addTab(tab, tab->title());
69 m_tabWidget->showPage(tab); 74 m_tabWidget->showPage(tab);
70 tab->setID(m_tabWidget->currentPageIndex()); 75 tab->setID(m_tabWidget->currentPageIndex());
71 m_tabs.append(tab); 76 m_tabs.append(tab);
72} 77}
73 78
74void MainWindow::changeEvent(IRCTab *tab) { 79void MainWindow::changeEvent(IRCTab *tab) {
75 if (tab->id() != m_tabWidget->currentPageIndex()) 80 if (tab->id() != m_tabWidget->currentPageIndex())
76 m_tabWidget->setTabColor(tab->id(), blue); 81 m_tabWidget->setTabColor(tab->id(), blue);
77} 82}
78 83
79void MainWindow::killTab(IRCTab *tab, bool imediate) { 84void MainWindow::killTab(IRCTab *tab, bool imediate) {
85 if (tab == m_dccTab)
86 m_dccTab = 0;
87
80 m_toDelete.append( tab ); 88 m_toDelete.append( tab );
81 89
82 if ( imediate ) 90 if ( imediate )
83 slotKillTabsLater(); 91 slotKillTabsLater();
84 else 92 else
85 QTimer::singleShot(0, this, SLOT(slotKillTabsLater()) ); 93 QTimer::singleShot(0, this, SLOT(slotKillTabsLater()) );
86} 94}
87 95
88void MainWindow::slotKillTabsLater() { 96void MainWindow::slotKillTabsLater() {
89 for ( QListIterator<IRCTab> it(m_toDelete); it.current(); ++it ) { 97 for ( QListIterator<IRCTab> it(m_toDelete); it.current(); ++it ) {
90 m_tabWidget->removePage( it.current() ); 98 m_tabWidget->removePage( it.current() );
91 odebug << it.current() << oendl; 99 odebug << it.current() << oendl;
92 m_tabs.remove( it.current() ); 100 m_tabs.remove( it.current() );
93 } 101 }
94 102
95 m_toDelete.setAutoDelete( true ); 103 m_toDelete.setAutoDelete( true );
96 m_toDelete.clear(); 104 m_toDelete.clear();
97 m_toDelete.setAutoDelete( false ); 105 m_toDelete.setAutoDelete( false );
98} 106}
99 107
100void MainWindow::newConnection() { 108void MainWindow::newConnection() {
101 IRCServerList list(this, "ServerList", TRUE); 109 IRCServerList list(this, "ServerList", TRUE);
102 if (list.exec() == QDialog::Accepted && list.hasServer()) { 110 if (list.exec() == QDialog::Accepted && list.hasServer()) {
103 IRCServerTab *serverTab = new IRCServerTab(list.server(), this, m_tabWidget); 111 IRCServerTab *serverTab = new IRCServerTab(list.server(), this, m_tabWidget);
104 addTab(serverTab); 112 addTab(serverTab);
105 serverTab->doConnect(); 113 serverTab->doConnect();
106 } 114 }
107} 115}
108 116
109void MainWindow::settings() { 117void MainWindow::settings() {
110 IRCSettings settings(this, "Settings", TRUE); 118 IRCSettings settings(this, "Settings", TRUE);
111 if (settings.exec() == QDialog::Accepted) { 119 if (settings.exec() == QDialog::Accepted) {
112 QListIterator<IRCTab> it(m_tabs); 120 QListIterator<IRCTab> it(m_tabs);
113 for (; it.current(); ++it) { 121 for (; it.current(); ++it) {
114 /* Inform all tabs about the new settings */ 122 /* Inform all tabs about the new settings */
115 it.current()->settingsChanged(); 123 it.current()->settingsChanged();
116 } 124 }
117 } 125 }
118} 126}
119 127
120 128
121void MainWindow::slotNextTab() { 129void MainWindow::slotNextTab() {
122 int i = m_tabWidget->currentPageIndex (); 130 int i = m_tabWidget->currentPageIndex ();
123 m_tabWidget->setCurrentPage ( i+1 ); 131 m_tabWidget->setCurrentPage ( i+1 );
124 132
125 int j = m_tabWidget->currentPageIndex (); 133 int j = m_tabWidget->currentPageIndex ();
126 if ( i == j ) 134 if ( i == j )
127 m_tabWidget->setCurrentPage ( 1 ); 135 m_tabWidget->setCurrentPage ( 1 );
128} 136}
129 137
130void MainWindow::slotPrevTab() { 138void MainWindow::slotPrevTab() {
131 int i = m_tabWidget->currentPageIndex (); 139 int i = m_tabWidget->currentPageIndex ();
132 if ( i > 1 ) 140 if ( i > 1 )
133 m_tabWidget->setCurrentPage ( i-1 ); 141 m_tabWidget->setCurrentPage ( i-1 );
134} 142}
135 143
136void MainWindow::slotPing( const QString& /*channel*/ ) { 144void MainWindow::slotPing( const QString& /*channel*/ ) {
137 raise(); 145 raise();
138} 146}
139 147
148void MainWindow::addDCC(DCCTransfer::Type type, Q_UINT32 ip4Addr, Q_UINT16 port,
149 const QString &filename, const QString &nickname, unsigned int size) {
150
151 if (!m_dccTab) {
152 m_dccTab = new DCCTransferTab(this);
153 addTab(m_dccTab);
154 m_dccTab->show();
155 }
156
157 m_dccTab->addTransfer(type, ip4Addr, port, filename, nickname, size);
158}
159
diff --git a/noncore/net/opieirc/mainwindow.h b/noncore/net/opieirc/mainwindow.h
index abf205d..873a685 100644
--- a/noncore/net/opieirc/mainwindow.h
+++ b/noncore/net/opieirc/mainwindow.h
@@ -1,61 +1,67 @@
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 __MAINWINDOW_H 21#ifndef __MAINWINDOW_H
22#define __MAINWINDOW_H 22#define __MAINWINDOW_H
23 23
24#include <qmainwindow.h> 24#include <qmainwindow.h>
25#include <qaction.h> 25#include <qaction.h>
26#include <qlist.h> 26#include <qlist.h>
27#include "mainwindow.h" 27
28#include "dcctransfer.h"
28#include "ircmisc.h" 29#include "ircmisc.h"
29#include "irctab.h" 30#include "irctab.h"
30 31
32class DCCTransferTab;
33
31class MainWindow : public QMainWindow { 34class MainWindow : public QMainWindow {
32 Q_OBJECT 35 Q_OBJECT
33public: 36public:
34 MainWindow(QWidget *parent = 0, const char *name = 0, WFlags f = 0); 37 MainWindow(QWidget *parent = 0, const char *name = 0, WFlags f = 0);
35// IRCTabWidget getTabWidget(); 38// IRCTabWidget getTabWidget();
36 void addTab(IRCTab *tab); 39 void addTab(IRCTab *tab);
37 void killTab(IRCTab *tab, bool now = false); 40 void killTab(IRCTab *tab, bool now = false);
38 static QString appName() { return QString::fromLatin1("opieirc"); } 41 static QString appName() { return QString::fromLatin1("opieirc"); }
39 static QString appCaption(); 42 static QString appCaption();
43 void addDCC(DCCTransfer::Type type, Q_UINT32 ip4Addr, Q_UINT16 port,
44 const QString &filename, const QString &nickname, unsigned int size);
40signals: 45signals:
41 void updateScroll(); 46 void updateScroll();
42protected slots: 47protected slots:
43 void newConnection(); 48 void newConnection();
44 void settings(); 49 void settings();
45 void selected(QWidget *); 50 void selected(QWidget *);
46 void changeEvent(IRCTab *); 51 void changeEvent(IRCTab *);
47 52
48 void slotNextTab(); 53 void slotNextTab();
49 void slotPrevTab(); 54 void slotPrevTab();
50 void slotPing(const QString&); 55 void slotPing(const QString&);
51 void slotKillTabsLater(); 56 void slotKillTabsLater();
52 57
53protected: 58protected:
54 void loadSettings(); 59 void loadSettings();
55protected: 60protected:
56 IRCTabWidget *m_tabWidget; 61 IRCTabWidget *m_tabWidget;
57 QList<IRCTab> m_tabs; 62 QList<IRCTab> m_tabs;
58 QList<IRCTab> m_toDelete; 63 QList<IRCTab> m_toDelete;
64 DCCTransferTab *m_dccTab;
59}; 65};
60 66
61#endif /* __MAINWINDOW_H */ 67#endif /* __MAINWINDOW_H */
diff --git a/noncore/net/opieirc/opieirc.pro b/noncore/net/opieirc/opieirc.pro
index 1ef9be2..5e91450 100644
--- a/noncore/net/opieirc/opieirc.pro
+++ b/noncore/net/opieirc/opieirc.pro
@@ -1,30 +1,35 @@
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 ircchannelperson.h dcctransfertab.h \
11 dccprogress.h dcctransfer.h \
12 dcctransferrecv.h
11 SOURCES = ircchannel.cpp ircconnection.cpp \ 13 SOURCES = ircchannel.cpp ircconnection.cpp \
12 ircmessage.cpp \ 14 ircmessage.cpp \
13 ircmessageparser.cpp ircoutput.cpp \ 15 ircmessageparser.cpp ircoutput.cpp \
14 ircperson.cpp ircserver.cpp \ 16 ircperson.cpp ircserver.cpp \
15 ircsession.cpp main.cpp mainwindow.cpp \ 17 ircsession.cpp main.cpp mainwindow.cpp \
16 irctab.cpp ircservertab.cpp \ 18 irctab.cpp ircservertab.cpp \
17 ircchanneltab.cpp ircchannellist.cpp \ 19 ircchanneltab.cpp ircchannellist.cpp \
18 ircserverlist.cpp ircservereditor.cpp \ 20 ircserverlist.cpp ircservereditor.cpp \
19 ircquerytab.cpp ircsettings.cpp ircmisc.cpp \ 21 ircquerytab.cpp ircsettings.cpp ircmisc.cpp \
20 ircchannelperson.cpp 22 ircchannelperson.cpp dcctransfertab.cpp \
23 dccprogress.cpp dcctransfer.cpp \
24 dcctransferrecv.cpp
25
21INCLUDEPATH += $(OPIEDIR)/include 26INCLUDEPATH += $(OPIEDIR)/include
22DEPENDPATH += $(OPIEDIR)/include 27DEPENDPATH += $(OPIEDIR)/include
23 28
24PRECOMPILED_HEADER = stable.h 29PRECOMPILED_HEADER = stable.h
25 30
26LIBS += -lqpe -lopiecore2 -lopieui2 -lqtaux2 31LIBS += -lqpe -lopiecore2 -lopieui2 -lqtaux2
27TARGET = opieirc 32TARGET = opieirc
28 33
29 34
30include( $(OPIEDIR)/include.pro ) 35include( $(OPIEDIR)/include.pro )