summaryrefslogtreecommitdiffstats
path: root/kolf/pluginloader.cpp
blob: 9f320856b246ba74bcadfc1de4ba12d09f8f573a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <tqstring.h>
#include <tqvaluelist.h>
#include <tqstringlist.h>
#include <tqfile.h>
#include <tqobject.h>

#include <kdebug.h>
#include <kglobal.h>
#include <kstandarddirs.h>
#include <ksimpleconfig.h>
#include <klibloader.h>

#include "pluginloader.h"

ObjectList *PluginLoader::loadAll()
{
	ObjectList *ret = new ObjectList;

	TQStringList libs;
	TQStringList files = TDEGlobal::dirs()->findAllResources("appdata", "*.plugin", false, true);

	for (TQStringList::Iterator it = files.begin(); it != files.end(); ++it)
	{
		KSimpleConfig cfg(*it);
		TQString filename(cfg.readEntry("Filename", ""));

		libs.append(filename);
	}

	for (TQStringList::Iterator it = libs.begin(); it != libs.end(); ++it)
	{
		Object *newObject = load(*it);
		if (newObject)
			ret->append(newObject);
	}

	return ret;
}

Object *PluginLoader::load(const TQString &filename)
{
	KLibFactory *factory = KLibLoader::self()->factory(filename.latin1());

	if (!factory)
	{
		kdWarning() << "no factory for " << filename << "!" << endl;
		return 0;
	}

	TQObject *newObject = factory->create(0, "objectInstance", "Object");
	
	if (!newObject)
	{
		kdWarning() << "no newObject for " << filename << "!" << endl;
		return 0;
	}

	Object *ret = dynamic_cast<Object *>(newObject);

	if (!ret)
		kdWarning() << "no ret for " << filename << "!" << endl;

	return ret;
}