summaryrefslogtreecommitdiff
authorwazlaf <wazlaf>2002-09-21 23:59:08 (UTC)
committer wazlaf <wazlaf>2002-09-21 23:59:08 (UTC)
commitd60625b5551f26cdc35f7b2497ab538de859537d (patch) (side-by-side diff)
tree998c8d2e1f12a9c7ab9b55fa578f93d1a178ade6
parent54238c669808ceccaa6fb0ab0dcbf4565b370196 (diff)
downloadopie-d60625b5551f26cdc35f7b2497ab538de859537d.zip
opie-d60625b5551f26cdc35f7b2497ab538de859537d.tar.gz
opie-d60625b5551f26cdc35f7b2497ab538de859537d.tar.bz2
query windows and basic commands such as /me, /msg
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/opieirc/ircchanneltab.cpp7
-rw-r--r--noncore/net/opieirc/ircmessage.cpp1
-rw-r--r--noncore/net/opieirc/ircmessageparser.cpp10
-rw-r--r--noncore/net/opieirc/ircmessageparser.h1
-rw-r--r--noncore/net/opieirc/ircperson.cpp6
-rw-r--r--noncore/net/opieirc/ircperson.h3
-rw-r--r--noncore/net/opieirc/ircquerytab.cpp76
-rw-r--r--noncore/net/opieirc/ircquerytab.h27
-rw-r--r--noncore/net/opieirc/ircservertab.cpp54
-rw-r--r--noncore/net/opieirc/ircservertab.h7
10 files changed, 182 insertions, 10 deletions
diff --git a/noncore/net/opieirc/ircchanneltab.cpp b/noncore/net/opieirc/ircchanneltab.cpp
index 3267525..4675265 100644
--- a/noncore/net/opieirc/ircchanneltab.cpp
+++ b/noncore/net/opieirc/ircchanneltab.cpp
@@ -11,12 +11,13 @@ IRCChannelTab::IRCChannelTab(IRCChannel *channel, IRCServerTab *parentTab, MainW
m_textview = new QTextView(hbox);
m_textview->setHScrollBarMode(QScrollView::AlwaysOff);
m_textview->setVScrollBarMode(QScrollView::AlwaysOn);
m_listVisible = TRUE;
m_listButton = new QPushButton(">", m_textview);
m_textview->setCornerWidget(m_listButton);
+ m_textview->setTextFormat(RichText);
connect(m_listButton, SIGNAL(clicked()), this, SLOT(toggleList()));
m_list = new IRCChannelList(m_channel, hbox);
m_list->update();
m_list->setMaximumWidth(LISTWIDTH);
m_field = new QLineEdit(this);
m_layout->add(hbox);
@@ -44,16 +45,14 @@ void IRCChannelTab::processCommand() {
if (text.startsWith("/") && !text.startsWith("//")) {
/* Command mode */
m_parentTab->executeCommand(this, text);;
} else {
if (text.startsWith("//"))
text = text.right(text.length()-1);
- if (session()->isSessionActive()) {
- session()->sendMessage(m_channel, m_field->text());
- appendText("&lt;<font color=\"#dd0000\">"+m_parentTab->server()->nick()+"</font>&gt; "+IRCOutput::toHTML(m_field->text())+"<br>");
- }
+ session()->sendMessage(m_channel, m_field->text());
+ appendText("&lt;<font color=\"#dd0000\">"+m_parentTab->server()->nick()+"</font>&gt; "+IRCOutput::toHTML(m_field->text())+"<br>");
}
} else {
appendText("<font color=\"#ff0000\">"+tr("Disconnected")+"</font><br>");
}
}
m_field->clear();
diff --git a/noncore/net/opieirc/ircmessage.cpp b/noncore/net/opieirc/ircmessage.cpp
index 9c2869c..d823ad1 100644
--- a/noncore/net/opieirc/ircmessage.cpp
+++ b/noncore/net/opieirc/ircmessage.cpp
@@ -74,13 +74,12 @@ IRCMessage::IRCMessage(QString line) {
for (unsigned int i=0; i<m_parameters.count(); i++) {
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());
-
*/
}
QString IRCMessage::param(int param) {
return m_parameters[param];
}
diff --git a/noncore/net/opieirc/ircmessageparser.cpp b/noncore/net/opieirc/ircmessageparser.cpp
index 4038673..3063741 100644
--- a/noncore/net/opieirc/ircmessageparser.cpp
+++ b/noncore/net/opieirc/ircmessageparser.cpp
@@ -41,13 +41,15 @@ IRCNumericalMessageParserStruct IRCMessageParser::numericalParserProcTable[] = {
{ 366, FUNC(parseNumericalEndOfNames) }, // RPL_ENDOFNAMES
{ 375, FUNC(parseNumericalStats) }, // RPL_MOTDSTART
{ 372, FUNC(parseNumericalStats) }, // RPL_MOTD
{ 376, FUNC(parseNumericalStats) }, // RPL_ENDOFMOTD
{ 377, FUNC(parseNumericalStats) }, // RPL_MOTD2
{ 378, FUNC(parseNumericalStats) }, // RPL_MOTD3
- { 412, FUNC(parseNumericalStats) }, // ERNOTEXTTOSEND
+ { 401, FUNC(parseNumericalNoSuchNick) }, // ERR_NOSUCHNICK
+ { 406, FUNC(parseNumericalNoSuchNick) }, // ERR_WASNOSUCHNICK
+ { 412, FUNC(parseNumericalStats) }, // ERR_NOTEXTTOSEND
{ 433, FUNC(parseNumericalNicknameInUse) }, // ERR_NICKNAMEINUSE
{ 0, 0 }
};
IRCMessageParser::IRCMessageParser(IRCSession *session) {
m_session = session;
@@ -169,13 +171,13 @@ void IRCMessageParser::parseLiteralPrivMsg(IRCMessage *message) {
IRCPerson *person = m_session->getPerson(mask.nick());
if (!person) {
/* Person not yet known, create and add to the current session */
person = new IRCPerson(message->prefix());
m_session->addPerson(person);
}
- IRCOutput output(OUTPUT_CHANPRIVMSG, message->param(1));
+ IRCOutput output(OUTPUT_QUERYPRIVMSG, message->param(1));
output.addParam(person);
emit outputReady(output);
} else if (message->param(0).at(0) == '#') {
/* IRC Channel message detected, verify sender, channel and display it */
IRCChannel *channel = m_session->getChannel(message->param(0));
if (channel) {
@@ -476,6 +478,10 @@ void IRCMessageParser::parseNumericalEndOfNames(IRCMessage *message) {
void IRCMessageParser::parseNumericalNicknameInUse(IRCMessage *) {
emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Nickname is in use, please reconnect with a different nickname")));
m_session->endSession();
}
+
+void IRCMessageParser::parseNumericalNoSuchNick(IRCMessage *) {
+ emit outputReady(IRCOutput(OUTPUT_ERROR, tr("No such nickname")));
+}
diff --git a/noncore/net/opieirc/ircmessageparser.h b/noncore/net/opieirc/ircmessageparser.h
index b45b8f0..f774047 100644
--- a/noncore/net/opieirc/ircmessageparser.h
+++ b/noncore/net/opieirc/ircmessageparser.h
@@ -78,12 +78,13 @@ private:
void parseNumerical004(IRCMessage *message);
void parseNumerical005(IRCMessage *message);
void parseNumericalStats(IRCMessage *message);
void parseNumericalNames(IRCMessage *message);
void parseNumericalEndOfNames(IRCMessage *message);
void parseNumericalNicknameInUse(IRCMessage *message);
+ void parseNumericalNoSuchNick(IRCMessage *message);
void parseCTCPPing(IRCMessage *message);
void parseCTCPVersion(IRCMessage *message);
void parseCTCPAction(IRCMessage *message);
protected:
IRCSession *m_session;
/* Parser tables */
diff --git a/noncore/net/opieirc/ircperson.cpp b/noncore/net/opieirc/ircperson.cpp
index bd6b8d6..bd341f1 100644
--- a/noncore/net/opieirc/ircperson.cpp
+++ b/noncore/net/opieirc/ircperson.cpp
@@ -4,12 +4,18 @@
IRCPerson::IRCPerson() {
m_nick = "";
m_user = "";
m_host = "";
}
+IRCPerson::IRCPerson(const IRCPerson &person) {
+ m_nick = person.m_nick;
+ m_user = person.m_user;
+ m_host = person.m_host;
+}
+
IRCPerson::IRCPerson(QString mask) {
IRCPerson();
fromMask(mask);
}
void IRCPerson::fromMask(QString mask) {
diff --git a/noncore/net/opieirc/ircperson.h b/noncore/net/opieirc/ircperson.h
index 850f91b..38732c4 100644
--- a/noncore/net/opieirc/ircperson.h
+++ b/noncore/net/opieirc/ircperson.h
@@ -28,13 +28,16 @@
IRCMessage-prefixes too
*/
class IRCPerson {
public:
IRCPerson();
+ /* Create an IRCPerson from an IRC style description (nick!user@host) */
IRCPerson(QString mask);
+ /* Copy constructor */
+ IRCPerson(const IRCPerson &person);
void fromMask(QString mask);
void setNick(QString name);
void setUser(QString user);
void setHost(QString host);
QString toMask();
diff --git a/noncore/net/opieirc/ircquerytab.cpp b/noncore/net/opieirc/ircquerytab.cpp
index 6d24845..642cc5b 100644
--- a/noncore/net/opieirc/ircquerytab.cpp
+++ b/noncore/net/opieirc/ircquerytab.cpp
@@ -1,2 +1,78 @@
+#include <qhbox.h>
#include "ircquerytab.h"
+#include "ircservertab.h"
+
+IRCQueryTab::IRCQueryTab(IRCPerson *person, IRCServerTab *parentTab, MainWindow *mainWindow, QWidget *parent, const char *name, WFlags f) : IRCTab(parent, name, f) {
+ m_mainWindow = mainWindow;
+ m_parentTab = parentTab;
+ m_person = new IRCPerson(*person); /* We need this (the person might sign off and the original IRCPerson gets deleted) */
+ m_description->setText(tr("Talking to ") + " <b>" + person->nick() + "</b>");
+ QHBox *hbox = new QHBox(this);
+ m_textview = new QTextView(hbox);
+ m_textview->setHScrollBarMode(QScrollView::AlwaysOff);
+ m_textview->setVScrollBarMode(QScrollView::AlwaysOn);
+ m_textview->setTextFormat(RichText);
+ m_field = new QLineEdit(this);
+ m_layout->add(hbox);
+ hbox->show();
+ m_layout->add(m_field);
+ m_field->setFocus();
+ connect(m_field, SIGNAL(returnPressed()), this, SLOT(processCommand()));
+
+}
+
+void IRCQueryTab::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());
+}
+
+IRCQueryTab::~IRCQueryTab() {
+ m_parentTab->removeQueryTab(this);
+ delete m_person;
+}
+
+void IRCQueryTab::processCommand() {
+ 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 (text.startsWith("//"))
+ text = text.right(text.length()-1);
+ session()->sendMessage(m_person, m_field->text());
+ appendText("&lt;<font color=\"#dd0000\">"+m_parentTab->server()->nick()+"</font>&gt; "+IRCOutput::toHTML(m_field->text())+"<br>");
+ }
+ } else {
+ appendText("<font color=\"#ff0000\">"+tr("Disconnected")+"</font><br>");
+ }
+ }
+ m_field->clear();
+}
+
+void IRCQueryTab::display(IRCOutput output) {
+ if (output.type() == OUTPUT_QUERYPRIVMSG) {
+ appendText("&lt;<font color=\"#0000dd\">"+m_person->nick()+"</font>&gt; " + output.htmlMessage() + "<br>");
+ } else if (output.type() == OUTPUT_QUERYACTION) {
+ appendText("<font color=\"#0000dd\">" + output.htmlMessage() + "<br>");
+ }
+}
+
+QString IRCQueryTab::title() {
+ return m_person->nick();
+}
+
+IRCSession *IRCQueryTab::session() {
+ return m_parentTab->session();
+}
+
+void IRCQueryTab::remove() {
+ m_mainWindow->killTab(this);
+}
+
+IRCPerson *IRCQueryTab::person() {
+ return m_person;
+}
diff --git a/noncore/net/opieirc/ircquerytab.h b/noncore/net/opieirc/ircquerytab.h
index fac976d..ea777f4 100644
--- a/noncore/net/opieirc/ircquerytab.h
+++ b/noncore/net/opieirc/ircquerytab.h
@@ -18,7 +18,34 @@
*/
#ifndef __IRCQUERYTAB_H
#define __IRCQUERYTAB_H
+#include "ircsession.h"
+#include "mainwindow.h"
+
+class IRCServerTab;
+class IRCQueryTab : public IRCTab {
+ Q_OBJECT
+public:
+ /* IRCTab implementation */
+ IRCQueryTab(IRCPerson *person, IRCServerTab *parentTab, MainWindow *mainWindow, QWidget *parent = 0, const char *name = 0, WFlags f = 0);
+ ~IRCQueryTab();
+ QString title();
+ IRCSession *session();
+ IRCPerson *person();
+ void appendText(QString text);
+public slots:
+ void remove();
+ void processCommand();
+ void display(IRCOutput output);
+protected:
+ bool m_close;
+ MainWindow *m_mainWindow;
+ IRCServerTab *m_parentTab;
+ IRCPerson *m_person;
+ QTextView *m_textview;
+ QLineEdit *m_field;
+};
+
#endif /* __IRCQUERYTAB_H */
diff --git a/noncore/net/opieirc/ircservertab.cpp b/noncore/net/opieirc/ircservertab.cpp
index 503a758..8b8771f 100644
--- a/noncore/net/opieirc/ircservertab.cpp
+++ b/noncore/net/opieirc/ircservertab.cpp
@@ -8,12 +8,13 @@ IRCServerTab::IRCServerTab(IRCServer server, MainWindow *mainWindow, QWidget *pa
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_textview->setTextFormat(RichText);
m_layout->add(m_textview);
m_field = new QLineEdit(this);
m_layout->add(m_field);
connect(m_field, SIGNAL(returnPressed()), this, SLOT(processCommand()));
m_field->setFocus();
connect(m_session, SIGNAL(outputReady(IRCOutput)), this, SLOT(display(IRCOutput)));
@@ -30,12 +31,16 @@ IRCServerTab::~IRCServerTab() {
}
void IRCServerTab::removeChannelTab(IRCChannelTab *tab) {
m_channelTabs.remove(tab);
}
+void IRCServerTab::removeQueryTab(IRCQueryTab *tab) {
+ m_queryTabs.remove(tab);
+}
+
QString IRCServerTab::title() {
return "Server";
}
IRCSession *IRCServerTab::session() {
return m_session;
@@ -57,22 +62,36 @@ void IRCServerTab::executeCommand(IRCTab *tab, QString line) {
if (channel.length() > 0 && channel.startsWith("#")) {
m_session->join(channel);
} else {
tab->appendText("<font color=\"#ff0000\">Unknown channel format!</font><br>");
}
} else if (command == "ME") {
- QString text = IRCOutput::toHTML(line.right(line.length()-4));
+ QString text = line.right(line.length()-4);
if (text.length() > 0) {
if (tab->isA("IRCChannelTab")) {
- tab->appendText("<font color=\"#cc0000\">*" + m_server.nick() + " " + text + "</font><br>");
+ tab->appendText("<font color=\"#cc0000\">*" + IRCOutput::toHTML(m_server.nick()) + " " + IRCOutput::toHTML(text) + "</font><br>");
m_session->sendAction(((IRCChannelTab *)tab)->channel(), text);
} else if (tab->isA("IRCQueryTab")) {
+ tab->appendText("<font color=\"#cc0000\">*" + IRCOutput::toHTML(m_server.nick()) + " " + IRCOutput::toHTML(text) + "</font><br>");
+ m_session->sendAction(((IRCQueryTab *)tab)->person(), text);
} else {
tab->appendText("<font color=\"#ff0000\">Invalid tab for this command</font><br>");
}
}
+ } else if (command == "MSG") {
+ QString nickname;
+ stream >> nickname;
+ if (nickname.length() > 0) {
+ if (line.length() > 6 + nickname.length()) {
+ QString text = line.right(line.length()-nickname.length()-6);
+ IRCPerson person;
+ person.setNick(nickname);
+ tab->appendText("&gt;<font color=\"#0000dd\">"+IRCOutput::toHTML(nickname)+"</font>&lt; "+IRCOutput::toHTML(text)+"<br>");
+ m_session->sendMessage(&person, text);
+ }
+ }
} else {
tab->appendText("<font color=\"#ff0000\">Unknown command</font><br>");
}
}
void IRCServerTab::processCommand() {
@@ -97,12 +116,16 @@ void IRCServerTab::remove() {
} else {
/* Session has previously been closed */
m_channelTabs.first();
while (m_channelTabs.current() != 0) {
m_mainWindow->killTab(m_channelTabs.current());
}
+ m_queryTabs.first();
+ while (m_queryTabs.current() != 0) {
+ m_mainWindow->killTab(m_queryTabs.current());
+ }
m_mainWindow->killTab(this);
}
}
IRCChannelTab *IRCServerTab::getTabForChannel(IRCChannel *channel) {
QListIterator<IRCChannelTab> it(m_channelTabs);
@@ -111,22 +134,36 @@ IRCChannelTab *IRCServerTab::getTabForChannel(IRCChannel *channel) {
if (it.current()->channel() == channel)
return it.current();
}
return 0;
}
+IRCQueryTab *IRCServerTab::getTabForQuery(IRCPerson *person) {
+ QListIterator<IRCQueryTab> it(m_queryTabs);
+
+ for (; it.current(); ++it) {
+ if (it.current()->person()->nick() == person->nick())
+ 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) {
m_channelTabs.first();
while (m_channelTabs.current() != 0) {
m_mainWindow->killTab(m_channelTabs.current());
}
+ m_queryTabs.first();
+ while (m_queryTabs.current() != 0) {
+ m_mainWindow->killTab(m_queryTabs.current());
+ }
m_mainWindow->killTab(this);
} 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>");
@@ -138,13 +175,24 @@ void IRCServerTab::display(IRCOutput output) {
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.htmlMessage()+"<br>");
+ channelTab->appendText("&lt;<font color=\"#0000dd\">"+IRCOutput::toHTML(((IRCChannelPerson *)output.getParam(1))->person->nick())+"</font>&gt; "+output.htmlMessage()+"<br>");
+ }
+ break;
+ case OUTPUT_QUERYACTION:
+ case OUTPUT_QUERYPRIVMSG: {
+ IRCQueryTab *queryTab = getTabForQuery((IRCPerson *)output.getParam(0));
+ if (!queryTab) {
+ queryTab = new IRCQueryTab((IRCPerson *)output.getParam(0), this, m_mainWindow, (QWidget *)parent());
+ m_queryTabs.append(queryTab);
+ m_mainWindow->addTab(queryTab);
+ }
+ queryTab->display(output);
}
break;
case OUTPUT_SELFPART: {
IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0));
if (channelTab)
m_mainWindow->killTab(channelTab);
diff --git a/noncore/net/opieirc/ircservertab.h b/noncore/net/opieirc/ircservertab.h
index cfa0832..e439d84 100644
--- a/noncore/net/opieirc/ircservertab.h
+++ b/noncore/net/opieirc/ircservertab.h
@@ -22,12 +22,13 @@
#define __IRCSERVERTAB_H
#include "irctab.h"
#include "ircsession.h"
#include "mainwindow.h"
#include "ircchanneltab.h"
+#include "ircquerytab.h"
class IRCServerTab : public IRCTab {
Q_OBJECT
public:
/* IRCTab implementation */
IRCServerTab(IRCServer server, MainWindow *mainWindow, QWidget *parent = 0, const char *name = 0, WFlags f = 0);
@@ -35,29 +36,35 @@ public:
QString title();
IRCSession *session();
IRCServer *server();
/* Start the server session */
void doConnect();
+ /* Remove tabs from the internal tab lists */
void removeChannelTab(IRCChannelTab *tab);
+ void removeQueryTab(IRCQueryTab *tab);
/* Execute a user command such as /join */
void executeCommand(IRCTab *tab, QString line);
protected:
void appendText(QString text);
IRCChannelTab *getTabForChannel(IRCChannel *channel);
+ IRCQueryTab *getTabForQuery(IRCPerson *person);
public slots:
void remove();
void processCommand();
protected slots:
void display(IRCOutput output);
protected:
bool m_close;
IRCServer m_server;
IRCSession *m_session;
MainWindow *m_mainWindow;
QTextView *m_textview;
QLineEdit *m_field;
+ /* Channel tabs associated with this server tab */
QList<IRCChannelTab> m_channelTabs;
+ /* Query tabs associated with this server tab */
+ QList<IRCQueryTab> m_queryTabs;
};
#endif /* __IRCSERVERTAB_H */