1 | // Copyright (C) 2021 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #ifndef QQMLPLUGINIMPORTER_P_H |
5 | #define QQMLPLUGINIMPORTER_P_H |
6 | |
7 | // |
8 | // W A R N I N G |
9 | // ------------- |
10 | // |
11 | // This file is not part of the Qt API. It exists purely as an |
12 | // implementation detail. This header file may change from version to |
13 | // version without notice, or even be removed. |
14 | // |
15 | // We mean it. |
16 | // |
17 | |
18 | #include <private/qtqmlglobal_p.h> |
19 | #include <private/qqmlimport_p.h> |
20 | #include <private/qqmltypeloaderqmldircontent_p.h> |
21 | |
22 | #include <QtCore/qjsonarray.h> |
23 | #include <QtCore/qplugin.h> |
24 | #include <QtCore/qversionnumber.h> |
25 | |
26 | QT_BEGIN_NAMESPACE |
27 | |
28 | class QQmlPluginImporter |
29 | { |
30 | Q_DISABLE_COPY_MOVE(QQmlPluginImporter) |
31 | |
32 | public: |
33 | QQmlPluginImporter(const QString &uri, QTypeRevision version, QQmlImportDatabase *database, |
34 | const QQmlTypeLoaderQmldirContent *qmldir, QQmlTypeLoader *typeLoader, |
35 | QList<QQmlError> *errors) |
36 | : uri(uri) |
37 | , qmldirPath(truncateToDirectory(qmldirFilePath: qmldir->qmldirLocation())) |
38 | , qmldir(qmldir) |
39 | , database(database) |
40 | , typeLoader(typeLoader) |
41 | , errors(errors) |
42 | , version(version) |
43 | {} |
44 | |
45 | ~QQmlPluginImporter() = default; |
46 | |
47 | QTypeRevision importDynamicPlugin( |
48 | const QString &filePath, const QString &pluginId, bool optional); |
49 | QTypeRevision importStaticPlugin(QObject *instance, const QString &pluginId); |
50 | QTypeRevision importPlugins(); |
51 | |
52 | static bool removePlugin(const QString &pluginId); |
53 | static QStringList plugins(); |
54 | |
55 | private: |
56 | struct StaticPluginData { |
57 | QStaticPlugin plugin; |
58 | QJsonArray uriList; |
59 | }; |
60 | |
61 | static QString truncateToDirectory(const QString &qmldirFilePath); |
62 | bool populatePluginDataVector(QVector<StaticPluginData> &result, |
63 | const QStringList &versionUris); |
64 | |
65 | QString resolvePlugin(const QString &qmldirPluginPath, const QString &baseName); |
66 | void finalizePlugin(QObject *instance, const QString &path); |
67 | |
68 | const QString uri; |
69 | const QString qmldirPath; |
70 | |
71 | const QQmlTypeLoaderQmldirContent *qmldir = nullptr; |
72 | QQmlImportDatabase *database = nullptr; |
73 | QQmlTypeLoader *typeLoader = nullptr; |
74 | QList<QQmlError> *errors = nullptr; |
75 | |
76 | const QTypeRevision version; |
77 | }; |
78 | |
79 | QT_END_NAMESPACE |
80 | |
81 | #endif // QQMLPLUGINIMPORTER_P_H |
82 | |