22 #include <pluginloaderbase.h>
24 #include <ksimpleconfig.h>
25 #include <tdelocale.h>
26 #include <kstandarddirs.h>
27 #include <klibloader.h>
28 #include <tdeglobal.h>
32 #include <tqstringlist.h>
34 static kdbgstream warning() {
35 return kdWarning( 5300 ) <<
"PluginLoaderBase: ";
38 static kdbgstream debug(
bool cond )
40 static kndbgstream debug(
bool cond )
43 return kdDebug( cond, 5300 ) <<
"PluginLoaderBase: ";
48 PluginLoaderBase::PluginLoaderBase() : d(0) {}
49 PluginLoaderBase::~PluginLoaderBase() {}
52 TQStringList PluginLoaderBase::types()
const {
54 for ( TQMap< TQString, PluginMetaData >::const_iterator it = mPluginMap.begin();
55 it != mPluginMap.end() ; ++it )
56 result.push_back( it.key() );
60 const PluginMetaData * PluginLoaderBase::infoForName(
const TQString & type )
const {
61 return mPluginMap.contains( type ) ? &(mPluginMap[type]) : 0 ;
65 void PluginLoaderBase::doScan(
const char * path ) {
68 const TQStringList list =
69 TDEGlobal::dirs()->findAllResources(
"data", path,
true,
true );
70 for ( TQStringList::const_iterator it = list.begin() ;
71 it != list.end() ; ++it ) {
72 KSimpleConfig config( *it,
true );
73 if ( config.hasGroup(
"Misc" ) && config.hasGroup(
"Plugin" ) ) {
74 config.setGroup(
"Plugin" );
76 const TQString type = config.readEntry(
"Type" ).lower();
77 if ( type.isEmpty() ) {
78 warning() <<
"missing or empty [Plugin]Type value in \""
79 << *it <<
"\" - skipping" << endl;
83 const TQString library = config.readEntry(
"X-TDE-Library" );
84 if ( library.isEmpty() ) {
85 warning() <<
"missing or empty [Plugin]X-TDE-Library value in \""
86 << *it <<
"\" - skipping" << endl;
90 config.setGroup(
"Misc" );
92 TQString name = config.readEntry(
"Name" );
93 if ( name.isEmpty() ) {
94 warning() <<
"missing or empty [Misc]Name value in \""
95 << *it <<
"\" - inserting default name" << endl;
96 name = i18n(
"Unnamed plugin");
99 TQString comment = config.readEntry(
"Comment" );
100 if ( comment.isEmpty() ) {
101 warning() <<
"missing or empty [Misc]Comment value in \""
102 << *it <<
"\" - inserting default name" << endl;
103 comment = i18n(
"No description available");
106 mPluginMap.insert( type, PluginMetaData( library, name, comment ) );
108 warning() <<
"Desktop file \"" << *it
109 <<
"\" doesn't seem to describe a plugin "
110 <<
"(misses Misc and/or Plugin group)" << endl;
115 void * PluginLoaderBase::mainFunc(
const TQString & type,
116 const char * mf_name )
const {
117 if ( type.isEmpty() || !mPluginMap.contains( type ) )
120 const TQString libName = mPluginMap[ type ].library;
121 if ( libName.isEmpty() )
124 const KLibrary * lib = openLibrary( libName );
128 mPluginMap[ type ].loaded =
true;
130 const TQString factory_name = libName +
'_' + mf_name;
131 if ( !lib->hasSymbol( factory_name.latin1() ) ) {
132 warning() <<
"No symbol named \"" << factory_name.latin1() <<
"\" ("
133 << factory_name <<
") was found in library \"" << libName
138 return lib->symbol( factory_name.latin1() );
141 const KLibrary * PluginLoaderBase::openLibrary(
const TQString & libName )
const {
143 const TQString path = KLibLoader::findLibrary( TQFile::encodeName( libName ) );
145 if ( path.isEmpty() ) {
146 warning() <<
"No plugin library named \"" << libName
147 <<
"\" was found!" << endl;
151 const KLibrary * library = KLibLoader::self()->library( TQFile::encodeName( path ) );
153 debug( !library ) <<
"Could not load library '" << libName <<
"'" << endl;
TDEPIM classes for drag and drop of mails.