diff --git a/src/datatypes/ticket.cpp b/src/datatypes/ticket.cpp index 9f6b5b3..90bdb8b 100644 --- a/src/datatypes/ticket.cpp +++ b/src/datatypes/ticket.cpp @@ -1,51 +1,76 @@ /* Copyright (C) 2018 Volker Krause This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "ticket.h" #include "datatypes_p.h" using namespace KItinerary; namespace KItinerary { class SeatPrivate : public QSharedData { public: QString seatNumber; QString seatRow; QString seatSection; }; KITINERARY_MAKE_SIMPLE_CLASS(Seat) KITINERARY_MAKE_PROPERTY(Seat, QString, seatNumber, setSeatNumber) KITINERARY_MAKE_PROPERTY(Seat, QString, seatRow, setSeatRow) KITINERARY_MAKE_PROPERTY(Seat, QString, seatSection, setSeatSection) class TicketPrivate : public QSharedData { public: Seat ticketedSeat; QString ticketToken; }; KITINERARY_MAKE_SIMPLE_CLASS(Ticket) KITINERARY_MAKE_PROPERTY(Ticket, Seat, ticketedSeat, setTicketedSeat) KITINERARY_MAKE_PROPERTY(Ticket, QString, ticketToken, setTicketToken) +Ticket::TicketTokenType Ticket::ticketTokenType() const +{ + if (d->ticketToken.startsWith(QLatin1Literal("qrcode:"), Qt::CaseInsensitive)) { + return QRCode; + } else if (d->ticketToken.startsWith(QLatin1String("azteccode:"), Qt::CaseInsensitive)) { + return AztecCode; + } else if (d->ticketToken.startsWith(QLatin1String("http"), Qt::CaseInsensitive)) { + return Url; + } + return Unknown; +} + +QString Ticket::ticketTokenData() const +{ + switch (ticketTokenType()) { + case QRCode: + return ticketToken().mid(7); + case AztecCode: + return ticketToken().mid(10); + default: + break; + } + return ticketToken(); +} + } #include "moc_ticket.cpp" diff --git a/src/datatypes/ticket.h b/src/datatypes/ticket.h index 0d1acca..14c3ca1 100644 --- a/src/datatypes/ticket.h +++ b/src/datatypes/ticket.h @@ -1,60 +1,81 @@ /* Copyright (C) 2018 Volker Krause This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef KITINERARY_TICKET_H #define KITINERARY_TICKET_H #include "kitinerary_export.h" #include "datatypes.h" namespace KItinerary { class SeatPrivate; /** A reserved seat. * @see https://schema.org/Seat */ class KITINERARY_EXPORT Seat { KITINERARY_GADGET(Seat) KITINERARY_PROPERTY(QString, seatNumber, setSeatNumber) KITINERARY_PROPERTY(QString, seatRow, setSeatRow) KITINERARY_PROPERTY(QString, seatSection, setSeatSection) private: QExplicitlySharedDataPointer d; }; class TicketPrivate; /** A booked ticket. * @see https://schema.org/Ticket */ class KITINERARY_EXPORT Ticket { KITINERARY_GADGET(Ticket) KITINERARY_PROPERTY(KItinerary::Seat, ticketedSeat, setTicketedSeat) + /** The raw ticket token string. + * @see ticketTokenType, ticketTokenData + */ KITINERARY_PROPERTY(QString, ticketToken, setTicketToken) + + /** The type of the content in ticketToken. */ + Q_PROPERTY(TicketTokenType ticketTokenType READ ticketTokenType STORED false) + /** The ticket token payload for barcodes, otherwise the same as ticketToken. */ + Q_PROPERTY(QString ticketTokenData READ ticketTokenData STORED false) + +public: + /** The type of content in the ticketToken property. */ + enum TicketTokenType { + QRCode, ///< QR code + AztecCode, ///< Aztec bar code + Url, ///< A download URL + Unknown ///< Unknown or empty ticket token + }; + Q_ENUM(TicketTokenType) + + TicketTokenType ticketTokenType() const; + QString ticketTokenData() const; private: QExplicitlySharedDataPointer d; }; } Q_DECLARE_METATYPE(KItinerary::Seat) Q_DECLARE_METATYPE(KItinerary::Ticket) #endif // KITINERARY_TICKET_H