Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 0e13dba8 authored by Volker Krause's avatar Volker Krause

Add merge handler for ticket tokens

This prefers barcodes over URLs, which fixes losing boarding pass barcodes
when merging existing data with the structured annotations of a LH
boarding pass email.
parent a1efa7a7
[{
"@context": "http://schema.org",
"@type": "FlightReservation",
"reservedTicket": {
"@type": "Ticket",
"ticketToken": "aztecCode:M1DOE/JOHN EXXX007 TXLBRUSN 2592 110"
}
}]
[{
"@context": "http://schema.org",
"@type": "FlightReservation",
"reservedTicket": {
"@type": "Ticket",
"ticketToken": "aztecCode:M1DOE/JOHN EXXX007 TXLBRUSN 2592 110"
}
}]
[{
"@context": "http://schema.org",
"@type": "FlightReservation",
"reservedTicket": {
"@type": "Ticket",
"ticketToken": "https://airline.com/download-your-boarding-pass-here.html"
}
}]
......@@ -29,6 +29,7 @@
#include <KItinerary/Person>
#include <KItinerary/Reservation>
#include <KItinerary/Taxi>
#include <KItinerary/Ticket>
#include <KItinerary/TrainTrip>
#include <KItinerary/Visit>
......@@ -386,6 +387,16 @@ static QDateTime mergeValue(const QDateTime &lhs, const QDateTime &rhs)
return lhs.isValid() && lhs.timeSpec() == Qt::TimeZone && rhs.timeSpec() != Qt::TimeZone ? lhs : rhs;
}
static Ticket mergeValue(const Ticket &lhs, const Ticket &rhs)
{
auto t = JsonLdDocument::apply(lhs, rhs).value<Ticket>();
// prefer barcode ticket tokens over URLs
if (t.ticketTokenType() == Ticket::Url && lhs.ticketTokenType() != Ticket::Url && lhs.ticketTokenType() != Ticket::Unknown) {
t.setTicketToken(lhs.ticketToken());
}
return t;
}
QVariant MergeUtil::merge(const QVariant &lhs, const QVariant &rhs)
{
if (rhs.isNull()) {
......@@ -415,6 +426,8 @@ QVariant MergeUtil::merge(const QVariant &lhs, const QVariant &rhs)
rv = mergeValue(lv.value<Airline>(), rv.value<Airline>());
} else if (mt == qMetaTypeId<QDateTime>()) {
rv = mergeValue(lv.toDateTime(), rv.toDateTime());
} else if (mt == qMetaTypeId<Ticket>()) {
rv = mergeValue(lv.value<Ticket>(), rv.value<Ticket>());
} else if (QMetaType(mt).metaObject()) {
rv = merge(prop.readOnGadget(lhs.constData()), rv);
}
......
Markdown is supported
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