diff --git a/gtk/gtkprinteroptionwidget.c b/gtk/gtkprinteroptionwidget.c index 2b5941164f..85b767baab 100644 --- a/gtk/gtkprinteroptionwidget.c +++ b/gtk/gtkprinteroptionwidget.c @@ -411,31 +411,41 @@ filesave_changed_cb (GtkWidget *w, GtkPrinterOptionWidget *widget) { GtkPrinterOptionWidgetPrivate *priv = widget->priv; - char *value; - char *directory; - const char *file; + gchar *uri, *directory, *path; + const gchar *file; + + /* TODO: how do we support nonlocal file systems? */ + directory = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (priv->combo)); + file = g_filename_from_utf8 (gtk_entry_get_text (GTK_ENTRY (priv->entry)), + -1, NULL, NULL, NULL); + if (file == NULL) + return; /* combine the value of the chooser with the value of the entry */ g_signal_handler_block (priv->source, priv->source_changed_handler); - - /* TODO: how do we support nonlocal file systems? */ - directory = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (priv->combo)); - file = gtk_entry_get_text (GTK_ENTRY (priv->entry)); if (g_path_is_absolute (file)) - value = g_strdup (file); -#ifdef G_OS_UNIX - else if (file[0] == '~' && file[1] == '/') - value = g_build_filename (g_get_home_dir (), file + 2, NULL); -#endif + uri = g_filename_to_uri (file, NULL, NULL); else - value = g_build_filename (directory, file, NULL); + { +#ifdef G_OS_UNIX + if (file[0] == '~' && file[1] == '/') + { + directory = g_strdup (g_get_home_dir ()); + file += 2; + } +#endif + + path = g_build_filename (directory, file, NULL); + uri = g_filename_to_uri (path, NULL, NULL); + g_free (path); + } - if (value) - gtk_printer_option_set (priv->source, value); + if (uri) + gtk_printer_option_set (priv->source, uri); g_free (directory); - g_free (value); + g_free (uri); g_signal_handler_unblock (priv->source, priv->source_changed_handler); emit_changed (widget); @@ -505,7 +515,7 @@ alternative_set (GtkWidget *box, { gtk_container_foreach (GTK_CONTAINER (box), (GtkCallback) select_maybe, - value); + (gpointer) value); } static GSList * @@ -619,8 +629,8 @@ construct_widgets (GtkPrinterOptionWidget *widget) /* TODO: make this a gtkfilechooserentry once we move to GTK */ priv->entry = gtk_entry_new (); - priv->combo = gtk_file_chooser_button_new (_("Print to PDF"), - GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER); + priv->combo = gtk_file_chooser_button_new (source->display_text, + GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER); label = gtk_label_new_with_mnemonic (_("_Name:")); gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); diff --git a/gtk/gtkprintsettings.h b/gtk/gtkprintsettings.h index d893373b87..50d7ef7f53 100644 --- a/gtk/gtkprintsettings.h +++ b/gtk/gtkprintsettings.h @@ -110,6 +110,9 @@ void gtk_print_settings_set_int (GtkPrintSettings #define GTK_PRINT_SETTINGS_NUMBER_UP "number-up" #define GTK_PRINT_SETTINGS_OUTPUT_BIN "output-bin" +#define GTK_PRINT_SETTINGS_OUTPUT_FILE_FORMAT "output-file-format" +#define GTK_PRINT_SETTINGS_OUTPUT_URI "output-uri" + #define GTK_PRINT_SETTINGS_WIN32_DRIVER_VERSION "win32-driver-version" #define GTK_PRINT_SETTINGS_WIN32_DRIVER_EXTRA "win32-driver-extra" diff --git a/modules/printbackends/pdf/gtkprintbackendpdf.c b/modules/printbackends/pdf/gtkprintbackendpdf.c index 81b9c07f75..2d09772ea7 100644 --- a/modules/printbackends/pdf/gtkprintbackendpdf.c +++ b/modules/printbackends/pdf/gtkprintbackendpdf.c @@ -305,25 +305,32 @@ gtk_print_backend_pdf_print_stream (GtkPrintBackend *print_backend, _PrintStreamData *ps; GtkPrintSettings *settings; GIOChannel *save_channel; - const char *filename; + const gchar *uri; + gchar *filename = NULL; /* quit gcc */ printer = gtk_print_job_get_printer (job); settings = gtk_print_job_get_settings (job); error = NULL; - filename = gtk_print_settings_get (settings, "pdf-filename"); + uri = gtk_print_settings_get (settings, GTK_PRINT_SETTINGS_OUTPUT_URI); + 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) - filename = "output.pdf"; + filename = g_strdup_printf ("output.pdf"); ps = g_new0 (_PrintStreamData, 1); ps->callback = callback; ps->user_data = user_data; ps->dnotify = dnotify; ps->job = g_object_ref (job); + ps->backend = print_backend; ps->target_fd = creat (filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH); - ps->backend = print_backend; + g_free (filename); if (ps->target_fd == -1) { @@ -376,7 +383,7 @@ pdf_printer_get_options (GtkPrinter *printer, { GtkPrinterOptionSet *set; GtkPrinterOption *option; - const char *filename; + const char *uri; char *n_up[] = {"1" }; set = gtk_printer_option_set_new (); @@ -394,8 +401,8 @@ pdf_printer_get_options (GtkPrinter *printer, gtk_printer_option_set_add (set, option); if (settings != NULL && - (filename = gtk_print_settings_get (settings, "pdf-filename"))!= NULL) - gtk_printer_option_set (option, filename); + (uri = gtk_print_settings_get (settings, GTK_PRINT_SETTINGS_OUTPUT_URI))!= NULL) + gtk_printer_option_set (option, uri); return set; } @@ -408,7 +415,7 @@ pdf_printer_get_settings_from_options (GtkPrinter *printer, GtkPrinterOption *option; option = gtk_printer_option_set_lookup (options, "gtk-main-page-custom-input"); - gtk_print_settings_set (settings, "pdf-filename", option->value); + gtk_print_settings_set (settings, GTK_PRINT_SETTINGS_OUTPUT_URI, option->value); } static void