From c1870c362c10d2ab4e9fde474c4deea18b11082c Mon Sep 17 00:00:00 2001 From: Chris Adams Date: Thu, 7 Jan 2021 15:44:26 +1000 Subject: [PATCH] [nemo-qml-plugin-calendar] Purge deleted local events. Contributes to JB#52656 Local calendar events are never synced anywhere, so we can purge them rather than merely marking them as deleted, in order to avoid them remaining in the database (along with their reminder alarms). Note that the purgeDeletedIncidences() call must occur after the call to ExtendedStorage::save() in order to work correctly. --- src/calendarworker.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/calendarworker.cpp b/src/calendarworker.cpp index 50da76a6..1d55a7c0 100644 --- a/src/calendarworker.cpp +++ b/src/calendarworker.cpp @@ -193,11 +193,17 @@ void CalendarWorker::save() if (!mDeletedEvents.isEmpty()) { for (const QPair &pair: mDeletedEvents) { KCalendarCore::Event::Ptr event = mCalendar->deletedEvent(pair.first, pair.second); - if (!needSendCancellation(event)) { - continue; + if (needSendCancellation(event)) { + event->setStatus(KCalendarCore::Incidence::StatusCanceled); + mKCal::ServiceHandler::instance().sendUpdate(event, QString(), mCalendar, mStorage); + } + // if the event was stored in a local (non-synced) notebook, purge it. + const QString notebookUid = mCalendar->notebook(event); + const mKCal::Notebook::Ptr notebook = mStorage->notebook(notebookUid); + if (!notebook.isNull() && notebook->pluginName().isEmpty() && notebook->account().isEmpty() + && !mStorage->purgeDeletedIncidences(KCalendarCore::Incidence::List() << event)) { + qWarning() << "Failed to purge deleted event " << event->uid() << " from local calendar " << notebookUid; } - event->setStatus(KCalendarCore::Incidence::StatusCanceled); - mKCal::ServiceHandler::instance().sendUpdate(event, QString(), mCalendar, mStorage); } mDeletedEvents.clear(); }