make it a two-way connection and added a property_name parameter so it can

2003-10-25  Sven Neumann  <sven@gimp.org>

	* app/config/gimpconfig-utils.[ch] (gimp_config_connect): make it
	a two-way connection and added a property_name parameter so it
	can be used to connect only a certain property.

	* app/tools/gimptexttool.c: changed accordingly.

	* app/tools/gimphistogramoptions.c: use gimp_config_connect().
	Changed the default histogram scale to linear.
This commit is contained in:
Sven Neumann 2003-10-25 17:25:34 +00:00 committed by Sven Neumann
parent ad37e4a6bc
commit f7db733ee2
7 changed files with 127 additions and 82 deletions

View File

@ -1,3 +1,14 @@
2003-10-25 Sven Neumann <sven@gimp.org>
* app/config/gimpconfig-utils.[ch] (gimp_config_connect): make it
a two-way connection and added a property_name parameter so it
can be used to connect only a certain property.
* app/tools/gimptexttool.c: changed accordingly.
* app/tools/gimphistogramoptions.c: use gimp_config_connect().
Changed the default histogram scale to linear.
2003-10-25 DindinX <david@dindinx.net>
* plug-ins/gimpressionist/Makefile.am: added a real dependency for

View File

@ -52,7 +52,10 @@ gimp_config_connect_notify (GObject *src,
g_value_init (&value, param_spec->value_type);
g_object_get_property (src, param_spec->name, &value);
g_signal_handlers_block_by_func (dest, gimp_config_connect_notify, src);
g_object_set_property (dest, param_spec->name, &value);
g_signal_handlers_unblock_by_func (dest, gimp_config_connect_notify, src);
g_value_unset (&value);
}
@ -61,43 +64,70 @@ gimp_config_connect_notify (GObject *src,
/**
* gimp_config_connect:
* @src: a #GObject
* @dest: another #GObject of the same type as @src
* @a: a #GObject
* @b: another #GObject
* @property_name: the name of a property to connect or %NULL for all
*
* Connects @dest with @src so that all property changes of @src are
* applied to @dest using a "notify" handler.
* Connects the two object @a and @b in a way that property changes of
* one are propagated to the other. This is a two-way connection.
*
* If @property_name is %NULL the connection is setup for all
* properties. It is then required that @a and @b are of the same
* type. If a name is given, only this property is connected. In this
* case, the two objects don't need to be of the same type but they
* should both have a property of the same type that has the given
* @property_name.
**/
void
gimp_config_connect (GObject *src,
GObject *dest)
gimp_config_connect (GObject *a,
GObject *b,
const gchar *property_name)
{
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));
gchar *signal_name;
g_signal_connect_object (src, "notify",
g_return_if_fail (a != b);
g_return_if_fail (G_IS_OBJECT (a));
g_return_if_fail (G_IS_OBJECT (b));
g_return_if_fail (property_name != NULL ||
G_TYPE_FROM_INSTANCE (a) == G_TYPE_FROM_INSTANCE (b));
if (property_name)
signal_name = g_strconcat ("notify::", property_name, NULL);
else
signal_name = "notify";
g_signal_connect_object (a, signal_name,
G_CALLBACK (gimp_config_connect_notify),
dest, 0);
b, 0);
g_signal_connect_object (b, signal_name,
G_CALLBACK (gimp_config_connect_notify),
a, 0);
if (property_name)
g_free (signal_name);
}
/**
* gimp_config_disconnect:
* @src: a #GObject
* @dest: another #GObject of the same type as @src
* @a: a #GObject
* @a: another #GObject
*
* Removes a connection between @dest and @src that was previously set
* up using gimp_config_connect().
**/
void
gimp_config_disconnect (GObject *src,
GObject *dest)
gimp_config_disconnect (GObject *a,
GObject *b)
{
g_return_if_fail (G_IS_OBJECT (src));
g_return_if_fail (G_IS_OBJECT (dest));
g_return_if_fail (G_IS_OBJECT (a));
g_return_if_fail (G_IS_OBJECT (b));
g_signal_handlers_disconnect_by_func (src,
g_signal_handlers_disconnect_by_func (b,
G_CALLBACK (gimp_config_connect_notify),
dest);
a);
g_signal_handlers_disconnect_by_func (a,
G_CALLBACK (gimp_config_connect_notify),
b);
}

