23 #include "ircclient.h" 26 IRCClient::IRCClient()
28 recvTimer.setSingleShot(
true);
31 QObject::connect(&socket, SIGNAL(readyRead()),
this, SLOT(receiveSocketDataDelayed()));
32 QObject::connect(&recvTimer, SIGNAL(timeout()),
this, SLOT(receiveSocketData()));
35 IRCClient::~IRCClient()
40 void IRCClient::connect(
const QString &address,
unsigned short port)
43 this->hostName = address;
45 emit
infoMessage(tr(
"IRC: Connecting: %1:%2").arg(this->hostName).arg(this->port));
46 socket.connectToHost(address, port);
51 pAdapter->pSocket = &socket;
52 pAdapter->connect(&socket, SIGNAL(connected()), SLOT(connected()));
53 pAdapter->connect(&socket, SIGNAL(disconnected()), SLOT(disconnected()));
54 pAdapter->connect(&socket, SIGNAL(error(QAbstractSocket::SocketError)), SLOT(errorReceived(QAbstractSocket::SocketError)));
58 void IRCClient::disconnect()
64 bool IRCClient::isConnected()
const 66 return socket.state() == QTcpSocket::ConnectedState;
69 void IRCClient::receiveSocketData()
71 while (socket.canReadLine())
73 QByteArray socketData = socket.readLine();
74 QString responseLine = QString::fromUtf8(socketData.constData(), socketData.size());
75 emit ircServerResponse(responseLine);
79 void IRCClient::receiveSocketDataDelayed()
81 if (!recvTimer.isActive())
85 bool IRCClient::sendMessage(
const QString &message)
90 QByteArray messageContent = message.toUtf8();
91 messageContent.append(
"\r\n");
93 qint64 numBytesWritten = socket.write(messageContent);
96 return numBytesWritten == messageContent.size();
99 void IRCClient::setFakeRecvLag(
int lagMs)
101 recvTimer.setInterval(lagMs);
void infoMessage(const QString &message)
These are the messages that IRCClient class sends to inform the upper layers of progress.