Skip to content

Add a flag not to update the lastModified field automatically.

Damien Caliste requested to merge dcaliste/kcalendarcore:update into master

I'm wondering if such change can have a general interest. I'm explaining the context: it's about a process responsible for syncing a local storage with some server content using CalDAV RFC.

The already stored incidences are represented in memory via a specialisation of a MemoryCalendar object. This specialisation ensures that modifications done to the incidences in the calendar are synced to a permanent storage like a SQlite database. This permanent storage inherits from CalStorage and is an observer of my MemoryCalendar.

Modifications are retrieved from the server and applied to the incidences in my MemoryCalendar. Doing so triggers for every modified incidence the incidenceUpdated() code of MemoryCalendar class, which itself calls the notifyIncidenceChanged() of my CalStorage resulting in the end, with the modifications being stored in my SQlite database. So far so good.

But the internals of MemoryCalendar::incidenceUpdated() actually change unconditionnally the lastModified field of the incidence which is a "public" field of the iCal data. So to keep it in sync with the server, I need to apply tricks like:

storedIncidence->startUpdates();
*storedIncidence = *receivedIncidence;
storedIncidence->endUpdates();
storedIncidence->setLastModified(receivedIncidence->lastModified());

Or in another part of the sync code, when I set a custom property like the etag value for instance:

const QDateTime dt(incidence->lastModified());
incidence->setCustomProperty("VOLATILE", "ETAG", etag);
incidence->setLastModified(dt);

The patch I'm proposing here is adding a flag to MemoryCalendar object to update or not the lastModified field on change. I'm doing it in MemoryCalendar since it's this class that adds itself as an incidence observer when calling addIncidence() (and not its parent class), and it's in the observer callback that the lastModified field is changed. Removing the incidence observer is not an option since I still want the incidenceUpdated() code to be called so the internal arrays like the mIncidencesForDate are still consistent, and also because I want my CalStorage observer to be notify of any incidence changes so they can be propagated to the SQlite database.

@winterz if you think that the use case is valid, but you have a better solution than a flag in MemoryCalendar for this, please comment.

Merge request reports