[gnome-software/1266-indeterminate-progress-bar-for-os-updates] gs-app-list: Add gs_app_list_override_progress()
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/1266-indeterminate-progress-bar-for-os-updates] gs-app-list: Add gs_app_list_override_progress()
- Date: Wed, 13 Oct 2021 14:00:54 +0000 (UTC)
commit 875cb18106b67f4a45af80339f7a76a153defe24
Author: Milan Crha <mcrha redhat com>
Date: Wed Oct 13 15:49:52 2021 +0200
gs-app-list: Add gs_app_list_override_progress()
Override the progress property to be this value, or use GS_APP_PROGRESS_UNKNOWN,
to unset the override. This can be used when only the overall progress is known,
instead of a per-application progress.
lib/gs-app-list.c | 38 ++++++++++++++++++++++++++++++++++++++
lib/gs-app-list.h | 2 ++
2 files changed, 40 insertions(+)
---
diff --git a/lib/gs-app-list.c b/lib/gs-app-list.c
index 33a01ce56..b80a7b6d6 100644
--- a/lib/gs-app-list.c
+++ b/lib/gs-app-list.c
@@ -35,6 +35,7 @@ struct _GsAppList
GsAppListFlags flags;
GsAppState state;
guint progress; /* 0–100 inclusive, or %GS_APP_PROGRESS_UNKNOWN */
+ guint custom_progress; /* overrides the 'progress', if not
%GS_APP_PROGRESS_UNKNOWN */
};
G_DEFINE_TYPE (GsAppList, gs_app_list, G_TYPE_OBJECT)
@@ -91,9 +92,45 @@ guint
gs_app_list_get_progress (GsAppList *list)
{
g_return_val_if_fail (GS_IS_APP_LIST (list), GS_APP_PROGRESS_UNKNOWN);
+ if (list->custom_progress != GS_APP_PROGRESS_UNKNOWN)
+ return list->custom_progress;
return list->progress;
}
+static gboolean
+app_list_notify_progress_idle_cb (gpointer user_data)
+{
+ GsAppList *list = user_data;
+
+ g_object_notify (G_OBJECT (list), "progress");
+ g_object_unref (list);
+
+ return G_SOURCE_REMOVE;
+}
+
+/**
+ * gs_app_list_override_progress:
+ * @list: a #GsAppList
+ * @progress: a progress to set, between 0 and 100 inclusive, or %GS_APP_PROGRESS_UNKNOWN
+ *
+ * Override the progress property to be this value, or use %GS_APP_PROGRESS_UNKNOWN,
+ * to unset the override. This can be used when only the overall progress is known,
+ * instead of a per-application progress.
+ *
+ * Since: 42
+ **/
+void
+gs_app_list_override_progress (GsAppList *list,
+ guint progress)
+{
+ g_return_if_fail (GS_IS_APP_LIST (list));
+
+ if (list->custom_progress != progress) {
+ list->custom_progress = progress;
+ g_idle_add (app_list_notify_progress_idle_cb, g_object_ref (list));
+ }
+}
+
static void
gs_app_list_add_watched_for_app (GsAppList *list, GPtrArray *apps, GsApp *app)
{
@@ -969,6 +1006,7 @@ gs_app_list_init (GsAppList *list)
{
g_mutex_init (&list->mutex);
list->array = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
+ list->custom_progress = GS_APP_PROGRESS_UNKNOWN;
}
/**
diff --git a/lib/gs-app-list.h b/lib/gs-app-list.h
index 1330e8048..b762e4f45 100644
--- a/lib/gs-app-list.h
+++ b/lib/gs-app-list.h
@@ -82,5 +82,7 @@ void gs_app_list_sort (GsAppList *list,
void gs_app_list_filter (GsAppList *list,
GsAppListFilterFunc func,
gpointer user_data);
+void gs_app_list_override_progress (GsAppList *list,
+ guint progress);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]