[gnome-control-center/wip/cdavis/40-consistency: 1/5] notifications: Use preferences styling from libhandy




commit 83a88ee385d6697be9c93add9241eb55d2eee662
Author: Christopher Davis <brainblasted disroot org>
Date:   Tue Feb 9 21:21:57 2021 -0800

    notifications: Use preferences styling from libhandy
    
    In libhandy we have a pattern for preferences pages
    that includes rounded listboxes and sections with headers.
    We can make use of that here.
    
    See https://gitlab.gnome.org/GNOME/gnome-control-center/-/issues/1190

 panels/notifications/cc-notifications-panel.c  |  58 +++-------
 panels/notifications/cc-notifications-panel.ui | 153 +++++++------------------
 2 files changed, 61 insertions(+), 150 deletions(-)
---
diff --git a/panels/notifications/cc-notifications-panel.c b/panels/notifications/cc-notifications-panel.c
index 358b87e62..dc798a248 100644
--- a/panels/notifications/cc-notifications-panel.c
+++ b/panels/notifications/cc-notifications-panel.c
@@ -24,6 +24,7 @@
 #include <glib.h>
 #include <gio/gio.h>
 #include <gio/gdesktopappinfo.h>
+#include <libhandy-1/handy.h>
 
 #include "cc-list-row.h"
 #include "list-box-helper.h"
@@ -36,27 +37,26 @@
 #define APP_PREFIX "/org/gnome/desktop/notifications/application/"
 
 struct _CcNotificationsPanel {
-  CcPanel            parent_instance;
+  CcPanel             parent_instance;
 
-  GtkListBox        *app_listbox;
-  GtkAdjustment     *focus_adjustment;
-  CcListRow         *lock_screen_row;
-  GtkScrolledWindow *main_scrolled_window;
-  GtkBox            *main_box;
-  GtkListBox        *options_listbox;
-  CcListRow         *dnd_row;
-  GtkSizeGroup      *sizegroup1;
+  HdyPreferencesPage *page;
+  GtkListBox         *app_listbox;
+  GtkAdjustment      *focus_adjustment;
+  CcListRow          *lock_screen_row;
+  GtkListBox         *options_listbox;
+  CcListRow          *dnd_row;
+  GtkSizeGroup       *sizegroup1;
 
-  GSettings         *master_settings;
+  GSettings          *master_settings;
 
-  GCancellable      *cancellable;
+  GCancellable       *cancellable;
 
-  GHashTable        *known_applications;
+  GHashTable         *known_applications;
 
-  GList             *sections;
-  GList             *sections_reverse;
+  GList              *sections;
+  GList              *sections_reverse;
 
-  GDBusProxy        *perm_store;
+  GDBusProxy         *perm_store;
 };
 
 struct _CcNotificationsPanelClass {
@@ -107,7 +107,6 @@ keynav_failed (CcNotificationsPanel *panel,
                GtkDirectionType      direction,
                GtkWidget            *widget)
 {
-  gdouble  value, lower, upper, page;
   GList   *item, *sections;
 
   /* Find the widget in the list of GtkWidgets */
@@ -124,22 +123,6 @@ keynav_failed (CcNotificationsPanel *panel,
       return TRUE;
     }
 
-  value = gtk_adjustment_get_value (panel->focus_adjustment);
-  lower = gtk_adjustment_get_lower (panel->focus_adjustment);
-  upper = gtk_adjustment_get_upper (panel->focus_adjustment);
-  page  = gtk_adjustment_get_page_size (panel->focus_adjustment);
-
-  if (direction == GTK_DIR_UP && value > lower)
-    {
-      gtk_adjustment_set_value (panel->focus_adjustment, lower);
-      return TRUE;
-    }
-  else if (direction == GTK_DIR_DOWN && value < upper - page)
-    {
-      gtk_adjustment_set_value (panel->focus_adjustment, upper - page);
-      return TRUE;
-    }
-
   return FALSE;
 }
 
@@ -183,20 +166,14 @@ cc_notifications_panel_init (CcNotificationsPanel *panel)
                    panel->lock_screen_row,
                    "active", G_SETTINGS_BIND_DEFAULT);
 
