From 3cacd8d82090f6a275623830ab83fd4ce94d3940 Mon Sep 17 00:00:00 2001 From: Bradford Hovinen Date: Wed, 19 Dec 2001 14:53:59 +0000 Subject: [PATCH] Connect to value_changed signal 2001-12-19 Bradford Hovinen * gconf-property-editor.c (gconf_peditor_new_float_range) (gconf_peditor_new_int_range): Connect to value_changed signal * capplet-util.c: Comment out most of this file * gconf-property-editor.c (gconf_peditor_new_int_range): Convert to ~_float_range (gconf_peditor_new_float_range): Add callbacks for conversion between widget's values and GConf values in the signature (peditor_float_range_widget_changed): Issue callback, if available, to convert from widget's values to GConf values (peditor_float_range_value_changed): Vice verca above (gconf_peditor_new_int_range, peditor_int_range_widget_changed) (peditor_int_range_value_changed): Implement. Copy from float versions --- capplets/common/ChangeLog | 18 ++++ capplets/common/capplet-util.c | 8 ++ capplets/common/gconf-property-editor.c | 123 ++++++++++++++++++++++-- capplets/common/gconf-property-editor.h | 57 ++++++----- 4 files changed, 174 insertions(+), 32 deletions(-) diff --git a/capplets/common/ChangeLog b/capplets/common/ChangeLog index cd0414785..be68d13ee 100644 --- a/capplets/common/ChangeLog +++ b/capplets/common/ChangeLog @@ -1,3 +1,21 @@ +2001-12-19 Bradford Hovinen + + * gconf-property-editor.c (gconf_peditor_new_float_range) + (gconf_peditor_new_int_range): Connect to value_changed signal + + * capplet-util.c: Comment out most of this file + + * gconf-property-editor.c (gconf_peditor_new_int_range): Convert + to ~_float_range + (gconf_peditor_new_float_range): Add callbacks for conversion + between widget's values and GConf values in the signature + (peditor_float_range_widget_changed): Issue callback, if + available, to convert from widget's values to GConf values + (peditor_float_range_value_changed): Vice verca above + (gconf_peditor_new_int_range, peditor_int_range_widget_changed) + (peditor_int_range_value_changed): Implement. Copy from float + versions + 2001-12-18 Bradford Hovinen * capplet-util.h: Don't #include bonobo*.h diff --git a/capplets/common/capplet-util.c b/capplets/common/capplet-util.c index 0a788d79d..bc1e5f15f 100644 --- a/capplets/common/capplet-util.c +++ b/capplets/common/capplet-util.c @@ -40,6 +40,8 @@ static SetupPropertyEditorsFn setup_property_editors_cb = NULL; static GConfChangeSet *changeset; +#if 0 + /* apply_cb * * Callback issued when the user clicks "Apply" or "Ok". This function is @@ -171,6 +173,8 @@ get_property_name (const gchar *binary) return res; } +#endif + /* setup_session_mgmt * * Make sure the capplet launches and applies its settings next time the user @@ -218,6 +222,8 @@ setup_session_mgmt (const gchar *binary_name) #endif } +#if 0 + /* capplet_init -- see documentation in capplet-util.h */ @@ -282,3 +288,5 @@ capplet_init (int argc, gconf_change_set_unref (changeset); } } + +#endif diff --git a/capplets/common/gconf-property-editor.c b/capplets/common/gconf-property-editor.c index c9fc7a3f4..ade3f4b03 100644 --- a/capplets/common/gconf-property-editor.c +++ b/capplets/common/gconf-property-editor.c @@ -529,34 +529,55 @@ gconf_peditor_new_select_radio (GConfChangeSet *changeset, gchar *key, GSList *r } static void -peditor_int_range_value_changed (GConfClient *client, guint cnxn_id, GConfEntry *entry, GConfPropertyEditor *peditor) +peditor_float_range_value_changed (GConfClient *client, guint cnxn_id, GConfEntry *entry, GConfPropertyEditor *peditor) { GConfValue *value; GtkAdjustment *adjustment; + GConfPEditorValueConvFn to_widget_cb; + gfloat value_f; + + to_widget_cb = g_object_get_data (G_OBJECT (peditor), "to-widget-cb"); gconf_change_set_remove (peditor->p->changeset, peditor->p->key); value = gconf_entry_get_value (entry); if (value != NULL) { + value_f = gconf_value_get_float (value); + + if (to_widget_cb != NULL) + value_f = to_widget_cb (value_f); + adjustment = g_object_get_data (G_OBJECT (peditor), "adjustment"); - gtk_adjustment_set_value (adjustment, gconf_value_get_int (value)); + gtk_adjustment_set_value (adjustment, value_f); } } static void -peditor_int_range_widget_changed (GConfPropertyEditor *peditor, GtkAdjustment *adjustment) +peditor_float_range_widget_changed (GConfPropertyEditor *peditor, GtkAdjustment *adjustment) { GConfValue *value; + gfloat value_f; + GConfPEditorValueConvFn from_widget_cb; - gconf_change_set_set_int (peditor->p->changeset, peditor->p->key, - gtk_adjustment_get_value (adjustment)); + from_widget_cb = g_object_get_data (G_OBJECT (peditor), "from-widget-cb"); + + value_f = gtk_adjustment_get_value (adjustment); + + if (from_widget_cb != NULL) + value_f = from_widget_cb (value_f); + + gconf_change_set_set_float (peditor->p->changeset, peditor->p->key, value_f); gconf_change_set_check_value (peditor->p->changeset, peditor->p->key, &value); g_signal_emit (peditor, peditor_signals[VALUE_CHANGED], 0, peditor->p->key, value); } GObject * -gconf_peditor_new_int_range (GConfChangeSet *changeset, gchar *key, GtkWidget *range) +gconf_peditor_new_float_range (GConfChangeSet *changeset, + gchar *key, + GtkWidget *range, + GConfPEditorValueConvFn to_widget_cb, + GConfPEditorValueConvFn from_widget_cb) { GObject *peditor; GConfClient *client; @@ -564,6 +585,91 @@ gconf_peditor_new_int_range (GConfChangeSet *changeset, gchar *key, GtkWidget *r GSList *item; GtkAdjustment *adjustment; + peditor = g_object_new (gconf_property_editor_get_type (), + "key", key, + "callback", peditor_float_range_value_changed, + "changeset", changeset, + "object", range, + NULL); + + adjustment = gtk_range_get_adjustment (GTK_RANGE (range)); + g_object_set_data (peditor, "adjustment", adjustment); + g_object_set_data (peditor, "to-widget-cb", to_widget_cb); + g_object_set_data (peditor, "from-widget-cb", from_widget_cb); + + g_signal_connect_swapped (G_OBJECT (adjustment), "value_changed", + (GCallback) peditor_float_range_widget_changed, peditor); + + client = gconf_client_get_default (); + gconf_entry = gconf_client_get_entry (client, key, NULL, TRUE, NULL); + peditor_float_range_value_changed (client, 0, gconf_entry, GCONF_PROPERTY_EDITOR (peditor)); + + return peditor; +} + +/* FIXME: These differ only trivially from the float versions; we should combine them */ + +static void +peditor_int_range_value_changed (GConfClient *client, + guint cnxn_id, + GConfEntry *entry, + GConfPropertyEditor *peditor) +{ + GConfValue *value; + GtkAdjustment *adjustment; + GConfPEditorValueConvFn to_widget_cb; + gfloat value_i; + + to_widget_cb = g_object_get_data (G_OBJECT (peditor), "to-widget-cb"); + + gconf_change_set_remove (peditor->p->changeset, peditor->p->key); + value = gconf_entry_get_value (entry); + + if (value != NULL) { + value_i = gconf_value_get_int (value); + + if (to_widget_cb != NULL) + value_i = to_widget_cb (value_i); + + adjustment = g_object_get_data (G_OBJECT (peditor), "adjustment"); + gtk_adjustment_set_value (adjustment, value_i); + } +} + +static void +peditor_int_range_widget_changed (GConfPropertyEditor *peditor, + GtkAdjustment *adjustment) +{ + GConfValue *value; + gfloat value_i; + GConfPEditorValueConvFn from_widget_cb; + + from_widget_cb = g_object_get_data (G_OBJECT (peditor), "from-widget-cb"); + + value_i = gtk_adjustment_get_value (adjustment); + + if (from_widget_cb != NULL) + value_i = from_widget_cb (value_i); + + gconf_change_set_set_int (peditor->p->changeset, peditor->p->key, value_i); + + gconf_change_set_check_value (peditor->p->changeset, peditor->p->key, &value); + g_signal_emit (peditor, peditor_signals[VALUE_CHANGED], 0, peditor->p->key, value); +} + +GObject * +gconf_peditor_new_int_range (GConfChangeSet *changeset, + gchar *key, + GtkWidget *range, + GConfPEditorValueConvFn to_widget_cb, + GConfPEditorValueConvFn from_widget_cb) +{ + GObject *peditor; + GConfClient *client; + GConfEntry *gconf_entry; + GSList *item; + GtkAdjustment *adjustment; + peditor = g_object_new (gconf_property_editor_get_type (), "key", key, "callback", peditor_int_range_value_changed, @@ -573,8 +679,10 @@ gconf_peditor_new_int_range (GConfChangeSet *changeset, gchar *key, GtkWidget *r adjustment = gtk_range_get_adjustment (GTK_RANGE (range)); g_object_set_data (peditor, "adjustment", adjustment); + g_object_set_data (peditor, "to-widget-cb", to_widget_cb); + g_object_set_data (peditor, "from-widget-cb", from_widget_cb); - g_signal_connect_swapped (G_OBJECT (adjustment), "changed", + g_signal_connect_swapped (G_OBJECT (adjustment), "value_changed", (GCallback) peditor_int_range_widget_changed, peditor); client = gconf_client_get_default (); @@ -600,4 +708,3 @@ gconf_peditor_widget_set_guard (GConfPropertyEditor *peditor, GtkWidget *widget) g_signal_connect (G_OBJECT (peditor), "value-changed", (GCallback) guard_value_changed, widget); } - diff --git a/capplets/common/gconf-property-editor.h b/capplets/common/gconf-property-editor.h index 4a74bcf06..5588e77e9 100644 --- a/capplets/common/gconf-property-editor.h +++ b/capplets/common/gconf-property-editor.h @@ -38,6 +38,8 @@ typedef struct _GConfPropertyEditor GConfPropertyEditor; typedef struct _GConfPropertyEditorClass GConfPropertyEditorClass; typedef struct _GConfPropertyEditorPrivate GConfPropertyEditorPrivate; +typedef gfloat (*GConfPEditorValueConvFn) (gfloat); + struct _GConfPropertyEditor { GObject parent; @@ -54,32 +56,39 @@ struct _GConfPropertyEditorClass GType gconf_property_editor_get_type (void); -const gchar *gconf_property_editor_get_key (GConfPropertyEditor *peditor); +const gchar *gconf_property_editor_get_key (GConfPropertyEditor *peditor); -GObject *gconf_peditor_new_boolean (GConfChangeSet *changeset, - gchar *key, - GtkWidget *checkbox); -GObject *gconf_peditor_new_string (GConfChangeSet *changeset, - gchar *key, - GtkWidget *entry); -GObject *gconf_peditor_new_filename (GConfChangeSet *changeset, - gchar *key, - GtkWidget *file_entry); -GObject *gconf_peditor_new_color (GConfChangeSet *changeset, - gchar *key, - GtkWidget *color_entry); -GObject *gconf_peditor_new_select_menu (GConfChangeSet *changeset, - gchar *key, - GtkWidget *option_menu); -GObject *gconf_peditor_new_select_radio (GConfChangeSet *changeset, - gchar *key, - GSList *radio_group); -GObject *gconf_peditor_new_int_range (GConfChangeSet *changeset, - gchar *key, - GtkWidget *range); +GObject *gconf_peditor_new_boolean (GConfChangeSet *changeset, + gchar *key, + GtkWidget *checkbox); +GObject *gconf_peditor_new_string (GConfChangeSet *changeset, + gchar *key, + GtkWidget *entry); +GObject *gconf_peditor_new_filename (GConfChangeSet *changeset, + gchar *key, + GtkWidget *file_entry); +GObject *gconf_peditor_new_color (GConfChangeSet *changeset, + gchar *key, + GtkWidget *color_entry); +GObject *gconf_peditor_new_select_menu (GConfChangeSet *changeset, + gchar *key, + GtkWidget *option_menu); +GObject *gconf_peditor_new_select_radio (GConfChangeSet *changeset, + gchar *key, + GSList *radio_group); +GObject *gconf_peditor_new_float_range (GConfChangeSet *changeset, + gchar *key, + GtkWidget *range, + GConfPEditorValueConvFn to_widget_cb, + GConfPEditorValueConvFn from_widget_cb); +GObject *gconf_peditor_new_int_range (GConfChangeSet *changeset, + gchar *key, + GtkWidget *range, + GConfPEditorValueConvFn to_widget_cb, + GConfPEditorValueConvFn from_widget_cb); -void gconf_peditor_widget_set_guard (GConfPropertyEditor *peditor, - GtkWidget *widget); +void gconf_peditor_widget_set_guard (GConfPropertyEditor *peditor, + GtkWidget *widget); G_END_DECLS