[gnome-software] Split the 'size' property into size-installed and size-download



commit 647dc44384ef1f3b8a636273e11dd3abf01f3218
Author: Richard Hughes <richard hughsie com>
Date:   Fri Apr 22 17:22:43 2016 +0100

    Split the 'size' property into size-installed and size-download
    
    The PackageKit backend only has one size (installed size for INSTALLED,
    download size for AVAILABLE) but that doesn't mean we have to restrict the
    GNOME Software plugin API or UI to this artificial limitation.

 src/gs-app.c                                   |   86 +++++++++++++++++++++---
 src/gs-app.h                                   |   12 ++--
 src/gs-plugin-loader.c                         |    3 +-
 src/gs-shell-details.c                         |   39 ++++++++---
 src/gs-shell-details.ui                        |   48 ++++++++++++--
 src/gs-shell-extras.c                          |    1 -
 src/plugins/gs-plugin-dpkg.c                   |    2 +-
 src/plugins/gs-plugin-dummy.c                  |    6 +-
 src/plugins/gs-plugin-epiphany.c               |    2 +-
 src/plugins/gs-plugin-fedora-distro-upgrades.c |    3 +-
 src/plugins/gs-plugin-fwupd.c                  |    3 +-
 src/plugins/gs-plugin-packagekit-refine.c      |   19 ++++-
 src/plugins/gs-plugin-packagekit-refresh.c     |    3 +-
 src/plugins/gs-plugin-rpm.c                    |    6 +-
 src/plugins/gs-plugin-shell-extensions.c       |    6 +-
 src/plugins/gs-plugin-steam.c                  |    8 ++-
 src/plugins/gs-plugin-xdg-app.c                |   25 +++-----
 17 files changed, 205 insertions(+), 67 deletions(-)
---
diff --git a/src/gs-app.c b/src/gs-app.c
index 3b2654a..b8ee746 100644
--- a/src/gs-app.c
+++ b/src/gs-app.c
@@ -87,7 +87,8 @@ struct _GsApp
        gint                     rating;
        GArray                  *review_ratings;
        GPtrArray               *reviews; /* of GsReview */
-       guint64                  size;
+       guint64                  size_installed;
+       guint64                  size_download;
        AsAppKind                kind;
        AsAppState               state;
        AsAppState               state_recover;
@@ -315,9 +316,15 @@ gs_app_to_string (GsApp *app)
                                  G_GUINT64_FORMAT "",
                                  app->install_date);
        }
-       if (app->size != 0) {
-               gs_app_kv_printf (str, "size", "%" G_GUINT64_FORMAT "k",
-                                 app->size / 1024);
+       if (app->size_installed != 0) {
+               gs_app_kv_printf (str, "size-installed",
+                                 "%" G_GUINT64_FORMAT "k",
+                                 app->size_installed / 1024);
+       }
+       if (app->size_download != 0) {
+               gs_app_kv_printf (str, "size-download",
+                                 "%" G_GUINT64_FORMAT "k",
+                                 app->size_download / 1024);
        }
        if (app->related->len > 0)
                gs_app_kv_printf (str, "related", "%i", app->related->len);
@@ -1782,23 +1789,82 @@ gs_app_remove_review (GsApp *app, GsReview *review)
 }
 
 /**
- * gs_app_get_size:
+ * gs_app_get_size_download:
+ * @app: A #GsApp
+ *
+ * Gets the size of the total download needed to either install an available
+ * application, or update an already installed one.
+ *
+ * If there is a runtime not yet installed then this is also added.
+ *
+ * Returns: number of bytes, 0 for unknown, or %GS_APP_SIZE_UNKNOWABLE for invalid.
  */
 guint64
