/***************************************************************************
                            QDir.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_QStringList.h>
#include <qtc/qt_QDir.h>
#include <qtobjc/QDir.h>

@implementation  QDir

- (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: qt_new_QDir()];
		[self setAllocatedInObjcWorld: YES];
		[QtSupport setObject: self forQtKey: [self qt]];
	}
	[super init];
	return self;
}

- initWithText: (NSString *)path nameFilter: (NSString *)nameFilter sortSpec: (int)sortSpec filterSpec: (int)filterSpec
{
static qt_QString * _qstring_nameFilter = 0L;
static qt_QString * _qstring_path = 0L;
	if ([self qt] == 0L) {
		[self setQt: qt_new_QDir1((qt_QString *) [path toQString: &_qstring_path], (qt_QString *) [nameFilter toQString: &_qstring_nameFilter], (int)sortSpec, (int)filterSpec)];
		[self setAllocatedInObjcWorld: YES];
		[QtSupport setObject: self forQtKey: [self qt]];
	}
	[super init];
	return self;
}

- initWithText: (NSString *)path 
{
static qt_QString * _qstring_path = 0L;
	if ([self qt] == 0L) {
		[self setQt: qt_new_QDir1((qt_QString *) [path toQString: &_qstring_path], qt_QString_null(), [QDir Name] | [QDir IgnoreCase], [QDir All])];
		[self setAllocatedInObjcWorld: YES];
		[QtSupport setObject: self forQtKey: [self qt]];
	}
	[super init];
	return self;
}

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

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

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

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

- (NSString *) absPath
{
static qt_QString * _qstring = 0L;
	_qstring = qt_QDir_absPath((qt_QDir *)[self qt]);
	return [NSString fromQString: _qstring];
}

- (NSString *) canonicalPath
{
static qt_QString * _qstring = 0L;
	_qstring = qt_QDir_canonicalPath((qt_QDir *)[self qt]);
	return [NSString fromQString: _qstring];
}

- (NSString *) dirName
{
static qt_QString * _qstring = 0L;
	_qstring = qt_QDir_dirName((qt_QDir *)[self qt]);
	return [NSString fromQString: _qstring];
}

- (NSString *) filePath: (NSString *)fileName acceptAbsPath: (BOOL)acceptAbsPath
{
static qt_QString * _qstring = 0L;
static qt_QString * _qstring_fileName = 0L;
	_qstring = qt_QDir_filePath((qt_QDir *)[self qt], (qt_QString *) [fileName toQString: &_qstring_fileName], (int)acceptAbsPath);
	return [NSString fromQString: _qstring];
}

- (NSString *) absFilePath: (NSString *)fileName acceptAbsPath: (BOOL)acceptAbsPath
{
static qt_QString * _qstring = 0L;
static qt_QString * _qstring_fileName = 0L;
	_qstring = qt_QDir_absFilePath((qt_QDir *)[self qt], (qt_QString *) [fileName toQString: &_qstring_fileName], (int)acceptAbsPath);
	return [NSString fromQString: _qstring];
}

- (BOOL) cd: (NSString *)dirName acceptAbsPath: (BOOL)acceptAbsPath
{
static qt_QString * _qstring_dirName = 0L;
	return (BOOL) qt_QDir_cd((qt_QDir *)[self qt], (qt_QString *) [dirName toQString: &_qstring_dirName], (int)acceptAbsPath);
}

- (BOOL) cd: (NSString *)dirName 
{
static qt_QString * _qstring_dirName = 0L;
	return (BOOL) qt_QDir_cd((qt_QDir *)[self qt], (qt_QString *) [dirName toQString: &_qstring_dirName], 1);
}

- (BOOL) cdUp
{
	return (BOOL) qt_QDir_cdUp((qt_QDir *)[self qt]);
}

- (NSString *) nameFilter
{
static qt_QString * _qstring = 0L;
	_qstring = qt_QDir_nameFilter((qt_QDir *)[self qt]);
	return [NSString fromQString: _qstring];
}

- setNameFilter: (NSString *)nameFilter
{
static qt_QString * _qstring_nameFilter = 0L;
	qt_QDir_setNameFilter((qt_QDir *)[self qt], (qt_QString *) [nameFilter toQString: &_qstring_nameFilter]);
	return self;
}

- (int) filter
{
	return (int) qt_QDir_filter((qt_QDir *)[self qt]);
}

- setFilter: (int)filterSpec
{
	qt_QDir_setFilter((qt_QDir *)[self qt], (int)filterSpec);
	return self;
}

- (int) sorting
{
	return (int) qt_QDir_sorting((qt_QDir *)[self qt]);
}

- setSorting: (int)sortSpec
{
	qt_QDir_setSorting((qt_QDir *)[self qt], (int)sortSpec);
	return self;
}

- (BOOL) matchAllDirs
{
	return (BOOL) qt_QDir_matchAllDirs((qt_QDir *)[self qt]);
}

- setMatchAllDirs: (BOOL)arg1
{
	qt_QDir_setMatchAllDirs((qt_QDir *)[self qt], (int)arg1);
	return self;
}

- (unsigned int) count
{
	return (unsigned int) qt_QDir_count((qt_QDir *)[self qt]);
}

- (NSArray *) encodedEntryList: (int)filterSpec sortSpec: (int)sortSpec
{
static qt_QStrList * _qlist = 0L;
	_qlist = qt_QDir_encodedEntryList((qt_QDir *)[self qt], (int)filterSpec, (int)sortSpec);
	return (NSArray *) [NSMutableArray arrayWithQStrList: _qlist];
}

- (NSArray *) encodedEntryList: (NSString *)nameFilter filterSpec: (int)filterSpec sortSpec: (int)sortSpec
{
static qt_QStrList * _qlist = 0L;
static qt_QString * _qstring_nameFilter = 0L;
	_qlist = qt_QDir_encodedEntryList1((qt_QDir *)[self qt], (qt_QString *) [nameFilter toQString: &_qstring_nameFilter], (int)filterSpec, (int)sortSpec);
	return (NSArray *) [NSMutableArray arrayWithQStrList: _qlist];
}

- (NSArray *) entryList: (int)filterSpec sortSpec: (int)sortSpec
{
static qt_QStringList * _qlist = 0L;
	_qlist = qt_QDir_entryList((qt_QDir *)[self qt], (int)filterSpec, (int)sortSpec);
	return (NSArray *) [NSMutableArray arrayWithQStringList: _qlist];
}

- (NSArray *) entryList: (NSString *)nameFilter filterSpec: (int)filterSpec sortSpec: (int)sortSpec
{
static qt_QStringList * _qlist = 0L;
static qt_QString * _qstring_nameFilter = 0L;
	_qlist = qt_QDir_entryList1((qt_QDir *)[self qt], (qt_QString *) [nameFilter toQString: &_qstring_nameFilter], (int)filterSpec, (int)sortSpec);
	return (NSArray *) [NSMutableArray arrayWithQStringList: _qlist];
}

- (NSArray *) entryInfoList: (int)filterSpec sortSpec: (int)sortSpec
{
static qt_QFileInfoList * _qlist = 0L;
	_qlist = qt_QDir_entryInfoList((qt_QDir *)[self qt], (int)filterSpec, (int)sortSpec);
	return (NSArray *) [NSMutableArray arrayWithQFileInfoList: _qlist];
}

- (NSArray *) entryInfoList: (NSString *)nameFilter filterSpec: (int)filterSpec sortSpec: (int)sortSpec
{
static qt_QFileInfoList * _qlist = 0L;
static qt_QString * _qstring_nameFilter = 0L;
	_qlist = qt_QDir_entryInfoList1((qt_QDir *)[self qt], (qt_QString *) [nameFilter toQString: &_qstring_nameFilter], (int)filterSpec, (int)sortSpec);
	return (NSArray *) [NSMutableArray arrayWithQFileInfoList: _qlist];
}

- (BOOL) mkdir: (NSString *)dirName acceptAbsPath: (BOOL)acceptAbsPath
{
static qt_QString * _qstring_dirName = 0L;
	return (BOOL) qt_QDir_mkdir((qt_QDir *)[self qt], (qt_QString *) [dirName toQString: &_qstring_dirName], (int)acceptAbsPath);
}

- (BOOL) mkdir: (NSString *)dirName 
{
static qt_QString * _qstring_dirName = 0L;
	return (BOOL) qt_QDir_mkdir((qt_QDir *)[self qt], (qt_QString *) [dirName toQString: &_qstring_dirName], 1);
}

- (BOOL) rmdir: (NSString *)dirName acceptAbsPath: (BOOL)acceptAbsPath
{
static qt_QString * _qstring_dirName = 0L;
	return (BOOL) qt_QDir_rmdir((qt_QDir *)[self qt], (qt_QString *) [dirName toQString: &_qstring_dirName], (int)acceptAbsPath);
}

- (BOOL) rmdir: (NSString *)dirName 
{
static qt_QString * _qstring_dirName = 0L;
	return (BOOL) qt_QDir_rmdir((qt_QDir *)[self qt], (qt_QString *) [dirName toQString: &_qstring_dirName], 1);
}

- (BOOL) isReadable
{
	return (BOOL) qt_QDir_isReadable((qt_QDir *)[self qt]);
}

- (BOOL) exists
{
	return (BOOL) qt_QDir_exists((qt_QDir *)[self qt]);
}

- (BOOL) isRoot
{
	return (BOOL) qt_QDir_isRoot((qt_QDir *)[self qt]);
}

- (BOOL) isRelative
{
	return (BOOL) qt_QDir_isRelative((qt_QDir *)[self qt]);
}

- convertToAbs
{
	qt_QDir_convertToAbs((qt_QDir *)[self qt]);
	return self;
}

- (BOOL) remove: (NSString *)fileName acceptAbsPath: (BOOL)acceptAbsPath
{
static qt_QString * _qstring_fileName = 0L;
	return (BOOL) qt_QDir_remove((qt_QDir *)[self qt], (qt_QString *) [fileName toQString: &_qstring_fileName], (int)acceptAbsPath);
}

- (BOOL) remove: (NSString *)fileName 
{
static qt_QString * _qstring_fileName = 0L;
	return (BOOL) qt_QDir_remove((qt_QDir *)[self qt], (qt_QString *) [fileName toQString: &_qstring_fileName], 1);
}

- (BOOL) rename: (NSString *)name newName: (NSString *)newName acceptAbsPaths: (BOOL)acceptAbsPaths
{
static qt_QString * _qstring_newName = 0L;
static qt_QString * _qstring_name = 0L;
	return (BOOL) qt_QDir_rename((qt_QDir *)[self qt], (qt_QString *) [name toQString: &_qstring_name], (qt_QString *) [newName toQString: &_qstring_newName], (int)acceptAbsPaths);
}

- (BOOL) rename: (NSString *)name newName: (NSString *)newName 
{
static qt_QString * _qstring_newName = 0L;
static qt_QString * _qstring_name = 0L;
	return (BOOL) qt_QDir_rename((qt_QDir *)[self qt], (qt_QString *) [name toQString: &_qstring_name], (qt_QString *) [newName toQString: &_qstring_newName], 1);
}

- (BOOL) exists: (NSString *)name acceptAbsPath: (BOOL)acceptAbsPath
{
static qt_QString * _qstring_name = 0L;
	return (BOOL) qt_QDir_exists1((qt_QDir *)[self qt], (qt_QString *) [name toQString: &_qstring_name], (int)acceptAbsPath);
}

- (BOOL) exists: (NSString *)name 
{
static qt_QString * _qstring_name = 0L;
	return (BOOL) qt_QDir_exists1((qt_QDir *)[self qt], (qt_QString *) [name toQString: &_qstring_name], 1);
}

+ (NSString *) convertSeparators: (NSString *)pathName
{
static qt_QString * _qstring = 0L;
static qt_QString * _qstring_pathName = 0L;
	_qstring = qt_QDir_convertSeparators((qt_QString *) [pathName toQString: &_qstring_pathName]);
	return [NSString fromQString: _qstring];
}

+ (NSArray *) drives
{
static qt_QFileInfoList * _qlist = 0L;
	_qlist = qt_QDir_drives();
	return (NSArray *) [NSMutableArray arrayWithQFileInfoList: _qlist];
}

+ (char) separator
{
	return (char) qt_QDir_separator();
}

+ (BOOL) setCurrent: (NSString *)path
{
static qt_QString * _qstring_path = 0L;
	return (BOOL) qt_QDir_setCurrent((qt_QString *) [path toQString: &_qstring_path]);
}

+ (QDir*) current
{
	return (QDir*) [QtSupport objectForQtKey: qt_QDir_current() withClass: [QDir class] allocatedInObjcWorld: YES];
}

+ (QDir*) home
{
	return (QDir*) [QtSupport objectForQtKey: qt_QDir_home() withClass: [QDir class] allocatedInObjcWorld: YES];
}

+ (QDir*) root
{
	return (QDir*) [QtSupport objectForQtKey: qt_QDir_root() withClass: [QDir class] allocatedInObjcWorld: YES];
}

+ (NSString *) currentDirPath
{
static qt_QString * _qstring = 0L;
	_qstring = qt_QDir_currentDirPath();
	return [NSString fromQString: _qstring];
}

+ (NSString *) homeDirPath
{
static qt_QString * _qstring = 0L;
	_qstring = qt_QDir_homeDirPath();
	return [NSString fromQString: _qstring];
}

+ (NSString *) rootDirPath
{
static qt_QString * _qstring = 0L;
	_qstring = qt_QDir_rootDirPath();
	return [NSString fromQString: _qstring];
}

+ (BOOL) matchWithFilters: (NSArray *)filters fileName: (NSString *)fileName
{
static qt_QString * _qstring_fileName = 0L;
static qt_QStringList * _qlist_filters = 0L;
	return (BOOL) qt_QDir_match((qt_QStringList*) [filters toQStringList: (void *)&_qlist_filters], (qt_QString *) [fileName toQString: &_qstring_fileName]);
}

+ (BOOL) matchWithFilter: (NSString *)filter fileName: (NSString *)fileName
{
static qt_QString * _qstring_fileName = 0L;
static qt_QString * _qstring_filter = 0L;
	return (BOOL) qt_QDir_match1((qt_QString *) [filter toQString: &_qstring_filter], (qt_QString *) [fileName toQString: &_qstring_fileName]);
}

+ (NSString *) cleanDirPath: (NSString *)dirPath
{
static qt_QString * _qstring = 0L;
static qt_QString * _qstring_dirPath = 0L;
	_qstring = qt_QDir_cleanDirPath((qt_QString *) [dirPath toQString: &_qstring_dirPath]);
	return [NSString fromQString: _qstring];
}

+ (BOOL) isRelativePath: (NSString *)path
{
static qt_QString * _qstring_path = 0L;
	return (BOOL) qt_QDir_isRelativePath((qt_QString *) [path toQString: &_qstring_path]);
}

+ (int) Dirs
{
	return (int) QDIR_Dirs;
}

+ (int) Files
{
	return (int) QDIR_Files;
}

+ (int) Drives
{
	return (int) QDIR_Drives;
}

+ (int) NoSymLinks
{
	return (int) QDIR_NoSymLinks;
}

+ (int) All
{
	return (int) QDIR_All;
}

+ (int) TypeMask
{
	return (int) QDIR_TypeMask;
}

+ (int) Readable
{
	return (int) QDIR_Readable;
}

+ (int) Writable
{
	return (int) QDIR_Writable;
}

+ (int) Executable
{
	return (int) QDIR_Executable;
}

+ (int) RWEMask
{
	return (int) QDIR_RWEMask;
}

+ (int) Modified
{
	return (int) QDIR_Modified;
}

+ (int) Hidden
{
	return (int) QDIR_Hidden;
}

+ (int) System
{
	return (int) QDIR_System;
}

+ (int) AccessMask
{
	return (int) QDIR_AccessMask;
}

+ (int) DefaultFilter
{
	return (int) QDIR_DefaultFilter;
}

+ (int) Name
{
	return (int) QDIR_Name;
}

+ (int) Time
{
	return (int) QDIR_Time;
}

+ (int) Size
{
	return (int) QDIR_Size;
}

+ (int) Unsorted
{
	return (int) QDIR_Unsorted;
}

+ (int) SortByMask
{
	return (int) QDIR_SortByMask;
}

+ (int) DirsFirst
{
	return (int) QDIR_DirsFirst;
}

+ (int) Reversed
{
	return (int) QDIR_Reversed;
}

+ (int) IgnoreCase
{
	return (int) QDIR_IgnoreCase;
}

+ (int) DefaultSort
{
	return (int) QDIR_DefaultSort;
}

@end
