/** * as_data_pool_merge_components: * * Merge selected data from two components. */ static void as_data_pool_merge_components (AsDataPool *dpool, AsComponent *src_cpt, AsComponent *dest_cpt) { guint i; gchar **cats; gchar **pkgnames; /* FIXME: We only do this for GNOME Software compatibility. In future, we need better rules on what to merge how, and * whether we want to merge stuff at all. */ cats = as_component_get_categories (src_cpt); if (cats != NULL) { g_autoptr(GHashTable) cat_table = NULL; gchar **new_cats = NULL; cat_table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); for (i = 0; cats[i] != NULL; i++) { g_hash_table_add (cat_table, g_strdup (cats[i])); } cats = as_component_get_categories (dest_cpt); if (cats != NULL) { for (i = 0; cats[i] != NULL; i++) { g_hash_table_add (cat_table, g_strdup (cats[i])); } } new_cats = (gchar**) g_hash_table_get_keys_as_array (cat_table, NULL); as_component_set_categories (dest_cpt, new_cats); } pkgnames = as_component_get_pkgnames (src_cpt); if ((pkgnames != NULL) && (pkgnames[0] != '\0')) as_component_set_pkgnames (dest_cpt, as_component_get_pkgnames (src_cpt)); if (as_component_has_bundle (src_cpt)) as_component_set_bundles_table (dest_cpt, as_component_get_bundles_table (src_cpt)); }
/** * as_merge_components: * * Merge selected data from two components. */ static void as_merge_components (AsComponent *dest_cpt, AsComponent *src_cpt) { guint i; AsMergeKind merge_kind; merge_kind = as_component_get_merge_kind (src_cpt); g_return_if_fail (merge_kind != AS_MERGE_KIND_NONE); /* FIXME: We need to merge more attributes */ /* merge stuff in append mode */ if (merge_kind == AS_MERGE_KIND_APPEND) { GPtrArray *suggestions; GPtrArray *cats; /* merge categories */ cats = as_component_get_categories (src_cpt); if (cats->len > 0) { g_autoptr(GHashTable) cat_table = NULL; GPtrArray *dest_categories; cat_table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); for (i = 0; i < cats->len; i++) { const gchar *cat = (const gchar*) g_ptr_array_index (cats, i); g_hash_table_add (cat_table, g_strdup (cat)); } dest_categories = as_component_get_categories (dest_cpt); if (dest_categories->len > 0) { for (i = 0; i < dest_categories->len; i++) { const gchar *cat = (const gchar*) g_ptr_array_index (dest_categories, i); g_hash_table_add (cat_table, g_strdup (cat)); } } g_ptr_array_set_size (dest_categories, 0); as_hash_table_string_keys_to_array (cat_table, dest_categories); } /* merge suggestions */ suggestions = as_component_get_suggested (src_cpt); if (suggestions != NULL) { for (i = 0; i < suggestions->len; i++) { as_component_add_suggested (dest_cpt, AS_SUGGESTED (g_ptr_array_index (suggestions, i))); } } } /* merge stuff in replace mode */ if (merge_kind == AS_MERGE_KIND_REPLACE) { gchar **pkgnames; /* merge names */ if (as_component_get_name (src_cpt) != NULL) as_component_set_name (dest_cpt, as_component_get_name (src_cpt), as_component_get_active_locale (src_cpt)); /* merge package names */ pkgnames = as_component_get_pkgnames (src_cpt); if ((pkgnames != NULL) && (pkgnames[0] != '\0')) as_component_set_pkgnames (dest_cpt, as_component_get_pkgnames (src_cpt)); /* merge bundles */ if (as_component_has_bundle (src_cpt)) as_component_set_bundles_array (dest_cpt, as_component_get_bundles (src_cpt)); } g_debug ("Merged data for '%s'", as_component_get_data_id (dest_cpt)); }