Changeset View
Changeset View
Standalone View
Standalone View
tests/testlib/akonadifakedata.cpp
Show All 21 Lines | |||||
22 | */ | 22 | */ | ||
23 | 23 | | |||
24 | #include "akonadifakedata.h" | 24 | #include "akonadifakedata.h" | ||
25 | #include "akonadifakemonitor.h" | 25 | #include "akonadifakemonitor.h" | ||
26 | #include "akonadifakestorage.h" | 26 | #include "akonadifakestorage.h" | ||
27 | 27 | | |||
28 | #include <KCalCore/Todo> | 28 | #include <KCalCore/Todo> | ||
29 | 29 | | |||
30 | #include "akonadi/akonadiserializer.h" | ||||
30 | #include "akonadi/akonadiapplicationselectedattribute.h" | 31 | #include "akonadi/akonadiapplicationselectedattribute.h" | ||
31 | 32 | | |||
32 | #include <algorithm> | 33 | #include <algorithm> | ||
33 | 34 | | |||
34 | using namespace Testlib; | 35 | using namespace Testlib; | ||
36 | using Akonadi::Serializer; | ||||
35 | 37 | | |||
36 | template<class Entity> | 38 | template<class Entity> | ||
37 | static Akonadi::Collection::Id findParentId(const Entity &entity) | 39 | static Akonadi::Collection::Id findParentId(const Entity &entity) | ||
38 | { | 40 | { | ||
39 | const auto parent = entity.parentCollection(); | 41 | const auto parent = entity.parentCollection(); | ||
40 | return parent.isValid() ? parent.id() | 42 | return parent.isValid() ? parent.id() | ||
41 | : Akonadi::Collection::root().id(); | 43 | : Akonadi::Collection::root().id(); | ||
42 | } | 44 | } | ||
43 | 45 | | |||
44 | static const char s_contextListProperty[] = "ContextList"; | | |||
45 | static const char s_appName[] = "Zanshin"; | | |||
46 | | ||||
47 | // Should be in the serializer ideally ... but we don't link to that from here anyway. | 46 | // Should be in the serializer ideally ... but we don't link to that from here anyway. | ||
48 | static QStringList extractContextUids(const Akonadi::Item &taskItem) | 47 | static QStringList extractContextUids(const Akonadi::Item &taskItem) | ||
49 | { | 48 | { | ||
50 | if (!taskItem.hasPayload<KCalCore::Todo::Ptr>()) | 49 | if (!taskItem.hasPayload<KCalCore::Todo::Ptr>()) | ||
51 | return {}; | 50 | return {}; | ||
52 | auto todo = taskItem.payload<KCalCore::Todo::Ptr>(); | 51 | auto todo = taskItem.payload<KCalCore::Todo::Ptr>(); | ||
53 | const QString contexts = todo->customProperty(s_appName, s_contextListProperty); | 52 | const QString contexts = todo->customProperty(Serializer::customPropertyAppName(), Serializer::customPropertyContextList()); | ||
54 | return contexts.split(',', QString::SkipEmptyParts); | 53 | return contexts.split(',', QString::SkipEmptyParts); | ||
55 | } | 54 | } | ||
56 | 55 | | |||
57 | // Duplicated from the serializer | 56 | // Duplicated from the serializer | ||
58 | static QString contextUid(const Akonadi::Item &contextItem) | 57 | static QString contextUid(const Akonadi::Item &contextItem) | ||
59 | { | 58 | { | ||
60 | auto contextTodo = contextItem.payload<KCalCore::Todo::Ptr>(); | 59 | auto contextTodo = contextItem.payload<KCalCore::Todo::Ptr>(); | ||
61 | return contextTodo->uid(); | 60 | return contextTodo->uid(); | ||
62 | } | 61 | } | ||
63 | 62 | | |||
64 | // Somewhat duplicated from the serializer | 63 | // Somewhat duplicated from the serializer | ||
65 | static void removeContextFromTask(const QString &contextUid, Akonadi::Item &item) | 64 | static void removeContextFromTask(const QString &contextUid, Akonadi::Item &item) | ||
66 | { | 65 | { | ||
67 | auto todo = item.payload<KCalCore::Todo::Ptr>(); | 66 | auto todo = item.payload<KCalCore::Todo::Ptr>(); | ||
68 | const QString contexts = todo->customProperty(s_appName, s_contextListProperty); | 67 | const QString contexts = todo->customProperty(Serializer::customPropertyAppName(), Serializer::customPropertyContextList()); | ||
69 | QStringList contextList = contexts.split(',', QString::SkipEmptyParts); | 68 | QStringList contextList = contexts.split(',', QString::SkipEmptyParts); | ||
70 | contextList.removeAll(contextUid); | 69 | contextList.removeAll(contextUid); | ||
71 | if (contextList.isEmpty()) | 70 | if (contextList.isEmpty()) | ||
72 | todo->removeCustomProperty(s_appName, s_contextListProperty); | 71 | todo->removeCustomProperty(Serializer::customPropertyAppName(), Serializer::customPropertyContextList()); | ||
73 | else | 72 | else | ||
74 | todo->setCustomProperty(s_appName, s_contextListProperty, contextList.join(',')); | 73 | todo->setCustomProperty(Serializer::customPropertyAppName(), Serializer::customPropertyContextList(), contextList.join(',')); | ||
75 | item.setPayload<KCalCore::Todo::Ptr>(todo); | 74 | item.setPayload<KCalCore::Todo::Ptr>(todo); | ||
76 | Q_ASSERT(contextList == extractContextUids(item)); | 75 | Q_ASSERT(contextList == extractContextUids(item)); | ||
77 | } | 76 | } | ||
78 | 77 | | |||
79 | // Duplicate from the serializer | 78 | // Duplicate from the serializer | ||
80 | static bool isContext(const Akonadi::Item &item) | 79 | static bool isContext(const Akonadi::Item &item) | ||
81 | { | 80 | { | ||
82 | if (!item.hasPayload<KCalCore::Todo::Ptr>()) | 81 | if (!item.hasPayload<KCalCore::Todo::Ptr>()) | ||
83 | return false; | 82 | return false; | ||
84 | 83 | | |||
85 | auto todo = item.payload<KCalCore::Todo::Ptr>(); | 84 | auto todo = item.payload<KCalCore::Todo::Ptr>(); | ||
86 | return !todo->customProperty(s_appName, "Context").isEmpty(); | 85 | return !todo->customProperty(Serializer::customPropertyAppName(), Serializer::customPropertyIsContext()).isEmpty(); | ||
87 | } | 86 | } | ||
88 | 87 | | |||
89 | AkonadiFakeData::AkonadiFakeData() | 88 | AkonadiFakeData::AkonadiFakeData() | ||
90 | : m_monitor(new AkonadiFakeMonitor) | 89 | : m_monitor(new AkonadiFakeMonitor) | ||
91 | { | 90 | { | ||
92 | } | 91 | } | ||
93 | 92 | | |||
94 | AkonadiFakeData::AkonadiFakeData(const AkonadiFakeData &other) | 93 | AkonadiFakeData::AkonadiFakeData(const AkonadiFakeData &other) | ||
▲ Show 20 Lines • Show All 386 Lines • Show Last 20 Lines |