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

@implementation  KProcess


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

- (BOOL) setExecutable: (NSString *)proc
{
static qt_QString * _qstring_proc = 0L;
	return (BOOL) kde_KProcess_setExecutable((kde_KProcess *)[self qt], (qt_QString *) [proc toQString: &_qstring_proc]);
}

- clearArguments
{
	kde_KProcess_clearArguments((kde_KProcess *)[self qt]);
	return self;
}

- (BOOL) start: (int)runmode comm: (int)comm
{
	return (BOOL) kde_KProcess_start((kde_KProcess *)[self qt], (int)runmode, (int)comm);
}

- (BOOL) start
{
	return (BOOL) kde_KProcess_start((kde_KProcess *)[self qt], [KProcess NotifyOnExit], [KProcess NoCommunication]);
}

- (BOOL) kill: (int)signo
{
	return (BOOL) kde_KProcess_kill((kde_KProcess *)[self qt], (int)signo);
}

//- (BOOL) kill
//{
//	return (BOOL) kde_KProcess_kill((kde_KProcess *)[self qt], [KProcess SIGTERM]);
//}

- (BOOL) isRunning
{
	return (BOOL) kde_KProcess_isRunning((kde_KProcess *)[self qt]);
}

- (long) pid
{
	return (long) kde_KProcess_pid((kde_KProcess *)[self qt]);
}

- (long) getPid
{
	return (long) kde_KProcess_getPid((kde_KProcess *)[self qt]);
}

- suspend
{
	kde_KProcess_suspend((kde_KProcess *)[self qt]);
	return self;
}

- resume
{
	kde_KProcess_resume((kde_KProcess *)[self qt]);
	return self;
}

- (BOOL) normalExit
{
	return (BOOL) kde_KProcess_normalExit((kde_KProcess *)[self qt]);
}

- (int) exitStatus
{
	return (int) kde_KProcess_exitStatus((kde_KProcess *)[self qt]);
}

- (BOOL) writeStdin: (NSString *)buffer buflen: (int)buflen
{
	return (BOOL) kde_KProcess_writeStdin((kde_KProcess *)[self qt], (char*) [buffer cString], (int)buflen);
}

- (BOOL) closeStdin
{
	return (BOOL) kde_KProcess_closeStdin((kde_KProcess *)[self qt]);
}

- (BOOL) closeStdout
{
	return (BOOL) kde_KProcess_closeStdout((kde_KProcess *)[self qt]);
}

- (BOOL) closeStderr
{
	return (BOOL) kde_KProcess_closeStderr((kde_KProcess *)[self qt]);
}

- setRunPrivileged: (BOOL)keepPrivileges
{
	kde_KProcess_setRunPrivileged((kde_KProcess *)[self qt], (int)keepPrivileges);
	return self;
}

- (BOOL) runPrivileged
{
	return (BOOL) kde_KProcess_runPrivileged((kde_KProcess *)[self qt]);
}

- setEnvironment: (NSString *)name value: (NSString *)value
{
static qt_QString * _qstring_value = 0L;
static qt_QString * _qstring_name = 0L;
	kde_KProcess_setEnvironment((kde_KProcess *)[self qt], (qt_QString *) [name toQString: &_qstring_name], (qt_QString *) [value toQString: &_qstring_value]);
	return self;
}

- setWorkingDirectory: (NSString *)dir
{
static qt_QString * _qstring_dir = 0L;
	kde_KProcess_setWorkingDirectory((kde_KProcess *)[self qt], (qt_QString *) [dir toQString: &_qstring_dir]);
	return self;
}

- detach
{
	kde_KProcess_detach((kde_KProcess *)[self qt]);
	return self;
}

- setupEnvironment
{
	kde_KProcess_setupEnvironment((kde_KProcess *)[self qt]);
	return self;
}

- (int) setupCommunication: (int)comm
{
	return (int) kde_KProcess_setupCommunication((kde_KProcess *)[self qt], (int)comm);
}

- (int) commSetupDoneP
{
	return (int) kde_KProcess_commSetupDoneP((kde_KProcess *)[self qt]);
}

- (int) commSetupDoneC
{
	return (int) kde_KProcess_commSetupDoneC((kde_KProcess *)[self qt]);
}

- processHasExited: (int)state
{
	kde_KProcess_processHasExited((kde_KProcess *)[self qt], (int)state);
	return self;
}

- commClose
{
	kde_KProcess_commClose((kde_KProcess *)[self qt]);
	return self;
}

- (int) childOutput: (int)fdno
{
	return (int) kde_KProcess_childOutput((kde_KProcess *)[self qt], (int)fdno);
}

- (int) childError: (int)fdno
{
	return (int) kde_KProcess_childError((kde_KProcess *)[self qt], (int)fdno);
}

- slotChildOutput: (int)fdno
{
	kde_KProcess_slotChildOutput((kde_KProcess *)[self qt], (int)fdno);
	return self;
}

- slotChildError: (int)fdno
{
	kde_KProcess_slotChildError((kde_KProcess *)[self qt], (int)fdno);
	return self;
}

- slotSendData: (int)dummy
{
	kde_KProcess_slotSendData((kde_KProcess *)[self qt], (int)dummy);
	return self;
}

+ (int) NoCommunication
{
	return (int) KPROCESS_NoCommunication;
}

+ (int) Stdin
{
	return (int) KPROCESS_Stdin;
}

+ (int) Stdout
{
	return (int) KPROCESS_Stdout;
}

+ (int) Stderr
{
	return (int) KPROCESS_Stderr;
}

+ (int) AllOutput
{
	return (int) KPROCESS_AllOutput;
}

+ (int) All
{
	return (int) KPROCESS_All;
}

+ (int) NoRead
{
	return (int) KPROCESS_NoRead;
}

+ (int) DontCare
{
	return (int) KPROCESS_DontCare;
}

+ (int) NotifyOnExit
{
	return (int) KPROCESS_NotifyOnExit;
}

+ (int) Block
{
	return (int) KPROCESS_Block;
}

@end
