From 9ef4d77592277c11ccab1adf7fda9b5116a38fec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Karas?= Date: Tue, 20 Feb 2024 01:43:52 +0100 Subject: [PATCH 1/3] fetch read-only google calendars --- .../googlecalendarsyncadaptor.cpp | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/google/google-calendars/googlecalendarsyncadaptor.cpp b/src/google/google-calendars/googlecalendarsyncadaptor.cpp index 686d0a8..573b965 100644 --- a/src/google/google-calendars/googlecalendarsyncadaptor.cpp +++ b/src/google/google-calendars/googlecalendarsyncadaptor.cpp @@ -1229,19 +1229,25 @@ void GoogleCalendarSyncAdaptor::calendarsFinishedHandler() for (int i = 0; i < items.count(); ++i) { QJsonObject currCalendar = items.at(i).toObject(); if (!currCalendar.isEmpty() && currCalendar.find(QStringLiteral("id")) != currCalendar.end()) { - // we only sync calendars which the user owns (ie, not autogenerated calendars) QString accessRole = currCalendar.value(QStringLiteral("accessRole")).toString(); - if (accessRole == QStringLiteral("owner") || accessRole == QStringLiteral("writer")) { + AccessRole access = NoAccess; + if (accessRole == QStringLiteral("owner")) { + access = Owner; + } else if (accessRole == QStringLiteral("writer")) { + access = Writer; + } else if (accessRole == QStringLiteral("reader")) { + access = Reader; + } else if (accessRole == QStringLiteral("freeBusyReader")) { + access = FreeBusyReader; + } + + if (access != NoAccess) { GoogleCalendarSyncAdaptor::CalendarInfo currCalendarInfo; currCalendarInfo.color = currCalendar.value(QStringLiteral("backgroundColor")).toString(); currCalendarInfo.summary = currCalendar.value(QStringLiteral("summary")).toString(); currCalendarInfo.description = currCalendar.value(QStringLiteral("description")).toString(); currCalendarInfo.change = NoChange; // we detect the appropriate change type (if required) later. - if (accessRole == QStringLiteral("owner")) { - currCalendarInfo.access = Owner; - } else { - currCalendarInfo.access = Writer; - } + currCalendarInfo.access = access; QString currCalendarId = currCalendar.value(QStringLiteral("id")).toString(); m_serverCalendarIdToCalendarInfo.insert(currCalendarId, currCalendarInfo); } From 0d369168530105177ea54dfa52b280d4e763d932 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Karas?= Date: Sat, 16 Mar 2024 23:14:03 +0100 Subject: [PATCH 2/3] setup read-only flag of mKCal::Notebook when needed --- src/google/google-calendars/googlecalendarsyncadaptor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/google/google-calendars/googlecalendarsyncadaptor.cpp b/src/google/google-calendars/googlecalendarsyncadaptor.cpp index 573b965..d81ed8b 100644 --- a/src/google/google-calendars/googlecalendarsyncadaptor.cpp +++ b/src/google/google-calendars/googlecalendarsyncadaptor.cpp @@ -2448,7 +2448,7 @@ void GoogleCalendarSyncAdaptor::setCalendarProperties( const QString &syncProfile, const QString &ownerEmail) { - notebook->setIsReadOnly(false); + notebook->setIsReadOnly(calendarInfo.access == GoogleCalendarSyncAdaptor::Reader || calendarInfo.access == GoogleCalendarSyncAdaptor::FreeBusyReader); notebook->setName(calendarInfo.summary); notebook->setDescription(calendarInfo.description); notebook->setPluginName(QStringLiteral("google")); From 13a6b1b5c06a201fa2517c2ce8be680f409a9c24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Karas?= Date: Sat, 16 Mar 2024 23:50:12 +0100 Subject: [PATCH 3/3] percent encode calendarId used in url Google calendar id may contain some characters that has special meaning in Url, like '#'. For example: "cs.czech#holiday@group.v.calendar.google.com". So, it is necessary to percent encode it, before usage un url. --- .../google-calendars/googlecalendarsyncadaptor.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/google/google-calendars/googlecalendarsyncadaptor.cpp b/src/google/google-calendars/googlecalendarsyncadaptor.cpp index d81ed8b..e02d6a0 100644 --- a/src/google/google-calendars/googlecalendarsyncadaptor.cpp +++ b/src/google/google-calendars/googlecalendarsyncadaptor.cpp @@ -879,6 +879,10 @@ QString toBase32hex(QByteArray bytes) return result; } +QString percentEnc(const QString &str) { + return QString::fromUtf8(QUrl::toPercentEncoding(str)); +} + QString generate_uuid() { // UUID documentation here: @@ -1416,7 +1420,7 @@ void GoogleCalendarSyncAdaptor::requestEvents(const QString &accessToken, const queryItems.append(QPair(QString::fromLatin1("pageToken"), pageToken)); } - QUrl url(QString::fromLatin1("https://www.googleapis.com/calendar/v3/calendars/%1/events").arg(calendarId)); + QUrl url(QString::fromLatin1("https://www.googleapis.com/calendar/v3/calendars/%1/events").arg(percentEnc(calendarId))); QUrlQuery query(url); query.setQueryItems(queryItems); url.setQuery(query); @@ -2149,8 +2153,8 @@ void GoogleCalendarSyncAdaptor::upsyncChanges(const UpsyncChange &changeToUpsync const QByteArray &eventData = changeToUpsync.eventData; QUrl requestUrl = upsyncType == GoogleCalendarSyncAdaptor::Insert - ? QUrl(QString::fromLatin1("https://www.googleapis.com/calendar/v3/calendars/%1/events").arg(calendarId)) - : QUrl(QString::fromLatin1("https://www.googleapis.com/calendar/v3/calendars/%1/events/%2").arg(calendarId).arg(eventId)); + ? QUrl(QString::fromLatin1("https://www.googleapis.com/calendar/v3/calendars/%1/events").arg(percentEnc(calendarId))) + : QUrl(QString::fromLatin1("https://www.googleapis.com/calendar/v3/calendars/%1/events/%2").arg(percentEnc(calendarId)).arg(eventId)); QNetworkRequest request(requestUrl); request.setRawHeader("GData-Version", "3.0");