author | wazlaf <wazlaf> | 2002-09-21 07:11:10 (UTC) |
---|---|---|
committer | wazlaf <wazlaf> | 2002-09-21 07:11:10 (UTC) |
commit | d8accaeed5f95340e8d293d6d5d1bb136c57fe35 (patch) (side-by-side diff) | |
tree | 8452081a1b36ab0db6b34a5a738ff7b64be641e9 | |
parent | 2f560ac908935bd4bc4a6b8852d27676100510bb (diff) | |
download | opie-d8accaeed5f95340e8d293d6d5d1bb136c57fe35.zip opie-d8accaeed5f95340e8d293d6d5d1bb136c57fe35.tar.gz opie-d8accaeed5f95340e8d293d6d5d1bb136c57fe35.tar.bz2 |
CTCP action now work via /me, HTML escaping now also works for text sent by yourself
-rw-r--r-- | noncore/net/opieirc/ircchanneltab.cpp | 4 | ||||
-rw-r--r-- | noncore/net/opieirc/ircoutput.cpp | 6 | ||||
-rw-r--r-- | noncore/net/opieirc/ircoutput.h | 2 | ||||
-rw-r--r-- | noncore/net/opieirc/ircservertab.cpp | 11 | ||||
-rw-r--r-- | noncore/net/opieirc/ircsession.cpp | 8 | ||||
-rw-r--r-- | noncore/net/opieirc/ircsession.h | 2 |
6 files changed, 31 insertions, 2 deletions
diff --git a/noncore/net/opieirc/ircchanneltab.cpp b/noncore/net/opieirc/ircchanneltab.cpp index 754442a..3267525 100644 --- a/noncore/net/opieirc/ircchanneltab.cpp +++ b/noncore/net/opieirc/ircchanneltab.cpp @@ -1,93 +1,95 @@ #include <qhbox.h> #include "ircchanneltab.h" #include "ircservertab.h" 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; 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); 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); m_field->setFocus(); connect(m_field, SIGNAL(returnPressed()), this, SLOT(processCommand())); } 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() { 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); if (session()->isSessionActive()) { session()->sendMessage(m_channel, m_field->text()); - appendText("<<font color=\"#dd0000\">"+m_parentTab->server()->nick()+"</font>> "+m_field->text()+"<br>"); + 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 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() { 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/ircoutput.cpp b/noncore/net/opieirc/ircoutput.cpp index 878bc9b..4822fc4 100644 --- a/noncore/net/opieirc/ircoutput.cpp +++ b/noncore/net/opieirc/ircoutput.cpp @@ -1,29 +1,33 @@ #include "ircoutput.h" 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("&"), "&"); + return toHTML(m_message); +} + +QString IRCOutput::toHTML(QString message) { + QString htmlMessage =message.replace(QRegExp("&"), "&"); htmlMessage = htmlMessage.replace(QRegExp(">"), ">"); htmlMessage = htmlMessage.replace(QRegExp("<"), "<"); 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 72361d4..e8cc524 100644 --- a/noncore/net/opieirc/ircoutput.h +++ b/noncore/net/opieirc/ircoutput.h @@ -1,72 +1,74 @@ /* OpieIRC - An embedded IRC client Copyright (C) 2002 Wenzel Jakob This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 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 __IRCOUTPUT_H #define __IRCOUTPUT_H #include <qstring.h> #include <qlist.h> #include "ircchannel.h" /* Types of possible IRC output */ enum IRCOutputType { OUTPUT_ERROR = -1, /* parameters : none */ OUTPUT_SERVERMESSAGE = 0, /* parameters : none */ OUTPUT_CLIENTMESSAGE = 1, /* parameters : none */ OUTPUT_CHANPRIVMSG = 2, /* parameters : channel (IRCChannel), person (IRCChannelPerson) */ OUTPUT_QUERYPRIVMSG = 3, /* parameters : person (IRCPerson) */ OUTPUT_NICKCHANGE = 4, /* parameters : person (IRCPerson) */ OUTPUT_SELFJOIN = 5, /* parameters : channel (IRCChannel) */ OUTPUT_OTHERJOIN = 6, /* parameters : channel (IRCChannel), person (IRCChannelPerson) */ OUTPUT_SELFPART = 7, /* parameters : channel (IRCChannel) */ OUTPUT_OTHERPART = 8, /* parameters : channel (IRCChannel), person (IRCChannelPerson) */ OUTPUT_QUIT = 9, /* parameters : person (IRCPerson) */ OUTPUT_CONNCLOSE = 10, /* parameters : none */ OUTPUT_CTCP = 11, /* parameters : none */ OUTPUT_SELFKICK = 12, /* parameters : channel (IRCChannel) */ OUTPUT_OTHERKICK = 13, /* parameters : channel (IRCChannel) person (IRCChannelPerson) */ OUTPUT_CHANACTION = 14, /* parameters : channel (IRCChannel) person (IRCChannelPerson) */ OUTPUT_QUERYACTION = 15, /* parameters : person (IRCPerson) */ OUTPUT_CHANPERSONMODE = 16 /* parameters : channel (IRCCHannel) person (IRCChannelPerson) */ }; /* The IRCOutput class is used as a kind of message which is sent by the 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 < instead of '<') */ QString htmlMessage(); + + static QString toHTML(QString message); void *getParam(int index); protected: IRCOutputType m_type; QString m_message; QList<void> m_parameters; }; #endif diff --git a/noncore/net/opieirc/ircservertab.cpp b/noncore/net/opieirc/ircservertab.cpp index 2ad56a8..503a758 100644 --- a/noncore/net/opieirc/ircservertab.cpp +++ b/noncore/net/opieirc/ircservertab.cpp @@ -1,157 +1,168 @@ #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); 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))); } 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() { 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 if (command == "ME") { + QString text = IRCOutput::toHTML(line.right(line.length()-4)); + if (text.length() > 0) { + if (tab->isA("IRCChannelTab")) { + tab->appendText("<font color=\"#cc0000\">*" + m_server.nick() + " " + text + "</font><br>"); + m_session->sendAction(((IRCChannelTab *)tab)->channel(), text); + } else if (tab->isA("IRCQueryTab")) { + } else { + tab->appendText("<font color=\"#ff0000\">Invalid tab for this command</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(); } 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) { m_channelTabs.first(); while (m_channelTabs.current() != 0) { m_mainWindow->killTab(m_channelTabs.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>"); } } 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("<<font color=\"#0000dd\">"+((IRCChannelPerson *)output.getParam(1))->person->nick()+"</font>> "+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.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.htmlMessage()+"</font><br>"); } break; case OUTPUT_QUIT: { QString nick = ((IRCPerson *)output.getParam(0))->nick(); QListIterator<IRCChannelTab> it(m_channelTabs); for (; it.current(); ++it) { diff --git a/noncore/net/opieirc/ircsession.cpp b/noncore/net/opieirc/ircsession.cpp index 89df68c..122a943 100644 --- a/noncore/net/opieirc/ircsession.cpp +++ b/noncore/net/opieirc/ircsession.cpp @@ -1,103 +1,111 @@ #include "ircsession.h" #include "ircmessageparser.h" #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); } void IRCSession::sendMessage(IRCPerson *person, QString message) { m_connection->sendLine("PRIVMSG " + person->nick() + " :" + message); } void IRCSession::sendMessage(IRCChannel *channel, QString message) { m_connection->sendLine("PRIVMSG " + channel->channelname() + " :" + message); } +void IRCSession::sendAction(IRCChannel *channel, QString message) { + m_connection->sendLine("PRIVMSG " + channel->channelname() + " :\001ACTION " + message + "\001"); +} + +void IRCSession::sendAction(IRCPerson *person, QString message) { + m_connection->sendLine("PRIVMSG " + person->nick() + " :\001ACTION " + message + "\001"); +} + bool IRCSession::isSessionActive() { return m_connection->isConnected(); } void IRCSession::endSession() { if (m_connection->isLoggedIn()) m_connection->sendLine("QUIT :" APP_VERSION); else m_connection->close(); } void IRCSession::part(IRCChannel *channel) { m_connection->sendLine("PART " + channel->channelname() + " :" + APP_VERSION); } IRCChannel *IRCSession::getChannel(QString channelname) { QListIterator<IRCChannel> it(m_channels); for (; it.current(); ++it) { if (it.current()->channelname() == channelname) { return it.current(); } } return 0; } IRCPerson *IRCSession::getPerson(QString nickname) { QListIterator<IRCPerson> it(m_people); for (; it.current(); ++it) { if (it.current()->nick() == nickname) { return it.current(); } } return 0; } void IRCSession::getChannelsByPerson(IRCPerson *person, QList<IRCChannel> &channels) { QListIterator<IRCChannel> it(m_channels); for (; it.current(); ++it) { if (it.current()->getPerson(person->nick()) != 0) { channels.append(it.current()); } } } void IRCSession::addPerson(IRCPerson *person) { m_people.append(person); } void IRCSession::addChannel(IRCChannel *channel) { m_channels.append(channel); } void IRCSession::removeChannel(IRCChannel *channel) { m_channels.remove(channel); } void IRCSession::removePerson(IRCPerson *person) { m_people.remove(person); } void IRCSession::handleMessage(IRCMessage *message) { m_parser->parse(message); } diff --git a/noncore/net/opieirc/ircsession.h b/noncore/net/opieirc/ircsession.h index 59c26aa..aa4bed3 100644 --- a/noncore/net/opieirc/ircsession.h +++ b/noncore/net/opieirc/ircsession.h @@ -1,73 +1,75 @@ /* OpieIRC - An embedded IRC client Copyright (C) 2002 Wenzel Jakob This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 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 __IRCSESSION_H #define __IRCSESSION_H #include <qstring.h> #include <qlist.h> #include "ircserver.h" #include "ircconnection.h" #include "ircmessage.h" #include "ircchannel.h" #include "ircoutput.h" class IRCMessageParser; /* The IRCSession stores all information relating to the connection to one IRC server. IRCSession makes it possible to run multiple IRC server connections from within the same program */ class IRCSession : public QObject { friend class IRCMessageParser; Q_OBJECT public: IRCSession(IRCServer *server); ~IRCSession(); void join(QString channel); void part(IRCChannel *channel); void beginSession(); bool isSessionActive(); void endSession(); void sendMessage(IRCPerson *person, QString message); void sendMessage(IRCChannel *channel, QString message); + void sendAction(IRCPerson *person, QString message); + void sendAction(IRCChannel *channel, QString message); IRCChannel *getChannel(QString channelname); IRCPerson *getPerson(QString nickname); protected: void addPerson(IRCPerson *person); void addChannel(IRCChannel *channel); void removeChannel(IRCChannel *channel); void removePerson(IRCPerson *person); void getChannelsByPerson(IRCPerson *person, QList<IRCChannel> &channels); protected slots: void handleMessage(IRCMessage *message); signals: void outputReady(IRCOutput output); protected: IRCServer *m_server; IRCConnection *m_connection; IRCMessageParser *m_parser; QList<IRCChannel> m_channels; QList<IRCPerson> m_people; }; #endif /* __IRCSESSION_H */ |