[gnome-control-center] applications: Show snap app sizes



commit aa471faa4ae0aed1bdfe979e760f6426d3df445f
Author: Robert Ancell <robert ancell canonical com>
Date:   Tue Mar 12 16:59:56 2019 +1300

    applications: Show snap app sizes

 meson.build                                 | 11 +++++++++++
 meson_options.txt                           |  1 +
 panels/applications/cc-applications-panel.c | 10 ++++++----
 panels/applications/meson.build             |  8 +++++++-
 panels/applications/utils.c                 | 25 +++++++++++++++++++++++++
 panels/applications/utils.h                 |  2 ++
 6 files changed, 52 insertions(+), 5 deletions(-)
---
diff --git a/meson.build b/meson.build
index 87662a472..e52b5ea1f 100644
--- a/meson.build
+++ b/meson.build
@@ -195,6 +195,16 @@ config_h.set10('HAVE_FN_EXPLICIT_BZERO',
                cc.has_function('explicit_bzero', prefix: '''#include <string.h>'''),
                description: 'Define if explicit_bzero is available')
 
+# Snap support
+enable_snap = get_option('snap')
+if enable_snap
+  snapd_glib_deps = [
+    dependency('snapd-glib', version: '>= 1.49')
+  ]
+endif
+config_h.set('HAVE_SNAP', enable_snap,
+             description: 'Define to 1 if Snap support is enabled')
+
 if host_is_linux
   # network manager
   network_manager_deps = [
@@ -286,5 +296,6 @@ output += '     Cheese (Users panel webcam support) ........ ' + enable_cheese.t
 output += '     IBus (Region panel IBus support) ........... ' + enable_ibus.to_string() + '\n'
 output += '     NetworkManager (Network panel) ............. ' + host_is_linux.to_string() + '\n'
 output += '     Wacom (Wacom tablet panel) ................. ' + host_is_linux_not_s390.to_string() + '\n'
+output += '     Snap support ............................... ' + enable_snap.to_string() + '\n'
 
 message(output)
diff --git a/meson_options.txt b/meson_options.txt
index b7a7c055c..e76308e8a 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -2,6 +2,7 @@ option('cheese', type: 'boolean', value: true, description: 'build with cheese w
 option('documentation', type: 'boolean', value: false, description: 'build documentation')
 option('ibus', type: 'boolean', value: true, description: 'build with IBus support')
 option('privileged_group', type: 'string', value: 'wheel', description: 'name of group that has elevated 
permissions')
+option('snap', type: 'boolean', value: false, description: 'build with Snap support')
 option('tests', type: 'boolean', value: true, description: 'build tests')
 option('tracing', type: 'boolean', value: false, description: 'add extra debugging information')
 option('wayland', type: 'boolean', value: true, description: 'build with Wayland support')
diff --git a/panels/applications/cc-applications-panel.c b/panels/applications/cc-applications-panel.c
index a05102fca..8759afd42 100644
--- a/panels/applications/cc-applications-panel.c
+++ b/panels/applications/cc-applications-panel.c
@@ -1367,7 +1367,9 @@ update_app_row (CcApplicationsPanel *self,
 {
   g_autofree gchar *formatted_size = NULL;
 
-  if (!g_str_has_prefix (app_id, PORTAL_SNAP_PREFIX))
+  if (g_str_has_prefix (app_id, PORTAL_SNAP_PREFIX))
+    self->app_size = get_snap_app_size (app_id + strlen (PORTAL_SNAP_PREFIX));
+  else
     self->app_size = get_flatpak_app_size (app_id);
   formatted_size = g_format_size (self->app_size);
   g_object_set (self->app, "info", formatted_size, NULL);
@@ -1375,8 +1377,8 @@ update_app_row (CcApplicationsPanel *self,
 }
 
 static void
-update_flatpak_sizes (CcApplicationsPanel *self,
-                      const gchar         *app_id)
+update_app_sizes (CcApplicationsPanel *self,
+                  const gchar         *app_id)
 {
   gtk_widget_set_sensitive (self->clear_cache_button, FALSE);
 
@@ -1396,7 +1398,7 @@ update_usage_section (CcApplicationsPanel *self,
   if (portal_app_id != NULL)
     {
       gtk_widget_show (self->usage_section);
-      update_flatpak_sizes (self, portal_app_id);
+      update_app_sizes (self, portal_app_id);
     }
   else
     {
diff --git a/panels/applications/meson.build b/panels/applications/meson.build
index f0b1041c3..ce3b41a77 100644
--- a/panels/applications/meson.build
+++ b/panels/applications/meson.build
@@ -38,10 +38,16 @@ sources += gnome.compile_resources(
         export : true
 )
 
+deps = common_deps
+
+if enable_snap
+  deps += snapd_glib_deps
+endif
+
 panels_libs += static_library(
            cappletname,
               sources : sources,
   include_directories : [ top_inc, common_inc ],
-         dependencies : common_deps,
+         dependencies : deps,
                c_args : cflags
 )
diff --git a/panels/applications/utils.c b/panels/applications/utils.c
index bf9860bea..96704a4c0 100644
--- a/panels/applications/utils.c
+++ b/panels/applications/utils.c
@@ -24,6 +24,9 @@
 
 #include <config.h>
 #include <glib/gi18n.h>
+#ifdef HAVE_SNAP
+#include <snapd-glib/snapd-glib.h>
+#endif
 #include <sys/types.h>
 #include <sys/stat.h>
 
@@ -231,6 +234,28 @@ get_flatpak_app_size (const gchar *app_id)
   return (guint64)(val * factor);
 }
 
+guint64
+get_snap_app_size (const gchar *snap_name)
+{
+#ifdef HAVE_SNAP
+  g_autoptr(SnapdClient) client = NULL;
+  g_autoptr(SnapdSnap) snap = NULL;
+  g_autoptr(GError) error = NULL;
+
+  client = snapd_client_new ();
+  snap = snapd_client_get_snap_sync (client, snap_name, NULL, &error);
+  if (snap == NULL)
+    {
+      g_warning ("Failed to get snap size: %s", error->message);
+      return 0;
+    }
+
+  return snapd_snap_get_installed_size (snap);
+#else
+  return 0;
+#endif
+}
+
 char *
 get_app_id (GAppInfo *info)
 {
diff --git a/panels/applications/utils.h b/panels/applications/utils.h
index a2e39229a..5f899d781 100644
--- a/panels/applications/utils.h
+++ b/panels/applications/utils.h
@@ -50,6 +50,8 @@ GKeyFile* get_flatpak_metadata (const gchar         *app_id);
 
 guint64   get_flatpak_app_size (const gchar         *app_id);
 
+guint64   get_snap_app_size    (const gchar         *snap_name);
+
 gchar*    get_app_id           (GAppInfo            *info);
 
 G_END_DECLS


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