/***************************************************************************
                            KCharsets.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_KCharsets.h>
#include <kdeobjc/KDESupport.h>
#include <kdeobjc/KCharsets.h>
#include <qtobjc/QFont.h>


@implementation  KCharsets

- (void *) qt
{
	return _qt;
}

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

- (BOOL) allocatedInObjcWorld
{
	return _allocatedInObjcWorld;
}

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


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

- (QTextCodec*) codecForName: (NSString *)name
{
static qt_QString * _qstring_name = 0L;
	return (QTextCodec*) [QtSupport objectForQtKey: kde_KCharsets_codecForName((kde_KCharsets *)[self qt], (qt_QString *) [name toQString: &_qstring_name]) withClass: [QTextCodec class] allocatedInObjcWorld: YES];
}

- (QTextCodec*) codecForName: (NSString *)n ok: (BOOL)ok
{
static qt_QString * _qstring_n = 0L;
	return (QTextCodec*) [QtSupport objectForQtKey: kde_KCharsets_codecForName1((kde_KCharsets *)[self qt], (qt_QString *) [n toQString: &_qstring_n], (int)ok) withClass: [QTextCodec class] allocatedInObjcWorld: YES];
}

- (NSArray *) availableEncodingNames
{
static qt_QStringList * _qlist = 0L;
	_qlist = kde_KCharsets_availableEncodingNames((kde_KCharsets *)[self qt]);
	return (NSArray *) [NSMutableArray arrayWithQStringList: _qlist];
}

- (NSArray *) descriptiveEncodingNames
{
static qt_QStringList * _qlist = 0L;
	_qlist = kde_KCharsets_descriptiveEncodingNames((kde_KCharsets *)[self qt]);
	return (NSArray *) [NSMutableArray arrayWithQStringList: _qlist];
}

//- (NSArray *) languages
//{
//static qt_QStringList * _qlist = 0L;
//	_qlist = kde_KCharsets_languages((kde_KCharsets *)[self qt]);
//	return (NSArray *) [NSMutableArray arrayWithQStringList: _qlist];
//}

//- (NSArray *) encodingsForLanguage: (NSString *)language
//{
//static qt_QStringList * _qlist = 0L;
//static qt_QString * _qstring_language = 0L;
//	_qlist = kde_KCharsets_encodingsForLanguage((kde_KCharsets *)[self qt], (qt_QString *) [language toQString: &_qstring_language]);
//	return (NSArray *) [NSMutableArray arrayWithQStringList: _qlist];
//}

- (NSString *) languageForEncoding: (NSString *)encoding
{
static qt_QString * _qstring = 0L;
static qt_QString * _qstring_encoding = 0L;
	_qstring = kde_KCharsets_languageForEncoding((kde_KCharsets *)[self qt], (qt_QString *) [encoding toQString: &_qstring_encoding]);
	return [NSString fromQString: _qstring];
}

- (NSString *) encodingForName: (NSString *)descriptiveName
{
static qt_QString * _qstring = 0L;
static qt_QString * _qstring_descriptiveName = 0L;
	_qstring = kde_KCharsets_encodingForName((kde_KCharsets *)[self qt], (qt_QString *) [descriptiveName toQString: &_qstring_descriptiveName]);
	return [NSString fromQString: _qstring];
}

+ (unichar*) fromEntity: (NSString *)str
{
static qt_QString * _qstring_str = 0L;
	return (unichar*) kde_KCharsets_fromEntity((qt_QString *) [str toQString: &_qstring_str]);
}

+ (unichar*) fromEntity: (NSString *)str len: (int)len
{
static qt_QString * _qstring_str = 0L;
	return (unichar*) kde_KCharsets_fromEntity1((qt_QString *) [str toQString: &_qstring_str], (int)len);
}

+ (NSString *) toEntity: (unichar *)ch
{
static qt_QString * _qstring = 0L;
	_qstring = kde_KCharsets_toEntity((qt_QChar*)ch);
	return [NSString fromQString: _qstring];
}

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

@end
