File indexing completed on 2025-01-05 04:47:03

0001 /*
0002     SPDX-FileCopyrightText: 2008 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "collectionscheduler.h"
0010 
0011 #include <QDateTime>
0012 #include <QHash>
0013 
0014 namespace Akonadi
0015 {
0016 namespace Server
0017 {
0018 class ItemRetrievalManager;
0019 
0020 /**
0021   Interval checking thread.
0022 */
0023 class IntervalCheck : public CollectionScheduler
0024 {
0025     Q_OBJECT
0026 
0027 protected:
0028     /**
0029      * Use AkThread::create() to create and start a new IntervalCheck thread.
0030      */
0031     explicit IntervalCheck(ItemRetrievalManager &itemRetrievalManager);
0032 
0033 public:
0034     ~IntervalCheck() override;
0035 
0036     /**
0037      * Requests the given collection to be synced.
0038      * Executed from any thread, forwards to triggerCollectionXSync() in the
0039      * retrieval thread.
0040      * A minimum time interval between two sync requests is ensured.
0041      */
0042     void requestCollectionSync(const Collection &collection);
0043 
0044 protected:
0045     int collectionScheduleInterval(const Collection &collection) override;
0046     bool hasChanged(const Collection &collection, const Collection &changed) override;
0047     bool shouldScheduleCollection(const Collection &collection) override;
0048 
0049     void collectionExpired(const Collection &collection) override;
0050 
0051 private:
0052     QHash<int, QDateTime> mLastChecks;
0053     QHash<QString, QDateTime> mLastCollectionTreeSyncs;
0054     ItemRetrievalManager &mItemRetrievalManager;
0055 };
0056 
0057 } // namespace Server
0058 } // namespace Akonadi