Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qcupsjobwidget.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5
7
8#include <QCheckBox>
9#include <QDateTime>
10#include <QFontDatabase>
11#include <QLabel>
12#include <QLayout>
13#include <QTime>
14#include <QTableWidget>
15#include <QTableWidgetItem>
16#include <QHeaderView>
17#include <QPrinter>
18#include <QPrintEngine>
19
20#include <kernel/qprintdevice_p.h>
21
23
24/*!
25 \internal
26 \class QCupsJobWidget
27
28 A widget to add to QPrintDialog to enable extra CUPS options
29 such as Job Scheduling, Job Priority or Job Billing
30 \ingroup printing
31 \inmodule QtPrintSupport
32 */
33
35 : QWidget(parent),
36 m_printer(printer),
37 m_printDevice(printDevice)
38{
39 m_ui.setupUi(this);
40 //set all the default values
41 initJobHold();
42 initJobBilling();
43 initJobPriority();
44 initBannerPages();
45
46 updateSavedValues();
47}
48
52
54{
55 QCUPSSupport::setJobHold(m_printer, jobHold(), jobHoldTime());
56 QCUPSSupport::setJobBilling(m_printer, jobBilling());
57 QCUPSSupport::setJobPriority(m_printer, jobPriority());
58 QCUPSSupport::setBannerPages(m_printer, startBannerPage(), endBannerPage());
59}
60
62{
63 m_savedJobHoldWithTime = { jobHold(), jobHoldTime() };
64 m_savedJobBilling = jobBilling();
65 m_savedPriority = jobPriority();
66 m_savedJobSheets = { startBannerPage(), endBannerPage() };
67}
68
70{
71 setJobHold(m_savedJobHoldWithTime.jobHold, m_savedJobHoldWithTime.time);
72 toggleJobHoldTime();
73
74 setJobBilling(m_savedJobBilling);
75
76 setJobPriority(m_savedPriority);
77
78 setStartBannerPage(m_savedJobSheets.startBannerPage);
79 setEndBannerPage(m_savedJobSheets.endBannerPage);
80}
81
82void QCupsJobWidget::initJobHold()
83{
84 m_ui.jobHoldComboBox->addItem(tr("Print Immediately"), QVariant::fromValue(QCUPSSupport::NoHold));
85 m_ui.jobHoldComboBox->addItem(tr("Hold Indefinitely"), QVariant::fromValue(QCUPSSupport::Indefinite));
86 m_ui.jobHoldComboBox->addItem(tr("Day (06:00 to 17:59)"), QVariant::fromValue(QCUPSSupport::DayTime));
87 m_ui.jobHoldComboBox->addItem(tr("Night (18:00 to 05:59)"), QVariant::fromValue(QCUPSSupport::Night));
88 m_ui.jobHoldComboBox->addItem(tr("Second Shift (16:00 to 23:59)"), QVariant::fromValue(QCUPSSupport::SecondShift));
89 m_ui.jobHoldComboBox->addItem(tr("Third Shift (00:00 to 07:59)"), QVariant::fromValue(QCUPSSupport::ThirdShift));
90 m_ui.jobHoldComboBox->addItem(tr("Weekend (Saturday to Sunday)"), QVariant::fromValue(QCUPSSupport::Weekend));
91 m_ui.jobHoldComboBox->addItem(tr("Specific Time"), QVariant::fromValue(QCUPSSupport::SpecificTime));
92
93 connect(m_ui.jobHoldComboBox, &QComboBox::currentIndexChanged, this, &QCupsJobWidget::toggleJobHoldTime);
94
95 QCUPSSupport::JobHoldUntilWithTime jobHoldWithTime;
96
97 if (m_printDevice) {
98 const QString jobHoldUntilString = m_printDevice->property(PDPK_CupsJobHoldUntil).toString();
99 jobHoldWithTime = QCUPSSupport::parseJobHoldUntil(jobHoldUntilString);
100 }
101
102 setJobHold(jobHoldWithTime.jobHold, jobHoldWithTime.time);
103 toggleJobHoldTime();
104}
105
106void QCupsJobWidget::setJobHold(QCUPSSupport::JobHoldUntil jobHold, QTime holdUntilTime)
107{
108 if (jobHold == QCUPSSupport::SpecificTime && holdUntilTime.isNull()) {
109 jobHold = QCUPSSupport::NoHold;
110 toggleJobHoldTime();
111 }
112 m_ui.jobHoldComboBox->setCurrentIndex(m_ui.jobHoldComboBox->findData(QVariant::fromValue(jobHold)));
113 m_ui.jobHoldTimeEdit->setTime(holdUntilTime);
114}
115
116QCUPSSupport::JobHoldUntil QCupsJobWidget::jobHold() const
117{
118 return qvariant_cast<QCUPSSupport::JobHoldUntil>(m_ui.jobHoldComboBox->itemData(m_ui.jobHoldComboBox->currentIndex()));
119}
120
121void QCupsJobWidget::toggleJobHoldTime()
122{
123 if (jobHold() == QCUPSSupport::SpecificTime)
124 m_ui.jobHoldTimeEdit->setEnabled(true);
125 else
126 m_ui.jobHoldTimeEdit->setEnabled(false);
127}
128
129QTime QCupsJobWidget::jobHoldTime() const
130{
131 return m_ui.jobHoldTimeEdit->time();
132}
133
134void QCupsJobWidget::initJobBilling()
135{
136 QString jobBilling;
137 if (m_printDevice)
138 jobBilling = m_printDevice->property(PDPK_CupsJobBilling).toString();
139
140 setJobBilling(jobBilling);
141}
142
143void QCupsJobWidget::setJobBilling(const QString &jobBilling)
144{
145 m_ui.jobBillingLineEdit->setText(jobBilling);
146}
147
148QString QCupsJobWidget::jobBilling() const
149{
150 return m_ui.jobBillingLineEdit->text();
151}
152
153void QCupsJobWidget::initJobPriority()
154{
155 int priority = -1;
156 if (m_printDevice) {
157 bool ok;
158 priority = m_printDevice->property(PDPK_CupsJobPriority).toInt(&ok);
159 if (!ok)
160 priority = -1;
161 }
162
163 if (priority < 0 || priority > 100)
164 priority = 50;
165
166 setJobPriority(priority);
167}
168
169void QCupsJobWidget::setJobPriority(int jobPriority)
170{
171 m_ui.jobPrioritySpinBox->setValue(jobPriority);
172}
173
174int QCupsJobWidget::jobPriority() const
175{
176 return m_ui.jobPrioritySpinBox->value();
177}
178
179void QCupsJobWidget::initBannerPages()
180{
181 m_ui.startBannerPageCombo->addItem(tr("None", "CUPS Banner page"), QVariant::fromValue(QCUPSSupport::NoBanner));
182 m_ui.startBannerPageCombo->addItem(tr("Standard", "CUPS Banner page"), QVariant::fromValue(QCUPSSupport::Standard));
183 m_ui.startBannerPageCombo->addItem(tr("Unclassified", "CUPS Banner page"), QVariant::fromValue(QCUPSSupport::Unclassified));
184 m_ui.startBannerPageCombo->addItem(tr("Confidential", "CUPS Banner page"), QVariant::fromValue(QCUPSSupport::Confidential));
185 m_ui.startBannerPageCombo->addItem(tr("Classified", "CUPS Banner page"), QVariant::fromValue(QCUPSSupport::Classified));
186 m_ui.startBannerPageCombo->addItem(tr("Secret", "CUPS Banner page"), QVariant::fromValue(QCUPSSupport::Secret));
187 m_ui.startBannerPageCombo->addItem(tr("Top Secret", "CUPS Banner page"), QVariant::fromValue(QCUPSSupport::TopSecret));
188
189 m_ui.endBannerPageCombo->addItem(tr("None", "CUPS Banner page"), QVariant::fromValue(QCUPSSupport::NoBanner));
190 m_ui.endBannerPageCombo->addItem(tr("Standard", "CUPS Banner page"), QVariant::fromValue(QCUPSSupport::Standard));
191 m_ui.endBannerPageCombo->addItem(tr("Unclassified", "CUPS Banner page"), QVariant::fromValue(QCUPSSupport::Unclassified));
192 m_ui.endBannerPageCombo->addItem(tr("Confidential", "CUPS Banner page"), QVariant::fromValue(QCUPSSupport::Confidential));
193 m_ui.endBannerPageCombo->addItem(tr("Classified", "CUPS Banner page"), QVariant::fromValue(QCUPSSupport::Classified));
194 m_ui.endBannerPageCombo->addItem(tr("Secret", "CUPS Banner page"), QVariant::fromValue(QCUPSSupport::Secret));
195 m_ui.endBannerPageCombo->addItem(tr("Top Secret", "CUPS Banner page"), QVariant::fromValue(QCUPSSupport::TopSecret));
196
197 QCUPSSupport::JobSheets jobSheets;
198
199 if (m_printDevice) {
200 const QString jobSheetsString = m_printDevice->property(PDPK_CupsJobSheets).toString();
201 jobSheets = QCUPSSupport::parseJobSheets(jobSheetsString);
202 }
203
204 setStartBannerPage(jobSheets.startBannerPage);
205 setEndBannerPage(jobSheets.endBannerPage);
206}
207
208void QCupsJobWidget::setStartBannerPage(const QCUPSSupport::BannerPage bannerPage)
209{
210 m_ui.startBannerPageCombo->setCurrentIndex(m_ui.startBannerPageCombo->findData(QVariant::fromValue(bannerPage)));
211}
212
213QCUPSSupport::BannerPage QCupsJobWidget::startBannerPage() const
214{
215 return qvariant_cast<QCUPSSupport::BannerPage>(m_ui.startBannerPageCombo->itemData(m_ui.startBannerPageCombo->currentIndex()));
216}
217
218void QCupsJobWidget::setEndBannerPage(const QCUPSSupport::BannerPage bannerPage)
219{
220 m_ui.endBannerPageCombo->setCurrentIndex(m_ui.endBannerPageCombo->findData(QVariant::fromValue(bannerPage)));
221}
222
223QCUPSSupport::BannerPage QCupsJobWidget::endBannerPage() const
224{
225 return qvariant_cast<QCUPSSupport::BannerPage>(m_ui.endBannerPageCombo->itemData(m_ui.endBannerPageCombo->currentIndex()));
226}
227
228QT_END_NAMESPACE
229
230#include "moc_qcupsjobwidget_p.cpp"
QObject * parent
Definition qobject.h:74
\reentrant
Definition qprinter.h:29
Combined button and popup list for selecting options.