2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2001-12-18 20:39:45 +08:00
|
|
|
* Copyright (C) 1995-1997 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* Utitility functions for GimpConfig.
|
2003-07-24 22:14:23 +08:00
|
|
|
* Copyright (C) 2001-2003 Sven Neumann <sven@gimp.org>
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2001-12-18 20:39:45 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2001-12-18 20:39:45 +08:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2018-07-12 05:27:07 +08:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2001-12-18 20:39:45 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2013-10-15 07:58:39 +08:00
|
|
|
#include <gio/gio.h>
|
2001-12-18 20:39:45 +08:00
|
|
|
|
2003-04-06 03:56:38 +08:00
|
|
|
#include "libgimpbase/gimpbase.h"
|
2005-01-26 03:11:26 +08:00
|
|
|
#include "libgimpconfig/gimpconfig.h"
|
2001-12-18 20:39:45 +08:00
|
|
|
|
2003-03-06 04:21:50 +08:00
|
|
|
#include "config-types.h"
|
|
|
|
|
2001-12-18 20:39:45 +08:00
|
|
|
#include "gimpconfig-utils.h"
|
|
|
|
|
|
|
|
|
2003-02-10 22:13:55 +08:00
|
|
|
static void
|
|
|
|
gimp_config_connect_notify (GObject *src,
|
|
|
|
GParamSpec *param_spec,
|
|
|
|
GObject *dest)
|
|
|
|
{
|
2004-03-12 02:47:37 +08:00
|
|
|
if (param_spec->flags & G_PARAM_READABLE)
|
2003-09-30 02:29:11 +08:00
|
|
|
{
|
2004-03-12 02:47:37 +08:00
|
|
|
GParamSpec *dest_spec;
|
2003-02-10 22:13:55 +08:00
|
|
|
|
2004-03-12 02:47:37 +08:00
|
|
|
dest_spec = g_object_class_find_property (G_OBJECT_GET_CLASS (dest),
|
|
|
|
param_spec->name);
|
2003-02-10 22:13:55 +08:00
|
|
|
|
2004-03-12 02:47:37 +08:00
|
|
|
if (dest_spec &&
|
|
|
|
(dest_spec->value_type == param_spec->value_type) &&
|
|
|
|
(dest_spec->flags & G_PARAM_WRITABLE) &&
|
|
|
|
(dest_spec->flags & G_PARAM_CONSTRUCT_ONLY) == 0)
|
|
|
|
{
|
2016-03-26 22:59:26 +08:00
|
|
|
GValue value = G_VALUE_INIT;
|
2004-03-12 02:47:37 +08:00
|
|
|
|
|
|
|
g_value_init (&value, param_spec->value_type);
|
|
|
|
|
|
|
|
g_object_get_property (src, param_spec->name, &value);
|
2003-10-26 01:25:34 +08:00
|
|
|
|
2004-03-12 02:47:37 +08:00
|
|
|
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);
|
2003-02-10 22:13:55 +08:00
|
|
|
|
2004-03-12 02:47:37 +08:00
|
|
|
g_value_unset (&value);
|
|
|
|
}
|
2003-09-30 02:29:11 +08:00
|
|
|
}
|
2003-02-10 22:13:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_config_connect:
|
2003-10-26 01:25:34 +08:00
|
|
|
* @a: a #GObject
|
|
|
|
* @b: another #GObject
|
|
|
|
* @property_name: the name of a property to connect or %NULL for all
|
|
|
|
*
|
|
|
|
* 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.
|
2003-07-24 22:14:23 +08:00
|
|
|
*
|
2003-10-26 01:25:34 +08:00
|
|
|
* If @property_name is %NULL the connection is setup for all
|
2004-03-12 02:47:37 +08:00
|
|
|
* properties. It is not required that @a and @b are of the same type.
|
|
|
|
* Only changes on properties that exist in both object classes and
|
|
|
|
* are of the same value_type are propagated.
|
2003-02-10 22:13:55 +08:00
|
|
|
**/
|
|
|
|
void
|
2003-10-26 01:25:34 +08:00
|
|
|
gimp_config_connect (GObject *a,
|
|
|
|
GObject *b,
|
|
|
|
const gchar *property_name)
|
2003-02-10 22:13:55 +08:00
|
|
|
{
|
2003-10-26 01:25:34 +08:00
|
|
|
gchar *signal_name;
|
|
|
|
|
|
|
|
g_return_if_fail (a != b);
|
2004-03-12 02:47:37 +08:00
|
|
|
g_return_if_fail (G_IS_OBJECT (a) && G_IS_OBJECT (b));
|
2003-10-26 01:25:34 +08:00
|
|
|
|
|
|
|
if (property_name)
|
|
|
|
signal_name = g_strconcat ("notify::", property_name, NULL);
|
|
|
|
else
|
|
|
|
signal_name = "notify";
|
2003-02-10 22:13:55 +08:00
|
|
|
|
2003-10-26 01:25:34 +08:00
|
|
|
g_signal_connect_object (a, signal_name,
|
2003-02-10 22:13:55 +08:00
|
|
|
G_CALLBACK (gimp_config_connect_notify),
|
2003-10-26 01:25:34 +08:00
|
|
|
b, 0);
|
|
|
|
g_signal_connect_object (b, signal_name,
|
|
|
|
G_CALLBACK (gimp_config_connect_notify),
|
|
|
|
a, 0);
|
|
|
|
|
|
|
|
if (property_name)
|
|
|
|
g_free (signal_name);
|
2003-02-10 22:13:55 +08:00
|
|
|
}
|
|
|
|
|
2006-01-14 08:09:22 +08:00
|
|
|
static void
|
|
|
|
gimp_config_connect_full_notify (GObject *src,
|
|
|
|
GParamSpec *param_spec,
|
|
|
|
GObject *dest)
|
|
|
|
{
|
|
|
|
if (param_spec->flags & G_PARAM_READABLE)
|
|
|
|
{
|
|
|
|
gchar *attach_key;
|
|
|
|
gchar *dest_prop_name;
|
|
|
|
GParamSpec *dest_spec = NULL;
|
|
|
|
|
|
|
|
attach_key = g_strdup_printf ("%p-%s", dest, param_spec->name);
|
|
|
|
dest_prop_name = g_object_get_data (src, attach_key);
|
|
|
|
g_free (attach_key);
|
|
|
|
|
|
|
|
if (dest_prop_name)
|
|
|
|
dest_spec = g_object_class_find_property (G_OBJECT_GET_CLASS (dest),
|
|
|
|
dest_prop_name);
|
|
|
|
|
|
|
|
if (dest_spec &&
|
|
|
|
(dest_spec->value_type == param_spec->value_type) &&
|
|
|
|
(dest_spec->flags & G_PARAM_WRITABLE) &&
|
|
|
|
(dest_spec->flags & G_PARAM_CONSTRUCT_ONLY) == 0)
|
|
|
|
{
|
2016-03-26 22:59:26 +08:00
|
|
|
GValue value = G_VALUE_INIT;
|
2006-01-14 08:09:22 +08:00
|
|
|
|
|
|
|
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_full_notify, src);
|
|
|
|
g_object_set_property (dest, dest_prop_name, &value);
|
|
|
|
g_signal_handlers_unblock_by_func (dest,
|
|
|
|
gimp_config_connect_full_notify, src);
|
|
|
|
|
|
|
|
g_value_unset (&value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_config_connect_full:
|
|
|
|
* @a: a #GObject
|
|
|
|
* @b: another #GObject
|
|
|
|
* @property_name_a: the name of a property of @a to connect
|
|
|
|
* @property_name_b: the name of a property of @b to connect
|
|
|
|
*
|
|
|
|
* 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 not required that @a and @b are of the same type.
|
|
|
|
* Only changes on properties that exist in both object classes and
|
|
|
|
* are of the same value_type are propagated.
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
gimp_config_connect_full (GObject *a,
|
|
|
|
GObject *b,
|
|
|
|
const gchar *property_name_a,
|
|
|
|
const gchar *property_name_b)
|
|
|
|
{
|
|
|
|
gchar *signal_name;
|
|
|
|
gchar *attach_key;
|
|
|
|
|
|
|
|
g_return_if_fail (a != b);
|
|
|
|
g_return_if_fail (G_IS_OBJECT (a) && G_IS_OBJECT (b));
|
|
|
|
g_return_if_fail (property_name_a != NULL);
|
|
|
|
g_return_if_fail (property_name_b != NULL);
|
|
|
|
|
|
|
|
signal_name = g_strconcat ("notify::", property_name_a, NULL);
|
|
|
|
attach_key = g_strdup_printf ("%p-%s", b, property_name_a);
|
|
|
|
|
|
|
|
g_signal_connect_object (a, signal_name,
|
|
|
|
G_CALLBACK (gimp_config_connect_full_notify),
|
|
|
|
b, 0);
|
|
|
|
g_object_set_data_full (a, attach_key, g_strdup (property_name_b),
|
|
|
|
(GDestroyNotify) g_free);
|
|
|
|
|
|
|
|
g_free (signal_name);
|
|
|
|
g_free (attach_key);
|
|
|
|
|
|
|
|
signal_name = g_strconcat ("notify::", property_name_b, NULL);
|
|
|
|
attach_key = g_strdup_printf ("%p-%s", a, property_name_b);
|
|
|
|
|
|
|
|
g_signal_connect_object (b, signal_name,
|
|
|
|
G_CALLBACK (gimp_config_connect_full_notify),
|
|
|
|
a, 0);
|
|
|
|
g_object_set_data_full (b, attach_key, g_strdup (property_name_a),
|
|
|
|
(GDestroyNotify) g_free);
|
|
|
|
|
|
|
|
g_free (signal_name);
|
|
|
|
g_free (attach_key);
|
|
|
|
}
|
|
|
|
|
2003-02-10 22:13:55 +08:00
|
|
|
/**
|
|
|
|
* gimp_config_disconnect:
|
2003-10-26 01:25:34 +08:00
|
|
|
* @a: a #GObject
|
2003-10-26 04:32:10 +08:00
|
|
|
* @b: another #GObject
|
2003-07-24 22:14:23 +08:00
|
|
|
*
|
2003-02-10 22:13:55 +08:00
|
|
|
* Removes a connection between @dest and @src that was previously set
|
|
|
|
* up using gimp_config_connect().
|
|
|
|
**/
|
|
|
|
void
|
2003-10-26 01:25:34 +08:00
|
|
|
gimp_config_disconnect (GObject *a,
|
|
|
|
GObject *b)
|
2003-02-10 22:13:55 +08:00
|
|
|
{
|
2004-03-12 02:47:37 +08:00
|
|
|
g_return_if_fail (G_IS_OBJECT (a) && G_IS_OBJECT (b));
|
2003-02-10 22:13:55 +08:00
|
|
|
|
2003-10-26 01:25:34 +08:00
|
|
|
g_signal_handlers_disconnect_by_func (b,
|
|
|
|
G_CALLBACK (gimp_config_connect_notify),
|
|
|
|
a);
|
|
|
|
g_signal_handlers_disconnect_by_func (a,
|
2003-02-10 22:13:55 +08:00
|
|
|
G_CALLBACK (gimp_config_connect_notify),
|
2003-10-26 01:25:34 +08:00
|
|
|
b);
|
2003-02-10 22:13:55 +08:00
|
|
|
}
|
|
|
|
|