/***************************************************************************
                            QTextCodec.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_QTextCodec.h>
#include <qtobjc/QTextCodec.h>
#include <qtobjc/QIODevice.h>

#include <qtobjc/QByteArray.h>

@implementation  QTextCodec

- (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]) {
			qt_del_QTextCodec((qt_QTextCodec *)[self qt]);
		}
		[QtSupport removeQtKey: [self qt]];
		[self setQt: 0L];
	}
	[super dealloc];
}

- (NSString *) name
{
	return (NSString *) [NSString stringWithCString: qt_QTextCodec_name((qt_QTextCodec *)[self qt])];
}

- (NSString *) mimeName
{
	return (NSString *) [NSString stringWithCString: qt_QTextCodec_mimeName((qt_QTextCodec *)[self qt])];
}

- (int) mibEnum
{
	return (int) qt_QTextCodec_mibEnum((qt_QTextCodec *)[self qt]);
}

- (QTextDecoder*) makeDecoder
{
	return (QTextDecoder*) [QtSupport objectForQtKey: qt_QTextCodec_makeDecoder((qt_QTextCodec *)[self qt]) withClass: [QTextDecoder class] allocatedInObjcWorld: YES];
}

- (QTextEncoder*) makeEncoder
{
	return (QTextEncoder*) [QtSupport objectForQtKey: qt_QTextCodec_makeEncoder((qt_QTextCodec *)[self qt]) withClass: [QTextEncoder class] allocatedInObjcWorld: YES];
}

- (NSString *) toUnicode: (NSString *)chars len: (int)len
{
static qt_QString * _qstring = 0L;
	_qstring = qt_QTextCodec_toUnicode((qt_QTextCodec *)[self qt], (char*) [chars cString], (int)len);
	return [NSString fromQString: _qstring];
}

- (NSString *) fromUnicode: (NSString *)uc lenInOut: (int)lenInOut
{
static qt_QCString * _qcstring = 0L;
static qt_QString * _qstring_uc = 0L;
	_qcstring = qt_QTextCodec_fromUnicode((qt_QTextCodec *)[self qt], (qt_QString *) [uc toQString: &_qstring_uc], (int)lenInOut);
	return [NSString fromQCString: _qcstring];
}

- (NSString *) fromUnicode: (NSString *)uc
{
static qt_QCString * _qcstring = 0L;
static qt_QString * _qstring_uc = 0L;
	_qcstring = qt_QTextCodec_fromUnicode1((qt_QTextCodec *)[self qt], (qt_QString *) [uc toQString: &_qstring_uc]);
	return [NSString fromQCString: _qcstring];
}

- (NSString *) byteArrayToUnicode: (QByteArray*)arg1 len: (int)len
{
static qt_QString * _qstring = 0L;
	_qstring = qt_QTextCodec_toUnicode1((qt_QTextCodec *)[self qt], (qt_QByteArray*) [arg1 qt], (int)len);
	return [NSString fromQString: _qstring];
}

- (NSString *) byteArrayToUnicode: (QByteArray*)arg1
{
static qt_QString * _qstring = 0L;
	_qstring = qt_QTextCodec_toUnicode2((qt_QTextCodec *)[self qt], (qt_QByteArray*) [arg1 qt]);
	return [NSString fromQString: _qstring];
}

//- (NSString *) toUnicode: (NSString *)arg1 len: (int)len
//{
//static qt_QString * _qstring = 0L;
//static qt_QCString * _qcstring_arg1 = 0L;
//	_qstring = qt_QTextCodec_toUnicode3((qt_QTextCodec *)[self qt], (qt_QCString*) [arg1 toQCString: &_qcstring_arg1], (int)len);
//	return [NSString fromQString: _qstring];
//}

- (NSString *) toUnicode: (NSString *)arg1
{
static qt_QString * _qstring = 0L;
static qt_QCString * _qcstring_arg1 = 0L;
	_qstring = qt_QTextCodec_toUnicode4((qt_QTextCodec *)[self qt], (qt_QCString*) [arg1 toQCString: &_qcstring_arg1]);
	return [NSString fromQString: _qstring];
}

//- (NSString *) toUnicode: (NSString *)chars
//{
//static qt_QString * _qstring = 0L;
//	_qstring = qt_QTextCodec_toUnicode5((qt_QTextCodec *)[self qt], (char*) [chars cString]);
//	return [NSString fromQString: _qstring];
//}

- (BOOL) canEncodeUnichar: (unichar *)arg1
{
	return (BOOL) qt_QTextCodec_canEncode((qt_QTextCodec *)[self qt], (qt_QChar*)arg1);
}

- (BOOL) canEncodeString: (NSString *)arg1
{
static qt_QString * _qstring_arg1 = 0L;
	return (BOOL) qt_QTextCodec_canEncode1((qt_QTextCodec *)[self qt], (qt_QString *) [arg1 toQString: &_qstring_arg1]);
}

- (int) heuristicContentMatch: (NSString *)chars len: (int)len
{
	return (int) qt_QTextCodec_heuristicContentMatch((qt_QTextCodec *)[self qt], (char*) [chars cString], (int)len);
}

- (int) heuristicNameMatch: (NSString *)hint
{
	return (int) qt_QTextCodec_heuristicNameMatch((qt_QTextCodec *)[self qt], (char*) [hint cString]);
}

- (QByteArray*) fromUnicode: (NSString *)uc from: (int)from len: (int)len
{
static qt_QString * _qstring_uc = 0L;
	return (QByteArray*) [QtSupport objectForQtKey: qt_QTextCodec_fromUnicode2((qt_QTextCodec *)[self qt], (qt_QString *) [uc toQString: &_qstring_uc], (int)from, (int)len) withClass: [QByteArray class] allocatedInObjcWorld: YES];
}

- (unsigned short) characterFromUnicode: (NSString *)str pos: (int)pos
{
static qt_QString * _qstring_str = 0L;
	return (unsigned short) qt_QTextCodec_characterFromUnicode((qt_QTextCodec *)[self qt], (qt_QString *) [str toQString: &_qstring_str], (int)pos);
}

+ (QTextCodec*) loadCharmap: (QIODevice *)arg1
{
	return (QTextCodec*) [QtSupport objectForQtKey: qt_QTextCodec_loadCharmap((qt_QIODevice *) [arg1 qt]) withClass: [QTextCodec class] allocatedInObjcWorld: YES];
}

+ (QTextCodec*) loadCharmapFile: (NSString *)filename
{
static qt_QString * _qstring_filename = 0L;
	return (QTextCodec*) [QtSupport objectForQtKey: qt_QTextCodec_loadCharmapFile((qt_QString *) [filename toQString: &_qstring_filename]) withClass: [QTextCodec class] allocatedInObjcWorld: YES];
}

+ (QTextCodec*) codecForMib: (int)mib
{
	return (QTextCodec*) [QtSupport objectForQtKey: qt_QTextCodec_codecForMib((int)mib) withClass: [QTextCodec class] allocatedInObjcWorld: YES];
}

+ (QTextCodec*) codecForName: (NSString *)hint accuracy: (int)accuracy
{
	return (QTextCodec*) [QtSupport objectForQtKey: qt_QTextCodec_codecForName((char*) [hint cString], (int)accuracy) withClass: [QTextCodec class] allocatedInObjcWorld: YES];
}

+ (QTextCodec*) codecForName: (NSString *)hint 
{
	return (QTextCodec*) [QtSupport objectForQtKey: qt_QTextCodec_codecForName((char*) [hint cString], 0) withClass: [QTextCodec class] allocatedInObjcWorld: YES];
}

+ (QTextCodec*) codecForContent: (NSString *)chars len: (int)len
{
	return (QTextCodec*) [QtSupport objectForQtKey: qt_QTextCodec_codecForContent((char*) [chars cString], (int)len) withClass: [QTextCodec class] allocatedInObjcWorld: YES];
}

+ (QTextCodec*) codecForIndex: (int)i
{
	return (QTextCodec*) [QtSupport objectForQtKey: qt_QTextCodec_codecForIndex((int)i) withClass: [QTextCodec class] allocatedInObjcWorld: YES];
}

+ (QTextCodec*) codecForLocale
{
	return (QTextCodec*) [QtSupport objectForQtKey: qt_QTextCodec_codecForLocale() withClass: [QTextCodec class] allocatedInObjcWorld: YES];
}

+ setCodecForLocale: (QTextCodec*)c
{
	qt_QTextCodec_setCodecForLocale((qt_QTextCodec*) [c qt]);
	return self;
}

+ deleteAllCodecs
{
	qt_QTextCodec_deleteAllCodecs();
	return self;
}

+ (NSString *) locale
{
	return (NSString *) [NSString stringWithCString: qt_QTextCodec_locale()];
}

@end
