From 6a633c832153247fd0b7c1ce3b8e59871b6a6455 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=99emysl=20Janouch?= Date: Wed, 29 Aug 2012 18:27:41 +0200 Subject: Renaming, order categories by name. So at least in English the order will make some sense. And it shall stay consistent. --- liblogdiag/ld-symbol-category.c | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) (limited to 'liblogdiag/ld-symbol-category.c') diff --git a/liblogdiag/ld-symbol-category.c b/liblogdiag/ld-symbol-category.c index 0e2a220..f5f5b75 100644 --- a/liblogdiag/ld-symbol-category.c +++ b/liblogdiag/ld-symbol-category.c @@ -329,60 +329,70 @@ static void on_category_notify_name (LdSymbolCategory *category, GParamSpec *pspec, gpointer user_data) { - /* XXX: We could disown the category if a name collision has occured. */ + LdSymbolCategory *self; + + self = (LdSymbolCategory *) user_data; g_warning ("name of a library subcategory has changed"); + + /* The easy way of handling it. */ + g_object_ref (category); + ld_symbol_category_remove_child (self, category); + ld_symbol_category_add_child (self, category); + g_object_unref (category); } /** - * ld_symbol_category_insert_subcategory: + * ld_symbol_category_add_child: * @self: an #LdSymbolCategory object. * @category: the category to be inserted. - * @pos: the position at which the category will be inserted. - * Negative values will append to the end of list. * * Insert a subcategory into the category. * * Return value: %TRUE if successful (no name collisions). */ gboolean -ld_symbol_category_insert_subcategory (LdSymbolCategory *self, - LdSymbolCategory *category, gint pos) +ld_symbol_category_add_child (LdSymbolCategory *self, + LdSymbolCategory *category) { const gchar *name; - const GSList *iter; + GSList *iter; g_return_val_if_fail (LD_IS_SYMBOL_CATEGORY (self), FALSE); g_return_val_if_fail (LD_IS_SYMBOL_CATEGORY (category), FALSE); - /* Check for name collisions. */ name = ld_symbol_category_get_name (category); for (iter = self->priv->subcategories; iter; iter = iter->next) { - if (!strcmp (name, ld_symbol_category_get_name (iter->data))) + gint comp; + + comp = g_utf8_collate (name, ld_symbol_category_get_name (iter->data)); + if (!comp) { g_warning ("attempted to insert multiple `%s' subcategories into" " category `%s'", name, ld_symbol_category_get_name (self)); return FALSE; } + if (comp < 0) + break; } g_signal_connect (category, "notify::name", G_CALLBACK (on_category_notify_name), self); - self->priv->subcategories - = g_slist_insert (self->priv->subcategories, category, pos); + self->priv->subcategories = g_slist_insert_before + (self->priv->subcategories, iter, category); g_object_ref (category); return TRUE; } /** - * ld_symbol_category_remove_subcategory: + * ld_symbol_category_remove_child: * @self: an #LdSymbolCategory object. * @category: the category to be removed. * * Removes a subcategory from the category. */ void -ld_symbol_category_remove_subcategory (LdSymbolCategory *self, +ld_symbol_category_remove_child (LdSymbolCategory *self, LdSymbolCategory *category) { g_return_if_fail (LD_IS_SYMBOL_CATEGORY (self)); @@ -399,14 +409,14 @@ ld_symbol_category_remove_subcategory (LdSymbolCategory *self, } /** - * ld_symbol_category_get_subcategories: + * ld_symbol_category_get_children: * @self: an #LdSymbolCategory object. * * Return value: (element-type LdSymbolCategory *): * a list of subcategories. Do not modify. */ const GSList * -ld_symbol_category_get_subcategories (LdSymbolCategory *self) +ld_symbol_category_get_children (LdSymbolCategory *self) { g_return_val_if_fail (LD_IS_SYMBOL_CATEGORY (self), NULL); return self->priv->subcategories; -- cgit v1.2.3