/***************************************************************************
                            KSocket.m -  description
                             -------------------
    begin                : Thu Mar 21 01:01:29 2002
    copyright            : (C) 2000-2002 Lost Highway Ltd. All rights reserved.
    email                : Lost_Highway@tipitina.demon.co.uk
    generated by         : duke@tipitina on Thu Mar 21 01:01:29 2002, using kalyptus 0.9.
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This library is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU Library General Public License as       *
 *   published by the Free Software Foundation; either version 2 of the    *
 *   License, or (at your option) any later version.                       *
 *                                                                         *
 ***************************************************************************/

#include <qtc/qt_QString.h>
#include <qtc/qt_QCString.h>
#include <kdec/kde_KSocket.h>
#include <kdeobjc/KDESupport.h>
#include <kdeobjc/KSocket.h>

@implementation  KSocket


- initWithInt: (int)_sock
{
	if ([self qt] == 0L) {
		[self setQt: kde_new_KSocket((int)_sock)];
		[self setAllocatedInObjcWorld: YES];
		[QtSupport setObject: self forQtKey: [self qt]];
	}
	[super init];
	return self;
}

- initWithText: (NSString *)_host _port: (unsigned short)_port timeOut: (int)timeOut
{
	if ([self qt] == 0L) {
		[self setQt: kde_new_KSocket1((char*) [_host cString], (unsigned short)_port, (int)timeOut)];
		[self setAllocatedInObjcWorld: YES];
		[QtSupport setObject: self forQtKey: [self qt]];
	}
	[super init];
	return self;
}

- initWithText: (NSString *)_host _port: (unsigned short)_port 
{
	if ([self qt] == 0L) {
		[self setQt: kde_new_KSocket1((char*) [_host cString], (unsigned short)_port, 30)];
		[self setAllocatedInObjcWorld: YES];
		[QtSupport setObject: self forQtKey: [self qt]];
	}
	[super init];
	return self;
}

- initWithText: (NSString *)_path
{
	if ([self qt] == 0L) {
		[self setQt: kde_new_KSocket2((char*) [_path cString])];
		[self setAllocatedInObjcWorld: YES];
		[QtSupport setObject: self forQtKey: [self qt]];
	}
	[super init];
	return self;
}

- (void) dealloc
{
	if ([self qt] != 0L) {
		if ([self allocatedInObjcWorld] && [self parent] == nil) {
			kde_del_KSocket((kde_KSocket *)[self qt]);
		}
		[QtSupport removeQtKey: [self qt]];
		[self setQt: 0L];
	}
	[super dealloc];
}

- (int) socket
{
	return (int) kde_KSocket_socket((kde_KSocket *)[self qt]);
}

- enableRead: (BOOL)arg1
{
	kde_KSocket_enableRead((kde_KSocket *)[self qt], (int)arg1);
	return self;
}

- enableWrite: (BOOL)arg1
{
	kde_KSocket_enableWrite((kde_KSocket *)[self qt], (int)arg1);
	return self;
}

//- (unsigned long) ipv4_addr
//{
//	return (unsigned long) kde_KSocket_ipv4_addr((kde_KSocket *)[self qt]);
//}

- slotWrite: (int)arg1
{
	kde_KSocket_slotWrite((kde_KSocket *)[self qt], (int)arg1);
	return self;
}

- slotRead: (int)arg1
{
	kde_KSocket_slotRead((kde_KSocket *)[self qt], (int)arg1);
	return self;
}

//+ (BOOL) initSockaddr: (void*)server_name hostname: (NSString *)hostname port: (unsigned short)port domain: (int)domain
//{
//	return (BOOL) kde_KSocket_initSockaddr((void*)server_name, (char*) [hostname cString], (unsigned short)port, (int)domain);
//}

//+ (BOOL) initSockaddr: (void*)server_name hostname: (NSString *)hostname port: (unsigned short)port
//{
//	return (BOOL) kde_KSocket_initSockaddr((void*)server_name, (char*) [hostname cString], (unsigned short)port, [KSocket PF_INET]);
//}

- (BOOL) connect: (NSString *)_host _port: (unsigned short)_port timeout: (int)timeout
{
static qt_QString * _qstring__host = 0L;
	return (BOOL) kde_KSocket_connect((kde_KSocket *)[self qt], (qt_QString *) [_host toQString: &_qstring__host], (unsigned short)_port, (int)timeout);
}

- (BOOL) connect: (NSString *)_host _port: (unsigned short)_port 
{
static qt_QString * _qstring__host = 0L;
	return (BOOL) kde_KSocket_connect((kde_KSocket *)[self qt], (qt_QString *) [_host toQString: &_qstring__host], (unsigned short)_port, 0);
}

- (BOOL) connect: (NSString *)_path
{
	return (BOOL) kde_KSocket_connect1((kde_KSocket *)[self qt], (char*) [_path cString]);
}

@end
