[gnome-control-center/wip/new-design: 4/7] Status icon and label OK




commit 11aaafdfa5fed3c95484c8073ca569c6aa783d73
Author: Kate Hsuan <hpa redhat com>
Date:   Mon Aug 1 13:13:16 2022 +0800

    Status icon and label OK

 .../cc-firmware-security-dialog.c                  | 49 +++++++++++++++--
 .../firmware-security/cc-firmware-security-panel.c |  8 +--
 .../firmware-security/cc-firmware-security-utils.c | 63 ++++++++++++++++++++++
 .../firmware-security/cc-firmware-security-utils.h |  9 ++--
 4 files changed, 118 insertions(+), 11 deletions(-)
---
diff --git a/panels/firmware-security/cc-firmware-security-dialog.c 
b/panels/firmware-security/cc-firmware-security-dialog.c
index 726427f80..2e923a8af 100644
--- a/panels/firmware-security/cc-firmware-security-dialog.c
+++ b/panels/firmware-security/cc-firmware-security-dialog.c
@@ -259,10 +259,51 @@ hsi_create_pg_row (const gchar *icon_name,
                    FwupdSecurityAttr *attr)
 {
   GtkWidget *row;
+  GtkWidget *subrow;
+  GtkWidget *status_icon;
+  GtkWidget *status_label;
+  GtkWidget *title;
+  GtkWidget *box;
+
+
+  printf("result->%d %s\n", attr->result, fwupd_security_attr_result_to_string(attr->result));
 
   row = adw_expander_row_new ();
-  adw_expander_row_set_icon_name (ADW_EXPANDER_ROW (row), icon_name);
+  box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
+  //adw_expander_row_set_icon_name (ADW_EXPANDER_ROW (row), icon_name);
   adw_preferences_row_set_title (ADW_PREFERENCES_ROW (row), attr->title);
+  //adw_preferences_row_set_title (ADW_PREFERENCES_ROW (row), "Test");
+  title = gtk_label_new (attr->title);
+  status_label = gtk_label_new (fwupd_security_attr_result_to_string(attr->result));
+
+  if (fwupd_get_result_status (attr->result))
+    {
+      status_icon = gtk_image_new_from_icon_name ("emblem-ok");
+    }
+  else
+    {
+      status_icon = gtk_image_new_from_icon_name ("process-stop");
+    }
+  
+  //gtk_box_append (GTK_BOX (box), status_icon);
+  //gtk_box_append (GTK_BOX (box), status_label);
+
+  //adw_expander_row_add_prefix (ADW_EXPANDER_ROW (row), title);
+  //adw_expander_row_add_prefix (ADW_EXPANDER_ROW (row), box);
+  adw_expander_row_add_action (ADW_EXPANDER_ROW (row), status_label);
+  adw_expander_row_add_action (ADW_EXPANDER_ROW (row), status_icon);
+  
+
+
+  //gtk_widget_set_halign (status_label, GTK_ALIGN_END);
+  //gtk_widget_set_hexpand (status_label, true);
+
+  //gtk_widget_set_halign (status_icon, GTK_ALIGN_END);
+  //gtk_widget_set_hexpand (status_icon, true);
+
+  gtk_widget_add_css_class (status_icon, "icon");
+  gtk_widget_add_css_class (status_label, "hsi_label");
+  //gtk_list_box_row_set_child (GTK_LIST_BOX_ROW (row), status_icon);
 
   if (attr->description != NULL)
     {
@@ -317,13 +358,15 @@ update_hsi_listbox (CcFirmwareSecurityDialog *self,
         continue;
       if (firmware_security_attr_has_flag (attr, FWUPD_SECURITY_ATTR_FLAG_SUCCESS))
         {
-          pg_row = hsi_create_pg_row ("emblem-default-symbolic", "color_green", attr);
+          pg_row = hsi_create_pg_row ("emblem-ok", "color_green", attr);
           gtk_widget_add_css_class (pg_row, "success-icon");
+          gtk_widget_add_css_class (pg_row, "success-title");
         }
       else
         {
-          pg_row = hsi_create_pg_row ("dialog-error-symbolic", "color_dim", attr);
+          pg_row = hsi_create_pg_row ("process-stop", "color_dim", attr);
           gtk_widget_add_css_class (pg_row, "error-icon");
+          gtk_widget_add_css_class (pg_row, "error-title");
         }
       adw_preferences_group_add (ADW_PREFERENCES_GROUP (hsi_pg), GTK_WIDGET (pg_row));
     }
diff --git a/panels/firmware-security/cc-firmware-security-panel.c 
b/panels/firmware-security/cc-firmware-security-panel.c
index 69b5cb313..b046b8d98 100644
--- a/panels/firmware-security/cc-firmware-security-panel.c
+++ b/panels/firmware-security/cc-firmware-security-panel.c
@@ -180,13 +180,13 @@ parse_event_variant_iter (CcfirmwareSecurityPanel *self,
   row = adw_expander_row_new ();
   if (attr->flags & FWUPD_SECURITY_ATTR_FLAG_SUCCESS)
     {
-      adw_expander_row_set_icon_name (ADW_EXPANDER_ROW (row), "emblem-default-symbolic");
+      adw_expander_row_set_icon_name (ADW_EXPANDER_ROW (row), "emblem-ok");
       gtk_widget_add_css_class (row, "success-icon");
     }
   else
     {
-      adw_expander_row_set_icon_name (ADW_EXPANDER_ROW (row), "dialog-warning-symbolic");
-      gtk_widget_add_css_class (row, "warning-icon");
+      adw_expander_row_set_icon_name (ADW_EXPANDER_ROW (row), "process-stop");
+      gtk_widget_add_css_class (row, "error-icon");
     }
 
   if (attr->description != NULL)
@@ -665,7 +665,7 @@ cc_firmware_security_panel_init (CcfirmwareSecurityPanel *self)
 
   self->hsi1_dict = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) 
fu_security_attr_free);
   self->hsi2_dict = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) 