View File

@ -23,10 +23,11 @@
#define __GIMP_CONFIG_UTILS_H__
void gimp_config_connect (GObject *src,
GObject *dest);
void gimp_config_disconnect (GObject *src,
GObject *dest);
void gimp_config_connect (GObject *a,
GObject *b,
const gchar *property_name);
void gimp_config_disconnect (GObject *a,
GObject *b);
GList * gimp_config_diff (GimpConfig *a,
GimpConfig *b,

View File

@ -23,6 +23,7 @@
#include "tools-types.h"
#include "config/gimpconfig-params.h"
#include "config/gimpconfig-utils.h"
#include "widgets/gimphistogramview.h"
#include "widgets/gimppropwidgets.h"
@ -51,10 +52,6 @@ static void gimp_histogram_options_get_property (GObject *object,
GValue *value,
GParamSpec *pspec);
static void gimp_histogram_options_scale_notify (GObject *src,
GParamSpec *pspec,
GObject *dest);
static GimpColorOptionsClass *parent_class = NULL;
@ -100,7 +97,7 @@ gimp_histogram_options_class_init (GimpHistogramOptionsClass *klass)
GIMP_CONFIG_INSTALL_PROP_ENUM (object_class, PROP_SCALE,
"histogram-scale", NULL,
GIMP_TYPE_HISTOGRAM_SCALE,
GIMP_HISTOGRAM_SCALE_LOGARITHMIC,
GIMP_HISTOGRAM_SCALE_LINEAR,
0);
}
@ -165,35 +162,7 @@ gimp_histogram_options_connect_view (GimpHistogramOptions *options,
g_return_if_fail (GIMP_IS_HISTOGRAM_OPTIONS (options));
g_return_if_fail (GIMP_IS_HISTOGRAM_VIEW (view));
g_signal_connect_object (options, "notify::histogram-scale",
G_CALLBACK (gimp_histogram_options_scale_notify),
view, 0);
g_signal_connect_object (view, "notify::histogram-scale",
G_CALLBACK (gimp_histogram_options_scale_notify),
options, 0);
gimp_config_connect (G_OBJECT (options), G_OBJECT (view), "histogram-scale");
g_object_notify (G_OBJECT (options), "histogram-scale");
}
static void
gimp_histogram_options_scale_notify (GObject *src,
GParamSpec *pspec,
GObject *dest)
{
GValue value = { 0, };
g_return_if_fail (g_type_is_a (pspec->value_type,
GIMP_TYPE_HISTOGRAM_SCALE));
g_value_init (&value, pspec->value_type);
g_object_get_property (src, pspec->name, &value);
g_signal_handlers_block_by_func (dest,
gimp_histogram_options_scale_notify, src);
g_object_set_property (dest, pspec->name, &value);
g_signal_handlers_unblock_by_func (dest,
gimp_histogram_options_scale_notify, src);
g_value_unset (&value);
}

View File

