File indexing completed on 2024-04-28 04:58:11
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 <libkonq_export.h> 0012 0013 #include <KPluginMetaData> 0014 #include <KXMLGUIClient> 0015 #include <QDomElement> 0016 #include <QObject> 0017 #include <memory> 0018 0019 class KPluginMetaData; 0020 0021 namespace KonqParts 0022 { 0023 class PluginPrivate; 0024 0025 /** 0026 * @class Plugin plugin.h <KParts/Plugin> 0027 * 0028 * @short A plugin is the way to add actions to an existing KParts application, 0029 * or to a Part. 0030 * 0031 * The XML of those plugins looks exactly like of the shell or parts, 0032 * with one small difference: The document tag should have an additional 0033 * attribute, named "library", and contain the name of the library implementing 0034 * the plugin. 0035 * 0036 * If you want this plugin to be used by a part, you need to 0037 * install the rc file under the directory 0038 * "data" (KDEDIR/share/apps usually)+"/instancename/kpartplugins/" 0039 * where instancename is the name of the part's instance. 0040 * 0041 * You should also install a "plugin info" .desktop file with the same name. 0042 * \see KPluginInfo 0043 */ 0044 class LIBKONQ_EXPORT Plugin : public QObject, virtual public KXMLGUIClient 0045 { 0046 Q_OBJECT 0047 public: 0048 struct PluginInfo { 0049 KPluginMetaData m_metaData; 0050 QString m_absXMLFileName; // full path of most recent filename matching the relative 0051 QDomDocument m_document; 0052 }; 0053 0054 /** 0055 * Construct a new KParts plugin. 0056 */ 0057 explicit Plugin(QObject *parent = nullptr); 0058 /** 0059 * Destructor. 0060 */ 0061 ~Plugin() override; 0062 0063 /** 0064 * Reimplemented for internal reasons 0065 */ 0066 QString xmlFile() const override; 0067 0068 /** 0069 * Reimplemented for internal reasons 0070 */ 0071 QString localXMLFile() const override; 0072 0073 /** 0074 * Load the plugin libraries specified by the list @p pluginInfos, make the 0075 * Plugin objects children of @p parent, and use the given @p instance. 0076 * 0077 * It is recommended to use the last loadPlugins method instead, 0078 * to support enabling and disabling of plugins. 0079 */ 0080 static void loadPlugins(QObject *parent, const QList<PluginInfo> &pluginInfos, const QString &instance); 0081 0082 /** 0083 * Load the plugin libraries for the given @p instance, make the 0084 * Plugin objects children of @p parent, and insert the plugin as a child GUI client 0085 * of @p parentGUIClient. 0086 * 0087 * This method uses the KConfig object of the given instance, to find out which 0088 * plugins are enabled and which are disabled. 0089 * If a disabled plugin is already loaded it will be removed from the GUI 0090 * factory and deleted. 0091 * 0092 * 0093 * This method is automatically called by KParts::Part and by KParts::MainWindow. 0094 * @see PartBase::setPluginLoadingMode, PartBase::setPluginInterfaceVersion 0095 * 0096 * If you call this method in an already constructed GUI (like when the user 0097 * has changed which plugins are enabled) you need to add the new plugins to 0098 * the KXMLGUIFactory: 0099 * \code 0100 * if( factory() ) 0101 * { 0102 * const QList<KParts::Plugin *> plugins = KParts::Plugin::pluginObjects( this ); 0103 * for ( KParts::Plugin * plugin : plugins ) 0104 * factory()->addClient( plugin ); 0105 * } 0106 * \endcode 0107 */ 0108 static void loadPlugins(QObject *parent, KXMLGUIClient *parentGUIClient, const QString &instance); 0109 0110 /** 0111 * Returns a list of plugin objects loaded for @p parent. This 0112 * functions basically iterates over the children of the given object 0113 * and returns those that inherit from KParts::Plugin. 0114 **/ 0115 static QList<Plugin *> pluginObjects(QObject *parent); 0116 0117 protected: 0118 /** 0119 * @since 5.77 0120 */ 0121 void setMetaData(const KPluginMetaData &metaData); 0122 0123 private: 0124 /** 0125 * Look for plugins in the @p instance's "data" directory (+"/kpartplugins") 0126 * 0127 * @return A list of QDomDocument s, containing the parsed xml documents returned by plugins. 0128 */ 0129 static QList<Plugin::PluginInfo> pluginInfos(const QString &instance); 0130 0131 /** 0132 * @internal 0133 * @return The plugin created from the library @p libname 0134 */ 0135 static Plugin *loadPlugin(QObject *parent, const KPluginMetaData &data); 0136 0137 private: 0138 static bool hasPlugin(QObject *parent, const QString &pluginId); 0139 std::unique_ptr<PluginPrivate> const d; 0140 }; 0141 0142 } 0143 0144 #endif 0145