Commit b438da9a authored by blam's avatar blam

Merge branch 'kf5' into 'master'

[buteo-sync-plugins-social] Port to KF5CalendarCore. JB#47814

See merge request !80
parents 88e70f24 3706db11
......@@ -41,7 +41,7 @@ A Buteo plugin which provides data synchronization with various social services.
%package facebook-calendars
Summary: Provides calendar synchronisation with Facebook
BuildRequires: pkgconfig(libmkcal-qt5)
BuildRequires: pkgconfig(libkcalcoren-qt5)
BuildRequires: pkgconfig(KF5CalendarCore)
Requires: %{name} = %{version}-%{release}
%description facebook-calendars
......@@ -126,7 +126,7 @@ systemctl-user try-restart msyncd.service || :
%package google-calendars
Summary: Provides calendar synchronisation with Google
BuildRequires: pkgconfig(libmkcal-qt5) >= 0.5.9
BuildRequires: pkgconfig(libkcalcoren-qt5)
BuildRequires: pkgconfig(KF5CalendarCore)
Requires: %{name} = %{version}-%{release}
%description google-calendars
......@@ -498,7 +498,7 @@ systemctl-user restart msyncd.service || :
%package vk-calendars
Summary: Provides calendar synchronisation with VK
BuildRequires: pkgconfig(libmkcal-qt5)
BuildRequires: pkgconfig(libkcalcoren-qt5)
BuildRequires: pkgconfig(KF5CalendarCore)
Requires: %{name} = %{version}-%{release}
%description vk-calendars
......
CONFIG += link_pkgconfig
PKGCONFIG += libmkcal-qt5 libkcalcoren-qt5
PKGCONFIG += libmkcal-qt5 KF5CalendarCore
SOURCES += $$PWD/facebookcalendarsyncadaptor.cpp
HEADERS += $$PWD/facebookcalendarsyncadaptor.h
INCLUDEPATH += $$PWD
......
......@@ -81,7 +81,7 @@ namespace {
FacebookCalendarSyncAdaptor::FacebookCalendarSyncAdaptor(QObject *parent)
: FacebookDataTypeSyncAdaptor(SocialNetworkSyncAdaptor::Calendars, parent)
, m_calendar(mKCal::ExtendedCalendar::Ptr(new mKCal::ExtendedCalendar(QLatin1String("UTC"))))
, m_calendar(mKCal::ExtendedCalendar::Ptr(new mKCal::ExtendedCalendar(QTimeZone::utc())))
, m_storage(mKCal::ExtendedCalendar::defaultStorage(m_calendar))
, m_storageNeedsSave(false)
{
......@@ -140,17 +140,17 @@ void FacebookCalendarSyncAdaptor::finalCleanup()
// given incidence belongs to, so we have to instead load
// everything and then find the ones which are ophaned.
m_storage->load();
KCalCore::Incidence::List allIncidences = m_calendar->incidences();
KCalendarCore::Incidence::List allIncidences = m_calendar->incidences();
mKCal::Notebook::List allNotebooks = m_storage->notebooks();
QSet<QString> notebookIncidenceUids;
foreach (mKCal::Notebook::Ptr notebook, allNotebooks) {
KCalCore::Incidence::List currNbIncidences;
KCalendarCore::Incidence::List currNbIncidences;
m_storage->allIncidences(&currNbIncidences, notebook->uid());
foreach (KCalCore::Incidence::Ptr incidence, currNbIncidences) {
foreach (KCalendarCore::Incidence::Ptr incidence, currNbIncidences) {
notebookIncidenceUids.insert(incidence->uid());
}
}
foreach (const KCalCore::Incidence::Ptr incidence, allIncidences) {
foreach (const KCalendarCore::Incidence::Ptr incidence, allIncidences) {
if (!notebookIncidenceUids.contains(incidence->uid())) {
// orphan/ghost incidence. must be deleted.
SOCIALD_LOG_DEBUG("deleting orphan event with uid:" << incidence->uid());
......@@ -355,23 +355,11 @@ void FacebookCalendarSyncAdaptor::finishedHandler()
endTimeString = startTimeString;
}
KDateTime parsedStartTime = KDateTime::fromString(startTimeString);
KDateTime parsedEndTime = KDateTime::fromString(endTimeString);
QDateTime parsedStartTime = QDateTime::fromString(startTimeString, Qt::ISODate);
QDateTime parsedEndTime = QDateTime::fromString(endTimeString, Qt::ISODate);
// Sometimes KDateTime cannot parse the timezone
// even if it should support it
// We are then doing it manually
if (parsedStartTime.isNull()) {
parsedStartTime = KDateTime::fromString(startTimeString,
QLatin1String("%Y-%m-%dT%H:%M:%S%z"));
}
if (parsedEndTime.isNull()) {
parsedEndTime = KDateTime::fromString(endTimeString,
QLatin1String("%Y-%m-%dT%H:%M:%S%z"));
}
parsedEvent.m_startTime = parsedStartTime.toLocalZone();
parsedEvent.m_endTime = parsedEndTime.toLocalZone();
parsedEvent.m_startTime = parsedStartTime.toTimeZone(QTimeZone::systemTimeZone());
parsedEvent.m_endTime = parsedEndTime.toTimeZone(QTimeZone::systemTimeZone());
parsedEvent.m_summary = dataMap.value(QLatin1String("name")).toString();
parsedEvent.m_description = dataMap.value(QLatin1String("description")).toString();
parsedEvent.m_location = dataMap.value(QLatin1String("place")).toObject().toVariantMap().value("name").toString();
......@@ -445,7 +433,7 @@ void FacebookCalendarSyncAdaptor::processParsedEvents(int accountId)
fbNotebook->setIsReadOnly(false);
// We load incidences that are associated to Facebook into memory
KCalCore::Incidence::List dbEvents;
KCalendarCore::Incidence::List dbEvents;
m_storage->loadNotebookIncidences(fbNotebook->uid());
if (!m_storage->allIncidences(&dbEvents, fbNotebook->uid())) {
SOCIALD_LOG_ERROR("unable to load Facebook events from database");
......@@ -458,9 +446,9 @@ void FacebookCalendarSyncAdaptor::processParsedEvents(int accountId)
// find the local event associated with this event.
bool foundLocal = false;
const FacebookParsedEvent &parsedEvent = m_parsedEvents[fbId];
Q_FOREACH (KCalCore::Incidence::Ptr incidence, dbEvents) {
Q_FOREACH (KCalendarCore::Incidence::Ptr incidence, dbEvents) {
if (incidence->uid().endsWith(QStringLiteral(":%1").arg(fbId))) {
KCalCore::Event::Ptr event = m_calendar->event(incidence->uid());
KCalendarCore::Event::Ptr event = m_calendar->event(incidence->uid());
if (!event) continue; // not a valid event incidence.
// found. If it has been modified remotely, then modify locally.
foundLocal = true;
......@@ -478,9 +466,6 @@ void FacebookCalendarSyncAdaptor::processParsedEvents(int accountId)
event->setDtStart(parsedEvent.m_startTime);
if (parsedEvent.m_endExists) {
event->setDtEnd(parsedEvent.m_endTime);
event->setHasEndDate(true);
} else {
event->setHasEndDate(false);
}
if (parsedEvent.m_isDateOnly) {
event->setAllDay(true);
......@@ -497,7 +482,7 @@ void FacebookCalendarSyncAdaptor::processParsedEvents(int accountId)
// if not found locally, it must be a new addition.
if (!foundLocal) {
KCalCore::Event::Ptr event = KCalCore::Event::Ptr(new KCalCore::Event);
KCalendarCore::Event::Ptr event = KCalendarCore::Event::Ptr(new KCalendarCore::Event);
QString eventUid = QUuid::createUuid().toString();
eventUid = eventUid.mid(1); // remove leading {
eventUid.chop(1); // remove trailing }
......@@ -509,9 +494,6 @@ void FacebookCalendarSyncAdaptor::processParsedEvents(int accountId)
event->setDtStart(parsedEvent.m_startTime);
if (parsedEvent.m_endExists) {
event->setDtEnd(parsedEvent.m_endTime);
event->setHasEndDate(true);
} else {
event->setHasEndDate(false);
}
if (parsedEvent.m_isDateOnly) {
event->setAllDay(true);
......@@ -524,7 +506,7 @@ void FacebookCalendarSyncAdaptor::processParsedEvents(int accountId)
}
// Any local events which were not seen, must have been removed remotely.
Q_FOREACH (KCalCore::Incidence::Ptr incidence, dbEvents) {
Q_FOREACH (KCalendarCore::Incidence::Ptr incidence, dbEvents) {
if (!seenLocalEvents.contains(incidence->uid())) {
// note: have to delete from calendar after loaded from calendar.
m_calendar->deleteIncidence(m_calendar->incidence(incidence->uid()));
......
......@@ -37,8 +37,8 @@ public:
QString m_id;
bool m_isDateOnly;
bool m_endExists;
KDateTime m_startTime;
KDateTime m_endTime;
QDateTime m_startTime;
QDateTime m_endTime;
QString m_summary;
QString m_description;
QString m_location;
......
CONFIG += link_pkgconfig
PKGCONFIG += libmkcal-qt5 libkcalcoren-qt5
PKGCONFIG += libmkcal-qt5 KF5CalendarCore
SOURCES += \
$$PWD/googlecalendarsyncadaptor.cpp
HEADERS += \
......
......@@ -24,16 +24,16 @@
#include <QtDebug>
#include <memorycalendar.h>
#include <extendedcalendar.h>
#include <extendedstorage.h>
#include <icalformat.h>
#include <incidence.h>
#include <event.h>
#include <todo.h>
#include <journal.h>
#include <attendee.h>
#include <kdatetime.h>
#include <KCalendarCore/ICalFormat>
#include <KCalendarCore/MemoryCalendar>
#include <KCalendarCore/Incidence>
#include <KCalendarCore/Event>
#include <KCalendarCore/Todo>
#include <KCalendarCore/Journal>
#include <KCalendarCore/Attendee>
#include "trace.h"
......@@ -54,7 +54,7 @@
}
namespace GoogleCalendarIncidenceComparator {
void normalizePersonEmail(KCalCore::Person *p)
void normalizePersonEmail(KCalendarCore::Person *p)
{
QString email = p->email().replace(QStringLiteral("mailto:"), QString(), Qt::CaseInsensitive);
if (email != p->email()) {
......@@ -76,7 +76,7 @@ namespace GoogleCalendarIncidenceComparator {
return true;
}
bool eventsEqual(const KCalCore::Event::Ptr &a, const KCalCore::Event::Ptr &b, bool printDebug)
bool eventsEqual(const KCalendarCore::Event::Ptr &a, const KCalendarCore::Event::Ptr &b, bool printDebug)
{
GIC_RETURN_FALSE_IF_NOT_EQUAL_CUSTOM(a->dateEnd() != b->dateEnd(), "dateEnd", (a->dateEnd().toString() + " != " + b->dateEnd().toString()));
GIC_RETURN_FALSE_IF_NOT_EQUAL(a, b, transparency(), "transparency");
......@@ -107,7 +107,7 @@ namespace GoogleCalendarIncidenceComparator {
return true;
}
bool todosEqual(const KCalCore::Todo::Ptr &a, const KCalCore::Todo::Ptr &b, bool printDebug)
bool todosEqual(const KCalendarCore::Todo::Ptr &a, const KCalendarCore::Todo::Ptr &b, bool printDebug)
{
GIC_RETURN_FALSE_IF_NOT_EQUAL(a, b, hasCompletedDate(), "hasCompletedDate");
GIC_RETURN_FALSE_IF_NOT_EQUAL_CUSTOM(a->dtRecurrence() != b->dtRecurrence(), "dtRecurrence", (a->dtRecurrence().toString() + " != " + b->dtRecurrence().toString()));
......@@ -121,14 +121,14 @@ namespace GoogleCalendarIncidenceComparator {
return true;
}
bool journalsEqual(const KCalCore::Journal::Ptr &, const KCalCore::Journal::Ptr &, bool)
bool journalsEqual(const KCalendarCore::Journal::Ptr &, const KCalendarCore::Journal::Ptr &, bool)
{
// no journal-specific properties; it only uses the base incidence properties
return true;
}
// Checks whether a specific set of properties are equal.
bool incidencesEqual(const KCalCore::Incidence::Ptr &a, const KCalCore::Incidence::Ptr &b, bool printDebug)
bool incidencesEqual(const KCalendarCore::Incidence::Ptr &a, const KCalendarCore::Incidence::Ptr &b, bool printDebug)
{
if (!a || !b) {
qWarning() << "Invalid paramters! a:" << a << "b:" << b;
......@@ -138,7 +138,7 @@ namespace GoogleCalendarIncidenceComparator {
// Do not compare created() or lastModified() because we don't update these fields when
// an incidence is updated by copyIncidenceProperties(), so they are guaranteed to be unequal.
// TODO compare deref alarms and attachment lists to compare them also.
// Don't compare resources() for now because KCalCore may insert QStringList("") as the resources
// Don't compare resources() for now because KCalendarCore may insert QStringList("") as the resources
// when in fact it should be QStringList(), which causes the comparison to fail.
GIC_RETURN_FALSE_IF_NOT_EQUAL(a, b, type(), "type");
GIC_RETURN_FALSE_IF_NOT_EQUAL(a, b, duration(), "duration");
......@@ -170,8 +170,8 @@ namespace GoogleCalendarIncidenceComparator {
}
// Some servers insert a mailto: in the organizer email address, so ignore this when comparing organizers
KCalCore::Person personA(*a->organizer().data());
KCalCore::Person personB(*b->organizer().data());
KCalendarCore::Person personA(a->organizer());
KCalendarCore::Person personB(b->organizer());
normalizePersonEmail(&personA);
normalizePersonEmail(&personB);
const QString aEmail = personA.email();
......@@ -185,23 +185,23 @@ namespace GoogleCalendarIncidenceComparator {
}
switch (a->type()) {
case KCalCore::IncidenceBase::TypeEvent:
if (!eventsEqual(a.staticCast<KCalCore::Event>(), b.staticCast<KCalCore::Event>(), printDebug)) {
case KCalendarCore::IncidenceBase::TypeEvent:
if (!eventsEqual(a.staticCast<KCalendarCore::Event>(), b.staticCast<KCalendarCore::Event>(), printDebug)) {
return false;
}
break;
case KCalCore::IncidenceBase::TypeTodo:
if (!todosEqual(a.staticCast<KCalCore::Todo>(), b.staticCast<KCalCore::Todo>(), printDebug)) {
case KCalendarCore::IncidenceBase::TypeTodo:
if (!todosEqual(a.staticCast<KCalendarCore::Todo>(), b.staticCast<KCalendarCore::Todo>(), printDebug)) {
return false;
}
break;
case KCalCore::IncidenceBase::TypeJournal:
if (!journalsEqual(a.staticCast<KCalCore::Journal>(), b.staticCast<KCalCore::Journal>(), printDebug)) {
case KCalendarCore::IncidenceBase::TypeJournal:
if (!journalsEqual(a.staticCast<KCalendarCore::Journal>(), b.staticCast<KCalendarCore::Journal>(), printDebug)) {
return false;
}
break;
case KCalCore::IncidenceBase::TypeFreeBusy:
case KCalCore::IncidenceBase::TypeUnknown:
case KCalendarCore::IncidenceBase::TypeFreeBusy:
case KCalendarCore::IncidenceBase::TypeUnknown:
SOCIALD_LOG_DEBUG_MAYBE("Unable to compare FreeBusy or Unknown incidence, assuming equal");
break;
}
......
......@@ -31,8 +31,7 @@
#include <extendedcalendar.h>
#include <extendedstorage.h>
#include <icalformat.h>
#include <kdatetime.h>
#include <KCalendarCore/ICalFormat>
class GoogleCalendarSyncAdaptor : public GoogleDataTypeSyncAdaptor
{
......@@ -73,7 +72,7 @@ private:
QString accessToken;
ChangeType upsyncType;
QString kcalEventId;
KDateTime recurrenceId;
QDateTime recurrenceId;
QString calendarId;
QString eventId;
QByteArray eventData;
......@@ -98,7 +97,7 @@ private:
const QString &calendarId, const QDateTime &since);
void upsyncChanges(const QString &accessToken,
GoogleCalendarSyncAdaptor::ChangeType upsyncType,
const QString &kcalEventId, const KDateTime &recurrenceId, const QString &calendarId,
const QString &kcalEventId, const QDateTime &recurrenceId, const QString &calendarId,
const QString &eventId,const QByteArray &eventData);
void applyRemoteChangesLocally();
......@@ -108,7 +107,7 @@ private:
void finishedRequestingRemoteEvents(const QString &accessToken,
const QString &calendarId, const QString &syncToken,
const QString &nextSyncToken, const QDateTime &since);
void clampEventTimeToSync(KCalCore::Event::Ptr event) const;
void clampEventTimeToSync(KCalendarCore::Event::Ptr event) const;
static void setCalendarProperties(mKCal::Notebook::Ptr notebook,
const CalendarInfo &calendarInfo,
......@@ -117,8 +116,8 @@ private:
const QString &syncProfile,
const QString &ownerEmail);
const QList<KDateTime> getExceptionInstanceDates(const KCalCore::Event::Ptr event) const;
QJsonObject kCalToJson(KCalCore::Event::Ptr event, KCalCore::ICalFormat &icalFormat, bool setUidProperty = false) const;
const QList<QDateTime> getExceptionInstanceDates(const KCalendarCore::Event::Ptr event) const;
QJsonObject kCalToJson(KCalendarCore::Event::Ptr event, KCalendarCore::ICalFormat &icalFormat, bool setUidProperty = false) const;
private Q_SLOTS:
void calendarsFinishedHandler();
......@@ -139,17 +138,17 @@ private:
QMap<QString, QString> m_calendarsNextSyncTokens; // calendarId to sync token to use during next sync cycle
QMap<QString, QDateTime> m_calendarsSyncDate; // calendarId to since date to use when determining delta
QMultiMap<QString, QPair<GoogleCalendarSyncAdaptor::ChangeType, QJsonObject> > m_changesFromDownsync; // calendarId to change
QMultiMap<QString, QPair<KCalCore::Event::Ptr, QJsonObject> > m_changesFromUpsync; // calendarId to event+upsyncResponse
QMultiMap<QString, QPair<KCalendarCore::Event::Ptr, QJsonObject> > m_changesFromUpsync; // calendarId to event+upsyncResponse
QSet<QString> m_syncTokenFailure; // calendarIds suffering from 410 error due to invalid sync token
QSet<QString> m_timeMinFailure; // calendarIds suffering from 410 error due to invalid timeMin value
KCalCore::Incidence::List m_purgeList;
QMap<QString, KCalCore::Incidence::Ptr> m_deletedGcalIdToIncidence;
KCalendarCore::Incidence::List m_purgeList;
QMap<QString, KCalendarCore::Incidence::Ptr> m_deletedGcalIdToIncidence;
mKCal::ExtendedCalendar::Ptr m_calendar;
mKCal::ExtendedStorage::Ptr m_storage;
mutable KCalCore::ICalFormat m_icalFormat;
mutable KCalendarCore::ICalFormat m_icalFormat;
bool m_storageNeedsSave;
KDateTime m_syncedDateTime;
QDateTime m_syncedDateTime;
};
#endif // GOOGLECALENDARSYNCADAPTOR_H
CONFIG += link_pkgconfig
PKGCONFIG += libmkcal-qt5 libkcalcoren-qt5
PKGCONFIG += libmkcal-qt5 KF5CalendarCore
SOURCES += $$PWD/vkcalendarsyncadaptor.cpp
HEADERS += $$PWD/vkcalendarsyncadaptor.h
INCLUDEPATH += $$PWD
......
......@@ -23,14 +23,14 @@
#define SOCIALD_VK_MAX_CALENDAR_ENTRY_RESULTS 100
namespace {
bool eventNeedsUpdate(KCalCore::Event::Ptr event, const QJsonObject &json)
bool eventNeedsUpdate(KCalendarCore::Event::Ptr event, const QJsonObject &json)
{
// TODO: compare data, determine if we need to update
Q_UNUSED(event)
Q_UNUSED(json)
return true;
}
void jsonToKCal(const QString &vkId, const QJsonObject &json, KCalCore::Event::Ptr event, bool isUpdate)
void jsonToKCal(const QString &vkId, const QJsonObject &json, KCalendarCore::Event::Ptr event, bool isUpdate)
{
SOCIALD_LOG_DEBUG("Converting group event JSON to calendar event:" << json);
if (!isUpdate) {
......@@ -46,13 +46,10 @@ namespace {
event->setLocation(eventAddress.isEmpty() ? addressTitle : eventAddress);
if (json.contains(QStringLiteral("start_date"))) {
uint startTime = json.value(QStringLiteral("start_date")).toDouble();
event->setDtStart(KDateTime(QDateTime::fromTime_t(startTime)));
event->setDtStart(QDateTime::fromTime_t(startTime));
if (json.contains(QStringLiteral("end_date"))) {
uint endTime = json.value(QStringLiteral("end_date")).toDouble();
event->setHasEndDate(true);
event->setDtEnd(KDateTime(QDateTime::fromTime_t(endTime)));
} else {
event->setHasEndDate(false);
event->setDtEnd(QDateTime::fromTime_t(endTime));
}
}
}
......@@ -60,7 +57,7 @@ namespace {
VKCalendarSyncAdaptor::VKCalendarSyncAdaptor(QObject *parent)
: VKDataTypeSyncAdaptor(SocialNetworkSyncAdaptor::Calendars, parent)
, m_calendar(mKCal::ExtendedCalendar::Ptr(new mKCal::ExtendedCalendar(QLatin1String("UTC"))))
, m_calendar(mKCal::ExtendedCalendar::Ptr(new mKCal::ExtendedCalendar(QTimeZone::utc())))
, m_storage(mKCal::ExtendedCalendar::defaultStorage(m_calendar))
, m_storageNeedsSave(false)
{
......@@ -115,11 +112,11 @@ void VKCalendarSyncAdaptor::finalize(int accountId)
// Build up a map of existing events, then determine A/M/R delta.
int addedCount = 0, modifiedCount = 0, removedCount = 0;
m_storage->loadNotebookIncidences(m_vkNotebook->uid());
KCalCore::Incidence::List allIncidences;
KCalendarCore::Incidence::List allIncidences;
m_storage->allIncidences(&allIncidences, m_vkNotebook->uid());
QSet<QString> serverSideEventIds = m_eventObjects[accountId].keys().toSet();
Q_FOREACH (const KCalCore::Incidence::Ptr incidence, allIncidences) {
KCalCore::Event::Ptr event = m_calendar->event(incidence->uid());
Q_FOREACH (const KCalendarCore::Incidence::Ptr incidence, allIncidences) {
KCalendarCore::Event::Ptr event = m_calendar->event(incidence->uid());
// when we add new events, we generate the uid like QUUID:vkId
// to ensure that even after removal/re-add, the uid is unique.
const QString &eventUid = event->uid();
......@@ -156,7 +153,7 @@ void VKCalendarSyncAdaptor::finalize(int accountId)
Q_FOREACH (const QString &vkId, serverSideEventIds) {
m_vkNotebook->setIsReadOnly(false); // temporarily
const QJsonObject &eventObject(m_eventObjects[accountId][vkId]);
KCalCore::Event::Ptr event = KCalCore::Event::Ptr(new KCalCore::Event);
KCalendarCore::Event::Ptr event = KCalendarCore::Event::Ptr(new KCalendarCore::Event);
jsonToKCal(vkId, eventObject, event, false); // direct conversion
event->setReadOnly(true);
if (!m_calendar->addEvent(event, m_vkNotebook->uid())) {
......
Markdown is supported
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