balsa r8091 - in trunk: . libbalsa



Author: PeterB
Date: Sat Feb 28 17:26:05 2009
New Revision: 8091
URL: http://svn.gnome.org/viewvc/balsa?rev=8091&view=rev

Log:
tell GdkPixbufLoader the mime type

Modified:
   trunk/ChangeLog
   trunk/libbalsa/body.c

Modified: trunk/libbalsa/body.c
==============================================================================
--- trunk/libbalsa/body.c	(original)
+++ trunk/libbalsa/body.c	Sat Feb 28 17:26:05 2009
@@ -621,37 +621,38 @@
 GdkPixbuf *
 libbalsa_message_body_get_pixbuf(LibBalsaMessageBody * body, GError ** err)
 {
-    GdkPixbufLoader *loader;
     GMimeStream *stream;
-    gssize count;
-    gboolean ok = TRUE;
-    gchar buf[4096];
+    gchar *mime_type;
+    GdkPixbufLoader *loader;
     GdkPixbuf *pixbuf = NULL;
 
     stream = libbalsa_message_body_get_stream(body, err);
     if (!stream)
         return pixbuf;
+
     libbalsa_mailbox_lock_store(body->message->mailbox);
     g_mime_stream_reset(stream);
 
-    loader = gdk_pixbuf_loader_new();
-    while ((count = g_mime_stream_read(stream, buf, sizeof(buf))) > 0) {
-        if (!gdk_pixbuf_loader_write(loader, (guchar *) buf, count, err)) {
-            ok = FALSE;
-            break;
-        }
-    }
-    libbalsa_mailbox_unlock_store(body->message->mailbox);
-    g_object_unref(stream);
+    mime_type = libbalsa_message_body_get_mime_type(body);
+    loader = gdk_pixbuf_loader_new_with_mime_type(mime_type, err);
+    g_free(mime_type);
+
+    if (loader) {
+        gssize count;
+        gchar buf[4096];
+
+        while ((count = g_mime_stream_read(stream, buf, sizeof(buf))) > 0)
+            if (!gdk_pixbuf_loader_write(loader, (guchar *) buf, count, err))
+                break;
 
-    if (!gdk_pixbuf_loader_close(loader, ok ? err : NULL))
-	ok = FALSE;
+        if (gdk_pixbuf_loader_close(loader, *err ? NULL : err))
+            pixbuf = g_object_ref(gdk_pixbuf_loader_get_pixbuf(loader));
 
-    if (ok) {
-        pixbuf = gdk_pixbuf_loader_get_pixbuf(loader);
-	g_object_ref(pixbuf);
+        g_object_unref(loader);
     }
-    g_object_unref(loader);
+
+    libbalsa_mailbox_unlock_store(body->message->mailbox);
+    g_object_unref(stream);
 
     return pixbuf;
 }



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