[gnome-software] Add gs_category_get_size() to get the number of applications in each category



commit a104dc62e670ebfd042b30351b95775c89ad4f44
Author: Richard Hughes <richard hughsie com>
Date:   Mon Sep 16 10:46:03 2013 +0100

    Add gs_category_get_size() to get the number of applications in each category

 src/gs-category.c |   29 +++++++++++++++++++++++++++++
 src/gs-category.h |    2 ++
 2 files changed, 31 insertions(+), 0 deletions(-)
---
diff --git a/src/gs-category.c b/src/gs-category.c
index e27fc8e..8caff79 100644
--- a/src/gs-category.c
+++ b/src/gs-category.c
@@ -35,11 +35,39 @@ struct GsCategoryPrivate
        gchar           *id;
        gchar           *name;
        GsCategory      *parent;
+       guint            size;
        GList           *subcategories;
 };
 
 G_DEFINE_TYPE (GsCategory, gs_category, G_TYPE_OBJECT)
 
+/**
+ * gs_category_get_size:
+ *
+ * Returns how many applications the category could contain.
+ *
+ * NOTE: This may over-estimate the number if duplicate applications are
+ * filtered or core applications are not shown.
+ **/
+guint
+gs_category_get_size (GsCategory *category)
+{
+       g_return_val_if_fail (GS_IS_CATEGORY (category), 0);
+       return category->priv->size;
+}
+
+/**
+ * gs_category_increment_size:
+ *
+ * Adds one to the size count if an application is available
+ **/
+void
+gs_category_increment_size (GsCategory *category)
+{
+       g_return_if_fail (GS_IS_CATEGORY (category));
+       category->priv->size++;
+}
+
 const gchar *
 gs_category_get_id (GsCategory *category)
 {
@@ -119,6 +147,7 @@ gs_category_sort_subcategories (GsCategory *category)
                /* TRANSLATORS: this is where all applications that don't
                 * fit in other groups are put */
                all = gs_category_new (category, NULL, _("General"));
+               all->priv->size = G_MAXUINT;
                gs_category_add_subcategory (category, all);
        }
 
diff --git a/src/gs-category.h b/src/gs-category.h
index f7c6ff4..794e51e 100644
--- a/src/gs-category.h
+++ b/src/gs-category.h
@@ -61,6 +61,8 @@ void           gs_category_sort_subcategories (GsCategory     *category);
 GList          *gs_category_get_subcategories  (GsCategory     *category);
 void            gs_category_add_subcategory    (GsCategory     *category,
                                                 GsCategory     *subcategory);
+guint           gs_category_get_size           (GsCategory     *category);
+void            gs_category_increment_size     (GsCategory     *category);
 
 G_END_DECLS
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]