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

KParts

  • kparts
componentfactory.h
Go to the documentation of this file.
1 /* This file is part of the KDE project
2  Copyright (C) 2001 Simon Hausmann <hausmann@kde.org>
3  Copyright (C) 2002-2006 David Faure <faure@kde.org>
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License as published by the Free Software Foundation; either
8  version 2 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Library General Public License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to the
17  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  Boston, MA 02110-1301, USA.
19 */
20 #ifndef KPARTS_COMPONENTFACTORY_H
21 #define KPARTS_COMPONENTFACTORY_H
22 
23 #include <kparts/factory.h>
24 #include <kparts/part.h>
25 #include <kservicetypetrader.h>
26 #ifndef KDE_NO_DEPRECATED
27 #include <klibloader.h>
28 #endif
29 #include <kmimetypetrader.h>
30 
31 namespace KParts
32 {
33  namespace ComponentFactory
34  {
54 #ifndef KDE_NO_DEPRECATED
55  template <class T>
56  KDE_DEPRECATED T *createPartInstanceFromFactory( KParts::Factory *factory,
57  QWidget *parentWidget = 0,
58  QObject *parent = 0,
59  const QStringList &args = QStringList() )
60  {
61  KParts::Part *object = factory->createPart( parentWidget,
62  parent,
63  T::staticMetaObject.className(),
64  args );
65 
66  T *result = dynamic_cast<T *>( object );
67  if ( !result )
68  delete object;
69  return result;
70  }
71 #endif
72 
73  /*
74  * @deprecated use KPluginFactory::create instead
75  */
76 #ifndef KDE_NO_DEPRECATED
77  template <class T>
78  KDE_DEPRECATED T *createPartInstanceFromLibrary( const char *libraryName,
79  QWidget *parentWidget = 0,
80  QObject *parent = 0,
81  const QStringList &args = QStringList(),
82  int *error = 0 )
83  {
84  KLibrary *library = KLibLoader::self()->library( QString( libraryName ) ); // compatibility hack
85  if ( !library )
86  {
87  if ( error )
88  *error = KLibLoader::ErrNoLibrary;
89  return 0;
90  }
91  KLibFactory *factory = library->factory();
92  if ( !factory )
93  {
94  library->unload();
95  if ( error )
96  *error = KLibLoader::ErrNoFactory;
97  return 0;
98  }
99  KParts::Factory *partFactory = dynamic_cast<KParts::Factory *>( factory );
100  if ( !partFactory )
101  {
102  library->unload();
103  if ( error )
104  *error = KLibLoader::ErrNoFactory;
105  return 0;
106  }
107  T *res = createPartInstanceFromFactory<T>( partFactory, parentWidget,
108  parent, args );
109  if ( !res )
110  {
111  library->unload();
112  if ( error )
113  *error = KLibLoader::ErrNoComponent;
114  }
115  return res;
116  }
117 #endif
118 
122 #ifndef KDE_NO_DEPRECATED
123  template <class T>
124  KDE_DEPRECATED T *createPartInstanceFromService( const KService::Ptr &service,
125  QWidget *parentWidget = 0,
126  QObject *parent = 0,
127  const QStringList &args = QStringList(),
128  int *error = 0 )
129  {
130  QString library = service->library();
131  if ( library.isEmpty() )
132  {
133  if ( error )
134  *error = KLibLoader::ErrServiceProvidesNoLibrary;
135  return 0;
136  }
137 
138  return createPartInstanceFromLibrary<T>( library.toLocal8Bit().data(), parentWidget,
139  parent, args, error );
140  }
141 #endif
142 
143 #ifndef KDE_NO_DEPRECATED
144  template <class T, class ServiceIterator>
145  KDE_DEPRECATED T *createPartInstanceFromServices( ServiceIterator begin,
146  ServiceIterator end,
147  QWidget *parentWidget = 0,
148  QObject *parent = 0,
149  const QStringList &args = QStringList(),
150  int *error = 0 )
151  {
152  for (; begin != end; ++begin )
153  {
154  KService::Ptr service = *begin;
155 
156  if ( error )
157  *error = 0;
158 
159  T *component = createPartInstanceFromService<T>( service, parentWidget,
160  parent, args, error );
161  if ( component )
162  return component;
163  }
164 
165  if ( error )
166  *error = KLibLoader::ErrNoServiceFound;
167 
168  return 0;
169 
170  }
171 #endif
172 
201 #ifndef KDE_NO_DEPRECATED
202  template <class T>
203  KDE_DEPRECATED T *createPartInstanceFromQuery( const QString &mimeType,
204  const QString &constraint,
205  QWidget *parentWidget = 0,
206  QObject *parent = 0,
207  const QStringList &args = QStringList(),
208  int *error = 0 )
209  {
210  const KService::List offers = KMimeTypeTrader::self()->query( mimeType, QLatin1String("KParts/ReadOnlyPart"), constraint );
211  if ( offers.isEmpty() )
212  {
213  if ( error )
214  *error = KLibLoader::ErrNoServiceFound;
215  return 0;
216  }
217 
218  return createPartInstanceFromServices<T>( offers.begin(), offers.end(),
219  parentWidget,
220  parent, args, error );
221  }
222 #endif // KDE_NO_DEPRECATED
223  }
224 }
225 
226 /*
227  * vim: et sw=4
228  */
229 
230 #endif
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Fri Dec 7 2012 16:11:51 by doxygen 1.8.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.8.5 API Reference

Skip menu "kdelibs-4.8.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