diff --git a/akonadi/agentinstancecreatejob.cpp b/akonadi/agentinstancecreatejob.cpp index 6489ba682..72796b801 100644 --- a/akonadi/agentinstancecreatejob.cpp +++ b/akonadi/agentinstancecreatejob.cpp @@ -1,134 +1,146 @@ /* Copyright (c) 2008 Volker Krause This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "agentinstancecreatejob.h" #include "agentmanager.h" #include "agentmanager_p.h" #include "agentinstance.h" #include #include #include +#ifdef Q_OS_UNIX +#include +#include +#endif + using namespace Akonadi; static const int safetyTimeout = 10000; // ms /** * @internal */ class AgentInstanceCreateJob::Private { public: Private( AgentInstanceCreateJob* parent ) : q( parent ), parentWidget( 0 ), safetyTimer( 0 ), doConfig( false ), tooLate( false ) { } ~Private() { } void agentInstanceAdded( const AgentInstance &instance ) { if ( agentInstance == instance && !tooLate ) { safetyTimer->stop(); if ( doConfig ) { // return from dbus call first before doing the next one QTimer::singleShot( 0, q, SLOT( doConfigure() ) ); } else { q->emitResult(); } } } void doConfigure() { agentInstance.configure( parentWidget ); q->emitResult(); } void timeout() { tooLate = true; q->setError( KJob::UserDefinedError ); q->setErrorText( i18n( "Agent instance creation timed out." ) ); q->emitResult(); } void emitResult() { q->emitResult(); } AgentInstanceCreateJob* q; AgentType agentType; AgentInstance agentInstance; QWidget* parentWidget; QTimer *safetyTimer; bool doConfig; bool tooLate; }; AgentInstanceCreateJob::AgentInstanceCreateJob(const AgentType & agentType, QObject * parent) : KJob( parent ), 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() { delete d; } void AgentInstanceCreateJob::configure( QWidget *parent ) { d->parentWidget = parent; d->doConfig = true; } AgentInstance AgentInstanceCreateJob::instance() const { return d->agentInstance; } void AgentInstanceCreateJob::start() { d->agentInstance = AgentManager::self()->d->createInstance( d->agentType ); if ( !d->agentInstance.isValid() ) { setError( KJob::UserDefinedError ); setErrorText( i18n("Unable to create agent instance." ) ); QTimer::singleShot( 0, this , SLOT(emitResult()) ); } else { - d->safetyTimer->start( safetyTimeout ); + int timeout = safetyTimeout; +#ifdef Q_OS_UNIX + // Increate the timeout when valgrinding the agent, because that slows down things a log. + QString agentValgrind = QString::fromLocal8Bit( qgetenv( "AKONADI_VALGRIND" ) ); + if ( !agentValgrind.isEmpty() && d->agentType.identifier().contains( agentValgrind ) ) + timeout *= 15; +#endif + d->safetyTimer->start( timeout ); } } #include "agentinstancecreatejob.moc" diff --git a/akonadi/agentmanager.h b/akonadi/agentmanager.h index 8bd648cf4..efc5e235e 100644 --- a/akonadi/agentmanager.h +++ b/akonadi/agentmanager.h @@ -1,206 +1,206 @@ /* Copyright (c) 2006-2008 Tobias Koenig This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef AKONADI_AGENTMANAGER_H #define AKONADI_AGENTMANAGER_H #include "akonadi_export.h" #include #include #include namespace Akonadi { class AgentManagerPrivate; class Collection; /** * @short Provides an interface to retrieve agent types and manage agent instances. * * This singleton class can be used to create or remove agent instances or trigger * synchronization of collections. Furthermore it provides information about status * changes of the agents. * * @code * * Akonadi::AgentManager *manager = Akonadi::AgentManager::self(); * * Akonadi::AgentType::List types = manager->types(); * foreach( const Akonadi::AgentType type&, types ) { * qDebug() << "Type:" << type.name() << type.description(); * } * * @endcode * * @author Tobias Koenig */ class AKONADI_EXPORT AgentManager : public QObject { friend class AgentInstance; friend class AgentInstanceCreateJob; friend class AgentManagerPrivate; Q_OBJECT public: /** * Returns the global instance of the agent manager. */ static AgentManager *self(); /** * Destroys the agent manager. */ ~AgentManager(); /** * Returns the list of all available agent types. */ AgentType::List types() const; /** * Returns the agent type with the given @p identifier or * an invalid agent type if the identifier does not exist. */ - AgentType type( const QString &identififer ) const; + AgentType type( const QString &identifier ) const; /** * Returns the list of all available agent instances. */ AgentInstance::List instances() const; /** * Returns the agent instance with the given @p identifier or * an invalid agent instance if the identifier does not exist. */ AgentInstance instance( const QString &identifier ) const; /** * Removes the given agent @p instance. */ void removeInstance( const AgentInstance &instance ); /** * Trigger a synchronization of the given collection by its owning resource agent. * * @param collection The collection to synchronize. */ void synchronizeCollection( const Collection &collection ); Q_SIGNALS: /** * This signal is emitted whenever a new agent type was installed on the system. * * @param type The new agent type. */ void typeAdded( const Akonadi::AgentType &type ); /** * This signal is emitted whenever an agent type was removed from the system. * * @param type The removed agent type. */ void typeRemoved( const Akonadi::AgentType &type ); /** * This signal is emitted whenever a new agent instance was created. * * @param instance The new agent instance. */ void instanceAdded( const Akonadi::AgentInstance &instance ); /** * This signal is emitted whenever an agent instance was removed. * * @param instance The removed agent instance. */ void instanceRemoved( const Akonadi::AgentInstance &instance ); /** * This signal is emitted whenever the status of an agent instance has * changed. * * @param instance The agent instance that status has changed. */ void instanceStatusChanged( const Akonadi::AgentInstance &instance ); /** * This signal is emitted whenever the progress of an agent instance has * changed. * * @param instance The agent instance that progress has changed. */ void instanceProgressChanged( const Akonadi::AgentInstance &instance ); /** * This signal is emitted whenever the name of the agent instance has changed. * * @param instance The agent instance that name has changed. */ void instanceNameChanged( const Akonadi::AgentInstance &instance ); /** * This signal is emitted whenever the agent instance raised an error. * * @param instance The agent instance that raised the error. * @param message The i18n'ed error message. */ void instanceError( const Akonadi::AgentInstance &instance, const QString &message ); /** * This signal is emitted whenever the agent instance raised a warning. * * @param instance The agent instance that raised the warning. * @param message The i18n'ed warning message. */ void instanceWarning( const Akonadi::AgentInstance &instance, const QString &message ); /** * This signal is emitted whenever the online state of an agent changed. * * @param instance The agent instance that changed its online state. * @param online The new online state. * @since 4.2 */ void instanceOnline( const Akonadi::AgentInstance &instance, bool online ); private: //@cond PRIVATE AgentManager(); AgentManagerPrivate* const d; Q_PRIVATE_SLOT( d, void agentTypeAdded( const QString& ) ) Q_PRIVATE_SLOT( d, void agentTypeRemoved( const QString& ) ) Q_PRIVATE_SLOT( d, void agentInstanceAdded( const QString& ) ) Q_PRIVATE_SLOT( d, void agentInstanceRemoved( const QString& ) ) Q_PRIVATE_SLOT( d, void agentInstanceStatusChanged( const QString&, int, const QString& ) ) Q_PRIVATE_SLOT( d, void agentInstanceProgressChanged( const QString&, uint, const QString& ) ) Q_PRIVATE_SLOT( d, void agentInstanceNameChanged( const QString&, const QString& ) ) Q_PRIVATE_SLOT( d, void agentInstanceWarning( const QString&, const QString& ) ) Q_PRIVATE_SLOT( d, void agentInstanceError( const QString&, const QString& ) ) Q_PRIVATE_SLOT( d, void agentInstanceOnlineChanged( const QString&, bool ) ) //@endcond }; } #endif