Better support for CUPS features in Qt 5.11

During the last couple of months KDAB engineers have been working on improving CUPS printing support for Linux in Qt.

This work has been sponsored by the LiMux project, a big thank you to them for allowing us to spend time improving Qt :).

We started in early December with a series of small commits cleaning up some code, removing some code that was never called [1] and merging several small functions so the code flow is easier to understand and increases maintainability [2][3][4][5][6].

Our big goal was reviving the Advanced options tab that was present in the first versions of Qt 5 but was removed due to usability concerns [7]. Unfortunately this meant that support of advanced options like automatic stapling (see a quirky video of that here: [8]) was lost.

In the Linux world those advanced options are exposed through CUPS [9] and its support for PPD [10] files. The interesting feature of PPD files is that they have a way to describe not only the options but also how they should be grouped, so you can build an automatic UI on top of it relatively easily.

So working towards the goal we started adding a way to be able to access the PPD structures through the QPrintDevice and its Linux backend (QPpdPrintDevice) [11] [12].

Once that was in, we were in a position to restore the old code (improved thanks to code review) to show the Advanced CUPS options in the printing dialog [13]. The code basically traverses the PPD structures returned by CUPS and creates a model containing all the options. Then this model is plugged into an editable tree view. As said previously, one of the reasons it was removed was that some options were shown in two different places creating confusion for the user. That was solved easily through a blacklist, meaning that important options, like the Page Size, that already have their own space in the user interface, would not be shown in the advanced options tab.

PPD files also have a way of describing conflicts between various options, for example, you can’t print on Photo quality unless you’re using Photo paper. The initial code commit didn’t fully implement this correctly so we had to fix it [14].

Another usability problem the print dialog had is that it was a bit confusing how much of the state it kept, depending on which order you clicked Ok/Cancel and opened/closed it. Some of the settings would or would not be stored, so we also fixed that 🙂 [15][16].

Not strictly related to PPD and the advanced CUPS options, is a fix we did regarding the handling of Custom page sizes. Printers can define their own page sizes and the support for that was broken, so since we were going through the code, we also contributed a fix for it [17].

Going back to the Advanced options improvements, we added support for Installable Options [18][19]. Those are some options which basically say, if the user installed some add-ons to their printer like a duplexer or stapler, that enables some of the Advanced options to actually be selectable. For that we also had to contribute a fix to CUPS itself [20] to fix the reported conflicting options when Installable Options are involved, so make sure you’re using CUPS >= 2.3 once it is released, or apply that patch to CUPS manually if you use a printer with Installable Options.

The last change we did for the Advanced tab was to make sure the text that comes from the PPD to describe the options is shown in the correct language (if your PPD has multi language support) [21].

One more feature we implemented in the Qt CUPS printing dialog is arbitrary range printing [22]. Previously one could only say “Print from page 3 to 5”, but not “Print page 1, then from 3 to 5 and then page 11”. This feature has been implemented in Qt itself, so applications don’t need to support it explicitly. Any application that uses the Qt print dialog will gain support for this feature “automagically”!

All these improvements will be released with Qt 5.11. We will soon start to work on some more improvements and bugfixes for the Qt Linux printing dialog for Qt 5.12. Stay tuned!