KItinerary
pkpassdocumentprocessor.cpp
44bool PkPassDocumentProcessor::canHandleData(const QByteArray &encodedData, QStringView fileName) const
50ExtractorDocumentNode PkPassDocumentProcessor::createNodeFromData(const QByteArray &encodedData) const
60 node.setContextDateTime(pass->relevantDate().addDays(-1)); // go a bit back, to compensate for unknown departure timezone at this point
65ExtractorDocumentNode PkPassDocumentProcessor::createNodeFromContent(const QVariant &decodedData) const
75 node.setContextDateTime(pass->relevantDate().addDays(-1)); // go a bit back, to compensate for unknown departure timezone at this point
80void PkPassDocumentProcessor::expandNode(ExtractorDocumentNode &node, const ExtractorEngine *engine) const
92 if (std::any_of(msg.begin(), msg.end(), [](QChar c) { return c.isNonCharacter() || c.isNull() || !c.isPrint(); })) {
107QJSValue PkPassDocumentProcessor::contentToScriptValue(const ExtractorDocumentNode &node, QJSEngine *engine) const
133 if (s.isEmpty() || s.size() > 10 || s.count(QLatin1Char('-')) > 1 || s.count(QLatin1Char(' ')) > 2) {
152 if (!flight.boardingTime().isValid() && field.key().contains("boarding"_L1, Qt::CaseInsensitive)) {
169 if (!flight.departureTime().isValid() && field.key().contains("departure"_L1, Qt::CaseInsensitive)) {
191 // "relevantDate" is the best guess for the boarding time if we didn't find an explicit field for it
193 const auto tz = KnowledgeDb::timezoneForAirport(KnowledgeDb::IataCode{flight.departureAirport().iataCode()});
252[[nodiscard]] static TrainReservation extractTrainTicket(KPkPass::Pass *pass, TrainReservation res)
261 if (trip.departurePlatform().isEmpty() && field.key().contains("track"_L1, Qt::CaseInsensitive)) {
269 if (!trip.departureTime().isValid() && field.key().contains("departure"_L1, Qt::CaseInsensitive)) {
278 if (ticket.ticketedSeat().seatSection().isEmpty() && field.key().contains("coach"_L1, Qt::CaseInsensitive)) {
283 if (ticket.ticketedSeat().seatNumber().isEmpty() && field.key().contains("seat"_L1, Qt::CaseInsensitive)) {
290 // "relevantDate" is the best guess for the departure time if we didn't find an explicit field for it
332 if (pass->expirationDate().isValid() && pass->relevantDate().date() == pass->expirationDate().date() &&
376void PkPassDocumentProcessor::preExtract(ExtractorDocumentNode &node, [[maybe_unused]] const ExtractorEngine *engine) const
440 // if this doesn't contain a single IATA BCBP we wont be able to get sufficient information out of this
444 res = JsonLdDocument::apply(node.childNodes()[0].result().result().at(0), res).value<FlightReservation>();
454 res = JsonLdDocument::apply(JsonLdDocument::fromJsonSingular(ReservationConverter::flightToTrain(flightRes)), res).value<TrainReservation>();
456 res = JsonLdDocument::apply(node.childNodes()[0].result().result().at(0), res).value<TrainReservation>();
470 flightRes.setReservationFor(extractBoardingPass(pass, flightRes.reservationFor().value<Flight>()));
505void PkPassDocumentProcessor::postExtract(ExtractorDocumentNode &node, [[maybe_unused]] const ExtractorEngine *engine) const
515 DocumentUtil::addDocumentId(res, DocumentUtil::idForPkPass(pass->passTypeIdentifier(), pass->serialNumber()));
519 // pass->relevantDate() as modification time is inherently unreliable (it wont change most of the time)
522 JsonLdDocument::writeProperty(res, "modifiedTime", node.parent().contextDateTime().toString(Qt::ISODate));
ExtractorDocumentNode createNode(const QByteArray &data, QStringView fileName={}, QStringView mimeType={}) const
Create a new document node from data.
Definition extractordocumentnodefactory.cpp:159
A node in the extracted document object tree.
Definition extractordocumentnode.h:50
void setResult(ExtractorResult &&result)
Replace the existing results by result.
Definition extractordocumentnode.cpp:160
void appendChild(ExtractorDocumentNode &child)
Add another child node.
Definition extractordocumentnode.cpp:141
void setContextDateTime(const QDateTime &contextDateTime)
Set the context date/time.
Definition extractordocumentnode.cpp:173
QDateTime contextDateTime
The best known context date/time at this point in the document tree.
Definition extractordocumentnode.h:68
void setContent(const QVariant &content)
Set decoded content.
Definition extractordocumentnode.cpp:120
KItinerary::ExtractorDocumentNode parent
The parent node, or a null node if this is the root node.
Definition extractordocumentnode.h:55
const ExtractorDocumentNodeFactory * documentNodeFactory() const
Factory for creating new document nodes.
Definition engine/extractorengine.cpp:172
static void writeProperty(QVariant &obj, const char *name, const QVariant &value)
Set property name on object obj to value value.
Definition jsonlddocument.cpp:538
static QVariant apply(const QVariant &lhs, const QVariant &rhs)
Apply all properties of rhs on to lhs.
Definition jsonlddocument.cpp:564
static QVariant fromJsonSingular(const QJsonObject &obj)
Convert a single JSON-LD object into an instantiated data type.
Definition jsonlddocument.cpp:361
Processor for Apple Wallet pass files.
Definition pkpassdocumentprocessor.h:15
void preExtract(ExtractorDocumentNode &node, const ExtractorEngine *engine) const override
Called before extractors are applied to node.
Definition pkpassdocumentprocessor.cpp:376
ExtractorDocumentNode createNodeFromContent(const QVariant &decodedData) const override
Create a document node from an already decoded data type.
Definition pkpassdocumentprocessor.cpp:65
QJSValue contentToScriptValue(const ExtractorDocumentNode &node, QJSEngine *engine) const override
Create a QJSValue for the node content.
Definition pkpassdocumentprocessor.cpp:107
ExtractorDocumentNode createNodeFromData(const QByteArray &encodedData) const override
Create a document node from raw data.
Definition pkpassdocumentprocessor.cpp:50
void postExtract(ExtractorDocumentNode &node, const ExtractorEngine *engine) const override
Called after extractors have been applied to node.
Definition pkpassdocumentprocessor.cpp:505
void destroyNode(ExtractorDocumentNode &node) const override
Destroys type-specific data in node.
Definition pkpassdocumentprocessor.cpp:102
void expandNode(ExtractorDocumentNode &node, const ExtractorEngine *engine) const override
Create child nodes for node, as far as that's necessary for this document type.
Definition pkpassdocumentprocessor.cpp:80
static Pass * fromData(const QByteArray &data, QObject *parent=nullptr)
AKONADI_CALENDAR_EXPORT KCalendarCore::Event::Ptr event(const Akonadi::Item &item)
bool addDocumentId(QVariant &obj, const QString &id)
Add a document id to the object obj.
Definition documentutil.cpp:35
QString idForPkPass(const QString &passTypeIdentifier, const QString &serialNumber)
Determine a document identifier for a Apple Wallet pass.
Definition documentutil.cpp:26
QTimeZone timezoneForAirport(IataCode iataCode)
Returns the timezone the airport with IATA code iataCode is in.
Definition airportdb.cpp:40
std::vector< IataCode > iataCodesFromName(QStringView name)
Returns all possible IATA code candidates for the given airport name.
Definition airportdb.cpp:209
GeoCoordinates geo(const QVariant &location)
Returns the geo coordinates of a given location.
Definition locationutil.cpp:119
QJsonObject flightToTrain(const QJsonObject &flightRes)
Convert a flight reservation to a train reservation.
Definition reservationconverter.cpp:86
Classes for reservation/travel data models, data extraction and data augmentation.
Definition berelement.h:17
bool isValid() const const
QString toString(QStringView format, QCalendar cal) const const
QJSValue toScriptValue(const T &value)
bool isEmpty() const const
iterator insert(QLatin1StringView key, const QJsonValue &value)
qsizetype count() const const
bool isEmpty() const const
bool isNull() const const
qsizetype size() const const
CaseInsensitive
ISODate
T value() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:56:37 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:56:37 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.