/***************************************************************************
                            PtyProcess.cpp -  description
                             -------------------
    begin                : Sun Jan 27 16:22:17 2002
    copyright            : (C) 2000-2001 Lost Highway Ltd.
    email                : Richard_Dale@tipitina.demon.co.uk
    generated by         : duke@tipitina on Sun Jan 27 16:22:17 2002, using kalyptus 0.9.
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
***************************************************************************/

#define _BOOL_H_
#include <kdesu/process.h>
#include <qstring.h>
#include <qcstring.h>

#include <qtjava/QtSupport.h>
#include <kdejava/KDESupport.h>
#include <kdejava/PtyProcess.h>

class PtyProcessJBridge : public PtyProcess
{
public:
	PtyProcessJBridge() : PtyProcess() {}
	~PtyProcessJBridge() {QtSupport::qtKeyDeleted(this);}
};


JNIEXPORT void JNICALL
Java_org_kde_koala_PtyProcess_newPtyProcess(JNIEnv *env, jobject obj)
{
	if (QtSupport::getQt(env, obj) == 0) {
		QtSupport::setQt(env, obj, new PtyProcessJBridge());
		QtSupport::setObjectForQtKey(env, obj, QtSupport::getQt(env, obj));
	}
	return;
}

JNIEXPORT void JNICALL
Java_org_kde_koala_PtyProcess_finalize(JNIEnv *env, jobject obj)
{
	if (QtSupport::allocatedInJavaWorld(env, obj)) {
		delete (PtyProcess*)QtSupport::getQt(env, obj);
		QtSupport::setQt(env, obj, 0);
	}
	return;
}

JNIEXPORT void JNICALL
Java_org_kde_koala_PtyProcess_dispose(JNIEnv *env, jobject obj)
{
	Java_org_kde_koala_PtyProcess_finalize(env, obj);
	return;
}

JNIEXPORT jboolean JNICALL
Java_org_kde_koala_PtyProcess_isDisposed(JNIEnv *env, jobject obj)
{
	return (QtSupport::getQt(env, obj) == 0);
}

//JNIEXPORT jint JNICALL
//Java_org_kde_koala_PtyProcess_exec(JNIEnv *env, jobject obj, jstring command, jstring args)
//{
//static QCString * _qcstring_command = 0;
//	return (jint) ((PtyProcess*) QtSupport::getQt(env, obj))->exec((QCString&) * (QCString *) QtSupport::toQCString(env, command, &_qcstring_command), (QCStringList) args);
//}

JNIEXPORT jstring JNICALL
Java_org_kde_koala_PtyProcess_readLine(JNIEnv *env, jobject obj, jboolean block)
{
	QCString  _qcstring;
	_qcstring = ((PtyProcess*) QtSupport::getQt(env, obj))->readLine((bool) block);
	return QtSupport::fromQCString(env, &_qcstring);
}

JNIEXPORT void JNICALL
Java_org_kde_koala_PtyProcess_writeLine__Ljava_lang_String_2Z(JNIEnv *env, jobject obj, jstring line, jboolean addNewline)
{
static QCString * _qcstring_line = 0;
	((PtyProcess*) QtSupport::getQt(env, obj))->writeLine((QCString&) * (QCString *) QtSupport::toQCString(env, line, &_qcstring_line), (bool) addNewline);
	return;
}

JNIEXPORT void JNICALL
Java_org_kde_koala_PtyProcess_writeLine__Ljava_lang_String_2(JNIEnv *env, jobject obj, jstring line)
{
static QCString * _qcstring_line = 0;
	((PtyProcess*) QtSupport::getQt(env, obj))->writeLine((QCString&) * (QCString *) QtSupport::toQCString(env, line, &_qcstring_line), true);
	return;
}

JNIEXPORT void JNICALL
Java_org_kde_koala_PtyProcess_unreadLine__Ljava_lang_String_2Z(JNIEnv *env, jobject obj, jstring line, jboolean addNewline)
{
static QCString * _qcstring_line = 0;
	((PtyProcess*) QtSupport::getQt(env, obj))->unreadLine((QCString&) * (QCString *) QtSupport::toQCString(env, line, &_qcstring_line), (bool) addNewline);
	return;
}

JNIEXPORT void JNICALL
Java_org_kde_koala_PtyProcess_unreadLine__Ljava_lang_String_2(JNIEnv *env, jobject obj, jstring line)
{
static QCString * _qcstring_line = 0;
	((PtyProcess*) QtSupport::getQt(env, obj))->unreadLine((QCString&) * (QCString *) QtSupport::toQCString(env, line, &_qcstring_line), true);
	return;
}

JNIEXPORT void JNICALL
Java_org_kde_koala_PtyProcess_setExitString(JNIEnv *env, jobject obj, jstring exit)
{
static QCString * _qcstring_exit = 0;
	((PtyProcess*) QtSupport::getQt(env, obj))->setExitString((QCString&) * (QCString *) QtSupport::toQCString(env, exit, &_qcstring_exit));
	return;
}

JNIEXPORT jint JNICALL
Java_org_kde_koala_PtyProcess_waitForChild(JNIEnv *env, jobject obj)
{
	return (jint) ((PtyProcess*) QtSupport::getQt(env, obj))->waitForChild();
}

JNIEXPORT jint JNICALL
Java_org_kde_koala_PtyProcess_WaitSlave(JNIEnv *env, jobject obj)
{
	return (jint) ((PtyProcess*) QtSupport::getQt(env, obj))->WaitSlave();
}

JNIEXPORT jint JNICALL
Java_org_kde_koala_PtyProcess_enableLocalEcho__Z(JNIEnv *env, jobject obj, jboolean enable)
{
	return (jint) ((PtyProcess*) QtSupport::getQt(env, obj))->enableLocalEcho((bool) enable);
}

JNIEXPORT jint JNICALL
Java_org_kde_koala_PtyProcess_enableLocalEcho__(JNIEnv *env, jobject obj)
{
	return (jint) ((PtyProcess*) QtSupport::getQt(env, obj))->enableLocalEcho(true);
}

JNIEXPORT void JNICALL
Java_org_kde_koala_PtyProcess_setTerminal(JNIEnv *env, jobject obj, jboolean terminal)
{
	((PtyProcess*) QtSupport::getQt(env, obj))->setTerminal((bool) terminal);
	return;
}

JNIEXPORT void JNICALL
Java_org_kde_koala_PtyProcess_setErase(JNIEnv *env, jobject obj, jboolean erase)
{
	((PtyProcess*) QtSupport::getQt(env, obj))->setErase((bool) erase);
	return;
}

//JNIEXPORT void JNICALL
//Java_org_kde_koala_PtyProcess_setEnvironment(JNIEnv *env, jobject obj, jstring _env)
//{
//	((PtyProcess*) QtSupport::getQt(env, obj))->setEnvironment((QCStringList) _env);
//	return;
//}

JNIEXPORT jint JNICALL
Java_org_kde_koala_PtyProcess_fd(JNIEnv *env, jobject obj)
{
	return (jint) ((PtyProcess*) QtSupport::getQt(env, obj))->fd();
}

JNIEXPORT jint JNICALL
Java_org_kde_koala_PtyProcess_pid(JNIEnv *env, jobject obj)
{
	return (jint) ((PtyProcess*) QtSupport::getQt(env, obj))->pid();
}

