7 #include "aggregatedfetchscope.h" 8 #include <shared/akranges.h> 10 #include <QRecursiveMutex> 11 #include <QMutexLocker> 13 #define LOCKED_D(name) \ 15 QMutexLocker lock(&d->lock); 21 class AggregatedFetchScopePrivate
24 AggregatedFetchScopePrivate()
30 auto it = count.
find(value);
31 if (it == count.
end()) {
32 it = count.
insert(value, 0);
40 auto it = count.
find(value);
41 if (it == count.
end()) {
51 inline void updateBool(
bool newValue,
int &store)
53 store += newValue ? 1 : -1;
59 const auto added = newSet - oldSet;
60 for (
const auto &value : added) {
61 addToSet(value,
set, count);
63 const auto removed = oldSet - newSet;
64 for (
const auto &value : removed) {
65 removeFromSet(value,
set, count);
73 class AggregatedCollectionFetchScopePrivate :
public AggregatedFetchScopePrivate
84 class AggregatedTagFetchScopePrivate :
public AggregatedFetchScopePrivate
91 int fetchRemoteId = 0;
92 int doNotFetchAllAttributes = 0;
95 class AggregatedItemFetchScopePrivate :
public AggregatedFetchScopePrivate
98 mutable Protocol::ItemFetchScope mCachedScope;
99 mutable bool mCachedScopeValid =
false;
106 int ancestors[3] = { 0, 0, 0 };
109 int allAttributes = 0;
113 int ignoreErrors = 0;
118 int fetchRelations = 0;
129 AggregatedCollectionFetchScope::AggregatedCollectionFetchScope()
130 : d_ptr(new AggregatedCollectionFetchScopePrivate)
134 AggregatedCollectionFetchScope::~AggregatedCollectionFetchScope()
139 void AggregatedCollectionFetchScope::apply(
const Protocol::CollectionFetchScope &oldScope,
140 const Protocol::CollectionFetchScope &newScope)
142 LOCKED_D(AggregatedCollectionFetchScope)
144 if (newScope.includeStatistics() != oldScope.includeStatistics()) {
145 d->updateBool(newScope.includeStatistics(), d->fetchStats);
147 if (newScope.fetchIdOnly() != oldScope.fetchIdOnly()) {
148 d->updateBool(newScope.fetchIdOnly(), d->fetchIdOnly);
150 if (newScope.attributes() != oldScope.attributes()) {
151 d->applySet(oldScope.attributes(), newScope.attributes(), d->attrs, d->attrsCount);
157 LOCKED_D(
const AggregatedCollectionFetchScope)
161 bool AggregatedCollectionFetchScope::fetchIdOnly()
const 163 LOCKED_D(
const AggregatedCollectionFetchScope)
166 return d->fetchIdOnly == d->subscribers;
169 bool AggregatedCollectionFetchScope::fetchStatistics()
const 171 LOCKED_D(
const AggregatedCollectionFetchScope);
173 return d->fetchStats > 0;
176 void AggregatedCollectionFetchScope::addSubscriber()
178 LOCKED_D(AggregatedCollectionFetchScope)
182 void AggregatedCollectionFetchScope::removeSubscriber()
184 LOCKED_D(AggregatedCollectionFetchScope)
189 AggregatedItemFetchScope::AggregatedItemFetchScope()
190 : d_ptr(new AggregatedItemFetchScopePrivate)
194 AggregatedItemFetchScope::~AggregatedItemFetchScope()
199 void AggregatedItemFetchScope::apply(
const Protocol::ItemFetchScope &oldScope,
200 const Protocol::ItemFetchScope &newScope)
202 LOCKED_D(AggregatedItemFetchScope);
204 const auto newParts = newScope.requestedParts() | AkRanges::Actions::toQSet;
205 const auto oldParts = oldScope.requestedParts() | AkRanges::Actions::toQSet;
206 if (newParts != oldParts) {
207 d->applySet(oldParts, newParts, d->parts, d->partsCount);
209 if (newScope.ancestorDepth() != oldScope.ancestorDepth()) {
210 updateAncestorDepth(oldScope.ancestorDepth(), newScope.ancestorDepth());
212 if (newScope.cacheOnly() != oldScope.cacheOnly()) {
213 d->updateBool(newScope.cacheOnly(), d->cacheOnly);
215 if (newScope.fullPayload() != oldScope.fullPayload()) {
216 d->updateBool(newScope.fullPayload(), d->fullPayload);
218 if (newScope.allAttributes() != oldScope.allAttributes()) {
219 d->updateBool(newScope.allAttributes(), d->allAttributes);
221 if (newScope.fetchSize() != oldScope.fetchSize()) {
222 d->updateBool(newScope.fetchSize(), d->fetchSize);
224 if (newScope.fetchMTime() != oldScope.fetchMTime()) {
225 d->updateBool(newScope.fetchMTime(), d->fetchMTime);
227 if (newScope.fetchRemoteRevision() != oldScope.fetchRemoteRevision()) {
228 d->updateBool(newScope.fetchRemoteRevision(), d->fetchRRev);
230 if (newScope.ignoreErrors() != oldScope.ignoreErrors()) {
231 d->updateBool(newScope.ignoreErrors(), d->ignoreErrors);
233 if (newScope.fetchFlags() != oldScope.fetchFlags()) {
234 d->updateBool(newScope.fetchFlags(), d->fetchFlags);
236 if (newScope.fetchRemoteId() != oldScope.fetchRemoteId()) {
237 d->updateBool(newScope.fetchRemoteId(), d->fetchRID);
239 if (newScope.fetchGID() != oldScope.fetchGID()) {
240 d->updateBool(newScope.fetchGID(), d->fetchGID);
242 if (newScope.fetchTags() != oldScope.fetchTags()) {
243 d->updateBool(newScope.fetchTags(), d->fetchTags);
245 if (newScope.fetchRelations() != oldScope.fetchRelations()) {
246 d->updateBool(newScope.fetchRelations(), d->fetchRelations);
248 if (newScope.fetchVirtualReferences() != oldScope.fetchVirtualReferences()) {
249 d->updateBool(newScope.fetchVirtualReferences(), d->fetchVRefs);
252 d->mCachedScopeValid =
false;
257 LOCKED_D(
const AggregatedItemFetchScope);
258 if (d->mCachedScopeValid) {
259 return d->mCachedScope;
263 d->mCachedScope.setRequestedParts(d->parts | AkRanges::Actions::toQVector);
264 d->mCachedScope.setAncestorDepth(ancestorDepth());
266 d->mCachedScope.setFetch(ItemFetchScope::CacheOnly, cacheOnly());
267 d->mCachedScope.setFetch(ItemFetchScope::FullPayload, fullPayload());
268 d->mCachedScope.setFetch(ItemFetchScope::AllAttributes, allAttributes());
269 d->mCachedScope.setFetch(ItemFetchScope::Size, fetchSize());
270 d->mCachedScope.setFetch(ItemFetchScope::MTime, fetchMTime());
271 d->mCachedScope.setFetch(ItemFetchScope::RemoteRevision, fetchRemoteRevision());
272 d->mCachedScope.setFetch(ItemFetchScope::IgnoreErrors, ignoreErrors());
273 d->mCachedScope.setFetch(ItemFetchScope::Flags, fetchFlags());
274 d->mCachedScope.setFetch(ItemFetchScope::RemoteID, fetchRemoteId());
275 d->mCachedScope.setFetch(ItemFetchScope::GID, fetchGID());
276 d->mCachedScope.setFetch(ItemFetchScope::Tags, fetchTags());
277 d->mCachedScope.setFetch(ItemFetchScope::Relations, fetchRelations());
278 d->mCachedScope.setFetch(ItemFetchScope::VirtReferences, fetchVirtualReferences());
279 d->mCachedScopeValid =
true;
280 return d->mCachedScope;
285 LOCKED_D(
const AggregatedItemFetchScope)
289 ItemFetchScope::AncestorDepth AggregatedItemFetchScope::ancestorDepth()
const 291 LOCKED_D(
const AggregatedItemFetchScope)
294 return ItemFetchScope::AllAncestors;
295 }
else if (d->ancestors[ItemFetchScope::ParentAncestor] > 0) {
296 return ItemFetchScope::ParentAncestor;
298 return ItemFetchScope::NoAncestor;
302 void AggregatedItemFetchScope::updateAncestorDepth(ItemFetchScope::AncestorDepth oldDepth,
303 ItemFetchScope::AncestorDepth newDepth)
305 LOCKED_D(AggregatedItemFetchScope)
306 if (d->ancestors[oldDepth] > 0) {
307 --d->ancestors[oldDepth];
309 ++d->ancestors[newDepth];
312 bool AggregatedItemFetchScope::cacheOnly()
const 314 LOCKED_D(
const AggregatedItemFetchScope)
317 return d->cacheOnly == d->subscribers;
320 bool AggregatedItemFetchScope::fullPayload()
const 322 LOCKED_D(
const AggregatedItemFetchScope)
325 return d->fullPayload > 0;
328 bool AggregatedItemFetchScope::allAttributes()
const 330 LOCKED_D(
const AggregatedItemFetchScope)
333 return d->allAttributes > 0;
336 bool AggregatedItemFetchScope::fetchSize()
const 338 LOCKED_D(
const AggregatedItemFetchScope)
340 return d->fetchSize > 0;
343 bool AggregatedItemFetchScope::fetchMTime()
const 345 LOCKED_D(
const AggregatedItemFetchScope)
347 return d->fetchMTime > 0;
350 bool AggregatedItemFetchScope::fetchRemoteRevision()
const 352 LOCKED_D(
const AggregatedItemFetchScope)
354 return d->fetchRRev > 0;
357 bool AggregatedItemFetchScope::ignoreErrors()
const 359 LOCKED_D(
const AggregatedItemFetchScope)
362 return d->ignoreErrors == d->subscribers;
365 bool AggregatedItemFetchScope::fetchFlags()
const 367 LOCKED_D(
const AggregatedItemFetchScope)
369 return d->fetchFlags > 0;
372 bool AggregatedItemFetchScope::fetchRemoteId()
const 374 LOCKED_D(
const AggregatedItemFetchScope)
376 return d->fetchRID > 0;
379 bool AggregatedItemFetchScope::fetchGID()
const 381 LOCKED_D(
const AggregatedItemFetchScope)
383 return d->fetchGID > 0;
386 bool AggregatedItemFetchScope::fetchTags()
const 388 LOCKED_D(
const AggregatedItemFetchScope)
390 return d->fetchTags > 0;
393 bool AggregatedItemFetchScope::fetchRelations()
const 395 LOCKED_D(
const AggregatedItemFetchScope)
397 return d->fetchRelations > 0;
400 bool AggregatedItemFetchScope::fetchVirtualReferences()
const 402 LOCKED_D(
const AggregatedItemFetchScope)
404 return d->fetchVRefs > 0;
407 void AggregatedItemFetchScope::addSubscriber()
409 LOCKED_D(AggregatedItemFetchScope)
413 void AggregatedItemFetchScope::removeSubscriber()
415 LOCKED_D(AggregatedItemFetchScope)
422 AggregatedTagFetchScope::AggregatedTagFetchScope()
423 : d_ptr(new AggregatedTagFetchScopePrivate)
427 AggregatedTagFetchScope::~AggregatedTagFetchScope()
432 void AggregatedTagFetchScope::apply(
const Protocol::TagFetchScope &oldScope,
433 const Protocol::TagFetchScope &newScope)
435 LOCKED_D(AggregatedTagFetchScope)
437 if (newScope.fetchIdOnly() != oldScope.fetchIdOnly()) {
438 d->updateBool(newScope.fetchIdOnly(), d->fetchIdOnly);
440 if (newScope.fetchRemoteID() != oldScope.fetchRemoteID()) {
441 d->updateBool(newScope.fetchRemoteID(), d->fetchRemoteId);
443 if (newScope.fetchAllAttributes() != oldScope.fetchAllAttributes()) {
445 d->updateBool(!newScope.fetchAllAttributes(), d->doNotFetchAllAttributes);
447 if (newScope.attributes() != oldScope.attributes()) {
448 d->applySet(oldScope.attributes(), newScope.attributes(), d->attrs, d->attrsCount);
452 Protocol::TagFetchScope AggregatedTagFetchScope::toFetchScope()
const 454 Protocol::TagFetchScope tfs;
455 tfs.setFetchIdOnly(fetchIdOnly());
456 tfs.setFetchRemoteID(fetchRemoteId());
457 tfs.setFetchAllAttributes(fetchAllAttributes());
458 tfs.setAttributes(attributes());
462 bool AggregatedTagFetchScope::fetchIdOnly()
const 464 LOCKED_D(
const AggregatedTagFetchScope)
467 return d->fetchIdOnly == d->subscribers;
470 bool AggregatedTagFetchScope::fetchRemoteId()
const 472 LOCKED_D(
const AggregatedTagFetchScope)
473 return d->fetchRemoteId > 0;
476 bool AggregatedTagFetchScope::fetchAllAttributes()
const 478 LOCKED_D(
const AggregatedTagFetchScope)
480 return d->doNotFetchAllAttributes != d->subscribers;
485 LOCKED_D(
const AggregatedTagFetchScope)
489 void AggregatedTagFetchScope::addSubscriber()
491 LOCKED_D(AggregatedTagFetchScope)
495 void AggregatedTagFetchScope::removeSubscriber()
497 LOCKED_D(AggregatedTagFetchScope)
QHash::iterator insert(const Key &key, const T &value)
QHash::iterator erase(QHash::iterator pos)
Specifies which parts of an item should be fetched from the Akonadi storage.
QHash::iterator find(const Key &key)
Helper integration between Akonadi and Qt.