From 2b9b54340220e1f93e1dfd000ec2e23000dbb5b9 Mon Sep 17 00:00:00 2001 From: Přemysl Janouch Date: Sun, 24 Oct 2010 13:43:41 +0200 Subject: Implement the LdSymbol "name" property. --- src/ld-lua-symbol.c | 2 +- src/ld-symbol.c | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/ld-symbol.h | 7 ++-- 3 files changed, 100 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/ld-lua-symbol.c b/src/ld-lua-symbol.c index 63a1665..6447019 100644 --- a/src/ld-lua-symbol.c +++ b/src/ld-lua-symbol.c @@ -103,7 +103,7 @@ ld_lua_symbol_new (const gchar *name, LdLua *lua, const gchar *ident) self = g_object_new (LD_TYPE_LUA_SYMBOL, NULL); - /* TODO: Set the symbol name. */ + ld_symbol_set_name (LD_SYMBOL (self), name); self->priv->lua = lua; g_object_ref (lua); diff --git a/src/ld-symbol.c b/src/ld-symbol.c index 0c79d23..c1d9abf 100644 --- a/src/ld-symbol.c +++ b/src/ld-symbol.c @@ -37,6 +37,20 @@ struct _LdSymbolPrivate G_DEFINE_ABSTRACT_TYPE (LdSymbol, ld_symbol, G_TYPE_OBJECT); +enum +{ + PROP_0, + PROP_NAME +}; + +static void +ld_symbol_get_property (GObject *object, guint property_id, + GValue *value, GParamSpec *pspec); + +static void +ld_symbol_set_property (GObject *object, guint property_id, + const GValue *value, GParamSpec *pspec); + static void ld_symbol_finalize (GObject *gobject); @@ -44,10 +58,23 @@ static void ld_symbol_class_init (LdSymbolClass *klass) { GObjectClass *object_class; + GParamSpec *pspec; object_class = G_OBJECT_CLASS (klass); + object_class->get_property = ld_symbol_get_property; + object_class->set_property = ld_symbol_set_property; object_class->finalize = ld_symbol_finalize; +/** + * LdSymbol:name: + * + * The name of this symbol. + */ + pspec = g_param_spec_string ("name", "Name", + "The name of this symbol.", + "", G_PARAM_READWRITE); + g_object_class_install_property (object_class, PROP_NAME, pspec); + g_type_class_add_private (klass, sizeof (LdSymbolPrivate)); } @@ -58,6 +85,40 @@ ld_symbol_init (LdSymbol *self) (self, LD_TYPE_SYMBOL, LdSymbolPrivate); } +static void +ld_symbol_get_property (GObject *object, guint property_id, + GValue *value, GParamSpec *pspec) +{ + LdSymbol *self; + + self = LD_SYMBOL (object); + switch (property_id) + { + case PROP_NAME: + g_value_set_string (value, ld_symbol_get_name (self)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + } +} + +static void +ld_symbol_set_property (GObject *object, guint property_id, + const GValue *value, GParamSpec *pspec) +{ + LdSymbol *self; + + self = LD_SYMBOL (object); + switch (property_id) + { + case PROP_NAME: + ld_symbol_set_name (self, g_value_get_string (value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + } +} + static void ld_symbol_finalize (GObject *gobject) { @@ -65,10 +126,44 @@ ld_symbol_finalize (GObject *gobject) self = LD_SYMBOL (gobject); + if (self->priv->name) + g_free (self->priv->name); + /* Chain up to the parent class. */ G_OBJECT_CLASS (ld_symbol_parent_class)->finalize (gobject); } +/** + * ld_symbol_set_name: + * @self: An #LdSymbol object. + * @name: A new name for the symbol. + * + * Set the name of a symbol. + */ +void +ld_symbol_set_name (LdSymbol *self, const gchar *name) +{ + g_return_if_fail (LD_IS_SYMBOL (self)); + g_return_if_fail (name != NULL); + + if (self->priv->name) + g_free (self->priv->name); + self->priv->name = g_strdup (name); +} + +/** + * ld_symbol_get_name: + * @self: An #LdSymbol object. + * + * Return value: The name of the symbol. + */ +const gchar * +ld_symbol_get_name (LdSymbol *self) +{ + g_return_if_fail (LD_IS_SYMBOL (self)); + return self->priv->name; +} + /** * ld_symbol_draw: * @self: A symbol object. diff --git a/src/ld-symbol.h b/src/ld-symbol.h index 7e8a00e..4010107 100644 --- a/src/ld-symbol.h +++ b/src/ld-symbol.h @@ -57,11 +57,12 @@ struct _LdSymbolClass GType ld_symbol_get_type (void) G_GNUC_CONST; +void ld_symbol_set_name (LdSymbol *self, const gchar *name); +const gchar *ld_symbol_get_name (LdSymbol *self); + void ld_symbol_draw (LdSymbol *self, cairo_t *cr); -/* TODO: Interface for symbol terminals - * Interface + property for symbol name (will be used by _new) - */ +/* TODO: Interface for symbol terminals. */ G_END_DECLS -- cgit v1.2.3-70-g09d2