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);
51void 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);
82void AgentManagerPrivate::agentTypeRemoved(
const QString &identifier)
84 if (!mTypes.contains(identifier)) {
88 const AgentType type = mTypes.take(identifier);
92void 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);
116void AgentManagerPrivate::agentInstanceRemoved(
const QString &identifier)
118 if (!mInstances.contains(identifier)) {
126void 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;
139void 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;
154void AgentManagerPrivate::agentInstanceWarning(
const QString &identifier,
const QString &msg)
156 if (!mInstances.contains(identifier)) {
164void AgentManagerPrivate::agentInstanceError(
const QString &identifier,
const QString &msg)
166 if (!mInstances.contains(identifier)) {
174void AgentManagerPrivate::agentInstanceOnlineChanged(
const QString &identifier,
bool state)
176 if (!mInstances.contains(identifier)) {
181 instance.d->mIsOnline = state;
185void 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);
225AgentType 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);
239void AgentManagerPrivate::setName(
const AgentInstance &instance,
const QString &name)
241 mManager->setAgentInstanceName(instance.
identifier(), name);
244void AgentManagerPrivate::setOnline(
const AgentInstance &instance,
bool state)
246 mManager->setAgentInstanceOnline(instance.
identifier(), state);
249void AgentManagerPrivate::configure(
const AgentInstance &instance, QWidget *parent)
253 winId = (qlonglong)(parent->window()->winId());
256 mManager->agentInstanceConfigure(instance.
identifier(), winId);
259void AgentManagerPrivate::synchronize(
const AgentInstance &instance)
261 mManager->agentInstanceSynchronize(instance.
identifier());
264void AgentManagerPrivate::synchronizeCollectionTree(
const AgentInstance &instance)
266 mManager->agentInstanceSynchronizeCollectionTree(instance.
identifier());
269AgentInstance 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);
289AgentInstance 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;
302void AgentManagerPrivate::serviceOwnerChanged(
const QString &,
const QString &oldOwner,
const QString &)
304 if (oldOwner.isEmpty()) {
305 if (mTypes.isEmpty()) {
308 if (mInstances.isEmpty()) {
314void 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()) {
353AgentManager::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);
418 const QString resId = collection.resource();
419 Q_ASSERT(!resId.isEmpty());
420 d->mManager->agentInstanceSynchronizeCollection(resId, collection.id(), recursive);
423#include "moc_agentmanager.cpp"
A representation of an agent instance.
QString identifier() const
Returns the unique identifier of the agent instance.
bool isValid() const
Returns whether the agent instance object is valid.
QList< AgentInstance > List
Describes a list of agent instances.
void readAgentTypes()
Reads the information about all known agent types from the serverside agent manager and updates mType...
void readAgentInstances()
Reads the information about all known agent instances from the server.
Provides an interface to retrieve agent types and manage agent instances.
void instanceProgressChanged(const Akonadi::AgentInstance &instance)
This signal is emitted whenever the progress of an agent instance has changed.
AgentType::List types() const
Returns the list of all available agent types.
AgentType type(const QString &identifier) const
Returns the agent type with the given identifier or an invalid agent type if the identifier does not ...
static AgentManager * self()
Returns the global instance of the agent manager.
void typeAdded(const Akonadi::AgentType &type)
This signal is emitted whenever a new agent type was installed on the system.
void instanceRemoved(const Akonadi::AgentInstance &instance)
This signal is emitted whenever an agent instance was removed.
void instanceNameChanged(const Akonadi::AgentInstance &instance)
This signal is emitted whenever the name of the agent instance has changed.
void typeRemoved(const Akonadi::AgentType &type)
This signal is emitted whenever an agent type was removed from the system.
void removeInstance(const AgentInstance &instance)
Removes the given agent instance.
void instanceAdded(const Akonadi::AgentInstance &instance)
This signal is emitted whenever a new agent instance was created.
~AgentManager()
Destroys the agent manager.
void instanceOnline(const Akonadi::AgentInstance &instance, bool online)
This signal is emitted whenever the online state of an agent changed.
AgentInstance instance(const QString &identifier) const
Returns the agent instance with the given identifier or an invalid agent instance if the identifier d...
void instanceWarning(const Akonadi::AgentInstance &instance, const QString &message)
This signal is emitted whenever the agent instance raised a warning.
void instanceStatusChanged(const Akonadi::AgentInstance &instance)
This signal is emitted whenever the status of an agent instance has changed.
void instanceError(const Akonadi::AgentInstance &instance, const QString &message)
This signal is emitted whenever the agent instance raised an error.
void synchronizeCollection(const Collection &collection)
Trigger a synchronization of the given collection by its owning resource agent.
AgentInstance::List instances() const
Returns the list of all available agent instances.
A representation of an agent type.
bool isValid() const
Returns whether the agent type is valid.
QList< AgentType > List
Describes a list of agent types.
Represents a collection of PIM items.
static QString serviceName(ServiceType serviceType)
Returns the namespaced D-Bus service name for serviceType.
FreeBusyManager::Singleton.