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 603823 - Print to File suggests ".ps" as filename, if GTK_PRINT_SETTINGS_OUTPUT_URI is a "file://" uri (with libgtk versions >= 2.16)
Print to File suggests ".ps" as filename, if GTK_PRINT_SETTINGS_OUTPUT_URI is...
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Printing
2.24.x
Other Linux
: Normal normal
: ---
Assigned To: gtk-bugs
: 649758 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2009-12-04 21:47 UTC by Daniel Holbert
Modified: 2013-10-18 06:37 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
simple program that demonstrates problem (2.57 KB, text/plain)
2009-12-05 00:47 UTC, Daniel Holbert
  Details
Sample application that works with gtk3 (2.70 KB, text/plain)
2011-09-18 03:28 UTC, Timothy Arceri
  Details
Fix for lost uri (713 bytes, patch)
2011-09-27 11:21 UTC, Timothy Arceri
none Details | Review
Fix lost filename (1.32 KB, patch)
2011-10-28 07:01 UTC, Timothy Arceri
none Details | Review
Fix lost filename v2 (1.40 KB, patch)
2011-11-02 02:10 UTC, Timothy Arceri
accepted-commit_now Details | Review
print to file: fixed lost filename in gui (1.85 KB, patch)
2011-12-08 01:04 UTC, Allison Karlitskaya (desrt)
committed Details | Review
Fix print to file filename (1.83 KB, patch)
2013-10-08 22:06 UTC, Timothy Arceri
none Details | Review

Description Daniel Holbert 2009-12-04 21:47:05 UTC
STEPS TO REPRODUCE:
 0. Be running a version of libgtk >= 2.16.  (I personally have tested 2.16 & 2.18)
 1. Start up a version of Firefox 3.0 or later. (with GTK print integration)
 2. Visit about:blank
 3. File | Print (or Ctrl+P)
 4. Select "Print To File"

EXPECTED RESULTS: Suggested output filename should be "mozilla.ps" or "mozilla.pdf"

ACTUAL RESULTS: Suggested output filename is ".ps" or ".pdf"

Corresponding Mozilla bug page for this:
  https://bugzilla.mozilla.org/show_bug.cgi?id=485067

As described in https://bugzilla.mozilla.org/show_bug.cgi?id=485067#c3 , this appears to happen whenever we pass a string that contains a colon to gtk_print_settings_set() for the key GTK_PRINT_SETTINGS_OUTPUT_URI.

