/******************************************************************************
* Create the Akonadi agent for this calendar.
*/
void CalendarCreator::createAgent(const QString& agentType, QObject* parent)
{
    emit creating(mPath);
    AgentInstanceCreateJob* job = new AgentInstanceCreateJob(agentType, parent);
    connect(job, SIGNAL(result(KJob*)), SLOT(agentCreated(KJob*)));
    job->start();
}
Пример #2
0
    void testIllegalResourceManagement()
    {
      AgentInstanceCreateJob *job = new AgentInstanceCreateJob( AgentManager::self()->type( "non_existing_resource" ) );
      QVERIFY( !job->exec() );

      // unique agent
      // According to vkrause the mailthreader agent is no longer started by
      // default so this won't work.
      /*
      const AgentType type = AgentManager::self()->type( "akonadi_mailthreader_agent" );
      QVERIFY( type.isValid() );
      job = new AgentInstanceCreateJob( type );
      AKVERIFYEXEC( job );

      job = new AgentInstanceCreateJob( type );
      QVERIFY( !job->exec() );
      */
    }
/******************************************************************************
* Called when the agent creation job for this resource has completed.
* Applies the calendar resource configuration to the Akonadi agent.
*/
void CalendarCreator::agentCreated(KJob* j)
{
    if (j->error())
    {
        mErrorMessage = j->errorString();
        kError() << "AgentInstanceCreateJob error:" << mErrorMessage;
        finish(false);
        return;
    }

    // Configure the Akonadi Agent
    kDebug() << mName;
    AgentInstanceCreateJob* job = static_cast<AgentInstanceCreateJob*>(j);
    mAgent = job->instance();
    mAgent.setName(mName);
    bool ok = false;
    switch (mResourceType)
    {
        case LocalFile:
            ok = migrateLocalFile();
            break;
        case LocalDir:
            ok = migrateLocalDirectory();
            break;
        case RemoteFile:
            ok = migrateRemoteFile();
            break;
        default:
            kError() << "Invalid resource type";
            break;
    }
    if (!ok)
    {
        finish(true);
        return;
    }
    mAgent.reconfigure();   // notify the agent that its configuration has been changed

    // Wait for the resource to create its collection.
    ResourceSynchronizationJob* sjob = new ResourceSynchronizationJob(mAgent);
    connect(sjob, SIGNAL(result(KJob*)), SLOT(resourceSynchronised(KJob*)));
    sjob->start();   // this is required (not an Akonadi::Job)
}
Пример #4
0
    void testResourceManagement()
    {
      qRegisterMetaType<Akonadi::AgentInstance>();
      QSignalSpy spyAddInstance( AgentManager::self(), SIGNAL(instanceAdded(Akonadi::AgentInstance)) );
      QVERIFY( spyAddInstance.isValid() );
      QSignalSpy spyRemoveInstance( AgentManager::self(), SIGNAL(instanceRemoved(Akonadi::AgentInstance)) );
      QVERIFY( spyRemoveInstance.isValid() );

      AgentType type = AgentManager::self()->type( "akonadi_knut_resource" );
      QVERIFY( type.isValid() );

      QCOMPARE( type.capabilities(), QStringList( "Resource" ) );

      AgentInstanceCreateJob *job = new AgentInstanceCreateJob( type );
      AKVERIFYEXEC( job );

      AgentInstance instance = job->instance();
      QVERIFY( instance.isValid() );

      QCOMPARE( spyAddInstance.count(), 1 );
      QCOMPARE( spyAddInstance.first().at( 0 ).value<AgentInstance>(), instance );
      QVERIFY( AgentManager::self()->instance( instance.identifier() ).isValid() );

      job = new AgentInstanceCreateJob( type );
      AKVERIFYEXEC( job );
      AgentInstance instance2 = job->instance();
      QVERIFY( !( instance == instance2 ) );
      QCOMPARE( spyAddInstance.count(), 2 );

      AgentManager::self()->removeInstance( instance );
      AgentManager::self()->removeInstance( instance2 );
      QTest::qWait( 2000 );
      QCOMPARE( spyRemoveInstance.count(), 2 );
      QVERIFY( !AgentManager::self()->instances().contains( instance ) );
      QVERIFY( !AgentManager::self()->instances().contains( instance2 ) );
    }