[gnome-software] Only show applications in 'Other' that did not match any other subcategories
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] Only show applications in 'Other' that did not match any other subcategories
- Date: Mon, 30 Jun 2014 15:23:07 +0000 (UTC)
commit 16fc2a8a1e30baeb5d9b1241d49168149ccf586d
Author: Richard Hughes <richard hughsie com>
Date: Mon Jun 30 16:10:20 2014 +0100
Only show applications in 'Other' that did not match any other subcategories
Resolves: https://bugzilla.gnome.org/show_bug.cgi?id=732481
src/gs-category.c | 51 +++++++++++---------
src/gs-category.h | 2 +
src/plugins/gs-plugin-appstream.c | 91 ++++++++++++++++++++++---------------
3 files changed, 85 insertions(+), 59 deletions(-)
---
diff --git a/src/gs-category.c b/src/gs-category.c
index d7757b4..70ba1a3 100644
--- a/src/gs-category.c
+++ b/src/gs-category.c
@@ -89,6 +89,24 @@ gs_category_set_name (GsCategory *category, const gchar *name)
}
GsCategory *
+gs_category_find_child (GsCategory *category, const gchar *id)
+{
+ GList *l;
+ GsCategoryPrivate *priv = category->priv;
+ GsCategory *tmp;
+
+ /* find the subcategory */
+ if (priv->subcategories == NULL)
+ return NULL;
+ for (l = priv->subcategories; l != NULL; l = l->next) {
+ tmp = GS_CATEGORY (l->data);
+ if (g_strcmp0 (id, gs_category_get_id (tmp)) == 0)
+ return tmp;
+ }
+ return NULL;
+}
+
+GsCategory *
gs_category_get_parent (GsCategory *category)
{
g_return_val_if_fail (GS_IS_CATEGORY (category), NULL);
@@ -129,12 +147,12 @@ gs_category_sort_subcategories_cb (gconstpointer a, gconstpointer b)
const gchar *id_a = gs_category_get_id (ca);
const gchar *id_b = gs_category_get_id (cb);
- if (!id_a)
+ if (g_strcmp0 (id_a, "other") == 0)
return 1;
else if (g_strcmp0 (id_a, "featured") == 0)
return -1;
- if (!id_b)
+ if (g_strcmp0 (id_b, "other") == 0)
return -1;
else if (g_strcmp0 (id_b, "featured") == 0)
return 1;
@@ -148,33 +166,12 @@ gs_category_sort_subcategories_cb (gconstpointer a, gconstpointer b)
void
gs_category_sort_subcategories (GsCategory *category)
{
- gboolean subcat_all = FALSE;
- GList *l;
- GsCategory *all;
GsCategoryPrivate *priv = category->priv;
- const gchar *id;
/* nothing here */
if (priv->subcategories == NULL)
return;
- /* ensure there is a general entry */
- for (l = priv->subcategories; l != NULL; l = l->next) {
- id = gs_category_get_id (GS_CATEGORY (l->data));
- if (id == NULL) {
- subcat_all = TRUE;
- break;
- }
- }
- if (!subcat_all && g_strcmp0 (category->priv->id, "Addons") != 0) {
- /* TRANSLATORS: this is where all applications that don't
- * fit in other groups are put */
- all = gs_category_new (category, NULL, _("Other"));
- all->priv->size = G_MAXUINT;
- gs_category_add_subcategory (category, all);
- g_object_unref (all);
- }
-
/* actually sort the data */
priv->subcategories = g_list_sort (priv->subcategories,
gs_category_sort_subcategories_cb);
@@ -210,6 +207,14 @@ GsCategory *
gs_category_new (GsCategory *parent, const gchar *id, const gchar *name)
{
GsCategory *category;
+
+ /* special case, we don't want translations in the plugins */
+ if (g_strcmp0 (id, "other") == 0) {
+ /* TRANSLATORS: this is where all applications that don't
+ * fit in other groups are put */
+ name =_("Other");
+ }
+
category = g_object_new (GS_TYPE_CATEGORY, NULL);
category->priv->parent = parent;
category->priv->id = g_strdup (id);
diff --git a/src/gs-category.h b/src/gs-category.h
index 794e51e..acfda4b 100644
--- a/src/gs-category.h
+++ b/src/gs-category.h
@@ -54,6 +54,8 @@ GsCategory *gs_category_new (GsCategory *parent,
const gchar *name);
const gchar *gs_category_get_id (GsCategory *category);
GsCategory *gs_category_get_parent (GsCategory *category);
+GsCategory *gs_category_find_child (GsCategory *category,
+ const gchar *id);
const gchar *gs_category_get_name (GsCategory *category);
void gs_category_set_name (GsCategory *category,
const gchar *name);
diff --git a/src/plugins/gs-plugin-appstream.c b/src/plugins/gs-plugin-appstream.c
index 53827a5..aba6854 100644
--- a/src/plugins/gs-plugin-appstream.c
+++ b/src/plugins/gs-plugin-appstream.c
@@ -889,6 +889,52 @@ out:
}
/**
+ * gs_plugin_add_categories_for_app:
+ */
+static void
+gs_plugin_add_categories_for_app (GList *list, AsApp *app)
+{
+ GList *children;
+ GList *l;
+ GList *l2;
+ GsCategory *category;
+ GsCategory *parent;
+ gboolean found_subcat;
+
+ /* does it match the main category */
+ for (l = list; l != NULL; l = l->next) {
+ parent = GS_CATEGORY (l->data);
+ if (!as_app_has_category (app, gs_category_get_id (parent)))
+ continue;
+ gs_category_increment_size (parent);
+
+ /* does it match any sub-categories */
+ found_subcat = FALSE;
+ children = gs_category_get_subcategories (parent);
+ for (l2 = children; l2 != NULL; l2 = l2->next) {
+ category = GS_CATEGORY (l2->data);
+ if (!as_app_has_category (app, gs_category_get_id (category)))
+ continue;
+ gs_category_increment_size (category);
+ found_subcat = TRUE;
+ }
+ g_list_free (children);
+
+ /* matching the main category but no subcategories means we have
+ * to create a new 'Other' subcategory manually */
+ if (!found_subcat) {
+ category = gs_category_find_child (parent, "other");
+ if (category == NULL) {
+ category = gs_category_new (parent, "other", NULL);
+ gs_category_add_subcategory (parent, category);
+ }
+ as_app_add_category (app, gs_category_get_id (category), -1);
+ gs_category_increment_size (category);
+ }
+ }
+}
+
+/**
* gs_plugin_add_categories:
*/
gboolean
@@ -897,16 +943,9 @@ gs_plugin_add_categories (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
- AsApp *item;
- const gchar *search_id1;
- const gchar *search_id2 = NULL;
- gboolean ret = TRUE;
- GList *l;
- GList *l2;
- GList *children;
+ AsApp *app;
GPtrArray *array;
- GsCategory *category;
- GsCategory *parent;
+ gboolean ret = TRUE;
guint i;
/* load XML files */
@@ -920,33 +959,13 @@ gs_plugin_add_categories (GsPlugin *plugin,
/* find out how many packages are in each category */
gs_profile_start (plugin->profile, "appstream::add-categories");
array = as_store_get_apps (plugin->priv->store);
- for (l = *list; l != NULL; l = l->next) {
- parent = GS_CATEGORY (l->data);
- search_id2 = gs_category_get_id (parent);
- children = gs_category_get_subcategories (parent);
- for (l2 = children; l2 != NULL; l2 = l2->next) {
- category = GS_CATEGORY (l2->data);
-
- /* just look at each app in turn */
- for (i = 0; i < array->len; i++) {
- item = g_ptr_array_index (array, i);
- if (as_app_get_id (item) == NULL)
- continue;
- if (as_app_get_priority (item) < 0)
- continue;
- if (!as_app_has_category (item, search_id2))
- continue;
- search_id1 = gs_category_get_id (category);
- if (search_id1 != NULL &&
- !as_app_has_category (item, search_id1))
- continue;
-
- /* we have another result */
- gs_category_increment_size (category);
- gs_category_increment_size (parent);
- }
- }
- g_list_free (children);
+ for (i = 0; i < array->len; i++) {
+ app = g_ptr_array_index (array, i);
+ if (as_app_get_id (app) == NULL)
+ continue;
+ if (as_app_get_priority (app) < 0)
+ continue;
+ gs_plugin_add_categories_for_app (*list, app);
}
gs_profile_stop (plugin->profile, "appstream::add-categories");
out:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]