/***************************************************************************
                            KServerSocket.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_KServerSocket.h>
#include <kdeobjc/KDESupport.h>
#include <kdeobjc/KServerSocket.h>

@implementation  KServerSocket


- initWithUnsigned: (unsigned short)_port _bind: (BOOL)_bind
{
	if ([self qt] == 0L) {
		[self setQt: kde_new_KServerSocket((unsigned short)_port, (int)_bind)];
		[self setAllocatedInObjcWorld: YES];
		[QtSupport setObject: self forQtKey: [self qt]];
	}
	[super init];
	return self;
}

- initWithUnsigned: (unsigned short)_port 
{
	if ([self qt] == 0L) {
		[self setQt: kde_new_KServerSocket((unsigned short)_port, 1)];
		[self setAllocatedInObjcWorld: YES];
		[QtSupport setObject: self forQtKey: [self qt]];
	}
	[super init];
	return self;
}

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

- initWithText: (NSString *)_path 
{
	if ([self qt] == 0L) {
		[self setQt: kde_new_KServerSocket1((char*) [_path cString], 1)];
		[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_KServerSocket((kde_KServerSocket *)[self qt]);
		}
		[QtSupport removeQtKey: [self qt]];
		[self setQt: 0L];
	}
	[super dealloc];
}

- (BOOL) bindAndListen
{
	return (BOOL) kde_KServerSocket_bindAndListen((kde_KServerSocket *)[self qt]);
}

- (int) socket
{
	return (int) kde_KServerSocket_socket((kde_KServerSocket *)[self qt]);
}

- (unsigned short) port
{
	return (unsigned short) kde_KServerSocket_port((kde_KServerSocket *)[self qt]);
}

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

- slotAccept: (int)arg1
{
	kde_KServerSocket_slotAccept((kde_KServerSocket *)[self qt], (int)arg1);
	return self;
}

- (BOOL) initWithId: (short)arg1
{
	return (BOOL) kde_KServerSocket_init((kde_KServerSocket *)[self qt], (short)arg1);
}

- (BOOL) init: (NSString *)_path
{
	return (BOOL) kde_KServerSocket_init1((kde_KServerSocket *)[self qt], (char*) [_path cString]);
}

@end
