Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <vcl/print.hxx>
30 : :
31 : : #include <svtools/svtresid.hxx>
32 : : #include "prnsetup.hrc"
33 : : #include <svtools/prnsetup.hxx>
34 : :
35 : : // =======================================================================
36 : :
37 : 0 : void ImplFillPrnDlgListBox( const Printer* pPrinter,
38 : : ListBox* pBox, PushButton* pPropBtn )
39 : : {
40 : 0 : ImplFreePrnDlgListBox( pBox );
41 : :
42 : 0 : const std::vector<rtl::OUString>& rPrinters = Printer::GetPrinterQueues();
43 : 0 : unsigned int nCount = rPrinters.size();
44 [ # # ]: 0 : if ( nCount )
45 : : {
46 [ # # ]: 0 : for( unsigned int i = 0; i < nCount; i++ )
47 [ # # ]: 0 : pBox->InsertEntry( rPrinters[i] );
48 [ # # ]: 0 : pBox->SelectEntry( pPrinter->GetName() );
49 : : }
50 : :
51 : 0 : pBox->Enable( nCount != 0 );
52 : 0 : pPropBtn->Show( pPrinter->HasSupport( SUPPORT_SETUPDIALOG ) );
53 : 0 : }
54 : :
55 : : // -----------------------------------------------------------------------
56 : :
57 : 0 : void ImplFreePrnDlgListBox( ListBox* pBox, sal_Bool bClear )
58 : : {
59 [ # # ]: 0 : if ( bClear )
60 : 0 : pBox->Clear();
61 : 0 : }
62 : :
63 : : // -----------------------------------------------------------------------
64 : :
65 : 0 : Printer* ImplPrnDlgListBoxSelect( ListBox* pBox, PushButton* pPropBtn,
66 : : Printer* pPrinter, Printer* pTempPrinter )
67 : : {
68 [ # # ]: 0 : if ( pBox->GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND )
69 : : {
70 [ # # ][ # # ]: 0 : const QueueInfo* pInfo = Printer::GetQueueInfo( pBox->GetSelectEntry(), true );
71 [ # # ]: 0 : if( pInfo)
72 : : {
73 [ # # ]: 0 : if ( !pTempPrinter )
74 : : {
75 [ # # # # ]: 0 : if ( (pPrinter->GetName() == pInfo->GetPrinterName()) &&
[ # # ]
76 : 0 : (pPrinter->GetDriverName() == pInfo->GetDriver()) )
77 [ # # ]: 0 : pTempPrinter = new Printer( pPrinter->GetJobSetup() );
78 : : else
79 [ # # ]: 0 : pTempPrinter = new Printer( *pInfo );
80 : : }
81 : : else
82 : : {
83 [ # # # # ]: 0 : if ( (pTempPrinter->GetName() != pInfo->GetPrinterName()) ||
[ # # ]
84 : 0 : (pTempPrinter->GetDriverName() != pInfo->GetDriver()) )
85 : : {
86 [ # # ]: 0 : delete pTempPrinter;
87 [ # # ]: 0 : pTempPrinter = new Printer( *pInfo );
88 : : }
89 : : }
90 : :
91 : 0 : pPropBtn->Enable( pTempPrinter->HasSupport( SUPPORT_SETUPDIALOG ) );
92 : : }
93 : : else
94 : 0 : pPropBtn->Disable();
95 : : }
96 : : else
97 : 0 : pPropBtn->Disable();
98 : :
99 : 0 : return pTempPrinter;
100 : : }
101 : :
102 : : // -----------------------------------------------------------------------
103 : :
104 : 0 : Printer* ImplPrnDlgUpdatePrinter( Printer* pPrinter, Printer* pTempPrinter )
105 : : {
106 [ # # ]: 0 : XubString aPrnName;
107 [ # # ]: 0 : if ( pTempPrinter )
108 [ # # ]: 0 : aPrnName = pTempPrinter->GetName();
109 : : else
110 [ # # ]: 0 : aPrnName = pPrinter->GetName();
111 : :
112 [ # # ][ # # ]: 0 : if ( ! Printer::GetQueueInfo( aPrnName, false ) )
[ # # ]
113 : : {
114 [ # # ]: 0 : if ( pTempPrinter )
115 [ # # ][ # # ]: 0 : delete pTempPrinter;
116 [ # # ][ # # ]: 0 : pTempPrinter = new Printer;
117 : : }
118 : :
119 [ # # ]: 0 : return pTempPrinter;
120 : : }
121 : :
122 : : // -----------------------------------------------------------------------
123 : :
124 : 0 : void ImplPrnDlgUpdateQueueInfo( ListBox* pBox, QueueInfo& rInfo )
125 : : {
126 [ # # ]: 0 : if ( pBox->GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND )
127 : : {
128 [ # # ][ # # ]: 0 : const QueueInfo* pInfo = Printer::GetQueueInfo( pBox->GetSelectEntry(), true );
129 [ # # ]: 0 : if( pInfo )
130 : 0 : rInfo = *pInfo;
131 : : }
132 : 0 : }
133 : :
134 : : // -----------------------------------------------------------------------
135 : :
136 : 0 : static void ImplPrnDlgAddString( XubString& rStr, const XubString& rAddStr )
137 : : {
138 [ # # ]: 0 : if ( rStr.Len() )
139 : 0 : rStr.AppendAscii( "; " );
140 : 0 : rStr += rAddStr;
141 : 0 : }
142 : :
143 : : // -----------------------------------------------------------------------
144 : :
145 : 0 : static void ImplPrnDlgAddResString( XubString& rStr, sal_uInt16 nResId )
146 : : {
147 [ # # ][ # # ]: 0 : ImplPrnDlgAddString( rStr, SVT_RESSTR(nResId) );
[ # # ][ # # ]
148 : 0 : }
149 : :
150 : : // -----------------------------------------------------------------------
151 : :
152 : 0 : XubString ImplPrnDlgGetStatusText( const QueueInfo& rInfo )
153 : : {
154 : 0 : XubString aStr;
155 : 0 : sal_uLong nStatus = rInfo.GetStatus();
156 : :
157 : : // Default-Printer
158 [ # # ]: 0 : if ( !rInfo.GetPrinterName().isEmpty() &&
[ # # # # ]
159 [ # # ][ # # ]: 0 : (rInfo.GetPrinterName() == Printer::GetDefaultPrinterName()) )
[ # # ]
160 [ # # ]: 0 : ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_DEFPRINTER );
161 : :
162 : : // Status
163 [ # # ]: 0 : if ( nStatus & QUEUE_STATUS_READY )
164 [ # # ]: 0 : ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_READY );
165 [ # # ]: 0 : if ( nStatus & QUEUE_STATUS_PAUSED )
166 [ # # ]: 0 : ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_PAUSED );
167 [ # # ]: 0 : if ( nStatus & QUEUE_STATUS_PENDING_DELETION )
168 [ # # ]: 0 : ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_PENDING );
169 [ # # ]: 0 : if ( nStatus & QUEUE_STATUS_BUSY )
170 [ # # ]: 0 : ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_BUSY );
171 [ # # ]: 0 : if ( nStatus & QUEUE_STATUS_INITIALIZING )
172 [ # # ]: 0 : ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_INITIALIZING );
173 [ # # ]: 0 : if ( nStatus & QUEUE_STATUS_WAITING )
174 [ # # ]: 0 : ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_WAITING );
175 [ # # ]: 0 : if ( nStatus & QUEUE_STATUS_WARMING_UP )
176 [ # # ]: 0 : ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_WARMING_UP );
177 [ # # ]: 0 : if ( nStatus & QUEUE_STATUS_PROCESSING )
178 [ # # ]: 0 : ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_PROCESSING );
179 [ # # ]: 0 : if ( nStatus & QUEUE_STATUS_PRINTING )
180 [ # # ]: 0 : ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_PRINTING );
181 [ # # ]: 0 : if ( nStatus & QUEUE_STATUS_OFFLINE )
182 [ # # ]: 0 : ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_OFFLINE );
183 [ # # ]: 0 : if ( nStatus & QUEUE_STATUS_ERROR )
184 [ # # ]: 0 : ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_ERROR );
185 [ # # ]: 0 : if ( nStatus & QUEUE_STATUS_SERVER_UNKNOWN )
186 [ # # ]: 0 : ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_SERVER_UNKNOWN );
187 [ # # ]: 0 : if ( nStatus & QUEUE_STATUS_PAPER_JAM )
188 [ # # ]: 0 : ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_PAPER_JAM );
189 [ # # ]: 0 : if ( nStatus & QUEUE_STATUS_PAPER_OUT )
190 [ # # ]: 0 : ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_PAPER_OUT );
191 [ # # ]: 0 : if ( nStatus & QUEUE_STATUS_MANUAL_FEED )
192 [ # # ]: 0 : ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_MANUAL_FEED );
193 [ # # ]: 0 : if ( nStatus & QUEUE_STATUS_PAPER_PROBLEM )
194 [ # # ]: 0 : ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_PAPER_PROBLEM );
195 [ # # ]: 0 : if ( nStatus & QUEUE_STATUS_IO_ACTIVE )
196 [ # # ]: 0 : ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_IO_ACTIVE );
197 [ # # ]: 0 : if ( nStatus & QUEUE_STATUS_OUTPUT_BIN_FULL )
198 [ # # ]: 0 : ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_OUTPUT_BIN_FULL );
199 [ # # ]: 0 : if ( nStatus & QUEUE_STATUS_TONER_LOW )
200 [ # # ]: 0 : ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_TONER_LOW );
201 [ # # ]: 0 : if ( nStatus & QUEUE_STATUS_NO_TONER )
202 [ # # ]: 0 : ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_NO_TONER );
203 [ # # ]: 0 : if ( nStatus & QUEUE_STATUS_PAGE_PUNT )
204 [ # # ]: 0 : ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_PAGE_PUNT );
205 [ # # ]: 0 : if ( nStatus & QUEUE_STATUS_USER_INTERVENTION )
206 [ # # ]: 0 : ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_USER_INTERVENTION );
207 [ # # ]: 0 : if ( nStatus & QUEUE_STATUS_OUT_OF_MEMORY )
208 [ # # ]: 0 : ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_OUT_OF_MEMORY );
209 [ # # ]: 0 : if ( nStatus & QUEUE_STATUS_DOOR_OPEN )
210 [ # # ]: 0 : ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_DOOR_OPEN );
211 [ # # ]: 0 : if ( nStatus & QUEUE_STATUS_POWER_SAVE )
212 [ # # ]: 0 : ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_POWER_SAVE );
213 : :
214 : : // Anzahl Jobs
215 : 0 : sal_uLong nJobs = rInfo.GetJobs();
216 [ # # ][ # # ]: 0 : if ( nJobs && (nJobs != QUEUE_JOBS_DONTKNOW) )
217 : : {
218 [ # # ][ # # ]: 0 : XubString aJobStr( SVT_RESSTR( STR_SVT_PRNDLG_JOBCOUNT ) );
[ # # ]
219 [ # # ]: 0 : XubString aJobs( XubString::CreateFromInt32( nJobs ) );
220 [ # # ]: 0 : aJobStr.SearchAndReplaceAscii( "%d", aJobs );
221 [ # # ][ # # ]: 0 : ImplPrnDlgAddString( aStr, aJobStr );
[ # # ]
222 : : }
223 : :
224 : 0 : return aStr;
225 : : }
226 : :
227 : : // =======================================================================
228 : :
229 : 0 : PrinterSetupDialog::PrinterSetupDialog( Window* pWindow ) :
230 : : ModalDialog ( pWindow, SvtResId( DLG_SVT_PRNDLG_PRNSETUPDLG ) ),
231 : : maFlPrinter ( this, SvtResId( FL_PRINTER ) ),
232 : : maFtName ( this, SvtResId( FT_NAME ) ),
233 : : maLbName ( this, SvtResId( LB_NAMES ) ),
234 : : maBtnProperties ( this, SvtResId( BTN_PROPERTIES ) ),
235 : : maBtnOptions ( this, SvtResId( BTN_OPTIONS ) ),
236 : : maFtStatus ( this, SvtResId( FT_STATUS ) ),
237 : : maFiStatus ( this, SvtResId( FI_STATUS ) ),
238 : : maFtType ( this, SvtResId( FT_TYPE ) ),
239 : : maFiType ( this, SvtResId( FI_TYPE ) ),
240 : : maFtLocation ( this, SvtResId( FT_LOCATION ) ),
241 : : maFiLocation ( this, SvtResId( FI_LOCATION ) ),
242 : : maFtComment ( this, SvtResId( FT_COMMENT ) ),
243 : : maFiComment ( this, SvtResId( FI_COMMENT ) ),
244 : : maFlSepButton ( this, SvtResId( FL_SEPBUTTON ) ),
245 : : maBtnOK ( this, SvtResId( BTN_OK ) ),
246 : : maBtnCancel ( this, SvtResId( BTN_CANCEL ) ),
247 [ # # ][ # # ]: 0 : maBtnHelp ( this, SvtResId( BTN_HELP ) )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
248 : : {
249 [ # # ]: 0 : FreeResource();
250 : :
251 : : // show options button only if link is set
252 [ # # ]: 0 : maBtnOptions.Hide();
253 : :
254 : 0 : mpPrinter = NULL;
255 : 0 : mpTempPrinter = NULL;
256 : :
257 [ # # ]: 0 : maStatusTimer.SetTimeout( IMPL_PRINTDLG_STATUS_UPDATE );
258 [ # # ]: 0 : maStatusTimer.SetTimeoutHdl( LINK( this, PrinterSetupDialog, ImplStatusHdl ) );
259 [ # # ]: 0 : maBtnProperties.SetClickHdl( LINK( this, PrinterSetupDialog, ImplPropertiesHdl ) );
260 [ # # ]: 0 : maLbName.SetSelectHdl( LINK( this, PrinterSetupDialog, ImplChangePrinterHdl ) );
261 : 0 : }
262 : :
263 : : // -----------------------------------------------------------------------
264 : :
265 [ # # ][ # # ]: 0 : PrinterSetupDialog::~PrinterSetupDialog()
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
266 : : {
267 [ # # ]: 0 : ImplFreePrnDlgListBox( &maLbName, sal_False );
268 [ # # ][ # # ]: 0 : delete mpTempPrinter;
269 [ # # ]: 0 : }
270 : :
271 : : // -----------------------------------------------------------------------
272 : :
273 : 0 : void PrinterSetupDialog::SetOptionsHdl( const Link& rLink )
274 : : {
275 : 0 : maBtnOptions.SetClickHdl( rLink );
276 : 0 : maBtnOptions.Show( rLink.IsSet() );
277 : 0 : }
278 : :
279 : 0 : void PrinterSetupDialog::ImplSetInfo()
280 : : {
281 [ # # ][ # # ]: 0 : const QueueInfo* pInfo = Printer::GetQueueInfo(maLbName.GetSelectEntry(), true);
282 [ # # ]: 0 : if ( pInfo )
283 : : {
284 [ # # ]: 0 : maFiType.SetText( pInfo->GetDriver() );
285 [ # # ]: 0 : maFiLocation.SetText( pInfo->GetLocation() );
286 [ # # ]: 0 : maFiComment.SetText( pInfo->GetComment() );
287 [ # # ]: 0 : maFiStatus.SetText( ImplPrnDlgGetStatusText( *pInfo ) );
288 : : }
289 : : else
290 : : {
291 [ # # ]: 0 : XubString aTempStr;
292 [ # # ]: 0 : maFiType.SetText( aTempStr );
293 [ # # ]: 0 : maFiLocation.SetText( aTempStr );
294 [ # # ]: 0 : maFiComment.SetText( aTempStr );
295 [ # # ][ # # ]: 0 : maFiStatus.SetText( aTempStr );
296 : : }
297 : 0 : }
298 : :
299 : : // -----------------------------------------------------------------------
300 : :
301 : 0 : IMPL_LINK_NOARG(PrinterSetupDialog, ImplStatusHdl)
302 : : {
303 [ # # ]: 0 : QueueInfo aInfo;
304 [ # # ]: 0 : ImplPrnDlgUpdateQueueInfo( &maLbName, aInfo );
305 [ # # ][ # # ]: 0 : maFiStatus.SetText( ImplPrnDlgGetStatusText( aInfo ) );
[ # # ]
306 : :
307 [ # # ]: 0 : return 0;
308 : : }
309 : :
310 : : // -----------------------------------------------------------------------
311 : :
312 : 0 : IMPL_LINK_NOARG(PrinterSetupDialog, ImplPropertiesHdl)
313 : : {
314 [ # # ]: 0 : if ( !mpTempPrinter )
315 [ # # ]: 0 : mpTempPrinter = new Printer( mpPrinter->GetJobSetup() );
316 : 0 : mpTempPrinter->Setup( this );
317 : :
318 : 0 : return 0;
319 : : }
320 : :
321 : : // -----------------------------------------------------------------------
322 : :
323 : 0 : IMPL_LINK_NOARG(PrinterSetupDialog, ImplChangePrinterHdl)
324 : : {
325 : : mpTempPrinter = ImplPrnDlgListBoxSelect( &maLbName, &maBtnProperties,
326 : 0 : mpPrinter, mpTempPrinter );
327 : 0 : ImplSetInfo();
328 : 0 : return 0;
329 : : }
330 : :
331 : : // -----------------------------------------------------------------------
332 : :
333 : 0 : long PrinterSetupDialog::Notify( NotifyEvent& rNEvt )
334 : : {
335 [ # # ][ # # ]: 0 : if ( (rNEvt.GetType() == EVENT_GETFOCUS) && IsReallyVisible() )
[ # # ]
336 : 0 : ImplStatusHdl( &maStatusTimer );
337 : :
338 : 0 : return ModalDialog::Notify( rNEvt );
339 : : }
340 : :
341 : : // -----------------------------------------------------------------------
342 : :
343 : 0 : void PrinterSetupDialog::DataChanged( const DataChangedEvent& rDCEvt )
344 : : {
345 [ # # ]: 0 : if ( rDCEvt.GetType() == DATACHANGED_PRINTER )
346 : : {
347 : 0 : mpTempPrinter = ImplPrnDlgUpdatePrinter( mpPrinter, mpTempPrinter );
348 : : Printer* pPrn;
349 [ # # ]: 0 : if ( mpTempPrinter )
350 : 0 : pPrn = mpTempPrinter;
351 : : else
352 : 0 : pPrn = mpPrinter;
353 : 0 : ImplFillPrnDlgListBox( pPrn, &maLbName, &maBtnProperties );
354 : 0 : ImplSetInfo();
355 : : }
356 : :
357 : 0 : ModalDialog::DataChanged( rDCEvt );
358 : 0 : }
359 : :
360 : : // -----------------------------------------------------------------------
361 : :
362 : 0 : short PrinterSetupDialog::Execute()
363 : : {
364 [ # # ][ # # ]: 0 : if ( !mpPrinter || mpPrinter->IsPrinting() || mpPrinter->IsJobActive() )
[ # # ][ # # ]
365 : : {
366 : : SAL_WARN( "svtools.dialogs", "PrinterSetupDialog::Execute() - No Printer or printer is printing" );
367 : 0 : return sal_False;
368 : : }
369 : :
370 : 0 : Printer::updatePrinters();
371 : :
372 : 0 : ImplFillPrnDlgListBox( mpPrinter, &maLbName, &maBtnProperties );
373 : 0 : ImplSetInfo();
374 : 0 : maStatusTimer.Start();
375 : :
376 : : // Dialog starten
377 : 0 : short nRet = ModalDialog::Execute();
378 : :
379 : : // Wenn Dialog mit OK beendet wurde, dann die Daten updaten
380 [ # # ]: 0 : if ( nRet == sal_True )
381 : : {
382 [ # # ]: 0 : if ( mpTempPrinter )
383 : 0 : mpPrinter->SetPrinterProps( mpTempPrinter );
384 : : }
385 : :
386 : 0 : maStatusTimer.Stop();
387 : :
388 : 0 : return nRet;
389 : : }
390 : :
391 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|