[nautilus] preferences: use g_settings_bind_with_mapping() for radiobuttons



commit f200bfbe8332c0df74335f608f68350609e435d7
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Thu Apr 7 13:54:43 2011 -0400

    preferences: use g_settings_bind_with_mapping() for radiobuttons
    
    This also fixes radiobuttons preferences not being applied when opening
    the properties dialog.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=644478

 src/nautilus-file-management-properties.c |   80 ++++++++++------------------
 1 files changed, 29 insertions(+), 51 deletions(-)
---
diff --git a/src/nautilus-file-management-properties.c b/src/nautilus-file-management-properties.c
index b94918f..e7ff1c1 100644
--- a/src/nautilus-file-management-properties.c
+++ b/src/nautilus-file-management-properties.c
@@ -648,48 +648,38 @@ bind_builder_uint_enum (GtkBuilder *builder,
 				      binding, g_free);
 }
 
-typedef struct {
-	GtkWidget *button;
-	const char *value;
-	const char *key;
-	GSettings *settings;
-} RadioBinding;
-
-static void
-radio_binding_setting_changed (GSettings   *settings,
-			       const gchar *key,
-			       gpointer     user_data)
+static GVariant *
+radio_mapping_set (const GValue *gvalue,
+		   const GVariantType *expected_type,
+		   gpointer user_data)
 {
-	RadioBinding *binding = user_data;
-	char *value;
+	const gchar *widget_value = user_data;
+	GVariant *retval = NULL;
 
-	value = g_settings_get_string (settings, key);
-
-	if (strcmp (value, binding->value) == 0) {
-		/* This will unset the currently active, no need
-		   to do that manually */
-		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (binding->button), TRUE);
+	if (g_value_get_boolean (gvalue)) {
+		retval = g_variant_new_string (widget_value);
 	}
-	g_free (value);
-}
 
-static void
-radio_binding_button_toggled (GtkToggleButton *toggle_button,
-			      RadioBinding *binding)
-{
-	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (binding->button))) {
-		g_settings_set_string (binding->settings, binding->key, binding->value);
-	}
+	return retval;
 }
 
-static void
-free_radio_binding (gpointer	 data,
-		    GClosure	*closure)
+static gboolean
+radio_mapping_get (GValue *gvalue,
+		   GVariant *variant,
+		   gpointer user_data)
 {
-	RadioBinding *binding = data;
+	const gchar *widget_value = user_data;
+	const gchar *value;
 
-	g_object_unref (binding->settings);
-	g_free (binding);
+	value = g_variant_get_string (variant, NULL);
+
+	if (g_strcmp0 (value, widget_value) == 0) {
+		g_value_set_boolean (gvalue, TRUE);
+	} else {
+		g_value_set_boolean (gvalue, FALSE);
+	}
+
+	return TRUE;
 }
 
 static void
@@ -701,27 +691,15 @@ bind_builder_radio (GtkBuilder *builder,
 {
 	GtkWidget *button;
 	int i;
-	char *detailed_signal;
-	RadioBinding *binding;
-
-	detailed_signal = g_strdup_printf ("changed::%s", prefs);
 
 	for (i = 0; widget_names[i] != NULL; i++) {
 		button = GTK_WIDGET (gtk_builder_get_object (builder, widget_names[i]));
 
-		binding = g_new (RadioBinding, 1);
-		binding->button = button;
-		binding->value = values[i];
-		binding->key = prefs;
-		binding->settings = g_object_ref (settings);
-
-		g_signal_connect (settings, detailed_signal,
-				  G_CALLBACK(radio_binding_setting_changed),
-				  binding);
-
-		g_signal_connect_data (G_OBJECT (button), "toggled",
-				       G_CALLBACK (radio_binding_button_toggled),
-				       binding, free_radio_binding, 0);
+		g_settings_bind_with_mapping (settings, prefs,
+					      button, "active",
+					      G_SETTINGS_BIND_DEFAULT,
+					      radio_mapping_get, radio_mapping_set,
+					      (gpointer) values[i], NULL);
 	}
 }
 



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