-gs_app_get_size (GsApp *app)
+gs_app_get_size_download (GsApp *app)
 {
+       guint64 sz;
+
        g_return_val_if_fail (GS_IS_APP (app), G_MAXUINT64);
-       return app->size;
+
+       /* this app */
+       sz = app->size_download;
+
+       /* add the runtime if this is not installed */
+       if (app->runtime != NULL) {
+               if (gs_app_get_state (app->runtime) == AS_APP_STATE_AVAILABLE)
+                       sz += gs_app_get_size_installed (app->runtime);
+       }
+
+       return sz;
+}
+
+/**
+ * gs_app_set_size_download:
+ */
+void
+gs_app_set_size_download (GsApp *app, guint64 size_download)
+{
+       g_return_if_fail (GS_IS_APP (app));
+       app->size_download = size_download;
+}
+
+/**
+ * gs_app_get_size_installed:
+ *
+ * Gets the size on disk, either for an existing application of one that could
+ * be installed.
+ *
+ * If there is a runtime not yet installed then this is also added.
+ *
+ * Returns: size in bytes, 0 for unknown, or %GS_APP_SIZE_UNKNOWABLE for invalid.
+ */
+guint64
+gs_app_get_size_installed (GsApp *app)
+{
+       guint64 sz;
+
+       g_return_val_if_fail (GS_IS_APP (app), G_MAXUINT64);
+
+       /* this app */
+       sz = app->size_installed;
+
+       /* add the runtime if this is not installed */
+       if (app->runtime != NULL) {
+               if (gs_app_get_state (app->runtime) == AS_APP_STATE_AVAILABLE)
+                       sz += gs_app_get_size_installed (app->runtime);
+       }
+
+       return sz;
 }
 
 /**
- * gs_app_set_size:
+ * gs_app_set_size_installed:
  */
 void
-gs_app_set_size (GsApp *app, guint64 size)
+gs_app_set_size_installed (GsApp *app, guint64 size_installed)
 {
        g_return_if_fail (GS_IS_APP (app));
-       app->size = size;
+       app->size_installed = size_installed;
 }
 
 /**
diff --git a/src/gs-app.h b/src/gs-app.h
index a74bdb7..d1fd56f 100644
--- a/src/gs-app.h
+++ b/src/gs-app.h
@@ -60,8 +60,7 @@ typedef enum {
 
 #define        GS_APP_INSTALL_DATE_UNSET               0
 #define        GS_APP_INSTALL_DATE_UNKNOWN             1 /* 1s past the epoch */
-#define        GS_APP_SIZE_UNKNOWN                     0
-#define        GS_APP_SIZE_MISSING                     1
+#define        GS_APP_SIZE_UNKNOWABLE                  G_MAXUINT64
 
 typedef enum {
        GS_APP_QUALITY_UNKNOWN,
@@ -203,9 +202,12 @@ void                gs_app_add_review              (GsApp          *app,
                                                 GsReview       *review);
 void            gs_app_remove_review           (GsApp          *app,
                                                 GsReview       *review);
-guint64                 gs_app_get_size                (GsApp          *app);
-void            gs_app_set_size                (GsApp          *app,
-                                                guint64         size);
+guint64                 gs_app_get_size_installed      (GsApp          *app);
+void            gs_app_set_size_installed      (GsApp          *app,
+                                                guint64         size_installed);
+guint64                 gs_app_get_size_download       (GsApp          *app);
+void            gs_app_set_size_download       (GsApp          *app,
+                                                guint64         size_download);
 GPtrArray      *gs_app_get_addons              (GsApp          *app);
 void            gs_app_add_addon               (GsApp          *app,
                                                 GsApp          *addon);
diff --git a/src/gs-plugin-loader.c b/src/gs-plugin-loader.c
index 074e51a..22e8ac8 100644
--- a/src/gs-plugin-loader.c
+++ b/src/gs-plugin-loader.c
@@ -1593,7 +1593,8 @@ gs_plugin_loader_convert_unavailable_app (GsApp *app, const gchar *search)
        gs_app_set_summary_missing (app, tmp->str);
        gs_app_set_kind (app, AS_APP_KIND_GENERIC);
        gs_app_set_state (app, AS_APP_STATE_UNAVAILABLE);
-       gs_app_set_size (app, GS_APP_SIZE_MISSING);
+       gs_app_set_size_installed (app, GS_APP_SIZE_UNKNOWABLE);
+       gs_app_set_size_download (app, GS_APP_SIZE_UNKNOWABLE);
        return TRUE;
 }
 
