Commit 6f94a085 authored by Volker Krause's avatar Volker Krause
Browse files

Add a generic extraction path for ical files too

So far this is just recovering our own custom property if present, which
is needed by PBI.
parent 5809ceb1
......@@ -18,3 +18,5 @@ Makefile
.cmake/
CMakeLists.txt.user*
*.unc-backup*
*.fail
*.rej
BEGIN:VCALENDAR
PRODID:-//K Desktop Environment//NONSGML libkcal 4.3//EN
VERSION:2.0
CALSCALE:GREGORIAN
BEGIN:VEVENT
DTSTAMP:20171227T111649Z
X-KDE-KITINERARY-RESERVATION:[{"@context":"http://schema.org"\,"@type":
"EventReservation"\,"reservationFor":{"@type":"Event"\,"endDate":{"@type":
"QDateTime"\,"@value":"2019-07-13T16:30:00+02:00"\,"timezone":
"Europe/Rome"}\,"location":{"@type":"Place"\,"address":{"@type":
"PostalAddress"\,"addressCountry":"IT"\,"addressLocality":
"Milan"\,"addressRegion":"Lombardy"\,"postalCode":
"20126"\,"streetAddress":"Piazza dell'Ateneo Nuovo\, 1"}\,"name":
"University of Milano-Bicocca"}\,"name":"Akademy 2019"\,"startDate":
{"@type":"QDateTime"\,"@value":"2019-09-07T09:30:00+02:00"\,"timezone":
"Europe/Rome"}}\,"reservationNumber":"42"\,"underName":{"@type":
"Person"\,"name":"Dr Konqui"}}\,{"@context":"http://schema.org"\,"@type":
"EventReservation"\,"reservationFor":{"@type":"Event"\,"endDate":{"@type":
"QDateTime"\,"@value":"2019-07-13T16:30:00+02:00"\,"timezone":
"Europe/Rome"}\,"location":{"@type":"Place"\,"address":{"@type":
"PostalAddress"\,"addressCountry":"IT"\,"addressLocality":
"Milan"\,"addressRegion":"Lombardy"\,"postalCode":
"20126"\,"streetAddress":"Piazza dell'Ateneo Nuovo\, 1"}\,"name":
"University of Milano-Bicocca"}\,"name":"Akademy 2019"\,"startDate":
{"@type":"QDateTime"\,"@value":"2019-09-07T09:30:00+02:00"\,"timezone":
"Europe/Rome"}}\,"reservationNumber":"42"\,"underName":{"@type":
"Person"\,"name":"Katie Dragon"}}]
CREATED:20171227T111649Z
UID:KIT-1234567890-1b22236a-21ff-4885-8c99-b3b2bbca062c
LAST-MODIFIED:20171227T111649Z
DESCRIPTION:Dr Konqui\nBooking reference: 42\nKatie Dragon\nBooking reference: 42
SUMMARY:Akademy 2019
LOCATION:University of Milano-Bicocca
DTSTART;TZID=Europe/Rome:20190907T093000
DTEND;TZID=Europe/Rome:20190713T163000
TRANSP:OPAQUE
END:VEVENT
END:VCALENDAR
[
{
"@context": "http://schema.org",
"@type": "EventReservation",
"modifiedTime": "2018-01-01T00:00:00",
"reservationFor": {
"@type": "Event",
"endDate": {
"@type": "QDateTime",
"@value": "2019-07-13T16:30:00+02:00",
"timezone": "Europe/Rome"
},
"location": {
"@type": "Place",
"address": {
"@type": "PostalAddress",
"addressCountry": "IT",
"addressLocality": "Milan",
"addressRegion": "Lombardy",
"postalCode": "20126",
"streetAddress": "Piazza dell'Ateneo Nuovo, 1"
},
"name": "University of Milano-Bicocca"
},
"name": "Akademy 2019",
"startDate": {
"@type": "QDateTime",
"@value": "2019-09-07T09:30:00+02:00",
"timezone": "Europe/Rome"
}
},
"reservationNumber": "42",
"underName": {
"@type": "Person",
"name": "Dr Konqui"
}
},
{
"@context": "http://schema.org",
"@type": "EventReservation",
"modifiedTime": "2018-01-01T00:00:00",
"reservationFor": {
"@type": "Event",
"endDate": {
"@type": "QDateTime",
"@value": "2019-07-13T16:30:00+02:00",
"timezone": "Europe/Rome"
},
"location": {
"@type": "Place",
"address": {
"@type": "PostalAddress",
"addressCountry": "IT",
"addressLocality": "Milan",
"addressRegion": "Lombardy",
"postalCode": "20126",
"streetAddress": "Piazza dell'Ateneo Nuovo, 1"
},
"name": "University of Milano-Bicocca"
},
"name": "Akademy 2019",
"startDate": {
"@type": "QDateTime",
"@value": "2019-09-07T09:30:00+02:00",
"timezone": "Europe/Rome"
}
},
"reservationNumber": "42",
"underName": {
"@type": "Person",
"name": "Katie Dragon"
}
}
]
......@@ -25,6 +25,7 @@ set(kitinerary_lib_srcs
datatypes/visit.cpp
generic/genericextractor.cpp
generic/genericicalextractor.cpp
generic/genericpdfextractor.cpp
generic/genericpkpassextractor.cpp
generic/genericuic918extractor.cpp
......
......@@ -24,6 +24,7 @@
#include "extractorinput.h"
#include "extractorrepository.h"
#include "generic/genericpdfextractor_p.h"
#include "generic/genericicalextractor_p.h"
#include "generic/genericpkpassextractor_p.h"
#include "generic/genericuic918extractor_p.h"
#include "generic/genericvdvextractor_p.h"
......@@ -498,6 +499,11 @@ void ExtractorEnginePrivate::extractGeneric()
else if (m_pass) {
m_genericResults.emplace_back(GenericPkPassExtractor::extract(m_pass.get(), m_context->m_senderDate));
}
#ifdef HAVE_KCAL
else if (m_calendar) {
m_genericResults = GenericIcalExtractor::extract(m_calendar);
}
#endif
else if (!m_text.isEmpty()) {
if (IataBcbpParser::maybeIataBcbp(m_text)) {
const auto res = IataBcbpParser::parse(m_text, m_context->m_senderDate.date());
......
/*
Copyright (C) 2020 Volker Krause <vkrause@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <config-kitinerary.h>
#include "genericicalextractor_p.h"
#include "genericextractor_p.h"
#ifdef HAVE_KCAL
#include <KCalendarCore/Calendar>
#include <KCalendarCore/Event>
#include <QDebug>
#include <QJsonArray>
#include <QJsonDocument>
using namespace KItinerary;
static GenericExtractor::Result extractEvent(const KCalendarCore::Event::Ptr &event)
{
const auto data = event->customProperty("KITINERARY", "RESERVATION");
if (data.isEmpty()) {
return {};
}
const auto array = QJsonDocument::fromJson(data.toUtf8()).array();
if (array.isEmpty()) {
return {};
}
return GenericExtractor::Result(array);
}
std::vector<GenericExtractor::Result> GenericIcalExtractor::extract(const KCalendarCore::Calendar::Ptr &calendar)
{
std::vector<GenericExtractor::Result> results;
for (const auto &event : calendar->events()) {
auto res = extractEvent(event);
if (!res.isEmpty()) {
results.push_back(std::move(res));
}
}
return results;
}
#endif
/*
Copyright (C) 2020 Volker Krause <vkrause@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef KITINERARY_GENERICICALEXTRACTOR_P_H
#define KITINERARY_GENERICICALEXTRACTOR_P_H
#include <QSharedPointer>
#include <vector>
namespace KCalendarCore {
class Calendar;
}
namespace KItinerary {
namespace GenericExtractor {
class Result;
}
/** Generic extraction from ical calendars/events. */
namespace GenericIcalExtractor
{
std::vector<GenericExtractor::Result> extract(const QSharedPointer<KCalendarCore::Calendar> &calendar);
}
}
#endif // KITINERARY_GENERICICALEXTRACTOR_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