void EventModel::initModel() { createHeaderItems(m_headerPartsList); Akonadi::CollectionFetchScope scope; QStringList mimeTypes; mimeTypes << Akonadi::IncidenceMimeTypeVisitor::eventMimeType(); mimeTypes << Akonadi::IncidenceMimeTypeVisitor::todoMimeType(); mimeTypes << "text/calendar"; scope.setContentMimeTypes(mimeTypes); Akonadi::CollectionFetchJob *job = new Akonadi::CollectionFetchJob(Akonadi::Collection::root(), Akonadi::CollectionFetchJob::Recursive); job->setFetchScope(scope); connect(job, SIGNAL(result(KJob *)), this, SLOT(initialCollectionFetchFinished(KJob *))); job->start(); }
bool KonsoleKalendar::printCalendarList() { Akonadi::CollectionFetchJob *job = new Akonadi::CollectionFetchJob(Akonadi::Collection::root(), Akonadi::CollectionFetchJob::Recursive); QStringList mimeTypes = QStringList() << QStringLiteral("text/calendar") << KCalCore::Event::eventMimeType() << KCalCore::Todo::todoMimeType() << KCalCore::Journal::journalMimeType(); job->fetchScope().setContentMimeTypes(mimeTypes); QEventLoop loop; QObject::connect(job, &Akonadi::CollectionFetchJob::result, &loop, &QEventLoop::quit); job->start(); loop.exec(); if (job->error() != 0) { return false; } Akonadi::Collection::List collections = job->collections(); if (collections.isEmpty()) { cout << i18n("There are no calendars available.").toLocal8Bit().data() << endl; } else { cout << "--------------------------" << endl; QSet<QString> mimeTypeSet = mimeTypes.toSet(); foreach (const Akonadi::Collection &collection, collections) { if (!mimeTypeSet.intersect(collection.contentMimeTypes().toSet()).isEmpty()) { QString colId = QString::number(collection.id()).leftJustified(6, QLatin1Char(' ')); colId += QLatin1String("- "); bool readOnly = !(collection.rights() & Akonadi::Collection::CanCreateItem || collection.rights() & Akonadi::Collection::CanChangeItem || collection.rights() & Akonadi::Collection::CanDeleteItem); QString readOnlyString = readOnly ? i18n("(Read only)") + QLatin1Char(' ') : QString(); cout << colId.toLocal8Bit().data() << readOnlyString.toLocal8Bit().constData() << collection.displayName().toLocal8Bit().data() << endl; } } } return true; }