Commit 200177b8 authored by Volker Krause's avatar Volker Krause
Browse files

Make Ticket::ticketTokenData a QVariant

Now that KF5::Prison can consume binary data, this allows us to pass
binary barcode content as a QByteArray instead of relying on QString
encoding not messing things up.
parent 3104a4e5
......@@ -61,15 +61,14 @@ Ticket::TicketTokenType Ticket::ticketTokenType() const
return Unknown;
}
QString Ticket::ticketTokenData() const
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)) {
const auto b = QByteArray::fromBase64(d->ticketToken.midRef(9).toLatin1());
return QString::fromLatin1(b.constData(), b.size());
return QByteArray::fromBase64(d->ticketToken.midRef(9).toLatin1());
} else if (d->ticketToken.startsWith(QLatin1String("barcode128:"), Qt::CaseInsensitive)) {
return ticketToken().mid(11);
} else if (d->ticketToken.startsWith(QLatin1String("datamatrix:"), Qt::CaseInsensitive)) {
......@@ -77,8 +76,7 @@ QString Ticket::ticketTokenData() const
} else if (d->ticketToken.startsWith(QLatin1String("pdf417:"), Qt::CaseInsensitive)) {
return ticketToken().mid(7);
} else if (d->ticketToken.startsWith(QLatin1String("pdf417bin:"), Qt::CaseInsensitive)) {
const auto b = QByteArray::fromBase64(d->ticketToken.midRef(10).toLatin1());
return QString::fromLatin1(b.constData(), b.size());
return QByteArray::fromBase64(d->ticketToken.midRef(10).toLatin1());
}
return ticketToken();
}
......
......@@ -44,8 +44,10 @@ class KITINERARY_EXPORT Ticket
/** 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)
/** 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. */
......@@ -61,7 +63,7 @@ public:
Q_ENUM(TicketTokenType)
TicketTokenType ticketTokenType() const;
QString ticketTokenData() const;
QVariant ticketTokenData() const;
private:
QExplicitlySharedDataPointer<TicketPrivate> d;
};
......
......@@ -158,7 +158,7 @@ void ExtractorPostprocessorPrivate::mergeOrAppend(const QVariant &elem)
QVariant ExtractorPostprocessorPrivate::processFlightReservation(FlightReservation res) const
{
// expand ticketToken for IATA BCBP data
const auto bcbp = res.reservedTicket().value<Ticket>().ticketTokenData();
const auto bcbp = res.reservedTicket().value<Ticket>().ticketTokenData().toString();
if (!bcbp.isEmpty()) {
const auto bcbpData = IataBcbpParser::parse(bcbp, m_contextDate);
if (bcbpData.size() == 1) {
......
......@@ -39,11 +39,8 @@ static bool equalAndPresent(const QString &lhs, const QString &rhs, Qt::CaseSens
{
return !lhs.isEmpty() && (lhs.compare(rhs, caseSensitive) == 0);
}
static bool equalAndPresent(const QDate &lhs, const QDate &rhs)
{
return lhs.isValid() && lhs == rhs;
}
static bool equalAndPresent(const QDateTime &lhs, const QDateTime &rhs)
template <typename T>
static bool equalAndPresent(const T &lhs, const T &rhs)
{
return lhs.isValid() && lhs == rhs;
}
......@@ -53,7 +50,8 @@ static bool conflictIfPresent(const QString &lhs, const QString &rhs, Qt::CaseSe
{
return !lhs.isEmpty() && !rhs.isEmpty() && lhs.compare(rhs, caseSensitive) != 0;
}
static bool conflictIfPresent(const QDateTime &lhs, const QDateTime &rhs)
template <typename T>
static bool conflictIfPresent(const T &lhs, const T &rhs)
{
return lhs.isValid() && rhs.isValid() && lhs != rhs;
}
......
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