Falkon Develop
Cross-platform Qt-based web browser
plugins.h
Go to the documentation of this file.
1/* ============================================================
2* Falkon - Qt web browser
3* Copyright (C) 2010-2018 David Rosca <nowrep@gmail.com>
4*
5* This program is free software: you can redistribute it and/or modify
6* it under the terms of the GNU General Public License as published by
7* the Free Software Foundation, either version 3 of the License, or
8* (at your option) any later version.
9*
10* This program is distributed in the hope that it will be useful,
11* but WITHOUT ANY WARRANTY; without even the implied warranty of
12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13* GNU General Public License for more details.
14*
15* You should have received a copy of the GNU General Public License
16* along with this program. If not, see <http://www.gnu.org/licenses/>.
17* ============================================================ */
18#ifndef PLUGINLOADER_H
19#define PLUGINLOADER_H
20
21#include <QObject>
22#include <QVariant>
23#include <QPointer>
24#include <QPixmap>
25
26#include "qzcommon.h"
27#include "plugininterface.h"
28
29class QLibrary;
30class QPluginLoader;
31
32class SpeedDial;
33
34struct PluginSpec {
35 QString name;
36 QString description;
37 QString author;
38 QString version;
39 QPixmap icon;
40 bool hasSettings = false;
41
42 bool operator==(const PluginSpec &other) const {
43 return (this->name == other.name &&
44 this->description == other.description &&
45 this->author == other.author &&
46 this->version == other.version);
47 }
48};
49
50class FALKON_EXPORT Plugins : public QObject
51{
52 Q_OBJECT
53public:
54 struct Plugin {
55 enum Type {
56 Invalid = 0,
61 };
62 Type type = Invalid;
63 QString pluginId;
64 QString pluginPath;
66 PluginInterface *instance = nullptr;
67
68 // InternalPlugin
69 PluginInterface *internalInstance = nullptr;
70
71 // SharedLibraryPlugin
72 QPluginLoader *pluginLoader = nullptr;
73
74 // Other
75 QVariant data;
76
77 bool isLoaded() const;
78 bool isRemovable() const;
79 bool operator==(const Plugin &other) const;
80 };
81
82 explicit Plugins(QObject* parent = nullptr);
83
84 QList<Plugin> availablePlugins();
85
86 bool loadPlugin(Plugin* plugin);
87 void unloadPlugin(Plugin* plugin);
88 void removePlugin(Plugin *plugin);
89
90 bool addPlugin(const QString &id);
91
92 void shutdown();
93
94 // SpeedDial
95 SpeedDial* speedDial() { return m_speedDial; }
96
97 static PluginSpec createSpec(const QJsonObject &metaData);
98 static PluginSpec createSpec(const DesktopFile &metaData);
99
100public Q_SLOTS:
101 void loadSettings();
102
103 void loadPlugins();
104
105protected:
106 QList<PluginInterface*> m_loadedPlugins;
107
108Q_SIGNALS:
111
112private:
113 void loadPythonSupport();
114 Plugin loadPlugin(const QString &id);
115 Plugin loadInternalPlugin(const QString &name);
116 Plugin loadSharedLibraryPlugin(const QString &name);
117 Plugin loadPythonPlugin(const QString &name);
118 bool initPlugin(PluginInterface::InitState state, Plugin *plugin);
119 void initInternalPlugin(Plugin *plugin);
120 void initSharedLibraryPlugin(Plugin *plugin);
121 void initPythonPlugin(Plugin *plugin);
122
123 void registerAvailablePlugin(const Plugin &plugin);
124
125 void refreshLoadedPlugins();
126 void loadAvailablePlugins();
127
128 QList<Plugin> m_availablePlugins;
129 QStringList m_allowedPlugins;
130
131 bool m_pluginsLoaded;
132
133 SpeedDial* m_speedDial;
134 QList<PluginInterface*> m_internalPlugins;
135
136 QLibrary *m_pythonPlugin = nullptr;
137};
138
140
141#endif // PLUGINLOADER_H
SpeedDial * speedDial()
Definition: plugins.h:95
void pluginUnloaded(PluginInterface *plugin)
void availablePluginsChanged()
QList< PluginInterface * > m_loadedPlugins
Definition: plugins.h:106
Q_DECLARE_METATYPE(FlashCookie)
State state
bool operator==(const HistoryEntry &x, const HistoryEntry &y)
Definition: qmlstaticdata.h:84
#define FALKON_EXPORT
Definition: qzcommon.h:28
bool hasSettings
Definition: plugins.h:40
QString version
Definition: plugins.h:38
bool operator==(const PluginSpec &other) const
Definition: plugins.h:42
QString name
Definition: plugins.h:35
QPixmap icon
Definition: plugins.h:39
QString description
Definition: plugins.h:36
QString author
Definition: plugins.h:37
QVariant data
Definition: plugins.h:75
QString pluginId
Definition: plugins.h:63
PluginSpec pluginSpec
Definition: plugins.h:65
QString pluginPath
Definition: plugins.h:64
@ SharedLibraryPlugin
Definition: plugins.h:58