/***************************************************************************
                            DCOPClient.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_DCOPClient.h>
#include <kdeobjc/KDESupport.h>
#include <kdeobjc/DCOPClient.h>
#include <qtobjc/QByteArray.h>


@implementation  DCOPClient


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

- (BOOL) attach
{
	return (BOOL) kde_DCOPClient_attach((kde_DCOPClient *)[self qt]);
}

- bindToApp
{
	kde_DCOPClient_bindToApp((kde_DCOPClient *)[self qt]);
	return self;
}

- (BOOL) detach
{
	return (BOOL) kde_DCOPClient_detach((kde_DCOPClient *)[self qt]);
}

- (BOOL) isAttached
{
	return (BOOL) kde_DCOPClient_isAttached((kde_DCOPClient *)[self qt]);
}

- (BOOL) isAttachedToForeignServer
{
	return (BOOL) kde_DCOPClient_isAttachedToForeignServer((kde_DCOPClient *)[self qt]);
}

- (BOOL) acceptCalls
{
	return (BOOL) kde_DCOPClient_acceptCalls((kde_DCOPClient *)[self qt]);
}

- setAcceptCalls: (BOOL)b
{
	kde_DCOPClient_setAcceptCalls((kde_DCOPClient *)[self qt], (int)b);
	return self;
}

- (NSString *) registerAs: (NSString *)appId addPID: (BOOL)addPID
{
static qt_QCString * _qcstring = 0L;
static qt_QCString * _qcstring_appId = 0L;
	_qcstring = kde_DCOPClient_registerAs((kde_DCOPClient *)[self qt], (qt_QCString*) [appId toQCString: &_qcstring_appId], (int)addPID);
	return [NSString fromQCString: _qcstring];
}

- (BOOL) isRegistered
{
	return (BOOL) kde_DCOPClient_isRegistered((kde_DCOPClient *)[self qt]);
}

- (NSString *) appId
{
static qt_QCString * _qcstring = 0L;
	_qcstring = kde_DCOPClient_appId((kde_DCOPClient *)[self qt]);
	return [NSString fromQCString: _qcstring];
}

- (int) socket
{
	return (int) kde_DCOPClient_socket((kde_DCOPClient *)[self qt]);
}

- suspend
{
	kde_DCOPClient_suspend((kde_DCOPClient *)[self qt]);
	return self;
}

- resume
{
	kde_DCOPClient_resume((kde_DCOPClient *)[self qt]);
	return self;
}

- (BOOL) send: (NSString *)remApp remObj: (NSString *)remObj remFun: (NSString *)remFun data: (QByteArray*)data
{
static qt_QCString * _qcstring_remFun = 0L;
static qt_QCString * _qcstring_remObj = 0L;
static qt_QCString * _qcstring_remApp = 0L;
	return (BOOL) kde_DCOPClient_send((kde_DCOPClient *)[self qt], (qt_QCString*) [remApp toQCString: &_qcstring_remApp], (qt_QCString*) [remObj toQCString: &_qcstring_remObj], (qt_QCString*) [remFun toQCString: &_qcstring_remFun], (qt_QByteArray*) [data qt]);
}

- (BOOL) send: (NSString *)remApp remObj: (NSString *)remObj remFun: (NSString *)remFun dataString: (NSString *)data
{
static qt_QString * _qstring_data = 0L;
static qt_QCString * _qcstring_remFun = 0L;
static qt_QCString * _qcstring_remObj = 0L;
static qt_QCString * _qcstring_remApp = 0L;
	return (BOOL) kde_DCOPClient_send1((kde_DCOPClient *)[self qt], (qt_QCString*) [remApp toQCString: &_qcstring_remApp], (qt_QCString*) [remObj toQCString: &_qcstring_remObj], (qt_QCString*) [remFun toQCString: &_qcstring_remFun], (qt_QString *) [data toQString: &_qstring_data]);
}

- (BOOL) call: (NSString *)remApp remObj: (NSString *)remObj remFun: (NSString *)remFun data: (QByteArray*)data replyType: (NSString *)replyType replyData: (QByteArray*)replyData useEventLoop: (BOOL)useEventLoop
{
static qt_QCString * _qcstring_replyType = 0L;
static qt_QCString * _qcstring_remFun = 0L;
static qt_QCString * _qcstring_remObj = 0L;
static qt_QCString * _qcstring_remApp = 0L;
	return (BOOL) kde_DCOPClient_call((kde_DCOPClient *)[self qt], (qt_QCString*) [remApp toQCString: &_qcstring_remApp], (qt_QCString*) [remObj toQCString: &_qcstring_remObj], (qt_QCString*) [remFun toQCString: &_qcstring_remFun], (qt_QByteArray*) [data qt], (qt_QCString*) [replyType toQCString: &_qcstring_replyType], (qt_QByteArray*) [replyData qt], (int)useEventLoop);
}

- (BOOL) call: (NSString *)remApp remObj: (NSString *)remObj remFun: (NSString *)remFun data: (QByteArray*)data replyType: (NSString *)replyType replyData: (QByteArray*)replyData 
{
static qt_QCString * _qcstring_replyType = 0L;
static qt_QCString * _qcstring_remFun = 0L;
static qt_QCString * _qcstring_remObj = 0L;
static qt_QCString * _qcstring_remApp = 0L;
	return (BOOL) kde_DCOPClient_call((kde_DCOPClient *)[self qt], (qt_QCString*) [remApp toQCString: &_qcstring_remApp], (qt_QCString*) [remObj toQCString: &_qcstring_remObj], (qt_QCString*) [remFun toQCString: &_qcstring_remFun], (qt_QByteArray*) [data qt], (qt_QCString*) [replyType toQCString: &_qcstring_replyType], (qt_QByteArray*) [replyData qt], 0);
}

- (BOOL) findObject: (NSString *)remApp remObj: (NSString *)remObj remFun: (NSString *)remFun data: (QByteArray*)data foundApp: (NSString *)foundApp foundObj: (NSString *)foundObj useEventLoop: (BOOL)useEventLoop
{
static qt_QCString * _qcstring_foundObj = 0L;
static qt_QCString * _qcstring_foundApp = 0L;
static qt_QCString * _qcstring_remFun = 0L;
static qt_QCString * _qcstring_remObj = 0L;
static qt_QCString * _qcstring_remApp = 0L;
	return (BOOL) kde_DCOPClient_findObject((kde_DCOPClient *)[self qt], (qt_QCString*) [remApp toQCString: &_qcstring_remApp], (qt_QCString*) [remObj toQCString: &_qcstring_remObj], (qt_QCString*) [remFun toQCString: &_qcstring_remFun], (qt_QByteArray*) [data qt], (qt_QCString*) [foundApp toQCString: &_qcstring_foundApp], (qt_QCString*) [foundObj toQCString: &_qcstring_foundObj], (int)useEventLoop);
}

- (BOOL) findObject: (NSString *)remApp remObj: (NSString *)remObj remFun: (NSString *)remFun data: (QByteArray*)data foundApp: (NSString *)foundApp foundObj: (NSString *)foundObj 
{
static qt_QCString * _qcstring_foundObj = 0L;
static qt_QCString * _qcstring_foundApp = 0L;
static qt_QCString * _qcstring_remFun = 0L;
static qt_QCString * _qcstring_remObj = 0L;
static qt_QCString * _qcstring_remApp = 0L;
	return (BOOL) kde_DCOPClient_findObject((kde_DCOPClient *)[self qt], (qt_QCString*) [remApp toQCString: &_qcstring_remApp], (qt_QCString*) [remObj toQCString: &_qcstring_remObj], (qt_QCString*) [remFun toQCString: &_qcstring_remFun], (qt_QByteArray*) [data qt], (qt_QCString*) [foundApp toQCString: &_qcstring_foundApp], (qt_QCString*) [foundObj toQCString: &_qcstring_foundObj], 0);
}

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

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

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

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

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

- (BOOL) disconnectDCOPSignal: (NSString *)sender signal: (NSString *)signal receiverObj: (NSString *)receiverObj slot: (NSString *)slot
{
static qt_QCString * _qcstring_slot = 0L;
static qt_QCString * _qcstring_receiverObj = 0L;
static qt_QCString * _qcstring_signal = 0L;
static qt_QCString * _qcstring_sender = 0L;
	return (BOOL) kde_DCOPClient_disconnectDCOPSignal1((kde_DCOPClient *)[self qt], (qt_QCString*) [sender toQCString: &_qcstring_sender], (qt_QCString*) [signal toQCString: &_qcstring_signal], (qt_QCString*) [receiverObj toQCString: &_qcstring_receiverObj], (qt_QCString*) [slot toQCString: &_qcstring_slot]);
}

- (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_DCOPClient_process((kde_DCOPClient *)[self qt], (qt_QCString*) [fun toQCString: &_qcstring_fun], (qt_QByteArray*) [data qt], (qt_QCString*) [replyType toQCString: &_qcstring_replyType], (qt_QByteArray*) [replyData qt]);
}

//- (DCOPClientTransaction*) beginTransaction
//{
//	return (DCOPClientTransaction*) [QtSupport objectForQtKey: kde_DCOPClient_beginTransaction((kde_DCOPClient *)[self qt]) withClass: [DCOPClientTransaction class] allocatedInObjcWorld: YES];
//}

//- endTransaction: (DCOPClientTransaction*)arg1 replyType: (NSString *)replyType replyData: (QByteArray*)replyData
//{
//static qt_QCString * _qcstring_replyType = 0L;
//	kde_DCOPClient_endTransaction((kde_DCOPClient *)[self qt], (kde_DCOPClientTransaction*) [arg1 qt], (qt_QCString*) [replyType toQCString: &_qcstring_replyType], (qt_QByteArray*) [replyData qt]);
//	return self;
//}

- (int) transactionId
{
	return (int) kde_DCOPClient_transactionId((kde_DCOPClient *)[self qt]);
}

- (BOOL) isApplicationRegistered: (NSString *)remApp
{
static qt_QCString * _qcstring_remApp = 0L;
	return (BOOL) kde_DCOPClient_isApplicationRegistered((kde_DCOPClient *)[self qt], (qt_QCString*) [remApp toQCString: &_qcstring_remApp]);
}

- (NSArray *) registeredApplications
{
static kde_QCStringList * _qlist = 0L;
	_qlist = kde_DCOPClient_registeredApplications((kde_DCOPClient *)[self qt]);
	return (NSArray *) [NSMutableArray arrayWithQCStringList: _qlist];
}

- (NSArray *) remoteObjects: (NSString *)remApp ok: (int*)ok
{
static kde_QCStringList * _qlist = 0L;
static qt_QCString * _qcstring_remApp = 0L;
	_qlist = kde_DCOPClient_remoteObjects((kde_DCOPClient *)[self qt], (qt_QCString*) [remApp toQCString: &_qcstring_remApp], (int*)ok);
	return (NSArray *) [NSMutableArray arrayWithQCStringList: _qlist];
}

- (NSArray *) remoteInterfaces: (NSString *)remApp remObj: (NSString *)remObj ok: (int*)ok
{
static kde_QCStringList * _qlist = 0L;
static qt_QCString * _qcstring_remObj = 0L;
static qt_QCString * _qcstring_remApp = 0L;
	_qlist = kde_DCOPClient_remoteInterfaces((kde_DCOPClient *)[self qt], (qt_QCString*) [remApp toQCString: &_qcstring_remApp], (qt_QCString*) [remObj toQCString: &_qcstring_remObj], (int*)ok);
	return (NSArray *) [NSMutableArray arrayWithQCStringList: _qlist];
}

- (NSArray *) remoteFunctions: (NSString *)remApp remObj: (NSString *)remObj ok: (int*)ok
{
static kde_QCStringList * _qlist = 0L;
static qt_QCString * _qcstring_remObj = 0L;
static qt_QCString * _qcstring_remApp = 0L;
	_qlist = kde_DCOPClient_remoteFunctions((kde_DCOPClient *)[self qt], (qt_QCString*) [remApp toQCString: &_qcstring_remApp], (qt_QCString*) [remObj toQCString: &_qcstring_remObj], (int*)ok);
	return (NSArray *) [NSMutableArray arrayWithQCStringList: _qlist];
}

- (BOOL) receive: (NSString *)app obj: (NSString *)obj fun: (NSString *)fun data: (QByteArray*)data replyType: (NSString *)replyType replyData: (QByteArray*)replyData
{
static qt_QCString * _qcstring_replyType = 0L;
static qt_QCString * _qcstring_fun = 0L;
static qt_QCString * _qcstring_obj = 0L;
static qt_QCString * _qcstring_app = 0L;
	return (BOOL) kde_DCOPClient_receive((kde_DCOPClient *)[self qt], (qt_QCString*) [app toQCString: &_qcstring_app], (qt_QCString*) [obj toQCString: &_qcstring_obj], (qt_QCString*) [fun toQCString: &_qcstring_fun], (qt_QByteArray*) [data qt], (qt_QCString*) [replyType toQCString: &_qcstring_replyType], (qt_QByteArray*) [replyData qt]);
}

- (BOOL) find: (NSString *)app obj: (NSString *)obj fun: (NSString *)fun data: (QByteArray*)data replyType: (NSString *)replyType replyData: (QByteArray*)replyData
{
static qt_QCString * _qcstring_replyType = 0L;
static qt_QCString * _qcstring_fun = 0L;
static qt_QCString * _qcstring_obj = 0L;
static qt_QCString * _qcstring_app = 0L;
	return (BOOL) kde_DCOPClient_find((kde_DCOPClient *)[self qt], (qt_QCString*) [app toQCString: &_qcstring_app], (qt_QCString*) [obj toQCString: &_qcstring_obj], (qt_QCString*) [fun toQCString: &_qcstring_fun], (qt_QByteArray*) [data qt], (qt_QCString*) [replyType toQCString: &_qcstring_replyType], (qt_QByteArray*) [replyData qt]);
}

- (NSString *) senderId
{
static qt_QCString * _qcstring = 0L;
	_qcstring = kde_DCOPClient_senderId((kde_DCOPClient *)[self qt]);
	return [NSString fromQCString: _qcstring];
}

- setDefaultObject: (NSString *)objId
{
static qt_QCString * _qcstring_objId = 0L;
	kde_DCOPClient_setDefaultObject((kde_DCOPClient *)[self qt], (qt_QCString*) [objId toQCString: &_qcstring_objId]);
	return self;
}

- (NSString *) defaultObject
{
static qt_QCString * _qcstring = 0L;
	_qcstring = kde_DCOPClient_defaultObject((kde_DCOPClient *)[self qt]);
	return [NSString fromQCString: _qcstring];
}

- setNotifications: (BOOL)enabled
{
	kde_DCOPClient_setNotifications((kde_DCOPClient *)[self qt], (int)enabled);
	return self;
}

- setDaemonMode: (BOOL)daemonMode
{
	kde_DCOPClient_setDaemonMode((kde_DCOPClient *)[self qt], (int)daemonMode);
	return self;
}

+ setServerAddress: (NSString *)addr
{
static qt_QCString * _qcstring_addr = 0L;
	kde_DCOPClient_setServerAddress((qt_QCString*) [addr toQCString: &_qcstring_addr]);
	return self;
}

+ (NSString *) normalizeFunctionSignature: (NSString *)fun
{
static qt_QCString * _qcstring = 0L;
static qt_QCString * _qcstring_fun = 0L;
	_qcstring = kde_DCOPClient_normalizeFunctionSignature((qt_QCString*) [fun toQCString: &_qcstring_fun]);
	return [NSString fromQCString: _qcstring];
}

+ (DCOPClient*) mainClient
{
	return (DCOPClient*) [QtSupport objectForQtKey: kde_DCOPClient_mainClient() withClass: [DCOPClient class] allocatedInObjcWorld: YES];
}

+ setMainClient: (DCOPClient*)arg1
{
	kde_DCOPClient_setMainClient((kde_DCOPClient*) [arg1 qt]);
	return self;
}

+ emergencyClose
{
	kde_DCOPClient_emergencyClose();
	return self;
}

+ (NSString *) postMortemSender
{
	return (NSString *) [NSString stringWithCString: kde_DCOPClient_postMortemSender()];
}

+ (NSString *) postMortemObject
{
	return (NSString *) [NSString stringWithCString: kde_DCOPClient_postMortemObject()];
}

+ (NSString *) postMortemFunction
{
	return (NSString *) [NSString stringWithCString: kde_DCOPClient_postMortemFunction()];
}

+ (NSString *) dcopServerFile: (NSString *)hostname
{
static qt_QCString * _qcstring = 0L;
static qt_QCString * _qcstring_hostname = 0L;
	_qcstring = kde_DCOPClient_dcopServerFile((qt_QCString*) [hostname toQCString: &_qcstring_hostname]);
	return [NSString fromQCString: _qcstring];
}

+ (NSString *) dcopServerFileOld: (NSString *)hostname
{
static qt_QCString * _qcstring = 0L;
static qt_QCString * _qcstring_hostname = 0L;
	_qcstring = kde_DCOPClient_dcopServerFileOld((qt_QCString*) [hostname toQCString: &_qcstring_hostname]);
	return [NSString fromQCString: _qcstring];
}

- processSocketData: (int)socknum
{
	kde_DCOPClient_processSocketData((kde_DCOPClient *)[self qt], (int)socknum);
	return self;
}

@end
