• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeprint
 

tdeprint

  • tdeprint
kpgeneralpage.cpp
1 /*
2  * This file is part of the KDE libraries
3  * Copyright (c) 2001 Michael Goffioul <tdeprint@swing.be>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License version 2 as published by the Free Software Foundation.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public License
15  * along with this library; see the file COPYING.LIB. If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  **/
19 
20 #include "kpgeneralpage.h"
21 #include "driver.h"
22 #include "kmprinter.h"
23 #include "kprinter.h"
24 
25 #include <tqcombobox.h>
26 #include <tqlabel.h>
27 #include <tqbutton.h>
28 #include <tqbuttongroup.h>
29 #include <tqlayout.h>
30 #include <tqradiobutton.h>
31 #include <tqwhatsthis.h>
32 
33 #include <kcursor.h>
34 #include <kdebug.h>
35 #include <kdialog.h>
36 #include <kiconloader.h>
37 #include <tdelocale.h>
38 
39 // Some ID's
40 #define ORIENT_PORTRAIT_ID 0
41 #define ORIENT_LANDSCAPE_ID 1
42 #define ORIENT_REVLANDSCAPE_ID 2
43 #define ORIENT_REVPORTRAIT_ID 3
44 
45 #define DUPLEX_NONE_ID 0
46 #define DUPLEX_LONG_ID 1
47 #define DUPLEX_SHORT_ID 2
48 
49 #define NUP_1_ID 0
50 #define NUP_2_ID 1
51 #define NUP_4_ID 2
52 
53 static void initCombo(TQComboBox *cb, DrListOption *opt)
54 {
55  cb->clear();
56  TQPtrListIterator<DrBase> it(*(opt->choices()));
57  for (;it.current();++it)
58  {
59  cb->insertItem(it.current()->get("text"));
60  if (it.current() == opt->currentChoice())
61  cb->setCurrentItem(cb->count()-1);
62  }
63 }
64 
65 static void setComboItem(TQComboBox *cb, const TQString& txt)
66 {
67  for (int i=0;i<cb->count();i++)
68  if (cb->text(i) == txt)
69  {
70  cb->setCurrentItem(i);
71  return;
72  }
73 }
74 
75 static int findOption(const char *strs[], int n, const TQString& txt)
76 {
77  for (int i=0;i<n;i+=2)
78  if (txt == strs[i]) return (i/2);
79  return (-1);
80 }
81 
82 //*************************************************************************************************
83 
84 // default values in case of NULL driver
85 static const char* default_size[] = {
86  "A4", I18N_NOOP("ISO A4"),
87  "Letter", I18N_NOOP("US Letter"),
88  "Legal", I18N_NOOP("US Legal"),
89  "Ledger", I18N_NOOP("Ledger"),
90  "Folio", I18N_NOOP("Folio"),
91  "Comm10", I18N_NOOP("US #10 Envelope"),
92  "DL", I18N_NOOP("ISO DL Envelope"),
93  "Tabloid", I18N_NOOP("Tabloid"),
94  "A3", I18N_NOOP( "ISO A3" ),
95  "A2", I18N_NOOP( "ISO A2" ),
96  "A1", I18N_NOOP( "ISO A1" ),
97  "A0", I18N_NOOP( "ISO A0" )
98 };
99 
100 #define SMALLSIZE_BEGIN 0
101 #define MEDIUMSIZE_BEGIN 14
102 #define HIGHSIZE_BEGIN 20
103 #define DEFAULT_SIZE 24
104 
105 #define DEFAULT_SOURCE 8
106 static const char* default_source[] = {
107  "Upper", I18N_NOOP("Upper Tray"),
108  "Lower", I18N_NOOP("Lower Tray"),
109  "MultiPurpose", I18N_NOOP("Multi-Purpose Tray"),
110  "LargeCapacity", I18N_NOOP("Large Capacity Tray")
111 };
112 #define DEFAULT_TYPE 4
113 static const char* default_type[] = {
114  "Normal", I18N_NOOP("Normal"),
115  "Transparency", I18N_NOOP("Transparency")
116 };
117 
118 //***************************************************************************************************
119 
120 KPGeneralPage::KPGeneralPage(KMPrinter *pr, DrMain *dr, TQWidget *parent, const char *name)
121 : KPrintDialogPage(pr,dr,parent,name)
122 {
123  //WhatsThis strings.... (added by pfeifle@kde.org)
124  TQString whatsThisPrintPropertiesGeneralPage = i18n( " <qt> "
125  " <p><b>\"General\"</b> </p> "
126  " <p>This dialog page contains <em>general</em> print job settings."
127  " General settings are applicable to most printers, most jobs "
128  " and most job file types. "
129  " <p>To get more specific help, enable the \"WhatsThis\" cursor and click on any of the "
130  " text labels or GUI elements of this dialog. "
131  " </qt>" );
132  TQString whatsThisGeneralPageSizeLabel = i18n( " <qt> "
133  " <p><b>Page size:</b> Select paper size to be printed on from "
134  " the drop-down menu. </p>"
135  " <p>The exact list of choices depends on the printer driver (\"PPD\") you have installed.</p> "
136  " <br> "
137  " <hr> "
138  " <p><em><b>Additional hint for power users:</b> This TDEPrint GUI element matches "
139  " with the CUPS commandline job option parameter:</em> "
140  " <pre>"
141  " -o PageSize=... # examples: \"A4\" or \"Letter\" "
142  " </pre>"
143  " </p> "
144  " </qt>" );
145  TQString whatsThisGeneralPaperTypeLabel = i18n( " <qt> "
146  " <p><b>Paper type:</b> Select paper type to be printed on from "
147  " the drop-down menu. </p>"
148  " <p>The exact list of choices depends on the printer driver (\"PPD\") you have installed. </p>"
149  " <br> "
150  " <hr> "
151  " <p><em><b>Additional hint for power users:</b> This TDEPrint GUI element matches "
152  " with the CUPS commandline job option parameter:</em> "
153  " <pre>"
154  " -o MediaType=... # example: \"Transparency\" "
155  " </pre>"
156  " </p> "
157  " </qt>" );
158  TQString whatsThisGeneralPaperSourceLabel = i18n( " <qt> "
159  " <p><b>Paper source:</b> Select paper source tray for the paper"
160  " to be printed on from the drop-down menu. "
161  " <p>The exact list of choices depends on the printer driver (\"PPD\") you have installed. </p>"
162  " <br> "
163  " <hr> "
164  " <p><em><b>Additional hint for power users:</b> This TDEPrint GUI element matches "
165  " with the CUPS commandline job option parameter:</em> "
166  " <pre>"
167  " -o InputSlot=... # examples: \"Lower\" or \"LargeCapacity\" "
168  " </pre>"
169  " </p> "
170  " </qt>" );
171  TQString whatsThisGeneralOrientationLabel = i18n( " <qt> "
172  " <p><b>Image Orientation:</b> Orientation of the printed "
173  " page image on your paper is controlled by the radio buttons. By default, "
174  " the orientation is <em>Portrait</em> "
175  " <p>You can select 4 alternatives: "
176  " <ul> "
177  " <li> <b>Portrait.</b>.Portrait is the default setting. </li> "
178  " <li> <b>Landscape.</b> </li> "
179  " <li> <b>Reverse Landscape.</b> Reverse Landscape prints the images upside down. </li> "
180  " <li> <b>Reverse Portrait.</b> Reverse Portrait prints the image upside down.</li> "
181  " </ul> "
182  " The icon changes according to your selection.</p>"
183  " <br> "
184  " <hr> "
185  " <p><em><b>Additional hint for power users:</b> This TDEPrint GUI element matches "
186  " with the CUPS commandline job option parameter:</em> "
187  " <pre>"
188  " -o orientation-requested=... # examples: \"landscape\" or \"reverse-portrait\" "
189  " </pre>"
190  " </p> "
191  " </qt>" );
192  TQString whatsThisGeneralDuplexLabel = i18n( " <qt> "
193  " <p><b>Duplex Printing:</b> These controls may be grayed out if your printer "
194  " does not support <em>duplex printing</em> (i.e. printing on both sides of the sheet). "
195  " These controls are active if your printer supports duplex printing. "
196  " <p> "
197  " You can choose from 3 alternatives: </p>"
198  " <ul> "
199  " <li> <b>None.</b> This prints each page of the job on one side of the sheets only. </li> "
200  " <li> <b>Long Side.</b> This prints the job on both sides of the paper sheets. "
201  " It prints the job in a way so that the backside has the same orientation as the front "
202  " side if you turn the paper over the long edge. (Some printer drivers name this mode "
203  " <em>duplex-non-tumbled</em>). </li> "
204  " <li> <b>Short Side.</b> This prints the job on both sides of the paper sheets. "
205  " It prints the job so that the backside has the reverse orientation from the front "
206  " side if you turn the paper over the long edge, but the same orientation, if you turn it over "
207  " the short edge. (Some printer drivers name this mode "
208  " <em>duplex-tumbled</em>). </li> "
209  " </ul> "
210  " <hr> "
211  " <p><em><b>Additional hint for power users:</b> This TDEPrint GUI element matches "
212  " with the CUPS commandline job option parameter:</em> "
213  " <pre>"
214  " -o duplex=... # examples: \"tumble\" or \"two-sided-short-edge\" "
215  " </pre>"
216  " </p> "
217  " </qt>" );
218  TQString whatsThisGeneralBannersLabel = i18n( " <qt> "
219  " <p><b>Banner Page(s):</b> Select banner(s) to print one or two special sheets "
220  " of paper just before or after your main job. </p>"
221  " <p>Banners may contain some pieces of job information, such as user name, time of printing, job"
222  " title and more. </p>"
223  " <p>Banner pages are useful to separate different jobs more easily, especially in a multi-user "
224  " environment. </p>"
225  " <p><em><b>Hint:</em></b> You can design your own banner pages. To make use of them, just put the banner "
226  " file into the standard CUPS <em>banners</em> directory (This is usually <em>\"/usr/share/cups/banner/\"</em> "
227  " Your custom banner(s) must have one of the supported printable formats. "
228  " Supported formats are ASCII text, PostScript, PDF and nearly any image format such as PNG, JPEG or "
229  " GIF. Your added banner pages will appear in the drop down menu after a restart of CUPS. </p>"
230  " <p>CUPS comes with a selection of banner pages. </p>"
231  " <br> "
232  " <hr> "
233  " <p><em><b>Additional hint for power users:</b> This TDEPrint GUI element matches "
234  " with the CUPS commandline job option parameter:</em> "
235  " <pre>"
236  " -o job-sheets=... # examples: \"standard\" or \"topsecret\" "
237  " </pre>"
238  " </p> "
239  " </qt>" );
240  TQString whatsThisGeneralPagesPerSheetLabel = i18n( " <qt> "
241  " <p><b>Pages per Sheet:</b> "
242  " You can choose to print more than one page onto each sheet of paper. "
243  " This is sometimes useful to save paper. </p>"
244  " <p><b>Note 1:</b> the page images get scaled down accordingly to print 2 or 4 pages per sheet. "
245  " The page image does not get scaled if you print 1 page per sheet (the default setting.). "
246  " <p><b>Note 2:</b> If you select multiple pages per sheet here, the scaling and re-arranging is done "
247  " by your printing system. Be aware, that some printers can by themselves print multiple pages per sheet. "
248  " In this case you find the option in the printer driver settings. Be careful: if you enable multiple "
249  " pages per sheet in both places, your printout will not look as you intended. </p>"
250  " <br> "
251  " <hr> "
252  " <p><em><b>Additional hint for power users:</b> This TDEPrint GUI element matches "
253  " with the CUPS commandline job option parameter:</em> "
254  " <pre>"
255  " -o number-up=... # examples: \"2\" or \"4\" "
256  " </pre>"
257  " </p> "
258  " </qt>" );
259 
260 
261  setTitle(i18n("General"));
262 
263  // widget creation
264  TQLabel *m_pagesizelabel = new TQLabel(i18n("Page s&ize:"), this);
265  m_pagesizelabel->setAlignment(Qt::AlignVCenter|Qt::AlignRight);
266  TQWhatsThis::add(m_pagesizelabel, whatsThisGeneralPageSizeLabel);
267 
268  TQLabel *m_papertypelabel = new TQLabel(i18n("Paper t&ype:"), this);
269  m_papertypelabel->setAlignment(Qt::AlignVCenter|Qt::AlignRight);
270  TQWhatsThis::add(m_papertypelabel, whatsThisGeneralPaperTypeLabel);
271 
272  TQLabel *m_inputslotlabel = new TQLabel(i18n("Paper so&urce:"), this);
273  m_inputslotlabel->setAlignment(Qt::AlignVCenter|Qt::AlignRight);
274  TQWhatsThis::add(m_inputslotlabel, whatsThisGeneralPaperSourceLabel);
275 
276  m_pagesize = new TQComboBox(this);
277  TQWhatsThis::add(m_pagesize, whatsThisGeneralPageSizeLabel);
278 
279  m_papertype = new TQComboBox(this);
280  TQWhatsThis::add(m_papertype, whatsThisGeneralPaperTypeLabel);
281 
282  m_inputslot = new TQComboBox(this);
283  TQWhatsThis::add(m_inputslot, whatsThisGeneralPaperSourceLabel);
284 
285  m_pagesizelabel->setBuddy(m_pagesize);
286  m_papertypelabel->setBuddy(m_papertype);
287  m_inputslotlabel->setBuddy(m_inputslot);
288 
289  m_orientbox = new TQButtonGroup(0, Qt::Vertical, i18n("Orientation"), this);
290  TQWhatsThis::add(m_orientbox, whatsThisGeneralOrientationLabel);
291 
292  m_duplexbox = new TQButtonGroup(0, Qt::Vertical, i18n("Duplex Printing"), this);
293  TQWhatsThis::add(m_duplexbox, whatsThisGeneralDuplexLabel);
294 
295  m_nupbox = new TQButtonGroup(0, Qt::Vertical, i18n("Pages per Sheet"), this);
296  TQWhatsThis::add(m_nupbox, whatsThisGeneralPagesPerSheetLabel);
297 
298  m_bannerbox = new TQGroupBox(0, Qt::Vertical, i18n("Banners"), this);
299  TQWhatsThis::add(m_bannerbox, whatsThisGeneralBannersLabel);
300 
301  TQRadioButton *m_portrait = new TQRadioButton(i18n("&Portrait"), m_orientbox);
302  TQRadioButton *m_landscape = new TQRadioButton(i18n("&Landscape"), m_orientbox);
303  TQRadioButton *m_revland = new TQRadioButton(i18n("&Reverse landscape"), m_orientbox);
304  TQRadioButton *m_revport = new TQRadioButton(i18n("R&everse portrait"), m_orientbox);
305 
306  m_portrait->setChecked(true);
307  m_orientpix = new TQLabel(m_orientbox);
308  m_orientpix->setAlignment(Qt::AlignCenter);
309  TQRadioButton *m_dupnone = new TQRadioButton(i18n("duplex orientation", "&None"), m_duplexbox);
310  TQRadioButton *m_duplong = new TQRadioButton(i18n("duplex orientation", "Lon&g side"), m_duplexbox);
311  TQRadioButton *m_dupshort = new TQRadioButton(i18n("duplex orientation", "S&hort side"), m_duplexbox);
312  m_dupnone->setChecked(true);
313  m_duplexpix = new TQLabel(m_duplexbox);
314  m_duplexpix->setAlignment(Qt::AlignCenter);
315  TQRadioButton *m_nup1 = new TQRadioButton("&1", m_nupbox);
316  TQRadioButton *m_nup2 = new TQRadioButton("&2", m_nupbox);
317  TQRadioButton *m_nup4 = new TQRadioButton("&4", m_nupbox);
318  m_nup1->setChecked(true);
319  m_nuppix = new TQLabel(m_nupbox);
320  m_nuppix->setAlignment(Qt::AlignCenter);
321  m_startbanner = new TQComboBox(m_bannerbox);
322  m_endbanner = new TQComboBox(m_bannerbox);
323  TQLabel *m_startbannerlabel = new TQLabel(i18n("S&tart:"), m_bannerbox);
324  TQLabel *m_endbannerlabel = new TQLabel(i18n("En&d:"), m_bannerbox);
325  m_startbannerlabel->setBuddy(m_startbanner);
326  m_endbannerlabel->setBuddy(m_endbanner);
327 
328  // layout creation
329  TQVBoxLayout *lay0 = new TQVBoxLayout(this, 0, KDialog::spacingHint());
330  TQWhatsThis::add(this, whatsThisPrintPropertiesGeneralPage);
331  TQGridLayout *lay1 = new TQGridLayout(0, 3, 2, 0, KDialog::spacingHint());
332  TQGridLayout *lay2 = new TQGridLayout(0, 2, 2, 0, KDialog::spacingHint());
333  lay0->addStretch(1);
334  lay0->addLayout(TQT_TQLAYOUT(lay1));
335  lay0->addStretch(1);
336  lay0->addLayout(TQT_TQLAYOUT(lay2));
337  lay0->addStretch(2);
338  lay1->addWidget(m_pagesizelabel, 0, 0);
339  lay1->addWidget(m_papertypelabel, 1, 0);
340  lay1->addWidget(m_inputslotlabel, 2, 0);
341  lay1->addWidget(m_pagesize, 0, 1);
342  lay1->addWidget(m_papertype, 1, 1);
343  lay1->addWidget(m_inputslot, 2, 1);
344  lay2->addWidget(m_orientbox, 0, 0);
345  lay2->addWidget(m_bannerbox, 1, 0);
346  lay2->addWidget(m_duplexbox, 0, 1);
347  lay2->addWidget(m_nupbox, 1, 1);
348  lay2->setColStretch(0, 1);
349  lay2->setColStretch(1, 1);
350  TQGridLayout *lay3 = new TQGridLayout(m_orientbox->layout(), 4, 2,
351  KDialog::spacingHint());
352  lay3->addWidget(m_portrait, 0, 0);
353  lay3->addWidget(m_landscape, 1, 0);
354  lay3->addWidget(m_revland, 2, 0);
355  lay3->addWidget(m_revport, 3, 0);
356  lay3->addMultiCellWidget(m_orientpix, 0, 3, 1, 1);
357  TQGridLayout *lay4 = new TQGridLayout(m_duplexbox->layout(), 3, 2,
358  KDialog::spacingHint());
359  lay4->addWidget(m_dupnone, 0, 0);
360  lay4->addWidget(m_duplong, 1, 0);
361  lay4->addWidget(m_dupshort, 2, 0);
362  lay4->addMultiCellWidget(m_duplexpix, 0, 2, 1, 1);
363  lay4->setRowStretch( 0, 1 );
364  TQGridLayout *lay5 = new TQGridLayout(m_nupbox->layout(), 3, 2,
365  KDialog::spacingHint());
366  lay5->addWidget(m_nup1, 0, 0);
367  lay5->addWidget(m_nup2, 1, 0);
368  lay5->addWidget(m_nup4, 2, 0);
369  lay5->addMultiCellWidget(m_nuppix, 0, 2, 1, 1);
370  TQGridLayout *lay6 = new TQGridLayout(m_bannerbox->layout(), 2, 2,
371  KDialog::spacingHint());
372  lay6->addWidget(m_startbannerlabel, 0, 0);
373  lay6->addWidget(m_endbannerlabel, 1, 0);
374  lay6->addWidget(m_startbanner, 0, 1);
375  lay6->addWidget(m_endbanner, 1, 1);
376  lay6->setColStretch(1, 1);
377 
378  // connections (+ misc)
379  connect(m_orientbox,TQT_SIGNAL(clicked(int)),TQT_SLOT(slotOrientationChanged(int)));
380  connect(m_nupbox,TQT_SIGNAL(clicked(int)),TQT_SLOT(slotNupChanged(int)));
381  connect(m_duplexbox,TQT_SIGNAL(clicked(int)),TQT_SLOT(slotDuplexChanged(int)));
382 
383  // init
384  initialize();
385 }
386 
387 KPGeneralPage::~KPGeneralPage()
388 {
389 }
390 
391 void KPGeneralPage::initialize()
392 {
393  if (driver())
394  {
395  // Size, Type and Source
396  DrListOption *opt = (DrListOption*)driver()->findOption("PageSize");
397  if (opt) initCombo(m_pagesize,opt);
398  else m_pagesize->setEnabled(false);
399  opt = (DrListOption*)driver()->findOption("MediaType");
400  if (opt) initCombo(m_papertype,opt);
401  else m_papertype->setEnabled(false);
402  opt = (DrListOption*)driver()->findOption("InputSlot");
403  if (opt) initCombo(m_inputslot,opt);
404  else m_inputslot->setEnabled(false);
405  // Duplex
406  opt = (DrListOption*)driver()->findOption("Duplex");
407  if (opt)
408  {
409  if ( opt->choices()->count() == 2 )
410  {
411  // probably a On/Off option instead of the standard PS one
412  TQButton *btn = static_cast<TQButton*>(m_duplexbox->find( DUPLEX_SHORT_ID ));
413  m_duplexbox->remove( btn );
414  btn->hide();
415  //delete btn;
416  static_cast<TQButton*>(m_duplexbox->find( DUPLEX_NONE_ID ))->setText( i18n( "Disabled" ) );
417  static_cast<TQButton*>(m_duplexbox->find( DUPLEX_LONG_ID ))->setText( i18n( "Enabled" ) );
418  m_duplexpix->hide();
419  }
420  if (opt->currentChoice())
421  {
422  int ID(DUPLEX_NONE_ID);
423  if (opt->currentChoice()->name() == "DuplexNoTumble" || opt->currentChoice()->name() == "On") ID = DUPLEX_LONG_ID;
424  else if (opt->currentChoice()->name() == "DuplexTumble") ID = DUPLEX_SHORT_ID;
425  m_duplexbox->setButton(ID);
426  slotDuplexChanged(ID);
427  }
428  }
429  else m_duplexbox->setEnabled(false);
430  }
431  else
432  {
433  // PageSize
434  for (int i=SMALLSIZE_BEGIN+1;i<MEDIUMSIZE_BEGIN;i+=2)
435  m_pagesize->insertItem(i18n(default_size[i]));
436  if ( printer()->printerCap() & KMPrinter::CapMedium )
437  for ( int i=MEDIUMSIZE_BEGIN+1; i<HIGHSIZE_BEGIN; i+=2 )
438  m_pagesize->insertItem(i18n(default_size[i]));
439  if ( printer()->printerCap() & KMPrinter::CapLarge )
440  for ( int i=HIGHSIZE_BEGIN+1; i<DEFAULT_SIZE; i+=2 )
441  m_pagesize->insertItem(i18n(default_size[i]));
442  // set default page size using locale settings
443  TQString psname = pageSizeToPageName((KPrinter::PageSize)(TDEGlobal::locale()->pageSize()));
444  int index = findOption(default_size, DEFAULT_SIZE, psname);
445  if (index >= 0)
446  m_pagesize->setCurrentItem(index);
447  // MediaType
448  for (int i=1;i<DEFAULT_TYPE;i+=2)
449  m_papertype->insertItem(i18n(default_type[i]));
450  // PageSize
451  for (int i=1;i<DEFAULT_SOURCE;i+=2)
452  m_inputslot->insertItem(i18n(default_source[i]));
453 
454  // Enable duplex setting if supported
455  m_duplexbox->setEnabled( printer()->printerCap() & KMPrinter::CapDuplex );
456  }
457 
458  // Banners
459  TQStringList values = TQStringList::split(',',printer()->option("kde-banners-supported"),false);
460  if (values.count() > 0)
461  {
462  for (TQStringList::ConstIterator it = values.begin(); it != values.end(); ++it)
463  {
464  m_startbanner->insertItem(*it);
465  m_endbanner->insertItem(*it);
466  }
467  values = TQStringList::split(',',printer()->option("kde-banners"),false);
468  while (values.count() < 2) values.append("none");
469  setComboItem(m_startbanner, values[0]);
470  setComboItem(m_endbanner, values[1]);
471  }
472  else
473  m_bannerbox->setEnabled(false);
474 
475  slotOrientationChanged(ORIENT_PORTRAIT_ID);
476  slotNupChanged(NUP_1_ID);
477 }
478 
479 void KPGeneralPage::setOptions(const TQMap<TQString,TQString>& opts)
480 {
481  TQString value;
482 
483  if (driver())
484  {
485  value = opts["media"];
486  TQStringList l = TQStringList::split(',',value,false);
487  for(TQStringList::ConstIterator it = l.begin(); it != l.end(); ++it)
488  {
489  value = *it;
490  DrBase *ch;
491  if ((ch = (driver()->findOption("PageSize"))) &&
492  (ch = (static_cast<DrListOption*>(ch))->findChoice(value)))
493  {
494  if (m_pagesize->isEnabled())
495  setComboItem(m_pagesize, ch->get("text"));
496  }
497  else if ((ch = (driver()->findOption("MediaType"))) &&
498  (ch = (static_cast<DrListOption*>(ch))->findChoice(value)))
499  {
500  if (m_papertype->isEnabled())
501  setComboItem(m_papertype, ch->get("text"));
502  }
503  else if ((ch = (driver()->findOption("InputSlot"))) &&
504  (ch = static_cast<DrListOption*>(ch)->findChoice(value)))
505  {
506  if (m_inputslot)
507  setComboItem(m_inputslot, ch->get("text"));
508  }
509  else
510  {
511  kdWarning() << "media option '" << value << "' not handled." << endl;
512  }
513  }
514  value = opts["PageSize"];
515  if (m_pagesize->isEnabled() && !value.isEmpty())
516  {
517  DrBase *ch = ((DrListOption*)driver()->findOption("PageSize"))->findChoice(value);
518  if (ch) setComboItem(m_pagesize, ch->get("text"));
519  }
520  value = opts["MediaType"];
521  if (m_papertype->isEnabled() && !value.isEmpty())
522  {
523  DrBase *ch = ((DrListOption*)driver()->findOption("MediaType"))->findChoice(value);
524  if (ch) setComboItem(m_papertype, ch->get("text"));
525  }
526  value = opts["InputSlot"];
527  if (m_inputslot && m_inputslot->isEnabled() && !value.isEmpty())
528  {
529  DrBase *ch = ((DrListOption*)driver()->findOption("InputSlot"))->findChoice(value);
530  if (ch) setComboItem(m_inputslot, ch->get("text"));
531  }
532 
533  value = opts["Duplex"];
534  if (m_duplexbox->isEnabled() && !value.isEmpty())
535  {
536  int ID(0);
537  if (value == "DuplexNoTumble" || value == "On") ID = 1;
538  else if (value == "DuplexTumble") ID = 2;
539  m_duplexbox->setButton(ID);
540  slotDuplexChanged(ID);
541  }
542  }
543  else
544  {
545  // Try to find "media" option
546  value = opts["media"];
547  if (!value.isEmpty())
548  {
549  int index(-1);
550  TQStringList l = TQStringList::split(',',value,false);
551  for(TQStringList::ConstIterator it = l.begin(); it != l.end(); ++it)
552  {
553  value = *it;
554 
555  if ((index=findOption(default_size,DEFAULT_SIZE,value)) >= 0)
556  m_pagesize->setCurrentItem(index);
557  else if ((index=findOption(default_type,DEFAULT_TYPE,value)) >= 0)
558  m_papertype->setCurrentItem(index);
559  else if ((index=findOption(default_source,DEFAULT_SOURCE,value)) >= 0)
560  m_inputslot->setCurrentItem(index);
561  else
562  kdWarning() << "media option '" << value << "' not handled." << endl;
563  }
564  }
565 
566  // Try to find "sides" option
567  value = opts["sides"];
568  int ID(0);
569  if (value == "two-sided-long-edge") ID = 1;
570  else if (value == "two-sided-short-edge") ID = 2;
571  m_duplexbox->setButton(ID);
572  slotDuplexChanged(ID);
573  }
574 
575  // Banners
576  value = opts["job-sheets"];
577  if (!value.isEmpty())
578  {
579  TQStringList l = TQStringList::split(',',value,false);
580  if (l.count() > 0) setComboItem(m_startbanner,l[0]);
581  if (l.count() > 1) setComboItem(m_endbanner,l[1]);
582  }
583 
584  // Orientation
585  value = opts["orientation-requested"];
586  if (!value.isEmpty())
587  {
588  bool ok;
589  int ID = value.toInt(&ok)-3;
590  if (ok)
591  {
592  m_orientbox->setButton(ID);
593  slotOrientationChanged(ID);
594  }
595  }
596 
597  // N-up
598  value = opts["number-up"];
599  if (!value.isEmpty())
600  {
601  bool ok;
602  int ID = TQMIN(value.toInt(&ok)-1,2);
603  if (ok)
604  {
605  m_nupbox->setButton(ID);
606  slotNupChanged(ID);
607  }
608  }
609 
610  if ( m_orientbox->isEnabled() )
611  m_orientbox->setDisabled( opts[ "kde-orientation-fixed" ] == "1" );
612  if ( m_pagesize->isEnabled() )
613  m_pagesize->setDisabled( opts[ "kde-pagesize-fixed" ] == "1" );
614 }
615 
616 void KPGeneralPage::getOptions(TQMap<TQString,TQString>& opts, bool incldef)
617 {
618  TQString value;
619 
620  if (driver())
621  {
622  DrListOption *opt;
623  if ((opt=(DrListOption*)driver()->findOption("PageSize")) != NULL)
624  {
625  DrBase *ch = opt->choices()->at(m_pagesize->currentItem());
626  if (incldef || ch->name() != opt->get("default")) opts["PageSize"] = ch->name();
627  }
628  if ((opt=(DrListOption*)driver()->findOption("MediaType")) != NULL)
629  {
630  DrBase *ch = opt->choices()->at(m_papertype->currentItem());
631  if (incldef || ch->name() != opt->get("default")) opts["MediaType"] = ch->name();
632  }
633  if ((opt=(DrListOption*)driver()->findOption("InputSlot")) != NULL)
634  {
635  DrBase *ch = opt->choices()->at(m_inputslot->currentItem());
636  if (incldef || ch->name() != opt->get("default")) opts["InputSlot"] = ch->name();
637  }
638 
639  if (m_duplexbox->isEnabled() && (opt=(DrListOption*)driver()->findOption("Duplex")) != NULL)
640  {
641  bool twoChoices = ( m_duplexbox->count() == 2 );
642  switch (m_duplexbox->id(m_duplexbox->selected()))
643  {
644  case DUPLEX_NONE_ID: value = ( twoChoices ? "Off" : "None" ); break;
645  case DUPLEX_LONG_ID: value = ( twoChoices ? "On" : "DuplexNoTumble" ); break;
646  case DUPLEX_SHORT_ID: value = "DuplexTumble"; break;
647  }
648  if (incldef || value != opt->get("default")) opts["Duplex"] = value;
649  }
650  }
651  else
652  {
653  value = TQString("%1,%2,%3").arg(default_size[m_pagesize->currentItem()*2]).arg(default_type[m_papertype->currentItem()*2]).arg(default_source[m_inputslot->currentItem()*2]);
654  opts["media"] = value;
655 
656  if (m_duplexbox->isEnabled())
657  {
658  switch (m_duplexbox->id(m_duplexbox->selected()))
659  {
660  case 0: value = "one-sided"; break;
661  case 1: value = "two-sided-long-edge"; break;
662  case 2: value = "two-sided-short-edge"; break;
663  }
664  opts["sides"] = value;
665  }
666  }
667 
668  value = TQString::number(m_orientbox->id(m_orientbox->selected())+3);
669  if (value != "3" || incldef) opts["orientation-requested"] = value;
670 
671  if (m_nupbox->isEnabled())
672  {
673  switch (m_nupbox->id(m_nupbox->selected()))
674  {
675  case 0: value = "1"; break;
676  case 1: value = "2"; break;
677  case 2: value = "4"; break;
678  }
679  if (value != "1" || incldef) opts["number-up"] = value;
680  }
681 
682  if (m_bannerbox->isEnabled())
683  {
684  TQStringList l = TQStringList::split(',',printer()->option("kde-banners"),false);
685  if (incldef || (l.count() == 2 && (l[0] != m_startbanner->currentText() || l[1] != m_endbanner->currentText()))
686  || (l.count() == 0 && (m_startbanner->currentText() != "none" || m_endbanner->currentText() != "none")))
687  {
688  value = TQString("%1,%2").arg(m_startbanner->currentText()).arg(m_endbanner->currentText());
689  opts["job-sheets"] = value;
690  }
691  }
692 }
693 
694 void KPGeneralPage::slotOrientationChanged(int ID)
695 {
696  TQString iconstr;
697  switch (ID)
698  {
699  case ORIENT_PORTRAIT_ID: iconstr = "tdeprint_portrait"; break;
700  case ORIENT_LANDSCAPE_ID: iconstr = "tdeprint_landscape"; break;
701  case ORIENT_REVPORTRAIT_ID: iconstr = "tdeprint_revportrait"; break;
702  case ORIENT_REVLANDSCAPE_ID: iconstr = "tdeprint_revlandscape"; break;
703  default: iconstr = "tdeprint_portrait"; break;
704  }
705  m_orientpix->setPixmap(UserIcon(iconstr));
706 }
707 
708 void KPGeneralPage::slotNupChanged(int ID)
709 {
710  TQString iconstr;
711  switch (ID)
712  {
713  case NUP_1_ID: iconstr = "tdeprint_nup1"; break;
714  case NUP_2_ID: iconstr = "tdeprint_nup2"; break;
715  case NUP_4_ID: iconstr = "tdeprint_nup4"; break;
716  default: iconstr = "tdeprint_nup1"; break;
717  }
718  m_nuppix->setPixmap(UserIcon(iconstr));
719 }
720 
721 void KPGeneralPage::slotDuplexChanged(int ID)
722 {
723  if (m_duplexbox->isEnabled())
724  {
725  TQString iconstr;
726  switch (ID)
727  {
728  case DUPLEX_NONE_ID: iconstr = "tdeprint_duplex_none"; break;
729  case DUPLEX_LONG_ID: iconstr = "tdeprint_duplex_long"; break;
730  case DUPLEX_SHORT_ID: iconstr = "tdeprint_duplex_short"; break;
731  default: iconstr = "tdeprint_duplex_none"; break;
732  }
733  m_duplexpix->setPixmap(UserIcon(iconstr));
734  }
735 }
736 #include "kpgeneralpage.moc"
KPrintDialogPage
This class is intended to be used as base class for customized print dialog page. ...
Definition: kprintdialogpage.h:90
KPrinter::PageSize
PageSize
Defines the paper size to use.
Definition: kprinter.h:167

tdeprint

Skip menu "tdeprint"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

tdeprint

Skip menu "tdeprint"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeprint by doxygen 1.8.8
This website is maintained by Timothy Pearson.