/***************************************************************************
                            KFileItem.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_KFileItem.h>
#include <kdeobjc/KDESupport.h>
#include <kdeobjc/KFileItem.h>
#include <kdeobjc/KFileMetaInfo.h>

#include <kdeobjc/KURL.h>


@implementation  KFileItem

- (void *) qt
{
	return _qt;
}

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

- (BOOL) allocatedInObjcWorld
{
	return _allocatedInObjcWorld;
}

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


//- initWithUDSEntry: (UDSEntry*)_entry _url: (KURL*)_url _determineMimeTypeOnDemand: (BOOL)_determineMimeTypeOnDemand _urlIsDirectory: (BOOL)_urlIsDirectory
//{
//	if ([self qt] == 0L) {
//		[self setQt: kde_new_KFileItem((kde_UDSEntry*) [_entry qt], (kde_KURL*) [_url qt], (int)_determineMimeTypeOnDemand, (int)_urlIsDirectory)];
//		[self setAllocatedInObjcWorld: YES];
//		[QtSupport setObject: self forQtKey: [self qt]];
//	}
//	[super init];
//	return self;
//}

//- initWithUDSEntry: (UDSEntry*)_entry _url: (KURL*)_url
//{
//	if ([self qt] == 0L) {
//		[self setQt: kde_new_KFileItem((kde_UDSEntry*) [_entry qt], (kde_KURL*) [_url qt], 0, 0)];
//		[self setAllocatedInObjcWorld: YES];
//		[QtSupport setObject: self forQtKey: [self qt]];
//	}
//	[super init];
//	return self;
//}

- initWithLong: (long)_mode _permissions: (long)_permissions _url: (KURL*)_url _determineMimeTypeOnDemand: (BOOL)_determineMimeTypeOnDemand
{
	if ([self qt] == 0L) {
		[self setQt: kde_new_KFileItem1((long)_mode, (long)_permissions, (kde_KURL*) [_url qt], (int)_determineMimeTypeOnDemand)];
		[self setAllocatedInObjcWorld: YES];
		[QtSupport setObject: self forQtKey: [self qt]];
	}
	[super init];
	return self;
}

- initWithLong: (long)_mode _permissions: (long)_permissions _url: (KURL*)_url 
{
	if ([self qt] == 0L) {
		[self setQt: kde_new_KFileItem1((long)_mode, (long)_permissions, (kde_KURL*) [_url qt], 0)];
		[self setAllocatedInObjcWorld: YES];
		[QtSupport setObject: self forQtKey: [self qt]];
	}
	[super init];
	return self;
}

- initWithURL: (KURL*)url mimeType: (NSString *)mimeType mode: (long)mode
{
static qt_QString * _qstring_mimeType = 0L;
	if ([self qt] == 0L) {
		[self setQt: kde_new_KFileItem2((kde_KURL*) [url qt], (qt_QString *) [mimeType toQString: &_qstring_mimeType], (long)mode)];
		[self setAllocatedInObjcWorld: YES];
		[QtSupport setObject: self forQtKey: [self qt]];
	}
	[super init];
	return self;
}

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

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

- refresh
{
	kde_KFileItem_refresh((kde_KFileItem *)[self qt]);
	return self;
}

- refreshMimeType
{
	kde_KFileItem_refreshMimeType((kde_KFileItem *)[self qt]);
	return self;
}

- (KURL*) url
{
	return (KURL*) [QtSupport objectForQtKey: kde_KFileItem_url((kde_KFileItem *)[self qt]) withClass: [KURL class] allocatedInObjcWorld: YES];
}

- setURL: (KURL*)url
{
	kde_KFileItem_setURL((kde_KFileItem *)[self qt], (kde_KURL*) [url qt]);
	return self;
}

- (long) permissions
{
	return (long) kde_KFileItem_permissions((kde_KFileItem *)[self qt]);
}

- (NSString *) permissionsString
{
static qt_QString * _qstring = 0L;
	_qstring = kde_KFileItem_permissionsString((kde_KFileItem *)[self qt]);
	return [NSString fromQString: _qstring];
}

- (long) mode
{
	return (long) kde_KFileItem_mode((kde_KFileItem *)[self qt]);
}

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

- (NSString *) group
{
static qt_QString * _qstring = 0L;
	_qstring = kde_KFileItem_group((kde_KFileItem *)[self qt]);
	return [NSString fromQString: _qstring];
}

- (BOOL) isLink
{
	return (BOOL) kde_KFileItem_isLink((kde_KFileItem *)[self qt]);
}

- (BOOL) isDir
{
	return (BOOL) kde_KFileItem_isDir((kde_KFileItem *)[self qt]);
}

- (BOOL) isFile
{
	return (BOOL) kde_KFileItem_isFile((kde_KFileItem *)[self qt]);
}

- (BOOL) isReadable
{
	return (BOOL) kde_KFileItem_isReadable((kde_KFileItem *)[self qt]);
}

- (NSString *) linkDest
{
static qt_QString * _qstring = 0L;
	_qstring = kde_KFileItem_linkDest((kde_KFileItem *)[self qt]);
	return [NSString fromQString: _qstring];
}

//- (unsigned long) size
//{
//	return (unsigned long) kde_KFileItem_size((kde_KFileItem *)[self qt]);
//}

- (long) time: (unsigned int)which
{
	return (long) kde_KFileItem_time((kde_KFileItem *)[self qt], (unsigned int)which);
}

- (NSString *) timeString: (unsigned int)which
{
static qt_QString * _qstring = 0L;
	_qstring = kde_KFileItem_timeString((kde_KFileItem *)[self qt], (unsigned int)which);
	return [NSString fromQString: _qstring];
}

- (BOOL) isLocalFile
{
	return (BOOL) kde_KFileItem_isLocalFile((kde_KFileItem *)[self qt]);
}

- (NSString *) text
{
static qt_QString * _qstring = 0L;
	_qstring = kde_KFileItem_text((kde_KFileItem *)[self qt]);
	return [NSString fromQString: _qstring];
}

- (NSString *) name: (BOOL)lowerCase
{
static qt_QString * _qstring = 0L;
	_qstring = kde_KFileItem_name((kde_KFileItem *)[self qt], (int)lowerCase);
	return [NSString fromQString: _qstring];
}

- (NSString *) mimetype
{
static qt_QString * _qstring = 0L;
	_qstring = kde_KFileItem_mimetype((kde_KFileItem *)[self qt]);
	return [NSString fromQString: _qstring];
}

//- (KMimeType_Ptr) determineMimeType
//{
//	return (KMimeType_Ptr) kde_KFileItem_determineMimeType((kde_KFileItem *)[self qt]);
//}

//- (KMimeType_Ptr) mimeTypePtr
//{
//	return (KMimeType_Ptr) kde_KFileItem_mimeTypePtr((kde_KFileItem *)[self qt]);
//}

- (BOOL) isMimeTypeKnown
{
	return (BOOL) kde_KFileItem_isMimeTypeKnown((kde_KFileItem *)[self qt]);
}

- (NSString *) mimeComment
{
static qt_QString * _qstring = 0L;
	_qstring = kde_KFileItem_mimeComment((kde_KFileItem *)[self qt]);
	return [NSString fromQString: _qstring];
}

- (NSString *) iconName
{
static qt_QString * _qstring = 0L;
	_qstring = kde_KFileItem_iconName((kde_KFileItem *)[self qt]);
	return [NSString fromQString: _qstring];
}

- (QPixmap*) pixmap: (int)_size _state: (int)_state
{
	return (QPixmap*) [QtSupport objectForQtKey: kde_KFileItem_pixmap((kde_KFileItem *)[self qt], (int)_size, (int)_state) withClass: [QPixmap class] allocatedInObjcWorld: YES];
}

- (QPixmap*) pixmap: (int)_size 
{
	return (QPixmap*) [QtSupport objectForQtKey: kde_KFileItem_pixmap((kde_KFileItem *)[self qt], (int)_size, 0) withClass: [QPixmap class] allocatedInObjcWorld: YES];
}

- (NSString *) getStatusBarInfo
{
static qt_QString * _qstring = 0L;
	_qstring = kde_KFileItem_getStatusBarInfo((kde_KFileItem *)[self qt]);
	return [NSString fromQString: _qstring];
}

- (NSString *) getToolTipText: (int)maxcount
{
static qt_QString * _qstring = 0L;
	_qstring = kde_KFileItem_getToolTipText((kde_KFileItem *)[self qt], (int)maxcount);
	return [NSString fromQString: _qstring];
}

- (BOOL) acceptsDrops
{
	return (BOOL) kde_KFileItem_acceptsDrops((kde_KFileItem *)[self qt]);
}

- run
{
	kde_KFileItem_run((kde_KFileItem *)[self qt]);
	return self;
}

//- (UDSEntry*) entry
//{
//	return (UDSEntry*) kde_KFileItem_entry((kde_KFileItem *)[self qt]);
//}

- (BOOL) isMarked
{
	return (BOOL) kde_KFileItem_isMarked((kde_KFileItem *)[self qt]);
}

- mark
{
	kde_KFileItem_mark((kde_KFileItem *)[self qt]);
	return self;
}

- unmark
{
	kde_KFileItem_unmark((kde_KFileItem *)[self qt]);
	return self;
}

- (BOOL) cmp: (KFileItem*)item
{
	return (BOOL) kde_KFileItem_cmp((kde_KFileItem *)[self qt], (kde_KFileItem*) [item qt]);
}

- setExtraData: (void*)key value: (void*)value
{
	kde_KFileItem_setExtraData((kde_KFileItem *)[self qt], (void*)key, (void*)value);
	return self;
}

- (void*) extraData: (void*)key
{
	return (void*) kde_KFileItem_extraData((kde_KFileItem *)[self qt], (void*)key);
}

//- (void*) extraData: (void*)key
//{
//	return (void*) kde_KFileItem_extraData1((kde_KFileItem *)[self qt], (void*)key);
//}

- removeExtraData: (void*)key
{
	kde_KFileItem_removeExtraData((kde_KFileItem *)[self qt], (void*)key);
	return self;
}

//- setMetaInfo: (KFileMetaInfo*)info
//{
//	kde_KFileItem_setMetaInfo((kde_KFileItem *)[self qt], (KFileMetaInfo) info);
//	return self;
//}

//- (KFileMetaInfo&) metaInfo
//{
//	return (KFileMetaInfo&) kde_KFileItem_metaInfo((kde_KFileItem *)[self qt]);
//}

- assign: (KFileItem*)item
{
	kde_KFileItem_assign((kde_KFileItem *)[self qt], (kde_KFileItem*) [item qt]);
	return self;
}

- init: (BOOL)_determineMimeTypeOnDemand
{
	kde_KFileItem_init((kde_KFileItem *)[self qt], (int)_determineMimeTypeOnDemand);
	return self;
}

- (NSString *) parsePermissions: (long)perm
{
static qt_QString * _qstring = 0L;
	_qstring = kde_KFileItem_parsePermissions((kde_KFileItem *)[self qt], (long)perm);
	return [NSString fromQString: _qstring];
}

+ (int) Unknown
{
	return (int) KFILEITEM_Unknown;
}

@end
