Warning, file /office/calligra/libs/plugin/KoPluginLoader.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /* This file is part of the KDE project
0002  * Copyright (c) 2006 Boudewijn Rempt (boud@valdyas.org)
0003  * Copyright (c) 2016 Friedrich W. H. Kossebau <kossebau@kde.org>
0004  *
0005  * This library is free software; you can redistribute it and/or
0006  * modify it under the terms of the GNU Library General Public
0007  * License as published by the Free Software Foundation; either
0008  * version 2 of the License, or (at your option) any later version.
0009  *
0010  * This library is distributed in the hope that it will be useful,
0011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0013  * Library General Public License for more details.
0014  *
0015  * You should have received a copy of the GNU Library General Public License
0016  * along with this library; see the file COPYING.LIB.  If not, write to
0017  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0018  * Boston, MA 02110-1301, USA.
0019  */
0020 
0021 #ifndef KO_PLUGIN_LOADER_H
0022 #define KO_PLUGIN_LOADER_H
0023 
0024 #include <QStringList>
0025 
0026 #include "koplugin_export.h"
0027 
0028 class QObject;
0029 class QPluginLoader;
0030 class KPluginFactory;
0031 
0032 /**
0033  * The pluginloader singleton is responsible for loading the plugins
0034  * that it's asked to load. It keeps track of which servicetypes it
0035  * has seen and doesn't reload them. The plugins need to inherit
0036  * a QObject with a default constructor. Inside the default
0037  * constructor you can create whatever object you want and add it to
0038  * whatever registry you prefer. After having been constructed, your plugin
0039  * will be deleted, so do all you need in the constructor.  Things like
0040  * adding a factory to a registry make sense there.
0041  * Example header file;
0042  * @code
0043  * #include <QObject>
0044  * 
0045  * class MyPlugin : public QObject {
0046  *    Q_OBJECT
0047  * public:
0048  *    MyPlugin(QObject *parent, const QVariantList & );
0049  *    ~MyPlugin() {}
0050  * };
0051  * @endcode
0052  * Example cpp file;
0053  * @code
0054  * #include "MyPlugin.h"
0055  * #include <kpluginfactory.h>
0056  * 
0057  * K_PLUGIN_FACTORY_WITH_JSON(MyPluginFactory, "myplugin.json", registerPlugin<MyPlugin>();)
0058  * 
0059  * MyPlugin::MyPlugin( QObject *parent, const QVariantList& ) : QObject(parent) {
0060  *    // do stuff like creating a factory and adding it to the
0061  *    // registry instance.
0062  * }
0063  * #include <MyPlugin.moc>
0064  * @endcode
0065  */
0066 namespace KoPluginLoader
0067 {
0068     /**
0069      * Config object for load()
0070      * It is possible to limit which plugins will be loaded in the KConfig configuration file by
0071      * stating explicitly which plugins are wanted.
0072      */
0073     struct KOPLUGIN_EXPORT PluginsConfig {
0074         PluginsConfig() : group(0), whiteList(0), blacklist(0) {}
0075         /**
0076          * The properties are retrieved from the config using the following construct;
0077          * /code
0078          *  KConfigGroup configGroup =  KSharedConfig::openConfig()->group(config.group);
0079          * /endcode
0080          * For most cases you can pass the string "calligra" into this variable.
0081          */
0082         const char * group;
0083         /// This contains the variable name for the list of plugins (by library name) the user wants to load
0084         const char * whiteList;
0085         /// This contains the variable name for the list of plugins (by library name) that will not be loaded
0086         const char * blacklist;
0087         /// A registry can state it wants to load a default set of plugins instead of all plugins
0088         /// when the application starts the first time.  Append all such plugin (library) names to this list.
0089         QStringList defaults;
0090     };
0091 
0092     /**
0093      * Load all plugins that are located in the specified directory,
0094      * for instance:
0095      * KoPluginLoader::load(QStringLiteral("calligra/flakes"));
0096      * If you pass a PluginsConfig struct only those plugins are loaded that are specified in the
0097      * application config file.  New plugins found since last start will be automatically loaded.
0098      * @param directory The directory to search for plugins, as relative path.
0099      * All entries of QCoreApplication::libraryPaths() will be checked with @p directory appended as a
0100      * subdirectory.
0101      * @param config when passing a valid config only the wanted plugins are actually loaded
0102      * @param owner QObject owner
0103      * @return a list of services (by library name) that were not know in the config
0104      */
0105     KOPLUGIN_EXPORT void load(const QString & directory, const PluginsConfig &config = PluginsConfig(), QObject* owner = 0);
0106 
0107     /**
0108      * Load all plugins that are located in the specified directory and return their KPluginFactory objects.
0109      * @param directory The directory to search for plugins, as relative path.
0110      * All entries of QCoreApplication::libraryPaths() will be checked with @p directory appended as a
0111      * subdirectory.
0112      * @return a list of plugin factories from the found plugins matching the servicetype
0113      */
0114     KOPLUGIN_EXPORT QList<KPluginFactory *> instantiatePluginFactories(const QString & directory);
0115 
0116     /**
0117      * Creates and returns pluginLoaders for all plugins that are located in the specified directory.
0118      * @param directory The directory to search for plugins, as relative path.
0119      * All entries of QCoreApplication::libraryPaths() will be checked with @p directory appended as a
0120      * subdirectory.
0121      * @param mimeType The string used to identify the plugins.
0122      * @return a list of plugin loaders from the found plugins matching the mimetype, ownership is transferred to the caller
0123      */
0124     KOPLUGIN_EXPORT QList<QPluginLoader *> pluginLoaders(const QString &directory, const QString &mimeType = QString());
0125 }
0126 
0127 #endif // KO_PLUGIN_LOADER_H