author | erik <erik> | 2007-07-09 22:06:00 (UTC) |
---|---|---|
committer | erik <erik> | 2007-07-09 22:06:00 (UTC) |
commit | a91bbaee9eb419dc985d9f5c3689831c8aa75c1e (patch) (side-by-side diff) | |
tree | ba0da224a93f7af1a80a4bef3186edff8dc9483f | |
parent | 1ec355e1cc016edd2e322ff7d57469feaa46474b (diff) | |
download | opie-a91bbaee9eb419dc985d9f5c3689831c8aa75c1e.zip opie-a91bbaee9eb419dc985d9f5c3689831c8aa75c1e.tar.gz opie-a91bbaee9eb419dc985d9f5c3689831c8aa75c1e.tar.bz2 |
Fix for opie bug 1719. This should make opie-irc play nicer with utf-8.
Patches were culled from OE. Thanks to whoever the original patch author
was.
-rw-r--r-- | noncore/net/opieirc/ircconnection.cpp | 5 | ||||
-rw-r--r-- | noncore/net/opieirc/ircmessageparser.cpp | 4 |
2 files changed, 5 insertions, 4 deletions
diff --git a/noncore/net/opieirc/ircconnection.cpp b/noncore/net/opieirc/ircconnection.cpp index 88e63f7..fb7e168 100644 --- a/noncore/net/opieirc/ircconnection.cpp +++ b/noncore/net/opieirc/ircconnection.cpp @@ -1,122 +1,123 @@ #include <unistd.h> #include <string.h> #include <qstringlist.h> #include <qdatetime.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()); + QCString uline = line.utf8(); + m_socket->writeBlock(uline, uline.length()); } void IRCConnection::sendCTCPReply(const QString &nickname, const QString &type, const QString &args) { sendLine("NOTICE " + nickname + " :\001" + type + " " + args + "\001"); } void IRCConnection::sendCTCPRequest(const QString &nickname, const QString &type, const QString &args) { sendLine("PRIVMSG " + nickname + " :\001" + type + " " + args + "\001"); } void IRCConnection::sendCTCPPing(const QString &nickname) { QDateTime tm; tm.setTime_t(0); QString strtime = QString::number(tm.secsTo(QDateTime::currentDateTime())); sendCTCPRequest(nickname, "PING", strtime); } void IRCConnection::whois(const QString &nickname) { sendLine("WHOIS " + nickname); } /* * 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()); + IRCMessage message(QString::fromUtf8(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("#") || 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 c449a65..ae47f69 100644 --- a/noncore/net/opieirc/ircmessageparser.cpp +++ b/noncore/net/opieirc/ircmessageparser.cpp @@ -606,78 +606,78 @@ void IRCMessageParser::parseNumericalNames(IRCMessage *message) { case '~': case '&': case '@': flag = IRCChannelPerson::PERSON_FLAG_OP; break; case '+': flag = IRCChannelPerson::PERSON_FLAG_VOICE; break; case '%': flag = IRCChannelPerson::PERSON_FLAG_HALFOP; break; default : flag = 0; break; } } else nick = temp; IRCPerson *person = m_session->getPerson(nick); if (person == 0) { person = new IRCPerson(); person->setNick(nick); m_session->addPerson(person); } IRCChannelPerson *chan_person = new IRCChannelPerson(person); chan_person->setFlags(flag); channel->addPerson(chan_person); } } else emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Server message with unknown channel"))); } void IRCMessageParser::parseNumericalEndOfNames(IRCMessage *message) { /* Done syncing to channel */ IRCChannel *channel = m_session->getChannel(message->param(1).lower()); if (channel) { channel->setHasPeople(TRUE); /* Yes, we want the names before anything happens inside the GUI */ IRCOutput output(OUTPUT_SELFJOIN, tr("You joined channel ") + channel->channelname()); output.addParam(channel); emit outputReady(output); } else { emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Server message with unknown channel"))); } } void IRCMessageParser::parseNumericalNicknameInUse(IRCMessage *) { /* If we are connnected this error is not critical */ if(m_session->isLoggedIn()) return; 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"))); } void IRCMessageParser::parseNumericalTopic(IRCMessage *message) { IRCChannel *channel = m_session->getChannel(message->param(1).lower()); if (channel) { - IRCOutput output(OUTPUT_TOPIC, tr("Topic for channel " + channel->channelname() + " is \"" + message->param(2) + "\"")); + IRCOutput output(OUTPUT_TOPIC, tr("Topic for channel ") + channel->channelname() + tr(" is \"") + message->param(2) + "\""); output.addParam(channel); emit outputReady(output); } else { - IRCOutput output(OUTPUT_TOPIC, tr("Topic for channel " + message->param(1) + " is \"" + message->param(2) + "\"")); + IRCOutput output(OUTPUT_TOPIC, tr("Topic for channel ") + message->param(1) + tr(" is \"") + message->param(2) + "\""); output.addParam(0); emit outputReady(output); } } void IRCMessageParser::parseNumericalTopicWhoTime(IRCMessage *) { } |