diff options
author | Matthias Clasen <mclasen@redhat.com> | 2007-04-29 06:59:27 +0000 |
---|---|---|
committer | Matthias Clasen <matthiasc@src.gnome.org> | 2007-04-29 06:59:27 +0000 |
commit | 034ec57184382ba8a40d8f094560d7137a4fdaae (patch) | |
tree | 7f2409d335910b777e1728f867de0a3b0751ef44 /gtk/gtkprintoperation-unix.c | |
parent | e61bea3494aa58811b6e7b7f61e39120461e8a29 (diff) | |
download | gtk+-034ec57184382ba8a40d8f094560d7137a4fdaae.tar.gz |
Support passing a print settings file to the preview command. (#403717,
2007-04-29 Matthias Clasen <mclasen@redhat.com>
* gtk/gtkprintoperation-unix.c
(_gtk_print_operation_platform_backend_launch_preview):
Support passing a print settings file to the preview
command. (#403717, Christian Persch)
* gtk/gtksettings.c: Document %s in the
gtk-print-preview-command setting.
svn path=/trunk/; revision=17704
Diffstat (limited to 'gtk/gtkprintoperation-unix.c')
-rw-r--r-- | gtk/gtkprintoperation-unix.c | 73 |
1 files changed, 57 insertions, 16 deletions
diff --git a/gtk/gtkprintoperation-unix.c b/gtk/gtkprintoperation-unix.c index 03f5b607c5..c65cfa5070 100644 --- a/gtk/gtkprintoperation-unix.c +++ b/gtk/gtkprintoperation-unix.c @@ -118,20 +118,26 @@ op_unix_free (GtkPrintOperationUnix *op_unix) static gchar * shell_command_substitute_file (const gchar *cmd, - const gchar *filename) + const gchar *pdf_filename, + const gchar *settings_filename, + gboolean *pdf_filename_replaced, + gboolean *settings_filename_replaced) { const gchar *inptr, *start; gchar *result; GString *final; g_return_val_if_fail (cmd != NULL, NULL); - g_return_val_if_fail (filename != NULL, NULL); + g_return_val_if_fail (pdf_filename != NULL, NULL); + g_return_val_if_fail (settings_filename != NULL, NULL); result = NULL; final = g_string_new (NULL); - start = inptr = cmd; + *pdf_filename_replaced = FALSE; + *settings_filename_replaced = FALSE; + start = inptr = cmd; while ((inptr = strchr (inptr, '%')) != NULL) { g_string_append_len (final, start, inptr - start); @@ -139,7 +145,13 @@ shell_command_substitute_file (const gchar *cmd, switch (*inptr) { case 'f': - g_string_append (final, filename ? filename : ""); + g_string_append (final, pdf_filename); + *pdf_filename_replaced = TRUE; + break; + + case 's': + g_string_append (final, settings_filename); + *settings_filename_replaced = TRUE; break; case '%': @@ -176,29 +188,52 @@ _gtk_print_operation_platform_backend_launch_preview (GtkPrintOperation *op, gchar *cmd; gchar *preview_cmd; GtkSettings *settings; + GtkPrintSettings *print_settings; + gchar *settings_filename; gchar *quoted_filename; + gchar *quoted_settings_filename; + gboolean filename_used; + gboolean settings_used; GdkScreen *screen; GError *error = NULL; + gint fd; cairo_surface_destroy (surface); - settings = gtk_settings_get_default (); + if (parent) + screen = gtk_window_get_screen (parent); + else + screen = gdk_screen_get_default (); + + settings_filename = g_build_filename (g_get_tmp_dir (), "settingsXXXXXX.ini", NULL); + fd = g_mkstemp (settings_filename); + + print_settings = gtk_print_operation_get_print_settings (op); + if (!gtk_print_settings_to_file (print_settings, settings_filename, &error)) + goto out; + + close (fd); + + settings = gtk_settings_get_for_screen (screen); g_object_get (settings, "gtk-print-preview-command", &preview_cmd, NULL); quoted_filename = g_shell_quote (filename); - cmd = shell_command_substitute_file (preview_cmd, quoted_filename); + quoted_settings_filename = g_shell_quote (settings_filename); + cmd = shell_command_substitute_file (preview_cmd, quoted_filename, quoted_settings_filename, &filename_used, &settings_used); g_shell_parse_argv (cmd, &argc, &argv, &error); + g_free (preview_cmd); + g_free (quoted_filename); + g_free (quoted_settings_filename); + g_free (cmd); + if (error != NULL) goto out; - if (parent) - screen = gtk_window_get_screen (parent); - else - screen = gdk_screen_get_default (); - gdk_spawn_on_screen (screen, NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, &error); + g_strfreev (argv); + out: if (error != NULL) { @@ -216,13 +251,19 @@ _gtk_print_operation_platform_backend_launch_preview (GtkPrintOperation *op, gtk_window_present (GTK_WINDOW (edialog)); - g_error_free (error); + g_error_free (error); + + filename_used = FALSE; + settings_used = FALSE; } - g_free (cmd); - g_free (quoted_filename); - g_free (preview_cmd); - g_strfreev (argv); + if (!filename_used) + g_unlink (filename); + + if (!settings_used) + g_unlink (settings_filename); + + g_free (settings_filename); } static void |