Handle filename encoding consistently. (#351812, Christian Persch)

2006-08-17  Matthias Clasen  <mclasen@redhat.com>

	* gtk/gtkprinteroptionwidget.c (update_widgets):
	* modules/printbackends/file/gtkprintbackendfile.c
	(output_file_from_settings): Handle filename encoding
	consistently.  (#351812, Christian Persch)
This commit is contained in:
Matthias Clasen 2006-08-18 01:30:24 +00:00 committed by Matthias Clasen
parent 3336c855fe
commit 919cdba486
4 changed files with 65 additions and 34 deletions

View File

@ -1,5 +1,10 @@
2006-08-17 Matthias Clasen <mclasen@redhat.com> 2006-08-17 Matthias Clasen <mclasen@redhat.com>
* gtk/gtkprinteroptionwidget.c (update_widgets):
* modules/printbackends/file/gtkprintbackendfile.c
(output_file_from_settings): Handle filename encoding
consistently. (#351812, Christian Persch)
* NEWS: Updates * NEWS: Updates
2006-08-17 Federico Mena Quintero <federico@novell.com> 2006-08-17 Federico Mena Quintero <federico@novell.com>

View File

@ -1,5 +1,10 @@
2006-08-17 Matthias Clasen <mclasen@redhat.com> 2006-08-17 Matthias Clasen <mclasen@redhat.com>
* gtk/gtkprinteroptionwidget.c (update_widgets):
* modules/printbackends/file/gtkprintbackendfile.c
(output_file_from_settings): Handle filename encoding
consistently. (#351812, Christian Persch)
* NEWS: Updates * NEWS: Updates
2006-08-17 Federico Mena Quintero <federico@novell.com> 2006-08-17 Federico Mena Quintero <federico@novell.com>

View File

@ -841,14 +841,27 @@ update_widgets (GtkPrinterOptionWidget *widget)
break; break;
case GTK_PRINTER_OPTION_TYPE_FILESAVE: case GTK_PRINTER_OPTION_TYPE_FILESAVE:
{ {
char *basename = g_path_get_basename (source->value); gchar *filename = g_filename_from_uri (source->value, NULL, NULL);
char *dirname = g_path_get_dirname (source->value); if (filename != NULL)
gtk_entry_set_text (GTK_ENTRY (priv->entry), basename); {
if (g_path_is_absolute (dirname)) gchar *basename, *dirname, *text;
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (priv->combo),
dirname); basename = g_path_get_basename (filename);
g_free (basename); dirname = g_path_get_dirname (filename);
g_free (dirname); text = g_filename_to_utf8 (basename, -1, NULL, NULL, NULL);
if (text != NULL)
gtk_entry_set_text (GTK_ENTRY (priv->entry), basename);
if (g_path_is_absolute (dirname))
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (priv->combo),
dirname);
g_free (text);
g_free (basename);
g_free (dirname);
g_free (filename);
}
else
gtk_entry_set_text (GTK_ENTRY (priv->entry), source->value);
break; break;
} }
default: default:

View File

@ -205,27 +205,18 @@ format_from_settings (GtkPrintSettings *settings)
} }
static gchar * static gchar *
filename_from_settings (GtkPrintSettings *settings, output_file_from_settings (GtkPrintSettings *settings,
gchar *default_format) const gchar *default_format)
{ {
gchar *filename; gchar *uri = NULL;
filename = NULL;
if (settings) if (settings)
{ uri = g_strdup (gtk_print_settings_get (settings, GTK_PRINT_SETTINGS_OUTPUT_URI));
const gchar *uri;
uri = gtk_print_settings_get (settings, GTK_PRINT_SETTINGS_OUTPUT_URI); if (uri == NULL)
if (uri)
filename = g_filename_from_uri (uri, NULL, NULL);
}
/* FIXME: shouldn't we error out if we get an URI we cannot handle,
* rather than to print to some random file somewhere?
*/
if (filename == NULL)
{ {
gchar *extension; const gchar *extension;
gchar *name, *locale_name, *path;
if (default_format) if (default_format)
extension = default_format; extension = default_format;
@ -238,10 +229,21 @@ filename_from_settings (GtkPrintSettings *settings,
} }
/* default filename used for print-to-file */ /* default filename used for print-to-file */
filename = g_strdup_printf (_("output.%s"), extension); name = g_strdup_printf (_("output.%s"), extension);
locale_name = g_filename_from_utf8 (name, -1, NULL, NULL, NULL);
g_free (name);
if (locale_name != NULL)
{
path = g_build_filename (g_get_current_dir (), locale_name, NULL);
g_free (locale_name);
uri = g_filename_to_uri (path, NULL, NULL);
g_free (path);
}
} }
return filename; return uri;
} }
static cairo_status_t static cairo_status_t
@ -260,7 +262,7 @@ _cairo_write (void *closure,
while (length > 0) while (length > 0)
{ {
g_io_channel_write_chars (io, data, length, &written, &error); g_io_channel_write_chars (io, (const gchar *) data, length, &written, &error);
if (error != NULL) if (error != NULL)
{ {
@ -403,7 +405,7 @@ gtk_print_backend_file_print_stream (GtkPrintBackend *print_backend,
GtkPrinter *printer; GtkPrinter *printer;
_PrintStreamData *ps; _PrintStreamData *ps;
GtkPrintSettings *settings; GtkPrintSettings *settings;
gchar *filename = NULL; gchar *uri, *filename;
printer = gtk_print_job_get_printer (job); printer = gtk_print_job_get_printer (job);
settings = gtk_print_job_get_settings (job); settings = gtk_print_job_get_settings (job);
@ -416,8 +418,13 @@ gtk_print_backend_file_print_stream (GtkPrintBackend *print_backend,
ps->backend = print_backend; ps->backend = print_backend;
internal_error = NULL; internal_error = NULL;
filename = filename_from_settings (settings, NULL); uri = output_file_from_settings (settings, NULL);
filename = g_filename_from_uri (uri, NULL, &internal_error);
g_free (uri);
if (filename == NULL)
goto error;
ps->target_io = g_io_channel_new_file (filename, "w", &internal_error); ps->target_io = g_io_channel_new_file (filename, "w", &internal_error);
g_free (filename); g_free (filename);
@ -425,6 +432,7 @@ gtk_print_backend_file_print_stream (GtkPrintBackend *print_backend,
if (internal_error == NULL) if (internal_error == NULL)
g_io_channel_set_encoding (ps->target_io, NULL, &internal_error); g_io_channel_set_encoding (ps->target_io, NULL, &internal_error);
error:
if (internal_error != NULL) if (internal_error != NULL)
{ {
file_print_cb (GTK_PRINT_BACKEND_FILE (print_backend), file_print_cb (GTK_PRINT_BACKEND_FILE (print_backend),
@ -475,7 +483,7 @@ file_printer_get_options (GtkPrinter *printer,
gchar *display_format_names[N_FORMATS]; gchar *display_format_names[N_FORMATS];
gint n_formats = 0; gint n_formats = 0;
OutputFormat format; OutputFormat format;
gchar *filename; gchar *uri;
gint current_format = 0; gint current_format = 0;
format = format_from_settings (settings); format = format_from_settings (settings);
@ -521,11 +529,11 @@ file_printer_get_options (GtkPrinter *printer,
} }
} }
filename = filename_from_settings (settings, supported_formats[current_format]); uri = output_file_from_settings (settings, supported_formats[current_format]);
option = gtk_printer_option_new ("gtk-main-page-custom-input", _("File"), option = gtk_printer_option_new ("gtk-main-page-custom-input", _("File"),
GTK_PRINTER_OPTION_TYPE_FILESAVE); GTK_PRINTER_OPTION_TYPE_FILESAVE);
gtk_printer_option_set (option, filename); gtk_printer_option_set (option, uri);
option->group = g_strdup ("GtkPrintDialogExtension"); option->group = g_strdup ("GtkPrintDialogExtension");
gtk_printer_option_set_add (set, option); gtk_printer_option_set_add (set, option);