File indexing completed on 2025-01-19 03:55:36

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2018-07-30
0007  * Description : manager to load external plugins at run-time
0008  *
0009  * SPDX-FileCopyrightText: 2018-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0010  *
0011  * SPDX-License-Identifier: GPL-2.0-or-later
0012  *
0013  * ============================================================ */
0014 
0015 #ifndef DIGIKAM_DPLUGIN_LOADER_H
0016 #define DIGIKAM_DPLUGIN_LOADER_H
0017 
0018 // Qt includes
0019 
0020 #include <QObject>
0021 #include <QList>
0022 
0023 // Local includes
0024 
0025 #include "digikam_export.h"
0026 #include "dinfointerface.h"
0027 #include "dplugin.h"
0028 #include "dpluginaction.h"
0029 #include "dimgloadersettings.h"
0030 
0031 namespace Digikam
0032 {
0033 
0034 /**
0035  * @short The class that handles digiKam's external plugins.
0036  *
0037  * Ownership policy for plugins:
0038  *
0039  * The DPluginLoader creates new objects and transfer ownership.
0040  * In order to create the objects, the DPluginLoader internally has a list of the tools
0041  * which are owned by the DPluginLoader and destroyed by it.
0042  */
0043 class DIGIKAM_EXPORT DPluginLoader : public QObject
0044 {
0045     Q_OBJECT
0046 
0047  public:
0048 
0049     /**
0050      * @brief instance: returns the singleton of plugin loader
0051      * @return DPluginLoader global instance
0052      */
0053     static DPluginLoader* instance();
0054 
0055     /**
0056      * Return the config group name used to store the list of plugins to load at startup.
0057      */
0058     QString configGroupName() const;
0059 
0060     /**
0061      * Register all Generic plugin actions to parent object.
0062      */
0063     void registerGenericPlugins(QObject* const parent);
0064 
0065     /**
0066      * Register all Editor plugin actions to parent object.
0067      */
0068     void registerEditorPlugins(QObject* const parent);
0069 
0070     /**
0071      * Register all Raw Import plugin to parent object.
0072      */
0073     void registerRawImportPlugins(QObject* const parent);
0074 
0075     /**
0076      * Init plugin loader. Call this method to parse and load relevant plugins installed on your system.
0077      */
0078     void init();
0079 
0080      /**
0081      * Unload all loaded plugins. Call this method before the main instance is closed.
0082      */
0083     void cleanUp();
0084 
0085     /**
0086      * @brief Returns all available plugins.
0087      */
0088     QList<DPlugin*> allPlugins() const;
0089 
0090     /**
0091      * @brief Returns a list of plugin actions set as type for a given parent.
0092      *        If no plugin have found in this category, this returns an empty list.
0093      */
0094     QList<DPluginAction*> pluginsActions(DPluginAction::ActionType type, QObject* const parent) const;
0095 
0096     /**
0097      * @brief Returns a list of plugin actions set as category for a given parent.
0098      *        If no plugin have found in this category, this returns an empty list.
0099      */
0100     QList<DPluginAction*> pluginsActions(DPluginAction::ActionCategory cat, QObject* const parent) const;
0101 
0102     /**
0103      * @brief Returns the plugin actions corresponding to a plugin internal ID string for a given parent.
0104      *        If not found, this returns an empty list.
0105      */
0106     QList<DPluginAction*> pluginActions(const QString& pluginIID, QObject* const parent) const;
0107 
0108     /**
0109      * @brief Returns the plugin action corresponding to a action name for a given parent.
0110      *        If not found, this returns a null pointer.
0111      */
0112     DPluginAction* pluginAction(const QString& actionName, QObject* const parent) const;
0113 
0114     /**
0115      * @brief Returns all xml sections as string of plugin actions set with a kind of category for a given parent.
0116      */
0117     QString pluginXmlSections(DPluginAction::ActionCategory cat, QObject* const parent) const;
0118 
0119     /**
0120      * @brief appendPluginToBlackList Prevent that a plugin is loaded from the given filename
0121      * @param filename The name of the file excluding file extension to blacklist. E.g.
0122      * to ignore "HtmlGalleryPlugin.so" on Linux and "HtmlGalleryPlugin.dll" on Windows, pass "HtmlGalleryPlugin"
0123      */
0124     void appendPluginToBlackList(const QString& filename);
0125 
0126     /**
0127      * @brief appendPluginToWhiteList Add a plugin to the whitelist of tools. If the whitelist is not
0128      * empty, only whitelisted tools are loaded. If a tool is both whitelisted and blacklisted,
0129      * it will not be loaded.
0130      * @param filename The name of the file excluding file extension to whitelist. E.g.
0131      * to not ignore "HtmlGalleryPlugin.so" on Linux and "HtmlGalleryPlugin.dll" on Windows, pass "HtmlGalleryPlugin"
0132      */
0133     void appendPluginToWhiteList(const QString& filename);
0134 
0135     /**
0136      * Return true if format is supported by a DPluginDImg to import image.
0137      */
0138     bool canImport(const QString& format) const;
0139 
0140     /**
0141      * Return true if format is supported by a DPluginDImg to export image.
0142      */
0143     bool canExport(const QString& format) const;
0144 
0145     /**
0146      * Return a new widget instance from a DPluginDImg to show settings while exporting image to specified format.
0147      * Return nullptr if format is not supported or if no settings widget is available for this format.
0148      */
0149     DImgLoaderSettings* exportWidget(const QString& format) const;
0150 
0151 private:
0152 
0153     // Disable constructor and destructor
0154     DPluginLoader();
0155     explicit DPluginLoader(QObject*);
0156     ~DPluginLoader() override;
0157 
0158     Q_DISABLE_COPY(DPluginLoader)
0159 
0160     class Private;
0161     Private* const d;
0162 
0163     friend class DPluginLoaderCreator;
0164 };
0165 
0166 } // namespace Digikam
0167 
0168 #endif // DIGIKAM_DPLUGIN_LOADER_H