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

tdeprint

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

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
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeprint by doxygen 1.7.6.1
This website is maintained by Timothy Pearson.