Exemplo n.º 1
0
void Firstrun::setupNext()
{
    delete mCurrentDefault;
    mCurrentDefault = 0;

    if (mPendingDefaults.isEmpty()) {
        deleteLater();
        return;
    }

    mCurrentDefault = new KConfig(mPendingDefaults.takeFirst());
    const KConfigGroup agentCfg = KConfigGroup(mCurrentDefault, "Agent");

    AgentType type = AgentManager::self()->type(agentCfg.readEntry("Type", QString()));
    if (!type.isValid()) {
        qCritical() << "Unable to obtain agent type for default resource agent configuration " << mCurrentDefault->name();
        setupNext();
        return;
    }
    if (type.capabilities().contains(QStringLiteral("Unique"))) {
        Q_FOREACH (const AgentInstance &agent, AgentManager::self()->instances()) {
            if (agent.type() == type) {
                // remember we set this one up already
                KConfigGroup cfg(mConfig, "ProcessedDefaults");
                cfg.writeEntry(agentCfg.readEntry("Id", QString()), agent.identifier());
                cfg.sync();
                setupNext();
                return;
            }
        }
    }
Exemplo n.º 2
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 ) );
    }