[gnome-software] Load 128x128 icons if they are installed on HiDPI hardware



commit ba9c9a881f69ee6058ac94cd7af1ab0b78098073
Author: Richard Hughes <richard hughsie com>
Date:   Fri Sep 26 17:26:42 2014 +0100

    Load 128x128 icons if they are installed on HiDPI hardware

 src/gs-app-row.c                  |    4 +-
 src/gs-app-tile.c                 |    3 +-
 src/gs-popular-tile.c             |    3 +-
 src/gs-shell-details.c            |    2 +-
 src/gs-update-dialog.c            |    2 +-
 src/gs-utils.c                    |   23 +++++++++++++++
 src/gs-utils.h                    |    6 ++++
 src/plugins/gs-plugin-appstream.c |   54 +++++++++++++++++++++++++++++++++---
 8 files changed, 86 insertions(+), 11 deletions(-)
---
diff --git a/src/gs-app-row.c b/src/gs-app-row.c
index 195f514..e306731 100644
--- a/src/gs-app-row.c
+++ b/src/gs-app-row.c
@@ -173,8 +173,8 @@ gs_app_row_refresh (GsAppRow *app_row)
        }
 
        if (gs_app_get_pixbuf (priv->app))
-               gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image),
-                                          gs_app_get_pixbuf (priv->app));
+               gs_image_set_from_pixbuf (GTK_IMAGE (priv->image),
+                                         gs_app_get_pixbuf (priv->app));
        gtk_widget_set_visible (priv->button, FALSE);
        gtk_widget_set_sensitive (priv->button, TRUE);
        gtk_widget_set_visible (priv->spinner, FALSE);
diff --git a/src/gs-app-tile.c b/src/gs-app-tile.c
index 9bb8fd5..3528c43 100644
--- a/src/gs-app-tile.c
+++ b/src/gs-app-tile.c
@@ -26,6 +26,7 @@
 
 #include "gs-app-tile.h"
 #include "gs-star-widget.h"
+#include "gs-utils.h"
 
 struct _GsAppTilePrivate
 {
@@ -166,7 +167,7 @@ gs_app_tile_set_app (GsAppTile *tile, GsApp *app)
                           G_CALLBACK (app_state_changed), tile);
         app_state_changed (priv->app, NULL, tile);
 
-       gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image), gs_app_get_pixbuf (app));
+       gs_image_set_from_pixbuf (GTK_IMAGE (priv->image), gs_app_get_pixbuf (app));
        gtk_label_set_label (GTK_LABEL (priv->name), gs_app_get_name (app));
        summary = gs_app_get_summary (app);
        gtk_label_set_label (GTK_LABEL (priv->summary), summary);
diff --git a/src/gs-popular-tile.c b/src/gs-popular-tile.c
index e26e006..d86a469 100644
--- a/src/gs-popular-tile.c
+++ b/src/gs-popular-tile.c
@@ -26,6 +26,7 @@
 
 #include "gs-popular-tile.h"
 #include "gs-star-widget.h"
+#include "gs-utils.h"
 
 struct _GsPopularTilePrivate
 {
@@ -144,7 +145,7 @@ gs_popular_tile_set_app (GsPopularTile *tile, GsApp *app)
                          G_CALLBACK (app_state_changed), tile);
        app_state_changed (priv->app, NULL, tile);
 
-       gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image), gs_app_get_pixbuf (priv->app));
+       gs_image_set_from_pixbuf (GTK_IMAGE (priv->image), gs_app_get_pixbuf (priv->app));
 
        gtk_label_set_label (GTK_LABEL (priv->label), gs_app_get_name (app));
 }
diff --git a/src/gs-shell-details.c b/src/gs-shell-details.c
index 2cf22bc..5199d59 100644
--- a/src/gs-shell-details.c
+++ b/src/gs-shell-details.c
@@ -566,7 +566,7 @@ gs_shell_details_refresh_all (GsShellDetails *shell_details)
                        pixbuf = gs_pixbuf_load ("application-x-executable", NULL, 96, NULL);
        }
        if (pixbuf != NULL) {
-               gtk_image_set_from_pixbuf (GTK_IMAGE (priv->application_details_icon), pixbuf);
+               gs_image_set_from_pixbuf (GTK_IMAGE (priv->application_details_icon), pixbuf);
                gtk_widget_set_visible (priv->application_details_icon, TRUE);
        } else {
                gtk_widget_set_visible (priv->application_details_icon, FALSE);
diff --git a/src/gs-update-dialog.c b/src/gs-update-dialog.c
index 11b276d..f5d17b6 100644
--- a/src/gs-update-dialog.c
+++ b/src/gs-update-dialog.c
@@ -124,7 +124,7 @@ set_updates_description_ui (GsUpdateDialog *dialog, GsApp *app)
        /* set update header */
        gtk_widget_set_visible (priv->box_header, kind == GS_APP_KIND_NORMAL || kind == GS_APP_KIND_SYSTEM);
        gtk_label_set_markup (GTK_LABEL (priv->label_details), update_desc);
-       gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image_icon), gs_app_get_pixbuf (app));
+       gs_image_set_from_pixbuf (GTK_IMAGE (priv->image_icon), gs_app_get_pixbuf (app));
        gtk_label_set_label (GTK_LABEL (priv->label_name), gs_app_get_name (app));
        gtk_label_set_label (GTK_LABEL (priv->label_summary), gs_app_get_summary (app));
        g_free (update_desc);
