/***************************************************************************
                            QProcess.m -  description
                             -------------------
    begin                : Wed Nov 21 12:08:37 2001
    copyright            : (C) 2000-2001 Lost Highway Ltd. All rights reserved.
    email                : Lost_Highway@tipitina.demon.co.uk
    generated by         : duke@tipitina on Wed Nov 21 12:08:37 2001, 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 <qtc/qt_QProcess.h>
#include <qtobjc/QProcess.h>
#include <qtobjc/QDir.h>


@implementation  QProcess


- initWithObject: (QObject *)parent name: (NSString *)name
{
	if ([self qt] == 0L) {
		[self setQt: qt_new_QProcess((qt_QObject *) [parent qt], (char*) [name cString])];
		[self setAllocatedInObjcWorld: YES];
		[QtSupport setObject: self forQtKey: [self qt]];
	}
	[super init];
	return self;
}

- init
{
	if ([self qt] == 0L) {
		[self setQt: qt_new_QProcess(0, 0)];
		[self setAllocatedInObjcWorld: YES];
		[QtSupport setObject: self forQtKey: [self qt]];
	}
	[super init];
	return self;
}

- initWithText: (NSString *)arg0 parent: (QObject *)parent name: (NSString *)name
{
static qt_QString * _qstring_arg0 = 0L;
	if ([self qt] == 0L) {
		[self setQt: qt_new_QProcess1((qt_QString *) [arg0 toQString: &_qstring_arg0], (qt_QObject *) [parent qt], (char*) [name cString])];
		[self setAllocatedInObjcWorld: YES];
		[QtSupport setObject: self forQtKey: [self qt]];
	}
	[super init];
	return self;
}

- initWithText: (NSString *)arg0 
{
static qt_QString * _qstring_arg0 = 0L;
	if ([self qt] == 0L) {
		[self setQt: qt_new_QProcess1((qt_QString *) [arg0 toQString: &_qstring_arg0], 0, 0)];
		[self setAllocatedInObjcWorld: YES];
		[QtSupport setObject: self forQtKey: [self qt]];
	}
	[super init];
	return self;
}

- initWithArray: (NSArray *)args parent: (QObject *)parent name: (NSString *)name
{
static qt_QStringList * _qlist_args = 0L;
	if ([self qt] == 0L) {
		[self setQt: qt_new_QProcess2((qt_QStringList*) [args toQStringList: (void *)&_qlist_args], (qt_QObject *) [parent qt], (char*) [name cString])];
		[self setAllocatedInObjcWorld: YES];
		[QtSupport setObject: self forQtKey: [self qt]];
	}
	[super init];
	return self;
}

- initWithArray: (NSArray *)args 
{
static qt_QStringList * _qlist_args = 0L;
	if ([self qt] == 0L) {
		[self setQt: qt_new_QProcess2((qt_QStringList*) [args toQStringList: (void *)&_qlist_args], 0, 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) {
			qt_del_QProcess((qt_QProcess *)[self qt]);
		}
		[QtSupport removeQtKey: [self qt]];
		[self setQt: 0L];
	}
	[super dealloc];
}

- (NSArray *) arguments
{
static qt_QStringList * _qlist = 0L;
	_qlist = qt_QProcess_arguments((qt_QProcess *)[self qt]);
	return (NSArray *) [NSMutableArray arrayWithQStringList: _qlist];
}

- clearArguments
{
	qt_QProcess_clearArguments((qt_QProcess *)[self qt]);
	return self;
}

- setArguments: (NSArray *)args
{
static qt_QStringList * _qlist_args = 0L;
	qt_QProcess_setArguments((qt_QProcess *)[self qt], (qt_QStringList*) [args toQStringList: (void *)&_qlist_args]);
	return self;
}

- addArgument: (NSString *)arg
{
static qt_QString * _qstring_arg = 0L;
	qt_QProcess_addArgument((qt_QProcess *)[self qt], (qt_QString *) [arg toQString: &_qstring_arg]);
	return self;
}

- (QDir*) workingDirectory
{
	return (QDir*) [QtSupport objectForQtKey: qt_QProcess_workingDirectory((qt_QProcess *)[self qt]) withClass: [QDir class] allocatedInObjcWorld: YES];
}

- setWorkingDirectory: (QDir *)dir
{
	qt_QProcess_setWorkingDirectory((qt_QProcess *)[self qt], (qt_QDir *) [dir qt]);
	return self;
}

- setCommunication: (int)c
{
	qt_QProcess_setCommunication((qt_QProcess *)[self qt], (int)c);
	return self;
}

- (int) communication
{
	return (int) qt_QProcess_communication((qt_QProcess *)[self qt]);
}

- (BOOL) start: (NSArray *)env
{
static qt_QStringList * _qlist_env = 0L;
	return (BOOL) qt_QProcess_start((qt_QProcess *)[self qt], (qt_QStringList*) [env toQStringList: (void *)&_qlist_env]);
}

- (BOOL) start
{
	return (BOOL) qt_QProcess_start((qt_QProcess *)[self qt], 0);
}

- (BOOL) launch: (NSString *)buf env: (NSArray *)env
{
static qt_QStringList * _qlist_env = 0L;
static qt_QString * _qstring_buf = 0L;
	return (BOOL) qt_QProcess_launch((qt_QProcess *)[self qt], (qt_QString *) [buf toQString: &_qstring_buf], (qt_QStringList*) [env toQStringList: (void *)&_qlist_env]);
}

- (BOOL) launch: (NSString *)buf 
{
static qt_QString * _qstring_buf = 0L;
	return (BOOL) qt_QProcess_launch((qt_QProcess *)[self qt], (qt_QString *) [buf toQString: &_qstring_buf], 0);
}

//- (BOOL) launch: (QByteArray*)buf env: (NSArray *)env
//{
//static qt_QStringList * _qlist_env = 0L;
//	return (BOOL) qt_QProcess_launch1((qt_QProcess *)[self qt], (qt_QByteArray*) [buf qt], (qt_QStringList*) [env toQStringList: (void *)&_qlist_env]);
//}

//- (BOOL) launch: (QByteArray*)buf
//{
//	return (BOOL) qt_QProcess_launch1((qt_QProcess *)[self qt], (qt_QByteArray*) [buf qt], 0);
//}

- (BOOL) isRunning
{
	return (BOOL) qt_QProcess_isRunning((qt_QProcess *)[self qt]);
}

- (BOOL) normalExit
{
	return (BOOL) qt_QProcess_normalExit((qt_QProcess *)[self qt]);
}

- (int) exitStatus
{
	return (int) qt_QProcess_exitStatus((qt_QProcess *)[self qt]);
}

- (QByteArray*) readStdout
{
	return (QByteArray*) [QtSupport objectForQtKey: qt_QProcess_readStdout((qt_QProcess *)[self qt]) withClass: [QByteArray class] allocatedInObjcWorld: YES];
}

- (QByteArray*) readStderr
{
	return (QByteArray*) [QtSupport objectForQtKey: qt_QProcess_readStderr((qt_QProcess *)[self qt]) withClass: [QByteArray class] allocatedInObjcWorld: YES];
}

- (BOOL) canReadLineStdout
{
	return (BOOL) qt_QProcess_canReadLineStdout((qt_QProcess *)[self qt]);
}

- (BOOL) canReadLineStderr
{
	return (BOOL) qt_QProcess_canReadLineStderr((qt_QProcess *)[self qt]);
}

- (NSString *) readLineStdout
{
static qt_QString * _qstring = 0L;
	_qstring = qt_QProcess_readLineStdout((qt_QProcess *)[self qt]);
	return [NSString fromQString: _qstring];
}

- (NSString *) readLineStderr
{
static qt_QString * _qstring = 0L;
	_qstring = qt_QProcess_readLineStderr((qt_QProcess *)[self qt]);
	return [NSString fromQString: _qstring];
}

- (long) processIdentifier
{
	return (long) qt_QProcess_processIdentifier((qt_QProcess *)[self qt]);
}

- flushStdin
{
	qt_QProcess_flushStdin((qt_QProcess *)[self qt]);
	return self;
}

- tryTerminate
{
	qt_QProcess_tryTerminate((qt_QProcess *)[self qt]);
	return self;
}

- kill
{
	qt_QProcess_kill((qt_QProcess *)[self qt]);
	return self;
}

//- writeToStdin: (QByteArray*)buf
//{
//	qt_QProcess_writeToStdin((qt_QProcess *)[self qt], (qt_QByteArray*) [buf qt]);
//	return self;
//}

- writeToStdin: (NSString *)buf
{
static qt_QString * _qstring_buf = 0L;
	qt_QProcess_writeToStdin1((qt_QProcess *)[self qt], (qt_QString *) [buf toQString: &_qstring_buf]);
	return self;
}

- closeStdin
{
	qt_QProcess_closeStdin((qt_QProcess *)[self qt]);
	return self;
}

- connectNotify: (NSString *)signal
{
	qt_QProcess_connectNotify((qt_QProcess *)[self qt], (char*) [signal cString]);
	return self;
}

- disconnectNotify: (NSString *)signal
{
	qt_QProcess_disconnectNotify((qt_QProcess *)[self qt], (char*) [signal cString]);
	return self;
}

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

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

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

+ (int) DupStderr
{
	return (int) QPROCESS_DupStderr;
}

@end
