1 /**************************************************************************
2 *   Copyright (C) 2005-2020 by Oleksandr Shneyder                         *
3 *                              <o.shneyder@phoca-gmbh.de>                 *
4 *                                                                         *
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.                          *
13 *                                                                         *
14 *   You should have received a copy of the GNU General Public License     *
15 *   along with this program.  If not, see <https://www.gnu.org/licenses/>. *
16 ***************************************************************************/
17 
18 #include "cupsprint.h"
19 #include "cupsprintwidget.h"
20 #ifndef Q_OS_WIN
21 #include "x2gologdebug.h"
22 #include "cupsprintersettingsdialog.h"
23 
CUPSPrintWidget(QWidget * parent)24 CUPSPrintWidget::CUPSPrintWidget ( QWidget* parent )
25 		: QWidget ( parent )
26 {
27 	m_cups=new CUPSPrint;
28 	ui.setupUi ( this );
29 
30 	ui.cbPrinters->addItems ( m_cups->getPrinters() );
31 	int defind=ui.cbPrinters->findText ( m_cups->getDefaultUserPrinter() );
32 	if ( defind!=-1 )
33 	{
34 		ui.cbPrinters->setCurrentIndex ( defind );
35 		slot_printerSelected ( defind );
36 	}
37 	connect ( ui.cbPrinters,
38 	          SIGNAL ( currentIndexChanged ( int ) ),
39 	          this,SLOT ( slot_printerSelected ( int ) ) ) ;
40 
41 	connect ( ui.pbProps,
42 	          SIGNAL ( clicked() ),
43 	          this, SLOT ( slot_printerSettings() ) );
44 }
45 
46 
~CUPSPrintWidget()47 CUPSPrintWidget::~CUPSPrintWidget()
48 {
49 	delete m_cups;
50 }
51 
52 
slot_printerSelected(int index)53 void CUPSPrintWidget::slot_printerSelected ( int index )
54 {
55 	if ( index == -1 )
56 		return;
57 	QString info;
58 	bool acceptJobs;
59 	QString location;
60 	QString model;
61 	CUPSPrint::printState state;
62 	QString stateReason;
63 	if ( !m_cups->getPrinterInfo ( ui.cbPrinters->currentText(),
64 	                               info,acceptJobs,
65 	                               location,model,state,stateReason ) )
66 		return;
67 	QString stText;
68 	switch ( state )
69 	{
70 		case CUPSPrint::IDLE:
71 			stText=tr ( "Idle" );
72 			break;
73 		case CUPSPrint::PRINTING:
74 			stText=tr ( "Printing" );
75 			break;
76 		case CUPSPrint::STOPPED:
77 			stText=tr ( "Stopped" );
78 			break;
79 		default:
80 			break;
81 	}
82 	if ( stateReason.length() >0 && stateReason != "none" )
83 		stText+= " ("+stateReason+")";
84 	ui.lState->setText ( stText );
85 
86 	( acceptJobs ) ?ui.lJAccept->setText (
87 	    tr ( "Yes" ) ) :ui.lJAccept->setText ( tr ( "No" ) );
88 
89 	ui.lType->setText ( info );
90 	ui.lLocation->setText ( location );
91 	ui.lComment->setText ( model );
92 }
93 
94 
slot_printerSettings()95 void CUPSPrintWidget::slot_printerSettings()
96 {
97 	CUPSPrinterSettingsDialog dlg ( ui.cbPrinters->currentText(),
98 	                                m_cups,this );
99 	dlg.exec();
100 }
101 
savePrinter()102 void CUPSPrintWidget::savePrinter()
103 {
104 	m_cups->setDefaultUserPrinter ( ui.cbPrinters->currentText() );
105 }
106 #endif
107