Port things from MSN to WLM plugin:
[kdenetwork.git] / kopete / protocols / groupwise / gwconnector.cpp
blobc3cb3c9f2d9e125e431bd24403f1fe73468b328b
2 /***************************************************************************
3 gwconnector.cpp - Socket Connector for KNetwork
4 -------------------
5 begin : Wed Jul 7 2004
6 copyright : (C) 2004 by Till Gerken <till@tantalo.net>
8 Kopete (C) 2004-2007 Kopete developers <kopete-devel@kde.org>
9 ***************************************************************************/
11 /***************************************************************************
12 * *
13 * This program is free software; you can redistribute it and/or modify *
14 * it under the terms of the GNU Lesser General Public License as *
15 * published by the Free Software Foundation; either version 2.1 of the *
16 * License, or (at your option) any later version. *
17 * *
18 ***************************************************************************/
20 #include <k3bufferedsocket.h>
21 #include <kdebug.h>
22 #include <k3resolver.h>
24 #include "gwconnector.h"
25 #include "gwerror.h"
26 #include "gwbytestream.h"
28 KNetworkConnector::KNetworkConnector ( QObject *parent )
29 : Connector ( parent )
31 kDebug () << "New KNetwork connector.";
33 mErrorCode = 0;
35 mByteStream = new KNetworkByteStream ( this );
37 connect ( mByteStream, SIGNAL ( connected () ), this, SLOT ( slotConnected () ) );
38 connect ( mByteStream, SIGNAL ( error ( int ) ), this, SLOT ( slotError ( int ) ) );
39 mPort = 0;
42 KNetworkConnector::~KNetworkConnector ()
45 delete mByteStream;
49 void KNetworkConnector::connectToServer ( const QString &server )
51 kDebug () << "Initiating connection to " << mHost;
52 Q_ASSERT( !mHost.isNull() );
53 Q_ASSERT( mPort );
55 * FIXME: we should use a SRV lookup to determine the
56 * actual server to connect to. As this is currently
57 * not supported yet, we're using setOptHostPort().
58 * For XMPP 1.0, we need to enable this!
61 mErrorCode = 0;
63 mByteStream->connect ( mHost, QString::number ( mPort ) );
66 void KNetworkConnector::slotConnected ()
68 kDebug() << "We are connected.";
70 // FIXME: setPeerAddress() is something different, find out correct usage later
71 //KInetSocketAddress inetAddress = mStreamSocket->address().asInet().makeIPv6 ();
72 //setPeerAddress ( QHostAddress ( inetAddress.ipAddress().addr () ), inetAddress.port () );
74 emit connected ();
78 void KNetworkConnector::slotError ( int code )
80 kDebug() << "Error detected: " << code;
82 mErrorCode = code;
83 emit error ();
86 int KNetworkConnector::errorCode ()
89 return mErrorCode;
93 ByteStream *KNetworkConnector::stream () const
96 return mByteStream;
100 void KNetworkConnector::done ()
102 kDebug () ;
103 mByteStream->close ();
106 void KNetworkConnector::setOptHostPort ( const QString &host, quint16 port )
108 kDebug () << "Manually specifying host " << host << " and port " << port;
110 mHost = host;
111 mPort = port;
115 void KNetworkConnector::setOptSSL ( bool ssl )
117 kDebug () << "Setting SSL to " << ssl;
119 setUseSSL ( ssl );
123 #include "gwconnector.moc"