1 /***************************************************************************
2 * Copyright (C) 2005/06 by The Quassel Team *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
24 socket = new QTcpSocket();
33 Message::init(&handleServerMsg, &handleUserMsg);
37 connect(socket, SIGNAL(connected()), this, SLOT(socketConnected()));
38 connect(socket, SIGNAL(disconnected()), this, SLOT(socketDisconnected()));
39 connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(socketError(QAbstractSocket::SocketError)));
40 connect(socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), this, SLOT(socketStateChanged(QAbstractSocket::SocketState)));
41 connect(socket, SIGNAL(readyRead()), this, SLOT(socketHasData()));
43 stream.setDevice(socket);
44 //connectToIrc("irc.quakenet.org", 6667);
49 QAbstractSocket::SocketState TcpConnection::state( ) const {
50 return socket.state();
54 void Server::connectToIrc( const QString & host, quint16 port ) {
55 qDebug() << "Connecting...";
56 socket->connectToHost(host, port);
59 void Server::disconnectFromIrc( ) {
60 socket->disconnectFromHost();
63 void Server::putRawLine( const QString &s ) {
64 qDebug() << "Raw line: " << s;
65 stream << s << "\r\n" << flush;
68 void Server::socketHasData( ) {
69 while(socket->canReadLine()) {
70 QString s = stream.readLine();
71 qDebug() << "Read: " << s;
72 emit recvLine(s + "\n");
76 void Server::socketError( QAbstractSocket::SocketError err ) {
77 qDebug() << "Socket Error!";
81 void Server::socketConnected( ) {
82 qDebug() << "Socket connected!";
86 void Server::socketDisconnected( ) {
87 qDebug() << "Socket disconnected!";
88 //emit disconnected();
91 void Server::socketStateChanged(QAbstractSocket::SocketState state) {
92 qDebug() << "Socket state changed: " << state;
95 void Server::handleServerMsg(Message *msg) {
100 void Server::handleUserMsg(Message *msg) {