Changeset View
Changeset View
Standalone View
Standalone View
src/akonadi/akonaditaskrepository.cpp
Show First 20 Lines • Show All 121 Lines • ▼ Show 20 Line(s) | 117 | { | |||
---|---|---|---|---|---|
122 | 122 | | |||
123 | return createItem(item); | 123 | return createItem(item); | ||
124 | } | 124 | } | ||
125 | 125 | | |||
126 | KJob *TaskRepository::update(Domain::Task::Ptr task) | 126 | KJob *TaskRepository::update(Domain::Task::Ptr task) | ||
127 | { | 127 | { | ||
128 | auto item = m_serializer->createItemFromTask(task); | 128 | auto item = m_serializer->createItemFromTask(task); | ||
129 | Q_ASSERT(item.isValid()); | 129 | Q_ASSERT(item.isValid()); | ||
130 | return m_storage->updateItem(item); | 130 | return m_storage->updateItem(item, this); | ||
131 | } | 131 | } | ||
132 | 132 | | |||
133 | KJob *TaskRepository::remove(Domain::Task::Ptr task) | 133 | KJob *TaskRepository::remove(Domain::Task::Ptr task) | ||
134 | { | 134 | { | ||
135 | auto item = m_serializer->createItemFromTask(task); | 135 | auto item = m_serializer->createItemFromTask(task); | ||
136 | Q_ASSERT(item.isValid()); | 136 | Q_ASSERT(item.isValid()); | ||
137 | 137 | | |||
138 | auto compositeJob = new CompositeJob(); | 138 | auto compositeJob = new CompositeJob(); | ||
139 | ItemFetchJobInterface *fetchItemJob = m_storage->fetchItem(item, this); | 139 | ItemFetchJobInterface *fetchItemJob = m_storage->fetchItem(item, this); | ||
140 | compositeJob->install(fetchItemJob->kjob(), [fetchItemJob, compositeJob, this] { | 140 | compositeJob->install(fetchItemJob->kjob(), [fetchItemJob, compositeJob, this] { | ||
141 | if (fetchItemJob->kjob()->error() != KJob::NoError) | 141 | if (fetchItemJob->kjob()->error() != KJob::NoError) | ||
142 | return; | 142 | return; | ||
143 | 143 | | |||
144 | Q_ASSERT(fetchItemJob->items().size() == 1); | 144 | Q_ASSERT(fetchItemJob->items().size() == 1); | ||
145 | auto item = fetchItemJob->items().at(0); | 145 | auto item = fetchItemJob->items().at(0); | ||
146 | 146 | | |||
147 | ItemFetchJobInterface *fetchCollectionItemsJob = m_storage->fetchItems(item.parentCollection(), this); | 147 | ItemFetchJobInterface *fetchCollectionItemsJob = m_storage->fetchItems(item.parentCollection(), this); | ||
148 | compositeJob->install(fetchCollectionItemsJob->kjob(), [fetchCollectionItemsJob, item, compositeJob, this] { | 148 | compositeJob->install(fetchCollectionItemsJob->kjob(), [fetchCollectionItemsJob, item, compositeJob, this] { | ||
149 | if (fetchCollectionItemsJob->kjob()->error() != KJob::NoError) | 149 | if (fetchCollectionItemsJob->kjob()->error() != KJob::NoError) | ||
150 | return; | 150 | return; | ||
151 | 151 | | |||
152 | Item::List childItems = m_serializer->filterDescendantItems(fetchCollectionItemsJob->items(), item); | 152 | Item::List childItems = m_serializer->filterDescendantItems(fetchCollectionItemsJob->items(), item); | ||
153 | childItems << item; | 153 | childItems << item; | ||
154 | 154 | | |||
155 | auto removeJob = m_storage->removeItems(childItems); | 155 | auto removeJob = m_storage->removeItems(childItems, this); | ||
156 | compositeJob->addSubjob(removeJob); | 156 | compositeJob->addSubjob(removeJob); | ||
157 | removeJob->start(); | 157 | removeJob->start(); | ||
158 | }); | 158 | }); | ||
159 | }); | 159 | }); | ||
160 | 160 | | |||
161 | return compositeJob; | 161 | return compositeJob; | ||
162 | } | 162 | } | ||
163 | 163 | | |||
164 | KJob *TaskRepository::promoteToProject(Domain::Task::Ptr task) | 164 | KJob *TaskRepository::promoteToProject(Domain::Task::Ptr task) | ||
165 | { | 165 | { | ||
166 | auto item = m_serializer->createItemFromTask(task); | 166 | auto item = m_serializer->createItemFromTask(task); | ||
167 | 167 | | |||
168 | auto job = new CompositeJob(); | 168 | auto job = new CompositeJob(); | ||
169 | auto fetchJob = m_storage->fetchItem(item, this); | 169 | auto fetchJob = m_storage->fetchItem(item, this); | ||
170 | job->install(fetchJob->kjob(), [fetchJob, job, this] { | 170 | job->install(fetchJob->kjob(), [fetchJob, job, this] { | ||
171 | if (fetchJob->kjob()->error() != KJob::NoError) | 171 | if (fetchJob->kjob()->error() != KJob::NoError) | ||
172 | return; | 172 | return; | ||
173 | 173 | | |||
174 | Q_ASSERT(fetchJob->items().size() == 1); | 174 | Q_ASSERT(fetchJob->items().size() == 1); | ||
175 | auto item = fetchJob->items().at(0); | 175 | auto item = fetchJob->items().at(0); | ||
176 | m_serializer->promoteItemToProject(item); | 176 | m_serializer->promoteItemToProject(item); | ||
177 | 177 | | |||
178 | auto updateJob = m_storage->updateItem(item); | 178 | auto updateJob = m_storage->updateItem(item, this); | ||
179 | job->addSubjob(updateJob); | 179 | job->addSubjob(updateJob); | ||
180 | updateJob->start(); | 180 | updateJob->start(); | ||
181 | }); | 181 | }); | ||
182 | return job; | 182 | return job; | ||
183 | } | 183 | } | ||
184 | 184 | | |||
185 | KJob *TaskRepository::associate(Domain::Task::Ptr parent, Domain::Task::Ptr child) | 185 | KJob *TaskRepository::associate(Domain::Task::Ptr parent, Domain::Task::Ptr child) | ||
186 | { | 186 | { | ||
▲ Show 20 Lines • Show All 55 Lines • ▼ Show 20 Line(s) | 236 | job->install(fetchChildrenItemJob->kjob(), [fetchChildrenItemJob, childItem, parentItem, job, this] { | |||
242 | auto transaction = m_storage->createTransaction(); | 242 | auto transaction = m_storage->createTransaction(); | ||
243 | m_storage->updateItem(childItem, transaction); | 243 | m_storage->updateItem(childItem, transaction); | ||
244 | childItems.push_front(childItem); | 244 | childItems.push_front(childItem); | ||
245 | m_storage->moveItems(childItems, parentItem.parentCollection(), transaction); | 245 | m_storage->moveItems(childItems, parentItem.parentCollection(), transaction); | ||
246 | job->addSubjob(transaction); | 246 | job->addSubjob(transaction); | ||
247 | transaction->start(); | 247 | transaction->start(); | ||
248 | }); | 248 | }); | ||
249 | } else { | 249 | } else { | ||
250 | auto updateJob = m_storage->updateItem(childItem); | 250 | auto updateJob = m_storage->updateItem(childItem, this); | ||
251 | job->addSubjob(updateJob); | 251 | job->addSubjob(updateJob); | ||
252 | updateJob->start(); | 252 | updateJob->start(); | ||
253 | } | 253 | } | ||
254 | }); | 254 | }); | ||
255 | }); | 255 | }); | ||
256 | 256 | | |||
257 | return job; | 257 | return job; | ||
258 | } | 258 | } | ||
259 | 259 | | |||
260 | KJob *TaskRepository::dissociate(Domain::Task::Ptr child) | 260 | KJob *TaskRepository::dissociate(Domain::Task::Ptr child) | ||
261 | { | 261 | { | ||
262 | auto job = new CompositeJob(); | 262 | auto job = new CompositeJob(); | ||
263 | auto childItem = m_serializer->createItemFromTask(child); | 263 | auto childItem = m_serializer->createItemFromTask(child); | ||
264 | ItemFetchJobInterface *fetchItemJob = m_storage->fetchItem(childItem, this); | 264 | ItemFetchJobInterface *fetchItemJob = m_storage->fetchItem(childItem, this); | ||
265 | job->install(fetchItemJob->kjob(), [fetchItemJob, job, this] { | 265 | job->install(fetchItemJob->kjob(), [fetchItemJob, job, this] { | ||
266 | if (fetchItemJob->kjob()->error() != KJob::NoError) | 266 | if (fetchItemJob->kjob()->error() != KJob::NoError) | ||
267 | return; | 267 | return; | ||
268 | 268 | | |||
269 | Q_ASSERT(fetchItemJob->items().size() == 1); | 269 | Q_ASSERT(fetchItemJob->items().size() == 1); | ||
270 | auto childItem = fetchItemJob->items().at(0); | 270 | auto childItem = fetchItemJob->items().at(0); | ||
271 | 271 | | |||
272 | m_serializer->removeItemParent(childItem); | 272 | m_serializer->removeItemParent(childItem); | ||
273 | 273 | | |||
274 | auto updateJob = m_storage->updateItem(childItem); | 274 | auto updateJob = m_storage->updateItem(childItem, this); | ||
275 | job->addSubjob(updateJob); | 275 | job->addSubjob(updateJob); | ||
276 | updateJob->start(); | 276 | updateJob->start(); | ||
277 | }); | 277 | }); | ||
278 | 278 | | |||
279 | return job; | 279 | return job; | ||
280 | } | 280 | } | ||
281 | 281 | | |||
282 | KJob *TaskRepository::dissociateAll(Domain::Task::Ptr child) | 282 | KJob *TaskRepository::dissociateAll(Domain::Task::Ptr child) | ||
283 | { | 283 | { | ||
284 | auto job = new CompositeJob(); | 284 | auto job = new CompositeJob(); | ||
285 | auto childItem = m_serializer->createItemFromTask(child); | 285 | auto childItem = m_serializer->createItemFromTask(child); | ||
286 | ItemFetchJobInterface *fetchItemJob = m_storage->fetchItem(childItem, this); | 286 | ItemFetchJobInterface *fetchItemJob = m_storage->fetchItem(childItem, this); | ||
287 | job->install(fetchItemJob->kjob(), [fetchItemJob, job, this] { | 287 | job->install(fetchItemJob->kjob(), [fetchItemJob, job, this] { | ||
288 | if (fetchItemJob->kjob()->error() != KJob::NoError) | 288 | if (fetchItemJob->kjob()->error() != KJob::NoError) | ||
289 | return; | 289 | return; | ||
290 | 290 | | |||
291 | Q_ASSERT(fetchItemJob->items().size() == 1); | 291 | Q_ASSERT(fetchItemJob->items().size() == 1); | ||
292 | auto childItem = fetchItemJob->items().at(0); | 292 | auto childItem = fetchItemJob->items().at(0); | ||
293 | 293 | | |||
294 | m_serializer->removeItemParent(childItem); | 294 | m_serializer->removeItemParent(childItem); | ||
295 | m_serializer->clearItem(&childItem); | 295 | m_serializer->clearItem(&childItem); | ||
296 | 296 | | |||
297 | auto updateJob = m_storage->updateItem(childItem); | 297 | auto updateJob = m_storage->updateItem(childItem, this); | ||
298 | job->addSubjob(updateJob); | 298 | job->addSubjob(updateJob); | ||
299 | updateJob->start(); | 299 | updateJob->start(); | ||
300 | }); | 300 | }); | ||
301 | 301 | | |||
302 | return job; | 302 | return job; | ||
303 | } | 303 | } |