[gnome-software/1131-featured-carousel: 13/21] gs-app: Rename gs_app_set_pixbuf() to gs_app_add_pixbuf()




commit e6cb6723c14151472f3f6c4aece0f82b5e3159d8
Author: Philip Withnall <pwithnall endlessos org>
Date:   Wed Feb 17 18:16:09 2021 +0000

    gs-app: Rename gs_app_set_pixbuf() to gs_app_add_pixbuf()
    
    This is a step towards supporting multiple icon sizes for apps, so that
    different parts of the UI can display icons at different sizes.
    
    Backends need to be able to expose all the natively-supported icon sizes
    for an app, rather than being forced to provide the largest-possible
    icon and have it downsized for most use cases.
    
    Subsequent commits will rework the rest of the `GsApp` pixbuf/icon API.
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>

 lib/gs-app.c                              | 19 ++++++++++++++-----
 lib/gs-app.h                              |  2 +-
 plugins/core/gs-plugin-icons.c            |  2 +-
 plugins/dummy/gs-plugin-dummy.c           |  4 ++--
 plugins/flatpak/gs-flatpak.c              |  2 +-
 plugins/packagekit/gs-plugin-packagekit.c |  1 -
 plugins/rpm-ostree/gs-plugin-rpm-ostree.c |  1 -
 plugins/snap/gs-plugin-snap.c             |  2 +-
 8 files changed, 20 insertions(+), 13 deletions(-)
---
diff --git a/lib/gs-app.c b/lib/gs-app.c
index 8aa8ca8dc..e1b24b750 100644
--- a/lib/gs-app.c
+++ b/lib/gs-app.c
@@ -2047,20 +2047,29 @@ gs_app_set_runtime (GsApp *app, GsApp *runtime)
 }
 
 /**
- * gs_app_set_pixbuf:
+ * gs_app_add_pixbuf:
  * @app: a #GsApp
- * @pixbuf: (transfer none) (nullable): a #GdkPixbuf, or %NULL
+ * @pixbuf: (transfer none) (not nullable): a #GdkPixbuf
  *
- * Sets a pixbuf used to represent the application.
+ * Add a pixbuf to the set of pixbufs used to represent the application.
+ * Multiple pixbufs are supported as the application’s icon might be available
+ * in multiple sizes.
  *
- * Since: 3.22
+ * Only add pixbufs for native icon sizes provided by the backend — don’t resize
+ * a pixbuf to pass to this function. #GsApp can handle resizing pixbufs itself.
+ *
+ * Since: 40
  **/
 void
-gs_app_set_pixbuf (GsApp *app, GdkPixbuf *pixbuf)
+gs_app_add_pixbuf (GsApp *app, GdkPixbuf *pixbuf)
 {
        GsAppPrivate *priv = gs_app_get_instance_private (app);
        g_autoptr(GMutexLocker) locker = NULL;
+
        g_return_if_fail (GS_IS_APP (app));
+       g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
+
+       /* TODO: For the moment, only one pixbuf is actually supported */
        locker = g_mutex_locker_new (&priv->mutex);
        g_set_object (&priv->pixbuf, pixbuf);
 }
diff --git a/lib/gs-app.h b/lib/gs-app.h
index f215151e5..50b85e8e0 100644
--- a/lib/gs-app.h
+++ b/lib/gs-app.h
@@ -354,7 +354,7 @@ const gchar *gs_app_get_management_plugin   (GsApp          *app);
 void            gs_app_set_management_plugin   (GsApp          *app,
                                                 const gchar    *management_plugin);
 GdkPixbuf      *gs_app_get_pixbuf              (GsApp          *app);
