[gnome-system-monitor/wip/cdavis/libhandy] preferences: Use GtkSwitch instead of GtkCheckButton for rows



commit 96eac798e5163e9fcd1fd32a9baa4af6ac1a659a
Author: Christopher Davis <brainblasted disroot org>
Date:   Fri Feb 5 02:26:48 2021 -0800

    preferences: Use GtkSwitch instead of GtkCheckButton for rows
    
    Switches are typically used in cases like this.

 data/preferences.ui | 117 +++++++++++++++++++++-------------------------------
 src/prefsdialog.cpp |  52 +++++++++++------------
 2 files changed, 74 insertions(+), 95 deletions(-)
---
diff --git a/data/preferences.ui b/data/preferences.ui
index df5db446..098f8e52 100644
--- a/data/preferences.ui
+++ b/data/preferences.ui
@@ -40,14 +40,13 @@
                 <property name="visible">True</property>
                 <property name="use-underline">True</property>
                 <property name="title" translatable="yes">Enable _Smooth Refresh</property>
-                <property name="activatable-widget">smooth_button</property>
-                <child type="prefix">
-                  <object class="GtkCheckButton" id="smooth_button">
+                <property name="activatable-widget">smooth_switch</property>
+                <child>
+                  <object class="GtkSwitch" id="smooth_switch">
                     <property name="visible">True</property>
                     <property name="can_focus">True</property>
                     <property name="receives_default">False</property>
-                    <property name="halign">start</property>
-                    <property name="draw_indicator">True</property>
+                    <property name="valign">center</property>
                   </object>
                 </child>
               </object>
@@ -57,14 +56,13 @@
                 <property name="visible">True</property>
                 <property name="use-underline">True</property>
                 <property name="title" translatable="yes">Alert Before Ending or _Killing 
Processes</property>
-                <property name="activatable-widget">check_button</property>
-                <child type="prefix">
-                  <object class="GtkCheckButton" id="check_button">
+                <property name="activatable-widget">check_switch</property>
+                <child>
+                  <object class="GtkSwitch" id="check_switch">
                     <property name="visible">True</property>
                     <property name="can_focus">True</property>
                     <property name="receives_default">False</property>
-                    <property name="halign">start</property>
-                    <property name="draw_indicator">True</property>
+                    <property name="valign">center</property>
                   </object>
                 </child>
               </object>
@@ -74,14 +72,13 @@
                 <property name="visible">True</property>
                 <property name="use-underline">True</property>
                 <property name="title" translatable="yes">_Divide CPU Usage by CPU Count</property>
-                <property name="activatable-widget">solaris_button</property>
-                <child type="prefix">
-                  <object class="GtkCheckButton" id="solaris_button">
+                <property name="activatable-widget">solaris_switch</property>
+                <child>
+                  <object class="GtkSwitch" id="solaris_switch">
                     <property name="visible">True</property>
                     <property name="can_focus">True</property>
                     <property name="receives_default">False</property>
-                    <property name="halign">start</property>
-                    <property name="draw_indicator">True</property>
+                    <property name="valign">center</property>
                   </object>
                 </child>
               </object>
@@ -91,15 +88,13 @@
                 <property name="visible">True</property>
                 <property name="use-underline">True</property>
                 <property name="title" translatable="yes">Show Memory in IEC</property>
-                <property name="activatable-widget">proc_mem_in_iec_button</property>
-                <child type="prefix">
-                  <object class="GtkCheckButton" id="proc_mem_in_iec_button">
+                <property name="activatable-widget">proc_mem_in_iec_switch</property>
+                <child>
+                  <object class="GtkSwitch" id="proc_mem_in_iec_switch">
                     <property name="visible">True</property>
                     <property name="can_focus">True</property>
                     <property name="receives_default">False</property>
-                    <property name="halign">start</property>
-                    <property name="use_underline">True</property>
-                    <property name="draw_indicator">True</property>
+                    <property name="valign">center</property>
                   </object>
                 </child>
               </object>
@@ -180,15 +175,13 @@
                 <property name="visible">True</property>
                 <property name="use-underline">True</property>
                 <property name="title" translatable="yes">_Draw CPU Chart as Stacked Area Chart</property>
-                <property name="activatable-widget">draw_stacked_button</property>
-                <child type="prefix">
-                  <object class="GtkCheckButton" id="draw_stacked_button">
+                <property name="activatable-widget">draw_stacked_switch</property>
+                <child>
+                  <object class="GtkSwitch" id="draw_stacked_switch">
                     <property name="visible">True</property>
                     <property name="can_focus">True</property>
                     <property name="receives_default">False</property>
