/usr/include/kparts/componentfactory.h is in kdelibs5-dev 4:4.14.2-5+deb8u2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 | /* This file is part of the KDE project
Copyright (C) 2001 Simon Hausmann <hausmann@kde.org>
Copyright (C) 2002-2006 David Faure <faure@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef KPARTS_COMPONENTFACTORY_H
#define KPARTS_COMPONENTFACTORY_H
#include <kparts/factory.h>
#include <kparts/part.h>
#include <kservicetypetrader.h>
#ifndef KDE_NO_DEPRECATED
#include <klibloader.h>
#endif
#include <kmimetypetrader.h>
#include <QtCore/QFile>
namespace KParts
{
namespace ComponentFactory
{
/**
* This template function allows to ask the given kparts factory to
* create an instance of the given template type.
*
* Example of usage:
* \code
* KViewPart *doc = KParts::ComponentFactory::createPartInstanceFromFactory<KViewPart>( factory, parent );
* \endcode
*
* @deprecated use KPluginFactory::create instead
*
* @param factory The factory to ask for the creation of the component
* @param parentWidget the parent widget for the part
* @param parent The parent object (see QObject constructor)
* @param args A list of string arguments, passed to the factory and possibly
* to the component (see KLibFactory)
* @return A pointer to the newly created object or a null pointer if the
* factory was unable to create an object of the given type.
*/
#ifndef KDE_NO_DEPRECATED
template <class T>
KDE_DEPRECATED T *createPartInstanceFromFactory( KParts::Factory *factory,
QWidget *parentWidget = 0,
QObject *parent = 0,
const QStringList &args = QStringList() )
{
KParts::Part *object = factory->createPart( parentWidget,
parent,
T::staticMetaObject.className(),
args );
T *result = dynamic_cast<T *>( object );
if ( !result )
delete object;
return result;
}
#endif
/*
* @deprecated use KPluginFactory::create instead
*/
#ifndef KDE_NO_DEPRECATED
template <class T>
KDE_DEPRECATED T *createPartInstanceFromLibrary( const char *libraryName,
QWidget *parentWidget = 0,
QObject *parent = 0,
const QStringList &args = QStringList(),
int *error = 0 )
{
KLibrary *library = KLibLoader::self()->library( QFile::decodeName( libraryName ) ); // compatibility hack
if ( !library )
{
if ( error )
*error = KLibLoader::ErrNoLibrary;
return 0;
}
KLibFactory *factory = library->factory();
if ( !factory )
{
library->unload();
if ( error )
*error = KLibLoader::ErrNoFactory;
return 0;
}
KParts::Factory *partFactory = dynamic_cast<KParts::Factory *>( factory );
if ( !partFactory )
{
library->unload();
if ( error )
*error = KLibLoader::ErrNoFactory;
return 0;
}
T *res = createPartInstanceFromFactory<T>( partFactory, parentWidget,
parent, args );
if ( !res )
{
library->unload();
if ( error )
*error = KLibLoader::ErrNoComponent;
}
return res;
}
#endif
/**
* @deprecated use KService::createInstance instead
*/
#ifndef KDE_NO_DEPRECATED
template <class T>
KDE_DEPRECATED T *createPartInstanceFromService( const KService::Ptr &service,
QWidget *parentWidget = 0,
QObject *parent = 0,
const QStringList &args = QStringList(),
int *error = 0 )
{
QString library = service->library();
if ( library.isEmpty() )
{
if ( error )
*error = KLibLoader::ErrServiceProvidesNoLibrary;
return 0;
}
return createPartInstanceFromLibrary<T>( QFile::encodeName( library ).constData(), parentWidget,
parent, args, error );
}
#endif
#ifndef KDE_NO_DEPRECATED
template <class T, class ServiceIterator>
KDE_DEPRECATED T *createPartInstanceFromServices( ServiceIterator begin,
ServiceIterator end,
QWidget *parentWidget = 0,
QObject *parent = 0,
const QStringList &args = QStringList(),
int *error = 0 )
{
for (; begin != end; ++begin )
{
KService::Ptr service = *begin;
if ( error )
*error = 0;
T *component = createPartInstanceFromService<T>( service, parentWidget,
parent, args, error );
if ( component )
return component;
}
if ( error )
*error = KLibLoader::ErrNoServiceFound;
return 0;
}
#endif
/**
* This method creates and returns a KParts part from a serviceType (e.g. a mimetype).
*
* You can use this method to create a generic viewer - that can display any
* kind of file, provided that there is a ReadOnlyPart installed for it - in 5 lines:
* \code
* // Given the following: KUrl url, QWidget* parentWidget and QObject* parentObject.
* QString mimetype = KMimeType::findByURL( url )->name();
* KParts::ReadOnlyPart* part = KParts::ComponentFactory::createPartInstanceFromQuery<KParts::ReadOnlyPart>( mimetype, QString(), parentWidget, parentObject );
* if ( part ) {
* part->openUrl( url );
* part->widget()->show(); // also insert the widget into a layout, or simply use a KVBox as parentWidget
* }
* \endcode
*
* @deprecated use KMimeTypeTrader::createPartInstanceFromQuery instead
*
* @param mimeType the mimetype which this part is associated with
* @param constraint an optional constraint to pass to the trader (see KTrader)
* @param parentWidget the parent widget, will be set as the parent of the part's widget
* @param parent the parent object for the part itself
* @param args A list of string arguments, passed to the factory and possibly
* to the component (see KLibFactory)
* @param error The int passed here will receive an error code in case of errors.
* (See enum KLibLoader::ComponentLoadingError)
* @return A pointer to the newly created object or a null pointer if the
* factory was unable to create an object of the given type.
*/
#ifndef KDE_NO_DEPRECATED
template <class T>
KDE_DEPRECATED T *createPartInstanceFromQuery( const QString &mimeType,
const QString &constraint,
QWidget *parentWidget = 0,
QObject *parent = 0,
const QStringList &args = QStringList(),
int *error = 0 )
{
const KService::List offers = KMimeTypeTrader::self()->query( mimeType, QLatin1String("KParts/ReadOnlyPart"), constraint );
if ( offers.isEmpty() )
{
if ( error )
*error = KLibLoader::ErrNoServiceFound;
return 0;
}
return createPartInstanceFromServices<T>( offers.begin(), offers.end(),
parentWidget,
parent, args, error );
}
#endif // KDE_NO_DEPRECATED
}
}
/*
* vim: et sw=4
*/
#endif
|