changeset 1497:2c54f3f71634

report pixbuf loader errors https://sourceforge.net/tracker/?func=detail&aid=2720577&group_id=222125&atid=1054680
author nadvornik
date Tue, 31 Mar 2009 19:34:39 +0000
parents 03c22c05c6b6
children 5f49f305a6b6
files src/image-load.c src/image-load.h
diffstat 2 files changed, 20 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/image-load.c	Tue Mar 31 18:45:33 2009 +0000
+++ b/src/image-load.c	Tue Mar 31 19:34:39 2009 +0000
@@ -155,6 +155,8 @@
 
 	image_loader_stop(il);
 
+	if (il->error) DEBUG_1("%s", image_loader_get_error(il));
+
 	DEBUG_1("freeing image loader %p bytes_read=%d", il, il->bytes_read);
 
 	if (il->idle_done_id != -1) g_source_remove(il->idle_done_id);
@@ -179,6 +181,8 @@
 		}
 
 	if (il->pixbuf) g_object_unref(il->pixbuf);
+	
+	if (il->error) g_error_free(il->error);
 
 	file_data_unref(il->fd);
 #ifdef HAVE_GTHREAD
@@ -460,7 +464,7 @@
 	if (il->loader)
 		{
 		/* some loaders do not have a pixbuf till close, order is important here */
-		gdk_pixbuf_loader_close(il->loader, NULL);
+		gdk_pixbuf_loader_close(il->loader, il->error ? NULL : &il->error); /* we are interested in the first error only */
 		image_loader_sync_pixbuf(il);
 		g_object_unref(G_OBJECT(il->loader));
 		il->loader = NULL;
@@ -519,7 +523,7 @@
 			return FALSE;
 			}
 
-		if (b < 0 || (b > 0 && !gdk_pixbuf_loader_write(il->loader, il->mapped_file + il->bytes_read, b, NULL)))
+		if (b < 0 || (b > 0 && !gdk_pixbuf_loader_write(il->loader, il->mapped_file + il->bytes_read, b, &il->error)))
 			{
 			image_loader_error(il);
 			return FALSE;
@@ -549,7 +553,7 @@
 
 	image_loader_setup_loader(il);
 
-	if (!gdk_pixbuf_loader_write(il->loader, il->mapped_file + il->bytes_read, b, NULL))
+	if (!gdk_pixbuf_loader_write(il->loader, il->mapped_file + il->bytes_read, b, &il->error))
 		{
 		image_loader_stop_loader(il);
 		return FALSE;
@@ -561,7 +565,7 @@
 	while (il->loader && !gdk_pixbuf_loader_get_pixbuf(il->loader) && b > 0 && !image_loader_get_stopping(il))
 		{
 		b = MIN(il->read_buffer_size, il->bytes_total - il->bytes_read);
-		if (b < 0 || (b > 0 && !gdk_pixbuf_loader_write(il->loader, il->mapped_file + il->bytes_read, b, NULL)))
+		if (b < 0 || (b > 0 && !gdk_pixbuf_loader_write(il->loader, il->mapped_file + il->bytes_read, b, &il->error)))
 			{
 			image_loader_stop_loader(il);
 			return FALSE;
@@ -1013,6 +1017,16 @@
 	return ret;
 }
 
+const gchar *image_loader_get_error(ImageLoader *il)
+{
+	const gchar *ret = NULL;
+	if (!il) return NULL;
+	g_mutex_lock(il->data_mutex);
+	if (il->error) ret = il->error->message;
+	g_mutex_unlock(il->data_mutex);
+	return ret;
+}
+
 
 /* FIXME - this can be rather slow and blocks until the size is known */
 gboolean image_load_dimensions(FileData *fd, gint *width, gint *height)
--- a/src/image-load.h	Tue Mar 31 18:45:33 2009 +0000
+++ b/src/image-load.h	Tue Mar 31 19:34:39 2009 +0000
@@ -42,6 +42,7 @@
 	gint idle_priority;
 
 	GdkPixbufLoader *loader;
+	GError *error;
 
 	gint idle_done_id;
 	GList *area_param_list;
@@ -101,6 +102,7 @@
 gboolean image_loader_get_is_done(ImageLoader *il);
 FileData *image_loader_get_fd(ImageLoader *il);
 gboolean image_loader_get_shrunk(ImageLoader *il);
+const gchar *image_loader_get_error(ImageLoader *il);
 
 gboolean image_load_dimensions(FileData *fd, gint *width, gint *height);