[gnome-software] Show a pulsing progressbar if plugins do not report progress notifications



commit db7d30abdba8b86311ace34ff0cfaa8907f572b5
Author: Richard Hughes <richard hughsie com>
Date:   Mon May 22 14:14:10 2017 +0100

    Show a pulsing progressbar if plugins do not report progress notifications
    
    This avoids the UI just sitting at 0% complete and then disappearing.

 src/gs-loading-page.c |   34 ++++++++++++++++++++++++++++++++--
 1 files changed, 32 insertions(+), 2 deletions(-)
---
diff --git a/src/gs-loading-page.c b/src/gs-loading-page.c
index 44a5d0c..5a72491 100644
--- a/src/gs-loading-page.c
+++ b/src/gs-loading-page.c
@@ -35,6 +35,7 @@ typedef struct {
 
        GtkWidget               *progressbar;
        GtkWidget               *label;
+       guint                    progress_pulse_id;
 } GsLoadingPagePrivate;
 
 G_DEFINE_TYPE_WITH_PRIVATE (GsLoadingPage, gs_loading_page, GS_TYPE_PAGE)
@@ -46,6 +47,15 @@ enum {
 
 static guint signals [SIGNAL_LAST] = { 0 };
 
+static gboolean
+_pulse_cb (gpointer user_data)
+{
+       GsLoadingPage *self = GS_LOADING_PAGE (user_data);
+       GsLoadingPagePrivate *priv = gs_loading_page_get_instance_private (self);
+       gtk_progress_bar_pulse (GTK_PROGRESS_BAR (priv->progressbar));
+       return TRUE;
+}
+
 static void
 gs_loading_page_status_changed_cb (GsPluginLoader *plugin_loader,
                                    GsApp *app,
@@ -72,8 +82,16 @@ gs_loading_page_status_changed_cb (GsPluginLoader *plugin_loader,
 
        /* update progresbar */
        if (app != NULL) {
-               gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (priv->progressbar),
-                                              (gdouble) gs_app_get_progress (app) / 100.0f);
+               if (priv->progress_pulse_id != 0) {
+                       g_source_remove (priv->progress_pulse_id);
+                       priv->progress_pulse_id = 0;
+               }
+               if (gs_app_get_progress (app) == 0) {
+                       priv->progress_pulse_id = g_timeout_add (50, _pulse_cb, self);
+               } else {
+                       gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (priv->progressbar),
+                                                      (gdouble) gs_app_get_progress (app) / 100.0f);
+               }
        }
 }
 
@@ -82,6 +100,7 @@ gs_loading_page_refresh_cb (GObject *source_object, GAsyncResult *res, gpointer
 {
        GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (source_object);
        GsLoadingPage *self = GS_LOADING_PAGE (user_data);
+       GsLoadingPagePrivate *priv = gs_loading_page_get_instance_private (self);
        g_autoptr(GError) error = NULL;
 
        /* no longer care */
@@ -93,6 +112,12 @@ gs_loading_page_refresh_cb (GObject *source_object, GAsyncResult *res, gpointer
                return;
        }
 
+       /* no more pulsing */
+       if (priv->progress_pulse_id != 0) {
+               g_source_remove (priv->progress_pulse_id);
+               priv->progress_pulse_id = 0;
+       }
+
        /* UI is good to go */
        g_signal_emit (self, signals[SIGNAL_REFRESHED], 0);
 }
@@ -158,6 +183,11 @@ gs_loading_page_dispose (GObject *object)
        GsLoadingPage *self = GS_LOADING_PAGE (object);
        GsLoadingPagePrivate *priv = gs_loading_page_get_instance_private (self);
 
+       if (priv->progress_pulse_id != 0) {
+               g_source_remove (priv->progress_pulse_id);
+               priv->progress_pulse_id = 0;
+       }
+
        g_clear_object (&priv->plugin_loader);
        g_clear_object (&priv->cancellable);
 


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