Navigation Menu

Skip to content

Commit

Permalink
[buteo-sync-plugins-social] Set summary+description info into Google …
Browse files Browse the repository at this point in the history
…Calendars. Contributes to MER#884

Previously, we hardcoded calendar summary information for calendars
synced from Google.  Instead, we should use the summary and description
provided by the server.

Contributes to MER#884
  • Loading branch information
Chris Adams committed Apr 13, 2015
1 parent f9102d6 commit 7d744e2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 18 deletions.
39 changes: 22 additions & 17 deletions src/google/google-calendars/googlecalendarsyncadaptor.cpp
Expand Up @@ -641,7 +641,7 @@ void GoogleCalendarSyncAdaptor::beginSync(int accountId, const QString &accessTo
purgeDataForOldAccount(accountId, SocialNetworkSyncAdaptor::CleanUpPurge);
m_storage->open(); // we close it in finalCleanup()
}
m_serverCalendarIdToSummaryAndColor[accountId].clear();
m_serverCalendarIdToCalendarInfo[accountId].clear();
m_calendarIdToEventObjects[accountId].clear();
m_syncSucceeded[accountId] = true; // set to false on error
requestCalendars(accountId, accessToken, needCleanSync);
Expand Down Expand Up @@ -723,11 +723,12 @@ void GoogleCalendarSyncAdaptor::calendarsFinishedHandler()
// we only sync calendars which the user owns (ie, not autogenerated calendars)
QString accessRole = currCalendar.value(QStringLiteral("accessRole")).toString();
if (accessRole == QStringLiteral("owner")) {
GoogleCalendarSyncAdaptor::CalendarInfo currCalendarInfo;
currCalendarInfo.color = currCalendar.value(QStringLiteral("backgroundColor")).toString();
currCalendarInfo.summary = currCalendar.value(QStringLiteral("summary")).toString();
currCalendarInfo.description = currCalendar.value(QStringLiteral("description")).toString();
QString currCalendarId = currCalendar.value(QStringLiteral("id")).toString();
QString currCalendarSummary = currCalendar.value(QStringLiteral("summary")).toString();
QString currCalendarBgColor = currCalendar.value(QStringLiteral("backgroundColor")).toString();
QPair<QString, QString> summaryAndColor(currCalendarSummary, currCalendarBgColor);
m_serverCalendarIdToSummaryAndColor[accountId].insert(currCalendarId, summaryAndColor);
m_serverCalendarIdToCalendarInfo[accountId].insert(currCalendarId, currCalendarInfo);
}
}
}
Expand Down Expand Up @@ -760,24 +761,26 @@ void GoogleCalendarSyncAdaptor::updateLocalCalendarNotebooks(int accountId, cons
if (notebook->pluginName().startsWith(QStringLiteral("google-"))
&& notebook->account() == QString::number(accountId)) {
QString currDeviceCalendarId = notebook->pluginName().mid(7);
if (m_serverCalendarIdToSummaryAndColor[accountId].contains(currDeviceCalendarId)) {
if (m_serverCalendarIdToCalendarInfo[accountId].contains(currDeviceCalendarId)) {
// the server-side calendar exists on the device.
// we don't need to purge it, but we may need to update its summary/color details.
deviceCalendarIds.append(currDeviceCalendarId);
if (notebook->name() != m_serverCalendarIdToSummaryAndColor[accountId].value(currDeviceCalendarId).first
|| notebook->color() != m_serverCalendarIdToSummaryAndColor[accountId].value(currDeviceCalendarId).second
if (notebook->name() != m_serverCalendarIdToCalendarInfo[accountId].value(currDeviceCalendarId).summary
|| notebook->color() != m_serverCalendarIdToCalendarInfo[accountId].value(currDeviceCalendarId).color
|| notebook->description() != m_serverCalendarIdToCalendarInfo[accountId].value(currDeviceCalendarId).description
|| notebook->isReadOnly()) {
// summary or color changed server-side.
// calendar information changed server-side.
notebook->setIsReadOnly(false);
notebook->setName(m_serverCalendarIdToSummaryAndColor[accountId].value(currDeviceCalendarId).first);
notebook->setColor(m_serverCalendarIdToSummaryAndColor[accountId].value(currDeviceCalendarId).second);
notebook->setName(m_serverCalendarIdToCalendarInfo[accountId].value(currDeviceCalendarId).summary);
notebook->setColor(m_serverCalendarIdToCalendarInfo[accountId].value(currDeviceCalendarId).color);
notebook->setDescription(m_serverCalendarIdToCalendarInfo[accountId].value(currDeviceCalendarId).description);
m_storage->updateNotebook(notebook);
m_storageNeedsSave = true;
}
} else {
// the calendar has been removed from the server.
// we need to purge it from the device.
SOCIALD_LOG_DEBUG("removing calendar" << notebook->name() << "for Google account:" << accountId);
SOCIALD_LOG_DEBUG("removing calendar" << notebook->name() << currDeviceCalendarId << "for Google account:" << accountId);
m_storage->loadNotebookIncidences(notebook->uid());
KCalCore::Incidence::List incidenceList;
m_storage->allIncidences(&incidenceList, notebook->uid());
Expand All @@ -791,14 +794,16 @@ void GoogleCalendarSyncAdaptor::updateLocalCalendarNotebooks(int accountId, cons
}

// any calendarIds which exist on the server but not the device need to be created.
foreach (const QString &serverCalendarId, m_serverCalendarIdToSummaryAndColor[accountId].keys()) {
foreach (const QString &serverCalendarId, m_serverCalendarIdToCalendarInfo[accountId].keys()) {
if (!deviceCalendarIds.contains(serverCalendarId)) {
SOCIALD_LOG_DEBUG("adding new calendar" << m_serverCalendarIdToSummaryAndColor[accountId].value(serverCalendarId).first <<
SOCIALD_LOG_DEBUG("adding new calendar" << serverCalendarId <<
m_serverCalendarIdToCalendarInfo[accountId].value(serverCalendarId).summary <<
"for Google account:" << accountId);
mKCal::Notebook::Ptr notebook = mKCal::Notebook::Ptr(new mKCal::Notebook);
notebook->setIsReadOnly(false);
notebook->setName(m_serverCalendarIdToSummaryAndColor[accountId].value(serverCalendarId).first);
notebook->setColor(m_serverCalendarIdToSummaryAndColor[accountId].value(serverCalendarId).second);
notebook->setName(m_serverCalendarIdToCalendarInfo[accountId].value(serverCalendarId).summary);
notebook->setColor(m_serverCalendarIdToCalendarInfo[accountId].value(serverCalendarId).color);
notebook->setDescription(m_serverCalendarIdToCalendarInfo[accountId].value(serverCalendarId).description);
notebook->setPluginName(QStringLiteral("google-") + serverCalendarId);
notebook->setAccount(QString::number(accountId));
m_storage->addNotebook(notebook);
Expand All @@ -808,7 +813,7 @@ void GoogleCalendarSyncAdaptor::updateLocalCalendarNotebooks(int accountId, cons

SOCIALD_LOG_DEBUG("Syncing calendar events for Google account: " << accountId << " CleanSync: " << needCleanSync);

foreach (const QString &calendarId, m_serverCalendarIdToSummaryAndColor[accountId].keys()) {
foreach (const QString &calendarId, m_serverCalendarIdToCalendarInfo[accountId].keys()) {
requestEvents(accountId, accessToken, calendarId, needCleanSync);
}
}
Expand Down
7 changes: 6 additions & 1 deletion src/google/google-calendars/googlecalendarsyncadaptor.h
Expand Up @@ -77,7 +77,12 @@ private Q_SLOTS:
void upsyncFinishedHandler();

private:
QMap<int, QMap<QString, QPair<QString, QString> > > m_serverCalendarIdToSummaryAndColor;
struct CalendarInfo {
QString summary;
QString description;
QString color;
};
QMap<int, QMap<QString, CalendarInfo> > m_serverCalendarIdToCalendarInfo;
QMap<int, QMultiMap<QString, QJsonObject> > m_calendarIdToEventObjects;
QMap<int, QMap<QString, QString> > m_recurringEventIdToKCalUid;
QMap<int, bool> m_syncSucceeded;
Expand Down

0 comments on commit 7d744e2

Please sign in to comment.