aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/qmldesigner/components/contentlibrary/contentlibrarybundleimporter.h
blob: 02ccf3263e75bbbb6a55100756efad122c3cd61f (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
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0

#pragma once

#include <utils/filepath.h>

#include "nodemetainfo.h"

#include <QTimer>
#include <QVariantHash>

QT_BEGIN_NAMESPACE
QT_END_NAMESPACE

namespace QmlDesigner::Internal {

class ContentLibraryBundleImporter : public QObject
{
    Q_OBJECT

public:
    ContentLibraryBundleImporter(const QString &bundleDir,
                                 const QString &bundleId,
                                 const QStringList &sharedFiles,
                                 QObject *parent = nullptr);
    ~ContentLibraryBundleImporter() = default;

    QString importComponent(const QString &qmlFile,
                            const QStringList &files);
    QString unimportComponent(const QString &qmlFile);
    Utils::FilePath resolveBundleImportPath();

signals:
    // The metaInfo parameter will be invalid if an error was encountered during
    // asynchronous part of the import. In this case all remaining pending imports have been
    // terminated, and will not receive separate importFinished notifications.
    void importFinished(const QmlDesigner::NodeMetaInfo &metaInfo);
    void unimportFinished(const QmlDesigner::NodeMetaInfo &metaInfo);

private:
    void handleImportTimer();
    QVariantHash loadAssetRefMap(const Utils::FilePath &bundlePath);
    void writeAssetRefMap(const Utils::FilePath &bundlePath, const QVariantHash &assetRefMap);

    Utils::FilePath m_bundleDir;
    QString m_bundleId;
    QString m_moduleName;
    QStringList m_sharedFiles;
    QTimer m_importTimer;
    int m_importTimerCount = 0;
    bool m_importAddPending = false;
    bool m_fullReset = false;
    QHash<QString, bool> m_pendingTypes; // <type, isImport>
};

} // namespace QmlDesigner::Internal