-                    <property name="use_underline">True</property>
-                    <property name="halign">start</property>
-                    <property name="draw_indicator">True</property>
+                    <property name="valign">center</property>
                   </object>
                 </child>
               </object>
@@ -198,15 +191,13 @@
                 <property name="visible">True</property>
                 <property name="use-underline">True</property>
                 <property name="title" translatable="yes">Draw Charts as S_mooth Graphs</property>
-                <property name="activatable-widget">draw_smooth_button</property>
-                <child type="prefix">
-                  <object class="GtkCheckButton" id="draw_smooth_button">
+                <property name="activatable-widget">draw_smooth_switch</property>
+                <child>
+                  <object class="GtkSwitch" id="draw_smooth_switch">
                     <property name="visible">True</property>
                     <property name="can_focus">True</property>
                     <property name="receives_default">False</property>
-                    <property name="use_underline">True</property>
-                    <property name="halign">start</property>
-                    <property name="draw_indicator">True</property>
+                    <property name="valign">center</property>
                   </object>
                 </child>
               </object>
@@ -216,15 +207,13 @@
                 <property name="visible">True</property>
                 <property name="use-underline">True</property>
                 <property name="title" translatable="yes">Show Memory and Swap in IEC</property>
-                <property name="activatable-widget">res_mem_in_iec_button</property>
-                <child type="prefix">
-                  <object class="GtkCheckButton" id="res_mem_in_iec_button">
+                <property name="activatable-widget">res_mem_in_iec_switch</property>
+                <child>
+                  <object class="GtkSwitch" id="res_mem_in_iec_switch">
                     <property name="visible">True</property>
                     <property name="can_focus">True</property>
                     <property name="receives_default">False</property>
-                    <property name="halign">start</property>
-                    <property name="use_underline">True</property>
-                    <property name="draw_indicator">True</property>
+                    <property name="valign">center</property>
                   </object>
                 </child>
               </object>
@@ -234,15 +223,13 @@
                 <property name="visible">True</property>
                 <property name="use-underline">True</property>
                 <property name="title" translatable="yes">Show Memory in Logarithmic Scale</property>
-                <property name="activatable-widget">logarithmic_scale_button</property>
-                <child type="prefix">
-                  <object class="GtkCheckButton" id="logarithmic_scale_button">
+                <property name="activatable-widget">logarithmic_scale_switch</property>
+                <child>
+                  <object class="GtkSwitch" id="logarithmic_scale_switch">
                     <property name="visible">True</property>
                     <property name="can_focus">True</property>
                     <property name="receives_default">False</property>
-                    <property name="halign">start</property>
-                    <property name="use_underline">True</property>
-                    <property name="draw_indicator">True</property>
+                    <property name="valign">center</property>
                   </object>
                 </child>
               </object>
@@ -252,15 +239,13 @@
                 <property name="visible">True</property>
                 <property name="use-underline">True</property>
                 <property name="title" translatable="yes">_Show Network Speed in Bits</property>
-                <property name="activatable-widget">bits_button</property>
-                <child type="prefix">
-                  <object class="GtkCheckButton" id="bits_button">
+                <property name="activatable-widget">bits_switch</property>
+                <child>
+                  <object class="GtkSwitch" id="bits_switch">
                     <property name="visible">True</property>
                     <property name="can_focus">True</property>
                     <property name="receives_default">False</property>
-                    <property name="use_underline">True</property>
-                    <property name="halign">start</property>
-                    <property name="draw_indicator">True</property>
+                    <property name="valign">center</property>
                   </object>
                 </child>
               </object>
@@ -270,15 +255,13 @@
                 <property name="visible">True</property>
                 <property name="use-underline">True</property>
                 <property name="title" translatable="yes">Set Network Totals _Unit Separately</property>
-                <property name="activatable-widget">bits_unit_button</property>
-                <child type="prefix">
-                  <object class="GtkCheckButton" id="bits_unit_button">
+                <property name="activatable-widget">bits_unit_switch</property>
+                <child>
+                  <object class="GtkSwitch" id="bits_unit_switch">
                     <property name="visible">True</property>
                     <property name="can_focus">True</property>
                     <property name="receives_default">False</property>
-                    <property name="use_underline">True</property>
-                    <property name="halign">start</property>
-                    <property name="draw_indicator">True</property>
+                    <property name="valign">center</property>
                   </object>
                 </child>
               </object>
@@ -288,16 +271,14 @@
                 <property name="visible">True</property>
                 <property name="use-underline">True</property>
                 <property name="title" translatable="yes">Show Network _Totals in Bits</property>
