summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefano Karapetsas <[email protected]>2013-04-12 17:30:09 +0200
committerStefano Karapetsas <[email protected]>2013-04-12 17:30:09 +0200
commit0491e02f9023ec71a12c3b873b7f60e40b01c8fc (patch)
tree0068960534bbef524e33815e160343e1132d73e8
parentaa058adbb8181a301882d82cd215da9752c77c49 (diff)
downloadcaja-0491e02f9023ec71a12c3b873b7f60e40b01c8fc.tar.bz2
caja-0491e02f9023ec71a12c3b873b7f60e40b01c8fc.tar.xz
Fix radio buttons and GSettings in preferences window
Closes: https://github.com/mate-desktop/mate-file-manager/issues/104 Patch from: https://git.gnome.org/browse/nautilus/commit/?id=f200bfb
-rw-r--r--src/caja-file-management-properties.c80
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);
}
}