summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Grulich <[email protected]>2017-02-10 11:43:05 +0100
committerJan Grulich <[email protected]>2017-02-10 11:43:05 +0100
commit056e690f455df3a235e99d905ecf29425c33d579 (patch)
tree78304c4c7381c8fb5a55be9ebf31a76968f409f6
parente75dc3a65489ccf07a4f2ef131f0d9b73cedd479 (diff)
Differentiate download and installed size for upgradable applications
-rw-r--r--libdiscover/backends/FlatpakBackend/FlatpakBackend.cpp26
-rw-r--r--libdiscover/backends/FlatpakBackend/FlatpakResource.cpp34
-rw-r--r--libdiscover/backends/FlatpakBackend/FlatpakResource.h8
3 files changed, 49 insertions, 19 deletions
diff --git a/libdiscover/backends/FlatpakBackend/FlatpakBackend.cpp b/libdiscover/backends/FlatpakBackend/FlatpakBackend.cpp
index 3ddc440..04f0770 100644
--- a/libdiscover/backends/FlatpakBackend/FlatpakBackend.cpp
+++ b/libdiscover/backends/FlatpakBackend/FlatpakBackend.cpp
@@ -430,6 +430,7 @@ void FlatpakBackend::loadLocalUpdates(FlatpakInstallation *flatpakInstallation)
FlatpakResource *resource = getAppForInstalledRef(flatpakInstallation, ref);
if (resource) {
resource->setState(AbstractResource::Upgradeable);
+ updateAppSize(flatpakInstallation, resource);
}
}
}
@@ -450,6 +451,7 @@ void FlatpakBackend::loadRemoteUpdates(FlatpakInstallation *flatpakInstallation)
FlatpakResource *resource = getAppForInstalledRef(flatpakInstallation, ref);
if (resource) {
resource->setState(AbstractResource::Upgradeable);
+ updateAppSize(flatpakInstallation, resource);
}
}
}
@@ -519,7 +521,7 @@ void FlatpakBackend::updateAppInstalledMetadata(FlatpakInstalledRef *installedRe
// Update the rest
resource->updateFromRef(FLATPAK_REF(installedRef));
resource->setOrigin(QString::fromUtf8(flatpak_installed_ref_get_origin(installedRef)));
- resource->setSize(flatpak_installed_ref_get_installed_size(installedRef));
+ resource->setInstalledSize(flatpak_installed_ref_get_installed_size(installedRef));
resource->setState(AbstractResource::Installed);
}
@@ -602,14 +604,16 @@ bool FlatpakBackend::updateAppSize(FlatpakInstallation *flatpakInstallation, Fla
// right now it doesn't matter whether we get size for installed or not installed app, but if we
// start making difference then for not installed app check download and install size separately
- // if (resource->isInstalled()) {
+ if (resource->state() == AbstractResource::Installed) {
// The size appears to be already set (from updateAppInstalledMetadata() apparently)
- if (resource->size() > 0) {
+ if (resource->installedSize() > 0) {
return true;
}
- // } else {
- // TODO check download and installed size separately
- // }
+ } else {
+ if (resource->installedSize() > 0 && resource->downloadSize() > 0) {
+ return true;
+ }
+ }
// Check if we know the needed runtime which is needed for calculating the size
if (resource->runtime().isEmpty()) {
@@ -636,14 +640,14 @@ bool FlatpakBackend::updateAppSize(FlatpakInstallation *flatpakInstallation, Fla
}
}
- if (resource->isInstalled()) {
+ if (resource->state() == AbstractResource::Installed) {
g_autoptr(FlatpakInstalledRef) ref = nullptr;
ref = getInstalledRefForApp(flatpakInstallation, resource);
if (!ref) {
qWarning() << "Failed to get installed size of " << resource->name();
return false;
}
- resource->setSize(flatpak_installed_ref_get_installed_size(ref));
+ resource->setInstalledSize(flatpak_installed_ref_get_installed_size(ref));
} else {
g_autoptr(FlatpakRef) ref = nullptr;
g_autoptr(GError) localError = nullptr;
@@ -665,9 +669,11 @@ bool FlatpakBackend::updateAppSize(FlatpakInstallation *flatpakInstallation, Fla
// TODO: What size do we want to show (installed vs download)? Do we want to show app size + runtime size if runtime is not installed?
if (runtime && !runtime->isInstalled()) {
- resource->setSize(runtime->size() + installedSize);
+ resource->setDownloadSize(runtime->downloadSize() + downloadSize);
+ resource->setInstalledSize(runtime->installedSize() + installedSize);
} else {
- resource->setSize(installedSize);
+ resource->setDownloadSize(downloadSize);
+ resource->setInstalledSize(installedSize);
}
}
diff --git a/libdiscover/backends/FlatpakBackend/FlatpakResource.cpp b/libdiscover/backends/FlatpakBackend/FlatpakResource.cpp
index 68bf466..203ddf0 100644
--- a/libdiscover/backends/FlatpakBackend/FlatpakResource.cpp
+++ b/libdiscover/backends/FlatpakBackend/FlatpakResource.cpp
@@ -39,8 +39,9 @@
FlatpakResource::FlatpakResource(AppStream::Component *component, FlatpakBackend *parent)
: AbstractResource(parent)
, m_appdata(component)
+ , m_downloadSize(0)
+ , m_installedSize(0)
, m_scope(FlatpakResource::System)
- , m_size(0)
, m_state(AbstractResource::None)
, m_type(FlatpakResource::DesktopApp)
{
@@ -119,6 +120,11 @@ QString FlatpakResource::commit() const
return m_commit;
}
+int FlatpakResource::downloadSize() const
+{
+ return m_downloadSize;
+}
+
QStringList FlatpakResource::executables() const
{
// return m_appdata->provided(AppStream::Provided::KindBinary).items();
@@ -168,6 +174,11 @@ QString FlatpakResource::installedVersion() const
return version;
}
+int FlatpakResource::installedSize() const
+{
+ return m_installedSize;
+}
+
bool FlatpakResource::isTechnical() const
{
return false;
@@ -269,7 +280,11 @@ QString FlatpakResource::section()
int FlatpakResource::size()
{
- return m_size;
+ if (m_state == Installed) {
+ return m_installedSize;
+ } else {
+ return m_downloadSize;
+ }
}
AbstractResource::State FlatpakResource::state()
@@ -371,6 +386,11 @@ void FlatpakResource::setCommit(const QString &commit)
m_commit = commit;
}
+void FlatpakResource::setDownloadSize(int size)
+{
+ m_downloadSize = size;
+}
+
void FlatpakResource::setFlatpakName(const QString &name)
{
m_flatpakName = name;
@@ -381,6 +401,11 @@ void FlatpakResource::setIconPath(const QString &path)
m_iconPath = path;
}
+void FlatpakResource::setInstalledSize(int size)
+{
+ m_installedSize = size;
+}
+
void FlatpakResource::setOrigin(const QString &origin)
{
m_origin = origin;
@@ -403,11 +428,6 @@ void FlatpakResource::setState(AbstractResource::State state)
emit stateChanged();
}
-void FlatpakResource::setSize(int size)
-{
- m_size = size;
-}
-
void FlatpakResource::setType(FlatpakResource::ResourceType type)
{
m_type = type;
diff --git a/libdiscover/backends/FlatpakBackend/FlatpakResource.h b/libdiscover/backends/FlatpakBackend/FlatpakResource.h
index 3e89d97..fa2a92f 100644
--- a/libdiscover/backends/FlatpakBackend/FlatpakResource.h
+++ b/libdiscover/backends/FlatpakBackend/FlatpakResource.h
@@ -74,9 +74,11 @@ public:
QStringList categories() override;
QString comment() override;
QString commit() const;
+ int downloadSize() const;
QStringList executables() const override;
QVariant icon() const override;
QString installedVersion() const override;
+ int installedSize() const;
bool isTechnical() const override;
QUrl homepage() override;
QString flatpakName() const;
@@ -104,13 +106,14 @@ public:
void setArch(const QString &arch);
void setBranch(const QString &branch);
void setCommit(const QString &commit);
+ void setDownloadSize(int size);
void setIconPath(const QString &path);
+ void setInstalledSize(int size);
void setFlatpakName(const QString &name);
void setOrigin(const QString &origin);
void setRuntime(const QString &runtime);
void setScope(Scope scope);
void setState(State state);
- void setSize(int size);
void setType(ResourceType type);
// void setAddons(const AddonList& addons);
// void setAddonInstalled(const QString& addon, bool installed);
@@ -124,12 +127,13 @@ public:
QString m_arch;
QString m_branch;
QString m_commit;
+ int m_downloadSize;
QString m_flatpakName;
QString m_iconPath;
+ int m_installedSize;
QString m_origin;
QString m_runtime;
Scope m_scope;
- int m_size;
AbstractResource::State m_state;
ResourceType m_type;
};