[gnome-photos] dlna-renderer: Optionally scale the icon before returning it



commit 1b2d786bc3a33d1a59f1c2aa442b647d81a11645
Author: Debarshi Ray <debarshir gnome org>
Date:   Thu Jan 16 12:04:46 2014 +0100

    dlna-renderer: Optionally scale the icon before returning it
    
    The Resolution paramater is currently ignored by dleyna-renderer.
    
    Fixes: https://bugzilla.gnome.org/720404

 src/photos-dlna-renderer.c         |   15 ++++++++++++++-
 src/photos-dlna-renderer.h         |    3 ++-
 src/photos-dlna-renderers-dialog.c |    8 +++++++-
 3 files changed, 23 insertions(+), 3 deletions(-)
---
diff --git a/src/photos-dlna-renderer.c b/src/photos-dlna-renderer.c
index abd99e4..ff31ecc 100644
--- a/src/photos-dlna-renderer.c
+++ b/src/photos-dlna-renderer.c
@@ -667,9 +667,12 @@ photos_dlna_renderer_device_get_icon_cb (GObject *source_object,
   GTask *task = G_TASK (user_data);
   GInputStream *icon_stream;
   GdkPixbuf *pixbuf;
+  GtkIconSize size;
   GVariant *icon_variant;
   GBytes *icon_bytes;
   const gchar *icon_data;
+  gint height = -1;
+  gint width = -1;
   gsize icon_data_size;
   GError *error = NULL;
 
@@ -690,8 +693,16 @@ photos_dlna_renderer_device_get_icon_cb (GObject *source_object,
   icon_data = g_bytes_get_data (icon_bytes, &icon_data_size);
   g_bytes_unref (icon_bytes);
 
+  size = (GtkIconSize) GPOINTER_TO_INT (g_task_get_task_data (task));
+  gtk_icon_size_lookup (size, &width, &height);
+
   icon_stream = g_memory_input_stream_new_from_data (icon_data, icon_data_size, NULL);
-  pixbuf = gdk_pixbuf_new_from_stream (icon_stream, g_task_get_cancellable (task), &error);
+  pixbuf = gdk_pixbuf_new_from_stream_at_scale (icon_stream,
+                                                width,
+                                                height,
+                                                TRUE,
+                                                g_task_get_cancellable (task),
+                                                &error);
   g_object_unref (icon_stream);
 
   RETURN_ON_ERROR (task, error, "Failed to parse icon data");
@@ -724,6 +735,7 @@ void
 photos_dlna_renderer_get_icon (PhotosDlnaRenderer *self,
                                const gchar *requested_mimetype,
                                const gchar *resolution,
+                               GtkIconSize size,
                                GCancellable *cancellable,
                                GAsyncReadyCallback callback,
                                gpointer user_data)
@@ -732,6 +744,7 @@ photos_dlna_renderer_get_icon (PhotosDlnaRenderer *self,
   GTask *task;
 
   task = g_task_new (self, cancellable, callback, user_data);
+  g_task_set_task_data (task, GINT_TO_POINTER (size), NULL);
 
   dleyna_renderer_device_call_get_icon (priv->device, requested_mimetype, resolution,
                                         cancellable, photos_dlna_renderer_device_get_icon_cb,
diff --git a/src/photos-dlna-renderer.h b/src/photos-dlna-renderer.h
index 09c20e6..d81f200 100644
--- a/src/photos-dlna-renderer.h
+++ b/src/photos-dlna-renderer.h
@@ -21,8 +21,8 @@
 #ifndef PHOTOS_DLNA_RENDERER_H
 #define PHOTOS_DLNA_RENDERER_H
 
-#include <glib-object.h>
 #include <gio/gio.h>
+#include <gtk/gtk.h>
 
 #include "photos-base-item.h"
 
@@ -116,6 +116,7 @@ const gchar          *photos_dlna_renderer_get_udn            (PhotosDlnaRendere
 void                  photos_dlna_renderer_get_icon           (PhotosDlnaRenderer  *self,
                                                                const gchar         *requested_mimetype,
                                                                const gchar         *resolution,
+                                                               GtkIconSize          size,
                                                                GCancellable        *cancellable,
                                                                GAsyncReadyCallback  callback,
                                                                gpointer             user_data);
diff --git a/src/photos-dlna-renderers-dialog.c b/src/photos-dlna-renderers-dialog.c
index 633bbed..91d7c93 100644
--- a/src/photos-dlna-renderers-dialog.c
+++ b/src/photos-dlna-renderers-dialog.c
@@ -197,7 +197,13 @@ photos_dlna_renderers_dialog_add_renderer (PhotosDlnaRenderersDialog *self, Phot
   image = gtk_image_new_from_gicon (icon, GTK_ICON_SIZE_DIALOG);
 
   g_object_ref (image); /* keep a ref for the following async call and release it in the callback */
-  photos_dlna_renderer_get_icon (renderer, "", "", NULL, photos_dlna_renderers_dialog_set_icon_cb, image);
+  photos_dlna_renderer_get_icon (renderer,
+                                 "",
+                                 "",
+                                 GTK_ICON_SIZE_DIALOG,
+                                 NULL,
+                                 photos_dlna_renderers_dialog_set_icon_cb,
+                                 image);
 
   gtk_container_add (GTK_CONTAINER (row_grid), image);
 


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