Commit a789129e authored by Volker Krause's avatar Volker Krause
Browse files

Extend ERA SSB document processor to support multiple ticket versions

parent b04c7b10
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "ssbdocumentprocessor.h" #include "ssbdocumentprocessor.h"
#include "era/ssbv1ticket.h"
#include "era/ssbv3ticket.h" #include "era/ssbv3ticket.h"
#include <KItinerary/ExtractorFilter> #include <KItinerary/ExtractorFilter>
...@@ -16,27 +17,38 @@ using namespace KItinerary; ...@@ -16,27 +17,38 @@ using namespace KItinerary;
bool SsbDocumentProcessor::canHandleData(const QByteArray &encodedData, [[maybe_unused]] QStringView fileName) const bool SsbDocumentProcessor::canHandleData(const QByteArray &encodedData, [[maybe_unused]] QStringView fileName) const
{ {
return SSBv3Ticket::maybeSSB(encodedData); return SSBv3Ticket::maybeSSB(encodedData) || SSBv1Ticket::maybeSSB(encodedData);
} }
ExtractorDocumentNode SsbDocumentProcessor::createNodeFromData(const QByteArray &encodedData) const ExtractorDocumentNode SsbDocumentProcessor::createNodeFromData(const QByteArray &encodedData) const
{ {
ExtractorDocumentNode node; ExtractorDocumentNode node;
auto ticket = SSBv3Ticket(encodedData); if (SSBv3Ticket::maybeSSB(encodedData)) {
if (ticket.isValid()) { auto ticket = SSBv3Ticket(encodedData);
node.setContent(ticket); if (ticket.isValid()) {
node.setContent(ticket);
}
} else if (SSBv1Ticket::maybeSSB(encodedData)) {
auto ticket = SSBv1Ticket(encodedData);
if (ticket.isValid()) {
node.setContent(ticket);
}
} }
return node; return node;
} }
bool SsbDocumentProcessor::matches(const ExtractorFilter &filter, const ExtractorDocumentNode &node) const bool SsbDocumentProcessor::matches(const ExtractorFilter &filter, const ExtractorDocumentNode &node) const
{ {
const auto ticket = node.content<SSBv3Ticket>(); const auto ticket = node.content();
const auto propIdx = SSBv3Ticket::staticMetaObject.indexOfProperty(filter.fieldName().toUtf8().constData()); const auto mo = QMetaType(ticket.userType()).metaObject();
if (!mo) {
return false;
}
const auto propIdx = mo->indexOfProperty(filter.fieldName().toUtf8().constData());
if (propIdx < 0) { if (propIdx < 0) {
return false; return false;
} }
const auto prop = SSBv3Ticket::staticMetaObject.property(propIdx); const auto prop = mo->property(propIdx);
const auto value = prop.readOnGadget(&ticket); const auto value = prop.readOnGadget(ticket.constData());
return filter.matches(value.toString()); return filter.matches(value.toString());
} }
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