[gnome-software: 29/38] gs-loading-page: Use GsPluginJobRefreshMetadata::progress signal




commit ffce15de358cd6211e71fc4a5de31062193f5a66
Author: Philip Withnall <pwithnall endlessos org>
Date:   Wed Mar 2 13:08:29 2022 +0000

    gs-loading-page: Use GsPluginJobRefreshMetadata::progress signal
    
    Rather than passing the progress data all the way through
    `GsPluginLoader::status-changed` for no good reason. The plugin loader
    can’t have one single status, since it could have many jobs going on at
    once. Therefore it’s better for jobs to report their progress locally,
    and whichever bit of the UI cares should connect to the job’s progress
    signal.
    
    This also allows for more specific progress information for that job to
    be conveyed.
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>
    
    Helps: #1472

 lib/gs-plugin-loader.c | 25 ------------------------
 src/gs-loading-page.c  | 52 +++++++++++++++++---------------------------------
 2 files changed, 18 insertions(+), 59 deletions(-)
---
diff --git a/lib/gs-plugin-loader.c b/lib/gs-plugin-loader.c
index 3c0bc4fe2..0addcc215 100644
--- a/lib/gs-plugin-loader.c
+++ b/lib/gs-plugin-loader.c
@@ -3624,25 +3624,6 @@ run_job_cb (GObject      *source_object,
        g_assert_not_reached ();
 }
 
-static void
-plugin_progress_cb (GsPluginJob *plugin_job,
-                    guint        progress_percent,
-                    gpointer     user_data)
-{
-       GsPluginLoader *self = GS_PLUGIN_LOADER (user_data);
-       g_autoptr(GsApp) app_dl = NULL;
-
-       app_dl = gs_app_new ("refresh-metadata");
-       gs_app_set_summary_missing (app_dl,
-                                   /* TRANSLATORS: status text when downloading */
-                                   _("Downloading metadata files…"));
-       gs_app_set_progress (app_dl, progress_percent);
-
-       gs_plugin_loader_status_changed_cb (NULL, app_dl,
-                                           GS_PLUGIN_STATUS_DOWNLOADING,
-                                           self);
-}
-
 /**
  * gs_plugin_loader_job_process_async:
  * @plugin_loader: A #GsPluginLoader
@@ -3689,12 +3670,6 @@ gs_plugin_loader_job_process_async (GsPluginLoader *plugin_loader,
                g_task_set_task_data (task, GSIZE_TO_POINTER (begin_time_nsec), NULL);
 #endif
 
-               /* FIXME: Hook up to progress notification signals for backwards
-                * compatibility. */
-               if (GS_IS_PLUGIN_JOB_REFRESH_METADATA (plugin_job)) {
-                       g_signal_connect (plugin_job, "progress", G_CALLBACK (plugin_progress_cb), 
plugin_loader);
-               }
-
                job_class->run_async (plugin_job, plugin_loader, cancellable,
                                      run_job_cb, g_steal_pointer (&task));
                return;
diff --git a/src/gs-loading-page.c b/src/gs-loading-page.c
index 170c1e98d..18dac32c0 100644
--- a/src/gs-loading-page.c
+++ b/src/gs-loading-page.c
@@ -43,43 +43,29 @@ _pulse_cb (gpointer user_data)
 }
 
 static void
-gs_loading_page_status_changed_cb (GsPluginLoader *plugin_loader,
-                                   GsApp *app,
-                                   GsPluginStatus status,
-                                   GsLoadingPage *self)
+gs_loading_page_job_progress_cb (GsPluginJobRefreshMetadata *plugin_job,
+                                 guint                       progress_percent,
+                                 gpointer                    user_data)
 {
+       GsLoadingPage *self = GS_LOADING_PAGE (user_data);
        GsLoadingPagePrivate *priv = gs_loading_page_get_instance_private (self);
-       const gchar *str = NULL;
 
        /* update title */
-       if (status == GS_PLUGIN_STATUS_DOWNLOADING) {
-               if (app != NULL)
-                       str = gs_app_get_summary_missing (app);
-               if (str == NULL) {
-                       /* TRANSLATORS: initial start */
-                       str = _("Software catalog is being downloaded");
-               }
-       } else {
-               /* TRANSLATORS: initial start */
-               str = _("Software catalog is being downloaded");
+       adw_status_page_set_title (ADW_STATUS_PAGE (priv->status_page),
+                                  /* TRANSLATORS: initial start */
+                                  _("Software catalog is being downloaded"));
+
+       /* update progressbar */
+       if (priv->progress_pulse_id != 0) {
+               g_source_remove (priv->progress_pulse_id);
+               priv->progress_pulse_id = 0;
        }
 
-       /* update title */
-       adw_status_page_set_title (ADW_STATUS_PAGE (priv->status_page), str);
-
-       /* update progresbar */
-       if (app != NULL) {
-               if (priv->progress_pulse_id != 0) {
-                       g_source_remove (priv->progress_pulse_id);
-                       priv->progress_pulse_id = 0;
-               }
-
-               if (gs_app_get_progress (app) == GS_APP_PROGRESS_UNKNOWN) {
-                       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);
-               }
+       if (progress_percent == G_MAXUINT) {
+               priv->progress_pulse_id = g_timeout_add (50, _pulse_cb, self);
+       } else {
+               gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (priv->progressbar),
+                                              (gdouble) progress_percent / 100.0f);
        }
 }
 
@@ -134,13 +120,11 @@ gs_loading_page_load (GsLoadingPage *self)
 
        plugin_job = gs_plugin_job_refresh_metadata_new (cache_age_secs,
                                                         GS_PLUGIN_REFRESH_METADATA_FLAGS_NONE);
+       g_signal_connect (plugin_job, "progress", G_CALLBACK (gs_loading_page_job_progress_cb), self);
        gs_plugin_loader_job_process_async (priv->plugin_loader, plugin_job,
                                        priv->cancellable,
                                        gs_loading_page_refresh_cb,
                                        self);
-       g_signal_connect (priv->plugin_loader, "status-changed",
-                         G_CALLBACK (gs_loading_page_status_changed_cb),
-                         self);
 }
 
 static void


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