[seahorse/prefs-hdy-window] prefs: Migrate to HdyPreferencesWindow




commit 08e5c48ecc8d68a71559a93afb4222e68bf438c1
Author: Niels De Graef <nielsdegraef gmail com>
Date:   Sun Feb 21 14:15:14 2021 +0100

    prefs: Migrate to HdyPreferencesWindow

 common/meson.build                  |  1 +
 common/prefs-keyservers.vala        |  4 +-
 common/prefs.vala                   | 62 ++------------------------
 common/seahorse-prefs-keyservers.ui | 86 ++++++++++++++-----------------------
 common/seahorse-prefs.ui            | 27 ------------
 data/seahorse.gresource.xml         |  1 -
 pgp/seahorse-keyserver-sync.c       |  2 +-
 src/application.vala                |  3 +-
 8 files changed, 42 insertions(+), 144 deletions(-)
---
diff --git a/common/meson.build b/common/meson.build
index 0b520dcd..52e57c8a 100644
--- a/common/meson.build
+++ b/common/meson.build
@@ -32,6 +32,7 @@ common_deps = [
   gtk,
   gcr,
   gcr_ui,
+  libhandy_dep,
   config,
 ]
 
diff --git a/common/prefs-keyservers.vala b/common/prefs-keyservers.vala
index 89d101b8..adc1ed4d 100644
--- a/common/prefs-keyservers.vala
+++ b/common/prefs-keyservers.vala
@@ -19,7 +19,7 @@
  */
 
 [GtkTemplate (ui = "/org/gnome/Seahorse/seahorse-prefs-keyservers.ui")]
