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 68e9652f authored by Volker Krause's avatar Volker Krause

Detect RCT2 NRT and IRT ticket types

This works for ÖBB, SBB and NS samples, but still fails on DB ones due
to those slightly deviating from the field specification, and due to bugs
in our multi-line field handling.
parent 5d16f25d
......@@ -461,12 +461,35 @@ QDate Rct2Ticket::firstDayOfValidity() const
return d->firstDayOfValidity();
}
static const struct {
const char *name; // case folded
Rct2Ticket::Type type;
} rct2_ticket_type_map[] = {
{ "ticket + reservation", Rct2Ticket::TransportReservation },
{ "ticket", Rct2Ticket::Transport },
{ "billet", Rct2Ticket::Transport },
{ "fahrkarte", Rct2Ticket::Transport },
{ "fahrschein", Rct2Ticket::Transport },
{ "reservation", Rct2Ticket::Reservation }
};
Rct2Ticket::Type Rct2Ticket::type() const
{
// ### this field can theoretically be translated
if (d->fieldText(0, 18, 51).trimmed().compare(QLatin1String("RESERVATION"), Qt::CaseInsensitive) == 0) {
return Reservation;
const auto typeName1 = d->fieldText(0, 18, 51).trimmed().toCaseFolded();
const auto typeName2 = d->fieldText(1, 18, 51).trimmed().toCaseFolded(); // used for alternative language type name
// prefer exact matches
for (auto it = std::begin(rct2_ticket_type_map); it != std::end(rct2_ticket_type_map); ++it) {
if (typeName1 == QLatin1String(it->name) || typeName2 == QLatin1String(it->name)) {
return it->type;
}
}
for (auto it = std::begin(rct2_ticket_type_map); it != std::end(rct2_ticket_type_map); ++it) {
if (typeName1.contains(QLatin1String(it->name)) || typeName2.contains(QLatin1String(it->name))) {
return it->type;
}
}
return Unknown;
}
......
......@@ -67,7 +67,9 @@ public:
* @see ERA TAP TSI Annex B.6.
*/
enum Type {
Reservation, ///< an reservation-only ticket (RES)
Transport, ///< Non-integrated Reservation Ticket (NRT)
TransportReservation, ///< Integration Reservation Ticket (IRT)
Reservation, ///< Reservation Only Document (RES)
Unknown ///< ticket type could not be detected, or ticket type not supported yet
};
Q_ENUM(Type);
......
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