1
/**************************************************************************
2
* Copyright (C) 2005-2015 by Oleksandr Shneyder *
3
* o.shneyder@phoca-gmbh.de *
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU General Public License as published by *
7
* the Free Software Foundation; either version 2 of the License, or *
8
* (at your option) any later version. *
9
* This program 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 *
12
* GNU General Public License for more details. *
14
* You should have received a copy of the GNU General Public License *
15
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
16
***************************************************************************/
18
#include "cupsprintersettingsdialog.h"
19
#include "cupsprint.h"
21
#include <QHeaderView>
22
#include <QMessageBox>
25
CUPSPrinterSettingsDialog::CUPSPrinterSettingsDialog (
27
CUPSPrint* cupsObject,
30
) :QDialog ( parent, flags )
35
setWindowTitle ( prnName );
38
ui.splitter->setSizes ( sz );
39
if ( !m_cups->setCurrentPrinter ( printer ) )
46
connect ( ( QObject* ) ( ui.buttonBox->button (
47
QDialogButtonBox::RestoreDefaults ) ),
48
SIGNAL ( clicked() ),this,SLOT ( slot_restoreDefaults() ) );
49
connect ( ( QObject* ) ( ui.buttonBox->button (
50
QDialogButtonBox::Save ) ),
51
SIGNAL ( clicked() ),this,SLOT ( slot_saveOptions() ) );
52
connect ( ( QObject* ) ( ui.buttonBox->button (
53
QDialogButtonBox::Cancel ) ),
54
SIGNAL ( clicked() ),this,SLOT ( reject() ) );
55
connect ( ( QObject* ) ( ui.buttonBox->button (
56
QDialogButtonBox::Ok ) ),
57
SIGNAL ( clicked() ),this,SLOT ( slot_ok() ) );
62
CUPSPrinterSettingsDialog::~CUPSPrinterSettingsDialog()
68
void CUPSPrinterSettingsDialog::setCbBox ( QComboBox* cb,
69
QString optionKeyword )
72
QStringList descriptions;
73
int cur_val=m_cups->getOptionValues ( optionKeyword,
74
values,descriptions );
76
cb->setEnabled ( false );
79
cb->addItems ( descriptions );
80
cb->setCurrentIndex ( cur_val );
84
void CUPSPrinterSettingsDialog::slot_optionSelected ( QTreeWidgetItem * current,
87
ui.optionsTree->clear();
89
if ( current->childCount() ==0 )
91
ui.gbOptions->setTitle ( current->text ( 0 ) );
92
QStringList valueNames, valueTexts;
93
int selectedValue=m_cups->
96
valueNames,valueTexts );
97
for ( int i=0;i<valueNames.size();++i )
99
QTreeWidgetItem* ritem=new QTreeWidgetItem (
101
QTreeWidgetItem::Type ) ;
102
ritem->setText ( 0,valueTexts[i] );
103
ritem->setText ( 1,valueNames[i] );
104
if ( i==selectedValue )
105
ui.optionsTree->setCurrentItem (
110
ui.gbOptions->setTitle ( tr ( "No option selected" ) );
113
void CUPSPrinterSettingsDialog::slot_valueSelected ( QTreeWidgetItem * current,
118
QTreeWidgetItem* optionItem=ui.ppdTree->currentItem();
119
QString option=optionItem->text ( 2 );
120
QString newVal=current->text ( 1 );
121
QString prevVal,prevText;
122
m_cups->getOptionValue ( option,prevVal,prevText );
123
if ( prevVal==newVal )
126
//we need change current item
127
//do it outside this function
128
setNewValue ( option,newVal ) ;
129
QTimer::singleShot ( 1, this, SLOT ( slot_reloadValues() ) );
131
m_cups->getOptionValue ( option,prevVal,prevText );
132
optionItem->setText ( 1,prevText );
133
optionItem->setText ( 3,prevVal );
138
void CUPSPrinterSettingsDialog::setGeneralTab()
140
disconnect ( ui.cbPageSize,SIGNAL ( currentIndexChanged ( int ) ),
141
this,SLOT ( slot_changePSize ( int ) ) );
142
disconnect ( ui.cbMediaType,SIGNAL ( currentIndexChanged ( int ) ),
143
this,SLOT ( slot_changePType ( int ) ) );
144
disconnect ( ui.cbInputSlot,SIGNAL ( currentIndexChanged ( int ) ),
145
this,SLOT ( slot_changeISlot ( int ) ) );
146
disconnect ( ui.rbNone,SIGNAL ( clicked ( ) ),
147
this,SLOT ( slot_changeDuplex() ) );
148
disconnect ( ui.rbShort,SIGNAL ( clicked ( ) ),
149
this,SLOT ( slot_changeDuplex() ) );
150
disconnect ( ui.rbLong,SIGNAL ( clicked ( ) ),
151
this,SLOT ( slot_changeDuplex() ) );
152
ui.cbPageSize->clear();
153
ui.cbMediaType->clear();
154
ui.cbInputSlot->clear();
155
setCbBox ( ui.cbPageSize,"PageSize" );
156
setCbBox ( ui.cbMediaType,"MediaType" );
157
setCbBox ( ui.cbInputSlot,"InputSlot" );
158
QString valueName, valueText;
159
ui.rbNone->setChecked ( true );
160
if ( m_cups->getOptionValue ( "Duplex",valueName,valueText ) )
162
if ( valueName=="DuplexTumble" )
163
ui.rbShort->setChecked ( true );
164
if ( valueName=="DuplexNoTumble" )
165
ui.rbLong->setChecked ( true );
169
ui.gbDuplex->setEnabled ( false );
170
connect ( ui.cbPageSize,SIGNAL ( currentIndexChanged ( int ) ),
171
this,SLOT ( slot_changePSize ( int ) ) );
172
connect ( ui.cbMediaType,SIGNAL ( currentIndexChanged ( int ) ),
173
this,SLOT ( slot_changePType ( int ) ) );
174
connect ( ui.cbInputSlot,SIGNAL ( currentIndexChanged ( int ) ),
175
this,SLOT ( slot_changeISlot ( int ) ) );
176
connect ( ui.rbNone,SIGNAL ( clicked ( ) ),
177
this,SLOT ( slot_changeDuplex() ) );
178
connect ( ui.rbShort,SIGNAL ( clicked ( ) ),
179
this,SLOT ( slot_changeDuplex() ) );
180
connect ( ui.rbLong,SIGNAL ( clicked ( ) ),
181
this,SLOT ( slot_changeDuplex() ) );
186
void CUPSPrinterSettingsDialog::setPPDTab()
188
disconnect ( ui.ppdTree,
189
SIGNAL ( currentItemChanged ( QTreeWidgetItem*,
190
QTreeWidgetItem* ) ),
192
SLOT ( slot_optionSelected ( QTreeWidgetItem*,
193
QTreeWidgetItem* ) ) );
195
disconnect ( ui.optionsTree,
196
SIGNAL ( currentItemChanged ( QTreeWidgetItem*,
197
QTreeWidgetItem* ) ),
199
SLOT ( slot_valueSelected ( QTreeWidgetItem*,
200
QTreeWidgetItem* ) ) );
206
CUPSPrint::printState state;
208
QString valueName,valueText;
209
!m_cups->getPrinterInfo ( printer,
211
location,model,state,stateReason ) ;
215
QTreeWidgetItem* ritem=new QTreeWidgetItem ( ( QTreeWidgetItem* ) 0,
216
QTreeWidgetItem::Type ) ;
218
ritem->setText ( 0,model );
219
ui.ppdTree->addTopLevelItem ( ritem );
220
QStringList grName, grText;
221
m_cups->getOptionGroups ( grName,grText );
222
for ( int i=0;i<grName.size();++i )
224
QTreeWidgetItem* gritem=new QTreeWidgetItem ( ritem,
225
QTreeWidgetItem::Type ) ;
226
gritem->setText ( 0,grText[i] );
227
gritem->setText ( 2,grName[i] );
228
QStringList optName, optText;
229
m_cups->getOptionsList ( grName[i],optName,optText );
230
for ( int j=0;j<optName.size();++j )
232
QTreeWidgetItem* optitem=new QTreeWidgetItem ( gritem,
233
QTreeWidgetItem::Type ) ;
234
optitem->setText ( 0,optText[j] );
235
optitem->setText ( 2,optName[j] );
236
m_cups->getOptionValue ( optName[j],valueName,
238
optitem->setText ( 1,valueText );
239
optitem->setText ( 3,valueName );
243
ui.ppdTree->expandAll();
244
ui.ppdTree->header()->resizeSections ( QHeaderView::ResizeToContents );
245
slot_optionSelected ( ritem,0l );
246
connect ( ui.ppdTree,
247
SIGNAL ( currentItemChanged ( QTreeWidgetItem*,
248
QTreeWidgetItem* ) ),
250
SLOT ( slot_optionSelected ( QTreeWidgetItem*,
251
QTreeWidgetItem* ) ) );
253
connect ( ui.optionsTree,
254
SIGNAL ( currentItemChanged ( QTreeWidgetItem*,
255
QTreeWidgetItem* ) ),
257
SLOT ( slot_valueSelected ( QTreeWidgetItem*,
258
QTreeWidgetItem* ) ) );
263
bool CUPSPrinterSettingsDialog::setNewValue ( const QString& option,
264
const QString& value )
266
QString confVal,confOpt;
267
bool res=m_cups->setValue ( option,value,confOpt,confVal );
271
tr ( "This value is in conflict with other option" );
273
m_cups->getOptionText ( confOpt,txt );
275
m_cups->getOptionValue ( confOpt,val,valt );
276
if ( confOpt.length() >0 &&confVal.length() >0 )
278
textMessage+="\n("+txt+" : "+valt+")";
281
QMessageBox::critical ( this,tr ( "Options conflict" ),
288
void CUPSPrinterSettingsDialog::slot_reloadValues()
290
if ( ui.ppdTree->currentItem() )
291
slot_optionSelected ( ui.ppdTree->currentItem(),0l );
292
QTreeWidgetItemIterator it ( ui.ppdTree );
295
if ( ( *it )->childCount() ==0 )
297
QString opt= ( *it )->text ( 2 );
299
m_cups->getOptionValue ( opt,nval,ntext );
300
if ( ( *it )->text ( 3 ) != nval )
301
( *it )->setText ( 1,ntext );
302
( *it )->setText ( 3,nval );
309
void CUPSPrinterSettingsDialog::slot_changePSize ( int ind )
311
changeFromCbBox ( "PageSize",ind );
315
void CUPSPrinterSettingsDialog::slot_changePType ( int ind )
317
changeFromCbBox ( "MediaType",ind );
320
void CUPSPrinterSettingsDialog::slot_changeISlot ( int ind )
322
changeFromCbBox ( "InputSlot",ind );
325
void CUPSPrinterSettingsDialog::changeFromCbBox ( const QString& opt, int id )
327
QStringList vals,texts;
328
m_cups->getOptionValues ( opt,vals,texts );
329
if ( vals.size() <id )
331
changeGeneralOption ( opt,vals[id] );
334
void CUPSPrinterSettingsDialog::slot_changeDuplex()
336
if ( ui.rbShort->isChecked() )
338
changeGeneralOption ( "Duplex","DuplexTumble" );
340
if ( ui.rbLong->isChecked() )
342
changeGeneralOption ( "Duplex","DuplexNoTumble" );
344
if ( ui.rbNone->isChecked() )
346
changeGeneralOption ( "Duplex","None" );
350
void CUPSPrinterSettingsDialog::changeGeneralOption ( const QString& option,
353
if ( !setNewValue ( option,val ) )
354
QTimer::singleShot ( 1, this, SLOT ( setGeneralTab() ) );
358
void CUPSPrinterSettingsDialog::slot_restoreDefaults()
360
m_cups->setDefaults();
365
void CUPSPrinterSettingsDialog::slot_saveOptions()
367
m_cups->saveOptions();
370
void CUPSPrinterSettingsDialog::slot_ok()
372
m_cups->saveOptions();