make webinterface translatable. there are around 20 short strings, all with context...
[kdenetwork.git] / kopete / protocols / groupwise / gwbytestream.cpp
blob4b143097162b6d995a450c361d64188df92971d1
2 /***************************************************************************
3 gwbytestream.cpp - Byte Stream using KNetwork sockets
4 -------------------
5 begin : Wed Jul 7 2004
6 copyright : (C) 2004 by Till Gerken <till@tantalo.net>
7 Copyright : (c) 2006 Novell, Inc http://www.opensuse.org
9 Kopete (C) 2004-2007 Kopete developers <kopete-devel@kde.org>
10 ***************************************************************************/
12 /***************************************************************************
13 * *
14 * This program is free software; you can redistribute it and/or modify *
15 * it under the terms of the GNU General Public License as published by *
16 * the Free Software Foundation; either version 2 of the License, or *
17 * (at your option) any later version. *
18 * *
19 ***************************************************************************/
21 #include "gwbytestream.h"
22 #include <ksocketfactory.h>
24 #include <kdebug.h>
26 #include "gwerror.h"
28 KNetworkByteStream::KNetworkByteStream ( QObject *parent )
29 : ByteStream ( parent )
31 kDebug () << "Instantiating new KNetwork byte stream.";
33 // reset close tracking flag
34 mClosing = false;
36 mSocket = 0;
40 bool KNetworkByteStream::connect ( QString host, QString service )
42 kDebug () << "Connecting to " << host << ", service " << service;
43 mSocket = KSocketFactory::connectToHost( "gwims", host, service.toUInt(), this );
45 QObject::connect( mSocket, SIGNAL(error(QAbstractSocket::SocketError)),
46 this, SLOT(slotError(QAbstractSocket::SocketError)) );
47 QObject::connect( mSocket, SIGNAL(connected()), this, SLOT(slotConnected()) );
48 QObject::connect( mSocket, SIGNAL(disconnected()), this, SLOT(slotConnectionClosed()) );
49 QObject::connect( mSocket, SIGNAL(readyRead()), this, SLOT(slotReadyRead()) );
50 QObject::connect( mSocket, SIGNAL(bytesWritten(qint64)), this, SLOT(slotBytesWritten(qint64)) );
51 return true;
54 bool KNetworkByteStream::isOpen () const
57 // determine if socket is open
58 if ( socket() )
60 return socket()->isOpen ();
62 else
64 return false;
69 void KNetworkByteStream::close ()
71 kDebug () << "Closing stream.";
73 // close the socket and set flag that we are closing it ourselves
74 mClosing = true;
75 if ( socket() )
76 socket()->close();
80 int KNetworkByteStream::tryWrite ()
83 // send all data from the buffers to the socket
84 QByteArray writeData = takeWrite();
85 socket()->write ( writeData.data (), writeData.size () );
87 return writeData.size ();
91 QTcpSocket *KNetworkByteStream::socket () const
94 return mSocket;
98 KNetworkByteStream::~KNetworkByteStream ()
102 void KNetworkByteStream::slotConnected ()
105 emit connected ();
109 void KNetworkByteStream::slotConnectionClosed ()
111 kDebug () << "Socket has been closed.";
113 // depending on who closed the socket, emit different signals
114 if ( mClosing )
116 kDebug () << "..by ourselves!";
117 kDebug() << "socket error is \"" << socket()->errorString() << "\"";
118 emit connectionClosed ();
120 else
122 kDebug () << "..by the other end";
123 emit delayedCloseFinished ();
128 void KNetworkByteStream::slotReadyRead ()
130 appendRead ( socket()->readAll() );
132 emit readyRead ();
136 void KNetworkByteStream::slotBytesWritten ( qint64 bytes )
139 emit bytesWritten ( bytes );
143 void KNetworkByteStream::slotError ( QAbstractSocket::SocketError code )
145 kDebug () << "Socket error " << mSocket->errorString() << "' - Code : " << code;
146 emit error ( code );
149 #include "gwbytestream.moc"