Changeset View
Changeset View
Standalone View
Standalone View
src/core/agentmanager.cpp
Show All 24 Lines | |||||
25 | #include "KDBusConnectionPool" | 25 | #include "KDBusConnectionPool" | ||
26 | #include "servermanager.h" | 26 | #include "servermanager.h" | ||
27 | #include "collection.h" | 27 | #include "collection.h" | ||
28 | 28 | | |||
29 | #include "shared/akranges.h" | 29 | #include "shared/akranges.h" | ||
30 | 30 | | |||
31 | #include <QDBusServiceWatcher> | 31 | #include <QDBusServiceWatcher> | ||
32 | #include <QWidget> | 32 | #include <QWidget> | ||
33 | #include <kdbusconnectionpool.h> | ||||
33 | 34 | | |||
34 | using namespace Akonadi; | 35 | using namespace Akonadi; | ||
35 | using namespace AkRanges; | 36 | using namespace AkRanges; | ||
36 | 37 | | |||
37 | // @cond PRIVATE | 38 | // @cond PRIVATE | ||
38 | 39 | | |||
39 | AgentInstance AgentManagerPrivate::createInstance(const AgentType &type) | 40 | AgentInstance AgentManagerPrivate::createInstance(const AgentType &type) | ||
40 | { | 41 | { | ||
▲ Show 20 Lines • Show All 263 Lines • ▼ Show 20 Line(s) | 301 | { | |||
304 | Q_ASSERT_X(mTypes.contains(agentTypeIdentifier), "fillAgentInstanceLight", "Requests non-existing agent type"); | 305 | Q_ASSERT_X(mTypes.contains(agentTypeIdentifier), "fillAgentInstanceLight", "Requests non-existing agent type"); | ||
305 | 306 | | |||
306 | instance.d->mType = mTypes.value(agentTypeIdentifier); | 307 | instance.d->mType = mTypes.value(agentTypeIdentifier); | ||
307 | instance.d->mIdentifier = identifier; | 308 | instance.d->mIdentifier = identifier; | ||
308 | 309 | | |||
309 | return instance; | 310 | return instance; | ||
310 | } | 311 | } | ||
311 | 312 | | |||
312 | void AgentManagerPrivate::serviceOwnerChanged(const QString &, const QString &oldOwner, const QString &) | | |||
313 | { | | |||
314 | if (oldOwner.isEmpty()) { | | |||
315 | if (mTypes.isEmpty()) { // just to be safe | | |||
316 | readAgentTypes(); | | |||
317 | } | | |||
318 | if (mInstances.isEmpty()) { | | |||
319 | readAgentInstances(); | | |||
320 | } | | |||
321 | } | | |||
322 | } | | |||
323 | | ||||
324 | void AgentManagerPrivate::createDBusInterface() | 313 | void AgentManagerPrivate::createDBusInterface() | ||
325 | { | 314 | { | ||
326 | mTypes.clear(); | 315 | mTypes.clear(); | ||
327 | mInstances.clear(); | 316 | mInstances.clear(); | ||
328 | delete mManager; | 317 | delete mManager; | ||
329 | 318 | | |||
330 | mManager = new org::freedesktop::Akonadi::AgentManager(ServerManager::serviceName(ServerManager::Control), | 319 | mManager = new org::freedesktop::Akonadi::AgentManager(ServerManager::serviceName(ServerManager::Control), | ||
331 | QStringLiteral("/AgentManager"), | 320 | QStringLiteral("/AgentManager"), | ||
Show All 33 Lines | 352 | AgentManager::AgentManager() | |||
365 | , d(new AgentManagerPrivate(this)) | 354 | , d(new AgentManagerPrivate(this)) | ||
366 | { | 355 | { | ||
367 | // needed for queued connections on our signals | 356 | // needed for queued connections on our signals | ||
368 | qRegisterMetaType<Akonadi::AgentType>(); | 357 | qRegisterMetaType<Akonadi::AgentType>(); | ||
369 | qRegisterMetaType<Akonadi::AgentInstance>(); | 358 | qRegisterMetaType<Akonadi::AgentInstance>(); | ||
370 | 359 | | |||
371 | d->createDBusInterface(); | 360 | d->createDBusInterface(); | ||
372 | 361 | | |||
373 | QDBusServiceWatcher *watcher = new QDBusServiceWatcher(ServerManager::serviceName(ServerManager::Control), | 362 | d->mServiceWatcher = std::make_unique<QDBusServiceWatcher>( | ||
374 | KDBusConnectionPool::threadConnection(), | 363 | ServerManager::serviceName(ServerManager::Control), KDBusConnectionPool::threadConnection(), | ||
375 | QDBusServiceWatcher::WatchForOwnerChange, this); | 364 | QDBusServiceWatcher::WatchForRegistration); | ||
376 | connect(watcher, &QDBusServiceWatcher::serviceOwnerChanged, | 365 | connect(d->mServiceWatcher.get(), &QDBusServiceWatcher::serviceRegistered, | ||
377 | this, [this](const QString &arg1, const QString &arg2 , const QString &arg3) { d->serviceOwnerChanged(arg1, arg2, arg3); }); | 366 | this, [this]() { | ||
367 | if (d->mTypes.isEmpty()) { // just to be safe | ||||
368 | d->readAgentTypes(); | ||||
369 | } | ||||
370 | if (d->mInstances.isEmpty()) { | ||||
371 | d->readAgentInstances(); | ||||
372 | } | ||||
373 | }); | ||||
378 | } | 374 | } | ||
379 | 375 | | |||
380 | // @endcond | 376 | // @endcond | ||
381 | 377 | | |||
382 | AgentManager::~AgentManager() | 378 | AgentManager::~AgentManager() | ||
383 | { | 379 | { | ||
384 | delete d; | 380 | delete d; | ||
385 | } | 381 | } | ||
386 | 382 | | |||
387 | AgentManager *AgentManager::self() | 383 | AgentManager *AgentManager::self() | ||
388 | { | 384 | { | ||
389 | if (!AgentManagerPrivate::mSelf) { | 385 | if (!AgentManagerPrivate::mSelf) { | ||
390 | AgentManagerPrivate::mSelf = new AgentManager(); | 386 | AgentManagerPrivate::mSelf = new AgentManager(); | ||
391 | } | 387 | } | ||
392 | 388 | | |||
393 | return AgentManagerPrivate::mSelf; | 389 | return AgentManagerPrivate::mSelf; | ||
394 | } | 390 | } | ||
395 | 391 | | |||
396 | AgentType::List AgentManager::types() const | 392 | AgentType::List AgentManager::types() const | ||
397 | { | 393 | { | ||
398 | // Maybe the Control process is up and ready but we haven't been to the event loop yet so serviceOwnerChanged wasn't called yet. | 394 | // Maybe the Control process is up and ready but we haven't been to the event loop yet so | ||
395 | // QDBusServiceWatcher hasn't notified us yet. | ||||
399 | // In that case make sure to do it here, to avoid going into Broken state. | 396 | // In that case make sure to do it here, to avoid going into Broken state. | ||
400 | if (d->mTypes.isEmpty()) { | 397 | if (d->mTypes.isEmpty()) { | ||
401 | d->readAgentTypes(); | 398 | d->readAgentTypes(); | ||
402 | } | 399 | } | ||
403 | return d->mTypes | Views::values | Actions::toQVector; | 400 | return d->mTypes | Views::values | Actions::toQVector; | ||
404 | } | 401 | } | ||
405 | 402 | | |||
406 | AgentType AgentManager::type(const QString &identifier) const | 403 | AgentType AgentManager::type(const QString &identifier) const | ||
Show All 32 Lines |