[gnome-software/wip/hughsie/fwupd: 2/3] Do not use GsApp screenshot for transient screenshots



commit 328c949e52c2a7459e2e9673b60359fff22ccd17
Author: Richard Hughes <richard hughsie com>
Date:   Tue Jun 30 12:45:29 2020 +0100

    Do not use GsApp screenshot for transient screenshots
    
    We currently support showing the user a screenshot which provides a more
    friendly way to put a device into bootloader mode. Devices that support this
    currently add a screenshot to the GsApp and then it gets shown before the update
    is applied.
    
    This isn't really suitable as when the update has been installed we then show
    the screenshot prominently in the details page, which is really confusing.
    It's a transient screenshot that's only requried for GsAppFlags _USER_ACTION so
    give the property it deserves.

 lib/gs-app.c                 | 42 ++++++++++++++++++++++++++++++++++++++++++
 lib/gs-app.h                 |  3 +++
 plugins/fwupd/gs-fwupd-app.c |  2 +-
 src/gs-page.c                |  5 ++---
 4 files changed, 48 insertions(+), 4 deletions(-)
---
diff --git a/lib/gs-app.c b/lib/gs-app.c
index 842882a1..7d293e3c 100644
--- a/lib/gs-app.c
+++ b/lib/gs-app.c
@@ -112,6 +112,7 @@ typedef struct
        GFile                   *local_file;
        AsContentRating         *content_rating;
        GdkPixbuf               *pixbuf;  /* (nullable) (owned) */
+       AsScreenshot            *action_screenshot;  /* (nullable) (owned) */
        GCancellable            *cancellable;
        GsPluginAction           pending_action;
        GsAppPermissions         permissions;
@@ -467,6 +468,8 @@ gs_app_to_string_append (GsApp *app, GString *str)
                gs_app_kv_lpad (str, "name", priv->name);
        if (priv->pixbuf != NULL)
                gs_app_kv_printf (str, "pixbuf", "%p", priv->pixbuf);
+       if (priv->action_screenshot != NULL)
+               gs_app_kv_printf (str, "action-screenshot", "%p", priv->action_screenshot);
        for (i = 0; i < priv->icons->len; i++) {
                AsIcon *icon = g_ptr_array_index (priv->icons, i);
                gs_app_kv_lpad (str, "icon-kind",
@@ -1652,6 +1655,24 @@ gs_app_get_pixbuf (GsApp *app)
        return priv->pixbuf;
 }
 
+/**
+ * gs_app_get_action_screenshot:
+ * @app: a #GsApp
+ *
+ * Gets a screenshot for the pending user action.
+ *
+ * Returns: (transfer none) (nullable): a #AsScreenshot, or %NULL
+ *
+ * Since: 3.38
+ **/
+AsScreenshot *
+gs_app_get_action_screenshot (GsApp *app)
+{
+       GsAppPrivate *priv = gs_app_get_instance_private (app);
+       g_return_val_if_fail (GS_IS_APP (app), NULL);
+       return priv->action_screenshot;
+}
+
 /**
  * gs_app_get_icons:
  * @app: a #GsApp
@@ -1892,6 +1913,25 @@ gs_app_set_pixbuf (GsApp *app, GdkPixbuf *pixbuf)
        g_set_object (&priv->pixbuf, pixbuf);
 }
 
+/**
+ * gs_app_set_action_screenshot:
+ * @app: a #GsApp
+ * @action_screenshot: (transfer none) (nullable): a #AsScreenshot, or %NULL
+ *
+ * Sets a screenshot used to represent the action.
+ *
+ * Since: 3.38
+ **/
+void
+gs_app_set_action_screenshot (GsApp *app, AsScreenshot *action_screenshot)
+{
+       GsAppPrivate *priv = gs_app_get_instance_private (app);
+       g_autoptr(GMutexLocker) locker = NULL;
+       g_return_if_fail (GS_IS_APP (app));
+       locker = g_mutex_locker_new (&priv->mutex);
+       g_set_object (&priv->action_screenshot, action_screenshot);
+}
+
 typedef enum {
        GS_APP_VERSION_FIXUP_RELEASE            = 1,
        GS_APP_VERSION_FIXUP_DISTRO_SUFFIX      = 2,
@@ -4235,6 +4275,8 @@ gs_app_finalize (GObject *object)
                g_object_unref (priv->content_rating);
        if (priv->pixbuf != NULL)
                g_object_unref (priv->pixbuf);
+       if (priv->action_screenshot != NULL)
+               g_object_unref (priv->action_screenshot);
 
        G_OBJECT_CLASS (gs_app_parent_class)->finalize (object);
 }
diff --git a/lib/gs-app.h b/lib/gs-app.h
index 1e43f73f..fb150242 100644
--- a/lib/gs-app.h
+++ b/lib/gs-app.h
@@ -279,6 +279,9 @@ void                 gs_app_set_origin_hostname     (GsApp          *app,
 GPtrArray      *gs_app_get_screenshots         (GsApp          *app);
 void            gs_app_add_screenshot          (GsApp          *app,
                                                 AsScreenshot   *screenshot);
+AsScreenshot   *gs_app_get_action_screenshot   (GsApp          *app);
+void            gs_app_set_action_screenshot   (GsApp          *app,
+                                                AsScreenshot   *screenshot);
 const gchar    *gs_app_get_update_version      (GsApp          *app);
 const gchar    *gs_app_get_update_version_ui   (GsApp          *app);
 void            gs_app_set_update_version      (GsApp          *app,
diff --git a/plugins/fwupd/gs-fwupd-app.c b/plugins/fwupd/gs-fwupd-app.c
index 2db26c98..ba6e7e9a 100644
--- a/plugins/fwupd/gs-fwupd-app.c
+++ b/plugins/fwupd/gs-fwupd-app.c
@@ -230,7 +230,7 @@ gs_fwupd_app_set_from_release (GsApp *app, FwupdRelease *rel)
                as_screenshot_add_image (ss, im);
                if (fwupd_release_get_detach_caption (rel) != NULL)
                        as_screenshot_set_caption (ss, NULL, fwupd_release_get_detach_caption (rel));
-               gs_app_add_screenshot (app, ss);
+               gs_app_set_action_screenshot (app, ss);
        }
 #endif
 }
diff --git a/src/gs-page.c b/src/gs-page.c
index 1fcc9bab..be83273f 100644
--- a/src/gs-page.c
+++ b/src/gs-page.c
@@ -315,9 +315,8 @@ gs_page_update_app (GsPage *page, GsApp *app, GCancellable *cancellable)
        /* tell the user what they have to do */
        if (gs_app_get_kind (app) == AS_APP_KIND_FIRMWARE &&
            gs_app_has_quirk (app, GS_APP_QUIRK_NEEDS_USER_ACTION)) {
-               GPtrArray *screenshots = gs_app_get_screenshots (app);
-               if (screenshots->len > 0) {
-                       AsScreenshot *ss = g_ptr_array_index (screenshots, 0);
+               AsScreenshot *ss = gs_app_get_action_screenshot (app);
+               if (ss != NULL) {
                        if (as_screenshot_get_caption (ss, NULL) != NULL) {
                                gs_page_needs_user_action (helper, ss);
                                return;


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