/***************************************************************************
                            Connection.m -  description
                             -------------------
    begin                : Fri Mar  8 13:55:08 2002
    copyright            : (C) 2000-2002 Lost Highway Ltd. All rights reserved.
    email                : Lost_Highway@tipitina.demon.co.uk
    generated by         : duke@tipitina on Fri Mar  8 13:55:08 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_Connection.h>
#include <kdeobjc/KDESupport.h>
#include <kdeobjc/Connection.h>
#include <kdeobjc/KSocket.h>
#include <qtobjc/QByteArray.h>


@implementation  Connection


- init
{
	if ([self qt] == 0L) {
		[self setQt: kde_new_Connection()];
		[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_Connection((kde_Connection *)[self qt]);
		}
		[QtSupport removeQtKey: [self qt]];
		[self setQt: 0L];
	}
	[super dealloc];
}

- init: (KSocket*)sock
{
	kde_Connection_init((kde_Connection *)[self qt], (kde_KSocket*) [sock qt]);
	return self;
}

- init: (int)fd_in fd_out: (int)fd_out
{
	kde_Connection_init1((kde_Connection *)[self qt], (int)fd_in, (int)fd_out);
	return self;
}

- connect: (QObject *)receiver slot: (NSString *)member
{
	kde_Connection_connect((kde_Connection *)[self qt], (qt_QObject *) [receiver qt], (char*) [member cString]);
	return self;
}

- connect
{
	kde_Connection_connect((kde_Connection *)[self qt], 0, 0);
	return self;
}

- close
{
	kde_Connection_close((kde_Connection *)[self qt]);
	return self;
}

- (int) fd_from
{
	return (int) kde_Connection_fd_from((kde_Connection *)[self qt]);
}

- (int) fd_to
{
	return (int) kde_Connection_fd_to((kde_Connection *)[self qt]);
}

- (BOOL) inited
{
	return (BOOL) kde_Connection_inited((kde_Connection *)[self qt]);
}

- send: (int)cmd arr: (QByteArray*)arr
{
	kde_Connection_send((kde_Connection *)[self qt], (int)cmd, (qt_QByteArray*) [arr qt]);
	return self;
}

- send: (int)cmd 
{
	kde_Connection_send((kde_Connection *)[self qt], (int)cmd, 0);
	return self;
}

- (BOOL) sendnow: (int)cmd data: (QByteArray*)data
{
	return (BOOL) kde_Connection_sendnow((kde_Connection *)[self qt], (int)cmd, (qt_QByteArray*) [data qt]);
}

- (int) read: (int*)cmd bytearray: (QByteArray*)arg1
{
	return (int) kde_Connection_read((kde_Connection *)[self qt], (int*)cmd, (qt_QByteArray*) [arg1 qt]);
}

- suspend
{
	kde_Connection_suspend((kde_Connection *)[self qt]);
	return self;
}

- resume
{
	kde_Connection_resume((kde_Connection *)[self qt]);
	return self;
}

- (BOOL) suspended
{
	return (BOOL) kde_Connection_suspended((kde_Connection *)[self qt]);
}

- dequeue
{
	kde_Connection_dequeue((kde_Connection *)[self qt]);
	return self;
}

@end
