/***************************************************************************
                            KUniqueApplication.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_KUniqueApplication.h>
#include <kdec/kde_DCOPObject.h>
#include <kdeobjc/KDESupport.h>
#include <kdeobjc/KUniqueApplication.h>
#include <qtobjc/QByteArray.h>


@implementation  KUniqueApplication


- initWithBOOL: (BOOL)allowStyles GUIenabled: (BOOL)GUIenabled configUnique: (BOOL)configUnique
{
	if ([self qt] == 0L) {
		[self setQt: kde_new_KUniqueApplication((int)allowStyles, (int)GUIenabled, (int)configUnique)];
		[self setAllocatedInObjcWorld: YES];
		[QtSupport setObject: self forQtKey: [self qt]];
	}
	[super init];
	return self;
}

- init
{
	if ([self qt] == 0L) {
		[self setQt: kde_new_KUniqueApplication(1, 1, 0)];
		[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_KUniqueApplication((kde_KUniqueApplication *)[self qt]);
		}
		[QtSupport removeQtKey: [self qt]];
		[self setQt: 0L];
	}
	[super dealloc];
}

- (BOOL) process: (NSString *)fun data: (QByteArray*)data replyType: (NSString *)replyType replyData: (QByteArray*)replyData
{
static qt_QCString * _qcstring_replyType = 0L;
static qt_QCString * _qcstring_fun = 0L;
	return (BOOL) kde_KUniqueApplication_process((kde_KUniqueApplication *)[self qt], (qt_QCString*) [fun toQCString: &_qcstring_fun], (qt_QByteArray*) [data qt], (qt_QCString*) [replyType toQCString: &_qcstring_replyType], (qt_QByteArray*) [replyData qt]);
}

- (int) newInstance
{
	return (int) kde_KUniqueApplication_newInstance((kde_KUniqueApplication *)[self qt]);
}

+ addCmdLineOptions
{
	kde_KUniqueApplication_addCmdLineOptions();
	return self;
}

+ (BOOL) start
{
	return (BOOL) kde_KUniqueApplication_start();
}

@end

@implementation KUniqueApplication (DCOPObjectImplementation)

- (NSString *) objId
{
static qt_QCString * _qcstring = 0L;
	_qcstring = kde_DCOPObject_objId(kde_KUniqueApplication_DCOPObject([self qt]));
	return [NSString fromQCString: _qcstring];
}

- (BOOL) setObjId: (NSString *)objId
{
static qt_QCString * _qcstring_objId = 0L;
	return (BOOL) kde_DCOPObject_setObjId(kde_KUniqueApplication_DCOPObject([self qt]), (qt_QCString*) [objId toQCString: &_qcstring_objId]);
}

- (BOOL) process: (NSString *)fun data: (QByteArray*)data replyType: (NSString *)replyType replyData: (QByteArray*)replyData
{
static qt_QCString * _qcstring_replyType = 0L;
static qt_QCString * _qcstring_fun = 0L;
	return (BOOL) kde_DCOPObject_process(kde_KUniqueApplication_DCOPObject([self qt]), (qt_QCString*) [fun toQCString: &_qcstring_fun], (qt_QByteArray*) [data qt], (qt_QCString*) [replyType toQCString: &_qcstring_replyType], (qt_QByteArray*) [replyData qt]);
}

- (BOOL) processDynamic: (NSString *)fun data: (QByteArray*)data replyType: (NSString *)replyType replyData: (QByteArray*)replyData
{
static qt_QCString * _qcstring_replyType = 0L;
static qt_QCString * _qcstring_fun = 0L;
	return (BOOL) kde_DCOPObject_processDynamic(kde_KUniqueApplication_DCOPObject([self qt]), (qt_QCString*) [fun toQCString: &_qcstring_fun], (qt_QByteArray*) [data qt], (qt_QCString*) [replyType toQCString: &_qcstring_replyType], (qt_QByteArray*) [replyData qt]);
}

- (NSArray *) functionsDynamic
{
static kde_QCStringList * _qlist = 0L;
	_qlist = kde_DCOPObject_functionsDynamic(kde_KUniqueApplication_DCOPObject([self qt]));
	return (NSArray *) [NSMutableArray arrayWithQCStringList: _qlist];
}

- (NSArray *) interfacesDynamic
{
static kde_QCStringList * _qlist = 0L;
	_qlist = kde_DCOPObject_interfacesDynamic(kde_KUniqueApplication_DCOPObject([self qt]));
	return (NSArray *) [NSMutableArray arrayWithQCStringList: _qlist];
}

- (NSArray *) interfaces
{
static kde_QCStringList * _qlist = 0L;
	_qlist = kde_DCOPObject_interfaces(kde_KUniqueApplication_DCOPObject([self qt]));
	return (NSArray *) [NSMutableArray arrayWithQCStringList: _qlist];
}

- (NSArray *) functions
{
static kde_QCStringList * _qlist = 0L;
	_qlist = kde_DCOPObject_functions(kde_KUniqueApplication_DCOPObject([self qt]));
	return (NSArray *) [NSMutableArray arrayWithQCStringList: _qlist];
}

- emitDCOPSignal: (NSString *)signal data: (QByteArray*)data
{
static qt_QCString * _qcstring_signal = 0L;
	kde_DCOPObject_emitDCOPSignal(kde_KUniqueApplication_DCOPObject([self qt]), (qt_QCString*) [signal toQCString: &_qcstring_signal], (qt_QByteArray*) [data qt]);
	return self;
}

- (BOOL) connectDCOPSignal: (NSString *)sender senderObj: (NSString *)senderObj signal: (NSString *)signal slot: (NSString *)slot Volatile: (BOOL)Volatile
{
static qt_QCString * _qcstring_slot = 0L;
static qt_QCString * _qcstring_signal = 0L;
static qt_QCString * _qcstring_senderObj = 0L;
static qt_QCString * _qcstring_sender = 0L;
	return (BOOL) kde_DCOPObject_connectDCOPSignal(kde_KUniqueApplication_DCOPObject([self qt]), (qt_QCString*) [sender toQCString: &_qcstring_sender], (qt_QCString*) [senderObj toQCString: &_qcstring_senderObj], (qt_QCString*) [signal toQCString: &_qcstring_signal], (qt_QCString*) [slot toQCString: &_qcstring_slot], (int)Volatile);
}

- (BOOL) disconnectDCOPSignal: (NSString *)sender senderObj: (NSString *)senderObj signal: (NSString *)signal slot: (NSString *)slot
{
static qt_QCString * _qcstring_slot = 0L;
static qt_QCString * _qcstring_signal = 0L;
static qt_QCString * _qcstring_senderObj = 0L;
static qt_QCString * _qcstring_sender = 0L;
	return (BOOL) kde_DCOPObject_disconnectDCOPSignal(kde_KUniqueApplication_DCOPObject([self qt]), (qt_QCString*) [sender toQCString: &_qcstring_sender], (qt_QCString*) [senderObj toQCString: &_qcstring_senderObj], (qt_QCString*) [signal toQCString: &_qcstring_signal], (qt_QCString*) [slot toQCString: &_qcstring_slot]);
}

+ (BOOL) hasObject: (NSString *)objId
{
static qt_QCString * _qcstring_objId = 0L;
	return (BOOL) kde_DCOPObject_hasObject((qt_QCString*) [objId toQCString: &_qcstring_objId]);
}

+ (DCOPObject*) find: (NSString *)objId
{
static qt_QCString * _qcstring_objId = 0L;
	return (DCOPObject*) [QtSupport objectForQtKey: kde_DCOPObject_find((qt_QCString*) [objId toQCString: &_qcstring_objId]) withClass: [DCOPObject class] allocatedInObjcWorld: YES];
}

+ (NSString *) objectName: (QObject *)obj
{
static qt_QCString * _qcstring = 0L;
	_qcstring = kde_DCOPObject_objectName((qt_QObject *) [obj qt]);
	return [NSString fromQCString: _qcstring];
}

@end
