Implement the rest of LdSymbolCategory.

Added GObject properties for object parameters.
Implemented methods for children management.
This commit is contained in:
Přemysl Eric Janouch 2010-10-24 12:43:16 +02:00
parent ffc57249c8
commit ba3b348dfd
2 changed files with 135 additions and 3 deletions

View File

@ -40,6 +40,21 @@ struct _LdSymbolCategoryPrivate
G_DEFINE_TYPE (LdSymbolCategory, ld_symbol_category, G_TYPE_OBJECT);
enum
{
PROP_0,
PROP_NAME,
PROP_IMAGE_PATH
};
static void
ld_symbol_category_get_property (GObject *object, guint property_id,
GValue *value, GParamSpec *pspec);
static void
ld_symbol_category_set_property (GObject *object, guint property_id,
const GValue *value, GParamSpec *pspec);
static void
ld_symbol_category_finalize (GObject *gobject);
@ -48,10 +63,33 @@ static void
ld_symbol_category_class_init (LdSymbolCategoryClass *klass)
{
GObjectClass *object_class;
GParamSpec *pspec;
object_class = G_OBJECT_CLASS (klass);
object_class->get_property = ld_symbol_category_get_property;
object_class->set_property = ld_symbol_category_set_property;
object_class->finalize = ld_symbol_category_finalize;
/**
* LdSymbolCategory:name:
*
* The name of this symbol category.
*/
pspec = g_param_spec_string ("name", "Name",
"The name of this symbol category.",
"", G_PARAM_READWRITE);
g_object_class_install_property (object_class, PROP_NAME, pspec);
/**
* LdSymbolCategory:image-path:
*
* Path to an image file representing this category.
*/
pspec = g_param_spec_string ("image-path", "Image path",
"Path to an image file representing this category.",
"", G_PARAM_READWRITE);
g_object_class_install_property (object_class, PROP_IMAGE_PATH, pspec);
g_type_class_add_private (klass, sizeof (LdSymbolCategoryPrivate));
}
@ -62,6 +100,46 @@ ld_symbol_category_init (LdSymbolCategory *self)
(self, LD_TYPE_SYMBOL_CATEGORY, LdSymbolCategoryPrivate);
}
static void
ld_symbol_category_get_property (GObject *object, guint property_id,
GValue *value, GParamSpec *pspec)
{
LdSymbolCategory *self;
self = LD_SYMBOL_CATEGORY (object);
switch (property_id)
{
case PROP_NAME:
g_value_set_string (value, ld_symbol_category_get_name (self));
break;
case PROP_IMAGE_PATH:
g_value_set_string (value, ld_symbol_category_get_image_path (self));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
}
static void
ld_symbol_category_set_property (GObject *object, guint property_id,
const GValue *value, GParamSpec *pspec)
{
LdSymbolCategory *self;
self = LD_SYMBOL_CATEGORY (object);
switch (property_id)
{
case PROP_NAME:
ld_symbol_category_set_name (self, g_value_get_string (value));
break;
case PROP_IMAGE_PATH:
ld_symbol_category_set_image_path (self, g_value_get_string (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
}
static void
ld_symbol_category_finalize (GObject *gobject)
{
@ -74,6 +152,9 @@ ld_symbol_category_finalize (GObject *gobject)
if (self->priv->image_path)
g_free (self->priv->image_path);
g_slist_foreach (self->priv->children, (GFunc) g_object_unref, NULL);
g_slist_free (self->priv->children);
/* Chain up to the parent class. */
G_OBJECT_CLASS (ld_symbol_category_parent_class)->finalize (gobject);
}
@ -153,3 +234,54 @@ ld_symbol_category_get_image_path (LdSymbolCategory *self)
return self->priv->image_path;
}
/**
* ld_symbol_category_insert_child:
* @self: An #LdSymbolCategory object.
* @child: The child to be inserted.
* @pos: The position at which the child will be inserted.
* Negative values will append to the end of list.
*
* Insert a child into the category.
*/
void
ld_symbol_category_insert_child (LdSymbolCategory *self,
GObject *child, gint pos)
{
g_return_if_fail (LD_IS_SYMBOL_CATEGORY (self));
g_return_if_fail (G_IS_OBJECT (child));
g_object_ref (child);
self->priv->children = g_slist_insert (self->priv->children, child, pos);
}
/**
* ld_symbol_category_remove_child:
* @self: An #LdSymbolCategory object.
* @child: The child to be removed.
*
* Removes a child from the category.
*/
void
ld_symbol_category_remove_child (LdSymbolCategory *self,
GObject *child)
{
g_return_if_fail (LD_IS_SYMBOL_CATEGORY (self));
g_return_if_fail (G_IS_OBJECT (child));
g_object_unref (child);
self->priv->children = g_slist_remove (self->priv->children, child);
}
/**
* ld_symbol_category_get_children:
* @self: An #LdSymbolCategory object.
*
* Return value: The internal list of children. Do not modify.
*/
const GSList *
ld_symbol_category_get_children (LdSymbolCategory *self)
{
g_return_val_if_fail (LD_IS_SYMBOL_CATEGORY (self), NULL);
return self->priv->children;
}

View File

@ -47,6 +47,7 @@ struct _LdSymbolCategory
*/
struct _LdSymbolCategoryClass
{
/*< private >*/
GObjectClass parent_class;
};
@ -55,18 +56,17 @@ GType ld_symbol_category_get_type (void) G_GNUC_CONST;
LdSymbolCategory *ld_symbol_category_new (const gchar *name);
/* TODO: Create properties for "name" and "image_path". */
void ld_symbol_category_set_name (LdSymbolCategory *self, const gchar *name);
const gchar *ld_symbol_category_get_name (LdSymbolCategory *self);
void ld_symbol_category_set_image_path (LdSymbolCategory *self,
const gchar *image_path);
const gchar *ld_symbol_category_get_image_path (LdSymbolCategory *self);
/* TODO: Implement. */
void ld_symbol_category_insert_child (LdSymbolCategory *self,
GObject *child, gint pos);
void ld_symbol_category_remove_child (LdSymbolCategory *self,
GObject *child);
GSList *ld_symbol_category_get_children (LdSymbolCategory *self);
const GSList *ld_symbol_category_get_children (LdSymbolCategory *self);
G_END_DECLS