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 );
228 type.d->mCustomProperties = mManager->agentCustomProperties( identifier );
233 void AgentManagerPrivate::setName(
const AgentInstance &instance,
const QString &name )
235 mManager->setAgentInstanceName( instance.
identifier(), name );
238 void AgentManagerPrivate::setOnline(
const AgentInstance &instance,
bool state )
240 mManager->setAgentInstanceOnline( instance.
identifier(), state );
243 void AgentManagerPrivate::configure(
const AgentInstance &instance, QWidget *parent )
247 winId = (qlonglong)( parent->window()->winId() );
250 mManager->agentInstanceConfigure( instance.
identifier(), winId );
253 void AgentManagerPrivate::synchronize(
const AgentInstance &instance )
255 mManager->agentInstanceSynchronize( instance.
identifier() );
258 void AgentManagerPrivate::synchronizeCollectionTree(
const AgentInstance &instance )
260 mManager->agentInstanceSynchronizeCollectionTree( instance.
identifier() );
263 AgentInstance AgentManagerPrivate::fillAgentInstance(
const QString &identifier )
const
267 const QString agentTypeIdentifier = mManager->agentInstanceType( identifier );
268 if ( !mTypes.contains( agentTypeIdentifier ) ) {
272 instance.d->mType = mTypes.value( agentTypeIdentifier );
273 instance.d->mIdentifier = identifier;
274 instance.d->mName = mManager->agentInstanceName( identifier );
275 instance.d->mStatus = mManager->agentInstanceStatus( identifier );
276 instance.d->mStatusMessage = mManager->agentInstanceStatusMessage( identifier );
277 instance.d->mProgress = mManager->agentInstanceProgress( identifier );
278 instance.d->mIsOnline = mManager->agentInstanceOnline( identifier );
283 AgentInstance AgentManagerPrivate::fillAgentInstanceLight(
const QString &identifier )
const
287 const QString agentTypeIdentifier = mManager->agentInstanceType( identifier );
288 Q_ASSERT_X( mTypes.contains( agentTypeIdentifier ),
"fillAgentInstanceLight",
"Requests non-existing agent type" );
290 instance.d->mType = mTypes.value( agentTypeIdentifier );
291 instance.d->mIdentifier = identifier;
296 void AgentManagerPrivate::serviceOwnerChanged(
const QString&,
const QString &oldOwner,
const QString& )
298 if ( oldOwner.isEmpty() ) {
304 void AgentManagerPrivate::createDBusInterface()
311 QLatin1String(
"/AgentManager" ),
312 DBusConnectionPool::threadConnection(), mParent );
314 QObject::connect( mManager, SIGNAL(agentTypeAdded(QString)),
315 mParent, SLOT(agentTypeAdded(QString)) );
316 QObject::connect( mManager, SIGNAL(agentTypeRemoved(QString)),
317 mParent, SLOT(agentTypeRemoved(QString)) );
318 QObject::connect( mManager, SIGNAL(agentInstanceAdded(QString)),
319 mParent, SLOT(agentInstanceAdded(QString)) );
320 QObject::connect( mManager, SIGNAL(agentInstanceRemoved(QString)),
321 mParent, SLOT(agentInstanceRemoved(QString)) );
322 QObject::connect( mManager, SIGNAL(agentInstanceStatusChanged(QString,
int,QString)),
323 mParent, SLOT(agentInstanceStatusChanged(QString,
int,QString)) );
324 QObject::connect( mManager, SIGNAL(agentInstanceProgressChanged(QString,uint,QString)),
325 mParent, SLOT(agentInstanceProgressChanged(QString,uint,QString)) );
326 QObject::connect( mManager, SIGNAL(agentInstanceNameChanged(QString,QString)),
327 mParent, SLOT(agentInstanceNameChanged(QString,QString)) );
328 QObject::connect( mManager, SIGNAL(agentInstanceWarning(QString,QString)),
329 mParent, SLOT(agentInstanceWarning(QString,QString)) );
330 QObject::connect( mManager, SIGNAL(agentInstanceError(QString,QString)),
331 mParent, SLOT(agentInstanceError(QString,QString)) );
332 QObject::connect( mManager, SIGNAL(agentInstanceOnlineChanged(QString,
bool)),
333 mParent, SLOT(agentInstanceOnlineChanged(QString,
bool)) );
335 if ( mManager->isValid() ) {
336 QDBusReply<QStringList> result = mManager->agentTypes();
337 if ( result.isValid() ) {
338 foreach (
const QString &type, result.value() ) {
339 const AgentType agentType = fillAgentType( type );
340 mTypes.insert( type, agentType );
343 result = mManager->agentInstances();
344 if ( result.isValid() ) {
345 foreach (
const QString &instance, result.value() ) {
346 const AgentInstance agentInstance = fillAgentInstance( instance );
347 mInstances.insert( instance, agentInstance );
351 kWarning() <<
"AgentManager failed to get a valid AgentManager DBus interface. Error is:" << mManager->lastError().type() << mManager->lastError().name() << mManager->lastError().message();
357 AgentManager::AgentManager()
361 qRegisterMetaType<Akonadi::AgentType>();
362 qRegisterMetaType<Akonadi::AgentInstance>();
364 d->createDBusInterface();
367 DBusConnectionPool::threadConnection(),
368 QDBusServiceWatcher::WatchForOwnerChange,
this );
369 connect( watcher, SIGNAL(serviceOwnerChanged(QString,QString,QString)),
370 this, SLOT(serviceOwnerChanged(QString,QString,QString)) );
382 if ( !AgentManagerPrivate::mSelf ) {
386 return AgentManagerPrivate::mSelf;
391 return d->mTypes.values();
396 return d->mTypes.value( identifier );
401 return d->mInstances.values();
406 return d->mInstances.value( identifier );
411 d->mManager->removeAgentInstance( instance.
identifier() );
421 const QString resId = collection.
resource();
422 Q_ASSERT( !resId.isEmpty() );
423 d->mManager->agentInstanceSynchronizeCollection( resId, collection.
id(), recursive );
426 #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.