-  gtk_container_set_focus_vadjustment (GTK_CONTAINER (panel->main_box), panel->focus_adjustment);
+  gtk_container_set_focus_vadjustment (GTK_CONTAINER (panel->page), panel->focus_adjustment);
 
   panel->sections = g_list_append (panel->sections, panel->options_listbox);
   panel->sections_reverse = g_list_prepend (panel->sections_reverse, panel->options_listbox);
-  gtk_list_box_set_header_func (panel->options_listbox,
-                                cc_list_box_update_header_func,
-                                NULL, NULL);
 
   panel->sections = g_list_append (panel->sections, panel->app_listbox);
   panel->sections_reverse = g_list_prepend (panel->sections_reverse, panel->app_listbox);
   gtk_list_box_set_sort_func (panel->app_listbox, (GtkListBoxSortFunc)sort_apps, NULL, NULL);
-  gtk_list_box_set_header_func (panel->app_listbox,
-                                cc_list_box_update_header_func,
-                                NULL, NULL);
 
   build_app_store (panel);
 
@@ -234,11 +211,10 @@ cc_notifications_panel_class_init (CcNotificationsPanelClass *klass)
 
   gtk_widget_class_set_template_from_resource (widget_class, 
"/org/gnome/control-center/notifications/cc-notifications-panel.ui");
 
+  gtk_widget_class_bind_template_child (widget_class, CcNotificationsPanel, page);
   gtk_widget_class_bind_template_child (widget_class, CcNotificationsPanel, app_listbox);
   gtk_widget_class_bind_template_child (widget_class, CcNotificationsPanel, focus_adjustment);
   gtk_widget_class_bind_template_child (widget_class, CcNotificationsPanel, lock_screen_row);
-  gtk_widget_class_bind_template_child (widget_class, CcNotificationsPanel, main_scrolled_window);
-  gtk_widget_class_bind_template_child (widget_class, CcNotificationsPanel, main_box);
   gtk_widget_class_bind_template_child (widget_class, CcNotificationsPanel, options_listbox);
   gtk_widget_class_bind_template_child (widget_class, CcNotificationsPanel, dnd_row);
   gtk_widget_class_bind_template_child (widget_class, CcNotificationsPanel, sizegroup1);
diff --git a/panels/notifications/cc-notifications-panel.ui b/panels/notifications/cc-notifications-panel.ui
index 184b7c807..2015feef0 100644
--- a/panels/notifications/cc-notifications-panel.ui
+++ b/panels/notifications/cc-notifications-panel.ui
@@ -4,124 +4,59 @@
   <template class="CcNotificationsPanel" parent="CcPanel">
     <property name="visible">True</property>
     <child>
-      <object class="GtkScrolledWindow" id="main_scrolled_window">
+      <object class="HdyPreferencesPage" id="page">
         <property name="visible">True</property>
-        <property name="can_focus">True</property>
-        <property name="hscrollbar_policy">never</property>
-        <property name="shadow_type">none</property>
-        <property name="vadjustment">focus_adjustment</property>
         <child>
-          <object class="GtkViewport">
+          <object class="HdyPreferencesGroup">
             <property name="visible">True</property>
-            <property name="can_focus">False</property>
             <child>
-              <object class="HdyClamp">
+              <object class="GtkListBox" id="options_listbox">
                 <property name="visible">True</property>
-                <property name="margin_top">32</property>
-                <property name="margin_bottom">32</property>
-                <property name="margin_start">12</property>
-                <property name="margin_end">12</property>
+                <property name="can_focus">False</property>
+                <property name="hexpand">True</property>
+                <property name="selection_mode">none</property>
+                <signal name="keynav-failed" handler="keynav_failed" object="CcNotificationsPanel" 
swapped="yes" />
                 <child>
-                  <object class="GtkBox" id="main_box">
+                  <object class="CcListRow" id="dnd_row">
                     <property name="visible">True</property>