@ -366,7 +366,8 @@ gimp_text_tool_connect (GimpTextTool *tool,
tool);
}
gimp_config_disconnect (G_OBJECT (options->text), G_OBJECT (tool->text));
gimp_config_disconnect (G_OBJECT (options->text),
G_OBJECT (tool->text));
g_object_unref (tool->text);
tool->text = NULL;
@ -384,7 +385,9 @@ gimp_text_tool_connect (GimpTextTool *tool,
gimp_config_sync (GIMP_CONFIG (tool->text),
GIMP_CONFIG (options->text), 0);
gimp_config_connect (G_OBJECT (options->text), G_OBJECT (tool->text));
gimp_config_connect (G_OBJECT (options->text),
G_OBJECT (tool->text),
NULL);
tool->offset_x = off_x;
tool->offset_y = off_y;

View File

@ -52,7 +52,10 @@ gimp_config_connect_notify (GObject *src,
g_value_init (&value, param_spec->value_type);
g_object_get_property (src, param_spec->name, &value);
g_signal_handlers_block_by_func (dest, gimp_config_connect_notify, src);
g_object_set_property (dest, param_spec->name, &value);
g_signal_handlers_unblock_by_func (dest, gimp_config_connect_notify, src);
g_value_unset (&value);
}
@ -61,43 +64,70 @@ gimp_config_connect_notify (GObject *src,
/**
* gimp_config_connect:
* @src: a #GObject
* @dest: another #GObject of the same type as @src
* @a: a #GObject
* @b: another #GObject
* @property_name: the name of a property to connect or %NULL for all
*
* Connects @dest with @src so that all property changes of @src are
* applied to @dest using a "notify" handler.
* Connects the two object @a and @b in a way that property changes of
* one are propagated to the other. This is a two-way connection.
*
* If @property_name is %NULL the connection is setup for all
* properties. It is then required that @a and @b are of the same
* type. If a name is given, only this property is connected. In this
* case, the two objects don't need to be of the same type but they
* should both have a property of the same type that has the given
* @property_name.
**/
void
gimp_config_connect (GObject *src,
GObject *dest)
gimp_config_connect (GObject *a,
GObject *b,
const gchar *property_name)
{
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));
gchar *signal_name;
g_signal_connect_object (src, "notify",
g_return_if_fail (a != b);
g_return_if_fail (G_IS_OBJECT (a));
g_return_if_fail (G_IS_OBJECT (b));
g_return_if_fail (property_name != NULL ||
G_TYPE_FROM_INSTANCE (a) == G_TYPE_FROM_INSTANCE (b));
if (property_name)
signal_name = g_strconcat ("notify::", property_name, NULL);
else
signal_name = "notify";
g_signal_connect_object (a, signal_name,
G_CALLBACK (gimp_config_connect_notify),
dest, 0);
b, 0);
g_signal_connect_object (b, signal_name,
G_CALLBACK (gimp_config_connect_notify),
a, 0);
if (property_name)
g_free (signal_name);
}
/**
* gimp_config_disconnect:
* @src: a #GObject
* @dest: another #GObject of the same type as @src
* @a: a #GObject
* @a: another #GObject
*
* Removes a connection between @dest and @src that was previously set
* up using gimp_config_connect().
**/
void
gimp_config_disconnect (GObject *src,
GObject *dest)
gimp_config_disconnect (GObject *a,
GObject *b)
{
g_return_if_fail (G_IS_OBJECT (src));
g_return_if_fail (G_IS_OBJECT (dest));
g_return_if_fail (G_IS_OBJECT (a));
g_return_if_fail (G_IS_OBJECT (b));
g_signal_handlers_disconnect_by_func (src,
g_signal_handlers_disconnect_by_func (b,
G_CALLBACK (gimp_config_connect_notify),
dest);
a);
g_signal_handlers_disconnect_by_func (a,
G_CALLBACK (gimp_config_connect_notify),
b);
}

View File

@ -23,10 +23,11 @@
#define __GIMP_CONFIG_UTILS_H__
void gimp_config_connect (GObject *src,
GObject *dest);
void gimp_config_disconnect (GObject *src,
GObject *dest);
void gimp_config_connect (GObject *a,
GObject *b,
const gchar *property_name);
void gimp_config_disconnect (GObject *a,
GObject *b);
GList * gimp_config_diff (GimpConfig *a,
GimpConfig *b,