-                <property name="activatable-widget">bits_total_button</property>
-                <property name="sensitive" bind-source="bits_unit_button" bind-property="active" 
bind-flags="sync-create"/>
-                <child type="prefix">
-                  <object class="GtkCheckButton" id="bits_total_button">
+                <property name="activatable-widget">bits_total_switch</property>
+                <property name="sensitive" bind-source="bits_unit_switch" bind-property="active" 
bind-flags="sync-create"/>
+                <child>
+                  <object class="GtkSwitch" id="bits_total_switch">
                     <property name="visible">True</property>
                     <property name="can_focus">True</property>
                     <property name="receives_default">False</property>
-                    <property name="use_underline">True</property>
-                    <property name="halign">start</property>
-                    <property name="draw_indicator">True</property>
+                    <property name="valign">center</property>
                   </object>
                 </child>
               </object>
@@ -339,14 +320,12 @@
                 <property name="use-underline">True</property>
                 <property name="title" translatable="yes">Show _All File Systems</property>
                 <property name="activatable-widget">all_devices_check</property>
-                <child type="prefix">
-                  <object class="GtkCheckButton" id="all_devices_check">
+                <child>
+                  <object class="GtkSwitch" id="all_devices_check">
                     <property name="visible">True</property>
                     <property name="can_focus">True</property>
                     <property name="receives_default">False</property>
-                    <property name="use_underline">True</property>
-                    <property name="halign">start</property>
-                    <property name="draw_indicator">True</property>
+                    <property name="valign">center</property>
                   </object>
                 </child>
               </object>
diff --git a/src/prefsdialog.cpp b/src/prefsdialog.cpp
index a0ac65f7..39ca3842 100644
--- a/src/prefsdialog.cpp
+++ b/src/prefsdialog.cpp
@@ -230,8 +230,8 @@ create_preferences_dialog (GsmApplication *app)
 
     GtkAdjustment *adjustment;
     GtkSpinButton *spin_button;
-    GtkCheckButton *check_button;
-    GtkCheckButton *smooth_button;
+    GtkSwitch *check_switch;
+    GtkSwitch *smooth_switch;
     GtkBuilder *builder;
     gfloat update;
 
@@ -257,42 +257,42 @@ create_preferences_dialog (GsmApplication *app)
     g_signal_connect (G_OBJECT (spin_button), "focus_out_event",
                       G_CALLBACK (SBU::callback), &interval_updater);
 
-    smooth_button = GTK_CHECK_BUTTON (gtk_builder_get_object (builder, "smooth_button"));
-    g_settings_bind(app->settings->gobj (), SmoothRefresh::KEY.c_str(), smooth_button, "active", 
G_SETTINGS_BIND_DEFAULT);
+    smooth_switch = GTK_SWITCH (gtk_builder_get_object (builder, "smooth_switch"));
+    g_settings_bind(app->settings->gobj (), SmoothRefresh::KEY.c_str(), smooth_switch, "active", 
G_SETTINGS_BIND_DEFAULT);
 
-    check_button = GTK_CHECK_BUTTON (gtk_builder_get_object (builder, "check_button"));
+    check_switch = GTK_SWITCH (gtk_builder_get_object (builder, "check_switch"));
     g_settings_bind (app->settings->gobj (), GSM_SETTING_SHOW_KILL_DIALOG,
-                     check_button, "active",
+                     check_switch, "active",
                      G_SETTINGS_BIND_DEFAULT);
 
-    GtkCheckButton *solaris_button = GTK_CHECK_BUTTON (gtk_builder_get_object (builder, "solaris_button"));
+    GtkSwitch *solaris_switch = GTK_SWITCH (gtk_builder_get_object (builder, "solaris_switch"));
     g_settings_bind (app->settings->gobj (), GSM_SETTING_SOLARIS_MODE,
-                     solaris_button, "active",
+                     solaris_switch, "active",
                      G_SETTINGS_BIND_DEFAULT);
 
-    GtkCheckButton *proc_mem_in_iec_button = GTK_CHECK_BUTTON (gtk_builder_get_object (builder, 
"proc_mem_in_iec_button"));
+    GtkSwitch *proc_mem_in_iec_switch = GTK_SWITCH (gtk_builder_get_object (builder, 
"proc_mem_in_iec_switch"));
     g_settings_bind(app->settings->gobj (), GSM_SETTING_PROCESS_MEMORY_IN_IEC,
-                    proc_mem_in_iec_button, "active",
+                    proc_mem_in_iec_switch, "active",
                     G_SETTINGS_BIND_DEFAULT);
 
