Commit 23050aba authored by Richard Hughes's avatar Richard Hughes
Browse files

Add a 'General' subcategory to return all the results without filtering

parent 8e83ad51
......@@ -21,6 +21,8 @@
#include "config.h"
#include <glib/gi18n.h>
#include "gs-category.h"
static void gs_category_finalize (GObject *object);
......@@ -80,6 +82,48 @@ gs_category_add_subcategory (GsCategory *category, GsCategory *subcategory)
category->priv->subcategories = g_list_prepend (category->priv->subcategories, g_object_ref (subcategory));
}
/**
* gs_category_sort_subcategories_cb:
**/
static gint
gs_category_sort_subcategories_cb (gconstpointer a, gconstpointer b)
{
return g_strcmp0 (gs_category_get_name (GS_CATEGORY (a)),
gs_category_get_name (GS_CATEGORY (b)));
}
/**
* gs_category_sort_subcategories:
**/
void
gs_category_sort_subcategories (GsCategory *category)
{
gboolean subcat_all = FALSE;
GList *l;
GsCategory *all;
GsCategoryPrivate *priv = category->priv;
/* nothing here */
if (priv->subcategories == NULL)
return;
/* ensure there is a general entry */
for (l = priv->subcategories; l != NULL; l = l->next) {
if (gs_category_get_id (GS_CATEGORY (l->data)) == NULL) {
subcat_all = TRUE;
break;
}
}
if (!subcat_all) {
all = gs_category_new (category, NULL, _("General"));
gs_category_add_subcategory (category, all);
}
/* actually sort the data */
priv->subcategories = g_list_sort (priv->subcategories,
gs_category_sort_subcategories_cb);
}
static void
gs_category_class_init (GsCategoryClass *klass)
{
......
......@@ -56,6 +56,7 @@ GsCategory *gs_category_get_parent (GsCategory *categor
const gchar *gs_category_get_name (GsCategory *category);
void gs_category_set_name (GsCategory *category,
const gchar *name);
void gs_category_sort_subcategories (GsCategory *category);
GList *gs_category_get_subcategories (GsCategory *category);
void gs_category_add_subcategory (GsCategory *category,
GsCategory *subcategory);
......
......@@ -1026,6 +1026,7 @@ cd_plugin_loader_get_categories_thread_cb (GSimpleAsyncResult *res,
GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (object);
GsPlugin *plugin;
GsPluginResultsFunc plugin_func = NULL;
GList *l;
guint i;
/* run each plugin */
......@@ -1063,6 +1064,8 @@ cd_plugin_loader_get_categories_thread_cb (GSimpleAsyncResult *res,
/* sort by name */
state->list = g_list_sort (state->list, gs_plugin_loader_category_sort_cb);
for (l = state->list; l != NULL; l = l->next)
gs_category_sort_subcategories (GS_CATEGORY (l->data));
/* success */
if (state->list == NULL) {
......
......@@ -743,6 +743,12 @@ gs_plugin_add_category_apps (GsPlugin *plugin,
if (parent != NULL)
search_id2 = gs_category_get_id (parent);
/* the "General" item has no ID */
if (search_id1 == NULL) {
search_id1 = search_id2;
search_id2 = NULL;
}
/* just look at each app in turn */
for (i = 0; i < plugin->priv->array->len; i++) {
item = g_ptr_array_index (plugin->priv->array, i);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment