Akonadi

intervalcheck.cpp
1/*
2 SPDX-FileCopyrightText: 2008 Volker Krause <vkrause@kde.org>
3 SPDX-FileCopyrightText: 2014 Daniel Vrátil <dvraitl@redhat.com>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#include "intervalcheck.h"
9#include "storage/datastore.h"
10#include "storage/entity.h"
11#include "storage/itemretrievalmanager.h"
12
13using namespace Akonadi::Server;
14
15static const int MINIMUM_AUTOSYNC_INTERVAL = 5; // minutes
16static const int MINIMUM_COLTREESYNC_INTERVAL = 5; // minutes
17
19 : CollectionScheduler(QStringLiteral("IntervalCheck"), QThread::IdlePriority)
20 , mItemRetrievalManager(itemRetrievalManager)
21{
22}
23
24IntervalCheck::~IntervalCheck()
25{
26 quitThread();
27}
28
30{
32 this,
33 [this, collection]() {
34 collectionExpired(collection);
35 },
37}
38
39int IntervalCheck::collectionScheduleInterval(const Collection &collection)
40{
41 return collection.cachePolicyCheckInterval();
42}
43
44bool IntervalCheck::hasChanged(const Collection &collection, const Collection &changed)
45{
46 return collection.cachePolicyCheckInterval() != changed.cachePolicyCheckInterval() || collection.enabled() != changed.enabled()
47 || collection.syncPref() != changed.syncPref();
48}
49
50bool IntervalCheck::shouldScheduleCollection(const Collection &collection)
51{
52 return collection.cachePolicyCheckInterval() > 0
53 && ((collection.syncPref() == Collection::True) || ((collection.syncPref() == Collection::Undefined) && collection.enabled()));
54}
55
56void IntervalCheck::collectionExpired(const Collection &collection)
57{
59
60 if (collection.parentId() == 0) {
61 const QString resourceName = collection.resource().name();
62
63 const int interval = qMax(MINIMUM_COLTREESYNC_INTERVAL, collection.cachePolicyCheckInterval());
64
65 const QDateTime lastExpectedCheck = now.addSecs(interval * -60);
66 if (!mLastCollectionTreeSyncs.contains(resourceName) || mLastCollectionTreeSyncs.value(resourceName) < lastExpectedCheck) {
67 mLastCollectionTreeSyncs.insert(resourceName, now);
68 mItemRetrievalManager.triggerCollectionTreeSync(resourceName);
69 }
70 }
71
72 // now on to the actual collection syncing
73 const int interval = qMax(MINIMUM_AUTOSYNC_INTERVAL, collection.cachePolicyCheckInterval());
74
75 const QDateTime lastExpectedCheck = now.addSecs(interval * -60);
76 if (mLastChecks.contains(collection.id()) && mLastChecks.value(collection.id()) > lastExpectedCheck) {
77 return;
78 }
79 mLastChecks.insert(collection.id(), now);
80 mItemRetrievalManager.triggerCollectionSync(collection.resource().name(), collection.id());
81}
82
83#include "moc_intervalcheck.cpp"
Represents a collection of PIM items.
Definition collection.h:62
IntervalCheck(ItemRetrievalManager &itemRetrievalManager)
Use AkThread::create() to create and start a new IntervalCheck thread.
void requestCollectionSync(const Collection &collection)
Requests the given collection to be synced.
Manages and processes item retrieval requests.
QDateTime currentDateTime()
bool contains(const Key &key) const const
iterator insert(const Key &key, const T &value)
T value(const Key &key) const const
bool invokeMethod(QObject *context, Functor &&function, FunctorReturnType *ret)
T qobject_cast(QObject *object)
QueuedConnection
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:13:38 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.