GNOME Bugzilla – Bug 474302
printing to an existing file overwrites without confirmation
Last modified: 2008-03-12 18:06:14 UTC
- Open evince, eog, or any application using the gtk printing dialog. - Print a document to a file named "output.pdf", for instance. - Print (a different document, or from a different application) to the same output file. - The existing pdf is overwrited, without asking for confirmation. The dialog should warn the user about this. There could even be data loss.
*** Bug 494050 has been marked as a duplicate of this bug. ***
The old print dialog didn't suffer from this. It simply used GtkFileChooser which made this under control.
Created attachment 105911 [details] [review] This patch adds overwrite confirmation dialog to GtkPrintUnixDialog. This patch adds overwrite confirmation dialog to GtkPrintUnixDialog. It is similar to that in FileChooserDialog.
Thanks for the patch, here is a quick review: + button = gtk_button_new_with_mnemonic (mnemonic_label); + if (button != NULL) This if seems superfluous. + printer = gtk_print_unix_dialog_get_selected_printer(print_dialog); Missing a space before the ( here. (other than this, the coding style is nearly perfect for GTK+...) + if ((printer != NULL) && (strcmp (gtk_printer_get_name (printer), "Print to File") == 0)) This is comparing of the name is somewhat icky, and won't work, since the name is a translated string. I'd propose to do this somewhat differently: connect and disconnect the signal handler depending on whether the currently selected printer is virtual or not, see gtk_printer_is_virtual. While not 100% correct, that is good enough until any other virtual printers show up... option = gtk_printer_option_set_lookup (priv->options,"gtk-main-page-custom-input"); + Here I would check option->type == GTK_PRINTER_OPTION_TYPE_FILESAVE to make sure that we have the right thing. + if ((option != NULL) && g_file_test (g_filename_from_uri (option->value,0,0), G_FILE_TEST_EXISTS)) g_filename_from_uri returns a newly allocated string, which you are leaking here. Also, please don't use 0 for NULL pointers. A bit further down, the same problem occurs again for g_path_get_basename and g_path_get_dirname, and g_filename_from_uri again. + "A file named \"%s\" already exists. Do you want to replace it?", String needs to be marked for translation with _(). "The file already exists in \"%s\". Replacing it will " + "overwrite its contents.", + This one too. + add_custom_button_to_dialog (GTK_DIALOG (dialog), "_Replace", GTK_STOCK_PRINT, GTK_RESPONSE_ACCEPT); And this one, too.
Created attachment 106273 [details] [review] Overwrite confirmation patch. Overwrite confirmation dialog modified according to previous review.
2008-03-12 Matthias Clasen <mclasen@redhat.com> * gtk/gtkprintunixdialog.c: Add an overwrite confirmation dialog for print-to-file. (#474302, Marek Kašík)