diff --git a/src/gs-shell-details.c b/src/gs-shell-details.c
index 9d38f5a..b89ca8d 100644
--- a/src/gs-shell-details.c
+++ b/src/gs-shell-details.c
@@ -86,7 +86,10 @@ struct _GsShellDetails
        GtkWidget               *label_details_license_value;
        GtkWidget               *label_details_origin_title;
        GtkWidget               *label_details_origin_value;
-       GtkWidget               *label_details_size_value;
+       GtkWidget               *label_details_size_installed_title;
+       GtkWidget               *label_details_size_installed_value;
+       GtkWidget               *label_details_size_download_title;
+       GtkWidget               *label_details_size_download_value;
        GtkWidget               *label_details_updated_value;
        GtkWidget               *label_details_version_value;
        GtkWidget               *label_failed;
@@ -753,17 +756,28 @@ gs_shell_details_refresh_all (GsShellDetails *self)
                gtk_label_set_label (GTK_LABEL (self->label_details_version_value), C_("version", "Unknown"));
        }
 
-       /* set the size */
-       if (gs_app_get_size (self->app) == GS_APP_SIZE_UNKNOWN) {
-               /* TRANSLATORS: this is where the size is being worked out */
-               gtk_label_set_label (GTK_LABEL (self->label_details_size_value), C_("size", "Calculating…"));
-       } else if (gs_app_get_size (self->app) == GS_APP_SIZE_MISSING) {
-               /* TRANSLATORS: this is where the size is not known */
-               gtk_label_set_label (GTK_LABEL (self->label_details_size_value), C_("size", "Unknown"));
+       /* set the installed size */
+       if (gs_app_get_size_installed (self->app) == GS_APP_SIZE_UNKNOWABLE) {
+               gtk_widget_hide (self->label_details_size_installed_title);
+               gtk_widget_hide (self->label_details_size_installed_value);
        } else {
                g_autofree gchar *size = NULL;
-               size = g_format_size (gs_app_get_size (self->app));
-               gtk_label_set_label (GTK_LABEL (self->label_details_size_value), size);
+               size = g_format_size (gs_app_get_size_installed (self->app));
+               gtk_label_set_label (GTK_LABEL (self->label_details_size_installed_value), size);
+               gtk_widget_show (self->label_details_size_installed_title);
+               gtk_widget_show (self->label_details_size_installed_value);
+       }
+
+       /* set the download size */
+       if (gs_app_get_size_download (self->app) == GS_APP_SIZE_UNKNOWABLE) {
+               gtk_widget_hide (self->label_details_size_download_title);
+               gtk_widget_hide (self->label_details_size_download_value);
+       } else {
+               g_autofree gchar *size = NULL;
+               size = g_format_size (gs_app_get_size_download (self->app));
+               gtk_label_set_label (GTK_LABEL (self->label_details_size_download_value), size);
+               gtk_widget_show (self->label_details_size_download_title);
+               gtk_widget_show (self->label_details_size_download_value);
        }
 
        /* set the updated date */
@@ -1695,7 +1709,10 @@ gs_shell_details_class_init (GsShellDetailsClass *klass)
        gtk_widget_class_bind_template_child (widget_class, GsShellDetails, label_details_license_value);
        gtk_widget_class_bind_template_child (widget_class, GsShellDetails, label_details_origin_title);
        gtk_widget_class_bind_template_child (widget_class, GsShellDetails, label_details_origin_value);
-       gtk_widget_class_bind_template_child (widget_class, GsShellDetails, label_details_size_value);
+       gtk_widget_class_bind_template_child (widget_class, GsShellDetails, 
label_details_size_download_title);
+       gtk_widget_class_bind_template_child (widget_class, GsShellDetails, 
label_details_size_download_value);
+       gtk_widget_class_bind_template_child (widget_class, GsShellDetails, 
label_details_size_installed_title);
+       gtk_widget_class_bind_template_child (widget_class, GsShellDetails, 
label_details_size_installed_value);
        gtk_widget_class_bind_template_child (widget_class, GsShellDetails, label_details_updated_value);
        gtk_widget_class_bind_template_child (widget_class, GsShellDetails, label_details_version_value);
        gtk_widget_class_bind_template_child (widget_class, GsShellDetails, label_failed);
diff --git a/src/gs-shell-details.ui b/src/gs-shell-details.ui
index 63080b4..aa2f9de 100644
--- a/src/gs-shell-details.ui
+++ b/src/gs-shell-details.ui
@@ -604,7 +604,7 @@
                             <property name="visible">True</property>
                             <property name="can_focus">False</property>
                             <property name="row_spacing">6</property>
-                            <property name="column_spacing">12</property>
+                            <property name="column_spacing">24</property>
                             <child>
                               <object class="GtkLabel" id="label_details_version_title">
                                 <property name="visible">True</property>
@@ -710,11 +710,12 @@
                                 <property name="top_attach">2</property>
                               </packing>
                             </child>
+
                             <child>
-                              <object class="GtkLabel" id="label_details_size_title">
+                              <object class="GtkLabel" id="label_details_size_installed_title">
                                 <property name="visible">True</property>
                                 <property name="can_focus">False</property>
-                                <property name="label" translatable="yes">Size</property>
+                                <property name="label" translatable="yes">Installed Size</property>
                                 <property name="xalign">0</property>
                                 <property name="yalign">0</property>
                                 <style>
@@ -727,7 +728,7 @@
                               </packing>
                             </child>
                             <child>
-                              <object class="GtkLabel" id="label_details_size_value">
+                              <object class="GtkLabel" id="label_details_size_installed_value">
                                 <property name="visible">True</property>
                                 <property name="can_focus">False</property>
                                 <property name="hexpand">True</property>
@@ -741,6 +742,39 @@
                                 <property name="top_attach">6</property>
                               </packing>
                             </child>
+
+                            <child>
+                              <object class="GtkLabel" id="label_details_size_download_title">
+                                <property name="visible">True</property>
+                                <property name="can_focus">False</property>
+                                <property name="label" translatable="yes">Download Size</property>
+                                <property name="xalign">0</property>
+                                <property name="yalign">0</property>
+                                <style>
+                                  <class name="dim-label"/>
+                                </style>
+                              </object>
+                              <packing>
+                                <property name="left_attach">0</property>
+                                <property name="top_attach">7</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <object class="GtkLabel" id="label_details_size_download_value">
+                                <property name="visible">True</property>
+                                <property name="can_focus">False</property>
+                                <property name="hexpand">True</property>
+                                <property name="label">30 MB</property>
+                                <property name="selectable">True</property>
+                                <property name="xalign">0</property>
+                                <property name="yalign">0</property>
+                              </object>
+                              <packing>
+                                <property name="left_attach">1</property>
+                                <property name="top_attach">7</property>
+                              </packing>
+                            </child>
+
                             <child>
                               <object class="GtkLabel" id="label_details_origin_title">
                                 <property name="visible">True</property>
@@ -1173,7 +1207,8 @@
       <widget name="label_details_category_title"/>
       <widget name="label_details_origin_title"/>
       <widget name="label_details_license_title"/>
-      <widget name="label_details_size_title"/>
+      <widget name="label_details_size_installed_title"/>
+      <widget name="label_details_size_download_title"/>
       <widget name="label_details_developer_title"/>
     </widgets>
   </object>
@@ -1184,7 +1219,8 @@
       <widget name="label_details_updated_value"/>
       <widget name="label_details_category_value"/>
       <widget name="label_details_license_value"/>
-      <widget name="label_details_size_value"/>
+      <widget name="label_details_size_installed_value"/>
+      <widget name="label_details_size_download_value"/>
       <widget name="label_details_developer_value"/>
     </widgets>
   </object>
diff --git a/src/gs-shell-extras.c b/src/gs-shell-extras.c
index 9633179..b6cace0 100644
--- a/src/gs-shell-extras.c
+++ b/src/gs-shell-extras.c
@@ -422,7 +422,6 @@ create_missing_app (SearchData *search_data)
 
        gs_app_set_kind (app, AS_APP_KIND_GENERIC);
        gs_app_set_state (app, AS_APP_STATE_UNAVAILABLE);
-       gs_app_set_size (app, GS_APP_SIZE_MISSING);
        gs_app_set_url (app, AS_URL_KIND_MISSING, search_data->url_not_found);
 
        return app;
diff --git a/src/plugins/gs-plugin-dpkg.c b/src/plugins/gs-plugin-dpkg.c
index 6bc58b3..0ea214d 100644
--- a/src/plugins/gs-plugin-dpkg.c
+++ b/src/plugins/gs-plugin-dpkg.c
@@ -99,7 +99,7 @@ gs_plugin_filename_to_app (GsPlugin *plugin,
        gs_app_add_source (app, tokens[0]);
        gs_app_set_name (app, GS_APP_QUALITY_LOWEST, tokens[0]);
        gs_app_set_version (app, tokens[1]);
-       gs_app_set_size (app, 1024 * atoi (tokens[2]));
+       gs_app_set_size_installed (app, 1024 * atoi (tokens[2]));
        gs_app_set_url (app, AS_URL_KIND_HOMEPAGE, tokens[3]);
        gs_app_set_summary (app, GS_APP_QUALITY_LOWEST, tokens[4]);
        gs_app_set_kind (app, AS_APP_KIND_GENERIC);
diff --git a/src/plugins/gs-plugin-dummy.c b/src/plugins/gs-plugin-dummy.c
index 4c8c497..914dd9f 100644
--- a/src/plugins/gs-plugin-dummy.c
+++ b/src/plugins/gs-plugin-dummy.c
@@ -180,7 +180,8 @@ gs_plugin_add_search (GsPlugin *plugin,
        gs_app_set_name (app, GS_APP_QUALITY_NORMAL, "Chiron");
        gs_app_set_summary (app, GS_APP_QUALITY_NORMAL, "A teaching application");
        gs_app_set_icon (app, ic);
-       gs_app_set_size (app, 42 * 1024 * 1024);
+       gs_app_set_size_installed (app, 42 * 1024 * 1024);
+       gs_app_set_size_download (app, 50 * 1024 * 1024);
        gs_app_set_kind (app, AS_APP_KIND_DESKTOP);
        gs_app_set_state (app, AS_APP_STATE_INSTALLED);
        gs_app_set_management_plugin (app, gs_plugin_get_name (plugin));
@@ -516,7 +517,8 @@ gs_plugin_add_distro_upgrades (GsPlugin *plugin,
        gs_app_add_quirk (app, AS_APP_QUIRK_PROVENANCE);
        gs_app_add_quirk (app, AS_APP_QUIRK_NOT_REVIEWABLE);
        gs_app_set_version (app, "25");
-       gs_app_set_size (app, 1024 * 1024 * 1024);
+       gs_app_set_size_installed (app, 256 * 1024 * 1024);
+       gs_app_set_size_download (app, 1024 * 1024 * 1024);
        gs_app_set_license (app, GS_APP_QUALITY_LOWEST, "LicenseRef-free");
        gs_app_set_origin_ui (app, "Dummy");
        gs_app_set_management_plugin (app, gs_plugin_get_name (plugin));
diff --git a/src/plugins/gs-plugin-epiphany.c b/src/plugins/gs-plugin-epiphany.c
index 6aba229..a4c77d0 100644
--- a/src/plugins/gs-plugin-epiphany.c
+++ b/src/plugins/gs-plugin-epiphany.c
@@ -280,7 +280,7 @@ gs_plugin_refine_app (GsPlugin *plugin,
                       gs_plugin_get_name (plugin)) != 0)
                return TRUE;
 
-       gs_app_set_size (app, 4096);
+       gs_app_set_size_installed (app, 4096);
 
        name = gs_app_get_name (app);
        if (name == NULL) {
diff --git a/src/plugins/gs-plugin-fedora-distro-upgrades.c b/src/plugins/gs-plugin-fedora-distro-upgrades.c
index bde6cc4..d29e519 100644
--- a/src/plugins/gs-plugin-fedora-distro-upgrades.c
+++ b/src/plugins/gs-plugin-fedora-distro-upgrades.c
@@ -372,7 +372,8 @@ gs_plugin_add_distro_upgrades (GsPlugin *plugin,
                                        "complete set of tools for developers "
                                        "and makers of all kinds.");
                gs_app_set_version (app, app_version);
-               gs_app_set_size (app, 1024 * 1024 * 1024); /* estimate */
+               gs_app_set_size_installed (app, 1024 * 1024 * 1024); /* estimate */
+               gs_app_set_size_download (app, 256 * 1024 * 1024); /* estimate */
                gs_app_set_license (app, GS_APP_QUALITY_LOWEST, "LicenseRef-free");
                gs_app_add_quirk (app, AS_APP_QUIRK_NEEDS_REBOOT);
                gs_app_add_quirk (app, AS_APP_QUIRK_PROVENANCE);
diff --git a/src/plugins/gs-plugin-fwupd.c b/src/plugins/gs-plugin-fwupd.c
index 3e0a0db..07b1235 100644
--- a/src/plugins/gs-plugin-fwupd.c
+++ b/src/plugins/gs-plugin-fwupd.c
@@ -236,7 +236,8 @@ gs_plugin_fwupd_new_app_from_results (FwupdResult *res)
                gs_app_set_version (app, fwupd_result_get_device_version (res));
        }
        if (fwupd_result_get_update_size (res) != 0) {
-               gs_app_set_size (app, fwupd_result_get_update_size (res));
+               gs_app_set_size_installed (app, 0);
+               gs_app_set_size_download (app, fwupd_result_get_update_size (res));
        }
        if (fwupd_result_get_device_created (res) != 0) {
                gs_app_set_install_date (app, fwupd_result_get_device_created (res));
diff --git a/src/plugins/gs-plugin-packagekit-refine.c b/src/plugins/gs-plugin-packagekit-refine.c
index e211d43..d1641d5 100644
--- a/src/plugins/gs-plugin-packagekit-refine.c
+++ b/src/plugins/gs-plugin-packagekit-refine.c
@@ -190,7 +190,8 @@ gs_plugin_packagekit_set_metadata_from_package (GsPlugin *plugin,
                if (data != NULL)
                        gs_app_set_origin (app, data);
                gs_app_set_state (app, AS_APP_STATE_UNAVAILABLE);
-               gs_app_set_size (app, GS_APP_SIZE_MISSING);
+               gs_app_set_size_installed (app, GS_APP_SIZE_UNKNOWABLE);
+               gs_app_set_size_download (app, GS_APP_SIZE_UNKNOWABLE);
                break;
        default:
                /* should we expect anything else? */
@@ -530,8 +531,15 @@ gs_plugin_packagekit_refine_details_app (GsPlugin *plugin,
        }
 
        /* the size is the size of all sources */
-       if (size > 0 && gs_app_get_size (app) == 0)
-               gs_app_set_size (app, size);
+       if (gs_app_get_state (app) == AS_APP_STATE_INSTALLED) {
+               gs_app_set_size_download (app, GS_APP_SIZE_UNKNOWABLE);
+               if (size > 0 && gs_app_get_size_installed (app) == 0)
+                       gs_app_set_size_installed (app, size);
+       } else {
+               gs_app_set_size_installed (app, GS_APP_SIZE_UNKNOWABLE);
+               if (size > 0 && gs_app_get_size_download (app) == 0)
+                       gs_app_set_size_download (app, size);
+       }
 }
 
 /**
@@ -669,7 +677,10 @@ gs_plugin_refine_app_needs_details (GsPlugin *plugin, GsPluginRefineFlags flags,
            gs_app_get_url (app, AS_URL_KIND_HOMEPAGE) == NULL)
                return TRUE;
        if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_SIZE) > 0 &&
-           gs_app_get_size (app) == GS_APP_SIZE_UNKNOWN)
+           gs_app_get_size_installed (app) == 0)
+               return TRUE;
+       if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_SIZE) > 0 &&
+           gs_app_get_size_download (app) == 0)
                return TRUE;
        return FALSE;
 }
diff --git a/src/plugins/gs-plugin-packagekit-refresh.c b/src/plugins/gs-plugin-packagekit-refresh.c
index feadaea..59b704f 100644
--- a/src/plugins/gs-plugin-packagekit-refresh.c
+++ b/src/plugins/gs-plugin-packagekit-refresh.c
@@ -367,7 +367,8 @@ gs_plugin_filename_to_app (GsPlugin *plugin,
        gs_plugin_packagekit_refresh_set_text (app,
                                               pk_details_get_description (item));
        gs_app_set_url (app, AS_URL_KIND_HOMEPAGE, pk_details_get_url (item));
-       gs_app_set_size (app, pk_details_get_size (item));
+       gs_app_set_size_installed (app, pk_details_get_size (item));
+       gs_app_set_size_download (app, 0);
        license_spdx = as_utils_license_to_spdx (pk_details_get_license (item));
        gs_app_set_license (app, GS_APP_QUALITY_LOWEST, license_spdx);
 
diff --git a/src/plugins/gs-plugin-rpm.c b/src/plugins/gs-plugin-rpm.c
index 2e5c5f7..b29715e 100644
--- a/src/plugins/gs-plugin-rpm.c
+++ b/src/plugins/gs-plugin-rpm.c
@@ -132,10 +132,12 @@ gs_plugin_refine_app (GsPlugin *plugin,
                }
 
                /* set size */
-               if (gs_app_get_size (app) == 0) {
+               if (gs_app_get_size_download (app) == 0)
+                       gs_app_set_size_download (app, 0);
+               if (gs_app_get_size_installed (app) == 0) {
                        guint64 tmp;
                        tmp = headerGetNumber (h, RPMTAG_SIZE);
-                       gs_app_set_size (app, tmp);
+                       gs_app_set_size_installed (app, tmp);
                }
 
                /* set license */
diff --git a/src/plugins/gs-plugin-shell-extensions.c b/src/plugins/gs-plugin-shell-extensions.c
index f1af60b..12910f6 100644
--- a/src/plugins/gs-plugin-shell-extensions.c
+++ b/src/plugins/gs-plugin-shell-extensions.c
@@ -319,8 +319,10 @@ gs_plugin_refine_app (GsPlugin *plugin,
                gs_app_set_state (app, AS_APP_STATE_AVAILABLE);
 
        /* FIXME: assume these are small */
-       if (gs_app_get_size (app) == 0)
-               gs_app_set_size (app, 1024 * 50);
+       if (gs_app_get_size_installed (app) == 0)
+               gs_app_set_size_installed (app, 1024 * 50);
+       if (gs_app_get_size_download (app) == 0)
+               gs_app_set_size_download (app, GS_APP_SIZE_UNKNOWABLE);
 
        return TRUE;
 }
diff --git a/src/plugins/gs-plugin-steam.c b/src/plugins/gs-plugin-steam.c
index 1a1e3f0..cbb95ec 100644
--- a/src/plugins/gs-plugin-steam.c
+++ b/src/plugins/gs-plugin-steam.c
@@ -838,13 +838,17 @@ gs_plugin_refine_app (GsPlugin *plugin,
        /* is this true? */
        gs_app_set_kind (app, AS_ID_KIND_DESKTOP);
 
+       /* no way of knowing */
+       if (gs_app_get_size_download (app) == 0)
+               gs_app_set_size_download (app, GS_APP_SIZE_UNKNOWABLE);
+
        /* size */
        tmp = gs_app_get_metadata_item (app, "X-Steam-Size");
        if (tmp != NULL) {
                guint64 sz;
                sz = g_ascii_strtoull (tmp, NULL, 10);
                if (sz > 0)
-                       gs_app_set_size (app, sz);
+                       gs_app_set_size_installed (app, sz);
        }
 
        /* check manifest */
@@ -869,7 +873,7 @@ gs_plugin_refine_app (GsPlugin *plugin,
                guint64 sz;
                sz = g_ascii_strtoull (tmp, NULL, 10);
                if (sz > 0)
-                       gs_app_set_size (app, sz);
+                       gs_app_set_size_installed (app, sz);
        }
 
        /* set state */
diff --git a/src/plugins/gs-plugin-xdg-app.c b/src/plugins/gs-plugin-xdg-app.c
index 43d89e9..7ca0f98 100644
--- a/src/plugins/gs-plugin-xdg-app.c
+++ b/src/plugins/gs-plugin-xdg-app.c
@@ -351,7 +351,7 @@ gs_plugin_xdg_app_set_metadata_installed (GsApp *app, XdgAppInstalledRef *xref)
        /* this is faster than xdg_app_installation_fetch_remote_size_sync() */
        size_installed = xdg_app_installed_ref_get_installed_size (xref);
        if (size_installed != 0)
-               gs_app_set_size (app, size_installed);
+               gs_app_set_size_installed (app, size_installed);
 }
 
 /**
@@ -1029,12 +1029,12 @@ gs_plugin_refine_item_size (GsPlugin *plugin,
        gboolean ret;
        guint64 download_size;
        guint64 installed_size;
-       guint64 size = 0;
-       g_auto(GStrv) split = NULL;
        g_autoptr(AsProfileTask) ptask = NULL;
        g_autoptr(GError) error_local = NULL;
 
-       if (gs_app_get_size (app) > 0)
+       /* already set */
+       if (gs_app_get_size_installed (app) > 0 &&
+           gs_app_get_size_download (app) > 0)
                return TRUE;
 
        /* need commit */
@@ -1073,9 +1073,6 @@ gs_plugin_refine_item_size (GsPlugin *plugin,
                                                         cancellable,
                                                         error))
                                return FALSE;
-                       g_debug ("runtime %s is not installed, so adding download",
-                                gs_app_get_id (app_runtime));
-                       size += gs_app_get_size (app_runtime);
                }
        }
 
@@ -1091,16 +1088,12 @@ gs_plugin_refine_item_size (GsPlugin *plugin,
        if (!ret) {
                g_warning ("libxdgapp failed to return application size: %s",
                           error_local->message);
+               gs_app_set_size_installed (app, GS_APP_SIZE_UNKNOWABLE);
+               gs_app_set_size_download (app, GS_APP_SIZE_UNKNOWABLE);
        } else {
-               if (gs_app_get_state (app) == AS_APP_STATE_INSTALLED) {
-                       size += installed_size;
-               } else {
-                       size += download_size;
-               }
+               gs_app_set_size_installed (app, installed_size);
+               gs_app_set_size_download (app, download_size);
        }
-       if (size == 0)
-               size = GS_APP_SIZE_MISSING;
-       gs_app_set_size (app, size);
        return TRUE;
 }
 
@@ -1413,7 +1406,7 @@ gs_plugin_filename_to_app (GsPlugin *plugin,
        app = gs_app_new (id_prefixed);
        gs_app_set_kind (app, AS_APP_KIND_DESKTOP);
        gs_app_set_state (app, AS_APP_STATE_AVAILABLE_LOCAL);
-       gs_app_set_size (app, xdg_app_bundle_ref_get_installed_size (xref_bundle));
+       gs_app_set_size_installed (app, xdg_app_bundle_ref_get_installed_size (xref_bundle));
        gs_plugin_xdg_app_set_metadata (app, XDG_APP_REF (xref_bundle));
        metadata = xdg_app_bundle_ref_get_metadata (xref_bundle);
        if (!gs_plugin_xdg_app_set_app_metadata (app,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]