SVN_SILENT made messages (.desktop file)
[kdepim.git] / console / calendarjanitor / collectionloader.cpp
blob7e55a7279c0f19e4dd5e34c4494ea43212b2b847
1 /*
2 Copyright (c) 2013 Sérgio Martins <iamsergio@gmail.com>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 As a special exception, permission is given to link this program
19 with any edition of Qt, and distribute the resulting executable,
20 without including the source code for Qt in the source distribution.
23 #include "collectionloader.h"
25 #include <KCalCore/Incidence>
27 #include <Akonadi/CollectionFetchJob>
28 #include <Akonadi/CollectionFetchScope>
29 #include <QString>
30 #include <QSet>
33 CollectionLoader::CollectionLoader(QObject *parent) :
34 QObject(parent)
38 void CollectionLoader::load()
40 Akonadi::CollectionFetchJob *job = new Akonadi::CollectionFetchJob(Akonadi::Collection::root(),
41 Akonadi::CollectionFetchJob::Recursive);
43 job->fetchScope().setContentMimeTypes(KCalCore::Incidence::mimeTypes());
44 connect(job, SIGNAL(result(KJob*)), SLOT(onCollectionsLoaded(KJob*)));
45 job->start();
48 Akonadi::Collection::List CollectionLoader::collections() const
50 return m_collections;
53 void CollectionLoader::onCollectionsLoaded(KJob *job)
55 if (job->error() == 0) {
56 Akonadi::CollectionFetchJob *cfj = qobject_cast<Akonadi::CollectionFetchJob*>(job);
57 Q_ASSERT(cfj);
58 foreach(const Akonadi::Collection &collection, cfj->collections()) {
59 QSet<QString> mimeTypeSet = KCalCore::Incidence::mimeTypes().toSet();
60 if (!mimeTypeSet.intersect(collection.contentMimeTypes().toSet()).isEmpty()) {
61 m_collections << collection;
64 emit loaded(true);
65 } else {
66 kError() << job->errorString();
67 emit loaded(false);