File indexing completed on 2024-04-14 14:35:57
0001 /************************************************************************ 0002 * * 0003 * This file is part of Kooka, a scanning/OCR application using * 0004 * Qt <http://www.qt.io> and KDE Frameworks <http://www.kde.org>. * 0005 * * 0006 * Copyright (C) 2018 Jonathan Marten <jjm@keelhaul.me.uk> * 0007 * * 0008 * Kooka is free software; you can redistribute it and/or modify it * 0009 * under the terms of the GNU Library General Public License as * 0010 * published by the Free Software Foundation and appearing in the * 0011 * file COPYING included in the packaging of this file; either * 0012 * version 2 of the License, or (at your option) any later version. * 0013 * * 0014 * As a special exception, permission is given to link this program * 0015 * with any version of the KADMOS OCR/ICR engine (a product of * 0016 * reRecognition GmbH, Kreuzlingen), and distribute the resulting * 0017 * executable without including the source code for KADMOS in the * 0018 * source distribution. * 0019 * * 0020 * This program is distributed in the hope that it will be useful, * 0021 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0022 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0023 * GNU General Public License for more details. * 0024 * * 0025 * You should have received a copy of the GNU General Public * 0026 * License along with this program; see the file COPYING. If * 0027 * not, see <http://www.gnu.org/licenses/>. * 0028 * * 0029 ************************************************************************/ 0030 0031 #ifndef PLUGINMANAGER_H 0032 #define PLUGINMANAGER_H 0033 0034 #include "kookacore_export.h" 0035 0036 #include <qstring.h> 0037 #include <qmap.h> 0038 0039 0040 class AbstractPlugin; 0041 class AbstractPluginInfo; 0042 0043 0044 /** 0045 * @short Manages plugins 0046 * 0047 * @author Jonathan Marten 0048 **/ 0049 0050 class KOOKACORE_EXPORT PluginManager 0051 { 0052 public: 0053 enum PluginType 0054 { 0055 OcrPlugin, 0056 DestinationPlugin 0057 }; 0058 0059 /** 0060 * Get the singleton instance, creating it if necessary. 0061 * 0062 * @return the instance 0063 **/ 0064 static PluginManager *self(); 0065 0066 /** 0067 * Load and create an instance object for a plugin of the specified type. 0068 * 0069 * @param type The type of the plugin required 0070 * @param name The name of the plugin, or a null string to unload the plugin 0071 * @return A loaded plugin instance object of that type, 0072 * or @c nullptr if the specified @p name is null or if no plugin could 0073 * be found or loaded. 0074 * 0075 * @note Only one plugin of a particular type can be loaded; if a plugin 0076 * of the specified type already exists then it is unloaded and deleted. 0077 * 0078 * If a plugin is successfully loaded, it is available via @c currentPlugin(). 0079 **/ 0080 AbstractPlugin *loadPlugin(PluginManager::PluginType type, const QString &name); 0081 0082 /** 0083 * Enumerate (but do not load) all of the available plugins of a specified type. 0084 * 0085 * @param type The type of the plugins required 0086 * @return A map (name -> information) of all the plugins 0087 **/ 0088 QMap<QString,AbstractPluginInfo> allPlugins(PluginManager::PluginType type) const; 0089 0090 /** 0091 * Get the currently loaded instance of a plugin of the specified type. 0092 * 0093 * @param type The type of the plugin required 0094 * @return The loaded plugin instance object of that type, 0095 * or @c nullptr if no plugin of that type is currently loaded 0096 **/ 0097 AbstractPlugin *currentPlugin(PluginManager::PluginType type) const; 0098 0099 private: 0100 PluginManager(); 0101 ~PluginManager() = default; 0102 0103 QMap<PluginManager::PluginType,AbstractPlugin *> mLoadedPlugins; 0104 }; 0105 0106 #endif // PLUGINMANAGER_H