Bump version to 5.0-14
[LibreOffice.git] / svtools / source / dialogs / prnsetup.cxx
blob05a7e6d9c59b37fe55e17588425ac639abae1fbc
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
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();
34 if ( nCount )
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 ) );
47 void ImplFreePrnDlgListBox( ListBox* pBox, bool bClear )
49 if ( bClear )
50 pBox->Clear();
55 Printer* ImplPrnDlgListBoxSelect( ListBox* pBox, PushButton* pPropBtn,
56 Printer* pPrinter, Printer* pTempPrinterIn )
58 VclPtr<Printer> pTempPrinter( pTempPrinterIn );
59 if ( pBox->GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND )
61 const QueueInfo* pInfo = Printer::GetQueueInfo( pBox->GetSelectEntry(), true );
62 if( pInfo)
64 if ( !pTempPrinter )
66 if ( (pPrinter->GetName() == pInfo->GetPrinterName()) &&
67 (pPrinter->GetDriverName() == pInfo->GetDriver()) )
68 pTempPrinter = VclPtr<Printer>::Create( pPrinter->GetJobSetup() );
69 else
70 pTempPrinter = VclPtr<Printer>::Create( *pInfo );
72 else
74 if ( (pTempPrinter->GetName() != pInfo->GetPrinterName()) ||
75 (pTempPrinter->GetDriverName() != pInfo->GetDriver()) )
77 pTempPrinter.disposeAndClear();
78 pTempPrinter = VclPtr<Printer>::Create( *pInfo );
82 pPropBtn->Enable( pTempPrinter->HasSupport( SUPPORT_SETUPDIALOG ) );
84 else
85 pPropBtn->Disable();
87 else
88 pPropBtn->Disable();
90 return pTempPrinter;
95 Printer* ImplPrnDlgUpdatePrinter( Printer* pPrinter, Printer* pTempPrinterIn )
97 VclPtr<Printer> pTempPrinter( pTempPrinterIn );
98 OUString aPrnName;
99 if ( pTempPrinter )
100 aPrnName = pTempPrinter->GetName();
101 else
102 aPrnName = pPrinter->GetName();
104 if ( ! Printer::GetQueueInfo( aPrnName, false ) )
106 pTempPrinter.disposeAndClear();
107 pTempPrinter = VclPtr<Printer>::Create();
110 return pTempPrinter;
115 void ImplPrnDlgUpdateQueueInfo( ListBox* pBox, QueueInfo& rInfo )
117 if ( pBox->GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND )
119 const QueueInfo* pInfo = Printer::GetQueueInfo( pBox->GetSelectEntry(), true );
120 if( pInfo )
121 rInfo = *pInfo;
127 static OUString ImplPrnDlgAddString(const OUString& rStr, const OUString& rAddStr)
129 OUString aStr(rStr);
130 if (!aStr.isEmpty())
131 aStr += "; " ;
132 return aStr + rAddStr;
137 static OUString ImplPrnDlgAddResString(const OUString& rStr, sal_uInt16 nResId)
139 return ImplPrnDlgAddString(rStr, SVT_RESSTR(nResId));
144 OUString ImplPrnDlgGetStatusText( const QueueInfo& rInfo )
146 OUString aStr;
147 PrintQueueFlags nStatus = rInfo.GetStatus();
149 // Default-Printer
150 if ( !rInfo.GetPrinterName().isEmpty() &&
151 (rInfo.GetPrinterName() == Printer::GetDefaultPrinterName()) )
152 aStr = ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_DEFPRINTER );
154 // Status
155 if ( nStatus & PrintQueueFlags::Ready )
156 aStr = ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_READY );
157 if ( nStatus & PrintQueueFlags::Paused )
158 aStr = ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_PAUSED );
159 if ( nStatus & PrintQueueFlags::PendingDeletion )
160 aStr = ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_PENDING );
161 if ( nStatus & PrintQueueFlags::Busy )
162 aStr = ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_BUSY );
163 if ( nStatus & PrintQueueFlags::Initializing )
164 aStr = ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_INITIALIZING );
165 if ( nStatus & PrintQueueFlags::Waiting )
166 aStr = ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_WAITING );
167 if ( nStatus & PrintQueueFlags::WarmingUp )
168 aStr = ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_WARMING_UP );
169 if ( nStatus & PrintQueueFlags::Processing )
170 aStr = ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_PROCESSING );
171 if ( nStatus & PrintQueueFlags::Printing )
172 aStr = ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_PRINTING );
173 if ( nStatus & PrintQueueFlags::Offline )
174 aStr = ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_OFFLINE );
175 if ( nStatus & PrintQueueFlags::Error )
176 aStr = ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_ERROR );
177 if ( nStatus & PrintQueueFlags::StatusUnknown )
178 aStr = ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_SERVER_UNKNOWN );
179 if ( nStatus & PrintQueueFlags::PaperJam )
180 aStr = ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_PAPER_JAM );
181 if ( nStatus & PrintQueueFlags::PaperOut )
182 aStr = ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_PAPER_OUT );
183 if ( nStatus & PrintQueueFlags::ManualFeed )
184 aStr = ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_MANUAL_FEED );
185 if ( nStatus & PrintQueueFlags::PaperProblem )
186 aStr = ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_PAPER_PROBLEM );
187 if ( nStatus & PrintQueueFlags::IOActive )
188 aStr = ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_IO_ACTIVE );
189 if ( nStatus & PrintQueueFlags::OutputBinFull )
190 aStr = ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_OUTPUT_BIN_FULL );
191 if ( nStatus & PrintQueueFlags::TonerLow )
192 aStr = ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_TONER_LOW );
193 if ( nStatus & PrintQueueFlags::NoToner )
194 aStr = ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_NO_TONER );
195 if ( nStatus & PrintQueueFlags::PagePunt )
196 aStr = ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_PAGE_PUNT );
197 if ( nStatus & PrintQueueFlags::UserIntervention )
198 aStr = ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_USER_INTERVENTION );
199 if ( nStatus & PrintQueueFlags::OutOfMemory )
200 aStr = ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_OUT_OF_MEMORY );
201 if ( nStatus & PrintQueueFlags::DoorOpen )
202 aStr = ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_DOOR_OPEN );
203 if ( nStatus & PrintQueueFlags::PowerSave )
204 aStr = ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_POWER_SAVE );
206 // Anzahl Jobs
207 sal_uLong nJobs = rInfo.GetJobs();
208 if ( nJobs && (nJobs != QUEUE_JOBS_DONTKNOW) )
210 OUString aJobStr( SVT_RESSTR( STR_SVT_PRNDLG_JOBCOUNT ) );
211 OUString aJobs( OUString::number( nJobs ) );
212 aStr = ImplPrnDlgAddString(aStr, aJobStr.replaceAll("%d", aJobs));
215 return aStr;
220 PrinterSetupDialog::PrinterSetupDialog(vcl::Window* pParent)
221 : ModalDialog(pParent, "PrinterSetupDialog",
222 "svt/ui/printersetupdialog.ui")
224 get(m_pLbName, "name");
225 m_pLbName->SetStyle(m_pLbName->GetStyle() | WB_SORT);
226 get(m_pBtnProperties, "properties");
227 get(m_pBtnOptions, "options");
228 get(m_pFiStatus, "status");
229 get(m_pFiType, "type");
230 get(m_pFiLocation, "location");
231 get(m_pFiComment, "comment");
233 // show options button only if link is set
234 m_pBtnOptions->Hide();
236 mpPrinter = NULL;
237 mpTempPrinter = NULL;
239 maStatusTimer.SetTimeout( IMPL_PRINTDLG_STATUS_UPDATE );
240 maStatusTimer.SetTimeoutHdl( LINK( this, PrinterSetupDialog, ImplStatusHdl ) );
241 m_pBtnProperties->SetClickHdl( LINK( this, PrinterSetupDialog, ImplPropertiesHdl ) );
242 m_pLbName->SetSelectHdl( LINK( this, PrinterSetupDialog, ImplChangePrinterHdl ) );
247 PrinterSetupDialog::~PrinterSetupDialog()
249 disposeOnce();
252 void PrinterSetupDialog::dispose()
254 ImplFreePrnDlgListBox(m_pLbName, false);
255 m_pLbName.clear();
256 m_pBtnProperties.clear();
257 m_pBtnOptions.clear();
258 m_pFiStatus.clear();
259 m_pFiType.clear();
260 m_pFiLocation.clear();
261 m_pFiComment.clear();
262 mpTempPrinter.disposeAndClear();
263 mpPrinter.clear();
264 ModalDialog::dispose();
267 void PrinterSetupDialog::SetOptionsHdl( const Link<>& rLink )
269 m_pBtnOptions->SetClickHdl( rLink );
270 m_pBtnOptions->Show( rLink.IsSet() );
273 void PrinterSetupDialog::ImplSetInfo()
275 const QueueInfo* pInfo = Printer::GetQueueInfo(m_pLbName->GetSelectEntry(), true);
276 if ( pInfo )
278 m_pFiType->SetText( pInfo->GetDriver() );
279 m_pFiLocation->SetText( pInfo->GetLocation() );
280 m_pFiComment->SetText( pInfo->GetComment() );
281 m_pFiStatus->SetText( ImplPrnDlgGetStatusText( *pInfo ) );
283 else
285 OUString aTempStr;
286 m_pFiType->SetText( aTempStr );
287 m_pFiLocation->SetText( aTempStr );
288 m_pFiComment->SetText( aTempStr );
289 m_pFiStatus->SetText( aTempStr );
295 IMPL_LINK_NOARG_TYPED(PrinterSetupDialog, ImplStatusHdl, Timer *, void)
297 QueueInfo aInfo;
298 ImplPrnDlgUpdateQueueInfo(m_pLbName, aInfo);
299 m_pFiStatus->SetText( ImplPrnDlgGetStatusText( aInfo ) );
304 IMPL_LINK_NOARG(PrinterSetupDialog, ImplPropertiesHdl)
306 if ( !mpTempPrinter )
307 mpTempPrinter = VclPtr<Printer>::Create( mpPrinter->GetJobSetup() );
308 mpTempPrinter->Setup( this );
310 return 0;
315 IMPL_LINK_NOARG(PrinterSetupDialog, ImplChangePrinterHdl)
317 mpTempPrinter = ImplPrnDlgListBoxSelect(m_pLbName, m_pBtnProperties,
318 mpPrinter, mpTempPrinter );
319 ImplSetInfo();
320 return 0;
325 bool PrinterSetupDialog::Notify( NotifyEvent& rNEvt )
327 if ( (rNEvt.GetType() == MouseNotifyEvent::GETFOCUS) && IsReallyVisible() )
328 ImplStatusHdl( &maStatusTimer );
330 return ModalDialog::Notify( rNEvt );
335 void PrinterSetupDialog::DataChanged( const DataChangedEvent& rDCEvt )
337 if ( rDCEvt.GetType() == DataChangedEventType::PRINTER )
339 mpTempPrinter = ImplPrnDlgUpdatePrinter( mpPrinter, mpTempPrinter );
340 Printer* pPrn;
341 if ( mpTempPrinter )
342 pPrn = mpTempPrinter;
343 else
344 pPrn = mpPrinter;
345 ImplFillPrnDlgListBox(pPrn, m_pLbName, m_pBtnProperties);
346 ImplSetInfo();
349 ModalDialog::DataChanged( rDCEvt );
354 short PrinterSetupDialog::Execute()
356 if ( !mpPrinter || mpPrinter->IsPrinting() || mpPrinter->IsJobActive() )
358 SAL_WARN( "svtools.dialogs", "PrinterSetupDialog::Execute() - No Printer or printer is printing" );
359 return RET_CANCEL;
362 Printer::updatePrinters();
364 ImplFillPrnDlgListBox(mpPrinter, m_pLbName, m_pBtnProperties);
365 ImplSetInfo();
366 maStatusTimer.Start();
368 // start dialog
369 short nRet = ModalDialog::Execute();
371 // update data if the dialog was terminated with OK
372 if ( nRet == RET_OK )
374 if ( mpTempPrinter )
375 mpPrinter->SetPrinterProps( mpTempPrinter );
378 maStatusTimer.Stop();
380 return nRet;
383 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */