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" 31 #include <klocalizedstring.h> 33 #include <QtCore/QTimer> 36 #include <sys/types.h> 42 #if defined(Q_WS_MAEMO_5) 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;
160 AgentInstanceCreateJob::~ AgentInstanceCreateJob()
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" AgentInstance instance() const
Returns the AgentInstance object of the newly created agent instance.
void configure(QWidget *parent=0)
Setup the job to show agent configuration dialog once the agent instance has been successfully starte...
void removeInstance(const AgentInstance &instance)
Removes the given agent instance.
A representation of an agent type.
static QString agentServiceName(ServiceAgentType agentType, const QString &identifier)
Returns the namespaced D-Bus service name for an agent of type agentType with agent identifier identi...
AgentType type(const QString &identifier) const
Returns the agent type with the given identifier or an invalid agent type if the identifier does not ...
Job for creating new agent instances.
AgentInstanceCreateJob(const AgentType &type, QObject *parent=0)
Creates a new agent instance create job.
FreeBusyManager::Singleton.
static AgentManager * self()
Returns the global instance of the agent manager.
A representation of an agent instance.
Base class for the private class of KJob but not Akonadi::Job based jobs that require the Akonadi ser...
void start()
Starts the instance creation.