summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <matthiasc@src.gnome.org>2008-07-01 05:38:49 +0000
committerMatthias Clasen <matthiasc@src.gnome.org>2008-07-01 05:38:49 +0000
commita7abdcf8fc5a6aabb00830c4c299fe154edbc3fc (patch)
treee3ca926e1bae0cd7f4e4ef13649b35cb78bd772e
parentcbd06646dd1e5b5a231dbf33999770995decae58 (diff)
downloadgtk+-a7abdcf8fc5a6aabb00830c4c299fe154edbc3fc.tar.gz
Handle failure to create temp file by returning NULL.
* gtk/gtkprintoperation-unix.c (_gtk_print_operation_platform_backend_create_preview_surface): Handle failure to create temp file by returning NULL. * gtk/gtkprintoperation.c (gtk_print_operation_preview_handler): Return FALSE if surface creation fails. (print_pages): If the preiew signal is not handled, show an error dialog. svn path=/trunk/; revision=20715
-rw-r--r--ChangeLog17
-rw-r--r--gtk/gtkprintoperation-unix.c9
-rw-r--r--gtk/gtkprintoperation.c45
3 files changed, 63 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index a0014987e0..e57c8afbcb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2008-07-01 Matthias Clasen <mclasen@redhat.com>
+
+ Bug 434535 – printoperation's create_surface doesn't check temp file
+ creation for success
+
+ Patch by Marek Kasik:
+
+ * gtk/gtkprintoperation-unix.c
+ (_gtk_print_operation_platform_backend_create_preview_surface):
+ Handle failure to create temp file by returning NULL.
+
+ * gtk/gtkprintoperation.c (gtk_print_operation_preview_handler):
+ Return FALSE if surface creation fails.
+
+ (print_pages): If the preiew signal is not handled, show an
+ error dialog.
+
2008-07-01 Michael Natterer <mitch@imendio.com>
Bug 442042 – GtkScaleButton is too limited
diff --git a/gtk/gtkprintoperation-unix.c b/gtk/gtkprintoperation-unix.c
index 329361238d..583ec929ce 100644
--- a/gtk/gtkprintoperation-unix.c
+++ b/gtk/gtkprintoperation-unix.c
@@ -667,6 +667,13 @@ _gtk_print_operation_platform_backend_create_preview_surface (GtkPrintOperation
filename = g_build_filename (g_get_tmp_dir (), "previewXXXXXX.pdf", NULL);
fd = g_mkstemp (filename);
+
+ if (fd < 0)
+ {
+ g_free (filename);
+ return NULL;
+ }
+
*target = filename;
paper_size = gtk_page_setup_get_paper_size (page_setup);
@@ -674,7 +681,7 @@ _gtk_print_operation_platform_backend_create_preview_surface (GtkPrintOperation
h = gtk_paper_size_get_height (paper_size, GTK_UNIT_POINTS);
*dpi_x = *dpi_y = 72;
- surface = cairo_pdf_surface_create_for_stream (write_preview, GINT_TO_POINTER(fd), w, h);
+ surface = cairo_pdf_surface_create_for_stream (write_preview, GINT_TO_POINTER (fd), w, h);
cairo_surface_set_user_data (surface, &key, GINT_TO_POINTER (fd), close_preview);
diff --git a/gtk/gtkprintoperation.c b/gtk/gtkprintoperation.c
index 3a182c5fb0..0a03391090 100644
--- a/gtk/gtkprintoperation.c
+++ b/gtk/gtkprintoperation.c
@@ -491,6 +491,12 @@ gtk_print_operation_preview_handler (GtkPrintOperation *op,
&dpi_x, &dpi_y,
&pop->filename);
+ if (pop->surface == NULL)
+ {
+ g_free (pop);
+ return FALSE;
+ }
+
cr = cairo_create (pop->surface);
gtk_print_context_set_cairo_context (op->priv->print_context, cr,
dpi_x, dpi_y);
@@ -2271,13 +2277,38 @@ print_pages (GtkPrintOperation *op,
priv->print_context,
parent,
&handled);
-
- if (!handled ||
- gtk_print_context_get_cairo_context (priv->print_context) == NULL)
- {
- /* Programmer error */
- g_error ("You must set a cairo context on the print context");
- }
+
+ if (!handled)
+ {
+ GtkMessageDialog *error_dialog;
+
+ error_dialog = gtk_message_dialog_new (parent,
+ GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_OK,
+ _("Error creating print preview"));
+
+ gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (error_dialog),
+ _("The most probable reason is that a temporary file could not be created."));
+
+ if (parent->group)
+ gtk_window_group_add_window (parent->group, GTK_WINDOW (error_dialog));
+
+ g_signal_connect (error_dialog, "response",
+ G_CALLBACK (gtk_widget_destroy), NULL);
+
+ gtk_widget_show (error_dialog);
+
+ print_pages_idle_done (data);
+
+ return;
+ }
+
+ if (gtk_print_context_get_cairo_context (priv->print_context) == NULL)
+ {
+ /* Programmer error */
+ g_error ("You must set a cairo context on the print context");
+ }
priv->start_page = preview_start_page;
priv->end_page = preview_end_page;