Commit 041fbe4d authored by Volker Krause's avatar Volker Krause
Browse files

Factor out ticket token parsing and use that for program membershipts too

parent 7d86a0ed
Pipeline #165153 passed with stages
in 1 minute and 47 seconds
......@@ -3,7 +3,7 @@
# SPDX-License-Identifier: BSD-3-Clause
cmake_minimum_required(VERSION 3.16 FATAL_ERROR)
set(PIM_VERSION "5.20.40")
set(PIM_VERSION "5.20.41")
project(KItinerary VERSION ${PIM_VERSION})
set(KF5_MIN_VERSION "5.91.0")
......
......@@ -22,6 +22,7 @@ target_sources(KPimItinerary PRIVATE
datatypes/reservation.cpp
datatypes/taxi.cpp
datatypes/ticket.cpp
datatypes/token.cpp
datatypes/traintrip.cpp
datatypes/rentalcar.cpp
datatypes/visit.cpp
......@@ -251,6 +252,7 @@ ecm_generate_headers(KItinerary_Datatypes_FORWARDING_HEADERS
ProgramMembership
Taxi
Ticket
Token
TrainTrip
Visit
PREFIX KItinerary
......
......@@ -28,4 +28,14 @@ KITINERARY_MAKE_OPERATOR(ProgramMembership)
}
Token::TokenType ProgramMembership::tokenType() const
{
return Token::tokenType(d->token);
}
QVariant ProgramMembership::tokenData() const
{
return Token::tokenData(d->token);
}
#include "moc_programmembership.cpp"
......@@ -9,6 +9,7 @@
#include "kitinerary_export.h"
#include "datatypes.h"
#include "person.h"
#include "token.h"
namespace KItinerary {
......@@ -31,6 +32,17 @@ class KITINERARY_EXPORT ProgramMembership
*/
KITINERARY_PROPERTY(QString, token, setToken)
/** The type of the token. */
Q_PROPERTY(KItinerary::Token::TokenType tokenType READ tokenType STORED false)
/** The token payload for barcodes, otherwise the same as ticketToken.
* For binary content barcodes this is a QByteArray, otherwise a QString.
*/
Q_PROPERTY(QVariant tokenData READ tokenData STORED false)
public:
Token::TokenType tokenType() const;
QVariant tokenData() const;
private:
QExplicitlySharedDataPointer<ProgramMembershipPrivate> d;
};
......
......@@ -43,42 +43,14 @@ KITINERARY_MAKE_PROPERTY(Ticket, Seat, ticketedSeat, setTicketedSeat)
KITINERARY_MAKE_PROPERTY(Ticket, QString, ticketToken, setTicketToken)
KITINERARY_MAKE_OPERATOR(Ticket)
Ticket::TicketTokenType Ticket::ticketTokenType() const
Token::TokenType Ticket::ticketTokenType() const
{
if (d->ticketToken.startsWith(QLatin1String("qrcode:"), Qt::CaseInsensitive)) {
return QRCode;
} else if (d->ticketToken.startsWith(QLatin1String("aztec"), Qt::CaseInsensitive)) {
return AztecCode;
} else if (d->ticketToken.startsWith(QLatin1String("barcode128:"), Qt::CaseInsensitive)) {
return Code128;
} else if (d->ticketToken.startsWith(QLatin1String("datamatrix:"), Qt::CaseInsensitive)) {
return DataMatrix;
} else if (d->ticketToken.startsWith(QLatin1String("pdf417"), Qt::CaseInsensitive)) {
return PDF417;
} else if (d->ticketToken.startsWith(QLatin1String("http"), Qt::CaseInsensitive)) {
return Url;
}
return Unknown;
return Token::tokenType(d->ticketToken);
}
QVariant Ticket::ticketTokenData() const
{
if (d->ticketToken.startsWith(QLatin1String("qrcode:"), Qt::CaseInsensitive)) {
return ticketToken().mid(7);
} else if (d->ticketToken.startsWith(QLatin1String("azteccode:"), Qt::CaseInsensitive)) {
return ticketToken().mid(10);
} else if (d->ticketToken.startsWith(QLatin1String("aztecbin:"), Qt::CaseInsensitive)) {
return QByteArray::fromBase64(QStringView(d->ticketToken).mid(9).toLatin1());
} else if (d->ticketToken.startsWith(QLatin1String("barcode128:"), Qt::CaseInsensitive)) {
return ticketToken().mid(11);
} else if (d->ticketToken.startsWith(QLatin1String("datamatrix:"), Qt::CaseInsensitive)) {
return ticketToken().mid(11);
} else if (d->ticketToken.startsWith(QLatin1String("pdf417:"), Qt::CaseInsensitive)) {
return ticketToken().mid(7);
} else if (d->ticketToken.startsWith(QLatin1String("pdf417bin:"), Qt::CaseInsensitive)) {
return QByteArray::fromBase64(QStringView(d->ticketToken).mid(10).toLatin1());
}
return ticketToken();
return Token::tokenData(d->ticketToken);
}
}
......
......@@ -8,6 +8,7 @@
#include "kitinerary_export.h"
#include "datatypes.h"
#include "token.h"
namespace KItinerary {
......@@ -43,26 +44,28 @@ class KITINERARY_EXPORT Ticket
KITINERARY_PROPERTY(QString, ticketToken, setTicketToken)
/** The type of the content in ticketToken. */
Q_PROPERTY(TicketTokenType ticketTokenType READ ticketTokenType STORED false)
Q_PROPERTY(KItinerary::Token::TokenType ticketTokenType READ ticketTokenType STORED false)
/** The ticket token payload for barcodes, otherwise the same as ticketToken.
* For binary content barcodes this is a QByteArray, otherwise a QString.
*/
Q_PROPERTY(QVariant ticketTokenData READ ticketTokenData STORED false)
public:
/** The type of content in the ticketToken property. */
/** The type of content in the ticketToken property.
* @deprecated Use Token::TokenType instead.
*/
enum TicketTokenType {
Unknown, ///< Unknown or empty ticket token
Url, ///< A download URL
QRCode, ///< QR code
AztecCode, ///< Aztec code
Code128, ///< Code 128 barcode
DataMatrix, ///< A DataMatrix barcode
PDF417, ///< A PDF417 barcode
Unknown = Token::Unknown, ///< Unknown or empty ticket token
Url = Token::Url, ///< A download URL
QRCode = Token::QRCode, ///< QR code
AztecCode = Token::AztecCode, ///< Aztec code
Code128 = Token::Code128, ///< Code 128 barcode
DataMatrix = Token::DataMatrix, ///< A DataMatrix barcode
PDF417 = Token::PDF417, ///< A PDF417 barcode
};
Q_ENUM(TicketTokenType)
TicketTokenType ticketTokenType() const;
Token::TokenType ticketTokenType() const;
QVariant ticketTokenData() const;
private:
QExplicitlySharedDataPointer<TicketPrivate> d;
......
/*
SPDX-FileCopyrightText: 2018-2022 Volker Krause <vkrause@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "token.h"
#include <QStringView>
#include <QVariant>
using namespace KItinerary;
Token::TokenType Token::tokenType(QStringView token)
{
if (token.startsWith(QLatin1String("qrcode:"), Qt::CaseInsensitive)) {
return QRCode;
} else if (token.startsWith(QLatin1String("aztec"), Qt::CaseInsensitive)) {
return AztecCode;
} else if (token.startsWith(QLatin1String("barcode128:"), Qt::CaseInsensitive)) {
return Code128;
} else if (token.startsWith(QLatin1String("datamatrix:"), Qt::CaseInsensitive)) {
return DataMatrix;
} else if (token.startsWith(QLatin1String("pdf417"), Qt::CaseInsensitive)) {
return PDF417;
} else if (token.startsWith(QLatin1String("http"), Qt::CaseInsensitive)) {
return Url;
}
return Unknown;
}
QVariant Token::tokenData(const QString &token)
{
if (token.startsWith(QLatin1String("qrcode:"), Qt::CaseInsensitive)) {
return token.mid(7);
} else if (token.startsWith(QLatin1String("azteccode:"), Qt::CaseInsensitive)) {
return token.mid(10);
} else if (token.startsWith(QLatin1String("aztecbin:"), Qt::CaseInsensitive)) {
return QByteArray::fromBase64(QStringView(token).mid(9).toLatin1());
} else if (token.startsWith(QLatin1String("barcode128:"), Qt::CaseInsensitive)) {
return token.mid(11);
} else if (token.startsWith(QLatin1String("datamatrix:"), Qt::CaseInsensitive)) {
return token.mid(11);
} else if (token.startsWith(QLatin1String("pdf417:"), Qt::CaseInsensitive)) {
return token.mid(7);
} else if (token.startsWith(QLatin1String("pdf417bin:"), Qt::CaseInsensitive)) {
return QByteArray::fromBase64(QStringView(token).mid(10).toLatin1());
}
return token;
}
/*
SPDX-FileCopyrightText: 2018-2022 Volker Krause <vkrause@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#ifndef KITINERARY_TOKEN_H
#define KITINERARY_TOKEN_H
#include "kitinerary_export.h"
#include <qobjectdefs.h>
class QStringView;
class QVariant;
namespace KItinerary {
/** Barcode token utilities.
* @see Ticket
* @see ProgramMembership
* @since 5.20.41
*/
class KITINERARY_EXPORT Token
{
Q_GADGET
public:
/** Token format. */
enum TokenType {
Unknown, ///< Unknown or empty ticket token
Url, ///< A download URL, if shown in a barcode its format can be determined by the application.
QRCode, ///< QR code
AztecCode, ///< Aztec code. Binary content is handled transparently by tokenData().
Code128, ///< Code 128 barcode
DataMatrix, ///< A DataMatrix barcode
PDF417, ///< A PDF417 barcode
};
Q_ENUM(TokenType)
/** Determine token type for the given token. */
static TokenType tokenType(QStringView token);
/** Determine token content for the given token. */
static QVariant tokenData(const QString &token);
};
}
#endif // KITINERARY_TOKEN_H
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment