[gthumb] image_print: don't abort when an error occurs on image loading



commit 2ce977cbe16c4f10550750dcb1990e09ee90d066
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Thu Feb 3 21:45:30 2011 +0100

    image_print: don't abort when an error occurs on image loading
    
    If one or more of the selected files could not be loaded just ignore them and keep loading the remaining files. If no file could be loaded an error is shown.

 extensions/image_print/gth-image-print-job.c      |   47 ++++++++++++++++++--
 extensions/image_print/gth-load-image-info-task.c |   17 ++++---
 2 files changed, 52 insertions(+), 12 deletions(-)
---
diff --git a/extensions/image_print/gth-image-print-job.c b/extensions/image_print/gth-image-print-job.c
index 2f74c32..d499c3e 100644
--- a/extensions/image_print/gth-image-print-job.c
+++ b/extensions/image_print/gth-image-print-job.c
@@ -1575,16 +1575,53 @@ load_image_info_task_completed_cb (GthTask  *task,
 				   GError   *error,
 				   gpointer  user_data)
 {
-	GthImagePrintJob        *self = user_data;
-	GtkPrintOperationResult  result;
-	char                    *filename;
-	GtkPrintSettings        *settings;
+	GthImagePrintJob         *self = user_data;
+	int                       n_loaded_images;
+	GthImageInfo            **loaded_images;
+	int                       i, j;
+	GtkPrintOperationResult   result;
+	char                     *filename;
+	GtkPrintSettings         *settings;
 
 	if (error != NULL) {
-		_gtk_error_dialog_from_gerror_show (GTK_WINDOW (self->priv->browser), _("Could not print"), &error);
+		g_object_unref (self);
+		return;
+	}
+
+	n_loaded_images = 0;
+	for (i = 0; i < self->priv->n_images; i++) {
+		GthImageInfo *image_info = self->priv->images[i];
+
+		if (image_info->thumbnail == NULL) {
+			gth_image_info_unref (self->priv->images[i]);
+			self->priv->images[i] = NULL;
+		}
+		else
+			n_loaded_images += 1;
+	}
+
+	if (n_loaded_images == 0) {
+		_gtk_error_dialog_show (GTK_WINDOW (self->priv->browser),
+					_("Could not print"),
+					"%s",
+					_("No suitable loader available for this file type"));
+		g_object_unref (self);
 		return;
 	}
 
+	loaded_images = g_new (GthImageInfo *, n_loaded_images + 1);
+	for (i = 0, j = 0; i < self->priv->n_images; i++) {
+		if (self->priv->images[i] != NULL) {
+			loaded_images[j] = self->priv->images[i];
+			j += 1;
+		}
+	}
+	loaded_images[j] = NULL;
+
+	g_free (self->priv->images);
+	self->priv->images = loaded_images;
+	self->priv->n_images = n_loaded_images;
+
 	filename = gth_user_dir_get_file (GTH_DIR_CONFIG, "gthumb", "print_settings", NULL);
 	settings = gtk_print_settings_new_from_file (filename, NULL);
 	if (settings != NULL)
diff --git a/extensions/image_print/gth-load-image-info-task.c b/extensions/image_print/gth-load-image-info-task.c
index c9e3dbf..459673d 100644
--- a/extensions/image_print/gth-load-image-info-task.c
+++ b/extensions/image_print/gth-load-image-info-task.c
@@ -124,16 +124,19 @@ image_loader_ready_cb (GObject      *source_object,
 	if (error == NULL)
 		g_cancellable_set_error_if_cancelled (gth_task_get_cancellable (GTH_TASK (self)), &error);
 
-	if (error != NULL) {
+	if (error == NULL) {
+		image_info = self->priv->images[self->priv->current];
+		if (pixbuf != NULL) {
+			gth_image_info_set_pixbuf (image_info, pixbuf);
+			g_object_unref (pixbuf);
+		}
+	}
+	else if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
 		gth_task_completed (GTH_TASK (self), error);
 		return;
 	}
-
-	image_info = self->priv->images[self->priv->current];
-	if (pixbuf != NULL) {
-		gth_image_info_set_pixbuf (image_info, pixbuf);
-		g_object_unref (pixbuf);
-	}
+	else
+		g_clear_error (&error);
 
 	continue_loading_image (self);
 }



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