From 92bbb2fe7d76587e2e7445c38175186a7f25dae5 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Fri, 16 Jun 2006 17:17:56 +0000 Subject: [PATCH] Require cvs glib. 2006-06-16 Matthias Clasen * configure.in: Require cvs glib. * gtk/gtkprintoperation-unix.c: (_gtk_print_operation_platform_backend_create_preview_surface): Don't use a temporary directory for preview files, since it is not clear who cleans it up. Instead, use g_mkstemp() directly to create a temp pdf file, and make the preview app responsible for cleaning it up. --- ChangeLog | 8 +++++ ChangeLog.pre-2-10 | 8 +++++ configure.in | 2 +- gtk/gtkprintoperation-unix.c | 63 ++++++++++++++++++++++++++++-------- 4 files changed, 66 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index 720ee78641..f7bf490517 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,14 @@ 2006-06-16 Matthias Clasen + * configure.in: Require cvs glib. + * gtk/gtkprintoperation-unix.c: + (_gtk_print_operation_platform_backend_create_preview_surface): + Don't use a temporary directory for preview files, since it + is not clear who cleans it up. Instead, use g_mkstemp() directly + to create a temp pdf file, and make the preview app responsible + for cleaning it up. + * gtk/gtkprintbackend.c: Move the registration of the gtk-print-preview-command setting from gtkprintbackend.c to gtkprintoperation-unix.c, to make sure it is registered before diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 720ee78641..f7bf490517 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,6 +1,14 @@ 2006-06-16 Matthias Clasen + * configure.in: Require cvs glib. + * gtk/gtkprintoperation-unix.c: + (_gtk_print_operation_platform_backend_create_preview_surface): + Don't use a temporary directory for preview files, since it + is not clear who cleans it up. Instead, use g_mkstemp() directly + to create a temp pdf file, and make the preview app responsible + for cleaning it up. + * gtk/gtkprintbackend.c: Move the registration of the gtk-print-preview-command setting from gtkprintbackend.c to gtkprintoperation-unix.c, to make sure it is registered before diff --git a/configure.in b/configure.in index ffda4cae8e..82cd19d634 100644 --- a/configure.in +++ b/configure.in @@ -31,7 +31,7 @@ m4_define([gtk_api_version], [2.0]) m4_define([gtk_binary_version], [2.10.0]) # required versions of other packages -m4_define([glib_required_version], [2.11.0]) +m4_define([glib_required_version], [2.11.4]) m4_define([pango_required_version], [1.13.0]) m4_define([atk_required_version], [1.9.0]) m4_define([cairo_required_version], [1.1.8]) diff --git a/gtk/gtkprintoperation-unix.c b/gtk/gtkprintoperation-unix.c index 0b7014b84c..a72866d73e 100644 --- a/gtk/gtkprintoperation-unix.c +++ b/gtk/gtkprintoperation-unix.c @@ -604,6 +604,41 @@ _gtk_print_operation_platform_backend_run_dialog_async (GtkPrintOperation } } +static cairo_status_t +write_preview (void *closure, + const unsigned char *data, + unsigned int length) +{ + gint fd = GPOINTER_TO_INT (closure); + gssize written; + + while (length > 0) + { + written = write (fd, data, length); + + if (written == -1) + { + if (errno == EAGAIN || errno == EINTR) + continue; + + return CAIRO_STATUS_WRITE_ERROR; + } + + data += written; + length -= written; + } + + return CAIRO_STATUS_SUCCESS; +} + +static void +close_preview (void *data) +{ + gint fd = GPOINTER_TO_INT (data); + + close (fd); +} + cairo_surface_t * _gtk_print_operation_platform_backend_create_preview_surface (GtkPrintOperation *op, GtkPageSetup *page_setup, @@ -611,29 +646,29 @@ _gtk_print_operation_platform_backend_create_preview_surface (GtkPrintOperation gdouble *dpi_y, gchar **target) { - gchar *tmp_dir, *dir_template, *preview_filename; + gchar *filename; + gint fd; GtkPaperSize *paper_size; gdouble w, h; + cairo_surface_t *surface; + static cairo_user_data_key_t key; - dir_template = g_build_filename (g_get_tmp_dir (), "print-preview-XXXXXX", NULL); + filename = g_build_filename (g_get_tmp_dir (), "previewXXXXXX.pdf", NULL); + fd = g_mkstemp (filename); + *target = filename; + + g_print ("target is %s\n", filename); - /* use temp dirs because apps like evince need to have extensions - * to determine the mime type - */ - tmp_dir = mkdtemp (dir_template); - /* print preview pdf filename (please leave the trailing .pdf in place) */ - preview_filename = g_build_filename (tmp_dir, - _("Print Preview.pdf"), - NULL); - g_free (dir_template); - *target = preview_filename; - paper_size = gtk_page_setup_get_paper_size (page_setup); w = gtk_paper_size_get_width (paper_size, GTK_UNIT_POINTS); h = gtk_paper_size_get_height (paper_size, GTK_UNIT_POINTS); *dpi_x = *dpi_y = 72; - return cairo_pdf_surface_create (preview_filename, 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); + + return surface; } void