[gnome-control-center] cc-list-row: Subclass AdwActionRow



commit e637f47e785add2b7e8373f7447add094323e480
Author: Christopher Davis <christopherdavis gnome org>
Date:   Wed Jan 5 22:14:02 2022 -0800

    cc-list-row: Subclass AdwActionRow
    
    AdwActionRow handles many of the properties we use
    CcListRow for. We can re-use it instead of re-creating it.
    
    CcListRow is now an AdwActionRow with three suffixes.
    The `activatable-widget` is set when the switch is visible.
    
    Since our `icon-name` property was only used for the arrow
    icon, it has been replaced with a `show-arrow` property.
    
    The `bold` property has been removed - it was only used in
    one place, and it's not a pattern used in other apps.
    
    I decided to go this route because replacing all the
    instances of CcListRow with AdwActionRow directly would
    end up being more code.

 panels/common/cc-list-row.c                    | 132 ++++++-------------------
 panels/common/cc-list-row.h                    |  27 ++---
 panels/common/cc-list-row.ui                   | 108 ++++++--------------
 panels/info-overview/cc-info-overview-panel.ui |   2 +-
 panels/network/cc-wifi-panel.ui                |   6 --
 panels/sharing/cc-sharing-panel.ui             |   8 +-
 panels/wwan/cc-wwan-device-page.ui             |  10 +-
 7 files changed, 82 insertions(+), 211 deletions(-)
---
diff --git a/panels/common/cc-list-row.c b/panels/common/cc-list-row.c
index d5dfe8d3e..e27d30919 100644
--- a/panels/common/cc-list-row.c
+++ b/panels/common/cc-list-row.c
@@ -34,13 +34,12 @@
 
 struct _CcListRow
 {
-  GtkListBoxRow parent_instance;
+  AdwActionRow  parent_instance;
 
-  GtkBox       *box;
-  GtkLabel     *title;
-  GtkLabel     *subtitle;
   GtkLabel     *secondary_label;
-  GtkImage     *icon;
+
+  GtkImage     *arrow;
+  gboolean      show_arrow;
 
   GtkSwitch    *enable_switch;
   gboolean      show_switch;
@@ -48,19 +47,15 @@ struct _CcListRow
   gboolean      switch_active;
 };
 
-G_DEFINE_TYPE (CcListRow, cc_list_row, GTK_TYPE_LIST_BOX_ROW)
+G_DEFINE_TYPE (CcListRow, cc_list_row, ADW_TYPE_ACTION_ROW)
 
 
 enum {
   PROP_0,
-  PROP_TITLE,
-  PROP_SUBTITLE,
   PROP_SECONDARY_LABEL,
-  PROP_ICON_NAME,
+  PROP_SHOW_ARROW,
   PROP_SHOW_SWITCH,
   PROP_ACTIVE,
-  PROP_BOLD,
-  PROP_USE_UNDERLINE,
   N_PROPS
 };
 
