KPkPass

pass.h
1/*
2 SPDX-FileCopyrightText: 2017-2018 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#pragma once
8
9#include "field.h"
10#include "kpkpass_export.h"
11
12#include <QList>
13#include <QObject>
14
15#include <memory>
16
17class QByteArray;
18class QColor;
19class QDateTime;
20class QString;
21class QUrl;
22class QVariant;
23
24namespace KPkPass
25{
26class Barcode;
27class Location;
28class PassPrivate;
29
30/** Base class for a pkpass file.
31 * @see https://developer.apple.com/library/archive/documentation/UserExperience/Conceptual/PassKit_PG/index.html
32 * @see https://developer.apple.com/library/content/documentation/UserExperience/Reference/PassKit_Bundle/Chapters/TopLevel.html
33 */
34class KPKPASS_EXPORT Pass : public QObject
35{
36 Q_OBJECT
37 Q_PROPERTY(Type type READ type CONSTANT)
38
39 Q_PROPERTY(QString description READ description CONSTANT)
40 Q_PROPERTY(QString organizationName READ organizationName CONSTANT)
41 Q_PROPERTY(QString passTypeIdentifier READ passTypeIdentifier CONSTANT)
42 Q_PROPERTY(QString serialNumber READ serialNumber CONSTANT)
43
44 Q_PROPERTY(QDateTime expirationDate READ expirationDate CONSTANT)
45 Q_PROPERTY(bool isVoided READ isVoided CONSTANT)
46
47 Q_PROPERTY(QDateTime relevantDate READ relevantDate CONSTANT)
48
49 Q_PROPERTY(QColor backgroundColor READ backgroundColor CONSTANT)
50 Q_PROPERTY(QColor foregroundColor READ foregroundColor CONSTANT)
51 Q_PROPERTY(QString groupingIdentifier READ groupingIdentifier CONSTANT)
52 Q_PROPERTY(QColor labelColor READ labelColor CONSTANT)
53 Q_PROPERTY(QString logoText READ logoText CONSTANT)
54
55 Q_PROPERTY(bool hasIcon READ hasIcon CONSTANT)
56 Q_PROPERTY(bool hasLogo READ hasLogo CONSTANT)
57 Q_PROPERTY(bool hasStrip READ hasStrip CONSTANT)
58 Q_PROPERTY(bool hasBackground READ hasBackground CONSTANT)
59 Q_PROPERTY(bool hasFooter READ hasFooter CONSTANT)
60 Q_PROPERTY(bool hasThumbnail READ hasThumbnail CONSTANT)
61
62 // needs to be QVariantList just for QML (Grantlee would also work with QList<Field>
63 Q_PROPERTY(QList<KPkPass::Barcode> barcodes READ barcodes CONSTANT)
64 Q_PROPERTY(QList<KPkPass::Field> auxiliaryFields READ auxiliaryFields CONSTANT)
65 Q_PROPERTY(QList<KPkPass::Field> backFields READ backFields CONSTANT)
66 Q_PROPERTY(QList<KPkPass::Field> headerFields READ headerFields CONSTANT)
67 Q_PROPERTY(QList<KPkPass::Field> primaryFields READ primaryFields CONSTANT)
68 Q_PROPERTY(QList<KPkPass::Field> secondaryFields READ secondaryFields CONSTANT)
69 Q_PROPERTY(QList<KPkPass::Location> locations READ locations CONSTANT)
70 Q_PROPERTY(QVariantMap field READ fieldsVariantMap CONSTANT)
71
72public:
73 ~Pass() override;
74
75 /** Type of the pass. */
76 enum Type {
78 Coupon,
79 EventTicket,
80 Generic,
81 StoreCard
82 };
83 Q_ENUM(Type)
84 [[nodiscard]] Type type() const;
85
86 // standard keys
87 [[nodiscard]] QString description() const;
88 [[nodiscard]] QString organizationName() const;
89 [[nodiscard]] QString passTypeIdentifier() const;
90 [[nodiscard]] QString serialNumber() const;
91
92 // expiration keys
93 [[nodiscard]] QDateTime expirationDate() const;
94 [[nodiscard]] bool isVoided() const;
95
96 // relevance keys
97 /** Locations associated with this pass. */
98 [[nodiscard]] QList<Location> locations() const;
99 /** Distance in meters to any of the pass locations before this pass becomes relevant. */
100 [[nodiscard]] int maximumDistance() const;
101 [[nodiscard]] QDateTime relevantDate() const;
102
103 // visual appearance keys
104 /** Returns all barcodes defined in the pass. */
105 [[nodiscard]] QList<Barcode> barcodes() const;
106 [[nodiscard]] QColor backgroundColor() const;
107 [[nodiscard]] QColor foregroundColor() const;
108 [[nodiscard]] QString groupingIdentifier() const;
109 [[nodiscard]] QColor labelColor() const;
110 [[nodiscard]] QString logoText() const;
111
112 /** Returns @c true if an image asset with the given base name exists.
113 * @param baseName The name of the asset, without the file type and high dpi extensions.
114 * @since 5.20.41
115 */
116 bool hasImage(const QString &baseName) const;
117 bool hasIcon() const;
118 bool hasLogo() const;
119 bool hasStrip() const;
120 bool hasBackground() const;
121 bool hasFooter() const;
122 bool hasThumbnail() const;
123
124 /** Returns an image asset of this pass.
125 * @param baseName The name of the asset, without the file name extension.
126 * @param devicePixelRatio The device pixel ration, for loading highdpi assets.
127 */
128 [[nodiscard]] QImage image(const QString &baseName, unsigned int devicePixelRatio = 1) const;
129 /** Returns the pass icon. */
130 Q_INVOKABLE [[nodiscard]] QImage icon(unsigned int devicePixelRatio = 1) const;
131 /** Returns the pass logo. */
132 Q_INVOKABLE [[nodiscard]] QImage logo(unsigned int devicePixelRatio = 1) const;
133 /** Returns the strip image if present. */
134 Q_INVOKABLE [[nodiscard]] QImage strip(unsigned int devicePixelRatio = 1) const;
135 /** Returns the background image if present. */
136 Q_INVOKABLE [[nodiscard]] QImage background(unsigned int devicePixelRatio = 1) const;
137 /** Returns the footer image if present. */
138 Q_INVOKABLE [[nodiscard]] QImage footer(unsigned int devicePixelRatio = 1) const;
139 /** Returns the thumbnail image if present. */
140 Q_INVOKABLE [[nodiscard]] QImage thumbnail(unsigned int devicePixelRatio = 1) const;
141
142 // web service keys
143 [[nodiscard]] QString authenticationToken() const;
144 [[nodiscard]] QUrl webServiceUrl() const;
145 /** Pass update URL.
146 * @see https://developer.apple.com/library/content/documentation/PassKit/Reference/PassKit_WebService/WebService.html
147 */
148 [[nodiscard]] QUrl passUpdateUrl() const;
149
150 QList<Field> auxiliaryFields() const;
151 QList<Field> backFields() const;
152 QList<Field> headerFields() const;
153 QList<Field> primaryFields() const;
154 QList<Field> secondaryFields() const;
155
156 /** Returns the field with key @p key. */
157 Field field(const QString &key) const;
158 /** Returns all fields found in this pass. */
159 QList<Field> fields() const;
160
161 /** Create a appropriate sub-class based on the pkpass file type. */
162 static Pass *fromData(const QByteArray &data, QObject *parent = nullptr);
163 /** Create a appropriate sub-class based on the pkpass file type. */
164 static Pass *fromFile(const QString &fileName, QObject *parent = nullptr);
165
166 /** The raw data of this pass.
167 * That is the binary representation of the ZIP archive which contains
168 * all the pass data.
169 * @since 5.20.41
170 */
171 QByteArray rawData() const;
172
173protected:
174 ///@cond internal
175 friend class Barcode;
176 friend class Field;
177 friend class PassPrivate;
178 explicit Pass(Type passType, QObject *parent = nullptr);
179 std::unique_ptr<PassPrivate> d;
180 ///@endcond
181
182private:
183 QVariantMap fieldsVariantMap() const;
184};
185
186}
A pass barcode element.
Definition barcode.h:27
Field element in a KPkPass::Pass.
Definition field.h:29
Base class for a pkpass file.
Definition pass.h:35
Type
Type of the pass.
Definition pass.h:76
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:39:50 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.