[gthumb] fixed crash when trying to print files that aren't images.



commit 60d1597baa58e43f37b25699574d01853c14b270
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Sun Jul 4 20:10:33 2010 +0200

    fixed crash when trying to print files that aren't images.

 extensions/image_print/actions.c             |   14 +++++++++-----
 extensions/image_print/gth-image-print-job.c |   19 ++++++++++++++++---
 extensions/image_print/gth-image-print-job.h |    9 +++++----
 3 files changed, 30 insertions(+), 12 deletions(-)
---
diff --git a/extensions/image_print/actions.c b/extensions/image_print/actions.c
index 6747733..2dbeb2e 100644
--- a/extensions/image_print/actions.c
+++ b/extensions/image_print/actions.c
@@ -38,11 +38,15 @@ gth_browser_activate_action_file_print (GtkAction  *action,
 	file_list = gth_file_list_get_files (GTH_FILE_LIST (gth_browser_get_file_list (browser)), items);
 	if (file_list != NULL) {
 		GthImagePrintJob *print_job;
-
-		print_job = gth_image_print_job_new (file_list);
-		gth_image_print_job_run (print_job,
-					 GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
-					 browser);
+		GError           *error = NULL;
+
+		print_job = gth_image_print_job_new (file_list, &error);
+		if (print_job != NULL)
+			gth_image_print_job_run (print_job,
+						 GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
+						 browser);
+		else
+			_gtk_error_dialog_from_gerror_run (GTK_WINDOW (browser), _("Could not print the selected files"), &error);
 	}
 
 	_g_object_list_unref (file_list);
diff --git a/extensions/image_print/gth-image-print-job.c b/extensions/image_print/gth-image-print-job.c
index 10050aa..c724183 100644
--- a/extensions/image_print/gth-image-print-job.c
+++ b/extensions/image_print/gth-image-print-job.c
@@ -1505,7 +1505,8 @@ print_operation_done_cb (GtkPrintOperation       *operation,
 
 
 GthImagePrintJob *
-gth_image_print_job_new (GList *file_data_list)
+gth_image_print_job_new (GList   *file_data_list,
+			 GError **error)
 {
 	GthImagePrintJob *self;
 	GList            *scan;
@@ -1515,12 +1516,24 @@ gth_image_print_job_new (GList *file_data_list)
 
 	self->priv->n_images = g_list_length (file_data_list);
 	self->priv->images = g_new (GthImageInfo *, self->priv->n_images + 1);
-	for (scan = file_data_list, n = 0; scan; scan = scan->next)
-		self->priv->images[n++] = gth_image_info_new ((GthFileData *) scan->data);
+	for (scan = file_data_list, n = 0; scan; scan = scan->next) {
+		GthFileData *file_data = scan->data;
+
+		if (_g_mime_type_is_image (gth_file_data_get_mime_type (file_data)))
+			self->priv->images[n++] = gth_image_info_new (file_data);
+	}
 	self->priv->images[n] = NULL;
+	self->priv->n_images = n;
 	self->priv->image_width = 0;
 	self->priv->image_height = 0;
 
+	if (self->priv->n_images == 0) {
+		if (error != NULL)
+			*error = g_error_new_literal (GTH_ERROR, GTH_ERROR_GENERIC, _("No valid file selected."));
+		g_object_unref (self);
+		return NULL;
+	}
+
 	self->priv->print_operation = gtk_print_operation_new ();
 	gtk_print_operation_set_allow_async (self->priv->print_operation, TRUE);
 	gtk_print_operation_set_custom_tab_label (self->priv->print_operation, _("Layout"));
diff --git a/extensions/image_print/gth-image-print-job.h b/extensions/image_print/gth-image-print-job.h
index ffe198d..84e1dbc 100644
--- a/extensions/image_print/gth-image-print-job.h
+++ b/extensions/image_print/gth-image-print-job.h
@@ -49,10 +49,11 @@ struct _GthImagePrintJobClass {
 };
 
 GType              gth_image_print_job_get_type (void);
-GthImagePrintJob * gth_image_print_job_new      (GList                   *file_data_list);
-void               gth_image_print_job_run      (GthImagePrintJob        *self,
-						 GtkPrintOperationAction  action,
-						 GthBrowser              *browser);
+GthImagePrintJob * gth_image_print_job_new      (GList                    *file_data_list,
+						 GError                  **error);
+void               gth_image_print_job_run      (GthImagePrintJob         *self,
+						 GtkPrintOperationAction   action,
+						 GthBrowser               *browser);
 
 G_END_DECLS
 



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