[gnome-software: 2/5] prefs-dialog: Make it a HdyPreferencesWindow




commit a88eab1ddbd31637b262188b108651e71c9fa4c3
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Fri Jul 23 13:51:50 2021 +0200

    prefs-dialog: Make it a HdyPreferencesWindow
    
    This makes it in line with other GNOME preferences dialogs, and makes
    the code simpler. This also makes it work on smartphones.

 src/gs-prefs-dialog.c  |  16 +++--
 src/gs-prefs-dialog.h  |   3 +-
 src/gs-prefs-dialog.ui | 157 ++++++++++++-------------------------------------
 src/gs-shell.c         |   4 --
 4 files changed, 46 insertions(+), 134 deletions(-)
---
diff --git a/src/gs-prefs-dialog.c b/src/gs-prefs-dialog.c
index 51191a791..d34699899 100644
--- a/src/gs-prefs-dialog.c
+++ b/src/gs-prefs-dialog.c
@@ -19,16 +19,16 @@
 
 struct _GsPrefsDialog
 {
-       GtkDialog        parent_instance;
-       GSettings       *settings;
+       HdyPreferencesWindow     parent_instance;
+       GSettings               *settings;
 
-       GCancellable    *cancellable;
-       GsPluginLoader  *plugin_loader;
-       GtkWidget       *switch_updates;
-       GtkWidget       *switch_updates_notify;
+       GCancellable            *cancellable;
+       GsPluginLoader          *plugin_loader;
+       GtkWidget               *switch_updates;
+       GtkWidget               *switch_updates_notify;
 };
 
-G_DEFINE_TYPE (GsPrefsDialog, gs_prefs_dialog, GTK_TYPE_DIALOG)
+G_DEFINE_TYPE (GsPrefsDialog, gs_prefs_dialog, HDY_TYPE_PREFERENCES_WINDOW)
 
 static void
 gs_prefs_dialog_dispose (GObject *object)
