[gnome-software/wip/ubuntu-3-22: 3/19] Download changelog information on demand - this stops the UI blocking on startup



commit 40d6921590ec406479e2c10c56bf35d2f5db0efc
Author: Robert Ancell <robert ancell canonical com>
Date:   Mon Nov 7 16:55:18 2016 +1300

    Download changelog information on demand - this stops the UI blocking on startup

 src/gs-plugin.h        |    2 ++
 src/gs-update-dialog.c |   36 +++++++++++++++++++++++++++++++++---
 2 files changed, 35 insertions(+), 3 deletions(-)
---
diff --git a/src/gs-plugin.h b/src/gs-plugin.h
index c90cecc..8043b49 100644
--- a/src/gs-plugin.h
+++ b/src/gs-plugin.h
@@ -168,6 +168,7 @@ typedef enum {
  * @GS_PLUGIN_REFINE_FLAGS_REQUIRE_ORIGIN_HOSTNAME:    Require the origin hostname
  * @GS_PLUGIN_REFINE_FLAGS_REQUIRE_ORIGIN_UI:          Require the origin for UI
  * @GS_PLUGIN_REFINE_FLAGS_REQUIRE_RUNTIME:            Require the runtime
+ * @GS_PLUGIN_REFINE_FLAGS_REQUIRE_CHANGELOG:          Require the changelog
  *
  * The refine flags.
  **/
@@ -198,6 +199,7 @@ typedef enum {
 #define GS_PLUGIN_REFINE_FLAGS_REQUIRE_ORIGIN_HOSTNAME (1u << 23)
 #define GS_PLUGIN_REFINE_FLAGS_REQUIRE_ORIGIN_UI       (1u << 24)
 #define GS_PLUGIN_REFINE_FLAGS_REQUIRE_RUNTIME         (1u << 25)
+#define GS_PLUGIN_REFINE_FLAGS_REQUIRE_CHANGELOG       (1u << 26)
 typedef guint64 GsPluginRefineFlags;
 
 /**
diff --git a/src/gs-update-dialog.c b/src/gs-update-dialog.c
index f8ce342..f81aebe 100644
--- a/src/gs-update-dialog.c
+++ b/src/gs-update-dialog.c
@@ -42,6 +42,7 @@ struct _GsUpdateDialog
        GQueue          *back_entry_stack;
        GCancellable    *cancellable;
        GsPluginLoader  *plugin_loader;
+       GsApp           *app;
        GtkWidget       *box_header;
        GtkWidget       *button_back;
        GtkWidget       *image_icon;
@@ -87,12 +88,34 @@ back_entry_free (BackEntry *entry)
 }
 
 static void
+refine_cb (GsPluginLoader *plugin_loader, GAsyncResult *res, GsUpdateDialog *dialog)
+{
+       const gchar *update_details;
+       g_autoptr(GError) error = NULL;
+
+       if (!gs_plugin_loader_app_refine_finish (plugin_loader, res, &error))
+               g_warning ("Failed to get changelog information: %s", error->message);
+
+       update_details = gs_app_get_update_details (dialog->app);
+       if (update_details == NULL) {
+               /* TRANSLATORS: this is where the packager did not write
+                * a description for the update */
+               update_details = _("No update description available.");
+       }
+
+       gtk_label_set_label (GTK_LABEL (dialog->label_details), update_details);
+}
+
+static void
 set_updates_description_ui (GsUpdateDialog *dialog, GsApp *app)
 {
        AsAppKind kind;
        const GdkPixbuf *pixbuf;
        const gchar *update_details;
 
+       g_clear_object (&dialog->app);
+       dialog->app = g_object_ref (app);
+
        /* set window title */
        kind = gs_app_get_kind (app);
        if (kind == AS_APP_KIND_OS_UPDATE) {
@@ -116,9 +139,15 @@ set_updates_description_ui (GsUpdateDialog *dialog, GsApp *app)
        gtk_widget_set_visible (dialog->box_header, kind == AS_APP_KIND_DESKTOP);
        update_details = gs_app_get_update_details (app);
        if (update_details == NULL) {
-               /* TRANSLATORS: this is where the packager did not write
-                * a description for the update */
-               update_details = _("No update description available.");
+               /* TRANSLATORS: this is displayed while the changelog is being downloaded */
+               update_details = _("Downloading change information…");
+
+               gs_plugin_loader_app_refine_async (dialog->plugin_loader,
+                                                  app,
+                                                  GS_PLUGIN_REFINE_FLAGS_REQUIRE_CHANGELOG,
+                                                  dialog->cancellable,
+                                                  (GAsyncReadyCallback) refine_cb,
+                                                  dialog);
        }
        gtk_label_set_label (GTK_LABEL (dialog->label_details), update_details);
        gtk_label_set_label (GTK_LABEL (dialog->label_name), gs_app_get_name (app));
@@ -458,6 +487,7 @@ gs_update_dialog_dispose (GObject *object)
        }
 
        g_clear_object (&dialog->plugin_loader);
+       g_clear_object (&dialog->app);
 
        G_OBJECT_CLASS (gs_update_dialog_parent_class)->dispose (object);
 }


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