diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-09-13 12:42:31 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-09-13 12:42:31 +0200 |
commit | c12a9a09da59b9e418316dba02e6215cb55e47ee (patch) | |
tree | 05498d9a42e399bcca787f40c1fc473fb09e680e /examples/davresource/davresource.cpp | |
parent | 55fe06979ceebe67553135b43aa47e70d931304b (diff) | |
parent | ebdb89b8bb482bbb5ecd544c3d38bef35fc7d820 (diff) | |
download | sink-2cbc37da82bb06757c38f891c465a24219268d3b.tar.gz sink-2cbc37da82bb06757c38f891c465a24219268d3b.zip |
Merge commit 'ebdb89b8bb482bbb5ecd544c3d38bef35fc7d820'v0.4.0
Diffstat (limited to 'examples/davresource/davresource.cpp')
-rw-r--r-- | examples/davresource/davresource.cpp | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/examples/davresource/davresource.cpp b/examples/davresource/davresource.cpp index 465220f..22c502f 100644 --- a/examples/davresource/davresource.cpp +++ b/examples/davresource/davresource.cpp | |||
@@ -93,7 +93,7 @@ public: | |||
93 | QVector<QByteArray> ridList; | 93 | QVector<QByteArray> ridList; |
94 | for(const auto &f : addressbookList) { | 94 | for(const auto &f : addressbookList) { |
95 | const auto &rid = getRid(f); | 95 | const auto &rid = getRid(f); |
96 | SinkTrace() << "Found addressbook:" << rid; | 96 | SinkLog() << "Found addressbook:" << rid << f.displayName(); |
97 | ridList.append(rid); | 97 | ridList.append(rid); |
98 | createAddressbook(f.displayName(), rid, ""); | 98 | createAddressbook(f.displayName(), rid, ""); |
99 | } | 99 | } |
@@ -138,19 +138,21 @@ public: | |||
138 | if (error) { | 138 | if (error) { |
139 | SinkWarningCtx(mLogCtx) << "Failed to synchronize addressbooks." << collectionsFetchJob->errorString(); | 139 | SinkWarningCtx(mLogCtx) << "Failed to synchronize addressbooks." << collectionsFetchJob->errorString(); |
140 | } else { | 140 | } else { |
141 | synchronizeAddressbooks(collectionsFetchJob ->collections()); | 141 | synchronizeAddressbooks(collectionsFetchJob->collections()); |
142 | } | 142 | } |
143 | }); | 143 | }); |
144 | return job; | 144 | return job; |
145 | } else if (query.type() == ApplicationDomain::getTypeName<ApplicationDomain::Contact>()) { | 145 | } else if (query.type() == ApplicationDomain::getTypeName<ApplicationDomain::Contact>()) { |
146 | SinkLogCtx(mLogCtx) << "Synchronizing contacts."; | 146 | SinkLogCtx(mLogCtx) << "Synchronizing contacts."; |
147 | auto ridList = QSharedPointer<QByteArrayList>::create(); | 147 | auto ridList = QSharedPointer<QByteArrayList>::create(); |
148 | auto total = QSharedPointer<int>::create(0); | ||
149 | auto progress = QSharedPointer<int>::create(0); | ||
148 | auto collectionsFetchJob = new KDAV2::DavCollectionsFetchJob(mResourceUrl); | 150 | auto collectionsFetchJob = new KDAV2::DavCollectionsFetchJob(mResourceUrl); |
149 | auto job = runJob(collectionsFetchJob).then([this, collectionsFetchJob] { | 151 | auto job = runJob(collectionsFetchJob).then([this, collectionsFetchJob] { |
150 | synchronizeAddressbooks(collectionsFetchJob ->collections()); | 152 | synchronizeAddressbooks(collectionsFetchJob ->collections()); |
151 | return collectionsFetchJob->collections(); | 153 | return collectionsFetchJob->collections(); |
152 | }) | 154 | }) |
153 | .serialEach([this, ridList](const KDAV2::DavCollection &collection) { | 155 | .serialEach([=](const KDAV2::DavCollection &collection) { |
154 | auto collId = getRid(collection); | 156 | auto collId = getRid(collection); |
155 | const auto addressbookLocalId = syncStore().resolveRemoteId(ENTITY_TYPE_ADDRESSBOOK, collId); | 157 | const auto addressbookLocalId = syncStore().resolveRemoteId(ENTITY_TYPE_ADDRESSBOOK, collId); |
156 | auto ctag = collection.CTag().toLatin1(); | 158 | auto ctag = collection.CTag().toLatin1(); |
@@ -158,10 +160,11 @@ public: | |||
158 | SinkTraceCtx(mLogCtx) << "Syncing " << collId; | 160 | SinkTraceCtx(mLogCtx) << "Syncing " << collId; |
159 | auto cache = std::shared_ptr<KDAV2::EtagCache>(new KDAV2::EtagCache()); | 161 | auto cache = std::shared_ptr<KDAV2::EtagCache>(new KDAV2::EtagCache()); |
160 | auto davItemsListJob = new KDAV2::DavItemsListJob(collection.url(), cache); | 162 | auto davItemsListJob = new KDAV2::DavItemsListJob(collection.url(), cache); |
161 | const QByteArray bufferType = ENTITY_TYPE_CONTACT; | ||
162 | QHash<QByteArray, Query::Comparator> mergeCriteria; | 163 | QHash<QByteArray, Query::Comparator> mergeCriteria; |
163 | auto colljob = runJob(davItemsListJob).then([davItemsListJob] { | 164 | auto colljob = runJob(davItemsListJob).then([=] { |
164 | return KAsync::value(davItemsListJob->items()); | 165 | const auto items = davItemsListJob->items(); |
166 | *total = items.size(); | ||
167 | return KAsync::value(items); | ||
165 | }) | 168 | }) |
166 | .serialEach([=] (const KDAV2::DavItem &item) { | 169 | .serialEach([=] (const KDAV2::DavItem &item) { |
167 | QByteArray rid = getRid(item); | 170 | QByteArray rid = getRid(item); |
@@ -175,13 +178,19 @@ public: | |||
175 | Sink::ApplicationDomain::Contact contact; | 178 | Sink::ApplicationDomain::Contact contact; |
176 | contact.setVcard(item.data()); | 179 | contact.setVcard(item.data()); |
177 | contact.setAddressbook(addressbookLocalId); | 180 | contact.setAddressbook(addressbookLocalId); |
178 | createOrModify(bufferType, rid, contact, mergeCriteria); | 181 | createOrModify(ENTITY_TYPE_CONTACT, rid, contact, mergeCriteria); |
179 | return item; | 182 | return item; |
180 | }) | 183 | }) |
181 | .then([this, ridList] (const KDAV2::DavItem &item) { | 184 | .then([=] (const KDAV2::DavItem &item) { |
182 | const auto rid = getRid(item); | 185 | const auto rid = getRid(item); |
183 | syncStore().writeValue(rid + "_etag", item.etag().toLatin1()); | 186 | syncStore().writeValue(rid + "_etag", item.etag().toLatin1()); |
184 | ridList->append(rid); | 187 | ridList->append(rid); |
188 | *progress += 1; | ||
189 | reportProgress(*progress, *total, QByteArrayList{} << addressbookLocalId); | ||
190 | //commit every 5 contacts (so contacts start appearing in the UI) | ||
191 | if ((*progress % 5) == 0) { | ||
192 | commit(); | ||
193 | } | ||
185 | return rid; | 194 | return rid; |
186 | }); | 195 | }); |
187 | return itemjob; | 196 | return itemjob; |
@@ -190,7 +199,7 @@ public: | |||
190 | return KAsync::value(rid); | 199 | return KAsync::value(rid); |
191 | } | 200 | } |
192 | }) | 201 | }) |
193 | .then([this, collId, ctag] () { | 202 | .then([=] () { |
194 | syncStore().writeValue(collId + "_ctag", ctag); | 203 | syncStore().writeValue(collId + "_ctag", ctag); |
195 | }); | 204 | }); |
196 | return colljob; | 205 | return colljob; |
@@ -251,6 +260,7 @@ DavResourceFactory::DavResourceFactory(QObject *parent) | |||
251 | : Sink::ResourceFactory(parent, | 260 | : Sink::ResourceFactory(parent, |
252 | {Sink::ApplicationDomain::ResourceCapabilities::Contact::contact, | 261 | {Sink::ApplicationDomain::ResourceCapabilities::Contact::contact, |
253 | Sink::ApplicationDomain::ResourceCapabilities::Contact::addressbook, | 262 | Sink::ApplicationDomain::ResourceCapabilities::Contact::addressbook, |
263 | Sink::ApplicationDomain::ResourceCapabilities::Contact::storage | ||
254 | } | 264 | } |
255 | ) | 265 | ) |
256 | { | 266 | { |