[gnome-control-center/hostnamed-device-model-vendor] info-overview: Present Hardware "vendor" and "model" fields




commit 6e414fb6ebea83293a5cd30b797941464339cde3
Author: Felipe Borges <felipeborges gnome org>
Date:   Thu Nov 26 19:04:22 2020 +0100

    info-overview: Present Hardware "vendor" and "model" fields
    
    These fields can help users identify their hardware vendor and model,
    helping hardware vendors debug device specific problems.
    
    This information is provided by systemd-hostnamed, which sources
    this information from hwdb, and fallbacks to the DMI device. See
    https://github.com/systemd/systemd/pull/15531
    
    See https://teams.fedoraproject.org/project/silverblue/us/127

 panels/info-overview/cc-info-overview-panel.c  | 59 ++++++++++++++++++++++++++
 panels/info-overview/cc-info-overview-panel.ui | 18 ++++++++
 2 files changed, 77 insertions(+)
---
diff --git a/panels/info-overview/cc-info-overview-panel.c b/panels/info-overview/cc-info-overview-panel.c
index fe7a23c2c..0ebd5843b 100644
--- a/panels/info-overview/cc-info-overview-panel.c
+++ b/panels/info-overview/cc-info-overview-panel.c
@@ -66,6 +66,8 @@ struct _CcInfoOverviewPanel
   GtkDialog       *hostname_editor;
   CcHostnameEntry *hostname_entry;
   CcListRow       *hostname_row;
+  CcListRow       *hardware_vendor_row;
+  CcListRow       *hardware_model_row;
   CcListRow       *memory_row;
   GtkListBox      *os_box;
   CcListRow       *os_name_row;
@@ -520,6 +522,59 @@ get_primary_disc_info (CcInfoOverviewPanel *self)
     }
 }
 
+static void
+get_hardware_vendor_and_model (CcInfoOverviewPanel *self)
+{
+  g_autoptr(GDBusProxy) hostnamed_proxy = NULL;
+  g_autoptr(GVariant) vendor_variant = NULL;
+  g_autoptr(GVariant) model_variant = NULL;
+  const char *vendor_string, *model_string;
+  g_autoptr(GError) error = NULL;
+
+  hostnamed_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
+                                                   G_DBUS_PROXY_FLAGS_NONE,
+                                                   NULL,
+                                                   "org.freedesktop.hostname1",
+                                                   "/org/freedesktop/hostname1",
+                                                   "org.freedesktop.hostname1",
+                                                   NULL,
+                                                   &error);
+  if (hostnamed_proxy == NULL)
+    {
+      g_debug ("Couldn't get hostnamed to start, bailing: %s", error->message);
+      return;
+    }
+
+  vendor_variant = g_dbus_proxy_get_cached_property (hostnamed_proxy, "HardwareVendor");
+  if (!vendor_variant)
+    {
+      g_debug ("Unable to retrieve org.freedesktop.hostname1.HardwareVendor property");
+      return;
+    }
+
+  model_variant = g_dbus_proxy_get_cached_property (hostnamed_proxy, "HardwareModel");
+  if (!model_variant)
+    {
+      g_debug ("Unable to retrieve org.freedesktop.hostname1.HardwareVendor property");
+      return;
+    }
+
+  vendor_string = g_variant_get_string (vendor_variant, NULL);
+  model_string = g_variant_get_string (model_variant, NULL);
+
+  if (vendor_string && g_strcmp0 (vendor_string, "") != 0)
+    {
+      cc_list_row_set_secondary_label (self->hardware_vendor_row, vendor_string);
+      gtk_widget_set_visible (GTK_WIDGET (self->hardware_vendor_row), TRUE);
+    }
+
+  if (model_string && g_strcmp0 (model_string, "") != 0)
+    {
+      cc_list_row_set_secondary_label (self->hardware_model_row, model_string);
+      gtk_widget_set_visible (GTK_WIDGET (self->hardware_model_row), TRUE);
+    }
+}
+
 static char *
 get_cpu_info (const glibtop_sysinfo *info)
 {
@@ -698,6 +753,8 @@ info_overview_panel_setup_overview (CcInfoOverviewPanel *self)
 
   cc_list_row_set_secondary_label (self->windowing_system_row, get_windowing_system ());
 
+  get_hardware_vendor_and_model (self);
+
   glibtop_get_mem (&mem);
   memory_text = g_format_size_full (mem.total, G_FORMAT_SIZE_IEC_UNITS);
   cc_list_row_set_secondary_label (self->memory_row, memory_text);
@@ -826,6 +883,8 @@ cc_info_overview_panel_class_init (CcInfoOverviewPanelClass *klass)
   gtk_widget_class_bind_template_child (widget_class, CcInfoOverviewPanel, hostname_editor);
   gtk_widget_class_bind_template_child (widget_class, CcInfoOverviewPanel, hostname_entry);
   gtk_widget_class_bind_template_child (widget_class, CcInfoOverviewPanel, hostname_row);
+  gtk_widget_class_bind_template_child (widget_class, CcInfoOverviewPanel, hardware_vendor_row);
+  gtk_widget_class_bind_template_child (widget_class, CcInfoOverviewPanel, hardware_model_row);
   gtk_widget_class_bind_template_child (widget_class, CcInfoOverviewPanel, memory_row);
   gtk_widget_class_bind_template_child (widget_class, CcInfoOverviewPanel, os_box);
   gtk_widget_class_bind_template_child (widget_class, CcInfoOverviewPanel, os_name_row);
diff --git a/panels/info-overview/cc-info-overview-panel.ui b/panels/info-overview/cc-info-overview-panel.ui
index 98cb85df3..5080d3b83 100644
--- a/panels/info-overview/cc-info-overview-panel.ui
+++ b/panels/info-overview/cc-info-overview-panel.ui
@@ -66,6 +66,24 @@
                       <class name="frame" />
                     </style>
 
+                    <!-- Hardware Vendor -->
+                    <child>
+                      <object class="CcListRow" id="hardware_vendor_row">
+                        <property name="visible">False</property>
+                        <property name="activatable">False</property>
+                        <property name="title" translatable="yes">Hardware vendor</property>
+                      </object>
+                    </child>
+
+                    <!-- Hardware Model -->
+                    <child>
+                      <object class="CcListRow" id="hardware_model_row">
+                        <property name="visible">False</property>
+                        <property name="activatable">False</property>
+                        <property name="title" translatable="yes">Hardware model</property>
+                      </object>
+                    </child>
+
                     <!-- Memory -->
                     <child>
                       <object class="CcListRow" id="memory_row">


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