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>
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 if (mTypes.isEmpty()) {
74 const AgentType type = fillAgentType(identifier);
76 mTypes.insert(identifier, type);
82 void AgentManagerPrivate::agentTypeRemoved(
const QString &identifier)
84 if (!mTypes.contains(identifier)) {
88 const AgentType type = mTypes.take(identifier);
92 void AgentManagerPrivate::agentInstanceAdded(
const QString &identifier)
104 const bool newAgentInstance = !mInstances.contains(identifier);
105 if (newAgentInstance) {
106 mInstances.insert(identifier, instance);
109 mInstances.remove(identifier);
110 mInstances.insert(identifier, instance);
116 void AgentManagerPrivate::agentInstanceRemoved(
const QString &identifier)
118 if (!mInstances.contains(identifier)) {
126 void AgentManagerPrivate::agentInstanceStatusChanged(
const QString &identifier,
int status,
const QString &msg)
128 if (!mInstances.contains(identifier)) {
133 instance.d->mStatus = status;
134 instance.d->mStatusMessage = msg;
139 void AgentManagerPrivate::agentInstanceProgressChanged(
const QString &identifier, uint progress,
const QString &msg)
141 if (!mInstances.contains(identifier)) {
146 instance.d->mProgress = progress;
147 if (!msg.isEmpty()) {
148 instance.d->mStatusMessage = msg;
154 void AgentManagerPrivate::agentInstanceWarning(
const QString &identifier,
const QString &msg)
156 if (!mInstances.contains(identifier)) {
164 void AgentManagerPrivate::agentInstanceError(
const QString &identifier,
const QString &msg)
166 if (!mInstances.contains(identifier)) {
174 void AgentManagerPrivate::agentInstanceOnlineChanged(
const QString &identifier,
bool state)
176 if (!mInstances.contains(identifier)) {
181 instance.d->mIsOnline = state;
185 void AgentManagerPrivate::agentInstanceNameChanged(
const QString &identifier,
const QString &name)
187 if (!mInstances.contains(identifier)) {
192 instance.d->mName = name;
199 const QDBusReply<QStringList> types = mManager->agentTypes();
200 if (types.isValid()) {
201 foreach (
const QString &type, types.value()) {
202 const AgentType agentType = fillAgentType(type);
204 mTypes.insert(type, agentType);
213 const QDBusReply<QStringList> instances = mManager->agentInstances();
214 if (instances.isValid()) {
215 foreach (
const QString &instance, instances.value()) {
216 const AgentInstance agentInstance = fillAgentInstance(instance);
218 mInstances.insert(instance, agentInstance);
225 AgentType AgentManagerPrivate::fillAgentType(
const QString &identifier)
const
228 type.d->mIdentifier = identifier;
229 type.d->mName = mManager->agentName(identifier, KGlobal::locale()->language());
230 type.d->mDescription = mManager->agentComment(identifier, KGlobal::locale()->language());
231 type.d->mIconName = mManager->agentIcon(identifier);
232 type.d->mMimeTypes = mManager->agentMimeTypes(identifier);
233 type.d->mCapabilities = mManager->agentCapabilities(identifier);
234 type.d->mCustomProperties = mManager->agentCustomProperties(identifier);
239 void AgentManagerPrivate::setName(
const AgentInstance &instance,
const QString &name)
241 mManager->setAgentInstanceName(instance.
identifier(), name);
244 void AgentManagerPrivate::setOnline(
const AgentInstance &instance,
bool state)
246 mManager->setAgentInstanceOnline(instance.
identifier(), state);
249 void AgentManagerPrivate::configure(
const AgentInstance &instance, QWidget *parent)
253 winId = (qlonglong)(parent->window()->winId());
256 mManager->agentInstanceConfigure(instance.
identifier(), winId);
259 void AgentManagerPrivate::synchronize(
const AgentInstance &instance)
261 mManager->agentInstanceSynchronize(instance.
identifier());
264 void AgentManagerPrivate::synchronizeCollectionTree(
const AgentInstance &instance)
266 mManager->agentInstanceSynchronizeCollectionTree(instance.
identifier());
269 AgentInstance AgentManagerPrivate::fillAgentInstance(
const QString &identifier)
const
273 const QString agentTypeIdentifier = mManager->agentInstanceType(identifier);
274 if (!mTypes.contains(agentTypeIdentifier)) {
278 instance.d->mType = mTypes.value(agentTypeIdentifier);
279 instance.d->mIdentifier = identifier;
280 instance.d->mName = mManager->agentInstanceName(identifier);
281 instance.d->mStatus = mManager->agentInstanceStatus(identifier);
282 instance.d->mStatusMessage = mManager->agentInstanceStatusMessage(identifier);
283 instance.d->mProgress = mManager->agentInstanceProgress(identifier);
284 instance.d->mIsOnline = mManager->agentInstanceOnline(identifier);
289 AgentInstance AgentManagerPrivate::fillAgentInstanceLight(
const QString &identifier)
const
293 const QString agentTypeIdentifier = mManager->agentInstanceType(identifier);
294 Q_ASSERT_X(mTypes.contains(agentTypeIdentifier),
"fillAgentInstanceLight",
"Requests non-existing agent type");
296 instance.d->mType = mTypes.value(agentTypeIdentifier);
297 instance.d->mIdentifier = identifier;
302 void AgentManagerPrivate::serviceOwnerChanged(
const QString &,
const QString &oldOwner,
const QString &)
304 if (oldOwner.isEmpty()) {
305 if (mTypes.isEmpty()) {
308 if (mInstances.isEmpty()) {
314 void AgentManagerPrivate::createDBusInterface()
321 QLatin1String(
"/AgentManager"),
322 DBusConnectionPool::threadConnection(), mParent);
324 QObject::connect(mManager, SIGNAL(agentTypeAdded(QString)),
325 mParent, SLOT(agentTypeAdded(QString)));
326 QObject::connect(mManager, SIGNAL(agentTypeRemoved(QString)),
327 mParent, SLOT(agentTypeRemoved(QString)));
328 QObject::connect(mManager, SIGNAL(agentInstanceAdded(QString)),
329 mParent, SLOT(agentInstanceAdded(QString)));
330 QObject::connect(mManager, SIGNAL(agentInstanceRemoved(QString)),
331 mParent, SLOT(agentInstanceRemoved(QString)));
332 QObject::connect(mManager, SIGNAL(agentInstanceStatusChanged(QString,
int,QString)),
333 mParent, SLOT(agentInstanceStatusChanged(QString,
int,QString)));
334 QObject::connect(mManager, SIGNAL(agentInstanceProgressChanged(QString,uint,QString)),
335 mParent, SLOT(agentInstanceProgressChanged(QString,uint,QString)));
336 QObject::connect(mManager, SIGNAL(agentInstanceNameChanged(QString,QString)),
337 mParent, SLOT(agentInstanceNameChanged(QString,QString)));
338 QObject::connect(mManager, SIGNAL(agentInstanceWarning(QString,QString)),
339 mParent, SLOT(agentInstanceWarning(QString,QString)));
340 QObject::connect(mManager, SIGNAL(agentInstanceError(QString,QString)),
341 mParent, SLOT(agentInstanceError(QString,QString)));
342 QObject::connect(mManager, SIGNAL(agentInstanceOnlineChanged(QString,
bool)),
343 mParent, SLOT(agentInstanceOnlineChanged(QString,
bool)));
345 if (mManager->isValid()) {
353 AgentManager::AgentManager()
358 qRegisterMetaType<Akonadi::AgentType>();
359 qRegisterMetaType<Akonadi::AgentInstance>();
361 d->createDBusInterface();
364 DBusConnectionPool::threadConnection(),
365 QDBusServiceWatcher::WatchForOwnerChange,
this);
366 connect(watcher, SIGNAL(serviceOwnerChanged(QString,QString,QString)),
367 this, SLOT(serviceOwnerChanged(QString,QString,QString)));
379 if (!AgentManagerPrivate::mSelf) {
383 return AgentManagerPrivate::mSelf;
388 return d->mTypes.values();
393 return d->mTypes.value(identifier);
398 return d->mInstances.values();
403 return d->mInstances.value(identifier);
408 d->mManager->removeAgentInstance(instance.
identifier());
418 const QString resId = collection.
resource();
419 Q_ASSERT(!resId.isEmpty());
420 d->mManager->agentInstanceSynchronizeCollection(resId, collection.
id(), recursive);
423 #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.
FreeBusyManager::Singleton.
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.