File indexing completed on 2024-05-12 05:11:15
0001 /* 0002 * SPDX-FileCopyrightText: 2014 Christian Mollekopf <mollekopf@kolabsys.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 * 0006 */ 0007 #include "collectionupdatejob.h" 0008 #include "akonadi_indexer_agent_debug.h" 0009 0010 #include <Akonadi/CollectionFetchJob> 0011 #include <Akonadi/CollectionFetchScope> 0012 #include <Akonadi/EntityDisplayAttribute> 0013 #include <Akonadi/IndexPolicyAttribute> 0014 0015 CollectionUpdateJob::CollectionUpdateJob(Index &index, const Akonadi::Collection &col, QObject *parent) 0016 : KJob(parent) 0017 , mCol(col) 0018 , mIndex(index) 0019 { 0020 } 0021 0022 void CollectionUpdateJob::start() 0023 { 0024 if (shouldIndex(mCol)) { 0025 mIndex.change(mCol); 0026 } 0027 0028 // Fetch children to update the path accordingly 0029 auto fetchJob = new Akonadi::CollectionFetchJob(mCol, Akonadi::CollectionFetchJob::Recursive, this); 0030 fetchJob->fetchScope().setAncestorRetrieval(Akonadi::CollectionFetchScope::All); 0031 fetchJob->fetchScope().ancestorFetchScope().fetchAttribute<Akonadi::EntityDisplayAttribute>(); 0032 fetchJob->fetchScope().setListFilter(Akonadi::CollectionFetchScope::NoFilter); 0033 fetchJob->fetchScope().fetchAttribute<Akonadi::IndexPolicyAttribute>(); 0034 connect(fetchJob, &Akonadi::CollectionFetchJob::collectionsReceived, this, &CollectionUpdateJob::onCollectionsReceived); 0035 connect(fetchJob, &KJob::result, this, &CollectionUpdateJob::onCollectionsFetched); 0036 } 0037 0038 void CollectionUpdateJob::onCollectionsReceived(const Akonadi::Collection::List &list) 0039 { 0040 // Required to update the path 0041 for (const Akonadi::Collection &child : list) { 0042 if (shouldIndex(mCol)) { 0043 mIndex.change(child); 0044 } 0045 } 0046 } 0047 0048 void CollectionUpdateJob::onCollectionsFetched(KJob *job) 0049 { 0050 if (job->error()) { 0051 qCWarning(AKONADI_INDEXER_AGENT_LOG) << job->errorString(); 0052 } 0053 emitResult(); 0054 } 0055 0056 bool CollectionUpdateJob::shouldIndex(const Akonadi::Collection &col) const 0057 { 0058 return !col.isVirtual() && (!mCol.hasAttribute<Akonadi::IndexPolicyAttribute>() || mCol.attribute<Akonadi::IndexPolicyAttribute>()->indexingEnabled()); 0059 } 0060 0061 #include "moc_collectionupdatejob.cpp"