Changeset View
Changeset View
Standalone View
Standalone View
plugins/extensions/pykrita/plugin/PythonPluginManager.h
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * This file is part of PyKrita, Krita' Python scripting plugin. | ||||
3 | * | ||||
4 | * Copyright (C) 2013 Alex Turbov <i.zaufi@gmail.com> | ||||
5 | * Copyright (C) 2014-2016 Boudewijn Rempt <boud@valdyas.org> | ||||
6 | * Copyright (C) 2017 Jouni Pentikäinen (joupent@gmail.com) | ||||
7 | * | ||||
8 | * This library is free software; you can redistribute it and/or | ||||
9 | * modify it under the terms of the GNU Library General Public | ||||
10 | * License as published by the Free Software Foundation; either | ||||
11 | * version 2 of the License, or (at your option) any later version. | ||||
12 | * | ||||
13 | * This library is distributed in the hope that it will be useful, | ||||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
16 | * Library General Public License for more details. | ||||
17 | * | ||||
18 | * You should have received a copy of the GNU Library General Public License | ||||
19 | * along with this library; see the file COPYING.LIB. If not, write to | ||||
20 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||||
21 | * Boston, MA 02110-1301, USA. | ||||
22 | */ | ||||
23 | #ifndef PYTHONMODULEMANAGER_H | ||||
24 | #define PYTHONMODULEMANAGER_H | ||||
25 | | ||||
26 | #include <QObject> | ||||
27 | #include "version_checker.h" | ||||
28 | #include "PythonPluginsModel.h" | ||||
29 | | ||||
30 | class PythonPluginsModel; | ||||
31 | | ||||
32 | /** | ||||
33 | * Represents a Python described in the plugin's .desktop file. | ||||
34 | */ | ||||
35 | class PythonPlugin | ||||
36 | { | ||||
37 | public: | ||||
38 | /** | ||||
39 | * Transforms the Python module name into a file path part | ||||
40 | */ | ||||
41 | QString moduleFilePathPart() const; | ||||
42 | | ||||
43 | bool isValid() const; | ||||
44 | | ||||
45 | inline const QString& errorReason() const | ||||
46 | { | ||||
47 | return m_errorReason; | ||||
48 | } | ||||
49 | | ||||
50 | inline bool isEnabled() const | ||||
51 | { | ||||
52 | return m_enabled; | ||||
53 | } | ||||
54 | | ||||
55 | inline bool isBroken() const | ||||
56 | { | ||||
57 | return m_broken; | ||||
58 | } | ||||
59 | | ||||
60 | inline bool isUnstable() const | ||||
61 | { | ||||
62 | return m_unstable; | ||||
63 | } | ||||
64 | | ||||
65 | QString name() const | ||||
66 | { | ||||
67 | return m_name; | ||||
68 | } | ||||
69 | | ||||
70 | QString moduleName() const | ||||
71 | { | ||||
72 | return m_moduleName; | ||||
73 | } | ||||
74 | | ||||
75 | QVariant property(const QString &name) const | ||||
76 | { | ||||
77 | return m_properties.value(name, ""); | ||||
78 | } | ||||
79 | | ||||
80 | QString comment() const | ||||
81 | { | ||||
82 | return m_comment; | ||||
83 | } | ||||
84 | | ||||
85 | private: | ||||
86 | friend class PythonPluginManager; | ||||
87 | | ||||
88 | PythonPlugin() { | ||||
89 | m_properties["X-Python-Dependencies"] = QStringList(); | ||||
90 | m_properties["X-Python-2-Dependencies"] = QStringList(); | ||||
91 | } | ||||
92 | | ||||
93 | QString m_errorReason; | ||||
94 | bool m_enabled{false}; | ||||
95 | bool m_broken{false}; | ||||
96 | bool m_unstable{false}; | ||||
97 | bool m_loaded{false}; | ||||
98 | | ||||
99 | QString m_name; | ||||
100 | QString m_moduleName; | ||||
101 | QString m_comment; | ||||
102 | QMap<QString, QVariant> m_properties; | ||||
103 | }; | ||||
104 | | ||||
105 | /** | ||||
106 | * The Python plugin manager handles discovery, loading and unloading of Python plugins. | ||||
107 | * To get a reference to the manager, use PyKrita::pluginManager(). | ||||
108 | */ | ||||
109 | class PythonPluginManager : public QObject | ||||
110 | { | ||||
111 | Q_OBJECT | ||||
112 | | ||||
113 | public: | ||||
114 | PythonPluginManager(); | ||||
115 | | ||||
116 | const QList<PythonPlugin>& plugins() const; | ||||
117 | PythonPlugin *plugin(int index); | ||||
118 | | ||||
119 | void scanPlugins(); | ||||
120 | void tryLoadEnabledPlugins(); | ||||
121 | void setPluginEnabled(PythonPlugin &plugin, bool enabled); | ||||
122 | | ||||
123 | PythonPluginsModel *model(); | ||||
124 | | ||||
125 | public Q_SLOTS: | ||||
126 | void unloadAllModules(); | ||||
127 | | ||||
128 | private: | ||||
129 | void loadModule(PythonPlugin &plugin); | ||||
130 | void unloadModule(PythonPlugin &plugin); | ||||
131 | | ||||
132 | static bool verifyModuleExists(PythonPlugin &); | ||||
133 | static void verifyDependenciesSetStatus(PythonPlugin&); | ||||
134 | static QPair<QString, PyKrita::version_checker> parseDependency(const QString&); | ||||
135 | | ||||
136 | QList<PythonPlugin> m_plugins; | ||||
137 | | ||||
138 | PythonPluginsModel m_model; | ||||
139 | }; | ||||
140 | | ||||
141 | #endif //PYTHONMODULEMANAGER_H |