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

messageviewer

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

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