File indexing completed on 2024-05-12 05:10:38

0001 /*
0002     SPDX-FileCopyrightText: 2013 Sérgio Martins <iamsergio@gmail.com>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "helper.h"
0008 
0009 #include <Akonadi/CollectionFetchJob>
0010 #include <Akonadi/CollectionFetchScope>
0011 #include <Akonadi/ItemFetchJob>
0012 
0013 #include <QStringList>
0014 
0015 using namespace Akonadi;
0016 
0017 bool Helper::confirmExists(const Akonadi::Item &item)
0018 {
0019     auto job = new ItemFetchJob(item);
0020     return job->exec() != 0;
0021 }
0022 
0023 bool Helper::confirmDoesntExist(const Akonadi::Item &item)
0024 {
0025     auto job = new ItemFetchJob(item);
0026     return job->exec() == 0;
0027 }
0028 
0029 Akonadi::Collection Helper::fetchCollection()
0030 {
0031     auto job = new CollectionFetchJob(Collection::root(), CollectionFetchJob::Recursive);
0032     // Get list of collections
0033     job->fetchScope().setContentMimeTypes(QStringList() << QStringLiteral("application/x-vnd.akonadi.calendar.event"));
0034     const bool ret = job->exec();
0035     Q_ASSERT(ret);
0036     Q_UNUSED(ret)
0037 
0038     // Find our collection
0039     const Collection::List collections = job->collections();
0040     Q_ASSERT(!collections.isEmpty());
0041     Collection collection = collections.first();
0042 
0043     Q_ASSERT(collection.isValid());
0044 
0045     return collection;
0046 }