diff options
author | Přemysl Janouch <p.janouch@gmail.com> | 2010-10-24 13:43:41 +0200 |
---|---|---|
committer | Přemysl Janouch <p.janouch@gmail.com> | 2010-10-26 16:40:21 +0200 |
commit | 2b9b54340220e1f93e1dfd000ec2e23000dbb5b9 (patch) | |
tree | 838e8ac4ff6fddad39b092d751b8ffc208d774ff /src | |
parent | ba3b348dfde4949c7632777bd93d951396c41694 (diff) | |
download | logdiag-2b9b54340220e1f93e1dfd000ec2e23000dbb5b9.tar.gz logdiag-2b9b54340220e1f93e1dfd000ec2e23000dbb5b9.tar.xz logdiag-2b9b54340220e1f93e1dfd000ec2e23000dbb5b9.zip |
Implement the LdSymbol "name" property.
Diffstat (limited to 'src')
-rw-r--r-- | src/ld-lua-symbol.c | 2 | ||||
-rw-r--r-- | src/ld-symbol.c | 95 | ||||
-rw-r--r-- | src/ld-symbol.h | 7 |
3 files changed, 100 insertions, 4 deletions
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)); } @@ -59,17 +86,85 @@ ld_symbol_init (LdSymbol *self) } 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) { LdSymbol *self; 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. * @cr: A cairo surface to be drawn on. 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 |