Merge lp:~ahayzen/ubuntu-settings-components/extract-job-attributes into lp:~phablet-team/ubuntu-settings-components/printer-components

Proposed by Andrew Hayzen
Status: Merged
Approved by: Jonas G. Drange
Approved revision: 230
Merged at revision: 229
Proposed branch: lp:~ahayzen/ubuntu-settings-components/extract-job-attributes
Merge into: lp:~phablet-team/ubuntu-settings-components/printer-components
Diff against target: 873 lines (+513/-11)
10 files modified
examples/PrinterQueue.qml (+5/-0)
plugins/Ubuntu/Settings/Printers/backend/backend_cups.cpp (+80/-4)
plugins/Ubuntu/Settings/Printers/cups/cupsfacade.cpp (+85/-0)
plugins/Ubuntu/Settings/Printers/cups/cupsfacade.h (+1/-0)
plugins/Ubuntu/Settings/Printers/cups/cupspkhelper.cpp (+120/-2)
plugins/Ubuntu/Settings/Printers/cups/cupspkhelper.h (+3/-0)
plugins/Ubuntu/Settings/Printers/models/jobmodel.cpp (+78/-0)
plugins/Ubuntu/Settings/Printers/models/jobmodel.h (+15/-0)
plugins/Ubuntu/Settings/Printers/printer/printerjob.cpp (+94/-4)
plugins/Ubuntu/Settings/Printers/printer/printerjob.h (+32/-1)
To merge this branch: bzr merge lp:~ahayzen/ubuntu-settings-components/extract-job-attributes
Reviewer Review Type Date Requested Status
Jonas G. Drange (community) Approve
Review via email: mp+316563@code.launchpad.net

Commit message

* Expose many more properties of PrinterJob to the JobModel
* Load PrinterJob properties from the ipp job attributes when loading for the JobModel

Description of the change

* Expose many more properties of PrinterJob to the JobModel
* Load PrinterJob properties from the ipp job attributes when loading for the JobModel

To post a comment you must log in.
Revision history for this message
Jonas G. Drange (jonas-drange) wrote :

Looks good, thanks! One small comment.

review: Approve
230. By Andrew Hayzen

* Fix missing READ in Q_PROPERTY

Revision history for this message
Andrew Hayzen (ahayzen) wrote :

