1 | /* |
2 | Copyright (c) 2013 David Faure <faure@kde.org> |
3 | |
4 | This library is free software; you can redistribute it and/or modify it |
5 | under the terms of the GNU Library General Public License as published by |
6 | the Free Software Foundation; either version 2 of the License, or (at your |
7 | option) any later version. |
8 | |
9 | This library is distributed in the hope that it will be useful, but WITHOUT |
10 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
11 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public |
12 | License for more details. |
13 | |
14 | You should have received a copy of the GNU Library General Public License |
15 | along with this library; see the file COPYING.LIB. If not, write to the |
16 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
17 | 02110-1301, USA. |
18 | */ |
19 | |
20 | #include "specialcollectionsdiscoveryjob.h" |
21 | #include "specialcollectionattribute_p.h" |
22 | #include <akonadi/collectionfetchscope.h> |
23 | #include <akonadi/collectionfetchjob.h> |
24 | #include <QStringList> |
25 | |
26 | using namespace Akonadi; |
27 | |
28 | /** |
29 | @internal |
30 | */ |
31 | class Akonadi::SpecialCollectionsDiscoveryJobPrivate |
32 | { |
33 | public: |
34 | SpecialCollectionsDiscoveryJobPrivate(SpecialCollections *collections, const QStringList &mimeTypes) |
35 | : mSpecialCollections(collections) |
36 | , mMimeTypes(mimeTypes) |
37 | { |
38 | } |
39 | |
40 | SpecialCollections *mSpecialCollections; |
41 | QStringList mMimeTypes; |
42 | }; |
43 | |
44 | Akonadi::SpecialCollectionsDiscoveryJob::SpecialCollectionsDiscoveryJob(SpecialCollections *collections, const QStringList &mimeTypes, QObject *parent) |
45 | : KCompositeJob(parent) |
46 | , d(new SpecialCollectionsDiscoveryJobPrivate(collections, mimeTypes)) |
47 | { |
48 | } |
49 | |
50 | Akonadi::SpecialCollectionsDiscoveryJob::~SpecialCollectionsDiscoveryJob() |
51 | { |
52 | delete d; |
53 | } |
54 | |
55 | void Akonadi::SpecialCollectionsDiscoveryJob::start() |
56 | { |
57 | CollectionFetchJob *job = new CollectionFetchJob(Collection::root(), CollectionFetchJob::Recursive, this); |
58 | job->fetchScope().setContentMimeTypes(d->mMimeTypes); |
59 | addSubjob(job); |
60 | } |
61 | |
62 | void Akonadi::SpecialCollectionsDiscoveryJob::slotResult(KJob *job) |
63 | { |
64 | if (job->error()) { |
65 | qWarning() << job->errorString(); |
66 | return; |
67 | } |
68 | Akonadi::CollectionFetchJob *fetchJob = qobject_cast<Akonadi::CollectionFetchJob *>(job); |
69 | foreach (const Akonadi::Collection &collection, fetchJob->collections()) { |
70 | if (collection.hasAttribute<SpecialCollectionAttribute>()) { |
71 | d->mSpecialCollections->registerCollection(collection.attribute<SpecialCollectionAttribute>()->collectionType(), collection); |
72 | } |
73 | } |
74 | emitResult(); |
75 | } |
76 | |