1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <svtools/prnsetup.hxx>
21 #include <svtools/svtools.hrc>
22 #include <svtools/svtresid.hxx>
23 #include <vcl/print.hxx>
25 // =======================================================================
27 void ImplFillPrnDlgListBox( const Printer
* pPrinter
,
28 ListBox
* pBox
, PushButton
* pPropBtn
)
30 ImplFreePrnDlgListBox( pBox
);
32 const std::vector
<OUString
>& rPrinters
= Printer::GetPrinterQueues();
33 unsigned int nCount
= rPrinters
.size();
36 for( unsigned int i
= 0; i
< nCount
; i
++ )
37 pBox
->InsertEntry( rPrinters
[i
] );
38 pBox
->SelectEntry( pPrinter
->GetName() );
41 pBox
->Enable( nCount
!= 0 );
42 pPropBtn
->Show( pPrinter
->HasSupport( SUPPORT_SETUPDIALOG
) );
45 // -----------------------------------------------------------------------
47 void ImplFreePrnDlgListBox( ListBox
* pBox
, sal_Bool bClear
)
53 // -----------------------------------------------------------------------
55 Printer
* ImplPrnDlgListBoxSelect( ListBox
* pBox
, PushButton
* pPropBtn
,
56 Printer
* pPrinter
, Printer
* pTempPrinter
)
58 if ( pBox
->GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND
)
60 const QueueInfo
* pInfo
= Printer::GetQueueInfo( pBox
->GetSelectEntry(), true );
65 if ( (pPrinter
->GetName() == pInfo
->GetPrinterName()) &&
66 (pPrinter
->GetDriverName() == pInfo
->GetDriver()) )
67 pTempPrinter
= new Printer( pPrinter
->GetJobSetup() );
69 pTempPrinter
= new Printer( *pInfo
);
73 if ( (pTempPrinter
->GetName() != pInfo
->GetPrinterName()) ||
74 (pTempPrinter
->GetDriverName() != pInfo
->GetDriver()) )
77 pTempPrinter
= new Printer( *pInfo
);
81 pPropBtn
->Enable( pTempPrinter
->HasSupport( SUPPORT_SETUPDIALOG
) );
92 // -----------------------------------------------------------------------
94 Printer
* ImplPrnDlgUpdatePrinter( Printer
* pPrinter
, Printer
* pTempPrinter
)
98 aPrnName
= pTempPrinter
->GetName();
100 aPrnName
= pPrinter
->GetName();
102 if ( ! Printer::GetQueueInfo( aPrnName
, false ) )
106 pTempPrinter
= new Printer
;
112 // -----------------------------------------------------------------------
114 void ImplPrnDlgUpdateQueueInfo( ListBox
* pBox
, QueueInfo
& rInfo
)
116 if ( pBox
->GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND
)
118 const QueueInfo
* pInfo
= Printer::GetQueueInfo( pBox
->GetSelectEntry(), true );
124 // -----------------------------------------------------------------------
126 static void ImplPrnDlgAddString( XubString
& rStr
, const XubString
& rAddStr
)
129 rStr
.AppendAscii( "; " );
133 // -----------------------------------------------------------------------
135 static void ImplPrnDlgAddResString( XubString
& rStr
, sal_uInt16 nResId
)
137 ImplPrnDlgAddString( rStr
, SVT_RESSTR(nResId
) );
140 // -----------------------------------------------------------------------
142 XubString
ImplPrnDlgGetStatusText( const QueueInfo
& rInfo
)
145 sal_uLong nStatus
= rInfo
.GetStatus();
148 if ( !rInfo
.GetPrinterName().isEmpty() &&
149 (rInfo
.GetPrinterName() == Printer::GetDefaultPrinterName()) )
150 ImplPrnDlgAddResString( aStr
, STR_SVT_PRNDLG_DEFPRINTER
);
153 if ( nStatus
& QUEUE_STATUS_READY
)
154 ImplPrnDlgAddResString( aStr
, STR_SVT_PRNDLG_READY
);
155 if ( nStatus
& QUEUE_STATUS_PAUSED
)
156 ImplPrnDlgAddResString( aStr
, STR_SVT_PRNDLG_PAUSED
);
157 if ( nStatus
& QUEUE_STATUS_PENDING_DELETION
)
158 ImplPrnDlgAddResString( aStr
, STR_SVT_PRNDLG_PENDING
);
159 if ( nStatus
& QUEUE_STATUS_BUSY
)
160 ImplPrnDlgAddResString( aStr
, STR_SVT_PRNDLG_BUSY
);
161 if ( nStatus
& QUEUE_STATUS_INITIALIZING
)
162 ImplPrnDlgAddResString( aStr
, STR_SVT_PRNDLG_INITIALIZING
);
163 if ( nStatus
& QUEUE_STATUS_WAITING
)
164 ImplPrnDlgAddResString( aStr
, STR_SVT_PRNDLG_WAITING
);
165 if ( nStatus
& QUEUE_STATUS_WARMING_UP
)
166 ImplPrnDlgAddResString( aStr
, STR_SVT_PRNDLG_WARMING_UP
);
167 if ( nStatus
& QUEUE_STATUS_PROCESSING
)
168 ImplPrnDlgAddResString( aStr
, STR_SVT_PRNDLG_PROCESSING
);
169 if ( nStatus
& QUEUE_STATUS_PRINTING
)
170 ImplPrnDlgAddResString( aStr
, STR_SVT_PRNDLG_PRINTING
);
171 if ( nStatus
& QUEUE_STATUS_OFFLINE
)
172 ImplPrnDlgAddResString( aStr
, STR_SVT_PRNDLG_OFFLINE
);
173 if ( nStatus
& QUEUE_STATUS_ERROR
)
174 ImplPrnDlgAddResString( aStr
, STR_SVT_PRNDLG_ERROR
);
175 if ( nStatus
& QUEUE_STATUS_SERVER_UNKNOWN
)
176 ImplPrnDlgAddResString( aStr
, STR_SVT_PRNDLG_SERVER_UNKNOWN
);
177 if ( nStatus
& QUEUE_STATUS_PAPER_JAM
)
178 ImplPrnDlgAddResString( aStr
, STR_SVT_PRNDLG_PAPER_JAM
);
179 if ( nStatus
& QUEUE_STATUS_PAPER_OUT
)
180 ImplPrnDlgAddResString( aStr
, STR_SVT_PRNDLG_PAPER_OUT
);
181 if ( nStatus
& QUEUE_STATUS_MANUAL_FEED
)
182 ImplPrnDlgAddResString( aStr
, STR_SVT_PRNDLG_MANUAL_FEED
);
183 if ( nStatus
& QUEUE_STATUS_PAPER_PROBLEM
)
184 ImplPrnDlgAddResString( aStr
, STR_SVT_PRNDLG_PAPER_PROBLEM
);
185 if ( nStatus
& QUEUE_STATUS_IO_ACTIVE
)
186 ImplPrnDlgAddResString( aStr
, STR_SVT_PRNDLG_IO_ACTIVE
);
187 if ( nStatus
& QUEUE_STATUS_OUTPUT_BIN_FULL
)
188 ImplPrnDlgAddResString( aStr
, STR_SVT_PRNDLG_OUTPUT_BIN_FULL
);
189 if ( nStatus
& QUEUE_STATUS_TONER_LOW
)
190 ImplPrnDlgAddResString( aStr
, STR_SVT_PRNDLG_TONER_LOW
);
191 if ( nStatus
& QUEUE_STATUS_NO_TONER
)
192 ImplPrnDlgAddResString( aStr
, STR_SVT_PRNDLG_NO_TONER
);
193 if ( nStatus
& QUEUE_STATUS_PAGE_PUNT
)
194 ImplPrnDlgAddResString( aStr
, STR_SVT_PRNDLG_PAGE_PUNT
);
195 if ( nStatus
& QUEUE_STATUS_USER_INTERVENTION
)
196 ImplPrnDlgAddResString( aStr
, STR_SVT_PRNDLG_USER_INTERVENTION
);
197 if ( nStatus
& QUEUE_STATUS_OUT_OF_MEMORY
)
198 ImplPrnDlgAddResString( aStr
, STR_SVT_PRNDLG_OUT_OF_MEMORY
);
199 if ( nStatus
& QUEUE_STATUS_DOOR_OPEN
)
200 ImplPrnDlgAddResString( aStr
, STR_SVT_PRNDLG_DOOR_OPEN
);
201 if ( nStatus
& QUEUE_STATUS_POWER_SAVE
)
202 ImplPrnDlgAddResString( aStr
, STR_SVT_PRNDLG_POWER_SAVE
);
205 sal_uLong nJobs
= rInfo
.GetJobs();
206 if ( nJobs
&& (nJobs
!= QUEUE_JOBS_DONTKNOW
) )
208 XubString
aJobStr( SVT_RESSTR( STR_SVT_PRNDLG_JOBCOUNT
) );
209 XubString
aJobs( OUString::number( nJobs
) );
210 aJobStr
.SearchAndReplaceAscii( "%d", aJobs
);
211 ImplPrnDlgAddString( aStr
, aJobStr
);
217 // =======================================================================
219 PrinterSetupDialog::PrinterSetupDialog(Window
* pParent
)
220 : ModalDialog(pParent
, "PrinterSetupDialog",
221 "svt/ui/printersetupdialog.ui")
223 get(m_pLbName
, "name");
224 m_pLbName
->SetStyle(m_pLbName
->GetStyle() | WB_SORT
);
225 get(m_pBtnProperties
, "properties");
226 get(m_pBtnOptions
, "options");
227 get(m_pFiStatus
, "status");
228 get(m_pFiType
, "type");
229 get(m_pFiLocation
, "location");
230 get(m_pFiComment
, "comment");
232 // show options button only if link is set
233 m_pBtnOptions
->Hide();
236 mpTempPrinter
= NULL
;
238 maStatusTimer
.SetTimeout( IMPL_PRINTDLG_STATUS_UPDATE
);
239 maStatusTimer
.SetTimeoutHdl( LINK( this, PrinterSetupDialog
, ImplStatusHdl
) );
240 m_pBtnProperties
->SetClickHdl( LINK( this, PrinterSetupDialog
, ImplPropertiesHdl
) );
241 m_pLbName
->SetSelectHdl( LINK( this, PrinterSetupDialog
, ImplChangePrinterHdl
) );
244 // -----------------------------------------------------------------------
246 PrinterSetupDialog::~PrinterSetupDialog()
248 ImplFreePrnDlgListBox(m_pLbName
, sal_False
);
249 delete mpTempPrinter
;
252 // -----------------------------------------------------------------------
254 void PrinterSetupDialog::SetOptionsHdl( const Link
& rLink
)
256 m_pBtnOptions
->SetClickHdl( rLink
);
257 m_pBtnOptions
->Show( rLink
.IsSet() );
260 void PrinterSetupDialog::ImplSetInfo()
262 const QueueInfo
* pInfo
= Printer::GetQueueInfo(m_pLbName
->GetSelectEntry(), true);
265 m_pFiType
->SetText( pInfo
->GetDriver() );
266 m_pFiLocation
->SetText( pInfo
->GetLocation() );
267 m_pFiComment
->SetText( pInfo
->GetComment() );
268 m_pFiStatus
->SetText( ImplPrnDlgGetStatusText( *pInfo
) );
273 m_pFiType
->SetText( aTempStr
);
274 m_pFiLocation
->SetText( aTempStr
);
275 m_pFiComment
->SetText( aTempStr
);
276 m_pFiStatus
->SetText( aTempStr
);
280 // -----------------------------------------------------------------------
282 IMPL_LINK_NOARG(PrinterSetupDialog
, ImplStatusHdl
)
285 ImplPrnDlgUpdateQueueInfo(m_pLbName
, aInfo
);
286 m_pFiStatus
->SetText( ImplPrnDlgGetStatusText( aInfo
) );
291 // -----------------------------------------------------------------------
293 IMPL_LINK_NOARG(PrinterSetupDialog
, ImplPropertiesHdl
)
295 if ( !mpTempPrinter
)
296 mpTempPrinter
= new Printer( mpPrinter
->GetJobSetup() );
297 mpTempPrinter
->Setup( this );
302 // -----------------------------------------------------------------------
304 IMPL_LINK_NOARG(PrinterSetupDialog
, ImplChangePrinterHdl
)
306 mpTempPrinter
= ImplPrnDlgListBoxSelect(m_pLbName
, m_pBtnProperties
,
307 mpPrinter
, mpTempPrinter
);
312 // -----------------------------------------------------------------------
314 long PrinterSetupDialog::Notify( NotifyEvent
& rNEvt
)
316 if ( (rNEvt
.GetType() == EVENT_GETFOCUS
) && IsReallyVisible() )
317 ImplStatusHdl( &maStatusTimer
);
319 return ModalDialog::Notify( rNEvt
);
322 // -----------------------------------------------------------------------
324 void PrinterSetupDialog::DataChanged( const DataChangedEvent
& rDCEvt
)
326 if ( rDCEvt
.GetType() == DATACHANGED_PRINTER
)
328 mpTempPrinter
= ImplPrnDlgUpdatePrinter( mpPrinter
, mpTempPrinter
);
331 pPrn
= mpTempPrinter
;
334 ImplFillPrnDlgListBox(pPrn
, m_pLbName
, m_pBtnProperties
);
338 ModalDialog::DataChanged( rDCEvt
);
341 // -----------------------------------------------------------------------
343 short PrinterSetupDialog::Execute()
345 if ( !mpPrinter
|| mpPrinter
->IsPrinting() || mpPrinter
->IsJobActive() )
347 SAL_WARN( "svtools.dialogs", "PrinterSetupDialog::Execute() - No Printer or printer is printing" );
351 Printer::updatePrinters();
353 ImplFillPrnDlgListBox(mpPrinter
, m_pLbName
, m_pBtnProperties
);
355 maStatusTimer
.Start();
358 short nRet
= ModalDialog::Execute();
360 // Wenn Dialog mit OK beendet wurde, dann die Daten updaten
361 if ( nRet
== sal_True
)
364 mpPrinter
->SetPrinterProps( mpTempPrinter
);
367 maStatusTimer
.Stop();
372 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */