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