From 09d6bda3db6ba986dad3dd4150e502ef664d6812 Mon Sep 17 00:00:00 2001
From: Přemysl Janouch
Date: Sun, 9 Sep 2012 16:39:36 +0200
Subject: Add ld_category_get_path() and use it.
---
liblogdiag/ld-category-symbol-view.c | 11 +++++++++++
liblogdiag/ld-category.c | 32 ++++++++++++++++++++++++++++++++
liblogdiag/ld-category.h | 1 +
3 files changed, 44 insertions(+)
(limited to 'liblogdiag')
diff --git a/liblogdiag/ld-category-symbol-view.c b/liblogdiag/ld-category-symbol-view.c
index 85f7c1e..36c0d0f 100644
--- a/liblogdiag/ld-category-symbol-view.c
+++ b/liblogdiag/ld-category-symbol-view.c
@@ -28,6 +28,7 @@
struct _LdCategorySymbolViewPrivate
{
LdCategory *category;
+ gchar *path;
guint height_negotiation : 1;
};
@@ -106,6 +107,7 @@ ld_category_symbol_view_finalize (GObject *gobject)
if (self->priv->category)
g_object_unref (self->priv->category);
+ g_free (self->priv->path);
/* Chain up to the parent class. */
G_OBJECT_CLASS (ld_category_symbol_view_parent_class)->finalize (gobject);
@@ -234,8 +236,17 @@ ld_category_symbol_view_set_category (LdCategorySymbolView *self,
g_return_if_fail (LD_IS_CATEGORY (category));
if (self->priv->category)
+ {
g_object_unref (self->priv->category);
+ g_free (self->priv->path);
+ self->priv->path = NULL;
+ }
+
+ /* XXX: We should rebuild the path if the name changes but it shouldn't
+ * happen and we would have to track the parents, too. */
+ self->priv->path = ld_category_get_path (category);
+
self->priv->category = category;
g_object_ref (category);
diff --git a/liblogdiag/ld-category.c b/liblogdiag/ld-category.c
index b15b6de..369de65 100644
--- a/liblogdiag/ld-category.c
+++ b/liblogdiag/ld-category.c
@@ -428,6 +428,38 @@ ld_category_get_parent (LdCategory *self)
return self->priv->parent;
}
+/**
+ * ld_category_get_path:
+ * @self: an #LdCategory object.
+ *
+ * Return value: the path to this category within the library.
+ */
+gchar *
+ld_category_get_path (LdCategory *self)
+{
+ LdCategory *iter;
+ gchar *path = NULL, *new_path;
+
+ g_return_val_if_fail (LD_IS_CATEGORY (self), NULL);
+
+ for (iter = self; iter; iter = ld_category_get_parent (iter))
+ {
+ const gchar *name;
+
+ /* Stop at the root category. */
+ name = ld_category_get_name (iter);
+ if (!strcmp (name, LD_LIBRARY_IDENTIFIER_SEPARATOR))
+ break;
+
+ new_path = g_build_path
+ (LD_LIBRARY_IDENTIFIER_SEPARATOR, name, path, NULL);
+ g_free (path);
+ path = new_path;
+ }
+
+ return path;
+}
+
static void
on_category_notify_name (LdCategory *category,
GParamSpec *pspec, gpointer user_data)
diff --git a/liblogdiag/ld-category.h b/liblogdiag/ld-category.h
index 59d6449..77afff2 100644
--- a/liblogdiag/ld-category.h
+++ b/liblogdiag/ld-category.h
@@ -67,6 +67,7 @@ const GSList *ld_category_get_symbols (LdCategory *self);
void ld_category_set_parent (LdCategory *self, LdCategory *parent);
LdCategory *ld_category_get_parent (LdCategory *self);
+gchar *ld_category_get_path (LdCategory *self);
gboolean ld_category_add_child (LdCategory *self, LdCategory *category);
void ld_category_remove_child (LdCategory *self, LdCategory *category);
--
cgit v1.2.3-70-g09d2