diff options
author | Sven Neumann <sven@gimp.org> | 2007-08-09 15:05:23 +0000 |
---|---|---|
committer | Sven Neumann <neo@src.gnome.org> | 2007-08-09 15:05:23 +0000 |
commit | 8c4287775bce3ce5eb6a3dfc0097db186d2b200b (patch) | |
tree | ede728cc34bfc7c6632f952f3225ec4b8f43018a /modules/printbackends | |
parent | 07a789f58a391bc2c913982e9d9025c3ab12a2de (diff) | |
download | gdk-pixbuf-8c4287775bce3ce5eb6a3dfc0097db186d2b200b.tar.gz |
change the file extension when the file format is changed in the Print
2007-08-09 Sven Neumann <sven@gimp.org>
* 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
Diffstat (limited to 'modules/printbackends')
-rw-r--r-- | modules/printbackends/file/gtkprintbackendfile.c | 61 |
1 files changed, 59 insertions, 2 deletions
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); } |