Changeset View
Changeset View
Standalone View
Standalone View
tests/testlib/akonadifakedataxmlloader.cpp
Show All 35 Lines | |||||
36 | { | 36 | { | ||
37 | } | 37 | } | ||
38 | 38 | | |||
39 | void AkonadiFakeDataXmlLoader::load(const QString &fileName) const | 39 | void AkonadiFakeDataXmlLoader::load(const QString &fileName) const | ||
40 | { | 40 | { | ||
41 | Akonadi::XmlDocument doc(fileName); | 41 | Akonadi::XmlDocument doc(fileName); | ||
42 | Q_ASSERT(doc.isValid()); | 42 | Q_ASSERT(doc.isValid()); | ||
43 | 43 | | |||
44 | Akonadi::Tag::Id tagId = m_data->maxTagId() + 1; | | |||
45 | Akonadi::Collection::Id collectionId = m_data->maxCollectionId() + 1; | 44 | Akonadi::Collection::Id collectionId = m_data->maxCollectionId() + 1; | ||
46 | Akonadi::Item::Id itemId = m_data->maxItemId() + 1; | 45 | Akonadi::Item::Id itemId = m_data->maxItemId() + 1; | ||
47 | 46 | | |||
48 | QHash<QString, Akonadi::Tag> tagByRid; | | |||
49 | | ||||
50 | foreach (const Akonadi::Tag &tag, doc.tags()) { | | |||
51 | auto t = tag; | | |||
52 | t.setId(tagId++); | | |||
53 | m_data->createTag(t); | | |||
54 | tagByRid[t.remoteId()] = t; | | |||
55 | } | | |||
56 | | ||||
57 | QHash<QString, Akonadi::Collection> collectionByRid; | 47 | QHash<QString, Akonadi::Collection> collectionByRid; | ||
58 | 48 | | |||
59 | foreach (const Akonadi::Collection &c, doc.collections()) { | 49 | foreach (const Akonadi::Collection &c, doc.collections()) { | ||
60 | collectionByRid[c.remoteId()] = c; | 50 | collectionByRid[c.remoteId()] = c; | ||
61 | } | 51 | } | ||
62 | 52 | | |||
63 | std::function<int(const Akonadi::Collection &collection)> depth | 53 | std::function<int(const Akonadi::Collection &collection)> depth | ||
64 | = [&depth, &collectionByRid] (const Akonadi::Collection &c) { | 54 | = [&depth, &collectionByRid] (const Akonadi::Collection &c) { | ||
Show All 20 Lines | 70 | foreach (const Akonadi::Collection &collection, collectionsByDepth) { | |||
85 | c.setParentCollection(collectionByRid.value(c.parentCollection().remoteId())); | 75 | c.setParentCollection(collectionByRid.value(c.parentCollection().remoteId())); | ||
86 | m_data->createCollection(c); | 76 | m_data->createCollection(c); | ||
87 | 77 | | |||
88 | foreach (const Akonadi::Item &item, doc.items(collection)) { | 78 | foreach (const Akonadi::Item &item, doc.items(collection)) { | ||
89 | auto i = item; | 79 | auto i = item; | ||
90 | i.setId(itemId++); | 80 | i.setId(itemId++); | ||
91 | i.setParentCollection(c); | 81 | i.setParentCollection(c); | ||
92 | i.setModificationTime(QDateTime::currentDateTime()); | 82 | i.setModificationTime(QDateTime::currentDateTime()); | ||
93 | auto tags = i.tags(); | | |||
94 | std::transform(tags.constBegin(), tags.constEnd(), | | |||
95 | tags.begin(), | | |||
96 | [&tagByRid] (const Akonadi::Tag &tag) { | | |||
97 | return tagByRid.value(tag.remoteId()); | | |||
98 | }); | | |||
99 | i.setTags(tags); | | |||
100 | m_data->createItem(i); | 83 | m_data->createItem(i); | ||
101 | } | 84 | } | ||
102 | } | 85 | } | ||
103 | } | 86 | } | ||
104 | 87 | |