From 5d402908f848362c1e7dab6c0077194e70a5c6f8 Mon Sep 17 00:00:00 2001 From: Sven Neumann Date: Mon, 10 Feb 2003 14:13:55 +0000 Subject: [PATCH] added new utility functions gimp_config_connect() and 2003-02-10 Sven Neumann * app/config/gimpconfig-utils.[ch]: added new utility functions gimp_config_connect() and gimp_config_disconnect() and documented most functions. * app/tools/gimptexttool.c (gimp_text_tool_connect): use the new GimpConfig utility functions. --- ChangeLog | 9 +++ app/config/gimpconfig-utils.c | 87 ++++++++++++++++++++++++++ app/config/gimpconfig-utils.h | 4 ++ app/tools/gimptexttool.c | 25 ++------ devel-docs/ChangeLog | 4 ++ devel-docs/libgimp/tmpl/gimpenums.sgml | 6 +- libgimpconfig/gimpconfig-utils.c | 87 ++++++++++++++++++++++++++ libgimpconfig/gimpconfig-utils.h | 4 ++ 8 files changed, 202 insertions(+), 24 deletions(-) diff --git a/ChangeLog b/ChangeLog index 972a0dede8..1efe9f1ecf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2003-02-10 Sven Neumann + + * app/config/gimpconfig-utils.[ch]: added new utility functions + gimp_config_connect() and gimp_config_disconnect() and documented + most functions. + + * app/tools/gimptexttool.c (gimp_text_tool_connect): use the new + GimpConfig utility functions. + 2003-02-10 Sven Neumann * app/config/gimprc.c (gimp_rc_query): allow to query for gimp diff --git a/app/config/gimpconfig-utils.c b/app/config/gimpconfig-utils.c index 6e564d0ac4..5dbc892510 100644 --- a/app/config/gimpconfig-utils.c +++ b/app/config/gimpconfig-utils.c @@ -30,6 +30,17 @@ #include "gimpconfig-utils.h" +/** + * gimp_config_diff: + * @a: a #GObject + * @b: another #GObject of the same type as @a + * @flags: a mask of GParamFlags + * + * Compares all properties of @a and @b that have all @flags set. If + * @flags is 0, all properties are compared. + * + * Return value: a GList of differing GParamSpecs. + **/ GList * gimp_config_diff (GObject *a, GObject *b, @@ -74,6 +85,71 @@ gimp_config_diff (GObject *a, return g_list_reverse (list); } + +static void +gimp_config_connect_notify (GObject *src, + GParamSpec *param_spec, + GObject *dest) +{ + GValue value = { 0, }; + + g_value_init (&value, param_spec->value_type); + + g_object_get_property (src, param_spec->name, &value); + g_object_set_property (dest, param_spec->name, &value); + + g_value_unset (&value); +} + +/** + * gimp_config_connect: + * @src: a #GObject + * @dest: another #GObject of the same type as @src + * + * Connects @dest with @src so that all property changes of @src are + * applied to @dest using a "notify" handler. + **/ +void +gimp_config_connect (GObject *src, + GObject *dest) +{ + g_return_if_fail (G_IS_OBJECT (src)); + g_return_if_fail (G_IS_OBJECT (dest)); + g_return_if_fail (G_TYPE_FROM_INSTANCE (src) == G_TYPE_FROM_INSTANCE (dest)); + + g_signal_connect_object (src, "notify", + G_CALLBACK (gimp_config_connect_notify), + dest, 0); +} + +/** + * gimp_config_disconnect: + * @src: a #GObject + * @dest: another #GObject of the same type as @src + * + * Removes a connection between @dest and @src that was previously set + * up using gimp_config_connect(). + **/ +void +gimp_config_disconnect (GObject *src, + GObject *dest) +{ + g_return_if_fail (G_IS_OBJECT (src)); + g_return_if_fail (G_IS_OBJECT (dest)); + + g_signal_handlers_disconnect_by_func (src, + G_CALLBACK (gimp_config_connect_notify), + dest); +} + +/** + * gimp_config_copy_properties: + * @src: a #GObject + * @dest: another #GObject of the same type as @src + * + * Retrieves all read and writeable property settings from @src and + * applies the values to @dest. + **/ void gimp_config_copy_properties (GObject *src, GObject *dest) @@ -117,6 +193,13 @@ gimp_config_copy_properties (GObject *src, g_free (property_specs); } +/** + * gimp_config_reset_properties: + * @object: a #GObject + * + * Resets all writable properties of @object to the default values as + * defined in their #GParamSpec. + **/ void gimp_config_reset_properties (GObject *object) { @@ -158,6 +241,10 @@ gimp_config_reset_properties (GObject *object) } +/* + * GimpConfig path utilities + */ + gchar * gimp_config_build_data_path (const gchar *name) { diff --git a/app/config/gimpconfig-utils.h b/app/config/gimpconfig-utils.h index 973fad77b5..237ffaca47 100644 --- a/app/config/gimpconfig-utils.h +++ b/app/config/gimpconfig-utils.h @@ -26,6 +26,10 @@ GList * gimp_config_diff (GObject *a, GObject *b, GParamFlags flags); +void gimp_config_connect (GObject *src, + GObject *dest); +void gimp_config_disconnect (GObject *src, + GObject *dest); void gimp_config_copy_properties (GObject *src, GObject *dest); void gimp_config_reset_properties (GObject *object); diff --git a/app/tools/gimptexttool.c b/app/tools/gimptexttool.c index c3166f21e7..82114da16b 100644 --- a/app/tools/gimptexttool.c +++ b/app/tools/gimptexttool.c @@ -295,21 +295,6 @@ text_tool_create_layer (GimpTextTool *text_tool) gimp_image_flush (gimage); } -static void -gimp_text_tool_notify (GObject *tool, - GParamSpec *param_spec, - GObject *text) -{ - GValue value = { 0, }; - - g_value_init (&value, param_spec->value_type); - - g_object_get_property (tool, param_spec->name, &value); - g_object_set_property (text, param_spec->name, &value); - - g_value_unset (&value); -} - static void gimp_text_tool_connect (GimpTextTool *tool, GimpText *text) @@ -323,9 +308,8 @@ gimp_text_tool_connect (GimpTextTool *tool, if (tool->text) { - g_signal_handlers_disconnect_by_func (options->text, - gimp_text_tool_notify, - tool->text); + gimp_config_disconnect (G_OBJECT (options->text), + G_OBJECT (tool->text)); g_object_unref (tool->text); tool->text = NULL; @@ -338,9 +322,8 @@ gimp_text_tool_connect (GimpTextTool *tool, gimp_config_copy_properties (G_OBJECT (tool->text), G_OBJECT (options->text)); - g_signal_connect (options->text, "notify", - G_CALLBACK (gimp_text_tool_notify), - tool->text); + gimp_config_connect (G_OBJECT (options->text), + G_OBJECT (tool->text)); } } diff --git a/devel-docs/ChangeLog b/devel-docs/ChangeLog index b89b041815..926e93c2fd 100644 --- a/devel-docs/ChangeLog +++ b/devel-docs/ChangeLog @@ -1,3 +1,7 @@ +2003-02-10 Sven Neumann + + * libgimp/tmpl/gimpenums.sgml: regenerated. + 2003-02-06 Sven Neumann * libgimp/libgimp-docs.sgml diff --git a/devel-docs/libgimp/tmpl/gimpenums.sgml b/devel-docs/libgimp/tmpl/gimpenums.sgml index f22f5dc4cf..b37d479315 100644 --- a/devel-docs/libgimp/tmpl/gimpenums.sgml +++ b/devel-docs/libgimp/tmpl/gimpenums.sgml @@ -274,9 +274,9 @@ Enums and definitions. -@GIMP_HORIZONTAL: -@GIMP_VERTICAL: -@GIMP_UNKNOWN: +@GIMP_ORIENTATION_HORIZONTAL: +@GIMP_ORIENTATION_VERTICAL: +@GIMP_ORIENTATION_UNKNOWN: diff --git a/libgimpconfig/gimpconfig-utils.c b/libgimpconfig/gimpconfig-utils.c index 6e564d0ac4..5dbc892510 100644 --- a/libgimpconfig/gimpconfig-utils.c +++ b/libgimpconfig/gimpconfig-utils.c @@ -30,6 +30,17 @@ #include "gimpconfig-utils.h" +/** + * gimp_config_diff: + * @a: a #GObject + * @b: another #GObject of the same type as @a + * @flags: a mask of GParamFlags + * + * Compares all properties of @a and @b that have all @flags set. If + * @flags is 0, all properties are compared. + * + * Return value: a GList of differing GParamSpecs. + **/ GList * gimp_config_diff (GObject *a, GObject *b, @@ -74,6 +85,71 @@ gimp_config_diff (GObject *a, return g_list_reverse (list); } + +static void +gimp_config_connect_notify (GObject *src, + GParamSpec *param_spec, + GObject *dest) +{ + GValue value = { 0, }; + + g_value_init (&value, param_spec->value_type); + + g_object_get_property (src, param_spec->name, &value); + g_object_set_property (dest, param_spec->name, &value); + + g_value_unset (&value); +} + +/** + * gimp_config_connect: + * @src: a #GObject + * @dest: another #GObject of the same type as @src + * + * Connects @dest with @src so that all property changes of @src are + * applied to @dest using a "notify" handler. + **/ +void +gimp_config_connect (GObject *src, + GObject *dest) +{ + g_return_if_fail (G_IS_OBJECT (src)); + g_return_if_fail (G_IS_OBJECT (dest)); + g_return_if_fail (G_TYPE_FROM_INSTANCE (src) == G_TYPE_FROM_INSTANCE (dest)); + + g_signal_connect_object (src, "notify", + G_CALLBACK (gimp_config_connect_notify), + dest, 0); +} + +/** + * gimp_config_disconnect: + * @src: a #GObject + * @dest: another #GObject of the same type as @src + * + * Removes a connection between @dest and @src that was previously set + * up using gimp_config_connect(). + **/ +void +gimp_config_disconnect (GObject *src, + GObject *dest) +{ + g_return_if_fail (G_IS_OBJECT (src)); + g_return_if_fail (G_IS_OBJECT (dest)); + + g_signal_handlers_disconnect_by_func (src, + G_CALLBACK (gimp_config_connect_notify), + dest); +} + +/** + * gimp_config_copy_properties: + * @src: a #GObject + * @dest: another #GObject of the same type as @src + * + * Retrieves all read and writeable property settings from @src and + * applies the values to @dest. + **/ void gimp_config_copy_properties (GObject *src, GObject *dest) @@ -117,6 +193,13 @@ gimp_config_copy_properties (GObject *src, g_free (property_specs); } +/** + * gimp_config_reset_properties: + * @object: a #GObject + * + * Resets all writable properties of @object to the default values as + * defined in their #GParamSpec. + **/ void gimp_config_reset_properties (GObject *object) { @@ -158,6 +241,10 @@ gimp_config_reset_properties (GObject *object) } +/* + * GimpConfig path utilities + */ + gchar * gimp_config_build_data_path (const gchar *name) { diff --git a/libgimpconfig/gimpconfig-utils.h b/libgimpconfig/gimpconfig-utils.h index 973fad77b5..237ffaca47 100644 --- a/libgimpconfig/gimpconfig-utils.h +++ b/libgimpconfig/gimpconfig-utils.h @@ -26,6 +26,10 @@ GList * gimp_config_diff (GObject *a, GObject *b, GParamFlags flags); +void gimp_config_connect (GObject *src, + GObject *dest); +void gimp_config_disconnect (GObject *src, + GObject *dest); void gimp_config_copy_properties (GObject *src, GObject *dest); void gimp_config_reset_properties (GObject *object);