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 469210 - Honor CUPS user default options for GtkPrint
Honor CUPS user default options for GtkPrint
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Printing
2.12.x
Other Linux
: Normal blocker
: ---
Assigned To: gtk-bugs
: 452348 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2007-08-22 11:52 UTC by Stijn Hoop
Modified: 2008-08-24 18:51 UTC
See Also:
GNOME target: 2.22.x
GNOME version: 2.21/2.22


Attachments
Patch to let GtkPrint honor user default CUPS options (5.28 KB, patch)
2007-08-22 11:52 UTC, Stijn Hoop
reviewed Details | Review
honor user default CUPS options, try #2 (6.30 KB, patch)
2007-08-31 12:30 UTC, Stijn Hoop
reviewed Details | Review
Simple fix (529 bytes, patch)
2008-03-09 12:04 UTC, Wouter Bolsterlee (uws)
committed Details | Review

Description Stijn Hoop 2007-08-22 11:52:18 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.
Comment 1 Stijn Hoop 2007-08-22 11:52:46 UTC
Created attachment 94100 [details] [review]
Patch to let GtkPrint honor user default CUPS options
Comment 2 Christian Persch 2007-08-22 19:26:24 UTC
+  /* 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.
Comment 3 Stijn Hoop 2007-08-23 10:42:03 UTC
Hmm, ok. I'll attempt to rewrite it or ask the CUPS developers for relicensing permission.
Comment 4 Karl Relton 2007-08-30 20:54:29 UTC
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.
Comment 5 Stijn Hoop 2007-08-31 07:27:13 UTC
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.
Comment 6 Stijn Hoop 2007-08-31 12:30:20 UTC
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.
Comment 7 Emmanuele Bassi (:ebassi) 2007-08-31 13:03:31 UTC
(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.
Comment 8 Matthias Clasen 2008-03-05 03:50:10 UTC
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)

Comment 9 Wouter Bolsterlee (uws) 2008-03-09 12:02:07 UTC
The last patch is not correct. See bug #521350 for a crash report.
Comment 10 Wouter Bolsterlee (uws) 2008-03-09 12:04:19 UTC
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.
Comment 11 Wouter Bolsterlee (uws) 2008-03-09 12:53:09 UTC
(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).
Comment 12 Matthias Clasen 2008-03-09 21:39:32 UTC
Thanks for catching this, please commit 
Comment 13 Wouter Bolsterlee (uws) 2008-03-10 08:56:31 UTC
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.
Comment 14 Wouter Bolsterlee (uws) 2008-03-10 08:57:35 UTC
(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!
Comment 15 Karl Relton 2008-08-24 18:51:01 UTC
*** Bug 452348 has been marked as a duplicate of this bug. ***