-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 @@ -32,35 +32,37 @@ void IRCChannelTab::appendText(QString text) { 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(">"); 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 @@ -49,24 +49,26 @@ enum IRCOutputType { /* 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 @@ -46,32 +46,43 @@ IRCServer *IRCServerTab::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(); 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 @@ -23,32 +23,40 @@ IRCSession::~IRCSession() { 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); } 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 @@ -37,32 +37,34 @@ class IRCMessageParser; 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; |