(This bug also affects gedit version 2.28.0 on my system (running Ubuntu 9.10), though it apparently doesn't affect gedit on Fedora 12.)
Comment 1 Daniel Holbert 2009-12-04 21:53:10 UTC
More details from the mozilla bug page:
Quoting https://bugzilla.mozilla.org/show_bug.cgi?id=485067#c3
> Here's the line of Mozilla code that comes into play here:
> 
> > 460   gtk_print_settings_set(mPrintSettings, GTK_PRINT_SETTINGS_OUTPUT_URI, url.get());
> http://mxr.mozilla.org/mozilla-central/source/widget/src/gtk2/nsPrintSettingsGTK.cpp#460
> 
[snip]
> I've tried replacing the "url.get()" token there with some hard-coded string
> constants, and I've learned the following -- it looks like we hit this bug
> whenever we pass in a string that contains a colon character.  When I exclude
> the colon, then the print dialog ends up using the correct filename (albeit
> with no path information).
> 
> e.g. "/random/directory/foo.ps" and "file///random/directory/foo.ps" both end
> up presenting print dialogs that offer to save "foo.ps" in the current working
> directory.  And if I add a colon (yielding "file:///random/directory/foo.ps"),
> then the print dialog buggily reverts to naming the file ".ps".

Note also that GTK's documentation for the "GTK_PRINT_SETTINGS_OUTPUT_URI" specifically states that "file://" URIs are supported:
http://library.gnome.org/devel/gtk/unstable/GtkPrintSettings.html#GTK-PRINT-SETTINGS-OUTPUT-URI:CAPS
Comment 2 Daniel Holbert 2009-12-05 00:47:11 UTC
Created attachment 149130 [details]
simple program that demonstrates problem

The attached simple program demonstrates the problem.

I can compile it on Ubuntu 9.10 with this command:
> g++ simple-gtk.cpp -o simple-gtk `pkg-config gtk+-2.0 --cflags --libs` -I /usr/include/gtk-unix-print-2.0/

It presents a list of buttons, each of which generates a print dialog with the button's label passed in as GTK_PRINT_SETTINGS_OUTPUT_URI.

The values beginning with "file:/" all exhibit this bug -- they end up with the suggested filename being ".ps".

The other values are fine -- they appear to use everything after the last "/" character. (which is reasonable behavior)
Comment 3 Daniel Holbert 2009-12-05 00:51:48 UTC
(In reply to comment #2)
> The other values are fine -- they appear to use everything after the last "/"
> character. (which is reasonable behavior)

Just for completeness, the exception to the above statement is "foo:///tmp/nonfile_path_with_colon.ps" -- given that value, the print-dialog uses the full value (including "foo:///") as its suggested filename.  (This is still reasonable behavior, since that this is silly "foo://" URI.  The behavior I'd like to see changed/fixed is for file://, the format this dialog is supposed to support. :))
Comment 4 Javier Jardón (IRC: jjardon) 2009-12-05 02:07:16 UTC
Maybe related with this bug: https://bugzilla.gnome.org/show_bug.cgi?id=587053
Comment 5 Timothy Arceri 2011-09-18 03:28:52 UTC
Created attachment 196862 [details]
Sample application that works with gtk3

I have tested this in GTK 3 and the problem is not will the colon but with this setting:
 gtk_print_settings_set(printSettings, GTK_PRINT_SETTINGS_OUTPUT_FILE_FORMAT, "ps");

When the file format is left unset the URI works correctly. Something is going wrong when file format is set to "ps" or "svg" if its set to pdf the uri is fine.

I've attached a new test file that works with GTK 3. To build it:

g++ simple-gtk3.cpp -o simple-gtk `pkg-config gtk+-3.0 --cflags --libs` -I /usr/include/gtk-3.0/unix-print
Comment 6 Timothy Arceri 2011-09-27 06:21:00 UTC
ok here is what is happening there is a function file_printer_output_file_format_changed in gtkprintbackendfile.c 
When "Print to File" is selected this method is called twice. The first time the lookup of uri_option returns the correct value e.g "file:///home/timothy/mozilla.ps" the second time it returns "" the question is why is this being called twice and what data is being passed to it?

I can make a patch with a work around to ignore blank strings but it would be better if I (or someone else) can find the cause of the second call.
Comment 7 Timothy Arceri 2011-09-27 06:43:36 UTC
On the first call the format is set to "pdf", and on the second call its set to "ps" this it where the uri data is lost.
Comment 8 Timothy Arceri 2011-09-27 11:21:36 UTC
Created attachment 197556 [details] [review]
Fix for lost uri

Ok so whats happening is when the format type is changed this triggers "file_printer_output_file_format_changed" to be called, and at the end of this "gtk_printer_option_set" is called which triggers a change which is intended to update the GUI (I think) however this also triggers "file_printer_output_file_format_changed" to be called again. I'm not sure how this could be implemented without the need for this circular calls happening (maybe it cant) as this is really my first time working with GTK.

I do however have a patch which reapplies the uri value that gets lost during the cycle.
Comment 9 Timothy Arceri 2011-09-28 02:00:33 UTC
Also just to bump up the importance of this bug, Firefox is not the only application affected. As far as I can tell all Gnome apps that use this feature are.

Steps to Reproduce:
1. Use Print to File to print in PostScript format rather than pdf
2. Open the print to File dialog again and now suggested output is ".ps"
Comment 10 Milan Bouchet-Valat 2011-10-14 07:28:26 UTC
Thanks for the patch, but I don't think it will be committed as-is. You'd need to find out why the URI is erased in the first place by file_printer_output_file_format_changed(), which AIUI shouldn't happen. Good luck! ;-)
Comment 11 Timothy Arceri 2011-10-28 07:01:39 UTC
Created attachment 200156 [details] [review]
Fix lost filename 

Ok found the cause of the problem. The widget was creating an event before it had finished updating all the values. Please let me know if I've used the right blocking functions here, Thanks.
Comment 12 Federico Mena Quintero 2011-10-31 21:01:42 UTC
Yes, those are the correct functions to block the signal emission.

One other thing - in that patch, the call to gtk_file_chooser_set_current_folder() should really be gtk_file_chooser_set_filename().  (This is not a problem with your patch per se; it's a problem with the original code.)  The file chooser button is used in SELECT_FOLDER mode, and the code intends to set the selection - not the "folder in which the selection lives", which is what gtk_file_chooser_set_current_folder() is about.
Comment 13 Timothy Arceri 2011-11-02 02:10:31 UTC
Created attachment 200472 [details] [review]
Fix lost filename v2

Updated fix with suggestion to change gtk_file_chooser_set_current_folder to gtk_file_chooser_set_filename

Please review
Comment 14 Timothy Arceri 2011-11-08 01:44:51 UTC
@Federico, Milan

Is one of you able to review my latest patch and let me know if I need to change anything to get it committed. It would be good to finally have this issue resolved.

Thanks
Comment 15 Milan Bouchet-Valat 2011-11-08 10:01:47 UTC
Sorry, I've no authority to review your patch, and I've even no way of testing it ATM. :-/ From a purely stylistic POV it looks good to me, and your reasoning makes sense, but... Don't worry, though, somebody will probably review it.
Comment 16 Milan Bouchet-Valat 2011-11-24 18:55:58 UTC
I think you should ping e.g. mclasen on #gtk+ on irc.gnome.org.
Comment 17 Matthias Clasen 2011-11-28 05:03:04 UTC
Review of attachment 200472 [details] [review]:

Makes sense to me, and works fine in my testing.
Comment 18 Timothy Arceri 2011-12-01 05:09:55 UTC
Thanks for the review. Can someone push the patch to git master for me as I don't have git access.
Comment 19 Allison Karlitskaya (desrt) 2011-12-08 01:04:38 UTC
Created attachment 203038 [details] [review]
print to file: fixed lost filename in gui

Stop widget creating an event before updating both directory and
filename values.
Comment 20 Allison Karlitskaya (desrt) 2011-12-08 01:05:09 UTC
Attachment 203038 [details] pushed as 36effbb - print to file: fixed lost filename in gui
Comment 21 Timothy Arceri 2013-05-29 05:02:30 UTC
*** Bug 649758 has been marked as a duplicate of this bug. ***
Comment 22 Timothy Arceri 2013-10-08 22:04:25 UTC
Reopening with request for this to be applied to the 2.24 branch. I will apply a fresh patch that fixes so whitespaces
Comment 23 Timothy Arceri 2013-10-08 22:06:03 UTC
Created attachment 256770 [details] [review]
Fix print to file filename

Fixes whitespaces in previous patch
Comment 24 Timothy Arceri 2013-10-15 20:31:01 UTC
bump. Can someone commit this to the 2.24 branch?
Comment 25 Timothy Arceri 2013-10-18 06:37:22 UTC
Closing again as this is pretty much obsolete if the fix for https://bugzilla.gnome.org/show_bug.cgi?id=554712 is back ported to gtk2