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

Add method to check if an ical event can be created from a reservation

This is taken from the KMail plug-in, but is also needed for PBI.
parent 0df50ee7
......@@ -77,7 +77,9 @@ private Q_SLOTS:
ExtractorPostprocessor postproc;
postproc.process(preData);
QCOMPARE(inArray.size(), postproc.result().size());
const auto postData = postproc.result();
QVERIFY(std::all_of(postData.begin(), postData.end(), CalendarHandler::canCreateEvent));
QCOMPARE(inArray.size(), postData.size());
MemoryCalendar::Ptr refCal(new MemoryCalendar(QTimeZone::systemTimeZone()));
ICalFormat format;
......@@ -86,7 +88,7 @@ private Q_SLOTS:
const auto refEvents = refCal->rawEvents(KCalendarCore::EventSortStartDate, KCalendarCore::SortDirectionAscending);
QCOMPARE(refEvents.size(), 1);
Event::Ptr newEvent(new Event);
CalendarHandler::fillEvent(postproc.result(), newEvent);
CalendarHandler::fillEvent(postData, newEvent);
// sync volatile fields, we only care for differences elsewhere
const auto &refEvent = refEvents.at(0);
......
......@@ -121,6 +121,22 @@ QVector<QVariant> CalendarHandler::reservationsForEvent(const QSharedPointer<KCa
#endif
}
bool CalendarHandler::canCreateEvent(const QVariant &reservation)
{
#ifdef HAVE_KCAL
if (JsonLd::isA<FlightReservation>(reservation)) {
const auto f = reservation.value<FlightReservation>().reservationFor().value<Flight>();
if (f.departureTime().isValid() && f.arrivalTime().isValid()) {
return true;
}
}
return SortUtil::startDateTime(reservation).isValid();
#else
Q_UNUSED(reservation);
return false;
#endif
}
void CalendarHandler::fillEvent(const QVector<QVariant> &reservations, const QSharedPointer<KCalendarCore::Event> &event)
{
if (reservations.isEmpty()) {
......
......@@ -46,11 +46,14 @@ namespace CalendarHandler
*/
KITINERARY_EXPORT QVector<QVariant> reservationsForEvent(const QSharedPointer<KCalendarCore::Event> &event);
/** Checks if the given @p reservation contains enough information to create an iCal event from it. */
KITINERARY_EXPORT bool canCreateEvent(const QVariant &reservation);
/** Fills @p event with details of @p reservations.
* Can be used on new events or to update existing ones.
* @param reservations When passing more than one reservation here, those most be for the same multi-traveler trip.
* @param event The event.
* @param reservations When passing more than one reservation here, those must be for the same multi-traveler trip.
* That is, MergeUtil::isSame() returns true for Reservation::reservationFor for each pair of values.
* @param event The event.
*/
KITINERARY_EXPORT void fillEvent(const QVector<QVariant> &reservations, const QSharedPointer<KCalendarCore::Event> &event);
}
......
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