GNOME Bugzilla – Bug 469210
Honor CUPS user default options for GtkPrint
Last modified: 2008-08-24 18:51:01 UTC
As per Red Hat bug 157878: https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=157878 We have a network printer with duplex unit, which has a default of printing on both sides. However it is impossible to let GtkPrint honor a *user* default option in ~/.cups/lpoptions for one of our users, who by default wants everything printed single-sided. The attached patch (which is the same as the one in the Red Hat bug) does fix it but I'm aware that my C is rusty and it might not be in the style that is preferred. I'd be happy to try and fix any problems with it. I did test it with the current GTK+ SVN trunk, it does apply and it works.
Created attachment 94100 [details] [review] Patch to let GtkPrint honor user default CUPS options
+ /* Code taken from CUPS 1.2.10 source, cups_get_dests function */ CUPS is LGPL 2-only, while gtk+ is LGPL 2+, that might be a problem.
Hmm, ok. I'll attempt to rewrite it or ask the CUPS developers for relicensing permission.
Why is it necessary to copy & paste this cups code at all? Why not have GTK+ call cupsGetDests() from the Cups client library ... just like the cups lpoptions command does (see systemv/lpoptions.c in the cups source code). Or am I missing something? Using the cups client library should also mean administrator-specified defaults are picked up for printers that are on a remote cups server somewhere, if my understanding of how things work is correct.
I did that for the same reasons that lots of cupsFoo functions are reimplemented in gtkprintbackendcups.c: CUPS does not have an asynchronous API so calls that might require a roundtrip to the server can block, and we don't want that to block the print dialog as well. Just below my code in cups_request_default_printer you'll find the original code that already did an async request to the CUPS server for getting the default printer, as cupsGetDests() would do.
Created attachment 94706 [details] [review] honor user default CUPS options, try #2 Had some more time today, so I sent a request for relicensing to the CUPS mailing list. Let's see what they think. Furthermore here's an updated version that is basically the "rewrite" -- however there is only one really relevant way to read a file a line at a time and parse for certain keywords, so I'm not sure how to avoid "copying" the few lines of code that are left from the original. Any clues? When is it "reuse" vs "copyright theft"? Anyway, this updated version splits out the two tasks that cups_parse_lpoptions did in the first patch; I think it's better this way but feel free to comment on that too.
(In reply to comment #6) > Furthermore here's an updated version that is basically the "rewrite" -- > however there is only one really relevant way to read a file a line at a time > and parse for certain keywords, so I'm not sure how to avoid "copying" the few > lines of code that are left from the original. Any clues? When is it "reuse" vs > "copyright theft"? if you're worried about lifting code, you should probably rewrite the function to actually use GLib API, like g_file_get_contents() instead of fopen()+fgets() and the various string convenience functions for parsing the file. in any case, if all you're doing is parsing a file with a known format, then it's slightly difficult to incur in a license violation unless you literally lift the code.
I've rewritten the code some more to follow gtk style better, and committed it: 2008-03-04 Matthias Clasen <mclasen@redhat.com> * modules/printbackends/cups/gtkprintbackendcups.c: Honor cups user default options from ~/.cups/lpoptions (#469210, Stijn Hoop)
The last patch is not correct. See bug #521350 for a crash report.
Created attachment 106893 [details] [review] Simple fix This fixes the issue seen in bug #521350. Raising severity to blocker, since this really needs to go in before Gnome 2.22 comes out. Without this patch printing in Evince causes a crash.
(In reply to comment #10) > Created an attachment (id=106893) Btw, this same looping construct is used elsewhere in that file as well. This one was just left-over cruft I assume. (This notice may help release-team reviewing the patch).
Thanks for catching this, please commit
2008-03-10 Wouter Bolsterlee <wbolster@svn.gnome.org> reviewed by: Matthias Clasen <mclasen@redhat.com> * modules/printbackends/cups/gtkprintbackendcups.c (cups_get_user_options): Bug 469210 – Honor CUPS user default options for GtkPrint Correctly iterate over filename list, avoiding a critical warning/crash.
(In reply to comment #12) > Thanks for catching this, please commit Matthias, I'm leaving it to you to commit this patch to trunk. I've only committed it to the gtk-2-12 branch. Therefor I'm leaving this bug open for now. Thanks!
*** Bug 452348 has been marked as a duplicate of this bug. ***