Add ClutterBindingPool:name
The BindingPool constructor should only check for duplicate pools and then set the :name constructor-only property. If a BindingPool is created without a name we also make a fuss about it. It is also possible to simply dispose of a binding pool using g_object_unref(), as long as it has been created by using clutter_binding_pool_new() or directly with g_object_new(). Only BindingPools attached to a class are not owned by the user.
This commit is contained in:
parent
a4c8a70c83
commit
a9ae1c65c3
@ -118,7 +118,7 @@
|
|||||||
typedef struct _ClutterBindingPoolClass ClutterBindingPoolClass;
|
typedef struct _ClutterBindingPoolClass ClutterBindingPoolClass;
|
||||||
typedef struct _ClutterBindingEntry ClutterBindingEntry;
|
typedef struct _ClutterBindingEntry ClutterBindingEntry;
|
||||||
|
|
||||||
static GSList *binding_pools = NULL;
|
static GSList *clutter_binding_pools = NULL;
|
||||||
static GQuark key_class_bindings = 0;
|
static GQuark key_class_bindings = 0;
|
||||||
|
|
||||||
struct _ClutterBindingPool
|
struct _ClutterBindingPool
|
||||||
@ -148,6 +148,13 @@ struct _ClutterBindingEntry
|
|||||||
guint is_blocked : 1;
|
guint is_blocked : 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
PROP_0,
|
||||||
|
|
||||||
|
PROP_NAME
|
||||||
|
};
|
||||||
|
|
||||||
G_DEFINE_TYPE (ClutterBindingPool, clutter_binding_pool, G_TYPE_OBJECT);
|
G_DEFINE_TYPE (ClutterBindingPool, clutter_binding_pool, G_TYPE_OBJECT);
|
||||||
|
|
||||||
static guint
|
static guint
|
||||||
@ -223,7 +230,7 @@ clutter_binding_pool_finalize (GObject *gobject)
|
|||||||
ClutterBindingPool *pool = CLUTTER_BINDING_POOL (gobject);
|
ClutterBindingPool *pool = CLUTTER_BINDING_POOL (gobject);
|
||||||
|
|
||||||
/* remove from the pools */
|
/* remove from the pools */
|
||||||
binding_pools = g_slist_remove (binding_pools, pool);
|
clutter_binding_pools = g_slist_remove (clutter_binding_pools, pool);
|
||||||
|
|
||||||
g_hash_table_destroy (pool->entries_hash);
|
g_hash_table_destroy (pool->entries_hash);
|
||||||
|
|
||||||
@ -233,22 +240,95 @@ clutter_binding_pool_finalize (GObject *gobject)
|
|||||||
G_OBJECT_CLASS (clutter_binding_pool_parent_class)->finalize (gobject);
|
G_OBJECT_CLASS (clutter_binding_pool_parent_class)->finalize (gobject);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
clutter_binding_pool_set_property (GObject *gobject,
|
||||||
|
guint prop_id,
|
||||||
|
const GValue *value,
|
||||||
|
GParamSpec *pspec)
|
||||||
|
{
|
||||||
|
ClutterBindingPool *pool = CLUTTER_BINDING_POOL (gobject);
|
||||||
|
|
||||||
|
switch (prop_id)
|
||||||
|
{
|
||||||
|
case PROP_NAME:
|
||||||
|
pool->name = (gchar *) g_intern_string (g_value_get_string (value));
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
clutter_binding_pool_get_property (GObject *gobject,
|
||||||
|
guint prop_id,
|
||||||
|
GValue *value,
|
||||||
|
GParamSpec *pspec)
|
||||||
|
{
|
||||||
|
ClutterBindingPool *pool = CLUTTER_BINDING_POOL (gobject);
|
||||||
|
|
||||||
|
switch (prop_id)
|
||||||
|
{
|
||||||
|
case PROP_NAME:
|
||||||
|
g_value_set_string (value, pool->name);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
clutter_binding_pool_constructed (GObject *gobject)
|
||||||
|
{
|
||||||
|
ClutterBindingPool *pool = CLUTTER_BINDING_POOL (gobject);
|
||||||
|
|
||||||
|
/* bad monkey! bad, bad monkey! */
|
||||||
|
if (G_UNLIKELY (pool->name == NULL))
|
||||||
|
g_critical ("No name set for ClutterBindingPool %p", pool);
|
||||||
|
|
||||||
|
if (G_OBJECT_CLASS (clutter_binding_pool_parent_class)->constructed)
|
||||||
|
G_OBJECT_CLASS (clutter_binding_pool_parent_class)->constructed (gobject);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
clutter_binding_pool_class_init (ClutterBindingPoolClass *klass)
|
clutter_binding_pool_class_init (ClutterBindingPoolClass *klass)
|
||||||
{
|
{
|
||||||
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
||||||
|
GParamSpec *pspec = NULL;
|
||||||
|
|
||||||
|
gobject_class->constructed = clutter_binding_pool_constructed;
|
||||||
|
gobject_class->set_property = clutter_binding_pool_set_property;
|
||||||
|
gobject_class->get_property = clutter_binding_pool_get_property;
|
||||||
gobject_class->finalize = clutter_binding_pool_finalize;
|
gobject_class->finalize = clutter_binding_pool_finalize;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ClutterBindingPool:name:
|
||||||
|
*
|
||||||
|
* The unique name of the #ClutterBindingPool.
|
||||||
|
*
|
||||||
|
* Since: 1.0
|
||||||
|
*/
|
||||||
|
pspec = g_param_spec_string ("name",
|
||||||
|
"Name",
|
||||||
|
"The unique name of the binding pool",
|
||||||
|
NULL,
|
||||||
|
CLUTTER_PARAM_READWRITE |
|
||||||
|
G_PARAM_CONSTRUCT_ONLY);
|
||||||
|
g_object_class_install_property (gobject_class, PROP_NAME, pspec);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
clutter_binding_pool_init (ClutterBindingPool *pool)
|
clutter_binding_pool_init (ClutterBindingPool *pool)
|
||||||
{
|
{
|
||||||
|
pool->name = NULL;
|
||||||
pool->entries = NULL;
|
pool->entries = NULL;
|
||||||
pool->entries_hash = g_hash_table_new (binding_entry_hash,
|
pool->entries_hash = g_hash_table_new (binding_entry_hash,
|
||||||
binding_entry_compare);
|
binding_entry_compare);
|
||||||
|
|
||||||
binding_pools = g_slist_prepend (binding_pools, pool);
|
clutter_binding_pools = g_slist_prepend (clutter_binding_pools, pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -261,8 +341,7 @@ clutter_binding_pool_init (ClutterBindingPool *pool)
|
|||||||
* be able to return the correct binding pool.
|
* be able to return the correct binding pool.
|
||||||
*
|
*
|
||||||
* Return value: the newly created binding pool with the given
|
* Return value: the newly created binding pool with the given
|
||||||
* name. The binding pool is owned by Clutter and should not
|
* name. Use g_object_unref() when done.
|
||||||
* be freed directly
|
|
||||||
*
|
*
|
||||||
* Since: 1.0
|
* Since: 1.0
|
||||||
*/
|
*/
|
||||||
@ -282,10 +361,7 @@ clutter_binding_pool_new (const gchar *name)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
pool = g_object_new (CLUTTER_TYPE_BINDING_POOL, NULL);
|
return g_object_new (CLUTTER_TYPE_BINDING_POOL, "name", name, NULL);
|
||||||
pool->name = (gchar *) g_intern_string (name);
|
|
||||||
|
|
||||||
return pool;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -352,7 +428,7 @@ clutter_binding_pool_find (const gchar *name)
|
|||||||
|
|
||||||
g_return_val_if_fail (name != NULL, NULL);
|
g_return_val_if_fail (name != NULL, NULL);
|
||||||
|
|
||||||
for (l = binding_pools; l != NULL; l = l->next)
|
for (l = clutter_binding_pools; l != NULL; l = l->next)
|
||||||
{
|
{
|
||||||
ClutterBindingPool *pool = l->data;
|
ClutterBindingPool *pool = l->data;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user