KItinerary

ticket.cpp
1 /*
2  SPDX-FileCopyrightText: 2018 Volker Krause <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "ticket.h"
8 #include "datatypes_p.h"
9 
10 #include <QByteArray>
11 
12 using namespace KItinerary;
13 
14 namespace KItinerary {
15 
16 class SeatPrivate : public QSharedData
17 {
18 public:
19  QString seatNumber;
20  QString seatRow;
21  QString seatSection;
22  QString seatingType;
23 };
24 
25 KITINERARY_MAKE_SIMPLE_CLASS(Seat)
26 KITINERARY_MAKE_PROPERTY(Seat, QString, seatNumber, setSeatNumber)
27 KITINERARY_MAKE_PROPERTY(Seat, QString, seatRow, setSeatRow)
28 KITINERARY_MAKE_PROPERTY(Seat, QString, seatSection, setSeatSection)
29 KITINERARY_MAKE_PROPERTY(Seat, QString, seatingType, setSeatingType)
30 KITINERARY_MAKE_OPERATOR(Seat)
31 
32 class TicketPrivate : public QSharedData
33 {
34 public:
35  QString name;
36  Seat ticketedSeat;
37  QString ticketToken;
38 };
39 
40 KITINERARY_MAKE_SIMPLE_CLASS(Ticket)
41 KITINERARY_MAKE_PROPERTY(Ticket, QString, name, setName)
42 KITINERARY_MAKE_PROPERTY(Ticket, Seat, ticketedSeat, setTicketedSeat)
43 KITINERARY_MAKE_PROPERTY(Ticket, QString, ticketToken, setTicketToken)
44 KITINERARY_MAKE_OPERATOR(Ticket)
45 
46 Ticket::TicketTokenType Ticket::ticketTokenType() const
47 {
48  if (d->ticketToken.startsWith(QLatin1String("qrcode:"), Qt::CaseInsensitive)) {
49  return QRCode;
50  } else if (d->ticketToken.startsWith(QLatin1String("aztec"), Qt::CaseInsensitive)) {
51  return AztecCode;
52  } else if (d->ticketToken.startsWith(QLatin1String("barcode128:"), Qt::CaseInsensitive)) {
53  return Code128;
54  } else if (d->ticketToken.startsWith(QLatin1String("datamatrix:"), Qt::CaseInsensitive)) {
55  return DataMatrix;
56  } else if (d->ticketToken.startsWith(QLatin1String("pdf417"), Qt::CaseInsensitive)) {
57  return PDF417;
58  } else if (d->ticketToken.startsWith(QLatin1String("http"), Qt::CaseInsensitive)) {
59  return Url;
60  }
61  return Unknown;
62 }
63 
64 QVariant Ticket::ticketTokenData() const
65 {
66  if (d->ticketToken.startsWith(QLatin1String("qrcode:"), Qt::CaseInsensitive)) {
67  return ticketToken().mid(7);
68  } else if (d->ticketToken.startsWith(QLatin1String("azteccode:"), Qt::CaseInsensitive)) {
69  return ticketToken().mid(10);
70  } else if (d->ticketToken.startsWith(QLatin1String("aztecbin:"), Qt::CaseInsensitive)) {
71  return QByteArray::fromBase64(QStringView(d->ticketToken).mid(9).toLatin1());
72  } else if (d->ticketToken.startsWith(QLatin1String("barcode128:"), Qt::CaseInsensitive)) {
73  return ticketToken().mid(11);
74  } else if (d->ticketToken.startsWith(QLatin1String("datamatrix:"), Qt::CaseInsensitive)) {
75  return ticketToken().mid(11);
76  } else if (d->ticketToken.startsWith(QLatin1String("pdf417:"), Qt::CaseInsensitive)) {
77  return ticketToken().mid(7);
78  } else if (d->ticketToken.startsWith(QLatin1String("pdf417bin:"), Qt::CaseInsensitive)) {
79  return QByteArray::fromBase64(QStringView(d->ticketToken).mid(10).toLatin1());
80  }
81  return ticketToken();
82 }
83 
84 }
85 
86 #include "moc_ticket.cpp"
QByteArray toLatin1() const const
Classes for reservation/travel data models, data extraction and data augmentation.
const QLatin1String name
A booked ticket.
Definition: ticket.h:35
CaseInsensitive
QByteArray mid(int pos, int len) const const
QByteArray fromBase64(const QByteArray &base64, QByteArray::Base64Options options)
A reserved seat.
Definition: ticket.h:19
QStringView mid(qsizetype start) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Jan 15 2022 23:06:18 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.