-    GtkCheckButton *logarithmic_scale_button = GTK_CHECK_BUTTON (gtk_builder_get_object (builder, 
"logarithmic_scale_button"));
+    GtkSwitch *logarithmic_scale_switch = GTK_SWITCH (gtk_builder_get_object (builder, 
"logarithmic_scale_switch"));
     g_settings_bind (app->settings->gobj (), GSM_SETTING_LOGARITHMIC_SCALE,
-                     logarithmic_scale_button, "active",
+                     logarithmic_scale_switch, "active",
                      G_SETTINGS_BIND_DEFAULT);
 
-    GtkCheckButton *draw_stacked_button = GTK_CHECK_BUTTON (gtk_builder_get_object (builder, 
"draw_stacked_button"));
+    GtkSwitch *draw_stacked_switch = GTK_SWITCH (gtk_builder_get_object (builder, "draw_stacked_switch"));
     g_settings_bind (app->settings->gobj (), GSM_SETTING_DRAW_STACKED,
-                     draw_stacked_button, "active",
+                     draw_stacked_switch, "active",
                      G_SETTINGS_BIND_DEFAULT);
 
-    GtkCheckButton *draw_smooth_button = GTK_CHECK_BUTTON (gtk_builder_get_object (builder, 
"draw_smooth_button"));
+    GtkSwitch *draw_smooth_switch = GTK_SWITCH (gtk_builder_get_object (builder, "draw_smooth_switch"));
     g_settings_bind (app->settings->gobj (), GSM_SETTING_DRAW_SMOOTH,
-                     draw_smooth_button, "active",
+                     draw_smooth_switch, "active",
                      G_SETTINGS_BIND_DEFAULT);
 
-    GtkCheckButton *res_mem_in_iec_button = GTK_CHECK_BUTTON (gtk_builder_get_object (builder, 
"res_mem_in_iec_button"));
+    GtkSwitch *res_mem_in_iec_switch = GTK_SWITCH (gtk_builder_get_object (builder, 
"res_mem_in_iec_switch"));
     g_settings_bind(app->settings->gobj (), GSM_SETTING_RESOURCES_MEMORY_IN_IEC,
-                    res_mem_in_iec_button, "active",
+                    res_mem_in_iec_switch, "active",
                     G_SETTINGS_BIND_DEFAULT);
 
     create_field_page (builder, GTK_TREE_VIEW (app->tree), "proctree");
@@ -315,19 +315,19 @@ create_preferences_dialog (GsmApplication *app)
                       G_CALLBACK(ScaleUpdater::callback),
                       &graph_points_updater);
 
-    GtkCheckButton *bits_button = GTK_CHECK_BUTTON (gtk_builder_get_object (builder, "bits_button"));
+    GtkSwitch *bits_switch = GTK_SWITCH (gtk_builder_get_object (builder, "bits_switch"));
     g_settings_bind(app->settings->gobj (), GSM_SETTING_NETWORK_IN_BITS,
-                    bits_button, "active",
+                    bits_switch, "active",
                     G_SETTINGS_BIND_DEFAULT);
 
-    GtkCheckButton *bits_unit_button = GTK_CHECK_BUTTON (gtk_builder_get_object (builder, 
"bits_unit_button"));
+    GtkSwitch *bits_unit_switch = GTK_SWITCH (gtk_builder_get_object (builder, "bits_unit_switch"));
     g_settings_bind(app->settings->gobj (), GSM_SETTING_NETWORK_TOTAL_UNIT,
-                    bits_unit_button, "active",
+                    bits_unit_switch, "active",
                     G_SETTINGS_BIND_DEFAULT);
 
-    GtkCheckButton *bits_total_button = GTK_CHECK_BUTTON (gtk_builder_get_object (builder, 
"bits_total_button"));
+    GtkSwitch *bits_total_switch = GTK_SWITCH (gtk_builder_get_object (builder, "bits_total_switch"));
     g_settings_bind(app->settings->gobj (), GSM_SETTING_NETWORK_TOTAL_IN_BITS,
-                    bits_total_button, "active",
+                    bits_total_switch, "active",
                     G_SETTINGS_BIND_DEFAULT);
 
     update = (gfloat) app->config.disks_update_interval;
@@ -340,9 +340,9 @@ create_preferences_dialog (GsmApplication *app)
                       &disks_interval_updater);
 
 
-    check_button = GTK_CHECK_BUTTON (gtk_builder_get_object (builder, "all_devices_check"));
+    check_switch = GTK_SWITCH (gtk_builder_get_object (builder, "all_devices_check"));
     g_settings_bind (app->settings->gobj (), GSM_SETTING_SHOW_ALL_FS,
-                     check_button, "active",
+                     check_switch, "active",
                      G_SETTINGS_BIND_DEFAULT);
 
     create_field_page (builder, GTK_TREE_VIEW (app->disk_list), "disktreenew");


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