/** * as_category_new: * * Creates a new #AsCategory. * * Returns: (transfer full): a new #AsCategory **/ AsCategory* as_category_new (void) { AsCategory *cat; cat = g_object_new (AS_TYPE_CATEGORY, NULL); return AS_CATEGORY (cat); }
/** * as_utils_sort_components_into_categories: * @cpts: (element-type AsComponent): List of components. * @categories: (element-type AsCategory): List of categories to sort components into. * @check_duplicates: Whether to check for duplicates. * * Sorts all components in @cpts into the #AsCategory categories listed in @categories. */ void as_utils_sort_components_into_categories (GPtrArray *cpts, GPtrArray *categories, gboolean check_duplicates) { guint i; for (i = 0; i < cpts->len; i++) { guint j; AsComponent *cpt = AS_COMPONENT (g_ptr_array_index (cpts, i)); for (j = 0; j < categories->len; j++) { guint k; GPtrArray *children; gboolean added_to_main = FALSE; AsCategory *main_cat = AS_CATEGORY (g_ptr_array_index (categories, j)); if (as_component_is_member_of_category (cpt, main_cat)) { if (!check_duplicates || !as_category_has_component (main_cat, cpt)) { as_category_add_component (main_cat, cpt); added_to_main = TRUE; } } /* fortunately, categories are only nested one level deep in all known cases. * if this will ever change, we will need to adjust this code to go through * a whole tree of categories, eww... */ children = as_category_get_children (main_cat); for (k = 0; k < children->len; k++) { AsCategory *subcat = AS_CATEGORY (g_ptr_array_index (children, k)); /* skip duplicates */ if (check_duplicates && as_category_has_component (subcat, cpt)) continue; if (as_component_is_member_of_category (cpt, subcat)) { as_category_add_component (subcat, cpt); if (!added_to_main) { if (!check_duplicates || !as_category_has_component (main_cat, cpt)) { as_category_add_component (main_cat, cpt); } } } } } } }
/** * as_category_finalize: */ static void as_category_finalize (GObject *object) { AsCategory *cat = AS_CATEGORY (object); AsCategoryPrivate *priv = GET_PRIVATE (cat); g_free (priv->name); g_free (priv->summary); g_free (priv->icon); g_free (priv->directory); g_list_free_full (priv->included, g_free); g_list_free_full (priv->excluded, g_free); g_list_free_full (priv->subcats, g_object_unref); G_OBJECT_CLASS (as_category_parent_class)->finalize (object); }