• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • 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 #include <klibloader.h>
00027 #include <kmimetypetrader.h>
00028 
00029 namespace KParts
00030 {
00031     namespace ComponentFactory
00032     {
00052         template <class T>
00053         KDE_DEPRECATED T *createPartInstanceFromFactory( KParts::Factory *factory,
00054                                           QWidget *parentWidget = 0,
00055                                           QObject *parent = 0,
00056                                           const QStringList &args = QStringList() )
00057         {
00058             KParts::Part *object = factory->createPart( parentWidget,
00059                                                         parent,
00060                                                         T::staticMetaObject.className(),
00061                                                         args );
00062 
00063             T *result = dynamic_cast<T *>( object );
00064             if ( !result )
00065                 delete object;
00066             return result;
00067         }
00068         /*
00069          * @deprecated use KPluginFactory::create instead
00070          */
00071         template <class T>
00072         KDE_DEPRECATED T *createPartInstanceFromLibrary( const char *libraryName,
00073                                           QWidget *parentWidget = 0,
00074                                           QObject *parent = 0,
00075                                           const QStringList &args = QStringList(),
00076                                           int *error = 0 )
00077         {
00078             KLibrary *library = KLibLoader::self()->library( libraryName );
00079             if ( !library )
00080             {
00081                 if ( error )
00082                     *error = KLibLoader::ErrNoLibrary;
00083                 return 0;
00084             }
00085             KLibFactory *factory = library->factory();
00086             if ( !factory )
00087             {
00088                 library->unload();
00089                 if ( error )
00090                     *error = KLibLoader::ErrNoFactory;
00091                 return 0;
00092             }
00093             KParts::Factory *partFactory = dynamic_cast<KParts::Factory *>( factory );
00094             if ( !partFactory )
00095             {
00096                 library->unload();
00097                 if ( error )
00098                     *error = KLibLoader::ErrNoFactory;
00099                 return 0;
00100             }
00101             T *res = createPartInstanceFromFactory<T>( partFactory, parentWidget,
00102                                                        parent, args );
00103             if ( !res )
00104             {
00105                 library->unload();
00106                 if ( error )
00107                     *error = KLibLoader::ErrNoComponent;
00108             }
00109             return res;
00110         }
00111 
00115         template <class T>
00116         KDE_DEPRECATED T *createPartInstanceFromService( const KService::Ptr &service,
00117                                           QWidget *parentWidget = 0,
00118                                           QObject *parent = 0,
00119                                           const QStringList &args = QStringList(),
00120                                           int *error = 0 )
00121         {
00122             QString library = service->library();
00123             if ( library.isEmpty() )
00124             {
00125                 if ( error )
00126                     *error = KLibLoader::ErrServiceProvidesNoLibrary;
00127                 return 0;
00128             }
00129 
00130             return createPartInstanceFromLibrary<T>( library.toLocal8Bit().data(), parentWidget,
00131                                                      parent, args, error );
00132         }
00133 
00134         template <class T, class ServiceIterator>
00135         KDE_DEPRECATED T *createPartInstanceFromServices( ServiceIterator begin,
00136                                            ServiceIterator end,
00137                                            QWidget *parentWidget = 0,
00138                                            QObject *parent = 0,
00139                                            const QStringList &args = QStringList(),
00140                                            int *error = 0 )
00141          {
00142             for (; begin != end; ++begin )
00143             {
00144                 KService::Ptr service = *begin;
00145 
00146                 if ( error )
00147                     *error = 0;
00148 
00149                 T *component = createPartInstanceFromService<T>( service, parentWidget,
00150                                                                  parent, args, error );
00151                 if ( component )
00152                     return component;
00153             }
00154 
00155             if ( error )
00156                 *error = KLibLoader::ErrNoServiceFound;
00157 
00158             return 0;
00159 
00160         }
00161 
00190         template <class T>
00191         T *createPartInstanceFromQuery( const QString &mimeType,
00192                                         const QString &constraint,
00193                                         QWidget *parentWidget = 0,
00194                                         QObject *parent = 0,
00195                                         const QStringList &args = QStringList(),
00196                                         int *error = 0 )
00197         {
00198             const KService::List offers = KMimeTypeTrader::self()->query( mimeType, QLatin1String("KParts/ReadOnlyPart"), constraint );
00199             if ( offers.isEmpty() )
00200             {
00201                 if ( error )
00202                     *error = KLibLoader::ErrNoServiceFound;
00203                 return 0;
00204             }
00205 
00206             return createPartInstanceFromServices<T>( offers.begin(), offers.end(),
00207                                                       parentWidget,
00208                                                       parent, args, error );
00209         }
00210 
00211     }
00212 }
00213 
00214 /*
00215  * vim: et sw=4
00216  */
00217 
00218 #endif

KParts

Skip menu "KParts"
  • Main Page
  • 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