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

KParts

componentfactory.h

Go to the documentation of this file.
00001 /* This file is part of the KDE project
00002    Copyright (C) 2001 Simon Hausmann <hausmann@kde.org>
00003    Copyright (C) 2002-2006 David Faure <faure@kde.org>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013    GNU Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to the
00017    Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018    Boston, MA 02110-1301, USA.
00019 */
00020 #ifndef KPARTS_COMPONENTFACTORY_H
00021 #define KPARTS_COMPONENTFACTORY_H
00022 
00023 #include <kparts/factory.h>
00024 #include <kparts/part.h>
00025 #include <kservicetypetrader.h>
00026 #ifndef KDE_NO_DEPRECATED
00027 #include <klibloader.h>
00028 #endif
00029 #include <kmimetypetrader.h>
00030 
00031 namespace KParts
00032 {
00033     namespace ComponentFactory
00034     {
00054 #ifndef KDE_NO_DEPRECATED
00055         template <class T>
00056         KDE_DEPRECATED T *createPartInstanceFromFactory( KParts::Factory *factory,
00057                                           QWidget *parentWidget = 0,
00058                                           QObject *parent = 0,
00059                                           const QStringList &args = QStringList() )
00060         {
00061             KParts::Part *object = factory->createPart( parentWidget,
00062                                                         parent,
00063                                                         T::staticMetaObject.className(),
00064                                                         args );
00065 
00066             T *result = dynamic_cast<T *>( object );
00067             if ( !result )
00068                 delete object;
00069             return result;
00070         }
00071 #endif
00072 
00073         /*
00074          * @deprecated use KPluginFactory::create instead
00075          */
00076 #ifndef KDE_NO_DEPRECATED
00077         template <class T>
00078         KDE_DEPRECATED T *createPartInstanceFromLibrary( const char *libraryName,
00079                                           QWidget *parentWidget = 0,
00080                                           QObject *parent = 0,
00081                                           const QStringList &args = QStringList(),
00082                                           int *error = 0 )
00083         {
00084             KLibrary *library = KLibLoader::self()->library( QString( libraryName ) ); // compatibility hack
00085             if ( !library )
00086             {
00087                 if ( error )
00088                     *error = KLibLoader::ErrNoLibrary;
00089                 return 0;
00090             }
00091             KLibFactory *factory = library->factory();
00092             if ( !factory )
00093             {
00094                 library->unload();
00095                 if ( error )
00096                     *error = KLibLoader::ErrNoFactory;
00097                 return 0;
00098             }
00099             KParts::Factory *partFactory = dynamic_cast<KParts::Factory *>( factory );
00100             if ( !partFactory )
00101             {
00102                 library->unload();
00103                 if ( error )
00104                     *error = KLibLoader::ErrNoFactory;
00105                 return 0;
00106             }
00107             T *res = createPartInstanceFromFactory<T>( partFactory, parentWidget,
00108                                                        parent, args );
00109             if ( !res )
00110             {
00111                 library->unload();
00112                 if ( error )
00113                     *error = KLibLoader::ErrNoComponent;
00114             }
00115             return res;
00116         }
00117 #endif
00118 
00122 #ifndef KDE_NO_DEPRECATED
00123         template <class T>
00124         KDE_DEPRECATED T *createPartInstanceFromService( const KService::Ptr &service,
00125                                           QWidget *parentWidget = 0,
00126                                           QObject *parent = 0,
00127                                           const QStringList &args = QStringList(),
00128                                           int *error = 0 )
00129         {
00130             QString library = service->library();
00131             if ( library.isEmpty() )
00132             {
00133                 if ( error )
00134                     *error = KLibLoader::ErrServiceProvidesNoLibrary;
00135                 return 0;
00136             }
00137 
00138             return createPartInstanceFromLibrary<T>( library.toLocal8Bit().data(), parentWidget,
00139                                                      parent, args, error );
00140         }
00141 #endif
00142 
00143 #ifndef KDE_NO_DEPRECATED
00144         template <class T, class ServiceIterator>
00145         KDE_DEPRECATED T *createPartInstanceFromServices( ServiceIterator begin,
00146                                            ServiceIterator end,
00147                                            QWidget *parentWidget = 0,
00148                                            QObject *parent = 0,
00149                                            const QStringList &args = QStringList(),
00150                                            int *error = 0 )
00151          {
00152             for (; begin != end; ++begin )
00153             {
00154                 KService::Ptr service = *begin;
00155 
00156                 if ( error )
00157                     *error = 0;
00158 
00159                 T *component = createPartInstanceFromService<T>( service, parentWidget,
00160                                                                  parent, args, error );
00161                 if ( component )
00162                     return component;
00163             }
00164 
00165             if ( error )
00166                 *error = KLibLoader::ErrNoServiceFound;
00167 
00168             return 0;
00169 
00170         }
00171 #endif
00172 
00201 #ifndef KDE_NO_DEPRECATED
00202         template <class T>
00203         KDE_DEPRECATED T *createPartInstanceFromQuery( const QString &mimeType,
00204                                         const QString &constraint,
00205                                         QWidget *parentWidget = 0,
00206                                         QObject *parent = 0,
00207                                         const QStringList &args = QStringList(),
00208                                         int *error = 0 )
00209         {
00210             const KService::List offers = KMimeTypeTrader::self()->query( mimeType, QLatin1String("KParts/ReadOnlyPart"), constraint );
00211             if ( offers.isEmpty() )
00212             {
00213                 if ( error )
00214                     *error = KLibLoader::ErrNoServiceFound;
00215                 return 0;
00216             }
00217 
00218             return createPartInstanceFromServices<T>( offers.begin(), offers.end(),
00219                                                       parentWidget,
00220                                                       parent, args, error );
00221         }
00222 #endif // KDE_NO_DEPRECATED
00223     }
00224 }
00225 
00226 /*
00227  * vim: et sw=4
00228  */
00229 
00230 #endif

KParts

Skip menu "KParts"
  • 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
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.7.3
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