-rw-r--r-- | noncore/net/opieirc/ircservertab.cpp | 2 | ||||
-rw-r--r-- | noncore/net/opieirc/ircsession.cpp | 3 | ||||
-rw-r--r-- | noncore/net/opieirc/ircsession.h | 3 |
3 files changed, 5 insertions, 3 deletions
diff --git a/noncore/net/opieirc/ircservertab.cpp b/noncore/net/opieirc/ircservertab.cpp index bddc37e..62a06e8 100644 --- a/noncore/net/opieirc/ircservertab.cpp +++ b/noncore/net/opieirc/ircservertab.cpp @@ -1,273 +1,273 @@ #include <qtextstream.h> #include <qwhatsthis.h> #include "ircservertab.h" #include "ircmessageparser.h" #include "ircchannelperson.h" bool IRCServerTab::containsPing( const QString& text, IRCServerTab* tab ) { return (text.contains(IRCMessageParser::tr("Received a CTCP PING from "))) || (text.find("ping") != -1 && text.find( tab->server()->nick() != -1)); } 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_session = new IRCSession(this, &m_server); m_mainWindow = mainWindow; m_close = FALSE; m_lines = 0; m_description->setText(tr("Connecting 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); QWhatsThis::add(m_textview, tr("Server messages")); m_layout->add(m_textview); m_field = new IRCHistoryLineEdit(this); connect(m_field, SIGNAL(nextTab()), this, SIGNAL(nextTab())); connect(m_field, SIGNAL(prevTab()), this, SIGNAL(prevTab())); connect(m_field, SIGNAL(closeTab()), this, SIGNAL(closeTab())); connect(this, SIGNAL(editFocus()), m_field, SLOT(setEditFocus())); QWhatsThis::add(m_field, tr("Type commands here. A list of available commands can be found inside the OpieIRC help")); m_layout->add(m_field); connect(m_field, SIGNAL(returnPressed()), this, SLOT(processCommand())); connect(m_session, SIGNAL(outputReady(IRCOutput)), this, SLOT(display(IRCOutput))); connect(m_mainWindow, SIGNAL(updateScroll()), this, SLOT(scrolling())); connect(m_session, SIGNAL(updateChannels()), this, SLOT(slotUpdateChannels())); settingsChanged(); m_field->setFocus(); m_field->setActiveWindow(); } void IRCServerTab::scrolling(){ m_textview->ensureVisible(0, m_textview->contentsHeight()); } void IRCServerTab::appendText(QString text) { /* not using append because it creates layout problems */ QString txt = m_textview->text() + IRCTab::appendTimestamp( text ); if (m_maxLines > 0 && m_lines >= m_maxLines) { int firstBreak = txt.find('\n'); if (firstBreak != -1) { txt = "<qt bgcolor=\"" + m_backgroundColor + "\"/>" + txt.right(txt.length() - (firstBreak + 1)); } } else { m_lines++; } m_textview->setText(txt); m_textview->ensureVisible(0, m_textview->contentsHeight()); emit changed(this); } IRCServerTab::~IRCServerTab() { delete m_session; } void IRCServerTab::removeChannelTab(IRCChannelTab *tab) { m_channelTabs.remove(tab); } void IRCServerTab::removeQueryTab(IRCQueryTab *tab) { m_queryTabs.remove(tab); } void IRCServerTab::addQueryTab(IRCQueryTab *tab) { m_queryTabs.append(tab); } QString IRCServerTab::title() { return "Server"; } IRCSession *IRCServerTab::session() { return m_session; } /* QString *IRCServerTab::mynick() { return (*m_server->nick()); } */ IRCServer *IRCServerTab::server() { return &m_server; } void IRCServerTab::settingsChanged() { m_textview->setText("<qt bgcolor=\"" + m_backgroundColor + "\"/>"); m_lines = 0; } void IRCServerTab::executeCommand(IRCTab *tab, QString line) { QTextIStream stream(&line); QString command; stream >> command; command = command.upper().right(command.length()-1); //JOIN if (command == "JOIN" || command == "J") { QString channel; stream >> channel; /* According to RFC 1459 */ if (channel.length() > 0 && channel.length() < 200 && channel.find(",") == -1 && channel.find("") == -1) { if (!channel.startsWith("#") && !channel.startsWith("&")) { channel = channel.prepend("#"); } m_session->join(channel); } else { tab->appendText("<font color=\"" + m_errorColor + "\">Unknown channel format!</font><br>"); } } //KICK else if (command == "KICK"){ QString nickname; stream >> nickname; if (nickname.length() > 0) { if (line.length() > 7 + nickname.length()) { QString text = line.right(line.length()-nickname.length()-7); IRCPerson person; person.setNick(nickname); m_session->kick(((IRCChannelTab *)tab)->channel(), &person, text); } else { IRCPerson person; person.setNick(nickname); m_session->kick(((IRCChannelTab *)tab)->channel(), &person); } } } else if (command == "OP"){ QString nickname; stream >> nickname; if (nickname.length() > 0) { QString text = line.right(line.length()-nickname.length()-5); IRCPerson person; person.setNick(nickname); m_session->op(((IRCChannelTab *)tab)->channel(), &person); } } //SEND MODES else if (command == "MODE"){ QString text = line.right(line.length()-6); if (text.length() > 0) { m_session->mode(text); } else { tab->appendText("<font color=\"" + m_errorColor + "\">/mode channel {[+|-]|o|p|s|i|t|n|b|v} [limit] [user] [ban mask]<br>/mode nickname {[+|-]|i|w|s|o}</font><br>"); } } //SEND RAW MESSAGE TO SERVER, COMPLETELY UNCHECKED - anything in the RFC...or really anything you want else if (command == "RAW"){ QString text = line.right(line.length()-5); if (text.length() > 0) { m_session->raw(text); } } else if (command == "SUSPEND"){ QString text = line.right(line.length()-9); if (text.upper() == "ON") { QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; } else if (text.upper() == "OFF"){ QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Disable; } else { tab->appendText("<font color=\"" + m_errorColor + "\">Line: "+ line +"</font><br>Text: "+text); } } else if (command == "QUIT"){ QString text = line.right(line.length()-6); if (text.length() > 0) { m_session->quit(text); } else { m_session->quit(); } } //SEND ACTION else if (command == "ME") { QString text = line.right(line.length()-4); if (text.length() > 0) { if (tab->isA("IRCChannelTab")) { tab->appendText("<font color=\"" + m_selfColor + "\">*" + 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=\"" + m_selfColor + "\">*" + IRCOutput::toHTML(m_server.nick()) + " " + IRCOutput::toHTML(text) + "</font><br>"); m_session->sendAction(((IRCQueryTab *)tab)->person(), text); } else { tab->appendText("<font color=\"" + m_errorColor + "\">Invalid tab for this command</font><br>"); } } } //SEND PRIVMSG 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=\"" + m_textColor + "\">></font><font color=\"" + m_otherColor + "\">"+IRCOutput::toHTML(nickname)+"</font><font color=\"" + m_textColor + "\">< "+IRCOutput::toHTML(text)+"</font><br>"); m_session->sendMessage(&person, text); } } } else { tab->appendText("<font color=\"" + m_errorColor + "\">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(), true); } m_queryTabs.first(); while (m_queryTabs.current() != 0) { m_mainWindow->killTab(m_queryTabs.current(), true); } 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; } diff --git a/noncore/net/opieirc/ircsession.cpp b/noncore/net/opieirc/ircsession.cpp index 80a327a..fd8ba72 100644 --- a/noncore/net/opieirc/ircsession.cpp +++ b/noncore/net/opieirc/ircsession.cpp @@ -1,214 +1,215 @@ #include "ircsession.h" #include "ircmessageparser.h" #include "ircchannelperson.h" #include "ircversion.h" -IRCSession::IRCSession(IRCServer *server) { +IRCSession::IRCSession(QWidget *parent, IRCServer *server) { m_server = server; m_connection = new IRCConnection(m_server); m_parser = new IRCMessageParser(this); + m_parent = parent; 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::quit(){ m_connection->sendLine("QUIT :[OI] I'm too good to need a reason"); } void IRCSession::quit(QString message){ m_connection->sendLine("QUIT :" + message); } void IRCSession::topic(IRCChannel *channel, QString message){ m_connection->sendLine("TOPIC :" + channel->channelname() + " " + message); } void IRCSession::mode(IRCChannel *channel, QString message){ m_connection->sendLine("MODE " + channel->channelname() + " " + message); } void IRCSession::mode(IRCPerson *person, QString message){ m_connection->sendLine("MODE " + person->nick() + " " + message); } void IRCSession::mode(QString message){ m_connection->sendLine("MODE " + message); } void IRCSession::raw(QString message){ m_connection->sendLine(message); } void IRCSession::kick(IRCChannel *channel, IRCPerson *person) { m_connection->sendLine("KICK " + channel->channelname() + " " + person->nick() +" :0wn3d - no reason"); } void IRCSession::op(IRCChannel *channel, IRCPerson *person) { m_connection->sendLine("MODE " + channel->channelname() + " +ooo " + person->nick()); } void IRCSession::kick(IRCChannel *channel, IRCPerson *person, QString message) { m_connection->sendLine("KICK " + channel->channelname() + " " + person->nick() +" :" + message); } 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(); } bool IRCSession::isLoggedIn() { return m_connection->isLoggedIn(); } void IRCSession::endSession() { if (m_connection->isLoggedIn()) quit(APP_VERSION); else m_connection->close(); } void IRCSession::part(IRCChannel *channel) { m_connection->sendLine("PART " + channel->channelname() + " :" + APP_VERSION); } void IRCSession::setValidUsermodes(const QString &modes) { m_validUsermodes = modes; } void IRCSession::setValidChannelmodes(const QString &modes) { m_validChannelmodes = modes; } void IRCSession::updateNickname(const QString &oldNickname, const QString &newNickname) { QList<IRCChannel> channels; IRCOutput output; if (oldNickname == m_server->nick()) { m_server->setNick(newNickname); output = IRCOutput(OUTPUT_NICKCHANGE, tr("You are now known as %1").arg(newNickname)); channels = m_channels; } else { IRCPerson *person = getPerson(oldNickname); if(!person) { emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Nickname change of an unknown person"))); return; } getChannelsByPerson(person, channels); output = IRCOutput(OUTPUT_NICKCHANGE, tr("%1 is now known as %2").arg(oldNickname).arg(newNickname)); } QListIterator<IRCChannel> it(channels); for (;it.current(); ++it) { IRCChannelPerson *chanperson = it.current()->getPerson(oldNickname); it.current()->removePerson(chanperson); chanperson->setNick(newNickname); it.current()->addPerson(chanperson); } emit updateChannels(); output.addParam(new QString(newNickname)); emit outputReady(output); } 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); } void IRCSession::whois(const QString &nickname) { m_connection->whois(nickname); } void IRCSession::sendCTCPPing(const QString &nickname) { m_connection->sendCTCPPing(nickname); } void IRCSession::sendCTCPRequest(const QString &nickname, const QString &type, const QString &args) { m_connection->sendCTCPRequest(nickname, type, args); } void IRCSession::sendCTCPReply(const QString &nickname, const QString &type, const QString &args) { m_connection->sendCTCPReply(nickname, type, args); } diff --git a/noncore/net/opieirc/ircsession.h b/noncore/net/opieirc/ircsession.h index 3859b68..7c91893 100644 --- a/noncore/net/opieirc/ircsession.h +++ b/noncore/net/opieirc/ircsession.h @@ -1,95 +1,96 @@ /* 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(QWidget *parent, IRCServer *server); ~IRCSession(); void join(QString channel); void quit(QString message); void quit(); void raw(QString message); void topic(IRCChannel *channel, QString message); void mode(IRCChannel *channel, QString message); void mode(IRCPerson *person, QString message); void mode(QString message); void part(IRCChannel *channel); void op(IRCChannel *channel, IRCPerson *person); void kick(IRCChannel *channel, IRCPerson *person); void kick(IRCChannel *channel, IRCPerson *person, QString message); void beginSession(); bool isSessionActive(); void endSession(); bool isLoggedIn(); void sendMessage(IRCPerson *person, QString message); void sendMessage(IRCChannel *channel, QString message); void sendAction(IRCPerson *person, QString message); void sendAction(IRCChannel *channel, QString message); void updateNickname(const QString &oldNickname, const QString &newNickname); void setValidUsermodes(const QString &modes); void setValidChannelmodes(const QString &modes); void whois(const QString &nickname); void sendCTCPPing(const QString &nickname); void sendCTCPRequest(const QString &nickname, const QString &type, const QString &args); void sendCTCPReply(const QString &nickname, const QString &type, const QString &args); 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); void updateChannels(); protected: IRCServer *m_server; IRCConnection *m_connection; IRCMessageParser *m_parser; QList<IRCChannel> m_channels; QList<IRCPerson> m_people; QString m_validUsermodes; QString m_validChannelmodes; + QWidget *m_parent; }; #endif /* __IRCSESSION_H */ |