You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
160 lines
4.6 KiB
160 lines
4.6 KiB
15 years ago
|
/* -*- c++ -*-
|
||
13 years ago
|
This file is part of libtdepim.
|
||
15 years ago
|
|
||
|
Copyright (c) 2002,2004 Marc Mutz <mutz@kde.org>
|
||
|
|
||
|
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.
|
||
|
|
||
|
This library 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
|
||
|
Library General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU Library General Public License
|
||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
|
#include <pluginloaderbase.h>
|
||
|
|
||
|
#include <ksimpleconfig.h>
|
||
|
#include <klocale.h>
|
||
|
#include <kstandarddirs.h>
|
||
|
#include <klibloader.h>
|
||
|
#include <kglobal.h>
|
||
|
#include <kdebug.h>
|
||
|
|
||
15 years ago
|
#include <tqfile.h>
|
||
|
#include <tqstringlist.h>
|
||
15 years ago
|
|
||
|
static kdbgstream warning() {
|
||
|
return kdWarning( 5300 ) << "PluginLoaderBase: ";
|
||
|
}
|
||
|
#ifndef NDEBUG
|
||
|
static kdbgstream debug( bool cond )
|
||
|
#else
|
||
|
static kndbgstream debug( bool cond )
|
||
|
#endif
|
||
|
{
|
||
|
return kdDebug( cond, 5300 ) << "PluginLoaderBase: ";
|
||
|
}
|
||
|
|
||
|
namespace KPIM {
|
||
|
|
||
|
PluginLoaderBase::PluginLoaderBase() : d(0) {}
|
||
|
PluginLoaderBase::~PluginLoaderBase() {}
|
||
|
|
||
|
|
||
15 years ago
|
TQStringList PluginLoaderBase::types() const {
|
||
|
TQStringList result;
|
||
|
for ( TQMap< TQString, PluginMetaData >::const_iterator it = mPluginMap.begin();
|
||
15 years ago
|
it != mPluginMap.end() ; ++it )
|
||
|
result.push_back( it.key() );
|
||
|
return result;
|
||
|
}
|
||
|
|
||
15 years ago
|
const PluginMetaData * PluginLoaderBase::infoForName( const TQString & type ) const {
|
||
13 years ago
|
return mPluginMap.contains( type ) ? &(mPluginMap[type]) : 0 ;
|
||
15 years ago
|
}
|
||
|
|
||
|
|
||
|
void PluginLoaderBase::doScan( const char * path ) {
|
||
|
mPluginMap.clear();
|
||
|
|
||
15 years ago
|
const TQStringList list =
|
||
15 years ago
|
KGlobal::dirs()->findAllResources( "data", path, true, true );
|
||
15 years ago
|
for ( TQStringList::const_iterator it = list.begin() ;
|
||
15 years ago
|
it != list.end() ; ++it ) {
|
||
|
KSimpleConfig config( *it, true );
|
||
|
if ( config.hasGroup( "Misc" ) && config.hasGroup( "Plugin" ) ) {
|
||
|
config.setGroup( "Plugin" );
|
||
|
|
||
15 years ago
|
const TQString type = config.readEntry( "Type" ).lower();
|
||
15 years ago
|
if ( type.isEmpty() ) {
|
||
|
warning() << "missing or empty [Plugin]Type value in \""
|
||
|
<< *it << "\" - skipping" << endl;
|
||
|
continue;
|
||
|
}
|
||
|
|
||
15 years ago
|
const TQString library = config.readEntry( "X-KDE-Library" );
|
||
15 years ago
|
if ( library.isEmpty() ) {
|
||
|
warning() << "missing or empty [Plugin]X-KDE-Library value in \""
|
||
|
<< *it << "\" - skipping" << endl;
|
||
|
continue;
|
||
|
}
|
||
|
|
||
|
config.setGroup( "Misc" );
|
||
|
|
||
15 years ago
|
TQString name = config.readEntry( "Name" );
|
||
15 years ago
|
if ( name.isEmpty() ) {
|
||
|
warning() << "missing or empty [Misc]Name value in \""
|
||
|
<< *it << "\" - inserting default name" << endl;
|
||
|
name = i18n("Unnamed plugin");
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString comment = config.readEntry( "Comment" );
|
||
15 years ago
|
if ( comment.isEmpty() ) {
|
||
|
warning() << "missing or empty [Misc]Comment value in \""
|
||
|
<< *it << "\" - inserting default name" << endl;
|
||
|
comment = i18n("No description available");
|
||
|
}
|
||
|
|
||
|
mPluginMap.insert( type, PluginMetaData( library, name, comment ) );
|
||
|
} else {
|
||
|
warning() << "Desktop file \"" << *it
|
||
|
<< "\" doesn't seem to describe a plugin "
|
||
|
<< "(misses Misc and/or Plugin group)" << endl;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
void * PluginLoaderBase::mainFunc( const TQString & type,
|
||
15 years ago
|
const char * mf_name ) const {
|
||
13 years ago
|
if ( type.isEmpty() || !mPluginMap.contains( type ) )
|
||
15 years ago
|
return 0;
|
||
|
|
||
15 years ago
|
const TQString libName = mPluginMap[ type ].library;
|
||
15 years ago
|
if ( libName.isEmpty() )
|
||
|
return 0;
|
||
|
|
||
|
const KLibrary * lib = openLibrary( libName );
|
||
|
if ( !lib )
|
||
|
return 0;
|
||
|
|
||
|
mPluginMap[ type ].loaded = true;
|
||
|
|
||
15 years ago
|
const TQString factory_name = libName + '_' + mf_name;
|
||
15 years ago
|
if ( !lib->hasSymbol( factory_name.latin1() ) ) {
|
||
|
warning() << "No symbol named \"" << factory_name.latin1() << "\" ("
|
||
|
<< factory_name << ") was found in library \"" << libName
|
||
|
<< "\"" << endl;
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
return lib->symbol( factory_name.latin1() );
|
||
|
}
|
||
|
|
||
15 years ago
|
const KLibrary * PluginLoaderBase::openLibrary( const TQString & libName ) const {
|
||
15 years ago
|
|
||
15 years ago
|
const TQString path = KLibLoader::findLibrary( TQFile::encodeName( libName ) );
|
||
15 years ago
|
|
||
|
if ( path.isEmpty() ) {
|
||
|
warning() << "No plugin library named \"" << libName
|
||
|
<< "\" was found!" << endl;
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
15 years ago
|
const KLibrary * library = KLibLoader::self()->library( TQFile::encodeName( path ) );
|
||
15 years ago
|
|
||
|
debug( !library ) << "Could not load library '" << libName << "'" << endl;
|
||
|
|
||
|
return library;
|
||
|
}
|
||
|
|
||
|
|
||
|
} // namespace KMime
|