aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/qqmlpluginimporter_p.h
blob: b0056e8e33043148ed8e092702d3058b3752fe05 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Copyright (C) 2021 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#ifndef QQMLPLUGINIMPORTER_P_H
#define QQMLPLUGINIMPORTER_P_H

//
//  W A R N I N G
//  -------------
//
// This file is not part of the Qt API.  It exists purely as an
// implementation detail.  This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//

#include <private/qtqmlglobal_p.h>
#include <private/qqmlimport_p.h>
#include <private/qqmltypeloaderqmldircontent_p.h>

#include <QtCore/qjsonarray.h>
#include <QtCore/qplugin.h>
#include <QtCore/qversionnumber.h>

QT_BEGIN_NAMESPACE

class QQmlPluginImporter
{
    Q_DISABLE_COPY_MOVE(QQmlPluginImporter)

public:
    QQmlPluginImporter(const QString &uri, QTypeRevision version, QQmlImportDatabase *database,
                   const QQmlTypeLoaderQmldirContent *qmldir, QQmlTypeLoader *typeLoader,
                   QList<QQmlError> *errors)
        : uri(uri)
        , qmldirPath(truncateToDirectory(qmldir->qmldirLocation()))
        , qmldir(qmldir)
        , database(database)
        , typeLoader(typeLoader)
        , errors(errors)
        , version(version)
    {}

    ~QQmlPluginImporter() = default;

    QTypeRevision importDynamicPlugin(
            const QString &filePath, const QString &pluginId, bool optional);
    QTypeRevision importStaticPlugin(QObject *instance, const QString &pluginId);
    QTypeRevision importPlugins();

    static bool removePlugin(const QString &pluginId);
    static QStringList plugins();

private:
    struct StaticPluginData {
        QStaticPlugin plugin;
        QJsonArray uriList;
    };

    static QString truncateToDirectory(const QString &qmldirFilePath);
    bool populatePluginDataVector(QVector<StaticPluginData> &result,
                                  const QStringList &versionUris);

    QString resolvePlugin(const QString &qmldirPluginPath, const QString &baseName);
    void finalizePlugin(QObject *instance, const QString &path);

    const QString uri;
    const QString qmldirPath;

    const QQmlTypeLoaderQmldirContent *qmldir = nullptr;
    QQmlImportDatabase *database = nullptr;
    QQmlTypeLoader *typeLoader = nullptr;
    QList<QQmlError> *errors = nullptr;

    const QTypeRevision version;
};

QT_END_NAMESPACE

#endif // QQMLPLUGINIMPORTER_P_H