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"
28 #include "servermanager.h"
33 #include <QtCore/QTimer>
36 #include <sys/types.h>
40 using namespace Akonadi;
42 #if defined(Q_WS_MAEMO_5) || defined(Q_OS_WINCE)
43 static const int safetyTimeout = 60000;
45 static const int safetyTimeout = 10000;
58 safetyTimer( new QTimer( parent ) ),
64 QObject::connect( safetyTimer, SIGNAL(timeout()), q, SLOT(timeout()) );
69 if ( agentInstance == instance && !tooLate ) {
73 QTimer::singleShot( 0, q, SLOT(doConfigure()) );
82 org::freedesktop::Akonadi::Agent::Control *agentControlIface =
84 QLatin1String(
"/" ), DBusConnectionPool::threadConnection(), q );
85 if ( !agentControlIface || !agentControlIface->isValid() ) {
86 delete agentControlIface;
88 q->setError( KJob::UserDefinedError );
89 q->setErrorText( i18n(
"Unable to access D-Bus interface of created agent." ) );
94 q->connect( agentControlIface, SIGNAL(configurationDialogAccepted()),
95 q, SLOT(configurationDialogAccepted()) );
96 q->connect( agentControlIface, SIGNAL(configurationDialogRejected()),
97 q, SLOT(configurationDialogRejected()) );
99 agentInstance.configure( parentWidget );
102 void configurationDialogAccepted()
109 void configurationDialogRejected()
122 q->setError( KJob::UserDefinedError );
123 q->setErrorText( i18n(
"Agent instance creation timed out." ) );
138 QWidget* parentWidget;
148 d( new AgentInstanceCreateJobPrivate( this ) )
150 d->agentType = agentType;
155 d( new AgentInstanceCreateJobPrivate( this ) )
157 d->agentTypeId = typeId;
167 d->parentWidget = parent;
173 return d->agentInstance;
181 void AgentInstanceCreateJobPrivate::doStart()
183 if ( !agentType.isValid() && !agentTypeId.isEmpty() ) {
187 if ( !agentType.isValid() ) {
188 q->setError( KJob::UserDefinedError );
189 q->setErrorText( i18n(
"Unable to obtain agent type '%1'.", agentTypeId ) );
190 QTimer::singleShot( 0, q, SLOT(emitResult()) );
195 if ( !agentInstance.isValid() ) {
196 q->setError( KJob::UserDefinedError );
197 q->setErrorText( i18n(
"Unable to create agent instance." ) );
198 QTimer::singleShot( 0, q, SLOT(emitResult()) );
200 int timeout = safetyTimeout;
203 QString agentValgrind = QString::fromLocal8Bit( qgetenv(
"AKONADI_VALGRIND" ) );
204 if ( !agentValgrind.isEmpty() && agentType.identifier().contains( agentValgrind ) ) {
209 const QString agentDebugging = QString::fromLocal8Bit( qgetenv(
"AKONADI_DEBUG_WAIT" ) );
210 if ( !agentDebugging.isEmpty() ) {
212 const QString agentDebuggingTimeout = QString::fromLocal8Bit( qgetenv(
"AKONADI_DEBUG_TIMEOUT" ) );
213 if ( agentDebuggingTimeout.isEmpty() ) {
215 timeout = 15* safetyTimeout;
218 timeout = agentDebuggingTimeout.toInt();
222 safetyTimer->start( timeout );
226 #include "moc_agentinstancecreatejob.cpp"