2
For general Scribus (>=1.3.2) copyright and licensing information please refer
3
to the COPYING file provided with the program. Following this notice may exist
4
a copyright and/or license notice that predates the release of Scribus 1.3.2
5
for which a new license (GPL+exception) is in place.
7
/***************************************************************************
8
cupsoptions.cpp - description
10
begin : Fre Jan 3 2003
11
copyright : (C) 2003 by Franz Schmid
12
email : Franz.Schmid@altmuehlnet.de
13
***************************************************************************/
15
/***************************************************************************
17
* This program is free software; you can redistribute it and/or modify *
18
* it under the terms of the GNU General Public License as published by *
19
* the Free Software Foundation; either version 2 of the License, or *
20
* (at your option) any later version. *
22
***************************************************************************/
24
#include "cupsoptions.h"
26
#include <QHBoxLayout>
27
#include <QVBoxLayout>
28
#include <QPushButton>
30
#include <QHeaderView>
31
#include <QTableWidget>
32
#include <QTableWidgetItem>
34
#include <QStringList>
36
#include <QSpacerItem>
38
#include "prefsmanager.h"
39
#include "prefscontext.h"
40
#include "prefsfile.h"
41
#include "commonstrings.h"
44
#include <cups/cups.h>
46
#include "util_icon.h"
48
CupsOptions::CupsOptions(QWidget* parent, QString Geraet) : QDialog( parent )
52
setWindowTitle( tr( "Printer Options" ) );
53
setWindowIcon(QIcon(loadIcon ( "AppIcon.png" )));
54
prefs = PrefsManager::instance()->prefsFile->getContext("cups_options");
55
setSizeGripEnabled(true);
56
CupsOptionsLayout = new QVBoxLayout( this );
57
CupsOptionsLayout->setSpacing( 5 );
58
CupsOptionsLayout->setMargin( 10 );
59
Table = new QTableWidget(0, 2, this);
60
Table->setSortingEnabled(false);
61
Table->setSelectionMode(QAbstractItemView::NoSelection);
62
Table->verticalHeader()->hide();
63
Table->setHorizontalHeaderItem(0, new QTableWidgetItem( tr("Option")));
64
Table->setHorizontalHeaderItem(1, new QTableWidgetItem( tr("Value")));
65
QHeaderView* headerH = Table->horizontalHeader();
66
headerH->setStretchLastSection(true);
67
headerH->setMovable(false);
68
headerH->setClickable(false);
69
headerH->setResizeMode(QHeaderView::Fixed);
70
Table->setMinimumSize(300, 100);
76
const char *filename; /* PPD filename */
77
ppd_file_t *ppd; /* PPD data */
78
ppd_group_t *group; /* Current group */
79
num_dests = cupsGetDests(&dests);
80
dest = cupsGetDest(Geraet.toLocal8Bit().constData(), NULL, num_dests, dests);
81
if (!(dest == NULL || (filename = cupsGetPPD(dest->name)) == NULL || (ppd = ppdOpenFile(filename)) == NULL))
84
cupsMarkOptions(ppd, dest->num_options, dest->options);
89
for (i = ppd->num_groups, group = ppd->groups; i > 0; i --, ++group)
92
ppd_option_t *option; /* Current option */
93
ppd_choice_t *choice; /* Current choice */
94
for (ix = group->num_options, option = group->options; ix > 0; ix --, ++option)
100
for (j = option->num_choices, choice = option->choices;
101
j > 0; j --, ++choice)
103
opts.append(QString(choice->choice));
105
Marked = QString(choice->choice);
107
if (!Marked.isEmpty())
109
Table->setRowCount(Table->rowCount()+1);
110
Table->setItem(Table->rowCount()-1, 0, new QTableWidgetItem(QString(option->text)));
111
QComboBox *item = new QComboBox( this );
112
item->setEditable(false);
113
FlagsOpt.append(item);
114
Daten.Cnum = static_cast<int>(FlagsOpt.count()-1);
115
Daten.KeyW = QString(option->keyword);
116
KeyToText[QString(option->text)] = Daten;
117
item->addItems(opts);
118
int lastSelected = prefs->getInt(QString(option->text), 0);
119
if (lastSelected >= static_cast<int>(opts.count()))
121
item->setCurrentIndex(lastSelected);
122
KeyToDefault[QString(option->text)] = Marked;
123
Table->setCellWidget(Table->rowCount()-1, 1, item);
128
cupsFreeDests(num_dests, dests);
132
Table->setRowCount(Table->rowCount()+1);
133
Table->setItem(Table->rowCount()-1, 0, new QTableWidgetItem(QString( tr("Page Set"))));
134
QComboBox *item4 = new QComboBox( this );
135
item4->setEditable(false);
136
FlagsOpt.append(item4);
137
Daten.Cnum = static_cast<int>(FlagsOpt.count()-1);
138
Daten.KeyW = "page-set";
139
KeyToText["Page Set"] = Daten;
140
item4->addItem( tr("All Pages"));
141
item4->addItem( tr("Even Pages only"));
142
item4->addItem( tr("Odd Pages only"));
143
int lastSelected = prefs->getInt( tr("Page Set"), 0);
144
if (lastSelected >= 3)
146
item4->setCurrentIndex(lastSelected);
147
KeyToDefault["Page Set"] = tr("All Pages");
148
Table->setCellWidget(Table->rowCount()-1, 1, item4);
149
Table->setRowCount(Table->rowCount()+1);
150
Table->setItem(Table->rowCount()-1, 0, new QTableWidgetItem(QString( tr("Mirror"))));
151
QComboBox *item2 = new QComboBox( this );
152
item2->setEditable(false);
153
FlagsOpt.append(item2);
154
Daten.Cnum = static_cast<int>(FlagsOpt.count()-1);
155
Daten.KeyW = "mirror";
156
KeyToText["Mirror"] = Daten;
157
item2->addItem(CommonStrings::trNo);
158
item2->addItem(CommonStrings::trYes);
159
item2->setCurrentIndex(0);
160
lastSelected = prefs->getInt( tr("Mirror"), 0);
161
if (lastSelected >= 2)
163
item2->setCurrentIndex(lastSelected);
164
KeyToDefault["Mirror"] = CommonStrings::trNo;
165
Table->setCellWidget(Table->rowCount()-1, 1, item2);
166
Table->setRowCount(Table->rowCount()+1);
167
Table->setItem(Table->rowCount()-1, 0, new QTableWidgetItem(QString( tr("Orientation"))));
168
QComboBox *item5 = new QComboBox( this );
169
item5->setEditable(false);
170
FlagsOpt.append(item5);
171
Daten.Cnum = static_cast<int>(FlagsOpt.count()-1);
172
Daten.KeyW = "orientation";
173
KeyToText["Orientation"] = Daten;
174
item5->addItem( tr("Portrait"));
175
item5->addItem( tr("Landscape"));
176
item5->setCurrentIndex(0);
177
lastSelected = prefs->getInt( tr("Orientation"), 0);
178
if (lastSelected >= 2)
180
item5->setCurrentIndex(lastSelected);
181
KeyToDefault["Orientation"] = tr("Portrait");
182
Table->setCellWidget(Table->rowCount()-1, 1, item5);
183
Table->setRowCount(Table->rowCount()+1);
184
Table->setItem(Table->rowCount()-1, 0, new QTableWidgetItem(QString( tr("N-Up Printing"))));
185
QComboBox *item3 = new QComboBox( this );
186
item3->setEditable(false);
187
FlagsOpt.append(item3);
188
Daten.Cnum = static_cast<int>(FlagsOpt.count()-1);
189
Daten.KeyW = "number-up";
190
KeyToText["N-Up Printing"] = Daten;
191
item3->addItem("1 "+ tr("Page per Sheet"));
192
item3->addItem("2 "+ tr("Pages per Sheet"));
193
item3->addItem("4 "+ tr("Pages per Sheet"));
194
item3->addItem("6 "+ tr("Pages per Sheet"));
195
item3->addItem("9 "+ tr("Pages per Sheet"));
196
item3->addItem("16 "+ tr("Pages per Sheet"));
197
lastSelected = prefs->getInt( tr("N-Up Printing"), 0);
198
if (lastSelected >= 6)
200
item3->setCurrentIndex(lastSelected);
201
KeyToDefault["N-Up Printing"] = "1 "+ tr("Page per Sheet");
202
Table->setCellWidget(Table->rowCount()-1, 1, item3);
204
Table->resizeColumnsToContents();
205
CupsOptionsLayout->addWidget( Table );
207
Layout2 = new QHBoxLayout;
208
Layout2->setSpacing( 5 );
209
Layout2->setMargin( 0 );
210
QSpacerItem* spacer = new QSpacerItem( 2, 2, QSizePolicy::Expanding, QSizePolicy::Minimum );
211
Layout2->addItem( spacer );
212
PushButton1 = new QPushButton( CommonStrings::tr_OK, this );
213
PushButton1->setDefault( true );
214
Layout2->addWidget( PushButton1 );
215
PushButton2 = new QPushButton( CommonStrings::tr_Cancel, this );
216
PushButton2->setDefault( false );
217
PushButton1->setFocus();
218
Layout2->addWidget( PushButton2 );
219
CupsOptionsLayout->addLayout( Layout2 );
220
setMinimumSize( sizeHint() );
221
resize(minimumSizeHint().expandedTo(QSize(300, 100)));
224
Table->setToolTip( "<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>" );
226
// signals and slots connections
227
connect( PushButton2, SIGNAL( clicked() ), this, SLOT( reject() ) );
228
connect( PushButton1, SIGNAL( clicked() ), this, SLOT( accept() ) );
231
CupsOptions::~CupsOptions()
233
for (int i = 0; i < Table->rowCount(); ++i)
235
QComboBox* combo = dynamic_cast<QComboBox*>(Table->cellWidget(i, 1));
237
prefs->set(Table->item(i, 0)->text(), combo->currentIndex());