File indexing completed on 2024-04-21 14:56:06
0001 /* This file is part of the KDE project 0002 Copyright (C) 1999 Simon Hausmann <hausmann@kde.org> 0003 (C) 1999 David Faure <faure@kde.org> 0004 0005 This library is free software; you can redistribute it and/or 0006 modify it under the terms of the GNU Library General Public 0007 License as published by the Free Software Foundation; either 0008 version 2 of the License, or (at your option) any later version. 0009 0010 This library is distributed in the hope that it will be useful, 0011 but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0013 Library General Public License for more details. 0014 0015 You should have received a copy of the GNU Library General Public License 0016 along with this library; see the file COPYING.LIB. If not, write to 0017 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0018 Boston, MA 02110-1301, USA. 0019 */ 0020 #ifndef __kparts_factory_h__ 0021 #define __kparts_factory_h__ 0022 0023 #include <kdelibs4support_export.h> 0024 #include <kpluginfactory.h> 0025 #include <kcomponentdata.h> 0026 0027 class QWidget; 0028 0029 namespace KParts 0030 { 0031 0032 class Part; 0033 0034 /** 0035 * A generic factory object to create a Part. 0036 * 0037 * Factory is an abstract class. Reimplement the 0038 * createPartObject() method to give it functionality. 0039 * 0040 * @see KPluginFactory. 0041 */ 0042 class KDELIBS4SUPPORT_DEPRECATED_EXPORT Factory : public KPluginFactory 0043 { 0044 Q_OBJECT 0045 public: 0046 Factory(QObject *parent = nullptr); 0047 ~Factory() override; 0048 0049 /** 0050 * Creates a part. 0051 * 0052 * The QStringList can be used to pass additional arguments to the part. 0053 * If the part needs additional arguments, it should take them as 0054 * name="value" pairs. This is the way additional arguments will get passed 0055 * to the part from eg. khtml. You can for example emebed the part into HTML 0056 * by using the following code: 0057 * \code 0058 * <object type="my_mimetype" data="url_to_my_data"> 0059 * <param name="name1" value="value1"> 0060 * <param name="name2" value="value2"> 0061 * </object> 0062 * \endcode 0063 * This could result in a call to 0064 * \code 0065 * createPart( parentWidget, parentObject, "KParts::Part", 0066 * QStringList("name1="value1"", "name2="value2") ); 0067 * \endcode 0068 * 0069 * @returns the newly created part. 0070 * 0071 * createPart() automatically emits a signal KPluginFactory::objectCreated to tell 0072 * the library about its newly created object. This is very 0073 * important for reference counting, and allows unloading the 0074 * library automatically once all its objects have been destroyed. 0075 */ 0076 Part *createPart(QWidget *parentWidget = nullptr, QObject *parent = nullptr, const char *classname = "KParts::Part", const QStringList &args = QStringList()); 0077 0078 /** 0079 * If you have a part contained in a shared library you might want to query 0080 * for meta-information like the about-data, or the KComponentData in general. 0081 * If the part is exported using KParts::GenericFactory then this method will 0082 * return the instance that belongs to the part without the need to instantiate 0083 * the part component. 0084 */ 0085 virtual KComponentData partComponentData(); 0086 0087 /** 0088 * A convenience method for partComponentData that takes care of retrieving 0089 * the factory for a given library name and calling partComponentData on it. 0090 * 0091 * @param libraryName name of the library to query the instance from 0092 */ 0093 static KComponentData partComponentDataFromLibrary(const QString &libraryName); 0094 0095 protected: 0096 0097 /** 0098 * Reimplement this method in your implementation to create the Part. 0099 * 0100 * The QStringList can be used to pass additional arguments to the part. 0101 * If the part needs additional arguments, it should take them as 0102 * name="value" pairs. This is the way additional arguments will get passed 0103 * to the part from eg. khtml. You can for example emebed the part into HTML 0104 * by using the following code: 0105 * \code 0106 * <object type="my_mimetype" data="url_to_my_data"> 0107 * <param name="name1" value="value1"> 0108 * <param name="name2" value="value2"> 0109 * </object> 0110 * \endcode 0111 * This could result in a call to 0112 * \code 0113 * createPart( parentWidget, parentObject, "KParts::Part", 0114 * QStringList("name1="value1"", "name2="value2") ); 0115 * \endcode 0116 * 0117 * @returns the newly created part. 0118 */ 0119 Part *createPartObject(QWidget *parentWidget = nullptr, QObject *parent = nullptr, const char *classname = "KParts::Part", const QStringList &args = QStringList()) override = 0; 0120 0121 /** 0122 * Reimplemented from KPluginFactory. Calls createPart() 0123 */ 0124 QObject *createObject(QObject *parent = nullptr, const char *classname = "QObject", const QStringList &args = QStringList()) override; 0125 0126 }; 0127 0128 } 0129 0130 #endif