summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Grulich <[email protected]>2017-03-28 14:54:05 +0200
committerJan Grulich <[email protected]>2017-03-29 07:07:11 +0200
commitc2cc4b1e27c82e8a99731470d522c45405b15702 (patch)
treeda99f4f72794c092bfaaaafa3e5417ba2c8abaec
parent6a71d25b43038ec2ebdc21d2c724f0252f469dad (diff)
Use better description for size when size is not known
Summary: Show that size is being fetched instead of displaying size 0 which can confuse users. Also when we fail to fetch the size, then display "unknown size" rather then again showing that size is 0. Reviewers: apol Reviewed By: apol Subscribers: plasma-devel Tags: #plasma Differential Revision: https://phabricator.kde.org/D5219
-rw-r--r--libdiscover/backends/FlatpakBackend/FlatpakBackend.cpp5
-rw-r--r--libdiscover/backends/FlatpakBackend/FlatpakFetchDataJob.cpp6
-rw-r--r--libdiscover/backends/FlatpakBackend/FlatpakFetchDataJob.h2
-rw-r--r--libdiscover/backends/FlatpakBackend/FlatpakResource.cpp20
4 files changed, 29 insertions, 4 deletions
diff --git a/libdiscover/backends/FlatpakBackend/FlatpakBackend.cpp b/libdiscover/backends/FlatpakBackend/FlatpakBackend.cpp
index 6f2fefa..8aad980 100644
--- a/libdiscover/backends/FlatpakBackend/FlatpakBackend.cpp
+++ b/libdiscover/backends/FlatpakBackend/FlatpakBackend.cpp
@@ -878,6 +878,10 @@ bool FlatpakBackend::updateAppSizeFromRemote(FlatpakInstallation *flatpakInstall
FlatpakFetchDataJob *job = new FlatpakFetchDataJob(flatpakInstallation, resource, FlatpakFetchDataJob::FetchSize);
connect(job, &FlatpakFetchDataJob::finished, job, &FlatpakFetchDataJob::deleteLater);
connect(job, &FlatpakFetchDataJob::jobFetchSizeFinished, this, &FlatpakBackend::onFetchSizeFinished);
+ connect(job, &FlatpakFetchDataJob::jobFetchSizeFailed, [resource] () {
+ resource->setDownloadSize(-2);
+ resource->setInstalledSize(-2);
+ });
job->start();
}
@@ -928,6 +932,7 @@ int FlatpakBackend::updatesCount() const
ResultsStream * FlatpakBackend::search(const AbstractResourcesBackend::Filters &filter)
{
QVector<AbstractResource*> ret;
+
foreach(AbstractResource* r, m_resources) {
if (qobject_cast<FlatpakResource*>(r)->type() == FlatpakResource::Runtime && filter.state != AbstractResource::Upgradeable) {
continue;
diff --git a/libdiscover/backends/FlatpakBackend/FlatpakFetchDataJob.cpp b/libdiscover/backends/FlatpakBackend/FlatpakFetchDataJob.cpp
index 3f9d203..1796110 100644
--- a/libdiscover/backends/FlatpakBackend/FlatpakFetchDataJob.cpp
+++ b/libdiscover/backends/FlatpakBackend/FlatpakFetchDataJob.cpp
@@ -53,11 +53,13 @@ void FlatpakFetchDataJob::run()
if (m_app->origin().isEmpty()) {
qWarning() << "Failed to get metadata file because of missing origin";
+ Q_EMIT jobFetchMetadataFailed();
return;
}
fakeRef = createFakeRef(m_app);
if (!fakeRef) {
+ Q_EMIT jobFetchMetadataFailed();
return;
}
@@ -67,11 +69,13 @@ void FlatpakFetchDataJob::run()
metadataContent = QByteArray((char *)g_bytes_get_data(data, &len));
} else {
qWarning() << "Failed to get metadata file: " << localError->message;
+ Q_EMIT jobFetchMetadataFailed();
return;
}
if (metadataContent.isEmpty()) {
qWarning() << "Failed to get metadata file: empty metadata";
+ Q_EMIT jobFetchMetadataFailed();
return;
}
@@ -83,12 +87,14 @@ void FlatpakFetchDataJob::run()
ref = createFakeRef(m_app);
if (!ref) {
+ Q_EMIT jobFetchSizeFailed();
return;
}
if (!flatpak_installation_fetch_remote_size_sync(m_installation, m_app->origin().toStdString().c_str(),
ref, &downloadSize, &installedSize, m_cancellable, &localError)) {
qWarning() << "Failed to get remote size of " << m_app->name() << ": " << localError->message;
+ Q_EMIT jobFetchSizeFailed();
return;
}
diff --git a/libdiscover/backends/FlatpakBackend/FlatpakFetchDataJob.h b/libdiscover/backends/FlatpakBackend/FlatpakFetchDataJob.h
index 911324c..03abbf6 100644
--- a/libdiscover/backends/FlatpakBackend/FlatpakFetchDataJob.h
+++ b/libdiscover/backends/FlatpakBackend/FlatpakFetchDataJob.h
@@ -46,7 +46,9 @@ public:
void run() override;
Q_SIGNALS:
+ void jobFetchMetadataFailed();
void jobFetchMetadataFinished(FlatpakInstallation *installation, FlatpakResource *resource, const QByteArray &metadata);
+ void jobFetchSizeFailed();
void jobFetchSizeFinished(FlatpakResource *resource, int downloadSize, int installedSize);
private:
diff --git a/libdiscover/backends/FlatpakBackend/FlatpakResource.cpp b/libdiscover/backends/FlatpakBackend/FlatpakResource.cpp
index 7583dd3..3bd6680 100644
--- a/libdiscover/backends/FlatpakBackend/FlatpakResource.cpp
+++ b/libdiscover/backends/FlatpakBackend/FlatpakResource.cpp
@@ -45,8 +45,8 @@
FlatpakResource::FlatpakResource(AppStream::Component *component, FlatpakBackend *parent)
: AbstractResource(parent)
, m_appdata(component)
- , m_downloadSize(0)
- , m_installedSize(0)
+ , m_downloadSize(-1)
+ , m_installedSize(-1)
, m_scope(FlatpakResource::System)
, m_state(AbstractResource::None)
, m_type(FlatpakResource::DesktopApp)
@@ -352,9 +352,21 @@ QString FlatpakResource::sizeDescription()
{
KFormat f;
if (!isInstalled() || canUpgrade()) {
- return i18nc("@info app size", "%1 to download, %2 on disk", f.formatByteSize(downloadSize()), f.formatByteSize(installedSize()));
+ if (downloadSize() == -1 || installedSize() == -1) {
+ return i18n("Retrieving size information");
+ } else if (downloadSize() == -2 || installedSize() == -2) {
+ return i18n("Unknown size");
+ } else {
+ return i18nc("@info app size", "%1 to download, %2 on disk", f.formatByteSize(downloadSize()), f.formatByteSize(installedSize()));
+ }
} else {
- return i18nc("@info app size", "%1 on disk", f.formatByteSize(installedSize()));
+ if (installedSize() == -1) {
+ return i18n("Retrieving size information");
+ } else if (installedSize() == -2) {
+ return i18n("Unknown size");
+ } else {
+ return i18nc("@info app size", "%1 on disk", f.formatByteSize(installedSize()));
+ }
}
}