void Akonadi::SpecialCollectionsDiscoveryJob::slotResult(KJob *job) { if (job->error()) { qCWarning(AKONADICORE_LOG) << job->errorString(); return; } Akonadi::CollectionFetchJob *fetchJob = qobject_cast<Akonadi::CollectionFetchJob *>(job); foreach (const Akonadi::Collection &collection, fetchJob->collections()) { if (collection.hasAttribute<SpecialCollectionAttribute>()) { d->mSpecialCollections->registerCollection(collection.attribute<SpecialCollectionAttribute>()->collectionType(), collection); } } emitResult(); }
void EventModel::initialCollectionFetchFinished(KJob *job) { if (job->error()) { kDebug() << "Initial collection fetch failed!"; } else { Akonadi::CollectionFetchJob *cJob = qobject_cast<Akonadi::CollectionFetchJob *>(job); Akonadi::Collection::List collections = cJob->collections(); foreach (const Akonadi::Collection &collection, collections) { m_collections.insert(collection.id(), collection); Akonadi::ItemFetchJob *job = new Akonadi::ItemFetchJob(collection); job->fetchScope().fetchFullPayload(); job->fetchScope().setAncestorRetrieval( Akonadi::ItemFetchScope::Parent ); connect(job, SIGNAL(result(KJob *)), this, SLOT(initialItemFetchFinished(KJob *))); job->start(); } }
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; }