From 702d06c8f82f5f584ad6f03225e0b1b088f8dc6a Mon Sep 17 00:00:00 2001 From: Rachel Hestilow Date: Mon, 22 Apr 2002 01:26:59 +0000 Subject: [PATCH] Add in an explicit 'use_nick' parameter. Implicit guessing can break badly 2002-04-21 Rachel Hestilow * gconf-property-editor.c (gconf_peditor_new_select_menu_with_enum, gconf_peditor_new_enum_toggle, gconf_peditor_new_select_radio_with_enum): Add in an explicit 'use_nick' parameter. Implicit guessing can break badly if the gconf data gets corrupted. (peditor_enum_int_from_string): Change use_nick to copy-by-value, do not try to guess it. (peditor_enum_conv_to_widget, guard_get_bool, peditor_enum_toggle_conv_to_widget): Do not pass in use_nick as a reference. --- capplets/common/ChangeLog | 14 +++++++++++ capplets/common/gconf-property-editor.c | 33 +++++++++++++------------ capplets/common/gconf-property-editor.h | 3 +++ 3 files changed, 34 insertions(+), 16 deletions(-) diff --git a/capplets/common/ChangeLog b/capplets/common/ChangeLog index ad6ce3090..84943c561 100644 --- a/capplets/common/ChangeLog +++ b/capplets/common/ChangeLog @@ -1,3 +1,17 @@ +2002-04-21 Rachel Hestilow + + * gconf-property-editor.c + (gconf_peditor_new_select_menu_with_enum, + gconf_peditor_new_enum_toggle, + gconf_peditor_new_select_radio_with_enum): Add in an explicit + 'use_nick' parameter. Implicit guessing can break badly if + the gconf data gets corrupted. + (peditor_enum_int_from_string): Change use_nick to copy-by-value, + do not try to guess it. + (peditor_enum_conv_to_widget, guard_get_bool, + peditor_enum_toggle_conv_to_widget): Do not pass in use_nick + as a reference. + Thu Apr 18 17:56:25 2002 Jonathan Blandford * theme-common.c: Notify when the theme changes. diff --git a/capplets/common/gconf-property-editor.c b/capplets/common/gconf-property-editor.c index e98dcf535..6f1268bd9 100644 --- a/capplets/common/gconf-property-editor.c +++ b/capplets/common/gconf-property-editor.c @@ -663,28 +663,23 @@ gconf_peditor_new_color (GConfChangeSet *changeset, } static int -peditor_enum_int_from_string (GType type, const gchar *str, gboolean *use_nick) +peditor_enum_int_from_string (GType type, const gchar *str, gboolean use_nick) { GEnumClass *klass; GEnumValue *val; int ret = -1; - if (use_nick) - *use_nick = FALSE; - klass = g_type_class_ref (type); - val = g_enum_get_value_by_name (klass, str); - if (!val) - { + if (use_nick) val = g_enum_get_value_by_nick (klass, str); - if (use_nick) - *use_nick = TRUE; - } - if (val) - ret = val->value; - + else + val = g_enum_get_value_by_name (klass, str); + g_type_class_unref (klass); + if (val) + ret = val->value; + return ret; } @@ -725,7 +720,7 @@ peditor_enum_conv_to_widget (GConfPropertyEditor *peditor, index = peditor_enum_int_from_string (data->enum_type, gconf_value_get_string (value), - &data->use_nick); + data->use_nick); gconf_value_set_int (ret, index); @@ -826,6 +821,7 @@ gconf_peditor_new_select_menu_with_enum (GConfChangeSet *changeset, gchar *key, GtkWidget *option_menu, GType enum_type, + gboolean use_nick, gchar *first_property_name, ...) { @@ -840,6 +836,7 @@ gconf_peditor_new_select_menu_with_enum (GConfChangeSet *changeset, data = g_new0 (GConfPropertyEditorEnumData, 1); data->enum_type = enum_type; + data->use_nick = use_nick; va_start (var_args, first_property_name); @@ -1041,7 +1038,7 @@ guard_get_bool (GConfPropertyEditor *peditor, const GConfValue *value) else { GConfPropertyEditorEnumData *data = peditor->p->data; - int index = peditor_enum_int_from_string (data->enum_type, gconf_value_get_string (value), &data->use_nick); + int index = peditor_enum_int_from_string (data->enum_type, gconf_value_get_string (value), data->use_nick); return (index != data->enum_val_false); } } @@ -1285,7 +1282,7 @@ peditor_enum_toggle_conv_to_widget (GConfPropertyEditor *peditor, index = peditor_enum_int_from_string (data->enum_type, gconf_value_get_string (value), - &data->use_nick); + data->use_nick); gconf_value_set_bool (ret, (index != data->enum_val_false)); return ret; @@ -1323,6 +1320,7 @@ gconf_peditor_new_enum_toggle (GConfChangeSet *changeset, GType enum_type, GConfPEditorGetValueFn val_true_fn, guint val_false, + gboolean use_nick, gpointer data, gchar *first_property_name, ...) @@ -1340,6 +1338,7 @@ gconf_peditor_new_enum_toggle (GConfChangeSet *changeset, enum_data->enum_val_true_fn = val_true_fn; enum_data->enum_val_true_fn_data = data; enum_data->enum_val_false = val_false; + enum_data->use_nick = use_nick; va_start (var_args, first_property_name); @@ -1578,6 +1577,7 @@ gconf_peditor_new_select_radio_with_enum (GConfChangeSet *changeset, gchar *key, GSList *radio_group, GType enum_type, + gboolean use_nick, gchar *first_property_name, ...) { @@ -1594,6 +1594,7 @@ gconf_peditor_new_select_radio_with_enum (GConfChangeSet *changeset, enum_data = g_new0 (GConfPropertyEditorEnumData, 1); enum_data->enum_type = enum_type; + enum_data->use_nick = use_nick; first_button = GTK_RADIO_BUTTON (radio_group->data); diff --git a/capplets/common/gconf-property-editor.h b/capplets/common/gconf-property-editor.h index 993de71f0..c0e45cd91 100644 --- a/capplets/common/gconf-property-editor.h +++ b/capplets/common/gconf-property-editor.h @@ -78,6 +78,7 @@ GObject *gconf_peditor_new_enum_toggle (GConfChangeSet *changeset, GType enum_type, GConfPEditorGetValueFn val_true_fn, guint val_false, + gboolean use_nick, gpointer data, gchar *first_property_name, ...); @@ -109,6 +110,7 @@ GObject *gconf_peditor_new_select_menu_with_enum (GConfChangeSet *changeset, gchar *key, GtkWidget *option_menu, GType enum_type, + gboolean use_nick, gchar *first_property_name, ...); @@ -122,6 +124,7 @@ GObject *gconf_peditor_new_select_radio_with_enum (GConfChangeSet *changeset, gchar *key, GSList *radio_group, GType enum_type, + gboolean use_nick, gchar *first_property_name, ...);