Fix akonadimodel.cpp:1: warning: unterminated character constant
[kdepim.git] / messageviewer / pluginloaderbase.cpp
blob39784260f3304c0eceeb52a1b32a1c9ab905ccd3
1 /* -*- c++ -*-
2 This file is part of libkdepim.
4 Copyright (c) 2002,2004 Marc Mutz <mutz@kde.org>
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
22 #include "pluginloaderbase.h"
24 #include <KConfigGroup>
25 #include <KDebug>
26 #include <KGlobal>
27 #include <KLibLoader>
28 #include <KLocale>
29 #include <KStandardDirs>
31 #include <QFile>
32 #include <QStringList>
34 PluginLoaderBase::PluginLoaderBase() : d(0) {}
35 PluginLoaderBase::~PluginLoaderBase() {}
37 QStringList PluginLoaderBase::types() const {
38 QStringList result;
39 for ( QMap< QString, PluginMetaData >::const_iterator it = mPluginMap.constBegin(); it != mPluginMap.constEnd() ; ++it )
40 result.push_back( it.key() );
41 return result;
44 const PluginMetaData * PluginLoaderBase::infoForName( const QString & type ) const {
45 return mPluginMap.contains( type ) ? &(const_cast<PluginLoaderBase*>(this)->mPluginMap[type]) : 0 ;
49 void PluginLoaderBase::doScan( const char * path ) {
50 mPluginMap.clear();
52 const QStringList list =
53 KGlobal::dirs()->findAllResources( "data", path,
54 KStandardDirs::Recursive |
55 KStandardDirs::NoDuplicates );
56 for ( QStringList::const_iterator it = list.constBegin(); it != list.constEnd(); ++it ) {
57 KConfig config( *it, KConfig::SimpleConfig);
58 if ( config.hasGroup( "Misc" ) && config.hasGroup( "Plugin" ) ) {
59 KConfigGroup group( &config, "Plugin" );
61 const QString type = group.readEntry( "Type" ).toLower();
62 if ( type.isEmpty() ) {
63 kWarning( 5300 ) << "missing or empty [Plugin]Type value in \"" << *it << "\" - skipping" << endl;
64 continue;
67 const QString library = group.readEntry( "X-KDE-Library" );
68 if ( library.isEmpty() ) {
69 kWarning( 5300 ) << "missing or empty [Plugin]X-KDE-Library value in \"" << *it << "\" - skipping" << endl;
70 continue;
73 KConfigGroup group2( &config, "Misc" );
75 QString name = group2.readEntry( "Name" );
76 if ( name.isEmpty() ) {
77 kWarning( 5300 ) << "missing or empty [Misc]Name value in \"" << *it << "\" - inserting default name" << endl;
78 name = i18n("Unnamed plugin");
81 QString comment = group2.readEntry( "Comment" );
82 if ( comment.isEmpty() ) {
83 kWarning( 5300 ) << "missing or empty [Misc]Comment value in \"" << *it << "\" - inserting default name" << endl;
84 comment = i18n("No description available");
87 mPluginMap.insert( type, PluginMetaData( library, name, comment ) );
88 } else {
89 kWarning( 5300 ) << "Desktop file \"" << *it << "\" doesn't seem to describe a plugin " << "(misses Misc and/or Plugin group)" << endl;
94 KLibrary::void_function_ptr PluginLoaderBase::mainFunc( const QString & type, const char * mf_name ) const {
95 if ( type.isEmpty() || !mPluginMap.contains( type ) )
96 return 0;
98 const QString libName = mPluginMap[ type ].library;
99 if ( libName.isEmpty() )
100 return 0;
102 const KLibrary * lib = openLibrary( libName );
103 if ( !lib )
104 return 0;
106 PluginMetaData pmd = mPluginMap.value( type );
107 pmd.loaded = true;
108 mPluginMap[ type ] = pmd;
110 const QString factory_name = libName + '_' + mf_name;
111 KLibrary::void_function_ptr sym = const_cast<KLibrary*>( lib )->resolveFunction( factory_name.toLatin1() );
112 if ( !sym ) {
113 kWarning( 5300 ) << "No symbol named \"" << factory_name.toLatin1() << "\" (" << factory_name << ") was found in library \"" << libName << "\"" << endl;
114 return 0;
117 return sym;
120 const KLibrary * PluginLoaderBase::openLibrary( const QString & libName ) const {
122 const QString path = KLibLoader::findLibrary( libName );
124 if ( path.isEmpty() ) {
125 kWarning( 5300 ) << "No plugin library named \"" << libName << "\" was found!" << endl;
126 return 0;
129 const KLibrary * library = KLibLoader::self()->library( path );
131 kDebug( !library, 5300 ) << "Could not load library '" << libName << "'" << endl;
133 return library;