Changeset View
Changeset View
Standalone View
Standalone View
libdiscover/resources/ResourcesModel.cpp
Show First 20 Lines • Show All 385 Lines • ▼ Show 20 Line(s) | 377 | if (backend != m_currentApplicationBackend) { | |||
---|---|---|---|---|---|
386 | qCDebug(LIBDISCOVER_LOG) << "setting currentApplicationBackend" << backend; | 386 | qCDebug(LIBDISCOVER_LOG) << "setting currentApplicationBackend" << backend; | ||
387 | m_currentApplicationBackend = backend; | 387 | m_currentApplicationBackend = backend; | ||
388 | Q_EMIT currentApplicationBackendChanged(backend); | 388 | Q_EMIT currentApplicationBackendChanged(backend); | ||
389 | } | 389 | } | ||
390 | } | 390 | } | ||
391 | 391 | | |||
392 | void ResourcesModel::initApplicationsBackend() | 392 | void ResourcesModel::initApplicationsBackend() | ||
393 | { | 393 | { | ||
394 | KConfigGroup settings(KSharedConfig::openConfig(), "ResourcesModel"); | 394 | const auto name = applicationSourceName(); | ||
395 | const QString name = settings.readEntry<QString>("currentApplicationBackend", QStringLiteral("packagekit-backend")); | | |||
396 | 395 | | |||
397 | const auto backends = applicationBackends(); | 396 | const auto backends = applicationBackends(); | ||
398 | auto idx = kIndexOf(backends, [name](AbstractResourcesBackend* b) { return b->name() == name; }); | 397 | auto idx = kIndexOf(backends, [name](AbstractResourcesBackend* b) { return b->name() == name; }); | ||
399 | if (idx<0) { | 398 | if (idx<0) { | ||
400 | idx = kIndexOf(backends, [](AbstractResourcesBackend* b) { return b->hasApplications(); }); | 399 | idx = kIndexOf(backends, [](AbstractResourcesBackend* b) { return b->hasApplications(); }); | ||
401 | qCDebug(LIBDISCOVER_LOG) << "falling back applications backend to" << idx; | 400 | qCDebug(LIBDISCOVER_LOG) << "falling back applications backend to" << idx; | ||
402 | } | 401 | } | ||
403 | setCurrentApplicationBackend(backends.value(idx, nullptr), false); | 402 | setCurrentApplicationBackend(backends.value(idx, nullptr), false); | ||
404 | } | 403 | } | ||
405 | 404 | | |||
406 | | ||||
407 | int ResourcesModel::fetchingUpdatesProgress() const | 405 | int ResourcesModel::fetchingUpdatesProgress() const | ||
408 | { | 406 | { | ||
409 | if (m_backends.isEmpty()) | 407 | if (m_backends.isEmpty()) | ||
410 | return 0; | 408 | return 0; | ||
411 | 409 | | |||
412 | int sum = 0; | 410 | int sum = 0; | ||
413 | for(auto backend: m_backends) { | 411 | for(auto backend: m_backends) { | ||
414 | sum += backend->fetchingUpdatesProgress(); | 412 | sum += backend->fetchingUpdatesProgress(); | ||
415 | } | 413 | } | ||
416 | return sum / m_backends.count(); | 414 | return sum / m_backends.count(); | ||
417 | } | 415 | } | ||
416 | | ||||
417 | QString ResourcesModel::applicationSourceName() const | ||||
418 | { | ||||
419 | KConfigGroup settings(KSharedConfig::openConfig(), "ResourcesModel"); | ||||
420 | return settings.readEntry<QString>("currentApplicationBackend", QStringLiteral("packagekit-backend")); | ||||
421 | } |