File indexing completed on 2024-11-10 04:40:31
0001 /* 0002 SPDX-FileCopyrightText: 2013 David Faure <faure@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "specialcollectionsdiscoveryjob.h" 0008 #include "collectionfetchjob.h" 0009 #include "collectionfetchscope.h" 0010 #include "specialcollectionattribute.h" 0011 #include <QStringList> 0012 0013 #include "akonadicore_debug.h" 0014 0015 using namespace Akonadi; 0016 0017 /** 0018 @internal 0019 */ 0020 class Akonadi::SpecialCollectionsDiscoveryJobPrivate 0021 { 0022 public: 0023 SpecialCollectionsDiscoveryJobPrivate(SpecialCollections *collections, const QStringList &mimeTypes) 0024 : mSpecialCollections(collections) 0025 , mMimeTypes(mimeTypes) 0026 { 0027 } 0028 0029 SpecialCollections *const mSpecialCollections; 0030 const QStringList mMimeTypes; 0031 }; 0032 0033 Akonadi::SpecialCollectionsDiscoveryJob::SpecialCollectionsDiscoveryJob(SpecialCollections *collections, const QStringList &mimeTypes, QObject *parent) 0034 : KCompositeJob(parent) 0035 , d(new SpecialCollectionsDiscoveryJobPrivate(collections, mimeTypes)) 0036 { 0037 } 0038 0039 Akonadi::SpecialCollectionsDiscoveryJob::~SpecialCollectionsDiscoveryJob() = default; 0040 0041 void Akonadi::SpecialCollectionsDiscoveryJob::start() 0042 { 0043 auto job = new CollectionFetchJob(Collection::root(), CollectionFetchJob::Recursive, this); 0044 job->fetchScope().setContentMimeTypes(d->mMimeTypes); 0045 addSubjob(job); 0046 } 0047 0048 void Akonadi::SpecialCollectionsDiscoveryJob::slotResult(KJob *job) 0049 { 0050 if (job->error()) { 0051 qCWarning(AKONADICORE_LOG) << job->errorString(); 0052 return; 0053 } 0054 auto fetchJob = qobject_cast<Akonadi::CollectionFetchJob *>(job); 0055 const Akonadi::Collection::List lstCollections = fetchJob->collections(); 0056 for (const Akonadi::Collection &collection : lstCollections) { 0057 if (collection.hasAttribute<SpecialCollectionAttribute>()) { 0058 d->mSpecialCollections->registerCollection(collection.attribute<SpecialCollectionAttribute>()->collectionType(), collection); 0059 } 0060 } 0061 emitResult(); 0062 } 0063 0064 #include "moc_specialcollectionsdiscoveryjob.cpp"