diff options
Diffstat (limited to 'src/caja-file-management-properties.c')
-rw-r--r-- | src/caja-file-management-properties.c | 80 |
1 files changed, 28 insertions, 52 deletions
diff --git a/src/caja-file-management-properties.c b/src/caja-file-management-properties.c index 3db0d05b..1de79523 100644 --- a/src/caja-file-management-properties.c +++ b/src/caja-file-management-properties.c @@ -839,49 +839,37 @@ 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); + return retval; } -static void -radio_binding_button_toggled (GtkToggleButton *toggle_button, - RadioBinding *binding) +static gboolean +radio_mapping_get (GValue *gvalue, + GVariant *variant, + gpointer user_data) { - if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (binding->button))) { - g_settings_set_string (binding->settings, binding->key, binding->value); + const gchar *widget_value = user_data; + const gchar *value; + 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); } -} -static void -free_radio_binding (gpointer data, - GClosure *closure) -{ - RadioBinding *binding = data; - - g_object_unref (binding->settings); - g_free (binding); -} + return TRUE; + } static void bind_builder_radio (GtkBuilder *builder, @@ -892,27 +880,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); } } |