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

@implementation  KSaveFile

- (void *) qt
{
	return _qt;
}

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

- (BOOL) allocatedInObjcWorld
{
	return _allocatedInObjcWorld;
}

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


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

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

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

- (int) status
{
	return (int) kde_KSaveFile_status((kde_KSaveFile *)[self qt]);
}

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

- (int) handle
{
	return (int) kde_KSaveFile_handle((kde_KSaveFile *)[self qt]);
}

//- (FILE*) fstream
//{
//	return (FILE*) kde_KSaveFile_fstream((kde_KSaveFile *)[self qt]);
//}

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

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

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

- abort
{
	kde_KSaveFile_abort((kde_KSaveFile *)[self qt]);
	return self;
}

- (BOOL) close
{
	return (BOOL) kde_KSaveFile_close((kde_KSaveFile *)[self qt]);
}

@end
