[gnome-utils/gsettings-tutorial: 4/22] [gsettings-tutorial] Bind the toolbar visibility to the setting key



commit 7099c866f078a7aacb7bd4d71e7e48dd1f260b86
Author: Vincent Untz <vuntz gnome org>
Date:   Fri Apr 16 15:13:12 2010 -0400

    [gsettings-tutorial] Bind the toolbar visibility to the setting key
    
    g_settings_bind() lets us bind a key from GSettings to the property of
    an object. In this example, we bind a boolean key to the visibility of a
    widget. Note that this lets us remove some non-interesting code.
    
    A few notes:
    
      + g_settings_bind() is able to map between the usual types (since a
        value in GSettings has a GVariantType and the property has a GType).
        So for most standard cases, it just works. If this is not enough,
        g_settings_bind_with_mapping() can be used to specify functions to
        do the mapping.

 baobab/src/baobab.c    |   30 +++++++++---------------------
 baobab/src/baobab.h    |    2 +-
 baobab/src/callbacks.c |    1 -
 3 files changed, 10 insertions(+), 23 deletions(-)
---
diff --git a/baobab/src/baobab.c b/baobab/src/baobab.c
index 18c9e7c..4da7b59 100644
--- a/baobab/src/baobab.c
+++ b/baobab/src/baobab.c
@@ -516,21 +516,6 @@ baobab_is_excluded_location (GFile *file)
 }
 
 void
-set_toolbar_visible (gboolean visible)
-{
-	GtkToggleAction *action;
-
-	if (visible)
-		gtk_widget_show (baobab.toolbar);
-	else
-		gtk_widget_hide (baobab.toolbar);
-
-	/* make sure the check menu item is consistent */
-	action = GTK_TOGGLE_ACTION (gtk_builder_get_object (baobab.main_ui, "view_tb"));
-	gtk_toggle_action_set_active (action, visible);
-}
-
-void
 set_statusbar_visible (gboolean visible)
 {
 	GtkToggleAction *action;
@@ -641,12 +626,6 @@ baobab_create_toolbar (void)
 			  G_CALLBACK (toolbar_reconfigured_cb), baobab.spinner);
 	toolbar_reconfigured_cb (item, GEDIT_SPINNER (baobab.spinner));
 	baobab_toolbar_style (NULL, 0, NULL, NULL);
-
-	visible = gconf_client_get_bool (baobab.gconf_client,
-					 BAOBAB_TOOLBAR_VISIBLE_KEY,
-					 NULL);
-
-	set_toolbar_visible (visible);
 }
 
 static void
@@ -856,6 +835,13 @@ baobab_init (void)
 							    NULL);
 
 	monitor_home_dir ();
+
+	/* GSettings */
+	baobab.settings_ui = g_settings_new ("org.gnome.baobab.ui");
+
+	g_settings_bind (baobab.settings_ui, "toolbar_visible",
+			 baobab.toolbar, "visible",
+			 G_SETTINGS_BIND_DEFAULT);
 }
 
 static void
@@ -878,6 +864,8 @@ baobab_shutdown (void)
 
 	if (baobab.gconf_client)
 		g_object_unref (baobab.gconf_client);
+	if (baobab.settings_ui)
+		g_object_unref (baobab.settings_ui);
 }
 
 static void
diff --git a/baobab/src/baobab.h b/baobab/src/baobab.h
index 9e9a214..701b8aa 100644
--- a/baobab/src/baobab.h
+++ b/baobab/src/baobab.h
@@ -83,6 +83,7 @@ struct _baobab_application {
 	char *selected_path;
 
 	GConfClient *gconf_client;
+	GSettings *settings_ui;
 	gint model_max_depth;
 };
 
@@ -117,7 +118,6 @@ void fill_model (struct chan_data *);
 void first_row (void);
 gboolean baobab_is_excluded_location (GFile *);
 void baobab_set_excluded_locations (GSList *);
-void set_toolbar_visible (gboolean visible);
 void set_statusbar_visible (gboolean visible);
 void set_statusbar (const gchar *);
 
diff --git a/baobab/src/callbacks.c b/baobab/src/callbacks.c
index 653b62a..d13ffca 100644
--- a/baobab/src/callbacks.c
+++ b/baobab/src/callbacks.c
@@ -275,7 +275,6 @@ on_view_tb_activate (GtkToggleAction *action,
 	gboolean visible;
 
 	visible = gtk_toggle_action_get_active (action);
-	set_toolbar_visible (visible);
 
 	gconf_client_set_bool (baobab.gconf_client,
 			       BAOBAB_TOOLBAR_VISIBLE_KEY,



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