• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.9.5 API Reference
  • 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 #include <QtCore/QFile>
00032 
00033 namespace KParts
00034 {
00035     namespace ComponentFactory
00036     {
00056 #ifndef KDE_NO_DEPRECATED
00057         template <class T>
00058         KDE_DEPRECATED T *createPartInstanceFromFactory( KParts::Factory *factory,
00059                                           QWidget *parentWidget = 0,
00060                                           QObject *parent = 0,
00061                                           const QStringList &args = QStringList() )
00062         {
00063             KParts::Part *object = factory->createPart( parentWidget,
00064                                                         parent,
00065                                                         T::staticMetaObject.className(),
00066                                                         args );
00067 
00068             T *result = dynamic_cast<T *>( object );
00069             if ( !result )
00070                 delete object;
00071             return result;
00072         }
00073 #endif
00074 
00075         /*
00076          * @deprecated use KPluginFactory::create instead
00077          */
00078 #ifndef KDE_NO_DEPRECATED
00079         template <class T>
00080         KDE_DEPRECATED T *createPartInstanceFromLibrary( const char *libraryName,
00081                                           QWidget *parentWidget = 0,
00082                                           QObject *parent = 0,
00083                                           const QStringList &args = QStringList(),
00084                                           int *error = 0 )
00085         {
00086             KLibrary *library = KLibLoader::self()->library( QFile::decodeName( libraryName ) ); // compatibility hack
00087             if ( !library )
00088             {
00089                 if ( error )
00090                     *error = KLibLoader::ErrNoLibrary;
00091                 return 0;
00092             }
00093             KLibFactory *factory = library->factory();
00094             if ( !factory )
00095             {
00096                 library->unload();
00097                 if ( error )
00098                     *error = KLibLoader::ErrNoFactory;
00099                 return 0;
00100             }
00101             KParts::Factory *partFactory = dynamic_cast<KParts::Factory *>( factory );
00102             if ( !partFactory )
00103             {
00104                 library->unload();
00105                 if ( error )
00106                     *error = KLibLoader::ErrNoFactory;
00107                 return 0;
00108             }
00109             T *res = createPartInstanceFromFactory<T>( partFactory, parentWidget,
00110                                                        parent, args );
00111             if ( !res )
00112             {
00113                 library->unload();
00114                 if ( error )
00115                     *error = KLibLoader::ErrNoComponent;
00116             }
00117             return res;
00118         }
00119 #endif
00120 
00124 #ifndef KDE_NO_DEPRECATED
00125         template <class T>
00126         KDE_DEPRECATED T *createPartInstanceFromService( const KService::Ptr &service,
00127                                           QWidget *parentWidget = 0,
00128                                           QObject *parent = 0,
00129                                           const QStringList &args = QStringList(),
00130                                           int *error = 0 )
00131         {
00132             QString library = service->library();
00133             if ( library.isEmpty() )
00134             {
00135                 if ( error )
00136                     *error = KLibLoader::ErrServiceProvidesNoLibrary;
00137                 return 0;
00138             }
00139 
00140             return createPartInstanceFromLibrary<T>( QFile::encodeName( library ).constData(), parentWidget,
00141                                                      parent, args, error );
00142         }
00143 #endif
00144 
00145 #ifndef KDE_NO_DEPRECATED
00146         template <class T, class ServiceIterator>
00147         KDE_DEPRECATED T *createPartInstanceFromServices( ServiceIterator begin,
00148                                            ServiceIterator end,
00149                                            QWidget *parentWidget = 0,
00150                                            QObject *parent = 0,
00151                                            const QStringList &args = QStringList(),
00152                                            int *error = 0 )
00153          {
00154             for (; begin != end; ++begin )
00155             {
00156                 KService::Ptr service = *begin;
00157 
00158                 if ( error )
00159                     *error = 0;
00160 
00161                 T *component = createPartInstanceFromService<T>( service, parentWidget,
00162                                                                  parent, args, error );
00163                 if ( component )
00164                     return component;
00165             }
00166 
00167             if ( error )
00168                 *error = KLibLoader::ErrNoServiceFound;
00169 
00170             return 0;
00171 
00172         }
00173 #endif
00174 
00203 #ifndef KDE_NO_DEPRECATED
00204         template <class T>
00205         KDE_DEPRECATED T *createPartInstanceFromQuery( const QString &mimeType,
00206                                         const QString &constraint,
00207                                         QWidget *parentWidget = 0,
00208                                         QObject *parent = 0,
00209                                         const QStringList &args = QStringList(),
00210                                         int *error = 0 )
00211         {
00212             const KService::List offers = KMimeTypeTrader::self()->query( mimeType, QLatin1String("KParts/ReadOnlyPart"), constraint );
00213             if ( offers.isEmpty() )
00214             {
00215                 if ( error )
00216                     *error = KLibLoader::ErrNoServiceFound;
00217                 return 0;
00218             }
00219 
00220             return createPartInstanceFromServices<T>( offers.begin(), offers.end(),
00221                                                       parentWidget,
00222                                                       parent, args, error );
00223         }
00224 #endif // KDE_NO_DEPRECATED
00225     }
00226 }
00227 
00228 /*
00229  * vim: et sw=4
00230  */
00231 
00232 #endif
This file is part of the KDE documentation.
Documentation copyright © 1996-2019 The KDE developers.
Generated on Mon Jan 21 2019 12:36:35 by doxygen 1.7.5.1 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KParts

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

kdelibs-4.9.5 API Reference

Skip menu "kdelibs-4.9.5 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • 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
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