File indexing completed on 2024-04-14 15:51:35

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