summaryrefslogtreecommitdiff
authorwazlaf <wazlaf>2002-09-20 23:28:14 (UTC)
committer wazlaf <wazlaf>2002-09-20 23:28:14 (UTC)
commit912092425248f7fc5155b4c7c46b7d00ec2676bc (patch) (side-by-side diff)
tree5bbf746e83b2dffad89542c42031a573c34da751
parentcd3df897c1b0ed93c2be3ab411011a0bdfe88bf9 (diff)
downloadopie-912092425248f7fc5155b4c7c46b7d00ec2676bc.zip
opie-912092425248f7fc5155b4c7c46b7d00ec2676bc.tar.gz
opie-912092425248f7fc5155b4c7c46b7d00ec2676bc.tar.bz2
support for client commands (only /join implemented so far), crash bugfix, fixed 2 leaks, server browser now includes a channel list
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/opieirc/ircchannel.cpp5
-rw-r--r--noncore/net/opieirc/ircchannel.h1
-rw-r--r--noncore/net/opieirc/ircchanneltab.cpp26
-rw-r--r--noncore/net/opieirc/ircconnection.cpp8
-rw-r--r--noncore/net/opieirc/ircmessage.cpp3
-rw-r--r--noncore/net/opieirc/ircmessageparser.cpp3
-rw-r--r--noncore/net/opieirc/ircoutput.cpp7
-rw-r--r--noncore/net/opieirc/ircoutput.h2
-rw-r--r--noncore/net/opieirc/ircserver.cpp12
-rw-r--r--noncore/net/opieirc/ircserver.h6
-rw-r--r--noncore/net/opieirc/ircservereditor.cpp19
-rw-r--r--noncore/net/opieirc/ircservereditor.h1
-rw-r--r--noncore/net/opieirc/ircserverlist.cpp2
-rw-r--r--noncore/net/opieirc/ircservertab.cpp70
-rw-r--r--noncore/net/opieirc/ircservertab.h3
-rw-r--r--noncore/net/opieirc/ircsession.cpp4
-rw-r--r--noncore/net/opieirc/irctab.h1
-rw-r--r--noncore/net/opieirc/ircversion.h2
18 files changed, 151 insertions, 24 deletions
diff --git a/noncore/net/opieirc/ircchannel.cpp b/noncore/net/opieirc/ircchannel.cpp
index 71ec03b..9814a26 100644
--- a/noncore/net/opieirc/ircchannel.cpp
+++ b/noncore/net/opieirc/ircchannel.cpp
@@ -1,20 +1,25 @@
#include "ircchannel.h"
#include <stdio.h>
IRCChannel::IRCChannel(QString channelname) {
m_hasPeople = FALSE;
m_channelname = channelname;
}
+IRCChannel::~IRCChannel() {
+ /* We want this to get deleted */
+ m_people.setAutoDelete(TRUE);
+}
+
QString IRCChannel::channelname() {
return m_channelname;
}
bool IRCChannel::hasPeople() {
return m_hasPeople;
}
void IRCChannel::setHasPeople(bool hasPeople) {
m_hasPeople = hasPeople;
}
diff --git a/noncore/net/opieirc/ircchannel.h b/noncore/net/opieirc/ircchannel.h
index c800b99..e78f182 100644
--- a/noncore/net/opieirc/ircchannel.h
+++ b/noncore/net/opieirc/ircchannel.h
@@ -38,24 +38,25 @@ enum IRCChannelPersonFlag {
typedef struct IRCChannelPerson {
IRCPerson *person;
unsigned int flags;
};
/* IRCChannel is the object-oriented representation
of an IRC channel. It basically acts as a container
for IRCChannelPersons */
class IRCChannel : public QObject {
Q_OBJECT
public:
IRCChannel(QString channelname);
+ ~IRCChannel();
void addPerson(IRCChannelPerson *person);
void removePerson(IRCChannelPerson *person);
IRCChannelPerson *getPerson(QString nickname);
QListIterator<IRCChannelPerson> people();
/* hasPeople identifies whether the irc channel is
done synchronizing with the current state -
this is only relevant when joining a channel */
void setHasPeople(bool hasPeople);
QString channelname();
bool hasPeople();
diff --git a/noncore/net/opieirc/ircchanneltab.cpp b/noncore/net/opieirc/ircchanneltab.cpp
index c96a365..754442a 100644
--- a/noncore/net/opieirc/ircchanneltab.cpp
+++ b/noncore/net/opieirc/ircchanneltab.cpp
@@ -29,49 +29,65 @@ IRCChannelTab::IRCChannelTab(IRCChannel *channel, IRCServerTab *parentTab, MainW
void IRCChannelTab::appendText(QString text) {
/* not using append because it creates layout problems */
m_textview->setText(m_textview->text() + text);
m_textview->ensureVisible(0, m_textview->contentsHeight());
}
IRCChannelTab::~IRCChannelTab() {
m_parentTab->removeChannelTab(this);
}
void IRCChannelTab::processCommand() {
- if (m_field->text().length()>0) {
- session()->sendMessage(m_channel, m_field->text());
- appendText("&lt;<font color=\"#dd0000\">"+m_parentTab->server()->nick()+"</font>&gt; "+m_field->text()+"<br>");
- m_field->clear();
+ QString text = m_field->text();
+ if (text.length()>0) {
+ if (session()->isSessionActive()) {
+ if (text.startsWith("/") && !text.startsWith("//")) {
+ /* Command mode */
+ m_parentTab->executeCommand(this, text);;
+ } else {
+ if (session()->isSessionActive()) {
+ session()->sendMessage(m_channel, m_field->text());
+ appendText("&lt;<font color=\"#dd0000\">"+m_parentTab->server()->nick()+"</font>&gt; "+m_field->text()+"<br>");
+ }
+ }
+ } else {
+ appendText("<font color=\"#ff0000\">"+tr("Disconnected")+"</font><br>");
+ }
}
+ m_field->clear();
}
void IRCChannelTab::toggleList() {
if (m_listVisible) {
m_list->setMaximumWidth(0);
m_listButton->setText("<");
} else {
m_list->setMaximumWidth(LISTWIDTH);
m_listButton->setText(">");
}
m_listVisible = !m_listVisible;
}
QString IRCChannelTab::title() {
return m_channel->channelname();
}
IRCSession *IRCChannelTab::session() {
return m_parentTab->session();
}
void IRCChannelTab::remove() {
- session()->part(m_channel);
+ if (session()->isSessionActive()) {
+ session()->part(m_channel);
+ } else {
+ m_mainWindow->killTab(this);
+ }
}
IRCChannel *IRCChannelTab::channel() {
return m_channel;
}
IRCChannelList *IRCChannelTab::list() {
return m_list;
}
diff --git a/noncore/net/opieirc/ircconnection.cpp b/noncore/net/opieirc/ircconnection.cpp
index 02c4897..5eb0cf2 100644
--- a/noncore/net/opieirc/ircconnection.cpp
+++ b/noncore/net/opieirc/ircconnection.cpp
@@ -51,24 +51,32 @@ void IRCConnection::login() {
}
loginString += "NICK " + m_server->nick() + "\r\n" +
"USER " + m_server->username() + " " + hostname +
" " + m_server->hostname() + " :" + m_server->realname() + "\r\n";
sendLine(loginString);
}
/* Called when data arrives on the socket */
void IRCConnection::dataReady() {
while(m_socket->canReadLine()) {
IRCMessage message(m_socket->readLine());
if (!m_loggedIn && message.isNumerical() && message.commandNumber() == 1) {
+ /* Now autojoin all channels specified inside the server profile */
+ QStringList channels = QStringList::split(QChar(','), m_server->channels());
+ for (QStringList::Iterator it = channels.begin(); it != channels.end(); ++it) {
+ QString channelName = (*it).stripWhiteSpace();
+ if (channelName.startsWith("#")) {
+ sendLine("JOIN "+ channelName);
+ }
+ }
m_loggedIn = TRUE;
emit outputReady(IRCOutput(OUTPUT_CLIENTMESSAGE, tr("Successfully logged in.")));
}
emit messageArrived(&message);
}
}
/* Called if any type of socket error occurs */
void IRCConnection::error(int num) {
emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Socket error : ") + strerror(num)));
}
diff --git a/noncore/net/opieirc/ircmessage.cpp b/noncore/net/opieirc/ircmessage.cpp
index 74e9c6f..9c2869c 100644
--- a/noncore/net/opieirc/ircmessage.cpp
+++ b/noncore/net/opieirc/ircmessage.cpp
@@ -15,36 +15,39 @@ IRCMessage::IRCMessage(QString line) {
stream >> temp;
if (temp.startsWith(":")) {
/* extract the prefix */
m_prefix = temp.right(temp.length()-1);
stream >> temp;
m_command = temp.upper();
m_allParameters = line.right(line.length() - m_prefix.length() - m_command.length() - 3);
} else {
m_command = temp.upper();
m_allParameters = line.right(line.length() - m_command.length() - 1);
}
+
/* Create a list of all parameters */
while(!(stream.atEnd())) {
stream >> temp;
if (temp.startsWith(":")) {
/* last parameter */
m_trailing = line.right(line.length() - line.find(QChar(':'), 1) - 1);
m_parameters << m_trailing;
break;
} else {
m_parameters << temp;
}
}
+
+
m_commandNumber = m_command.toInt(&m_isNumerical);
/* Is this a CTCP command */
if ((m_command == "PRIVMSG" || m_command == "NOTICE") && m_trailing.length()>0 && m_trailing.left(1) == QChar(1)) {
m_ctcp = TRUE;
/* Strip CTCP \001 characters */
m_allParameters = m_allParameters.replace(QRegExp(QChar(1)), "");
QTextIStream ctcpStream(&m_allParameters);
if (m_command == "PRIVMSG")
ctcpStream >> m_ctcpDestination;
ctcpStream >> temp;
m_ctcpCommand = temp.upper().right(temp.length()-1);
m_parameters.clear();
diff --git a/noncore/net/opieirc/ircmessageparser.cpp b/noncore/net/opieirc/ircmessageparser.cpp
index a2be5a4..4038673 100644
--- a/noncore/net/opieirc/ircmessageparser.cpp
+++ b/noncore/net/opieirc/ircmessageparser.cpp
@@ -17,24 +17,25 @@ IRCLiteralMessageParserStruct IRCMessageParser::literalParserProcTable[] = {
{ "MODE", FUNC(parseLiteralMode) },
{ "KICK", FUNC(parseLiteralKick) },
{ 0 , 0 }
};
/* Lookup table for literal commands */
IRCCTCPMessageParserStruct IRCMessageParser::ctcpParserProcTable[] = {
{ "PING", FUNC(parseCTCPPing) },
{ "VERSION", FUNC(parseCTCPVersion) },
{ "ACTION", FUNC(parseCTCPAction) },
{ 0 , 0 }
};
+
/* Lookup table for numerical commands */
IRCNumericalMessageParserStruct IRCMessageParser::numericalParserProcTable[] = {
{ 1, FUNC(parseNumerical001) }, // RPL_WELCOME
{ 2, FUNC(parseNumerical002) }, // RPL_YOURHOST
{ 3, FUNC(parseNumerical003) }, // RPL_CREATED
{ 4, FUNC(parseNumerical004) }, // RPL_MYINFO
{ 5, FUNC(parseNumerical005) }, // RPL_BOUNCE, RPL_PROTOCTL
{ 251, FUNC(parseNumericalStats) }, // RPL_LUSERCLIENT
{ 254, FUNC(nullFunc)}, // RPL_LUSERCHANNELS
{ 255, FUNC(parseNumericalStats) }, // RPL_LUSERNAME
{ 353, FUNC(parseNumericalNames) }, // RPL_NAMREPLY
{ 366, FUNC(parseNumericalEndOfNames) }, // RPL_ENDOFNAMES
@@ -219,29 +220,31 @@ void IRCMessageParser::parseLiteralNick(IRCMessage *message) {
}
void IRCMessageParser::parseLiteralQuit(IRCMessage *message) {
IRCPerson mask(message->prefix());
IRCPerson *person = m_session->getPerson(mask.nick());
if (person) {
QList<IRCChannel> channels;
m_session->getChannelsByPerson(person, channels);
QListIterator<IRCChannel> it(channels);
for (;it.current(); ++it) {
IRCChannelPerson *chanperson = it.current()->getPerson(mask.nick());
it.current()->removePerson(chanperson);
+ delete chanperson;
}
m_session->removePerson(person);
IRCOutput output(OUTPUT_QUIT, mask.nick() + tr(" has quit ") + "(" + message->param(0) + ")");
output.addParam(person);
emit outputReady(output);
+ delete person;
} else {
emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown person quit - desynchronized?")));
}
}
void IRCMessageParser::parseLiteralError(IRCMessage *message) {
emit outputReady(IRCOutput(OUTPUT_ERROR, message->allParameters()));
}
void IRCMessageParser::parseCTCPPing(IRCMessage *message) {
IRCPerson mask(message->prefix());
m_session->m_connection->sendCTCP(mask.nick(), "PING " + message->allParameters());
diff --git a/noncore/net/opieirc/ircoutput.cpp b/noncore/net/opieirc/ircoutput.cpp
index aa57d86..878bc9b 100644
--- a/noncore/net/opieirc/ircoutput.cpp
+++ b/noncore/net/opieirc/ircoutput.cpp
@@ -4,19 +4,26 @@ IRCOutput::IRCOutput(IRCOutputType type, QString message) {
m_type = type;
m_message = message;
}
IRCOutputType IRCOutput::type() {
return m_type;
}
QString IRCOutput::message() {
return m_message;
}
+QString IRCOutput::htmlMessage() {
+ QString htmlMessage =m_message.replace(QRegExp("&"), "&amp;");
+ htmlMessage = htmlMessage.replace(QRegExp(">"), "&gt;");
+ htmlMessage = htmlMessage.replace(QRegExp("<"), "&lt;");
+ return htmlMessage;
+}
+
void IRCOutput::addParam(void *data) {
m_parameters.append(data);
}
void *IRCOutput::getParam(int index) {
return m_parameters.at(index);
}
diff --git a/noncore/net/opieirc/ircoutput.h b/noncore/net/opieirc/ircoutput.h
index 4b757ed..72361d4 100644
--- a/noncore/net/opieirc/ircoutput.h
+++ b/noncore/net/opieirc/ircoutput.h
@@ -51,20 +51,22 @@ enum IRCOutputType {
IRC parser to inform the GUI of changes. This could for example be a
channel message or a nickname change */
class IRCOutput {
public:
IRCOutput(IRCOutputType type, QString message);
/* Used to add a parameter to this IRCOutput. Parameters are dependent
on which IRCOutputType we are using (see above) */
void addParam(void *data);
IRCOutputType type();
QString message();
+ /* Return the message with all HTML code escaped (for example &lt; instead of '<') */
+ QString htmlMessage();
void *getParam(int index);
protected:
IRCOutputType m_type;
QString m_message;
QList<void> m_parameters;
};
#endif
diff --git a/noncore/net/opieirc/ircserver.cpp b/noncore/net/opieirc/ircserver.cpp
index e16e2b2..e27e41d 100644
--- a/noncore/net/opieirc/ircserver.cpp
+++ b/noncore/net/opieirc/ircserver.cpp
@@ -1,18 +1,20 @@
#include "ircserver.h"
IRCServer::IRCServer() {
m_port = 6667;
}
+/* Setter implementations */
+
void IRCServer::setHostname(QString hostname) {
m_hostname = hostname;
}
void IRCServer::setName(QString name) {
m_name = name;
}
void IRCServer::setPort(int port) {
m_port = port;
}
@@ -23,24 +25,30 @@ void IRCServer::setUsername(QString username) {
void IRCServer::setPassword(QString password) {
m_password = password;
}
void IRCServer::setNick(QString nick) {
m_nick = nick;
}
void IRCServer::setRealname(QString realname) {
m_realname = realname;
}
+void IRCServer::setChannels(QString channels) {
+ m_channels = channels;
+}
+
+/* Getter implementations */
+
QString IRCServer::hostname() {
return m_hostname;
}
QString IRCServer::name() {
return m_name;
}
unsigned short int IRCServer::port() {
return m_port;
}
@@ -51,12 +59,16 @@ QString IRCServer::username() {
QString IRCServer::password() {
return m_password;
}
QString IRCServer::nick() {
return m_nick;
}
QString IRCServer::realname() {
return m_realname;
}
+QString IRCServer::channels() {
+ return m_channels;
+}
+
diff --git a/noncore/net/opieirc/ircserver.h b/noncore/net/opieirc/ircserver.h
index f56f231..0bc7d4c 100644
--- a/noncore/net/opieirc/ircserver.h
+++ b/noncore/net/opieirc/ircserver.h
@@ -19,40 +19,46 @@
*/
#ifndef __IRCSERVER_H
#define __IRCSERVER_H
#include <qstring.h>
/* IRCServer stores all information required to
establish a connection to a server. */
class IRCServer {
public:
+ /* Initialize to the default values */
IRCServer();
+ /* Setters */
void setName(QString name);
void setHostname(QString hostname);
void setPort(int port);
void setUsername(QString username);
void setPassword(QString password);
void setNick(QString nick);
void setRealname(QString realname);
+ void setChannels(QString channels);
+ /* Getters */
QString hostname();
QString name();
unsigned short int port();
QString username();
QString password();
QString nick();
QString realname();
+ QString channels();
protected:
QString m_hostname;
QString m_name;
unsigned short int m_port;
QString m_username;
QString m_password;
QString m_nick;
QString m_realname;
+ QString m_channels;
};
#endif /* __IRCSERVER_H */
diff --git a/noncore/net/opieirc/ircservereditor.cpp b/noncore/net/opieirc/ircservereditor.cpp
index 798081f..c3a444d 100644
--- a/noncore/net/opieirc/ircservereditor.cpp
+++ b/noncore/net/opieirc/ircservereditor.cpp
@@ -1,61 +1,76 @@
#include <qmessagebox.h>
#include <qlayout.h>
#include <qlabel.h>
#include "ircservereditor.h"
IRCServerEditor::IRCServerEditor(IRCServer server, QWidget* parent, const char* name, bool modal = FALSE, WFlags f) : QDialog(parent, name, modal, f) {
- QGridLayout *layout = new QGridLayout(this, 6, 2, 5, 5);
+ QGridLayout *layout = new QGridLayout(this, 7, 2, 5, 5);
QLabel *label = new QLabel(tr("Profile name :"), this);
m_name = new QLineEdit(server.name(), this);
layout->addWidget(label, 0, 0);
layout->addWidget(m_name, 0, 1);
label = new QLabel(tr("Hostname :"), this);
m_hostname = new QLineEdit(server.hostname(), this);
layout->addWidget(label, 1, 0);
layout->addWidget(m_hostname, 1, 1);
label = new QLabel(tr("Port :"), this);
m_port = new QLineEdit(QString::number(server.port()), this);
layout->addWidget(label, 2, 0);
layout->addWidget(m_port, 2, 1);
label = new QLabel(tr("Nickname :"), this);
m_nickname = new QLineEdit(server.nick(), this);
layout->addWidget(label, 3, 0);
layout->addWidget(m_nickname, 3, 1);
label = new QLabel(tr("Realname :"), this);
m_realname = new QLineEdit(server.realname(), this);
layout->addWidget(label, 4, 0);
layout->addWidget(m_realname, 4, 1);
label = new QLabel(tr("Password :"), this);
m_password = new QLineEdit(server.password(), this);
layout->addWidget(label, 5, 0);
layout->addWidget(m_password, 5, 1);
+ label = new QLabel(tr("Channels :"), this);
+ m_channels = new QLineEdit(server.channels(), this);
+ layout->addWidget(label, 6, 0);
+ layout->addWidget(m_channels, 6, 1);
showMaximized();
}
void IRCServerEditor::accept() {
if (m_name->text().length()==0)
QMessageBox::critical(this, tr("Error"), tr("Profile name required"));
else if (m_hostname->text().length()==0)
QMessageBox::critical(this, tr("Error"), tr("Host name required"));
else if (m_port->text().toInt()<=0)
QMessageBox::critical(this, tr("Error"), tr("Port required"));
else if (m_nickname->text().length()==0)
QMessageBox::critical(this, tr("Error"), tr("Nickname required"));
else if (m_realname->text().length()==0)
QMessageBox::critical(this, tr("Error"), tr("Realname required"));
- else
+ else {
+ /* Now verify whether the channel list has a valid format */
+ QStringList channels = QStringList::split(QChar(','), m_channels->text());
+ for (QStringList::Iterator it = channels.begin(); it != channels.end(); ++it) {
+ QString channelName = (*it).stripWhiteSpace();
+ if (!channelName.startsWith("#")) {
+ QMessageBox::critical(this, tr("Error"), tr("The channel list needs to contain a\ncomma separated list of channel\n names which start with '#'"));
+ return;
+ }
+ }
QDialog::accept();
+ }
}
IRCServer IRCServerEditor::getServer() {
IRCServer server;
server.setName(m_name->text());
server.setHostname(m_hostname->text());
server.setPort(m_port->text().toInt());
server.setNick(m_nickname->text());
server.setRealname(m_realname->text());
server.setUsername(m_nickname->text());
server.setPassword(m_password->text());
+ server.setChannels(m_channels->text());
return server;
}
diff --git a/noncore/net/opieirc/ircservereditor.h b/noncore/net/opieirc/ircservereditor.h
index 20c94f7..22311f7 100644
--- a/noncore/net/opieirc/ircservereditor.h
+++ b/noncore/net/opieirc/ircservereditor.h
@@ -30,15 +30,16 @@ class IRCServerEditor : public QDialog {
public:
IRCServerEditor(IRCServer server, QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags f = 0);
IRCServer getServer();
protected slots:
void accept();
protected:
QLineEdit *m_name;
QLineEdit *m_hostname;
QLineEdit *m_port;
QLineEdit *m_nickname;
QLineEdit *m_password;
QLineEdit *m_realname;
+ QLineEdit *m_channels;
};
#endif /* __IRCSERVEREDITOR_H */
diff --git a/noncore/net/opieirc/ircserverlist.cpp b/noncore/net/opieirc/ircserverlist.cpp
index b2d746a..e664ba1 100644
--- a/noncore/net/opieirc/ircserverlist.cpp
+++ b/noncore/net/opieirc/ircserverlist.cpp
@@ -50,24 +50,25 @@ IRCServerList::IRCServerList(QWidget* parent, const char *name, bool modal, WFla
m_config->setGroup("OpieIRC");
QString name = m_config->readEntry("Server"+QString::number(i));
if (name.length() > 0) {
IRCServer server;
m_config->setGroup(name);
server.setName(name);
server.setHostname(m_config->readEntry("Hostname"));
server.setPort(m_config->readNumEntry("Port"));
server.setUsername(m_config->readEntry("Username"));
server.setPassword(m_config->readEntry("Password"));
server.setNick(m_config->readEntry("Nick"));
server.setRealname(m_config->readEntry("Realname"));
+ server.setChannels(m_config->readEntry("Channels"));
m_list->insertItem(new IRCListBoxServer(server));
}
}
}
showMaximized();
}
void IRCServerList::addServer() {
IRCServer server;
IRCServerEditor editor(server, this, "ServerEditor", TRUE);
if (editor.exec() == QDialog::Accepted) {
@@ -105,24 +106,25 @@ int IRCServerList::exec() {
m_config->writeEntry("ServerCount", QString::number(m_list->count()));
for (unsigned int i=0; i<m_list->count(); i++) {
IRCServer server = ((IRCListBoxServer *)m_list->item(i))->server();
m_config->setGroup("OpieIRC");
m_config->writeEntry("Server"+QString::number(i), server.name());
m_config->setGroup(server.name());
m_config->writeEntry("Hostname", server.hostname());
m_config->writeEntry("Port", QString::number(server.port()));
m_config->writeEntry("Username", server.username());
m_config->writeEntry("Password", server.password());
m_config->writeEntry("Nick", server.nick());
m_config->writeEntry("Realname", server.realname());
+ m_config->writeEntry("Channels", server.channels());
}
return returncode;
}
bool IRCServerList::hasServer() {
return (m_list->currentItem() != -1);
}
IRCServer IRCServerList::server() {
return ((IRCListBoxServer *)m_list->item(m_list->currentItem()))->server();
}
diff --git a/noncore/net/opieirc/ircservertab.cpp b/noncore/net/opieirc/ircservertab.cpp
index 724f4bd..2ad56a8 100644
--- a/noncore/net/opieirc/ircservertab.cpp
+++ b/noncore/net/opieirc/ircservertab.cpp
@@ -1,13 +1,14 @@
#include <stdio.h>
+#include <qtextstream.h>
#include "ircservertab.h"
IRCServerTab::IRCServerTab(IRCServer server, MainWindow *mainWindow, QWidget *parent, const char *name, WFlags f) : IRCTab(parent, name, f) {
m_server = server;
m_session = new IRCSession(&m_server);
m_mainWindow = mainWindow;
m_close = FALSE;
m_description->setText(tr("Connection to")+" <b>" + server.hostname() + ":" + QString::number(server.port()) + "</b>");
m_textview = new QTextView(this);
m_textview->setHScrollBarMode(QScrollView::AlwaysOff);
m_textview->setVScrollBarMode(QScrollView::AlwaysOn);
m_layout->add(m_textview);
@@ -16,131 +17,168 @@ IRCServerTab::IRCServerTab(IRCServer server, MainWindow *mainWindow, QWidget *pa
connect(m_field, SIGNAL(returnPressed()), this, SLOT(processCommand()));
m_field->setFocus();
connect(m_session, SIGNAL(outputReady(IRCOutput)), this, SLOT(display(IRCOutput)));
}
void IRCServerTab::appendText(QString text) {
/* not using append because it creates layout problems */
m_textview->setText(m_textview->text() + text);
m_textview->ensureVisible(0, m_textview->contentsHeight());
}
IRCServerTab::~IRCServerTab() {
- QListIterator<IRCChannelTab> it(m_channelTabs);
- for (; it.current(); ++it) {
- m_mainWindow->killTab(it.current());
- }
delete m_session;
}
void IRCServerTab::removeChannelTab(IRCChannelTab *tab) {
m_channelTabs.remove(tab);
}
QString IRCServerTab::title() {
return "Server";
}
IRCSession *IRCServerTab::session() {
return m_session;
}
IRCServer *IRCServerTab::server() {
return &m_server;
}
+void IRCServerTab::executeCommand(IRCTab *tab, QString line) {
+ QTextIStream stream(&line);
+ QString command;
+ stream >> command;
+ command = command.upper().right(command.length()-1);
+
+ if (command == "JOIN") {
+ QString channel;
+ stream >> channel;
+ if (channel.length() > 0 && channel.startsWith("#")) {
+ m_session->join(channel);
+ } else {
+ tab->appendText("<font color=\"#ff0000\">Unknown channel format!</font><br>");
+ }
+ } else {
+ tab->appendText("<font color=\"#ff0000\">Unknown command</font><br>");
+ }
+}
+
void IRCServerTab::processCommand() {
+ QString text = m_field->text();
+ if (text.startsWith("/") && !text.startsWith("//")) {
+ /* Command mode */
+ executeCommand(this, text);
+ }
m_field->clear();
- appendText("<font color=\"#ff0000\">Not supported yet</font><br>");
}
void IRCServerTab::doConnect() {
m_session->beginSession();
}
void IRCServerTab::remove() {
+ /* Close requested */
if (m_session->isSessionActive()) {
+ /* While there is a running session */
m_close = TRUE;
m_session->endSession();
} else {
+ /* Session has previously been closed */
+ m_channelTabs.first();
+ while (m_channelTabs.current() != 0) {
+ m_mainWindow->killTab(m_channelTabs.current());
+ }
m_mainWindow->killTab(this);
}
}
IRCChannelTab *IRCServerTab::getTabForChannel(IRCChannel *channel) {
QListIterator<IRCChannelTab> it(m_channelTabs);
for (; it.current(); ++it) {
if (it.current()->channel() == channel)
return it.current();
}
return 0;
}
void IRCServerTab::display(IRCOutput output) {
+
+ /* All messages to be displayed inside the GUI get here */
switch (output.type()) {
case OUTPUT_CONNCLOSE:
- if (m_close)
+ if (m_close) {
+ m_channelTabs.first();
+ while (m_channelTabs.current() != 0) {
+ m_mainWindow->killTab(m_channelTabs.current());
+ }
m_mainWindow->killTab(this);
- else
- appendText("<font color=\"#0000dd\">" + output.message() +"</font><br>");
+ } else {
+ appendText("<font color=\"#0000dd\">" + output.htmlMessage() +"</font><br>");
+ QListIterator<IRCChannelTab> it(m_channelTabs);
+ for (; it.current(); ++it) {
+ it.current()->appendText("<font color=\"#0000dd\">" + output.htmlMessage() +"</font><br>");
+ }
+ }
break;
case OUTPUT_SELFJOIN: {
IRCChannelTab *channeltab = new IRCChannelTab((IRCChannel *)output.getParam(0), this, m_mainWindow, (QWidget *)parent());
m_channelTabs.append(channeltab);
m_mainWindow->addTab(channeltab);
}
break;
case OUTPUT_CHANPRIVMSG: {
IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0));
- channelTab->appendText("&lt;<font color=\"#0000dd\">"+((IRCChannelPerson *)output.getParam(1))->person->nick()+"</font>&gt; "+output.message()+"<br>");
+ channelTab->appendText("&lt;<font color=\"#0000dd\">"+((IRCChannelPerson *)output.getParam(1))->person->nick()+"</font>&gt; "+output.htmlMessage()+"<br>");
}
break;
case OUTPUT_SELFPART: {
IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0));
if (channelTab)
m_mainWindow->killTab(channelTab);
}
break;
case OUTPUT_SELFKICK: {
- appendText("<font color=\"#ff0000\">" + output.message() + "</font><br>");
+ appendText("<font color=\"#ff0000\">" + output.htmlMessage() + "</font><br>");
IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0));
if (channelTab)
m_mainWindow->killTab(channelTab);
}
break;
case OUTPUT_CHANACTION: {
IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0));
- channelTab->appendText("<font color=\"#cc0000\">"+output.message()+"</font><br>");
+ channelTab->appendText("<font color=\"#cc0000\">"+output.htmlMessage()+"</font><br>");
}
break;
case OUTPUT_QUIT: {
QString nick = ((IRCPerson *)output.getParam(0))->nick();
QListIterator<IRCChannelTab> it(m_channelTabs);
for (; it.current(); ++it) {
if (it.current()->list()->hasPerson(nick)) {
- it.current()->appendText("<font color=\"#aa3e00\">"+output.message()+"</font><br>");
+ it.current()->appendText("<font color=\"#aa3e00\">"+output.htmlMessage()+"</font><br>");
it.current()->list()->update();
}
}
}
break;
case OUTPUT_OTHERJOIN:
case OUTPUT_OTHERKICK:
case OUTPUT_CHANPERSONMODE:
case OUTPUT_OTHERPART: {
IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0));
- channelTab->appendText("<font color=\"#aa3e00\">"+output.message()+"</font><br>");
+ channelTab->appendText("<font color=\"#aa3e00\">"+output.htmlMessage()+"</font><br>");
channelTab->list()->update();
}
break;
case OUTPUT_CTCP:
- appendText("<font color=\"#00bb00\">" + output.message() + "</font><br>");
+ appendText("<font color=\"#00bb00\">" + output.htmlMessage() + "</font><br>");
break;
case OUTPUT_ERROR:
- appendText("<font color=\"#ff0000\">" + output.message() + "</font><br>");
+ appendText("<font color=\"#ff0000\">" + output.htmlMessage() + "</font><br>");
break;
default:
- appendText("<font color=\"#0000dd\">" + output.message() + "</font><br>");
+ appendText("<font color=\"#0000dd\">" + output.htmlMessage() + "</font><br>");
break;
}
}
diff --git a/noncore/net/opieirc/ircservertab.h b/noncore/net/opieirc/ircservertab.h
index fa9a0a3..cfa0832 100644
--- a/noncore/net/opieirc/ircservertab.h
+++ b/noncore/net/opieirc/ircservertab.h
@@ -30,24 +30,27 @@ class IRCServerTab : public IRCTab {
Q_OBJECT
public:
/* IRCTab implementation */
IRCServerTab(IRCServer server, MainWindow *mainWindow, QWidget *parent = 0, const char *name = 0, WFlags f = 0);
~IRCServerTab();
QString title();
IRCSession *session();
IRCServer *server();
/* Start the server session */
void doConnect();
void removeChannelTab(IRCChannelTab *tab);
+
+ /* Execute a user command such as /join */
+ void executeCommand(IRCTab *tab, QString line);
protected:
void appendText(QString text);
IRCChannelTab *getTabForChannel(IRCChannel *channel);
public slots:
void remove();
void processCommand();
protected slots:
void display(IRCOutput output);
protected:
bool m_close;
IRCServer m_server;
IRCSession *m_session;
diff --git a/noncore/net/opieirc/ircsession.cpp b/noncore/net/opieirc/ircsession.cpp
index b81038f..89df68c 100644
--- a/noncore/net/opieirc/ircsession.cpp
+++ b/noncore/net/opieirc/ircsession.cpp
@@ -3,24 +3,28 @@
#include "ircversion.h"
IRCSession::IRCSession(IRCServer *server) {
m_server = server;
m_connection = new IRCConnection(m_server);
m_parser = new IRCMessageParser(this);
connect(m_connection, SIGNAL(messageArrived(IRCMessage *)), this, SLOT(handleMessage(IRCMessage *)));
connect(m_parser, SIGNAL(outputReady(IRCOutput)), this, SIGNAL(outputReady(IRCOutput)));
connect(m_connection, SIGNAL(outputReady(IRCOutput)), this, SIGNAL(outputReady(IRCOutput)));
}
IRCSession::~IRCSession() {
+ /* We want this to get deleted automatically */
+ m_channels.setAutoDelete(TRUE);
+ m_people.setAutoDelete(TRUE);
+
delete m_parser;
delete m_connection;
}
void IRCSession::beginSession() {
m_connection->doConnect();
}
void IRCSession::join(QString channelname) {
m_connection->sendLine("JOIN "+channelname);
}
diff --git a/noncore/net/opieirc/irctab.h b/noncore/net/opieirc/irctab.h
index 3124980..0ce9777 100644
--- a/noncore/net/opieirc/irctab.h
+++ b/noncore/net/opieirc/irctab.h
@@ -28,20 +28,21 @@
#include <qlayout.h>
#include "ircsession.h"
/* This is the base class for any tabs which need to be integrated into
the main GUI tab widget */
class IRCTab : public QWidget {
Q_OBJECT
public:
IRCTab(QWidget *parent = 0, const char *name = 0, WFlags f = 0);
virtual QString title() = 0;
virtual IRCSession *session() = 0;
+ virtual void appendText(QString text) = 0;
public slots:
virtual void remove() = 0;
protected:
QLabel *m_description;
QVBoxLayout *m_layout;
};
#endif /* __IRCTAB_H */
diff --git a/noncore/net/opieirc/ircversion.h b/noncore/net/opieirc/ircversion.h
index 0ef0d2f..f8510e6 100644
--- a/noncore/net/opieirc/ircversion.h
+++ b/noncore/net/opieirc/ircversion.h
@@ -12,16 +12,16 @@
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __IRCVERSION_H
#define __IRCVERSION_H
-#define APP_VERSION "OpieIRC 0.1"
+#define APP_VERSION "OpieIRC 0.2"
#define APP_COPYSTR "(c) 2002 by Wenzel Jakob"
#endif /* __IRCVERSION_H */