Index: src/calendar.h =================================================================== --- src/calendar.h +++ src/calendar.h @@ -1349,10 +1349,16 @@ virtual void calendarIncidenceChanged(const Incidence::Ptr &incidence); /** + Notify the Observer that an Incidence will be removed. + @param incidence is a pointer to the Incidence that will be removed. + */ + virtual void calendarIncidenceAboutToBeDeleted(const Incidence::Ptr &incidence); + + /** Notify the Observer that an Incidence has been removed. @param incidence is a pointer to the Incidence that was removed. */ - virtual void calendarIncidenceDeleted(const Incidence::Ptr &incidence); + virtual void calendarIncidenceDeleted(const Incidence::Ptr &incidence, const Calendar *calendar); /** Notify the Observer that an addition of Incidence has been canceled. @@ -1410,8 +1416,14 @@ void notifyIncidenceChanged(const Incidence::Ptr &incidence); /** + Let Calendar subclasses notify that they will remove an Incidence. + @param incidence is a pointer to the Incidence object that will be removed. + */ + void notifyIncidenceAboutToBeDeleted(const Incidence::Ptr &incidence); + + /** Let Calendar subclasses notify that they removed an Incidence. - @param incidence is a pointer to the Incidence object that was removed. + @param incidence is a pointer to the Incidence object that has been removed. */ void notifyIncidenceDeleted(const Incidence::Ptr &incidence); Index: src/calendar.cpp =================================================================== --- src/calendar.cpp +++ src/calendar.cpp @@ -1182,11 +1182,17 @@ Q_UNUSED(incidence); } -void Calendar::CalendarObserver::calendarIncidenceDeleted(const Incidence::Ptr &incidence) +void Calendar::CalendarObserver::calendarIncidenceAboutToBeDeleted(const Incidence::Ptr &incidence) { Q_UNUSED(incidence); } +void Calendar::CalendarObserver::calendarIncidenceDeleted(const Incidence::Ptr &incidence, const Calendar *calendar) +{ + Q_UNUSED(incidence); + Q_UNUSED(calendar); +} + void Calendar::CalendarObserver::calendarIncidenceAdditionCanceled(const Incidence::Ptr &incidence) { @@ -1300,7 +1306,7 @@ } } -void Calendar::notifyIncidenceDeleted(const Incidence::Ptr &incidence) +void Calendar::notifyIncidenceAboutToBeDeleted(const Incidence::Ptr &incidence) { if (!incidence) { return; @@ -1311,7 +1317,22 @@ } foreach (CalendarObserver *observer, d->mObservers) { - observer->calendarIncidenceDeleted(incidence); + observer->calendarIncidenceAboutToBeDeleted(incidence); + } +} + +void Calendar::notifyIncidenceDeleted(const Incidence::Ptr &incidence) +{ + if (!incidence) { + return; + } + + if (!d->mObserversEnabled) { + return; + } + + foreach(CalendarObserver *observer, d->mObservers) { + observer->calendarIncidenceDeleted(incidence, this); } } Index: src/memorycalendar.cpp =================================================================== --- src/memorycalendar.cpp +++ src/memorycalendar.cpp @@ -183,11 +183,16 @@ // we remove relations in deleteIncidence, not in deleteTodo. removeRelations(incidence); const Incidence::IncidenceType type = incidence->type(); + const QString uid = realUid(incidence); - if (d->mIncidences[type].remove(uid, incidence)) { + if (d->mIncidences[type].contains(uid, incidence)) { + // Notify while the incidence is still available, + // this is necessary so korganizer still has time to query for exceptions + notifyIncidenceAboutToBeDeleted(incidence); + + d->mIncidences[type].remove(uid, incidence); d->mIncidencesByIdentifier.remove(realIdentifier(incidence)); setModified(true); - notifyIncidenceDeleted(incidence); if (deletionTracking()) { d->mDeletedIncidences[type].insert(uid, incidence); } @@ -200,6 +205,7 @@ if (!incidence->hasRecurrenceId()) { deleteIncidenceInstances(incidence); } + notifyIncidenceDeleted(incidence); return true; } else { qCWarning(KCALCORE_LOG) << incidence->typeStr() << " not found. uid=" << uid; @@ -233,7 +239,7 @@ QHashIteratori(mIncidences[incidenceType]); while (i.hasNext()) { i.next(); - q->notifyIncidenceDeleted(i.value()); + q->notifyIncidenceAboutToBeDeleted(i.value()); i.value()->unRegisterObserver(q); } mIncidences[incidenceType].clear();