[gnome-software] epiphany: Rescale the icon to 64x64 if a different size is specified
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] epiphany: Rescale the icon to 64x64 if a different size is specified
- Date: Fri, 18 Oct 2013 14:30:11 +0000 (UTC)
commit 64ce8e8060038713a33284842c7c99665b3b3030
Author: Richard Hughes <richard hughsie com>
Date: Fri Oct 18 15:28:59 2013 +0100
epiphany: Rescale the icon to 64x64 if a different size is specified
src/plugins/gs-plugin-epiphany.c | 34 +++++++++++++++++++++++++++++-----
1 files changed, 29 insertions(+), 5 deletions(-)
---
diff --git a/src/plugins/gs-plugin-epiphany.c b/src/plugins/gs-plugin-epiphany.c
index 52da747..1e83d48 100644
--- a/src/plugins/gs-plugin-epiphany.c
+++ b/src/plugins/gs-plugin-epiphany.c
@@ -487,6 +487,9 @@ out:
static gboolean
gs_plugin_epiphany_download (GsPlugin *plugin, const gchar *uri, const gchar *filename, GError **error)
{
+ GInputStream *stream = NULL;
+ GdkPixbuf *pixbuf = NULL;
+ GdkPixbuf *pixbuf_new = NULL;
SoupMessage *msg = NULL;
gboolean ret = TRUE;
guint status_code;
@@ -511,14 +514,35 @@ gs_plugin_epiphany_download (GsPlugin *plugin, const gchar *uri, const gchar *fi
goto out;
}
- /* process the tab-delimited data */
- ret = g_file_set_contents (filename,
- msg->response_body->data,
- msg->response_body->length,
- error);
+ /* we're assuming this is a 64x64 png file, resize if not */
+ stream = g_memory_input_stream_new_from_data (msg->response_body->data,
+ msg->response_body->length,
+ NULL);
+ pixbuf = gdk_pixbuf_new_from_stream (stream, NULL, error);
+ if (pixbuf == NULL) {
+ ret = FALSE;
+ goto out;
+ }
+ if (gdk_pixbuf_get_height (pixbuf) == 64 &&
+ gdk_pixbuf_get_width (pixbuf) == 64) {
+ pixbuf_new = g_object_ref (pixbuf);
+ } else {
+ pixbuf_new = gdk_pixbuf_scale_simple (pixbuf, 64, 64,
+ GDK_INTERP_BILINEAR);
+ }
+
+ /* write file */
+ ret = gdk_pixbuf_save (pixbuf_new, filename, "png", error, NULL);
if (!ret)
goto out;
+
out:
+ if (stream != NULL)
+ g_object_unref (stream);
+ if (pixbuf_new != NULL)
+ g_object_unref (pixbuf_new);
+ if (pixbuf != NULL)
+ g_object_unref (pixbuf);
if (msg != NULL)
g_object_unref (msg);
return ret;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]