Add ld_category_get_path() and use it.

This commit is contained in:
Přemysl Eric Janouch 2012-09-09 16:39:36 +02:00
parent 15d8c257d1
commit 09d6bda3db
3 changed files with 44 additions and 0 deletions

View File

@ -28,6 +28,7 @@
struct _LdCategorySymbolViewPrivate struct _LdCategorySymbolViewPrivate
{ {
LdCategory *category; LdCategory *category;
gchar *path;
guint height_negotiation : 1; guint height_negotiation : 1;
}; };
@ -106,6 +107,7 @@ ld_category_symbol_view_finalize (GObject *gobject)
if (self->priv->category) if (self->priv->category)
g_object_unref (self->priv->category); g_object_unref (self->priv->category);
g_free (self->priv->path);
/* Chain up to the parent class. */ /* Chain up to the parent class. */
G_OBJECT_CLASS (ld_category_symbol_view_parent_class)->finalize (gobject); 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)); g_return_if_fail (LD_IS_CATEGORY (category));
if (self->priv->category) if (self->priv->category)
{
g_object_unref (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; self->priv->category = category;
g_object_ref (category); g_object_ref (category);

View File

@ -428,6 +428,38 @@ ld_category_get_parent (LdCategory *self)
return self->priv->parent; 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 static void
on_category_notify_name (LdCategory *category, on_category_notify_name (LdCategory *category,
GParamSpec *pspec, gpointer user_data) GParamSpec *pspec, gpointer user_data)

View File

@ -67,6 +67,7 @@ const GSList *ld_category_get_symbols (LdCategory *self);
void ld_category_set_parent (LdCategory *self, LdCategory *parent); void ld_category_set_parent (LdCategory *self, LdCategory *parent);
LdCategory *ld_category_get_parent (LdCategory *self); LdCategory *ld_category_get_parent (LdCategory *self);
gchar *ld_category_get_path (LdCategory *self);
gboolean ld_category_add_child (LdCategory *self, LdCategory *category); gboolean ld_category_add_child (LdCategory *self, LdCategory *category);
void ld_category_remove_child (LdCategory *self, LdCategory *category); void ld_category_remove_child (LdCategory *self, LdCategory *category);