[baobab] Rework settings handling



commit f51c40c038ea75066693e243cf8bc8b238318c63
Author: Stefano Facchini <stefano facchini gmail com>
Date:   Fri Sep 29 11:39:56 2017 +0200

    Rework settings handling
    
    Use GtkWindow::get_size() instead of configure event to store window size.
    (See https://wiki.gnome.org/HowDoI/SaveWindowState).
    
    Don't use globals for GSettings objects.

 src/baobab-application.vala |   15 +--------------
 src/baobab-window.vala      |   11 ++++++++---
 2 files changed, 9 insertions(+), 17 deletions(-)
---
diff --git a/src/baobab-application.vala b/src/baobab-application.vala
index 0e004e7..97e7da8 100644
--- a/src/baobab-application.vala
+++ b/src/baobab-application.vala
@@ -33,9 +33,6 @@ namespace Baobab {
             { "quit", on_quit_activate }
         };
 
-        public Settings prefs_settings { get; private set; }
-        public Settings ui_settings { get; private set; }
-
         protected override void activate () {
             new Window (this);
         }
@@ -61,6 +58,7 @@ namespace Baobab {
             excluded_locations.add (home.get_child (".gvfs"));
 
             var root = File.new_for_path ("/");
+            var prefs_settings = new Settings ("org.gnome.baobab.preferences");
             foreach (var uri in prefs_settings.get_value ("excluded-uris")) {
                 var file = File.new_for_uri ((string) uri);
                 if (!file.equal (root)) {
@@ -84,12 +82,6 @@ namespace Baobab {
             }
             Gtk.StyleContext.add_provider_for_screen (Gdk.Screen.get_default (), css_provider, 
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
 
-            // Settings
-            ui_settings = new Settings ("org.gnome.baobab.ui");
-            prefs_settings = new Settings ("org.gnome.baobab.preferences");
-
-            ui_settings.delay ();
-
             set_accels_for_action ("win.gear-menu", { "F10" });
             set_accels_for_action ("win.reload", { "<Primary>r" });
         }
@@ -103,11 +95,6 @@ namespace Baobab {
             return -1; 
         }
 
-        protected override void shutdown () {
-            ui_settings.apply ();
-            base.shutdown ();
-        }
-
         public Application () {
             Object (application_id: "org.gnome.baobab", flags: ApplicationFlags.HANDLES_OPEN);
 
diff --git a/src/baobab-window.vala b/src/baobab-window.vala
index 982eb04..bbb45c4 100644
--- a/src/baobab-window.vala
+++ b/src/baobab-window.vala
@@ -24,7 +24,6 @@ namespace Baobab {
 
     [GtkTemplate (ui = "/org/gnome/baobab/ui/baobab-main-window.ui")]
     public class Window : Gtk.ApplicationWindow {
-        private Settings ui_settings;
         [GtkChild]
         private Gtk.Box vbox;
         [GtkChild]
@@ -121,7 +120,8 @@ namespace Baobab {
                 busy_cursor = new Gdk.Cursor.for_display (get_display(), Gdk.CursorType.WATCH);
             }
 
-            ui_settings = Application.get_default ().ui_settings;
+            var ui_settings = new Settings ("org.gnome.baobab.ui");
+            ui_settings.delay ();
 
             add_action_entries (action_entries, this);
             var action = ui_settings.create_action ("active-chart");
@@ -160,11 +160,16 @@ namespace Baobab {
 
             configure_event.connect ((event) => {
                 if (!(Gdk.WindowState.MAXIMIZED in get_window ().get_state ())) {
-                    ui_settings.set ("window-size", "(ii)", event.width, event.height);
+                    get_size (out width, out height);
+                    ui_settings.set ("window-size", "(ii)", width, height);
                 }
                 return false;
             });
 
+            destroy.connect (() => {
+                ui_settings.apply ();
+            });
+
             active_location = null;
             scan_completed_handler = 0;
 


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