20 #include "recursiveitemfetchjob.h"
22 #include <akonadi/collectionfetchjob.h>
23 #include <akonadi/collectionfetchscope.h>
24 #include <akonadi/itemfetchjob.h>
25 #include <akonadi/itemfetchscope.h>
27 #include <QtCore/QStringList>
28 #include <QtCore/QVariant>
30 using namespace Akonadi;
32 class RecursiveItemFetchJob::Private
35 Private(
const Collection &collection,
const QStringList &mimeTypes, RecursiveItemFetchJob *parent )
36 : mParent( parent ), mCollection( collection ), mMimeTypes( mimeTypes ), mFetchCount( 0 )
40 void collectionFetchResult( KJob *job )
43 mParent->emitResult();
47 const CollectionFetchJob *fetchJob = qobject_cast<CollectionFetchJob*>( job );
49 Collection::List collections = fetchJob->collections();
50 collections.prepend( mCollection );
52 foreach (
const Collection &collection, collections ) {
53 ItemFetchJob *itemFetchJob =
new ItemFetchJob( collection, mParent );
54 itemFetchJob->setFetchScope( mFetchScope );
55 mParent->connect( itemFetchJob, SIGNAL(result(KJob*)),
56 mParent, SLOT(itemFetchResult(KJob*)) );
62 void itemFetchResult( KJob *job )
64 if ( !job->error() ) {
65 const ItemFetchJob *fetchJob = qobject_cast<ItemFetchJob*>( job );
67 if ( !mMimeTypes.isEmpty() ) {
68 foreach (
const Item &item, fetchJob->items() ) {
69 if ( mMimeTypes.contains( item.mimeType() ) )
73 mItems << fetchJob->items();
79 if ( mFetchCount == 0 )
80 mParent->emitResult();
83 RecursiveItemFetchJob *mParent;
84 Collection mCollection;
86 ItemFetchScope mFetchScope;
87 QStringList mMimeTypes;
92 RecursiveItemFetchJob::RecursiveItemFetchJob(
const Collection &collection,
93 const QStringList &mimeTypes,
95 : KJob( parent ), d( new Private( collection, mimeTypes, this ) )
99 RecursiveItemFetchJob::~RecursiveItemFetchJob()
104 void RecursiveItemFetchJob::setFetchScope(
const ItemFetchScope &fetchScope )
106 d->mFetchScope = fetchScope;
109 ItemFetchScope &RecursiveItemFetchJob::fetchScope()
111 return d->mFetchScope;
114 void RecursiveItemFetchJob::start()
116 CollectionFetchJob *job =
new CollectionFetchJob( d->mCollection, CollectionFetchJob::Recursive,
this );
118 if ( !d->mMimeTypes.isEmpty() )
119 job->fetchScope().setContentMimeTypes( d->mMimeTypes );
121 connect( job, SIGNAL(result(KJob*)),
this, SLOT(collectionFetchResult(KJob*)) );
129 #include "recursiveitemfetchjob.moc"