After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 474302 - printing to an existing file overwrites without confirmation
printing to an existing file overwrites without confirmation
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Printing
2.12.x
Other Linux
: Normal major
: ---
Assigned To: gtk-bugs
: 494050 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2007-09-06 18:08 UTC by Claudio Saavedra
Modified: 2008-03-12 18:06 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
This patch adds overwrite confirmation dialog to GtkPrintUnixDialog. (4.39 KB, patch)
2008-02-25 14:53 UTC, Marek Kašík
none Details | Review
Overwrite confirmation patch. (5.18 KB, patch)
2008-02-29 16:06 UTC, Marek Kašík
committed Details | Review

Description Claudio Saavedra 2007-09-06 18:08:33 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.
Comment 1 Pavel Šefránek 2008-02-03 17:34:06 UTC
*** Bug 494050 has been marked as a duplicate of this bug. ***
Comment 2 Pavel Šefránek 2008-02-03 17:36:57 UTC
The old print dialog didn't suffer from this. It simply used GtkFileChooser which made this under control.
Comment 3 Marek Kašík 2008-02-25 14:53:34 UTC
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.
Comment 4 Matthias Clasen 2008-02-27 06:11:54 UTC
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.


Comment 5 Marek Kašík 2008-02-29 16:06:43 UTC
Created attachment 106273 [details] [review]
Overwrite confirmation patch.

Overwrite confirmation dialog modified according to previous review.
Comment 6 Matthias Clasen 2008-03-12 18:06:14 UTC
2008-03-12  Matthias Clasen  <mclasen@redhat.com>

        * gtk/gtkprintunixdialog.c: Add an overwrite confirmation
        dialog for print-to-file.  (#474302, Marek Kašík)