00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "kpgeneralpage.h"
00021 #include "driver.h"
00022 #include "kmprinter.h"
00023 #include "kprinter.h"
00024
00025 #include <qcombobox.h>
00026 #include <qlabel.h>
00027 #include <qbuttongroup.h>
00028 #include <qlayout.h>
00029 #include <qradiobutton.h>
00030 #include <qwhatsthis.h>
00031
00032 #include <kcursor.h>
00033 #include <kdebug.h>
00034 #include <kdialog.h>
00035 #include <kiconloader.h>
00036 #include <klocale.h>
00037
00038
00039 #define ORIENT_PORTRAIT_ID 0
00040 #define ORIENT_LANDSCAPE_ID 1
00041 #define ORIENT_REVLANDSCAPE_ID 2
00042 #define ORIENT_REVPORTRAIT_ID 3
00043
00044 #define DUPLEX_NONE_ID 0
00045 #define DUPLEX_LONG_ID 1
00046 #define DUPLEX_SHORT_ID 2
00047
00048 #define NUP_1_ID 0
00049 #define NUP_2_ID 1
00050 #define NUP_4_ID 2
00051
00052 static void initCombo(QComboBox *cb, DrListOption *opt)
00053 {
00054 cb->clear();
00055 QPtrListIterator<DrBase> it(*(opt->choices()));
00056 for (;it.current();++it)
00057 {
00058 cb->insertItem(it.current()->get("text"));
00059 if (it.current() == opt->currentChoice())
00060 cb->setCurrentItem(cb->count()-1);
00061 }
00062 }
00063
00064 static void setComboItem(QComboBox *cb, const QString& txt)
00065 {
00066 for (int i=0;i<cb->count();i++)
00067 if (cb->text(i) == txt)
00068 {
00069 cb->setCurrentItem(i);
00070 return;
00071 }
00072 }
00073
00074 static int findOption(const char *strs[], int n, const QString& txt)
00075 {
00076 for (int i=0;i<n;i+=2)
00077 if (txt == strs[i]) return (i/2);
00078 return (-1);
00079 }
00080
00081
00082
00083
00084 static const char* default_size[] = {
00085 "A4", I18N_NOOP("ISO A4"),
00086 "Letter", I18N_NOOP("US Letter"),
00087 "Legal", I18N_NOOP("US Legal"),
00088 "Ledger", I18N_NOOP("Ledger"),
00089 "Folio", I18N_NOOP("Folio"),
00090 "Comm10", I18N_NOOP("US #10 Envelope"),
00091 "DL", I18N_NOOP("ISO DL Envelope"),
00092 "Tabloid", I18N_NOOP("Tabloid"),
00093 "A3", I18N_NOOP( "ISO A3" ),
00094 "A2", I18N_NOOP( "ISO A2" ),
00095 "A1", I18N_NOOP( "ISO A1" ),
00096 "A0", I18N_NOOP( "ISO A0" )
00097 };
00098
00099 #define SMALLSIZE_BEGIN 0
00100 #define MEDIUMSIZE_BEGIN 14
00101 #define HIGHSIZE_BEGIN 20
00102 #define DEFAULT_SIZE 24
00103
00104 #define DEFAULT_SOURCE 8
00105 static const char* default_source[] = {
00106 "Upper", I18N_NOOP("Upper Tray"),
00107 "Lower", I18N_NOOP("Lower Tray"),
00108 "MultiPurpose", I18N_NOOP("Multi-Purpose Tray"),
00109 "LargeCapacity", I18N_NOOP("Large Capacity Tray")
00110 };
00111 #define DEFAULT_TYPE 4
00112 static const char* default_type[] = {
00113 "Normal", I18N_NOOP("Normal"),
00114 "Transparency", I18N_NOOP("Transparency")
00115 };
00116
00117
00118
00119 KPGeneralPage::KPGeneralPage(KMPrinter *pr, DrMain *dr, QWidget *parent, const char *name)
00120 : KPrintDialogPage(pr,dr,parent,name)
00121 {
00122
00123 QString whatsThisPrintPropertiesGeneralPage = i18n( " <qt> "
00124 " <p><b>\"General\"</b> </p> "
00125 " <p>This dialog page contains <em>general</em> print job settings."
00126 " General settings are applicable to most printers, most jobs "
00127 " and most job file types. "
00128 " <p>To get more specific help, enable the \"WhatsThis\" cursor and click on any of the "
00129 " text labels or GUI elements of this dialog. "
00130 " </qt>" );
00131 QString whatsThisGeneralPageSizeLabel = i18n( " <qt> "
00132 " <p><b>Page size:</b> Select paper size to be printed on from "
00133 " the drop-down menu. </p>"
00134 " <p>The exact list of choices depends on the printer driver (\"PPD\") you have installed.</p> "
00135 " <br> "
00136 " <hr> "
00137 " <p><em><b>Additional hint for power users:</b> This KDEPrint GUI element matches "
00138 " with the CUPS commandline job option parameter:</em> "
00139 " <pre>"
00140 " -o PageSize=... # examples: \"A4\" or \"Letter\" "
00141 " </pre>"
00142 " </p> "
00143 " </qt>" );
00144 QString whatsThisGeneralPaperTypeLabel = i18n( " <qt> "
00145 " <p><b>Paper type:</b> Select paper type to be printed on from "
00146 " the drop-down menu. </p>"
00147 " <p>The exact list of choices depends on the printer driver (\"PPD\") you have installed. </p>"
00148 " <br> "
00149 " <hr> "
00150 " <p><em><b>Additional hint for power users:</b> This KDEPrint GUI element matches "
00151 " with the CUPS commandline job option parameter:</em> "
00152 " <pre>"
00153 " -o MediaType=... # example: \"Transparency\" "
00154 " </pre>"
00155 " </p> "
00156 " </qt>" );
00157 QString whatsThisGeneralPaperSourceLabel = i18n( " <qt> "
00158 " <p><b>Paper source:</b> Select paper source tray for the paper"
00159 " to be printed on from the drop-down menu. "
00160 " <p>The exact list of choices depends on the printer driver (\"PPD\") you have installed. </p>"
00161 " <br> "
00162 " <hr> "
00163 " <p><em><b>Additional hint for power users:</b> This KDEPrint GUI element matches "
00164 " with the CUPS commandline job option parameter:</em> "
00165 " <pre>"
00166 " -o InputSlot=... # examples: \"Lower\" or \"LargeCapacity\" "
00167 " </pre>"
00168 " </p> "
00169 " </qt>" );
00170 QString whatsThisGeneralOrientationLabel = i18n( " <qt> "
00171 " <p><b>Image Orientation:</b> Orientation of the printed "
00172 " page image on your paper is controlled by the radio buttons. By default, "
00173 " the orientation is <em>Portrait</em> "
00174 " <p>You can select 4 alternatives: "
00175 " <ul> "
00176 " <li> <b>Portrait.</b>.Portrait is the default setting. </li> "
00177 " <li> <b>Landscape.</b> </li> "
00178 " <li> <b>Reverse Landscape.</b> Reverse Landscape prints the images upside down. </li> "
00179 " <li> <b>Reverse Portrait.</b> Reverse Portrait prints the image upside down.</li> "
00180 " </ul> "
00181 " The icon changes according to your selection.</p>"
00182 " <br> "
00183 " <hr> "
00184 " <p><em><b>Additional hint for power users:</b> This KDEPrint GUI element matches "
00185 " with the CUPS commandline job option parameter:</em> "
00186 " <pre>"
00187 " -o orientation-requested=... # examples: \"landscape\" or \"reverse-portrait\" "
00188 " </pre>"
00189 " </p> "
00190 " </qt>" );
00191 QString whatsThisGeneralDuplexLabel = i18n( " <qt> "
00192 " <p><b>Duplex Printing:</b> These controls may be grayed out if your printer "
00193 " does not support <em>duplex printing</em> (i.e. printing on both sides of the sheet). "
00194 " These controls are active if your printer supports duplex printing. "
00195 " <p> "
00196 " You can choose from 3 alternatives: </p>"
00197 " <ul> "
00198 " <li> <b>None.</b> This prints each page of the job on one side of the sheets only. </li> "
00199 " <li> <b>Long Side.</b> This prints the job on both sides of the paper sheets. "
00200 " It prints the job in a way so that the backside has the same orientation as the front "
00201 " side if you turn the paper over the long edge. (Some printer drivers name this mode "
00202 " <em>duplex-non-tumbled</em>). </li> "
00203 " <li> <b>Short Side.</b> This prints the job on both sides of the paper sheets. "
00204 " It prints the job so that the backside has the reverse orientation from the front "
00205 " side if you turn the paper over the long edge, but the same orientation, if you turn it over "
00206 " the short edge. (Some printer drivers name this mode "
00207 " <em>duplex-tumbled</em>). </li> "
00208 " </ul> "
00209 " <hr> "
00210 " <p><em><b>Additional hint for power users:</b> This KDEPrint GUI element matches "
00211 " with the CUPS commandline job option parameter:</em> "
00212 " <pre>"
00213 " -o duplex=... # examples: \"tumble\" or \"two-sided-short-edge\" "
00214 " </pre>"
00215 " </p> "
00216 " </qt>" );
00217 QString whatsThisGeneralBannersLabel = i18n( " <qt> "
00218 " <p><b>Banner Page(s):</b> Select banner(s) to print one or two special sheets "
00219 " of paper just before or after your main job. </p>"
00220 " <p>Banners may contain some pieces of job information, such as user name, time of printing, job"
00221 " title and more. </p>"
00222 " <p>Banner pages are useful to separate different jobs more easily, especially in a multi-user "
00223 " environment. </p>"
00224 " <p><em><b>Hint:</em></b> You can design your own banner pages. To make use of them, just put the banner "
00225 " file into the standard CUPS <em>banners</em> directory (This is usually <em>\"/usr/share/cups/banner/\"</em> "
00226 " Your custom banner(s) must have one of the supported printable formats. "
00227 " Supported formats are ASCII text, PostScript, PDF and nearly any image format such as PNG, JPEG or "
00228 " GIF. Your added banner pages will appear in the drop down menu after a restart of CUPS. </p>"
00229 " <p>CUPS comes with a selection of banner pages. </p>"
00230 " <br> "
00231 " <hr> "
00232 " <p><em><b>Additional hint for power users:</b> This KDEPrint GUI element matches "
00233 " with the CUPS commandline job option parameter:</em> "
00234 " <pre>"
00235 " -o job-sheets=... # examples: \"standard\" or \"topsecret\" "
00236 " </pre>"
00237 " </p> "
00238 " </qt>" );
00239 QString whatsThisGeneralPagesPerSheetLabel = i18n( " <qt> "
00240 " <p><b>Pages per Sheet:</b> "
00241 " You can choose to print more than one page onto each sheet of paper. "
00242 " This is sometimes useful to save paper. </p>"
00243 " <p><b>Note 1:</b> the page images get scaled down accordingly to print 2 or 4 pages per sheet. "
00244 " The page image does not get scaled if you print 1 page per sheet (the default setting.). "
00245 " <p><b>Note 2:</b> If you select multiple pages per sheet here, the scaling and re-arranging is done "
00246 " by your printing system. Be aware, that some printers can by themselves print multiple pages per sheet. "
00247 " In this case you find the option in the printer driver settings. Be careful: if you enable multiple "
00248 " pages per sheet in both places, your printout will not look as you intended. </p>"
00249 " <br> "
00250 " <hr> "
00251 " <p><em><b>Additional hint for power users:</b> This KDEPrint GUI element matches "
00252 " with the CUPS commandline job option parameter:</em> "
00253 " <pre>"
00254 " -o number-up=... # examples: \"2\" or \"4\" "
00255 " </pre>"
00256 " </p> "
00257 " </qt>" );
00258
00259
00260 setTitle(i18n("General"));
00261
00262
00263 QLabel *m_pagesizelabel = new QLabel(i18n("Page s&ize:"), this);
00264 m_pagesizelabel->setAlignment(Qt::AlignVCenter|Qt::AlignRight);
00265 QWhatsThis::add(m_pagesizelabel, whatsThisGeneralPageSizeLabel);
00266
00267 QLabel *m_papertypelabel = new QLabel(i18n("Paper t&ype:"), this);
00268 m_papertypelabel->setAlignment(Qt::AlignVCenter|Qt::AlignRight);
00269 QWhatsThis::add(m_papertypelabel, whatsThisGeneralPaperTypeLabel);
00270
00271 QLabel *m_inputslotlabel = new QLabel(i18n("Paper so&urce:"), this);
00272 m_inputslotlabel->setAlignment(Qt::AlignVCenter|Qt::AlignRight);
00273 QWhatsThis::add(m_inputslotlabel, whatsThisGeneralPaperSourceLabel);
00274
00275 m_pagesize = new QComboBox(this);
00276 QWhatsThis::add(m_pagesize, whatsThisGeneralPageSizeLabel);
00277
00278 m_papertype = new QComboBox(this);
00279 QWhatsThis::add(m_papertype, whatsThisGeneralPaperTypeLabel);
00280
00281 m_inputslot = new QComboBox(this);
00282 QWhatsThis::add(m_inputslot, whatsThisGeneralPaperSourceLabel);
00283
00284 m_pagesizelabel->setBuddy(m_pagesize);
00285 m_papertypelabel->setBuddy(m_papertype);
00286 m_inputslotlabel->setBuddy(m_inputslot);
00287
00288 m_orientbox = new QButtonGroup(0, Qt::Vertical, i18n("Orientation"), this);
00289 QWhatsThis::add(m_orientbox, whatsThisGeneralOrientationLabel);
00290
00291 m_duplexbox = new QButtonGroup(0, Qt::Vertical, i18n("Duplex Printing"), this);
00292 QWhatsThis::add(m_duplexbox, whatsThisGeneralDuplexLabel);
00293
00294 m_nupbox = new QButtonGroup(0, Qt::Vertical, i18n("Pages per Sheet"), this);
00295 QWhatsThis::add(m_nupbox, whatsThisGeneralPagesPerSheetLabel);
00296
00297 m_bannerbox = new QGroupBox(0, Qt::Vertical, i18n("Banners"), this);
00298 QWhatsThis::add(m_bannerbox, whatsThisGeneralBannersLabel);
00299
00300 QRadioButton *m_portrait = new QRadioButton(i18n("&Portrait"), m_orientbox);
00301 QRadioButton *m_landscape = new QRadioButton(i18n("&Landscape"), m_orientbox);
00302 QRadioButton *m_revland = new QRadioButton(i18n("&Reverse landscape"), m_orientbox);
00303 QRadioButton *m_revport = new QRadioButton(i18n("R&everse portrait"), m_orientbox);
00304
00305 m_portrait->setChecked(true);
00306 m_orientpix = new QLabel(m_orientbox);
00307 m_orientpix->setAlignment(Qt::AlignCenter);
00308 QRadioButton *m_dupnone = new QRadioButton(i18n("duplex orientation", "&None"), m_duplexbox);
00309 QRadioButton *m_duplong = new QRadioButton(i18n("duplex orientation", "Lon&g side"), m_duplexbox);
00310 QRadioButton *m_dupshort = new QRadioButton(i18n("duplex orientation", "S&hort side"), m_duplexbox);
00311 m_dupnone->setChecked(true);
00312 m_duplexpix = new QLabel(m_duplexbox);
00313 m_duplexpix->setAlignment(Qt::AlignCenter);
00314 QRadioButton *m_nup1 = new QRadioButton("&1", m_nupbox);
00315 QRadioButton *m_nup2 = new QRadioButton("&2", m_nupbox);
00316 QRadioButton *m_nup4 = new QRadioButton("&4", m_nupbox);
00317 m_nup1->setChecked(true);
00318 m_nuppix = new QLabel(m_nupbox);
00319 m_nuppix->setAlignment(Qt::AlignCenter);
00320 m_startbanner = new QComboBox(m_bannerbox);
00321 m_endbanner = new QComboBox(m_bannerbox);
00322 QLabel *m_startbannerlabel = new QLabel(i18n("S&tart:"), m_bannerbox);
00323 QLabel *m_endbannerlabel = new QLabel(i18n("En&d:"), m_bannerbox);
00324 m_startbannerlabel->setBuddy(m_startbanner);
00325 m_endbannerlabel->setBuddy(m_endbanner);
00326
00327
00328 QVBoxLayout *lay0 = new QVBoxLayout(this, 0, KDialog::spacingHint());
00329 QWhatsThis::add(this, whatsThisPrintPropertiesGeneralPage);
00330 QGridLayout *lay1 = new QGridLayout(0, 3, 2, 0, KDialog::spacingHint());
00331 QGridLayout *lay2 = new QGridLayout(0, 2, 2, 0, KDialog::spacingHint());
00332 lay0->addStretch(1);
00333 lay0->addLayout(lay1);
00334 lay0->addStretch(1);
00335 lay0->addLayout(lay2);
00336 lay0->addStretch(2);
00337 lay1->addWidget(m_pagesizelabel, 0, 0);
00338 lay1->addWidget(m_papertypelabel, 1, 0);
00339 lay1->addWidget(m_inputslotlabel, 2, 0);
00340 lay1->addWidget(m_pagesize, 0, 1);
00341 lay1->addWidget(m_papertype, 1, 1);
00342 lay1->addWidget(m_inputslot, 2, 1);
00343 lay2->addWidget(m_orientbox, 0, 0);
00344 lay2->addWidget(m_bannerbox, 1, 0);
00345 lay2->addWidget(m_duplexbox, 0, 1);
00346 lay2->addWidget(m_nupbox, 1, 1);
00347 lay2->setColStretch(0, 1);
00348 lay2->setColStretch(1, 1);
00349 QGridLayout *lay3 = new QGridLayout(m_orientbox->layout(), 4, 2,
00350 KDialog::spacingHint());
00351 lay3->addWidget(m_portrait, 0, 0);
00352 lay3->addWidget(m_landscape, 1, 0);
00353 lay3->addWidget(m_revland, 2, 0);
00354 lay3->addWidget(m_revport, 3, 0);
00355 lay3->addMultiCellWidget(m_orientpix, 0, 3, 1, 1);
00356 QGridLayout *lay4 = new QGridLayout(m_duplexbox->layout(), 3, 2,
00357 KDialog::spacingHint());
00358 lay4->addWidget(m_dupnone, 0, 0);
00359 lay4->addWidget(m_duplong, 1, 0);
00360 lay4->addWidget(m_dupshort, 2, 0);
00361 lay4->addMultiCellWidget(m_duplexpix, 0, 2, 1, 1);
00362 lay4->setRowStretch( 0, 1 );
00363 QGridLayout *lay5 = new QGridLayout(m_nupbox->layout(), 3, 2,
00364 KDialog::spacingHint());
00365 lay5->addWidget(m_nup1, 0, 0);
00366 lay5->addWidget(m_nup2, 1, 0);
00367 lay5->addWidget(m_nup4, 2, 0);
00368 lay5->addMultiCellWidget(m_nuppix, 0, 2, 1, 1);
00369 QGridLayout *lay6 = new QGridLayout(m_bannerbox->layout(), 2, 2,
00370 KDialog::spacingHint());
00371 lay6->addWidget(m_startbannerlabel, 0, 0);
00372 lay6->addWidget(m_endbannerlabel, 1, 0);
00373 lay6->addWidget(m_startbanner, 0, 1);
00374 lay6->addWidget(m_endbanner, 1, 1);
00375 lay6->setColStretch(1, 1);
00376
00377
00378 connect(m_orientbox,SIGNAL(clicked(int)),SLOT(slotOrientationChanged(int)));
00379 connect(m_nupbox,SIGNAL(clicked(int)),SLOT(slotNupChanged(int)));
00380 connect(m_duplexbox,SIGNAL(clicked(int)),SLOT(slotDuplexChanged(int)));
00381
00382
00383 initialize();
00384 }
00385
00386 KPGeneralPage::~KPGeneralPage()
00387 {
00388 }
00389
00390 void KPGeneralPage::initialize()
00391 {
00392 if (driver())
00393 {
00394
00395 DrListOption *opt = (DrListOption*)driver()->findOption("PageSize");
00396 if (opt) initCombo(m_pagesize,opt);
00397 else m_pagesize->setEnabled(false);
00398 opt = (DrListOption*)driver()->findOption("MediaType");
00399 if (opt) initCombo(m_papertype,opt);
00400 else m_papertype->setEnabled(false);
00401 opt = (DrListOption*)driver()->findOption("InputSlot");
00402 if (opt) initCombo(m_inputslot,opt);
00403 else m_inputslot->setEnabled(false);
00404
00405 opt = (DrListOption*)driver()->findOption("Duplex");
00406 if (opt)
00407 {
00408 if ( opt->choices()->count() == 2 )
00409 {
00410
00411 QButton *btn = m_duplexbox->find( DUPLEX_SHORT_ID );
00412 m_duplexbox->remove( btn );
00413 btn->hide();
00414
00415 m_duplexbox->find( DUPLEX_NONE_ID )->setText( i18n( "Disabled" ) );
00416 m_duplexbox->find( DUPLEX_LONG_ID )->setText( i18n( "Enabled" ) );
00417 m_duplexpix->hide();
00418 }
00419 if (opt->currentChoice())
00420 {
00421 int ID(DUPLEX_NONE_ID);
00422 if (opt->currentChoice()->name() == "DuplexNoTumble" || opt->currentChoice()->name() == "On") ID = DUPLEX_LONG_ID;
00423 else if (opt->currentChoice()->name() == "DuplexTumble") ID = DUPLEX_SHORT_ID;
00424 m_duplexbox->setButton(ID);
00425 slotDuplexChanged(ID);
00426 }
00427 }
00428 else m_duplexbox->setEnabled(false);
00429 }
00430 else
00431 {
00432
00433 for (int i=SMALLSIZE_BEGIN+1;i<MEDIUMSIZE_BEGIN;i+=2)
00434 m_pagesize->insertItem(i18n(default_size[i]));
00435 if ( printer()->printerCap() & KMPrinter::CapMedium )
00436 for ( int i=MEDIUMSIZE_BEGIN+1; i<HIGHSIZE_BEGIN; i+=2 )
00437 m_pagesize->insertItem(i18n(default_size[i]));
00438 if ( printer()->printerCap() & KMPrinter::CapLarge )
00439 for ( int i=HIGHSIZE_BEGIN+1; i<DEFAULT_SIZE; i+=2 )
00440 m_pagesize->insertItem(i18n(default_size[i]));
00441
00442 QString psname = pageSizeToPageName((KPrinter::PageSize)(KGlobal::locale()->pageSize()));
00443 int index = findOption(default_size, DEFAULT_SIZE, psname);
00444 if (index >= 0)
00445 m_pagesize->setCurrentItem(index);
00446
00447 for (int i=1;i<DEFAULT_TYPE;i+=2)
00448 m_papertype->insertItem(i18n(default_type[i]));
00449
00450 for (int i=1;i<DEFAULT_SOURCE;i+=2)
00451 m_inputslot->insertItem(i18n(default_source[i]));
00452
00453
00454 m_duplexbox->setEnabled( printer()->printerCap() & KMPrinter::CapDuplex );
00455 }
00456
00457
00458 QStringList values = QStringList::split(',',printer()->option("kde-banners-supported"),false);
00459 if (values.count() > 0)
00460 {
00461 for (QStringList::ConstIterator it = values.begin(); it != values.end(); ++it)
00462 {
00463 m_startbanner->insertItem(*it);
00464 m_endbanner->insertItem(*it);
00465 }
00466 values = QStringList::split(',',printer()->option("kde-banners"),false);
00467 while (values.count() < 2) values.append("none");
00468 setComboItem(m_startbanner, values[0]);
00469 setComboItem(m_endbanner, values[1]);
00470 }
00471 else
00472 m_bannerbox->setEnabled(false);
00473
00474 slotOrientationChanged(ORIENT_PORTRAIT_ID);
00475 slotNupChanged(NUP_1_ID);
00476 }
00477
00478 void KPGeneralPage::setOptions(const QMap<QString,QString>& opts)
00479 {
00480 QString value;
00481
00482 if (driver())
00483 {
00484 value = opts["media"];
00485 QStringList l = QStringList::split(',',value,false);
00486 for(QStringList::ConstIterator it = l.begin(); it != l.end(); ++it)
00487 {
00488 value = *it;
00489 DrBase *ch;
00490 if ((ch = (driver()->findOption("PageSize"))) &&
00491 (ch = (static_cast<DrListOption*>(ch))->findChoice(value)))
00492 {
00493 if (m_pagesize->isEnabled())
00494 setComboItem(m_pagesize, ch->get("text"));
00495 }
00496 else if ((ch = (driver()->findOption("MediaType"))) &&
00497 (ch = (static_cast<DrListOption*>(ch))->findChoice(value)))
00498 {
00499 if (m_papertype->isEnabled())
00500 setComboItem(m_papertype, ch->get("text"));
00501 }
00502 else if ((ch = (driver()->findOption("InputSlot"))) &&
00503 (ch = static_cast<DrListOption*>(ch)->findChoice(value)))
00504 {
00505 if (m_inputslot)
00506 setComboItem(m_inputslot, ch->get("text"));
00507 }
00508 else
00509 {
00510 kdWarning() << "media option '" << value << "' not handled." << endl;
00511 }
00512 }
00513 value = opts["PageSize"];
00514 if (m_pagesize->isEnabled() && !value.isEmpty())
00515 {
00516 DrBase *ch = ((DrListOption*)driver()->findOption("PageSize"))->findChoice(value);
00517 if (ch) setComboItem(m_pagesize, ch->get("text"));
00518 }
00519 value = opts["MediaType"];
00520 if (m_papertype->isEnabled() && !value.isEmpty())
00521 {
00522 DrBase *ch = ((DrListOption*)driver()->findOption("MediaType"))->findChoice(value);
00523 if (ch) setComboItem(m_papertype, ch->get("text"));
00524 }
00525 value = opts["InputSlot"];
00526 if (m_inputslot && m_inputslot->isEnabled() && !value.isEmpty())
00527 {
00528 DrBase *ch = ((DrListOption*)driver()->findOption("InputSlot"))->findChoice(value);
00529 if (ch) setComboItem(m_inputslot, ch->get("text"));
00530 }
00531
00532 value = opts["Duplex"];
00533 if (m_duplexbox->isEnabled() && !value.isEmpty())
00534 {
00535 int ID(0);
00536 if (value == "DuplexNoTumble" || value == "On") ID = 1;
00537 else if (value == "DuplexTumble") ID = 2;
00538 m_duplexbox->setButton(ID);
00539 slotDuplexChanged(ID);
00540 }
00541 }
00542 else
00543 {
00544
00545 value = opts["media"];
00546 if (!value.isEmpty())
00547 {
00548 int index(-1);
00549 QStringList l = QStringList::split(',',value,false);
00550 for(QStringList::ConstIterator it = l.begin(); it != l.end(); ++it)
00551 {
00552 value = *it;
00553
00554 if ((index=findOption(default_size,DEFAULT_SIZE,value)) >= 0)
00555 m_pagesize->setCurrentItem(index);
00556 else if ((index=findOption(default_type,DEFAULT_TYPE,value)) >= 0)
00557 m_papertype->setCurrentItem(index);
00558 else if ((index=findOption(default_source,DEFAULT_SOURCE,value)) >= 0)
00559 m_inputslot->setCurrentItem(index);
00560 else
00561 kdWarning() << "media option '" << value << "' not handled." << endl;
00562 }
00563 }
00564
00565
00566 value = opts["sides"];
00567 int ID(0);
00568 if (value == "two-sided-long-edge") ID = 1;
00569 else if (value == "two-sided-short-edge") ID = 2;
00570 m_duplexbox->setButton(ID);
00571 slotDuplexChanged(ID);
00572 }
00573
00574
00575 value = opts["job-sheets"];
00576 if (!value.isEmpty())
00577 {
00578 QStringList l = QStringList::split(',',value,false);
00579 if (l.count() > 0) setComboItem(m_startbanner,l[0]);
00580 if (l.count() > 1) setComboItem(m_endbanner,l[1]);
00581 }
00582
00583
00584 value = opts["orientation-requested"];
00585 if (!value.isEmpty())
00586 {
00587 bool ok;
00588 int ID = value.toInt(&ok)-3;
00589 if (ok)
00590 {
00591 m_orientbox->setButton(ID);
00592 slotOrientationChanged(ID);
00593 }
00594 }
00595
00596
00597 value = opts["number-up"];
00598 if (!value.isEmpty())
00599 {
00600 bool ok;
00601 int ID = QMIN(value.toInt(&ok)-1,2);
00602 if (ok)
00603 {
00604 m_nupbox->setButton(ID);
00605 slotNupChanged(ID);
00606 }
00607 }
00608
00609 if ( m_orientbox->isEnabled() )
00610 m_orientbox->setDisabled( opts[ "kde-orientation-fixed" ] == "1" );
00611 if ( m_pagesize->isEnabled() )
00612 m_pagesize->setDisabled( opts[ "kde-pagesize-fixed" ] == "1" );
00613 }
00614
00615 void KPGeneralPage::getOptions(QMap<QString,QString>& opts, bool incldef)
00616 {
00617 QString value;
00618
00619 if (driver())
00620 {
00621 DrListOption *opt;
00622 if ((opt=(DrListOption*)driver()->findOption("PageSize")) != NULL)
00623 {
00624 DrBase *ch = opt->choices()->at(m_pagesize->currentItem());
00625 if (incldef || ch->name() != opt->get("default")) opts["PageSize"] = ch->name();
00626 }
00627 if ((opt=(DrListOption*)driver()->findOption("MediaType")) != NULL)
00628 {
00629 DrBase *ch = opt->choices()->at(m_papertype->currentItem());
00630 if (incldef || ch->name() != opt->get("default")) opts["MediaType"] = ch->name();
00631 }
00632 if ((opt=(DrListOption*)driver()->findOption("InputSlot")) != NULL)
00633 {
00634 DrBase *ch = opt->choices()->at(m_inputslot->currentItem());
00635 if (incldef || ch->name() != opt->get("default")) opts["InputSlot"] = ch->name();
00636 }
00637
00638 if (m_duplexbox->isEnabled() && (opt=(DrListOption*)driver()->findOption("Duplex")) != NULL)
00639 {
00640 bool twoChoices = ( m_duplexbox->count() == 2 );
00641 switch (m_duplexbox->id(m_duplexbox->selected()))
00642 {
00643 case DUPLEX_NONE_ID: value = ( twoChoices ? "Off" : "None" ); break;
00644 case DUPLEX_LONG_ID: value = ( twoChoices ? "On" : "DuplexNoTumble" ); break;
00645 case DUPLEX_SHORT_ID: value = "DuplexTumble"; break;
00646 }
00647 if (incldef || value != opt->get("default")) opts["Duplex"] = value;
00648 }
00649 }
00650 else
00651 {
00652 value = QString("%1,%2,%3").arg(default_size[m_pagesize->currentItem()*2]).arg(default_type[m_papertype->currentItem()*2]).arg(default_source[m_inputslot->currentItem()*2]);
00653 opts["media"] = value;
00654
00655 if (m_duplexbox->isEnabled())
00656 {
00657 switch (m_duplexbox->id(m_duplexbox->selected()))
00658 {
00659 case 0: value = "one-sided"; break;
00660 case 1: value = "two-sided-long-edge"; break;
00661 case 2: value = "two-sided-short-edge"; break;
00662 }
00663 opts["sides"] = value;
00664 }
00665 }
00666
00667 value = QString::number(m_orientbox->id(m_orientbox->selected())+3);
00668 if (value != "3" || incldef) opts["orientation-requested"] = value;
00669
00670 if (m_nupbox->isEnabled())
00671 {
00672 switch (m_nupbox->id(m_nupbox->selected()))
00673 {
00674 case 0: value = "1"; break;
00675 case 1: value = "2"; break;
00676 case 2: value = "4"; break;
00677 }
00678 if (value != "1" || incldef) opts["number-up"] = value;
00679 }
00680
00681 if (m_bannerbox->isEnabled())
00682 {
00683 QStringList l = QStringList::split(',',printer()->option("kde-banners"),false);
00684 if (incldef || (l.count() == 2 && (l[0] != m_startbanner->currentText() || l[1] != m_endbanner->currentText()))
00685 || (l.count() == 0 && (m_startbanner->currentText() != "none" || m_endbanner->currentText() != "none")))
00686 {
00687 value = QString("%1,%2").arg(m_startbanner->currentText()).arg(m_endbanner->currentText());
00688 opts["job-sheets"] = value;
00689 }
00690 }
00691 }
00692
00693 void KPGeneralPage::slotOrientationChanged(int ID)
00694 {
00695 QString iconstr;
00696 switch (ID)
00697 {
00698 case ORIENT_PORTRAIT_ID: iconstr = "kdeprint_portrait"; break;
00699 case ORIENT_LANDSCAPE_ID: iconstr = "kdeprint_landscape"; break;
00700 case ORIENT_REVPORTRAIT_ID: iconstr = "kdeprint_revportrait"; break;
00701 case ORIENT_REVLANDSCAPE_ID: iconstr = "kdeprint_revlandscape"; break;
00702 default: iconstr = "kdeprint_portrait"; break;
00703 }
00704 m_orientpix->setPixmap(UserIcon(iconstr));
00705 }
00706
00707 void KPGeneralPage::slotNupChanged(int ID)
00708 {
00709 QString iconstr;
00710 switch (ID)
00711 {
00712 case NUP_1_ID: iconstr = "kdeprint_nup1"; break;
00713 case NUP_2_ID: iconstr = "kdeprint_nup2"; break;
00714 case NUP_4_ID: iconstr = "kdeprint_nup4"; break;
00715 default: iconstr = "kdeprint_nup1"; break;
00716 }
00717 m_nuppix->setPixmap(UserIcon(iconstr));
00718 }
00719
00720 void KPGeneralPage::slotDuplexChanged(int ID)
00721 {
00722 if (m_duplexbox->isEnabled())
00723 {
00724 QString iconstr;
00725 switch (ID)
00726 {
00727 case DUPLEX_NONE_ID: iconstr = "kdeprint_duplex_none"; break;
00728 case DUPLEX_LONG_ID: iconstr = "kdeprint_duplex_long"; break;
00729 case DUPLEX_SHORT_ID: iconstr = "kdeprint_duplex_short"; break;
00730 default: iconstr = "kdeprint_duplex_none"; break;
00731 }
00732 m_duplexpix->setPixmap(UserIcon(iconstr));
00733 }
00734 }
00735 #include "kpgeneralpage.moc"