File indexing completed on 2024-05-12 05:21:34

0001 /*
0002     SPDX-FileCopyrightText: 2018 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "barcode.h"
0008 #include "pass.h"
0009 #include "pass_p.h"
0010 
0011 #include <QJsonObject>
0012 
0013 using namespace KPkPass;
0014 
0015 namespace KPkPass
0016 {
0017 class BarcodePrivate
0018 {
0019 public:
0020     const Pass *pass = nullptr;
0021     QJsonObject obj;
0022 };
0023 }
0024 
0025 Barcode::Barcode()
0026     : d(new BarcodePrivate)
0027 {
0028 }
0029 
0030 Barcode::Barcode(const QJsonObject &obj, const Pass *pass)
0031     : d(new BarcodePrivate)
0032 {
0033     d->pass = pass;
0034     d->obj = obj;
0035 }
0036 
0037 Barcode::~Barcode() = default;
0038 
0039 QString Barcode::alternativeText() const
0040 {
0041     if (d->pass) {
0042         return d->pass->d->message(d->obj.value(QLatin1StringView("altText")).toString());
0043     }
0044     return {};
0045 }
0046 
0047 Barcode::Format KPkPass::Barcode::format() const
0048 {
0049     const auto format = d->obj.value(QLatin1StringView("format")).toString();
0050     if (format == QLatin1StringView("PKBarcodeFormatQR")) {
0051         return QR;
0052     } else if (format == QLatin1StringView("PKBarcodeFormatPDF417")) {
0053         return PDF417;
0054     } else if (format == QLatin1StringView("PKBarcodeFormatAztec")) {
0055         return Aztec;
0056     } else if (format == QLatin1StringView("PKBarcodeFormatCode128")) {
0057         return Code128;
0058     }
0059     return Invalid;
0060 }
0061 
0062 QString Barcode::message() const
0063 {
0064     return d->obj.value(QLatin1StringView("message")).toString();
0065 }
0066 
0067 QString Barcode::messageEncoding() const
0068 {
0069     return d->obj.value(QLatin1StringView("messageEncoding")).toString();
0070 }
0071 
0072 #include "moc_barcode.cpp"