void RecursiveMover::collectionListResult( KJob *job ) { Q_ASSERT( m_pendingCollections.isEmpty() ); --m_runningJobs; if ( job->error() ) return; // error handling is in the base class // build a parent -> children map for the following topological sorting // while we are iterating anyway, also fill m_collections here CollectionFetchJob *fetchJob = qobject_cast<CollectionFetchJob*>( job ); QHash<Collection::Id, Collection::List> colTree; foreach ( const Collection &col, fetchJob->collections() ) { colTree[col.parentCollection().id()] << col; m_collections.insert( col.id(), col ); } // topological sort; BFS traversal of the tree m_pendingCollections.push_back( m_movedCollection ); QQueue<Collection> toBeProcessed; toBeProcessed.enqueue( m_movedCollection ); while ( !toBeProcessed.isEmpty() ) { const Collection col = toBeProcessed.dequeue(); const Collection::List children = colTree.value( col.id() ); if ( children.isEmpty() ) continue; m_pendingCollections.append( children ); foreach ( const Collection &child, children ) toBeProcessed.enqueue( child ); } replayNextCollection(); }
void EntityTreeModelFactory::createFromRemoteId(const QString& remoteId) { Session *session = new Session("TEST", this); CollectionFetchJob *job = new CollectionFetchJob( Collection::root(), CollectionFetchJob::FirstLevel, session); job->setProperty(WANTED_REMOTE_ID, remoteId); connect(job, SIGNAL(collectionsReceived(Akonadi::Collection::List)), SLOT(collectionsFetched(Akonadi::Collection::List))); }
/****************************************************************************** * Find the collection which this agent manages. */ void CalendarCreator::fetchCollection() { CollectionFetchJob* job = new CollectionFetchJob(Collection::root(), CollectionFetchJob::FirstLevel); job->fetchScope().setResource(mAgent.identifier()); connect(job, SIGNAL(result(KJob*)), SLOT(collectionFetchResult(KJob*))); job->start(); }
void akonadimailsearch::query(QString &search) { mysearch=search; CollectionFetchJob *fetchJob = new CollectionFetchJob(Collection::root(), CollectionFetchJob::Recursive, this); fetchJob->fetchScope().setContentMimeTypes( QStringList() << "text/directory" ); connect(fetchJob, SIGNAL(finished(KJob*)), SLOT(onCollectionsFetched(KJob*))); }
void AkonadiSlave::listDir(const QUrl &url) { qCDebug(AKONADISLAVE_LOG) << url; if (!Collection::fromUrl(url).isValid()) { error(KIO::ERR_DOES_NOT_EXIST, i18n("No such collection.")); return; } // Fetching collections Collection collection = Collection::fromUrl(url); if (!collection.isValid()) { error(KIO::ERR_DOES_NOT_EXIST, i18n("No such collection.")); return; } CollectionFetchJob *job = new CollectionFetchJob(collection, CollectionFetchJob::FirstLevel); if (!job->exec()) { error(KIO::ERR_CANNOT_ENTER_DIRECTORY, job->errorString()); return; } Collection::List collections = job->collections(); foreach (const Collection &col, collections) { listEntry(entryForCollection(col)); }
void RecursiveMover::changeProcessed() { Q_ASSERT( m_currentAction != None ); if ( m_currentAction == AddCollection ) { Q_ASSERT( m_currentCollection.isValid() ); CollectionFetchJob *job = new CollectionFetchJob( m_currentCollection, CollectionFetchJob::Base, this ); job->fetchScope().setAncestorRetrieval( CollectionFetchScope::All ); connect( job, SIGNAL(result(KJob*)), SLOT(collectionFetchResult(KJob*)) ); addSubjob( job ); ++m_runningJobs; } m_currentAction = None; }
void CalendarBaseTest::fetchCollection() { CollectionFetchJob *job = new CollectionFetchJob(Collection::root(), CollectionFetchJob::Recursive, this); // Get list of collections job->fetchScope().setContentMimeTypes(QStringList() << QStringLiteral("application/x-vnd.akonadi.calendar.event")); AKVERIFYEXEC(job); // Find our collection Collection::List collections = job->collections(); QVERIFY(!collections.isEmpty()); mCollection = collections.first(); QVERIFY(mCollection.isValid()); }
void AkonadiSlave::stat(const QUrl &url) { qCDebug(AKONADISLAVE_LOG) << url; // Stats for a collection if (Collection::fromUrl(url).isValid()) { Collection collection = Collection::fromUrl(url); if (collection != Collection::root()) { // Check that the collection exists. CollectionFetchJob *job = new CollectionFetchJob(collection, CollectionFetchJob::Base); if (!job->exec()) { error(KIO::ERR_INTERNAL, job->errorString()); return; } if (job->collections().count() != 1) { error(KIO::ERR_DOES_NOT_EXIST, i18n("No such item.")); return; } collection = job->collections().at(0); } statEntry(entryForCollection(collection)); finished(); } // Stats for an item else if (Item::fromUrl(url).isValid()) { ItemFetchJob *job = new ItemFetchJob(Item::fromUrl(url)); if (!job->exec()) { error(KIO::ERR_INTERNAL, job->errorString()); return; } if (job->items().count() != 1) { error(KIO::ERR_DOES_NOT_EXIST, i18n("No such item.")); return; } const Item item = job->items().at(0); statEntry(entryForItem(item)); finished(); } }
void AkonadiEngine::fetchMicroBlogCollectionsDone(KJob* job) { // called when the job fetching microblog collections from Akonadi emits result() if ( job->error() ) { kDebug() << "Job Error:" << job->errorString(); } else { CollectionFetchJob* cjob = static_cast<CollectionFetchJob*>( job ); int i = 0; foreach( const Collection &collection, cjob->collections() ) { if (collection.contentMimeTypes().contains("application/x-vnd.kde.microblog")) { kDebug() << "Microblog setting data:" << collection.name() << collection.url() << collection.contentMimeTypes(); i++; setData("MicroblogCollection", QString("MicroBlog-%1").arg(collection.id()), collection.name()); } } kDebug() << i << "MicroBlog collections are in now"; scheduleSourcesUpdated(); } }
void AkonadiEngine::fetchContactCollectionsDone(KJob* job) { // called when the job fetching contact collections from Akonadi emits result() if ( job->error() ) { kDebug() << "Job Error:" << job->errorString(); } else { CollectionFetchJob* cjob = static_cast<CollectionFetchJob*>( job ); int i = 0; foreach( const Collection &collection, cjob->collections() ) { if (collection.contentMimeTypes().contains("text/directory")) { //kDebug() << "ContactCollection setting data:" << collection.name() << collection.url() << collection.contentMimeTypes(); i++; setData("ContactCollections", QString("ContactCollection-%1").arg(collection.id()), collection.name()); } } kDebug() << i << "Contact collections are in now"; scheduleSourcesUpdated(); } }
void RecursiveMover::collectionFetchResult( KJob *job ) { Q_ASSERT( m_currentCollection.isValid() ); --m_runningJobs; if ( job->error() ) return; // error handling is in the base class CollectionFetchJob *fetchJob = qobject_cast<CollectionFetchJob*>( job ); if ( fetchJob->collections().size() == 1 ) { m_currentCollection = fetchJob->collections().first(); m_currentCollection.setParentCollection( m_collections.value( m_currentCollection.parentCollection().id() ) ); m_collections.insert( m_currentCollection.id(), m_currentCollection ); } else { // already deleted, move on } if ( !m_runningJobs && m_pendingReplay ) replayNext(); }
QList<Collection> CollectionsFetcher::fetch() { LOG.debug("Fetching collections for: %s", collectionMimeType.c_str()); Collection filteredCollection(Collection::root()); filteredCollection.setContentMimeTypes(QStringList() << collectionMimeType.c_str()); QList<Collection> res; CollectionFetchJob* job = new CollectionFetchJob( filteredCollection, CollectionFetchJob::Recursive); if (!job->exec() ) { const char* err = job->errorString().toUtf8(); LOG.error("Job Error: %s", err); } else { CollectionFetchJob* cjob = static_cast<CollectionFetchJob*>( job ); foreach( const Collection &collection, cjob->collections() ) { if (collection.contentMimeTypes().contains(collectionMimeType.c_str())) { res.append(collection); } } } return res; }
void akonadimailsearch::onCollectionsFetched(KJob* job) { if (job->error()) { kWarning() << job->errorString(); emit finished(); } else { CollectionFetchJob *fetchJob = qobject_cast<CollectionFetchJob*>(job); QList<Collection> contactCollections; foreach (const Collection &collection, fetchJob->collections()) { if (collection.isVirtual()) { continue; } if (collection.contentMimeTypes().contains( KABC::Addressee::mimeType() ) ) { ItemFetchJob *itemFetchJob = new ItemFetchJob(collection); itemFetchJob->fetchScope().fetchFullPayload(); connect(itemFetchJob, SIGNAL(finished(KJob*)), SLOT(onItemsFetched(KJob*))); ++activeFetchJobsCount; } } if (activeFetchJobsCount == 0) { emit finished(); } } }
// TODO: test signals void testMove() { QFETCH( Collection, source ); QFETCH( Collection, destination ); QFETCH( bool, crossResource ); QVERIFY( source.isValid() ); QVERIFY( destination.isValid() ); CollectionFetchJob *fetch = new CollectionFetchJob( source, CollectionFetchJob::Base, this ); AKVERIFYEXEC( fetch ); QCOMPARE( fetch->collections().count(), 1 ); source = fetch->collections().first(); // obtain reference listing fetch = new CollectionFetchJob( source, CollectionFetchJob::Recursive ); AKVERIFYEXEC( fetch ); QHash<Collection, Item::List> referenceData; foreach ( const Collection &c, fetch->collections() ) { ItemFetchJob *job = new ItemFetchJob( c, this ); AKVERIFYEXEC( job ); referenceData.insert( c, job->items() ); } // move collection CollectionMoveJob *mod = new CollectionMoveJob( source, destination, this ); AKVERIFYEXEC( mod ); // check if source was modified correctly CollectionFetchJob *ljob = new CollectionFetchJob( source, CollectionFetchJob::Base ); AKVERIFYEXEC( ljob ); Collection::List list = ljob->collections(); QCOMPARE( list.count(), 1 ); Collection col = list.first(); QCOMPARE( col.name(), source.name() ); QCOMPARE( col.parentCollection(), destination ); // list destination and check if everything is still there ljob = new CollectionFetchJob( destination, CollectionFetchJob::Recursive ); AKVERIFYEXEC( ljob ); list = ljob->collections(); QVERIFY( list.count() >= referenceData.count() ); for ( QHash<Collection, Item::List>::ConstIterator it = referenceData.constBegin(); it != referenceData.constEnd(); ++it ) { QVERIFY( list.contains( it.key() ) ); if ( crossResource ) { QVERIFY( list[ list.indexOf( it.key() ) ].resource() != it.key().resource() ); } else { QCOMPARE( list[ list.indexOf( it.key() ) ].resource(), it.key().resource() ); } ItemFetchJob *job = new ItemFetchJob( it.key(), this ); job->fetchScope().fetchFullPayload(); AKVERIFYEXEC( job ); QCOMPARE( job->items().count(), it.value().count() ); foreach ( const Item &item, job->items() ) { QVERIFY( it.value().contains( item ) ); QVERIFY( item.hasPayload() ); } } // cleanup mod = new CollectionMoveJob( col, source.parentCollection(), this ); AKVERIFYEXEC( mod ); }
void testLink() { SearchCreateJob *create = new SearchCreateJob( "linkTestFolder", "dummy query", this ); AKVERIFYEXEC( create ); CollectionFetchJob *list = new CollectionFetchJob( Collection( 1 ), CollectionFetchJob::Recursive, this ); AKVERIFYEXEC( list ); Collection col; foreach ( const Collection &c, list->collections() ) { if ( c.name() == "linkTestFolder" ) { col = c; } } QVERIFY( col.isValid() ); Item::List items; items << Item( 3 ) << Item( 4 ) << Item( 6 ); Monitor *monitor = new Monitor( this ); monitor->setCollectionMonitored( col ); monitor->itemFetchScope().fetchFullPayload(); qRegisterMetaType<Akonadi::Collection>(); qRegisterMetaType<Akonadi::Item>(); QSignalSpy lspy( monitor, SIGNAL(itemLinked(Akonadi::Item,Akonadi::Collection)) ); QSignalSpy uspy( monitor, SIGNAL(itemUnlinked(Akonadi::Item,Akonadi::Collection)) ); QVERIFY( lspy.isValid() ); QVERIFY( uspy.isValid() ); LinkJob *link = new LinkJob( col, items, this ); AKVERIFYEXEC( link ); QTest::qWait( 1000 ); QVERIFY( uspy.isEmpty() ); QCOMPARE( lspy.count(), 3 ); QList<QVariant> arg = lspy.takeFirst(); Item item = arg.at( 0 ).value<Item>(); QCOMPARE( item.mimeType(), QString::fromLatin1( "application/octet-stream" ) ); QVERIFY( item.hasPayload<QByteArray>() ); lspy.clear(); ItemFetchJob *fetch = new ItemFetchJob( col ); AKVERIFYEXEC( fetch ); QCOMPARE( fetch->items().count(), 3 ); foreach ( const Item &item, fetch->items() ) { QVERIFY( items.contains( item ) ); } UnlinkJob *unlink = new UnlinkJob( col, items, this ); AKVERIFYEXEC( unlink ); QTest::qWait( 1000 ); QVERIFY( lspy.isEmpty() ); QCOMPARE( uspy.count(), 3 ); fetch = new ItemFetchJob( col ); AKVERIFYEXEC( fetch ); QCOMPARE( fetch->items().count(), 0 ); }
void Akonadi::SpecialCollectionsDiscoveryJob::start() { CollectionFetchJob *job = new CollectionFetchJob(Collection::root(), CollectionFetchJob::Recursive, this); job->fetchScope().setContentMimeTypes(d->mMimeTypes); addSubjob(job); }
/****************************************************************************** * Called when a collection fetch job has completed. * Obtains the collection handled by the agent, and configures it. */ void CalendarCreator::collectionFetchResult(KJob* j) { kDebug() << mName; if (j->error()) { mErrorMessage = j->errorString(); kError() << "CollectionFetchJob error: " << mErrorMessage; finish(true); return; } CollectionFetchJob* job = static_cast<CollectionFetchJob*>(j); Collection::List collections = job->collections(); if (collections.isEmpty()) { if (++mCollectionFetchRetryCount >= 10) { mErrorMessage = i18nc("@info/plain", "New configuration timed out"); kError() << "Timeout fetching collection for resource"; finish(true); return; } // Need to wait a bit longer until the resource has initialised and // created its collection. Retry after 200ms. kDebug() << "Retrying"; QTimer::singleShot(200, this, SLOT(fetchCollection())); return; } if (collections.count() > 1) { mErrorMessage = i18nc("@info/plain", "New configuration was corrupt"); kError() << "Wrong number of collections for this resource:" << collections.count(); finish(true); return; } // Set Akonadi Collection attributes Collection collection = collections[0]; collection.setContentMimeTypes(CalEvent::mimeTypes(mAlarmType)); EntityDisplayAttribute* dattr = collection.attribute<EntityDisplayAttribute>(Collection::AddIfMissing); dattr->setIconName("kalarm"); CollectionAttribute* attr = collection.attribute<CollectionAttribute>(Entity::AddIfMissing); attr->setEnabled(mEnabled ? mAlarmType : CalEvent::EMPTY); if (mStandard) attr->setStandard(mAlarmType); if (mColour.isValid()) attr->setBackgroundColor(mColour); // Update the calendar to the current KAlarm format if necessary, // and if the user agrees. bool dirResource = false; switch (mResourceType) { case LocalFile: case RemoteFile: break; case LocalDir: dirResource = true; break; default: Q_ASSERT(0); // Invalid resource type break; } //FIXME: port away of calendarupdater bool keep = true; bool duplicate = false; if (!mReadOnly) { /* CalendarUpdater* updater = new CalendarUpdater(collection, dirResource, false, true, this); duplicate = updater->isDuplicate(); keep = !updater->update(); // note that 'updater' will auto-delete when finished*/ } if (!duplicate) { // Record the user's choice of whether to update the calendar attr->setKeepFormat(keep); } // Update the collection's CollectionAttribute value in the Akonadi database. // Note that we can't supply 'collection' to CollectionModifyJob since // that also contains the CompatibilityAttribute value, which is read-only // for applications. So create a new Collection instance and only set a // value for CollectionAttribute. Collection c(collection.id()); CollectionAttribute* att = c.attribute<CollectionAttribute>(Entity::AddIfMissing); *att = *attr; CollectionModifyJob* cmjob = new CollectionModifyJob(c, this); connect(cmjob, SIGNAL(result(KJob*)), this, SLOT(modifyCollectionJobDone(KJob*))); }