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>
35 #include <KLocalizedString>
37 using namespace Akonadi;
43 const QString &identifier = mManager->createAgentInstance( type.
identifier() );
44 if ( identifier.isEmpty() ) {
48 return fillAgentInstanceLight( identifier );
51 void AgentManagerPrivate::agentTypeAdded(
const QString &identifier )
55 if ( mTypes.contains( identifier ) ) {
59 const AgentType type = fillAgentType( identifier );
61 mTypes.insert( identifier, type );
80 void AgentManagerPrivate::agentTypeRemoved(
const QString &identifier )
82 if ( !mTypes.contains( identifier ) ) {
86 const AgentType type = mTypes.take( identifier );
90 void AgentManagerPrivate::agentInstanceAdded(
const QString &identifier )
92 const AgentInstance instance = fillAgentInstance( identifier );
102 const bool newAgentInstance = !mInstances.contains( identifier );
103 if ( newAgentInstance ) {
104 mInstances.insert( identifier, instance );
107 mInstances.remove( identifier );
108 mInstances.insert( identifier, instance );
114 void AgentManagerPrivate::agentInstanceRemoved(
const QString &identifier )
116 if ( !mInstances.contains( identifier ) ) {
120 const AgentInstance instance = mInstances.take( identifier );
124 void AgentManagerPrivate::agentInstanceStatusChanged(
const QString &identifier,
int status,
const QString &msg )
126 if ( !mInstances.contains( identifier ) ) {
131 instance.d->mStatus = status;
132 instance.d->mStatusMessage = msg;
137 void AgentManagerPrivate::agentInstanceProgressChanged(
const QString &identifier, uint progress,
const QString &msg )
139 if ( !mInstances.contains( identifier ) ) {
144 instance.d->mProgress = progress;
145 if ( !msg.isEmpty() ) {
146 instance.d->mStatusMessage = msg;
152 void AgentManagerPrivate::agentInstanceWarning(
const QString &identifier,
const QString &msg )
154 if ( !mInstances.contains( identifier ) ) {
162 void AgentManagerPrivate::agentInstanceError(
const QString &identifier,
const QString &msg )
164 if ( !mInstances.contains( identifier ) ) {
172 void AgentManagerPrivate::agentInstanceOnlineChanged(
const QString &identifier,
bool state )
174 if ( !mInstances.contains( identifier ) ) {
179 instance.d->mIsOnline = state;
183 void AgentManagerPrivate::agentInstanceNameChanged(
const QString &identifier,
const QString &name )
185 if ( !mInstances.contains( identifier ) ) {
190 instance.d->mName = name;
197 const QDBusReply<QStringList> types = mManager->agentTypes();
198 if ( types.isValid() ) {
199 foreach (
const QString &type, types.value() ) {
200 if ( !mTypes.contains( type ) ) {
201 agentTypeAdded( type );
209 const QDBusReply<QStringList> instances = mManager->agentInstances();
210 if ( instances.isValid() ) {
211 foreach (
const QString &instance, instances.value() ) {
212 if ( !mInstances.contains( instance ) ) {
213 agentInstanceAdded( instance );
219 AgentType AgentManagerPrivate::fillAgentType(
const QString &identifier )
const
222 type.d->mIdentifier = identifier;
223 type.d->mName = mManager->agentName( identifier, KGlobal::locale()->language() );
224 type.d->mDescription = mManager->agentComment( identifier, KGlobal::locale()->language() );
225 type.d->mIconName = mManager->agentIcon( identifier );
226 type.d->mMimeTypes = mManager->agentMimeTypes( identifier );
227 type.d->mCapabilities = mManager->agentCapabilities( identifier );
232 void AgentManagerPrivate::setName(
const AgentInstance &instance,
const QString &name )
234 mManager->setAgentInstanceName( instance.
identifier(), name );
237 void AgentManagerPrivate::setOnline(
const AgentInstance &instance,
bool state )
239 mManager->setAgentInstanceOnline( instance.
identifier(), state );
242 void AgentManagerPrivate::configure(
const AgentInstance &instance, QWidget *parent )
246 winId = (qlonglong)( parent->window()->winId() );
249 mManager->agentInstanceConfigure( instance.
identifier(), winId );
252 void AgentManagerPrivate::synchronize(
const AgentInstance &instance )
254 mManager->agentInstanceSynchronize( instance.
identifier() );
257 void AgentManagerPrivate::synchronizeCollectionTree(
const AgentInstance &instance )
259 mManager->agentInstanceSynchronizeCollectionTree( instance.
identifier() );
262 AgentInstance AgentManagerPrivate::fillAgentInstance(
const QString &identifier )
const
266 const QString agentTypeIdentifier = mManager->agentInstanceType( identifier );
267 if ( !mTypes.contains( agentTypeIdentifier ) ) {
271 instance.d->mType = mTypes.value( agentTypeIdentifier );
272 instance.d->mIdentifier = identifier;
273 instance.d->mName = mManager->agentInstanceName( identifier );
274 instance.d->mStatus = mManager->agentInstanceStatus( identifier );
275 instance.d->mStatusMessage = mManager->agentInstanceStatusMessage( identifier );
276 instance.d->mProgress = mManager->agentInstanceProgress( identifier );
277 instance.d->mIsOnline = mManager->agentInstanceOnline( identifier );
282 AgentInstance AgentManagerPrivate::fillAgentInstanceLight(
const QString &identifier )
const
286 const QString agentTypeIdentifier = mManager->agentInstanceType( identifier );
287 Q_ASSERT_X( mTypes.contains( agentTypeIdentifier ),
"fillAgentInstanceLight",
"Requests non-existing agent type" );
289 instance.d->mType = mTypes.value( agentTypeIdentifier );
290 instance.d->mIdentifier = identifier;
295 void AgentManagerPrivate::serviceOwnerChanged(
const QString&,
const QString &oldOwner,
const QString& )
297 if ( oldOwner.isEmpty() ) {
303 void AgentManagerPrivate::createDBusInterface()
310 QLatin1String(
"/AgentManager" ),
311 DBusConnectionPool::threadConnection(), mParent );
313 QObject::connect( mManager, SIGNAL(agentTypeAdded(QString)),
314 mParent, SLOT(agentTypeAdded(QString)) );
315 QObject::connect( mManager, SIGNAL(agentTypeRemoved(QString)),
316 mParent, SLOT(agentTypeRemoved(QString)) );
317 QObject::connect( mManager, SIGNAL(agentInstanceAdded(QString)),
318 mParent, SLOT(agentInstanceAdded(QString)) );
319 QObject::connect( mManager, SIGNAL(agentInstanceRemoved(QString)),
320 mParent, SLOT(agentInstanceRemoved(QString)) );
321 QObject::connect( mManager, SIGNAL(agentInstanceStatusChanged(QString,
int,QString)),
322 mParent, SLOT(agentInstanceStatusChanged(QString,
int,QString)) );
323 QObject::connect( mManager, SIGNAL(agentInstanceProgressChanged(QString,uint,QString)),
324 mParent, SLOT(agentInstanceProgressChanged(QString,uint,QString)) );
325 QObject::connect( mManager, SIGNAL(agentInstanceNameChanged(QString,QString)),
326 mParent, SLOT(agentInstanceNameChanged(QString,QString)) );
327 QObject::connect( mManager, SIGNAL(agentInstanceWarning(QString,QString)),
328 mParent, SLOT(agentInstanceWarning(QString,QString)) );
329 QObject::connect( mManager, SIGNAL(agentInstanceError(QString,QString)),
330 mParent, SLOT(agentInstanceError(QString,QString)) );
331 QObject::connect( mManager, SIGNAL(agentInstanceOnlineChanged(QString,
bool)),
332 mParent, SLOT(agentInstanceOnlineChanged(QString,
bool)) );
334 if ( mManager->isValid() ) {
335 QDBusReply<QStringList> result = mManager->agentTypes();
336 if ( result.isValid() ) {
337 foreach (
const QString &type, result.value() ) {
338 const AgentType agentType = fillAgentType( type );
339 mTypes.insert( type, agentType );
342 result = mManager->agentInstances();
343 if ( result.isValid() ) {
344 foreach (
const QString &instance, result.value() ) {
345 const AgentInstance agentInstance = fillAgentInstance( instance );
346 mInstances.insert( instance, agentInstance );
350 kWarning() <<
"AgentManager failed to get a valid AgentManager DBus interface. Error is:" << mManager->lastError().type() << mManager->lastError().name() << mManager->lastError().message();
356 AgentManager::AgentManager()
360 qRegisterMetaType<Akonadi::AgentType>();
361 qRegisterMetaType<Akonadi::AgentInstance>();
363 d->createDBusInterface();
366 DBusConnectionPool::threadConnection(),
367 QDBusServiceWatcher::WatchForOwnerChange,
this );
368 connect( watcher, SIGNAL(serviceOwnerChanged(QString,QString,QString)),
369 this, SLOT(serviceOwnerChanged(QString,QString,QString)) );
381 if ( !AgentManagerPrivate::mSelf ) {
385 return AgentManagerPrivate::mSelf;
390 return d->mTypes.values();
395 return d->mTypes.value( identifier );
400 return d->mInstances.values();
405 return d->mInstances.value( identifier );
410 d->mManager->removeAgentInstance( instance.
identifier() );
420 const QString resId = collection.
resource();
421 Q_ASSERT( !resId.isEmpty() );
422 d->mManager->agentInstanceSynchronizeCollection( resId, collection.
id(), recursive );
425 #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.