File indexing completed on 2024-05-12 04:58:17
0001 /* ============================================================ 0002 * Falkon - Qt web browser 0003 * Copyright (C) 2010-2018 David Rosca <nowrep@gmail.com> 0004 * 0005 * This program is free software: you can redistribute it and/or modify 0006 * it under the terms of the GNU General Public License as published by 0007 * the Free Software Foundation, either version 3 of the License, or 0008 * (at your option) any later version. 0009 * 0010 * This program 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 0013 * GNU General Public License for more details. 0014 * 0015 * You should have received a copy of the GNU General Public License 0016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0017 * ============================================================ */ 0018 #ifndef PLUGINLOADER_H 0019 #define PLUGINLOADER_H 0020 0021 #include <QObject> 0022 #include <QVariant> 0023 #include <QPointer> 0024 #include <QPixmap> 0025 0026 #include "qzcommon.h" 0027 #include "plugininterface.h" 0028 0029 class QLibrary; 0030 class QPluginLoader; 0031 0032 class SpeedDial; 0033 0034 struct PluginSpec { 0035 QString name; 0036 QString description; 0037 QString author; 0038 QString version; 0039 QPixmap icon; 0040 bool hasSettings = false; 0041 0042 bool operator==(const PluginSpec &other) const { 0043 return (this->name == other.name && 0044 this->description == other.description && 0045 this->author == other.author && 0046 this->version == other.version); 0047 } 0048 }; 0049 0050 class FALKON_EXPORT Plugins : public QObject 0051 { 0052 Q_OBJECT 0053 public: 0054 struct Plugin { 0055 enum Type { 0056 Invalid = 0, 0057 InternalPlugin, 0058 SharedLibraryPlugin, 0059 PythonPlugin, 0060 QmlPlugin 0061 }; 0062 Type type = Invalid; 0063 QString pluginId; 0064 QString pluginPath; 0065 PluginSpec pluginSpec; 0066 PluginInterface *instance = nullptr; 0067 0068 // InternalPlugin 0069 PluginInterface *internalInstance = nullptr; 0070 0071 // SharedLibraryPlugin 0072 QPluginLoader *pluginLoader = nullptr; 0073 0074 // Other 0075 QVariant data; 0076 0077 bool isLoaded() const; 0078 bool isRemovable() const; 0079 bool operator==(const Plugin &other) const; 0080 }; 0081 0082 explicit Plugins(QObject* parent = nullptr); 0083 0084 QList<Plugin> availablePlugins(); 0085 0086 bool loadPlugin(Plugin* plugin); 0087 void unloadPlugin(Plugin* plugin); 0088 void removePlugin(Plugin *plugin); 0089 0090 bool addPlugin(const QString &id); 0091 0092 void shutdown(); 0093 0094 // SpeedDial 0095 SpeedDial* speedDial() { return m_speedDial; } 0096 0097 static PluginSpec createSpec(const QJsonObject &metaData); 0098 static PluginSpec createSpec(const DesktopFile &metaData); 0099 0100 public Q_SLOTS: 0101 void loadSettings(); 0102 0103 void loadPlugins(); 0104 0105 protected: 0106 QList<PluginInterface*> m_loadedPlugins; 0107 0108 Q_SIGNALS: 0109 void pluginUnloaded(PluginInterface* plugin); 0110 void availablePluginsChanged(); 0111 0112 private: 0113 void loadPythonSupport(); 0114 Plugin loadPlugin(const QString &id); 0115 Plugin loadInternalPlugin(const QString &name); 0116 Plugin loadSharedLibraryPlugin(const QString &name); 0117 Plugin loadPythonPlugin(const QString &name); 0118 bool initPlugin(PluginInterface::InitState state, Plugin *plugin); 0119 void initInternalPlugin(Plugin *plugin); 0120 void initSharedLibraryPlugin(Plugin *plugin); 0121 void initPythonPlugin(Plugin *plugin); 0122 0123 void registerAvailablePlugin(const Plugin &plugin); 0124 0125 void refreshLoadedPlugins(); 0126 void loadAvailablePlugins(); 0127 0128 QList<Plugin> m_availablePlugins; 0129 QStringList m_allowedPlugins; 0130 0131 bool m_pluginsLoaded; 0132 0133 SpeedDial* m_speedDial; 0134 QList<PluginInterface*> m_internalPlugins; 0135 0136 QLibrary *m_pythonPlugin = nullptr; 0137 }; 0138 0139 Q_DECLARE_METATYPE(Plugins::Plugin) 0140 0141 #endif // PLUGINLOADER_H