20 #include "agentmanager.h"
21 #include "agentmanager_p.h"
23 #include "agenttype_p.h"
24 #include "agentinstance_p.h"
25 #include "dbusconnectionpool.h"
26 #include "servermanager.h"
28 #include "collection.h"
30 #include <QtDBus/QDBusServiceWatcher>
36 using namespace Akonadi;
42 const QString &identifier = mManager->createAgentInstance( type.
identifier() );
43 if ( identifier.isEmpty() ) {
47 return fillAgentInstanceLight( identifier );
50 void AgentManagerPrivate::agentTypeAdded(
const QString &identifier )
54 if ( mTypes.contains( identifier ) ) {
58 const AgentType type = fillAgentType( identifier );
60 mTypes.insert( identifier, type );
79 void AgentManagerPrivate::agentTypeRemoved(
const QString &identifier )
81 if ( !mTypes.contains( identifier ) ) {
85 const AgentType type = mTypes.take( identifier );
89 void AgentManagerPrivate::agentInstanceAdded(
const QString &identifier )
91 const AgentInstance instance = fillAgentInstance( identifier );
101 const bool newAgentInstance = !mInstances.contains( identifier );
102 if ( newAgentInstance ) {
103 mInstances.insert( identifier, instance );
106 mInstances.remove( identifier );
107 mInstances.insert( identifier, instance );
113 void AgentManagerPrivate::agentInstanceRemoved(
const QString &identifier )
115 if ( !mInstances.contains( identifier ) ) {
119 const AgentInstance instance = mInstances.take( identifier );
123 void AgentManagerPrivate::agentInstanceStatusChanged(
const QString &identifier,
int status,
const QString &msg )
125 if ( !mInstances.contains( identifier ) ) {
130 instance.d->mStatus = status;
131 instance.d->mStatusMessage = msg;
136 void AgentManagerPrivate::agentInstanceProgressChanged(
const QString &identifier, uint progress,
const QString &msg )
138 if ( !mInstances.contains( identifier ) ) {
143 instance.d->mProgress = progress;
144 if ( !msg.isEmpty() ) {
145 instance.d->mStatusMessage = msg;
151 void AgentManagerPrivate::agentInstanceWarning(
const QString &identifier,
const QString &msg )
153 if ( !mInstances.contains( identifier ) ) {
161 void AgentManagerPrivate::agentInstanceError(
const QString &identifier,
const QString &msg )
163 if ( !mInstances.contains( identifier ) ) {
171 void AgentManagerPrivate::agentInstanceOnlineChanged(
const QString &identifier,
bool state )
173 if ( !mInstances.contains( identifier ) ) {
178 instance.d->mIsOnline = state;
182 void AgentManagerPrivate::agentInstanceNameChanged(
const QString &identifier,
const QString &name )
184 if ( !mInstances.contains( identifier ) ) {
189 instance.d->mName = name;
196 const QDBusReply<QStringList> types = mManager->agentTypes();
197 if ( types.isValid() ) {
198 foreach (
const QString &type, types.value() ) {
199 if ( !mTypes.contains( type ) ) {
200 agentTypeAdded( type );
208 const QDBusReply<QStringList> instances = mManager->agentInstances();
209 if ( instances.isValid() ) {
210 foreach (
const QString &instance, instances.value() ) {
211 if ( !mInstances.contains( instance ) ) {
212 agentInstanceAdded( instance );
218 AgentType AgentManagerPrivate::fillAgentType(
const QString &identifier )
const
221 type.d->mIdentifier = identifier;
222 type.d->mName = mManager->agentName( identifier, KGlobal::locale()->language() );
223 type.d->mDescription = mManager->agentComment( identifier, KGlobal::locale()->language() );
224 type.d->mIconName = mManager->agentIcon( identifier );
225 type.d->mMimeTypes = mManager->agentMimeTypes( identifier );
226 type.d->mCapabilities = mManager->agentCapabilities( identifier );
231 void AgentManagerPrivate::setName(
const AgentInstance &instance,
const QString &name )
233 mManager->setAgentInstanceName( instance.
identifier(), name );
236 void AgentManagerPrivate::setOnline(
const AgentInstance &instance,
bool state )
238 mManager->setAgentInstanceOnline( instance.
identifier(), state );
241 void AgentManagerPrivate::configure(
const AgentInstance &instance, QWidget *parent )
245 winId = (qlonglong)( parent->window()->winId() );
248 mManager->agentInstanceConfigure( instance.
identifier(), winId );
251 void AgentManagerPrivate::synchronize(
const AgentInstance &instance )
253 mManager->agentInstanceSynchronize( instance.
identifier() );
256 void AgentManagerPrivate::synchronizeCollectionTree(
const AgentInstance &instance )
258 mManager->agentInstanceSynchronizeCollectionTree( instance.
identifier() );
261 AgentInstance AgentManagerPrivate::fillAgentInstance(
const QString &identifier )
const
265 const QString agentTypeIdentifier = mManager->agentInstanceType( identifier );
266 if ( !mTypes.contains( agentTypeIdentifier ) ) {
270 instance.d->mType = mTypes.value( agentTypeIdentifier );
271 instance.d->mIdentifier = identifier;
272 instance.d->mName = mManager->agentInstanceName( identifier );
273 instance.d->mStatus = mManager->agentInstanceStatus( identifier );
274 instance.d->mStatusMessage = mManager->agentInstanceStatusMessage( identifier );
275 instance.d->mProgress = mManager->agentInstanceProgress( identifier );
276 instance.d->mIsOnline = mManager->agentInstanceOnline( identifier );
281 AgentInstance AgentManagerPrivate::fillAgentInstanceLight(
const QString &identifier )
const
285 const QString agentTypeIdentifier = mManager->agentInstanceType( identifier );
286 Q_ASSERT_X( mTypes.contains( agentTypeIdentifier ),
"fillAgentInstanceLight",
"Requests non-existing agent type" );
288 instance.d->mType = mTypes.value( agentTypeIdentifier );
289 instance.d->mIdentifier = identifier;
294 void AgentManagerPrivate::serviceOwnerChanged(
const QString&,
const QString &oldOwner,
const QString& )
296 if ( oldOwner.isEmpty() ) {
302 void AgentManagerPrivate::createDBusInterface()
309 QLatin1String(
"/AgentManager" ),
310 DBusConnectionPool::threadConnection(), mParent );
312 QObject::connect( mManager, SIGNAL(agentTypeAdded(QString)),
313 mParent, SLOT(agentTypeAdded(QString)) );
314 QObject::connect( mManager, SIGNAL(agentTypeRemoved(QString)),
315 mParent, SLOT(agentTypeRemoved(QString)) );
316 QObject::connect( mManager, SIGNAL(agentInstanceAdded(QString)),
317 mParent, SLOT(agentInstanceAdded(QString)) );
318 QObject::connect( mManager, SIGNAL(agentInstanceRemoved(QString)),
319 mParent, SLOT(agentInstanceRemoved(QString)) );
320 QObject::connect( mManager, SIGNAL(agentInstanceStatusChanged(QString,
int,QString)),
321 mParent, SLOT(agentInstanceStatusChanged(QString,
int,QString)) );
322 QObject::connect( mManager, SIGNAL(agentInstanceProgressChanged(QString,uint,QString)),
323 mParent, SLOT(agentInstanceProgressChanged(QString,uint,QString)) );
324 QObject::connect( mManager, SIGNAL(agentInstanceNameChanged(QString,QString)),
325 mParent, SLOT(agentInstanceNameChanged(QString,QString)) );
326 QObject::connect( mManager, SIGNAL(agentInstanceWarning(QString,QString)),
327 mParent, SLOT(agentInstanceWarning(QString,QString)) );
328 QObject::connect( mManager, SIGNAL(agentInstanceError(QString,QString)),
329 mParent, SLOT(agentInstanceError(QString,QString)) );
330 QObject::connect( mManager, SIGNAL(agentInstanceOnlineChanged(QString,
bool)),
331 mParent, SLOT(agentInstanceOnlineChanged(QString,
bool)) );
333 if ( mManager->isValid() ) {
334 QDBusReply<QStringList> result = mManager->agentTypes();
335 if ( result.isValid() ) {
336 foreach (
const QString &type, result.value() ) {
337 const AgentType agentType = fillAgentType( type );
338 mTypes.insert( type, agentType );
341 result = mManager->agentInstances();
342 if ( result.isValid() ) {
343 foreach (
const QString &instance, result.value() ) {
344 const AgentInstance agentInstance = fillAgentInstance( instance );
345 mInstances.insert( instance, agentInstance );
349 kWarning() <<
"AgentManager failed to get a valid AgentManager DBus interface. Error is:" << mManager->lastError().type() << mManager->lastError().name() << mManager->lastError().message();
355 AgentManager::AgentManager()
359 qRegisterMetaType<Akonadi::AgentType>();
360 qRegisterMetaType<Akonadi::AgentInstance>();
362 d->createDBusInterface();
365 DBusConnectionPool::threadConnection(),
366 QDBusServiceWatcher::WatchForOwnerChange,
this );
367 connect( watcher, SIGNAL(serviceOwnerChanged(QString,QString,QString)),
368 this, SLOT(serviceOwnerChanged(QString,QString,QString)) );
380 if ( !AgentManagerPrivate::mSelf ) {
384 return AgentManagerPrivate::mSelf;
389 return d->mTypes.values();
394 return d->mTypes.value( identifier );
399 return d->mInstances.values();
404 return d->mInstances.value( identifier );
409 d->mManager->removeAgentInstance( instance.
identifier() );
419 const QString resId = collection.
resource();
420 Q_ASSERT( !resId.isEmpty() );
421 d->mManager->agentInstanceSynchronizeCollection( resId, collection.
id(), recursive );
424 #include "moc_agentmanager.cpp"
void instanceStatusChanged(const Akonadi::AgentInstance &instance)
This signal is emitted whenever the status of an agent instance has changed.
void synchronizeCollection(const Collection &collection)
Trigger a synchronization of the given collection by its owning resource agent.
QList< AgentInstance > List
Describes a list of agent instances.
void instanceRemoved(const Akonadi::AgentInstance &instance)
This signal is emitted whenever an agent instance was removed.
AgentInstance::List instances() const
Returns the list of all available agent instances.
Provides an interface to retrieve agent types and manage agent instances.
Represents a collection of PIM items.
void readAgentInstances()
Reads the information about all known agent instances from the server.
void instanceError(const Akonadi::AgentInstance &instance, const QString &message)
This signal is emitted whenever the agent instance raised an error.
void instanceProgressChanged(const Akonadi::AgentInstance &instance)
This signal is emitted whenever the progress of an agent instance has changed.
bool isValid() const
Returns whether the agent type is valid.
void instanceNameChanged(const Akonadi::AgentInstance &instance)
This signal is emitted whenever the name of the agent instance has changed.
QString identifier() const
Returns the unique identifier of the agent instance.
static QString serviceName(ServiceType serviceType)
Returns the namespaced D-Bus service name for serviceType.
QString identifier() const
Returns the unique identifier of the agent type.
void removeInstance(const AgentInstance &instance)
Removes the given agent instance.
void readAgentTypes()
Reads the information about all known agent types from the serverside agent manager and updates mType...
void instanceAdded(const Akonadi::AgentInstance &instance)
This signal is emitted whenever a new agent instance was created.
void typeRemoved(const Akonadi::AgentType &type)
This signal is emitted whenever an agent type was removed from the system.
A representation of an agent type.
AgentInstance instance(const QString &identifier) const
Returns the agent instance with the given identifier or an invalid agent instance if the identifier d...
bool isValid() const
Returns whether the agent instance object is valid.
QList< AgentType > List
Describes a list of agent types.
Id id() const
Returns the unique identifier of the entity.
void instanceOnline(const Akonadi::AgentInstance &instance, bool online)
This signal is emitted whenever the online state of an agent changed.
AgentType type(const QString &identifier) const
Returns the agent type with the given identifier or an invalid agent type if the identifier does not ...
void instanceWarning(const Akonadi::AgentInstance &instance, const QString &message)
This signal is emitted whenever the agent instance raised a warning.
~AgentManager()
Destroys the agent manager.
AgentType::List types() const
Returns the list of all available agent types.
static AgentManager * self()
Returns the global instance of the agent manager.
A representation of an agent instance.
QString resource() const
Returns the identifier of the resource owning the collection.
void typeAdded(const Akonadi::AgentType &type)
This signal is emitted whenever a new agent type was installed on the system.