diff --git a/lightweight/calendardataservice/calendardataservice.pro b/lightweight/calendardataservice/calendardataservice.pro index 90456bb..8667c34 100644 --- a/lightweight/calendardataservice/calendardataservice.pro +++ b/lightweight/calendardataservice/calendardataservice.pro @@ -6,7 +6,7 @@ QT += qml dbus QT -= gui CONFIG += link_pkgconfig -PKGCONFIG += libkcalcoren-qt5 libmkcal-qt5 libical accounts-qt5 +PKGCONFIG += KF5CalendarCore libmkcal-qt5 libical accounts-qt5 HEADERS += \ calendardataservice.h \ diff --git a/rpm/nemo-qml-plugin-calendar-qt5.spec b/rpm/nemo-qml-plugin-calendar-qt5.spec index a946a58..7d8e12f 100644 --- a/rpm/nemo-qml-plugin-calendar-qt5.spec +++ b/rpm/nemo-qml-plugin-calendar-qt5.spec @@ -12,7 +12,7 @@ BuildRequires: pkgconfig(Qt5Gui) BuildRequires: pkgconfig(Qt5Qml) BuildRequires: pkgconfig(Qt5Concurrent) BuildRequires: pkgconfig(libmkcal-qt5) -BuildRequires: pkgconfig(libkcalcoren-qt5) +BuildRequires: pkgconfig(KF5CalendarCore) BuildRequires: pkgconfig(libical) BuildRequires: pkgconfig(accounts-qt5) @@ -41,7 +41,7 @@ Summary: Calendar import/export tool License: BSD Group: Applications/System BuildRequires: pkgconfig(libmkcal-qt5) -BuildRequires: pkgconfig(libkcalcoren-qt5) +BuildRequires: pkgconfig(KF5CalendarCore) %description tools %{summary}. diff --git a/src/calendarapi.cpp b/src/calendarapi.cpp index d668f74..008f814 100644 --- a/src/calendarapi.cpp +++ b/src/calendarapi.cpp @@ -1,6 +1,6 @@ /* - * Copyright (C) 2013 Jolla Ltd. - * Contact: Aaron Kennedy + * Copyright (C) 2013 - 2019 Jolla Ltd. + * Copyright (c) 2020 Open Mobile Platform LLC. * * You may use this file under the terms of the BSD license as follows: * @@ -65,7 +65,7 @@ CalendarEventModification * CalendarApi::createModification(CalendarEvent *sourc void CalendarApi::remove(const QString &uid, const QString &recurrenceId, const QDateTime &time) { - KDateTime recurrenceTime = KDateTime::fromString(recurrenceId); + QDateTime recurrenceTime = QDateTime::fromString(recurrenceId, Qt::ISODate); CalendarManager::instance()->deleteEvent(uid, recurrenceTime, time); // TODO: this sucks diff --git a/src/calendarchangeinformation.cpp b/src/calendarchangeinformation.cpp index c169ae5..da8de7f 100644 --- a/src/calendarchangeinformation.cpp +++ b/src/calendarchangeinformation.cpp @@ -1,4 +1,38 @@ +/* + * Copyright (c) 2015 - 2019 Jolla Ltd. + * Copyright (c) 2019 - 2020 Open Mobile Platform LLC. + * + * You may use this file under the terms of the BSD license as follows: + * + * "Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Nemo Mobile nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." + */ + #include "calendarchangeinformation.h" +#include "calendarutils.h" + #include CalendarChangeInformation::CalendarChangeInformation(QObject *parent) : @@ -10,7 +44,7 @@ CalendarChangeInformation::~CalendarChangeInformation() { } -void CalendarChangeInformation::setInformation(const QString &uniqueId, const KDateTime &recurrenceId) +void CalendarChangeInformation::setInformation(const QString &uniqueId, const QDateTime &recurrenceId) { m_uniqueId = uniqueId; m_recurrenceId = recurrenceId; @@ -33,5 +67,5 @@ QString CalendarChangeInformation::uniqueId() QString CalendarChangeInformation::recurrenceId() { - return m_recurrenceId.toString(); + return CalendarUtils::recurrenceIdToString(m_recurrenceId); } diff --git a/src/calendarchangeinformation.h b/src/calendarchangeinformation.h index abc4dbb..65c16c3 100644 --- a/src/calendarchangeinformation.h +++ b/src/calendarchangeinformation.h @@ -1,10 +1,41 @@ +/* + * Copyright (c) 2014 - 2019 Jolla Ltd. + * Copyright (c) 2020 Open Mobile Platform LLC. + * + * You may use this file under the terms of the BSD license as follows: + * + * "Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Nemo Mobile nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." + */ + #ifndef CALENDARCHANGEINFORMATION_H #define CALENDARCHANGEINFORMATION_H #include #include - -#include +#include class CalendarChangeInformation : public QObject { @@ -17,7 +48,7 @@ class CalendarChangeInformation : public QObject explicit CalendarChangeInformation(QObject *parent = 0); virtual ~CalendarChangeInformation(); - void setInformation(const QString &uniqueId, const KDateTime &recurrenceId); + void setInformation(const QString &uniqueId, const QDateTime &recurrenceId); bool pending(); QString uniqueId(); QString recurrenceId(); @@ -30,7 +61,7 @@ class CalendarChangeInformation : public QObject private: bool m_pending; QString m_uniqueId; - KDateTime m_recurrenceId; + QDateTime m_recurrenceId; }; #endif diff --git a/src/calendardata.h b/src/calendardata.h index 594c2df..0e32e44 100644 --- a/src/calendardata.h +++ b/src/calendardata.h @@ -1,12 +1,44 @@ +/* + * Copyright (c) 2014 - 2019 Jolla Ltd. + * Copyright (c) 2020 Open Mobile Platform LLC. + * + * You may use this file under the terms of the BSD license as follows: + * + * "Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Nemo Mobile nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." + */ + #ifndef NEMOCALENDARDATA_H #define NEMOCALENDARDATA_H #include #include +#include -// KCalCore -#include -#include +// KCalendarCore +#include #include "calendarevent.h" @@ -14,7 +46,7 @@ namespace CalendarData { struct EventOccurrence { QString eventUid; - KDateTime recurrenceId; + QDateTime recurrenceId; QDateTime startTime; QDateTime endTime; @@ -27,8 +59,8 @@ struct EventOccurrence { struct Event { QString displayLabel; QString description; - KDateTime startTime; - KDateTime endTime; + QDateTime startTime; + QDateTime endTime; bool allDay = false; bool readOnly = false; bool rsvp = false; @@ -38,7 +70,7 @@ struct Event { CalendarEvent::Days recurWeeklyDays; int reminder; // seconds; 15 minutes before event = +900, at time of event = 0, no reminder = negative value. QString uniqueId; - KDateTime recurrenceId; + QDateTime recurrenceId; QString location; CalendarEvent::Secrecy secrecy; QString calendarUid; @@ -92,8 +124,8 @@ struct Attendee { bool isOrganizer = false; QString name; QString email; - KCalCore::Attendee::Role participationRole = KCalCore::Attendee::OptParticipant; - KCalCore::Attendee::PartStat status = KCalCore::Attendee::None; + KCalendarCore::Attendee::Role participationRole = KCalendarCore::Attendee::OptParticipant; + KCalendarCore::Attendee::PartStat status = KCalendarCore::Attendee::None; bool operator==(const Attendee &other) const { return isOrganizer == other.isOrganizer diff --git a/src/calendarevent.cpp b/src/calendarevent.cpp index a0c26cc..adc41a7 100644 --- a/src/calendarevent.cpp +++ b/src/calendarevent.cpp @@ -1,6 +1,6 @@ /* - * Copyright (C) 2013 Jolla Ltd. - * Contact: Robin Burchell + * Copyright (c) 2013 - 2019 Jolla Ltd. + * Copyright (c) 2020 Open Mobile Platform LLC. * * You may use this file under the terms of the BSD license as follows: * @@ -33,13 +33,13 @@ #include "calendarevent.h" #include +#include +#include -// kcalcore -#include - +#include "calendarutils.h" #include "calendarmanager.h" -CalendarEvent::CalendarEvent(CalendarManager *manager, const QString &uid, const KDateTime &recurrenceId) +CalendarEvent::CalendarEvent(CalendarManager *manager, const QString &uid, const QDateTime &recurrenceId) : QObject(manager), mManager(manager), mUniqueId(uid), mRecurrenceId(recurrenceId) { connect(mManager, SIGNAL(notebookColorChanged(QString)), @@ -64,56 +64,47 @@ QString CalendarEvent::description() const QDateTime CalendarEvent::startTime() const { - // Cannot use KDateTime::dateTime() here because it is handling UTC - // spec in a different manner than other specs. If UTC, the QDateTime + // Cannot return the date time directly here. If UTC, the QDateTime // will be in UTC also and the UI will convert it to local when displaying // the time, while in every other case, it set the QDateTime in // local zone. - const KDateTime kdt = mManager->getEvent(mUniqueId, mRecurrenceId).startTime; - return QDateTime(kdt.date(), kdt.time()); + const QDateTime dt = mManager->getEvent(mUniqueId, mRecurrenceId).startTime; + return QDateTime(dt.date(), dt.time()); } QDateTime CalendarEvent::endTime() const { - const KDateTime kdt = mManager->getEvent(mUniqueId, mRecurrenceId).endTime; - return QDateTime(kdt.date(), kdt.time()); + const QDateTime dt = mManager->getEvent(mUniqueId, mRecurrenceId).endTime; + return QDateTime(dt.date(), dt.time()); } -static CalendarEvent::TimeSpec toTimeSpec(const KDateTime &dt) +static Qt::TimeSpec toTimeSpec(const QDateTime &dt) { - switch (dt.timeType()) { - case (KDateTime::ClockTime): - return CalendarEvent::SpecClockTime; - case (KDateTime::LocalZone): - return CalendarEvent::SpecLocalZone; - case (KDateTime::TimeZone): - return CalendarEvent::SpecTimeZone; - case (KDateTime::UTC): - return CalendarEvent::SpecUtc; - default: - // Ignore other time types. - return CalendarEvent::SpecLocalZone; + if (dt.timeZone() == QTimeZone::utc()) { + return Qt::UTC; } + + return dt.timeSpec(); } -CalendarEvent::TimeSpec CalendarEvent::startTimeSpec() const +Qt::TimeSpec CalendarEvent::startTimeSpec() const { return toTimeSpec(mManager->getEvent(mUniqueId, mRecurrenceId).startTime); } -CalendarEvent::TimeSpec CalendarEvent::endTimeSpec() const +Qt::TimeSpec CalendarEvent::endTimeSpec() const { return toTimeSpec(mManager->getEvent(mUniqueId, mRecurrenceId).endTime); } QString CalendarEvent::startTimeZone() const { - return mManager->getEvent(mUniqueId, mRecurrenceId).startTime.timeZone().name(); + return QString::fromLatin1(mManager->getEvent(mUniqueId, mRecurrenceId).startTime.timeZone().id()); } QString CalendarEvent::endTimeZone() const { - return mManager->getEvent(mUniqueId, mRecurrenceId).endTime.timeZone().name(); + return QString::fromLatin1(mManager->getEvent(mUniqueId, mRecurrenceId).endTime.timeZone().id()); } bool CalendarEvent::allDay() const @@ -201,7 +192,7 @@ bool CalendarEvent::sendResponse(int response) return mManager->sendResponse(mManager->getEvent(mUniqueId, mRecurrenceId), (Response)response); } -KDateTime CalendarEvent::recurrenceId() const +QDateTime CalendarEvent::recurrenceId() const { return mRecurrenceId; } @@ -209,7 +200,7 @@ KDateTime CalendarEvent::recurrenceId() const QString CalendarEvent::recurrenceIdString() const { if (mRecurrenceId.isValid()) { - return mRecurrenceId.toString(); + return CalendarUtils::recurrenceIdToString(mRecurrenceId); } else { return QString(); } diff --git a/src/calendarevent.h b/src/calendarevent.h index d8f6bf9..622eaed 100644 --- a/src/calendarevent.h +++ b/src/calendarevent.h @@ -36,8 +36,6 @@ #include #include -#include - class CalendarManager; class CalendarEvent : public QObject @@ -51,8 +49,8 @@ class CalendarEvent : public QObject Q_PROPERTY(QString description READ description NOTIFY descriptionChanged) Q_PROPERTY(QDateTime startTime READ startTime NOTIFY startTimeChanged) Q_PROPERTY(QDateTime endTime READ endTime NOTIFY endTimeChanged) - Q_PROPERTY(CalendarEvent::TimeSpec startTimeSpec READ startTimeSpec NOTIFY startTimeChanged) - Q_PROPERTY(CalendarEvent::TimeSpec endTimeSpec READ endTimeSpec NOTIFY endTimeChanged) + Q_PROPERTY(Qt::TimeSpec startTimeSpec READ startTimeSpec NOTIFY startTimeChanged) + Q_PROPERTY(Qt::TimeSpec endTimeSpec READ endTimeSpec NOTIFY endTimeChanged) Q_PROPERTY(QString startTimeZone READ startTimeZone NOTIFY startTimeChanged) Q_PROPERTY(QString endTimeZone READ endTimeZone NOTIFY endTimeChanged) Q_PROPERTY(bool allDay READ allDay NOTIFY allDayChanged) @@ -101,14 +99,6 @@ class CalendarEvent : public QObject Q_DECLARE_FLAGS(Days, Day) Q_FLAG(Days) - enum TimeSpec { - SpecLocalZone, - SpecClockTime, - SpecTimeZone, - SpecUtc - }; - Q_ENUM(TimeSpec) - enum Secrecy { SecrecyPublic, SecrecyPrivate, @@ -130,15 +120,15 @@ class CalendarEvent : public QObject }; Q_ENUM(SyncFailure) - CalendarEvent(CalendarManager *manager, const QString &uid, const KDateTime &recurrenceId); + CalendarEvent(CalendarManager *manager, const QString &uid, const QDateTime &recurrenceId); ~CalendarEvent(); QString displayLabel() const; QString description() const; QDateTime startTime() const; QDateTime endTime() const; - TimeSpec startTimeSpec() const; - TimeSpec endTimeSpec() const; + Qt::TimeSpec startTimeSpec() const; + Qt::TimeSpec endTimeSpec() const; QString startTimeZone() const; QString endTimeZone() const; bool allDay() const; @@ -152,7 +142,7 @@ class CalendarEvent : public QObject bool readOnly() const; QString calendarUid() const; QString location() const; - KDateTime recurrenceId() const; + QDateTime recurrenceId() const; QString recurrenceIdString() const; Secrecy secrecy() const; SyncFailure syncFailure() const; @@ -191,7 +181,7 @@ private slots: private: CalendarManager *mManager; QString mUniqueId; - KDateTime mRecurrenceId; + QDateTime mRecurrenceId; }; #endif // CALENDAREVENT_H diff --git a/src/calendareventmodification.cpp b/src/calendareventmodification.cpp index b586a30..bc2a6df 100644 --- a/src/calendareventmodification.cpp +++ b/src/calendareventmodification.cpp @@ -1,9 +1,60 @@ +/* + * Copyright (c) 2014 - 2019 Jolla Ltd. + * Copyright (c) 2020 Open Mobile Platform LLC. + * + * You may use this file under the terms of the BSD license as follows: + * + * "Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Nemo Mobile nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." + */ + #include "calendareventmodification.h" #include "calendarmanager.h" -#include +#include "calendarutils.h" +#include #include +namespace { + +void updateTime(QDateTime *dt, Qt::TimeSpec spec, const QString &timeZone) +{ + if (spec == Qt::TimeZone) { + QTimeZone tz(timeZone.toUtf8()); + if (tz.isValid()) { + dt->setTimeZone(tz); + } else { + qWarning() << "Cannot find time zone:" << timeZone; + } + } else { + dt->setTimeSpec(spec); + } +} + +} + CalendarEventModification::CalendarEventModification(CalendarData::Event data, QObject *parent) : QObject(parent), m_event(data), m_attendeesSet(false) { @@ -16,8 +67,6 @@ CalendarEventModification::CalendarEventModification(QObject *parent) m_event.reminder = -1; // ReminderNone m_event.allDay = false; m_event.readOnly = false; - m_event.startTime = KDateTime(QDateTime(), KDateTime::LocalZone); - m_event.endTime = KDateTime(QDateTime(), KDateTime::LocalZone); } CalendarEventModification::~CalendarEventModification() @@ -52,46 +101,28 @@ void CalendarEventModification::setDescription(const QString &description) QDateTime CalendarEventModification::startTime() const { - return m_event.startTime.dateTime(); -} - -static KDateTime toKDateTime(const QDateTime &dt, int spec, const QString &timezone) -{ - if (spec == CalendarEvent::SpecTimeZone) { - KTimeZone tz = KSystemTimeZones::zone(timezone); - if (tz.isValid()) { - return KDateTime(dt, tz); - } else { - qWarning() << "Invalid zone name, falling back to local zone:" << timezone; - return KDateTime(dt, KDateTime::LocalZone); - } - } else if (spec == CalendarEvent::SpecClockTime) { - return KDateTime(dt, KDateTime::ClockTime); - } else if (spec == CalendarEvent::SpecUtc) { - return KDateTime(QDateTime(dt.date(), dt.time(), Qt::UTC)); - } - return KDateTime(dt, KDateTime::LocalZone); + return m_event.startTime; } -void CalendarEventModification::setStartTime(const QDateTime &startTime, int spec, const QString &timezone) +void CalendarEventModification::setStartTime(const QDateTime &startTime, Qt::TimeSpec spec, const QString &timezone) { - const KDateTime time = toKDateTime(startTime, spec, timezone); - if (m_event.startTime != time) { - m_event.startTime = time; + if (m_event.startTime != startTime) { + m_event.startTime = startTime; + updateTime(&m_event.startTime, spec, timezone); emit startTimeChanged(); } } QDateTime CalendarEventModification::endTime() const { - return m_event.endTime.dateTime(); + return m_event.endTime; } -void CalendarEventModification::setEndTime(const QDateTime &endTime, int spec, const QString &timezone) +void CalendarEventModification::setEndTime(const QDateTime &endTime, Qt::TimeSpec spec, const QString &timezone) { - const KDateTime time = toKDateTime(endTime, spec, timezone); - if (m_event.endTime != time) { - m_event.endTime = time; + if (m_event.endTime != endTime) { + m_event.endTime = endTime; + updateTime(&m_event.endTime, spec, timezone); emit endTimeChanged(); } } @@ -168,7 +199,7 @@ void CalendarEventModification::setRecurWeeklyDays(CalendarEvent::Days days) QString CalendarEventModification::recurrenceIdString() const { if (m_event.recurrenceId.isValid()) { - return m_event.recurrenceId.toString(); + return CalendarUtils::recurrenceIdToString(m_event.recurrenceId); } else { return QString(); } diff --git a/src/calendareventmodification.h b/src/calendareventmodification.h index 7121bb4..a59570e 100644 --- a/src/calendareventmodification.h +++ b/src/calendareventmodification.h @@ -1,3 +1,35 @@ +/* + * Copyright (c) 2014 - 2019 Jolla Ltd. + * Copyright (c) 2020 Open Mobile Platform LLC. + * + * You may use this file under the terms of the BSD license as follows: + * + * "Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Nemo Mobile nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." + */ + #ifndef CALENDAREVENTMODIFICATION_H #define CALENDAREVENTMODIFICATION_H @@ -38,10 +70,10 @@ class CalendarEventModification : public QObject void setDescription(const QString &description); QDateTime startTime() const; - Q_INVOKABLE void setStartTime(const QDateTime &startTime, int spec, const QString &timezone = QString()); + Q_INVOKABLE void setStartTime(const QDateTime &startTime, Qt::TimeSpec spec, const QString &timezone = QString()); QDateTime endTime() const; - Q_INVOKABLE void setEndTime(const QDateTime &endTime, int spec, const QString &timezone = QString()); + Q_INVOKABLE void setEndTime(const QDateTime &endTime, Qt::TimeSpec spec, const QString &timezone = QString()); bool allDay() const; void setAllDay(bool); diff --git a/src/calendareventoccurrence.cpp b/src/calendareventoccurrence.cpp index 2fb8a10..fbb9cb8 100644 --- a/src/calendareventoccurrence.cpp +++ b/src/calendareventoccurrence.cpp @@ -1,6 +1,6 @@ /* - * Copyright (C) 2013 Jolla Ltd. - * Contact: Robin Burchell + * Copyright (C) 2013 - 2019 Jolla Ltd. + * Copyright (C) 2020 Open Mobile Platform LLC. * * You may use this file under the terms of the BSD license as follows: * @@ -38,7 +38,7 @@ #include "calendarmanager.h" CalendarEventOccurrence::CalendarEventOccurrence(const QString &eventUid, - const KDateTime &recurrenceId, + const QDateTime &recurrenceId, const QDateTime &startTime, const QDateTime &endTime, QObject *parent) @@ -74,15 +74,15 @@ void CalendarEventOccurrence::eventUidChanged(QString oldUid, QString newUid) } static QDateTime toEventDateTime(const QDateTime &dateTime, - CalendarEvent::TimeSpec eventSpec, + Qt::TimeSpec eventSpec, const QString &eventTimezone) { switch (eventSpec) { - case (CalendarEvent::SpecTimeZone): { + case (Qt::TimeZone): { const QDateTime dt = dateTime.toTimeZone(QTimeZone(eventTimezone.toUtf8())); return QDateTime(dt.date(), dt.time()); } - case (CalendarEvent::SpecUtc): { + case (Qt::UTC): { const QDateTime dt = dateTime.toUTC(); return QDateTime(dt.date(), dt.time()); } diff --git a/src/calendareventoccurrence.h b/src/calendareventoccurrence.h index eeffe01..e1ca555 100644 --- a/src/calendareventoccurrence.h +++ b/src/calendareventoccurrence.h @@ -1,6 +1,6 @@ /* - * Copyright (C) 2013 Jolla Ltd. - * Contact: Robin Burchell + * Copyright (C) 2013 - 2019 Jolla Ltd. + * Copyright (C) 2020 Open Mobile Platform LLC. * * You may use this file under the terms of the BSD license as follows: * @@ -36,8 +36,6 @@ #include #include -#include - class CalendarEvent; class CalendarEventOccurrence : public QObject @@ -53,7 +51,7 @@ class CalendarEventOccurrence : public QObject public: CalendarEventOccurrence(const QString &eventUid, - const KDateTime &recurrenceId, + const QDateTime &recurrenceId, const QDateTime &startTime, const QDateTime &endTime, QObject *parent = 0); @@ -70,7 +68,7 @@ private slots: private: QString mEventUid; - KDateTime mRecurrenceId; + QDateTime mRecurrenceId; QDateTime mStartTime; QDateTime mEndTime; }; diff --git a/src/calendareventquery.cpp b/src/calendareventquery.cpp index 03512cd..0ba7806 100644 --- a/src/calendareventquery.cpp +++ b/src/calendareventquery.cpp @@ -1,6 +1,6 @@ /* - * Copyright (C) 2013 Jolla Ltd. - * Contact: Aaron Kennedy + * Copyright (c) 2013 - 2019 Jolla Ltd. + * Copyright (c) 2020 Open Mobile Platform LLC. * * You may use this file under the terms of the BSD license as follows: * @@ -36,6 +36,8 @@ #include "calendareventoccurrence.h" #include "calendarutils.h" +#include + CalendarEventQuery::CalendarEventQuery() : mIsComplete(true), mOccurrence(0), mAttendeesCached(false), mEventError(false) { @@ -82,7 +84,7 @@ void CalendarEventQuery::setUniqueId(const QString &uid) QString CalendarEventQuery::recurrenceIdString() { if (mRecurrenceId.isValid()) { - return mRecurrenceId.toString(); + return CalendarUtils::recurrenceIdToString(mRecurrenceId); } else { return QString(); } @@ -90,7 +92,7 @@ QString CalendarEventQuery::recurrenceIdString() void CalendarEventQuery::setRecurrenceIdString(const QString &recurrenceId) { - KDateTime recurrenceIdTime = KDateTime::fromString(recurrenceId); + QDateTime recurrenceIdTime = QDateTime::fromString(recurrenceId, Qt::ISODate); if (mRecurrenceId == recurrenceIdTime) { return; } @@ -224,7 +226,7 @@ bool CalendarEventQuery::eventError() const return mEventError; } -KDateTime CalendarEventQuery::recurrenceId() +QDateTime CalendarEventQuery::recurrenceId() { return mRecurrenceId; } diff --git a/src/calendareventquery.h b/src/calendareventquery.h index d4345f7..1ce0b95 100644 --- a/src/calendareventquery.h +++ b/src/calendareventquery.h @@ -1,6 +1,6 @@ /* - * Copyright (C) 2013 Jolla Ltd. - * Contact: Aaron Kennedy + * Copyright (C) 2013 - 2019 Jolla Ltd. + * Copyright (C) 2020 Open Mobile Platform LLC. * * You may use this file under the terms of the BSD license as follows: * @@ -37,8 +37,6 @@ #include #include -#include - #include "calendardata.h" class CalendarEventOccurrence; @@ -111,7 +109,7 @@ class CalendarEventQuery : public QObject, public QQmlParserStatus QString recurrenceIdString(); void setRecurrenceIdString(const QString &recurrenceId); - KDateTime recurrenceId(); + QDateTime recurrenceId(); QDateTime startTime() const; void setStartTime(const QDateTime &); @@ -150,7 +148,7 @@ private slots: private: bool mIsComplete; QString mUid; - KDateTime mRecurrenceId; + QDateTime mRecurrenceId; QDateTime mStartTime; CalendarData::Event mEvent; CalendarEventOccurrence *mOccurrence; diff --git a/src/calendarimportevent.cpp b/src/calendarimportevent.cpp index f931be1..b40bc96 100644 --- a/src/calendarimportevent.cpp +++ b/src/calendarimportevent.cpp @@ -1,6 +1,6 @@ /* - * Copyright (C) 2015 Jolla Ltd. - * Contact: Petri M. Gerdt + * Copyright (C) 2015 - 2019 Jolla Ltd. + * Copyright (C) 2020 Open Mobile Platform LLC. * * You may use this file under the terms of the BSD license as follows: * @@ -38,7 +38,7 @@ #include -CalendarImportEvent::CalendarImportEvent(KCalCore::Event::Ptr event) +CalendarImportEvent::CalendarImportEvent(KCalendarCore::Event::Ptr event) : QObject(), mEvent(event), mColor("#ffffff") @@ -66,7 +66,7 @@ QDateTime CalendarImportEvent::startTime() const if (!mEvent) return QDateTime(); - return mEvent->dtStart().dateTime(); + return mEvent->dtStart(); } QDateTime CalendarImportEvent::endTime() const @@ -74,7 +74,7 @@ QDateTime CalendarImportEvent::endTime() const if (!mEvent) return QDateTime(); - return mEvent->dtEnd().dateTime(); + return mEvent->dtEnd(); } bool CalendarImportEvent::allDay() const @@ -148,18 +148,18 @@ CalendarEvent::Secrecy CalendarImportEvent::secrecy() const QString CalendarImportEvent::organizer() const { - if (!mEvent || !mEvent->organizer()) + if (!mEvent) return QString(); - return mEvent->organizer()->fullName(); + return mEvent->organizer().fullName(); } QString CalendarImportEvent::organizerEmail() const { - if (!mEvent || !mEvent->organizer()) + if (!mEvent) return QString(); - return mEvent->organizer()->email(); + return mEvent->organizer().email(); } void CalendarImportEvent::setColor(const QString &color) diff --git a/src/calendarimportevent.h b/src/calendarimportevent.h index 3f1311e..f858393 100644 --- a/src/calendarimportevent.h +++ b/src/calendarimportevent.h @@ -1,6 +1,6 @@ /* - * Copyright (C) 2015 Jolla Ltd. - * Contact: Petri M. Gerdt + * Copyright (C) 2015 - 2019 Jolla Ltd. + * Copyright (C) 2020 Open Mobile Platform LLC. * * You may use this file under the terms of the BSD license as follows: * @@ -35,8 +35,8 @@ #include -// kCalCore -#include +// KCalendarCore +#include #include "calendarevent.h" @@ -62,7 +62,7 @@ class CalendarImportEvent : public QObject Q_PROPERTY(bool rsvp READ rsvp CONSTANT) public: - CalendarImportEvent(KCalCore::Event::Ptr event); + CalendarImportEvent(KCalendarCore::Event::Ptr event); QString displayLabel() const; QString description() const; @@ -94,7 +94,7 @@ public slots: void colorChanged(); private: - KCalCore::Event::Ptr mEvent; + KCalendarCore::Event::Ptr mEvent; QString mColor; }; #endif // CALENDARIMPORTEVENT_H diff --git a/src/calendarimportmodel.cpp b/src/calendarimportmodel.cpp index 9ae0e60..bee22c4 100644 --- a/src/calendarimportmodel.cpp +++ b/src/calendarimportmodel.cpp @@ -1,6 +1,6 @@ /* - * Copyright (C) 2015 Jolla Ltd. - * Contact: Petri M. Gerdt + * Copyright (C) 2015 - 2019 Jolla Ltd. + * Copyright (C) 2020 Open Mobile Platform LLC. * * You may use this file under the terms of the BSD license as follows: * @@ -42,8 +42,8 @@ #include #include -// kcalcore -#include +// kcalendarcore +#include CalendarImportModel::CalendarImportModel(QObject *parent) : QAbstractListModel(parent) @@ -111,7 +111,7 @@ QVariant CalendarImportModel::data(const QModelIndex &index, int role) const if (!index.isValid() || index.row() >= mEventList.count()) return QVariant(); - KCalCore::Event::Ptr event = mEventList.at(index.row()); + KCalendarCore::Event::Ptr event = mEventList.at(index.row()); switch(role) { case DisplayLabelRole: @@ -119,9 +119,9 @@ QVariant CalendarImportModel::data(const QModelIndex &index, int role) const case DescriptionRole: return event->description(); case StartTimeRole: - return event->dtStart().dateTime(); + return event->dtStart(); case EndTimeRole: - return event->dtEnd().dateTime(); + return event->dtEnd(); case AllDayRole: return event->allDay(); case LocationRole: @@ -135,7 +135,7 @@ QVariant CalendarImportModel::data(const QModelIndex &index, int role) const bool CalendarImportModel::importToNotebook(const QString ¬ebookUid) { - mKCal::ExtendedCalendar::Ptr calendar(new mKCal::ExtendedCalendar(KDateTime::Spec::LocalZone())); + mKCal::ExtendedCalendar::Ptr calendar(new mKCal::ExtendedCalendar(QTimeZone::systemTimeZone())); mKCal::ExtendedStorage::Ptr storage = calendar->defaultStorage(calendar); if (!storage->open()) { qWarning() << "Unable to open calendar DB"; @@ -177,8 +177,8 @@ QHash CalendarImportModel::roleNames() const return roleNames; } -static bool incidenceLessThan(const KCalCore::Incidence::Ptr e1, - const KCalCore::Incidence::Ptr e2) +static bool incidenceLessThan(const KCalendarCore::Incidence::Ptr e1, + const KCalendarCore::Incidence::Ptr e2) { if (e1->dtStart() == e2->dtStart()) { int cmp = QString::compare(e1->summary(), @@ -211,17 +211,17 @@ bool CalendarImportModel::importToMemory(const QString &fileName, const QByteArr mEventList.clear(); beginResetModel(); - KCalCore::MemoryCalendar::Ptr cal(new KCalCore::MemoryCalendar(KDateTime::Spec::LocalZone())); + KCalendarCore::MemoryCalendar::Ptr cal(new KCalendarCore::MemoryCalendar(QTimeZone::systemTimeZone())); if (!fileName.isEmpty()) { CalendarUtils::importFromFile(fileName, cal); } else { CalendarUtils::importFromIcsRawData(icsData, cal); } - KCalCore::Incidence::List incidenceList = cal->incidences(); + KCalendarCore::Incidence::List incidenceList = cal->incidences(); for (int i = 0; i < incidenceList.size(); i++) { - KCalCore::Incidence::Ptr incidence = incidenceList.at(i); - if (incidence->type() == KCalCore::IncidenceBase::TypeEvent) - mEventList.append(incidence.staticCast()); + KCalendarCore::Incidence::Ptr incidence = incidenceList.at(i); + if (incidence->type() == KCalendarCore::IncidenceBase::TypeEvent) + mEventList.append(incidence.staticCast()); } if (!mEventList.isEmpty()) qSort(mEventList.begin(), mEventList.end(), incidenceLessThan); diff --git a/src/calendarimportmodel.h b/src/calendarimportmodel.h index abd2a5b..6ca0e9f 100644 --- a/src/calendarimportmodel.h +++ b/src/calendarimportmodel.h @@ -1,6 +1,6 @@ /* - * Copyright (C) 2015 Jolla Ltd. - * Contact: Petri M. Gerdt + * Copyright (C) 2015 - 2019 Jolla Ltd. + * Copyright (C) 2020 Open Mobile Platform LLC. * * You may use this file under the terms of the BSD license as follows: * @@ -35,8 +35,8 @@ #include -// kCalCore -#include +// kcalendarcore +#include class CalendarImportModel : public QAbstractListModel { @@ -90,7 +90,7 @@ public slots: QString mFileName; QByteArray mIcsRawData; - KCalCore::Event::List mEventList; + KCalendarCore::Event::List mEventList; }; #endif // CALENDARIMPORT_H diff --git a/src/calendarinvitationquery.cpp b/src/calendarinvitationquery.cpp index 4252130..f779ed1 100644 --- a/src/calendarinvitationquery.cpp +++ b/src/calendarinvitationquery.cpp @@ -1,6 +1,6 @@ /* * Copyright (C) 2017 Jolla Ltd. - * Contact: Chris Adams + * Copyright (C) 2020 Open Mobile Platform LLC. * * You may use this file under the terms of the BSD license as follows: * @@ -140,13 +140,14 @@ void CalendarInvitationQuery::queryResult(CalendarData::Event event) needUidEmit = true; } - if (mRid != event.recurrenceId.toString()) { - mRid = event.recurrenceId.toString(); + const QString &recurrenceIdString = CalendarUtils::recurrenceIdToString(event.recurrenceId); + if (mRid != recurrenceIdString) { + mRid = recurrenceIdString; needRidEmit = true; } - if (mStartTime != event.startTime.toString()) { - mStartTime = event.startTime.toString(); + if (mStartTime != event.startTime.toString(Qt::ISODate)) { + mStartTime = event.startTime.toString(Qt::ISODate); needSTEmit = true; } diff --git a/src/calendarinvitationquery.h b/src/calendarinvitationquery.h index 6be4f57..c709584 100644 --- a/src/calendarinvitationquery.h +++ b/src/calendarinvitationquery.h @@ -1,6 +1,6 @@ /* - * Copyright (C) 2017 Jolla Ltd. - * Contact: Chris Adams + * Copyright (C) 2017 - 2019 Jolla Ltd. + * Copyright (C) 2020 Open Mobile Platform LLC. * * You may use this file under the terms of the BSD license as follows: * @@ -39,8 +39,6 @@ #include #include -#include - class CalendarManager; class CalendarInvitationQuery : public QObject, public QQmlParserStatus { diff --git a/src/calendarmanager.cpp b/src/calendarmanager.cpp index 7d42f51..17ce10c 100644 --- a/src/calendarmanager.cpp +++ b/src/calendarmanager.cpp @@ -1,6 +1,6 @@ /* - * Copyright (C) 2014 Jolla Ltd. - * Contact: Petri M. Gerdt + * Copyright (C) 2014 - 2019 Jolla Ltd. + * Copyright (C) 2020 Open Mobile Platform LLC. * * You may use this file under the terms of the BSD license as follows: * @@ -42,14 +42,13 @@ #include "calendarinvitationquery.h" #include "calendarchangeinformation.h" -// kCalCore -#include +// kcalendarcore +#include CalendarManager::CalendarManager() : mLoadPending(false), mResetPending(false) { - qRegisterMetaType("KDateTime"); - qRegisterMetaType >("QList"); + qRegisterMetaType >("QList"); qRegisterMetaType("CalendarEvent::Recur"); qRegisterMetaType >("QHash"); qRegisterMetaType("CalendarData::Event"); @@ -137,7 +136,7 @@ void CalendarManager::setDefaultNotebook(const QString ¬ebookUid) Q_ARG(QString, notebookUid)); } -CalendarEvent* CalendarManager::eventObject(const QString &eventUid, const KDateTime &recurrenceId) +CalendarEvent* CalendarManager::eventObject(const QString &eventUid, const QDateTime &recurrenceId) { QMultiHash::iterator it = mEventObjects.find(eventUid); while (it != mEventObjects.end() && it.key() == eventUid) { @@ -155,9 +154,9 @@ CalendarEvent* CalendarManager::eventObject(const QString &eventUid, const KDate } // TODO: maybe attempt to read event from DB? This situation should not happen. - qWarning() << Q_FUNC_INFO << "No event with uid" << eventUid << recurrenceId.toString() << ", returning empty event"; + qWarning() << Q_FUNC_INFO << "No event with uid" << eventUid << recurrenceId << ", returning empty event"; - return new CalendarEvent(this, QString(), KDateTime()); + return new CalendarEvent(this, QString(), QDateTime()); } void CalendarManager::saveModification(CalendarData::Event eventData, bool updateAttendees, @@ -460,7 +459,7 @@ void CalendarManager::doAgendaAndQueryRefresh() if (eventUid.isEmpty()) continue; - KDateTime recurrenceId = query->recurrenceId(); + QDateTime recurrenceId = query->recurrenceId(); CalendarData::Event event = getEvent(eventUid, recurrenceId); if (event.uniqueId.isEmpty() && !mLoadedQueries.contains(eventUid) @@ -508,7 +507,7 @@ void CalendarManager::occurrenceExceptionFailedSlot(const CalendarData::Event &d const OccurrenceData &item = mPendingOccurrenceExceptions.at(i); if (item.event == data && item.occurrenceTime == occurrence) { if (item.changeObject) { - item.changeObject->setInformation(QString(), KDateTime()); + item.changeObject->setInformation(QString(), QDateTime()); } mPendingOccurrenceExceptions.removeAt(i); break; @@ -517,7 +516,7 @@ void CalendarManager::occurrenceExceptionFailedSlot(const CalendarData::Event &d } void CalendarManager::occurrenceExceptionCreatedSlot(const CalendarData::Event &data, const QDateTime &occurrence, - const KDateTime &newRecurrenceId) + const QDateTime &newRecurrenceId) { for (int i = 0; i < mPendingOccurrenceExceptions.length(); ++i) { const OccurrenceData &item = mPendingOccurrenceExceptions.at(i); @@ -533,11 +532,11 @@ void CalendarManager::occurrenceExceptionCreatedSlot(const CalendarData::Event & } -void CalendarManager::deleteEvent(const QString &uid, const KDateTime &recurrenceId, const QDateTime &time) +void CalendarManager::deleteEvent(const QString &uid, const QDateTime &recurrenceId, const QDateTime &time) { QMetaObject::invokeMethod(mCalendarWorker, "deleteEvent", Qt::QueuedConnection, Q_ARG(QString, uid), - Q_ARG(KDateTime, recurrenceId), + Q_ARG(QDateTime, recurrenceId), Q_ARG(QDateTime, time)); } @@ -562,7 +561,7 @@ QString CalendarManager::convertEventToICalendarSync(const QString &uid, const Q return vEvent; } -CalendarData::Event CalendarManager::getEvent(const QString &uid, const KDateTime &recurrenceId) +CalendarData::Event CalendarManager::getEvent(const QString &uid, const QDateTime &recurrenceId) { QMultiHash::iterator it = mEvents.find(uid); while (it != mEvents.end() && it.key() == uid) { @@ -698,25 +697,25 @@ void CalendarManager::notebooksChangedSlot(const QList & } } -CalendarEventOccurrence* CalendarManager::getNextOccurrence(const QString &uid, const KDateTime &recurrenceId, +CalendarEventOccurrence* CalendarManager::getNextOccurrence(const QString &uid, const QDateTime &recurrenceId, const QDateTime &start) { CalendarData::EventOccurrence eo; QMetaObject::invokeMethod(mCalendarWorker, "getNextOccurrence", Qt::BlockingQueuedConnection, Q_RETURN_ARG(CalendarData::EventOccurrence, eo), Q_ARG(QString, uid), - Q_ARG(KDateTime, recurrenceId), + Q_ARG(QDateTime, recurrenceId), Q_ARG(QDateTime, start)); if (!eo.startTime.isValid()) { - qWarning() << Q_FUNC_INFO << "Unable to find occurrence for event" << uid << recurrenceId.toString(); - return new CalendarEventOccurrence(QString(), KDateTime(), QDateTime(), QDateTime()); + qWarning() << Q_FUNC_INFO << "Unable to find occurrence for event" << uid << recurrenceId; + return new CalendarEventOccurrence(QString(), QDateTime(), QDateTime(), QDateTime()); } return new CalendarEventOccurrence(eo.eventUid, eo.recurrenceId, eo.startTime, eo.endTime); } -QList CalendarManager::getEventAttendees(const QString &uid, const KDateTime &recurrenceId, bool *resultValid) +QList CalendarManager::getEventAttendees(const QString &uid, const QDateTime &recurrenceId, bool *resultValid) { QList attendees; @@ -735,7 +734,7 @@ QList CalendarManager::getEventAttendees(const QString & QMetaObject::invokeMethod(mCalendarWorker, "getEventAttendees", Qt::BlockingQueuedConnection, Q_RETURN_ARG(QList, attendees), Q_ARG(QString, uid), - Q_ARG(KDateTime, recurrenceId)); + Q_ARG(QDateTime, recurrenceId)); } return attendees; diff --git a/src/calendarmanager.h b/src/calendarmanager.h index ba6f719..313a505 100644 --- a/src/calendarmanager.h +++ b/src/calendarmanager.h @@ -38,9 +38,7 @@ #include #include #include - -// KCalCore -#include +#include #include "calendardata.h" #include "calendarevent.h" @@ -62,7 +60,7 @@ class CalendarManager : public QObject static CalendarManager *instance(bool createIfNeeded = true); ~CalendarManager(); - CalendarEvent* eventObject(const QString &eventUid, const KDateTime &recurrenceId); + CalendarEvent* eventObject(const QString &eventUid, const QDateTime &recurrenceId); void saveModification(CalendarData::Event eventData, bool updateAttendees, const QList &required, @@ -72,7 +70,7 @@ class CalendarManager : public QObject bool updateAttendees, const QList &required, const QList &optional); - void deleteEvent(const QString &uid, const KDateTime &recurrenceId, const QDateTime &dateTime); + void deleteEvent(const QString &uid, const QDateTime &recurrenceId, const QDateTime &dateTime); void deleteAll(const QString &uid); void save(); @@ -80,7 +78,7 @@ class CalendarManager : public QObject QString convertEventToICalendarSync(const QString &uid, const QString &prodId); // Event - CalendarData::Event getEvent(const QString& uid, const KDateTime &recurrenceId); + CalendarData::Event getEvent(const QString& uid, const QDateTime &recurrenceId); bool sendResponse(const CalendarData::Event &eventData, CalendarEvent::Response response); // Notebooks @@ -108,10 +106,10 @@ class CalendarManager : public QObject // Caller gets ownership of returned CalendarEventOccurrence object // Does synchronous DB thread access - no DB operations, though, fast when no ongoing DB ops - CalendarEventOccurrence* getNextOccurrence(const QString &uid, const KDateTime &recurrenceId, + CalendarEventOccurrence* getNextOccurrence(const QString &uid, const QDateTime &recurrenceId, const QDateTime &start); // return attendees for given event, synchronous call - QList getEventAttendees(const QString &uid, const KDateTime &recurrenceId, bool *resultValid); + QList getEventAttendees(const QString &uid, const QDateTime &recurrenceId, bool *resultValid); private slots: void storageModifiedSlot(const QString &info); @@ -127,7 +125,7 @@ private slots: void timeout(); void occurrenceExceptionFailedSlot(const CalendarData::Event &data, const QDateTime &occurrence); void occurrenceExceptionCreatedSlot(const CalendarData::Event &data, const QDateTime &occurrence, - const KDateTime &newRecurrenceId); + const QDateTime &newRecurrenceId); void findMatchingEventFinished(const QString &invitationFile, const CalendarData::Event &event); diff --git a/src/calendarutils.cpp b/src/calendarutils.cpp index f5f2db5..b668c95 100644 --- a/src/calendarutils.cpp +++ b/src/calendarutils.cpp @@ -1,8 +1,6 @@ /* * Copyright (c) 2015-2019 Jolla Ltd. - * Copyright (c) 2019 Open Mobile Platform LLC. - * - * Contact: Petri M. Gerdt + * Copyright (c) 2019 - 2020 Open Mobile Platform LLC. * * You may use this file under the terms of the BSD license as follows: * @@ -36,9 +34,9 @@ #include "calendareventquery.h" -// kcalcore -#include -#include +// kcalendarcore +#include +#include //mkcal #include @@ -51,7 +49,7 @@ #include #include -CalendarEvent::Recur CalendarUtils::convertRecurrence(const KCalCore::Event::Ptr &event) +CalendarEvent::Recur CalendarUtils::convertRecurrence(const KCalendarCore::Event::Ptr &event) { if (!event->recurs()) return CalendarEvent::RecurOnce; @@ -62,20 +60,20 @@ CalendarEvent::Recur CalendarUtils::convertRecurrence(const KCalCore::Event::Ptr ushort rt = event->recurrence()->recurrenceType(); int freq = event->recurrence()->frequency(); - if (rt == KCalCore::Recurrence::rDaily && freq == 1) { + if (rt == KCalendarCore::Recurrence::rDaily && freq == 1) { return CalendarEvent::RecurDaily; - } else if (rt == KCalCore::Recurrence::rWeekly && freq == 1) { + } else if (rt == KCalendarCore::Recurrence::rWeekly && freq == 1) { if (event->recurrence()->days().count(true) == 0) { return CalendarEvent::RecurWeekly; } else { return CalendarEvent::RecurWeeklyByDays; } - } else if (rt == KCalCore::Recurrence::rWeekly && freq == 2 && event->recurrence()->days().count(true) == 0) { + } else if (rt == KCalendarCore::Recurrence::rWeekly && freq == 2 && event->recurrence()->days().count(true) == 0) { return CalendarEvent::RecurBiweekly; - } else if (rt == KCalCore::Recurrence::rMonthlyDay && freq == 1) { + } else if (rt == KCalendarCore::Recurrence::rMonthlyDay && freq == 1) { return CalendarEvent::RecurMonthly; - } else if (rt == KCalCore::Recurrence::rMonthlyPos && freq == 1) { - const QList monthPositions = event->recurrence()->monthPositions(); + } else if (rt == KCalendarCore::Recurrence::rMonthlyPos && freq == 1) { + const QList monthPositions = event->recurrence()->monthPositions(); if (monthPositions.length() == 1 && monthPositions.first().day() == event->dtStart().date().dayOfWeek()) { if (monthPositions.first().pos() > 0) { @@ -84,14 +82,14 @@ CalendarEvent::Recur CalendarUtils::convertRecurrence(const KCalCore::Event::Ptr return CalendarEvent::RecurMonthlyByLastDayOfWeek; } } - } else if (rt == KCalCore::Recurrence::rYearlyMonth && freq == 1) { + } else if (rt == KCalendarCore::Recurrence::rYearlyMonth && freq == 1) { return CalendarEvent::RecurYearly; } return CalendarEvent::RecurCustom; } -CalendarEvent::Days CalendarUtils::convertDayPositions(const KCalCore::Event::Ptr &event) +CalendarEvent::Days CalendarUtils::convertDayPositions(const KCalendarCore::Event::Ptr &event) { if (!event->recurs()) return CalendarEvent::NoDays; @@ -99,7 +97,7 @@ CalendarEvent::Days CalendarUtils::convertDayPositions(const KCalCore::Event::Pt if (event->recurrence()->rRules().count() != 1) return CalendarEvent::NoDays; - if (event->recurrence()->recurrenceType() != KCalCore::Recurrence::rWeekly + if (event->recurrence()->recurrenceType() != KCalendarCore::Recurrence::rWeekly || event->recurrence()->frequency() != 1) return CalendarEvent::NoDays; @@ -111,42 +109,42 @@ CalendarEvent::Days CalendarUtils::convertDayPositions(const KCalCore::Event::Pt CalendarEvent::Saturday, CalendarEvent::Sunday}; - const QList monthPositions = event->recurrence()->monthPositions(); + const QList monthPositions = event->recurrence()->monthPositions(); CalendarEvent::Days days = CalendarEvent::NoDays; - for (QList::ConstIterator it = monthPositions.constBegin(); + for (QList::ConstIterator it = monthPositions.constBegin(); it != monthPositions.constEnd(); ++it) { days |= week[it->day() - 1]; } return days; } -CalendarEvent::Secrecy CalendarUtils::convertSecrecy(const KCalCore::Event::Ptr &event) +CalendarEvent::Secrecy CalendarUtils::convertSecrecy(const KCalendarCore::Event::Ptr &event) { - KCalCore::Incidence::Secrecy s = event->secrecy(); + KCalendarCore::Incidence::Secrecy s = event->secrecy(); switch (s) { - case KCalCore::Incidence::SecrecyPrivate: + case KCalendarCore::Incidence::SecrecyPrivate: return CalendarEvent::SecrecyPrivate; - case KCalCore::Incidence::SecrecyConfidential: + case KCalendarCore::Incidence::SecrecyConfidential: return CalendarEvent::SecrecyConfidential; - case KCalCore::Incidence::SecrecyPublic: + case KCalendarCore::Incidence::SecrecyPublic: default: return CalendarEvent::SecrecyPublic; } } -int CalendarUtils::getReminder(const KCalCore::Event::Ptr &event) +int CalendarUtils::getReminder(const KCalendarCore::Event::Ptr &event) { - KCalCore::Alarm::List alarms = event->alarms(); + KCalendarCore::Alarm::List alarms = event->alarms(); - KCalCore::Alarm::Ptr alarm; + KCalendarCore::Alarm::Ptr alarm; int seconds = -1; for (int ii = 0; ii < alarms.count(); ++ii) { - if (alarms.at(ii)->type() == KCalCore::Alarm::Procedure) + if (alarms.at(ii)->type() == KCalendarCore::Alarm::Procedure) continue; alarm = alarms.at(ii); if (alarm) { - KCalCore::Duration d = alarm->startOffset(); + KCalendarCore::Duration d = alarm->startOffset(); seconds = d.asSeconds() * -1; // backend stores as "offset in seconds to dtStart", we return "seconds before" if (seconds >= 0) { break; @@ -158,35 +156,34 @@ int CalendarUtils::getReminder(const KCalCore::Event::Ptr &event) return seconds; } -QList CalendarUtils::getEventAttendees(const KCalCore::Event::Ptr &event) +QList CalendarUtils::getEventAttendees(const KCalendarCore::Event::Ptr &event) { QList result; - KCalCore::Person::Ptr calOrganizer = event->organizer(); + const KCalendarCore::Person calOrganizer = event->organizer(); CalendarData::Attendee organizer; - - if (!calOrganizer.isNull() && !calOrganizer->isEmpty()) { + if (!calOrganizer.email().isEmpty()) { organizer.isOrganizer = true; - organizer.name = calOrganizer->name(); - organizer.email = calOrganizer->email(); - organizer.participationRole = KCalCore::Attendee::Chair; + organizer.name = calOrganizer.name(); + organizer.email = calOrganizer.email(); + organizer.participationRole = KCalendarCore::Attendee::Chair; result.append(organizer); } - KCalCore::Attendee::List attendees = event->attendees(); + const KCalendarCore::Attendee::List attendees = event->attendees(); CalendarData::Attendee attendee; attendee.isOrganizer = false; - foreach (KCalCore::Attendee::Ptr calAttendee, attendees) { - attendee.name = calAttendee->name(); - attendee.email = calAttendee->email(); + for (const KCalendarCore::Attendee &calAttendee : attendees) { + attendee.name = calAttendee.name(); + attendee.email = calAttendee.email(); if (attendee.name == organizer.name && attendee.email == organizer.email) { // avoid duplicate info continue; } - attendee.status = calAttendee->status(); - attendee.participationRole = calAttendee->role(); + attendee.status = calAttendee.status(); + attendee.participationRole = calAttendee.role(); result.append(attendee); } @@ -199,13 +196,13 @@ QList CalendarUtils::convertAttendeeList(const QList CalendarUtils::convertAttendeeList(const QList CalendarUtils::convertAttendeeList(const QListdtStart().toLocalZone().dateTime(); - QDateTime dtEnd = event->dtEnd().toLocalZone().dateTime(); + QDateTime dtStart = event->dtStart().toTimeZone(systemTimeZone); + QDateTime dtEnd = event->dtEnd().toTimeZone(systemTimeZone); if (!start.isNull() && event->recurs()) { - KDateTime startTime = KDateTime(start, KDateTime::Spec(KDateTime::LocalZone)); - KCalCore::Recurrence *recurrence = event->recurrence(); + const QDateTime startTime = start.toTimeZone(systemTimeZone); + KCalendarCore::Recurrence *recurrence = event->recurrence(); if (recurrence->recursAt(startTime)) { - dtStart = startTime.toLocalZone().dateTime(); - dtEnd = KCalCore::Duration(event->dtStart(), event->dtEnd()).end(startTime).toLocalZone().dateTime(); + dtStart = startTime; + dtEnd = KCalendarCore::Duration(event->dtStart(), event->dtEnd()).end(startTime).toTimeZone(systemTimeZone); } else { - KDateTime match = recurrence->getNextDateTime(startTime); + QDateTime match = recurrence->getNextDateTime(startTime); if (match.isNull()) match = recurrence->getPreviousDateTime(startTime); if (!match.isNull()) { - dtStart = match.toLocalZone().dateTime(); - dtEnd = KCalCore::Duration(event->dtStart(), event->dtEnd()).end(match).toLocalZone().dateTime(); + dtStart = match.toTimeZone(systemTimeZone); + dtEnd = KCalendarCore::Duration(event->dtStart(), event->dtEnd()).end(match).toTimeZone(systemTimeZone); } } } @@ -271,7 +270,7 @@ CalendarData::EventOccurrence CalendarUtils::getNextOccurrence(const KCalCore::E } bool CalendarUtils::importFromFile(const QString &fileName, - KCalCore::Calendar::Ptr calendar) + KCalendarCore::Calendar::Ptr calendar) { QString filePath; QUrl url(fileName); @@ -294,10 +293,10 @@ bool CalendarUtils::importFromFile(const QString &fileName, bool ok = false; if (filePath.endsWith(".vcs")) { - KCalCore::VCalFormat vcalFormat; + KCalendarCore::VCalFormat vcalFormat; ok = vcalFormat.fromRawString(calendar, fileContent); } else if (filePath.endsWith(".ics")) { - KCalCore::ICalFormat icalFormat; + KCalendarCore::ICalFormat icalFormat; ok = icalFormat.fromRawString(calendar, fileContent); } if (!ok) @@ -307,10 +306,10 @@ bool CalendarUtils::importFromFile(const QString &fileName, } bool CalendarUtils::importFromIcsRawData(const QByteArray &icsData, - KCalCore::Calendar::Ptr calendar) + KCalendarCore::Calendar::Ptr calendar) { bool ok = false; - KCalCore::ICalFormat icalFormat; + KCalendarCore::ICalFormat icalFormat; ok = icalFormat.fromRawString(calendar, icsData); if (!ok) qWarning() << "Failed to import from raw data"; @@ -318,33 +317,33 @@ bool CalendarUtils::importFromIcsRawData(const QByteArray &icsData, return ok; } -CalendarEvent::Response CalendarUtils::convertPartStat(KCalCore::Attendee::PartStat status) +CalendarEvent::Response CalendarUtils::convertPartStat(KCalendarCore::Attendee::PartStat status) { switch (status) { - case KCalCore::Attendee::Accepted: + case KCalendarCore::Attendee::Accepted: return CalendarEvent::ResponseAccept; - case KCalCore::Attendee::Declined: + case KCalendarCore::Attendee::Declined: return CalendarEvent::ResponseDecline; - case KCalCore::Attendee::Tentative: + case KCalendarCore::Attendee::Tentative: return CalendarEvent::ResponseTentative; - case KCalCore::Attendee::NeedsAction: - case KCalCore::Attendee::None: + case KCalendarCore::Attendee::NeedsAction: + case KCalendarCore::Attendee::None: default: return CalendarEvent::ResponseUnspecified; } } -KCalCore::Attendee::PartStat CalendarUtils::convertResponse(CalendarEvent::Response response) +KCalendarCore::Attendee::PartStat CalendarUtils::convertResponse(CalendarEvent::Response response) { switch (response) { case CalendarEvent::ResponseAccept: - return KCalCore::Attendee::Accepted; + return KCalendarCore::Attendee::Accepted; case CalendarEvent::ResponseTentative: - return KCalCore::Attendee::Tentative; + return KCalendarCore::Attendee::Tentative; case CalendarEvent::ResponseDecline: - return KCalCore::Attendee::Declined; + return KCalendarCore::Attendee::Declined; default: - return KCalCore::Attendee::NeedsAction; + return KCalendarCore::Attendee::NeedsAction; } } @@ -366,3 +365,11 @@ CalendarEvent::Response CalendarUtils::convertResponseType(const QString &respon return CalendarEvent::ResponseUnspecified; } } + +QString CalendarUtils::recurrenceIdToString(const QDateTime &dt) +{ + // Convert to Qt::OffsetFromUTC spec to ensure time zone offset is included in string format, + // to be consistent with previous versions that used KDateTime::toString() to produce the + // same string format for recurrence ids. + return dt.toOffsetFromUtc(dt.offsetFromUtc()).toString(Qt::ISODate); +} diff --git a/src/calendarutils.h b/src/calendarutils.h index f1d2697..b1c6b0f 100644 --- a/src/calendarutils.h +++ b/src/calendarutils.h @@ -1,6 +1,6 @@ /* * Copyright (c) 2015-2019 Jolla Ltd. - * Copyright (c) 2019 Open Mobile Platform LLC. + * Copyright (c) 2019 - 2020 Open Mobile Platform LLC. * * Contact: Petri M. Gerdt * @@ -38,25 +38,26 @@ #include "calendarevent.h" #include "calendardata.h" -// kCalCore -#include -#include +// KCalendarCore +#include +#include namespace CalendarUtils { -CalendarEvent::Recur convertRecurrence(const KCalCore::Event::Ptr &event); -CalendarEvent::Days convertDayPositions(const KCalCore::Event::Ptr &event); -CalendarEvent::Secrecy convertSecrecy(const KCalCore::Event::Ptr &event); -int getReminder(const KCalCore::Event::Ptr &event); -QList getEventAttendees(const KCalCore::Event::Ptr &event); +CalendarEvent::Recur convertRecurrence(const KCalendarCore::Event::Ptr &event); +CalendarEvent::Days convertDayPositions(const KCalendarCore::Event::Ptr &event); +CalendarEvent::Secrecy convertSecrecy(const KCalendarCore::Event::Ptr &event); +int getReminder(const KCalendarCore::Event::Ptr &event); +QList getEventAttendees(const KCalendarCore::Event::Ptr &event); QList convertAttendeeList(const QList &list); -CalendarData::EventOccurrence getNextOccurrence(const KCalCore::Event::Ptr &event, +CalendarData::EventOccurrence getNextOccurrence(const KCalendarCore::Event::Ptr &event, const QDateTime &start = QDateTime::currentDateTime()); -bool importFromFile(const QString &fileName, KCalCore::Calendar::Ptr calendar); -bool importFromIcsRawData(const QByteArray &icsData, KCalCore::Calendar::Ptr calendar); -CalendarEvent::Response convertPartStat(KCalCore::Attendee::PartStat status); -KCalCore::Attendee::PartStat convertResponse(CalendarEvent::Response response); +bool importFromFile(const QString &fileName, KCalendarCore::Calendar::Ptr calendar); +bool importFromIcsRawData(const QByteArray &icsData, KCalendarCore::Calendar::Ptr calendar); +CalendarEvent::Response convertPartStat(KCalendarCore::Attendee::PartStat status); +KCalendarCore::Attendee::PartStat convertResponse(CalendarEvent::Response response); CalendarEvent::Response convertResponseType(const QString &responseType); +QString recurrenceIdToString(const QDateTime &dt); } // namespace CalendarUtils diff --git a/src/calendarworker.cpp b/src/calendarworker.cpp index 2f12c50..50da76a 100644 --- a/src/calendarworker.cpp +++ b/src/calendarworker.cpp @@ -1,8 +1,6 @@ /* - * Copyright (c) 2014-2019 Jolla Ltd. - * Copyright (c) 2019 Open Mobile Platform LLC. - * - * Contact: Petri M. Gerdt + * Copyright (c) 2014 - 2019 Jolla Ltd. + * Copyright (c) 2019 - 2020 Open Mobile Platform LLC. * * You may use this file under the terms of the BSD license as follows: * @@ -43,14 +41,14 @@ #include #include -// kCalCore -#include -#include -#include -#include -#include -#include -#include +// KCalendarCore +#include +#include +#include +#include +#include +#include +#include #include #include @@ -60,6 +58,22 @@ #include #include +namespace { + void updateAttendee(KCalendarCore::Event::Ptr event, + const KCalendarCore::Attendee &attendee, + const KCalendarCore::Attendee &updated) + { + KCalendarCore::Attendee::List allAttendees = event->attendees(); + for (int i = 0; i < allAttendees.size(); ++i) { + if (allAttendees[i] == attendee) { + allAttendees.replace(i, updated); + break; + } + } + event->setAttendees(allAttendees); + } +} + CalendarWorker::CalendarWorker() : QObject(0), mAccountManager(0) { @@ -104,9 +118,9 @@ void CalendarWorker::storageFinished(mKCal::ExtendedStorage *storage, bool error Q_UNUSED(info) } -void CalendarWorker::deleteEvent(const QString &uid, const KDateTime &recurrenceId, const QDateTime &dateTime) +void CalendarWorker::deleteEvent(const QString &uid, const QDateTime &recurrenceId, const QDateTime &dateTime) { - KCalCore::Event::Ptr event = mCalendar->event(uid, recurrenceId); + KCalendarCore::Event::Ptr event = mCalendar->event(uid, recurrenceId); if (!event) return; @@ -115,17 +129,17 @@ void CalendarWorker::deleteEvent(const QString &uid, const KDateTime &recurrence // We're deleting an occurrence from a recurring event. // No incidence is deleted from the database in that case, // only the base incidence is modified by adding an exDate. - event->recurrence()->addExDateTime(KDateTime(dateTime, KDateTime::Spec(KDateTime::LocalZone))); + event->recurrence()->addExDateTime(dateTime); event->setRevision(event->revision() + 1); } else { mCalendar->deleteEvent(event); - mDeletedEvents.append(QPair(uid, recurrenceId)); + mDeletedEvents.append(QPair(uid, recurrenceId)); } } void CalendarWorker::deleteAll(const QString &uid) { - KCalCore::Event::Ptr event = mCalendar->event(uid); + KCalendarCore::Event::Ptr event = mCalendar->event(uid); if (!event) { qWarning() << "Failed to delete event, not found" << uid; return; @@ -133,12 +147,12 @@ void CalendarWorker::deleteAll(const QString &uid) mCalendar->deleteEventInstances(event); mCalendar->deleteEvent(event); - mDeletedEvents.append(QPair(uid, KDateTime())); + mDeletedEvents.append(QPair(uid, QDateTime())); } bool CalendarWorker::sendResponse(const CalendarData::Event &eventData, const CalendarEvent::Response response) { - KCalCore::Event::Ptr event = mCalendar->event(eventData.uniqueId, eventData.recurrenceId); + KCalendarCore::Event::Ptr event = mCalendar->event(eventData.uniqueId, eventData.recurrenceId); if (!event) { qWarning() << "Failed to send response, event not found. UID = " << eventData.uniqueId; return false; @@ -148,21 +162,24 @@ bool CalendarWorker::sendResponse(const CalendarData::Event &eventData, const Ca : QString(); // TODO: should we save this change in DB? - KCalCore::Attendee::Ptr attender = event->attendeeByMail(ownerEmail); - attender->setStatus(CalendarUtils::convertResponse(response)); + const KCalendarCore::Attendee origAttendee = event->attendeeByMail(ownerEmail); + KCalendarCore::Attendee updated = origAttendee; + updated.setStatus(CalendarUtils::convertResponse(response)); + updateAttendee(event, origAttendee, updated); + return mKCal::ServiceHandler::instance().sendResponse(event, eventData.description, mCalendar, mStorage); } QString CalendarWorker::convertEventToICalendar(const QString &uid, const QString &prodId) const { // NOTE: not fetching eventInstances() with different recurrenceId - KCalCore::Event::Ptr event = mCalendar->event(uid); + KCalendarCore::Event::Ptr event = mCalendar->event(uid); if (event.isNull()) { qWarning() << "No event with uid " << uid << ", unable to create iCalendar"; return QString(); } - KCalCore::ICalFormat fmt; + KCalendarCore::ICalFormat fmt; fmt.setApplication(fmt.application(), prodId.isEmpty() ? QLatin1String("-//sailfishos.org/Sailfish//NONSGML v1.0//EN") : prodId); return fmt.toICalString(event); @@ -174,12 +191,12 @@ void CalendarWorker::save() // FIXME: should send response update if deleting an even we have responded to. // FIXME: should send cancel only if we own the event if (!mDeletedEvents.isEmpty()) { - for (const QPair &pair: mDeletedEvents) { - KCalCore::Event::Ptr event = mCalendar->deletedEvent(pair.first, pair.second); + for (const QPair &pair: mDeletedEvents) { + KCalendarCore::Event::Ptr event = mCalendar->deletedEvent(pair.first, pair.second); if (!needSendCancellation(event)) { continue; } - event->setStatus(KCalCore::Incidence::StatusCanceled); + event->setStatus(KCalendarCore::Incidence::StatusCanceled); mKCal::ServiceHandler::instance().sendUpdate(event, QString(), mCalendar, mStorage); } mDeletedEvents.clear(); @@ -192,14 +209,16 @@ void CalendarWorker::saveEvent(const CalendarData::Event &eventData, bool update { QString notebookUid = eventData.calendarUid; - if (!notebookUid.isEmpty() && !mStorage->isValidNotebook(notebookUid)) + if (!notebookUid.isEmpty() && !mStorage->isValidNotebook(notebookUid)) { + qWarning() << "Invalid notebook uid:" << notebookUid; return; + } - KCalCore::Event::Ptr event; + KCalendarCore::Event::Ptr event; bool createNew = eventData.uniqueId.isEmpty(); if (createNew) { - event = KCalCore::Event::Ptr(new KCalCore::Event); + event = KCalendarCore::Event::Ptr(new KCalendarCore::Event); // For exchange it is better to use upper case UIDs, because for some reason when // UID is generated out of Global object id of the email message we are getting a lowercase @@ -219,8 +238,8 @@ void CalendarWorker::saveEvent(const CalendarData::Event &eventData, bool update if (!notebookUid.isEmpty() && mCalendar->notebook(event) != notebookUid) { // mkcal does funny things when moving event between notebooks, work around by changing uid - KCalCore::Event::Ptr newEvent = KCalCore::Event::Ptr(event->clone()); - newEvent->setUid(KCalCore::CalFormat::createUniqueId().toUpper()); + KCalendarCore::Event::Ptr newEvent = KCalendarCore::Event::Ptr(event->clone()); + newEvent->setUid(KCalendarCore::CalFormat::createUniqueId().toUpper()); emit eventNotebookChanged(event->uid(), newEvent->uid(), notebookUid); mCalendar->deleteEvent(event); mCalendar->addEvent(newEvent, notebookUid); @@ -251,13 +270,12 @@ void CalendarWorker::saveEvent(const CalendarData::Event &eventData, bool update save(); } -void CalendarWorker::setEventData(KCalCore::Event::Ptr &event, const CalendarData::Event &eventData) +void CalendarWorker::setEventData(KCalendarCore::Event::Ptr &event, const CalendarData::Event &eventData) { event->setDescription(eventData.description); event->setSummary(eventData.displayLabel); event->setDtStart(eventData.startTime); event->setDtEnd(eventData.endTime); - // setDtStart() overwrites allDay status based on KDateTime::isDateOnly(), avoid by setting that later event->setAllDay(eventData.allDay); event->setLocation(eventData.location); setReminder(event, eventData.reminder); @@ -285,7 +303,7 @@ void CalendarWorker::replaceOccurrence(const CalendarData::Event &eventData, con return; } - KCalCore::Event::Ptr event = mCalendar->event(eventData.uniqueId, eventData.recurrenceId); + KCalendarCore::Event::Ptr event = mCalendar->event(eventData.uniqueId, eventData.recurrenceId); if (!event) { qWarning("Event to create occurrence replacement for not found"); emit occurrenceExceptionFailed(eventData, startTime); @@ -294,14 +312,14 @@ void CalendarWorker::replaceOccurrence(const CalendarData::Event &eventData, con // Note: for all day events, to guarantee that exception set in a given time // zone is also an exception when travelling to another time, we use the - // ClockTime spec. - KDateTime::SpecType spec(event->allDay() ? KDateTime::ClockTime : KDateTime::LocalZone); - KDateTime occurrenceTime(startTime, spec); - - KCalCore::Incidence::Ptr replacementIncidence = mCalendar->dissociateSingleOccurrence(event, - occurrenceTime, - KDateTime::LocalZone); - KCalCore::Event::Ptr replacement = replacementIncidence.staticCast(); + // LocalTime spec. + QDateTime occurrence = event->allDay() + ? QDateTime(startTime.date(), startTime.time(), Qt::LocalTime) + : startTime; + + KCalendarCore::Incidence::Ptr replacementIncidence = mCalendar->dissociateSingleOccurrence( + event, occurrence); + KCalendarCore::Event::Ptr replacement = replacementIncidence.staticCast(); if (!replacement) { qWarning("Didn't find event occurrence to replace"); emit occurrenceExceptionFailed(eventData, startTime); @@ -315,20 +333,21 @@ void CalendarWorker::replaceOccurrence(const CalendarData::Event &eventData, con } mCalendar->addEvent(replacement, notebookUid); + emit occurrenceExceptionCreated(eventData, startTime, replacement->recurrenceId()); save(); } void CalendarWorker::init() { - mCalendar = mKCal::ExtendedCalendar::Ptr(new mKCal::ExtendedCalendar(KDateTime::Spec::LocalZone())); + mCalendar = mKCal::ExtendedCalendar::Ptr(new mKCal::ExtendedCalendar(QTimeZone::systemTimeZone())); mStorage = mCalendar->defaultStorage(mCalendar); mStorage->open(); mStorage->registerObserver(this); loadNotebooks(); } -bool CalendarWorker::setRecurrence(KCalCore::Event::Ptr &event, CalendarEvent::Recur recur, CalendarEvent::Days days) +bool CalendarWorker::setRecurrence(KCalendarCore::Event::Ptr &event, CalendarEvent::Recur recur, CalendarEvent::Days days) { if (!event) return false; @@ -394,7 +413,7 @@ bool CalendarWorker::setRecurrence(KCalCore::Event::Ptr &event, CalendarEvent::R return false; } -bool CalendarWorker::setReminder(KCalCore::Event::Ptr &event, int seconds) +bool CalendarWorker::setReminder(KCalendarCore::Event::Ptr &event, int seconds) { if (!event) return false; @@ -402,9 +421,9 @@ bool CalendarWorker::setReminder(KCalCore::Event::Ptr &event, int seconds) if (CalendarUtils::getReminder(event) == seconds) return false; - KCalCore::Alarm::List alarms = event->alarms(); + KCalendarCore::Alarm::List alarms = event->alarms(); for (int ii = 0; ii < alarms.count(); ++ii) { - if (alarms.at(ii)->type() == KCalCore::Alarm::Procedure) + if (alarms.at(ii)->type() == KCalendarCore::Alarm::Procedure) continue; event->removeAlarm(alarms.at(ii)); } @@ -412,32 +431,32 @@ bool CalendarWorker::setReminder(KCalCore::Event::Ptr &event, int seconds) // negative reminder seconds means "no reminder", so only // deal with positive (or zero = at time of event) reminders. if (seconds >= 0) { - KCalCore::Alarm::Ptr alarm = event->newAlarm(); + KCalendarCore::Alarm::Ptr alarm = event->newAlarm(); alarm->setEnabled(true); // backend stores as "offset to dtStart", i.e negative if reminder before event. alarm->setStartOffset(-1 * seconds); - alarm->setType(KCalCore::Alarm::Display); + alarm->setType(KCalendarCore::Alarm::Display); } return true; } -bool CalendarWorker::needSendCancellation(KCalCore::Event::Ptr &event) const +bool CalendarWorker::needSendCancellation(KCalendarCore::Event::Ptr &event) const { if (!event) { qWarning() << Q_FUNC_INFO << "event is NULL"; return false; } - KCalCore::Attendee::List attendees = event->attendees(); + KCalendarCore::Attendee::List attendees = event->attendees(); if (attendees.size() == 0) { return false; } - KCalCore::Person::Ptr calOrganizer = event->organizer(); - if (calOrganizer.isNull() || calOrganizer->isEmpty()) { + KCalendarCore::Person calOrganizer = event->organizer(); + if (calOrganizer.isEmpty()) { return false; } // we shouldn't send a response if we are not an organizer - if (calOrganizer->email() != getNotebookAddress(event)) { + if (calOrganizer.email() != getNotebookAddress(event)) { return false; } return true; @@ -445,7 +464,7 @@ bool CalendarWorker::needSendCancellation(KCalCore::Event::Ptr &event) const // use explicit notebook uid so we don't need to assume the events involved being added there. // the related notebook is just needed to associate updates to some plugin/account -void CalendarWorker::updateEventAttendees(KCalCore::Event::Ptr event, bool newEvent, +void CalendarWorker::updateEventAttendees(KCalendarCore::Event::Ptr event, bool newEvent, const QList &required, const QList &optional, const QString ¬ebookUid) @@ -464,82 +483,96 @@ void CalendarWorker::updateEventAttendees(KCalCore::Event::Ptr event, bool newEv // set the notebook email address as the organizer email address // if no explicit organizer is set (i.e. assume we are the organizer). const QString notebookOwnerEmail = getNotebookAddress(notebookUid); - if (event->organizer()->email().isEmpty() && !notebookOwnerEmail.isEmpty()) { - event->organizer()->setEmail(notebookOwnerEmail); + if (event->organizer().email().isEmpty() && !notebookOwnerEmail.isEmpty()) { + KCalendarCore::Person organizer = event->organizer(); + organizer.setEmail(notebookOwnerEmail); + event->setOrganizer(organizer); } if (!newEvent) { // if existing attendees are removed, those should get a cancel update - KCalCore::Event::Ptr cancelEvent = KCalCore::Event::Ptr(event->clone()); + KCalendarCore::Event::Ptr cancelEvent = KCalendarCore::Event::Ptr(event->clone()); + KCalendarCore::Attendee::List cancelAttendees = cancelEvent->attendees(); + KCalendarCore::Attendee::List attendees = event->attendees(); // first remove everyone still listed as included for (int i = 0; i < required.length(); ++i) { - KCalCore::Attendee::Ptr toRemove = cancelEvent->attendeeByMail(required.at(i).email); - if (toRemove) { - cancelEvent->deleteAttendee(toRemove); + const KCalendarCore::Attendee toRemove = cancelEvent->attendeeByMail(required.at(i).email); + if (!toRemove.email().isEmpty()) { + cancelAttendees.removeOne(toRemove); } } for (int i = 0; i < optional.length(); ++i) { - KCalCore::Attendee::Ptr toRemove = cancelEvent->attendeeByMail(optional.at(i).email); - if (toRemove) { - cancelEvent->deleteAttendee(toRemove); + const KCalendarCore::Attendee toRemove = cancelEvent->attendeeByMail(optional.at(i).email); + if (!toRemove.email().isEmpty()) { + cancelAttendees.removeOne(toRemove); } } - const QString organizer = cancelEvent->organizer()->email(); + const QString organizer = cancelEvent->organizer().email(); if (!organizer.isEmpty()) { - KCalCore::Attendee::Ptr toRemove = cancelEvent->attendeeByMail(organizer); - if (toRemove) { - cancelEvent->deleteAttendee(toRemove); + const KCalendarCore::Attendee toRemove = cancelEvent->attendeeByMail(organizer); + if (!toRemove.email().isEmpty()) { + cancelAttendees.removeOne(toRemove); } } - KCalCore::Attendee::List remainingAttendees = cancelEvent->attendees(); - - for (int i = remainingAttendees.length() - 1; i >= 0; --i) { - KCalCore::Attendee::Ptr attendee = remainingAttendees.at(i); + bool attendeesChanged = false; + for (int i = cancelAttendees.length() - 1; i >= 0; --i) { + const KCalendarCore::Attendee attendee = cancelAttendees.at(i); // if there are non-participants getting update as FYI, or chair for any reason, // avoid sending them the cancel - if (attendee->role() != KCalCore::Attendee::ReqParticipant - && attendee->role() != KCalCore::Attendee::OptParticipant) { - cancelEvent->deleteAttendee(attendee); + if (attendee.role() != KCalendarCore::Attendee::ReqParticipant + && attendee.role() != KCalendarCore::Attendee::OptParticipant) { + cancelAttendees.removeAt(i); continue; } // this one really gets cancel so remove from update event side - KCalCore::Attendee::Ptr toRemove = event->attendeeByMail(attendee->email()); - if (toRemove) { - event->deleteAttendee(toRemove); + KCalendarCore::Attendee toRemove = event->attendeeByMail(attendee.email()); + if (!toRemove.email().isEmpty()) { + attendeesChanged = true; + attendees.removeOne(toRemove); } } - if (cancelEvent->attendees().length() > 0) { - cancelEvent->setStatus(KCalCore::Incidence::StatusCanceled); + + if (attendeesChanged) { + event->setAttendees(attendees); + } + + if (cancelAttendees.size()) { + cancelEvent->setAttendees(cancelAttendees); + cancelEvent->setStatus(KCalendarCore::Incidence::StatusCanceled); mKCal::ServiceHandler::instance().sendUpdate(cancelEvent, QString(), mCalendar, mStorage, notebook); } } if (required.length() > 0 || optional.length() > 0) { for (int i = 0; i < required.length(); ++i) { - KCalCore::Attendee::Ptr existing = event->attendeeByMail(required.at(i).email); - if (existing) { - existing->setRole(KCalCore::Attendee::ReqParticipant); + const KCalendarCore::Attendee existing = event->attendeeByMail(required.at(i).email); + if (!existing.email().isEmpty()) { + KCalendarCore::Attendee updated = existing; + updated.setRole(KCalendarCore::Attendee::ReqParticipant); + updateAttendee(event, existing, updated); } else { - auto attendee = new KCalCore::Attendee(required.at(i).name, required.at(i).email, true /* rsvp */, - KCalCore::Attendee::NeedsAction, - KCalCore::Attendee::ReqParticipant); - event->addAttendee(KCalCore::Attendee::Ptr(attendee)); + event->addAttendee(KCalendarCore::Attendee( + required.at(i).name, required.at(i).email, true /* rsvp */, + KCalendarCore::Attendee::NeedsAction, + KCalendarCore::Attendee::ReqParticipant)); } } for (int i = 0; i < optional.length(); ++i) { - KCalCore::Attendee::Ptr existing = event->attendeeByMail(optional.at(i).email); - if (existing) { - existing->setRole(KCalCore::Attendee::OptParticipant); + const KCalendarCore::Attendee existing = event->attendeeByMail(optional.at(i).email); + if (!existing.email().isEmpty()) { + KCalendarCore::Attendee updated = existing; + updated.setRole(KCalendarCore::Attendee::OptParticipant); + updateAttendee(event, existing, updated); } else { - auto attendee = new KCalCore::Attendee(optional.at(i).name, optional.at(i).email, true, - KCalCore::Attendee::NeedsAction, - KCalCore::Attendee::OptParticipant); - event->addAttendee(KCalCore::Attendee::Ptr(attendee)); + event->addAttendee(KCalendarCore::Attendee( + optional.at(i).name, optional.at(i).email, true, + KCalendarCore::Attendee::NeedsAction, + KCalendarCore::Attendee::OptParticipant)); } } @@ -561,7 +594,7 @@ QString CalendarWorker::getNotebookAddress(const QString ¬ebookUid) const : QString(); } -QString CalendarWorker::getNotebookAddress(const KCalCore::Event::Ptr &event) const +QString CalendarWorker::getNotebookAddress(const KCalendarCore::Event::Ptr &event) const { const QString ¬ebookUid = mCalendar->notebook(event); return mNotebooks.contains(notebookUid) ? mNotebooks.value(notebookUid).emailAddress @@ -669,7 +702,7 @@ CalendarWorker::eventOccurrences(const QList &ranges) const // mkcal fails to consider all day event end time inclusivity on this, add -1 days to start date mKCal::ExtendedCalendar::ExpandedIncidenceList newEvents = mCalendar->rawExpandedEvents(range.first.addDays(-1), range.second, - false, false, KDateTime::Spec(KDateTime::LocalZone)); + false, false, QTimeZone::systemTimeZone()); events = events << newEvents; } @@ -695,7 +728,7 @@ CalendarWorker::eventOccurrences(const QList &ranges) const QHash CalendarWorker::dailyEventOccurrences(const QList &ranges, - const QMultiHash &allDay, + const QMultiHash &allDay, const QList &occurrences) { QHash occurrenceHash; @@ -736,11 +769,11 @@ void CalendarWorker::loadData(const QList &ranges, mSentEvents.clear(); QMultiHash events; - QMultiHash allDay; + QMultiHash allDay; bool orphansDeleted = false; - const KCalCore::Event::List list = mCalendar->rawEvents(); - for (const KCalCore::Event::Ptr e : list) { + const KCalendarCore::Event::List list = mCalendar->rawEvents(); + for (const KCalendarCore::Event::Ptr e : list) { if (!mCalendar->isVisible(e)) { continue; } @@ -752,7 +785,7 @@ void CalendarWorker::loadData(const QList &ranges, // doesn't delete events which belong to a deleted notebook, then the // events will be "orphan" and need to be deleted. if (mStorage->load(e->uid())) { - KCalCore::Incidence::Ptr orphan = mCalendar->incidence(e->uid(), KDateTime()); + KCalendarCore::Incidence::Ptr orphan = mCalendar->incidence(e->uid(), QDateTime()); if (!orphan.isNull()) { bool deletedOrphanOccurrences = mCalendar->deleteIncidenceInstances(orphan); bool deletedOrphanSeries = mCalendar->deleteIncidence(orphan); @@ -789,7 +822,7 @@ void CalendarWorker::loadData(const QList &ranges, emit dataLoaded(ranges, uidList, events, occurrences, dailyOccurrences, reset); } -CalendarData::Event CalendarWorker::createEventStruct(const KCalCore::Event::Ptr &e, +CalendarData::Event CalendarWorker::createEventStruct(const KCalendarCore::Event::Ptr &e, mKCal::Notebook::Ptr notebook) const { CalendarData::Event event; @@ -816,14 +849,11 @@ CalendarData::Event CalendarWorker::createEventStruct(const KCalCore::Event::Ptr bool externalInvitation = false; const QString &calendarOwnerEmail = getNotebookAddress(e); - KCalCore::Person::Ptr organizer = e->organizer(); - if (!organizer.isNull()) { - QString organizerEmail = organizer->email(); - - if (!organizerEmail.isEmpty() && organizerEmail != calendarOwnerEmail - && (notebook.isNull() || !notebook->sharedWith().contains(organizer->email()))) { - externalInvitation = true; - } + KCalendarCore::Person organizer = e->organizer(); + const QString organizerEmail = organizer.email(); + if (!organizerEmail.isEmpty() && organizerEmail != calendarOwnerEmail + && (notebook.isNull() || !notebook->sharedWith().contains(organizerEmail))) { + externalInvitation = true; } event.externalInvitation = externalInvitation; @@ -834,22 +864,21 @@ CalendarData::Event CalendarWorker::createEventStruct(const KCalCore::Event::Ptr // This defaults to QString() -> ResponseUnspecified in case the property is undefined event.ownerStatus = CalendarUtils::convertResponseType(e->nonKDECustomProperty("X-EAS-RESPONSE-TYPE")); - KCalCore::Attendee::List attendees = e->attendees(); - - foreach (KCalCore::Attendee::Ptr calAttendee, attendees) { - if (calAttendee->email() == calendarOwnerEmail) { - if (CalendarUtils::convertPartStat(calAttendee->status()) != CalendarEvent::ResponseUnspecified) { + const KCalendarCore::Attendee::List attendees = e->attendees(); + for (const KCalendarCore::Attendee &calAttendee : attendees) { + if (calAttendee.email() == calendarOwnerEmail) { + if (CalendarUtils::convertPartStat(calAttendee.status()) != CalendarEvent::ResponseUnspecified) { // Override the ResponseType - event.ownerStatus = CalendarUtils::convertPartStat(calAttendee->status()); + event.ownerStatus = CalendarUtils::convertPartStat(calAttendee.status()); } - //TODO: KCalCore::Attendee::RSVP() returns false even if response was requested for some accounts like Google. + //TODO: KCalendarCore::Attendee::RSVP() returns false even if response was requested for some accounts like Google. // We can use attendee role until the problem is not fixed (probably in Google plugin). // To be updated later when google account support for responses is added. - event.rsvp = calAttendee->RSVP();// || calAttendee->role() != KCalCore::Attendee::Chair; + event.rsvp = calAttendee.RSVP();// || calAttendee->role() != KCalendarCore::Attendee::Chair; } } - KCalCore::RecurrenceRule *defaultRule = e->recurrence()->defaultRRule(); + KCalendarCore::RecurrenceRule *defaultRule = e->recurrence()->defaultRRule(); if (defaultRule) { event.recurEndDate = defaultRule->endDt().date(); } @@ -960,18 +989,18 @@ void CalendarWorker::loadNotebooks() CalendarData::EventOccurrence CalendarWorker::getNextOccurrence(const QString &uid, - const KDateTime &recurrenceId, + const QDateTime &recurrenceId, const QDateTime &start) const { - KCalCore::Event::Ptr event = mCalendar->event(uid, recurrenceId); + KCalendarCore::Event::Ptr event = mCalendar->event(uid, recurrenceId); return CalendarUtils::getNextOccurrence(event, start); } -QList CalendarWorker::getEventAttendees(const QString &uid, const KDateTime &recurrenceId) +QList CalendarWorker::getEventAttendees(const QString &uid, const QDateTime &recurrenceId) { QList result; - KCalCore::Event::Ptr event = mCalendar->event(uid, recurrenceId); + KCalendarCore::Event::Ptr event = mCalendar->event(uid, recurrenceId); if (event.isNull()) { return result; @@ -982,23 +1011,23 @@ QList CalendarWorker::getEventAttendees(const QString &u void CalendarWorker::findMatchingEvent(const QString &invitationFile) { - KCalCore::MemoryCalendar::Ptr cal(new KCalCore::MemoryCalendar(KDateTime::Spec::LocalZone())); + KCalendarCore::MemoryCalendar::Ptr cal(new KCalendarCore::MemoryCalendar(QTimeZone::systemTimeZone())); CalendarUtils::importFromFile(invitationFile, cal); - KCalCore::Incidence::List incidenceList = cal->incidences(); + KCalendarCore::Incidence::List incidenceList = cal->incidences(); for (int i = 0; i < incidenceList.size(); i++) { - KCalCore::Incidence::Ptr incidence = incidenceList.at(i); - if (incidence->type() == KCalCore::IncidenceBase::TypeEvent) { + KCalendarCore::Incidence::Ptr incidence = incidenceList.at(i); + if (incidence->type() == KCalendarCore::IncidenceBase::TypeEvent) { // Search for this event in the database. loadData(QList() << qMakePair(incidence->dtStart().date().addDays(-1), incidence->dtStart().date().addDays(1)), QStringList(), false); - KCalCore::Incidence::List dbIncidences = mCalendar->incidences(); - Q_FOREACH (KCalCore::Incidence::Ptr dbIncidence, dbIncidences) { + KCalendarCore::Incidence::List dbIncidences = mCalendar->incidences(); + Q_FOREACH (KCalendarCore::Incidence::Ptr dbIncidence, dbIncidences) { const QString remoteUidValue(dbIncidence->nonKDECustomProperty("X-SAILFISHOS-REMOTE-UID")); if (dbIncidence->uid().compare(incidence->uid(), Qt::CaseInsensitive) == 0 || remoteUidValue.compare(incidence->uid(), Qt::CaseInsensitive) == 0) { if ((!incidence->hasRecurrenceId() && !dbIncidence->hasRecurrenceId()) || (incidence->hasRecurrenceId() && dbIncidence->hasRecurrenceId() && incidence->recurrenceId() == dbIncidence->recurrenceId())) { - emit findMatchingEventFinished(invitationFile, createEventStruct(dbIncidence.staticCast())); + emit findMatchingEventFinished(invitationFile, createEventStruct(dbIncidence.staticCast())); return; } } diff --git a/src/calendarworker.h b/src/calendarworker.h index f8096af..4b2a7f8 100644 --- a/src/calendarworker.h +++ b/src/calendarworker.h @@ -69,7 +69,7 @@ public slots: void replaceOccurrence(const CalendarData::Event &eventData, const QDateTime &startTime, bool updateAttendees, const QList &required, const QList &optional); - void deleteEvent(const QString &uid, const KDateTime &recurrenceId, const QDateTime &dateTime); + void deleteEvent(const QString &uid, const QDateTime &recurrenceId, const QDateTime &dateTime); void deleteAll(const QString &uid); bool sendResponse(const CalendarData::Event &eventData, const CalendarEvent::Response response); QString convertEventToICalendar(const QString &uid, const QString &prodId) const; @@ -83,9 +83,9 @@ public slots: void loadData(const QList &ranges, const QStringList &uidList, bool reset); - CalendarData::EventOccurrence getNextOccurrence(const QString &uid, const KDateTime &recurrenceId, + CalendarData::EventOccurrence getNextOccurrence(const QString &uid, const QDateTime &recurrenceId, const QDateTime &startTime) const; - QList getEventAttendees(const QString &uid, const KDateTime &recurrenceId); + QList getEventAttendees(const QString &uid, const QDateTime &recurrenceId); void findMatchingEvent(const QString &invitationFile); @@ -107,32 +107,32 @@ public slots: void occurrenceExceptionFailed(const CalendarData::Event &eventData, const QDateTime &startTime); void occurrenceExceptionCreated(const CalendarData::Event &eventData, const QDateTime &startTime, - const KDateTime &newRecurrenceId); + const QDateTime &newRecurrenceId); void findMatchingEventFinished(const QString &invitationFile, const CalendarData::Event &eventData); private: - void setEventData(KCalCore::Event::Ptr &event, const CalendarData::Event &eventData); + void setEventData(KCalendarCore::Event::Ptr &event, const CalendarData::Event &eventData); void loadNotebooks(); QStringList excludedNotebooks() const; bool saveExcludeNotebook(const QString ¬ebookUid, bool exclude); - bool setRecurrence(KCalCore::Event::Ptr &event, CalendarEvent::Recur recur, CalendarEvent::Days days); - bool setReminder(KCalCore::Event::Ptr &event, int reminderSeconds); - bool needSendCancellation(KCalCore::Event::Ptr &event) const; - void updateEventAttendees(KCalCore::Event::Ptr event, bool newEvent, + bool setRecurrence(KCalendarCore::Event::Ptr &event, CalendarEvent::Recur recur, CalendarEvent::Days days); + bool setReminder(KCalendarCore::Event::Ptr &event, int reminderSeconds); + bool needSendCancellation(KCalendarCore::Event::Ptr &event) const; + void updateEventAttendees(KCalendarCore::Event::Ptr event, bool newEvent, const QList &required, const QList &optional, const QString ¬ebookUid); QString getNotebookAddress(const QString ¬ebookUid) const; - QString getNotebookAddress(const KCalCore::Event::Ptr &event) const; + QString getNotebookAddress(const KCalendarCore::Event::Ptr &event) const; - CalendarData::Event createEventStruct(const KCalCore::Event::Ptr &event, + CalendarData::Event createEventStruct(const KCalendarCore::Event::Ptr &event, mKCal::Notebook::Ptr notebook = mKCal::Notebook::Ptr()) const; QHash eventOccurrences(const QList &ranges) const; QHash dailyEventOccurrences(const QList &ranges, - const QMultiHash &allDay, + const QMultiHash &allDay, const QList &occurrences); Accounts::Manager *mAccountManager; @@ -143,12 +143,12 @@ public slots: // mDeletedEvents is used to make sure // that we are sending a cancellation email for events only // when user actually saved (so truly deleted) changes by calling of save() - QList> mDeletedEvents; + QList> mDeletedEvents; QHash mNotebooks; // Tracks which events have been already passed to manager. Maps Uid -> RecurrenceId - QMultiHash mSentEvents; + QMultiHash mSentEvents; }; #endif // CALENDARWORKER_H diff --git a/src/plugins.qmltypes b/src/plugins.qmltypes index 6d328ac..b3e0f54 100644 --- a/src/plugins.qmltypes +++ b/src/plugins.qmltypes @@ -155,15 +155,6 @@ Module { "Sunday": 64 } } - Enum { - name: "TimeSpec" - values: { - "SpecLocalZone": 0, - "SpecClockTime": 1, - "SpecTimeZone": 2, - "SpecUtc": 3 - } - } Enum { name: "Secrecy" values: { diff --git a/src/src.pro b/src/src.pro index fd04468..cddbc2c 100644 --- a/src/src.pro +++ b/src/src.pro @@ -9,7 +9,7 @@ QT -= gui QMAKE_CXXFLAGS += -Werror target.path = $$[QT_INSTALL_QML]/$$PLUGIN_IMPORT_PATH -PKGCONFIG += libkcalcoren-qt5 libmkcal-qt5 libical accounts-qt5 +PKGCONFIG += KF5CalendarCore libmkcal-qt5 libical accounts-qt5 INSTALLS += target diff --git a/tests/tst_calendarevent/tst_calendarevent.cpp b/tests/tst_calendarevent/tst_calendarevent.cpp index d636e36..3868dbb 100644 --- a/tests/tst_calendarevent/tst_calendarevent.cpp +++ b/tests/tst_calendarevent/tst_calendarevent.cpp @@ -1,10 +1,40 @@ +/* + * Copyright (c) 2014 - 2019 Jolla Ltd. + * Copyright (c) 2020 Open Mobile Platform LLC. + * + * You may use this file under the terms of the BSD license as follows: + * + * "Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Nemo Mobile nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." + */ #include #include #include #include #include - -#include +#include #include "calendarapi.h" #include "calendarevent.h" @@ -48,8 +78,14 @@ void tst_CalendarEvent::initTestCase() plugin->initializeEngine(engine, "foobar"); calendarApi = new CalendarApi(this); + // Ensure a default notebook exists for saving new events + CalendarManager *manager = CalendarManager::instance(); + if (manager->defaultNotebook().isEmpty()) { + manager->setDefaultNotebook(manager->notebooks().value(0).uid); + } + // FIXME: calls made directly after instantiating seem to have threading issues. - // KDateTime/Timezone initialization somehow fails and caches invalid timezones, + // QDateTime/Timezone initialization somehow fails and caches invalid timezones, // resulting in times such as 2014-11-26T00:00:00--596523:-14 // (Above offset hour is -2147482800 / (60*60)) QTest::qWait(100); @@ -86,7 +122,7 @@ void tst_CalendarEvent::modSetters() QSignalSpy endTimeSpy(eventMod, SIGNAL(endTimeChanged())); QDateTime endTime = QDateTime::currentDateTime(); - eventMod->setEndTime(endTime, CalendarEvent::SpecLocalZone); + eventMod->setEndTime(endTime, Qt::LocalTime); QCOMPARE(endTimeSpy.count(), 1); QCOMPARE(eventMod->endTime(), endTime); @@ -111,7 +147,7 @@ void tst_CalendarEvent::modSetters() QSignalSpy startTimeSpy(eventMod, SIGNAL(startTimeChanged())); QDateTime startTime = QDateTime::currentDateTime(); - eventMod->setStartTime(startTime, CalendarEvent::SpecLocalZone); + eventMod->setStartTime(startTime, Qt::LocalTime); QCOMPARE(startTimeSpy.count(), 1); QCOMPARE(eventMod->startTime(), startTime); @@ -140,7 +176,7 @@ void tst_CalendarEvent::testSave() QCOMPARE(eventMod->location(), location); QDateTime endTime = QDateTime::currentDateTime(); - eventMod->setEndTime(endTime, CalendarEvent::SpecLocalZone); + eventMod->setEndTime(endTime, Qt::LocalTime); QCOMPARE(eventMod->endTime(), endTime); CalendarEvent::Recur recur = CalendarEvent::RecurDaily; @@ -156,7 +192,7 @@ void tst_CalendarEvent::testSave() QCOMPARE(eventMod->reminder(), reminder); QDateTime startTime = QDateTime::currentDateTime(); - eventMod->setStartTime(startTime, CalendarEvent::SpecLocalZone); + eventMod->setStartTime(startTime, Qt::LocalTime); QCOMPARE(eventMod->startTime(), startTime); QString uid; @@ -179,15 +215,15 @@ void tst_CalendarEvent::testSave() CalendarEvent *eventB = (CalendarEvent*) query.event(); QVERIFY(eventB != 0); - // mKCal DB stores times as seconds, loosing millisecond accuracy. + // mKCal DB stores times as seconds, losing millisecond accuracy. // Compare dates with QDateTime::toTime_t() instead of QDateTime::toMSecsSinceEpoch() QCOMPARE(eventB->endTime().toTime_t(), endTime.toTime_t()); QCOMPARE(eventB->startTime().toTime_t(), startTime.toTime_t()); QCOMPARE(eventB->endTime().timeSpec(), Qt::LocalTime); QCOMPARE(eventB->startTime().timeSpec(), Qt::LocalTime); - QCOMPARE(eventB->endTimeSpec(), CalendarEvent::SpecTimeZone); - QCOMPARE(eventB->startTimeSpec(), CalendarEvent::SpecTimeZone); + QCOMPARE(eventB->endTimeSpec(), Qt::TimeZone); + QCOMPARE(eventB->startTimeSpec(), Qt::TimeZone); QCOMPARE(eventB->endTimeZone().toUtf8(), endTime.timeZone().id()); QCOMPARE(eventB->startTimeZone().toUtf8(), startTime.timeZone().id()); @@ -207,23 +243,22 @@ void tst_CalendarEvent::testSave() void tst_CalendarEvent::testTimeZone_data() { - QTest::addColumn("spec"); + QTest::addColumn("spec"); - QTest::newRow("clock time") << CalendarEvent::SpecClockTime; - QTest::newRow("local zone") << CalendarEvent::SpecLocalZone; - QTest::newRow("UTC") << CalendarEvent::SpecUtc; - QTest::newRow("time zone") << CalendarEvent::SpecTimeZone; + QTest::newRow("local zone") << Qt::LocalTime; + QTest::newRow("UTC") << Qt::UTC; + QTest::newRow("time zone") << Qt::TimeZone; } void tst_CalendarEvent::testTimeZone() { - QFETCH(CalendarEvent::TimeSpec, spec); + QFETCH(Qt::TimeSpec, spec); CalendarEventModification *eventMod = calendarApi->createNewEvent(); QVERIFY(eventMod != 0); QDateTime startTime = QDateTime(QDate(2020, 4, 8), QTime(16, 50)); - if (spec == CalendarEvent::SpecTimeZone) { + if (spec == Qt::TimeZone) { // Using the system time zone, because agendamodels are looking for // events in the same day in the system time zone. eventMod->setStartTime(startTime, spec, QDateTime::currentDateTime().timeZone().id()); @@ -231,7 +266,7 @@ void tst_CalendarEvent::testTimeZone() eventMod->setStartTime(startTime, spec); } QDateTime endTime = startTime.addSecs(3600); - if (spec == CalendarEvent::SpecTimeZone) { + if (spec == Qt::TimeZone) { eventMod->setEndTime(endTime, spec, QDateTime::currentDateTime().timeZone().id()); } else { eventMod->setEndTime(endTime, spec); @@ -262,13 +297,12 @@ void tst_CalendarEvent::testTimeZone() QCOMPARE(eventB->endTime().timeSpec(), Qt::LocalTime); QCOMPARE(eventB->startTime().timeSpec(), Qt::LocalTime); - if (spec == CalendarEvent::SpecClockTime - || spec == CalendarEvent::SpecUtc) { + if (spec == Qt::UTC) { QCOMPARE(eventB->endTimeSpec(), spec); QCOMPARE(eventB->startTimeSpec(), spec); } else { - QCOMPARE(eventB->endTimeSpec(), CalendarEvent::SpecTimeZone); - QCOMPARE(eventB->startTimeSpec(), CalendarEvent::SpecTimeZone); + QCOMPARE(eventB->endTimeSpec(), Qt::TimeZone); + QCOMPARE(eventB->startTimeSpec(), Qt::TimeZone); QCOMPARE(eventB->endTimeZone().toUtf8(), endTime.timeZone().id()); QCOMPARE(eventB->startTimeZone().toUtf8(), startTime.timeZone().id()); } @@ -288,8 +322,8 @@ void tst_CalendarEvent::testRecurrenceException() event->setDisplayLabel("Recurring event"); QDateTime startTime = QDateTime(QDate(2014, 6, 7), QTime(12, 00)); QDateTime endTime = startTime.addSecs(60 * 60); - event->setStartTime(startTime, CalendarEvent::SpecLocalZone); - event->setEndTime(endTime, CalendarEvent::SpecLocalZone); + event->setStartTime(startTime, Qt::LocalTime); + event->setEndTime(endTime, Qt::LocalTime); CalendarEvent::Recur recur = CalendarEvent::RecurWeekly; event->setRecur(recur); QString uid; @@ -320,8 +354,8 @@ void tst_CalendarEvent::testRecurrenceException() CalendarEventModification *recurrenceException = calendarApi->createModification(savedEvent); QVERIFY(recurrenceException != 0); QDateTime modifiedSecond = secondStart.addSecs(10*60); // 12:10 - recurrenceException->setStartTime(modifiedSecond, CalendarEvent::SpecLocalZone); - recurrenceException->setEndTime(modifiedSecond.addSecs(10*60), CalendarEvent::SpecLocalZone); + recurrenceException->setStartTime(modifiedSecond, Qt::LocalTime); + recurrenceException->setEndTime(modifiedSecond.addSecs(10*60), Qt::LocalTime); recurrenceException->setDisplayLabel("Modified recurring event instance"); CalendarChangeInformation *info = recurrenceException->replaceOccurrence(static_cast(query.occurrence())); @@ -334,17 +368,19 @@ void tst_CalendarEvent::testRecurrenceException() QTest::qWait(1000); // allow saved data to be reloaded // check the occurrences are correct - CalendarEventOccurrence *occurrence = CalendarManager::instance()->getNextOccurrence(uid, KDateTime(), + CalendarEventOccurrence *occurrence = CalendarManager::instance()->getNextOccurrence(uid, QDateTime(), startTime.addDays(-1)); + QVERIFY(occurrence); // first QCOMPARE(occurrence->startTime(), startTime); // third - occurrence = CalendarManager::instance()->getNextOccurrence(uid, KDateTime(), startTime.addDays(1)); + occurrence = CalendarManager::instance()->getNextOccurrence(uid, QDateTime(), startTime.addDays(1)); + QVERIFY(occurrence); QCOMPARE(occurrence->startTime(), startTime.addDays(14)); // second is exception - occurrence = CalendarManager::instance()->getNextOccurrence(uid, KDateTime::fromString(info->recurrenceId()), + occurrence = CalendarManager::instance()->getNextOccurrence(uid, QDateTime::fromString(info->recurrenceId(), Qt::ISODate), startTime.addDays(1)); - + QVERIFY(occurrence); QCOMPARE(occurrence->startTime(), modifiedSecond); delete recurrenceException; recurrenceException = 0; @@ -361,22 +397,22 @@ void tst_CalendarEvent::testRecurrenceException() QVERIFY(recurrenceException != 0); modifiedSecond = modifiedSecond.addSecs(20*60); // 12:30 - recurrenceException->setStartTime(modifiedSecond, CalendarEvent::SpecLocalZone); - recurrenceException->setEndTime(modifiedSecond.addSecs(10*60), CalendarEvent::SpecLocalZone); + recurrenceException->setStartTime(modifiedSecond, Qt::LocalTime); + recurrenceException->setEndTime(modifiedSecond.addSecs(10*60), Qt::LocalTime); QString modifiedLabel("Modified recurring event instance, ver 2"); recurrenceException->setDisplayLabel(modifiedLabel); recurrenceException->save(); QTest::qWait(1000); // allow saved data to be reloaded // check the occurrences are correct - occurrence = CalendarManager::instance()->getNextOccurrence(uid, KDateTime(), startTime.addDays(-1)); + occurrence = CalendarManager::instance()->getNextOccurrence(uid, QDateTime(), startTime.addDays(-1)); // first QCOMPARE(occurrence->startTime(), startTime); // third - occurrence = CalendarManager::instance()->getNextOccurrence(uid, KDateTime(), startTime.addDays(1)); + occurrence = CalendarManager::instance()->getNextOccurrence(uid, QDateTime(), startTime.addDays(1)); QCOMPARE(occurrence->startTime(), startTime.addDays(14)); // second is exception - occurrence = CalendarManager::instance()->getNextOccurrence(uid, KDateTime::fromString(info->recurrenceId()), + occurrence = CalendarManager::instance()->getNextOccurrence(uid, QDateTime::fromString(info->recurrenceId(), Qt::ISODate), startTime.addDays(1)); QVERIFY(occurrence); @@ -387,18 +423,18 @@ void tst_CalendarEvent::testRecurrenceException() CalendarEventModification *mod = calendarApi->createModification(savedEvent); QVERIFY(mod != 0); QDateTime modifiedStart = startTime.addSecs(40*60); // 12:40 - mod->setStartTime(modifiedStart, CalendarEvent::SpecLocalZone); - mod->setEndTime(modifiedStart.addSecs(40*60), CalendarEvent::SpecLocalZone); + mod->setStartTime(modifiedStart, Qt::LocalTime); + mod->setEndTime(modifiedStart.addSecs(40*60), Qt::LocalTime); mod->save(); QTest::qWait(1000); // and check - occurrence = CalendarManager::instance()->getNextOccurrence(uid, KDateTime(), startTime.addDays(-1)); + occurrence = CalendarManager::instance()->getNextOccurrence(uid, QDateTime(), startTime.addDays(-1)); QCOMPARE(occurrence->startTime(), modifiedStart); - occurrence = CalendarManager::instance()->getNextOccurrence(uid, KDateTime(), startTime.addDays(1)); + occurrence = CalendarManager::instance()->getNextOccurrence(uid, QDateTime(), startTime.addDays(1)); // TODO: Would be the best if second occurrence in the main series stays away, but at the moment it doesn't. //QCOMPARE(occurrence->startTime(), modifiedStart.addDays(14)); - occurrence = CalendarManager::instance()->getNextOccurrence(uid, KDateTime::fromString(info->recurrenceId()), + occurrence = CalendarManager::instance()->getNextOccurrence(uid, QDateTime::fromString(info->recurrenceId(), Qt::ISODate), startTime.addDays(1)); QVERIFY(occurrence); QCOMPARE(occurrence->startTime(), modifiedSecond); @@ -425,9 +461,9 @@ void tst_CalendarEvent::testRecurrenceException() // ensure all gone calendarApi->removeAll(uid); mSavedEvents.remove(uid); - occurrence = CalendarManager::instance()->getNextOccurrence(uid, KDateTime(), startTime.addDays(-1)); + occurrence = CalendarManager::instance()->getNextOccurrence(uid, QDateTime(), startTime.addDays(-1)); QVERIFY(!occurrence->startTime().isValid()); - occurrence = CalendarManager::instance()->getNextOccurrence(uid, KDateTime::fromString(info->recurrenceId()), + occurrence = CalendarManager::instance()->getNextOccurrence(uid, QDateTime::fromString(info->recurrenceId(), Qt::ISODate), startTime.addDays(1)); QVERIFY(!occurrence->startTime().isValid()); @@ -440,8 +476,8 @@ void tst_CalendarEvent::testRecurrenceException() bool tst_CalendarEvent::saveEvent(CalendarEventModification *eventMod, QString *uid) { CalendarAgendaModel agendaModel; - agendaModel.setStartDate(eventMod->startTime().date()); - agendaModel.setEndDate(eventMod->endTime().date()); + agendaModel.setStartDate(eventMod->startTime().toLocalTime().date()); + agendaModel.setEndDate(eventMod->endTime().toLocalTime().date()); // Wait for the agendaModel to get updated, no way to determine when that happens, so just wait QTest::qWait(2000); @@ -463,7 +499,7 @@ bool tst_CalendarEvent::saveEvent(CalendarEventModification *eventMod, QString * if (agendaModel.count() != count + 1 || countSpy.count() == 0) { - qWarning() << "saveEvent() - invalid counts"; + qWarning() << "saveEvent() - invalid counts" << agendaModel.count(); return false; } @@ -496,8 +532,8 @@ void tst_CalendarEvent::testDate() eventMod->setDisplayLabel(QString("test event for ") + date.toString()); QDateTime startTime(date, QTime(12, 0)); - eventMod->setStartTime(startTime, CalendarEvent::SpecLocalZone); - eventMod->setEndTime(startTime.addSecs(10*60), CalendarEvent::SpecLocalZone); + eventMod->setStartTime(startTime, Qt::LocalTime); + eventMod->setEndTime(startTime.addSecs(10*60), Qt::LocalTime); QString uid; bool ok = saveEvent(eventMod, &uid); @@ -530,8 +566,8 @@ void tst_CalendarEvent::testRecurrence() QVERIFY(eventMod != 0); const QDateTime dt(QDate(2020, 4, 27), QTime(8, 0)); - eventMod->setStartTime(dt, CalendarEvent::SpecLocalZone); - eventMod->setEndTime(dt.addSecs(10*60), CalendarEvent::SpecLocalZone); + eventMod->setStartTime(dt, Qt::LocalTime); + eventMod->setEndTime(dt.addSecs(10*60), Qt::LocalTime); eventMod->setRecur(recurType); eventMod->setDescription(QMetaEnum::fromType().valueToKey(recurType)); @@ -570,8 +606,8 @@ void tst_CalendarEvent::testRecurWeeklyDays() days |= CalendarEvent::Wednesday; days |= CalendarEvent::Thursday; const QDateTime dt(QDate(2020, 4, 30), QTime(9, 0)); // This is a Thursday - eventMod->setStartTime(dt, CalendarEvent::SpecLocalZone); - eventMod->setEndTime(dt.addSecs(10*60), CalendarEvent::SpecLocalZone); + eventMod->setStartTime(dt, Qt::LocalTime); + eventMod->setEndTime(dt.addSecs(10*60), Qt::LocalTime); eventMod->setRecur(CalendarEvent::RecurWeeklyByDays); eventMod->setRecurWeeklyDays(days); eventMod->setDescription(QLatin1String("Testing weekly by days...")); diff --git a/tests/tst_calendarmanager/tst_calendarmanager.cpp b/tests/tst_calendarmanager/tst_calendarmanager.cpp index e72dc6b..07d9625 100644 --- a/tests/tst_calendarmanager/tst_calendarmanager.cpp +++ b/tests/tst_calendarmanager/tst_calendarmanager.cpp @@ -5,8 +5,8 @@ #include "extendedcalendar.h" #include "extendedstorage.h" -// kCalCore -#include +// kcalendarcore +#include #include "calendarmanager.h" #include @@ -513,7 +513,7 @@ void tst_CalendarManager::test_addRanges() mKCal::Notebook::Ptr tst_CalendarManager::createNotebook() { - return mKCal::Notebook::Ptr(new mKCal::Notebook(KCalCore::CalFormat::createUniqueId(), + return mKCal::Notebook::Ptr(new mKCal::Notebook(KCalendarCore::CalFormat::createUniqueId(), "", QLatin1String(""), "#110000", @@ -542,7 +542,7 @@ void tst_CalendarManager::test_notebookApi() int notebookCount = manager->notebooks().count(); mDefaultNotebook = manager->defaultNotebook(); - mCalendar = mKCal::ExtendedCalendar::Ptr(new mKCal::ExtendedCalendar(KDateTime::Spec::LocalZone())); + mCalendar = mKCal::ExtendedCalendar::Ptr(new mKCal::ExtendedCalendar(QTimeZone::systemTimeZone())); mStorage = mCalendar->defaultStorage(mCalendar); mStorage->open(); diff --git a/tools/icalconverter/icalconverter.pro b/tools/icalconverter/icalconverter.pro index 52c00ee..fa373c2 100644 --- a/tools/icalconverter/icalconverter.pro +++ b/tools/icalconverter/icalconverter.pro @@ -2,7 +2,7 @@ TEMPLATE=app TARGET=icalconverter QT-=gui CONFIG += link_pkgconfig -PKGCONFIG += libkcalcoren-qt5 libmkcal-qt5 +PKGCONFIG += KF5CalendarCore libmkcal-qt5 QMAKE_CXXFLAGS += -fPIE -fvisibility=hidden -fvisibility-inlines-hidden SOURCES+=main.cpp diff --git a/tools/icalconverter/main.cpp b/tools/icalconverter/main.cpp index 91fb1dc..fd6fa85 100644 --- a/tools/icalconverter/main.cpp +++ b/tools/icalconverter/main.cpp @@ -40,17 +40,17 @@ #include #include -#include +#include +#include +#include +#include +#include +#include +#include +#include + #include #include -#include -#include -#include -#include -#include -#include -#include -#include #define LOG_DEBUG(msg) if (printDebug) qDebug() << msg @@ -92,7 +92,7 @@ namespace { namespace CalendarImportExport { namespace IncidenceHandler { - void normalizePersonEmail(KCalCore::Person *p) + void normalizePersonEmail(KCalendarCore::Person *p) { QString email = p->email().replace(QStringLiteral("mailto:"), QString(), Qt::CaseInsensitive); if (email != p->email()) { @@ -114,7 +114,7 @@ namespace CalendarImportExport { 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) { RETURN_FALSE_IF_NOT_EQUAL_CUSTOM(a->dateEnd() != b->dateEnd(), "dateEnd", (a->dateEnd().toString() + " != " + b->dateEnd().toString())); RETURN_FALSE_IF_NOT_EQUAL(a, b, transparency(), "transparency"); @@ -145,7 +145,7 @@ namespace CalendarImportExport { 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) { RETURN_FALSE_IF_NOT_EQUAL(a, b, hasCompletedDate(), "hasCompletedDate"); RETURN_FALSE_IF_NOT_EQUAL_CUSTOM(a->dtRecurrence() != b->dtRecurrence(), "dtRecurrence", (a->dtRecurrence().toString() + " != " + b->dtRecurrence().toString())); @@ -159,14 +159,14 @@ namespace CalendarImportExport { 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 copiedPropertiesAreEqual(const KCalCore::Incidence::Ptr &a, const KCalCore::Incidence::Ptr &b, bool printDebug) + bool copiedPropertiesAreEqual(const KCalendarCore::Incidence::Ptr &a, const KCalendarCore::Incidence::Ptr &b, bool printDebug) { if (!a || !b) { qWarning() << "Invalid paramters! a:" << a << "b:" << b; @@ -176,7 +176,7 @@ namespace CalendarImportExport { // 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. RETURN_FALSE_IF_NOT_EQUAL(a, b, type(), "type"); RETURN_FALSE_IF_NOT_EQUAL(a, b, duration(), "duration"); @@ -208,37 +208,37 @@ namespace CalendarImportExport { } // 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); RETURN_FALSE_IF_NOT_EQUAL_CUSTOM(personA != personB, "organizer", (personA.fullName() + " != " + personB.fullName())); switch (a->type()) { - case KCalCore::IncidenceBase::TypeEvent: - if (!eventsEqual(a.staticCast(), b.staticCast(), printDebug)) { + case KCalendarCore::IncidenceBase::TypeEvent: + if (!eventsEqual(a.staticCast(), b.staticCast(), printDebug)) { return false; } break; - case KCalCore::IncidenceBase::TypeTodo: - if (!todosEqual(a.staticCast(), b.staticCast(), printDebug)) { + case KCalendarCore::IncidenceBase::TypeTodo: + if (!todosEqual(a.staticCast(), b.staticCast(), printDebug)) { return false; } break; - case KCalCore::IncidenceBase::TypeJournal: - if (!journalsEqual(a.staticCast(), b.staticCast(), printDebug)) { + case KCalendarCore::IncidenceBase::TypeJournal: + if (!journalsEqual(a.staticCast(), b.staticCast(), printDebug)) { return false; } break; - case KCalCore::IncidenceBase::TypeFreeBusy: - case KCalCore::IncidenceBase::TypeUnknown: + case KCalendarCore::IncidenceBase::TypeFreeBusy: + case KCalendarCore::IncidenceBase::TypeUnknown: LOG_DEBUG("Unable to compare FreeBusy or Unknown incidence, assuming equal"); break; } return true; } - void copyIncidenceProperties(KCalCore::Incidence::Ptr dest, const KCalCore::Incidence::Ptr &src) + void copyIncidenceProperties(KCalendarCore::Incidence::Ptr dest, const KCalendarCore::Incidence::Ptr &src) { if (!dest || !src) { qWarning() << "Invalid parameters!"; @@ -249,29 +249,29 @@ namespace CalendarImportExport { return; } - KDateTime origCreated = dest->created(); - KDateTime origLastModified = dest->lastModified(); + QDateTime origCreated = dest->created(); + QDateTime origLastModified = dest->lastModified(); // Copy recurrence information if required. if (*(dest->recurrence()) != *(src->recurrence())) { dest->recurrence()->clear(); - KCalCore::Recurrence *dr = dest->recurrence(); - KCalCore::Recurrence *sr = src->recurrence(); + KCalendarCore::Recurrence *dr = dest->recurrence(); + KCalendarCore::Recurrence *sr = src->recurrence(); // recurrence rules and dates - KCalCore::RecurrenceRule::List srRRules = sr->rRules(); - for (QList::const_iterator it = srRRules.constBegin(), end = srRRules.constEnd(); it != end; ++it) { - KCalCore::RecurrenceRule *r = new KCalCore::RecurrenceRule(*(*it)); + KCalendarCore::RecurrenceRule::List srRRules = sr->rRules(); + for (QList::const_iterator it = srRRules.constBegin(), end = srRRules.constEnd(); it != end; ++it) { + KCalendarCore::RecurrenceRule *r = new KCalendarCore::RecurrenceRule(*(*it)); dr->addRRule(r); } dr->setRDates(sr->rDates()); dr->setRDateTimes(sr->rDateTimes()); // exception rules and dates - KCalCore::RecurrenceRule::List srExRules = sr->exRules(); - for (QList::const_iterator it = srExRules.constBegin(), end = srExRules.constEnd(); it != end; ++it) { - KCalCore::RecurrenceRule *r = new KCalCore::RecurrenceRule(*(*it)); + KCalendarCore::RecurrenceRule::List srExRules = sr->exRules(); + for (QList::const_iterator it = srExRules.constBegin(), end = srExRules.constEnd(); it != end; ++it) { + KCalendarCore::RecurrenceRule *r = new KCalendarCore::RecurrenceRule(*(*it)); dr->addExRule(r); } dr->setExDates(sr->exDates()); @@ -281,16 +281,16 @@ namespace CalendarImportExport { // copy the duration before the dtEnd as calling setDuration() changes the dtEnd COPY_IF_NOT_EQUAL(dest, src, duration(), setDuration); - if (dest->type() == KCalCore::IncidenceBase::TypeEvent && src->type() == KCalCore::IncidenceBase::TypeEvent) { - KCalCore::Event::Ptr destEvent = dest.staticCast(); - KCalCore::Event::Ptr srcEvent = src.staticCast(); + if (dest->type() == KCalendarCore::IncidenceBase::TypeEvent && src->type() == KCalendarCore::IncidenceBase::TypeEvent) { + KCalendarCore::Event::Ptr destEvent = dest.staticCast(); + KCalendarCore::Event::Ptr srcEvent = src.staticCast(); COPY_IF_NOT_EQUAL(destEvent, srcEvent, dtEnd(), setDtEnd); COPY_IF_NOT_EQUAL(destEvent, srcEvent, transparency(), setTransparency); } - if (dest->type() == KCalCore::IncidenceBase::TypeTodo && src->type() == KCalCore::IncidenceBase::TypeTodo) { - KCalCore::Todo::Ptr destTodo = dest.staticCast(); - KCalCore::Todo::Ptr srcTodo = src.staticCast(); + if (dest->type() == KCalendarCore::IncidenceBase::TypeTodo && src->type() == KCalendarCore::IncidenceBase::TypeTodo) { + KCalendarCore::Todo::Ptr destTodo = dest.staticCast(); + KCalendarCore::Todo::Ptr srcTodo = src.staticCast(); COPY_IF_NOT_EQUAL(destTodo, srcTodo, completed(), setCompleted); COPY_IF_NOT_EQUAL(destTodo, srcTodo, dtRecurrence(), setDtRecurrence); COPY_IF_NOT_EQUAL(destTodo, srcTodo, percentComplete(), setPercentComplete); @@ -304,9 +304,9 @@ namespace CalendarImportExport { COPY_IF_NOT_EQUAL(dest, src, organizer(), setOrganizer); COPY_IF_NOT_EQUAL(dest, src, isReadOnly(), setReadOnly); - if (!pointerDataEqual(src->attendees(), dest->attendees())) { + if (src->attendees() != dest->attendees()) { dest->clearAttendees(); - Q_FOREACH (const KCalCore::Attendee::Ptr &attendee, src->attendees()) { + Q_FOREACH (const KCalendarCore::Attendee &attendee, src->attendees()) { dest->addAttendee(attendee); } } @@ -340,14 +340,14 @@ namespace CalendarImportExport { if (!pointerDataEqual(src->alarms(), dest->alarms())) { dest->clearAlarms(); - Q_FOREACH (const KCalCore::Alarm::Ptr &alarm, src->alarms()) { + Q_FOREACH (const KCalendarCore::Alarm::Ptr &alarm, src->alarms()) { dest->addAlarm(alarm); } } - if (!pointerDataEqual(src->attachments(), dest->attachments())) { + if (src->attachments() != dest->attachments()) { dest->clearAttachments(); - Q_FOREACH (const KCalCore::Attachment::Ptr &attachment, src->attachments()) { + Q_FOREACH (const KCalendarCore::Attachment &attachment, src->attachments()) { dest->addAttachment(attachment); } } @@ -362,17 +362,17 @@ namespace CalendarImportExport { } } - void prepareImportedIncidence(KCalCore::Incidence::Ptr incidence, bool printDebug) + void prepareImportedIncidence(KCalendarCore::Incidence::Ptr incidence, bool printDebug) { - if (incidence->type() != KCalCore::IncidenceBase::TypeEvent) { + if (incidence->type() != KCalendarCore::IncidenceBase::TypeEvent) { qWarning() << "unable to handle imported non-event incidence; skipping"; return; } - KCalCore::Event::Ptr event = incidence.staticCast(); + KCalendarCore::Event::Ptr event = incidence.staticCast(); if (event->allDay()) { - KDateTime dtStart = event->dtStart(); - KDateTime dtEnd = event->dtEnd(); + QDateTime dtStart = event->dtStart(); + QDateTime dtEnd = event->dtEnd(); // calendar processing requires all-day events to have a dtEnd if (!dtEnd.isValid()) { @@ -385,32 +385,25 @@ namespace CalendarImportExport { } } - KCalCore::Incidence::Ptr incidenceToExport(KCalCore::Incidence::Ptr sourceIncidence, bool printDebug) + KCalendarCore::Incidence::Ptr incidenceToExport(KCalendarCore::Incidence::Ptr sourceIncidence, bool printDebug) { - if (sourceIncidence->type() != KCalCore::IncidenceBase::TypeEvent) { + if (sourceIncidence->type() != KCalendarCore::IncidenceBase::TypeEvent) { LOG_DEBUG("Incidence not an event; cannot create exportable version"); return sourceIncidence; } - KCalCore::Incidence::Ptr incidence = QSharedPointer(sourceIncidence->clone()); - KCalCore::Event::Ptr event = incidence.staticCast(); + KCalendarCore::Incidence::Ptr incidence = QSharedPointer(sourceIncidence->clone()); + KCalendarCore::Event::Ptr event = incidence.staticCast(); bool eventIsAllDay = event->allDay(); if (eventIsAllDay) { if (event->dtStart() == event->dtEnd()) { // A single-day all-day event was received without a DTEND, and it is still a single-day // all-day event, so remove the DTEND before upsyncing. LOG_DEBUG("Removing DTEND from" << incidence->uid()); - event->setDtEnd(KDateTime()); + event->setDtEnd(QDateTime()); } } - if (event->dtStart().isDateOnly()) { - KDateTime dt = KDateTime(event->dtStart().date(), KDateTime::Spec::ClockTime()); - dt.setDateOnly(true); - event->setDtStart(dt); - LOG_DEBUG("Stripping time from date-only DTSTART:" << dt.toString()); - } - // setting dtStart/End changes the allDay value, so ensure it is still set to true if needed. if (eventIsAllDay) { event->setAllDay(true); @@ -418,16 +411,24 @@ namespace CalendarImportExport { // The default storage implementation applies the organizer as an attendee by default. // Undo this as it turns the incidence into a scheduled event requiring acceptance/rejection/etc. - const KCalCore::Person::Ptr organizer = event->organizer(); - if (organizer) { - Q_FOREACH (const KCalCore::Attendee::Ptr &attendee, event->attendees()) { - if (attendee->email() == organizer->email() && attendee->fullName() == organizer->fullName()) { - LOG_DEBUG("Discarding organizer as attendee" << attendee->fullName()); - event->deleteAttendee(attendee); + const KCalendarCore::Person organizer = event->organizer(); + if (!organizer.email().isEmpty()) { + bool found = false; + KCalendarCore::Attendee::List attendees = event->attendees(); + for (int i = attendees.size() - 1; i >= 0; --i) { + const KCalendarCore::Attendee &attendee(attendees[i]); + if (attendee.email() == organizer.email() && attendee.fullName() == organizer.fullName()) { + LOG_DEBUG("Discarding organizer as attendee" << attendee.fullName()); + attendees.removeAt(i); + found = true; } else { - LOG_DEBUG("Not discarding attendee:" << attendee->fullName() << attendee->email() << ": not organizer:" << organizer->fullName() << organizer->email()); + LOG_DEBUG("Not discarding attendee:" << attendee.fullName() << attendee.email() << ": not organizer:" << organizer.fullName() << organizer.email()); } } + + if (found) { + event->setAttendees(attendees); + } } return event; @@ -436,7 +437,7 @@ namespace CalendarImportExport { void listNotebooks() { - mKCal::ExtendedCalendar::Ptr calendar = mKCal::ExtendedCalendar::Ptr(new mKCal::ExtendedCalendar(KDateTime::Spec::UTC())); + mKCal::ExtendedCalendar::Ptr calendar = mKCal::ExtendedCalendar::Ptr(new mKCal::ExtendedCalendar(QTimeZone::utc())); mKCal::ExtendedStorage::Ptr storage = mKCal::ExtendedCalendar::defaultStorage(calendar); storage->open(); storage->load(); @@ -448,27 +449,27 @@ namespace CalendarImportExport { storage->close(); } - QString constructExportIcs(mKCal::ExtendedCalendar::Ptr calendar, KCalCore::Incidence::List incidencesToExport, bool printDebug) + QString constructExportIcs(mKCal::ExtendedCalendar::Ptr calendar, KCalendarCore::Incidence::List incidencesToExport, bool printDebug) { // create an in-memory calendar // add to it the required incidences (ie, check if has recurrenceId -> load parent and all instances; etc) // for each of those, we need to do the IncidenceToExport() modifications first // then, export from that calendar to .ics file. - KCalCore::MemoryCalendar::Ptr memoryCalendar(new KCalCore::MemoryCalendar(KDateTime::UTC)); - Q_FOREACH (KCalCore::Incidence::Ptr toExport, incidencesToExport) { + KCalendarCore::MemoryCalendar::Ptr memoryCalendar(new KCalendarCore::MemoryCalendar(QTimeZone::utc())); + Q_FOREACH (KCalendarCore::Incidence::Ptr toExport, incidencesToExport) { LOG_DEBUG("Exporting incidence:" << toExport->uid()); if (toExport->hasRecurrenceId() || toExport->recurs()) { - KCalCore::Incidence::Ptr recurringIncidence = toExport->hasRecurrenceId() - ? calendar->incidence(toExport->uid(), KDateTime()) + KCalendarCore::Incidence::Ptr recurringIncidence = toExport->hasRecurrenceId() + ? calendar->incidence(toExport->uid(), QDateTime()) : toExport; // Don't crash on null instances if (recurringIncidence.isNull()) continue; - KCalCore::Incidence::List instances = calendar->instances(recurringIncidence); - KCalCore::Incidence::Ptr exportableIncidence = IncidenceHandler::incidenceToExport(recurringIncidence, printDebug); + KCalendarCore::Incidence::List instances = calendar->instances(recurringIncidence); + KCalendarCore::Incidence::Ptr exportableIncidence = IncidenceHandler::incidenceToExport(recurringIncidence, printDebug); // remove EXDATE values from the recurring incidence which correspond to the persistent occurrences (instances) - Q_FOREACH (KCalCore::Incidence::Ptr instance, instances) { - QList exDateTimes = exportableIncidence->recurrence()->exDateTimes(); + Q_FOREACH (KCalendarCore::Incidence::Ptr instance, instances) { + QList exDateTimes = exportableIncidence->recurrence()->exDateTimes(); exDateTimes.removeAll(instance->recurrenceId()); exportableIncidence->recurrence()->setExDateTimes(exDateTimes); } @@ -477,13 +478,13 @@ namespace CalendarImportExport { memoryCalendar->addIncidence(exportableIncidence); // now create the persistent occurrences in the in-memory calendar - Q_FOREACH (KCalCore::Incidence::Ptr instance, instances) { + Q_FOREACH (KCalendarCore::Incidence::Ptr instance, instances) { // We cannot call dissociateSingleOccurrence() on the MemoryCalendar // as that's an mKCal specific function. // We cannot call dissociateOccurrence() because that function - // takes only a QDate instead of a KDateTime recurrenceId. + // takes only a QDate instead of a QDateTime recurrenceId. // Thus, we need to manually create an exception occurrence. - KCalCore::Incidence::Ptr exportableOccurrence(exportableIncidence->clone()); + KCalendarCore::Incidence::Ptr exportableOccurrence(exportableIncidence->clone()); exportableOccurrence->setCreated(instance->created()); exportableOccurrence->setRevision(instance->revision()); exportableOccurrence->clearRecurrence(); @@ -498,20 +499,20 @@ namespace CalendarImportExport { exportableOccurrence->endUpdates(); } } else { - KCalCore::Incidence::Ptr exportableIncidence = IncidenceHandler::incidenceToExport(toExport, printDebug); + KCalendarCore::Incidence::Ptr exportableIncidence = IncidenceHandler::incidenceToExport(toExport, printDebug); memoryCalendar->addIncidence(exportableIncidence); } } - KCalCore::ICalFormat icalFormat; + KCalendarCore::ICalFormat icalFormat; return icalFormat.toString(memoryCalendar, QString(), false); } - QString constructExportIcs(const QString ¬ebookUid, const QString &incidenceUid, const KDateTime &recurrenceId, bool printDebug) + QString constructExportIcs(const QString ¬ebookUid, const QString &incidenceUid, const QDateTime &recurrenceId, bool printDebug) { // if notebookUid empty, we fall back to the default notebook. // if incidenceUid is empty, we load all incidences from the notebook. - mKCal::ExtendedCalendar::Ptr calendar = mKCal::ExtendedCalendar::Ptr(new mKCal::ExtendedCalendar(KDateTime::Spec::UTC())); + mKCal::ExtendedCalendar::Ptr calendar = mKCal::ExtendedCalendar::Ptr(new mKCal::ExtendedCalendar(QTimeZone::utc())); mKCal::ExtendedStorage::Ptr storage = mKCal::ExtendedCalendar::defaultStorage(calendar); storage->open(); storage->load(); @@ -523,7 +524,7 @@ namespace CalendarImportExport { } LOG_DEBUG("Exporting notebook:" << notebook->uid()); - KCalCore::Incidence::List incidencesToExport; + KCalendarCore::Incidence::List incidencesToExport; if (incidenceUid.isEmpty()) { storage->loadNotebookIncidences(notebook->uid()); storage->allIncidences(&incidencesToExport, notebook->uid()); @@ -538,30 +539,30 @@ namespace CalendarImportExport { return retn; } - bool updateIncidence(mKCal::ExtendedCalendar::Ptr calendar, mKCal::Notebook::Ptr notebook, KCalCore::Incidence::Ptr incidence, bool *criticalError, bool printDebug) + bool updateIncidence(mKCal::ExtendedCalendar::Ptr calendar, mKCal::Notebook::Ptr notebook, KCalendarCore::Incidence::Ptr incidence, bool *criticalError, bool printDebug) { if (incidence.isNull()) { return false; } - KCalCore::Incidence::Ptr storedIncidence; + KCalendarCore::Incidence::Ptr storedIncidence; switch (incidence->type()) { - case KCalCore::IncidenceBase::TypeEvent: - storedIncidence = calendar->event(incidence->uid(), incidence->hasRecurrenceId() ? incidence->recurrenceId() : KDateTime()); + case KCalendarCore::IncidenceBase::TypeEvent: + storedIncidence = calendar->event(incidence->uid(), incidence->hasRecurrenceId() ? incidence->recurrenceId() : QDateTime()); break; - case KCalCore::IncidenceBase::TypeTodo: + case KCalendarCore::IncidenceBase::TypeTodo: storedIncidence = calendar->todo(incidence->uid()); break; - case KCalCore::IncidenceBase::TypeJournal: + case KCalendarCore::IncidenceBase::TypeJournal: storedIncidence = calendar->journal(incidence->uid()); break; - case KCalCore::IncidenceBase::TypeFreeBusy: - case KCalCore::IncidenceBase::TypeUnknown: + case KCalendarCore::IncidenceBase::TypeFreeBusy: + case KCalendarCore::IncidenceBase::TypeUnknown: qWarning() << "Unsupported incidence type:" << incidence->type(); return false; } if (storedIncidence) { - if (incidence->status() == KCalCore::Incidence::StatusCanceled + if (incidence->status() == KCalendarCore::Incidence::StatusCanceled || incidence->customStatus().compare(QStringLiteral("CANCELLED"), Qt::CaseInsensitive) == 0) { LOG_DEBUG("Deleting cancelled event:" << storedIncidence->uid() << storedIncidence->recurrenceId().toString()); if (!calendar->deleteIncidence(storedIncidence)) { @@ -579,8 +580,8 @@ namespace CalendarImportExport { // single instances will correspond to an EXDATE, but most sync servers do not (and // so will not include the RECURRENCE-ID values as EXDATEs of the parent). if (storedIncidence->recurs()) { - KCalCore::Incidence::List instances = calendar->instances(incidence); - Q_FOREACH (KCalCore::Incidence::Ptr instance, instances) { + KCalendarCore::Incidence::List instances = calendar->instances(incidence); + Q_FOREACH (KCalendarCore::Incidence::Ptr instance, instances) { if (instance->hasRecurrenceId()) { storedIncidence->recurrence()->addExDateTime(instance->recurrenceId()); } @@ -591,16 +592,16 @@ namespace CalendarImportExport { } else { // the new incidence will be either a new persistent occurrence, or a new base-series (or new non-recurring). LOG_DEBUG("Have new incidence:" << incidence->uid() << incidence->recurrenceId().toString()); - KCalCore::Incidence::Ptr occurrence; + KCalendarCore::Incidence::Ptr occurrence; if (incidence->hasRecurrenceId()) { // no dissociated occurrence exists already (ie, it's not an update), so create a new one. // need to detach, and then copy the properties into the detached occurrence. - KCalCore::Incidence::Ptr recurringIncidence = calendar->event(incidence->uid(), KDateTime()); + KCalendarCore::Incidence::Ptr recurringIncidence = calendar->event(incidence->uid(), QDateTime()); if (recurringIncidence.isNull()) { qWarning() << "error: parent recurring incidence could not be retrieved:" << incidence->uid(); return false; } - occurrence = calendar->dissociateSingleOccurrence(recurringIncidence, incidence->recurrenceId(), incidence->recurrenceId().timeSpec()); + occurrence = calendar->dissociateSingleOccurrence(recurringIncidence, incidence->recurrenceId()); if (occurrence.isNull()) { qWarning() << "error: could not dissociate occurrence from recurring event:" << incidence->uid() << incidence->recurrenceId().toString(); return false; @@ -608,7 +609,7 @@ namespace CalendarImportExport { IncidenceHandler::prepareImportedIncidence(incidence, printDebug); IncidenceHandler::copyIncidenceProperties(occurrence, incidence); - if (!calendar->addEvent(occurrence.staticCast(), notebook->uid())) { + if (!calendar->addEvent(occurrence.staticCast(), notebook->uid())) { qWarning() << "error: could not add dissociated occurrence to calendar"; return false; } @@ -618,17 +619,17 @@ namespace CalendarImportExport { IncidenceHandler::prepareImportedIncidence(incidence, printDebug); bool added = false; switch (incidence->type()) { - case KCalCore::IncidenceBase::TypeEvent: - added = calendar->addEvent(incidence.staticCast(), notebook->uid()); + case KCalendarCore::IncidenceBase::TypeEvent: + added = calendar->addEvent(incidence.staticCast(), notebook->uid()); break; - case KCalCore::IncidenceBase::TypeTodo: - added = calendar->addTodo(incidence.staticCast(), notebook->uid()); + case KCalendarCore::IncidenceBase::TypeTodo: + added = calendar->addTodo(incidence.staticCast(), notebook->uid()); break; - case KCalCore::IncidenceBase::TypeJournal: - added = calendar->addJournal(incidence.staticCast(), notebook->uid()); + case KCalendarCore::IncidenceBase::TypeJournal: + added = calendar->addJournal(incidence.staticCast(), notebook->uid()); break; - case KCalCore::IncidenceBase::TypeFreeBusy: - case KCalCore::IncidenceBase::TypeUnknown: + case KCalendarCore::IncidenceBase::TypeFreeBusy: + case KCalendarCore::IncidenceBase::TypeUnknown: qWarning() << "Unsupported incidence type:" << incidence->type(); return false; } @@ -646,11 +647,11 @@ namespace CalendarImportExport { bool importIcsData(const QString &icsData, const QString ¬ebookUid, bool destructiveImport, bool printDebug) { - KCalCore::ICalFormat iCalFormat; - KCalCore::MemoryCalendar::Ptr cal(new KCalCore::MemoryCalendar(KDateTime::UTC)); + KCalendarCore::ICalFormat iCalFormat; + KCalendarCore::MemoryCalendar::Ptr cal(new KCalendarCore::MemoryCalendar(QTimeZone::utc())); if (!iCalFormat.fromString(cal, icsData)) { qWarning() << "unable to parse iCal data, trying as vCal"; - KCalCore::VCalFormat vCalFormat; + KCalendarCore::VCalFormat vCalFormat; if (!vCalFormat.fromString(cal, icsData)) { qWarning() << "unable to parse vCal data"; return false; @@ -658,9 +659,9 @@ namespace CalendarImportExport { } // Reorganize the list of imported incidences into lists of incidences segregated by UID. - QHash uidIncidences; - KCalCore::Incidence::List importedIncidences = cal->incidences(); - Q_FOREACH (KCalCore::Incidence::Ptr imported, importedIncidences) { + QHash uidIncidences; + KCalendarCore::Incidence::List importedIncidences = cal->incidences(); + Q_FOREACH (KCalendarCore::Incidence::Ptr imported, importedIncidences) { IncidenceHandler::prepareImportedIncidence(imported, printDebug); uidIncidences[imported->uid()] << imported; } @@ -669,7 +670,7 @@ namespace CalendarImportExport { // Note that the import may specify updates to existing events, so // we will need to compare the imported incidences with the // existing incidences, by UID. - mKCal::ExtendedCalendar::Ptr calendar = mKCal::ExtendedCalendar::Ptr(new mKCal::ExtendedCalendar(KDateTime::Spec::UTC())); + mKCal::ExtendedCalendar::Ptr calendar = mKCal::ExtendedCalendar::Ptr(new mKCal::ExtendedCalendar(QTimeZone::utc())); mKCal::ExtendedStorage::Ptr storage = mKCal::ExtendedCalendar::defaultStorage(calendar); storage->open(); storage->load(); @@ -679,13 +680,13 @@ namespace CalendarImportExport { storage->close(); return false; } - KCalCore::Incidence::List notebookIncidences; + KCalendarCore::Incidence::List notebookIncidences; storage->loadNotebookIncidences(notebook->uid()); storage->allIncidences(¬ebookIncidences, notebook->uid()); if (destructiveImport) { // Any incidences which don't exist in the import list should be deleted. - Q_FOREACH (KCalCore::Incidence::Ptr possiblyDoomed, notebookIncidences) { + Q_FOREACH (KCalendarCore::Incidence::Ptr possiblyDoomed, notebookIncidences) { if (!uidIncidences.contains(possiblyDoomed->uid())) { // no incidence or series with this UID exists in the import list. LOG_DEBUG("Removing rolled-back incidence:" << possiblyDoomed->uid() << possiblyDoomed->recurrenceId().toString()); @@ -700,7 +701,7 @@ namespace CalendarImportExport { Q_FOREACH (const QString &uid, uidIncidences.keys()) { // deal with every incidence or series from the import list. - KCalCore::Incidence::List incidences(uidIncidences[uid]); + KCalendarCore::Incidence::List incidences(uidIncidences[uid]); // find the recurring incidence (parent) in the import list, and save it. // alternatively, it may be a non-recurring base incidence. bool criticalError = false; @@ -715,7 +716,7 @@ namespace CalendarImportExport { if (parentIndex == -1) { LOG_DEBUG("No parent or base incidence in incidence list, performing direct updates to persistent occurrences"); for (int i = 0; i < incidences.size(); ++i) { - KCalCore::Incidence::Ptr importInstance = incidences[i]; + KCalendarCore::Incidence::Ptr importInstance = incidences[i]; updateIncidence(calendar, notebook, importInstance, &criticalError, printDebug); if (criticalError) { qWarning() << "Error saving updated persistent occurrence:" << importInstance->uid() << importInstance->recurrenceId().toString(); @@ -726,15 +727,15 @@ namespace CalendarImportExport { } else { // if there was a parent / base incidence, then we need to compare local/import lists. // load the local (persistent) occurrences of the series. Later we will update or remove them as required. - KCalCore::Incidence::Ptr localBaseIncidence = calendar->incidence(uid, KDateTime()); - KCalCore::Incidence::List localInstances; + KCalendarCore::Incidence::Ptr localBaseIncidence = calendar->incidence(uid, QDateTime()); + KCalendarCore::Incidence::List localInstances; if (!localBaseIncidence.isNull() && localBaseIncidence->recurs()) { localInstances = calendar->instances(localBaseIncidence); } // first save the added/updated base incidence LOG_DEBUG("Saving the added/updated base incidence before saving persistent exceptions:" << incidences[parentIndex]->uid()); - KCalCore::Incidence::Ptr updatedBaseIncidence = incidences[parentIndex]; + KCalendarCore::Incidence::Ptr updatedBaseIncidence = incidences[parentIndex]; updateIncidence(calendar, notebook, updatedBaseIncidence, &criticalError, printDebug); // update the base incidence first. if (criticalError) { qWarning() << "Error saving base incidence:" << updatedBaseIncidence->uid(); @@ -743,14 +744,14 @@ namespace CalendarImportExport { } // update persistent exceptions which are in the import list. - QList importRecurrenceIds; + QList importRecurrenceIds; for (int i = 0; i < incidences.size(); ++i) { if (i == parentIndex) { continue; // already handled this one. } LOG_DEBUG("Now saving a persistent exception:" << incidences[i]->recurrenceId().toString()); - KCalCore::Incidence::Ptr importInstance = incidences[i]; + KCalendarCore::Incidence::Ptr importInstance = incidences[i]; importRecurrenceIds.append(importInstance->recurrenceId()); updateIncidence(calendar, notebook, importInstance, &criticalError, printDebug); if (criticalError) { @@ -763,7 +764,7 @@ namespace CalendarImportExport { if (destructiveImport) { // remove persistent exceptions which are not in the import list. for (int i = 0; i < localInstances.size(); ++i) { - KCalCore::Incidence::Ptr localInstance = localInstances[i]; + KCalendarCore::Incidence::Ptr localInstance = localInstances[i]; if (!importRecurrenceIds.contains(localInstance->recurrenceId())) { LOG_DEBUG("Removing rolled-back persistent occurrence:" << localInstance->uid() << localInstance->recurrenceId().toString()); if (!calendar->deleteIncidence(localInstance)) { @@ -850,7 +851,7 @@ int main(int argc, char *argv[]) if (parser.positionalArguments().length() != 2) parser.showHelp(); const QString backupFile = parser.positionalArguments().at(1); - QString exportIcsData = CalendarImportExport::constructExportIcs(parser.value("notebook"), QString(), KDateTime(), verbose); + QString exportIcsData = CalendarImportExport::constructExportIcs(parser.value("notebook"), QString(), QDateTime(), verbose); if (exportIcsData.isEmpty()) { qWarning() << "No data to export!"; return 0;