fu_security_attr_free);
-s  self->hsi3_dict = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) 
fu_security_attr_free);
+  self->hsi3_dict = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) 
fu_security_attr_free);
   self->hsi4_dict = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) 
fu_security_attr_free);
 
   load_custom_css ("/org/gnome/control-center/firmware-security/security-level.css");
diff --git a/panels/firmware-security/cc-firmware-security-utils.c 
b/panels/firmware-security/cc-firmware-security-utils.c
index 4b65b9e92..a17acddfd 100644
--- a/panels/firmware-security/cc-firmware-security-utils.c
+++ b/panels/firmware-security/cc-firmware-security-utils.c
@@ -228,6 +228,67 @@ fu_security_attr_get_title_fallback (const gchar *appstream_id)
   return NULL;
 }
 
+const gchar *
+fwupd_security_attr_result_to_string(FwupdSecurityAttrResult result)
+{
+       if (result == FWUPD_SECURITY_ATTR_RESULT_VALID)
+               return _("Valid");
+       if (result == FWUPD_SECURITY_ATTR_RESULT_NOT_VALID)
+               return _("Not valid");
+       if (result == FWUPD_SECURITY_ATTR_RESULT_ENABLED)
+               return _("Enabled");
+       if (result == FWUPD_SECURITY_ATTR_RESULT_NOT_ENABLED)
+               return _("Not enabled");
+       if (result == FWUPD_SECURITY_ATTR_RESULT_LOCKED)
+               return _("Locked");
+       if (result == FWUPD_SECURITY_ATTR_RESULT_NOT_LOCKED)
+               return _("Not locked");
+       if (result == FWUPD_SECURITY_ATTR_RESULT_ENCRYPTED)
+               return _("Encrypted");
+       if (result == FWUPD_SECURITY_ATTR_RESULT_NOT_ENCRYPTED)
+               return _("Not encrypted");
+       if (result == FWUPD_SECURITY_ATTR_RESULT_TAINTED)
+               return _("Tainted");
+       if (result == FWUPD_SECURITY_ATTR_RESULT_NOT_TAINTED)
+               return _("Not tainted");
+       if (result == FWUPD_SECURITY_ATTR_RESULT_FOUND)
+               return _("Found");
+       if (result == FWUPD_SECURITY_ATTR_RESULT_NOT_FOUND)
+               return _("Not found");
+       if (result == FWUPD_SECURITY_ATTR_RESULT_SUPPORTED)
+               return _("Supported");
+       if (result == FWUPD_SECURITY_ATTR_RESULT_NOT_SUPPORTED)
+               return _("Not supported");
+       return NULL;
+}
+
+gboolean
+fwupd_get_result_status (FwupdSecurityAttrResult result)
+{
+  switch (result)
+    {
+      case FWUPD_SECURITY_ATTR_RESULT_ENABLED:
+      case FWUPD_SECURITY_ATTR_RESULT_VALID:
+      case FWUPD_SECURITY_ATTR_RESULT_LOCKED:
+      case FWUPD_SECURITY_ATTR_RESULT_ENCRYPTED:
+      case FWUPD_SECURITY_ATTR_RESULT_NOT_TAINTED:
+      case FWUPD_SECURITY_ATTR_RESULT_FOUND:
+      case FWUPD_SECURITY_ATTR_RESULT_SUPPORTED:
+        return true;
+      case FWUPD_SECURITY_ATTR_RESULT_UNKNOWN:
+      case FWUPD_SECURITY_ATTR_RESULT_NOT_ENABLED:
+      case FWUPD_SECURITY_ATTR_RESULT_NOT_VALID:
+      case FWUPD_SECURITY_ATTR_RESULT_NOT_LOCKED:
+      case FWUPD_SECURITY_ATTR_RESULT_NOT_ENCRYPTED:
+      case FWUPD_SECURITY_ATTR_RESULT_TAINTED:
+      case FWUPD_SECURITY_ATTR_RESULT_NOT_FOUND:
+      case FWUPD_SECURITY_ATTR_RESULT_NOT_SUPPORTED:
+        return false;
+      default:
+        return false;
+    }
+}
+
 /* ->summary and ->description are translated */
 FwupdSecurityAttr *
 fu_security_attr_new_from_variant (GVariantIter *iter)