diff --git a/src/gs-utils.c b/src/gs-utils.c
index 252a9ab..dc532e3 100644
--- a/src/gs-utils.c
+++ b/src/gs-utils.c
@@ -353,4 +353,27 @@ gs_reboot (GCallback reboot_failed)
        g_object_unref (bus);
 }
 
+/**
+ * gs_image_set_from_pixbuf_with_scale:
+ **/
+void
+gs_image_set_from_pixbuf_with_scale (GtkImage *image, const GdkPixbuf *pixbuf, gint scale)
+{
+       cairo_surface_t *surface;
+       surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, scale, NULL);
+       gtk_image_set_from_surface (image, surface);
+       cairo_surface_destroy (surface);
+}
+
+/**
+ * gs_image_set_from_pixbuf:
+ **/
+void
+gs_image_set_from_pixbuf (GtkImage *image, const GdkPixbuf *pixbuf)
+{
+       gint scale;
+       scale = gdk_pixbuf_get_width (pixbuf) / 64;
+       gs_image_set_from_pixbuf_with_scale (image, pixbuf, scale);
+}
+
 /* vim: set noexpandtab: */
diff --git a/src/gs-utils.h b/src/gs-utils.h
index 6c33eb3..bbc7a15 100644
--- a/src/gs-utils.h
+++ b/src/gs-utils.h
@@ -51,6 +51,12 @@ GdkPixbuf *gs_pixbuf_load            (const gchar    *icon_name,
                                         GError         **error);
 void     gs_reboot                      (GCallback       reboot_failed);
 
+void   gs_image_set_from_pixbuf_with_scale     (GtkImage               *image,
+                                                const GdkPixbuf        *pixbuf,
+                                                gint                    scale);
+void   gs_image_set_from_pixbuf                (GtkImage               *image,
+                                                const GdkPixbuf        *pixbuf);
+
 G_END_DECLS
 
 #endif /* __GS_UTILS_H */
diff --git a/src/plugins/gs-plugin-appstream.c b/src/plugins/gs-plugin-appstream.c
index 6b96079..b9ebfbb 100644
--- a/src/plugins/gs-plugin-appstream.c
+++ b/src/plugins/gs-plugin-appstream.c
@@ -168,6 +168,53 @@ out:
 }
 
 /**
+ * _as_app_get_icon_for_scale:
+ */
+static GdkPixbuf *
+_as_app_get_icon_for_scale (AsApp *app, gint scale, GError **error)
+{
+       GdkPixbuf *pixbuf = NULL;
+       const gchar *icon;
+       const gchar *icon_path;
+       gchar *filename_hidpi = NULL;
+       gchar *filename_lodpi = NULL;
+       gchar *filename = NULL;
+
+       /* HiDPI */
+       icon = as_app_get_icon (app);
+       if (icon == NULL)
+               goto out;
+       icon_path = as_app_get_icon_path (app);
+       if (icon_path == NULL)
+               goto out;
+       if (scale == 2) {
+               filename_hidpi = g_build_filename (icon_path, "128x128", icon, NULL);
+               if (g_file_test (filename_hidpi, G_FILE_TEST_EXISTS)) {
+                       pixbuf = gdk_pixbuf_new_from_file (filename_hidpi, error);
+                       if (pixbuf == NULL)
+                               goto out;
+                       goto out;
+               }
+       }
+
+       /* LoDPI */
+       filename_lodpi = g_build_filename (icon_path, "64x64", icon, NULL);
+       if (g_file_test (filename_lodpi, G_FILE_TEST_EXISTS)) {
+               pixbuf = gdk_pixbuf_new_from_file (filename_lodpi, error);
+               goto out;
+       }
+
+       /* fallback */
+       filename = g_build_filename (icon_path, icon, NULL);
+       pixbuf = gdk_pixbuf_new_from_file (filename, error);
+out:
+       g_free (filename_hidpi);
+       g_free (filename_lodpi);
+       g_free (filename);
+       return pixbuf;
+}
+
+/**
  * gs_plugin_refine_item_pixbuf:
  */
 static void
@@ -177,7 +224,6 @@ gs_plugin_refine_item_pixbuf (GsPlugin *plugin, GsApp *app, AsApp *item)
        GError *error = NULL;
        const gchar *icon;
        gboolean ret;
-       gchar *full_filename = NULL;
 
        icon = as_app_get_icon (item);
        switch (as_app_get_icon_kind (item)) {
@@ -195,11 +241,10 @@ gs_plugin_refine_item_pixbuf (GsPlugin *plugin, GsApp *app, AsApp *item)
                }
                break;
        case AS_ICON_KIND_CACHED:
-               full_filename = g_build_filename (as_app_get_icon_path (item), icon, NULL);
-               pb = gdk_pixbuf_new_from_file (full_filename, &error);
+               pb = _as_app_get_icon_for_scale (item, plugin->scale, &error);
                if (pb == NULL) {
                        g_warning ("failed to load cached icon %s: %s",
-                                  full_filename, error->message);
+                                  as_app_get_icon (item), error->message);
                        g_error_free (error);
                        goto out;
                }
@@ -212,7 +257,6 @@ gs_plugin_refine_item_pixbuf (GsPlugin *plugin, GsApp *app, AsApp *item)
 out:
        if (pb != NULL)
                g_object_unref (pb);
-       g_free (full_filename);
 }
 
 /**


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