7#include "agentmanager.h"
8#include "agentmanager_p.h"
10#include "agentinstance_p.h"
11#include "agenttype_p.h"
12#include "collection.h"
13#include "servermanager.h"
14#include <QDBusConnection>
16#include "shared/akranges.h"
18#include <QDBusServiceWatcher>
22using namespace AkRanges;
26AgentInstance AgentManagerPrivate::createInstance(
const AgentType &type)
28 const QString &identifier = mManager->createAgentInstance(
type.identifier());
33 return fillAgentInstanceLight(identifier);
36void AgentManagerPrivate::agentTypeAdded(
const QString &identifier)
40 if (mTypes.contains(identifier)) {
44 if (mTypes.isEmpty()) {
59 const AgentType
type = fillAgentType(identifier);
61 mTypes.insert(identifier, type);
63 Q_EMIT mParent->typeAdded(type);
67void AgentManagerPrivate::agentTypeRemoved(
const QString &identifier)
69 if (!mTypes.contains(identifier)) {
73 const AgentType
type = mTypes.take(identifier);
74 Q_EMIT mParent->typeRemoved(type);
77void AgentManagerPrivate::agentInstanceAdded(
const QString &identifier)
80 if (instance.isValid()) {
88 const bool newAgentInstance = !mInstances.contains(identifier);
89 if (newAgentInstance) {
90 mInstances.insert(identifier, instance);
91 Q_EMIT mParent->instanceAdded(instance);
93 mInstances.remove(identifier);
94 mInstances.insert(identifier, instance);
95 Q_EMIT mParent->instanceStatusChanged(instance);
100void AgentManagerPrivate::agentInstanceRemoved(
const QString &identifier)
102 if (!mInstances.contains(identifier)) {
107 Q_EMIT mParent->instanceRemoved(instance);
110void AgentManagerPrivate::agentInstanceStatusChanged(
const QString &identifier,
int status,
const QString &msg)
112 if (!mInstances.contains(identifier)) {
117 instance.d->mStatus =
status;
118 instance.d->mStatusMessage = msg;
120 Q_EMIT mParent->instanceStatusChanged(instance);
123void AgentManagerPrivate::agentInstanceProgressChanged(
const QString &identifier, uint progress,
const QString &msg)
125 if (!mInstances.contains(identifier)) {
130 instance.d->mProgress = progress;
132 instance.d->mStatusMessage = msg;
135 Q_EMIT mParent->instanceProgressChanged(instance);
138void AgentManagerPrivate::agentInstanceWarning(
const QString &identifier,
const QString &msg)
140 if (!mInstances.contains(identifier)) {
145 Q_EMIT mParent->instanceWarning(instance, msg);
148void AgentManagerPrivate::agentInstanceError(
const QString &identifier,
const QString &msg)
150 if (!mInstances.contains(identifier)) {
155 Q_EMIT mParent->instanceError(instance, msg);
158void AgentManagerPrivate::agentInstanceOnlineChanged(
const QString &identifier,
bool state)
160 if (!mInstances.contains(identifier)) {
165 instance.d->mIsOnline = state;
166 Q_EMIT mParent->instanceOnline(instance, state);
169void AgentManagerPrivate::agentInstanceNameChanged(
const QString &identifier,
const QString &name)
171 if (!mInstances.contains(identifier)) {
176 instance.d->mName =
name;
178 Q_EMIT mParent->instanceNameChanged(instance);
181void AgentManagerPrivate::readAgentTypes()
186 for (
const QString &type : lst) {
187 const AgentType agentType = fillAgentType(type);
188 if (agentType.isValid()) {
189 mTypes.insert(type, agentType);
190 Q_EMIT mParent->typeAdded(agentType);
196void AgentManagerPrivate::readAgentInstances()
199 if (instances.isValid()) {
201 for (
const QString &instance : lst) {
202 const AgentInstance agentInstance = fillAgentInstance(instance);
203 if (agentInstance.isValid()) {
204 mInstances.insert(instance, agentInstance);
205 Q_EMIT mParent->instanceAdded(agentInstance);
211AgentType AgentManagerPrivate::fillAgentType(
const QString &identifier)
const
214 type.d->mIdentifier = identifier;
215 type.d->mName = mManager->agentName(identifier);
216 type.d->mDescription = mManager->agentComment(identifier);
217 type.d->mIconName = mManager->agentIcon(identifier);
218 type.d->mMimeTypes = mManager->agentMimeTypes(identifier);
219 type.d->mCapabilities = mManager->agentCapabilities(identifier);
220 type.d->mCustomProperties = mManager->agentCustomProperties(identifier);
227 mManager->setAgentInstanceName(instance.
identifier(), name);
230void AgentManagerPrivate::setOnline(
const AgentInstance &instance,
bool state)
232 mManager->setAgentInstanceOnline(instance.
identifier(), state);
237 mManager->setAgentInstanceActivities(instance.
identifier(), activities);
240void AgentManagerPrivate::setActivitiesEnabled(
const AgentInstance &instance,
bool enabled)
242 mManager->setAgentInstanceActivitiesEnabled(instance.
identifier(), enabled);
249 winId =
static_cast<qlonglong
>(parent->
window()->winId());
252 mManager->agentInstanceConfigure(instance.
identifier(), winId);
255void AgentManagerPrivate::synchronize(
const AgentInstance &instance)
257 mManager->agentInstanceSynchronize(instance.
identifier());
260void AgentManagerPrivate::synchronizeCollectionTree(
const AgentInstance &instance)
262 mManager->agentInstanceSynchronizeCollectionTree(instance.
identifier());
265void AgentManagerPrivate::synchronizeTags(
const AgentInstance &instance)
267 mManager->agentInstanceSynchronizeTags(instance.
identifier());
274 const QString agentTypeIdentifier = mManager->agentInstanceType(identifier);
275 if (!mTypes.contains(agentTypeIdentifier)) {
279 instance.d->mType = mTypes.value(agentTypeIdentifier);
280 instance.d->mIdentifier = identifier;
281 instance.d->mName = mManager->agentInstanceName(identifier);
282 instance.d->mStatus = mManager->agentInstanceStatus(identifier);
283 instance.d->mStatusMessage = mManager->agentInstanceStatusMessage(identifier);
284 instance.d->mProgress = mManager->agentInstanceProgress(identifier);
285 instance.d->mIsOnline = mManager->agentInstanceOnline(identifier);
296 const QString agentTypeIdentifier = mManager->agentInstanceType(identifier);
297 Q_ASSERT_X(mTypes.contains(agentTypeIdentifier),
"fillAgentInstanceLight",
"Requests non-existing agent type");
299 instance.d->mType = mTypes.value(agentTypeIdentifier);
300 instance.d->mIdentifier = identifier;
305void AgentManagerPrivate::createDBusInterface()
310 using AgentManagerIface = org::freedesktop::Akonadi::AgentManager;
311 mManager = std::make_unique<AgentManagerIface>(ServerManager::serviceName(ServerManager::Control),
312 QStringLiteral(
"/AgentManager"),
316 connect(mManager.get(), &AgentManagerIface::agentTypeAdded,
this, &AgentManagerPrivate::agentTypeAdded);
317 connect(mManager.get(), &AgentManagerIface::agentTypeRemoved,
this, &AgentManagerPrivate::agentTypeRemoved);
318 connect(mManager.get(), &AgentManagerIface::agentInstanceAdded,
this, &AgentManagerPrivate::agentInstanceAdded);
319 connect(mManager.get(), &AgentManagerIface::agentInstanceRemoved,
this, &AgentManagerPrivate::agentInstanceRemoved);
320 connect(mManager.get(), &AgentManagerIface::agentInstanceStatusChanged,
this, &AgentManagerPrivate::agentInstanceStatusChanged);
321 connect(mManager.get(), &AgentManagerIface::agentInstanceProgressChanged,
this, &AgentManagerPrivate::agentInstanceProgressChanged);
322 connect(mManager.get(), &AgentManagerIface::agentInstanceNameChanged,
this, &AgentManagerPrivate::agentInstanceNameChanged);
323 connect(mManager.get(), &AgentManagerIface::agentInstanceWarning,
this, &AgentManagerPrivate::agentInstanceWarning);
324 connect(mManager.get(), &AgentManagerIface::agentInstanceError,
this, &AgentManagerPrivate::agentInstanceError);
325 connect(mManager.get(), &AgentManagerIface::agentInstanceOnlineChanged,
this, &AgentManagerPrivate::agentInstanceOnlineChanged);
327 if (mManager->isValid()) {
329 readAgentInstances();
337 , d(new AgentManagerPrivate(this))
340 qRegisterMetaType<Akonadi::AgentType>();
341 qRegisterMetaType<Akonadi::AgentInstance>();
343 d->createDBusInterface();
345 d->mServiceWatcher = std::make_unique<QDBusServiceWatcher>(ServerManager::serviceName(ServerManager::Control),
349 if (d->mTypes.isEmpty()) {
352 if (d->mInstances.isEmpty()) {
353 d->readAgentInstances();
364 if (!AgentManagerPrivate::mSelf) {
368 return AgentManagerPrivate::mSelf;
376 if (d->mTypes.isEmpty()) {
379 return d->mTypes | Views::values | Actions::toQVector;
384 return d->mTypes.value(identifier);
389 return d->mInstances | Views::values | Actions::toQVector;
394 return d->mInstances.value(identifier);
399 d->mManager->removeAgentInstance(instance.
identifier());
402void AgentManager::synchronizeCollection(
const Collection &collection)
404 synchronizeCollection(collection,
false);
407void AgentManager::synchronizeCollection(
const Collection &collection,
bool recursive)
409 const QString resId = collection.resource();
411 d->mManager->agentInstanceSynchronizeCollection(resId, collection.id(), recursive);
414#include "moc_agentmanager.cpp"
416#include "moc_agentmanager_p.cpp"
Represents one agent instance and takes care of communication with it.
QString identifier() const
Set/get the unique identifier of this AgentInstance.
The agent manager has knowledge about all available agents (it scans for .desktop files in the agent ...
AgentManager(bool verbose, QObject *parent=nullptr)
Creates a new agent manager.
~AgentManager() override
Destroys the agent manager.
A representation of an agent instance.
QString identifier() const
Returns the unique identifier of the agent instance.
Provides an interface to retrieve agent types and manage agent instances.
A representation of an agent type.
Represents a collection of PIM items.
Q_SCRIPTABLE CaptureState status()
Helper integration between Akonadi and Qt.
VehicleSection::Type type(QStringView coachNumber, QStringView coachClassification)
QString name(StandardAction id)
QDBusConnection sessionBus()
bool isValid() const const
void serviceRegistered(const QString &serviceName)
bool isEmpty() const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)