Changeset View
Changeset View
Standalone View
Standalone View
src/zanshin/migrator/zanshincontextitemsmigrator.cpp
Show All 26 Lines | |||||
27 | 27 | | |||
28 | #include <AkonadiCore/ItemCreateJob> | 28 | #include <AkonadiCore/ItemCreateJob> | ||
29 | #include <AkonadiCore/ItemModifyJob> | 29 | #include <AkonadiCore/ItemModifyJob> | ||
30 | #include <AkonadiCore/TagFetchJob> | 30 | #include <AkonadiCore/TagFetchJob> | ||
31 | 31 | | |||
32 | #include <QStringList> | 32 | #include <QStringList> | ||
33 | #include <KCalCore/Todo> | 33 | #include <KCalCore/Todo> | ||
34 | 34 | | |||
35 | using Akonadi::Serializer; | ||||
36 | | ||||
35 | static const char s_contextTagType[] = "Zanshin-Context"; | 37 | static const char s_contextTagType[] = "Zanshin-Context"; | ||
36 | 38 | | |||
37 | ZanshinContextItemsMigrator::ZanshinContextItemsMigrator() | 39 | ZanshinContextItemsMigrator::ZanshinContextItemsMigrator() | ||
38 | { | 40 | { | ||
39 | } | 41 | } | ||
40 | 42 | | |||
41 | ZanshinContextItemsMigrator::FetchResult ZanshinContextItemsMigrator::fetchAllItems(WhichItems which) | 43 | ZanshinContextItemsMigrator::FetchResult ZanshinContextItemsMigrator::fetchAllItems(WhichItems which) | ||
42 | { | 44 | { | ||
43 | FetchResult result; | 45 | FetchResult result; | ||
44 | 46 | | |||
45 | auto collectionsJob = m_storage.fetchCollections(Akonadi::Collection::root(), Akonadi::Storage::Recursive); | 47 | auto collectionsJob = m_storage.fetchCollections(Akonadi::Collection::root(), Akonadi::Storage::Recursive); | ||
46 | collectionsJob->kjob()->exec(); | 48 | collectionsJob->kjob()->exec(); | ||
47 | 49 | | |||
48 | auto collections = collectionsJob->collections(); | 50 | auto collections = collectionsJob->collections(); | ||
49 | foreach (const auto &collection, collections) { | 51 | foreach (const auto &collection, collections) { | ||
50 | auto job = m_storage.fetchItemsWithTags(collection); | 52 | auto job = m_storage.fetchItemsWithTags(collection); | ||
51 | job->kjob()->exec(); | 53 | job->kjob()->exec(); | ||
52 | bool hasTaskToConvert = false; | 54 | bool hasTaskToConvert = false; | ||
53 | auto items = job->items(); | 55 | auto items = job->items(); | ||
54 | Akonadi::Item::List selectedItems; | 56 | Akonadi::Item::List selectedItems; | ||
55 | foreach (const Akonadi::Item &item, items) { | 57 | foreach (const Akonadi::Item &item, items) { | ||
56 | if (item.hasPayload<KCalCore::Todo::Ptr>()) { | 58 | if (item.hasPayload<KCalCore::Todo::Ptr>()) { | ||
57 | auto todo = item.payload<KCalCore::Todo::Ptr>(); | 59 | auto todo = item.payload<KCalCore::Todo::Ptr>(); | ||
58 | if (which == WhichItems::TasksToConvert && !todo->customProperty("Zanshin", "ContextList").isEmpty()) { | 60 | if (which == WhichItems::TasksToConvert && !todo->customProperty(Serializer::customPropertyAppName(), Serializer::customPropertyContextList()).isEmpty()) { | ||
59 | // This folder was already migrated, skip it | 61 | // This folder was already migrated, skip it | ||
60 | hasTaskToConvert = false; | 62 | hasTaskToConvert = false; | ||
61 | qDebug() << "Detected an already converted task" << todo->uid(); | 63 | qDebug() << "Detected an already converted task" << todo->uid(); | ||
62 | break; | 64 | break; | ||
63 | } | 65 | } | ||
64 | const bool isContext = !todo->customProperty("Zanshin", "Context").isEmpty(); | 66 | const bool isContext = !todo->customProperty(Serializer::customPropertyAppName(), Serializer::customPropertyIsContext()).isEmpty(); | ||
65 | if ((isContext && which == WhichItems::OnlyContexts) || | 67 | if ((isContext && which == WhichItems::OnlyContexts) || | ||
66 | (!isContext && which == WhichItems::TasksToConvert) || | 68 | (!isContext && which == WhichItems::TasksToConvert) || | ||
67 | (!isContext && which == WhichItems::AllTasks)) { | 69 | (!isContext && which == WhichItems::AllTasks)) { | ||
68 | selectedItems.push_back(item); | 70 | selectedItems.push_back(item); | ||
69 | hasTaskToConvert = true; | 71 | hasTaskToConvert = true; | ||
70 | } | 72 | } | ||
71 | } | 73 | } | ||
72 | } | 74 | } | ||
▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Line(s) | 123 | if (tag.type() == s_contextTagType) { | |||
130 | if (job->exec()) { | 132 | if (job->exec()) { | ||
131 | item = job->item(); | 133 | item = job->item(); | ||
132 | ++count; | 134 | ++count; | ||
133 | } else { | 135 | } else { | ||
134 | qWarning() << "Failure to associate context" << tag.name() << "to task:" << job->errorString(); | 136 | qWarning() << "Failure to associate context" << tag.name() << "to task:" << job->errorString(); | ||
135 | } | 137 | } | ||
136 | } | 138 | } | ||
137 | } | 139 | } | ||
140 | // While we're here, port from "Project" to "ISPROJECT" | ||||
141 | auto todo = item.payload<KCalCore::Todo::Ptr>(); | ||||
142 | if (!todo->customProperty("Zanshin", "Project").isEmpty()) { | ||||
143 | todo->setCustomProperty(Serializer::customPropertyAppName(), Serializer::customPropertyIsProject(), QStringLiteral("1")); | ||||
144 | auto job = new Akonadi::ItemModifyJob(item); | ||||
145 | job->exec(); | ||||
146 | } | ||||
138 | } | 147 | } | ||
139 | qDebug() << "Associated contexts to" << count << "items"; | 148 | qDebug() << "Associated contexts to" << count << "items"; | ||
140 | } | 149 | } | ||
141 | 150 | | |||
142 | bool ZanshinContextItemsMigrator::migrateTags() | 151 | bool ZanshinContextItemsMigrator::migrateTags() | ||
143 | { | 152 | { | ||
144 | auto result = fetchAllItems(WhichItems::TasksToConvert); | 153 | auto result = fetchAllItems(WhichItems::TasksToConvert); | ||
145 | auto tags = fetchAllTags(); | 154 | auto tags = fetchAllTags(); | ||
146 | createContexts(tags, result.pickedCollection); | 155 | createContexts(tags, result.pickedCollection); | ||
147 | associateContexts(result.items); | 156 | associateContexts(result.items); | ||
148 | return true; | 157 | return true; | ||
149 | } | 158 | } | ||
150 | 159 | |