[gnome-control-center/wip/hadess/version-xml: 14/15] info-overview: Load GNOME version from gnome-shell




commit 97c1dced585abdaca480ff466f84d718321b365f
Author: Bastien Nocera <hadess hadess net>
Date:   Wed May 4 09:54:34 2022 +0200

    info-overview: Load GNOME version from gnome-shell
    
    See https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/5406

 panels/info-overview/cc-info-overview-panel.c | 62 ++++++++++++++++++++++++++-
 1 file changed, 60 insertions(+), 2 deletions(-)
---
diff --git a/panels/info-overview/cc-info-overview-panel.c b/panels/info-overview/cc-info-overview-panel.c
index d2fc3cf0f..4247c4cf3 100644
--- a/panels/info-overview/cc-info-overview-panel.c
+++ b/panels/info-overview/cc-info-overview-panel.c
@@ -23,6 +23,7 @@
 #include <config.h>
 
 #include "cc-hostname-entry.h"
+#include "shell/cc-object-storage.h"
 
 #include "cc-info-overview-resources.h"
 #include "info-cleanup.h"
@@ -745,6 +746,56 @@ get_ram_size_dmi (void)
   return ram_total;
 }
 
+static char *
+get_gnome_version (GDBusProxy *proxy)
+{
+  g_autoptr(GVariant) variant = NULL;
+  const char *gnome_version = NULL;
+  if (!proxy)
+    return NULL;
+
+  variant = g_dbus_proxy_get_cached_property (proxy, "ShellVersion");
+  if (!variant)
+    return NULL;
+
+  gnome_version = g_variant_get_string (variant, NULL);
+  if (!gnome_version || *gnome_version == '\0')
+    return NULL;
+  return g_strdup (gnome_version);
+}
+
+static void
+shell_proxy_ready (GObject             *source,
+                   GAsyncResult        *res,
+                   CcInfoOverviewPanel *self)
+{
+  g_autoptr(GDBusProxy) proxy = NULL;
+  g_autoptr(GError) error = NULL;
+  g_autoptr(GVariant) variant = NULL;
+  g_autofree char *gnome_version = NULL;
+
+  proxy = cc_object_storage_create_dbus_proxy_finish (res, &error);
+  if (!proxy)
+    {
+      if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+        return;
+      g_warning ("Failed to contact gnome-shell: %s", error->message);
+    }
+
+  gnome_version = get_gnome_version (proxy);
+
+  if (!gnome_version)
+    {
+      /* translators: this is the placeholder string when the GNOME Shell
+       * version couldn't be loaded, eg. “GNOME Version: Not Available” */
+      cc_list_row_set_secondary_label (self->gnome_version_row, _("Not Available"));
+    }
+  else
+    {
+      cc_list_row_set_secondary_label (self->gnome_version_row, gnome_version);
+    }
+}
+
 static void
 info_overview_panel_setup_overview (CcInfoOverviewPanel *self)
 {
@@ -757,8 +808,15 @@ info_overview_panel_setup_overview (CcInfoOverviewPanel *self)
   g_autofree char *os_name_text = NULL;
   g_autofree gchar *graphics_hardware_string = NULL;
 
-  if (load_gnome_version (&gnome_version))
-    cc_list_row_set_secondary_label (self->gnome_version_row, gnome_version);
+  cc_object_storage_create_dbus_proxy (G_BUS_TYPE_SESSION,
+                                       G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS |
+                                       G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
+                                       "org.gnome.Shell",
+                                       "/org/gnome/Shell",
+                                       "org.gnome.Shell",
+                                       cc_panel_get_cancellable (CC_PANEL (self)),
+                                       (GAsyncReadyCallback) shell_proxy_ready,
+                                       self);
 
   cc_list_row_set_secondary_label (self->windowing_system_row, get_windowing_system ());
 


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