diff --git a/src/google/google-calendars/googlecalendarsyncadaptor.cpp b/src/google/google-calendars/googlecalendarsyncadaptor.cpp index 686d0a8..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: @@ -1229,19 +1233,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); } @@ -1410,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); @@ -2143,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"); @@ -2442,7 +2452,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"));