/***************************************************************************
                            QIODevice.cpp -  description
                             -------------------
    begin                : Wed Nov 21 17:05:56 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 17:05:56 2001, 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 <qiodevice.h>
#include <qstring.h>
#include <qcstring.h>

#include <qtjava/QtSupport.h>
#include <qtjava/QIODevice.h>

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

JNIEXPORT jint JNICALL
Java_org_kde_qt_QIODevice_flags(JNIEnv *env, jobject obj)
{
	return (jint) ((QIODevice*) QtSupport::getQt(env, obj))->flags();
}

JNIEXPORT jint JNICALL
Java_org_kde_qt_QIODevice_mode(JNIEnv *env, jobject obj)
{
	return (jint) ((QIODevice*) QtSupport::getQt(env, obj))->mode();
}

JNIEXPORT jint JNICALL
Java_org_kde_qt_QIODevice_state(JNIEnv *env, jobject obj)
{
	return (jint) ((QIODevice*) QtSupport::getQt(env, obj))->state();
}

JNIEXPORT jboolean JNICALL
Java_org_kde_qt_QIODevice_isDirectAccess(JNIEnv *env, jobject obj)
{
	return (jboolean) ((QIODevice*) QtSupport::getQt(env, obj))->isDirectAccess();
}

JNIEXPORT jboolean JNICALL
Java_org_kde_qt_QIODevice_isSequentialAccess(JNIEnv *env, jobject obj)
{
	return (jboolean) ((QIODevice*) QtSupport::getQt(env, obj))->isSequentialAccess();
}

JNIEXPORT jboolean JNICALL
Java_org_kde_qt_QIODevice_isCombinedAccess(JNIEnv *env, jobject obj)
{
	return (jboolean) ((QIODevice*) QtSupport::getQt(env, obj))->isCombinedAccess();
}

JNIEXPORT jboolean JNICALL
Java_org_kde_qt_QIODevice_isBuffered(JNIEnv *env, jobject obj)
{
	return (jboolean) ((QIODevice*) QtSupport::getQt(env, obj))->isBuffered();
}

JNIEXPORT jboolean JNICALL
Java_org_kde_qt_QIODevice_isRaw(JNIEnv *env, jobject obj)
{
	return (jboolean) ((QIODevice*) QtSupport::getQt(env, obj))->isRaw();
}

JNIEXPORT jboolean JNICALL
Java_org_kde_qt_QIODevice_isSynchronous(JNIEnv *env, jobject obj)
{
	return (jboolean) ((QIODevice*) QtSupport::getQt(env, obj))->isSynchronous();
}

JNIEXPORT jboolean JNICALL
Java_org_kde_qt_QIODevice_isAsynchronous(JNIEnv *env, jobject obj)
{
	return (jboolean) ((QIODevice*) QtSupport::getQt(env, obj))->isAsynchronous();
}

JNIEXPORT jboolean JNICALL
Java_org_kde_qt_QIODevice_isTranslated(JNIEnv *env, jobject obj)
{
	return (jboolean) ((QIODevice*) QtSupport::getQt(env, obj))->isTranslated();
}

JNIEXPORT jboolean JNICALL
Java_org_kde_qt_QIODevice_isReadable(JNIEnv *env, jobject obj)
{
	return (jboolean) ((QIODevice*) QtSupport::getQt(env, obj))->isReadable();
}

JNIEXPORT jboolean JNICALL
Java_org_kde_qt_QIODevice_isWritable(JNIEnv *env, jobject obj)
{
	return (jboolean) ((QIODevice*) QtSupport::getQt(env, obj))->isWritable();
}

JNIEXPORT jboolean JNICALL
Java_org_kde_qt_QIODevice_isReadWrite(JNIEnv *env, jobject obj)
{
	return (jboolean) ((QIODevice*) QtSupport::getQt(env, obj))->isReadWrite();
}

JNIEXPORT jboolean JNICALL
Java_org_kde_qt_QIODevice_isInactive(JNIEnv *env, jobject obj)
{
	return (jboolean) ((QIODevice*) QtSupport::getQt(env, obj))->isInactive();
}

JNIEXPORT jboolean JNICALL
Java_org_kde_qt_QIODevice_isOpen(JNIEnv *env, jobject obj)
{
	return (jboolean) ((QIODevice*) QtSupport::getQt(env, obj))->isOpen();
}

JNIEXPORT jint JNICALL
Java_org_kde_qt_QIODevice_status(JNIEnv *env, jobject obj)
{
	return (jint) ((QIODevice*) QtSupport::getQt(env, obj))->status();
}

JNIEXPORT void JNICALL
Java_org_kde_qt_QIODevice_resetStatus(JNIEnv *env, jobject obj)
{
	((QIODevice*) QtSupport::getQt(env, obj))->resetStatus();
	return;
}

JNIEXPORT jboolean JNICALL
Java_org_kde_qt_QIODevice_open(JNIEnv *env, jobject obj, jint mode)
{
	return (jboolean) ((QIODevice*) QtSupport::getQt(env, obj))->open((int) mode);
}

JNIEXPORT void JNICALL
Java_org_kde_qt_QIODevice_close(JNIEnv *env, jobject obj)
{
	((QIODevice*) QtSupport::getQt(env, obj))->close();
	return;
}

JNIEXPORT void JNICALL
Java_org_kde_qt_QIODevice_flush(JNIEnv *env, jobject obj)
{
	((QIODevice*) QtSupport::getQt(env, obj))->flush();
	return;
}

JNIEXPORT jint JNICALL
Java_org_kde_qt_QIODevice_size(JNIEnv *env, jobject obj)
{
	return (jint) ((QIODevice*) QtSupport::getQt(env, obj))->size();
}

JNIEXPORT jint JNICALL
Java_org_kde_qt_QIODevice_at__(JNIEnv *env, jobject obj)
{
	return (jint) ((QIODevice*) QtSupport::getQt(env, obj))->at();
}

JNIEXPORT jboolean JNICALL
Java_org_kde_qt_QIODevice_at__I(JNIEnv *env, jobject obj, jint arg1)
{
	return (jboolean) ((QIODevice*) QtSupport::getQt(env, obj))->at((QIODevice::Offset) arg1);
}

JNIEXPORT jboolean JNICALL
Java_org_kde_qt_QIODevice_atEnd(JNIEnv *env, jobject obj)
{
	return (jboolean) ((QIODevice*) QtSupport::getQt(env, obj))->atEnd();
}

JNIEXPORT jboolean JNICALL
Java_org_kde_qt_QIODevice_reset(JNIEnv *env, jobject obj)
{
	return (jboolean) ((QIODevice*) QtSupport::getQt(env, obj))->reset();
}

JNIEXPORT jlong JNICALL
Java_org_kde_qt_QIODevice_readBlock(JNIEnv *env, jobject obj, jobject data, jlong maxlen)
{
static QCString * _qstring_data = 0;
	if (_qstring_data == 0) {
		_qstring_data = new QCString();
	}
	_qstring_data->resize((uint) maxlen);
	jlong result = (jlong) ((QIODevice*) QtSupport::getQt(env, obj))->readBlock((char*)_qstring_data->data(), (Q_ULONG) maxlen);
	QtSupport::fromQCStringToStringBuffer(env, _qstring_data, data);
	return result;
}

JNIEXPORT jlong JNICALL
Java_org_kde_qt_QIODevice_writeBlock__Ljava_lang_String_2J(JNIEnv *env, jobject obj, jstring data, jlong len)
{
static QCString * _qstring_data = 0;
	if (_qstring_data == 0) {
		_qstring_data = new QCString();
	}
	_qstring_data->resize((uint) len);
	return (jlong) ((QIODevice*) QtSupport::getQt(env, obj))->writeBlock((char*) QtSupport::toCharString(env, data, &_qstring_data), (Q_ULONG) len);
}

JNIEXPORT jlong JNICALL
Java_org_kde_qt_QIODevice_readLine(JNIEnv *env, jobject obj, jobject data, jlong maxlen)
{
	QCString _qstring_data((uint) maxlen);
	jlong result = (jlong) ((QIODevice*) QtSupport::getQt(env, obj))->readLine(_qstring_data.data(), (Q_ULONG) maxlen);
	_qstring_data.truncate((uint) result);	
	QtSupport::fromQCStringToStringBuffer(env, &_qstring_data, data);
	return result;
}

JNIEXPORT jlong JNICALL
Java_org_kde_qt_QIODevice_writeBlock___3B(JNIEnv *env, jobject obj, jbyteArray data)
{
static QByteArray * _qbyteArray_data = 0;
	return (jlong) ((QIODevice*) QtSupport::getQt(env, obj))->writeBlock((QByteArray&) * (QByteArray *) QtSupport::toQByteArray(env, data, &_qbyteArray_data));
}

JNIEXPORT jbyteArray JNICALL
Java_org_kde_qt_QIODevice_readAll(JNIEnv *env, jobject obj)
{
	QByteArray  _qbyteArray;
	_qbyteArray = ((QIODevice*) QtSupport::getQt(env, obj))->readAll();
	return QtSupport::fromQByteArray(env, &_qbyteArray);
}

JNIEXPORT jint JNICALL
Java_org_kde_qt_QIODevice_getch(JNIEnv *env, jobject obj)
{
	return (jint) ((QIODevice*) QtSupport::getQt(env, obj))->getch();
}

JNIEXPORT jint JNICALL
Java_org_kde_qt_QIODevice_putch(JNIEnv *env, jobject obj, jint arg1)
{
	return (jint) ((QIODevice*) QtSupport::getQt(env, obj))->putch((int) arg1);
}

JNIEXPORT jint JNICALL
Java_org_kde_qt_QIODevice_ungetch(JNIEnv *env, jobject obj, jint arg1)
{
	return (jint) ((QIODevice*) QtSupport::getQt(env, obj))->ungetch((int) arg1);
}

