diff --git a/plugins/messageviewer/bodypartformatter/autotests/calendarhandlerdata/flight.ics b/plugins/messageviewer/bodypartformatter/autotests/calendarhandlerdata/flight.ics index be7ecdd9..c091081b 100644 --- a/plugins/messageviewer/bodypartformatter/autotests/calendarhandlerdata/flight.ics +++ b/plugins/messageviewer/bodypartformatter/autotests/calendarhandlerdata/flight.ics @@ -1,17 +1,18 @@ BEGIN:VCALENDAR VERSION:2.0 CALSCALE:GREGORIAN BEGIN:VEVENT DTSTAMP:20171227T111649Z CREATED:20171227T111649Z UID:1b22236a-21ff-4885-8c99-b3b2bbca062c LAST-MODIFIED:20171227T111649Z DESCRIPTION:Booking reference: XXX007 SUMMARY:Flight AB 8075 from HEL to TXL LOCATION:Helsinki +GEO:60.317200;24.963301 DTSTART;TZID=Europe/Helsinki:20170920T150500 DTEND;TZID=Europe/Berlin:20170920T160000 TRANSP:OPAQUE END:VEVENT END:VCALENDAR diff --git a/plugins/messageviewer/bodypartformatter/autotests/calendarhandlerdata/train.ics b/plugins/messageviewer/bodypartformatter/autotests/calendarhandlerdata/train.ics index 6fa9818c..9b7f4862 100644 --- a/plugins/messageviewer/bodypartformatter/autotests/calendarhandlerdata/train.ics +++ b/plugins/messageviewer/bodypartformatter/autotests/calendarhandlerdata/train.ics @@ -1,17 +1,18 @@ BEGIN:VCALENDAR VERSION:2.0 CALSCALE:GREGORIAN BEGIN:VEVENT DTSTAMP:20171227T111649Z CREATED:20171227T111649Z UID:1b22236a-21ff-4885-8c99-b3b2bbca062c LAST-MODIFIED:20171227T111649Z DESCRIPTION:Coach: 17\nSeat: 62\nBooking reference: XXX007 SUMMARY:Train 5186 from Nîmes Gare to Lyon Part-Dieu LOCATION:Nîmes Gare +GEO:43.832291;4.365845 DTSTART;TZID="UTC+02:00":20170929T182600 DTEND;TZID="UTC+02:00":20170929T195200 TRANSP:OPAQUE END:VEVENT END:VCALENDAR diff --git a/plugins/messageviewer/bodypartformatter/semantic/calendarhandler.cpp b/plugins/messageviewer/bodypartformatter/semantic/calendarhandler.cpp index 5d369705..0c27c8b6 100644 --- a/plugins/messageviewer/bodypartformatter/semantic/calendarhandler.cpp +++ b/plugins/messageviewer/bodypartformatter/semantic/calendarhandler.cpp @@ -1,136 +1,151 @@ /* Copyright (c) 2017 Volker Krause This library 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 library 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 Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "calendarhandler.h" #include "datatypes.h" #include "jsonlddocument.h" #include "semantic_debug.h" #include using namespace KCalCore; void CalendarHandler::fillEvent(const QVariant &reservation, const KCalCore::Event::Ptr &event) { const int typeId = reservation.userType(); if (typeId == qMetaTypeId()) { return fillFlightReservation(reservation, event); } else if (typeId == qMetaTypeId()) { return fillLodgingReservation(reservation, event); } else if (typeId == qMetaTypeId()) { return fillTrainReservation(reservation, event); } } void CalendarHandler::fillFlightReservation(const QVariant &reservation, const KCalCore::Event::Ptr &event) { const auto flight = JsonLdDocument::readProperty(reservation, "reservationFor"); const auto airline = JsonLdDocument::readProperty(flight, "airline"); const auto depPort = JsonLdDocument::readProperty(flight, "departureAirport"); const auto arrPort = JsonLdDocument::readProperty(flight, "arrivalAirport"); if (flight.isNull() || airline.isNull() || depPort.isNull() || arrPort.isNull()) { qCDebug(SEMANTIC_LOG) << "got invalid flight reservation"; return; } event->setSummary(i18n("Flight %1 %2 from %3 to %4", JsonLdDocument::readProperty(airline, "iataCode").toString(), JsonLdDocument::readProperty(flight, "flightNumber").toString(), JsonLdDocument::readProperty(depPort, "iataCode").toString(), JsonLdDocument::readProperty(arrPort, "iataCode").toString() )); event->setLocation(JsonLdDocument::readProperty(depPort, "name").toString()); + fillGeoPosition(depPort, event); event->setDtStart(JsonLdDocument::readProperty(flight, "departureTime").toDateTime()); event->setDtEnd(JsonLdDocument::readProperty(flight, "arrivalTime").toDateTime()); event->setAllDay(false); event->setDescription(i18n("Booking reference: %1", JsonLdDocument::readProperty(reservation, "reservationNumber").toString() )); } void CalendarHandler::fillTrainReservation(const QVariant &reservation, const KCalCore::Event::Ptr &event) { const auto trip = JsonLdDocument::readProperty(reservation, "reservationFor"); const auto depStation = JsonLdDocument::readProperty(trip, "departureStation"); const auto arrStation = JsonLdDocument::readProperty(trip, "arrivalStation"); if (trip.isNull() || depStation.isNull() || arrStation.isNull()) { return; } event->setSummary(i18n("Train %1 from %2 to %3", JsonLdDocument::readProperty(trip, "trainNumber").toString(), JsonLdDocument::readProperty(depStation, "name").toString(), JsonLdDocument::readProperty(arrStation, "name").toString() )); event->setLocation(JsonLdDocument::readProperty(depStation, "name").toString()); + fillGeoPosition(depStation, event); event->setDtStart(JsonLdDocument::readProperty(trip, "departureTime").toDateTime()); event->setDtEnd(JsonLdDocument::readProperty(trip, "arrivalTime").toDateTime()); event->setAllDay(false); QStringList desc; auto s = JsonLdDocument::readProperty(trip, "departurePlatform").toString(); if (!s.isEmpty()) { desc.push_back(i18n("Departure platform: %1", s)); } const auto ticket = JsonLdDocument::readProperty(reservation, "reservedTicket"); const auto seat = JsonLdDocument::readProperty(ticket, "ticketedSeat"); s = JsonLdDocument::readProperty(seat, "seatSection").toString(); if (!s.isEmpty()) { desc.push_back(i18n("Coach: %1", s)); } s = JsonLdDocument::readProperty(seat, "seatNumber").toString(); if (!s.isEmpty()) { desc.push_back(i18n("Seat: %1", s)); } s = JsonLdDocument::readProperty(trip, "arrivalPlatform").toString(); if (!s.isEmpty()) { desc.push_back(i18n("Arrival platform: %1", s)); } s = JsonLdDocument::readProperty(reservation, "reservationNumber").toString(); if (!s.isEmpty()) { desc.push_back(i18n("Booking reference: %1", s)); } event->setDescription(desc.join(QLatin1Char('\n'))); } void CalendarHandler::fillLodgingReservation(const QVariant &reservation, const KCalCore::Event::Ptr &event) { const auto lodgingBusiness = JsonLdDocument::readProperty(reservation, "reservationFor"); const auto address = JsonLdDocument::readProperty(lodgingBusiness, "address"); if (lodgingBusiness.isNull() || address.isNull()) { return; } event->setSummary(i18n("Hotel reservation: %1", JsonLdDocument::readProperty(lodgingBusiness, "name").toString() )); event->setLocation(i18n("%1, %2 %3, %4", JsonLdDocument::readProperty(address, "streetAddress").toString(), JsonLdDocument::readProperty(address, "postalCode").toString(), JsonLdDocument::readProperty(address, "addressLocality").toString(), JsonLdDocument::readProperty(address, "addressCountry").toString() )); + fillGeoPosition(lodgingBusiness, event); event->setDtStart(QDateTime(JsonLdDocument::readProperty(reservation, "checkinDate").toDate(), QTime())); event->setDtEnd(QDateTime(JsonLdDocument::readProperty(reservation, "checkoutDate").toDate(), QTime())); event->setAllDay(true); event->setDescription(i18n("Booking reference: %1", JsonLdDocument::readProperty(reservation, "reservationNumber").toString() )); event->setTransparency(Event::Transparent); } + +void CalendarHandler::fillGeoPosition(const QVariant &place, const KCalCore::Event::Ptr &event) +{ + const auto geo = JsonLdDocument::readProperty(place, "geo"); + if (geo.isNull()) { + return; + } + + event->setHasGeo(true); + event->setGeoLatitude(JsonLdDocument::readProperty(geo, "latitude").toFloat()); + event->setGeoLongitude(JsonLdDocument::readProperty(geo, "longitude").toFloat()); +} diff --git a/plugins/messageviewer/bodypartformatter/semantic/calendarhandler.h b/plugins/messageviewer/bodypartformatter/semantic/calendarhandler.h index 0a07005f..d53fb902 100644 --- a/plugins/messageviewer/bodypartformatter/semantic/calendarhandler.h +++ b/plugins/messageviewer/bodypartformatter/semantic/calendarhandler.h @@ -1,39 +1,40 @@ /* Copyright (c) 2017 Volker Krause This library 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 library 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 Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef CALENDARHANDLER_H #define CALENDARHANDLER_H #include class QVariant; /** Methods for converting between ical events and JSON-LD booking data. */ class CalendarHandler { public: static void fillEvent(const QVariant &reservation, const KCalCore::Event::Ptr &event); private: static void fillFlightReservation(const QVariant &reservation, const KCalCore::Event::Ptr &event); static void fillTrainReservation(const QVariant &reservation, const KCalCore::Event::Ptr &event); static void fillLodgingReservation(const QVariant &reservation, const KCalCore::Event::Ptr &event); + static void fillGeoPosition(const QVariant &place, const KCalCore::Event::Ptr &event); }; #endif // CALENDARHANDLER_H