diff options
Diffstat (limited to 'common/resourcefacade.cpp')
-rw-r--r-- | common/resourcefacade.cpp | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/common/resourcefacade.cpp b/common/resourcefacade.cpp index bdb5841..583d6ec 100644 --- a/common/resourcefacade.cpp +++ b/common/resourcefacade.cpp | |||
@@ -283,6 +283,55 @@ AccountFacade::~AccountFacade() | |||
283 | { | 283 | { |
284 | } | 284 | } |
285 | 285 | ||
286 | QPair<KAsync::Job<void>, typename Sink::ResultEmitter<typename ApplicationDomain::SinkAccount::Ptr>::Ptr> AccountFacade::load(const Sink::Query &query) | ||
287 | { | ||
288 | auto runner = new LocalStorageQueryRunner<ApplicationDomain::SinkAccount>(query, mIdentifier, sConfigNotifier); | ||
289 | auto monitoredResources = QSharedPointer<QSet<QByteArray>>::create(); | ||
290 | runner->setStatusUpdater([runner, monitoredResources](ApplicationDomain::SinkAccount &account) { | ||
291 | Query query; | ||
292 | query.filter<ApplicationDomain::SinkResource::Account>(account.identifier()); | ||
293 | const auto resources = Store::read<ApplicationDomain::SinkResource>(query); | ||
294 | SinkTrace() << "Found resource belonging to the account " << account.identifier() << " : " << resources; | ||
295 | auto accountIdentifier = account.identifier(); | ||
296 | ApplicationDomain::Status status = ApplicationDomain::ConnectedStatus; | ||
297 | for (const auto &resource : resources) { | ||
298 | auto resourceAccess = ResourceAccessFactory::instance().getAccess(resource.identifier(), ResourceConfig::getResourceType(resource.identifier())); | ||
299 | if (!monitoredResources->contains(resource.identifier())) { | ||
300 | auto ret = QObject::connect(resourceAccess.data(), &ResourceAccess::notification, runner->guard(), [resource, runner, resourceAccess, accountIdentifier](const Notification ¬ification) { | ||
301 | SinkTrace() << "Received notification in facade: " << notification.type; | ||
302 | if (notification.type == Notification::Status) { | ||
303 | runner->statusChanged(accountIdentifier); | ||
304 | } | ||
305 | }); | ||
306 | Q_ASSERT(ret); | ||
307 | monitoredResources->insert(resource.identifier()); | ||
308 | } | ||
309 | |||
310 | //Figure out overall status | ||
311 | auto s = resourceAccess->getResourceStatus(); | ||
312 | switch (s) { | ||
313 | case ApplicationDomain::ErrorStatus: | ||
314 | status = ApplicationDomain::ErrorStatus; | ||
315 | break; | ||
316 | case ApplicationDomain::OfflineStatus: | ||
317 | if (status == ApplicationDomain::ConnectedStatus) { | ||
318 | status = ApplicationDomain::OfflineStatus; | ||
319 | } | ||
320 | break; | ||
321 | case ApplicationDomain::ConnectedStatus: | ||
322 | break; | ||
323 | case ApplicationDomain::BusyStatus: | ||
324 | if (status != ApplicationDomain::ErrorStatus) { | ||
325 | status = ApplicationDomain::BusyStatus; | ||
326 | } | ||
327 | break; | ||
328 | } | ||
329 | } | ||
330 | account.setStatusStatus(status); | ||
331 | }); | ||
332 | return qMakePair(KAsync::null<void>(), runner->emitter()); | ||
333 | } | ||
334 | |||
286 | IdentityFacade::IdentityFacade() : LocalStorageFacade<Sink::ApplicationDomain::Identity>("identities") | 335 | IdentityFacade::IdentityFacade() : LocalStorageFacade<Sink::ApplicationDomain::Identity>("identities") |
287 | { | 336 | { |
288 | } | 337 | } |