Good catch, fixed the issue now :-)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'examples/PrinterQueue.qml'
2--- examples/PrinterQueue.qml 2017-02-02 17:22:55 +0000
3+++ examples/PrinterQueue.qml 2017-02-07 14:30:05 +0000
4@@ -51,6 +51,11 @@
5 id: modelLayout
6 title.text: displayName
7 subtitle.text: "Job: " + model.id + " State: " + model.state
8+ + " Color: " + model.colorModel + " CreationTime: "
9+ + model.creationTime + " PageRange: "
10+ + model.printRange + " Messages: " + model.messages;
11+ subtitle.wrapMode: Text.WrapAtWordBoundaryOrAnywhere
12+ subtitle.maximumLineCount: 3
13 }
14 onClicked: {
15 console.debug("Cancel:", printer.name, model.id);
16
17=== modified file 'plugins/Ubuntu/Settings/Printers/backend/backend_cups.cpp'
18--- plugins/Ubuntu/Settings/Printers/backend/backend_cups.cpp 2017-02-06 13:58:14 +0000
19+++ plugins/Ubuntu/Settings/Printers/backend/backend_cups.cpp 2017-02-07 14:30:05 +0000
20@@ -20,6 +20,8 @@
21 #include "utils.h"
22
23 #include <QDBusConnection>
24+#include <QLocale>
25+#include <QTimeZone>
26
27 PrinterCupsBackend::PrinterCupsBackend(QObject *parent)
28 : PrinterCupsBackend(new CupsFacade(), QPrinterInfo(),
29@@ -276,12 +278,86 @@
30 QList<QSharedPointer<PrinterJob>> list;
31
32 Q_FOREACH(auto job, jobs) {
33- auto newJob = QSharedPointer<PrinterJob>(new PrinterJob(name, this, job->id));
34-
35- // TODO: needs to extract other properties like copies/duplex etc
36-
37+ QSharedPointer<PrinterJob> newJob = QSharedPointer<PrinterJob>(new PrinterJob(name, this, job->id));
38+
39+ // Extract the times
40+ QDateTime completedTime;
41+ completedTime.setTimeZone(QTimeZone::systemTimeZone());
42+ completedTime.setTime_t(job->completed_time);
43+
44+ QDateTime creationTime;
45+ creationTime.setTimeZone(QTimeZone::systemTimeZone());
46+ creationTime.setTime_t(job->creation_time);
47+
48+ QDateTime processingTime;
49+ processingTime.setTimeZone(QTimeZone::systemTimeZone());
50+ processingTime.setTime_t(job->processing_time);
51+
52+ // Load the information from the cups struct
53+ newJob->setCompletedTime(completedTime);
54+ newJob->setCreationTime(creationTime);
55+ newJob->setProcessingTime(processingTime);
56+ newJob->setSize(job->size);
57 newJob->setState(static_cast<PrinterEnum::JobState>(job->state));
58 newJob->setTitle(QString::fromLocal8Bit(job->title));
59+ newJob->setUser(QString::fromLocal8Bit(job->user));
60+
61+ // Load the extra attributes for the job
62+ // NOTE: we don't need to type check them as they have been filtered for us
63+ QMap<QString, QVariant> attributes = m_cups->printerGetJobAttributes(name, job->id);
64+
65+ newJob->setCollate(attributes.value("Collate").toBool());
66+ newJob->setCopies(attributes.value("copies").toInt());
67+
68+ // No colorModel will result in PrinterJob using defaultColorModel
69+ if (!newJob->printer()) {
70+ QString colorModel = attributes.value("ColorModel").toString();
71+
72+ for (int i=0; i < newJob->printer()->supportedColorModels().length(); i++) {
73+ if (newJob->printer()->supportedColorModels().at(i).originalOption == colorModel) {
74+ newJob->setColorModel(i);
75+ }
76+ }
77+ }
78+
79+ // No duplexMode will result in PrinterJob using defaultDuplexMode
80+ if (!newJob->printer()) {
81+ QString duplex = attributes.value("Duplex").toString();
82+ PrinterEnum::DuplexMode duplexMode = Utils::ppdChoiceToDuplexMode(duplex);
83+
84+ for (int i=0; i < newJob->printer()->supportedDuplexModes().length(); i++) {
85+ if (newJob->printer()->supportedDuplexModes().at(i) == duplexMode) {
86+ newJob->setDuplexMode(i);
87+ }
88+ }
89+ }
90+
91+ newJob->setLandscape(attributes.value("landscape").toBool());
92+ newJob->setMessages(attributes.value("messages").toStringList());
93+
94+ QStringList pageRanges = attributes.value("page-ranges").toStringList();
95+
96+ if (pageRanges.isEmpty()) {
97+ newJob->setPrintRangeMode(PrinterEnum::PrintRange::AllPages);
98+ newJob->setPrintRange(QStringLiteral(""));
99+ } else {
100+ newJob->setPrintRangeMode(PrinterEnum::PrintRange::PageRange);
101+ // Use groupSeparator as createSeparatedList adds "and" into the string
102+ newJob->setPrintRange(pageRanges.join(QLocale::system().groupSeparator()));
103+ }
104+
105+ // No quality will result in PrinterJob using defaultPrintQuality
106+ if (!newJob->printer()) {
107+ QString quality = attributes.value("quality").toString();
108+
109+ for (int i=0; i < newJob->printer()->supportedPrintQualities().length(); i++) {
110+ if (newJob->printer()->supportedPrintQualities().at(i).name == quality) {
111+ newJob->setQuality(i);
112+ }
113+ }
114+ }
115+
116+ newJob->setReverse(attributes.value("OutputOrder").toString() == "Reverse");
117
118 list.append(newJob);
119 }
120
121=== modified file 'plugins/Ubuntu/Settings/Printers/cups/cupsfacade.cpp'
122--- plugins/Ubuntu/Settings/Printers/cups/cupsfacade.cpp 2017-02-03 12:04:46 +0000
123+++ plugins/Ubuntu/Settings/Printers/cups/cupsfacade.cpp 2017-02-07 14:30:05 +0000
124@@ -28,6 +28,9 @@
125 #define __CUPS_ADD_OPTION(dest, name, value) dest->num_options = \
126 cupsAddOption(name, value, dest->num_options, &dest->options);
127
128+#define __CUPS_ATTR_EXISTS(map, attr, type) map.contains(attr) \
129+ && map.value(attr).canConvert<type>()
130+
131 CupsFacade::CupsFacade(QObject *parent) : QObject(parent)
132 {
133 }
134@@ -394,6 +397,88 @@
135 return list;
136 }
137
138+QMap<QString, QVariant> CupsFacade::printerGetJobAttributes(const QString &name, const int jobId)
139+{
140+ Q_UNUSED(name);
141+ QMap<QString, QVariant> rawMap = helper.printerGetJobAttributes(jobId);
142+ QMap<QString, QVariant> map;
143+
144+ // Filter attributes to know values
145+ // Do this here so we can use things such as m_knownQualityOptions
146+
147+ if (__CUPS_ATTR_EXISTS(rawMap, "Collate", bool)) {
148+ map.insert("Collate", rawMap.value("Collate"));
149+ } else {
150+ map.insert("Collate", QVariant(true));
151+ }
152+
153+ if (__CUPS_ATTR_EXISTS(rawMap, "copies", int)) {
154+ map.insert("copies", rawMap.value("copies"));
155+ } else {
156+ map.insert("copies", QVariant(1));
157+ }
158+
159+ if (__CUPS_ATTR_EXISTS(rawMap, "ColorModel", QString)) {
160+ map.insert("ColorModel", rawMap.value("ColorModel"));
161+ } else {
162+ map.insert("ColorModel", QVariant(""));
163+ }
164+
165+ if (__CUPS_ATTR_EXISTS(rawMap, "Duplex", QString)) {
166+ map.insert("Duplex", rawMap.value("Duplex"));
167+ } else {
168+ map.insert("Duplex", QVariant(""));
169+ }
170+
171+ if (__CUPS_ATTR_EXISTS(rawMap, "landscape", bool)) {
172+ map.insert("landscape", rawMap.value("landscape"));
173+ } else {
174+ map.insert("landscape", QVariant(false));
175+ }
176+
177+ if (__CUPS_ATTR_EXISTS(rawMap, "page-ranges", QList<QVariant>)) {
178+ QList<QVariant> range = rawMap.value("page-ranges").toList();
179+ QStringList rangeStrings;
180+
181+ Q_FOREACH(QVariant var, range) {
182+ rangeStrings << var.toString();
183+ }
184+
185+ map.insert("page-ranges", QVariant(rangeStrings));
186+ } else {
187+ map.insert("page-ranges", QVariant(QStringList()));
188+ }
189+
190+ Q_FOREACH(QString qualityOption, m_knownQualityOptions) {
191+ if (rawMap.contains(qualityOption)
192+ && rawMap.value(qualityOption).canConvert<QString>()) {
193+ map.insert("quality", rawMap.value(qualityOption).toString());
194+ }
195+ }
196+
197+ if (!map.contains("quality")) {
198+ map.insert("quality", QVariant(""));
199+ }
200+
201+ if (__CUPS_ATTR_EXISTS(rawMap, "OutputOrder", QString)) {
202+ map.insert("OutputOrder", rawMap.value("OutputOrder"));
203+ } else {
204+ map.insert("OutputOrder", "Normal");
205+ }
206+
207+ // Generate a list of messages
208+ // TODO: for now just using job-printer-state-message, are there others?
209+ QStringList messages;
210+
211+ if (__CUPS_ATTR_EXISTS(rawMap, "job-printer-state-message", QString)) {
212+ messages << rawMap.value("job-printer-state-message").toString();
213+ }
214+
215+ map.insert("messages", QVariant(messages));
216+
217+ return map;
218+}
219+
220 int CupsFacade::printFileToDest(const QString &filepath, const QString &title,
221 const cups_dest_t *dest)
222 {
223
224=== modified file 'plugins/Ubuntu/Settings/Printers/cups/cupsfacade.h'
225--- plugins/Ubuntu/Settings/Printers/cups/cupsfacade.h 2017-02-03 12:04:46 +0000
226+++ plugins/Ubuntu/Settings/Printers/cups/cupsfacade.h 2017-02-07 14:30:05 +0000
227@@ -90,6 +90,7 @@
228
229 void cancelJob(const QString &name, const int jobId);
230 QList<cups_job_t *> printerGetJobs(const QString &name);
231+ QMap<QString, QVariant> printerGetJobAttributes(const QString &name, const int jobId);
232 int printFileToDest(const QString &filepath, const QString &title,
233 const cups_dest_t *dest);
234 int createSubscription();
235
236=== modified file 'plugins/Ubuntu/Settings/Printers/cups/cupspkhelper.cpp'
237--- plugins/Ubuntu/Settings/Printers/cups/cupspkhelper.cpp 2017-02-06 13:58:14 +0000
238+++ plugins/Ubuntu/Settings/Printers/cups/cupspkhelper.cpp 2017-02-07 14:30:05 +0000
239@@ -1,7 +1,7 @@
240 /*
241 * Copyright (C) 2017 Canonical, Ltd.
242 * Copyright (C) 2014 John Layt <jlayt@kde.org>
243- * Copyright (C) 2009 Red Hat, Inc.
244+ * Copyright (C) 2002, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2013, 2014 Red Hat, Inc.
245 * Copyright (C) 2008 Novell, Inc.
246 *
247 * This program is free software; you can redistribute it and/or modify
248@@ -23,8 +23,10 @@
249 #include <string.h>
250 #include <unistd.h>
251
252+#include <QDebug>
253+#include <QDateTime>
254+#include <QTimeZone>
255 #include <QUrl>
256-#include <QDebug>
257
258 CupsPkHelper::CupsPkHelper()
259 : m_connection(httpConnectEncrypt(cupsServer(),
260@@ -275,6 +277,46 @@
261 return retval;
262 }
263
264+QMap<QString, QVariant> CupsPkHelper::printerGetJobAttributes(const int jobId)
265+{
266+ ipp_t *request;
267+ QMap<QString, QVariant> map;
268+
269+ // Construct request
270+ request = ippNewRequest(IPP_GET_JOB_ATTRIBUTES);
271+ QString uri = QStringLiteral("ipp://localhost/jobs/") + QString::number(jobId);
272+ qDebug() << "URI:" << uri;
273+
274+ ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, uri.toStdString().data());
275+
276+
277+ // Send request and construct reply
278+ ipp_t *reply;
279+ const QString resourceChar = getResource(CphResourceRoot);
280+ reply = cupsDoRequest(m_connection, request,
281+ resourceChar.toUtf8());
282+
283+ // Check if the reply is OK
284+ if (isReplyOk(reply, false)) {
285+ // Loop through the attributes
286+ ipp_attribute_t *attr;
287+
288+ for (attr = ippFirstAttribute(reply); attr; attr = ippNextAttribute(reply)) {
289+ QVariant value = getAttributeValue(attr);
290+ map.insert(ippGetName(attr), value);
291+ }
292+ } else {
293+ qWarning() << "Not able to get attributes of job:" << jobId;
294+ }
295+
296+ // Destruct the reply if valid
297+ if (reply) {
298+ ippDelete(reply);
299+ }
300+
301+ return map;
302+}
303+
304
305 /* This function sets given options to specified values in file 'ppdfile'.
306 * This needs to be done because of applications which use content of PPD files
307@@ -798,3 +840,79 @@
308
309 ippDelete(resp);
310 }
311+
312+QVariant CupsPkHelper::getAttributeValue(ipp_attribute_t *attr, int index) const
313+{
314+ QVariant var;
315+
316+ if (ippGetCount(attr) > 1 && index < 0) {
317+ QList<QVariant> list;
318+
319+ for (int i=0; i < ippGetCount(attr); i++) {
320+ list.append(getAttributeValue(attr, i));
321+ }
322+
323+ var = QVariant::fromValue<QList<QVariant>>(list);
324+ } else {
325+ if (index == -1) {
326+ index = 0;
327+ }
328+
329+ switch (ippGetValueTag(attr)) {
330+ case IPP_TAG_NAME:
331+ case IPP_TAG_TEXT:
332+ case IPP_TAG_KEYWORD:
333+ case IPP_TAG_URI:
334+ case IPP_TAG_CHARSET:
335+ case IPP_TAG_MIMETYPE:
336+ case IPP_TAG_LANGUAGE:
337+ var = QVariant::fromValue<QString>(ippGetString(attr, index, NULL));
338+ break;
339+ case IPP_TAG_INTEGER:
340+ case IPP_TAG_ENUM:
341+ var = QVariant::fromValue<int>(ippGetInteger(attr, index));
342+ break;
343+ case IPP_TAG_BOOLEAN:
344+ var = QVariant::fromValue<bool>(ippGetBoolean(attr, index));
345+ break;
346+ case IPP_TAG_RANGE: {
347+ QString range;
348+ int upper;
349+ int lower = ippGetRange(attr, index, &upper);
350+
351+ // Build a string similar to "1-3" "5-" "8" "-4"
352+ if (lower != INT_MIN) {
353+ range += QString::number(lower);
354+ }
355+
356+ if (lower != upper) {
357+ range += QStringLiteral("-");
358+
359+ if (upper != INT_MAX) {
360+ range += QString::number(upper);
361+ }
362+ }
363+
364+ var = QVariant(range);
365+ break;
366+ }
367+ case IPP_TAG_NOVALUE:
368+ var = QVariant();
369+ break;
370+ case IPP_TAG_DATE: {
371+ time_t time = ippDateToTime(ippGetDate(attr, index));
372+ QDateTime datetime;
373+ datetime.setTimeZone(QTimeZone::systemTimeZone());
374+ datetime.setTime_t(time);
375+
376+ var = QVariant::fromValue<QDateTime>(datetime);
377+ break;
378+ }
379+ default:
380+ qWarning() << "Unknown IPP value tab 0x" << ippGetValueTag(attr);
381+ break;
382+ }
383+ }
384+
385+ return var;
386+}
387
388=== modified file 'plugins/Ubuntu/Settings/Printers/cups/cupspkhelper.h'
389--- plugins/Ubuntu/Settings/Printers/cups/cupspkhelper.h 2017-02-02 22:52:19 +0000
390+++ plugins/Ubuntu/Settings/Printers/cups/cupspkhelper.h 2017-02-07 14:30:05 +0000
391@@ -62,6 +62,8 @@
392 ppd_file_t* getPpdFile(const QString &name, const QString &instance) const;
393 cups_dest_t* getDest(const QString &name, const QString &instance) const;
394
395+ QMap<QString, QVariant> printerGetJobAttributes(const int jobId);
396+
397 QString getLastError() const;
398
399 // This response needs to be free by the caller.
400@@ -110,6 +112,7 @@
401 bool handleReply(ipp_t *reply);
402 bool isReplyOk(ipp_t *reply, bool deleteIfReplyNotOk);
403 void setErrorFromReply(ipp_t *reply);
404+ QVariant getAttributeValue(ipp_attribute_t *attr, int index=-1) const;
405
406 http_t *m_connection;
407 ipp_status_t m_lastStatus = IPP_OK;
408
409=== modified file 'plugins/Ubuntu/Settings/Printers/models/jobmodel.cpp'
410--- plugins/Ubuntu/Settings/Printers/models/jobmodel.cpp 2017-02-03 16:34:49 +0000
411+++ plugins/Ubuntu/Settings/Printers/models/jobmodel.cpp 2017-02-07 14:30:05 +0000
412@@ -175,12 +175,72 @@
413 auto job = m_jobs[index.row()];
414
415 switch (role) {
416+ case CollateRole:
417+ ret = job->collate();
418+ break;
419+ case ColorModelRole: {
420+ if (job->printer()) {
421+ ret = job->printer()->supportedColorModels().at(job->colorModel()).text;
422+ } else {
423+ qWarning() << "Printer is undefined, no colorModel";
424+ ret = "";
425+ }
426+ break;
427+ }
428+ case CompletedTimeRole:
429+ ret = job->completedTime().toString(QLocale::system().dateTimeFormat());
430+ break;
431+ case CopiesRole:
432+ ret = job->copies();
433+ break;
434+ case CreationTimeRole:
435+ ret = job->creationTime().toString(QLocale::system().dateTimeFormat());
436+ break;
437+ case DuplexRole: {
438+ if (job->printer()) {
439+ ret = job->printer()->supportedDuplexStrings().at(job->duplexMode());
440+ } else {
441+ qWarning() << "Printer is undefined, no duplexMode";
442+ ret = "";
443+ }
444+ break;
445+ }
446 case IdRole:
447 ret = job->jobId();
448 break;
449+ case LandscapeRole:
450+ ret = job->landscape();
451+ break;
452+ case MessagesRole:
453+ ret = job->messages();
454+ break;
455 case OwnerRole:
456 ret = m_printer_name;
457 break;
458+ case PrintRangeRole:
459+ ret = job->printRange();
460+ break;
461+ case PrintRangeModeRole:
462+ ret = QVariant::fromValue<PrinterEnum::PrintRange>(job->printRangeMode());
463+ break;
464+ case ProcessingTimeRole:
465+ ret = job->processingTime().toString(QLocale::system().dateTimeFormat());
466+ break;
467+ case QualityRole: {
468+ if (job->printer()) {
469+ ret = job->printer()->supportedPrintQualities().at(job->quality()).text;
470+ } else {
471+ qWarning() << "Printer is undefined, no quality";
472+ ret = "";
473+ }
474+ break;
475+ }
476+ case ReverseRole:
477+ ret = job->reverse();
478+ break;
479+ case SizeRole:
480+ ret = job->size();
481+ break;
482 case StateRole:
483 // TODO: improve, for now have a switch
484 switch (job->state()) {
485@@ -211,6 +271,9 @@
486 case TitleRole:
487 ret = job->title();
488 break;
489+ case UserRole:
490+ ret = job->user();
491+ break;
492 }
493 }
494
495@@ -224,9 +287,24 @@
496 if (Q_UNLIKELY(names.empty())) {
497 names[Qt::DisplayRole] = "displayName";
498 names[IdRole] = "id";
499+ names[CollateRole] = "collate";
500+ names[ColorModelRole] = "colorModel";
501+ names[CompletedTimeRole] = "completedTime";
502+ names[CopiesRole] = "copies";
503+ names[CreationTimeRole] = "creationTime";
504+ names[DuplexRole] = "duplexMode";
505+ names[LandscapeRole] = "landscape";
506+ names[MessagesRole] = "messages";
507 names[OwnerRole] = "owner";
508+ names[PrintRangeRole] = "printRange";
509+ names[PrintRangeModeRole] = "printRangeMode";
510+ names[ProcessingTimeRole] = "processingTime";
511+ names[QualityRole] = "quality";
512+ names[ReverseRole] = "reverse";
513+ names[SizeRole] = "size";
514 names[StateRole] = "state";
515 names[TitleRole] = "title";
516+ names[UserRole] = "user";
517 names[LastStateMessageRole] = "lastStateMessage";
518 }
519
520
521=== modified file 'plugins/Ubuntu/Settings/Printers/models/jobmodel.h'
522--- plugins/Ubuntu/Settings/Printers/models/jobmodel.h 2017-02-03 16:34:49 +0000
523+++ plugins/Ubuntu/Settings/Printers/models/jobmodel.h 2017-02-07 14:30:05 +0000
524@@ -44,9 +44,24 @@
525 {
526 // Qt::DisplayRole holds job title
527 IdRole = Qt::UserRole,
528+ CollateRole,
529+ ColorModelRole,
530+ CompletedTimeRole,
531+ CopiesRole,
532+ CreationTimeRole,
533+ DuplexRole,
534+ LandscapeRole,
535 OwnerRole,
536+ MessagesRole,
537+ PrintRangeRole,
538+ PrintRangeModeRole,
539+ ProcessingTimeRole,
540+ QualityRole,
541+ ReverseRole,
542+ SizeRole,
543 StateRole,
544 TitleRole,
545+ UserRole,
546 LastStateMessageRole,
547 LastRole = LastStateMessageRole,
548 };
549
550=== modified file 'plugins/Ubuntu/Settings/Printers/printer/printerjob.cpp'
551--- plugins/Ubuntu/Settings/Printers/printer/printerjob.cpp 2017-02-06 13:58:14 +0000
552+++ plugins/Ubuntu/Settings/Printers/printer/printerjob.cpp 2017-02-07 14:30:05 +0000
553@@ -36,19 +36,25 @@
554 : QObject(parent)
555 , m_collate(true)
556 , m_color_model(0)
557+ , m_completed_time(QDateTime())
558 , m_copies(1)
559+ , m_creation_time(QDateTime())
560 , m_backend(backend)
561 , m_duplex_mode(0)
562 , m_is_two_sided(false)
563 , m_job_id(-1)
564+ , m_messages(QStringList())
565 , m_printer(printer)
566 , m_printer_name(QStringLiteral(""))
567 , m_print_range(QStringLiteral(""))
568 , m_print_range_mode(PrinterEnum::PrintRange::AllPages)
569+ , m_processing_time(QDateTime())
570 , m_quality(0)
571 , m_reverse(false)
572+ , m_size(0)
573 , m_state(PrinterEnum::JobState::Pending)
574 , m_title(QStringLiteral(""))
575+ , m_user("")
576 {
577 if (m_printer) {
578 m_printer_name = printer->name();
579@@ -88,11 +94,21 @@
580 return getColorModel().colorType;
581 }
582
583+QDateTime PrinterJob::completedTime() const
584+{
585+ return m_completed_time;
586+}
587+
588 int PrinterJob::copies() const
589 {
590 return m_copies;
591 }
592
593+QDateTime PrinterJob::creationTime() const
594+{
595+ return m_creation_time;
596+}
597+
598 int PrinterJob::duplexMode() const
599 {
600 return m_duplex_mode;
601@@ -150,10 +166,15 @@
602 }
603 }
604
605-//Printer *PrinterJob::printer() const
606-//{
607-// return m_printer;
608-//}
609+QStringList PrinterJob::messages() const
610+{
611+ return m_messages;
612+}
613+
614+Printer *PrinterJob::printer() const
615+{
616+ return m_printer;
617+}
618
619 QString PrinterJob::printerName() const
620 {
621@@ -179,6 +200,11 @@
622 return m_print_range_mode;
623 }
624
625+QDateTime PrinterJob::processingTime() const
626+{
627+ return m_processing_time;
628+}
629+
630 int PrinterJob::quality() const
631 {
632 return m_quality;
633@@ -189,6 +215,11 @@
634 return m_reverse;
635 }
636
637+int PrinterJob::size() const
638+{
639+ return m_size;
640+}
641+
642 PrinterEnum::JobState PrinterJob::state() const
643 {
644 return m_state;
645@@ -218,6 +249,15 @@
646 Q_EMIT colorModelTypeChanged();
647 }
648
649+void PrinterJob::setCompletedTime(const QDateTime &completedTime)
650+{
651+ if (m_completed_time != completedTime) {
652+ m_completed_time = completedTime;
653+
654+ Q_EMIT completedTimeChanged();
655+ }
656+}
657+
658 void PrinterJob::setCopies(const int copies)
659 {
660 if (m_copies != copies) {
661@@ -231,6 +271,15 @@
662 }
663 }
664
665+void PrinterJob::setCreationTime(const QDateTime &creationTime)
666+{
667+ if (m_creation_time != creationTime) {
668+ m_creation_time = creationTime;
669+
670+ Q_EMIT creationTimeChanged();
671+ }
672+}
673+
674 void PrinterJob::setDuplexMode(const int duplexMode)
675 {
676 if (m_duplex_mode != duplexMode) {
677@@ -262,6 +311,15 @@
678 }
679 }
680
681+void PrinterJob::setMessages(const QStringList &messages)
682+{
683+ if (m_messages != messages) {
684+ m_messages = messages;
685+
686+ Q_EMIT messagesChanged();
687+ }
688+}
689+
690 //void PrinterJob::setPrinter(Printer *printer)
691 //{
692 // qDebug() << "Attempting to set printer!" << printer;
693@@ -309,6 +367,15 @@
694 }
695 }
696
697+void PrinterJob::setProcessingTime(const QDateTime &processingTime)
698+{
699+ if (m_processing_time != processingTime) {
700+ m_processing_time = processingTime;
701+
702+ Q_EMIT processingTimeChanged();
703+ }
704+}
705+
706 void PrinterJob::setQuality(const int quality)
707 {
708 if (m_quality != quality) {
709@@ -327,6 +394,15 @@
710 }
711 }
712
713+void PrinterJob::setSize(const int size)
714+{
715+ if (m_size != size) {
716+ m_size = size;
717+
718+ Q_EMIT sizeChanged();
719+ }
720+}
721+
722 void PrinterJob::setState(const PrinterEnum::JobState &state)
723 {
724 if (m_state != state) {
725@@ -345,6 +421,15 @@
726 }
727 }
728
729+void PrinterJob::setUser(const QString &user)
730+{
731+ if (m_user != user) {
732+ m_user = user;
733+
734+ Q_EMIT userChanged();
735+ }
736+}
737+
738 QString PrinterJob::title() const
739 {
740 return m_title;
741@@ -386,3 +471,8 @@
742 setState(newPrinterJob->state());
743 setTitle(newPrinterJob->title());
744 }
745+
746+QString PrinterJob::user() const
747+{
748+ return m_user;
749+}
750
751=== modified file 'plugins/Ubuntu/Settings/Printers/printer/printerjob.h'
752--- plugins/Ubuntu/Settings/Printers/printer/printerjob.h 2017-02-03 14:43:41 +0000
753+++ plugins/Ubuntu/Settings/Printers/printer/printerjob.h 2017-02-07 14:30:05 +0000
754@@ -25,6 +25,7 @@
755 #include "backend/backend.h"
756 #include "printer/printer.h"
757
758+#include <QtCore/QDateTime>
759 #include <QtCore/QObject>
760
761 class Printer;
762@@ -37,18 +38,24 @@
763 Q_PROPERTY(bool collate READ collate WRITE setCollate NOTIFY collateChanged)
764 Q_PROPERTY(int colorModel READ colorModel WRITE setColorModel NOTIFY colorModelChanged)
765 Q_PROPERTY(PrinterEnum::ColorModelType colorModelType READ colorModelType NOTIFY colorModelTypeChanged)
766+ Q_PROPERTY(QDateTime completedTime READ completedTime NOTIFY completedTimeChanged)
767 Q_PROPERTY(int copies READ copies WRITE setCopies NOTIFY copiesChanged)
768+ Q_PROPERTY(QDateTime creationTime READ creationTime NOTIFY creationTimeChanged)
769 Q_PROPERTY(int duplexMode READ duplexMode WRITE setDuplexMode NOTIFY duplexModeChanged)
770 Q_PROPERTY(bool isTwoSided READ isTwoSided NOTIFY isTwoSidedChanged)
771 Q_PROPERTY(bool landscape READ landscape WRITE setLandscape NOTIFY landscapeChanged)
772+ Q_PROPERTY(QStringList messages READ messages NOTIFY messagesChanged)
773 // Q_PROPERTY(Printer *printer READ printer WRITE setPrinter NOTIFY printerChanged)
774 Q_PROPERTY(QString printerName READ printerName WRITE setPrinterName NOTIFY printerNameChanged)
775 Q_PROPERTY(QString printRange READ printRange WRITE setPrintRange NOTIFY printRangeChanged)
776 Q_PROPERTY(PrinterEnum::PrintRange printRangeMode READ printRangeMode WRITE setPrintRangeMode NOTIFY printRangeModeChanged)
777+ Q_PROPERTY(QDateTime processingTime READ processingTime NOTIFY processingTimeChanged)
778 Q_PROPERTY(int quality READ quality WRITE setQuality NOTIFY qualityChanged)
779 Q_PROPERTY(bool reverse READ reverse WRITE setReverse NOTIFY reverseChanged)
780+ Q_PROPERTY(int size READ size NOTIFY sizeChanged)
781 Q_PROPERTY(PrinterEnum::JobState state READ state NOTIFY stateChanged)
782 Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged)
783+ Q_PROPERTY(QString user READ user NOTIFY userChanged)
784
785 friend class PrinterCupsBackend;
786 public:
787@@ -62,19 +69,25 @@
788 bool collate() const;
789 int colorModel() const;
790 PrinterEnum::ColorModelType colorModelType() const;
791+ QDateTime completedTime() const;
792 int copies() const;
793+ QDateTime creationTime() const;
794 int duplexMode() const;
795 bool isTwoSided() const;
796 int jobId() const; // TODO: implement
797 bool landscape() const;
798-// Printer *printer() const;
799+ QStringList messages() const;
800+ Printer* printer() const;
801 QString printerName() const;
802 QString printRange() const;
803 PrinterEnum::PrintRange printRangeMode() const;
804+ QDateTime processingTime() const;
805 int quality() const;
806 bool reverse() const;
807+ int size() const;
808 PrinterEnum::JobState state() const;
809 QString title() const;
810+ QString user() const;
811
812 bool deepCompare(QSharedPointer<PrinterJob> other) const;
813 public Q_SLOTS:
814@@ -98,41 +111,59 @@
815 void updateFrom(QSharedPointer<PrinterJob> newPrinterJob);
816 private Q_SLOTS:
817 void loadDefaults();
818+ void setCompletedTime(const QDateTime &completedTime);
819+ void setCreationTime(const QDateTime &creationTime);
820 void setIsTwoSided(const bool isTwoSided);
821+ void setMessages(const QStringList &messages);
822+ void setProcessingTime(const QDateTime &processingTime);
823+ void setSize(const int size);
824 void setState(const PrinterEnum::JobState &state);
825+ void setUser(const QString &user);
826 Q_SIGNALS:
827 void collateChanged();
828 void colorModelChanged();
829 void colorModelTypeChanged();
830+ void completedTimeChanged();
831 void copiesChanged();
832+ void creationTimeChanged();
833 void duplexModeChanged();
834 void isTwoSidedChanged();
835 void landscapeChanged();
836+ void messagesChanged();
837 // void printerChanged();
838 void printerNameChanged();
839 void printRangeChanged();
840 void printRangeModeChanged();
841+ void processingTimeChanged();
842 void qualityChanged();
843 void reverseChanged();
844+ void sizeChanged();
845 void stateChanged();
846 void titleChanged();
847+ void userChanged();
848 private:
849 bool m_collate;
850 int m_color_model;
851+ QDateTime m_completed_time;
852 int m_copies;
853+ QDateTime m_creation_time;
854 PrinterBackend *m_backend; // TODO: Maybe use the printer's backend?
855 int m_duplex_mode;
856 bool m_is_two_sided;
857 int m_job_id;
858 bool m_landscape;
859+ QStringList m_messages;
860 Printer *m_printer;
861 QString m_printer_name;
862 QString m_print_range;
863 PrinterEnum::PrintRange m_print_range_mode;
864+ QDateTime m_processing_time;
865 int m_quality;
866 bool m_reverse;
867+ int m_size;
868 PrinterEnum::JobState m_state;
869 QString m_title;
870+ QString m_user;
871 };
872
873 #endif // USC_PRINTERS_PRINTERJOB_H

Subscribers

People subscribed via source and target branches