Skip to content

Commit

Permalink
Improve low-quality category check and extend its blacklist
Browse files Browse the repository at this point in the history
  • Loading branch information
ximion committed Jan 4, 2024
1 parent 1460994 commit bed40d5
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 23 deletions.
23 changes: 4 additions & 19 deletions src/as-desktop-entry.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,29 +141,14 @@ as_add_filtered_categories (gchar **cats, AsComponent *cpt, GPtrArray *issues)
for (i = 0; cats[i] != NULL; i++) {
const gchar *cat = cats[i];

if (g_strcmp0 (cat, "GTK") == 0)
continue;
if (g_strcmp0 (cat, "Qt") == 0)
continue;
if (g_strcmp0 (cat, "GNOME") == 0)
continue;
if (g_strcmp0 (cat, "KDE") == 0)
continue;
if (g_strcmp0 (cat, "GUI") == 0)
continue;
if (g_strcmp0 (cat, "Application") == 0)
continue;

/* custom categories are ignored */
if (g_str_has_prefix (cat, "X-"))
continue;
if (g_str_has_prefix (cat, "x-"))
continue;

/* check for invalid */
if (g_strcmp0 (cat, "") == 0)
continue;

/* ignore low-quality and custom categories */
if (as_utils_category_name_is_bad (cat))
continue;

/* add the category if it is valid */
if (as_utils_is_category_name (cat))
as_component_add_category (cpt, cat);
Expand Down
2 changes: 2 additions & 0 deletions src/as-utils-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ void as_ref_string_assign_transfer (GRefString **rstr_ptr, GRefString *new_rstr)
AS_INTERNAL_VISIBLE
gboolean as_utils_extract_tarball (const gchar *filename, const gchar *target_dir, GError **error);

gboolean as_utils_is_ignored_category_name (const gchar *category_name);

gboolean as_utils_is_platform_triplet_arch (const gchar *arch);
gboolean as_utils_is_platform_triplet_oskernel (const gchar *os);
gboolean as_utils_is_platform_triplet_osenv (const gchar *env);
Expand Down
56 changes: 52 additions & 4 deletions src/as-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -1278,7 +1278,7 @@ as_utils_ensure_resources (void)
}

/**
* as_utils_is_category_id:
* as_utils_is_category_name:
* @category_name: a XDG category name, e.g. "ProjectManagement"
*
* Searches the known list of registered XDG category names.
Expand Down Expand Up @@ -1316,6 +1316,56 @@ as_utils_is_category_name (const gchar *category_name)
return g_strstr_len (g_bytes_get_data (data, NULL), -1, key) != NULL;
}

/**
* as_utils_category_name_is_bad:
* @category_name: a XDG category name, e.g. "ProjectManagement"
*
* We want to ignore certain low-quality categories like "GTK", "Qt"
* or "GUI" that convey no meaning to the user at all,
* as well as any custom-defined categories.
*
* This functiuon checks for those, adn should be used in
* conjunction with %as_utils_is_category_name.
*
* It is not invalid to use the categories in desktop-entry files,
* but they should not end up in AppStream catalog metadata, and
* should ideally not be used in MetaInfo files as well.
*
* Returns: %TRUE if the category should be ignored.
**/
gboolean
as_utils_category_name_is_bad (const gchar *category_name)
{
if (as_str_equal0 (category_name, "GTK"))
return TRUE;
if (as_str_equal0 (category_name, "Qt"))
return TRUE;
if (as_str_equal0 (category_name, "KDE"))
return TRUE;
if (as_str_equal0 (category_name, "GNOME"))
return TRUE;
if (as_str_equal0 (category_name, "Motif"))
return TRUE;
if (as_str_equal0 (category_name, "Java"))
return TRUE;
if (as_str_equal0 (category_name, "GUI"))
return TRUE;
if (as_str_equal0 (category_name, "Application"))
return TRUE;
if (as_str_equal0 (category_name, "XFCE"))
return TRUE;
if (as_str_equal0 (category_name, "DDE"))
return TRUE;

/* we want to ignore custom categories */
if (g_str_has_prefix (cat, "X-"))
return TRUE;
if (g_str_has_prefix (cat, "x-"))
return TRUE;

return FALSE;
}

/**
* as_utils_is_tld:
* @tld: a top-level domain without dot, e.g. "de", "org", "name"
Expand Down Expand Up @@ -1665,9 +1715,7 @@ as_utils_sort_components_into_categories (GPtrArray *cpts,
GPtrArray *categories,
gboolean check_duplicates)
{
guint i;

for (i = 0; i < cpts->len; i++) {
for (guint i = 0; i < cpts->len; i++) {
guint j;
AsComponent *cpt = AS_COMPONENT (g_ptr_array_index (cpts, i));

Expand Down

0 comments on commit bed40d5

Please sign in to comment.