-public class Seahorse.PrefsKeyservers : Gtk.Box {
+public class Seahorse.PrefsKeyservers : Hdy.PreferencesPage {
 
     [GtkChild]
     public unowned Gtk.Grid keyserver_tab;
@@ -34,7 +34,7 @@ public class Seahorse.PrefsKeyservers : Gtk.Box {
     [GtkChild]
     private unowned Gtk.CheckButton auto_sync;
 
-    public PrefsKeyservers(Gtk.Window? parent) {
+    public PrefsKeyservers() {
         var model = Pgp.Backend.get().get_remotes();
         this.keyservers_list.bind_model(model, (item) => {
             return new KeyServerRow(item as ServerSource);
diff --git a/common/prefs.vala b/common/prefs.vala
index e1b681ab..cd0c8e74 100644
--- a/common/prefs.vala
+++ b/common/prefs.vala
@@ -18,45 +18,24 @@
  * <http://www.gnu.org/licenses/>.
  */
 
-public class Seahorse.Prefs : Gtk.Dialog {
-
-    private Gtk.Notebook notebook;
+public class Seahorse.Prefs : Hdy.PreferencesWindow {
 
     /**
      * Create a new preferences window.
      *
      * @param parent The Gtk.Window to set as the preferences dialog's parent
      */
-    public Prefs(Gtk.Window? parent, string? tabid = null) {
+    public Prefs(Gtk.Window? parent) {
         GLib.Object (
             title: _("Preferences"),
             transient_for: parent,
+            search_enabled: false,
             modal: true
         );
 
-        var builder = new Gtk.Builder();
-        try {
-            string path = "/org/gnome/Seahorse/seahorse-prefs.ui";
-            builder.add_from_resource(path);
-        } catch (GLib.Error err) {
-            GLib.critical("%s", err.message);
-        }
-        Gtk.Box content = (Gtk.Box) builder.get_object("prefs");
-        get_content_area().border_width = 0;
-        get_content_area().add(content);
-        this.notebook = (Gtk.Notebook) builder.get_object("notebook");
-
 #if WITH_KEYSERVER
-        var keyservers = new PrefsKeyservers(this);
-        var label = new Gtk.Label("Keyservers");
-        add_tab(label, keyservers);
+        add (new PrefsKeyservers());
 #endif
-
-        if (tabid != null) {
-            Gtk.Widget? tab = builder.get_object(tabid) as Gtk.Widget;
-            if (tab != null)
-                select_tab(tab);
-        }
     }
 
     public static bool available() {
@@ -66,37 +45,4 @@ public class Seahorse.Prefs : Gtk.Dialog {
         return false;
 #endif
     }
-
-    /**
-     * Add a tab to the preferences window
-     *
-     * @param label Label for the tab to be added
-     * @param tab Tab to be added
-     */
-    public void add_tab(Gtk.Widget? label, Gtk.Widget? tab) {
-        label.show();
-        this.notebook.prepend_page(tab, label);
-    }
-
-    /**
-     * Sets the input tab to be the active one
-     *
-     * @param tab The tab to be set active
-     */
-    public void select_tab(Gtk.Widget? tab) {
-        int pos = this.notebook.page_num(tab);
-        if (pos != -1)
-            this.notebook.set_current_page(pos);
-    }
-
-    /**
-     * Removes a tab from the preferences window
-     *
-     * @tab: The tab to be removed
-     */
-    public void remove_tab(Gtk.Widget? tab) {
-        int pos = this.notebook.page_num(tab);
-        if (pos != -1)
-            this.notebook.remove_page(pos);
-    }
 }
diff --git a/common/seahorse-prefs-keyservers.ui b/common/seahorse-prefs-keyservers.ui
index 40860fd9..4b47cc7e 100644
--- a/common/seahorse-prefs-keyservers.ui
+++ b/common/seahorse-prefs-keyservers.ui
@@ -1,79 +1,59 @@
 <?xml version="1.0"?>
 <interface>
   <requires lib="gtk+" version="3.24"/>
-  <template class="SeahorsePrefsKeyservers" parent="GtkBox">
+  <template class="SeahorsePrefsKeyservers" parent="HdyPreferencesPage">
     <property name="visible">True</property>
+    <property name="title" translatable="yes">Keyservers</property>
     <child>
-      <object class="GtkBox">
+      <object class="HdyPreferencesGroup">
         <property name="visible">True</property>
-        <property name="orientation">vertical</property>
-        <property name="border_width">12</property>
-        <property name="spacing">6</property>
+        <property name="title" translatable="yes">Keyservers</property>
         <child>
           <object class="GtkBox">
             <property name="visible">True</property>
-            <property name="orientation">horizontal</property>
+            <property name="orientation">vertical</property>
+            <property name="spacing">6</property>
             <child>
-              <object class="GtkLabel">
+              <object class="GtkScrolledWindow">
                 <property name="visible">True</property>
-                <property name="xalign">0</property>
-                <property name="hexpand">true</property>
-                <property name="label" translatable="yes">Keyservers</property>
-                <property name="use_underline">True</property>
-                <attributes>
-                  <attribute name="weight" value="bold"/>
-                </attributes>
+                <property name="can_focus">True</property>
+                <property name="hscrollbar_policy">never</property>
+                <property name="vscrollbar_policy">automatic</property>
+                <property name="propagate-natural-height">True</property>
+                <property name="max-content-height">300</property>
+                <child>
+                  <object class="GtkListBox" id="keyservers_list">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="hexpand">True</property>
+                    <style>
+                      <class name="content"/>
+                    </style>
+                  </object>
+                </child>
               </object>
             </child>
             <child>
               <object class="GtkButton" id="keyserver_add_button">
                 <property name="visible">True</property>
                 <property name="halign">end</property>
-                <property name="tooltip-text" translatable="yes">Add a new keyserver</property>
+                <property name="label" translatable="yes">Add keyserver</property>
                 <signal name="clicked" handler="on_add_button_clicked"/>
-                <child>
-                  <object class="GtkImage">
-                    <property name="visible">True</property>
-                    <property name="icon-name">list-add-symbolic</property>
-                  </object>
-                </child>
-                <style>
-                  <class name="image-button"/>
-                  <class name="flat"/>
-                </style>
               </object>
             </child>
           </object>
         </child>
+      </object>
+    </child>
+    <child>
+      <object class="HdyPreferencesGroup">
+        <property name="visible">True</property>
+        <property name="title" translatable="yes">Synchronization</property>
         <child>
           <object class="GtkGrid" id="keyserver_tab">
             <property name="visible">True</property>
             <property name="column_spacing">12</property>
             <property name="row_spacing">12</property>
-            <child>
-              <object class="GtkScrolledWindow" id="scrolledwindow1">
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="hscrollbar_policy">never</property>
-                <property name="vscrollbar_policy">automatic</property>
-                <property name="min-content-height">200</property>
-                <child>
-                  <object class="GtkListBox" id="keyservers_list">
-                    <property name="visible">True</property>
-                    <property name="can_focus">True</property>
-                    <property name="hexpand">True</property>
-                    <style>
-                      <class name="content"/>
-                    </style>
-                  </object>
-                </child>
-              </object>
-              <packing>
-                <property name="top_attach">0</property>
-                <property name="left_attach">0</property>
-                <property name="width">2</property>
-              </packing>
-            </child>
             <child>
               <object class="GtkLabel" id="keyserver_publish_to_label">
                 <property name="visible">True</property>
@@ -82,7 +62,7 @@
                 <property name="use_underline">True</property>
               </object>
               <packing>
-                <property name="top_attach">1</property>
+                <property name="top_attach">0</property>
                 <property name="left_attach">0</property>
               </packing>
             </child>
@@ -95,7 +75,7 @@
                 </child>
               </object>
               <packing>
-                <property name="top_attach">1</property>
+                <property name="top_attach">0</property>
                 <property name="left_attach">1</property>
               </packing>
             </child>
@@ -109,7 +89,7 @@
                 <property name="draw_indicator">True</property>
               </object>
               <packing>
-                <property name="top_attach">2</property>
+                <property name="top_attach">1</property>
                 <property name="left_attach">0</property>
                 <property name="width">2</property>
               </packing>
@@ -124,7 +104,7 @@
                 <property name="draw_indicator">True</property>
               </object>
               <packing>
-                <property name="top_attach">3</property>
+                <property name="top_attach">2</property>
                 <property name="left_attach">0</property>
                 <property name="width">2</property>
               </packing>
diff --git a/data/seahorse.gresource.xml b/data/seahorse.gresource.xml
index 6156a971..d389d25a 100644
--- a/data/seahorse.gresource.xml
+++ b/data/seahorse.gresource.xml
@@ -7,7 +7,6 @@
 
     <!-- Common -->
     <file alias="seahorse-add-keyserver.ui" 
preprocess="xml-stripblanks">../common/seahorse-add-keyserver.ui</file>
-    <file alias="seahorse-prefs.ui" preprocess="xml-stripblanks">../common/seahorse-prefs.ui</file>
     <file alias="seahorse-prefs-keyservers.ui" 
preprocess="xml-stripblanks">../common/seahorse-prefs-keyservers.ui</file>
 
     <!-- Seahorse -->
diff --git a/pgp/seahorse-keyserver-sync.c b/pgp/seahorse-keyserver-sync.c
index 9da86211..4cbd9214 100644
--- a/pgp/seahorse-keyserver-sync.c
+++ b/pgp/seahorse-keyserver-sync.c
@@ -94,7 +94,7 @@ on_sync_ok_clicked (GtkButton *button, SeahorseWidget *swidget)
 G_MODULE_EXPORT void
 on_sync_configure_clicked (GtkButton *button, SeahorseWidget *swidget)
 {
-    SeahorsePrefs *prefs_dialog = seahorse_prefs_new (GTK_WINDOW (seahorse_widget_get_widget (swidget, 
swidget->name)), "keyserver-tab");
+    SeahorsePrefs *prefs_dialog = seahorse_prefs_new (GTK_WINDOW (seahorse_widget_get_widget (swidget, 
swidget->name)));
     gtk_dialog_run (GTK_DIALOG (prefs_dialog));
     gtk_widget_destroy (GTK_WIDGET (prefs_dialog));
 }
diff --git a/src/application.vala b/src/application.vala
index bcfaacc7..40bcf366 100644
--- a/src/application.vala
+++ b/src/application.vala
@@ -194,7 +194,6 @@ public class Seahorse.Application : Gtk.Application {
 
     private void on_app_preferences(SimpleAction action, Variant? param) {
         Prefs prefs_dialog = new Prefs(this.key_mgr);
-        prefs_dialog.run();
-        prefs_dialog.destroy();
+        prefs_dialog.present();
     }
 }


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