File indexing completed on 2024-04-14 03:48:01

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2006-2008 Torsten Rahn <tackat@kde.org>
0004 // SPDX-FileCopyrightText: 2009 Jens-Michael Hoffmann <jensmh@gmx.de>
0005 //
0006 
0007 #ifndef MARBLE_PLUGINMANAGER_H
0008 #define MARBLE_PLUGINMANAGER_H
0009 
0010 #include <QObject>
0011 #include <QList>
0012 #include "marble_export.h"
0013 
0014 
0015 namespace Marble
0016 {
0017 
0018 class RenderPlugin;
0019 class PositionProviderPlugin;
0020 class PluginManagerPrivate;
0021 class SearchRunnerPlugin;
0022 class ReverseGeocodingRunnerPlugin;
0023 class RoutingRunnerPlugin;
0024 class ParseRunnerPlugin;
0025 
0026 /**
0027  * @short The class that handles Marble's plugins.
0028  *
0029  * Ownership policy for plugins:
0030  *
0031  * On every invocation of createNetworkPlugins and
0032  * createFloatItems the PluginManager creates new objects and transfers
0033  * ownership to the calling site. In order to create
0034  * the objects, the PluginManager internally has a list of the plugins
0035  * which are owned by the PluginManager and destroyed by it.
0036  *
0037  */
0038 
0039 class MARBLE_EXPORT PluginManager : public QObject
0040 {
0041     Q_OBJECT
0042 
0043  public:
0044     explicit PluginManager( QObject* parent = nullptr );
0045 
0046     ~PluginManager() override;
0047 
0048     /**
0049      * @brief Returns all available RenderPlugins.
0050      *
0051      * Ownership of the items remains in PluginManager.
0052      * In order to use the RenderPlugins, first create new instances using
0053      * RenderPlugin::newInstance().
0054      */
0055     QList<const RenderPlugin *> renderPlugins() const;
0056 
0057     /**
0058      * @brief Add a RenderPlugin manually to the list of known plugins. Normally you
0059      * don't need to call this method since all plugins are loaded automatically.
0060      * @param plugin The plugin to add. Ownership retains with the caller.
0061      */
0062     void addRenderPlugin( const RenderPlugin *plugin );
0063 
0064     /**
0065      * @brief Returns all available PositionProviderPlugins.
0066      *
0067      * Ownership of the items remains in PluginManager.
0068      * In order to use the PositionProviderPlugins, first create new instances using
0069      * PositionProviderPlugin::newInstance().
0070      */
0071     QList<const PositionProviderPlugin *> positionProviderPlugins() const;
0072 
0073     /**
0074      * @brief Add a PositionProviderPlugin manually to the list of known plugins. Normally you
0075      * don't need to call this method since all plugins are loaded automatically.
0076      * @param plugin The plugin to add. Ownership retains with the caller.
0077      */
0078     void addPositionProviderPlugin( const PositionProviderPlugin *plugin );
0079 
0080     /**
0081      * Returns all search runner plugins.
0082      * @note: Runner plugins are owned by the PluginManager, do not delete them.
0083      */
0084     QList<const SearchRunnerPlugin *> searchRunnerPlugins() const;
0085 
0086     /**
0087      * @brief Add a SearchRunnerPlugin manually to the list of known plugins. Normally you
0088      * don't need to call this method since all plugins are loaded automatically.
0089      * @param plugin The plugin to add. Ownership retains with the caller.
0090      */
0091     void addSearchRunnerPlugin( const SearchRunnerPlugin *plugin );
0092 
0093     /**
0094      * Returns all reverse geocoding runner plugins.
0095      * @note: The runner plugins are owned by the PluginManager, do not delete them.
0096      */
0097     QList<const ReverseGeocodingRunnerPlugin *> reverseGeocodingRunnerPlugins() const;
0098 
0099     /**
0100      * @brief Add a ReverseGeocodingRunnerPlugin manually to the list of known plugins. Normally you
0101      * don't need to call this method since all plugins are loaded automatically.
0102      * @param plugin The plugin to add. Ownership retains with the caller.
0103      */
0104     void addReverseGeocodingRunnerPlugin( const ReverseGeocodingRunnerPlugin *plugin );
0105 
0106     /**
0107      * Returns all routing runner plugins.
0108      * @note: The runner plugins are owned by the PluginManager, do not delete them.
0109      */
0110     QList<RoutingRunnerPlugin *> routingRunnerPlugins() const;
0111 
0112     /**
0113      * @brief Add a RoutingRunnerPlugin manually to the list of known plugins. Normally you
0114      * don't need to call this method since all plugins are loaded automatically.
0115      * @param plugin The plugin to add. Ownership retains with the caller.
0116      */
0117     void addRoutingRunnerPlugin( RoutingRunnerPlugin * plugin );
0118 
0119     /**
0120      * Returns all parse runner plugins.
0121      * @note: The runner plugins are owned by the PluginManager, do not delete them.
0122      */
0123     QList<const ParseRunnerPlugin *> parsingRunnerPlugins() const;
0124 
0125     /**
0126      * @brief Add a ParseRunnerPlugin manually to the list of known plugins. Normally you
0127      * don't need to call this method since all plugins are loaded automatically.
0128      * @param plugin The plugin to add. Ownership retains with the caller.
0129      */
0130     void addParseRunnerPlugin( const ParseRunnerPlugin *plugin );
0131 
0132     /**
0133      * @brief blacklistPlugin Prevent that a plugin is loaded from the given filename
0134      * @param filename The name of the file (excluding prefix and file extension) to blacklist. E.g.
0135      * to ignore "libWikipedia.so" on Linux and "Wikipedia.dll" on Windows, pass "Wikipedia"
0136      */
0137     static void blacklistPlugin(const QString &filename);
0138 
0139     /**
0140      * @brief whitelistPlugin Add a plugin to the whitelist of plugins. If the whitelist is not
0141      * empty, only whitelisted plugins are loaded. If a plugin is both whitelisted and blacklisted,
0142      * it will not be loaded
0143      * @param filename The name of the file (excluding prefix and file extension) to whitelist. E.g.
0144      * to ignore "libWikipedia.so" on Linux and "Wikipedia.dll" on Windows, pass "Wikipedia"
0145      */
0146     static void whitelistPlugin(const QString &filename);
0147 
0148 Q_SIGNALS:
0149     void renderPluginsChanged();
0150 
0151     void positionProviderPluginsChanged();
0152 
0153     void searchRunnerPluginsChanged();
0154 
0155     void reverseGeocodingRunnerPluginsChanged();
0156 
0157     void routingRunnerPluginsChanged();
0158 
0159     void parseRunnerPluginsChanged();
0160 
0161  private:
0162     Q_DISABLE_COPY( PluginManager )
0163 
0164 #ifdef Q_OS_ANDROID
0165     void installPluginsFromAssets() const;
0166 #endif
0167 
0168     PluginManagerPrivate  * const d;
0169 };
0170 
0171 }
0172 
0173 #endif