| 1 | // Copyright (C) 2020 The Qt Company Ltd. |
| 2 | // Copyright (C) 2019 Intel Corporation. |
| 3 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 4 | // Qt-Security score:significant reason:default |
| 5 | |
| 6 | #ifndef QRESOURCE_H |
| 7 | #define QRESOURCE_H |
| 8 | |
| 9 | #include <QtCore/qstring.h> |
| 10 | #include <QtCore/qlocale.h> |
| 11 | #include <QtCore/qstringlist.h> |
| 12 | #include <QtCore/qlist.h> |
| 13 | #include <QtCore/qscopedpointer.h> |
| 14 | |
| 15 | QT_BEGIN_NAMESPACE |
| 16 | |
| 17 | |
| 18 | class QResourcePrivate; |
| 19 | |
| 20 | class Q_CORE_EXPORT QResource |
| 21 | { |
| 22 | public: |
| 23 | enum Compression { |
| 24 | NoCompression, |
| 25 | ZlibCompression, |
| 26 | ZstdCompression |
| 27 | }; |
| 28 | |
| 29 | QResource(const QString &file = QString(), const QLocale &locale = QLocale()); |
| 30 | ~QResource(); |
| 31 | |
| 32 | void setFileName(const QString &file); |
| 33 | QString fileName() const; |
| 34 | QString absoluteFilePath() const; |
| 35 | |
| 36 | void setLocale(const QLocale &locale); |
| 37 | QLocale locale() const; |
| 38 | |
| 39 | bool isValid() const; |
| 40 | |
| 41 | Compression compressionAlgorithm() const; |
| 42 | qint64 size() const; |
| 43 | const uchar *data() const; |
| 44 | qint64 uncompressedSize() const; |
| 45 | QByteArray uncompressedData() const; |
| 46 | QDateTime lastModified() const; |
| 47 | |
| 48 | static bool registerResource(const QString &rccFilename, const QString &resourceRoot=QString()); |
| 49 | static bool unregisterResource(const QString &rccFilename, const QString &resourceRoot=QString()); |
| 50 | |
| 51 | static bool registerResource(const uchar *rccData, const QString &resourceRoot=QString()); |
| 52 | static bool unregisterResource(const uchar *rccData, const QString &resourceRoot=QString()); |
| 53 | |
| 54 | protected: |
| 55 | friend class QResourceFileEngine; |
| 56 | friend class QResourceFileEngineIterator; |
| 57 | bool isDir() const; |
| 58 | inline bool isFile() const { return !isDir(); } |
| 59 | QStringList children() const; |
| 60 | |
| 61 | protected: |
| 62 | QScopedPointer<QResourcePrivate> d_ptr; |
| 63 | |
| 64 | private: |
| 65 | Q_DECLARE_PRIVATE(QResource) |
| 66 | }; |
| 67 | |
| 68 | QT_END_NAMESPACE |
| 69 | |
| 70 | #endif // QRESOURCE_H |
| 71 | |