summaryrefslogtreecommitdiffstats
path: root/tdeprint/cups/kpschedulepage.cpp
blob: 0a3513c67236c37a6d29206dbe74a9d7337730dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
/*
 *  This file is part of the KDE libraries
 *  Copyright (c) 2001 Michael Goffioul <tdeprint@swing.be>
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Library General Public
 *  License version 2 as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Library General Public License for more details.
 *
 *  You should have received a copy of the GNU Library General Public License
 *  along with this library; see the file COPYING.LIB.  If not, write to
 *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 *  Boston, MA 02110-1301, USA.
 **/

#include "kpschedulepage.h"

#include <tqlabel.h>
#include <tqlayout.h>
#include <tqcombobox.h>
#include <tqregexp.h>
#include <tqdatetimeedit.h>
#include <tqdatetime.h>
#include <tqlineedit.h>
#include <tqwhatsthis.h>
#include <tdelocale.h>
#include <kseparator.h>
#include <knuminput.h>

#include <time.h>

KPSchedulePage::KPSchedulePage(TQWidget *parent, const char *name)
: KPrintDialogPage(parent, name)
{
	//WhatsThis strings.... (added by pfeifle@kde.org)
	TQString whatsThisBillingInfo = i18n(    " <qt> <p><b>Print Job Billing and Accounting</b></p> "
						" <p>Insert a meaningful string here to associate"
						" the current print job with a certain account. This"
						" string will appear in the CUPS \"page_log\" to help"
						" with the print accounting in your organization. (Leave"
						" it empty if you do not need it.)"
						" <p> It is useful for people"
						" who print on behalf of different \"customers\", like"
						" print service bureaux, letter shops, press and prepress"
						" companies, or secretaries who serve different bosses, etc.</p>"
						" <br> "
                                                " <hr> "
						" <p><em><b>Additional hint for power users:</b> This TDEPrint GUI element matches "
						" with the CUPS commandline job option parameter:</em> "
						" <pre>"
						"    -o job-billing=...         # example: \"Marketing_Department\" or \"Joe_Doe\" "
						" </pre>"
						" </p> "
                                                " </qt>" );

	TQString whatsThisScheduledPrinting = i18n(" <qt> <p><b>Scheduled Printing</b></p> "
						" <p>Scheduled printing lets you control the time"
						" of the actual printout, while you can still send away your"
						" job <b>now</b> and have it out of your way."
						" <p> Especially useful"
						" is the \"Never (hold indefinitely)\" option. It allows you"
						" to park your job until a time when you (or a printer administrator)"
						" decides to manually release it."
						" <p> This is often required in"
						" enterprise environments, where you normally are not"
						" allowed to directly and immediately access the huge production"
						" printers in your <em>Central Repro Department</em>. However it"
						" is okay to send jobs to the queue which is under the control of the"
						" operators (who, after all, need to make sure that the 10,000"
						" sheets of pink paper which is required by the Marketing"
						" Department for a particular job are available and loaded"
						" into the paper trays).</p>"
						" <br> "
						" <hr> "
						" <p><em><b>Additional hint for power users:</b> This TDEPrint GUI element matches "
						" with the CUPS commandline job option parameter:</em> "
						" <pre>"
						"    -o job-hold-until=...      # example: \"indefinite\" or \"no-hold\" "
						" </pre>"
						" </p> "
						" </qt>" );

	TQString whatsThisPageLabel = i18n(      " <qt> <p><b>Page Labels</b></p> "
						" <p>Page Labels are printed by CUPS at the top and bottom"
						" of each page. They appear on the pages surrounded by a little"
						" frame box."
						" <p>They contain any string you type into the line edit field.</p>"
						" <br> "
						" <hr> "
						" <p><em><b>Additional hint for power users:</b> This TDEPrint GUI element matches "
						" with the CUPS commandline job option parameter:</em> "
						" <pre>"
						"    -o page-label=\"...\"      # example: \"Company Confidential\" "
						" </pre>"
						" </p> "
						" </qt>" );

	TQString whatsThisJobPriority = i18n(    " <qt> <p><b>Job Priority</b></p> "
						" <p>Usually CUPS prints all jobs per queue according to"
						" the \"FIFO\" principle: <em>First In, First Out</em>."
						" <p> The"
						" job priority option allows you to re-order the queue according"
						" to your needs."
						" <p> It works in both directions: you can increase"
						" as well as decrease priorities. (Usually you can only control"
						" your <b>own</b> jobs)."
						" <p> Since the default job priority is \"50\", any job sent"
						" with, for example, \"49\" will be printed only after all those"
						" others have finished. Conversely, a"
						" \"51\" or higher priority job will go right to the top of"
						" a populated queue (if no other, higher prioritized one is present).</p>"
						" <br> "
						" <hr> "
						" <p><em><b>Additional hint for power users:</b> This TDEPrint GUI element matches "
						" with the CUPS commandline job option parameter:</em> "
						" <pre>"
						"    -o job-priority=...   # example: \"10\" or \"66\" or \"99\" "
						" </pre>"
						" </p> "
						" </qt>" );

	setTitle(i18n("Advanced Options"));
	setOnlyRealPrinters(true);

	// compute difference in hours between GMT and local time
	time_t	ct = time(0);
	struct tm	*ts = gmtime(&ct);
	m_gmtdiff = ts->tm_hour;
	ts = localtime(&ct);
	m_gmtdiff -= ts->tm_hour;

	m_time = new TQComboBox(this);
	m_time->insertItem(i18n("Immediately"));
	m_time->insertItem(i18n("Never (hold indefinitely)"));
	m_time->insertItem(i18n("Daytime (6 am - 6 pm)"));
	m_time->insertItem(i18n("Evening (6 pm - 6 am)"));
	m_time->insertItem(i18n("Night (6 pm - 6 am)"));
	m_time->insertItem(i18n("Weekend"));
	m_time->insertItem(i18n("Second Shift (4 pm - 12 am)"));
	m_time->insertItem(i18n("Third Shift (12 am - 8 am)"));
	m_time->insertItem(i18n("Specified Time"));
        TQWhatsThis::add(m_time, whatsThisScheduledPrinting);
	m_tedit = new TQTimeEdit(this);
	m_tedit->setAutoAdvance(true);
	m_tedit->setTime(TQTime::currentTime());
	m_tedit->setEnabled(false);
        TQWhatsThis::add(m_tedit, whatsThisScheduledPrinting);
	m_billing = new TQLineEdit(this);
        TQWhatsThis::add(m_billing, whatsThisBillingInfo);
	m_pagelabel = new TQLineEdit(this);
        TQWhatsThis::add(m_pagelabel, whatsThisPageLabel);
	m_priority = new KIntNumInput(50, this);
        TQWhatsThis::add(m_priority, whatsThisJobPriority);
	m_priority->setRange(1, 100, 10, true);

	TQLabel	*lab = new TQLabel(i18n("&Scheduled printing:"), this);
	lab->setBuddy(m_time);
        TQWhatsThis::add(lab, whatsThisScheduledPrinting);
	TQLabel	*lab1 = new TQLabel(i18n("&Billing information:"), this);
        TQWhatsThis::add(lab1, whatsThisBillingInfo);
	lab1->setBuddy(m_billing);
	TQLabel	*lab2 = new TQLabel(i18n("T&op/Bottom page label:"), this);
        TQWhatsThis::add(lab2, whatsThisPageLabel);
	lab2->setBuddy(m_pagelabel);
	m_priority->setLabel(i18n("&Job priority:"), TQt::AlignVCenter|TQt::AlignLeft);
        TQWhatsThis::add(m_priority, whatsThisJobPriority);

	KSeparator	*sep0 = new KSeparator(this);
	sep0->setFixedHeight(10);

	TQGridLayout	*l0 = new TQGridLayout(this, 6, 2, 0, 7);
	l0->addWidget(lab, 0, 0);
	TQHBoxLayout	*l1 = new TQHBoxLayout(0, 0, 5);
	l0->addLayout(l1, 0, 1);
	l1->addWidget(m_time);
	l1->addWidget(m_tedit);
	l0->addWidget(lab1, 1, 0);
	l0->addWidget(lab2, 2, 0);
	l0->addWidget(m_billing, 1, 1);
	l0->addWidget(m_pagelabel, 2, 1);
	l0->addMultiCellWidget(sep0, 3, 3, 0, 1);
	l0->addMultiCellWidget(m_priority, 4, 4, 0, 1);
	l0->setRowStretch(5, 1);

	connect(m_time, TQ_SIGNAL(activated(int)), TQ_SLOT(slotTimeChanged()));
}

