/***************************************************************************
                            KURL.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_KURL.h>
#include <kdeobjc/KDESupport.h>
#include <kdeobjc/KURL.h>
#include <qtobjc/QUrl.h>


@implementation  KURL

- (void *) qt
{
	return _qt;
}

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

- (BOOL) allocatedInObjcWorld
{
	return _allocatedInObjcWorld;
}

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


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

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

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

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

//- initWithText: (NSString *)url encoding_hint: (int)encoding_hint
//{
//	if ([self qt] == 0L) {
//		[self setQt: kde_new_KURL2((char*) [url cString], (int)encoding_hint)];
//		[self setAllocatedInObjcWorld: YES];
//		[QtSupport setObject: self forQtKey: [self qt]];
//	}
//	[super init];
//	return self;
//}

//- initWithText: (NSString *)url
//{
//	if ([self qt] == 0L) {
//		[self setQt: kde_new_KURL2((char*) [url cString], 0)];
//		[self setAllocatedInObjcWorld: YES];
//		[QtSupport setObject: self forQtKey: [self qt]];
//	}
//	[super init];
//	return self;
//}

//- initWithText: (NSString *)url encoding_hint: (int)encoding_hint
//{
//static qt_QCString * _qcstring_url = 0L;
//	if ([self qt] == 0L) {
//		[self setQt: kde_new_KURL3((qt_QCString*) [url toQCString: &_qcstring_url], (int)encoding_hint)];
//		[self setAllocatedInObjcWorld: YES];
//		[QtSupport setObject: self forQtKey: [self qt]];
//	}
//	[super init];
//	return self;
//}

//- initWithText: (NSString *)url
//{
//static qt_QCString * _qcstring_url = 0L;
//	if ([self qt] == 0L) {
//		[self setQt: kde_new_KURL3((qt_QCString*) [url toQCString: &_qcstring_url], 0)];
//		[self setAllocatedInObjcWorld: YES];
//		[QtSupport setObject: self forQtKey: [self qt]];
//	}
//	[super init];
//	return self;
//}

- copyWithZone: (NSZone *) zone
{
	KURL * aCopy;
	aCopy = [[(KURL *)[[self class] allocWithZone: zone] setQt: kde_new_KURL4([self qt])] init];
	[aCopy setAllocatedInObjcWorld: YES];
	[QtSupport setObject: aCopy forQtKey: [aCopy qt]];
	return aCopy;
}

- initWithUrl: (QUrl*)u
{
	if ([self qt] == 0L) {
		[self setQt: kde_new_KURL5((qt_QUrl*) [u qt])];
		[self setAllocatedInObjcWorld: YES];
		[QtSupport setObject: self forQtKey: [self qt]];
	}
	[super init];
	return self;
}

- initWithURL: (KURL*)_baseurl _rel_url: (NSString *)_rel_url encoding_hint: (int)encoding_hint
{
static qt_QString * _qstring__rel_url = 0L;
	if ([self qt] == 0L) {
		[self setQt: kde_new_KURL6((kde_KURL*) [_baseurl qt], (qt_QString *) [_rel_url toQString: &_qstring__rel_url], (int)encoding_hint)];
		[self setAllocatedInObjcWorld: YES];
		[QtSupport setObject: self forQtKey: [self qt]];
	}
	[super init];
	return self;
}

- initWithURL: (KURL*)_baseurl _rel_url: (NSString *)_rel_url 
{
static qt_QString * _qstring__rel_url = 0L;
	if ([self qt] == 0L) {
		[self setQt: kde_new_KURL6((kde_KURL*) [_baseurl qt], (qt_QString *) [_rel_url toQString: &_qstring__rel_url], 0)];
		[self setAllocatedInObjcWorld: YES];
		[QtSupport setObject: self forQtKey: [self qt]];
	}
	[super init];
	return self;
}

- (NSString *) protocol
{
static qt_QString * _qstring = 0L;
	_qstring = kde_KURL_protocol((kde_KURL *)[self qt]);
	return [NSString fromQString: _qstring];
}

- setProtocol: (NSString *)_txt
{
static qt_QString * _qstring__txt = 0L;
	kde_KURL_setProtocol((kde_KURL *)[self qt], (qt_QString *) [_txt toQString: &_qstring__txt]);
	return self;
}

- (NSString *) user
{
static qt_QString * _qstring = 0L;
	_qstring = kde_KURL_user((kde_KURL *)[self qt]);
	return [NSString fromQString: _qstring];
}

- setUser: (NSString *)_txt
{
static qt_QString * _qstring__txt = 0L;
	kde_KURL_setUser((kde_KURL *)[self qt], (qt_QString *) [_txt toQString: &_qstring__txt]);
	return self;
}

- (BOOL) hasUser
{
	return (BOOL) kde_KURL_hasUser((kde_KURL *)[self qt]);
}

- (NSString *) pass
{
static qt_QString * _qstring = 0L;
	_qstring = kde_KURL_pass((kde_KURL *)[self qt]);
	return [NSString fromQString: _qstring];
}

- setPass: (NSString *)_txt
{
static qt_QString * _qstring__txt = 0L;
	kde_KURL_setPass((kde_KURL *)[self qt], (qt_QString *) [_txt toQString: &_qstring__txt]);
	return self;
}

- (BOOL) hasPass
{
	return (BOOL) kde_KURL_hasPass((kde_KURL *)[self qt]);
}

- (NSString *) host
{
static qt_QString * _qstring = 0L;
	_qstring = kde_KURL_host((kde_KURL *)[self qt]);
	return [NSString fromQString: _qstring];
}

- setHost: (NSString *)_txt
{
static qt_QString * _qstring__txt = 0L;
	kde_KURL_setHost((kde_KURL *)[self qt], (qt_QString *) [_txt toQString: &_qstring__txt]);
	return self;
}

- (BOOL) hasHost
{
	return (BOOL) kde_KURL_hasHost((kde_KURL *)[self qt]);
}

- (unsigned short) port
{
	return (unsigned short) kde_KURL_port((kde_KURL *)[self qt]);
}

- setPort: (unsigned short)_p
{
	kde_KURL_setPort((kde_KURL *)[self qt], (unsigned short)_p);
	return self;
}

- (NSString *) path
{
static qt_QString * _qstring = 0L;
	_qstring = kde_KURL_path((kde_KURL *)[self qt]);
	return [NSString fromQString: _qstring];
}

- (NSString *) path: (int)_trailing
{
static qt_QString * _qstring = 0L;
	_qstring = kde_KURL_path1((kde_KURL *)[self qt], (int)_trailing);
	return [NSString fromQString: _qstring];
}

- setPath: (NSString *)path
{
static qt_QString * _qstring_path = 0L;
	kde_KURL_setPath((kde_KURL *)[self qt], (qt_QString *) [path toQString: &_qstring_path]);
	return self;
}

- (BOOL) hasPath
{
	return (BOOL) kde_KURL_hasPath((kde_KURL *)[self qt]);
}

- cleanPath: (BOOL)cleanDirSeparator
{
	kde_KURL_cleanPath((kde_KURL *)[self qt], (int)cleanDirSeparator);
	return self;
}

- cleanPath
{
	kde_KURL_cleanPath((kde_KURL *)[self qt], 1);
	return self;
}

- setEncodedPathAndQuery: (NSString *)_txt encoding_hint: (int)encoding_hint
{
static qt_QString * _qstring__txt = 0L;
	kde_KURL_setEncodedPathAndQuery((kde_KURL *)[self qt], (qt_QString *) [_txt toQString: &_qstring__txt], (int)encoding_hint);
	return self;
}

- setEncodedPathAndQuery: (NSString *)_txt 
{
static qt_QString * _qstring__txt = 0L;
	kde_KURL_setEncodedPathAndQuery((kde_KURL *)[self qt], (qt_QString *) [_txt toQString: &_qstring__txt], 0);
	return self;
}

- setEncodedPath: (NSString *)_txt encoding_hint: (int)encoding_hint
{
static qt_QString * _qstring__txt = 0L;
	kde_KURL_setEncodedPath((kde_KURL *)[self qt], (qt_QString *) [_txt toQString: &_qstring__txt], (int)encoding_hint);
	return self;
}

- setEncodedPath: (NSString *)_txt 
{
static qt_QString * _qstring__txt = 0L;
	kde_KURL_setEncodedPath((kde_KURL *)[self qt], (qt_QString *) [_txt toQString: &_qstring__txt], 0);
	return self;
}

- (NSString *) encodedPathAndQuery: (int)_trailing _no_empty_path: (BOOL)_no_empty_path encoding_hint: (int)encoding_hint
{
static qt_QString * _qstring = 0L;
	_qstring = kde_KURL_encodedPathAndQuery((kde_KURL *)[self qt], (int)_trailing, (int)_no_empty_path, (int)encoding_hint);
	return [NSString fromQString: _qstring];
}

- setQuery: (NSString *)_txt encoding_hint: (int)encoding_hint
{
static qt_QString * _qstring__txt = 0L;
	kde_KURL_setQuery((kde_KURL *)[self qt], (qt_QString *) [_txt toQString: &_qstring__txt], (int)encoding_hint);
	return self;
}

- setQuery: (NSString *)_txt 
{
static qt_QString * _qstring__txt = 0L;
	kde_KURL_setQuery((kde_KURL *)[self qt], (qt_QString *) [_txt toQString: &_qstring__txt], 0);
	return self;
}

- (NSString *) query
{
static qt_QString * _qstring = 0L;
	_qstring = kde_KURL_query((kde_KURL *)[self qt]);
	return [NSString fromQString: _qstring];
}

- (NSString *) ref
{
static qt_QString * _qstring = 0L;
	_qstring = kde_KURL_ref((kde_KURL *)[self qt]);
	return [NSString fromQString: _qstring];
}

- setRef: (NSString *)_txt
{
static qt_QString * _qstring__txt = 0L;
	kde_KURL_setRef((kde_KURL *)[self qt], (qt_QString *) [_txt toQString: &_qstring__txt]);
	return self;
}

- (BOOL) hasRef
{
	return (BOOL) kde_KURL_hasRef((kde_KURL *)[self qt]);
}

- (NSString *) htmlRef
{
static qt_QString * _qstring = 0L;
	_qstring = kde_KURL_htmlRef((kde_KURL *)[self qt]);
	return [NSString fromQString: _qstring];
}

- (NSString *) encodedHtmlRef
{
static qt_QString * _qstring = 0L;
	_qstring = kde_KURL_encodedHtmlRef((kde_KURL *)[self qt]);
	return [NSString fromQString: _qstring];
}

- setHTMLRef: (NSString *)_ref
{
static qt_QString * _qstring__ref = 0L;
	kde_KURL_setHTMLRef((kde_KURL *)[self qt], (qt_QString *) [_ref toQString: &_qstring__ref]);
	return self;
}

- (BOOL) hasHTMLRef
{
	return (BOOL) kde_KURL_hasHTMLRef((kde_KURL *)[self qt]);
}

- (BOOL) isValid
{
	return (BOOL) kde_KURL_isValid((kde_KURL *)[self qt]);
}

- (BOOL) isMalformed
{
	return (BOOL) kde_KURL_isMalformed((kde_KURL *)[self qt]);
}

- (BOOL) isLocalFile
{
	return (BOOL) kde_KURL_isLocalFile((kde_KURL *)[self qt]);
}

- setFileEncoding: (NSString *)encoding
{
static qt_QString * _qstring_encoding = 0L;
	kde_KURL_setFileEncoding((kde_KURL *)[self qt], (qt_QString *) [encoding toQString: &_qstring_encoding]);
	return self;
}

- (NSString *) fileEncoding
{
static qt_QString * _qstring = 0L;
	_qstring = kde_KURL_fileEncoding((kde_KURL *)[self qt]);
	return [NSString fromQString: _qstring];
}

- (BOOL) hasSubURL
{
	return (BOOL) kde_KURL_hasSubURL((kde_KURL *)[self qt]);
}

- addPath: (NSString *)_txt
{
static qt_QString * _qstring__txt = 0L;
	kde_KURL_addPath((kde_KURL *)[self qt], (qt_QString *) [_txt toQString: &_qstring__txt]);
	return self;
}

- (NSString *) queryItem: (NSString *)_item
{
static qt_QString * _qstring = 0L;
static qt_QString * _qstring__item = 0L;
	_qstring = kde_KURL_queryItem((kde_KURL *)[self qt], (qt_QString *) [_item toQString: &_qstring__item]);
	return [NSString fromQString: _qstring];
}

- setFileName: (NSString *)_txt
{
static qt_QString * _qstring__txt = 0L;
	kde_KURL_setFileName((kde_KURL *)[self qt], (qt_QString *) [_txt toQString: &_qstring__txt]);
	return self;
}

- (NSString *) fileName: (BOOL)_ignore_trailing_slash_in_path
{
static qt_QString * _qstring = 0L;
	_qstring = kde_KURL_fileName((kde_KURL *)[self qt], (int)_ignore_trailing_slash_in_path);
	return [NSString fromQString: _qstring];
}

- (NSString *) directory: (BOOL)_strip_trailing_slash_from_result _ignore_trailing_slash_in_path: (BOOL)_ignore_trailing_slash_in_path
{
static qt_QString * _qstring = 0L;
	_qstring = kde_KURL_directory((kde_KURL *)[self qt], (int)_strip_trailing_slash_from_result, (int)_ignore_trailing_slash_in_path);
	return [NSString fromQString: _qstring];
}

- (BOOL) cd: (NSString *)_dir
{
static qt_QString * _qstring__dir = 0L;
	return (BOOL) kde_KURL_cd((kde_KURL *)[self qt], (qt_QString *) [_dir toQString: &_qstring__dir]);
}

- (NSString *) url: (int)_trailing encoding_hint: (int)encoding_hint
{
static qt_QString * _qstring = 0L;
	_qstring = kde_KURL_url((kde_KURL *)[self qt], (int)_trailing, (int)encoding_hint);
	return [NSString fromQString: _qstring];
}

- (NSString *) prettyURL: (int)_trailing
{
static qt_QString * _qstring = 0L;
	_qstring = kde_KURL_prettyURL((kde_KURL *)[self qt], (int)_trailing);
	return [NSString fromQString: _qstring];
}

- (BOOL) isEmpty
{
	return (BOOL) kde_KURL_isEmpty((kde_KURL *)[self qt]);
}

- (KURL*) upURL
{
	return (KURL*) [QtSupport objectForQtKey: kde_KURL_upURL((kde_KURL *)[self qt]) withClass: [KURL class] allocatedInObjcWorld: YES];
}

- (BOOL) cmp: (KURL*)u ignore_trailing: (BOOL)ignore_trailing
{
	return (BOOL) kde_KURL_cmp((kde_KURL *)[self qt], (kde_KURL*) [u qt], (int)ignore_trailing);
}

- (BOOL) cmp: (KURL*)u 
{
	return (BOOL) kde_KURL_cmp((kde_KURL *)[self qt], (kde_KURL*) [u qt], 0);
}

- (BOOL) isParentOf: (KURL*)u
{
	return (BOOL) kde_KURL_isParentOf((kde_KURL *)[self qt], (kde_KURL*) [u qt]);
}

//+ (List) split: (NSString *)_url
//{
//static qt_QString * _qstring__url = 0L;
//	return (List) [QtSupport objectForQtKey: kde_KURL_split((qt_QString *) [_url toQString: &_qstring__url]) withClass: [ class] allocatedInObjcWorld: YES];
//}

//+ (List) split: (KURL*)_url
//{
//	return (List) [QtSupport objectForQtKey: kde_KURL_split1((kde_KURL*) [_url qt]) withClass: [ class] allocatedInObjcWorld: YES];
//}

//+ (KURL*) join: (List*)_list
//{
//	return (KURL*) [QtSupport objectForQtKey: kde_KURL_join((kde_List*) [_list qt]) withClass: [KURL class] allocatedInObjcWorld: YES];
//}

+ (NSString *) encode_string: (NSString *)str encoding_hint: (int)encoding_hint
{
static qt_QString * _qstring = 0L;
static qt_QString * _qstring_str = 0L;
	_qstring = kde_KURL_encode_string((qt_QString *) [str toQString: &_qstring_str], (int)encoding_hint);
	return [NSString fromQString: _qstring];
}

+ (NSString *) encode_string_no_slash: (NSString *)str encoding_hint: (int)encoding_hint
{
static qt_QString * _qstring = 0L;
static qt_QString * _qstring_str = 0L;
	_qstring = kde_KURL_encode_string_no_slash((qt_QString *) [str toQString: &_qstring_str], (int)encoding_hint);
	return [NSString fromQString: _qstring];
}

+ (NSString *) decode_string: (NSString *)str encoding_hint: (int)encoding_hint
{
static qt_QString * _qstring = 0L;
static qt_QString * _qstring_str = 0L;
	_qstring = kde_KURL_decode_string((qt_QString *) [str toQString: &_qstring_str], (int)encoding_hint);
	return [NSString fromQString: _qstring];
}

+ (BOOL) isRelativeURL: (NSString *)_url
{
static qt_QString * _qstring__url = 0L;
	return (BOOL) kde_KURL_isRelativeURL((qt_QString *) [_url toQString: &_qstring__url]);
}

- reset
{
	kde_KURL_reset((kde_KURL *)[self qt]);
	return self;
}

- parseURL: (NSString *)_url encoding_hint: (int)encoding_hint
{
static qt_QString * _qstring__url = 0L;
	kde_KURL_parse((kde_KURL *)[self qt], (qt_QString *) [_url toQString: &_qstring__url], (int)encoding_hint);
	return self;
}

- parseURL: (NSString *)_url
{
static qt_QString * _qstring__url = 0L;
	kde_KURL_parse((kde_KURL *)[self qt], (qt_QString *) [_url toQString: &_qstring__url], 0);
	return self;
}

@end
