KPkPass

barcode.cpp
1 /*
2  SPDX-FileCopyrightText: 2018 Volker Krause <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "barcode.h"
8 #include "pass.h"
9 #include "pass_p.h"
10 
11 #include <QJsonObject>
12 
13 using namespace KPkPass;
14 
15 namespace KPkPass {
16 class BarcodePrivate
17 {
18 public:
19  const Pass *pass = nullptr;
20  QJsonObject obj;
21 };
22 }
23 
24 Barcode::Barcode()
25  : d(new BarcodePrivate)
26 {
27 }
28 
29 Barcode::Barcode(const QJsonObject &obj, const Pass *pass)
30  : d(new BarcodePrivate)
31 {
32  d->pass = pass;
33  d->obj = obj;
34 }
35 
36 Barcode::~Barcode() = default;
37 
38 QString Barcode::alternativeText() const
39 {
40  if (d->pass) {
41  return d->pass->d->message(d->obj.value(QLatin1String("altText")).toString());
42  }
43  return {};
44 }
45 
46 Barcode::Format KPkPass::Barcode::format() const
47 {
48  const auto format = d->obj.value(QLatin1String("format")).toString();
49  if (format == QLatin1String("PKBarcodeFormatQR")) {
50  return QR;
51  } else if (format == QLatin1String("PKBarcodeFormatPDF417")) {
52  return PDF417;
53  } else if (format == QLatin1String("PKBarcodeFormatAztec")) {
54  return Aztec;
55  } else if (format == QLatin1String("PKBarcodeFormatCode128")) {
56  return Code128;
57  }
58  return Invalid;
59 }
60 
62 {
63  return d->obj.value(QLatin1String("message")).toString();
64 }
65 
67 {
68  return d->obj.value(QLatin1String("messageEncoding")).toString();
69 }
QString message() const
The message encoded in the barcode.
Format format() const
The barcode type.
Base class for a pkpass file.
Definition: pass.h:35
QString messageEncoding() const
Encoding used for the message() content.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat Oct 24 2020 23:21:22 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.