summaryrefslogtreecommitdiffstats
path: root/kbfxlib/data/kbfxplasmapluginloader.cpp
blob: 0258ca7a20252f14e58a2bf777054fe75173a5ec (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*
 *   Copyright (C) 2006
 *   Siraj Razick <[email protected]>
 *   PhobosK <[email protected]>
 *   see Also AUTHORS
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU Library General Public License version 2 as
 *   published by the Free Software Foundation
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details
 *
 *   You should have received a copy of the GNU Library General Public
 *   License along with this program; if not, write to the
 *   Free Software Foundation, Inc.,
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#include <config.h>

#include "kbfxplasmapluginloader.h"
#include <tqdir.h>
#include <tqfileinfo.h>
#include <kstandarddirs.h>
#include <kdebug.h>

KbfxPlasmaPluginLoader::KbfxPlasmaPluginLoader()
{
	m_plugin = 0;
	init();

}


void
KbfxPlasmaPluginLoader::init()
{

	TQString libprefix = locate ( "lib","libkbfxdata.so" );
	libprefix.remove ( "libkbfxdata.so" );
//	TQString libprefix = KBFX_LIB_INSTALL_DIR ;
	kdDebug() << "KBFX plugins lib is: " << libprefix << endl;
	TQDir * _dir  = new TQDir ( libprefix+"/kbfx/plugins/" );
	TQStringList plugins;
	_dir->setFilter ( TQDir::Files );
	_dir->setNameFilter ( "*.so" );
	if ( !_dir->exists() )
	{
		kdDebug() << "Invalid Plugin Prefix: " << libprefix << "/kbfx/plugins/" << endl;
		delete _dir;
		return ;//TQStringList("No Plugins found: Error in default Paths.Contact Package Manager");
	}

	const TQFileInfoList *list = _dir->entryInfoList();
	TQFileInfoListIterator it ( *list );
	TQFileInfo *fi=0;
	int _index  =0;
	while ( ( fi = it.current() ) != 0 )
	{
		TQString * path   = new TQString ( libprefix+"/kbfx/plugins/"+fi->fileName() );
		TQLibrary * _l = new TQLibrary ( *path );

		typedef TQString ( *getName ) ();
		getName nameFunc;
		nameFunc = ( getName ) _l->resolve ( "name" );
		if ( nameFunc )
		{
			pluginMap() [nameFunc() ] = new  KbfxPlugin ( nameFunc(),*path,_index++ );
		}
		++it;
		_l->unload();
		delete _l;
		delete path;
	}

	delete  _dir;
}


KbfxPlasmaPluginLoader::~KbfxPlasmaPluginLoader()
{
	//  if(m_plugin!=0)
//	delete m_plugin;

	// PluginMap::Iterator it;
	// for ( it = pluginMap().begin(); it != pluginMap().end(); ++it ) {
	//   delete  it.data();
	//   pluginMap().remove(it);
	//     }


}

KbfxDataStack *
KbfxPlasmaPluginLoader::getView ( TQString name )
{
	PluginMap::Iterator it;
	for ( it = pluginMap().begin(); it != pluginMap().end(); ++it )
	{
		pluginMap().remove ( it );
	}
	init();
	KbfxDataStack * stack = pluginMap() [name] ? pluginMap() [name]->data() : NULL;
	
        if (stack == 0 ) {
            return new KbfxDataStack();
        }

        return stack;
}

KbfxDataGroup *
KbfxPlasmaPluginLoader::search ( TQString pname,TQString keyword )
{
	if ( pname == NULL )
		return NULL;

	KbfxDataGroup * group = pluginMap() [pname]->search ( keyword );
	if ( group == NULL )
	{
		kdDebug() << "KbfxPlasmaaPluginLoader:109:Null pointer" << endl;
		return NULL;
	}

	return group;

}


KbfxPlasmaPluginLoader::PluginMap&
KbfxPlasmaPluginLoader::pluginMap()
{
	static PluginMap  * map = 0;
	if ( !map )
		map = new PluginMap();
	return *map;
}




TQStringList
KbfxPlasmaPluginLoader::scanPlugins()
{

	init();
	TQStringList plugins;
	PluginMap::Iterator it;

	for ( it = pluginMap().begin(); it != pluginMap().end();++it )
	{
		if ( it.data()->status() == false )
			plugins.append ( it.data()->name() );
	}
	return plugins;
}

#include "kbfxplasmapluginloader.moc"