/***************************************************************************
                            KLibLoader.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_KLibLoader.h>
#include <kdeobjc/KDESupport.h>
#include <kdeobjc/KLibLoader.h>
#include <kdeobjc/KInstance.h>


@implementation  KLibLoader


- (void) dealloc
{
	if ([self qt] != 0L) {
		if ([self allocatedInObjcWorld] && [self parent] == nil) {
			kde_del_KLibLoader((kde_KLibLoader *)[self qt]);
		}
		[QtSupport removeQtKey: [self qt]];
		[self setQt: 0L];
	}
	[super dealloc];
}

- (KLibFactory*) factory: (NSString *)libname
{
	return (KLibFactory*) [QtSupport objectForQtKey: kde_KLibLoader_factory((kde_KLibLoader *)[self qt], (char*) [libname cString]) withClass: [KLibFactory class] allocatedInObjcWorld: YES];
}

- (KLibrary*) library: (NSString *)libname
{
	return (KLibrary*) [QtSupport objectForQtKey: kde_KLibLoader_library((kde_KLibLoader *)[self qt], (char*) [libname cString]) withClass: [KLibrary class] allocatedInObjcWorld: YES];
}

- (KLibrary*) globalLibrary: (NSString *)name
{
	return (KLibrary*) [QtSupport objectForQtKey: kde_KLibLoader_globalLibrary((kde_KLibLoader *)[self qt], (char*) [name cString]) withClass: [KLibrary class] allocatedInObjcWorld: YES];
}

- (NSString *) lastErrorMessage
{
static qt_QString * _qstring = 0L;
	_qstring = kde_KLibLoader_lastErrorMessage((kde_KLibLoader *)[self qt]);
	return [NSString fromQString: _qstring];
}

- unloadLibrary: (NSString *)libname
{
	kde_KLibLoader_unloadLibrary((kde_KLibLoader *)[self qt], (char*) [libname cString]);
	return self;
}

+ (KLibLoader*) self
{
	return (KLibLoader*) [QtSupport objectForQtKey: kde_KLibLoader_self() withClass: [KLibLoader class] allocatedInObjcWorld: YES];
}

+ cleanUp
{
	kde_KLibLoader_cleanUp();
	return self;
}

+ (NSString *) findLibrary: (NSString *)name instance: (KInstance*)instance
{
static qt_QString * _qstring = 0L;
	_qstring = kde_KLibLoader_findLibrary((char*) [name cString], (kde_KInstance*) [instance qt]);
	return [NSString fromQString: _qstring];
}

- initWithObject: (QObject *)parent name: (NSString *)name
{
	if ([self qt] == 0L) {
		[self setQt: kde_new_KLibLoader((qt_QObject *) [parent qt], (char*) [name cString])];
		[self setAllocatedInObjcWorld: YES];
		[QtSupport setObject: self forQtKey: [self qt]];
	}
	[super init];
	return self;
}

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

@end
