7#include "aggregatedfetchscope.h"
8#include "shared/akranges.h"
10#include <QMutexLocker>
11#include <QRecursiveMutex>
13#define LOCKED_D(name) \
15 QMutexLocker lock(&d->lock);
21class AggregatedFetchScopePrivate
24 AggregatedFetchScopePrivate()
31 auto it = count.
find(value);
32 if (it == count.
end()) {
33 it = count.
insert(value, 0);
41 auto it = count.
find(value);
42 if (it == count.
end()) {
52 inline void updateBool(
bool newValue,
int &store)
54 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);
73class AggregatedCollectionFetchScopePrivate :
public AggregatedFetchScopePrivate
83class AggregatedTagFetchScopePrivate :
public AggregatedFetchScopePrivate
90 int fetchRemoteId = 0;
91 int doNotFetchAllAttributes = 0;
94class AggregatedItemFetchScopePrivate :
public AggregatedFetchScopePrivate
97 mutable Protocol::ItemFetchScope mCachedScope;
98 mutable bool mCachedScopeValid =
false;
105 int ancestors[3] = {0, 0, 0};
108 int allAttributes = 0;
112 int ignoreErrors = 0;
117 int fetchRelations = 0;
125using namespace Akonadi::Protocol;
126using namespace Akonadi::Server;
128AggregatedCollectionFetchScope::AggregatedCollectionFetchScope()
129 : d_ptr(new AggregatedCollectionFetchScopePrivate)
133AggregatedCollectionFetchScope::~AggregatedCollectionFetchScope() =
default;
135void AggregatedCollectionFetchScope::apply(
const Protocol::CollectionFetchScope &oldScope,
const Protocol::CollectionFetchScope &newScope)
137 LOCKED_D(AggregatedCollectionFetchScope)
139 if (newScope.includeStatistics() != oldScope.includeStatistics()) {
140 d->updateBool(newScope.includeStatistics(), d->fetchStats);
142 if (newScope.fetchIdOnly() != oldScope.fetchIdOnly()) {
143 d->updateBool(newScope.fetchIdOnly(), d->fetchIdOnly);
145 if (newScope.attributes() != oldScope.attributes()) {
146 d->applySet(oldScope.attributes(), newScope.attributes(), d->attrs, d->attrsCount);
152 LOCKED_D(
const AggregatedCollectionFetchScope)
156bool AggregatedCollectionFetchScope::fetchIdOnly()
const
158 LOCKED_D(
const AggregatedCollectionFetchScope)
161 return d->fetchIdOnly == d->subscribers;
164bool AggregatedCollectionFetchScope::fetchStatistics()
const
166 LOCKED_D(
const AggregatedCollectionFetchScope);
168 return d->fetchStats > 0;
171void AggregatedCollectionFetchScope::addSubscriber()
173 LOCKED_D(AggregatedCollectionFetchScope)
177void AggregatedCollectionFetchScope::removeSubscriber()
179 LOCKED_D(AggregatedCollectionFetchScope)
183AggregatedItemFetchScope::AggregatedItemFetchScope()
184 : d_ptr(new AggregatedItemFetchScopePrivate)
188AggregatedItemFetchScope::~AggregatedItemFetchScope() =
default;
190void AggregatedItemFetchScope::apply(
const Protocol::ItemFetchScope &oldScope,
const Protocol::ItemFetchScope &newScope)
192 LOCKED_D(AggregatedItemFetchScope);
194 const auto newParts = newScope.requestedParts() | AkRanges::Actions::toQSet;
195 const auto oldParts = oldScope.requestedParts() | AkRanges::Actions::toQSet;
196 if (newParts != oldParts) {
197 d->applySet(oldParts, newParts, d->parts, d->partsCount);
199 if (newScope.ancestorDepth() != oldScope.ancestorDepth()) {
200 updateAncestorDepth(oldScope.ancestorDepth(), newScope.ancestorDepth());
202 if (newScope.cacheOnly() != oldScope.cacheOnly()) {
203 d->updateBool(newScope.cacheOnly(), d->cacheOnly);
205 if (newScope.fullPayload() != oldScope.fullPayload()) {
206 d->updateBool(newScope.fullPayload(), d->fullPayload);
208 if (newScope.allAttributes() != oldScope.allAttributes()) {
209 d->updateBool(newScope.allAttributes(), d->allAttributes);
211 if (newScope.fetchSize() != oldScope.fetchSize()) {
212 d->updateBool(newScope.fetchSize(), d->fetchSize);
214 if (newScope.fetchMTime() != oldScope.fetchMTime()) {
215 d->updateBool(newScope.fetchMTime(), d->fetchMTime);
217 if (newScope.fetchRemoteRevision() != oldScope.fetchRemoteRevision()) {
218 d->updateBool(newScope.fetchRemoteRevision(), d->fetchRRev);
220 if (newScope.ignoreErrors() != oldScope.ignoreErrors()) {
221 d->updateBool(newScope.ignoreErrors(), d->ignoreErrors);
223 if (newScope.fetchFlags() != oldScope.fetchFlags()) {
224 d->updateBool(newScope.fetchFlags(), d->fetchFlags);
226 if (newScope.fetchRemoteId() != oldScope.fetchRemoteId()) {
227 d->updateBool(newScope.fetchRemoteId(), d->fetchRID);
229 if (newScope.fetchGID() != oldScope.fetchGID()) {
230 d->updateBool(newScope.fetchGID(), d->fetchGID);
232 if (newScope.fetchTags() != oldScope.fetchTags()) {
233 d->updateBool(newScope.fetchTags(), d->fetchTags);
235 if (newScope.fetchRelations() != oldScope.fetchRelations()) {
236 d->updateBool(newScope.fetchRelations(), d->fetchRelations);
238 if (newScope.fetchVirtualReferences() != oldScope.fetchVirtualReferences()) {
239 d->updateBool(newScope.fetchVirtualReferences(), d->fetchVRefs);
242 d->mCachedScopeValid =
false;
247 LOCKED_D(
const AggregatedItemFetchScope);
248 if (d->mCachedScopeValid) {
249 return d->mCachedScope;
253 d->mCachedScope.setRequestedParts(d->parts | AkRanges::Actions::toQVector);
254 d->mCachedScope.setAncestorDepth(ancestorDepth());
256 d->mCachedScope.setFetch(ItemFetchScope::CacheOnly, cacheOnly());
257 d->mCachedScope.setFetch(ItemFetchScope::FullPayload, fullPayload());
258 d->mCachedScope.setFetch(ItemFetchScope::AllAttributes, allAttributes());
259 d->mCachedScope.setFetch(ItemFetchScope::Size, fetchSize());
260 d->mCachedScope.setFetch(ItemFetchScope::MTime, fetchMTime());
261 d->mCachedScope.setFetch(ItemFetchScope::RemoteRevision, fetchRemoteRevision());
262 d->mCachedScope.setFetch(ItemFetchScope::IgnoreErrors, ignoreErrors());
263 d->mCachedScope.setFetch(ItemFetchScope::Flags, fetchFlags());
264 d->mCachedScope.setFetch(ItemFetchScope::RemoteID, fetchRemoteId());
265 d->mCachedScope.setFetch(ItemFetchScope::GID, fetchGID());
266 d->mCachedScope.setFetch(ItemFetchScope::Tags, fetchTags());
267 d->mCachedScope.setFetch(ItemFetchScope::Relations, fetchRelations());
268 d->mCachedScope.setFetch(ItemFetchScope::VirtReferences, fetchVirtualReferences());
269 d->mCachedScopeValid =
true;
270 return d->mCachedScope;
275 LOCKED_D(
const AggregatedItemFetchScope)
279ItemFetchScope::AncestorDepth AggregatedItemFetchScope::ancestorDepth()
const
281 LOCKED_D(
const AggregatedItemFetchScope)
283 if (d->ancestors[ItemFetchScope::AllAncestors] > 0) {
284 return ItemFetchScope::AllAncestors;
285 }
else if (d->ancestors[ItemFetchScope::ParentAncestor] > 0) {
286 return ItemFetchScope::ParentAncestor;
288 return ItemFetchScope::NoAncestor;
292void AggregatedItemFetchScope::updateAncestorDepth(ItemFetchScope::AncestorDepth oldDepth, ItemFetchScope::AncestorDepth newDepth)
294 LOCKED_D(AggregatedItemFetchScope)
295 if (d->ancestors[oldDepth] > 0) {
296 --d->ancestors[oldDepth];
298 ++d->ancestors[newDepth];
301bool AggregatedItemFetchScope::cacheOnly()
const
303 LOCKED_D(
const AggregatedItemFetchScope)
306 return d->cacheOnly == d->subscribers;
309bool AggregatedItemFetchScope::fullPayload()
const
311 LOCKED_D(
const AggregatedItemFetchScope)
314 return d->fullPayload > 0;
317bool AggregatedItemFetchScope::allAttributes()
const
319 LOCKED_D(
const AggregatedItemFetchScope)
322 return d->allAttributes > 0;
325bool AggregatedItemFetchScope::fetchSize()
const
327 LOCKED_D(
const AggregatedItemFetchScope)
329 return d->fetchSize > 0;
332bool AggregatedItemFetchScope::fetchMTime()
const
334 LOCKED_D(
const AggregatedItemFetchScope)
336 return d->fetchMTime > 0;
339bool AggregatedItemFetchScope::fetchRemoteRevision()
const
341 LOCKED_D(
const AggregatedItemFetchScope)
343 return d->fetchRRev > 0;
346bool AggregatedItemFetchScope::ignoreErrors()
const
348 LOCKED_D(
const AggregatedItemFetchScope)
351 return d->ignoreErrors == d->subscribers;
354bool AggregatedItemFetchScope::fetchFlags()
const
356 LOCKED_D(
const AggregatedItemFetchScope)
358 return d->fetchFlags > 0;
361bool AggregatedItemFetchScope::fetchRemoteId()
const
363 LOCKED_D(
const AggregatedItemFetchScope)
365 return d->fetchRID > 0;
368bool AggregatedItemFetchScope::fetchGID()
const
370 LOCKED_D(
const AggregatedItemFetchScope)
372 return d->fetchGID > 0;
375bool AggregatedItemFetchScope::fetchTags()
const
377 LOCKED_D(
const AggregatedItemFetchScope)
379 return d->fetchTags > 0;
382bool AggregatedItemFetchScope::fetchRelations()
const
384 LOCKED_D(
const AggregatedItemFetchScope)
386 return d->fetchRelations > 0;
389bool AggregatedItemFetchScope::fetchVirtualReferences()
const
391 LOCKED_D(
const AggregatedItemFetchScope)
393 return d->fetchVRefs > 0;
396void AggregatedItemFetchScope::addSubscriber()
398 LOCKED_D(AggregatedItemFetchScope)
402void AggregatedItemFetchScope::removeSubscriber()
404 LOCKED_D(AggregatedItemFetchScope)
408AggregatedTagFetchScope::AggregatedTagFetchScope()
409 : d_ptr(new AggregatedTagFetchScopePrivate)
413AggregatedTagFetchScope::~AggregatedTagFetchScope() =
default;
415void AggregatedTagFetchScope::apply(
const Protocol::TagFetchScope &oldScope,
const Protocol::TagFetchScope &newScope)
417 LOCKED_D(AggregatedTagFetchScope)
419 if (newScope.fetchIdOnly() != oldScope.fetchIdOnly()) {
420 d->updateBool(newScope.fetchIdOnly(), d->fetchIdOnly);
422 if (newScope.fetchRemoteID() != oldScope.fetchRemoteID()) {
423 d->updateBool(newScope.fetchRemoteID(), d->fetchRemoteId);
425 if (newScope.fetchAllAttributes() != oldScope.fetchAllAttributes()) {
427 d->updateBool(!newScope.fetchAllAttributes(), d->doNotFetchAllAttributes);
429 if (newScope.attributes() != oldScope.attributes()) {
430 d->applySet(oldScope.attributes(), newScope.attributes(), d->attrs, d->attrsCount);
434Protocol::TagFetchScope AggregatedTagFetchScope::toFetchScope()
const
436 Protocol::TagFetchScope tfs;
437 tfs.setFetchIdOnly(fetchIdOnly());
438 tfs.setFetchRemoteID(fetchRemoteId());
439 tfs.setFetchAllAttributes(fetchAllAttributes());
440 tfs.setAttributes(attributes());
444bool AggregatedTagFetchScope::fetchIdOnly()
const
446 LOCKED_D(
const AggregatedTagFetchScope)
449 return d->fetchIdOnly == d->subscribers;
452bool AggregatedTagFetchScope::fetchRemoteId()
const
454 LOCKED_D(
const AggregatedTagFetchScope)
455 return d->fetchRemoteId > 0;
458bool AggregatedTagFetchScope::fetchAllAttributes()
const
460 LOCKED_D(
const AggregatedTagFetchScope)
462 return d->doNotFetchAllAttributes != d->subscribers;
467 LOCKED_D(
const AggregatedTagFetchScope)
471void AggregatedTagFetchScope::addSubscriber()
473 LOCKED_D(AggregatedTagFetchScope)
477void AggregatedTagFetchScope::removeSubscriber()
479 LOCKED_D(AggregatedTagFetchScope)
Specifies which parts of an item should be fetched from the Akonadi storage.
Helper integration between Akonadi and Qt.
iterator erase(const_iterator pos)
iterator find(const Key &key)
iterator insert(const Key &key, const T &value)
iterator insert(const T &value)
bool remove(const T &value)