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