/***************************************************************************
                            QUrl.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_QUrl.h>
#include <qtobjc/QUrl.h>

@implementation  QUrl


- init
{
	if ([self qt] == 0L) {
		[self setQt: qt_new_QUrl()];
		[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: qt_new_QUrl1((qt_QString *) [url toQString: &_qstring_url])];
		[self setAllocatedInObjcWorld: YES];
		[QtSupport setObject: self forQtKey: [self qt]];
	}
	[super init];
	return self;
}

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

- initWithUrl: (QUrl*)url relUrl: (NSString *)relUrl checkSlash: (BOOL)checkSlash
{
static qt_QString * _qstring_relUrl = 0L;
	if ([self qt] == 0L) {
		[self setQt: qt_new_QUrl3((qt_QUrl*) [url qt], (qt_QString *) [relUrl toQString: &_qstring_relUrl], (int)checkSlash)];
		[self setAllocatedInObjcWorld: YES];
		[QtSupport setObject: self forQtKey: [self qt]];
	}
	[super init];
	return self;
}

- initWithUrl: (QUrl*)url relUrl: (NSString *)relUrl 
{
static qt_QString * _qstring_relUrl = 0L;
	if ([self qt] == 0L) {
		[self setQt: qt_new_QUrl3((qt_QUrl*) [url qt], (qt_QString *) [relUrl toQString: &_qstring_relUrl], 0)];
		[self setAllocatedInObjcWorld: YES];
		[QtSupport setObject: self forQtKey: [self qt]];
	}
	[super init];
	return self;
}

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

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

- setProtocol: (NSString *)protocol
{
static qt_QString * _qstring_protocol = 0L;
	qt_QUrl_setProtocol((qt_QUrl *)[self qt], (qt_QString *) [protocol toQString: &_qstring_protocol]);
	return self;
}

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

- setUser: (NSString *)user
{
static qt_QString * _qstring_user = 0L;
	qt_QUrl_setUser((qt_QUrl *)[self qt], (qt_QString *) [user toQString: &_qstring_user]);
	return self;
}

- (BOOL) hasUser
{
	return (BOOL) qt_QUrl_hasUser((qt_QUrl *)[self qt]);
}

- (NSString *) password
{
static qt_QString * _qstring = 0L;
	_qstring = qt_QUrl_password((qt_QUrl *)[self qt]);
	return [NSString fromQString: _qstring];
}

- setPassword: (NSString *)pass
{
static qt_QString * _qstring_pass = 0L;
	qt_QUrl_setPassword((qt_QUrl *)[self qt], (qt_QString *) [pass toQString: &_qstring_pass]);
	return self;
}

- (BOOL) hasPassword
{
	return (BOOL) qt_QUrl_hasPassword((qt_QUrl *)[self qt]);
}

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

- setHost: (NSString *)user
{
static qt_QString * _qstring_user = 0L;
	qt_QUrl_setHost((qt_QUrl *)[self qt], (qt_QString *) [user toQString: &_qstring_user]);
	return self;
}

- (BOOL) hasHost
{
	return (BOOL) qt_QUrl_hasHost((qt_QUrl *)[self qt]);
}

- (int) port
{
	return (int) qt_QUrl_port((qt_QUrl *)[self qt]);
}

- setPort: (int)port
{
	qt_QUrl_setPort((qt_QUrl *)[self qt], (int)port);
	return self;
}

- (BOOL) hasPort
{
	return (BOOL) qt_QUrl_hasPort((qt_QUrl *)[self qt]);
}

- (NSString *) path: (BOOL)correct
{
static qt_QString * _qstring = 0L;
	_qstring = qt_QUrl_path((qt_QUrl *)[self qt], (int)correct);
	return [NSString fromQString: _qstring];
}

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

- (BOOL) hasPath
{
	return (BOOL) qt_QUrl_hasPath((qt_QUrl *)[self qt]);
}

- setEncodedPathAndQuery: (NSString *)enc
{
static qt_QString * _qstring_enc = 0L;
	qt_QUrl_setEncodedPathAndQuery((qt_QUrl *)[self qt], (qt_QString *) [enc toQString: &_qstring_enc]);
	return self;
}

- (NSString *) encodedPathAndQuery
{
static qt_QString * _qstring = 0L;
	_qstring = qt_QUrl_encodedPathAndQuery((qt_QUrl *)[self qt]);
	return [NSString fromQString: _qstring];
}

- setQuery: (NSString *)txt
{
static qt_QString * _qstring_txt = 0L;
	qt_QUrl_setQuery((qt_QUrl *)[self qt], (qt_QString *) [txt toQString: &_qstring_txt]);
	return self;
}

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

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

- setRef: (NSString *)txt
{
static qt_QString * _qstring_txt = 0L;
	qt_QUrl_setRef((qt_QUrl *)[self qt], (qt_QString *) [txt toQString: &_qstring_txt]);
	return self;
}

- (BOOL) hasRef
{
	return (BOOL) qt_QUrl_hasRef((qt_QUrl *)[self qt]);
}

- (BOOL) isValid
{
	return (BOOL) qt_QUrl_isValid((qt_QUrl *)[self qt]);
}

- (BOOL) isLocalFile
{
	return (BOOL) qt_QUrl_isLocalFile((qt_QUrl *)[self qt]);
}

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

- setFileName: (NSString *)txt
{
static qt_QString * _qstring_txt = 0L;
	qt_QUrl_setFileName((qt_QUrl *)[self qt], (qt_QString *) [txt toQString: &_qstring_txt]);
	return self;
}

- (NSString *) fileName
{
static qt_QString * _qstring = 0L;
	_qstring = qt_QUrl_fileName((qt_QUrl *)[self qt]);
	return [NSString fromQString: _qstring];
}

- (NSString *) dirPath
{
static qt_QString * _qstring = 0L;
	_qstring = qt_QUrl_dirPath((qt_QUrl *)[self qt]);
	return [NSString fromQString: _qstring];
}

- (NSString *) toString: (BOOL)encodedPath forcePrependProtocol: (BOOL)forcePrependProtocol
{
static qt_QString * _qstring = 0L;
	_qstring = qt_QUrl_toString((qt_QUrl *)[self qt], (int)encodedPath, (int)forcePrependProtocol);
	return [NSString fromQString: _qstring];
}

- (BOOL) cdUp
{
	return (BOOL) qt_QUrl_cdUp((qt_QUrl *)[self qt]);
}

+ decode: (NSString *)url
{
static qt_QString * _qstring_url = 0L;
	qt_QUrl_decode((qt_QString *) [url toQString: &_qstring_url]);
	return self;
}

+ encode: (NSString *)url
{
static qt_QString * _qstring_url = 0L;
	qt_QUrl_encode((qt_QString *) [url toQString: &_qstring_url]);
	return self;
}

+ (BOOL) isRelativeUrl: (NSString *)url
{
static qt_QString * _qstring_url = 0L;
	return (BOOL) qt_QUrl_isRelativeUrl((qt_QString *) [url toQString: &_qstring_url]);
}

- reset
{
	qt_QUrl_reset((qt_QUrl *)[self qt]);
	return self;
}

- (BOOL) parseURL: (NSString *)url
{
static qt_QString * _qstring_url = 0L;
	return (BOOL) qt_QUrl_parse((qt_QUrl *)[self qt], (qt_QString *) [url toQString: &_qstring_url]);
}
- (void *) qt
{
	return _qt;
}

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

- (BOOL) allocatedInObjcWorld
{
	return _allocatedInObjcWorld;
}

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


@end
