[gnome-software/594-update-all-button-should-be-insensitive-when-installing-flatpak-updates] gs-updates-section: Disable update button when all applications are updating
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/594-update-all-button-should-be-insensitive-when-installing-flatpak-updates] gs-updates-section: Disable update button when all applications are updating
- Date: Thu, 3 Dec 2020 13:20:28 +0000 (UTC)
commit 0b0ce2880c0e60ba083a73969abba270850b4754
Author: Milan Crha <mcrha redhat com>
Date: Thu Dec 3 14:19:11 2020 +0100
gs-updates-section: Disable update button when all applications are updating
Closes https://gitlab.gnome.org/GNOME/gnome-software/-/issues/594
Closes https://gitlab.gnome.org/GNOME/gnome-software/-/merge_requests/557
lib/gs-app-list.c | 40 +++++++++++++++++++++++++++++++++++++++-
lib/gs-app-list.h | 5 +++++
src/gs-updates-section.c | 30 ++++++++++++++++++++++++++++++
3 files changed, 74 insertions(+), 1 deletion(-)
---
diff --git a/lib/gs-app-list.c b/lib/gs-app-list.c
index f2f599bc..d77e36ff 100644
--- a/lib/gs-app-list.c
+++ b/lib/gs-app-list.c
@@ -34,6 +34,7 @@ struct _GsAppList
GsAppListFlags flags;
AsAppState state;
guint progress; /* 0–100 inclusive, or %GS_APP_PROGRESS_UNKNOWN */
+ gboolean notify_state_always;
};
G_DEFINE_TYPE (GsAppList, gs_app_list, G_TYPE_OBJECT)
@@ -175,7 +176,7 @@ gs_app_list_invalidate_state (GsAppList *self)
break;
}
}
- if (self->state != state) {
+ if (self->state != state || self->notify_state_always) {
self->state = state;
g_object_notify (G_OBJECT (self), "state");
}
@@ -961,3 +962,40 @@ gs_app_list_new (void)
list = g_object_new (GS_TYPE_APP_LIST, NULL);
return GS_APP_LIST (list);
}
+
+/**
+ * gs_app_list_set_notify_state_always:
+ * @list: a #GsAppList
+ * @notify_state_always: value to set
+ *
+ * Set whether the state change on the applications covered by the @list
+ * should be notified always. If set to %FALSE, the @list notifies only
+ * when the overall @list state changes.
+ *
+ * Since: 3.40
+ **/
+void
+gs_app_list_set_notify_state_always (GsAppList *list,
+ gboolean notify_state_always)
+{
+ g_return_if_fail (GS_IS_APP_LIST (list));
+
+ list->notify_state_always = notify_state_always;
+}
+
+/**
+ * gs_app_list_get_notify_state_always:
+ * @list: a #GsAppList
+ *
+ * Returns: whether notifies about state change whenever any of
+ * the applications in the @list changes its state
+ *
+ * Since: 3.40
+ **/
+gboolean
+gs_app_list_get_notify_state_always (GsAppList *list)
+{
+ g_return_val_if_fail (GS_IS_APP_LIST (list), FALSE);
+
+ return list->notify_state_always;
+}
diff --git a/lib/gs-app-list.h b/lib/gs-app-list.h
index abb405b0..d9492ae8 100644
--- a/lib/gs-app-list.h
+++ b/lib/gs-app-list.h
@@ -42,5 +42,10 @@ void gs_app_list_sort (GsAppList *list,
void gs_app_list_filter (GsAppList *list,
GsAppListFilterFunc func,
gpointer user_data);
+void gs_app_list_set_notify_state_always
+ (GsAppList *list,
+ gboolean notify_state_always);
+gboolean gs_app_list_get_notify_state_always
+ (GsAppList *list);
G_END_DECLS
diff --git a/src/gs-updates-section.c b/src/gs-updates-section.c
index 24bb419d..a2081d1c 100644
--- a/src/gs-updates-section.c
+++ b/src/gs-updates-section.c
@@ -600,6 +600,28 @@ gs_updates_section_progress_notify_cb (GsAppList *list,
gs_app_list_get_progress (list));
}
+static void
+gs_updates_section_state_notify_cb (GsAppList *list,
+ GParamSpec *pspec,
+ GsUpdatesSection *self)
+{
+ guint ii, len, busy = 0;
+
+ len = gs_app_list_length (list);
+
+ for (ii = 0; ii < len; ii++) {
+ GsApp *app = gs_app_list_index (list, ii);
+ AsAppState state = gs_app_get_state (app);
+
+ if (state == AS_APP_STATE_INSTALLING ||
+ state == AS_APP_STATE_REMOVING) {
+ busy++;
+ }
+ }
+
+ gtk_widget_set_sensitive (self->button_update, busy < len);
+}
+
static void
gs_updates_section_init (GsUpdatesSection *self)
{
@@ -641,5 +663,13 @@ gs_updates_section_new (GsUpdatesSectionKind kind,
self->plugin_loader = g_object_ref (plugin_loader);
self->page = g_object_ref (page);
self->section_header = g_object_ref_sink (_build_section_header (self));
+
+ if (self->kind == GS_UPDATES_SECTION_KIND_ONLINE) {
+ gs_app_list_set_notify_state_always (self->list, TRUE);
+ g_signal_connect_object (self->list, "notify::state",
+ G_CALLBACK (gs_updates_section_state_notify_cb),
+ self, 0);
+ }
+
return GTK_LIST_BOX (self);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]