[Commits] [SCM] claws branch, master, updated. 3.17.3-125-g5571776

ticho at claws-mail.org ticho at claws-mail.org
Tue Mar 5 23:02:19 CET 2019


The branch, master has been updated
       via  55717767b62cf673760d72e1d8ddf02685103e6e (commit)
      from  4d4a522f4f20333fe2eee97c5bbe960a455626ed (commit)

Summary of changes:
 src/image_viewer.c |   45 ++++++++++++++++++++++++---------------------
 1 file changed, 24 insertions(+), 21 deletions(-)


- Log -----------------------------------------------------------------
commit 55717767b62cf673760d72e1d8ddf02685103e6e
Author: Andrej Kacian <ticho at claws-mail.org>
Date:   Tue Mar 5 23:01:26 2019 +0100

    Rewrite image_viewer.c to not create a temporary file for the image being loaded
    
    Instead, we use new procmime_get_part_as_inputstream().

diff --git a/src/image_viewer.c b/src/image_viewer.c
index 09fd79c..bd33c94 100644
--- a/src/image_viewer.c
+++ b/src/image_viewer.c
@@ -69,16 +69,35 @@ static GtkWidget *image_viewer_get_widget(MimeViewer *_mimeviewer)
 	return imageviewer->notebook;
 }
 
-static void image_viewer_load_file(ImageViewer *imageviewer, const gchar *imgfile)
+static void image_viewer_load_image(ImageViewer *imageviewer)
 {
 	GtkAllocation allocation;
 	GdkPixbufAnimation *animation = NULL;
 	GdkPixbuf *pixbuf = NULL;
 	GError *error = NULL;
+	GInputStream *stream;
 
-	debug_print("image_viewer_show_mimepart\n");
+	cm_return_if_fail(imageviewer != NULL);
+
+	if (imageviewer->mimeinfo == NULL)
+		return;
+
+	stream = procmime_get_part_as_inputstream(imageviewer->mimeinfo, &error);
+	if (error != NULL) {
+		g_warning("Couldn't get image MIME part: %s\n", error->message);
+		g_error_free(error);
+		return;
+	}
+
+	animation = gdk_pixbuf_animation_new_from_stream(stream, NULL, &error);
+	g_object_unref(stream);
+
+	if (error != NULL) {
+		g_warning("Couldn't load image: %s\n", error->message);
+		g_error_free(error);
+		return;
+	}
 
-	animation = gdk_pixbuf_animation_new_from_file(imgfile, &error);
 	if (gdk_pixbuf_animation_is_static_image(animation)
 	    || imageviewer->resize_img) {
 		pixbuf = gdk_pixbuf_animation_get_static_image(animation);
@@ -139,28 +158,12 @@ static void image_viewer_set_notebook_page(MimeViewer *_mimeviewer)
 		gtk_notebook_set_current_page(GTK_NOTEBOOK(imageviewer->notebook), 1);
 }
 
-static void image_viewer_load_image(ImageViewer *imageviewer)
-{
-	gchar *imgfile;
-
-	if (imageviewer->mimeinfo == NULL)
-		return;
-
-	imgfile = procmime_get_tmp_file_name(imageviewer->mimeinfo);
-	if (procmime_get_part(imgfile, imageviewer->mimeinfo) < 0) {
-		g_warning("Can't get mimepart file");	
-		g_free(imgfile);
-		return;
-	}
-	image_viewer_load_file(imageviewer, imgfile);
-	claws_unlink(imgfile);
-	g_free(imgfile);
-}
-
 static void image_viewer_show_mimepart(MimeViewer *_mimeviewer, const gchar *file, MimeInfo *mimeinfo)
 {
 	ImageViewer *imageviewer = (ImageViewer *) _mimeviewer;
 
+	debug_print("image_viewer_show_mimepart\n");
+
 	image_viewer_clear_viewer(_mimeviewer);
 	g_free(imageviewer->file);
 	imageviewer->file = g_strdup(file);

-----------------------------------------------------------------------


hooks/post-receive
-- 
Claws Mail


More information about the Commits mailing list