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 { BoardingPass, Coupon, EventTicket, Generic, StoreCard };
77 Q_ENUM(Type)
78 [[nodiscard]] Type type() const;
79
80 // standard keys
81 [[nodiscard]] QString description() const;
82 [[nodiscard]] QString organizationName() const;
83 [[nodiscard]] QString passTypeIdentifier() const;
84 [[nodiscard]] QString serialNumber() const;
85
86 // expiration keys
87 [[nodiscard]] QDateTime expirationDate() const;
88 [[nodiscard]] bool isVoided() const;
89
90 // relevance keys
91 /** Locations associated with this pass. */
92 [[nodiscard]] QList<Location> locations() const;
93 /** Distance in meters to any of the pass locations before this pass becomes relevant. */
94 [[nodiscard]] int maximumDistance() const;
95 [[nodiscard]] QDateTime relevantDate() const;
96
97 // visual appearance keys
98 /** Returns all barcodes defined in the pass. */
99 [[nodiscard]] QList<Barcode> barcodes() const;
100 [[nodiscard]] QColor backgroundColor() const;
101 [[nodiscard]] QColor foregroundColor() const;
102 [[nodiscard]] QString groupingIdentifier() const;
103 [[nodiscard]] QColor labelColor() const;
104 [[nodiscard]] QString logoText() const;
105
106 /** Returns @c true if an image asset with the given base name exists.
107 * @param baseName The name of the asset, without the file type and high dpi extensions.
108 * @since 5.20.41
109 */
110 bool hasImage(const QString &baseName) const;
111 bool hasIcon() const;
112 bool hasLogo() const;
113 bool hasStrip() const;
114 bool hasBackground() const;
115 bool hasFooter() const;
116 bool hasThumbnail() const;
117
118 /** Returns an image asset of this pass.
119 * @param baseName The name of the asset, without the file name extension.
120 * @param devicePixelRatio The device pixel ration, for loading highdpi assets.
121 */
122 [[nodiscard]] QImage image(const QString &baseName, unsigned int devicePixelRatio = 1) const;
123 /** Returns the pass icon. */
124 Q_INVOKABLE [[nodiscard]] QImage icon(unsigned int devicePixelRatio = 1) const;
125 /** Returns the pass logo. */
126 Q_INVOKABLE [[nodiscard]] QImage logo(unsigned int devicePixelRatio = 1) const;
127 /** Returns the strip image if present. */
128 Q_INVOKABLE [[nodiscard]] QImage strip(unsigned int devicePixelRatio = 1) const;
129 /** Returns the background image if present. */
130 Q_INVOKABLE [[nodiscard]] QImage background(unsigned int devicePixelRatio = 1) const;
131 /** Returns the footer image if present. */
132 Q_INVOKABLE [[nodiscard]] QImage footer(unsigned int devicePixelRatio = 1) const;
133 /** Returns the thumbnail image if present. */
134 Q_INVOKABLE [[nodiscard]] QImage thumbnail(unsigned int devicePixelRatio = 1) const;
135
136 // web service keys
137 [[nodiscard]] QString authenticationToken() const;
138 [[nodiscard]] QUrl webServiceUrl() const;
139 /** Pass update URL.
140 * @see https://developer.apple.com/library/content/documentation/PassKit/Reference/PassKit_WebService/WebService.html
141 */
142 [[nodiscard]] QUrl passUpdateUrl() const;
143
144 QList<Field> auxiliaryFields() const;
145 QList<Field> backFields() const;
146 QList<Field> headerFields() const;
147 QList<Field> primaryFields() const;
148 QList<Field> secondaryFields() const;
149
150 /** Returns the field with key @p key. */
151 Field field(const QString &key) const;
152 /** Returns all fields found in this pass. */
153 QList<Field> fields() const;
154
155 /** Create a appropriate sub-class based on the pkpass file type. */
156 static Pass *fromData(const QByteArray &data, QObject *parent = nullptr);
157 /** Create a appropriate sub-class based on the pkpass file type. */
158 static Pass *fromFile(const QString &fileName, QObject *parent = nullptr);
159
160 /** The raw data of this pass.
161 * That is the binary representation of the ZIP archive which contains
162 * all the pass data.
163 * @since 5.20.41
164 */
165 QByteArray rawData() const;
166
167protected:
168 ///@cond internal
169 friend class Barcode;
170 friend class Field;
171 friend class PassPrivate;
172 explicit Pass(Type passType, QObject *parent = nullptr);
173 std::unique_ptr<PassPrivate> d;
174 ///@endcond
175
176private:
177 QVariantMap fieldsVariantMap() const;
178};
179
180}
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 Fri May 17 2024 11:51:24 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.