Changeset View
Changeset View
Standalone View
Standalone View
plugins/messageviewer/bodypartformatter/pkpass/pkpassfile.h
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | Copyright (c) 2017 Volker Krause <vkrause@kde.org> | ||||
3 | | ||||
4 | This library is free software; you can redistribute it and/or modify it | ||||
5 | under the terms of the GNU Library General Public License as published by | ||||
6 | the Free Software Foundation; either version 2 of the License, or (at your | ||||
7 | option) any later version. | ||||
8 | | ||||
9 | This library is distributed in the hope that it will be useful, but WITHOUT | ||||
10 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||||
11 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public | ||||
12 | License for more details. | ||||
13 | | ||||
14 | You should have received a copy of the GNU Library General Public License | ||||
15 | along with this library; see the file COPYING.LIB. If not, write to the | ||||
16 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||||
17 | 02110-1301, USA. | ||||
18 | */ | ||||
19 | | ||||
20 | #ifndef PKPASSFILE_H | ||||
21 | #define PKPASSFILE_H | ||||
22 | | ||||
23 | #include "pkpassfield.h" | ||||
24 | | ||||
25 | #include <QByteArray> | ||||
26 | #include <QHash> | ||||
27 | #include <QJsonObject> | ||||
28 | #include <QObject> | ||||
29 | #include <QVector> | ||||
30 | | ||||
31 | #include <memory> | ||||
32 | | ||||
33 | class KZip; | ||||
34 | class QBuffer; | ||||
35 | class QColor; | ||||
36 | class QLatin1String; | ||||
37 | class QString; | ||||
38 | | ||||
39 | /** Base class for a pkpass file. */ | ||||
40 | class PkPassFile : public QObject | ||||
41 | { | ||||
42 | Q_OBJECT | ||||
43 | Q_PROPERTY(QString backgroundColor READ backgroundColor CONSTANT) | ||||
44 | Q_PROPERTY(QString foregroundColor READ foregroundColor CONSTANT) | ||||
45 | Q_PROPERTY(QString labelColor READ labelColor CONSTANT) | ||||
46 | Q_PROPERTY(QString logoText READ logoText CONSTANT) | ||||
47 | Q_PROPERTY(QString barcodeAltText READ barcodeAltText CONSTANT) | ||||
48 | | ||||
49 | Q_PROPERTY(QVector<PkPassField> auxiliaryFields READ auxiliaryFields CONSTANT) | ||||
50 | Q_PROPERTY(QVector<PkPassField> backFields READ backFields CONSTANT) | ||||
51 | Q_PROPERTY(QVector<PkPassField> headerFields READ headerFields CONSTANT) | ||||
52 | Q_PROPERTY(QVector<PkPassField> primaryFields READ primaryFields CONSTANT) | ||||
53 | Q_PROPERTY(QVector<PkPassField> secondaryFields READ secondaryFields CONSTANT) | ||||
54 | | ||||
55 | public: | ||||
56 | ~PkPassFile(); | ||||
57 | | ||||
58 | /** Content of the pass.json file. */ | ||||
59 | QJsonObject data() const; | ||||
60 | /** The pass data structure of the pass.json file. */ | ||||
61 | QJsonObject passData() const; | ||||
62 | /** Localized message for the given key. */ | ||||
63 | QString message(const QString &key) const; | ||||
64 | | ||||
65 | QString backgroundColor() const; | ||||
66 | QString foregroundColor() const; | ||||
67 | QString labelColor() const; | ||||
68 | QString logoText() const; | ||||
69 | QImage logo() const; | ||||
70 | QImage barcode() const; | ||||
71 | QString barcodeAltText() const; | ||||
72 | | ||||
73 | QVector<PkPassField> auxiliaryFields() const; | ||||
74 | QVector<PkPassField> backFields() const; | ||||
75 | QVector<PkPassField> headerFields() const; | ||||
76 | QVector<PkPassField> primaryFields() const; | ||||
77 | QVector<PkPassField> secondaryFields() const; | ||||
78 | | ||||
79 | /** Create a appropriate sub-class based on the pkpass file type. */ | ||||
80 | static PkPassFile* fromData(const QByteArray &data, QObject *parent = nullptr); | ||||
81 | | ||||
82 | protected: | ||||
83 | explicit PkPassFile(const QString &passType, QObject *parent = nullptr); | ||||
84 | | ||||
85 | private: | ||||
86 | void parse(); | ||||
87 | bool parseMessages(const QString &lang); | ||||
88 | QVector<PkPassField> fields(const QLatin1String &fieldType) const; | ||||
89 | | ||||
90 | std::unique_ptr<QBuffer> m_buffer; | ||||
91 | std::unique_ptr<KZip> m_zip; | ||||
92 | QJsonObject m_passObj; | ||||
93 | QHash<QString, QString> m_messages; | ||||
94 | QString m_passType; | ||||
95 | }; | ||||
96 | | ||||
97 | #endif // PKPASSFILE_H |