• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KDECore

klibloader.h

Go to the documentation of this file.
00001 /* This file is part of the KDE libraries
00002    Copyright (C) 1999 Torben Weis <weis@kde.org>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License version 2 as published by the Free Software Foundation.
00007 
00008    This library is distributed in the hope that it will be useful,
00009    but WITHOUT ANY WARRANTY; without even the implied warranty of
00010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011    Library General Public License for more details.
00012 
00013    You should have received a copy of the GNU Library General Public License
00014    along with this library; see the file COPYING.LIB.  If not, write to
00015    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00016    Boston, MA 02110-1301, USA.
00017 */
00018 #ifndef KLIBLOADER_H
00019 #define KLIBLOADER_H
00020 
00021 #include <kglobal.h>
00022 
00023 #include <QtCore/QObject>
00024 #include <QtCore/QStringList>
00025 #include <QtCore/QHash>
00026 #include <QtCore/QLibrary>
00027 #include <QtCore/QtPlugin>
00028 
00029 #include "kpluginfactory.h"
00030 #include "kpluginloader.h"
00031 #include "klibrary.h"
00032 
00033 # define K_EXPORT_COMPONENT_FACTORY( libname, factory ) \
00034     extern "C" { KDE_EXPORT KPluginFactory *init_##libname() { return new factory; } }
00035 
00053 class KDECORE_EXPORT KLibLoader : public QObject //krazy:exclude=dpointer (private class is kept as a global static)
00054 {
00055     friend class KLibrary;
00056     friend class KLibraryPrivate;
00057     friend class KLibLoaderPrivate;
00058 
00059     Q_OBJECT
00060 public:
00081     KPluginFactory* factory( const QString &libname, QLibrary::LoadHints loadHint = 0);
00082 
00103     KLibrary* library( const QString &libname, QLibrary::LoadHints loadHint = 0 );
00104 
00112     QString lastErrorMessage() const;
00113 
00128     void unloadLibrary( const QString &libname );
00129 
00138     static KDE_DEPRECATED KLibLoader* self();
00139 
00150     static QString findLibrary(const QString &libname, const KComponentData &cData = KGlobal::mainComponent());
00151 
00170     enum ComponentLoadingError { ErrNoLibrary = 1,
00171                                  ErrNoFactory,
00172                                  ErrNoComponent,
00173                                  ErrServiceProvidesNoLibrary,
00174                                  ErrNoServiceFound };
00175 
00181     static QString errorString( int componentLoadingError );
00182 
00183 
00196     template <typename T>
00197     static KDE_DEPRECATED T *createInstance(const QString &keyword, const QString &libname, QObject *parent = 0,
00198                               const QVariantList &args = QVariantList(),
00199                               int *error = 0 )
00200     {
00201         KLibrary *library = KLibLoader::self()->library( libname );
00202         if ( !library )
00203         {
00204             if ( error )
00205                 *error = ErrNoLibrary;
00206             return 0;
00207         }
00208         KPluginFactory *factory = library->factory();
00209         if ( !factory )
00210         {
00211             library->unload();
00212             if ( error )
00213                 *error = ErrNoFactory;
00214             return 0;
00215         }
00216         QObject *object = factory->template create<T>(keyword, parent, args);
00217         T *res = qobject_cast<T *>( object );
00218         if ( !res )
00219         {
00220             delete object;
00221             library->unload();
00222             if ( error )
00223                 *error = ErrNoComponent;
00224         }
00225         return res;
00226     }
00227 
00228     template <typename T>
00229     static KDE_DEPRECATED T *createInstance( const QString &libname, QObject *parent = 0,
00230                               const QVariantList &args = QVariantList(),
00231                               int *error = 0 )
00232     {
00233         return createInstance<T>(QString(), libname, parent, args, error);
00234     }
00235 
00240     template <typename T>
00241     static KDE_DEPRECATED T *createInstance( const QString &libname, QObject *parent,
00242                               const QStringList &args,
00243                               int *error = 0 )
00244     {
00245         KLibrary *library = KLibLoader::self()->library( libname );
00246         if ( !library )
00247         {
00248             if ( error )
00249                 *error = ErrNoLibrary;
00250             return 0;
00251         }
00252         KPluginFactory *factory = library->factory();
00253         if ( !factory )
00254         {
00255             library->unload();
00256             if ( error )
00257                 *error = ErrNoFactory;
00258             return 0;
00259         }
00260         QObject *object = factory->template create<T>(parent, args);
00261         T *res = qobject_cast<T *>( object );
00262         if ( !res )
00263         {
00264             delete object;
00265             library->unload();
00266             if ( error )
00267                 *error = ErrNoComponent;
00268         }
00269         return res;
00270     }
00271 
00272 private:
00273     ~KLibLoader();
00274 
00275     KLibLoader();
00276 };
00277 
00278 #endif

KDECore

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • KIO
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal