[gnome-software/594-update-all-button-should-be-insensitive-when-installing-flatpak-updates: 16/16] gs-updates-section: Disable update button when all applications are updating




commit 1bbf084e5769dd22c787ecfcceaf1e1a9bea1d7c
Author: Milan Crha <mcrha redhat com>
Date:   Fri Dec 4 13:31:02 2020 +0100

    gs-updates-section: Disable update button when all applications are updating
    
    Closes https://gitlab.gnome.org/GNOME/gnome-software/-/issues/594

 lib/gs-app-list.c        | 23 +++++++++++++++++++++++
 src/gs-updates-section.c | 29 +++++++++++++++++++++++++++++
 2 files changed, 52 insertions(+)
---
diff --git a/lib/gs-app-list.c b/lib/gs-app-list.c
index f2f599bc..b459492e 100644
--- a/lib/gs-app-list.c
+++ b/lib/gs-app-list.c
@@ -44,6 +44,13 @@ enum {
        PROP_LAST
 };
 
+enum {
+       SIGNAL_APP_STATE_CHANGED,
+       SIGNAL_LAST
+};
+
+static guint signals [SIGNAL_LAST] = { 0 };
+
 /**
  * gs_app_list_get_state:
  * @list: A #GsAppList
@@ -191,6 +198,8 @@ static void
 gs_app_list_state_notify_cb (GsApp *app, GParamSpec *pspec, GsAppList *self)
 {
        gs_app_list_invalidate_state (self);
+
+       g_signal_emit (self, signals[SIGNAL_APP_STATE_CHANGED], 0, app);
 }
 
 static void
@@ -936,6 +945,20 @@ gs_app_list_class_init (GsAppListClass *klass)
                                   0, GS_APP_PROGRESS_UNKNOWN, GS_APP_PROGRESS_UNKNOWN,
                                   G_PARAM_READABLE);
        g_object_class_install_property (object_class, PROP_PROGRESS, pspec);
+
+       /**
+        * GsAppList:app-state-changed:
+        * @app: a #GsApp
+        *
+        * Emitted when any of the internal #GsApp instances changes its state.
+        *
+        * Since: 3.40
+        */
+       signals [SIGNAL_APP_STATE_CHANGED] =
+               g_signal_new ("app-state-changed",
+                             G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
+                             0, NULL, NULL, g_cclosure_marshal_generic,
+                             G_TYPE_NONE, 1, GS_TYPE_APP);
 }
 
 static void
diff --git a/src/gs-updates-section.c b/src/gs-updates-section.c
index 24bb419d..16cfe436 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_app_state_changed_cb (GsAppList *list,
+                                        GsApp *in_app,
+                                        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,12 @@ 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) {
+               g_signal_connect_object (self->list, "app-state-changed",
+                                        G_CALLBACK (gs_updates_section_app_state_changed_cb),
+                                        self, 0);
+       }
+
        return GTK_LIST_BOX (self);
 }


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