File indexing completed on 2024-04-28 15:29:23
0001 /* 0002 This file is part of the KDE project 0003 SPDX-FileCopyrightText: 1999 Simon Hausmann <hausmann@kde.org> 0004 SPDX-FileCopyrightText: 1999 David Faure <faure@kde.org> 0005 0006 SPDX-License-Identifier: LGPL-2.0-or-later 0007 */ 0008 #ifndef PLUGIN_H 0009 #define PLUGIN_H 0010 0011 #include <kparts/kparts_export.h> 0012 0013 #if KPARTS_ENABLE_DEPRECATED_SINCE(5, 90) 0014 0015 #include <KXMLGUIClient> 0016 #include <QDomElement> 0017 #include <QObject> 0018 #include <memory> 0019 0020 #if KPARTS_BUILD_DEPRECATED_SINCE(5, 77) 0021 class KAboutData; 0022 #endif 0023 class KPluginMetaData; 0024 0025 namespace KParts 0026 { 0027 class PluginPrivate; 0028 0029 /** 0030 * @class Plugin plugin.h <KParts/Plugin> 0031 * 0032 * @short A plugin is the way to add actions to an existing KParts application, 0033 * or to a Part. 0034 * 0035 * The XML of those plugins looks exactly like of the shell or parts, 0036 * with one small difference: The document tag should have an additional 0037 * attribute, named "library", and contain the name of the library implementing 0038 * the plugin. 0039 * 0040 * If you want this plugin to be used by a part, you need to 0041 * install the rc file under the directory 0042 * "data" (KDEDIR/share/apps usually)+"/instancename/kpartplugins/" 0043 * where instancename is the name of the part's instance. 0044 * 0045 * You should also install a "plugin info" .desktop file with the same name. 0046 * \see KPluginInfo 0047 * @deprecated Since 5.90, the concept of KPart plugins is deprecated. 0048 * In the Konqueror KF5Konq lib is a reimplementation of this class, which is not deprecated. 0049 * Consider porting your usage to this class or import the plugin in Konqueror. 0050 */ 0051 class KPARTS_EXPORT Plugin : public QObject, virtual public KXMLGUIClient 0052 { 0053 Q_OBJECT 0054 public: 0055 struct PluginInfo { 0056 QString m_relXMLFileName; // relative filename, i.e. kpartplugins/name 0057 QString m_absXMLFileName; // full path of most recent filename matching the relative 0058 // filename 0059 QDomDocument m_document; 0060 }; 0061 0062 /** 0063 * Construct a new KParts plugin. 0064 */ 0065 KPARTS_DEPRECATED_VERSION(5, 90, "See class API docs") 0066 explicit Plugin(QObject *parent = nullptr); 0067 /** 0068 * Destructor. 0069 */ 0070 ~Plugin() override; 0071 0072 /** 0073 * Reimplemented for internal reasons 0074 */ 0075 QString xmlFile() const override; 0076 0077 /** 0078 * Reimplemented for internal reasons 0079 */ 0080 QString localXMLFile() const override; 0081 0082 /** 0083 * Load the plugin libraries from the directories appropriate 0084 * to @p instance and make the Plugin objects children of @p parent. 0085 * 0086 * It is recommended to use the last loadPlugins method instead, 0087 * to support enabling and disabling of plugins. 0088 */ 0089 KPARTS_DEPRECATED_VERSION(5, 90, "See class API docs") 0090 static void loadPlugins(QObject *parent, const QString &instance); 0091 0092 /** 0093 * Load the plugin libraries specified by the list @p docs and make the 0094 * Plugin objects children of @p parent . 0095 * 0096 * It is recommended to use the last loadPlugins method instead, 0097 * to support enabling and disabling of plugins. 0098 */ 0099 KPARTS_DEPRECATED_VERSION(5, 90, "See class API docs") 0100 static void loadPlugins(QObject *parent, const QList<PluginInfo> &pluginInfos); 0101 0102 /** 0103 * Load the plugin libraries specified by the list @p pluginInfos, make the 0104 * Plugin objects children of @p parent, and use the given @p instance. 0105 * 0106 * It is recommended to use the last loadPlugins method instead, 0107 * to support enabling and disabling of plugins. 0108 */ 0109 KPARTS_DEPRECATED_VERSION(5, 90, "See class API docs") 0110 static void loadPlugins(QObject *parent, const QList<PluginInfo> &pluginInfos, const QString &instance); 0111 0112 /** 0113 * Load the plugin libraries for the given @p instance, make the 0114 * Plugin objects children of @p parent, and insert the plugin as a child GUI client 0115 * of @p parentGUIClient. 0116 * 0117 * This method uses the KConfig object of the given instance, to find out which 0118 * plugins are enabled and which are disabled. What happens by default (i.e. 0119 * for new plugins that are not in that config file) is controlled by 0120 * @p enableNewPluginsByDefault. It can be overridden by the plugin if it 0121 * sets the X-KDE-PluginInfo-EnabledByDefault key in the .desktop file 0122 * (with the same name as the .rc file) 0123 * 0124 * If a disabled plugin is already loaded it will be removed from the GUI 0125 * factory and deleted. 0126 * 0127 * If you change the binary interface offered by your part, you can avoid crashes 0128 * from old plugins lying around by setting X-KDE-InterfaceVersion=2 in the 0129 * .desktop files of the plugins, and passing 2 to @p interfaceVersionRequired, so that 0130 * the old plugins are not loaded. Increase both numbers every time a 0131 * binary incompatible change in the application's plugin interface is made. 0132 * 0133 * 0134 * This method is automatically called by KParts::Part and by KParts::MainWindow. 0135 * @see PartBase::setPluginLoadingMode, PartBase::setPluginInterfaceVersion 0136 * 0137 * If you call this method in an already constructed GUI (like when the user 0138 * has changed which plugins are enabled) you need to add the new plugins to 0139 * the KXMLGUIFactory: 0140 * \code 0141 * if( factory() ) 0142 * { 0143 * const QList<KParts::Plugin *> plugins = KParts::Plugin::pluginObjects( this ); 0144 * for ( KParts::Plugin * plugin : plugins ) 0145 * factory()->addClient( plugin ); 0146 * } 0147 * \endcode 0148 */ 0149 KPARTS_DEPRECATED_VERSION(5, 90, "See class API docs") 0150 static void loadPlugins(QObject *parent, 0151 KXMLGUIClient *parentGUIClient, 0152 const QString &instance, 0153 bool enableNewPluginsByDefault = true, 0154 int interfaceVersionRequired = 0); 0155 0156 /** 0157 * Returns a list of plugin objects loaded for @p parent. This 0158 * functions basically iterates over the children of the given object 0159 * and returns those that inherit from KParts::Plugin. 0160 **/ 0161 KPARTS_DEPRECATED_VERSION(5, 90, "See class API docs") 0162 static QList<Plugin *> pluginObjects(QObject *parent); 0163 0164 protected: 0165 #if KPARTS_BUILD_DEPRECATED_SINCE(5, 77) 0166 /** 0167 * @deprecated Since 5.77, use setMetaData(const KPluginMetaData&) instead. 0168 */ 0169 KPARTS_DEPRECATED_VERSION(5, 77, "Use setMetaData(const KPluginMetaData&) instead") 0170 virtual void setComponentData(const KAboutData &pluginData); 0171 #endif 0172 0173 /** 0174 * @since 5.77 0175 */ 0176 void setMetaData(const KPluginMetaData &metaData); 0177 0178 private: 0179 /** 0180 * Look for plugins in the @p instance's "data" directory (+"/kpartplugins") 0181 * 0182 * @return A list of QDomDocument s, containing the parsed xml documents returned by plugins. 0183 */ 0184 KPARTS_DEPRECATED_VERSION(5, 90, "See class API docs") 0185 static QList<Plugin::PluginInfo> pluginInfos(const QString &instance); 0186 0187 /** 0188 * @internal 0189 * @return The plugin created from the library @p libname 0190 */ 0191 KPARTS_DEPRECATED_VERSION(5, 90, "See class API docs") 0192 static Plugin *loadPlugin(QObject *parent, const QString &libname, const QString &keyword = QString()); 0193 0194 private: 0195 static bool hasPlugin(QObject *parent, const QString &library); 0196 std::unique_ptr<PluginPrivate> const d; 0197 }; 0198 0199 } 0200 0201 #endif 0202 #endif