Changeset View
Changeset View
Standalone View
Standalone View
src/akonadi/akonadiserializer.cpp
Show All 24 Lines | |||||
25 | 25 | | |||
26 | #include "akonadiserializer.h" | 26 | #include "akonadiserializer.h" | ||
27 | 27 | | |||
28 | #include <AkonadiCore/Collection> | 28 | #include <AkonadiCore/Collection> | ||
29 | #include <AkonadiCore/EntityDisplayAttribute> | 29 | #include <AkonadiCore/EntityDisplayAttribute> | ||
30 | #include <AkonadiCore/Item> | 30 | #include <AkonadiCore/Item> | ||
31 | #include <Akonadi/Notes/NoteUtils> | 31 | #include <Akonadi/Notes/NoteUtils> | ||
32 | #include <KCalCore/Todo> | 32 | #include <KCalCore/Todo> | ||
33 | #include <kcalcore_version.h> | ||||
33 | #include <KMime/Message> | 34 | #include <KMime/Message> | ||
34 | #include <QMimeDatabase> | 35 | #include <QMimeDatabase> | ||
36 | #if KCALCORE_VERSION < QT_VERSION_CHECK(5, 6, 80) | ||||
35 | #include <KDateTime> | 37 | #include <KDateTime> | ||
38 | #endif | ||||
36 | 39 | | |||
37 | #include <numeric> | 40 | #include <numeric> | ||
38 | 41 | | |||
39 | #include "utils/mem_fn.h" | 42 | #include "utils/mem_fn.h" | ||
40 | 43 | | |||
41 | #include "akonadi/akonadiapplicationselectedattribute.h" | 44 | #include "akonadi/akonadiapplicationselectedattribute.h" | ||
42 | #include "akonadi/akonaditimestampattribute.h" | 45 | #include "akonadi/akonaditimestampattribute.h" | ||
43 | 46 | | |||
▲ Show 20 Lines • Show All 145 Lines • ▼ Show 20 Line(s) | 191 | { | |||
189 | if (!isTaskItem(item)) | 192 | if (!isTaskItem(item)) | ||
190 | return; | 193 | return; | ||
191 | 194 | | |||
192 | auto todo = item.payload<KCalCore::Todo::Ptr>(); | 195 | auto todo = item.payload<KCalCore::Todo::Ptr>(); | ||
193 | 196 | | |||
194 | task->setTitle(todo->summary()); | 197 | task->setTitle(todo->summary()); | ||
195 | task->setText(todo->description()); | 198 | task->setText(todo->description()); | ||
196 | task->setDone(todo->isCompleted()); | 199 | task->setDone(todo->isCompleted()); | ||
200 | #if KCALCORE_VERSION >= QT_VERSION_CHECK(5, 6, 80) | ||||
201 | if (todo->allDay()) { | ||||
202 | task->setDoneDate(QDateTime(todo->completed().date(), QTime(), Qt::UTC)); | ||||
203 | task->setStartDate(QDateTime(todo->dtStart().date(), QTime(), Qt::UTC)); | ||||
204 | task->setDueDate(QDateTime(todo->dtDue().date(), QTime(), Qt::UTC)); | ||||
205 | } else { | ||||
206 | task->setDoneDate(todo->completed().toUTC()); | ||||
207 | task->setStartDate(todo->dtStart().toUTC()); | ||||
208 | task->setDueDate(todo->dtDue().toUTC()); | ||||
209 | } | ||||
210 | #else | ||||
197 | task->setDoneDate(todo->completed().dateTime().toUTC()); | 211 | task->setDoneDate(todo->completed().dateTime().toUTC()); | ||
198 | task->setStartDate(todo->dtStart().dateTime().toUTC()); | 212 | task->setStartDate(todo->dtStart().dateTime().toUTC()); | ||
199 | task->setDueDate(todo->dtDue().dateTime().toUTC()); | 213 | task->setDueDate(todo->dtDue().dateTime().toUTC()); | ||
214 | #endif | ||||
200 | task->setProperty("itemId", item.id()); | 215 | task->setProperty("itemId", item.id()); | ||
201 | task->setProperty("parentCollectionId", item.parentCollection().id()); | 216 | task->setProperty("parentCollectionId", item.parentCollection().id()); | ||
202 | task->setProperty("todoUid", todo->uid()); | 217 | task->setProperty("todoUid", todo->uid()); | ||
203 | task->setProperty("relatedUid", todo->relatedTo()); | 218 | task->setProperty("relatedUid", todo->relatedTo()); | ||
204 | task->setRunning(todo->customProperty("Zanshin", "Running") == QLatin1String("1")); | 219 | task->setRunning(todo->customProperty("Zanshin", "Running") == QLatin1String("1")); | ||
205 | 220 | | |||
206 | switch (todo->recurrence()->recurrenceType()) { | 221 | switch (todo->recurrence()->recurrenceType()) { | ||
207 | case KCalCore::Recurrence::rDaily: | 222 | case KCalCore::Recurrence::rDaily: | ||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Line(s) | 268 | { | |||
256 | 271 | | |||
257 | auto todo = item.payload<KCalCore::Todo::Ptr>(); | 272 | auto todo = item.payload<KCalCore::Todo::Ptr>(); | ||
258 | if (todo->relatedTo() == task->property("todoUid")) | 273 | if (todo->relatedTo() == task->property("todoUid")) | ||
259 | return true; | 274 | return true; | ||
260 | 275 | | |||
261 | return false; | 276 | return false; | ||
262 | } | 277 | } | ||
263 | 278 | | |||
279 | #if KCALCORE_VERSION >= QT_VERSION_CHECK(5, 6, 80) | ||||
280 | #define KDateTime QDateTime | ||||
281 | #endif | ||||
282 | | ||||
283 | | ||||
264 | Akonadi::Item Serializer::createItemFromTask(Domain::Task::Ptr task) | 284 | Akonadi::Item Serializer::createItemFromTask(Domain::Task::Ptr task) | ||
265 | { | 285 | { | ||
266 | auto todo = KCalCore::Todo::Ptr::create(); | 286 | auto todo = KCalCore::Todo::Ptr::create(); | ||
267 | 287 | | |||
268 | todo->setSummary(task->title()); | 288 | todo->setSummary(task->title()); | ||
269 | todo->setDescription(task->text()); | 289 | todo->setDescription(task->text()); | ||
270 | 290 | | |||
291 | // We only support all-day todos, so ignore timezone information and possible effect from timezone on dates | ||||
292 | // KCalCore reads "DUE;VALUE=DATE:20171130" as QDateTime(QDate(2017, 11, 30), QTime(), Qt::LocalTime), for lack of timezone information | ||||
293 | // so we should never call toUtc() on that, it would mess up the date. Instead we force UTC while preserving the date. | ||||
294 | // If one day we want to support time information, we need to add a task->isAllDay()/setAllDay(). | ||||
295 | #if KCALCORE_VERSION >= QT_VERSION_CHECK(5, 6, 80) | ||||
296 | todo->setDtStart(QDateTime(task->startDate().date(), QTime(), Qt::UTC)); | ||||
297 | todo->setDtDue(QDateTime(task->dueDate().date(), QTime(), Qt::UTC)); | ||||
298 | todo->setAllDay(true); | ||||
299 | #else | ||||
271 | todo->setDtStart(KDateTime(task->startDate(), KDateTime::UTC)); | 300 | todo->setDtStart(KDateTime(task->startDate(), KDateTime::UTC)); | ||
272 | todo->setDtDue(KDateTime(task->dueDate(), KDateTime::UTC)); | 301 | todo->setDtDue(KDateTime(task->dueDate(), KDateTime::UTC)); | ||
302 | #endif | ||||
273 | 303 | | |||
274 | if (task->property("todoUid").isValid()) { | 304 | if (task->property("todoUid").isValid()) { | ||
275 | todo->setUid(task->property("todoUid").toString()); | 305 | todo->setUid(task->property("todoUid").toString()); | ||
276 | } | 306 | } | ||
277 | 307 | | |||
278 | if (task->property("relatedUid").isValid()) { | 308 | if (task->property("relatedUid").isValid()) { | ||
279 | todo->setRelatedTo(task->property("relatedUid").toString()); | 309 | todo->setRelatedTo(task->property("relatedUid").toString()); | ||
280 | } | 310 | } | ||
▲ Show 20 Lines • Show All 404 Lines • Show Last 20 Lines |