• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 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#include <QtCore/QFile>
32
33namespace KParts
34{
35 namespace ComponentFactory
36 {
56#ifndef KDE_NO_DEPRECATED
57 template <class T>
58 KDE_DEPRECATED T *createPartInstanceFromFactory( KParts::Factory *factory,
59 QWidget *parentWidget = 0,
60 QObject *parent = 0,
61 const QStringList &args = QStringList() )
62 {
63 KParts::Part *object = factory->createPart( parentWidget,
64 parent,
65 T::staticMetaObject.className(),
66 args );
67
68 T *result = dynamic_cast<T *>( object );
69 if ( !result )
70 delete object;
71 return result;
72 }
73#endif
74
75 /*
76 * @deprecated use KPluginFactory::create instead
77 */
78#ifndef KDE_NO_DEPRECATED
79 template <class T>
80 KDE_DEPRECATED T *createPartInstanceFromLibrary( const char *libraryName,
81 QWidget *parentWidget = 0,
82 QObject *parent = 0,
83 const QStringList &args = QStringList(),
84 int *error = 0 )
85 {
86 KLibrary *library = KLibLoader::self()->library( QFile::decodeName( libraryName ) ); // compatibility hack
87 if ( !library )
88 {
89 if ( error )
90 *error = KLibLoader::ErrNoLibrary;
91 return 0;
92 }
93 KLibFactory *factory = library->factory();
94 if ( !factory )
95 {
96 library->unload();
97 if ( error )
98 *error = KLibLoader::ErrNoFactory;
99 return 0;
100 }
101 KParts::Factory *partFactory = dynamic_cast<KParts::Factory *>( factory );
102 if ( !partFactory )
103 {
104 library->unload();
105 if ( error )
106 *error = KLibLoader::ErrNoFactory;
107 return 0;
108 }
109 T *res = createPartInstanceFromFactory<T>( partFactory, parentWidget,
110 parent, args );
111 if ( !res )
112 {
113 library->unload();
114 if ( error )
115 *error = KLibLoader::ErrNoComponent;
116 }
117 return res;
118 }
119#endif
120
124#ifndef KDE_NO_DEPRECATED
125 template <class T>
126 KDE_DEPRECATED T *createPartInstanceFromService( const KService::Ptr &service,
127 QWidget *parentWidget = 0,
128 QObject *parent = 0,
129 const QStringList &args = QStringList(),
130 int *error = 0 )
131 {
132 QString library = service->library();
133 if ( library.isEmpty() )
134 {
135 if ( error )
136 *error = KLibLoader::ErrServiceProvidesNoLibrary;
137 return 0;
138 }
139
140 return createPartInstanceFromLibrary<T>( QFile::encodeName( library ).constData(), parentWidget,
141 parent, args, error );
142 }
143#endif
144
145#ifndef KDE_NO_DEPRECATED
146 template <class T, class ServiceIterator>
147 KDE_DEPRECATED T *createPartInstanceFromServices( ServiceIterator begin,
148 ServiceIterator end,
149 QWidget *parentWidget = 0,
150 QObject *parent = 0,
151 const QStringList &args = QStringList(),
152 int *error = 0 )
153 {
154 for (; begin != end; ++begin )
155 {
156 KService::Ptr service = *begin;
157
158 if ( error )
159 *error = 0;
160
161 T *component = createPartInstanceFromService<T>( service, parentWidget,
162 parent, args, error );
163 if ( component )
164 return component;
165 }
166
167 if ( error )
168 *error = KLibLoader::ErrNoServiceFound;
169
170 return 0;
171
172 }
173#endif
174
203#ifndef KDE_NO_DEPRECATED
204 template <class T>
205 KDE_DEPRECATED T *createPartInstanceFromQuery( const QString &mimeType,
206 const QString &constraint,
207 QWidget *parentWidget = 0,
208 QObject *parent = 0,
209 const QStringList &args = QStringList(),
210 int *error = 0 )
211 {
212 const KService::List offers = KMimeTypeTrader::self()->query( mimeType, QLatin1String("KParts/ReadOnlyPart"), constraint );
213 if ( offers.isEmpty() )
214 {
215 if ( error )
216 *error = KLibLoader::ErrNoServiceFound;
217 return 0;
218 }
219
220 return createPartInstanceFromServices<T>( offers.begin(), offers.end(),
221 parentWidget,
222 parent, args, error );
223 }
224#endif // KDE_NO_DEPRECATED
225 }
226}
227
228/*
229 * vim: et sw=4
230 */
231
232#endif
KLibLoader::self
static KLibLoader * self()
KLibLoader::ErrServiceProvidesNoLibrary
ErrServiceProvidesNoLibrary
KLibLoader::ErrNoServiceFound
ErrNoServiceFound
KLibLoader::ErrNoComponent
ErrNoComponent
KLibLoader::ErrNoFactory
ErrNoFactory
KLibLoader::ErrNoLibrary
ErrNoLibrary
KLibLoader::library
KLibrary * library(const QString &libname, QLibrary::LoadHints loadHint=0)
KLibrary
KLibrary::unload
bool unload()
KLibrary::factory
KPluginFactory * factory(const char *factoryname=0)
KMimeTypeTrader::query
KService::List query(const QString &mimeType, const QString &genericServiceType=QString::fromLatin1("Application"), const QString &constraint=QString()) const
KMimeTypeTrader::self
static KMimeTypeTrader * self()
KParts::Factory
A generic factory object to create a Part.
Definition: factory.h:43
KParts::Factory::createPart
Part * createPart(QWidget *parentWidget=0, QObject *parent=0, const char *classname="KParts::Part", const QStringList &args=QStringList())
Creates a part.
Definition: factory.cpp:44
KParts::Part
Base class for parts.
Definition: part.h:216
KPluginFactory
KSharedPtr< KService >
QList< Ptr >
QObject
QWidget
factory.h
klibloader.h
kmimetypetrader.h
kservicetypetrader.h
T
#define T
KParts::ComponentFactory::createPartInstanceFromService
T * createPartInstanceFromService(const KService::Ptr &service, QWidget *parentWidget=0, QObject *parent=0, const QStringList &args=QStringList(), int *error=0)
Definition: componentfactory.h:126
KParts::ComponentFactory::createPartInstanceFromLibrary
T * createPartInstanceFromLibrary(const char *libraryName, QWidget *parentWidget=0, QObject *parent=0, const QStringList &args=QStringList(), int *error=0)
Definition: componentfactory.h:80
KParts::ComponentFactory::createPartInstanceFromFactory
T * createPartInstanceFromFactory(KParts::Factory *factory, QWidget *parentWidget=0, QObject *parent=0, const QStringList &args=QStringList())
This template function allows to ask the given kparts factory to create an instance of the given temp...
Definition: componentfactory.h:58
KParts::ComponentFactory::createPartInstanceFromQuery
T * createPartInstanceFromQuery(const QString &mimeType, const QString &constraint, QWidget *parentWidget=0, QObject *parent=0, const QStringList &args=QStringList(), int *error=0)
This method creates and returns a KParts part from a serviceType (e.g.
Definition: componentfactory.h:205
KParts::ComponentFactory::createPartInstanceFromServices
T * createPartInstanceFromServices(ServiceIterator begin, ServiceIterator end, QWidget *parentWidget=0, QObject *parent=0, const QStringList &args=QStringList(), int *error=0)
Definition: componentfactory.h:147
KParts
begin
const KShortcut & begin()
end
const KShortcut & end()
part.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 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.14.38 API Reference

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