File indexing completed on 2024-04-28 13:44:26

0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 // SPDX-FileCopyrightText: 2007 Dominik Seichter <domseichter@web.de>
0003 
0004 #ifndef PLUGIN_LOADER_H
0005 #define PLUGIN_LOADER_H
0006 
0007 #include <QHash>
0008 #include <QList>
0009 #include <QMap>
0010 
0011 class Plugin;
0012 class KConfigGroup;
0013 class KRenameImpl;
0014 
0015 class PluginLoader
0016 {
0017 public:
0018     ~PluginLoader();
0019 
0020     static PluginLoader *Instance();
0021 
0022     /** Find a plugin that supports a certain token
0023      *
0024      *  This works only for plugins of the type ePluginType_Token
0025      *
0026      *  @param token a token
0027      *  @returns a plugin or NULL
0028      */
0029     Plugin *findPlugin(const QString &token);
0030 
0031     /** Find a plugin by its name
0032      *
0033      *  @param name as returned by Plugin::name()
0034      *  @returns a plugin or NULL
0035      */
0036     Plugin *findPluginByName(const QString &name);
0037 
0038     /** A read-only list of all plugins
0039      *
0040      *  @returns a list of all plugins;
0041      */
0042     inline const QList<Plugin *> &plugins() const
0043     {
0044         return m_plugins;
0045     }
0046 
0047     /** This maybe called by plugins,
0048      *  if a setting in their UI was changed
0049      *  so that the preview in KRename
0050      *  should be updated.
0051      */
0052     void sendUpdatePreview();
0053 
0054     /** Save the plugin configuration.
0055      *
0056      *  Called when plugins should save their configuration.
0057      *
0058      *  @param group config group where the configuration should be stored
0059      */
0060     void saveConfig(KConfigGroup &group);
0061 
0062     /** Load the plugin configuration.
0063      *
0064      *  Called when plugins should load their configuration.
0065      *
0066      *  @param group config group where the configuration should be read from
0067      */
0068     void loadConfig(KConfigGroup &group);
0069 
0070     void registerForUpdates(KRenameImpl *kreanme);
0071     void deregisterForUpdates(KRenameImpl *kreanme);
0072 
0073 private:
0074     PluginLoader();
0075 
0076     /** Clear the plugin loader.
0077      *  I.e reset the object to its initial state and unload all plugins
0078      */
0079     void clear();
0080 
0081     /** Load all plugins
0082      */
0083     void load();
0084 
0085 private:
0086 
0087     static PluginLoader *s_instance;     ///< The handle to the only pluginloader instance
0088     QList<Plugin *>       m_plugins;     ///< The list of all plugins
0089 
0090     QMap<QString, Plugin *>  m_tokenMap; ///< All supported tokens in brackets are listed here
0091     QHash<QString, Plugin *> m_tokenCache; ///< All used tokens are listed here
0092 
0093     QList<KRenameImpl *>  m_observers;   ///< A list of KRenameImpls that should be notified on updates
0094 };
0095 
0096 #endif // PLUGIN_LOADER_H