KPSchedulePage::~KPSchedulePage()
{
}

bool KPSchedulePage::isValid(TQString& msg)
{
	if (m_time->currentItem() == 8 && !m_tedit->time().isValid())
	{
		msg = i18n("The time specified is not valid.");
		return false;
	}
	return true;
}

void KPSchedulePage::setOptions(const TQMap<TQString,TQString>& opts)
{
	TQString	t = opts["job-hold-until"];
	if (!t.isEmpty())
	{
		int	item(-1);

		if (t == "no-hold") item = 0;
		else if (t == "indefinite") item = 1;
		else if (t == "day-time") item = 2;
		else if (t == "evening") item = 3;
		else if (t == "night") item = 4;
		else if (t == "weekend") item = 5;
		else if (t == "second-shift") item = 6;
		else if (t == "third-shift") item = 7;
		else
		{
			TQTime	qt = TQTime::fromString(t);
			m_tedit->setTime(qt.addSecs(-3600 * m_gmtdiff));
			item = 8;
		}

		if (item != -1)
		{
			m_time->setCurrentItem(item);
			slotTimeChanged();
		}
	}
	TQRegExp	re("^\"|\"$");
	t = opts["job-billing"].stripWhiteSpace();
	t.replace(re, "");
	m_billing->setText(t);
	t = opts["page-label"].stripWhiteSpace();
	t.replace(re, "");
	m_pagelabel->setText(t);
	int	val = opts["job-priority"].toInt();
	if (val != 0)
		m_priority->setValue(val);
}

void KPSchedulePage::getOptions(TQMap<TQString,TQString>& opts, bool incldef)
{
	if (incldef || m_time->currentItem() != 0)
	{
		TQString	t;
		switch (m_time->currentItem())
		{
			case 0: t = "no-hold"; break;
			case 1: t = "indefinite"; break;
			case 2: t = "day-time"; break;
			case 3: t = "evening"; break;
			case 4: t = "night"; break;
			case 5: t = "weekend"; break;
			case 6: t = "second-shift"; break;
			case 7: t = "third-shift"; break;
			case 8:
				t = m_tedit->time().addSecs(3600 * m_gmtdiff).toString();
				break;
		}
		opts["job-hold-until"] = t;
	}
	if (incldef || !m_billing->text().isEmpty())
		opts["job-billing"] = "\"" + m_billing->text() + "\"";
	if (incldef || !m_pagelabel->text().isEmpty())
		opts["page-label"] = "\"" + m_pagelabel->text() + "\"";
	if (incldef || m_priority->value() != 50)
		opts["job-priority"] = TQString::number(m_priority->value());
}

void KPSchedulePage::slotTimeChanged()
{
	m_tedit->setEnabled(m_time->currentItem() == 8);
	if (m_time->currentItem() == 8)
		m_tedit->setFocus();
}

#include "kpschedulepage.moc"