[gnome-control-center/wip/applications] application: Drop libflatpak dependency



commit 20134c68d573c90aba388397d316132b076fe2da
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed Jan 2 12:39:15 2019 -0500

    application: Drop libflatpak dependency
    
    We can get by for now with some screenscraping,
    turning the flatpak dependency into a runtime thing.

 panels/applications/cc-applications-panel.c | 19 +-----
 panels/applications/meson.build             |  4 +-
 panels/applications/utils.c                 | 91 ++++++++++++++++++++---------
 panels/applications/utils.h                 |  3 +-
 4 files changed, 69 insertions(+), 48 deletions(-)
---
diff --git a/panels/applications/cc-applications-panel.c b/panels/applications/cc-applications-panel.c
index 896a6bc2b..f6be91734 100644
--- a/panels/applications/cc-applications-panel.c
+++ b/panels/applications/cc-applications-panel.c
@@ -36,8 +36,6 @@
 #include "search.h"
 #include "utils.h"
 
-#include <flatpak/flatpak.h>
-
 enum {
   PROP_0,
   PROP_PARAMETERS
@@ -521,26 +519,15 @@ add_static_permissions (CcApplicationsPanel *self,
                         GAppInfo            *info,
                         const gchar         *app_id)
 {
-  g_autoptr(FlatpakInstalledRef) ref = NULL;
-  g_autoptr(GBytes) bytes = NULL;
-  g_autoptr(GError) error = NULL;
   g_autoptr(GKeyFile) keyfile = NULL;
   gchar **strv;
   gchar *str;
   gint added = 0;
   g_autofree gchar *text = NULL;
   
-  ref = find_flatpak_ref (app_id);
-  bytes = flatpak_installed_ref_load_metadata (ref, NULL, NULL);
-  keyfile = g_key_file_new ();
-  if (!g_key_file_load_from_data (keyfile,
-                                  g_bytes_get_data (bytes, NULL),
-                                  g_bytes_get_size (bytes),
-                                  0, &error))
-    {
-      g_warning ("%s", error->message);
-      return FALSE;
-    }
+  keyfile = get_flatpak_metadata (app_id);
+  if (keyfile == NULL)
+    return FALSE;
 
   strv = g_key_file_get_string_list (keyfile, "Context", "sockets", NULL, NULL);
   if (strv && g_strv_contains ((const gchar * const*)strv, "system-bus"))
diff --git a/panels/applications/meson.build b/panels/applications/meson.build
index 75b9157c4..49796a322 100644
--- a/panels/applications/meson.build
+++ b/panels/applications/meson.build
@@ -38,14 +38,12 @@ sources += gnome.compile_resources(
         export : true
 )
 
-deps = common_deps + [ dependency('flatpak', version: '>= 1.0.0') ]
-
 cflags += '-DGNOMELOCALEDIR="@0@"'.format(control_center_localedir)
 
 panels_libs += static_library(
            cappletname,
               sources : sources,
   include_directories : [ top_inc, common_inc ],
-         dependencies : deps,
+         dependencies : common_deps,
                c_args : cflags
 )
diff --git a/panels/applications/utils.c b/panels/applications/utils.c
index f21e02e1d..1f025b6c5 100644
--- a/panels/applications/utils.c
+++ b/panels/applications/utils.c
@@ -24,7 +24,6 @@
 
 #include <config.h>
 #include <glib/gi18n.h>
-#include <flatpak/flatpak.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 
@@ -120,41 +119,79 @@ container_remove_all (GtkContainer *container)
   g_list_free (children);
 }
 
-FlatpakInstalledRef *
-find_flatpak_ref (const gchar *app_id)
+static char *
+get_output_of (const char **argv)
 {
-  g_autoptr(FlatpakInstallation) inst = NULL;
-  g_autoptr(GPtrArray) array = NULL;
-  FlatpakInstalledRef *ref;
-  gint i;
-
-  inst = flatpak_installation_new_user (NULL, NULL);
-  ref = flatpak_installation_get_current_installed_app (inst, app_id, NULL, NULL);
-  if (ref)
-    return ref;
-
-  array = flatpak_get_system_installations (NULL, NULL);
-  for (i = 0; i < array->len; i++)
+  g_autofree char *output = NULL;
+  int status;
+
+  if (!g_spawn_sync (NULL, (char **)argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, &output, NULL, &status, 
NULL))
+    return NULL;
+
+  if (!g_spawn_check_exit_status (status, NULL))
+    return NULL;
+
+  return g_steal_pointer (&output);
+}
+
+GKeyFile *
+get_flatpak_metadata (const gchar *app_id)
+{
+  const char *argv[5] = { "flatpak", "info", "-m", "app", NULL };
+  g_autofree char *data = NULL;
+  g_autoptr(GError) error = NULL;
+  g_autoptr(GKeyFile) keyfile = NULL;
+
+  argv[3] = app_id;
+
+  data = get_output_of (argv);
+  if (data == NULL)
+    return NULL;
+
+  keyfile = g_key_file_new ();
+  if (!g_key_file_load_from_data (keyfile, data, -1, 0, &error))
     {
-      FlatpakInstallation *si = g_ptr_array_index (array, i);
-      ref = flatpak_installation_get_current_installed_app (si, app_id, NULL, NULL);
-      if (ref)
-        return ref;
+      g_warning ("%s", error->message);
+      return NULL;
     }
 
-  return NULL;
+  return g_steal_pointer (&keyfile);
 }
 
 guint64
 get_flatpak_app_size (const gchar *app_id)
 {
-  g_autoptr(FlatpakInstalledRef) ref = NULL;
-
-  ref = find_flatpak_ref (app_id);
-  if (ref)
-    return flatpak_installed_ref_get_installed_size (ref);
-
-  return 0;
+  const char *argv[5] = { "flatpak", "info", "-s", "app", NULL };
+  g_autofree char *data = NULL;
+  guint64 factor;
+  double val;
+
+  argv[3] = app_id;
+
+  data = get_output_of (argv);
+  if (data == NULL)
+    return 0;
+
+  data = g_strstrip (data);
+  
+  if (g_str_has_suffix (data, "kB") || g_str_has_suffix (data, "kb"))
+    factor = 1000;
+  else if (g_str_has_suffix (data, "MB") || g_str_has_suffix (data, "Mb"))
+    factor = 1000 * 1000;
+  else if (g_str_has_suffix (data, "GB") || g_str_has_suffix (data, "Gb"))
+    factor = 1000 * 1000 * 1000;
+  else if (g_str_has_suffix (data, "KiB") || g_str_has_suffix (data, "Kib"))
+    factor = 1024;
+  else if (g_str_has_suffix (data, "MiB") || g_str_has_suffix (data, "Mib"))
+    factor = 1024 * 1024;
+  else if (g_str_has_suffix (data, "GiB") || g_str_has_suffix (data, "Gib"))
+    factor = 1024 * 1024 * 1024;
+  else 
+    factor = 1;
+
+  val = g_ascii_strtod (data, NULL);
+
+  return (guint64)(val * factor);
 }
 
 char *
diff --git a/panels/applications/utils.h b/panels/applications/utils.h
index ad58dd188..c1a4833a1 100644
--- a/panels/applications/utils.h
+++ b/panels/applications/utils.h
@@ -22,7 +22,6 @@
 
 #include <gio/gio.h>
 #include <gtk/gtk.h>
-#include <flatpak/flatpak.h>
 
 G_BEGIN_DECLS
 
@@ -36,7 +35,7 @@ void                 file_size_async      (GFile               *file,
 
 void                 container_remove_all (GtkContainer        *container);
 
-FlatpakInstalledRef* find_flatpak_ref     (const gchar         *app_id);
+GKeyFile             *get_flatpak_metadata (const gchar         *app_id);
 
 guint64              get_flatpak_app_size (const gchar         *app_id);
 


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