1 | // Copyright (C) 2021 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 |
3 | #ifndef QQMLJSRESOURCEFILEMAPPER_P_H |
4 | #define QQMLJSRESOURCEFILEMAPPER_P_H |
5 | |
6 | // |
7 | // W A R N I N G |
8 | // ------------- |
9 | // |
10 | // This file is not part of the Qt API. It exists purely as an |
11 | // implementation detail. This header file may change from version to |
12 | // version without notice, or even be removed. |
13 | // |
14 | // We mean it. |
15 | |
16 | #include <private/qtqmlcompilerexports_p.h> |
17 | |
18 | #include <QStringList> |
19 | #include <QHash> |
20 | #include <QFile> |
21 | #include <private/qglobal_p.h> |
22 | |
23 | QT_BEGIN_NAMESPACE |
24 | |
25 | struct Q_QMLCOMPILER_PRIVATE_EXPORT QQmlJSResourceFileMapper |
26 | { |
27 | struct Entry |
28 | { |
29 | QString resourcePath; |
30 | QString filePath; |
31 | bool isValid() const { return !resourcePath.isEmpty() && !filePath.isEmpty(); } |
32 | }; |
33 | |
34 | enum FilterMode { |
35 | File = 0x0, // Default is local (non-directory) file, without recursion |
36 | Directory = 0x1, // Directory, either local or resource |
37 | Resource = 0x2, // Resource path, either to file or directory |
38 | Recurse = 0x4, // Recurse into subdirectories if Directory |
39 | }; |
40 | Q_DECLARE_FLAGS(FilterFlags, FilterMode); |
41 | |
42 | struct Filter { |
43 | QString path; |
44 | QStringList suffixes; |
45 | FilterFlags flags; |
46 | }; |
47 | |
48 | static Filter allQmlJSFilter(); |
49 | static Filter localFileFilter(const QString &file); |
50 | static Filter resourceFileFilter(const QString &file); |
51 | static Filter resourceQmlDirectoryFilter(const QString &directory); |
52 | |
53 | QQmlJSResourceFileMapper(const QStringList &resourceFiles); |
54 | |
55 | bool isEmpty() const; |
56 | bool isFile(const QString &resourcePath) const; |
57 | |
58 | QList<Entry> filter(const Filter &filter) const; |
59 | QStringList filePaths(const Filter &filter) const; |
60 | QStringList resourcePaths(const Filter &filter) const; |
61 | Entry entry(const Filter &filter) const; |
62 | |
63 | private: |
64 | void populateFromQrcFile(QFile &file); |
65 | |
66 | QList<Entry> qrcPathToFileSystemPath; |
67 | }; |
68 | |
69 | Q_DECLARE_OPERATORS_FOR_FLAGS(QQmlJSResourceFileMapper::FilterFlags); |
70 | |
71 | QT_END_NAMESPACE |
72 | |
73 | #endif // QMLJSRESOURCEFILEMAPPER_P_H |
74 | |