aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2010-10-24 12:43:16 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2010-10-26 16:40:08 +0200
commitba3b348dfde4949c7632777bd93d951396c41694 (patch)
treedb51e339a55e4aa374b5574011dfc7d1844d16d6
parentffc57249c889e656f6dbacd567fd6cc458a3356d (diff)
downloadlogdiag-ba3b348dfde4949c7632777bd93d951396c41694.tar.gz
logdiag-ba3b348dfde4949c7632777bd93d951396c41694.tar.xz
logdiag-ba3b348dfde4949c7632777bd93d951396c41694.zip
Implement the rest of LdSymbolCategory.
Added GObject properties for object parameters. Implemented methods for children management.
-rw-r--r--src/ld-symbol-category.c132
-rw-r--r--src/ld-symbol-category.h6
2 files changed, 135 insertions, 3 deletions
diff --git a/src/ld-symbol-category.c b/src/ld-symbol-category.c
index 15c1351..0eb0dac 100644
--- a/src/ld-symbol-category.c
+++ b/src/ld-symbol-category.c
@@ -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));
}
@@ -63,6 +101,46 @@ ld_symbol_category_init (LdSymbolCategory *self)
}
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)
{
LdSymbolCategory *self;
@@ -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;
+}
+
diff --git a/src/ld-symbol-category.h b/src/ld-symbol-category.h
index 21286c9..113bf83 100644
--- a/src/ld-symbol-category.h
+++ b/src/ld-symbol-category.h
@@ -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