File indexing completed on 2024-12-22 04:56:55

0001 /*
0002     SPDX-FileCopyrightText: 2010 Grégory Oestreicher <greg@kamago.net>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "akonadietagcache.h"
0008 
0009 #include <Akonadi/Collection>
0010 #include <Akonadi/Item>
0011 #include <Akonadi/ItemFetchJob>
0012 #include <Akonadi/ItemFetchScope>
0013 
0014 using namespace KDAV;
0015 
0016 AkonadiEtagCache::AkonadiEtagCache(const Akonadi::Collection &collection, QObject *parent)
0017     : KDAV::EtagCache(parent)
0018 {
0019     auto job = new Akonadi::ItemFetchJob(collection);
0020     job->fetchScope().fetchFullPayload(false); // We only need the remote id and the revision
0021     connect(job, &Akonadi::ItemFetchJob::result, this, &AkonadiEtagCache::onItemFetchJobFinished);
0022     job->start();
0023 }
0024 
0025 void AkonadiEtagCache::onItemFetchJobFinished(KJob *job)
0026 {
0027     if (job->error()) {
0028         return;
0029     }
0030 
0031     const Akonadi::ItemFetchJob *fetchJob = qobject_cast<Akonadi::ItemFetchJob *>(job);
0032     const Akonadi::Item::List items = fetchJob->items();
0033 
0034     for (const Akonadi::Item &item : items) {
0035         if (!contains(item.remoteId())) {
0036             setEtagInternal(item.remoteId(), item.remoteRevision());
0037         }
0038     }
0039 }
0040 
0041 #include "moc_akonadietagcache.cpp"