-rw-r--r-- | noncore/net/opieirc/ircconnection.cpp | 2 | ||||
-rw-r--r-- | noncore/net/opieirc/ircmessageparser.cpp | 2 | ||||
-rw-r--r-- | noncore/net/opieirc/ircservereditor.cpp | 4 | ||||
-rw-r--r-- | noncore/net/opieirc/ircservertab.cpp | 2 |
4 files changed, 5 insertions, 5 deletions
diff --git a/noncore/net/opieirc/ircconnection.cpp b/noncore/net/opieirc/ircconnection.cpp index 5eb0cf2..2325cca 100644 --- a/noncore/net/opieirc/ircconnection.cpp +++ b/noncore/net/opieirc/ircconnection.cpp @@ -1,102 +1,102 @@ #include <unistd.h> #include <string.h> #include "ircconnection.h" IRCConnection::IRCConnection(IRCServer *server) { m_server = server; m_socket = new QSocket(this); m_connected = FALSE; m_loggedIn = FALSE; connect(m_socket, SIGNAL(connected()), this, SLOT(login())); connect(m_socket, SIGNAL(readyRead()), this, SLOT(dataReady())); connect(m_socket, SIGNAL(error(int)), this, SLOT(error(int))); connect(m_socket, SIGNAL(connectionClosed()), this, SLOT(disconnect())); connect(m_socket, SIGNAL(delayedCloseFinished()), this, SLOT(disconnect())); } /* Connect to the IRC server */ void IRCConnection::doConnect() { ASSERT(!m_connected); m_socket->connectToHost(m_server->hostname(), m_server->port()); } /* Send commands to the IRC server */ void IRCConnection::sendLine(QString line) { while((line.right(1) == "\n") || (line.right(1) == "\r")) line = line.left(line.length() - 1); line.append("\r\n"); m_socket->writeBlock(line, line.length()); } void IRCConnection::sendCTCP(QString nick, QString line) { sendLine("NOTICE " + nick + " :\001"+line+"\001"); } /* * login() is called right after the connection * to the IRC server has been established */ void IRCConnection::login() { char hostname[256]; QString loginString; emit outputReady(IRCOutput(OUTPUT_CLIENTMESSAGE, tr("Connected, logging in .."))); m_connected = TRUE; gethostname(hostname, sizeof(hostname)-1); hostname[sizeof (hostname) - 1] = 0; /* Create a logon string and send it */ if (m_server->password().length()>0) { loginString += "PASS " + m_server->password() + "\r\n"; } loginString += "NICK " + m_server->nick() + "\r\n" + "USER " + m_server->username() + " " + hostname + " " + m_server->hostname() + " :" + m_server->realname() + "\r\n"; sendLine(loginString); } /* Called when data arrives on the socket */ void IRCConnection::dataReady() { while(m_socket->canReadLine()) { IRCMessage message(m_socket->readLine()); if (!m_loggedIn && message.isNumerical() && message.commandNumber() == 1) { /* Now autojoin all channels specified inside the server profile */ QStringList channels = QStringList::split(QChar(','), m_server->channels()); for (QStringList::Iterator it = channels.begin(); it != channels.end(); ++it) { QString channelName = (*it).stripWhiteSpace(); - if (channelName.startsWith("#")) { + if (channelName.startsWith("#") || channelName.startsWith("+")) { sendLine("JOIN "+ channelName); } } m_loggedIn = TRUE; emit outputReady(IRCOutput(OUTPUT_CLIENTMESSAGE, tr("Successfully logged in."))); } emit messageArrived(&message); } } /* Called if any type of socket error occurs */ void IRCConnection::error(int num) { emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Socket error : ") + strerror(num))); } void IRCConnection::disconnect() { m_connected = FALSE; m_loggedIn = FALSE; emit outputReady(IRCOutput(OUTPUT_CONNCLOSE, tr("Connection closed"))); } bool IRCConnection::isConnected() { return m_connected; } bool IRCConnection::isLoggedIn() { return m_loggedIn; } void IRCConnection::close() { m_socket->close(); if (m_socket->state()==QSocket::Idle) { disconnect(); } } diff --git a/noncore/net/opieirc/ircmessageparser.cpp b/noncore/net/opieirc/ircmessageparser.cpp index 2b77414..a95c64e 100644 --- a/noncore/net/opieirc/ircmessageparser.cpp +++ b/noncore/net/opieirc/ircmessageparser.cpp @@ -90,193 +90,193 @@ void IRCMessageParser::parse(IRCMessage *message) { emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received unhandled literal command : ")+message->command())); } } void IRCMessageParser::nullFunc(IRCMessage *) { /* Do nothing */ } void IRCMessageParser::parseLiteralPing(IRCMessage *message) { m_session->m_connection->sendLine("PONG " + message->allParameters()); } void IRCMessageParser::parseLiteralNotice(IRCMessage *message) { emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, message->allParameters())); } void IRCMessageParser::parseLiteralJoin(IRCMessage *message) { QString channelName = message->param(0).lower(); IRCPerson mask(message->prefix()); IRCChannel *channel = m_session->getChannel(channelName); if (!channel) { /* We joined */ if (mask.nick() == m_session->m_server->nick()) { channel = new IRCChannel(channelName); m_session->addChannel(channel); } else { emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Nonexistant channel join - desynchronized?"))); } } else { /* Someone else joined */ if (mask.nick() != m_session->m_server->nick()) { if (!channel->getPerson(mask.nick())) { IRCChannelPerson *chanperson = new IRCChannelPerson(); IRCPerson *person = m_session->getPerson(mask.nick()); if (!person) { person = new IRCPerson(message->prefix()); m_session->addPerson(person); } chanperson->flags = 0; chanperson->person = person; channel->addPerson(chanperson); IRCOutput output(OUTPUT_OTHERJOIN, mask.nick() + tr(" joined channel ") + channelName); output.addParam(channel); output.addParam(chanperson); emit outputReady(output); } else { emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Person has already joined the channel - desynchronized?"))); } } else { emit outputReady(IRCOutput(OUTPUT_ERROR, tr("You already joined the channel - desynchronized?"))); } } } void IRCMessageParser::parseLiteralPart(IRCMessage *message) { QString channelName = message->param(0).lower(); IRCChannel *channel = m_session->getChannel(channelName); IRCPerson mask(message->prefix()); if (channel) { if (mask.nick() == m_session->m_server->nick()) { m_session->removeChannel(channel); IRCOutput output(OUTPUT_SELFPART, tr("You left channel ") + channelName); output.addParam(channel); emit outputReady(output); delete channel; } else { IRCChannelPerson *person = channel->getPerson(mask.nick()); if (person) { channel->removePerson(person); IRCOutput output(OUTPUT_OTHERPART, mask.nick() + tr(" left channel ") + channelName); output.addParam(channel); output.addParam(person); emit outputReady(output); delete person; } else { emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Parting person not found - desynchronized?"))); } } } else { emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Channel for part not found - desynchronized?"))); } } void IRCMessageParser::parseLiteralPrivMsg(IRCMessage *message) { if (m_session->m_server->nick() == message->param(0)) { /* 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_QUERYPRIVMSG, message->param(1)); output.addParam(person); emit outputReady(output); - } else if (message->param(0).at(0) == '#') { + } else if (message->param(0).at(0) == '#' || message->param(0).at(0) == '+') { /* IRC Channel message detected, verify sender, channel and display it */ IRCChannel *channel = m_session->getChannel(message->param(0).lower()); if (channel) { IRCPerson mask(message->prefix()); IRCChannelPerson *person = channel->getPerson(mask.nick()); if (person) { IRCOutput output(OUTPUT_CHANPRIVMSG, message->param(1)); output.addParam(channel); output.addParam(person); emit outputReady(output); } else { emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Channel message with unknown sender"))); } } else { emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Channel message with unknown channel ") + message->param(0).lower())); } } else { emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received PRIVMSG of unknown type"))); } } void IRCMessageParser::parseLiteralNick(IRCMessage *message) { IRCPerson mask(message->prefix()); if (mask.nick() == m_session->m_server->nick()) { /* We are changing our nickname */ m_session->m_server->setNick(message->param(0)); IRCOutput output(OUTPUT_NICKCHANGE, tr("You are now known as ")+message->param(0)); output.addParam(0); emit outputReady(output); } else { /* Someone else is */ IRCPerson *person = m_session->getPerson(mask.nick()); if (person) { IRCOutput output(OUTPUT_NICKCHANGE, mask.nick() + tr(" is now known as ") + message->param(0)); output.addParam(person); emit outputReady(output); } else { emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Nickname change of an unknown person"))); } } } void IRCMessageParser::parseLiteralQuit(IRCMessage *message) { IRCPerson mask(message->prefix()); IRCPerson *person = m_session->getPerson(mask.nick()); if (person) { QList<IRCChannel> channels; m_session->getChannelsByPerson(person, channels); QListIterator<IRCChannel> it(channels); for (;it.current(); ++it) { IRCChannelPerson *chanperson = it.current()->getPerson(mask.nick()); it.current()->removePerson(chanperson); delete chanperson; } m_session->removePerson(person); IRCOutput output(OUTPUT_QUIT, mask.nick() + tr(" has quit ") + "(" + message->param(0) + ")"); output.addParam(person); emit outputReady(output); delete person; } else { emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown person quit - desynchronized?"))); } } void IRCMessageParser::parseLiteralTopic(IRCMessage *message) { IRCPerson mask(message->prefix()); IRCChannel *channel = m_session->getChannel(message->param(0).lower()); if (channel) { IRCOutput output(OUTPUT_TOPIC, mask.nick() + tr(" changed topic to ") + "\"" + message->param(1) + "\""); output.addParam(channel); emit outputReady(output); } else { emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown channel topic - desynchronized?"))); } } void IRCMessageParser::parseLiteralError(IRCMessage *message) { emit outputReady(IRCOutput(OUTPUT_ERROR, message->allParameters())); } void IRCMessageParser::parseCTCPPing(IRCMessage *message) { IRCPerson mask(message->prefix()); m_session->m_connection->sendCTCP(mask.nick(), "PING " + message->allParameters()); emit outputReady(IRCOutput(OUTPUT_CTCP, tr("Received a CTCP PING from ")+mask.nick())); } void IRCMessageParser::parseCTCPVersion(IRCMessage *message) { IRCPerson mask(message->prefix()); m_session->m_connection->sendCTCP(mask.nick(), APP_VERSION " " APP_COPYSTR); emit outputReady(IRCOutput(OUTPUT_CTCP, tr("Received a CTCP VERSION from ")+mask.nick())); } void IRCMessageParser::parseCTCPAction(IRCMessage *message) { IRCPerson mask(message->prefix()); QString dest = message->ctcpDestination(); diff --git a/noncore/net/opieirc/ircservereditor.cpp b/noncore/net/opieirc/ircservereditor.cpp index 5e916ae..f976c84 100644 --- a/noncore/net/opieirc/ircservereditor.cpp +++ b/noncore/net/opieirc/ircservereditor.cpp @@ -1,77 +1,77 @@ #include <qmessagebox.h> #include <qlayout.h> #include <qlabel.h> #include "ircservereditor.h" IRCServerEditor::IRCServerEditor(IRCServer server, QWidget* parent, const char* name, bool modal = FALSE, WFlags f) : QDialog(parent, name, modal, f) { QGridLayout *layout = new QGridLayout(this, 7, 2, 5, 5); QLabel *label = new QLabel(tr("Profile name :"), this); m_name = new QLineEdit(server.name(), this); layout->addWidget(label, 0, 0); layout->addWidget(m_name, 0, 1); label = new QLabel(tr("Hostname :"), this); m_hostname = new QLineEdit(server.hostname(), this); layout->addWidget(label, 1, 0); layout->addWidget(m_hostname, 1, 1); label = new QLabel(tr("Port :"), this); m_port = new QLineEdit(QString::number(server.port()), this); layout->addWidget(label, 2, 0); layout->addWidget(m_port, 2, 1); label = new QLabel(tr("Nickname :"), this); m_nickname = new QLineEdit(server.nick(), this); layout->addWidget(label, 3, 0); layout->addWidget(m_nickname, 3, 1); label = new QLabel(tr("Realname :"), this); m_realname = new QLineEdit(server.realname(), this); layout->addWidget(label, 4, 0); layout->addWidget(m_realname, 4, 1); label = new QLabel(tr("Password :"), this); m_password = new QLineEdit(server.password(), this); layout->addWidget(label, 5, 0); layout->addWidget(m_password, 5, 1); label = new QLabel(tr("Channels :"), this); m_channels = new QLineEdit(server.channels(), this); layout->addWidget(label, 6, 0); layout->addWidget(m_channels, 6, 1); setCaption(tr("Edit server information")); showMaximized(); } void IRCServerEditor::accept() { if (m_name->text().length()==0) QMessageBox::critical(this, tr("Error"), tr("Profile name required")); else if (m_hostname->text().length()==0) QMessageBox::critical(this, tr("Error"), tr("Host name required")); else if (m_port->text().toInt()<=0) QMessageBox::critical(this, tr("Error"), tr("Port required")); else if (m_nickname->text().length()==0) QMessageBox::critical(this, tr("Error"), tr("Nickname required")); else if (m_realname->text().length()==0) QMessageBox::critical(this, tr("Error"), tr("Realname required")); else { /* Now verify whether the channel list has a valid format */ QStringList channels = QStringList::split(QChar(','), m_channels->text()); for (QStringList::Iterator it = channels.begin(); it != channels.end(); ++it) { QString channelName = (*it).stripWhiteSpace(); - if (!channelName.startsWith("#")) { - QMessageBox::critical(this, tr("Error"), tr("The channel list needs to contain a\ncomma separated list of channel\n names which start with '#'")); + if (!channelName.startsWith("#") && !channelName.startsWith("+")) { + QMessageBox::critical(this, tr("Error"), tr("The channel list needs to contain a\ncomma separated list of channel\n names which start with either '#' or '+'")); return; } } QDialog::accept(); } } IRCServer IRCServerEditor::getServer() { IRCServer server; server.setName(m_name->text()); server.setHostname(m_hostname->text()); server.setPort(m_port->text().toInt()); server.setNick(m_nickname->text()); server.setRealname(m_realname->text()); server.setUsername(m_nickname->text()); server.setPassword(m_password->text()); server.setChannels(m_channels->text()); return server; } diff --git a/noncore/net/opieirc/ircservertab.cpp b/noncore/net/opieirc/ircservertab.cpp index aea58a3..d16c05f 100644 --- a/noncore/net/opieirc/ircservertab.cpp +++ b/noncore/net/opieirc/ircservertab.cpp @@ -1,167 +1,167 @@ #include <qpe/config.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_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))); settingsChanged(); } 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); } 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; } IRCServer *IRCServerTab::server() { return &m_server; } void IRCServerTab::settingsChanged() { m_textview->setText("<qt bgcolor=\"" + m_backgroundColor + "\"/>"); } 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("#")) { + if (channel.length() > 0 && (channel.startsWith("#") || channel.startsWith("+"))) { m_session->join(channel); } else { tab->appendText("<font color=\"" + m_errorColor + "\">Unknown channel format!</font><br>"); } } 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>"); } } } 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()); } 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()); |