d493e67cfe1a6ce94098bf572912bd6048be7e1b
[quassel.git] / network / server.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005/06 by The Quassel Team                             *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
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.                                   *
9  *                                                                         *
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.                          *
14  *                                                                         *
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  ***************************************************************************/
20
21 #include "server.h"
22
23 Server::Server() {
24   socket = new QTcpSocket();
25
26 }
27
28 Server::~Server() {
29   delete socket;
30 }
31
32 void Server::run() {
33   connect(socket, SIGNAL(connected()), this, SLOT(socketConnected()));
34   connect(socket, SIGNAL(disconnected()), this, SLOT(socketDisconnected()));
35   connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(socketError(QAbstractSocket::SocketError)));
36   connect(socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), this, SLOT(socketStateChanged(QAbstractSocket::SocketState)));
37   connect(socket, SIGNAL(readyRead()), this, SLOT(socketHasData()));
38
39   stream.setDevice(socket);
40   //connectToIrc("irc.quakenet.org", 6667);
41   exec();
42 }
43
44 /*
45 QAbstractSocket::SocketState TcpConnection::state( ) const {
46   return socket.state();
47 }
48 */
49
50 void Server::connectToIrc( const QString & host, quint16 port ) {
51   qDebug() << "Connecting...";
52   socket->connectToHost(host, port);
53 }
54
55 void Server::disconnectFromIrc( ) {
56   socket->disconnectFromHost();
57 }
58
59 void Server::putRawLine( const QString &s ) {
60   qDebug() << "Raw line: " << s;
61   stream << s << "\r\n" << flush;
62 }
63
64 void Server::socketHasData( ) {
65   while(socket->canReadLine()) {
66     QString s = stream.readLine();
67     qDebug() << "Read: " << s;
68     emit recvLine(s + "\n");
69   }
70 }
71
72 void Server::socketError( QAbstractSocket::SocketError err ) {
73   qDebug() << "Socket Error!";
74   //emit error(err);
75 }
76
77 void Server::socketConnected( ) {
78   qDebug() << "Socket connected!";
79   //emit connected();
80 }
81
82 void Server::socketDisconnected( ) {
83   qDebug() << "Socket disconnected!";
84   //emit disconnected();
85 }
86
87 void Server::socketStateChanged(QAbstractSocket::SocketState state) {
88   qDebug() << "Socket state changed: " << state;
89 }
90
91