00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
#include "kpschedulepage.h"
00021
00022
#include <qlabel.h>
00023
#include <qlayout.h>
00024
#include <qcombobox.h>
00025
#include <qregexp.h>
00026
#include <qdatetimeedit.h>
00027
#include <qdatetime.h>
00028
#include <qlineedit.h>
00029
#include <qwhatsthis.h>
00030
#include <klocale.h>
00031
#include <kseparator.h>
00032
#include <knuminput.h>
00033
00034
#include <time.h>
00035
00036 KPSchedulePage::KPSchedulePage(
QWidget *parent,
const char *name)
00037 :
KPrintDialogPage(parent, name)
00038 {
00039
QString whatsThisBillingInfo = i18n(
" <qt> <p>Insert a meaningful string here to associate"
00040
" the current print job with a certain account. This"
00041
" string will appear in the CUPS \"page_log\" to help"
00042
" with the print accounting in your organization. (Leave"
00043
" it empty if you don't need it.)"
00044
" <p> It is useful for people"
00045
" who print on behalf of different \"customers\", like"
00046
" print service bureaux, letter shops, press and prepress"
00047
" companies, or secretaries who serve different bosses, etc."
00048
" </qt>" );
00049
00050
QString whatsThisScheduledPrinting = i18n(
" <qt> <p>Scheduled printing lets you control the time"
00051
" of the actual printout, while you can still send away your"
00052
" job <b>now</b> and have it out of your way."
00053
" <p> Especially useful"
00054
" is the \"Never (hold indefinitely)\" option. It allows you"
00055
" to park your job until a time when you (or a printer administrator)"
00056
" decides to manually release it."
00057
" <p> This is often required in"
00058
" enterprise environments, where you normally are not"
00059
" allowed to directly and immediately access the huge production"
00060
" printers in your <em>Central Repro Department</em>. However it"
00061
" is okay to send jobs to the queue which is under the control of the"
00062
" operators (who, after all, need to make sure that the 10,000"
00063
" sheets of pink paper which is required by the Marketing"
00064
" Department for a particular job are available and loaded"
00065
" into the paper trays)."
00066
" </qt>" );
00067
00068
QString whatsThisPageLabel = i18n(
" <qt> <p>Page Labels are printed by CUPS at the top and bottom"
00069
" of each page. They appear on the pages surrounded by a little"
00070
" frame box."
00071
" <p>They contain any string you type into the line edit field."
00072
" </qt>" );
00073
00074
QString whatsThisJobPriority = i18n(
" <qt> <p>Usually CUPS prints all jobs per queue according to"
00075
" the \"FIFO\" priniciple: <em>First In, First Out</em>."
00076
" <p> The"
00077
" job priority option allows you to re-order the queue according"
00078
" to your needs."
00079
" <p> It works in both directions: you can increase"
00080
" as well as decrease priorities. (Usually you can only control"
00081
" your <b>own</b> jobs)."
00082
" <p> Since the default job priority is \"50\", any job sent"
00083
" with, for example, \"49\" will be printed only after all those"
00084
" others have finished. Conversely, a"
00085
" \"51\" or higher priority job will go right at the top of"
00086
" a populated queue (if no other, higher prioritized one is present)."
00087
" </qt>" );
00088
00089 setTitle(i18n(
"Advanced Options"));
00090 setOnlyRealPrinters(
true);
00091
00092
00093 time_t ct = time(0);
00094
struct tm *ts = gmtime(&ct);
00095 m_gmtdiff = ts->tm_hour;
00096 ts = localtime(&ct);
00097 m_gmtdiff -= ts->tm_hour;
00098
00099 m_time =
new QComboBox(
this);
00100 m_time->insertItem(i18n(
"Immediately"));
00101 m_time->insertItem(i18n(
"Never (hold indefinitely)"));
00102 m_time->insertItem(i18n(
"Daytime (6 am - 6 pm)"));
00103 m_time->insertItem(i18n(
"Evening (6 pm - 6 am)"));
00104 m_time->insertItem(i18n(
"Night (6 pm - 6 am)"));
00105 m_time->insertItem(i18n(
"Weekend"));
00106 m_time->insertItem(i18n(
"Second Shift (4 pm - 12 am)"));
00107 m_time->insertItem(i18n(
"Third Shift (12 am - 8 am)"));
00108 m_time->insertItem(i18n(
"Specified Time"));
00109
QWhatsThis::add(m_time, whatsThisScheduledPrinting);
00110 m_tedit =
new QTimeEdit(
this);
00111 m_tedit->setAutoAdvance(
true);
00112 m_tedit->setTime(QTime::currentTime());
00113 m_tedit->setEnabled(
false);
00114
QWhatsThis::add(m_tedit, whatsThisScheduledPrinting);
00115 m_billing =
new QLineEdit(
this);
00116
QWhatsThis::add(m_billing, whatsThisBillingInfo);
00117 m_pagelabel =
new QLineEdit(
this);
00118
QWhatsThis::add(m_pagelabel, whatsThisPageLabel);
00119 m_priority =
new KIntNumInput(50,
this);
00120
QWhatsThis::add(m_priority, whatsThisJobPriority);
00121 m_priority->setRange(1, 100, 10,
true);
00122
00123
QLabel *lab =
new QLabel(i18n(
"&Schedule printing:"),
this);
00124 lab->
setBuddy(m_time);
00125
QWhatsThis::add(lab, whatsThisScheduledPrinting);
00126
QLabel *lab1 =
new QLabel(i18n(
"&Billing information:"),
this);
00127
QWhatsThis::add(lab1, whatsThisBillingInfo);
00128 lab1->
setBuddy(m_billing);
00129
QLabel *lab2 =
new QLabel(i18n(
"T&op/Bottom page label:"),
this);
00130
QWhatsThis::add(lab2, whatsThisPageLabel);
00131 lab2->
setBuddy(m_pagelabel);
00132 m_priority->setLabel(i18n(
"&Job priority:"), Qt::AlignVCenter|Qt::AlignLeft);
00133
QWhatsThis::add(m_priority, whatsThisJobPriority);
00134
00135 KSeparator *sep0 =
new KSeparator(
this);
00136 sep0->setFixedHeight(10);
00137
00138
QGridLayout *l0 =
new QGridLayout(
this, 6, 2, 0, 7);
00139 l0->
addWidget(lab, 0, 0);
00140
QHBoxLayout *l1 =
new QHBoxLayout(0, 0, 5);
00141 l0->
addLayout(l1, 0, 1);
00142 l1->addWidget(m_time);
00143 l1->addWidget(m_tedit);
00144 l0->
addWidget(lab1, 1, 0);
00145 l0->
addWidget(lab2, 2, 0);
00146 l0->
addWidget(m_billing, 1, 1);
00147 l0->
addWidget(m_pagelabel, 2, 1);
00148 l0->
addMultiCellWidget(sep0, 3, 3, 0, 1);
00149 l0->
addMultiCellWidget(m_priority, 4, 4, 0, 1);
00150 l0->
setRowStretch(5, 1);
00151
00152 connect(m_time, SIGNAL(activated(
int)), SLOT(slotTimeChanged()));
00153 }
00154
00155 KPSchedulePage::~KPSchedulePage()
00156 {
00157 }
00158
00159
bool KPSchedulePage::isValid(
QString& msg)
00160 {
00161
if (m_time->currentItem() == 8 && !m_tedit->time().isValid())
00162 {
00163 msg = i18n(
"The time specified is not valid.");
00164
return false;
00165 }
00166
return true;
00167 }
00168
00169
void KPSchedulePage::setOptions(
const QMap<QString,QString>& opts)
00170 {
00171
QString t = opts[
"job-hold-until"];
00172
if (!t.
isEmpty())
00173 {
00174
int item(-1);
00175
00176
if (t ==
"no-hold") item = 0;
00177
else if (t ==
"indefinite") item = 1;
00178
else if (t ==
"day-time") item = 2;
00179
else if (t ==
"evening") item = 3;
00180
else if (t ==
"night") item = 4;
00181
else if (t ==
"weekend") item = 5;
00182
else if (t ==
"second-shift") item = 6;
00183
else if (t ==
"third-shift") item = 7;
00184
else
00185 {
00186
QTime qt =
QTime::fromString(t);
00187 m_tedit->setTime(qt.
addSecs(-3600 * m_gmtdiff));
00188 item = 8;
00189 }
00190
00191
if (item != -1)
00192 {
00193 m_time->setCurrentItem(item);
00194 slotTimeChanged();
00195 }
00196 }
00197
QRegExp re(
"^\"|\"$");
00198 t = opts[
"job-billing"].
stripWhiteSpace();
00199 t.
replace(re,
"");
00200 m_billing->setText(t);
00201 t = opts[
"page-label"].
stripWhiteSpace();
00202 t.
replace(re,
"");
00203 m_pagelabel->setText(t);
00204
int val = opts[
"job-priority"].toInt();
00205
if (val != 0)
00206 m_priority->setValue(val);
00207 }
00208
00209
void KPSchedulePage::getOptions(
QMap<QString,QString>& opts,
bool incldef)
00210 {
00211
if (incldef || m_time->currentItem() != 0)
00212 {
00213
QString t;
00214
switch (m_time->currentItem())
00215 {
00216
case 0: t =
"no-hold";
break;
00217
case 1: t =
"indefinite";
break;
00218
case 2: t =
"day-time";
break;
00219
case 3: t =
"evening";
break;
00220
case 4: t =
"night";
break;
00221
case 5: t =
"weekend";
break;
00222
case 6: t =
"second-shift";
break;
00223
case 7: t =
"third-shift";
break;
00224
case 8:
00225 t = m_tedit->time().addSecs(3600 * m_gmtdiff).toString();
00226
break;
00227 }
00228 opts[
"job-hold-until"] = t;
00229 }
00230
if (incldef || !m_billing->text().isEmpty())
00231 opts[
"job-billing"] =
"\"" + m_billing->text() +
"\"";
00232
if (incldef || !m_pagelabel->text().isEmpty())
00233 opts[
"page-label"] =
"\"" + m_pagelabel->text() +
"\"";
00234
if (incldef || m_priority->value() != 50)
00235 opts[
"job-priority"] =
QString::number(m_priority->value());
00236 }
00237
00238
void KPSchedulePage::slotTimeChanged()
00239 {
00240 m_tedit->setEnabled(m_time->currentItem() == 8);
00241
if (m_time->currentItem() == 8)
00242 m_tedit->setFocus();
00243 }
00244
00245
#include "kpschedulepage.moc"