Changeset View
Changeset View
Standalone View
Standalone View
src/calendarutils.cpp
Show All 22 Lines | |||||
23 | // NOTE: The code of the following methods is taken from | 23 | // NOTE: The code of the following methods is taken from | ||
24 | // kdepim/korganizer/calendarview.cpp: | 24 | // kdepim/korganizer/calendarview.cpp: | ||
25 | // - makeIndependent (was incidence_unsub) | 25 | // - makeIndependent (was incidence_unsub) | ||
26 | // - makeChildrenIndependent | 26 | // - makeChildrenIndependent | ||
27 | 27 | | |||
28 | #include "calendarutils.h" | 28 | #include "calendarutils.h" | ||
29 | #include "utils.h" | 29 | #include "utils.h" | ||
30 | 30 | | |||
31 | #include <KCalCore/Incidence> | 31 | #include <KCalendarCore/Incidence> | ||
32 | #include <Akonadi/Calendar/ETMCalendar> | 32 | #include <Akonadi/Calendar/ETMCalendar> | ||
33 | #include <Akonadi/Calendar/IncidenceChanger> | 33 | #include <Akonadi/Calendar/IncidenceChanger> | ||
34 | 34 | | |||
35 | #include <KLocalizedString> | 35 | #include <KLocalizedString> | ||
36 | #include <KMessageBox> | 36 | #include <KMessageBox> | ||
37 | #include "calendarsupport_debug.h" | 37 | #include "calendarsupport_debug.h" | ||
38 | 38 | | |||
39 | using namespace CalendarSupport; | 39 | using namespace CalendarSupport; | ||
40 | using namespace KCalCore; | 40 | using namespace KCalendarCore; | ||
41 | 41 | | |||
42 | /// CalendarUtilsPrivate | 42 | /// CalendarUtilsPrivate | ||
43 | 43 | | |||
44 | struct MultiChange { | 44 | struct MultiChange { | ||
45 | Akonadi::Item parent; | 45 | Akonadi::Item parent; | ||
46 | QVector<Akonadi::Item::Id> children; | 46 | QVector<Akonadi::Item::Id> children; | ||
47 | bool success; | 47 | bool success; | ||
48 | 48 | | |||
Show All 14 Lines | |||||
63 | { | 63 | { | ||
64 | public: | 64 | public: | ||
65 | /// Methods | 65 | /// Methods | ||
66 | CalendarUtilsPrivate(const Akonadi::ETMCalendar::Ptr &calendar, CalendarUtils *qq); | 66 | CalendarUtilsPrivate(const Akonadi::ETMCalendar::Ptr &calendar, CalendarUtils *qq); | ||
67 | void handleChangeFinish(int changeId, const Akonadi::Item &item, | 67 | void handleChangeFinish(int changeId, const Akonadi::Item &item, | ||
68 | Akonadi::IncidenceChanger::ResultCode resultCode, | 68 | Akonadi::IncidenceChanger::ResultCode resultCode, | ||
69 | const QString &errorString); | 69 | const QString &errorString); | ||
70 | 70 | | |||
71 | bool purgeCompletedSubTodos(const KCalCore::Todo::Ptr &todo, bool &allPurged); | 71 | bool purgeCompletedSubTodos(const KCalendarCore::Todo::Ptr &todo, bool &allPurged); | ||
72 | 72 | | |||
73 | /// Members | 73 | /// Members | ||
74 | Akonadi::ETMCalendar::Ptr mCalendar; | 74 | Akonadi::ETMCalendar::Ptr mCalendar; | ||
75 | Akonadi::IncidenceChanger *mChanger = nullptr; | 75 | Akonadi::IncidenceChanger *mChanger = nullptr; | ||
76 | MultiChange mMultiChange; | 76 | MultiChange mMultiChange; | ||
77 | 77 | | |||
78 | private: | 78 | private: | ||
79 | CalendarUtils *const q_ptr; | 79 | CalendarUtils *const q_ptr; | ||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Line(s) | 126 | if (success) { | |||
128 | Q_EMIT q->actionFinished(item); | 128 | Q_EMIT q->actionFinished(item); | ||
129 | } else { | 129 | } else { | ||
130 | qCDebug(CALENDARSUPPORT_LOG) << "Change failed"; | 130 | qCDebug(CALENDARSUPPORT_LOG) << "Change failed"; | ||
131 | Q_EMIT q->actionFailed(Akonadi::Item(), errorString); | 131 | Q_EMIT q->actionFailed(Akonadi::Item(), errorString); | ||
132 | } | 132 | } | ||
133 | } | 133 | } | ||
134 | } | 134 | } | ||
135 | 135 | | |||
136 | bool CalendarUtilsPrivate::purgeCompletedSubTodos(const KCalCore::Todo::Ptr &todo, bool &allPurged) | 136 | bool CalendarUtilsPrivate::purgeCompletedSubTodos(const KCalendarCore::Todo::Ptr &todo, bool &allPurged) | ||
137 | { | 137 | { | ||
138 | if (!todo) { | 138 | if (!todo) { | ||
139 | return true; | 139 | return true; | ||
140 | } | 140 | } | ||
141 | 141 | | |||
142 | bool deleteThisTodo = true; | 142 | bool deleteThisTodo = true; | ||
143 | const Akonadi::Item::List subTodos = mCalendar->childItems(todo->uid()); | 143 | const Akonadi::Item::List subTodos = mCalendar->childItems(todo->uid()); | ||
144 | for (const Akonadi::Item &item : subTodos) { | 144 | for (const Akonadi::Item &item : subTodos) { | ||
145 | if (CalendarSupport::hasTodo(item)) { | 145 | if (CalendarSupport::hasTodo(item)) { | ||
146 | deleteThisTodo | 146 | deleteThisTodo | ||
147 | &= purgeCompletedSubTodos(item.payload<KCalCore::Todo::Ptr>(), allPurged); | 147 | &= purgeCompletedSubTodos(item.payload<KCalendarCore::Todo::Ptr>(), allPurged); | ||
148 | } | 148 | } | ||
149 | } | 149 | } | ||
150 | 150 | | |||
151 | if (deleteThisTodo) { | 151 | if (deleteThisTodo) { | ||
152 | if (todo->isCompleted()) { | 152 | if (todo->isCompleted()) { | ||
153 | if (!mChanger->deleteIncidence(mCalendar->item(todo), nullptr)) { | 153 | if (!mChanger->deleteIncidence(mCalendar->item(todo), nullptr)) { | ||
154 | allPurged = false; | 154 | allPurged = false; | ||
155 | } | 155 | } | ||
▲ Show 20 Lines • Show All 79 Lines • ▼ Show 20 Line(s) | |||||
235 | 235 | | |||
236 | /// Todo specific methods. | 236 | /// Todo specific methods. | ||
237 | 237 | | |||
238 | void CalendarUtils::purgeCompletedTodos() | 238 | void CalendarUtils::purgeCompletedTodos() | ||
239 | { | 239 | { | ||
240 | Q_D(CalendarUtils); | 240 | Q_D(CalendarUtils); | ||
241 | bool allDeleted = true; | 241 | bool allDeleted = true; | ||
242 | // startMultiModify( i18n( "Purging completed to-dos" ) ); | 242 | // startMultiModify( i18n( "Purging completed to-dos" ) ); | ||
243 | KCalCore::Todo::List todos = calendar()->rawTodos(); | 243 | KCalendarCore::Todo::List todos = calendar()->rawTodos(); | ||
244 | KCalCore::Todo::List rootTodos; | 244 | KCalendarCore::Todo::List rootTodos; | ||
245 | 245 | | |||
246 | for (const KCalCore::Todo::Ptr &todo : qAsConst(todos)) { | 246 | for (const KCalendarCore::Todo::Ptr &todo : qAsConst(todos)) { | ||
247 | if (todo && todo->relatedTo().isEmpty()) { // top level todo //REVIEW(AKONADI_PORT) | 247 | if (todo && todo->relatedTo().isEmpty()) { // top level todo //REVIEW(AKONADI_PORT) | ||
248 | rootTodos.append(todo); | 248 | rootTodos.append(todo); | ||
249 | } | 249 | } | ||
250 | } | 250 | } | ||
251 | 251 | | |||
252 | // now that we have a list of all root todos, check them and their children | 252 | // now that we have a list of all root todos, check them and their children | ||
253 | for (const KCalCore::Todo::Ptr &todo : qAsConst(rootTodos)) { | 253 | for (const KCalendarCore::Todo::Ptr &todo : qAsConst(rootTodos)) { | ||
254 | d->purgeCompletedSubTodos(todo, allDeleted); | 254 | d->purgeCompletedSubTodos(todo, allDeleted); | ||
255 | } | 255 | } | ||
256 | 256 | | |||
257 | // endMultiModify(); | 257 | // endMultiModify(); | ||
258 | if (!allDeleted) { | 258 | if (!allDeleted) { | ||
259 | KMessageBox::information( | 259 | KMessageBox::information( | ||
260 | nullptr, | 260 | nullptr, | ||
261 | i18nc("@info", | 261 | i18nc("@info", | ||
262 | "Unable to purge to-dos with uncompleted children."), | 262 | "Unable to purge to-dos with uncompleted children."), | ||
263 | i18nc("@title:window", "Delete To-do"), | 263 | i18nc("@title:window", "Delete To-do"), | ||
264 | QStringLiteral("UncompletedChildrenPurgeTodos")); | 264 | QStringLiteral("UncompletedChildrenPurgeTodos")); | ||
265 | } | 265 | } | ||
266 | } | 266 | } | ||
267 | 267 | | |||
268 | #include "moc_calendarutils.cpp" | 268 | #include "moc_calendarutils.cpp" |