File indexing completed on 2024-11-17 04:44:57
0001 /* 0002 SPDX-FileCopyrightText: 2015-2020 Krzysztof Nowicki <krissn@op.pl> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include <Akonadi/ItemFetchJob> 0010 0011 #include "ewsfinditemrequest.h" 0012 #include "ewsjob.h" 0013 0014 namespace Akonadi 0015 { 0016 class Collection; 0017 } 0018 class EwsClient; 0019 class EwsTagStore; 0020 class EwsResource; 0021 0022 class EwsFetchItemsJob : public EwsJob 0023 { 0024 Q_OBJECT 0025 public: 0026 struct QueuedUpdate { 0027 QString id; 0028 QString changeKey; 0029 EwsEventType type; 0030 }; 0031 0032 using QueuedUpdateList = QList<QueuedUpdate>; 0033 0034 EwsFetchItemsJob(const Akonadi::Collection &collection, 0035 EwsClient &client, 0036 const QString &syncState, 0037 const EwsId::List &itemsToCheck, 0038 EwsTagStore *tagStore, 0039 EwsResource *parent); 0040 ~EwsFetchItemsJob() override; 0041 0042 Akonadi::Item::List newItems() const 0043 { 0044 return mNewItems; 0045 } 0046 0047 Akonadi::Item::List changedItems() const 0048 { 0049 return mChangedItems; 0050 } 0051 0052 Akonadi::Item::List deletedItems() const 0053 { 0054 return mDeletedItems; 0055 } 0056 0057 const QString &syncState() const 0058 { 0059 return mSyncState; 0060 } 0061 0062 const Akonadi::Collection &collection() const 0063 { 0064 return mCollection; 0065 } 0066 0067 void setQueuedUpdates(const QueuedUpdateList &updates); 0068 0069 void start() override; 0070 private Q_SLOTS: 0071 void localItemFetchDone(KJob *job); 0072 void remoteItemFetchDone(KJob *job); 0073 void itemDetailFetchDone(KJob *job); 0074 void checkedItemsFetchFinished(KJob *job); 0075 void tagSyncFinished(KJob *job); 0076 Q_SIGNALS: 0077 void reportStatus(int status, const QString &message = QString()); 0078 void reportPercent(ulong progress); 0079 0080 private: 0081 void compareItemLists(); 0082 void syncTags(); 0083 bool processIncrementalRemoteItemUpdates(const EwsItem::List &items, 0084 QHash<QString, Akonadi::Item> &itemHash, 0085 QHash<EwsItemType, Akonadi::Item::List> &toFetchItems); 0086 0087 /*struct QueuedUpdateInt { 0088 QString changeKey; 0089 EwsEventType type; 0090 };*/ 0091 using QueuedUpdateHash = QHash<EwsEventType, QHash<QString, QString>>; 0092 0093 const Akonadi::Collection mCollection; 0094 EwsClient &mClient; 0095 EwsId::List mItemsToCheck; 0096 Akonadi::Item::List mLocalItems; 0097 EwsItem::List mRemoteAddedItems; 0098 EwsItem::List mRemoteChangedItems; 0099 EwsId::List mRemoteDeletedIds; 0100 QHash<EwsId, bool> mRemoteFlagChangedIds; 0101 int mPendingJobs; 0102 unsigned mTotalItemsToFetch; 0103 unsigned mTotalItemsFetched; 0104 QString mSyncState; 0105 bool mFullSync; 0106 QueuedUpdateHash mQueuedUpdates; 0107 EwsTagStore *mTagStore = nullptr; 0108 bool mTagsSynced; 0109 0110 Akonadi::Item::List mNewItems; 0111 Akonadi::Item::List mChangedItems; 0112 Akonadi::Item::List mDeletedItems; 0113 };