• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

messageviewer

  • sources
  • kde-4.12
  • kdepim
  • messageviewer
  • viewer
pluginloaderbase.cpp
Go to the documentation of this file.
1 /* -*- c++ -*-
2  This file is part of libkdepim.
3 
4  Copyright (c) 2002,2004 Marc Mutz <mutz@kde.org>
5 
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.
10 
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.
15 
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.
20 */
21 
22 
23 
24 #include "pluginloaderbase.h"
25 
26 #include <KConfigGroup>
27 #include <KDebug>
28 #include <KGlobal>
29 #include <KLibrary>
30 #include <KLocale>
31 #include <KStandardDirs>
32 
33 #include <QFile>
34 #include <QStringList>
35 
36 PluginLoaderBase::PluginLoaderBase() : d(0) {}
37 PluginLoaderBase::~PluginLoaderBase() {}
38 
39 QStringList PluginLoaderBase::types() const {
40  QStringList result;
41  QMap< QString, PluginMetaData >::const_iterator end( mPluginMap.constEnd() );
42  for ( QMap< QString, PluginMetaData >::const_iterator it = mPluginMap.constBegin(); it != end ; ++it )
43  result.push_back( it.key() );
44  return result;
45 }
46 
47 const PluginMetaData * PluginLoaderBase::infoForName( const QString & type ) const {
48  return mPluginMap.contains( type ) ? &(const_cast<PluginLoaderBase*>(this)->mPluginMap[type]) : 0 ;
49 }
50 
51 
52 void PluginLoaderBase::doScan( const char * path ) {
53  mPluginMap.clear();
54 
55  const QStringList list =
56  KGlobal::dirs()->findAllResources( "data", QString::fromLatin1(path),
57  KStandardDirs::Recursive |
58  KStandardDirs::NoDuplicates );
59  for ( QStringList::const_iterator it = list.constBegin(); it != list.constEnd(); ++it ) {
60  KConfig config( *it, KConfig::SimpleConfig);
61  if ( config.hasGroup( "Misc" ) && config.hasGroup( "Plugin" ) ) {
62  KConfigGroup group( &config, "Plugin" );
63 
64  const QString type = group.readEntry( "Type" ).toLower();
65  if ( type.isEmpty() ) {
66  kWarning() << "missing or empty [Plugin]Type value in \"" << *it << "\" - skipping";
67  continue;
68  }
69 
70  const QString library = group.readEntry( "X-KDE-Library" );
71  if ( library.isEmpty() ) {
72  kWarning() << "missing or empty [Plugin]X-KDE-Library value in \"" << *it << "\" - skipping";
73  continue;
74  }
75 
76  KConfigGroup group2( &config, "Misc" );
77 
78  QString name = group2.readEntry( "Name" );
79  if ( name.isEmpty() ) {
80  kWarning() << "missing or empty [Misc]Name value in \"" << *it << "\" - inserting default name";
81  name = i18n("Unnamed plugin");
82  }
83 
84  QString comment = group2.readEntry( "Comment" );
85  if ( comment.isEmpty() ) {
86  kWarning() << "missing or empty [Misc]Comment value in \"" << *it << "\" - inserting default name";
87  comment = i18n("No description available");
88  }
89 
90  mPluginMap.insert( type, PluginMetaData( library, name, comment ) );
91  } else {
92  kWarning() << "Desktop file \"" << *it << "\" doesn't seem to describe a plugin " << "(misses Misc and/or Plugin group)";
93  }
94  }
95 }
96 
97 KLibrary::void_function_ptr PluginLoaderBase::mainFunc( const QString & type, const char * mf_name ) const {
98  if ( type.isEmpty() || !mPluginMap.contains( type ) )
99  return 0;
100 
101  const QString libName = mPluginMap[ type ].library;
102  if ( libName.isEmpty() )
103  return 0;
104 
105  const KLibrary * lib = openLibrary( libName );
106  if ( !lib )
107  return 0;
108 
109  PluginMetaData pmd = mPluginMap.value( type );
110  pmd.loaded = true;
111  mPluginMap[ type ] = pmd;
112 
113  const QString factory_name = libName + QLatin1Char('_') + QString::fromLatin1(mf_name);
114  KLibrary::void_function_ptr sym = const_cast<KLibrary*>( lib )->resolveFunction( factory_name.toLatin1() );
115  if ( !sym ) {
116  kWarning() << "No symbol named \"" << factory_name.toLatin1() << "\" (" << factory_name << ") was found in library \"" << libName << "\"";
117  return 0;
118  }
119 
120  return sym;
121 }
122 
123 const KLibrary * PluginLoaderBase::openLibrary( const QString & libName ) const {
124  KLibrary * library = new KLibrary( libName );
125  if ( library->fileName().isEmpty() || !library->load() ) {
126  kWarning() << "Could not load plugin library" << libName << "error:" << library->errorString() << library->fileName();
127  delete library;
128  return 0;
129  }
130 
131  return library;
132 }
PluginMetaData
Definition: pluginloaderbase.h:31
PluginMetaData::loaded
bool loaded
Definition: pluginloaderbase.h:42
pluginloaderbase.h
PluginLoaderBase::doScan
void doScan(const char *path)
Rescans the plugin directory to find any newly installed plugins.
Definition: pluginloaderbase.cpp:52
PluginLoaderBase::types
QStringList types() const
Returns a list of all available plugin objects (of kind T)
Definition: pluginloaderbase.cpp:39
PluginLoaderBase::PluginLoaderBase
PluginLoaderBase()
Definition: pluginloaderbase.cpp:36
type
const char * type
Definition: bodypartformatter.cpp:192
PluginLoaderBase::~PluginLoaderBase
virtual ~PluginLoaderBase()
Definition: pluginloaderbase.cpp:37
PluginLoaderBase
Definition: pluginloaderbase.h:45
PluginLoaderBase::infoForName
const PluginMetaData * infoForName(const QString &type) const
Returns the PluginMetaData structure for a given type.
Definition: pluginloaderbase.cpp:47
PluginLoaderBase::mainFunc
KLibrary::void_function_ptr mainFunc(const QString &type, const char *main_func) const
Returns a pointer to symbol main_func in the library that implements the plugin of type type...
Definition: pluginloaderbase.cpp:97
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:55:57 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

messageviewer

Skip menu "messageviewer"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal