Commit 73cacb99 authored by Volker Krause's avatar Volker Krause
Browse files

Add ERA SSB extractor document processor

parent b833d10c
......@@ -67,6 +67,7 @@ set(kitinerary_lib_srcs
processors/mimedocumentprocessor.cpp
processors/pdfdocumentprocessor.cpp
processors/pkpassdocumentprocessor.cpp
processors/ssbdocumentprocessor.cpp
processors/textdocumentprocessor.cpp
processors/uic9183documentprocessor.cpp
processors/vdvdocumentprocessor.cpp
......
......@@ -18,6 +18,7 @@
#include "processors/mimedocumentprocessor.h"
#include "processors/pdfdocumentprocessor.h"
#include "processors/pkpassdocumentprocessor.h"
#include "processors/ssbdocumentprocessor.h"
#include "processors/textdocumentprocessor.h"
#include "processors/uic9183documentprocessor.h"
#include "processors/vdvdocumentprocessor.h"
......@@ -113,6 +114,7 @@ void ExtractorDocumentNodeFactoryStatic::registerBuiltIn()
registerProcessor<PkPassDocumentProcessor>(u"application/vnd.apple.pkpass");
registerProcessor<IcalEventProcessor>(u"internal/event");
registerProcessor<ImageDocumentProcessor>(u"internal/qimage", {u"image/png"});
registerProcessor<SsbDocumentProcessor>(u"internal/era-ssb");
registerProcessor<Uic9183DocumentProcessor>(u"internal/uic9183");
registerProcessor<VdvDocumentProcessor>(u"internal/vdv");
registerProcessor<IcalCalendarProcessor>(u"text/calendar");
......
/*
SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "ssbdocumentprocessor.h"
#include "era/ssbticket.h"
#include <KItinerary/ExtractorFilter>
#include <QMetaProperty>
using namespace KItinerary;
bool SsbDocumentProcessor::canHandleData(const QByteArray &encodedData, [[maybe_unused]] QStringView fileName) const
{
return SSBTicket::maybeSSB(encodedData);
}
ExtractorDocumentNode SsbDocumentProcessor::createNodeFromData(const QByteArray &encodedData) const
{
ExtractorDocumentNode node;
auto ticket = SSBTicket(encodedData);
if (ticket.isValid()) {
node.setContent(ticket);
}
return node;
}
bool SsbDocumentProcessor::matches(const ExtractorFilter &filter, const ExtractorDocumentNode &node) const
{
const auto ticket = node.content<SSBTicket>();
const auto propIdx = SSBTicket::staticMetaObject.indexOfProperty(filter.fieldName().toUtf8().constData());
if (propIdx < 0) {
return false;
}
const auto prop = SSBTicket::staticMetaObject.property(propIdx);
const auto value = prop.readOnGadget(&ticket);
return filter.matches(value.toString());
}
/*
SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#ifndef KITINERARY_SSBDOCUMENTPROCESSOR_H
#define KITINERARY_SSBDOCUMENTPROCESSOR_H
#include <KItinerary/ExtractorDocumentProcessor>
namespace KItinerary {
/** Document processor for ERA SSB ticket barcodes. */
class SsbDocumentProcessor : public ExtractorDocumentProcessor
{
public:
bool canHandleData(const QByteArray &encodedData, QStringView fileName) const override;
ExtractorDocumentNode createNodeFromData(const QByteArray &encodedData) const override;
bool matches(const KItinerary::ExtractorFilter &filter, const ExtractorDocumentNode &node) const override;
};
}
#endif // KITINERARY_SSBDOCUMENTPROCESSOR_H
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