Commit 667a7414 authored by Volker Krause's avatar Volker Krause
Browse files

Allow to add a calendar entry for a given reservation

This only works on Android so far, as we don't have a platform calendar
plugin for Akonadi yet.
parent c7b86a28
Pipeline #191511 passed with stage
in 5 minutes and 57 seconds
......@@ -102,6 +102,7 @@ target_include_directories(itinerary-app PRIVATE ${CMAKE_BINARY_DIR})
target_link_libraries(itinerary-app PRIVATE
itinerary
Qt::QuickControls2
KCalendarCoreExtras
)
if (ANDROID)
target_include_directories(itinerary-app PRIVATE ${Qt5Core_PRIVATE_INCLUDE_DIRS})
......
......@@ -8,6 +8,8 @@ import QtQuick 2.5
import QtQuick.Layouts 1.1
import QtQuick.Controls 2.1 as QQC2
import org.kde.kirigami 2.17 as Kirigami
import org.kde.kitemmodels 1.0
import org.kde.kcalendarcore 1.0 as KCalendarCore
import org.kde.kitinerary 1.0
import org.kde.itinerary 1.0
import "." as App
......@@ -57,6 +59,32 @@ Kirigami.ScrollablePage {
}
}
Component {
id: calendarModel
// needs to be created on demand, after we have calendar access permissions
KCalendarCore.CalendarListModel {}
}
KSortFilterProxyModel {
id: writableCalendars
filterRole: "accessMode"
filterString: KCalendarCore.KCalendarCore.ReadWrite
}
Kirigami.OverlaySheet {
id: calendarSelector
title: i18n("Select Calendar")
ListView {
model: writableCalendars
delegate: Kirigami.BasicListItem {
text: model.name
onClicked: {
controller.addToCalendar(model.calendar);
calendarSelector.close();
}
}
}
}
Component {
id: pkpassComponent
App.PkPassPage {
......@@ -137,6 +165,17 @@ Kirigami.ScrollablePage {
visible: root.editor != undefined
onTriggered: applicationWindow().pageStack.push(editor);
},
Kirigami.Action {
iconName: "view-calendar-day"
text: i18n("Add to calendar...")
onTriggered: PermissionManager.requestPermission(Permission.WriteCalendar, function() {
if (!writableCalendars.sourceModel) {
writableCalendars.sourceModel = calendarModel.createObject(root);
}
calendarSelector.open();
})
visible: KCalendarCore.CalendarPluginLoader.hasPlugin
},
Kirigami.Action {
iconName: "edit-delete"
text: i18n("Delete")
......
......@@ -47,6 +47,9 @@
#include <weatherforecastmanager.h>
#include <calendarlistmodel.h>
#include <calendarpluginloader.h>
#include <kitinerary_version.h>
#include <KItinerary/CountryDb>
#include <KItinerary/JsonLdDocument>
......@@ -102,6 +105,16 @@ void registerKContactsTypes()
qRegisterMetaType<KContacts::AddressFormatScriptPreference>();
}
void registerKCalendarCoreTypes()
{
// ### this should move into a QML plugin of KCalendarCore
qmlRegisterUncreatableMetaObject(KCalendarCore::staticMetaObject, "org.kde.kcalendarcore", 1, 0, "KCalendarCore", {});
qmlRegisterType<KCalendarCore::CalendarListModel>("org.kde.kcalendarcore", 1, 0, "CalendarListModel");
qmlRegisterSingletonType("org.kde.kcalendarcore", 1, 0, "CalendarPluginLoader", [](QQmlEngine *, QJSEngine *jsEngine) -> QJSValue {
return jsEngine->toScriptValue(KCalendarCore::CalendarPluginLoader());
});
}
void registerKPkPassTypes()
{
qmlRegisterUncreatableType<KPkPass::Barcode>("org.kde.pkpass", 1, 0, "Barcode", {});
......@@ -385,6 +398,7 @@ int main(int argc, char **argv)
#endif
registerKContactsTypes();
registerKCalendarCoreTypes();
registerKPkPassTypes();
registerKItineraryTypes();
registerApplicationTypes();
......
......@@ -16,6 +16,7 @@
#include "transfermanager.h"
#include <KItinerary/BusTrip>
#include <KItinerary/CalendarHandler>
#include <KItinerary/DocumentUtil>
#include <KItinerary/Flight>
#include <KItinerary/LocationUtil>
......@@ -747,4 +748,29 @@ int TimelineDelegateController::documentCount() const
return allDocIds.size();
}
void TimelineDelegateController::addToCalendar(KCalendarCore::Calendar *cal)
{
const auto resIds = m_resMgr->reservationsForBatch(m_batchId);
if (resIds.isEmpty() || !cal) {
return;
}
QVector<QVariant> reservations;
reservations.reserve(resIds.size());
for (const auto &resId : resIds) {
reservations.push_back(m_resMgr->reservation(resId));
}
const auto existingEvents = CalendarHandler::findEvents(cal, reservations.at(0));
if (existingEvents.size() == 1) {
auto event = existingEvents.at(0);
event->startUpdates();
CalendarHandler::fillEvent(reservations, event);
event->endUpdates();
} else {
KCalendarCore::Event::Ptr event(new KCalendarCore::Event);
CalendarHandler::fillEvent(reservations, event);
cal->addEvent(event);
}
}
#include "moc_timelinedelegatecontroller.cpp"
......@@ -11,6 +11,8 @@
#include <KPublicTransport/Journey>
#include <KPublicTransport/JourneyRequest>
#include <KCalendarCore/Calendar>
#include <QObject>
#include <QVariant>
......@@ -117,6 +119,9 @@ public:
int documentCount() const;
/** Add the current reservation to the calendar @p cal. */
Q_INVOKABLE void addToCalendar(KCalendarCore::Calendar *cal);
Q_SIGNALS:
void setupChanged();
void batchIdChanged();
......
Supports Markdown
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