File indexing completed on 2024-12-29 04:51:09

0001 /*
0002     SPDX-FileCopyrightText: 2019 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "kitinerary_export.h"
0010 
0011 #include <KItinerary/Person>
0012 
0013 #include <QDateTime>
0014 #include <QExplicitlySharedDataPointer>
0015 #include <QMetaType>
0016 
0017 namespace KItinerary {
0018 
0019 class VdvTicketHeader;
0020 class VdvTicketPrivate;
0021 class VdvTicketCommonTransactionData;
0022 class VdvTicketIssueData;
0023 class VdvTicketTrailer;
0024 namespace BER { class Element; }
0025 
0026 /** Ticket information from a VDV barcode.
0027  *  For use by tooling or custom extractor scripts.
0028  */
0029 class KITINERARY_EXPORT VdvTicket
0030 {
0031     Q_GADGET
0032     /** Begin of the validitiy of this ticket. */
0033     Q_PROPERTY(QDateTime beginDateTime READ beginDateTime)
0034     /** End of the validity of this ticket. */
0035     Q_PROPERTY(QDateTime endDateTime READ endDateTime)
0036 
0037     /** VDV organization identifier of the ticket issuer. */
0038     Q_PROPERTY(int issuerId READ issuerId)
0039     /** VDV organization identifier of the operator. */
0040     Q_PROPERTY(int operatorId READ operatorId)
0041     /** Service class for this ticket. */
0042     Q_PROPERTY(ServiceClass serviceClass READ serviceClass)
0043     /** The person this ticket is valid for. */
0044     Q_PROPERTY(KItinerary::Person person READ person)
0045     /** Ticket number. */
0046     Q_PROPERTY(QString ticketNumber READ ticketNumber)
0047 
0048     Q_PROPERTY(QByteArray rawData READ rawData STORED false)
0049 
0050 public:
0051     VdvTicket();
0052     VdvTicket(const QByteArray &data, const QByteArray &rawData);
0053     VdvTicket(const VdvTicket&);
0054     ~VdvTicket();
0055     VdvTicket& operator=(const VdvTicket&);
0056 
0057     QDateTime beginDateTime() const;
0058     QDateTime endDateTime() const;
0059     int issuerId() const;
0060     int operatorId() const;
0061 
0062     enum ServiceClass {
0063         UnknownClass = 0,
0064         FirstClass = 1,
0065         SecondClass = 2,
0066         FirstClassUpgrade = 3
0067     };
0068     Q_ENUM(ServiceClass)
0069     ServiceClass serviceClass() const;
0070 
0071     Person person() const;
0072     QString ticketNumber() const;
0073 
0074     // low-level content access
0075     const VdvTicketHeader* header() const;
0076     BER::Element productData() const;
0077     const VdvTicketCommonTransactionData* commonTransactionData() const;
0078     BER::Element productSpecificTransactionData() const;
0079     const VdvTicketIssueData* issueData() const;
0080     const VdvTicketTrailer* trailer() const;
0081 
0082     /** Raw data of this ticket.
0083      *  Useful for generating a barcode for it again.
0084      */
0085     QByteArray rawData() const;
0086 
0087 private:
0088     QExplicitlySharedDataPointer<VdvTicketPrivate> d;
0089 };
0090 
0091 }