/***************************************************************************
                            DCOPStub.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_DCOPStub.h>
#include <kdeobjc/KDESupport.h>
#include <kdeobjc/DCOPStub.h>
#include <kdeobjc/DCOPClient.h>


@implementation  DCOPStub

- (void *) qt
{
	return _qt;
}

- setQt: (void *) qt
{
	_qt = qt;
	return self;
}

- (BOOL) allocatedInObjcWorld
{
	return _allocatedInObjcWorld;
}

- setAllocatedInObjcWorld: (BOOL) yn
{
	_allocatedInObjcWorld = yn;
	return self;
}


- initWithText: (NSString *)app obj: (NSString *)obj
{
static qt_QCString * _qcstring_obj = 0L;
static qt_QCString * _qcstring_app = 0L;
	if ([self qt] == 0L) {
		[self setQt: kde_new_DCOPStub((qt_QCString*) [app toQCString: &_qcstring_app], (qt_QCString*) [obj toQCString: &_qcstring_obj])];
		[self setAllocatedInObjcWorld: YES];
		[QtSupport setObject: self forQtKey: [self qt]];
	}
	[super init];
	return self;
}

- initWithDCOPClient: (DCOPClient*)client app: (NSString *)app obj: (NSString *)obj
{
static qt_QCString * _qcstring_obj = 0L;
static qt_QCString * _qcstring_app = 0L;
	if ([self qt] == 0L) {
		[self setQt: kde_new_DCOPStub1((kde_DCOPClient*) [client qt], (qt_QCString*) [app toQCString: &_qcstring_app], (qt_QCString*) [obj toQCString: &_qcstring_obj])];
		[self setAllocatedInObjcWorld: YES];
		[QtSupport setObject: self forQtKey: [self qt]];
	}
	[super init];
	return self;
}

- (void) dealloc
{
	if ([self qt] != 0L) {
		if ([self allocatedInObjcWorld]) {
			kde_del_DCOPStub((kde_DCOPStub *)[self qt]);
		}
		[QtSupport removeQtKey: [self qt]];
		[self setQt: 0L];
	}
	[super dealloc];
}

- (NSString *) app
{
static qt_QCString * _qcstring = 0L;
	_qcstring = kde_DCOPStub_app((kde_DCOPStub *)[self qt]);
	return [NSString fromQCString: _qcstring];
}

- (NSString *) obj
{
static qt_QCString * _qcstring = 0L;
	_qcstring = kde_DCOPStub_obj((kde_DCOPStub *)[self qt]);
	return [NSString fromQCString: _qcstring];
}

- (int) status
{
	return (int) kde_DCOPStub_status((kde_DCOPStub *)[self qt]);
}

- (BOOL) ok
{
	return (BOOL) kde_DCOPStub_ok((kde_DCOPStub *)[self qt]);
}

- setStatus: (int)_status
{
	kde_DCOPStub_setStatus((kde_DCOPStub *)[self qt], (int)_status);
	return self;
}

- callFailed
{
	kde_DCOPStub_callFailed((kde_DCOPStub *)[self qt]);
	return self;
}

- (DCOPClient*) dcopClient
{
	return (DCOPClient*) [QtSupport objectForQtKey: kde_DCOPStub_dcopClient((kde_DCOPStub *)[self qt]) withClass: [DCOPClient class] allocatedInObjcWorld: YES];
}

+ (int) CallSucceeded
{
	return (int) DCOPSTUB_CallSucceeded;
}

+ (int) CallFailed
{
	return (int) DCOPSTUB_CallFailed;
}

@end
