KItinerary

uic9183parser.h
1/*
2 SPDX-FileCopyrightText: 2018 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#pragma once
8
9#include "kitinerary_export.h"
10
11#include <KItinerary/Organization>
12#include <KItinerary/Person>
13#include <KItinerary/Place>
14
15#include <QExplicitlySharedDataPointer>
16#include <QMetaType>
17
18class QDateTime;
19
20namespace KItinerary {
21
22class Rct2Ticket;
23class Uic9183Block;
24class Uic9183Header;
25class Uic9183ParserPrivate;
26class Uic9183TicketLayout;
27
28/** Parser for UIC 918.3 and 918.3* train tickets.
29 *
30 * @see https://www.era.europa.eu/sites/default/files/filesystem/tap/baseline_1.2.0_archive/era_technical_document_tap_b_7_v1.2.pdf
31 * for information about the general UIC 918-3 structure
32 * @see https://www.era.europa.eu/sites/default/files/filesystem/tap/baseline_1.2.0_archive/era_technical_document_tap_b_6_v1.2.pdf
33 * for information about the U_TLAY block
34 * @see https://www.bahn.de/p/view/angebot/regio/barcode.shtml
35 * for information about the 0080VU vendor block
36 */
37class KITINERARY_EXPORT Uic9183Parser
38{
39 Q_GADGET
40 Q_PROPERTY(QString pnr READ pnr)
41 Q_PROPERTY(QString name READ name)
42 Q_PROPERTY(QString carrierId READ carrierId)
43 Q_PROPERTY(KItinerary::Organization issuer READ issuer)
44 Q_PROPERTY(QDateTime validFrom READ validFrom)
45 Q_PROPERTY(QDateTime validUntil READ validUntil)
46 Q_PROPERTY(KItinerary::Person person READ person)
47 Q_PROPERTY(KItinerary::TrainStation outboundDepartureStation READ outboundDepartureStation)
48 Q_PROPERTY(KItinerary::TrainStation outboundArrivalStation READ outboundArrivalStation)
49 Q_PROPERTY(KItinerary::TrainStation returnDepartureStation READ returnDepartureStation)
50 Q_PROPERTY(KItinerary::TrainStation returnArrivalStation READ returnArrivalStation)
51 Q_PROPERTY(QString seatingType READ seatingType)
52 /** U_TLAY ticket layout block, if present, @c null otherwise. */
53 Q_PROPERTY(QVariant ticketLayout READ ticketLayoutVariant)
54 /** RCT2 ticket layout block, if present, @c null otherwise. */
55 Q_PROPERTY(QVariant rct2Ticket READ rct2TicketVariant)
56
57 Q_PROPERTY(QByteArray rawData READ rawData STORED false)
58
59public:
63 Uic9183Parser& operator=(const Uic9183Parser&);
64
65 /** Date/time this ticket was first encountered.
66 * This is used to recover a missing year in the ticket data.
67 */
68 [[deprecated("calling this is longer needed")]] void setContextDate(const QDateTime&);
69
70 void parse(const QByteArray &data);
71 bool isValid() const;
72
73 /** The booking reference. */
74 QString pnr() const;
75 /** Ticket name. */
76 QString name() const;
77 /** The UIC carrier code. */
78 QString carrierId() const;
79 /** Full issuer organization element. */
80 Organization issuer() const;
81 /** Begin of validity. */
82 QDateTime validFrom() const;
83 /** End of validity. */
84 QDateTime validUntil() const;
85 /** The person this ticket is issued to. */
86 Person person() const;
87
88 /** Station object for the departure station of the outbound trip. */
89 TrainStation outboundDepartureStation() const;
90 /** Station object for the arrival station of the outbound trip. */
91 TrainStation outboundArrivalStation() const;
92 /** Station object for the departure station of the return trip. */
93 TrainStation returnDepartureStation() const;
94 /** Station object for the arrival station of the return trip. */
95 TrainStation returnArrivalStation() const;
96
97 /** @see Ticket::seatingType */
98 QString seatingType() const;
99
100 /** U_TLAY ticket layout block. */
101 Uic9183TicketLayout ticketLayout() const;
102
103 /** RCT2 ticket layout, if present. */
104 Rct2Ticket rct2Ticket() const;
105
106 /** First data block in this ticket.
107 * Useful for iterating over all blocks.
108 */
109 Uic9183Block firstBlock() const;
110 /** Returns the first block with the given name.
111 * A null block is returned if no such block exists.
112 */
113 Uic9183Block findBlock(const char name[6]) const;
114 /** Returns the first block of type @tparam T.
115 * A null block is returned if no such block exists.
116 */
117 template <typename T>
118 inline T findBlock() const
119 {
120 return T(findBlock(T::RecordId));
121 }
122
123 /** Same as the above, but for JS usage. */
124 Q_INVOKABLE QVariant block(const QString &name) const;
125
126 /** Header found before the compressed payload. */
127 Uic9183Header header() const;
128
129 /** Raw data of this ticket.
130 * Useful for generating a barcode for it again.
131 */
132 QByteArray rawData() const;
133
134 /** Quickly checks if @p might be UIC 918.3 content.
135 * This prioritizes speed over correctness and is used in barcode content auto-detection.
136 */
137 static bool maybeUic9183(const QByteArray &data);
138
139private:
140 QVariant ticketLayoutVariant() const;
141 QVariant rct2TicketVariant() const;
143};
144
145}
A person.
Definition person.h:20
RCT2 ticket layout payload of an UIC 918.3 ticket token.
Definition rct2ticket.h:23
Train station.
Definition place.h:126
A data block from a UIC 918.3 ticket.
Header of an UIC 918.3 ticket.
Parser for UIC 918.3 and 918.3* train tickets.
Parser for a U_TLAY block in a UIC 918-3 ticket container, such as a ERA TLB ticket.
Classes for reservation/travel data models, data extraction and data augmentation.
Definition berelement.h:17
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:28:48 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.