From 8c4287775bce3ce5eb6a3dfc0097db186d2b200b Mon Sep 17 00:00:00 2001 From: Sven Neumann Date: Thu, 9 Aug 2007 15:05:23 +0000 Subject: [PATCH] change the file extension when the file format is changed in the Print 2007-08-09 Sven Neumann * modules/printbackends/file/gtkprintbackendfile.c: change the file extension when the file format is changed in the Print dialog (#356630). svn path=/trunk/; revision=18600 --- ChangeLog | 6 ++ .../printbackends/file/gtkprintbackendfile.c | 61 ++++++++++++++++++- 2 files changed, 65 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3aaeb5f61..cb552cd99 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2007-08-09 Sven Neumann + + * modules/printbackends/file/gtkprintbackendfile.c: change the + file extension when the file format is changed in the Print dialog + (#356630). + 2007-08-09 Stefan Kost * docs/reference/gtk/tmpl/gtkruler.sgml: diff --git a/modules/printbackends/file/gtkprintbackendfile.c b/modules/printbackends/file/gtkprintbackendfile.c index 7dae376cb..7ab8d4d9c 100644 --- a/modules/printbackends/file/gtkprintbackendfile.c +++ b/modules/printbackends/file/gtkprintbackendfile.c @@ -194,7 +194,8 @@ format_from_settings (GtkPrintSettings *settings) if (settings == NULL) return N_FORMATS; - value = gtk_print_settings_get (settings, GTK_PRINT_SETTINGS_OUTPUT_FILE_FORMAT); + value = gtk_print_settings_get (settings, + GTK_PRINT_SETTINGS_OUTPUT_FILE_FORMAT); if (value == NULL) return N_FORMATS; @@ -476,6 +477,58 @@ gtk_print_backend_file_init (GtkPrintBackendFile *backend) gtk_print_backend_set_list_done (GTK_PRINT_BACKEND (backend)); } +static void +file_printer_output_file_format_changed (GtkPrinterOption *format_option, + GtkPrinterOptionSet *set) +{ + GtkPrinterOption *uri_option; + gchar *base = NULL; + + if (! format_option->value) + return; + + uri_option = gtk_printer_option_set_lookup (set, + "gtk-main-page-custom-input"); + + if (uri_option && uri_option->value) + { + const gchar *uri = uri_option->value; + const gchar *dot = strrchr (uri, '.'); + + if (dot) + { + gint i; + + /* check if the file extension matches one of the known ones */ + for (i = 0; i < N_FORMATS; i++) + if (strcmp (dot + 1, formats[i]) == 0) + break; + + if (i < N_FORMATS && strcmp (formats[i], format_option->value)) + { + /* the file extension is known but doesn't match the + * selected one, strip it away + */ + base = g_strndup (uri, dot - uri); + } + } + else + { + /* there's no file extension */ + base = g_strdup (uri); + } + } + + if (base) + { + gchar *tmp = g_strdup_printf ("%s.%s", base, format_option->value); + + gtk_printer_option_set (uri_option, tmp); + g_free (tmp); + g_free (base); + } +} + static GtkPrinterOptionSet * file_printer_get_options (GtkPrinter *printer, GtkPrintSettings *settings, @@ -562,7 +615,11 @@ file_printer_get_options (GtkPrinter *printer, display_format_names); gtk_printer_option_set (option, supported_formats[current_format]); gtk_printer_option_set_add (set, option); - + + g_signal_connect (option, "changed", + G_CALLBACK (file_printer_output_file_format_changed), + set); + g_object_unref (option); }