@@ -127,6 +122,10 @@ cc_list_row_get_property (GObject    *object,
       g_value_set_string (value, gtk_label_get_label (self->secondary_label));
       break;
 
+    case PROP_SHOW_ARROW:
+      g_value_set_boolean (value, self->show_arrow);
+      break;
+
     case PROP_ACTIVE:
       g_value_set_boolean (value, self->switch_active);
       break;
@@ -143,49 +142,21 @@ cc_list_row_set_property (GObject      *object,
                           GParamSpec   *pspec)
 {
   CcListRow *self = (CcListRow *)object;
-  PangoAttrList *attributes;
-  PangoAttribute *attribute;
-  gint margin;
 
   switch (prop_id)
     {
-    case PROP_TITLE:
-      gtk_label_set_label (self->title, g_value_get_string (value));
-      break;
-
-    case PROP_SUBTITLE:
-      gtk_widget_set_visible (GTK_WIDGET (self->subtitle),
-                              g_value_get_string (value) != NULL);
-      gtk_label_set_label (self->subtitle, g_value_get_string (value));
-      if (g_value_get_string (value) != NULL)
-        margin = 6;
-      else
-        margin = 12;
-      g_object_set (self->box,
-                    "margin-top", margin,
-                    "margin-bottom", margin,
-                    NULL);
-      break;
-
     case PROP_SECONDARY_LABEL:
       gtk_label_set_label (self->secondary_label, g_value_get_string (value));
       break;
 
-    case PROP_ICON_NAME:
-      cc_list_row_set_icon_name (self, g_value_get_string (value));
+    case PROP_SHOW_ARROW:
+      cc_list_row_set_show_arrow (self, g_value_get_boolean (value));
       break;
 
     case PROP_SHOW_SWITCH:
       cc_list_row_set_show_switch (self, g_value_get_boolean (value));
       break;
 
-    case PROP_USE_UNDERLINE:
-      gtk_label_set_use_underline (self->title, g_value_get_boolean (value));
-      gtk_label_set_use_underline (self->subtitle, g_value_get_boolean (value));
-      gtk_label_set_mnemonic_widget (self->title, GTK_WIDGET (self));
-      gtk_label_set_mnemonic_widget (self->subtitle, GTK_WIDGET (self));
-      break;
-
     case PROP_ACTIVE:
       g_signal_handlers_block_by_func (self->enable_switch,
                                        cc_list_row_switch_active_cb, self);
@@ -196,24 +167,6 @@ cc_list_row_set_property (GObject      *object,
                                          cc_list_row_switch_active_cb, self);
       break;
 
-    case PROP_BOLD:
-      if (g_value_get_boolean (value))
-        attribute = pango_attr_weight_new (PANGO_WEIGHT_BOLD);
-      else
-        attribute = pango_attr_weight_new (PANGO_WEIGHT_NORMAL);
-
-      attributes = gtk_label_get_attributes (self->title);
-
-      if (!attributes)
-        attributes = pango_attr_list_new ();
-      else
-        pango_attr_list_ref (attributes);
-
-      pango_attr_list_change (attributes, attribute);
-      gtk_label_set_attributes (self->title, attributes);
-      pango_attr_list_unref (attributes);
-      break;
-
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
     }
@@ -228,20 +181,6 @@ cc_list_row_class_init (CcListRowClass *klass)
   object_class->get_property = cc_list_row_get_property;
   object_class->set_property = cc_list_row_set_property;
 
-  properties[PROP_TITLE] =
-    g_param_spec_string ("title",
-                         "Title",
-                         "List row primary title",
-                         NULL,
-                         G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS);
-
-  properties[PROP_SUBTITLE] =
-    g_param_spec_string ("subtitle",
-                         "Subtitle",
-                         "List row primary subtitle",
-                         NULL,
-                         G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS);
-
   properties[PROP_SECONDARY_LABEL] =
     g_param_spec_string ("secondary-label",
                          "Secondary Label",
@@ -249,12 +188,12 @@ cc_list_row_class_init (CcListRowClass *klass)
                          NULL,
                          G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
 
-  properties[PROP_ICON_NAME] =
-    g_param_spec_string ("icon-name",
-                         "Icon Name",
-                         "Secondary Icon name",
-                         NULL,
-                         G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS);
+  properties[PROP_SHOW_ARROW] =
+    g_param_spec_boolean ("show-arrow",
+                          "Show Arrow",
+                          "Whether to show an arrow at the end of the row",
+                          FALSE,
+                          G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
 
   properties[PROP_SHOW_SWITCH] =
     g_param_spec_boolean ("show-switch",
@@ -270,31 +209,14 @@ cc_list_row_class_init (CcListRowClass *klass)
                           FALSE,
                           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
 
-  properties[PROP_BOLD] =
-    g_param_spec_boolean ("bold",
-                          "Bold",
-                          "Whether title is bold or not",
-                          FALSE,
-                          G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
-
-  properties[PROP_USE_UNDERLINE] =
-    g_param_spec_boolean ("use-underline",
-                          "Use underline",
-                          "If set, text prefixed with underline shall be used as mnemonic",
-                          FALSE,
-                          G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS);
-
   g_object_class_install_properties (object_class, N_PROPS, properties);
 
   gtk_widget_class_set_template_from_resource (widget_class,
                                                "/org/gnome/control-center/"
                                                "common/cc-list-row.ui");
 
-  gtk_widget_class_bind_template_child (widget_class, CcListRow, box);
-  gtk_widget_class_bind_template_child (widget_class, CcListRow, title);
-  gtk_widget_class_bind_template_child (widget_class, CcListRow, subtitle);
   gtk_widget_class_bind_template_child (widget_class, CcListRow, secondary_label);
-  gtk_widget_class_bind_template_child (widget_class, CcListRow, icon);
+  gtk_widget_class_bind_template_child (widget_class, CcListRow, arrow);
   gtk_widget_class_bind_template_child (widget_class, CcListRow, enable_switch);
 
   gtk_widget_class_bind_template_callback (widget_class, cc_list_row_switch_active_cb);
@@ -312,16 +234,17 @@ cc_list_row_init (CcListRow *self)
 }
 
 void
-cc_list_row_set_icon_name (CcListRow   *self,
-                           const gchar *icon_name)
+cc_list_row_set_show_arrow (CcListRow *self,
+                            gboolean   show_arrow)
 {
   g_return_if_fail (CC_IS_LIST_ROW (self));
   g_return_if_fail (!self->show_switch);
 
-  if (icon_name)
-    g_object_set (self->icon, "icon-name", icon_name, NULL);
+  if (self->show_arrow == show_arrow)
+    return;
 
-  gtk_widget_set_visible (GTK_WIDGET (self->icon), icon_name != NULL);
+  self->show_arrow = show_arrow;
+  g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SHOW_ARROW]);
 }
 
 void
@@ -333,8 +256,11 @@ cc_list_row_set_show_switch (CcListRow *self,
   self->show_switch = !!show_switch;
 
   gtk_widget_set_visible (GTK_WIDGET (self->enable_switch), self->show_switch);
-  gtk_widget_set_visible (GTK_WIDGET (self->icon), !self->show_switch);
+  gtk_widget_set_visible (GTK_WIDGET (self->arrow), !self->show_switch);
   gtk_widget_set_visible (GTK_WIDGET (self->secondary_label), !self->show_switch);
+
+  adw_action_row_set_activatable_widget (ADW_ACTION_ROW (self),
+                                         self->show_switch ? GTK_WIDGET (self->enable_switch) : NULL);
 }
 
 gboolean
diff --git a/panels/common/cc-list-row.h b/panels/common/cc-list-row.h
index 54fbe07ce..b83582400 100644
--- a/panels/common/cc-list-row.h
+++ b/panels/common/cc-list-row.h
@@ -24,24 +24,25 @@
 
 #pragma once
 
+#include <adwaita.h>
 #include <gtk/gtk.h>
 
 G_BEGIN_DECLS
 
 #define CC_TYPE_LIST_ROW (cc_list_row_get_type())
-G_DECLARE_FINAL_TYPE (CcListRow, cc_list_row, CC, LIST_ROW, GtkListBoxRow)
+G_DECLARE_FINAL_TYPE (CcListRow, cc_list_row, CC, LIST_ROW, AdwActionRow)
 
-void       cc_list_row_set_icon_name        (CcListRow   *self,
-                                             const gchar *icon_name);
-void       cc_list_row_set_show_switch      (CcListRow   *self,
-                                             gboolean     show_switch);
-gboolean   cc_list_row_get_active           (CcListRow   *self);
-void       cc_list_row_activate             (CcListRow   *self);
-void       cc_list_row_set_secondary_label  (CcListRow   *self,
-                                             const gchar *label);
-void       cc_list_row_set_secondary_markup (CcListRow   *self,
-                                             const gchar *markup);
-void       cc_list_row_set_switch_sensitive (CcListRow   *self,
-                                             gboolean     sensitive);
+void     cc_list_row_set_show_arrow       (CcListRow   *self,
+                                           gboolean     show_arrow);
+void     cc_list_row_set_show_switch      (CcListRow   *self,
+                                           gboolean     show_switch);
+gboolean cc_list_row_get_active           (CcListRow   *self);
+void     cc_list_row_activate             (CcListRow   *self);
+void     cc_list_row_set_secondary_label  (CcListRow   *self,
+                                           const gchar *label);
+void     cc_list_row_set_secondary_markup (CcListRow   *self,
+                                           const gchar *markup);
+void     cc_list_row_set_switch_sensitive (CcListRow   *self,
+                                           gboolean     sensitive);
 
 G_END_DECLS
diff --git a/panels/common/cc-list-row.ui b/panels/common/cc-list-row.ui
index 655fd050d..f668a10e0 100644
--- a/panels/common/cc-list-row.ui
+++ b/panels/common/cc-list-row.ui
@@ -1,87 +1,37 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
-  <template class="CcListRow" parent="GtkListBoxRow">
-    <property name="visible">1</property>
-    <child>
-      <object class="GtkBox" id="box">
-        <property name="visible">1</property>
-        <property name="margin-start">12</property>
-        <property name="margin-end">12</property>
-        <property name="margin-top">12</property>
-        <property name="margin-bottom">12</property>
-        <property name="spacing">12</property>
-
-        <child>
-          <object class="GtkBox">
-            <property name="visible">1</property>
-            <property name="valign">center</property>
-            <property name="orientation">vertical</property>
-
-            <!-- Title -->
-            <child>
-              <object class="GtkLabel" id="title">
-                <property name="visible">1</property>
-                <property name="hexpand">1</property>
-                <property name="xalign">0.0</property>
-                <property name="ellipsize">end</property>
-              </object>
-            </child>
-
-            <!-- Subtitle -->
-            <child>
-              <object class="GtkLabel" id="subtitle">
-                <property name="visible">0</property>
-                <property name="hexpand">1</property>
-                <property name="xalign">0.0</property>
-                <property name="wrap-mode">word</property>
-                <property name="max-width-chars">42</property>
-                <style>
-                  <class name="dim-label"/>
-                </style>
-                <attributes>
-                  <attribute name="scale" value="0.83"/>
-                </attributes>
-              </object>
-            </child>
-
-          </object>
-        </child>
-
-        <!-- Secondary Label -->
-        <child>
-          <object class="GtkLabel" id="secondary_label">
-            <property name="visible">1</property>
-            <property name="valign">center</property>
-            <property name="ellipsize">end</property>
-            <property name="selectable" bind-source="CcListRow" bind-property="activatable" 
bind-flags="sync-create|invert-boolean" />
-            <style>
-              <class name="dim-label"/>
-            </style>
-          </object>
-        </child>
-
-        <!-- Icon -->
-        <child>
-          <object class="GtkImage" id="icon">
-            <property name="visible">0</property>
-            <property name="valign">center</property>
-            <style>
-              <class name="dim-label"/>
-            </style>
-          </object>
-        </child>
+  <template class="CcListRow" parent="AdwActionRow">
+    <property name="activatable">True</property>
+
+    <!-- Secondary Label -->
+    <child type="suffix">
+      <object class="GtkLabel" id="secondary_label">
+        <property name="valign">center</property>
+        <property name="ellipsize">end</property>
+        <property name="selectable" bind-source="CcListRow" bind-property="activatable" 
bind-flags="sync-create|invert-boolean" />
+        <style>
+          <class name="dim-label"/>
+        </style>
+      </object>
+    </child>
 
-        <!-- Switch -->
-        <child>
-          <object class="GtkSwitch" id="enable_switch">
-            <property name="visible">0</property>
-            <property name="can-focus">0</property>
-            <property name="valign">center</property>
-            <signal name="notify::active" handler="cc_list_row_switch_active_cb" swapped="yes"/>
-          </object>
-        </child>
+    <!-- Switch -->
+    <child type="suffix">
+      <object class="GtkSwitch" id="enable_switch">
+        <property name="visible">False</property>
+        <property name="valign">center</property>
+        <signal name="notify::active" handler="cc_list_row_switch_active_cb" swapped="yes"/>
+      </object>
+    </child>
 
+    <!-- Arrow -->
+    <child type="suffix">
+      <object class="GtkImage" id="arrow">
+        <property name="visible" bind-source="CcListRow" bind-property="show-arrow" 
bind-flags="sync-create"/>
+        <property name="valign">center</property>
+        <property name="icon-name">go-next-symbolic</property>
       </object>
     </child>
+
   </template>
 </interface>
diff --git a/panels/info-overview/cc-info-overview-panel.ui b/panels/info-overview/cc-info-overview-panel.ui
index 6e0ce452f..19d46675c 100644
--- a/panels/info-overview/cc-info-overview-panel.ui
+++ b/panels/info-overview/cc-info-overview-panel.ui
@@ -37,7 +37,7 @@
                       <object class="CcListRow" id="hostname_row">
                         <property name="title" translatable="yes">Device Name</property>
                         <property name="secondary-label" bind-source="hostname_entry" bind-property="text" 
bind-flags="sync-create" />
-                        <property name="icon-name">go-next-symbolic</property>
+                        <property name="show-arrow">True</property>
                       </object>
                     </child>
 
diff --git a/panels/network/cc-wifi-panel.ui b/panels/network/cc-wifi-panel.ui
index d4855cd2b..335fadaa1 100644
--- a/panels/network/cc-wifi-panel.ui
+++ b/panels/network/cc-wifi-panel.ui
@@ -28,13 +28,7 @@
                     </style>
                     <child>
                       <object class="CcListRow" id="rfkill_row">
-                        <property name="margin-start">6</property>
-                        <property name="margin-end">6</property>
-                        <property name="margin-top">6</property>
-                        <property name="margin-bottom">6</property>
-                        <property name="activatable">False</property>
                         <property name="show-switch">True</property>
-                        <property name="bold">True</property>
                         <property name="title" translatable="yes">Airplane Mode</property>
                         <property name="subtitle" translatable="yes">Disables Wi-Fi, Bluetooth and mobile 
broadband</property>
                         <signal name="notify::active" handler="rfkill_switch_notify_activate_cb" 
object="CcWifiPanel" swapped="no" />
diff --git a/panels/sharing/cc-sharing-panel.ui b/panels/sharing/cc-sharing-panel.ui
index d2341a521..4fe90a03d 100644
--- a/panels/sharing/cc-sharing-panel.ui
+++ b/panels/sharing/cc-sharing-panel.ui
@@ -45,28 +45,28 @@
                     </style>
                     <child>
                       <object class="CcListRow" id="personal_file_sharing_row">
-                        <property name="icon-name">go-next-symbolic</property>
+                        <property name="show-arrow">True</property>
                         <property name="use-underline">True</property>
                         <property name="title" translatable="yes">_File Sharing</property>
                       </object>
                     </child>
                     <child>
                       <object class="CcListRow" id="screen_sharing_row">
-                        <property name="icon-name">go-next-symbolic</property>
+                        <property name="show-arrow">True</property>
                         <property name="use-underline">True</property>
                         <property name="title" translatable="yes">_Screen Sharing</property>
                       </object>
                     </child>
                     <child>
                       <object class="CcListRow" id="media_sharing_row">
-                        <property name="icon-name">go-next-symbolic</property>
+                        <property name="show-arrow">True</property>
                         <property name="use-underline">True</property>
                         <property name="title" translatable="yes">_Media Sharing</property>
                       </object>
                     </child>
                     <child>
                       <object class="CcListRow" id="remote_login_row">
-                        <property name="icon-name">go-next-symbolic</property>
+                        <property name="show-arrow">True</property>
                         <property name="use-underline">True</property>
                         <property name="title" translatable="yes">_Remote Login</property>
                       </object>
diff --git a/panels/wwan/cc-wwan-device-page.ui b/panels/wwan/cc-wwan-device-page.ui
index 141775b18..6efec36f8 100644
--- a/panels/wwan/cc-wwan-device-page.ui
+++ b/panels/wwan/cc-wwan-device-page.ui
@@ -165,14 +165,14 @@
                     <child>
                       <object class="CcListRow" id="network_mode_row">
                         <property name="use-underline">True</property>
-                        <property name="icon-name">go-next-symbolic</property>
+                        <property name="show-arrow">True</property>
                         <property name="title" translatable="yes">_Network Mode</property>
                       </object>
                     </child>
                     <child>
                       <object class="CcListRow" id="network_name_row">
                         <property name="use-underline">True</property>
-                        <property name="icon-name">go-next-symbolic</property>
+                        <property name="show-arrow">True</property>
                         <property name="title" translatable="yes">N_etwork</property>
                       </object>
                     </child>
@@ -204,7 +204,7 @@
                     <child>
                       <object class="CcListRow" id="apn_settings_row">
                         <property name="use-underline">True</property>
-                        <property name="icon-name">go-next-symbolic</property>
+                        <property name="show-arrow">true</property>
                         <property name="title" translatable="yes">_Access Point Names</property>
                       </object>
                     </child>
@@ -213,7 +213,7 @@
                     <child>
                       <object class="CcListRow" id="sim_lock_row">
                         <property name="use-underline">True</property>
-                        <property name="icon-name">go-next-symbolic</property>
+                        <property name="show-arrow">True</property>
                         <property name="title" translatable="yes">_SIM Lock</property>
                         <property name="subtitle" translatable="yes">Lock SIM with PIN</property>
                       </object>
@@ -223,7 +223,7 @@
                     <child>
                       <object class="CcListRow" id="details_row">
                         <property name="use-underline">True</property>
-                        <property name="icon-name">go-next-symbolic</property>
+                        <property name="show-arrow">True</property>
                         <property name="title" translatable="yes">M_odem Details</property>
                       </object>
                     </child>


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