File indexing completed on 2024-04-28 04:36:30
0001 /* 0002 SPDX-FileCopyrightText: 1999-2001 Bernd Gehrmann <bernd@kdevelop.org> 0003 SPDX-FileCopyrightText: 2004, 2007 Alexander Dymo <adymo@kdevelop.org> 0004 SPDX-FileCopyrightText: 2006 Adam Treat <treat@kde.org> 0005 SPDX-FileCopyrightText: 2007 Andreas Pakulat <apaku@gmx.de> 0006 0007 SPDX-License-Identifier: LGPL-2.0-or-later 0008 */ 0009 0010 #ifndef KDEVPLATFORM_IPLUGIN_H 0011 #define KDEVPLATFORM_IPLUGIN_H 0012 0013 #include <QObject> 0014 0015 #include <KXMLGUIClient> 0016 0017 #include "interfacesexport.h" 0018 0019 namespace Sublime { 0020 class MainWindow; 0021 } 0022 0023 namespace KDevelop 0024 { 0025 0026 class ICore; 0027 class ConfigPage; 0028 class Context; 0029 class ContextMenuExtension; 0030 struct ProjectConfigOptions; 0031 class IPluginPrivate; 0032 0033 /** 0034 * The base class for all KDevelop plugins. 0035 * 0036 * Plugin is a component which is loaded into KDevelop shell at startup or by 0037 * request. Each plugin should have corresponding .desktop file with a 0038 * description. The .desktop file template looks like: 0039 * @code 0040 * [Desktop Entry] 0041 * Type=Service 0042 * Exec=blubb 0043 * Name= 0044 * Comment= 0045 * Icon= 0046 * X-KDE-Library= 0047 * X-KDE-PluginInfo-Name= 0048 * X-KDE-PluginInfo-Author= 0049 * X-KDE-PluginInfo-Version= 0050 * X-KDE-PluginInfo-License= 0051 * X-KDE-PluginInfo-Category= 0052 * X-KDevelop-Version= 0053 * X-KDevelop-Category= 0054 * X-KDevelop-Mode=GUI 0055 * X-KDevelop-LoadMode= 0056 * X-KDevelop-Languages= 0057 * X-KDevelop-SupportedMimeTypes= 0058 * X-KDevelop-Interfaces= 0059 * X-KDevelop-IOptional= 0060 * X-KDevelop-IRequired= 0061 * @endcode 0062 * <b>Description of parameters in .desktop file:</b> 0063 * - <i>Name</i> is a translatable name of a plugin, it is used in the plugin 0064 * selection list (required); 0065 * - <i>Comment</i> is a short description about the plugin (optional); 0066 * - <i>Icon</i> is a plugin icon (preferred); 0067 * <i>X-KDE-library</i>this is the name of the .so file to load for this plugin (required); 0068 * - <i>X-KDE-PluginInfo-Name</i> is a non-translatable user-readable plugin 0069 * identifier used in KTrader queries (required); 0070 * - <i>X-KDE-PluginInfo-Author</i> is a non-translateable name of the plugin 0071 * author (optional); 0072 * - <i>X-KDE-PluginInfo-Version</i> is version number of the plugin (optional); 0073 * - <i>X-KDE-PluginInfo-License</i> is a license (optional). can be: GPL, 0074 * LGPL, BSD, Artistic, QPL or Custom. If this property is not set, license is 0075 * considered as unknown; 0076 * - <i>X-KDE-PluginInfo-Category</i> is used to categorize plugins (optional). can be: 0077 * Core, Project Management, Version Control, Utilities, Documentation, 0078 * Language Support, Debugging, Other 0079 * If this property is not set, "Other" is assumed 0080 * - <i>X-KDevelop-Version</i> is the KDevPlatform API version this plugin 0081 * works with (required); 0082 * - <i>X-KDevelop-Interfaces</i> is a list of extension interfaces that this 0083 * plugin implements (optional); 0084 * - <i>X-KDevelop-IRequired</i> is a list of extension interfaces that this 0085 * plugin depends on (optional); A list entry can also be of the form @c interface\@pluginname, 0086 * in which case a plugin of the given name is required which implements the interface. 0087 * - <i>X-KDevelop-IOptional</i> is a list of extension interfaces that this 0088 * plugin will use if they are available (optional); 0089 * - <i>X-KDevelop-Languages</i> is a list of the names of the languages the plugin provides 0090 * support for (optional); 0091 * - <i>X-KDevelop-SupportedMimeTypes</i> is a list of mimetypes that the 0092 * language-parser in this plugin supports (optional); 0093 * - <i>X-KDevelop-Mode</i> is either GUI or NoGUI to indicate whether a plugin can run 0094 * with the GUI components loaded or not (required); 0095 * - <i>X-KDevelop-Category</i> is a scope of a plugin (see below for 0096 * explanation) (required); 0097 * - <i>X-KDevelop-LoadMode</i> can be set to AlwaysOn in which case the plugin will 0098 * never be unloaded even if requested via the API. (optional); 0099 * 0100 * Plugin scope can be either: 0101 * - Global 0102 * - Project 0103 * . 0104 * Global plugins are plugins which require only the shell to be loaded and do not operate on 0105 * the Project interface and/or do not use project wide information.\n 0106 * Core plugins are global plugins which offer some important "core" functionality and thus 0107 * are not selectable by user in plugin configuration pages.\n 0108 * Project plugins require a project to be loaded and are usually loaded/unloaded along with 0109 * the project. 0110 * If your plugin uses the Project interface and/or operates on project-related 0111 * information then this is a project plugin. 0112 * 0113 * 0114 * @sa Core class documentation for information about features available to 0115 * plugins from shell applications. 0116 */ 0117 class KDEVPLATFORMINTERFACES_EXPORT IPlugin: public QObject, public KXMLGUIClient 0118 { 0119 Q_OBJECT 0120 0121 public: 0122 /**Constructs a plugin. 0123 * @param componentName The component name for this plugin. 0124 * @param parent The parent object for the plugin. 0125 */ 0126 IPlugin(const QString &componentName, QObject *parent); 0127 0128 /**Destructs a plugin.*/ 0129 ~IPlugin() override; 0130 0131 /** 0132 * Signal the plugin that it should cleanup since it will be unloaded soon. 0133 */ 0134 virtual void unload(); 0135 0136 /** 0137 * Provides access to the ICore implementation 0138 */ 0139 ICore *core() const; 0140 0141 /** 0142 * Convenience API to access an interface inherited by this plugin 0143 * 0144 * @return Instance to the specified interface, or nullptr 0145 */ 0146 template<class Extension> 0147 inline Extension* extension() 0148 { 0149 return qobject_cast<Extension*>(this); 0150 } 0151 0152 /** 0153 * Ask the plugin for a ContextActionContainer, which contains actions 0154 * that will be merged into the context menu. 0155 * @param context the context describing where the context menu was requested 0156 * @param parent a widget to use for memory management of QActions, QMenus etc. created only for this request 0157 * @returns a container describing which actions to merge into which context menu part 0158 */ 0159 virtual ContextMenuExtension contextMenuExtension(KDevelop::Context* context, QWidget* parent); 0160 0161 /** 0162 * Can create a new KXMLGUIClient, and set it up correctly with all the plugins per-window GUI actions. 0163 * 0164 * The caller owns the created object, including all contained actions. The object is destroyed as soon as 0165 * the mainwindow is closed. 0166 * 0167 * The default implementation calls the convenience function @ref createActionsForMainWindow and uses it to fill a custom KXMLGUIClient. 0168 * 0169 * Only override this version if you need more specific features of KXMLGUIClient, or other special per-window handling. 0170 * 0171 * @param window The main window the actions are created for 0172 */ 0173 virtual KXMLGUIClient* createGUIForMainWindow( Sublime::MainWindow* window ); 0174 0175 /** 0176 * This function allows allows setting up plugin actions conveniently. Unless createGUIForMainWindow was overridden, 0177 * this is called for each new mainwindow, and the plugin should add its actions to @p actions, and write its KXMLGui xml file 0178 * into @p xmlFile. 0179 * 0180 * @param window The main window the actions are created for 0181 * @param xmlFile Change this to the xml file that needed for merging the actions into the GUI 0182 * @param actions Add your actions here. A new set of actions has to be created for each mainwindow. 0183 */ 0184 virtual void createActionsForMainWindow( Sublime::MainWindow* window, QString& xmlFile, KActionCollection& actions ); 0185 0186 /** 0187 * This function is necessary because there is no proper way to signal errors from plugin constructor. 0188 * @returns True if the plugin has encountered an error (and therefore has an error description), 0189 * false otherwise. 0190 */ 0191 bool hasError() const; 0192 0193 /** 0194 * Description of the last encountered error, of an empty string if none. 0195 */ 0196 QString errorDescription() const; 0197 0198 /** 0199 * Set a @p description of the error encountered. An empty error 0200 * description implies no error in the plugin. 0201 */ 0202 void setErrorDescription(QString const& description); 0203 0204 /** 0205 * Get the global config page with the \p number, config pages from 0 to 0206 * configPages()-1 are available if configPages() > 0. 0207 * 0208 * @param number index of config page 0209 * @param parent parent widget for config page 0210 * @return newly created config page or NULL, if the number is out of bounds, default implementation returns NULL. 0211 * This config page should inherit from ProjectConfigPage, but it is not a strict requirement. 0212 * The default implementation returns @c nullptr. 0213 * @see perProjectConfigPages(), ProjectConfigPage 0214 */ 0215 virtual ConfigPage* configPage(int number, QWidget *parent); 0216 0217 /** 0218 * Get the number of available config pages for global settings. 0219 * @return number of global config pages. The default implementation returns zero. 0220 * @see configPage() 0221 */ 0222 virtual int configPages() const; 0223 0224 /** 0225 * Get the number of available config pages for per project settings. 0226 * @return number of per project config pages. The default implementation returns zero. 0227 * @see perProjectConfigPage() 0228 */ 0229 virtual int perProjectConfigPages() const; 0230 0231 /** 0232 * Get the per project config page with the \p number, config pages from 0 to 0233 * perProjectConfigPages()-1 are available if perProjectConfigPages() > 0. 0234 * 0235 * @param number index of config page 0236 * @param options The options used to initialize the ProjectConfigPage 0237 * @param parent parent widget for config page 0238 * @return newly created config page or NULL, if the number is out of bounds, default implementation returns NULL. 0239 * This config page should inherit from ProjectConfigPage, but it is not a strict requirement. 0240 * The default implementation returns @c nullptr. 0241 * @see perProjectConfigPages(), ProjectConfigPage 0242 */ 0243 virtual ConfigPage* perProjectConfigPage(int number, const KDevelop::ProjectConfigOptions& options, QWidget* parent); 0244 0245 protected: 0246 /** 0247 * Initialize the XML GUI State. 0248 */ 0249 virtual void initializeGuiState(); 0250 0251 private: 0252 const QScopedPointer<class IPluginPrivate> d_ptr; 0253 Q_DECLARE_PRIVATE(IPlugin) 0254 friend class IPluginPrivate; 0255 }; 0256 0257 } 0258 0259 #endif