Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #58 from nemomobile/deleteorphans
[nemo-qml-plugin-calendar] Detect orphan events. Contributes to MER#1247
  • Loading branch information
Chris Adams committed Aug 31, 2015
2 parents 97ee79a + 5a59c9c commit 39f20be
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/calendarworker.cpp
Expand Up @@ -553,12 +553,32 @@ void NemoCalendarWorker::loadData(const QList<NemoCalendarData::Range> &ranges,

QMultiHash<QString, NemoCalendarData::Event> events;
QMultiHash<QString, KDateTime> allDay;
bool orphansDeleted = false;

foreach (const KCalCore::Event::Ptr e, list) {
// The database may have changed after loading the events, make sure that the notebook
// of the event still exists.
if (mStorage->notebook(mCalendar->notebook(e)).isNull())
if (mStorage->notebook(mCalendar->notebook(e)).isNull()) {
// This may be a symptom of a deeper bug: if a sync adapter (or mkcal)
// 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());
if (!orphan.isNull()) {
bool deletedOrphanOccurrences = mCalendar->deleteIncidenceInstances(orphan);
bool deletedOrphanSeries = mCalendar->deleteIncidence(orphan);
if (deletedOrphanOccurrences || deletedOrphanSeries) {
qWarning() << "Deleted orphan calendar event:" << orphan->uid()
<< orphan->summary() << orphan->description() << orphan->location();
orphansDeleted = true;
} else {
qWarning() << "Failed to delete orphan calendar event:" << orphan->uid()
<< orphan->summary() << orphan->description() << orphan->location();
}
}
}
continue;
}

NemoCalendarData::Event event = createEventStruct(e);

Expand All @@ -570,6 +590,10 @@ void NemoCalendarWorker::loadData(const QList<NemoCalendarData::Range> &ranges,
}
}

if (orphansDeleted) {
save(); // save the orphan deletions to storage.
}

QHash<QString, NemoCalendarData::EventOccurrence> occurrences = eventOccurrences(ranges);
QHash<QDate, QStringList> dailyOccurrences = dailyEventOccurrences(ranges, allDay, occurrences.values());

Expand Down

0 comments on commit 39f20be

Please sign in to comment.