-rw-r--r-- | noncore/net/opieirc/ircchanneltab.cpp | 7 | ||||
-rw-r--r-- | noncore/net/opieirc/ircmessage.cpp | 1 | ||||
-rw-r--r-- | noncore/net/opieirc/ircmessageparser.cpp | 10 | ||||
-rw-r--r-- | noncore/net/opieirc/ircmessageparser.h | 1 | ||||
-rw-r--r-- | noncore/net/opieirc/ircperson.cpp | 6 | ||||
-rw-r--r-- | noncore/net/opieirc/ircperson.h | 3 | ||||
-rw-r--r-- | noncore/net/opieirc/ircquerytab.cpp | 76 | ||||
-rw-r--r-- | noncore/net/opieirc/ircquerytab.h | 27 | ||||
-rw-r--r-- | noncore/net/opieirc/ircservertab.cpp | 54 | ||||
-rw-r--r-- | noncore/net/opieirc/ircservertab.h | 7 |
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 @@ -9,16 +9,17 @@ IRCChannelTab::IRCChannelTab(IRCChannel *channel, IRCServerTab *parentTab, MainW m_description->setText(tr("Talking on channel") + " <b>" + channel->channelname() + "</b>"); QHBox *hbox = new QHBox(this); 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); hbox->show(); m_layout->add(m_field); @@ -42,20 +43,18 @@ void IRCChannelTab::processCommand() { 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); - if (session()->isSessionActive()) { - session()->sendMessage(m_channel, m_field->text()); - appendText("<<font color=\"#dd0000\">"+m_parentTab->server()->nick()+"</font>> "+IRCOutput::toHTML(m_field->text())+"<br>"); - } + session()->sendMessage(m_channel, m_field->text()); + appendText("<<font color=\"#dd0000\">"+m_parentTab->server()->nick()+"</font>> "+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 @@ -72,17 +72,16 @@ IRCMessage::IRCMessage(QString line) { printf("Command : '%s'\n", m_command.ascii()); printf("Allparameters : '%s'\n", m_allParameters.ascii()); 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]; } QString IRCMessage::prefix() { 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 @@ -39,17 +39,19 @@ IRCNumericalMessageParserStruct IRCMessageParser::numericalParserProcTable[] = { { 255, FUNC(parseNumericalStats) }, // RPL_LUSERNAME { 353, FUNC(parseNumericalNames) }, // RPL_NAMREPLY { 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; } @@ -167,17 +169,17 @@ void IRCMessageParser::parseLiteralPrivMsg(IRCMessage *message) { /* IRC Query message detected, verify sender and display it */ IRCPerson mask(message->prefix()); 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) { IRCPerson mask(message->prefix()); IRCChannelPerson *person = channel->getPerson(mask.nick()); @@ -474,8 +476,12 @@ 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 @@ -76,16 +76,17 @@ private: void parseNumerical002(IRCMessage *message); void parseNumerical003(IRCMessage *message); 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 */ static IRCLiteralMessageParserStruct literalParserProcTable[]; static IRCNumericalMessageParserStruct numericalParserProcTable[]; 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 @@ -2,16 +2,22 @@ #include <stdio.h> 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) { int sep1 = mask.find("!"); int sep2 = mask.find("@"); 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 @@ -26,17 +26,20 @@ /* This class requires all required information relating to a person on the IRC network. This class can be used as an input mask for 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(); QString nick(); QString user(); 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("<<font color=\"#dd0000\">"+m_parentTab->server()->nick()+"</font>> "+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("<<font color=\"#0000dd\">"+m_person->nick()+"</font>> " + 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 @@ -16,9 +16,36 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #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 @@ -6,16 +6,17 @@ IRCServerTab::IRCServerTab(IRCServer server, MainWindow *mainWindow, QWidget *pa 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_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))); } @@ -28,16 +29,20 @@ void IRCServerTab::appendText(QString text) { IRCServerTab::~IRCServerTab() { delete m_session; } 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; } @@ -55,26 +60,40 @@ void IRCServerTab::executeCommand(IRCTab *tab, QString line) { 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 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("><font color=\"#0000dd\">"+IRCOutput::toHTML(nickname)+"</font>< "+IRCOutput::toHTML(text)+"<br>"); + m_session->sendMessage(&person, text); + } + } } else { tab->appendText("<font color=\"#ff0000\">Unknown command</font><br>"); } } void IRCServerTab::processCommand() { QString text = m_field->text(); if (text.startsWith("/") && !text.startsWith("//")) { @@ -95,40 +114,58 @@ void IRCServerTab::remove() { 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_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); for (; it.current(); ++it) { 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>"); } } @@ -136,17 +173,28 @@ void IRCServerTab::display(IRCOutput output) { 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("<<font color=\"#0000dd\">"+((IRCChannelPerson *)output.getParam(1))->person->nick()+"</font>> "+output.htmlMessage()+"<br>"); + channelTab->appendText("<<font color=\"#0000dd\">"+IRCOutput::toHTML(((IRCChannelPerson *)output.getParam(1))->person->nick())+"</font>> "+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); } break; 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 @@ -20,44 +20,51 @@ #ifndef __IRCSERVERTAB_H #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); ~IRCServerTab(); 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 */ |