Back to index

scribus-ng  1.3.4.dfsg+svn20071115
cupsoptions.cpp
Go to the documentation of this file.
00001 /*
00002 For general Scribus (>=1.3.2) copyright and licensing information please refer
00003 to the COPYING file provided with the program. Following this notice may exist
00004 a copyright and/or license notice that predates the release of Scribus 1.3.2
00005 for which a new license (GPL+exception) is in place.
00006 */
00007 /***************************************************************************
00008                           cupsoptions.cpp  -  description
00009                              -------------------
00010     begin                : Fre Jan 3 2003
00011     copyright            : (C) 2003 by Franz Schmid
00012     email                : Franz.Schmid@altmuehlnet.de
00013  ***************************************************************************/
00014 
00015 /***************************************************************************
00016  *                                                                         *
00017  *   This program is free software; you can redistribute it and/or modify  *
00018  *   it under the terms of the GNU General Public License as published by  *
00019  *   the Free Software Foundation; either version 2 of the License, or     *
00020  *   (at your option) any later version.                                   *
00021  *                                                                         *
00022  ***************************************************************************/
00023 
00024 #include "cupsoptions.h"
00025 #include "cupsoptions.moc"
00026 #include "prefsmanager.h"
00027 #include "prefscontext.h"
00028 #include "prefsfile.h"
00029 #include "commonstrings.h"
00030 
00031 #include "scconfig.h"
00032 
00033 #include <qstringlist.h>
00034 #ifdef HAVE_CUPS
00035 #include <cups/cups.h>
00036 #endif
00037 #include <qtooltip.h>
00038 extern QPixmap loadIcon(QString nam);
00039 
00040 CupsOptions::CupsOptions(QWidget* parent, QString Geraet) : QDialog( parent, "prin", true, 0 )
00041 {
00042        FlagsOpt.clear();
00043        setCaption( tr( "Printer Options" ) );
00044        setIcon(loadIcon("AppIcon.png"));
00045        prefs = PrefsManager::instance()->prefsFile->getContext("cups_options");
00046        setSizeGripEnabled(true);
00047        CupsOptionsLayout = new QVBoxLayout( this );
00048        CupsOptionsLayout->setSpacing( 5 );
00049        CupsOptionsLayout->setMargin( 10 );
00050        Table = new QTable( this, "Table1" );
00051        Table->setNumCols( 2 );
00052        Table->setSorting(false);
00053        Table->setSelectionMode(QTable::NoSelection);
00054        Table->setLeftMargin(0);
00055        Table->verticalHeader()->hide();
00056        Table->setMinimumSize(300, 100);
00057 #ifdef HAVE_CUPS
00058        int i;
00059        cups_dest_t *dests;
00060        cups_dest_t *dest;
00061        int num_dests;
00062        const char    *filename;    /* PPD filename */
00063        ppd_file_t    *ppd;                       /* PPD data */
00064        ppd_group_t   *group;                     /* Current group */
00065        num_dests = cupsGetDests(&dests);
00066        dest = cupsGetDest(Geraet, NULL, num_dests, dests);
00067        if (dest == NULL || (filename = cupsGetPPD(dest->name)) == NULL || (ppd = ppdOpenFile(filename)) == NULL)
00068               return;
00069        ppdMarkDefaults(ppd);
00070        cupsMarkOptions(ppd, dest->num_options, dest->options);
00071        QStringList opts;
00072        QString Marked = "";
00073        KeyToText.clear();
00074        KeyToDefault.clear();
00075        for (i = ppd->num_groups, group = ppd->groups; i > 0; i --, ++group)
00076        {
00077               int ix;
00078               ppd_option_t  *option;      /* Current option */
00079               ppd_choice_t  *choice;      /* Current choice */
00080               for (ix = group->num_options, option = group->options; ix > 0; ix --, ++option)
00081               {
00082                      int j;
00083                      Marked = "";
00084                      struct OpData Daten;
00085                      opts.clear();
00086                      for (j = option->num_choices, choice = option->choices;
00087                                    j > 0; j --, ++choice)
00088                      {
00089                             opts.append(QString(choice->choice));
00090                             if (choice->marked)
00091                                    Marked = QString(choice->choice);
00092                      }
00093                      if (!Marked.isEmpty())
00094                      {
00095                             Table->setNumRows(Table->numRows()+1);
00096                             Table->setText(Table->numRows()-1, 0, QString(option->text));
00097                      QComboBox *item = new QComboBox( true, this, "Replace" );
00098                             item->setEditable(false);
00099                      FlagsOpt.append(item);
00100                             Daten.Cnum = static_cast<int>(FlagsOpt.count()-1);
00101                             Daten.KeyW = QString(option->keyword);
00102                             KeyToText[QString(option->text)] = Daten;
00103                             item->insertStringList(opts);
00104                             int lastSelected = prefs->getInt(QString(option->text), 0);
00105                             if (lastSelected >= static_cast<int>(opts.count()))
00106                                    lastSelected = 0;
00107                             item->setCurrentItem(lastSelected);
00108                             KeyToDefault[QString(option->text)] = Marked;
00109                      Table->setCellWidget(Table->numRows()-1, 1, item);
00110                      }
00111               }
00112        }
00113        ppdClose(ppd);
00114        cupsFreeDests(num_dests, dests);
00115        struct OpData Daten;
00116 
00117        Table->setNumRows(Table->numRows()+1);
00118        Table->setText(Table->numRows()-1, 0, QString( tr("Page Set")));
00119        QComboBox *item4 = new QComboBox( true, this, "Replace" );
00120        item4->setEditable(false);
00121        FlagsOpt.append(item4);
00122        Daten.Cnum = static_cast<int>(FlagsOpt.count()-1);
00123        Daten.KeyW = "page-set";
00124        KeyToText["Page Set"] = Daten;
00125        item4->insertItem( tr("All Pages"));
00126        item4->insertItem( tr("Even Pages only"));
00127        item4->insertItem( tr("Odd Pages only"));
00128        int lastSelected = prefs->getInt( tr("Page Set"), 0);
00129        if (lastSelected >= 3)
00130               lastSelected = 0;
00131        item4->setCurrentItem(lastSelected);
00132        KeyToDefault["Page Set"] = tr("All Pages");
00133        Table->setCellWidget(Table->numRows()-1, 1, item4);
00134        Table->setNumRows(Table->numRows()+1);
00135        Table->setText(Table->numRows()-1, 0, QString( tr("Mirror")));
00136        QComboBox *item2 = new QComboBox( true, this, "Replace" );
00137        item2->setEditable(false);
00138        FlagsOpt.append(item2);
00139        Daten.Cnum = static_cast<int>(FlagsOpt.count()-1);
00140        Daten.KeyW = "mirror";
00141        KeyToText["Mirror"] = Daten;
00142        item2->insertItem(CommonStrings::trNo);
00143        item2->insertItem(CommonStrings::trYes);
00144        item2->setCurrentItem(0);
00145        lastSelected = prefs->getInt( tr("Mirror"), 0);
00146        if (lastSelected >= 2)
00147               lastSelected = 0;
00148        item2->setCurrentItem(lastSelected);
00149        KeyToDefault["Mirror"] = CommonStrings::trNo;
00150        Table->setCellWidget(Table->numRows()-1, 1, item2);
00151        Table->setNumRows(Table->numRows()+1);
00152        Table->setText(Table->numRows()-1, 0, QString( tr("Orientation")));
00153        QComboBox *item5 = new QComboBox( true, this, "Replace" );
00154        item5->setEditable(false);
00155        FlagsOpt.append(item5);
00156        Daten.Cnum = static_cast<int>(FlagsOpt.count()-1);
00157        Daten.KeyW = "orientation";
00158        KeyToText["Orientation"] = Daten;
00159        item5->insertItem( tr("Portrait"));
00160        item5->insertItem( tr("Landscape"));
00161        item5->setCurrentItem(0);
00162        lastSelected = prefs->getInt( tr("Orientation"), 0);
00163        if (lastSelected >= 2)
00164               lastSelected = 0;
00165        item5->setCurrentItem(lastSelected);
00166        KeyToDefault["Orientation"] = tr("Portrait");
00167        Table->setCellWidget(Table->numRows()-1, 1, item5);
00168        Table->setNumRows(Table->numRows()+1);
00169        Table->setText(Table->numRows()-1, 0, QString( tr("N-Up Printing")));
00170        QComboBox *item3 = new QComboBox( true, this, "Replace" );
00171        item3->setEditable(false);
00172        FlagsOpt.append(item3);
00173        Daten.Cnum = static_cast<int>(FlagsOpt.count()-1);
00174        Daten.KeyW = "number-up";
00175        KeyToText["N-Up Printing"] = Daten;
00176        item3->insertItem("1 "+ tr("Page per Sheet"));
00177        item3->insertItem("2 "+ tr("Pages per Sheet"));
00178        item3->insertItem("4 "+ tr("Pages per Sheet"));
00179        item3->insertItem("6 "+ tr("Pages per Sheet"));
00180        item3->insertItem("9 "+ tr("Pages per Sheet"));
00181        item3->insertItem("16 "+ tr("Pages per Sheet"));
00182        lastSelected = prefs->getInt( tr("N-Up Printing"), 0);
00183        if (lastSelected >= 6)
00184               lastSelected = 0;
00185        item3->setCurrentItem(lastSelected);
00186        KeyToDefault["N-Up Printing"] = "1 "+ tr("Page per Sheet");
00187        Table->setCellWidget(Table->numRows()-1, 1, item3);
00188 #endif
00189        Table->adjustColumn(0);
00190        Table->setColumnStretchable(1, true);
00191        Table->adjustColumn(1);
00192        Header = Table->horizontalHeader();
00193        Header->setLabel(0, tr("Option"));
00194        Header->setLabel(1, tr("Value"));
00195        CupsOptionsLayout->addWidget( Table );
00196 
00197        Layout2 = new QHBoxLayout;
00198        Layout2->setSpacing( 6 );
00199        Layout2->setMargin( 0 );
00200        QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
00201        Layout2->addItem( spacer );
00202        PushButton1 = new QPushButton( CommonStrings::tr_OK, this, "PushButton1" );
00203        PushButton1->setDefault( true );
00204        Layout2->addWidget( PushButton1 );
00205        PushButton2 = new QPushButton( CommonStrings::tr_Cancel, this, "PushButton1_2" );
00206        PushButton2->setDefault( false );
00207        PushButton1->setFocus();
00208        Layout2->addWidget( PushButton2 );
00209        CupsOptionsLayout->addLayout( Layout2 );
00210        setMinimumSize( sizeHint() );
00211        resize(minimumSizeHint().expandedTo(QSize(300, 100)));
00212 
00213 //tooltips
00214        QToolTip::add( Table, "<qt>" + tr( "This panel displays various CUPS options when printing. The exact parameters available will depend on your printer driver. You can confirm CUPS support by selecting Help > About. Look for the listings: C-C-T These equate to C=CUPS C=littlecms T=TIFF support. Missing library support is indicated by a *" ) + "</qt>" );
00215 
00216     // signals and slots connections
00217        connect( PushButton2, SIGNAL( clicked() ), this, SLOT( reject() ) );
00218        connect( PushButton1, SIGNAL( clicked() ), this, SLOT( accept() ) );
00219 }
00220 
00221 CupsOptions::~CupsOptions()
00222 {
00223        for (int i = 0; i < Table->numRows(); ++i)
00224        {
00225               QComboBox* combo = dynamic_cast<QComboBox*>(Table->cellWidget(i, 1));
00226               if (combo)
00227                      prefs->set(Table->text(i, 0), combo->currentItem());
00228        }
00229 }