-void            gs_app_set_pixbuf              (GsApp          *app,
+void            gs_app_add_pixbuf              (GsApp          *app,
                                                 GdkPixbuf      *pixbuf);
 GPtrArray      *gs_app_get_icons               (GsApp          *app);
 void            gs_app_add_icon                (GsApp          *app,
diff --git a/plugins/core/gs-plugin-icons.c b/plugins/core/gs-plugin-icons.c
index 4f7b45742..11c0af159 100644
--- a/plugins/core/gs-plugin-icons.c
+++ b/plugins/core/gs-plugin-icons.c
@@ -347,7 +347,7 @@ refine_app (GsPlugin             *plugin,
                        break;
                }
                if (pixbuf != NULL) {
-                       gs_app_set_pixbuf (app, pixbuf);
+                       gs_app_add_pixbuf (app, pixbuf);
                        break;
                }
 
diff --git a/plugins/dummy/gs-plugin-dummy.c b/plugins/dummy/gs-plugin-dummy.c
index 3a1ad44df..bb407a4dd 100644
--- a/plugins/dummy/gs-plugin-dummy.c
+++ b/plugins/dummy/gs-plugin-dummy.c
@@ -743,7 +743,7 @@ gs_plugin_add_category_apps (GsPlugin *plugin,
        gs_app_set_url (app, AS_URL_KIND_HOMEPAGE, "http://www.box.org";);
        gs_app_set_kind (app, AS_COMPONENT_KIND_DESKTOP_APP);
        gs_app_set_state (app, GS_APP_STATE_AVAILABLE);
-       gs_app_set_pixbuf (app, gdk_pixbuf_new_from_file 
("/usr/share/icons/hicolor/48x48/apps/chiron.desktop.png", NULL));
+       gs_app_add_pixbuf (app, gdk_pixbuf_new_from_file 
("/usr/share/icons/hicolor/48x48/apps/chiron.desktop.png", NULL));
        gs_app_set_kind (app, AS_COMPONENT_KIND_DESKTOP_APP);
        gs_app_set_management_plugin (app, gs_plugin_get_name (plugin));
        gs_app_list_add (list, app);
@@ -763,7 +763,7 @@ gs_plugin_add_recent (GsPlugin *plugin,
        gs_app_set_url (app, AS_URL_KIND_HOMEPAGE, "http://www.box.org";);
        gs_app_set_kind (app, AS_COMPONENT_KIND_DESKTOP_APP);
        gs_app_set_state (app, GS_APP_STATE_AVAILABLE);
-       gs_app_set_pixbuf (app, gdk_pixbuf_new_from_file 
("/usr/share/icons/hicolor/48x48/apps/chiron.desktop.png", NULL));
+       gs_app_add_pixbuf (app, gdk_pixbuf_new_from_file 
("/usr/share/icons/hicolor/48x48/apps/chiron.desktop.png", NULL));
        gs_app_set_kind (app, AS_COMPONENT_KIND_DESKTOP_APP);
        gs_app_set_management_plugin (app, gs_plugin_get_name (plugin));
        gs_app_list_add (list, app);
diff --git a/plugins/flatpak/gs-flatpak.c b/plugins/flatpak/gs-flatpak.c
index cc9937c93..07f29c08b 100644
--- a/plugins/flatpak/gs-flatpak.c
+++ b/plugins/flatpak/gs-flatpak.c
@@ -3023,7 +3023,7 @@ gs_flatpak_file_to_app_bundle (GsFlatpak *self,
                        gs_utils_error_convert_gdk_pixbuf (error);
                        return NULL;
                }
-               gs_app_set_pixbuf (app, pixbuf);
+               gs_app_add_pixbuf (app, pixbuf);
        } else {
                g_autoptr(AsIcon) icon = NULL;
                icon = as_icon_new ();
diff --git a/plugins/packagekit/gs-plugin-packagekit.c b/plugins/packagekit/gs-plugin-packagekit.c
index afe5da2ec..0c7309c88 100644
--- a/plugins/packagekit/gs-plugin-packagekit.c
+++ b/plugins/packagekit/gs-plugin-packagekit.c
@@ -445,7 +445,6 @@ gs_plugin_app_install (GsPlugin *plugin,
                /* get the new icon from the package */
                gs_app_set_local_file (app, NULL);
                gs_app_add_icon (app, NULL);
-               gs_app_set_pixbuf (app, NULL);
                break;
        default:
                g_set_error (error,
diff --git a/plugins/rpm-ostree/gs-plugin-rpm-ostree.c b/plugins/rpm-ostree/gs-plugin-rpm-ostree.c
index 419258559..a3117aeae 100644
--- a/plugins/rpm-ostree/gs-plugin-rpm-ostree.c
+++ b/plugins/rpm-ostree/gs-plugin-rpm-ostree.c
@@ -1209,7 +1209,6 @@ gs_plugin_app_install (GsPlugin *plugin,
        /* get the new icon from the package */
        gs_app_set_local_file (app, NULL);
        gs_app_add_icon (app, NULL);
-       gs_app_set_pixbuf (app, NULL);
 
        /* no longer valid */
        gs_app_clear_source_ids (app);
diff --git a/plugins/snap/gs-plugin-snap.c b/plugins/snap/gs-plugin-snap.c
index a42d8aa3d..87b1820ea 100644
--- a/plugins/snap/gs-plugin-snap.c
+++ b/plugins/snap/gs-plugin-snap.c
@@ -742,7 +742,7 @@ load_snap_icon (GsApp *app, SnapdClient *client, SnapdSnap *snap, GCancellable *
                g_warning ("Failed to decode snap icon %s: %s", icon_url, error->message);
                return FALSE;
        }
-       gs_app_set_pixbuf (app, pixbuf);
+       gs_app_add_pixbuf (app, pixbuf);
 
        return TRUE;
 }


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