KPkPass

pass.h
1 /*
2  SPDX-FileCopyrightText: 2017-2018 Volker Krause <[email protected]>
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 
17 class QByteArray;
18 class QColor;
19 class QDateTime;
20 class QString;
21 class QUrl;
22 class QVariant;
23 
24 namespace KPkPass
25 {
26 class Barcode;
27 class Location;
28 class 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  */
34 class 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(QVariantList barcodes READ barcodesVariant CONSTANT)
64  Q_PROPERTY(QVariantList auxiliaryFields READ auxiliaryFieldsVariant CONSTANT)
65  Q_PROPERTY(QVariantList backFields READ backFieldsVariant CONSTANT)
66  Q_PROPERTY(QVariantList headerFields READ headerFieldsVariant CONSTANT)
67  Q_PROPERTY(QVariantList primaryFields READ primaryFieldsVariant CONSTANT)
68  Q_PROPERTY(QVariantList secondaryFields READ secondaryFieldsVariant CONSTANT)
69  Q_PROPERTY(QVariantList locations READ locationsVariant CONSTANT)
70  Q_PROPERTY(QVariantMap field READ fieldsVariantMap CONSTANT)
71 
72 public:
73  ~Pass() override;
74 
75  /** Type of the pass. */
76  enum Type { BoardingPass, Coupon, EventTicket, Generic, StoreCard };
77  Q_ENUM(Type)
78  Q_REQUIRED_RESULT Type type() const;
79 
80  // standard keys
81  Q_REQUIRED_RESULT QString description() const;
82  Q_REQUIRED_RESULT QString organizationName() const;
83  Q_REQUIRED_RESULT QString passTypeIdentifier() const;
84  Q_REQUIRED_RESULT QString serialNumber() const;
85 
86  // expiration keys
87  Q_REQUIRED_RESULT QDateTime expirationDate() const;
88  Q_REQUIRED_RESULT bool isVoided() const;
89 
90  // relevance keys
91  /** Locations associated with this pass. */
92  Q_REQUIRED_RESULT QList<Location> locations() const;
93  /** Distance in meters to any of the pass locations before this pass becomes relevant. */
94  Q_REQUIRED_RESULT int maximumDistance() const;
95  Q_REQUIRED_RESULT QDateTime relevantDate() const;
96 
97  // visual appearance keys
98  /** Returns all barcodes defined in the pass. */
99  Q_REQUIRED_RESULT QList<Barcode> barcodes() const;
100  Q_REQUIRED_RESULT QColor backgroundColor() const;
101  Q_REQUIRED_RESULT QColor foregroundColor() const;
102  Q_REQUIRED_RESULT QString groupingIdentifier() const;
103  Q_REQUIRED_RESULT QColor labelColor() const;
104  Q_REQUIRED_RESULT 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  QImage image(const QString &baseName, unsigned int devicePixelRatio = 1) const;
123  /** Returns the pass icon. */
124  QImage icon(unsigned int devicePixelRatio = 1) const;
125  /** Returns the pass logo. */
126  QImage logo(unsigned int devicePixelRatio = 1) const;
127  /** Returns the strip image if present. */
128  QImage strip(unsigned int devicePixelRatio = 1) const;
129  /** Returns the background image if present. */
130  QImage background(unsigned int devicePixelRatio = 1) const;
131  /** Returns the footer image if present. */
132  QImage footer(unsigned int devicePixelRatio = 1) const;
133  /** Returns the thumbnail image if present. */
134  QImage thumbnail(unsigned int devicePixelRatio = 1) const;
135 
136  // web service keys
137  Q_REQUIRED_RESULT QString authenticationToken() const;
138  Q_REQUIRED_RESULT QUrl webServiceUrl() const;
139  /** Pass update URL.
140  * @see https://developer.apple.com/library/content/documentation/PassKit/Reference/PassKit_WebService/WebService.html
141  */
142  Q_REQUIRED_RESULT 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 
167 protected:
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 
176 private:
177  QVariantList auxiliaryFieldsVariant() const;
178  QVariantList backFieldsVariant() const;
179  QVariantList headerFieldsVariant() const;
180  QVariantList primaryFieldsVariant() const;
181  QVariantList secondaryFieldsVariant() const;
182  QVariantList barcodesVariant() const;
183  QVariantList locationsVariant() const;
184  QVariantMap fieldsVariantMap() const;
185 };
186 
187 }
A pass barcode element.
Definition: barcode.h:26
Base class for a pkpass file.
Definition: pass.h:34
Boarding pass.
Definition: boardingpass.h:14
Field element in a KPkPass::Pass.
Definition: field.h:28
Type
Type of the pass.
Definition: pass.h:76
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Sat Sep 30 2023 03:55:45 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.