summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/opieirc/ircchannellist.cpp2
-rw-r--r--noncore/net/opieirc/ircchanneltab.cpp17
-rw-r--r--noncore/net/opieirc/ircchanneltab.h3
-rw-r--r--noncore/net/opieirc/ircmessage.cpp35
-rw-r--r--noncore/net/opieirc/ircmessage.h6
-rw-r--r--noncore/net/opieirc/ircmessageparser.cpp158
-rw-r--r--noncore/net/opieirc/ircmessageparser.h10
-rw-r--r--noncore/net/opieirc/ircserver.cpp13
-rw-r--r--noncore/net/opieirc/ircservereditor.cpp8
-rw-r--r--noncore/net/opieirc/ircservertab.cpp39
-rw-r--r--noncore/net/opieirc/ircservertab.h1
-rw-r--r--noncore/net/opieirc/ircsession.cpp56
-rw-r--r--noncore/net/opieirc/ircsession.h7
13 files changed, 276 insertions, 79 deletions
diff --git a/noncore/net/opieirc/ircchannellist.cpp b/noncore/net/opieirc/ircchannellist.cpp
index 6bef318..c32c535 100644
--- a/noncore/net/opieirc/ircchannellist.cpp
+++ b/noncore/net/opieirc/ircchannellist.cpp
@@ -58,8 +58,8 @@ void IRCChannelList::adjustNicks() {
insertItem(pm, txt, i);
}
else {
removeItem(i);
- insertItem(txt,i);
+ insertItem(txt, i);
}
}
}
diff --git a/noncore/net/opieirc/ircchanneltab.cpp b/noncore/net/opieirc/ircchanneltab.cpp
index 581f9a5..4a35929 100644
--- a/noncore/net/opieirc/ircchanneltab.cpp
+++ b/noncore/net/opieirc/ircchanneltab.cpp
@@ -1,12 +1,15 @@
#include <qpe/resource.h>
#include <qwhatsthis.h>
#include <qhbox.h>
+#include <qdict.h>
#include "ircchanneltab.h"
#include "ircservertab.h"
#include "ircmessageparser.h"
+QDict<QString> IRCChannelTab::m_queuedMessages (17);
+
IRCChannelTab::IRCChannelTab(IRCChannel *channel, IRCServerTab *parentTab, MainWindow *mainWindow, QWidget *parent, const char *name, WFlags f) : IRCTab(parent, name, f) {
m_mainWindow = mainWindow;
m_parentTab = parentTab;
m_channel = channel;
@@ -52,8 +55,14 @@ IRCChannelTab::IRCChannelTab(IRCChannel *channel, IRCServerTab *parentTab, MainW
connect(m_field, SIGNAL(returnPressed()), this, SLOT(processCommand()));
connect(m_list, SIGNAL(doubleClicked ( QListBoxItem * ) ), this, SLOT(popupQuery( QListBoxItem * ) ));
settingsChanged();
+
+ if(m_queuedMessages[m_channel->channelname()]) {
+ appendText(*m_queuedMessages[m_channel->channelname()]);
+ delete m_queuedMessages[m_channel->channelname()];
+ m_queuedMessages.remove(m_channel->channelname());
+ }
}
void IRCChannelTab::scrolling(){
m_textview->ensureVisible(0, m_textview->contentsHeight());
@@ -181,11 +190,19 @@ void IRCChannelTab::remove() {
m_mainWindow->killTab(this);
}
}
+void IRCChannelTab::enqueue(const QString &channel, const QString &message) {
+ if (m_queuedMessages.count() == (m_queuedMessages.size() - 1) )
+ /* 17 messages max */
+ return;
+ m_queuedMessages.insert(channel, new QString(message));
+}
+
IRCChannel *IRCChannelTab::channel() {
return m_channel;
}
IRCChannelList *IRCChannelTab::list() {
return m_list;
}
+
diff --git a/noncore/net/opieirc/ircchanneltab.h b/noncore/net/opieirc/ircchanneltab.h
index 70b212c..ffd1d5f 100644
--- a/noncore/net/opieirc/ircchanneltab.h
+++ b/noncore/net/opieirc/ircchanneltab.h
@@ -30,8 +30,9 @@
#include "ircchannellist.h"
#define LISTWIDTH 70
+template <class T> class QDict;
class IRCServerTab;
class IRCChannelTab : public IRCTab {
Q_OBJECT
public:
@@ -43,8 +44,9 @@ public:
IRCChannel *channel();
IRCChannelList *list();
public:
void appendText(QString text);
+ static void enqueue(const QString &channel, const QString &message);
public slots:
void remove();
void settingsChanged();
void scrolling();
@@ -69,7 +71,8 @@ protected:
IRCHistoryLineEdit *m_field;
QPopupMenu *m_popup;
bool m_listVisible;
int m_lines;
+ static QDict<QString> m_queuedMessages;
};
#endif /* __IRCCHANNELTAB_H */
diff --git a/noncore/net/opieirc/ircmessage.cpp b/noncore/net/opieirc/ircmessage.cpp
index d823ad1..d0b2652 100644
--- a/noncore/net/opieirc/ircmessage.cpp
+++ b/noncore/net/opieirc/ircmessage.cpp
@@ -1,5 +1,8 @@
#include <qtextstream.h>
+#include <qstring.h>
+#include <qstringlist.h>
+
#include "ircmessage.h"
/*
* Create a new IRCMessage by evaluating
@@ -63,10 +66,10 @@ IRCMessage::IRCMessage(QString line) {
} else {
m_ctcp = FALSE;
}
- /*
- -- Uncomment to debug --
+ /*
+ //-- Uncomment to debug --
printf("Parsed : '%s'\n", line.ascii());
printf("Prefix : '%s'\n", m_prefix.ascii());
printf("Command : '%s'\n", m_command.ascii());
@@ -75,16 +78,42 @@ IRCMessage::IRCMessage(QString line) {
printf("Parameter %i : '%s'\n", i, m_parameters[i].ascii());
}
printf("CTCP Command : '%s'\n", m_ctcpCommand.latin1());
printf("CTCP Destination : '%s'\n", m_ctcpDestination.latin1());
- printf("CTCP param count is : '%i'\n", m_parameters.count());
+ printf("CTCP param count is : '%i'\n", m_parameters.count());
+
*/
}
QString IRCMessage::param(int param) {
return m_parameters[param];
}
+QStringList IRCMessage::params(const QString &paramstring) const {
+ QStringList params, retvalue;
+ params = QStringList::split(',', paramstring);
+ QStringList::Iterator end = params.end();
+
+ for (QStringList::Iterator it = params.begin(); it != end; ++it) {
+ int pos = (*it).find(':');
+ if(pos < 0) {
+ if((*it).toInt() < m_parameters.count())
+ retvalue << m_parameters[(*it).toInt()];
+ }
+
+ else {
+ int start, end;
+ start = (*it).left(pos).toInt();
+ end = (*it).mid(pos+1).toInt();
+ for (int i=start;i<=end && i < m_parameters.count() ;++i) {
+ retvalue << m_parameters[i];
+ }
+ }
+ }
+
+ return retvalue;
+}
+
QString IRCMessage::prefix() {
return m_prefix;
}
diff --git a/noncore/net/opieirc/ircmessage.h b/noncore/net/opieirc/ircmessage.h
index 0c5c879..10ba450 100644
--- a/noncore/net/opieirc/ircmessage.h
+++ b/noncore/net/opieirc/ircmessage.h
@@ -20,10 +20,10 @@
#ifndef __IRCMESSAGE_H
#define __IRCMESSAGE_H
-#include <qstring.h>
-#include <qstringlist.h>
+class QString;
+class QStringList;
/* IRCMessage objects are used to encapsulate information
which the IRC server sent to us. */
@@ -51,8 +51,10 @@ public:
/* Return the complete parameter string */
QString allParameters();
/* Return one parameter */
QString param(int param);
+ /* Return some parameters */
+ QStringList params(const QString &paramstring) const;
protected:
QString m_prefix;
QString m_command;
QString m_ctcpCommand;
diff --git a/noncore/net/opieirc/ircmessageparser.cpp b/noncore/net/opieirc/ircmessageparser.cpp
index f8ccbb6..fde156c 100644
--- a/noncore/net/opieirc/ircmessageparser.cpp
+++ b/noncore/net/opieirc/ircmessageparser.cpp
@@ -1,5 +1,7 @@
#include <qtextstream.h>
+#include <qdatetime.h>
+
#include "ircmessageparser.h"
#include "ircversion.h"
/* Lookup table for literal commands */
@@ -26,38 +28,57 @@ IRCCTCPMessageParserStruct IRCMessageParser::ctcpParserProcTable[] = {
{ "ACTION", FUNC(parseCTCPAction) },
{ 0 , 0 }
};
-/* Lookup table for numerical commands */
+/* Lookup table for numerical commands
+ * According to:
+ * http://www.faqs.org/rfcs/rfc1459.html
+ * http://www.faqs.org/rfcs/rfc2812.html
+*/
+
IRCNumericalMessageParserStruct IRCMessageParser::numericalParserProcTable[] = {
- { 1, FUNC(parseNumericalSecondParam) }, // RPL_WELCOME
- { 2, FUNC(parseNumericalSecondParam) }, // RPL_YOURHOST
- { 3, FUNC(parseNumericalSecondParam) }, // RPL_CREATED
- { 4, FUNC(parseNumericalAllParams) }, // RPL_MYINFO
- { 5, FUNC(parseNumericalSecondParam) }, // RPL_BOUNCE, RPL_PROTOCTL
- { 250, FUNC(parseNumericalAllParams) }, // RPL_STATSCONN
- { 251, FUNC(parseNumericalSecondParam) }, // RPL_LUSERCLIENT
- { 252, FUNC(parseNumericalAllParams) }, // RPL_LUSEROP
- { 253, FUNC(parseNumericalAllParams) }, // RPL_LUSERUNKNOWN
- { 254, FUNC(parseNumericalAllParams) }, // RPL_LUSERCHANNELS
- { 255, FUNC(parseNumericalSecondParam) }, // RPL_LUSERME
- { 265, FUNC(parseNumericalAllParams) }, // RPL_LOCALUSERS
- { 266, FUNC(parseNumericalAllParams) }, // RPL_GLOBALUSERS
- { 332, FUNC(parseNumericalTopic) }, // RPL_TOPIC
- { 333, FUNC(parseNumericalTopicWhoTime) }, // RPL_TOPICWHOTIME
- { 353, FUNC(parseNumericalNames) }, // RPL_NAMREPLY
- { 366, FUNC(parseNumericalEndOfNames) }, // RPL_ENDOFNAMES
- { 372, FUNC(parseNumericalSecondParam) }, // RPL_MOTD
- { 375, FUNC(parseNumericalSecondParam) }, // RPL_MOTDSTART
- { 376, FUNC(parseNumericalSecondParam) }, // RPL_ENDOFMOTD
- { 377, FUNC(parseNumericalSecondParam) }, // RPL_MOTD2
- { 378, FUNC(parseNumericalSecondParam) }, // RPL_MOTD3
- { 401, FUNC(parseNumericalNoSuchNick) }, // ERR_NOSUCHNICK
- { 406, FUNC(parseNumericalNoSuchNick) }, // ERR_WASNOSUCHNICK
- { 412, FUNC(parseNumericalSecondParam) }, // ERR_NOTEXTTOSEND
- { 422, FUNC(parseNumericalSecondParam) }, // ERR_NOMOTD
- { 433, FUNC(parseNumericalNicknameInUse) }, // ERR_NICKNAMEINUSE
- { 0, 0 }
+ { 1, "%1", "1", FUNC(parseNumericalServerName) }, // RPL_WELCOME
+ { 2, "%1", "1", 0 }, // RPL_YOURHOST
+ { 3, "%1", "1", 0 }, // RPL_CREATED
+ { 4, QT_TR_NOOP("Server %1 version %2 supports usermodes '%3' and channelmodes '%4'"), "1:4", FUNC(parseNumericalServerFeatures) }, // RPL_MYINFO
+ { 5, 0, 0, FUNC(parseNumericalServerProtocol) }, // RPL_BOUNCE, RPL_PROTOCTL
+ { 250, "%1", "1", 0 }, // RPL_STATSCONN
+ { 251, "%1", "1", 0 }, // RPL_LUSERCLIENT
+ { 252, QT_TR_NOOP("There are %1 operators connected"), "1", 0 }, // RPL_LUSEROP
+ { 253, QT_TR_NOOP("There are %1 unknown connection(s)"), "1", 0 }, // RPL_LUSERUNKNOWN
+ { 254, QT_TR_NOOP("There are %1 channels formed"), "1", 0 }, // RPL_LUSERCHANNELS
+ { 255, "%1", "1", 0 }, // RPL_LUSERME
+ { 263, QT_TR_NOOP("Please wait a while and try again"), 0, 0 }, // RPL_TRYAGAIN
+ { 265, "%1", "1", 0 }, // RPL_LOCALUSERS
+ { 266, "%1", "1", 0 }, // RPL_GLOBALUSERS
+ { 311, QT_TR_NOOP("Whois %1 (%2@%3)\nReal name: %4"), "1:3,5" }, // RPL_WHOISUSER
+ { 312, QT_TR_NOOP("%1 is using server %2"), "1,2", 0 }, // RPL_WHOISSERVER
+ { 317, 0, 0, FUNC(parseNumericalWhoisIdle) }, // RPL_WHOISIDLE
+ { 318, "%1 :%2", "1,2", 0 }, // RPL_ENDOFWHOIS
+ { 320, "%1 %2", "1,2", 0}, // RPL_WHOISVIRT
+ { 332, 0, 0, FUNC(parseNumericalTopic) }, // RPL_TOPIC
+ { 333, 0, 0, FUNC(parseNumericalTopicWhoTime) }, // RPL_TOPICWHOTIME*/
+ { 353, QT_TR_NOOP("Names for %1: %2"), "2,3", FUNC(parseNumericalNames) }, // RPL_NAMREPLY
+ { 366, "%1 :%2", "1,2", FUNC(parseNumericalEndOfNames) }, // RPL_ENDOFNAMES
+ { 369, "%1 :%2", "1,2", 0 }, // RPL_ENDOFWHOWAS
+ { 372, "%1", "1", 0 }, // RPL_MOTD
+ { 375, "%1", "1", 0 }, // RPL_MOTDSTART
+ { 376, "%1", "1", 0 }, // RPL_ENDOFMOTD
+ { 377, "%1", "1", 0 }, // RPL_MOTD2
+ { 378, "%1", "1", 0 }, // RPL_MOTD3
+ { 391, QT_TR_NOOP("Time on server %1 is %2"), "1,2", 0 }, // RPL_TIME
+ { 401, QT_TR_NOOP("Channel or nick %1 doesn't exists"), "1", 0 }, // ERR_NOSUCHNICK
+ { 406, QT_TR_NOOP("There is no history information for %1"), "1" }, // ERR_WASNOSUCHNICK
+ { 409, "%1", "1", 0 }, // ERR_NOORIGIN
+ { 411, "%1", "1", 0 }, // ERR_NORECIPIENT
+ { 412, "%1", "1", 0 }, // ERR_NOTEXTTOSEND
+ { 421, QT_TR_NOOP("Unknown command: %1"), "1", 0 }, // ERR_NOMOTD
+ { 422, QT_TR_NOOP("You're not on channel %1"), "1", 0}, // ERR_NOTONCHANNEL
+ { 422, "%1", "1", 0 }, // ERR_NOMOTD
+ { 433, QT_TR_NOOP("Can't change nick to %1: %2"), "1,2", FUNC(parseNumericalNicknameInUse) }, // ERR_NICKNAMEINUSE
+ { 477, "%1", "1", 0 }, // ERR_NOCHANMODES || ERR_NEEDREGGEDNICK
+ { 482, QT_TR_NOOP("[%1] Operation not permitted, you don't have enough channel privileges"), "1", 0 }, //ERR_CHANOPRIVSNEEDED
+ { 0, 0, 0, 0 }
};
IRCMessageParser::IRCMessageParser(IRCSession *session) {
@@ -69,9 +90,9 @@ void IRCMessageParser::parse(IRCMessage *message) {
the parser tables. If no handler can be found, print out an error message */
if (message->isNumerical()) {
for (int i=0; i<numericalParserProcTable[i].commandNumber; i++) {
if (message->commandNumber() == numericalParserProcTable[i].commandNumber) {
- (this->*(numericalParserProcTable[i].proc))(message);
+ parseNumerical(message, i);
return;
}
}
emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received unhandled numeric command: %1").arg( QString::number(message->commandNumber()) )));
@@ -93,10 +114,52 @@ void IRCMessageParser::parse(IRCMessage *message) {
emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received unhandled literal command: %1").arg( message->command()) ));
}
}
-void IRCMessageParser::nullFunc(IRCMessage *) {
- /* Do nothing */
+void IRCMessageParser::parseNumerical(IRCMessage *message, int position) {
+ QString out = tr(numericalParserProcTable[position].message);
+ QString paramString = numericalParserProcTable[position].params;
+
+ if(!out.isEmpty() && !paramString.isEmpty()) {
+ QStringList params = message->params(numericalParserProcTable[position].params);
+
+ QStringList::Iterator end = params.end();
+ for (QStringList::Iterator it = params.begin(); it != end; ++it) {
+ out = out.arg(*it);
+ }
+
+ emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, out));
+ }
+
+ if(numericalParserProcTable[position].proc)
+ (this->*(numericalParserProcTable[position].proc))(message);
+}
+
+void IRCMessageParser::parseNumericalServerName(IRCMessage *message) {
+ emit outputReady(IRCOutput(OUTPUT_TITLE, tr("Connected to")+" <b>" + message->prefix() + "</b>"));
+}
+
+void IRCMessageParser::parseNumericalServerFeatures(IRCMessage *message) {
+ m_session->setValidUsermodes(message->param(2));
+ m_session->setValidChannelmodes(message->param(3));
+
+}
+
+void IRCMessageParser::parseNumericalServerProtocol(IRCMessage *message) {
+ /* XXX: Add some usefull features here */
+ QString out = message->allParameters();
+ out = out.mid(out.find(' ')+1);
+ emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, out));
+}
+void IRCMessageParser::parseNumericalWhoisIdle(IRCMessage *message) {
+ QDateTime dt;
+ QTime t;
+ t = t.addSecs(message->param(2).toInt());
+ dt.setTime_t(message->param(3).toInt());
+
+ emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, tr("%1 has been idle for %2").arg(message->param(1)).arg(t.toString())));
+ emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, tr("%1 signed on %2").arg(message->param(1)).arg(dt.toString())));
+
}
void IRCMessageParser::parseLiteralPing(IRCMessage *message) {
m_session->m_connection->sendLine("PONG " + message->allParameters());
@@ -208,24 +271,24 @@ void IRCMessageParser::parseLiteralPrivMsg(IRCMessage *message) {
}
}
void IRCMessageParser::parseLiteralNick(IRCMessage *message) {
-
IRCPerson mask(message->prefix());
- /* this way of handling nick changes really sucks */
+ m_session->updateNickname(mask.nick(), message->param(0));
+ /* this way of handling nick changes really sucks
if (mask.nick() == m_session->m_server->nick()) {
- /* We are changing our nickname */
+ We are changing our nickname
m_session->m_server->setNick(message->param(0));
IRCOutput output(OUTPUT_NICKCHANGE, tr("You are now known as %1").arg( message->param(0)));
output.addParam(0);
emit outputReady(output);
} else {
- /* Someone else is */
- IRCPerson *person = m_session->getPerson(mask.nick());
+ Someone else is
+ RCPerson *person = m_session->getPerson(mask.nick());
if (person) {
//IRCOutput output(OUTPUT_NICKCHANGE, tr("%1 is now known as %2").arg( mask.nick() ).arg( message->param(0)));
- /* new code starts here -- this removes the person from all channels */
+ new code starts here -- this removes the person from all channels
QList<IRCChannel> channels;
m_session->getChannelsByPerson(person, channels);
QListIterator<IRCChannel> it(channels);
for (;it.current(); ++it) {
@@ -236,13 +299,13 @@ void IRCMessageParser::parseLiteralNick(IRCMessage *message) {
IRCOutput output(OUTPUT_NICKCHANGE, tr("%1 is now known as %2").arg( mask.nick() ).arg( message->param(0)));
output.addParam(person);
emit outputReady(output);
}
- /* new code ends here */
+ new code ends here
} else {
emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Nickname change of an unknown person")));
}
- }
+ }*/
}
void IRCMessageParser::parseLiteralQuit(IRCMessage *message) {
IRCPerson mask(message->prefix());
@@ -323,9 +386,9 @@ void IRCMessageParser::parseCTCPPing(IRCMessage *message) {
}
void IRCMessageParser::parseCTCPVersion(IRCMessage *message) {
IRCPerson mask(message->prefix());
- m_session->m_connection->sendCTCP(mask.nick(), APP_VERSION " " APP_COPYSTR);
+ m_session->m_connection->sendCTCP(mask.nick(), "VERSION " APP_VERSION " " APP_COPYSTR);
emit outputReady(IRCOutput(OUTPUT_CTCP, tr("Received a CTCP VERSION from ")+mask.nick()));
}
void IRCMessageParser::parseCTCPAction(IRCMessage *message) {
@@ -462,17 +525,8 @@ void IRCMessageParser::parseLiteralKick(IRCMessage *message) {
emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown channel kick - desynchronized?")));
}
}
-
-void IRCMessageParser::parseNumericalSecondParam(IRCMessage *message) {
- emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, message->param(1)));
-}
-
-void IRCMessageParser::parseNumericalAllParams(IRCMessage *message) {
- emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, message->allParameters()));
-}
-
void IRCMessageParser::parseNumericalNames(IRCMessage *message) {
/* Name list sent when joining a channel */
IRCChannel *channel = m_session->getChannel(message->param(2).lower());
if (channel != 0) {
@@ -531,8 +585,12 @@ void IRCMessageParser::parseNumericalEndOfNames(IRCMessage *message) {
}
void IRCMessageParser::parseNumericalNicknameInUse(IRCMessage *) {
+ /* If we are connnected this error is not critical */
+ if(m_session->isLoggedIn())
+ return;
+
emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Nickname is in use, please reconnect with a different nickname")));
m_session->endSession();
}
diff --git a/noncore/net/opieirc/ircmessageparser.h b/noncore/net/opieirc/ircmessageparser.h
index 5412f5f..2fca61e 100644
--- a/noncore/net/opieirc/ircmessageparser.h
+++ b/noncore/net/opieirc/ircmessageparser.h
@@ -45,8 +45,10 @@ typedef struct IRCCTCPMessageParserStruct {
/* Struct representing a numerical command handler */
typedef struct IRCNumericalMessageParserStruct {
unsigned short commandNumber;
+ char *message;
+ char *params;
IRCMessageParseProc proc;
};
class IRCMessageParser : public QObject {
@@ -60,9 +62,8 @@ signals:
/* Used to send commands to the UI (such as displaying text etc) */
void outputReady(IRCOutput output);
private:
/* Parser functions */
- void nullFunc(IRCMessage *message);
void parseLiteralPing(IRCMessage *message);
void parseLiteralNotice(IRCMessage *message);
void parseLiteralJoin(IRCMessage *message);
void parseLiteralPrivMsg(IRCMessage *message);
@@ -72,10 +73,13 @@ private:
void parseLiteralError(IRCMessage *message);
void parseLiteralMode(IRCMessage *message);
void parseLiteralKick(IRCMessage *message);
void parseLiteralTopic(IRCMessage *message);
- void parseNumericalSecondParam(IRCMessage *message);
- void parseNumericalAllParams(IRCMessage *message);
+ void parseNumerical(IRCMessage *message, int position);
+ void parseNumericalServerName(IRCMessage *message);
+ void parseNumericalServerFeatures(IRCMessage *message);
+ void parseNumericalServerProtocol(IRCMessage *message);
+ void parseNumericalWhoisIdle(IRCMessage *message);
void parseNumericalNames(IRCMessage *message);
void parseNumericalEndOfNames(IRCMessage *message);
void parseNumericalNicknameInUse(IRCMessage *message);
void parseNumericalNoSuchNick(IRCMessage *message);
diff --git a/noncore/net/opieirc/ircserver.cpp b/noncore/net/opieirc/ircserver.cpp
index e27e41d..7e7e412 100644
--- a/noncore/net/opieirc/ircserver.cpp
+++ b/noncore/net/opieirc/ircserver.cpp
@@ -1,5 +1,8 @@
#include "ircserver.h"
+#include "ircversion.h"
+
+#include <qobject.h>
IRCServer::IRCServer() {
m_port = 6667;
}
@@ -48,9 +51,12 @@ QString IRCServer::name() {
return m_name;
}
unsigned short int IRCServer::port() {
- return m_port;
+ if(m_port)
+ return m_port;
+
+ return 6667;
}
QString IRCServer::username() {
return m_username;
@@ -64,9 +70,12 @@ QString IRCServer::nick() {
return m_nick;
}
QString IRCServer::realname() {
- return m_realname;
+ if(!m_realname.isEmpty())
+ return m_realname;
+
+ return QString(QObject::tr("Using")) + " " + QString(APP_VERSION);
}
QString IRCServer::channels() {
return m_channels;
diff --git a/noncore/net/opieirc/ircservereditor.cpp b/noncore/net/opieirc/ircservereditor.cpp
index 2d11bf0..1fda868 100644
--- a/noncore/net/opieirc/ircservereditor.cpp
+++ b/noncore/net/opieirc/ircservereditor.cpp
@@ -57,14 +57,14 @@ 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_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 if (m_realname->text().length()==0)
+ // QMessageBox::critical(this, tr("Error"), tr("Realname required"));
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) {
diff --git a/noncore/net/opieirc/ircservertab.cpp b/noncore/net/opieirc/ircservertab.cpp
index e031d4d..90353f2 100644
--- a/noncore/net/opieirc/ircservertab.cpp
+++ b/noncore/net/opieirc/ircservertab.cpp
@@ -16,9 +16,9 @@ IRCServerTab::IRCServerTab(IRCServer server, MainWindow *mainWindow, QWidget *pa
m_session = new IRCSession(&m_server);
m_mainWindow = mainWindow;
m_close = FALSE;
m_lines = 0;
- m_description->setText(tr("Connection to")+" <b>" + server.hostname() + ":" + QString::number(server.port()) + "</b>");
+ m_description->setText(tr("Connecting 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_textview->setTextFormat(RichText);
@@ -34,8 +34,9 @@ IRCServerTab::IRCServerTab(IRCServer server, MainWindow *mainWindow, QWidget *pa
m_layout->add(m_field);
connect(m_field, SIGNAL(returnPressed()), this, SLOT(processCommand()));
connect(m_session, SIGNAL(outputReady(IRCOutput)), this, SLOT(display(IRCOutput)));
connect(m_mainWindow, SIGNAL(updateScroll()), this, SLOT(scrolling()));
+ connect(m_session, SIGNAL(updateChannels()), this, SLOT(slotUpdateChannels()));
settingsChanged();
m_field->setFocus();
m_field->setActiveWindow();
@@ -112,9 +113,15 @@ void IRCServerTab::executeCommand(IRCTab *tab, QString line) {
//JOIN
if (command == "JOIN" || command == "J") {
QString channel;
stream >> channel;
- if (channel.length() > 0 && (channel.startsWith("#") || channel.startsWith("+"))) {
+ /* According to RFC 1459 */
+ if (channel.length() > 0 && channel.length() < 200 &&
+ channel.find(",") == -1 && channel.find("") == -1) {
+
+ if (!channel.startsWith("#") && !channel.startsWith("&")) {
+ channel = channel.prepend("#");
+ }
m_session->join(channel);
} else {
tab->appendText("<font color=\"" + m_errorColor + "\">Unknown channel format!</font><br>");
}
@@ -344,9 +351,9 @@ void IRCServerTab::display(IRCOutput output) {
channelTab->appendText("<font color=\"" + m_notificationColor + "\">"+output.htmlMessage()+"</font><br>");
return;
}
}
- appendText("<font color=\"" + m_notificationColor + "\">"+output.htmlMessage()+"</font><br>");
+ IRCChannelTab::enqueue(channel->channelname(), "<font color=\"" + m_notificationColor + "\">"+output.htmlMessage()+"</font><br>");
}
break;
case OUTPUT_QUIT: {
QString nick = ((IRCPerson *)output.getParam(0))->nick();
@@ -358,21 +365,24 @@ void IRCServerTab::display(IRCOutput output) {
}
}
}
break;
-/* case OUTPUT_NICKCHANGE: {
- //WAS HERE
- QString nick = ((IRCPerson *)output.getParam(0))->nick();
+ case OUTPUT_NICKCHANGE: {
+ QString *nick = static_cast<QString*>(output.getParam(0));
+ if(!nick) {
+ appendText("<font color=\"" + m_notificationColor + "\">"+output.htmlMessage()+"</font><br>");
+ break;
+ }
QListIterator<IRCChannelTab> it(m_channelTabs);
for (; it.current(); ++it) {
- if (it.current()->list()->hasPerson(nick)) {
+ if (it.current()->list()->hasPerson(*nick)) {
it.current()->appendText("<font color=\"" + m_notificationColor + "\">"+output.htmlMessage()+"</font><br>");
- it.current()->list()->update();
}
}
+ delete nick;
}
break;
- */ case OUTPUT_OTHERJOIN:
+ case OUTPUT_OTHERJOIN:
case OUTPUT_OTHERKICK:
case OUTPUT_CHANPERSONMODE:
case OUTPUT_OTHERPART: {
IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0));
@@ -385,9 +395,20 @@ void IRCServerTab::display(IRCOutput output) {
break;
case OUTPUT_ERROR:
appendText("<font color=\"" + m_errorColor + "\">" + output.htmlMessage() + "</font><br>");
break;
+ case OUTPUT_TITLE:
+ m_description->setText(output.message());
+ break;
default:
appendText("<font color=\"" + m_serverColor + "\">" + output.htmlMessage() + "</font><br>");
break;
}
}
+
+void IRCServerTab::slotUpdateChannels() {
+ QListIterator<IRCChannelTab> it(m_channelTabs);
+ for (; it.current(); ++it) {
+ it.current()->list()->update();
+ }
+}
+
diff --git a/noncore/net/opieirc/ircservertab.h b/noncore/net/opieirc/ircservertab.h
index 69543fc..42f6f57 100644
--- a/noncore/net/opieirc/ircservertab.h
+++ b/noncore/net/opieirc/ircservertab.h
@@ -61,8 +61,9 @@ public slots:
void scrolling();
void remove();
void processCommand();
void settingsChanged();
+ void slotUpdateChannels();
protected slots:
void display(IRCOutput output);
protected:
int m_lines;
diff --git a/noncore/net/opieirc/ircsession.cpp b/noncore/net/opieirc/ircsession.cpp
index 3b176d0..ca0df50 100644
--- a/noncore/net/opieirc/ircsession.cpp
+++ b/noncore/net/opieirc/ircsession.cpp
@@ -24,9 +24,9 @@ void IRCSession::beginSession() {
m_connection->doConnect();
}
void IRCSession::join(QString channelname) {
- m_connection->sendLine("JOIN "+channelname);
+ m_connection->sendLine("JOIN " + channelname);
}
void IRCSession::quit(){
m_connection->sendLine("QUIT :[OI] I'm too good to need a reason");
@@ -56,17 +56,17 @@ void IRCSession::raw(QString message){
m_connection->sendLine(message);
}
void IRCSession::kick(IRCChannel *channel, IRCPerson *person) {
- m_connection->sendLine("KICK "+ channel->channelname() + " " + person->nick() +" :0wn3d - no reason");
+ m_connection->sendLine("KICK " + channel->channelname() + " " + person->nick() +" :0wn3d - no reason");
}
void IRCSession::op(IRCChannel *channel, IRCPerson *person) {
- m_connection->sendLine("MODE "+ channel->channelname() + " +ooo " + person->nick());
+ m_connection->sendLine("MODE " + channel->channelname() + " +ooo " + person->nick());
}
void IRCSession::kick(IRCChannel *channel, IRCPerson *person, QString message) {
- m_connection->sendLine("KICK "+ channel->channelname() + " " + person->nick() +" :" + message);
+ m_connection->sendLine("KICK " + channel->channelname() + " " + person->nick() +" :" + message);
}
void IRCSession::sendMessage(IRCPerson *person, QString message) {
m_connection->sendLine("PRIVMSG " + person->nick() + " :" + message);
@@ -87,19 +87,65 @@ void IRCSession::sendAction(IRCPerson *person, QString message) {
bool IRCSession::isSessionActive() {
return m_connection->isConnected();
}
+bool IRCSession::isLoggedIn() {
+ return m_connection->isLoggedIn();
+}
+
void IRCSession::endSession() {
if (m_connection->isLoggedIn())
- m_connection->sendLine("QUIT :" APP_VERSION);
+ quit(APP_VERSION);
else
m_connection->close();
}
void IRCSession::part(IRCChannel *channel) {
m_connection->sendLine("PART " + channel->channelname() + " :" + APP_VERSION);
}
+void IRCSession::setValidUsermodes(const QString &modes) {
+ m_validUsermodes = modes;
+}
+
+void IRCSession::setValidChannelmodes(const QString &modes) {
+ m_validChannelmodes = modes;
+}
+
+void IRCSession::updateNickname(const QString &oldNickname, const QString &newNickname) {
+ QList<IRCChannel> channels;
+ IRCOutput output;
+
+ if (oldNickname == m_server->nick()) {
+ m_server->setNick(newNickname);
+ output = IRCOutput(OUTPUT_NICKCHANGE, tr("You are now known as %1").arg(newNickname));
+ channels = m_channels;
+ }
+
+ else {
+ IRCPerson *person = getPerson(oldNickname);
+
+ if(!person) {
+ emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Nickname change of an unknown person")));
+ return;
+ }
+
+ getChannelsByPerson(person, channels);
+ output = IRCOutput(OUTPUT_NICKCHANGE, tr("%1 is now known as %2").arg(oldNickname).arg(newNickname));
+ }
+
+ QListIterator<IRCChannel> it(channels);
+ for (;it.current(); ++it) {
+ IRCChannelPerson *chanperson = it.current()->getPerson(oldNickname);
+ it.current()->removePerson(chanperson);
+ chanperson->person->setNick(newNickname);
+ it.current()->addPerson(chanperson);
+ }
+
+ emit updateChannels();
+ output.addParam(new QString(newNickname));
+ emit outputReady(output);
+}
IRCChannel *IRCSession::getChannel(QString channelname) {
QListIterator<IRCChannel> it(m_channels);
for (; it.current(); ++it) {
diff --git a/noncore/net/opieirc/ircsession.h b/noncore/net/opieirc/ircsession.h
index f6330d8..96de3e4 100644
--- a/noncore/net/opieirc/ircsession.h
+++ b/noncore/net/opieirc/ircsession.h
@@ -56,12 +56,16 @@ public:
void kick(IRCChannel *channel, IRCPerson *person, QString message);
void beginSession();
bool isSessionActive();
void endSession();
+ bool isLoggedIn();
void sendMessage(IRCPerson *person, QString message);
void sendMessage(IRCChannel *channel, QString message);
void sendAction(IRCPerson *person, QString message);
void sendAction(IRCChannel *channel, QString message);
+ void updateNickname(const QString &oldNickname, const QString &newNickname);
+ void setValidUsermodes(const QString &modes);
+ void setValidChannelmodes(const QString &modes);
IRCChannel *getChannel(QString channelname);
IRCPerson *getPerson(QString nickname);
protected:
void addPerson(IRCPerson *person);
@@ -72,13 +76,16 @@ protected:
protected slots:
void handleMessage(IRCMessage *message);
signals:
void outputReady(IRCOutput output);
+ void updateChannels();
protected:
IRCServer *m_server;
IRCConnection *m_connection;
IRCMessageParser *m_parser;
QList<IRCChannel> m_channels;
QList<IRCPerson> m_people;
+ QString m_validUsermodes;
+ QString m_validChannelmodes;
};
#endif /* __IRCSESSION_H */