Merge lp:~jonas-drange/ubuntu-settings-components/quality-read-write into lp:~phablet-team/ubuntu-settings-components/printer-components
- quality-read-write
- Merge into printer-components
Proposed by
Jonas G. Drange
Status: | Merged |
---|---|
Approved by: | Andrew Hayzen |
Approved revision: | 214 |
Merged at revision: | 210 |
Proposed branch: | lp:~jonas-drange/ubuntu-settings-components/quality-read-write |
Merge into: | lp:~phablet-team/ubuntu-settings-components/printer-components |
Diff against target: |
862 lines (+247/-213) 16 files modified
examples/Printers.qml (+15/-1) plugins/Ubuntu/Settings/Printers/cups/cupsfacade.h (+2/-0) plugins/Ubuntu/Settings/Printers/cups/cupsfacade_impl.cpp (+58/-31) plugins/Ubuntu/Settings/Printers/cups/cupsfacade_impl.h (+6/-1) plugins/Ubuntu/Settings/Printers/enums.h (+0/-9) plugins/Ubuntu/Settings/Printers/models/printermodel.cpp (+21/-5) plugins/Ubuntu/Settings/Printers/models/printermodel.h (+2/-1) plugins/Ubuntu/Settings/Printers/printer/printer.cpp (+48/-12) plugins/Ubuntu/Settings/Printers/printer/printer.h (+3/-3) plugins/Ubuntu/Settings/Printers/printer/printer_p.h (+5/-0) plugins/Ubuntu/Settings/Printers/printer/printerjob.cpp (+17/-8) plugins/Ubuntu/Settings/Printers/printer/printerjob.h (+5/-4) plugins/Ubuntu/Settings/Printers/structs.h (+23/-14) plugins/Ubuntu/Settings/Printers/utils.h (+13/-119) tests/unittests/Printers/mockcupsfacade.h (+6/-0) tests/unittests/Printers/tst_printer.cpp (+23/-5) |
To merge this branch: | bzr merge lp:~jonas-drange/ubuntu-settings-components/quality-read-write |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Andrew Hayzen (community) | Approve | ||
Review via email:
|
Commit message
* Implements read/write of select Quality ppd settings
* Updates PrinterJob to use the correct quality setting
* Fixes broken ColorModel system, now reflects most ppds, and leaves the ppd implementation details in the ppd (colorspace, organization, etc)
Description of the change
To post a comment you must log in.
- 212. By Jonas G. Drange
-
reloads qualities
Revision history for this message
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Andrew Hayzen (ahayzen) wrote : | # |
Also can the list of quality opts in CupsFacadeImpl:
- 213. By Jonas G. Drange
-
addresses comments from Andrew
- 214. By Jonas G. Drange
-
fixes warnings
Revision history for this message
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Andrew Hayzen (ahayzen) wrote : | # |
LGTM, thanks for the fixes :-)
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'examples/Printers.qml' |
2 | --- examples/Printers.qml 2017-01-19 17:59:17 +0000 |
3 | +++ examples/Printers.qml 2017-01-20 12:08:10 +0000 |
4 | @@ -121,11 +121,25 @@ |
5 | if (enabled) |
6 | selectedIndex = printer.colorModel |
7 | } |
8 | + } |
9 | |
10 | + ListItems.ValueSelector { |
11 | + anchors { |
12 | + left: parent.left |
13 | + right: parent.right |
14 | + } |
15 | + visible: printer.supportedPrintQualities.length |
16 | + text: "Quality" |
17 | + values: printer.supportedPrintQualities |
18 | + enabled: values.length > 1 |
19 | + onSelectedIndexChanged: printer.printQuality = selectedIndex |
20 | + Component.onCompleted: { |
21 | + if (enabled) |
22 | + selectedIndex = printer.printQuality |
23 | + } |
24 | } |
25 | } |
26 | } |
27 | - |
28 | } |
29 | } |
30 | |
31 | |
32 | === modified file 'plugins/Ubuntu/Settings/Printers/cups/cupsfacade.h' |
33 | --- plugins/Ubuntu/Settings/Printers/cups/cupsfacade.h 2017-01-17 16:21:54 +0000 |
34 | +++ plugins/Ubuntu/Settings/Printers/cups/cupsfacade.h 2017-01-20 12:08:10 +0000 |
35 | @@ -96,6 +96,8 @@ |
36 | |
37 | virtual QList<ColorModel> printerGetSupportedColorModels( |
38 | const QString &name) const = 0; |
39 | + virtual QList<PrintQuality> printerGetSupportedQualities( |
40 | + const QString &name) const = 0; |
41 | virtual int printFileToDest(const QString &filepath, |
42 | const QString &title, |
43 | const cups_dest_t *dest) = 0; |
44 | |
45 | === modified file 'plugins/Ubuntu/Settings/Printers/cups/cupsfacade_impl.cpp' |
46 | --- plugins/Ubuntu/Settings/Printers/cups/cupsfacade_impl.cpp 2017-01-18 14:35:30 +0000 |
47 | +++ plugins/Ubuntu/Settings/Printers/cups/cupsfacade_impl.cpp 2017-01-20 12:08:10 +0000 |
48 | @@ -190,9 +190,9 @@ |
49 | QVariant CupsFacadeImpl::printerGetOption(const QString &name, |
50 | const QString &option) |
51 | { |
52 | - Q_UNUSED(name); |
53 | - Q_UNUSED(option); |
54 | - return QVariant(); |
55 | + QStringList opts({option}); |
56 | + auto res = printerGetOptions(name, opts); |
57 | + return res[option]; |
58 | } |
59 | |
60 | QMap<QString, QVariant> CupsFacadeImpl::printerGetOptions( |
61 | @@ -222,17 +222,31 @@ |
62 | Q_FOREACH(const QString &option, options) { |
63 | if (option == "DefaultColorModel") { |
64 | ColorModel model; |
65 | - |
66 | - ppd_option_t *defCModel = ppdFindOption(ppd, option.toUtf8()); |
67 | - if (defCModel) { |
68 | - model = Utils::parsePpdColorModel(defCModel->choices[0].choice); |
69 | - } else { |
70 | - ppd_option_t *cModel = ppdFindOption(ppd, "ColorModel"); |
71 | - if (cModel) { |
72 | - model = Utils::parsePpdColorModel(cModel->defchoice); |
73 | + ppd_option_t *ppdColorModel = ppdFindOption(ppd, "ColorModel"); |
74 | + if (ppdColorModel) { |
75 | + ppd_choice_t* def = ppdFindChoice(ppdColorModel, |
76 | + ppdColorModel->defchoice); |
77 | + if (def) { |
78 | + model = Utils::parsePpdColorModel(def->choice, |
79 | + def->text, |
80 | + "ColorModel"); |
81 | } |
82 | } |
83 | ret[option] = QVariant::fromValue(model); |
84 | + } else if (option == "DefaultPrintQuality") { |
85 | + PrintQuality quality; |
86 | + Q_FOREACH(const QString opt, m_knownQualityOptions) { |
87 | + ppd_option_t *ppdQuality = ppdFindOption(ppd, opt.toUtf8()); |
88 | + if (ppdQuality) { |
89 | + ppd_choice_t* def = ppdFindChoice(ppdQuality, |
90 | + ppdQuality->defchoice); |
91 | + if (def) { |
92 | + quality = Utils::parsePpdPrintQuality(def->choice, |
93 | + def->text, opt); |
94 | + } |
95 | + } |
96 | + } |
97 | + ret[option] = QVariant::fromValue(quality); |
98 | } else { |
99 | ppd_option_t *val = ppdFindOption(ppd, option.toUtf8()); |
100 | |
101 | @@ -246,7 +260,6 @@ |
102 | |
103 | ppdClose(ppd); |
104 | cupsFreeDests(1, dest); |
105 | - |
106 | return ret; |
107 | } |
108 | |
109 | @@ -264,8 +277,36 @@ |
110 | |
111 | ppd_option_t *colorModels = ppdFindOption(ppd, "ColorModel"); |
112 | if (colorModels) { |
113 | - for (int i = 0; i < colorModels->num_choices; ++i) |
114 | - ret.append(Utils::parsePpdColorModel(colorModels->choices[i].choice)); |
115 | + for (int i = 0; i < colorModels->num_choices; ++i) { |
116 | + ret.append(Utils::parsePpdColorModel(colorModels->choices[i].choice, |
117 | + colorModels->choices[i].text, |
118 | + "ColorModel")); |
119 | + } |
120 | + } |
121 | + |
122 | + ppdClose(ppd); |
123 | + return ret; |
124 | +} |
125 | + |
126 | +QList<PrintQuality> CupsFacadeImpl::printerGetSupportedQualities(const QString &name) const |
127 | +{ |
128 | + QList<PrintQuality> ret; |
129 | + ppd_file_t* ppd; |
130 | + |
131 | + ppd = helper.getPpdFile(getPrinterName(name), getPrinterInstance(name)); |
132 | + if (!ppd) { |
133 | + qCritical() << "Could not get PPD for" << name; |
134 | + return ret; |
135 | + } |
136 | + |
137 | + Q_FOREACH(const QString &opt, m_knownQualityOptions) { |
138 | + ppd_option_t *qualityOpt = ppdFindOption(ppd, opt.toUtf8()); |
139 | + if (qualityOpt) { |
140 | + for (int i = 0; i < qualityOpt->num_choices; ++i) |
141 | + ret.append(Utils::parsePpdPrintQuality(qualityOpt->choices[i].choice, |
142 | + qualityOpt->choices[i].text, |
143 | + opt)); |
144 | + } |
145 | } |
146 | |
147 | ppdClose(ppd); |
148 | @@ -310,23 +351,9 @@ |
149 | __CUPS_ADD_OPTION(dest, "page-ranges", options->printRange().toLocal8Bit()); |
150 | } |
151 | |
152 | - QString printQuality = ""; |
153 | - switch (options->quality()) { |
154 | - case PrinterEnum::Quality::DraftQuality: |
155 | - printQuality = "FastDraft"; |
156 | - break; |
157 | - case PrinterEnum::Quality::BestQuality: |
158 | - printQuality = "Best"; |
159 | - break; |
160 | - case PrinterEnum::Quality::PhotoQuality: |
161 | - printQuality = "Photo"; |
162 | - break; |
163 | - case PrinterEnum::Quality::NormalQuality: |
164 | - default: |
165 | - printQuality = "Normal"; |
166 | - break; |
167 | - } |
168 | - __CUPS_ADD_OPTION(dest, "OutputMode", printQuality.toLocal8Bit()); |
169 | + PrintQuality quality = options->getPrintQuality(); |
170 | + __CUPS_ADD_OPTION(dest, quality.originalOption.toLocal8Bit(), |
171 | + quality.name.toLocal8Bit()); |
172 | |
173 | return dest; |
174 | } |
175 | |
176 | === modified file 'plugins/Ubuntu/Settings/Printers/cups/cupsfacade_impl.h' |
177 | --- plugins/Ubuntu/Settings/Printers/cups/cupsfacade_impl.h 2017-01-17 16:21:54 +0000 |
178 | +++ plugins/Ubuntu/Settings/Printers/cups/cupsfacade_impl.h 2017-01-20 12:08:10 +0000 |
179 | @@ -76,7 +76,8 @@ |
180 | ) override; |
181 | virtual QList<ColorModel> printerGetSupportedColorModels( |
182 | const QString &name) const override; |
183 | - |
184 | + virtual QList<PrintQuality> printerGetSupportedQualities( |
185 | + const QString &name) const override; |
186 | virtual cups_dest_t* makeDest(const QString &name, |
187 | const PrinterJob *options) override; |
188 | |
189 | @@ -87,6 +88,10 @@ |
190 | QString getPrinterName(const QString &name) const; |
191 | QString getPrinterInstance(const QString &name) const; |
192 | QStringList parsePpdColorModel(const QString &colorModel); |
193 | + const QStringList m_knownQualityOptions = QStringList({ |
194 | + "Quality", "PrintQuality", "HPPrintQuality", "StpQuality", |
195 | + "OutputMode", |
196 | + }); |
197 | CupsPkHelper helper; |
198 | }; |
199 | |
200 | |
201 | === modified file 'plugins/Ubuntu/Settings/Printers/enums.h' |
202 | --- plugins/Ubuntu/Settings/Printers/enums.h 2017-01-18 14:35:30 +0000 |
203 | +++ plugins/Ubuntu/Settings/Printers/enums.h 2017-01-20 12:08:10 +0000 |
204 | @@ -107,15 +107,6 @@ |
205 | }; |
206 | Q_ENUM(PrintRange) |
207 | |
208 | - enum class Quality |
209 | - { |
210 | - DraftQuality = 0, |
211 | - NormalQuality, |
212 | - BestQuality, |
213 | - PhotoQuality, |
214 | - }; |
215 | - Q_ENUM(Quality) |
216 | - |
217 | enum class State |
218 | { |
219 | IdleState = 0, |
220 | |
221 | === modified file 'plugins/Ubuntu/Settings/Printers/models/printermodel.cpp' |
222 | --- plugins/Ubuntu/Settings/Printers/models/printermodel.cpp 2017-01-19 20:05:56 +0000 |
223 | +++ plugins/Ubuntu/Settings/Printers/models/printermodel.cpp 2017-01-20 12:08:10 +0000 |
224 | @@ -190,10 +190,17 @@ |
225 | // case PdfModeRole: |
226 | // ret = printer->pdfMode(); |
227 | // break; |
228 | - // case QualityRole: |
229 | - // ret = printer->quality(); |
230 | - // break; |
231 | - |
232 | + case PrintQualityRole: |
233 | + ret = printer->supportedPrintQualities().indexOf(printer->defaultPrintQuality()); |
234 | + break; |
235 | + case SupportedPrintQualitiesRole: { |
236 | + QStringList qualities; |
237 | + Q_FOREACH(const PrintQuality &q, printer->supportedPrintQualities()) { |
238 | + qualities.append(q.text.isEmpty() ? q.name : q.text); |
239 | + } |
240 | + ret = qualities; |
241 | + } |
242 | + break; |
243 | case DescriptionRole: |
244 | ret = printer->description(); |
245 | break; |
246 | @@ -273,6 +280,14 @@ |
247 | } |
248 | } |
249 | break; |
250 | + case PrintQualityRole: { |
251 | + int index = value.toInt(); |
252 | + QList<PrintQuality> quals = printer->supportedPrintQualities(); |
253 | + if (index >= 0 && quals.size() > index) { |
254 | + printer->setDefaultPrintQuality(quals.at(index)); |
255 | + } |
256 | + } |
257 | + break; |
258 | } |
259 | } |
260 | |
261 | @@ -295,7 +310,8 @@ |
262 | names[PrintRangeRole] = "printRange"; |
263 | names[PrintRangeModeRole] = "printRangeMode"; |
264 | names[PdfModeRole] = "pdfMode"; |
265 | - names[QualityRole] = "quality"; |
266 | + names[PrintQualityRole] = "printQuality"; |
267 | + names[SupportedPrintQualitiesRole] = "supportedPrintQualities"; |
268 | names[DescriptionRole] = "description"; |
269 | names[PageSizeRole] = "pageSize"; |
270 | names[SupportedPageSizesRole] = "supportedPageSizes"; |
271 | |
272 | === modified file 'plugins/Ubuntu/Settings/Printers/models/printermodel.h' |
273 | --- plugins/Ubuntu/Settings/Printers/models/printermodel.h 2017-01-19 19:50:01 +0000 |
274 | +++ plugins/Ubuntu/Settings/Printers/models/printermodel.h 2017-01-20 12:08:10 +0000 |
275 | @@ -53,7 +53,8 @@ |
276 | PrintRangeRole, |
277 | PrintRangeModeRole, |
278 | PdfModeRole, |
279 | - QualityRole, |
280 | + PrintQualityRole, |
281 | + SupportedPrintQualitiesRole, |
282 | DescriptionRole, |
283 | PageSizeRole, |
284 | SupportedPageSizesRole, |
285 | |
286 | === modified file 'plugins/Ubuntu/Settings/Printers/printer/printer.cpp' |
287 | --- plugins/Ubuntu/Settings/Printers/printer/printer.cpp 2017-01-19 17:59:17 +0000 |
288 | +++ plugins/Ubuntu/Settings/Printers/printer/printer.cpp 2017-01-20 12:08:10 +0000 |
289 | @@ -41,6 +41,7 @@ |
290 | PrinterPrivate::PrinterPrivate(Printer *q) |
291 | { |
292 | loadColorModel(); |
293 | + loadPrintQualities(); |
294 | } |
295 | |
296 | PrinterPrivate::PrinterPrivate(Printer *q, PrinterInfo *info, CupsFacade *cups) |
297 | @@ -49,6 +50,7 @@ |
298 | this->cups = cups; |
299 | |
300 | loadColorModel(); |
301 | + loadPrintQualities(); |
302 | } |
303 | |
304 | PrinterPrivate::~PrinterPrivate() |
305 | @@ -70,9 +72,7 @@ |
306 | m_supportedColorModels.append(m_defaultColorModel); |
307 | } |
308 | } else { |
309 | - ColorModel rgb = ColorModel(); |
310 | - rgb.colorOrganization = PrinterEnum::ColorOrganization::UnknownOrganization; |
311 | - rgb.colorSpace = PrinterEnum::ColorSpace::RGBSpace; |
312 | + ColorModel rgb; |
313 | rgb.colorType = PrinterEnum::ColorModelType::ColorType; |
314 | rgb.name = "RGB"; |
315 | rgb.text = "Color"; |
316 | @@ -82,6 +82,23 @@ |
317 | } |
318 | } |
319 | |
320 | +void PrinterPrivate::loadPrintQualities() |
321 | +{ |
322 | + if (!this->info->isPdf()) { |
323 | + QString name = this->info->printerName(); |
324 | + m_defaultPrintQuality = this->cups->printerGetOption( |
325 | + name, "DefaultPrintQuality").value<PrintQuality>(); |
326 | + m_supportedPrintQualities = this->cups->printerGetSupportedQualities(name); |
327 | + } else { |
328 | + PrintQuality quality; |
329 | + m_defaultPrintQuality = quality; |
330 | + m_supportedPrintQualities = QList<PrintQuality>({quality}); |
331 | + } |
332 | + if (m_supportedPrintQualities.size() == 0) { |
333 | + m_supportedPrintQualities.append(m_defaultPrintQuality); |
334 | + } |
335 | +} |
336 | + |
337 | ColorModel Printer::defaultColorModel() const |
338 | { |
339 | Q_D(const Printer); |
340 | @@ -94,6 +111,18 @@ |
341 | return d->m_supportedColorModels; |
342 | } |
343 | |
344 | +PrintQuality Printer::defaultPrintQuality() const |
345 | +{ |
346 | + Q_D(const Printer); |
347 | + return d->m_defaultPrintQuality; |
348 | +} |
349 | + |
350 | +QList<PrintQuality> Printer::supportedPrintQualities() const |
351 | +{ |
352 | + Q_D(const Printer); |
353 | + return d->m_supportedPrintQualities; |
354 | +} |
355 | + |
356 | QList<PrinterEnum::DuplexMode> Printer::supportedDuplexModes() const |
357 | { |
358 | Q_D(const Printer); |
359 | @@ -137,12 +166,6 @@ |
360 | return d->info->printerName(); |
361 | } |
362 | |
363 | -PrinterEnum::Quality Printer::quality() const |
364 | -{ |
365 | - // FIXME: tmp return a valid quality |
366 | - return PrinterEnum::Quality::NormalQuality; |
367 | -} |
368 | - |
369 | QString Printer::description() const |
370 | { |
371 | Q_D(const Printer); |
372 | @@ -216,7 +239,7 @@ |
373 | return; |
374 | } |
375 | |
376 | - QStringList vals({Utils::colorModelToPpdColorModel(colorModel)}); |
377 | + QStringList vals({colorModel.name}); |
378 | QString reply = d->cups->printerAddOption(name(), "ColorModel", vals); |
379 | Q_UNUSED(reply); |
380 | |
381 | @@ -273,9 +296,22 @@ |
382 | |
383 | } |
384 | |
385 | -void Printer::setQuality(const PrinterEnum::Quality &quality) |
386 | +void Printer::setDefaultPrintQuality(const PrintQuality &quality) |
387 | { |
388 | - |
389 | + Q_D(Printer); |
390 | + |
391 | + if (defaultPrintQuality() == quality) { |
392 | + return; |
393 | + } |
394 | + |
395 | + if (!supportedPrintQualities().contains(quality)) { |
396 | + qWarning() << Q_FUNC_INFO << "quality not supported."; |
397 | + return; |
398 | + } |
399 | + |
400 | + QStringList vals({quality.name}); |
401 | + QString reply = d->cups->printerAddOption(name(), quality.originalOption, vals); |
402 | + d->loadPrintQualities(); |
403 | } |
404 | |
405 | void Printer::setDefaultPageSize(const QPageSize &pageSize) |
406 | |
407 | === modified file 'plugins/Ubuntu/Settings/Printers/printer/printer.h' |
408 | --- plugins/Ubuntu/Settings/Printers/printer/printer.h 2017-01-19 17:59:17 +0000 |
409 | +++ plugins/Ubuntu/Settings/Printers/printer/printer.h 2017-01-20 12:08:10 +0000 |
410 | @@ -45,7 +45,6 @@ |
411 | Q_PROPERTY(QStringList supportedDuplexStrings READ supportedDuplexStrings CONSTANT) |
412 | Q_PROPERTY(PrinterEnum::DuplexMode defaultDuplexMode READ defaultDuplexMode WRITE setDefaultDuplexMode NOTIFY defaultDuplexModeChanged) |
413 | Q_PROPERTY(QString name READ name NOTIFY nameChanged) |
414 | - Q_PROPERTY(PrinterEnum::Quality quality READ quality WRITE setQuality NOTIFY qualityChanged) |
415 | Q_PROPERTY(QString description READ description WRITE setDescription NOTIFY descriptionChanged) |
416 | Q_PROPERTY(QPageSize defaultPageSize READ defaultPageSize WRITE setDefaultPageSize NOTIFY defaultPageSizeChanged) |
417 | Q_PROPERTY(QList<QPageSize> supportedPageSizes READ supportedPageSizes CONSTANT) |
418 | @@ -68,7 +67,8 @@ |
419 | QStringList supportedDuplexStrings() const; |
420 | PrinterEnum::DuplexMode defaultDuplexMode() const; |
421 | QString name() const; |
422 | - PrinterEnum::Quality quality() const; |
423 | + PrintQuality defaultPrintQuality() const; |
424 | + QList<PrintQuality> supportedPrintQualities() const; |
425 | QString description() const; |
426 | QPageSize defaultPageSize() const; |
427 | QList<QPageSize> supportedPageSizes() const; |
428 | @@ -87,7 +87,7 @@ |
429 | void setEnabled(const bool enabled); |
430 | void setErrorPolicy(const PrinterEnum::ErrorPolicy &errorPolicy); |
431 | void setName(const QString &name); |
432 | - void setQuality(const PrinterEnum::Quality &quality); |
433 | + void setDefaultPrintQuality(const PrintQuality &quality); |
434 | void setDefaultPageSize(const QPageSize &pageSize); |
435 | |
436 | public Q_SLOTS: |
437 | |
438 | === modified file 'plugins/Ubuntu/Settings/Printers/printer/printer_p.h' |
439 | --- plugins/Ubuntu/Settings/Printers/printer/printer_p.h 2017-01-17 15:14:25 +0000 |
440 | +++ plugins/Ubuntu/Settings/Printers/printer/printer_p.h 2017-01-20 12:08:10 +0000 |
441 | @@ -25,12 +25,17 @@ |
442 | explicit PrinterPrivate(Printer *q, PrinterInfo *info, CupsFacade *cups); |
443 | ~PrinterPrivate(); |
444 | void loadColorModel(); |
445 | + void loadPrintQualities(); |
446 | |
447 | CupsFacade *cups; |
448 | Printer *q_ptr; |
449 | PrinterInfo *info; |
450 | + |
451 | ColorModel m_defaultColorModel; |
452 | QList<ColorModel> m_supportedColorModels; |
453 | + |
454 | + PrintQuality m_defaultPrintQuality; |
455 | + QList<PrintQuality> m_supportedPrintQualities; |
456 | }; |
457 | |
458 | #endif // USC_PRINTERS_PRINTERPRIVATE_H |
459 | |
460 | === modified file 'plugins/Ubuntu/Settings/Printers/printer/printerjob.cpp' |
461 | --- plugins/Ubuntu/Settings/Printers/printer/printerjob.cpp 2017-01-19 18:15:32 +0000 |
462 | +++ plugins/Ubuntu/Settings/Printers/printer/printerjob.cpp 2017-01-20 12:08:10 +0000 |
463 | @@ -31,7 +31,7 @@ |
464 | , m_printer_name(QStringLiteral("")) |
465 | , m_print_range(QStringLiteral("")) |
466 | , m_print_range_mode(PrinterEnum::PrintRange::AllPages) |
467 | - , m_quality(PrinterEnum::Quality::NormalQuality) |
468 | + , m_quality(0) |
469 | // TODO: Do we need a separate Job state? |
470 | // NotStarted, InQueue, Processing, Complete, Error ? |
471 | , m_state(PrinterEnum::State::IdleState) |
472 | @@ -88,11 +88,20 @@ |
473 | |
474 | ColorModel PrinterJob::getColorModel() const |
475 | { |
476 | + ColorModel ret; |
477 | if (m_printer && colorModel() > -1 && colorModel() < m_printer->supportedColorModels().count()) { |
478 | - return m_printer->supportedColorModels().at(colorModel()); |
479 | - } else { |
480 | - return ColorModel(); |
481 | - } |
482 | + ret = m_printer->supportedColorModels().at(colorModel()); |
483 | + } |
484 | + return ret; |
485 | +} |
486 | + |
487 | +PrintQuality PrinterJob::getPrintQuality() const |
488 | +{ |
489 | + PrintQuality ret; |
490 | + if (m_printer && quality() > -1 && quality() < m_printer->supportedPrintQualities().count()) { |
491 | + ret = m_printer->supportedPrintQualities().at(quality()); |
492 | + } |
493 | + return ret; |
494 | } |
495 | |
496 | PrinterEnum::DuplexMode PrinterJob::getDuplexMode() const |
497 | @@ -115,7 +124,7 @@ |
498 | // Load defaults from printer |
499 | setColorModel(m_printer->supportedColorModels().indexOf(m_printer->defaultColorModel())); |
500 | setDuplexMode(m_printer->supportedDuplexModes().indexOf(m_printer->defaultDuplexMode())); |
501 | - setQuality(m_printer->quality()); |
502 | + setQuality(m_printer->supportedPrintQualities().indexOf(m_printer->defaultPrintQuality())); |
503 | } |
504 | } |
505 | |
506 | @@ -152,7 +161,7 @@ |
507 | return m_print_range_mode; |
508 | } |
509 | |
510 | -PrinterEnum::Quality PrinterJob::quality() const |
511 | +int PrinterJob::quality() const |
512 | { |
513 | return m_quality; |
514 | } |
515 | @@ -261,7 +270,7 @@ |
516 | } |
517 | } |
518 | |
519 | -void PrinterJob::setQuality(const PrinterEnum::Quality &quality) |
520 | +void PrinterJob::setQuality(const int quality) |
521 | { |
522 | if (m_quality != quality) { |
523 | m_quality = quality; |
524 | |
525 | === modified file 'plugins/Ubuntu/Settings/Printers/printer/printerjob.h' |
526 | --- plugins/Ubuntu/Settings/Printers/printer/printerjob.h 2017-01-18 14:35:30 +0000 |
527 | +++ plugins/Ubuntu/Settings/Printers/printer/printerjob.h 2017-01-20 12:08:10 +0000 |
528 | @@ -43,7 +43,7 @@ |
529 | Q_PROPERTY(QString printerName READ printerName WRITE setPrinterName NOTIFY printerNameChanged) |
530 | Q_PROPERTY(QString printRange READ printRange WRITE setPrintRange NOTIFY printRangeChanged) |
531 | Q_PROPERTY(PrinterEnum::PrintRange printRangeMode READ printRangeMode WRITE setPrintRangeMode NOTIFY printRangeModeChanged) |
532 | - Q_PROPERTY(PrinterEnum::Quality quality READ quality WRITE setQuality NOTIFY qualityChanged) |
533 | + Q_PROPERTY(int quality READ quality WRITE setQuality NOTIFY qualityChanged) |
534 | Q_PROPERTY(PrinterEnum::State state READ state NOTIFY stateChanged) |
535 | Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged) |
536 | public: |
537 | @@ -60,13 +60,14 @@ |
538 | QString printerName() const; |
539 | QString printRange() const; |
540 | PrinterEnum::PrintRange printRangeMode() const; |
541 | - PrinterEnum::Quality quality() const; |
542 | + int quality() const; |
543 | PrinterEnum::State state() const; |
544 | QString title() const; |
545 | public Q_SLOTS: |
546 | Q_INVOKABLE void cancel(); |
547 | PrinterEnum::DuplexMode getDuplexMode() const; |
548 | ColorModel getColorModel() const; |
549 | + PrintQuality getPrintQuality() const; |
550 | Q_INVOKABLE void printFile(const QUrl &url); |
551 | void setColorModel(const int colorModel); |
552 | void setCopies(const int copies); |
553 | @@ -76,7 +77,7 @@ |
554 | void setPrinterName(const QString &printerName); |
555 | void setPrintRange(const QString &printRange); |
556 | void setPrintRangeMode(const PrinterEnum::PrintRange printRangeMode); |
557 | - void setQuality(const PrinterEnum::Quality &quality); |
558 | + void setQuality(const int quality); |
559 | void setTitle(const QString &title); |
560 | private Q_SLOTS: |
561 | void loadDefaults(); |
562 | @@ -104,7 +105,7 @@ |
563 | QString m_printer_name; |
564 | QString m_print_range; |
565 | PrinterEnum::PrintRange m_print_range_mode; |
566 | - PrinterEnum::Quality m_quality; |
567 | + int m_quality; |
568 | PrinterEnum::State m_state; |
569 | QString m_title; |
570 | }; |
571 | |
572 | === modified file 'plugins/Ubuntu/Settings/Printers/structs.h' |
573 | --- plugins/Ubuntu/Settings/Printers/structs.h 2017-01-17 16:21:54 +0000 |
574 | +++ plugins/Ubuntu/Settings/Printers/structs.h 2017-01-20 12:08:10 +0000 |
575 | @@ -36,18 +36,12 @@ |
576 | QString text = QString::null; |
577 | PrinterEnum::ColorModelType colorType |
578 | = PrinterEnum::ColorModelType::UnknownType; |
579 | - PrinterEnum::ColorSpace colorSpace |
580 | - = PrinterEnum::ColorSpace::UnknownSpace; |
581 | - PrinterEnum::ColorOrganization colorOrganization |
582 | - = PrinterEnum::ColorOrganization::UnknownOrganization; |
583 | - QString compressionMode = QString::null; |
584 | + |
585 | + QString originalOption = QString::null; |
586 | |
587 | bool operator==(const ColorModel& a) const |
588 | { |
589 | - return (name == a.name && text == a.text && colorType == a.colorType && |
590 | - colorSpace == a.colorSpace && |
591 | - colorOrganization == a.colorOrganization && |
592 | - compressionMode == a.compressionMode); |
593 | + return (name == a.name && originalOption == a.originalOption); |
594 | } |
595 | bool operator!=(const ColorModel& a) const |
596 | { |
597 | @@ -56,16 +50,31 @@ |
598 | void operator=(const ColorModel &m) { |
599 | name = m.name; |
600 | text = m.text; |
601 | - colorType = m.colorType; |
602 | - colorSpace = m.colorSpace; |
603 | - colorOrganization = m.colorOrganization; |
604 | - compressionMode = m.compressionMode; |
605 | + originalOption = m.originalOption; |
606 | + } |
607 | +}; |
608 | + |
609 | +// [1] https://www.cups.org/doc/ppd-compiler.html#COLOR |
610 | + |
611 | +struct PrintQuality |
612 | +{ |
613 | +public: |
614 | + QString name = "Normal"; // TODO: translate |
615 | + QString text = QString::null; |
616 | + |
617 | + // PrintQuality, StpQuality, HPPrintQuality, etc. |
618 | + QString originalOption = QString::null; |
619 | + |
620 | + bool operator==(const PrintQuality& a) const |
621 | + { |
622 | + return (name == a.name && originalOption == a.originalOption); |
623 | } |
624 | }; |
625 | |
626 | Q_DECLARE_TYPEINFO(ColorModel, Q_PRIMITIVE_TYPE); |
627 | Q_DECLARE_METATYPE(ColorModel) |
628 | |
629 | -// [1] https://www.cups.org/doc/ppd-compiler.html#COLOR |
630 | +Q_DECLARE_TYPEINFO(PrintQuality, Q_PRIMITIVE_TYPE); |
631 | +Q_DECLARE_METATYPE(PrintQuality) |
632 | |
633 | #endif // USC_PRINTERS_STRUCTS_H |
634 | |
635 | === modified file 'plugins/Ubuntu/Settings/Printers/utils.h' |
636 | --- plugins/Ubuntu/Settings/Printers/utils.h 2017-01-19 17:59:17 +0000 |
637 | +++ plugins/Ubuntu/Settings/Printers/utils.h 2017-01-20 12:08:10 +0000 |
638 | @@ -76,137 +76,31 @@ |
639 | } |
640 | } |
641 | |
642 | - static PrinterEnum::ColorSpace ppdColorSpaceToColorSpace(const ppd_cs_t &space) |
643 | - { |
644 | - switch (space) { |
645 | - case PPD_CS_CMY: |
646 | - return PrinterEnum::ColorSpace::CMYSpace; |
647 | - case PPD_CS_CMYK: |
648 | - return PrinterEnum::ColorSpace::CMYKSpace; |
649 | - case PPD_CS_GRAY: |
650 | - return PrinterEnum::ColorSpace::GraySpace; |
651 | - case PPD_CS_N: |
652 | - return PrinterEnum::ColorSpace::NSpace; |
653 | - case PPD_CS_RGB: |
654 | - return PrinterEnum::ColorSpace::RGBSpace; |
655 | - case PPD_CS_RGBK: |
656 | - return PrinterEnum::ColorSpace::RGBKSpace; |
657 | - } |
658 | - } |
659 | - |
660 | - /* For information about this method, please see |
661 | - <https://www.cups.org/doc/ref-ppdcfile.html#ColorModel>. */ |
662 | - static ColorModel parsePpdColorModel(const QString &colorModel) |
663 | + static ColorModel parsePpdColorModel(const QString &name, const QString &text, |
664 | + const QString &optionName) |
665 | { |
666 | ColorModel ret; |
667 | - QStringList vals = colorModel.split(" "); |
668 | - |
669 | - if (vals.size() == 1) { |
670 | - if (vals[0].contains("/")) { |
671 | - QStringList nameText = vals[0].split("/"); |
672 | - ret.name = nameText[0]; |
673 | - ret.text = nameText[1]; |
674 | - } else { |
675 | - ret.name = vals[0]; |
676 | - } |
677 | - } |
678 | + ret.name = name; |
679 | + ret.text = text; |
680 | + ret.originalOption = optionName; |
681 | |
682 | if (ret.name.contains("Gray") || ret.name.contains("Black")) { |
683 | ret.colorType = PrinterEnum::ColorModelType::GrayType; |
684 | } else { |
685 | ret.colorType = PrinterEnum::ColorModelType::ColorType; |
686 | } |
687 | - |
688 | - if (vals.size() == 2) { |
689 | - QString s = vals[1].toLower(); |
690 | - if (s == "cmy") ret.colorSpace = PrinterEnum::ColorSpace::CMYSpace; |
691 | - else if (s == "cmyk") ret.colorSpace = PrinterEnum::ColorSpace::CMYKSpace; |
692 | - else if (s == "n") ret.colorSpace = PrinterEnum::ColorSpace::NSpace; |
693 | - else if (s == "rgb") ret.colorSpace = PrinterEnum::ColorSpace::RGBSpace; |
694 | - else if (s == "rgbk") ret.colorSpace = PrinterEnum::ColorSpace::RGBKSpace; |
695 | - else ret.colorSpace = PrinterEnum::ColorSpace::GraySpace; |
696 | - } |
697 | - |
698 | - // ColorOrganization |
699 | - if (vals.size() == 3) { |
700 | - QString o = vals[2].toLower(); |
701 | - PrinterEnum::ColorOrganization org = ret.colorOrganization; |
702 | - if (vals[2] == "chunky") { |
703 | - org = PrinterEnum::ColorOrganization::ChunkyOrganization; |
704 | - } else if (vals[2] == "banded") { |
705 | - org = PrinterEnum::ColorOrganization::BandedOrganization; |
706 | - } else if (vals[3] == "planar") { |
707 | - org = PrinterEnum::ColorOrganization::PlanarOrganization; |
708 | - } |
709 | - ret.colorOrganization = org; |
710 | - } |
711 | - |
712 | - // Compression |
713 | - if (vals.size() == 4) { |
714 | - ret.compressionMode = vals[3]; |
715 | - } |
716 | return ret; |
717 | } |
718 | |
719 | - static QString colorModelToPpdColorModel(const ColorModel &model) |
720 | + static PrintQuality parsePpdPrintQuality(const QString &choice, |
721 | + const QString &text, |
722 | + const QString &optionName) |
723 | { |
724 | - QString nameText = model.name; |
725 | - if (!model.text.isEmpty()) nameText += QString("/%1").arg(model.text); |
726 | - |
727 | - QString colorSpace; |
728 | - if (model.colorSpace != PrinterEnum::ColorSpace::UnknownSpace) { |
729 | - switch (model.colorSpace) { |
730 | - case PrinterEnum::ColorSpace::CMYSpace: |
731 | - colorSpace = "cmy"; |
732 | - break; |
733 | - case PrinterEnum::ColorSpace::CMYKSpace: |
734 | - colorSpace = "cmyk"; |
735 | - break; |
736 | - case PrinterEnum::ColorSpace::NSpace: |
737 | - colorSpace = "n"; |
738 | - break; |
739 | - case PrinterEnum::ColorSpace::RGBSpace: |
740 | - colorSpace = "rgb"; |
741 | - break; |
742 | - case PrinterEnum::ColorSpace::RGBKSpace: |
743 | - colorSpace = "rgbk"; |
744 | - break; |
745 | - case PrinterEnum::ColorSpace::GraySpace: |
746 | - case PrinterEnum::ColorSpace::UnknownSpace: |
747 | - break; |
748 | - } |
749 | - } |
750 | - |
751 | - if (colorSpace.isEmpty()) { |
752 | - return nameText; |
753 | - } |
754 | - |
755 | - QString colorOrg; |
756 | - if (model.colorOrganization != PrinterEnum::ColorOrganization::UnknownOrganization) { |
757 | - switch (model.colorOrganization) { |
758 | - case PrinterEnum::ColorOrganization::ChunkyOrganization: |
759 | - colorOrg = "chunky"; |
760 | - break; |
761 | - case PrinterEnum::ColorOrganization::BandedOrganization: |
762 | - colorOrg = "banded"; |
763 | - break; |
764 | - case PrinterEnum::ColorOrganization::PlanarOrganization: |
765 | - colorOrg = "planar"; |
766 | - break; |
767 | - case PrinterEnum::ColorOrganization::UnknownOrganization: |
768 | - break; |
769 | - } |
770 | - } |
771 | - |
772 | - if (colorOrg.isEmpty()) { |
773 | - return QString("%1 %2").arg(nameText).arg(colorSpace); |
774 | - } |
775 | - |
776 | - if (model.compressionMode.isEmpty()) { |
777 | - return QString("%1 %2 %3").arg(nameText).arg(colorSpace).arg(colorOrg); |
778 | - } |
779 | - |
780 | - return QString("%1 %2 %3 %4").arg(nameText).arg(colorSpace).arg(colorOrg).arg(model.compressionMode); |
781 | + PrintQuality quality; |
782 | + quality.name = choice; |
783 | + quality.text = text; |
784 | + quality.originalOption = optionName; |
785 | + return quality; |
786 | } |
787 | }; |
788 | |
789 | |
790 | === modified file 'tests/unittests/Printers/mockcupsfacade.h' |
791 | --- tests/unittests/Printers/mockcupsfacade.h 2017-01-17 16:21:54 +0000 |
792 | +++ tests/unittests/Printers/mockcupsfacade.h 2017-01-20 12:08:10 +0000 |
793 | @@ -195,6 +195,12 @@ |
794 | return printerOptions[name].value("ColorModels").value<QList<ColorModel>>(); |
795 | } |
796 | |
797 | + virtual QList<PrintQuality> printerGetSupportedQualities( |
798 | + const QString &name) const override |
799 | + { |
800 | + return printerOptions[name].value("PrintQualities").value<QList<PrintQuality>>(); |
801 | + } |
802 | + |
803 | virtual cups_dest_t* makeDest(const QString &name, |
804 | const PrinterJob *options) override |
805 | { |
806 | |
807 | === modified file 'tests/unittests/Printers/tst_printer.cpp' |
808 | --- tests/unittests/Printers/tst_printer.cpp 2017-01-18 16:25:02 +0000 |
809 | +++ tests/unittests/Printers/tst_printer.cpp 2017-01-20 12:08:10 +0000 |
810 | @@ -67,12 +67,12 @@ |
811 | QTest::addColumn<QStringList>("strings"); |
812 | { |
813 | QList<PrinterEnum::DuplexMode> modes({PrinterEnum::DuplexMode::DuplexNone}); |
814 | - QStringList strings({"None"}); |
815 | + QStringList strings({"One Sided"}); |
816 | QTest::newRow("one") << modes << strings; |
817 | } |
818 | { |
819 | QList<PrinterEnum::DuplexMode> modes({PrinterEnum::DuplexMode::DuplexNone, PrinterEnum::DuplexMode::DuplexLongSide}); |
820 | - QStringList strings({"None", "Long edge (standard)"}); |
821 | + QStringList strings({"One Sided", "Long Edge (Standard)"}); |
822 | QTest::newRow("multiple") << modes << strings; |
823 | } |
824 | } |
825 | @@ -164,9 +164,6 @@ |
826 | void testDefaultColorMode() |
827 | { |
828 | ColorModel colorModel; |
829 | - ((MockCupsFacade*) m_mockcups)->printerOptions[m_printerName].insert( |
830 | - "DefaultColorModel", QVariant::fromValue(colorModel)); |
831 | - |
832 | QCOMPARE(m_instance->defaultColorModel(), colorModel); |
833 | } |
834 | void testSupportedColorModels() |
835 | @@ -185,6 +182,27 @@ |
836 | Printer p(info, cups); |
837 | QCOMPARE(p.supportedColorModels(), models); |
838 | } |
839 | + void testDefaultPrintQuality() |
840 | + { |
841 | + PrintQuality quality; |
842 | + QCOMPARE(m_instance->defaultPrintQuality(), quality); |
843 | + } |
844 | + void testSupportedQualities() |
845 | + { |
846 | + PrintQuality a; |
847 | + a.name = "Poor"; |
848 | + |
849 | + PrintQuality b; |
850 | + b.name = "Worse"; |
851 | + QList<PrintQuality> qualities({a, b}); |
852 | + |
853 | + PrinterInfo *info = new MockPrinterInfo(m_printerName); |
854 | + CupsFacade *cups = new MockCupsFacade; |
855 | + ((MockCupsFacade*) cups)->printerOptions[m_printerName].insert( |
856 | + "PrintQualities", QVariant::fromValue(qualities)); |
857 | + Printer p(info, cups); |
858 | + QCOMPARE(p.supportedPrintQualities(), qualities); |
859 | + } |
860 | void testIsDefault_data() |
861 | { |
862 | QTest::addColumn<bool>("isDefault"); |
For my HP printers I don't get any Quality values from them. I had to add "OutputMode" to the list of opts in CupsFacadeImpl: :printerGetSupp ortedQualities. See a grep of my ppd file http:// pastebin. ubuntu. com/23832630/ which shows that OutputMode and DefaultOutputMode should probably be used.