[gnome-software] trivial: Add a way to find out if a GsAppList has been truncated
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] trivial: Add a way to find out if a GsAppList has been truncated
- Date: Wed, 19 Apr 2017 21:22:36 +0000 (UTC)
commit e33ff0d560ecee0af9ea5e09b6377c9ae4688b6a
Author: Richard Hughes <richard hughsie com>
Date: Wed Apr 19 20:04:58 2017 +0100
trivial: Add a way to find out if a GsAppList has been truncated
lib/gs-app-list-private.h | 18 ++++++++++++++++++
lib/gs-app-list.c | 23 +++++++++++++++++++++++
lib/gs-self-test.c | 2 ++
3 files changed, 43 insertions(+), 0 deletions(-)
---
diff --git a/lib/gs-app-list-private.h b/lib/gs-app-list-private.h
index 2a477b1..76466f8 100644
--- a/lib/gs-app-list-private.h
+++ b/lib/gs-app-list-private.h
@@ -27,6 +27,22 @@
G_BEGIN_DECLS
/**
+ * GsAppListFlags:
+ * @GS_APP_LIST_FLAG_NONE: No flags set
+ * @GS_APP_LIST_FLAG_IS_RANDOMIZED: List has been randomized
+ * @GS_APP_LIST_FLAG_IS_TRUNCATED: List has been truncated
+ *
+ * Flags used to describe the list.
+ **/
+typedef enum {
+ GS_APP_LIST_FLAG_NONE = 0,
+ GS_APP_LIST_FLAG_IS_RANDOMIZED = 1 << 0,
+ GS_APP_LIST_FLAG_IS_TRUNCATED = 1 << 1,
+ /*< private >*/
+ GS_APP_LIST_FLAG_LAST
+} GsAppListFlags;
+
+/**
* GsAppListFilterFlags:
* @GS_APP_LIST_FILTER_FLAG_NONE: No flags set
* @GS_APP_LIST_FILTER_FLAG_PRIORITY: Filter by application priority
@@ -60,6 +76,8 @@ void gs_app_list_randomize (GsAppList *list);
void gs_app_list_remove_all (GsAppList *list);
void gs_app_list_truncate (GsAppList *list,
guint length);
+gboolean gs_app_list_has_flag (GsAppList *list,
+ GsAppListFlags flag);
G_END_DECLS
diff --git a/lib/gs-app-list.c b/lib/gs-app-list.c
index f3d5fa7..c7de5be 100644
--- a/lib/gs-app-list.c
+++ b/lib/gs-app-list.c
@@ -83,6 +83,23 @@ gs_app_list_lookup (GsAppList *list, const gchar *unique_id)
return g_hash_table_lookup (list->hash_by_id, unique_id);
}
+/**
+ * gs_app_list_has_flag:
+ * @list: A #GsAppList
+ * @flag: A flag to test, e.g. %GS_APP_LIST_FLAG_IS_TRUNCATED
+ *
+ * Gets if a specific flag is set.
+ *
+ * Returns: %TRUE if the flag is set
+ *
+ * Since: 3.24
+ **/
+gboolean
+gs_app_list_has_flag (GsAppList *list, GsAppListFlags flag)
+{
+ return (list->flags & flag) > 0;
+}
+
static gboolean
gs_app_list_check_for_duplicate (GsAppList *list, GsApp *app)
{
@@ -367,6 +384,9 @@ gs_app_list_truncate (GsAppList *list, guint length)
g_return_if_fail (GS_IS_APP_LIST (list));
g_return_if_fail (length <= list->array->len);
+ /* mark this list as unworthy */
+ list->flags |= GS_APP_LIST_FLAG_IS_TRUNCATED;
+
/* everything */
if (length == 0) {
gs_app_list_remove_all (list);
@@ -426,6 +446,9 @@ gs_app_list_randomize (GsAppList *list)
g_return_if_fail (GS_IS_APP_LIST (list));
+ /* mark this list as random */
+ list->flags |= GS_APP_LIST_FLAG_IS_RANDOMIZED;
+
key = g_strdup_printf ("Plugin::sort-key[%p]", list);
rand = g_rand_new ();
date = g_date_time_new_now_utc ();
diff --git a/lib/gs-self-test.c b/lib/gs-self-test.c
index 3b91429..65bab6d 100644
--- a/lib/gs-self-test.c
+++ b/lib/gs-self-test.c
@@ -340,9 +340,11 @@ gs_plugin_func (void)
app = gs_app_new ("c");
gs_app_list_add (list, app);
g_object_unref (app);
+ g_assert (!gs_app_list_has_flag (list, GS_APP_LIST_FLAG_IS_TRUNCATED));
g_assert_cmpint (gs_app_list_get_size_peak (list), ==, 3);
gs_app_list_truncate (list, 3);
g_assert_cmpint (gs_app_list_length (list), ==, 3);
+ g_assert (gs_app_list_has_flag (list, GS_APP_LIST_FLAG_IS_TRUNCATED));
g_assert_cmpint (gs_app_list_get_size_peak (list), ==, 3);
gs_app_list_truncate (list, 2);
g_assert_cmpint (gs_app_list_length (list), ==, 2);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]