@@ -79,9 +79,7 @@ gs_prefs_dialog_new (GtkWindow *parent, GsPluginLoader *plugin_loader)
 {
        GsPrefsDialog *dialog;
        dialog = g_object_new (GS_TYPE_PREFS_DIALOG,
-                              "use-header-bar", TRUE,
                               "transient-for", parent,
-                              "modal", TRUE,
                               NULL);
        dialog->plugin_loader = g_object_ref (plugin_loader);
        return GTK_WIDGET (dialog);
diff --git a/src/gs-prefs-dialog.h b/src/gs-prefs-dialog.h
index 27fb9559c..f25b30255 100644
--- a/src/gs-prefs-dialog.h
+++ b/src/gs-prefs-dialog.h
@@ -9,6 +9,7 @@
 #pragma once
 
 #include <gtk/gtk.h>
+#include <handy.h>
 
 #include "gnome-software-private.h"
 
@@ -16,7 +17,7 @@ G_BEGIN_DECLS
 
 #define GS_TYPE_PREFS_DIALOG (gs_prefs_dialog_get_type ())
 
-G_DECLARE_FINAL_TYPE (GsPrefsDialog, gs_prefs_dialog, GS, PREFS_DIALOG, GtkDialog)
+G_DECLARE_FINAL_TYPE (GsPrefsDialog, gs_prefs_dialog, GS, PREFS_DIALOG, HdyPreferencesWindow)
 
 GtkWidget      *gs_prefs_dialog_new            (GtkWindow      *parent,
                                                 GsPluginLoader *plugin_loader);
diff --git a/src/gs-prefs-dialog.ui b/src/gs-prefs-dialog.ui
index bdf989c0d..905ce716f 100644
--- a/src/gs-prefs-dialog.ui
+++ b/src/gs-prefs-dialog.ui
@@ -1,131 +1,48 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <requires lib="gtk+" version="3.10"/>
-  <template class="GsPrefsDialog" parent="GtkDialog">
+  <template class="GsPrefsDialog" parent="HdyPreferencesWindow">
     <property name="title" translatable="yes">Update Preferences</property>
-    <property name="modal">True</property>
-    <property name="destroy_with_parent">True</property>
-    <property name="type_hint">dialog</property>
-    <property name="resizable">False</property>
-    <property name="skip_taskbar_hint">True</property>
-    <property name="use_header_bar">1</property>
-    <child internal-child="headerbar">
-      <object class="GtkHeaderBar">
-        <child type="title">
-          <object class="GtkLabel" id="label_header">
-            <property name="visible">True</property>
-            <property name="label" translatable="yes">Update Preferences</property>
-            <property name="selectable">False</property>
-            <style>
-              <class name="title"/>
-            </style>
-          </object>
-        </child>
-      </object>
-    </child>
-    <child internal-child="vbox">
-      <object class="GtkBox" id="dialog-vbox1">
-        <property name="visible">True</property>
-        <property name="orientation">vertical</property>
-        <child>
-      <object class="GtkGrid">
+    <property name="default_width">610</property>
+    <property name="default_height">300</property>
+    <property name="search_enabled">False</property>
+    <child>
+      <object class="HdyPreferencesPage">
         <property name="visible">True</property>
-        <property name="margin_top">24</property>
-        <property name="margin_bottom">24</property>
-        <property name="margin_start">33</property>
-        <property name="margin_end">33</property>
-        <property name="row_spacing">6</property>
-        <property name="column_spacing">27</property>
-        <child>
-          <object class="GtkLabel">
-            <property name="visible">True</property>
-            <property name="halign">start</property>
-            <property name="label" translatable="yes">Automatic Updates</property>
-            <attributes>
-              <attribute name="weight" value="bold"/>
-            </attributes>
-          </object>
-          <packing>
-            <property name="left_attach">0</property>
-            <property name="top_attach">0</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkSwitch" id="switch_updates">
-            <property name="visible">True</property>
-            <property name="can_focus">True</property>
-            <property name="halign">end</property>
-            <property name="valign">start</property>
-          </object>
-          <packing>
-            <property name="left_attach">1</property>
-            <property name="top_attach">0</property>
-          </packing>
-        </child>
         <child>
-          <object class="GtkLabel">
+          <object class="HdyPreferencesGroup">
             <property name="visible">True</property>
-            <property name="halign">start</property>
-            <property name="margin_bottom">15</property>
-            <property name="label" translatable="yes">Automatic updates are disabled when on mobile or 
metered connections.</property>
-            <property name="wrap">True</property>
-            <property name="width_chars">28</property>
-            <property name="max_width_chars">28</property>
-            <property name="xalign">0</property>
-            <style>
-              <class name="dim-label"/>
-            </style>
+            <child>
+              <object class="HdyActionRow">
+                <property name="visible">True</property>
+                <property name="title" translatable="yes">Automatic Updates</property>
+                <property name="subtitle" translatable="yes">Automatic updates are disabled when on mobile 
or metered connections.</property>
+                <property name="subtitle_lines">0</property>
+                <property name="activatable_widget">switch_updates</property>
+                <child>
+                  <object class="GtkSwitch" id="switch_updates">
+                    <property name="visible">True</property>
+                    <property name="valign">center</property>
+                  </object>
+                </child>
+              </object>
+            </child>
+            <child>
+              <object class="HdyActionRow">
+                <property name="visible">True</property>
+                <property name="title" translatable="yes">Automatic Update Notifications</property>
+                <property name="subtitle" translatable="yes">Show notifications when updates have been 
automatically installed.</property>
+                <property name="subtitle_lines">0</property>
+                <property name="activatable_widget">switch_updates_notify</property>
+                <child>
+                  <object class="GtkSwitch" id="switch_updates_notify">
+                    <property name="visible">True</property>
+                    <property name="valign">center</property>
+                  </object>
+                </child>
+              </object>
+            </child>
           </object>
-          <packing>
-            <property name="left_attach">0</property>
-            <property name="top_attach">1</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkLabel">
-            <property name="visible">True</property>
-            <property name="halign">start</property>
-            <property name="label" translatable="yes">Automatic Update Notifications</property>
-            <attributes>
-              <attribute name="weight" value="bold"/>
-            </attributes>
-          </object>
-          <packing>
-            <property name="left_attach">0</property>
-            <property name="top_attach">2</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkLabel">
-            <property name="visible">True</property>
-            <property name="halign">start</property>
-            <property name="label" translatable="yes">Show notifications when updates have been 
automatically installed.</property>
-            <property name="wrap">True</property>
-            <property name="width_chars">28</property>
-            <property name="max_width_chars">28</property>
-            <property name="xalign">0</property>
-            <style>
-              <class name="dim-label"/>
-            </style>
-          </object>
-          <packing>
-            <property name="left_attach">0</property>
-            <property name="top_attach">3</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkSwitch" id="switch_updates_notify">
-            <property name="visible">True</property>
-            <property name="can_focus">True</property>
-            <property name="halign">end</property>
-            <property name="valign">start</property>
-          </object>
-          <packing>
-            <property name="left_attach">1</property>
-            <property name="top_attach">2</property>
-          </packing>
-        </child>
-      </object>
         </child>
       </object>
     </child>
diff --git a/src/gs-shell.c b/src/gs-shell.c
index 24b43d12b..93fc4b77f 100644
--- a/src/gs-shell.c
+++ b/src/gs-shell.c
@@ -2262,10 +2262,6 @@ gs_shell_show_prefs (GsShell *shell)
 
        dialog = gs_prefs_dialog_new (GTK_WINDOW (shell), shell->plugin_loader);
        gs_shell_modal_dialog_present (shell, GTK_WINDOW (dialog));
-
-       /* just destroy */
-       g_signal_connect_swapped (dialog, "response",
-                                 G_CALLBACK (gtk_widget_destroy), dialog);
 }
 
 void


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