20 #include "agentinstancecreatejob.h"
22 #include "agentinstance.h"
23 #include "agentmanager.h"
24 #include "agentmanager_p.h"
25 #include "controlinterface.h"
26 #include "dbusconnectionpool.h"
27 #include "kjobprivatebase_p.h"
32 #include <QtCore/QTimer>
35 #include <sys/types.h>
39 using namespace Akonadi;
41 #if defined(Q_WS_MAEMO_5) || defined(Q_OS_WINCE)
42 static const int safetyTimeout = 60000;
44 static const int safetyTimeout = 10000;
52 class AgentInstanceCreateJobPrivate :
public KJobPrivateBase
57 safetyTimer( new QTimer( parent ) ),
63 QObject::connect( safetyTimer, SIGNAL(timeout()), q, SLOT(timeout()) );
68 if ( agentInstance == instance && !tooLate ) {
72 QTimer::singleShot( 0, q, SLOT(doConfigure()) );
81 org::freedesktop::Akonadi::Agent::Control *agentControlIface =
82 new org::freedesktop::Akonadi::Agent::Control( QLatin1String(
"org.freedesktop.Akonadi.Agent." ) + agentInstance.identifier(),
83 QLatin1String(
"/" ), DBusConnectionPool::threadConnection(), q );
84 if ( !agentControlIface || !agentControlIface->isValid() ) {
85 delete agentControlIface;
87 q->setError( KJob::UserDefinedError );
88 q->setErrorText( i18n(
"Unable to access D-Bus interface of created agent." ) );
93 q->connect( agentControlIface, SIGNAL(configurationDialogAccepted()),
94 q, SLOT(configurationDialogAccepted()) );
95 q->connect( agentControlIface, SIGNAL(configurationDialogRejected()),
96 q, SLOT(configurationDialogRejected()) );
98 agentInstance.configure( parentWidget );
101 void configurationDialogAccepted()
108 void configurationDialogRejected()
121 q->setError( KJob::UserDefinedError );
122 q->setErrorText( i18n(
"Agent instance creation timed out." ) );
137 QWidget* parentWidget;
147 d( new AgentInstanceCreateJobPrivate( this ) )
149 d->agentType = agentType;
154 d( new AgentInstanceCreateJobPrivate( this ) )
156 d->agentTypeId = typeId;
166 d->parentWidget = parent;
172 return d->agentInstance;
180 void AgentInstanceCreateJobPrivate::doStart()
182 if ( !agentType.isValid() && !agentTypeId.isEmpty() )
185 if ( !agentType.isValid() ) {
186 q->setError( KJob::UserDefinedError );
187 q->setErrorText( i18n(
"Unable to obtain agent type '%1'.", agentTypeId) );
188 QTimer::singleShot( 0, q, SLOT(emitResult()) );
193 if ( !agentInstance.isValid() ) {
194 q->setError( KJob::UserDefinedError );
195 q->setErrorText( i18n(
"Unable to create agent instance." ) );
196 QTimer::singleShot( 0, q, SLOT(emitResult()) );
198 int timeout = safetyTimeout;
201 QString agentValgrind = QString::fromLocal8Bit( qgetenv(
"AKONADI_VALGRIND" ) );
202 if ( !agentValgrind.isEmpty() && agentType.identifier().contains( agentValgrind ) )
206 const QString agentDebugging = QString::fromLocal8Bit( qgetenv(
"AKONADI_DEBUG_WAIT" ) );
207 if ( !agentDebugging.isEmpty() ) {
209 const QString agentDebuggingTimeout = QString::fromLocal8Bit( qgetenv(
"AKONADI_DEBUG_TIMEOUT" ) );
210 if ( agentDebuggingTimeout.isEmpty() ) {
212 timeout = 15* safetyTimeout;
215 timeout = agentDebuggingTimeout.toInt();
219 safetyTimer->start( timeout );
223 #include "agentinstancecreatejob.moc"