@@ -244,6 +305,8 @@ fu_security_attr_new_from_variant (GVariantIter *iter)
         attr->flags = g_variant_get_uint64(value);
       else if (g_strcmp0 (key, "HsiLevel") == 0)
         attr->hsi_level = g_variant_get_uint32 (value);
+      else if (g_strcmp0 (key, "HsiResult") == 0)
+        attr->result = g_variant_get_uint32 (value);
       else if (g_strcmp0 (key, "Created") == 0)
         attr->timestamp = g_variant_get_uint64 (value);
       else if (g_strcmp0 (key, "Description") == 0)
diff --git a/panels/firmware-security/cc-firmware-security-utils.h 
b/panels/firmware-security/cc-firmware-security-utils.h
index ef844c001..6c895da87 100644
--- a/panels/firmware-security/cc-firmware-security-utils.h
+++ b/panels/firmware-security/cc-firmware-security-utils.h
@@ -123,9 +123,10 @@ void               fu_security_attr_free              (FwupdSecurityAttr *attr);
 
 G_DEFINE_AUTOPTR_CLEANUP_FUNC (FwupdSecurityAttr, fu_security_attr_free)
 
-gboolean     firmware_security_attr_has_flag (FwupdSecurityAttr       *attr,
-                                              FwupdSecurityAttrFlags   flag);
-void         load_custom_css                 (const char              *path);
-
+gboolean     firmware_security_attr_has_flag                    (FwupdSecurityAttr       *attr,
+                                                                 FwupdSecurityAttrFlags   flag);
+void         load_custom_css                                    (const char              *path);
+const gchar *fwupd_security_attr_result_to_string               (FwupdSecurityAttrResult  result);
+gboolean     fwupd_get_result_status                            (FwupdSecurityAttrResult  result);
 
 G_END_DECLS


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