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

@implementation  KTempFile

- (void *) qt
{
	return _qt;
}

- setQt: (void *) qt
{
	_qt = qt;
	return self;
}

- (BOOL) allocatedInObjcWorld
{
	return _allocatedInObjcWorld;
}

- setAllocatedInObjcWorld: (BOOL) yn
{
	_allocatedInObjcWorld = yn;
	return self;
}


- initWithText: (NSString *)filePrefix fileExtension: (NSString *)fileExtension mode: (int)mode
{
static qt_QString * _qstring_fileExtension = 0L;
static qt_QString * _qstring_filePrefix = 0L;
	if ([self qt] == 0L) {
		[self setQt: kde_new_KTempFile((qt_QString *) [filePrefix toQString: &_qstring_filePrefix], (qt_QString *) [fileExtension toQString: &_qstring_fileExtension], (int)mode)];
		[self setAllocatedInObjcWorld: YES];
		[QtSupport setObject: self forQtKey: [self qt]];
	}
	[super init];
	return self;
}

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

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

- setAutoDelete: (BOOL)autoDelete
{
	kde_KTempFile_setAutoDelete((kde_KTempFile *)[self qt], (int)autoDelete);
	return self;
}

- (int) status
{
	return (int) kde_KTempFile_status((kde_KTempFile *)[self qt]);
}

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

- (int) handle
{
	return (int) kde_KTempFile_handle((kde_KTempFile *)[self qt]);
}

//- (FILE*) fstream
//{
//	return (FILE*) kde_KTempFile_fstream((kde_KTempFile *)[self qt]);
//}

- (QTextStream*) textStream
{
	return (QTextStream*) [QtSupport objectForQtKey: kde_KTempFile_textStream((kde_KTempFile *)[self qt]) withClass: [QTextStream class] allocatedInObjcWorld: YES];
}

- (QDataStream*) dataStream
{
	return (QDataStream*) [QtSupport objectForQtKey: kde_KTempFile_dataStream((kde_KTempFile *)[self qt]) withClass: [QDataStream class] allocatedInObjcWorld: YES];
}

- (QFile*) file
{
	return (QFile*) [QtSupport objectForQtKey: kde_KTempFile_file((kde_KTempFile *)[self qt]) withClass: [QFile class] allocatedInObjcWorld: YES];
}

- unlink
{
	kde_KTempFile_unlink((kde_KTempFile *)[self qt]);
	return self;
}

- (BOOL) close
{
	return (BOOL) kde_KTempFile_close((kde_KTempFile *)[self qt]);
}

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

- (BOOL) create: (NSString *)filePrefix fileExtension: (NSString *)fileExtension mode: (int)mode
{
static qt_QString * _qstring_fileExtension = 0L;
static qt_QString * _qstring_filePrefix = 0L;
	return (BOOL) kde_KTempFile_create((kde_KTempFile *)[self qt], (qt_QString *) [filePrefix toQString: &_qstring_filePrefix], (qt_QString *) [fileExtension toQString: &_qstring_fileExtension], (int)mode);
}

- setError: (int)error
{
	kde_KTempFile_setError((kde_KTempFile *)[self qt], (int)error);
	return self;
}

@end
