Index: akonadi/agentinstancecreatejob.cpp =================================================================== --- akonadi/agentinstancecreatejob.cpp (révision 1108278) +++ akonadi/agentinstancecreatejob.cpp (révision 1108279) @@ -47,16 +47,15 @@ public: Private( AgentInstanceCreateJob* parent ) : q( parent ), parentWidget( 0 ), - safetyTimer( 0 ), + safetyTimer( new QTimer( parent ) ), doConfig( false ), tooLate( false ) { + QObject::connect( AgentManager::self(), SIGNAL(instanceAdded(Akonadi::AgentInstance)), + q, SLOT(agentInstanceAdded(Akonadi::AgentInstance)) ); + QObject::connect( safetyTimer, SIGNAL(timeout()), q, SLOT(timeout()) ); } - ~Private() - { - } - void agentInstanceAdded( const AgentInstance &instance ) { if ( agentInstance == instance && !tooLate ) { @@ -127,6 +126,7 @@ AgentInstanceCreateJob* q; AgentType agentType; + QString agentTypeId; AgentInstance agentInstance; QWidget* parentWidget; QTimer *safetyTimer; @@ -139,13 +139,16 @@ d( new Private( this ) ) { d->agentType = agentType; - connect( AgentManager::self(), SIGNAL( instanceAdded( const Akonadi::AgentInstance& ) ), - this, SLOT( agentInstanceAdded( const Akonadi::AgentInstance& ) ) ); +} - d->safetyTimer = new QTimer( this ); - connect( d->safetyTimer, SIGNAL( timeout() ), SLOT( timeout() ) ); +AgentInstanceCreateJob::AgentInstanceCreateJob(const QString& typeId, QObject* parent) : + KJob( parent ), + d( new Private( this ) ) +{ + d->agentTypeId = typeId; } + AgentInstanceCreateJob::~ AgentInstanceCreateJob() { delete d; @@ -169,6 +172,16 @@ void AgentInstanceCreateJob::Private::doStart() { + if ( !agentType.isValid() && !agentTypeId.isEmpty() ) + agentType = AgentManager::self()->type( agentTypeId ); + + if ( !agentType.isValid() ) { + q->setError( KJob::UserDefinedError ); + q->setErrorText( i18n("Unable to obtain agent type '%1'.", agentTypeId) ); + QTimer::singleShot( 0, q, SLOT( emitResult() ) ); + return; + } + agentInstance = AgentManager::self()->d->createInstance( agentType ); if ( !agentInstance.isValid() ) { q->setError( KJob::UserDefinedError ); Index: akonadi/agentinstancecreatejob.h =================================================================== --- akonadi/agentinstancecreatejob.h (révision 1108278) +++ akonadi/agentinstancecreatejob.h (révision 1108279) @@ -79,6 +79,14 @@ explicit AgentInstanceCreateJob( const AgentType &type, QObject *parent = 0 ); /** + * Create a new agent instance creation job. + * @param typeId The identifier of type of the agent to create. + * @param parent The parent object. + * @since 4.5 + */ + explicit AgentInstanceCreateJob( const QString &typeId, QObject *parent = 0 ); + + /** * Destroys the agent instance creation job. */ ~AgentInstanceCreateJob();