-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 @@ -13,8 +13,9 @@ IRCChannelTab::IRCChannelTab(IRCChannel *channel, IRCServerTab *parentTab, MainW 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); @@ -46,12 +47,10 @@ void IRCChannelTab::processCommand() { 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>"); } 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 @@ -76,9 +76,8 @@ IRCMessage::IRCMessage(QString line) { } 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) { 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 @@ -43,9 +43,11 @@ IRCNumericalMessageParserStruct IRCMessageParser::numericalParserProcTable[] = { { 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 } }; @@ -171,9 +173,9 @@ void IRCMessageParser::parseLiteralPrivMsg(IRCMessage *message) { /* 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 */ @@ -478,4 +480,8 @@ 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 @@ -80,8 +80,9 @@ private: 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: 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 @@ -6,8 +6,14 @@ IRCPerson::IRCPerson() { 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); } 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 @@ -30,9 +30,12 @@ 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); 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 @@ -20,5 +20,32 @@ #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 @@ -10,8 +10,9 @@ IRCServerTab::IRCServerTab(IRCServer server, MainWindow *mainWindow, QWidget *pa 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())); @@ -32,8 +33,12 @@ 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"; } @@ -59,18 +64,32 @@ void IRCServerTab::executeCommand(IRCTab *tab, QString line) { } 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>"); } } @@ -99,8 +118,12 @@ void IRCServerTab::remove() { 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); } } @@ -113,8 +136,18 @@ IRCChannelTab *IRCServerTab::getTabForChannel(IRCChannel *channel) { } 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()) { @@ -123,8 +156,12 @@ void IRCServerTab::display(IRCOutput output) { 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); @@ -140,9 +177,20 @@ void IRCServerTab::display(IRCOutput output) { } 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)); 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 @@ -24,8 +24,9 @@ #include "irctab.h" #include "ircsession.h" #include "mainwindow.h" #include "ircchanneltab.h" +#include "ircquerytab.h" class IRCServerTab : public IRCTab { Q_OBJECT public: @@ -37,15 +38,18 @@ public: 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: @@ -56,8 +60,11 @@ protected: 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 */ |