Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
openSUSE:Leap:15.5:Update
libkgapi.18301
0002-Calendar-API-implement-support-for-Event.e...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 0002-Calendar-API-implement-support-for-Event.eventType.patch of Package libkgapi.18301
From 9226cd800dcac445f3c063397bfbef9b8e940ee2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Vr=C3=A1til?= <dvratil@kde.org> Date: Mon, 12 Feb 2024 23:52:25 +0100 Subject: [PATCH 2/2] Calendar API: implement support for Event.eventType According to Google, they will start sending the 'workingLocation' events by default soon, unless we explicitly specify the types of events that we are interested in (and 'workingLocation' events we are not interested in at this point, since we cannot support them properly in KOrganizer (yet)). (cherry picked from commit 2d6ed1fec269b253335b6f57b8392e5731c48cf6) --- autotests/calendar/data/event1.json | 3 +- .../calendar/data/event1_create_request.txt | 3 +- .../calendar/data/event1_create_response.txt | 53 ++++++++++--------- .../calendar/data/event1_fetch_response.txt | 3 +- autotests/calendar/data/event2.json | 3 +- .../calendar/data/event2_create_request.txt | 3 +- .../calendar/data/event2_create_response.txt | 3 +- .../data/events_fetch_page1_request.txt | 2 +- .../data/events_fetch_page1_response.txt | 3 +- .../data/events_fetch_page2_request.txt | 2 +- .../data/events_fetch_page2_response.txt | 3 +- src/calendar/calendarservice.cpp | 51 +++++++++++++++++- src/calendar/calendarservice.h | 13 ++++- src/calendar/event.cpp | 13 ++++- src/calendar/event.h | 18 +++++++ src/calendar/eventfetchjob.cpp | 6 +++ src/calendar/eventfetchjob.h | 13 +++++ 17 files changed, 156 insertions(+), 39 deletions(-) diff --git a/autotests/calendar/data/event1.json b/autotests/calendar/data/event1.json index c0f77f0..9d6071d 100644 --- a/autotests/calendar/data/event1.json +++ b/autotests/calendar/data/event1.json @@ -42,5 +42,6 @@ "displayName": "John Doe", "email": "johnnyboy@example.test" }, - "id": "3if6lf59tove1e037baa75l54t" + "id": "3if6lf59tove1e037baa75l54t", + "eventType": "default" } diff --git a/autotests/calendar/data/event1_create_request.txt b/autotests/calendar/data/event1_create_request.txt index f395eb6..ef2c863 100644 --- a/autotests/calendar/data/event1_create_request.txt +++ b/autotests/calendar/data/event1_create_request.txt @@ -40,5 +40,6 @@ Content-Type: application/json }, "status": "confirmed", "summary": "Cool Meeting about stuff", - "transparency": "opaque" + "transparency": "opaque", + "eventType": "default" } diff --git a/autotests/calendar/data/event1_create_response.txt b/autotests/calendar/data/event1_create_response.txt index c3fdf19..03d9c77 100644 --- a/autotests/calendar/data/event1_create_response.txt +++ b/autotests/calendar/data/event1_create_response.txt @@ -4,49 +4,50 @@ Content-type: application/json; charset=UTF-8 { "attendees": [ { - "displayName": "", - "email": "attendee1@kde.test", + "displayName": "", + "email": "attendee1@kde.test", "id": "1234567890", "responseStatus": "needsAction" }, { - "displayName": "", - "email": "attendee2@kde.test", + "displayName": "", + "email": "attendee2@kde.test", "id": "0987654321", "responseStatus": "needsAction" } - ], - "created": "2018-03-30T22:28:48.000Z", + ], + "created": "2018-03-30T22:28:48.000Z", "creator": { - "self": true, - "displayName": "Dan Vr\u00e1til", + "self": true, + "displayName": "Dan Vr\u00e1til", "email": "dan.vratil@gmail.com" - }, - "description": "We shall meet and we shall discuss.", + }, + "description": "We shall meet and we shall discuss.", "end": { - "timeZone": "Europe/Prague", + "timeZone": "Europe/Prague", "dateTime": "2018-04-01T11:30:00+02:00" - }, - "etag": "\"3044897856406000\"", - "htmlLink": "https://www.google.com/calendar/event?eid=dW00anI0YmZqc2kwNm5ycGg0cDlyYjY1bXMgZGFuLnZyYXRpbEBt", - "iCalUID": "3if6lf59tove1e037baa75l54t@google.com", + }, + "etag": "\"3044897856406000\"", + "eventType": "default", + "htmlLink": "https://www.google.com/calendar/event?eid=dW00anI0YmZqc2kwNm5ycGg0cDlyYjY1bXMgZGFuLnZyYXRpbEBt", + "iCalUID": "3if6lf59tove1e037baa75l54t@google.com", "id": "3if6lf59tove1e037baa75l54t", - "kind": "calendar#event", - "location": "Meeting Room", + "kind": "calendar#event", + "location": "Meeting Room", "organizer": { - "self": true, - "displayName": "Konqui", + "self": true, + "displayName": "Konqui", "email": "konqui@kde.test" - }, + }, "reminders": { "useDefault": false - }, - "sequence": 0, + }, + "sequence": 0, "start": { - "timeZone": "Europe/Prague", + "timeZone": "Europe/Prague", "dateTime": "2018-04-01T10:30:00+02:00" - }, - "status": "confirmed", - "summary": "Cool Meeting about stuff", + }, + "status": "confirmed", + "summary": "Cool Meeting about stuff", "updated": "2018-03-30T22:28:48.203Z" } diff --git a/autotests/calendar/data/event1_fetch_response.txt b/autotests/calendar/data/event1_fetch_response.txt index 906c5f2..5b4fa70 100644 --- a/autotests/calendar/data/event1_fetch_response.txt +++ b/autotests/calendar/data/event1_fetch_response.txt @@ -45,5 +45,6 @@ Content-type: application/json; charset=UTF-8 "displayName": "John Doe", "email": "johnnyboy@example.test" }, - "id": "3if6lf59tove1e037baa75l54t" + "id": "3if6lf59tove1e037baa75l54t", + "eventType": "default" } diff --git a/autotests/calendar/data/event2.json b/autotests/calendar/data/event2.json index 9e45a68..a59364d 100644 --- a/autotests/calendar/data/event2.json +++ b/autotests/calendar/data/event2.json @@ -52,5 +52,6 @@ "displayName": "KDE Hacker 2", "email": "hacker2@kde.test" }, - "id": "_60o3iopicdhjib9g6ss32b9k70p68b9ocdhm8b9ocphjioj6clh36c9j70" + "id": "_60o3iopicdhjib9g6ss32b9k70p68b9ocdhm8b9ocphjioj6clh36c9j70", + "eventType": "default" } diff --git a/autotests/calendar/data/event2_create_request.txt b/autotests/calendar/data/event2_create_request.txt index 2962f69..f7b02af 100644 --- a/autotests/calendar/data/event2_create_request.txt +++ b/autotests/calendar/data/event2_create_request.txt @@ -42,5 +42,6 @@ Content-Type: application/json }, "status": "confirmed", "summary": "KDE PIM Sprint", - "transparency": "opaque" + "transparency": "opaque", + "eventType": "default" } diff --git a/autotests/calendar/data/event2_create_response.txt b/autotests/calendar/data/event2_create_response.txt index d15b841..43060c8 100644 --- a/autotests/calendar/data/event2_create_response.txt +++ b/autotests/calendar/data/event2_create_response.txt @@ -55,5 +55,6 @@ Content-type: application/json; charset=UTF-8 "displayName": "KDE Hacker 2", "email": "hacker2@kde.test" }, - "id": "_60o3iopicdhjib9g6ss32b9k70p68b9ocdhm8b9ocphjioj6clh36c9j70" + "id": "_60o3iopicdhjib9g6ss32b9k70p68b9ocdhm8b9ocphjioj6clh36c9j70", + "eventType": "default" } diff --git a/autotests/calendar/data/events_fetch_page1_request.txt b/autotests/calendar/data/events_fetch_page1_request.txt index 1605aa2..7f12dfe 100644 --- a/autotests/calendar/data/events_fetch_page1_request.txt +++ b/autotests/calendar/data/events_fetch_page1_request.txt @@ -1 +1 @@ -GET https://www.googleapis.com/calendar/v3/calendars/MockAccount/events?showDeleted=true&prettyPrint=false +GET https://www.googleapis.com/calendar/v3/calendars/MockAccount/events?showDeleted=true&eventTypes=default&eventTypes=focusTime&eventTypes=outOfOffice&prettyPrint=false diff --git a/autotests/calendar/data/events_fetch_page1_response.txt b/autotests/calendar/data/events_fetch_page1_response.txt index 1fec497..9dc424c 100644 --- a/autotests/calendar/data/events_fetch_page1_response.txt +++ b/autotests/calendar/data/events_fetch_page1_response.txt @@ -59,7 +59,8 @@ Content-type: application/json; charset=UTF-8 "displayName": "John Doe", "email": "johnnyboy@example.test" }, - "id": "3if6lf59tove1e037baa75l54t" + "id": "3if6lf59tove1e037baa75l54t", + "eventType": "default" } ], "updated": "2018-04-02T13:31:50.251Z", diff --git a/autotests/calendar/data/events_fetch_page2_request.txt b/autotests/calendar/data/events_fetch_page2_request.txt index f59748e..a434fc4 100644 --- a/autotests/calendar/data/events_fetch_page2_request.txt +++ b/autotests/calendar/data/events_fetch_page2_request.txt @@ -1 +1 @@ -GET https://www.googleapis.com/calendar/v3/calendars/MockAccount/events?showDeleted=true&prettyPrint=false&pageToken=ClEKQ182a3MzaWRoazZvcWpnYzlsNnNyM2NjcGc2OHBqMmUyMGRsbm00cWJjY2xwbmlyajM1cGptdXJyN2RoaWlzb3JmZGsYASCAgIDqg5PLwhIaDQgAEgAY-KP05dmb2gI%3D +GET https://www.googleapis.com/calendar/v3/calendars/MockAccount/events?showDeleted=true&eventTypes=default&eventTypes=focusTime&eventTypes=outOfOffice&prettyPrint=false&pageToken=ClEKQ182a3MzaWRoazZvcWpnYzlsNnNyM2NjcGc2OHBqMmUyMGRsbm00cWJjY2xwbmlyajM1cGptdXJyN2RoaWlzb3JmZGsYASCAgIDqg5PLwhIaDQgAEgAY-KP05dmb2gI%3D diff --git a/autotests/calendar/data/events_fetch_page2_response.txt b/autotests/calendar/data/events_fetch_page2_response.txt index 638938f..a0e89df 100644 --- a/autotests/calendar/data/events_fetch_page2_response.txt +++ b/autotests/calendar/data/events_fetch_page2_response.txt @@ -68,7 +68,8 @@ Content-type: application/json; charset=UTF-8 "displayName": "KDE Hacker 2", "email": "hacker2@kde.test" }, - "id": "_60o3iopicdhjib9g6ss32b9k70p68b9ocdhm8b9ocphjioj6clh36c9j70" + "id": "_60o3iopicdhjib9g6ss32b9k70p68b9ocdhm8b9ocphjioj6clh36c9j70", + "eventType": "default" } ], "updated": "2018-04-02T13:31:50.251Z", diff --git a/src/calendar/calendarservice.cpp b/src/calendar/calendarservice.cpp index 93a362e..025ae00 100644 --- a/src/calendar/calendarservice.cpp +++ b/src/calendar/calendarservice.cpp @@ -279,6 +279,8 @@ static const auto categoriesProperty = QLatin1String("categories"); static const auto hangoutLinkParam = QStringLiteral("hangoutLink"); +static const auto eventTypeParam = QStringLiteral("eventType"); + } QString APIVersion() @@ -595,6 +597,12 @@ ObjectPtr Private::JSONToEvent(const QVariantMap &data, const QString &timezone) setEventCategories(event, extendedProperties.value(propertyPrivateParam).toMap()); setEventCategories(event, extendedProperties.value(propertySharedParam).toMap()); + if (const auto eventType = data.value(eventTypeParam).toString(); !eventType.isEmpty()) { + event->setEventType(eventTypeFromString(eventType)); + } else { + event->setEventType(Event::EventType::Default); + } + return event.dynamicCast<Object>(); } @@ -769,8 +777,13 @@ QByteArray eventToJSON(const EventPtr &event, EventSerializeFlags flags) data.insert(eventExtendedPropertiesParam, QVariantMap{{propertySharedParam, QVariantMap{{categoriesProperty, event->categoriesStr()}}}}); } + // eventType not allowed in update, only in create + if (!data.contains(idParam)) { + data.insert(eventTypeParam, eventTypeToString(event->eventType())); + } + /* TODO: Implement support for additional features: - * https://developers.google.com/gdata/docs/2.0/elements?csw=1 + * https://developers.google.com/calendar/api/v3/reference/events/insert */ const auto document = QJsonDocument::fromVariant(data); @@ -815,6 +828,42 @@ ObjectsList parseEventJSONFeed(const QByteArray &jsonFeed, FeedData &feedData) return list; } +QString eventTypeToString(Event::EventType eventType) +{ + switch (eventType) { + case Event::EventType::Default: + return QStringLiteral("default"); + case Event::EventType::FocusTime: + return QStringLiteral("focusTime"); + case Event::EventType::OutOfOffice: + return QStringLiteral("outOfOffice"); + case Event::EventType::WorkingLocation: + return QStringLiteral("workingLocation"); + } + + Q_UNREACHABLE(); + return {}; +} + +Event::EventType eventTypeFromString(const QString &eventType) +{ + const auto eventTypeLc = eventType.toLower(); + if (eventTypeLc == u"default") { + return Event::EventType::Default; + } + if (eventTypeLc == u"outofoffice") { + return Event::EventType::OutOfOffice; + } + if (eventTypeLc == u"focustime") { + return Event::EventType::FocusTime; + } + if (eventTypeLc == u"workinglocation") { + return Event::EventType::WorkingLocation; + } + + return Event::EventType::Default; +} + /******************************** PRIVATE ***************************************/ KCalendarCore::DateList Private::parseRDate(const QString &rule) diff --git a/src/calendar/calendarservice.h b/src/calendar/calendarservice.h index a7be473..ac1206f 100644 --- a/src/calendar/calendarservice.h +++ b/src/calendar/calendarservice.h @@ -10,6 +10,7 @@ #include "types.h" #include "enums.h" +#include "event.h" #include "kgapicalendar_export.h" #include <QFlags> @@ -85,6 +86,16 @@ namespace CalendarService */ KGAPICALENDAR_EXPORT ObjectsList parseEventJSONFeed(const QByteArray& jsonFeed, FeedData& feedData); + /** + * @brief Converts event type enum value to string + */ + KGAPICALENDAR_EXPORT QString eventTypeToString(Event::EventType eventType); + + /** + * @brief Converts event type string to enum value + */ + KGAPICALENDAR_EXPORT Event::EventType eventTypeFromString(const QString &eventType); + /** * @brief Supported API version */ @@ -153,7 +164,7 @@ namespace CalendarService * @param updatesPolicy Whether to send notification to participants */ KGAPICALENDAR_EXPORT QUrl createEventUrl(const QString &calendarID, SendUpdatesPolicy updatesPolicy); - + /** * @brief Returns URL importing private copies of existing events. * diff --git a/src/calendar/event.cpp b/src/calendar/event.cpp index 8e10520..73ef9ed 100644 --- a/src/calendar/event.cpp +++ b/src/calendar/event.cpp @@ -7,6 +7,7 @@ */ #include "event.h" +#include "calendarservice.h" #include "debug.h" using namespace KGAPI2; @@ -15,12 +16,12 @@ namespace { static constexpr const char *EventIdProperty = "EventId"; static constexpr const char *EventHangoutLinkProperty = "EventHangoutLink"; +static constexpr const char *EventTypeProperty = "EventType"; } class Q_DECL_HIDDEN Event::Private { public: - QString id; bool deleted = false; bool useDefaultReminders = false; }; @@ -112,4 +113,14 @@ QString Event::hangoutLink() const void Event::setHangoutLink(const QString &hangoutLink) { setCustomProperty("LIBKGAPI", EventHangoutLinkProperty, hangoutLink); +} + +Event::EventType Event::eventType() const +{ + return CalendarService::eventTypeFromString(customProperty("LIBKGAPI", EventTypeProperty)); +} + +void Event::setEventType(EventType type) +{ + setCustomProperty("LIBKGAPI", EventTypeProperty, CalendarService::eventTypeToString(type)); } \ No newline at end of file diff --git a/src/calendar/event.h b/src/calendar/event.h index 1b8089e..b06f8fc 100644 --- a/src/calendar/event.h +++ b/src/calendar/event.h @@ -28,6 +28,14 @@ namespace KGAPI2 class KGAPICALENDAR_EXPORT Event : public KGAPI2::Object, public KCalendarCore::Event { public: + enum class EventType { + Default, //< Regular event + FocusTime, //< Focus time event + OutOfOffice, //< Out of office event + WorkingLocation //< Working location event + }; + Q_ENUM(EventType); + /** * @brief Constructor */ @@ -96,6 +104,16 @@ public: */ void setHangoutLink(const QString &id); + /** + * @brief Returns the type of the event + */ + EventType eventType() const; + + /** + * @brief Sets the type of the event. + */ + void setEventType(EventType eventType); + private: class Private; QScopedPointer<Private> const d; diff --git a/src/calendar/eventfetchjob.cpp b/src/calendar/eventfetchjob.cpp index c2fc252..d20de87 100644 --- a/src/calendar/eventfetchjob.cpp +++ b/src/calendar/eventfetchjob.cpp @@ -11,6 +11,8 @@ #include "calendarservice.h" #include "debug.h" #include "event.h" +#include "fetchjob.h" +#include "types.h" #include "utils.h" #include <QNetworkReply> @@ -26,6 +28,7 @@ public: QString eventId; QString filter; QString syncToken; + QList<Event::EventType> eventTypes = { Event::EventType::Default, Event::EventType::FocusTime, Event::EventType::OutOfOffice }; bool fetchDeleted = true; quint64 updatedTimestamp = 0; quint64 timeMin = 0; @@ -157,6 +160,9 @@ void EventFetchJob::start() } else { query.addQueryItem(QStringLiteral("syncToken"), d->syncToken); } + for (auto eventType : d->eventTypes) { + query.addQueryItem(QStringLiteral("eventTypes"), CalendarService::eventTypeToString(eventType)); + } url.setQuery(query); } else { url = CalendarService::fetchEventUrl(d->calendarId, d->eventId); diff --git a/src/calendar/eventfetchjob.h b/src/calendar/eventfetchjob.h index 2fe73ff..9233012 100644 --- a/src/calendar/eventfetchjob.h +++ b/src/calendar/eventfetchjob.h @@ -9,6 +9,7 @@ #pragma once #include "fetchjob.h" +#include "event.h" #include "kgapicalendar_export.h" #include <QScopedPointer> @@ -143,6 +144,18 @@ public: */ ~EventFetchJob() override; + /** + * @brief Sets the types of events to retrieve. + * + * Default set is EventType::Default, EventType::FocusTime and EventType::OutOfOffice. + */ + void setEventTypes(const QList<Event::EventType> eventTypes); + + /** + * @brief Returns the types of events to retrieve. + */ + QList<Event::EventType> eventTypes() const; + /** * @brief Sets fulltext filter. * -- 2.43.0
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor