KItinerary

ssbticketreader.cpp
1 /*
2  SPDX-FileCopyrightText: 2021 Volker Krause <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "ssbticketreader.h"
8 #include "ssbv1ticket.h"
9 #include "ssbv2ticket.h"
10 #include "ssbv3ticket.h"
11 
12 #include <QVariant>
13 
14 using namespace KItinerary;
15 
16 QVariant SSBTicketReader::read(const QByteArray& data, int versionOverride)
17 {
18  if (data.isEmpty()) {
19  return {};
20  }
21 
22  auto ticketData = data;
23  auto version = data[0] >> 4;
24  if (versionOverride > 0 && version != versionOverride) {
25  ticketData[0] = (ticketData[0] & 0x0f) | (versionOverride << 4);
26  version = versionOverride;
27  }
28 
29  switch (version) {
30  case 1:
31  {
32  SSBv1Ticket ticket(ticketData);
33  return ticket.isValid() ? QVariant::fromValue(ticket) : QVariant();
34  }
35  case 2:
36  {
37  SSBv2Ticket ticket(ticketData);
38  return ticket.isValid() ? QVariant::fromValue(ticket) : QVariant();
39  }
40  case 3:
41  {
42  SSBv3Ticket ticket(ticketData);
43  return ticket.isValid() ? QVariant::fromValue(ticket) : QVariant();
44  }
45  }
46 
47  return {};
48 }
ERA SSB ticket barcode (version 3).
Definition: ssbv3ticket.h:20
QVariant fromValue(const T &value)
ERA SSB ticket barcode (version 2).
Definition: ssbv2ticket.h:20
bool isValid() const
Returns true if this is a valid SSB ticket.
Definition: ssbv3ticket.cpp:34
bool isEmpty() const const
QVariant read(const QByteArray &data, int versionOverride=0)
Attempt to read an SSB ticket.
ERA SSB ticket barcode (version 1).
Definition: ssbv1ticket.h:20
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Fri Aug 12 2022 03:54:15 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.