/***************************************************************************
                            QFile.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_QFile.h>
#include <qtobjc/QFile.h>
#include <qtobjc/QByteArray.h>

@implementation  QFile


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

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

- (void) dealloc
{
	if ([self qt] != 0L) {
		if ([self allocatedInObjcWorld]) {
			qt_del_QFile((qt_QFile *)[self qt]);
		}
		[QtSupport removeQtKey: [self qt]];
		[self setQt: 0L];
	}
	[super dealloc];
}

- (NSString *) name
{
static qt_QString * _qstring = 0L;
	_qstring = qt_QFile_name((qt_QFile *)[self qt]);
	return [NSString fromQString: _qstring];
}

- setName: (NSString *)name
{
static qt_QString * _qstring_name = 0L;
	qt_QFile_setName((qt_QFile *)[self qt], (qt_QString *) [name toQString: &_qstring_name]);
	return self;
}

//- (typedef) QCString: (* EncoderFn)( QString*)fileName
//{
//	return (typedef) qt_QFile_QCString((qt_QFile *)[self qt], (* EncoderFn)( QString) fileName);
//}

//- (typedef) QString: (* DecoderFn)( QCString*)localfileName
//{
//	return (typedef) qt_QFile_QString((qt_QFile *)[self qt], (* DecoderFn)( QCString) localfileName);
//}

- (BOOL) exists
{
	return (BOOL) qt_QFile_exists((qt_QFile *)[self qt]);
}

- (BOOL) remove
{
	return (BOOL) qt_QFile_remove((qt_QFile *)[self qt]);
}

- (BOOL) open: (int)arg1
{
	return (BOOL) qt_QFile_open((qt_QFile *)[self qt], (int)arg1);
}

- (BOOL) open: (int)arg1 file: (FILE*)arg2
{
	return (BOOL) qt_QFile_open1((qt_QFile *)[self qt], (int)arg1, (FILE*)arg2);
}

- (BOOL) open: (int)arg1 int: (int)arg2
{
	return (BOOL) qt_QFile_open2((qt_QFile *)[self qt], (int)arg1, (int)arg2);
}

- close
{
	qt_QFile_close((qt_QFile *)[self qt]);
	return self;
}

- flush
{
	qt_QFile_flush((qt_QFile *)[self qt]);
	return self;
}

- (int) size
{
	return (int) qt_QFile_size((qt_QFile *)[self qt]);
}

- (int) at
{
	return (int) qt_QFile_at((qt_QFile *)[self qt]);
}

- (BOOL) at: (int)arg1
{
	return (BOOL) qt_QFile_at1((qt_QFile *)[self qt], (int)arg1);
}

- (BOOL) atEnd
{
	return (BOOL) qt_QFile_atEnd((qt_QFile *)[self qt]);
}

- (long) readBlock: (NSString *)data len: (long)len
{
	return (long) qt_QFile_readBlock((qt_QFile *)[self qt], (char*) [data cString], (long)len);
}

- (long) writeBlock: (NSString *)data len: (long)len
{
	return (long) qt_QFile_writeBlock((qt_QFile *)[self qt], (char*) [data cString], (long)len);
}

- (long) writeBlock: (QByteArray*)data
{
	return (long) qt_QFile_writeBlock1((qt_QFile *)[self qt], (qt_QByteArray*) [data qt]);
}

- (long) readLine: (NSString *)data maxlen: (long)maxlen
{
	return (long) qt_QFile_readLine((qt_QFile *)[self qt], (char*) [data cString], (long)maxlen);
}

//- (long) readLine: (NSString *)arg1 maxlen: (long)maxlen
//{
//static qt_QString * _qstring_arg1 = 0L;
//	return (long) qt_QFile_readLine1((qt_QFile *)[self qt], (qt_QString *) [arg1 toQString: &_qstring_arg1], (long)maxlen);
//}

- (int) getch
{
	return (int) qt_QFile_getch((qt_QFile *)[self qt]);
}

- (int) putch: (int)arg1
{
	return (int) qt_QFile_putch((qt_QFile *)[self qt], (int)arg1);
}

- (int) ungetch: (int)arg1
{
	return (int) qt_QFile_ungetch((qt_QFile *)[self qt], (int)arg1);
}

- (int) handle
{
	return (int) qt_QFile_handle((qt_QFile *)[self qt]);
}

+ (NSString *) encodeName: (NSString *)fileName
{
static qt_QCString * _qcstring = 0L;
static qt_QString * _qstring_fileName = 0L;
	_qcstring = qt_QFile_encodeName((qt_QString *) [fileName toQString: &_qstring_fileName]);
	return [NSString fromQCString: _qcstring];
}

+ (NSString *) decodeName: (NSString *)localFileName
{
static qt_QString * _qstring = 0L;
static qt_QCString * _qcstring_localFileName = 0L;
	_qstring = qt_QFile_decodeName((qt_QCString*) [localFileName toQCString: &_qcstring_localFileName]);
	return [NSString fromQString: _qstring];
}

//+ setEncodingFunction: (int)arg1
//{
//	qt_QFile_setEncodingFunction((int)arg1);
//	return self;
//}

//+ setDecodingFunction: (int)arg1
//{
//	qt_QFile_setDecodingFunction((int)arg1);
//	return self;
//}

+ (BOOL) exists: (NSString *)fileName
{
static qt_QString * _qstring_fileName = 0L;
	return (BOOL) qt_QFile_exists1((qt_QString *) [fileName toQString: &_qstring_fileName]);
}

+ (BOOL) remove: (NSString *)fileName
{
static qt_QString * _qstring_fileName = 0L;
	return (BOOL) qt_QFile_remove1((qt_QString *) [fileName toQString: &_qstring_fileName]);
}

@end
