Changeset View
Changeset View
Standalone View
Standalone View
src/eventarchiver.cpp
Show All 23 Lines | |||||
24 | 24 | | |||
25 | #include "eventarchiver.h" | 25 | #include "eventarchiver.h" | ||
26 | 26 | | |||
27 | #include "kcalprefs.h" | 27 | #include "kcalprefs.h" | ||
28 | #include "utils.h" | 28 | #include "utils.h" | ||
29 | 29 | | |||
30 | #include <Akonadi/Calendar/IncidenceChanger> | 30 | #include <Akonadi/Calendar/IncidenceChanger> | ||
31 | 31 | | |||
32 | #include <KCalCore/ICalFormat> | 32 | #include <KCalendarCore/ICalFormat> | ||
33 | #include <KCalCore/FileStorage> | 33 | #include <KCalendarCore/FileStorage> | ||
34 | #include <KCalCore/MemoryCalendar> | 34 | #include <KCalendarCore/MemoryCalendar> | ||
35 | 35 | | |||
36 | #include <KCalUtils/Stringify> | 36 | #include <KCalUtils/Stringify> | ||
37 | 37 | | |||
38 | #include "calendarsupport_debug.h" | 38 | #include "calendarsupport_debug.h" | ||
39 | #include <KLocalizedString> | 39 | #include <KLocalizedString> | ||
40 | #include <KMessageBox> | 40 | #include <KMessageBox> | ||
41 | #include <KIO/FileCopyJob> | 41 | #include <KIO/FileCopyJob> | ||
42 | #include <KIO/StatJob> | 42 | #include <KIO/StatJob> | ||
43 | #include <KJobWidgets> | 43 | #include <KJobWidgets> | ||
44 | 44 | | |||
45 | #include <QLocale> | 45 | #include <QLocale> | ||
46 | #include <QTemporaryFile> | 46 | #include <QTemporaryFile> | ||
47 | #include <QTimeZone> | 47 | #include <QTimeZone> | ||
48 | 48 | | |||
49 | using namespace KCalCore; | 49 | using namespace KCalendarCore; | ||
50 | using namespace KCalUtils; | 50 | using namespace KCalUtils; | ||
51 | using namespace CalendarSupport; | 51 | using namespace CalendarSupport; | ||
52 | 52 | | |||
53 | class GroupwareScoppedDisabler | 53 | class GroupwareScoppedDisabler | ||
54 | { | 54 | { | ||
55 | public: | 55 | public: | ||
56 | GroupwareScoppedDisabler(Akonadi::IncidenceChanger *changer) : m_changer(changer) | 56 | GroupwareScoppedDisabler(Akonadi::IncidenceChanger *changer) : m_changer(changer) | ||
57 | { | 57 | { | ||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Line(s) | |||||
107 | 107 | | |||
108 | void EventArchiver::run(const Akonadi::ETMCalendar::Ptr &calendar, | 108 | void EventArchiver::run(const Akonadi::ETMCalendar::Ptr &calendar, | ||
109 | Akonadi::IncidenceChanger *changer, const QDate &limitDate, QWidget *widget, | 109 | Akonadi::IncidenceChanger *changer, const QDate &limitDate, QWidget *widget, | ||
110 | bool withGUI, bool errorIfNone) | 110 | bool withGUI, bool errorIfNone) | ||
111 | { | 111 | { | ||
112 | GroupwareScoppedDisabler disabler(changer); // Disables groupware communication temporarily | 112 | GroupwareScoppedDisabler disabler(changer); // Disables groupware communication temporarily | ||
113 | 113 | | |||
114 | // We need to use rawEvents, otherwise events hidden by filters will not be archived. | 114 | // We need to use rawEvents, otherwise events hidden by filters will not be archived. | ||
115 | KCalCore::Event::List events; | 115 | KCalendarCore::Event::List events; | ||
116 | KCalCore::Todo::List todos; | 116 | KCalendarCore::Todo::List todos; | ||
117 | KCalCore::Journal::List journals; | 117 | KCalendarCore::Journal::List journals; | ||
118 | 118 | | |||
119 | if (KCalPrefs::instance()->mArchiveEvents) { | 119 | if (KCalPrefs::instance()->mArchiveEvents) { | ||
120 | events = calendar->rawEvents( | 120 | events = calendar->rawEvents( | ||
121 | QDate(1769, 12, 1), | 121 | QDate(1769, 12, 1), | ||
122 | // #29555, also advertised by the "limitDate not included" in the class docu | 122 | // #29555, also advertised by the "limitDate not included" in the class docu | ||
123 | limitDate.addDays(-1), | 123 | limitDate.addDays(-1), | ||
124 | QTimeZone::systemTimeZone(), | 124 | QTimeZone::systemTimeZone(), | ||
125 | true); | 125 | true); | ||
126 | } | 126 | } | ||
127 | if (KCalPrefs::instance()->mArchiveTodos) { | 127 | if (KCalPrefs::instance()->mArchiveTodos) { | ||
128 | const KCalCore::Todo::List rawTodos = calendar->rawTodos(); | 128 | const KCalendarCore::Todo::List rawTodos = calendar->rawTodos(); | ||
129 | 129 | | |||
130 | for (const KCalCore::Todo::Ptr &todo : rawTodos) { | 130 | for (const KCalendarCore::Todo::Ptr &todo : rawTodos) { | ||
131 | Q_ASSERT(todo); | 131 | Q_ASSERT(todo); | ||
132 | if (isSubTreeComplete(calendar, todo, limitDate)) { | 132 | if (isSubTreeComplete(calendar, todo, limitDate)) { | ||
133 | todos.append(todo); | 133 | todos.append(todo); | ||
134 | } | 134 | } | ||
135 | } | 135 | } | ||
136 | } | 136 | } | ||
137 | 137 | | |||
138 | const KCalCore::Incidence::List incidences = calendar->mergeIncidenceList(events, todos, | 138 | const KCalendarCore::Incidence::List incidences = calendar->mergeIncidenceList(events, todos, | ||
139 | journals); | 139 | journals); | ||
140 | 140 | | |||
141 | qCDebug(CALENDARSUPPORT_LOG) << "archiving incidences before" << limitDate | 141 | qCDebug(CALENDARSUPPORT_LOG) << "archiving incidences before" << limitDate | ||
142 | << " ->" << incidences.count() << " incidences found."; | 142 | << " ->" << incidences.count() << " incidences found."; | ||
143 | if (incidences.isEmpty()) { | 143 | if (incidences.isEmpty()) { | ||
144 | if (withGUI && errorIfNone) { | 144 | if (withGUI && errorIfNone) { | ||
145 | KMessageBox::information(widget, | 145 | KMessageBox::information(widget, | ||
146 | i18n("There are no items before %1", | 146 | i18n("There are no items before %1", | ||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Line(s) | 167 | { | |||
189 | changer->deleteIncidences(items, /**parent=*/ widget); | 189 | changer->deleteIncidences(items, /**parent=*/ widget); | ||
190 | 190 | | |||
191 | // TODO: Q_EMIT only after hearing back from incidence changer | 191 | // TODO: Q_EMIT only after hearing back from incidence changer | ||
192 | Q_EMIT eventsDeleted(); | 192 | Q_EMIT eventsDeleted(); | ||
193 | } | 193 | } | ||
194 | 194 | | |||
195 | void EventArchiver::archiveIncidences(const Akonadi::ETMCalendar::Ptr &calendar, | 195 | void EventArchiver::archiveIncidences(const Akonadi::ETMCalendar::Ptr &calendar, | ||
196 | Akonadi::IncidenceChanger *changer, const QDate &limitDate, | 196 | Akonadi::IncidenceChanger *changer, const QDate &limitDate, | ||
197 | QWidget *widget, const KCalCore::Incidence::List &incidences, | 197 | QWidget *widget, const KCalendarCore::Incidence::List &incidences, | ||
198 | bool withGUI) | 198 | bool withGUI) | ||
199 | { | 199 | { | ||
200 | Q_UNUSED(limitDate); | 200 | Q_UNUSED(limitDate); | ||
201 | Q_UNUSED(withGUI); | 201 | Q_UNUSED(withGUI); | ||
202 | 202 | | |||
203 | FileStorage storage(calendar); | 203 | FileStorage storage(calendar); | ||
204 | 204 | | |||
205 | QString tmpFileName; | 205 | QString tmpFileName; | ||
Show All 26 Lines | 229 | if (!archiveStore.load()) { | |||
232 | return; | 232 | return; | ||
233 | } | 233 | } | ||
234 | 234 | | |||
235 | // Strip active events from calendar so that only events to be archived | 235 | // Strip active events from calendar so that only events to be archived | ||
236 | // remain. This is not really efficient, but there is no other easy way. | 236 | // remain. This is not really efficient, but there is no other easy way. | ||
237 | QStringList uids; | 237 | QStringList uids; | ||
238 | Incidence::List allIncidences = archiveCalendar->rawIncidences(); | 238 | Incidence::List allIncidences = archiveCalendar->rawIncidences(); | ||
239 | uids.reserve(incidences.count()); | 239 | uids.reserve(incidences.count()); | ||
240 | for (const KCalCore::Incidence::Ptr &incidence : qAsConst(incidences)) { | 240 | for (const KCalendarCore::Incidence::Ptr &incidence : qAsConst(incidences)) { | ||
241 | uids.append(incidence->uid()); | 241 | uids.append(incidence->uid()); | ||
242 | } | 242 | } | ||
243 | for (const KCalCore::Incidence::Ptr &incidence : qAsConst(allIncidences)) { | 243 | for (const KCalendarCore::Incidence::Ptr &incidence : qAsConst(allIncidences)) { | ||
244 | if (!uids.contains(incidence->uid())) { | 244 | if (!uids.contains(incidence->uid())) { | ||
245 | archiveCalendar->deleteIncidence(incidence); | 245 | archiveCalendar->deleteIncidence(incidence); | ||
246 | } | 246 | } | ||
247 | } | 247 | } | ||
248 | 248 | | |||
249 | // Get or create the archive file | 249 | // Get or create the archive file | ||
250 | QUrl archiveURL(KCalPrefs::instance()->mArchiveFile); | 250 | QUrl archiveURL(KCalPrefs::instance()->mArchiveFile); | ||
251 | QString archiveFile; | 251 | QString archiveFile; | ||
▲ Show 20 Lines • Show All 80 Lines • ▼ Show 20 Line(s) | 327 | { | |||
332 | // This QList is only to prevent infinit recursion | 332 | // This QList is only to prevent infinit recursion | ||
333 | if (checkedUids.contains(todo->uid())) { | 333 | if (checkedUids.contains(todo->uid())) { | ||
334 | // Probably will never happen, calendar.cpp checks for this | 334 | // Probably will never happen, calendar.cpp checks for this | ||
335 | qCWarning(CALENDARSUPPORT_LOG) << "To-do hierarchy loop detected!"; | 335 | qCWarning(CALENDARSUPPORT_LOG) << "To-do hierarchy loop detected!"; | ||
336 | return false; | 336 | return false; | ||
337 | } | 337 | } | ||
338 | 338 | | |||
339 | checkedUids.append(todo->uid()); | 339 | checkedUids.append(todo->uid()); | ||
340 | const KCalCore::Incidence::List childs = calendar->childIncidences(todo->uid()); | 340 | const KCalendarCore::Incidence::List childs = calendar->childIncidences(todo->uid()); | ||
341 | for (const KCalCore::Incidence::Ptr &incidence : childs) { | 341 | for (const KCalendarCore::Incidence::Ptr &incidence : childs) { | ||
342 | const Todo::Ptr t = incidence.dynamicCast<KCalCore::Todo>(); | 342 | const Todo::Ptr t = incidence.dynamicCast<KCalendarCore::Todo>(); | ||
343 | if (t && !isSubTreeComplete(calendar, t, limitDate, checkedUids)) { | 343 | if (t && !isSubTreeComplete(calendar, t, limitDate, checkedUids)) { | ||
344 | return false; | 344 | return false; | ||
345 | } | 345 | } | ||
346 | } | 346 | } | ||
347 | 347 | | |||
348 | return true; | 348 | return true; | ||
349 | } | 349 | } |