Commit 5809ceb1 authored by Volker Krause's avatar Volker Krause
Browse files

Allow to generate iCal events for schema.org Events too

So far this was only working with EventReservation objects, but PBI can
also encounter the raw events.
parent db8269d8
BEGIN:VCALENDAR
VERSION:2.0
CALSCALE:GREGORIAN
BEGIN:VEVENT
DTSTAMP:20171227T111649Z
X-KDE-KITINERARY-RESERVATION:[{"@context":"http://schema.org"\,"@type":
"Event"\,"description":"For most of the year\, KDE—one of the largest free and open software communities in the world — works on-line by email\, IRC\, forums and mailing lists. Akademy provides all KDE contributors the opportunity to meet in person to foster social bonds\, work on concrete technology issues\, consider new ideas\, and reinforce the innovative\, dynamic culture of KDE. Akademy brings together artists\, designers\, developers\, translators\, users\, writers\, sponsors and many other types of KDE contributors to celebrate the achievements of the past year and help determine the direction for the next year. Hands-on sessions offer the opportunity for intense work bringing those plans to reality. The KDE community welcomes companies building on KDE technology\, and those that are looking for opportunities. For more information\, please contact the Akademy Team."\,"doorTime":{"@type":"QDateTime"\,"@value":"2019-07-13T08:30:00+02:00"\,"timezone":"Europe/Rome"}\,
"endDate":{"@type":"QDateTime"\,"@value":"2019-07-13T16:30:00+02:00"\,
"timezone":"Europe/Rome"}\,"image":"https://akademy.kde.org/sites/akademy.kde.org/files/2019/milanpanoramic.jpg"\,
"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"}\,"url":"https://akademy.kde.org/2019"}]
CREATED:20171227T111649Z
UID:KIT-1234567890-1b22236a-21ff-4885-8c99-b3b2bbca062c
LAST-MODIFIED:20171227T111649Z
SUMMARY:Akademy 2019
LOCATION:University of Milano-Bicocca
DTSTART;TZID=Europe/Rome:20190907T093000
DTEND;TZID=Europe/Rome:20190713T163000
TRANSP:OPAQUE
BEGIN:VALARM
DESCRIPTION:Entrance for Akademy 2019
ACTION:DISPLAY
TRIGGER:-P56DT1H
X-KDE-KCALCORE-ENABLED:TRUE
END:VALARM
END:VEVENT
END:VCALENDAR
[
{
"@context": "http://schema.org",
"@type": "Event",
"description": "For most of the year, KDE—one of the largest free and open software communities in the world — works on-line by email, IRC, forums and mailing lists. Akademy provides all KDE contributors the opportunity to meet in person to foster social bonds, work on concrete technology issues, consider new ideas, and reinforce the innovative, dynamic culture of KDE. Akademy brings together artists, designers, developers, translators, users, writers, sponsors and many other types of KDE contributors to celebrate the achievements of the past year and help determine the direction for the next year. Hands-on sessions offer the opportunity for intense work bringing those plans to reality. The KDE community welcomes companies building on KDE technology, and those that are looking for opportunities. For more information, please contact the Akademy Team.",
"doorTime": {
"@type": "QDateTime",
"@value": "2019-07-13T08:30:00+02:00",
"timezone": "Europe/Rome"
},
"endDate": {
"@type": "QDateTime",
"@value": "2019-07-13T16:30:00+02:00",
"timezone": "Europe/Rome"
},
"image": "https://akademy.kde.org/sites/akademy.kde.org/files/2019/milanpanoramic.jpg",
"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"
},
"url": "https://akademy.kde.org/2019"
}
]
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",
"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"
}
}
]
......@@ -84,26 +84,24 @@ private Q_SLOTS:
format.load(refCal, icalFile);
const auto refEvents = refCal->rawEvents(KCalendarCore::EventSortStartDate, KCalendarCore::SortDirectionAscending);
QCOMPARE(refEvents.size(), inArray.size());
for (int i = 0; i < inArray.size(); ++i) {
Event::Ptr newEvent(new Event);
CalendarHandler::fillEvent(postproc.result(), newEvent);
// sync volatile fields, we only care for differences elsewhere
const auto &refEvent = refEvents.at(i);
newEvent->setUid(refEvent->uid());
newEvent->setLastModified(refEvent->lastModified());
newEvent->setCreated(refEvent->created());
if (*newEvent != *refEvent) {
qDebug().noquote() << "Actual: " << format.toICalString(newEvent);
qDebug().noquote() << "Expected: " << format.toICalString(refEvent);
}
QCOMPARE(newEvent->dtStart(), refEvent->dtStart());
QCOMPARE(newEvent->dtEnd(), refEvent->dtEnd());
QVERIFY(*newEvent == *refEvent);
QCOMPARE(refEvents.size(), 1);
Event::Ptr newEvent(new Event);
CalendarHandler::fillEvent(postproc.result(), newEvent);
// sync volatile fields, we only care for differences elsewhere
const auto &refEvent = refEvents.at(0);
newEvent->setUid(refEvent->uid());
newEvent->setLastModified(refEvent->lastModified());
newEvent->setCreated(refEvent->created());
if (*newEvent != *refEvent) {
qDebug().noquote() << "Actual: " << format.toICalString(newEvent).remove(QLatin1Char('\r'));
qDebug().noquote() << "Expected: " << format.toICalString(refEvent).remove(QLatin1Char('\r'));
}
QCOMPARE(newEvent->dtStart(), refEvent->dtStart());
QCOMPARE(newEvent->dtEnd(), refEvent->dtEnd());
QVERIFY(*newEvent == *refEvent);
}
void testFindEvent_data()
......
......@@ -73,6 +73,7 @@ static void fillFlightReservation(const QVector<QVariant> &reservations, const K
static void fillTrainReservation(const TrainReservation &reservation, const KCalendarCore::Event::Ptr &event);
static void fillBusReservation(const BusReservation &reservation, const KCalendarCore::Event::Ptr &event);
static void fillLodgingReservation(const QVector<QVariant> &reservations, const KCalendarCore::Event::Ptr &event);
static void fillEvent(const KItinerary::Event &ev, const KCalCore::Event::Ptr &event);
static void fillEventReservation(const QVector<QVariant> &reservations, const KCalendarCore::Event::Ptr &event);
static void fillGeoPosition(const QVariant &place, const KCalendarCore::Event::Ptr &event);
static void fillFoodReservation(const FoodEstablishmentReservation &reservation, const KCalendarCore::Event::Ptr &event);
......@@ -83,7 +84,7 @@ static void fillTaxiReservation(const TaxiReservation &reservation, const KCalen
QSharedPointer<KCalendarCore::Event> CalendarHandler::findEvent(const QSharedPointer<KCalendarCore::Calendar> &calendar, const QVariant &reservation)
{
#ifdef HAVE_KCAL
if (!JsonLd::canConvert<Reservation>(reservation) || !calendar) {
if (!(JsonLd::canConvert<Reservation>(reservation) || JsonLd::canConvert<KItinerary::Event>(reservation)) || !calendar) {
return {};
}
......@@ -140,6 +141,8 @@ void CalendarHandler::fillEvent(const QVector<QVariant> &reservations, const QSh
fillBusReservation(reservation.value<BusReservation>(), event);
} else if (JsonLd::isA<EventReservation>(reservation)) {
fillEventReservation(reservations, event);
} else if (JsonLd::isA<Event>(reservation)) {
fillEvent(reservation.value<KItinerary::Event>(), event);
} else if (JsonLd::isA<FoodEstablishmentReservation>(reservation)) {
fillFoodReservation(reservation.value<FoodEstablishmentReservation>(), event);
} else if (JsonLd::isA<RentalCarReservation>(reservation)) {
......@@ -334,9 +337,8 @@ static void fillLodgingReservation(const QVector<QVariant> &reservations, const
event->setDescription(desc.join(QLatin1Char('\n')));
}
static void fillEventReservation(const QVector<QVariant> &reservations, const KCalendarCore::Event::Ptr &event)
static void fillEvent(const KItinerary::Event &ev, const KCalCore::Event::Ptr &event)
{
const auto ev = reservations.at(0).value<EventReservation>().reservationFor().value<KItinerary::Event>();
Place location;
if (JsonLd::canConvert<Place>(ev.location())) {
location = JsonLd::convert<Place>(ev.location());
......@@ -363,6 +365,12 @@ static void fillEventReservation(const QVector<QVariant> &reservations, const KC
event->addAlarm(alarm);
}
}
}
static void fillEventReservation(const QVector<QVariant> &reservations, const KCalendarCore::Event::Ptr &event)
{
const auto ev = reservations.at(0).value<EventReservation>().reservationFor().value<KItinerary::Event>();
fillEvent(ev, event);
QStringList desc;
for (const auto &r : reservations) {
......
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