-                    <property name="can_focus">False</property>
-                    <property name="orientation">vertical</property>
-                    <property name="hexpand">True</property>
-                    <child>
-                      <object class="GtkFrame">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="margin_bottom">32</property>
-                        <property name="hexpand">True</property>
-                        <property name="label_xalign">0</property>
-                        <property name="shadow_type">in</property>
-                        <child>
-                          <object class="GtkListBox" id="options_listbox">
-                            <property name="visible">True</property>
-                            <property name="can_focus">False</property>
-                            <property name="hexpand">True</property>
-                            <property name="selection_mode">none</property>
-                            <signal name="keynav-failed" handler="keynav_failed" 
object="CcNotificationsPanel" swapped="yes" />
-                            <child>
-                              <object class="CcListRow" id="dnd_row">
-                                <property name="visible">True</property>
-                                <property name="title" translatable="yes">_Do Not Disturb</property>
-                                <property name="use-underline">True</property>
-                                <property name="show-switch">True</property>
-                              </object>
-                            </child>
-                            <child>
-                              <object class="CcListRow" id="lock_screen_row">
-                                <property name="visible">True</property>
-                                <property name="title" translatable="yes">_Lock Screen 
Notifications</property>
-                                <property name="use-underline">True</property>
-                                <property name="show-switch">True</property>
-                              </object>
-                            </child>
-                          </object>
-                        </child>
-                        <child type="label_item">
-                          <placeholder/>
-                        </child>
-                      </object>
-                      <packing>
-                        <property name="expand">False</property>
-                        <property name="fill">True</property>
-                        <property name="position">0</property>
-                      </packing>
-                    </child>
-                    <child>
-                      <object class="GtkLabel" id="app_list_heading_label">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="xalign">0</property>
-                        <property name="margin_bottom">12</property>
-                        <property name="label" translatable="yes" comments="List of 
applications.">Applications</property>
-                        <attributes>
-                          <attribute name="weight" value="bold"/>
-                        </attributes>
-                        <accessibility>
-                          <relation type="label-for" target="app_listbox"/>
-                        </accessibility>
-                        </object>
-                      <packing>
-                        <property name="expand">False</property>
-                        <property name="fill">True</property>
-                        <property name="position">1</property>
-                      </packing>
-                    </child>
-                    <child>
-                      <object class="GtkFrame">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="hexpand">True</property>
-                        <property name="label_xalign">0</property>
-                        <property name="shadow_type">in</property>
-                        <child>
-                          <object class="GtkListBox" id="app_listbox">
-                            <property name="visible">True</property>
-                            <property name="can_focus">False</property>
-                            <property name="hexpand">True</property>
-                            <property name="selection_mode">none</property>
-                            <signal name="keynav-failed" handler="keynav_failed" 
object="CcNotificationsPanel" swapped="yes" />
-                            <signal name="row-activated" handler="select_app" object="CcNotificationsPanel" 
swapped="yes" />
-                            <accessibility>
-                              <relation type="labelled-by" target="app_list_heading_label"/>
-                            </accessibility>
-                          </object>
-                        </child>
-                        <child>
-                          <placeholder/>
-                        </child>
-                      </object>
-                      <packing>
-                        <property name="expand">False</property>
-                        <property name="fill">True</property>
-                        <property name="position">2</property>
-                      </packing>
-                    </child>
+                    <property name="title" translatable="yes">_Do Not Disturb</property>
+                    <property name="use-underline">True</property>
+                    <property name="show-switch">True</property>
                   </object>
                 </child>
+                <child>
+                  <object class="CcListRow" id="lock_screen_row">
+                    <property name="visible">True</property>
+                    <property name="title" translatable="yes">_Lock Screen Notifications</property>
+                    <property name="use-underline">True</property>
+                    <property name="show-switch">True</property>
+                  </object>
+                </child>
+                <style>
+                  <class name="content"/>
+                </style>
+              </object>
+            </child>
+          </object>
+        </child>
+        <child>
+          <object class="HdyPreferencesGroup" id="app_list_group">
+            <property name="visible">True</property>
+            <property name="title" translatable="yes" comments="List of 
applications.">Applications</property>
+            <child>
+              <object class="GtkListBox" id="app_listbox">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="hexpand">True</property>
+                <property name="selection_mode">none</property>
+                <signal name="keynav-failed" handler="keynav_failed" object="CcNotificationsPanel" 
swapped="yes" />
+                <signal name="row-activated" handler="select_app" object="CcNotificationsPanel" 
swapped="yes" />
+                <accessibility>
+                  <relation type="labelled-by" target="app_list_group"/>
+                </accessibility>
+                <style>
+                  <class name="content"/>
+                </style>
               </object>
             </child>
           </object>


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