Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <unistd.h>
21 :
22 : #include "adddlg.hxx"
23 : #include "newppdlg.hxx"
24 : #include "cmddlg.hxx"
25 : #include "padialog.hrc"
26 :
27 : #include "vcl/msgbox.hxx"
28 : #include "vcl/strhelper.hxx"
29 :
30 : #include <tools/config.hxx>
31 : #include <osl/thread.h>
32 : #include <rtl/strbuf.hxx>
33 : #include <boost/unordered_set.hpp>
34 :
35 : using namespace psp;
36 : using namespace padmin;
37 : using namespace std;
38 :
39 :
40 :
41 0 : APTabPage::APTabPage( AddPrinterDialog* pParent, const ResId& rResId )
42 : : TabPage( pParent, rResId ),
43 : m_aTitle( PaResId( RID_ADDP_STR_TITLE ) ),
44 0 : m_pParent( pParent )
45 : {
46 0 : }
47 :
48 0 : APChooseDevicePage::APChooseDevicePage( AddPrinterDialog* pParent ) :
49 : APTabPage( pParent, PaResId( RID_ADDP_PAGE_CHOOSEDEV ) ),
50 : m_aPrinterBtn( this, PaResId( RID_ADDP_CHDEV_BTN_PRINTER ) ),
51 : m_aFaxBtn( this, PaResId( RID_ADDP_CHDEV_BTN_FAX ) ),
52 : m_aPDFBtn( this, PaResId( RID_ADDP_CHDEV_BTN_PDF ) ),
53 : m_aOldBtn( this, PaResId( RID_ADDP_CHDEV_BTN_OLD ) ),
54 0 : m_aOverTxt( this, PaResId( RID_ADDP_CHDEV_TXT_OVER ) )
55 : {
56 0 : FreeResource();
57 0 : m_aPrinterBtn.Check( sal_True );
58 0 : m_aFaxBtn.Check( sal_False );
59 0 : m_aPDFBtn.Check( sal_False );
60 0 : m_aOldBtn.Check( sal_False );
61 0 : if( ! AddPrinterDialog::getOldPrinterLocation().Len() )
62 0 : m_aOldBtn.Enable( sal_False );
63 0 : if( ! PrinterInfoManager::get().addOrRemovePossible() )
64 : {
65 0 : m_aPrinterBtn.Check( sal_False );
66 0 : m_aFaxBtn.Check( sal_True );
67 0 : m_aPrinterBtn.Enable( sal_False );
68 0 : m_aOldBtn.Enable( sal_False );
69 : }
70 0 : }
71 :
72 0 : APChooseDevicePage::~APChooseDevicePage()
73 : {
74 0 : }
75 :
76 0 : bool APChooseDevicePage::check()
77 : {
78 0 : return true;
79 : }
80 :
81 0 : void APChooseDevicePage::fill( PrinterInfo& rInfo )
82 : {
83 0 : if( m_aPDFBtn.IsChecked() )
84 : {
85 0 : rInfo.m_aFeatures = OUString("pdf=");
86 : }
87 0 : else if( m_aFaxBtn.IsChecked() )
88 : {
89 0 : rInfo.m_aFeatures = OUString("fax");
90 : }
91 : else
92 0 : rInfo.m_aFeatures = "";
93 0 : }
94 :
95 : //--------------------------------------------------------------------
96 :
97 0 : APChooseDriverPage::APChooseDriverPage( AddPrinterDialog* pParent )
98 : : APTabPage( pParent, PaResId( RID_ADDP_PAGE_CHOOSEDRIVER ) ),
99 : m_aDriverTxt( this, PaResId( RID_ADDP_CHDRV_TXT_DRIVER ) ),
100 : m_aDriverBox( this, PaResId( RID_ADDP_CHDRV_BOX_DRIVER ) ),
101 : m_aAddBtn( this, PaResId( RID_ADDP_CHDRV_BTN_ADD ) ),
102 : m_aRemBtn( this, PaResId( RID_ADDP_CHDRV_BTN_REMOVE ) ),
103 0 : m_aRemStr( PaResId( RID_ADDP_CHDRV_STR_REMOVE ) )
104 : {
105 0 : FreeResource();
106 0 : m_aAddBtn.SetClickHdl( LINK( this, APChooseDriverPage, ClickBtnHdl ) );
107 0 : m_aRemBtn.SetClickHdl( LINK( this, APChooseDriverPage, ClickBtnHdl ) );
108 0 : m_aDriverBox.setDelPressedLink( LINK( this, APChooseDriverPage, DelPressedHdl ) );
109 0 : updateDrivers();
110 0 : }
111 :
112 0 : APChooseDriverPage::~APChooseDriverPage()
113 : {
114 0 : for( int i = 0; i < m_aDriverBox.GetEntryCount(); i++ )
115 0 : delete (String*)m_aDriverBox.GetEntryData( i );
116 0 : }
117 :
118 0 : bool APChooseDriverPage::check()
119 : {
120 0 : return m_aDriverBox.GetSelectEntryCount() > 0;
121 : }
122 :
123 0 : void APChooseDriverPage::fill( PrinterInfo& rInfo )
124 : {
125 0 : sal_uInt16 nPos = m_aDriverBox.GetSelectEntryPos();
126 0 : OUString* pDriver = (OUString*)m_aDriverBox.GetEntryData( nPos );
127 0 : rInfo.m_aDriverName = *pDriver;
128 : #if OSL_DEBUG_LEVEL > 1
129 : fprintf( stderr, "m_aLastPrinterName = \"%s\", rInfo.m_aPrinterName = \"%s\"\n",
130 : OUStringToOString( m_aLastPrinterName, RTL_TEXTENCODING_ISO_8859_1 ).getStr(),
131 : OUStringToOString( rInfo.m_aPrinterName, RTL_TEXTENCODING_ISO_8859_1 ).getStr() );
132 : #endif
133 0 : if( rInfo.m_aPrinterName.equals( m_aLastPrinterName ) )
134 : {
135 0 : OUString aPrinter( AddPrinterDialog::uniquePrinterName( m_aDriverBox.GetEntry( nPos ) ) );
136 0 : rInfo.m_aPrinterName = m_aLastPrinterName = aPrinter;
137 : }
138 0 : }
139 :
140 0 : void APChooseDriverPage::updateDrivers( bool bRefresh, const OUString& rSelectDriver )
141 : {
142 0 : for( int k = 0; k < m_aDriverBox.GetEntryCount(); k++ )
143 0 : delete (String*)m_aDriverBox.GetEntryData( k );
144 0 : m_aDriverBox.Clear();
145 :
146 0 : std::list< OUString > aDrivers;
147 0 : psp::PPDParser::getKnownPPDDrivers( aDrivers, bRefresh );
148 :
149 0 : OUString aSelectDriver( psp::PPDParser::getPPDPrinterName( rSelectDriver ) );
150 :
151 0 : OUString aSelectedEntry;
152 0 : for( std::list< OUString >::const_iterator it = aDrivers.begin(); it != aDrivers.end(); ++it )
153 : {
154 0 : OUString aDriver( psp::PPDParser::getPPDPrinterName( *it ) );
155 0 : if( !aDriver.isEmpty() )
156 : {
157 0 : int nPos = m_aDriverBox.InsertEntry( aDriver );
158 0 : m_aDriverBox.SetEntryData( nPos, new OUString( *it ) );
159 0 : if( aDriver == aSelectDriver )
160 0 : aSelectedEntry = aDriver;
161 : }
162 0 : }
163 :
164 0 : m_aDriverBox.SelectEntry( aSelectedEntry );
165 0 : m_aRemBtn.Enable( m_aDriverBox.GetEntryCount() > 0 );
166 0 : }
167 :
168 0 : IMPL_LINK( APChooseDriverPage, DelPressedHdl, ListBox*, pListBox )
169 : {
170 0 : if( pListBox == &m_aDriverBox )
171 0 : ClickBtnHdl( &m_aRemBtn );
172 :
173 0 : return 0;
174 : }
175 :
176 0 : IMPL_LINK( APChooseDriverPage, ClickBtnHdl, PushButton*, pButton )
177 : {
178 0 : if( pButton == &m_aAddBtn )
179 : {
180 0 : PPDImportDialog aDlg( this );
181 0 : if( aDlg.Execute() )
182 : {
183 0 : const std::list< OUString >& rImported( aDlg.getImportedFiles() );
184 0 : if( rImported.empty() )
185 0 : updateDrivers( true );
186 : else
187 0 : updateDrivers( true, rImported.front() );
188 0 : }
189 : }
190 0 : else if( pButton == &m_aRemBtn )
191 : {
192 0 : rtl_TextEncoding aEncoding = osl_getThreadTextEncoding();
193 0 : PrinterInfoManager& rPIManager( PrinterInfoManager::get() );
194 :
195 0 : for( int i = 0; i < m_aDriverBox.GetSelectEntryCount(); i++ )
196 : {
197 0 : int nSelect = m_aDriverBox.GetSelectEntryPos(i);
198 0 : OUString aDriver( *(OUString*)m_aDriverBox.GetEntryData( nSelect ) );
199 0 : if( !aDriver.isEmpty() )
200 : {
201 : // never delete the default driver
202 0 : if( aDriver.equalsIgnoreAsciiCase( "SGENPRT" ) )
203 : {
204 0 : OUString aText( PaResId( RID_ERR_REMOVESGENPRT ) );
205 0 : aText = aText.replaceFirst( OUString( "%s" ), m_aDriverBox.GetSelectEntry( i ) );
206 0 : ErrorBox aErrorBox( this, WB_OK | WB_DEF_OK, aText );
207 0 : aErrorBox.SetText( m_aRemStr );
208 0 : aErrorBox.Execute();
209 0 : continue;
210 : }
211 :
212 0 : PrinterInfo aDefInfo( rPIManager.getPrinterInfo( rPIManager.getDefaultPrinter() ) );
213 : // for comparisons convert to a OUString
214 0 : OUString aPPD( aDriver );
215 0 : if( aDefInfo.m_aDriverName == aPPD )
216 : {
217 0 : OUString aText( PaResId( RID_ERR_REMOVEDEFAULTDRIVER ) );
218 0 : aText = aText.replaceFirst( OUString( "%s" ), m_aDriverBox.GetSelectEntry( i ) );
219 0 : ErrorBox aErrorBox( this, WB_OK | WB_DEF_OK, aText );
220 0 : aErrorBox.SetText( m_aRemStr );
221 0 : aErrorBox.Execute();
222 0 : continue;
223 : }
224 :
225 0 : ::std::list< OUString > aPrinters;
226 0 : ::std::list< OUString >::iterator it;
227 0 : rPIManager.listPrinters( aPrinters );
228 0 : for( it = aPrinters.begin(); it != aPrinters.end(); ++it )
229 : {
230 0 : PrinterInfo aInfo( rPIManager.getPrinterInfo( *it ) );
231 0 : if( aInfo.m_aDriverName == aPPD )
232 0 : break;
233 0 : }
234 :
235 0 : if( it != aPrinters.end() )
236 : {
237 0 : OUString aText( PaResId( RID_QUERY_DRIVERUSED ) );
238 0 : aText = aText.replaceFirst( OUString( "%s" ), m_aDriverBox.GetSelectEntry( i ) );
239 0 : QueryBox aBox( this, WB_YES_NO | WB_DEF_NO, aText );
240 0 : aBox.SetText( m_aRemStr );
241 0 : if( aBox.Execute() == RET_NO )
242 0 : continue;
243 : }
244 : else
245 : {
246 0 : OUString aText( PaResId( RID_QUERY_REMOVEDRIVER ) );
247 0 : aText = aText.replaceFirst( OUString( "%s" ), m_aDriverBox.GetSelectEntry( i ) );
248 0 : QueryBox aBox( this, WB_YES_NO | WB_DEF_NO, aText );
249 0 : aBox.SetText( m_aRemStr );
250 0 : if( aBox.Execute() == RET_NO )
251 0 : continue;
252 : }
253 :
254 : // remove the printers using this driver
255 0 : for( it = aPrinters.begin(); it != aPrinters.end(); ++it )
256 : {
257 0 : PrinterInfo aInfo( rPIManager.getPrinterInfo( *it ) );
258 0 : if( aInfo.m_aDriverName == aPPD )
259 0 : rPIManager.removePrinter( *it );
260 0 : }
261 :
262 0 : std::list< OUString > aDirs;
263 : // get only psprint's directories, not eventual system dirs
264 0 : psp::getPrinterPathList( aDirs, NULL );
265 0 : std::list< OUString >::iterator dir;
266 0 : for( dir = aDirs.begin(); dir != aDirs.end(); ++dir )
267 : {
268 0 : ::std::list< String > aFiles;
269 0 : ::std::list< String >::iterator file;
270 0 : OUStringBuffer aDir( *dir );
271 0 : aDir.append( sal_Unicode( '/' ) );
272 0 : aDir.appendAscii( PRINTER_PPDDIR );
273 0 : OUString aPPDDir( aDir.makeStringAndClear() );
274 0 : FindFiles( aPPDDir, aFiles, OUString( "PS;PPD;PS.GZ;PPD.GZ" ), true );
275 0 : for( file = aFiles.begin(); file != aFiles.end(); ++file )
276 : {
277 0 : OUString aFile( aPPDDir );
278 0 : if( !aFile.endsWith( "/" ) )
279 0 : aFile += "/";
280 0 : aFile += *file;
281 :
282 0 : int nPos = file->SearchBackward( '.' );
283 0 : if( file->Copy( 0, nPos ) == String( aPPD ) )
284 : {
285 0 : OString aSysPath(OUStringToOString(aFile, aEncoding));
286 0 : if (unlink(aSysPath.getStr()))
287 : {
288 0 : OUString aText( PaResId( RID_ERR_REMOVEDRIVERFAILED ) );
289 0 : aText = aText.replaceFirst( OUString( "%s1" ), m_aDriverBox.GetSelectEntry( i ) );
290 0 : aText = aText.replaceFirst( OUString( "%s2" ), aFile );
291 0 : ErrorBox aErrorBox( this, WB_OK | WB_DEF_OK, aText );
292 0 : aErrorBox.SetText( m_aRemStr );
293 0 : aErrorBox.Execute();
294 0 : }
295 : }
296 0 : }
297 0 : }
298 : }
299 0 : }
300 0 : updateDrivers();
301 : }
302 0 : return 0;
303 : }
304 :
305 : //--------------------------------------------------------------------
306 :
307 0 : APNamePage::APNamePage( AddPrinterDialog* pParent, const String& rInitName, DeviceKind::type eKind )
308 : : APTabPage( pParent, PaResId( RID_ADDP_PAGE_NAME ) ),
309 : m_aNameTxt(
310 : this,
311 : PaResId(
312 : eKind == DeviceKind::Printer ? RID_ADDP_NAME_TXT_NAME :
313 : eKind == DeviceKind::Fax ? RID_ADDP_NAME_TXT_FAXNAME : RID_ADDP_NAME_TXT_PDFNAME
314 0 : )
315 : ),
316 : m_aNameEdt(
317 : this,
318 : PaResId(
319 : eKind == DeviceKind::Printer ? RID_ADDP_NAME_EDT_NAME :
320 : eKind == DeviceKind::Fax ? RID_ADDP_NAME_EDT_FAXNAME : RID_ADDP_NAME_EDT_PDFNAME
321 0 : )
322 : ),
323 : m_aDefaultBox( this, PaResId( RID_ADDP_NAME_BOX_DEFAULT ) ),
324 0 : m_aFaxSwallowBox( this, PaResId( RID_ADDP_NAME_BOX_FAXSWALLOW ) )
325 : {
326 0 : FreeResource();
327 0 : if( eKind != DeviceKind::Printer )
328 0 : m_aDefaultBox.Show( sal_False );
329 : else
330 0 : m_aNameEdt.SetText( rInitName );
331 0 : if( eKind != DeviceKind::Fax )
332 0 : m_aFaxSwallowBox.Show( sal_False );
333 :
334 0 : m_aNameEdt.SetText( AddPrinterDialog::uniquePrinterName( m_aNameEdt.GetText() ) );
335 0 : m_aDefaultBox.Check( sal_False );
336 0 : m_aFaxSwallowBox.Check( sal_False );
337 0 : }
338 :
339 0 : APNamePage::~APNamePage()
340 : {
341 0 : }
342 :
343 0 : bool APNamePage::check()
344 : {
345 0 : return !m_aNameEdt.GetText().isEmpty();
346 : }
347 :
348 0 : void APNamePage::fill( PrinterInfo& rInfo )
349 : {
350 0 : rInfo.m_aPrinterName = m_aNameEdt.GetText();
351 0 : }
352 :
353 : //--------------------------------------------------------------------
354 :
355 0 : APCommandPage::APCommandPage( AddPrinterDialog* pParent, DeviceKind::type eKind )
356 : : APTabPage( pParent, PaResId( RID_ADDP_PAGE_COMMAND ) ),
357 : m_aCommandTxt( this, PaResId( RID_ADDP_CMD_TXT_COMMAND ) ),
358 0 : m_aCommandBox( this, PaResId( eKind == DeviceKind::Pdf ? RID_ADDP_CMD_BOX_PDFCOMMAND : RID_ADDP_CMD_BOX_COMMAND ) ),
359 : m_aHelpBtn( this, PaResId( RID_ADDP_CMD_BTN_HELP ) ),
360 0 : m_aHelpTxt( PaResId( eKind == DeviceKind::Fax ? RID_ADDP_CMD_STR_FAXHELP : RID_ADDP_CMD_STR_PDFHELP ) ),
361 : m_aPdfDirTxt( this, PaResId( RID_ADDP_CMD_TXT_PDFDIR ) ),
362 : m_aPdfDirEdt( this, PaResId( RID_ADDP_CMD_EDT_PDFDIR ) ),
363 : m_aPdfDirBtn( this, PaResId( RID_ADDP_CMD_BTN_PDFDIR ) ),
364 0 : m_eKind( eKind )
365 : {
366 0 : FreeResource();
367 0 : ::std::list< String > aCommands;
368 0 : if( m_eKind == DeviceKind::Printer )
369 : {
370 0 : m_aHelpBtn.Show( sal_False );
371 0 : Size aSize = m_aCommandTxt.GetSizePixel();
372 0 : aSize.Width() = m_aCommandBox.GetSizePixel().Width();
373 0 : m_aCommandTxt.SetSizePixel( aSize );
374 : }
375 0 : if( m_eKind != DeviceKind::Pdf )
376 : {
377 0 : m_aPdfDirBtn.Show( sal_False );
378 0 : m_aPdfDirEdt.Show( sal_False );
379 0 : m_aPdfDirTxt.Show( sal_False );
380 : }
381 0 : switch( m_eKind )
382 : {
383 0 : case DeviceKind::Printer: CommandStore::getPrintCommands( aCommands );break;
384 0 : case DeviceKind::Fax: CommandStore::getFaxCommands( aCommands );break;
385 0 : case DeviceKind::Pdf: CommandStore::getPdfCommands( aCommands );break;
386 : }
387 : // adjust height of command text and help button
388 0 : Rectangle aPosSize( m_aCommandTxt.GetPosPixel(), m_aCommandTxt.GetSizePixel() );
389 0 : Rectangle aTextSize = m_aCommandTxt.GetTextRect( Rectangle( Point(), aPosSize.GetSize() ), m_aCommandTxt.GetText() );
390 0 : if( aTextSize.GetWidth() <= 2*(aPosSize.GetWidth()+1) )
391 : {
392 0 : Size aNewSize( aPosSize.GetWidth(), aPosSize.GetHeight()*2/3 );
393 0 : if( aNewSize.Height() < m_aHelpBtn.GetSizePixel().Height()+2 )
394 0 : aNewSize.Height() = m_aHelpBtn.GetSizePixel().Height()+2;
395 0 : Point aNewPos( aPosSize.Left(), aPosSize.Top() + aPosSize.GetHeight() - aNewSize.Height() );
396 0 : m_aCommandTxt.SetPosSizePixel( aNewPos, aNewSize );
397 0 : aNewPos.X() = m_aHelpBtn.GetPosPixel().X();
398 0 : m_aHelpBtn.SetPosPixel( aNewPos );
399 : }
400 :
401 : // fill in commands
402 0 : ::std::list< String >::iterator it;
403 0 : for( it = aCommands.begin(); it != aCommands.end(); ++it )
404 0 : m_aCommandBox.InsertEntry( *it );
405 :
406 0 : m_aHelpBtn.SetClickHdl( LINK( this, APCommandPage, ClickBtnHdl ) );
407 0 : m_aPdfDirBtn.SetClickHdl( LINK( this, APCommandPage, ClickBtnHdl ) );
408 0 : if( m_eKind != DeviceKind::Printer )
409 : {
410 0 : m_aCommandBox.SetModifyHdl( LINK( this, APCommandPage, ModifyHdl ) );
411 0 : m_pParent->enableNext( false );
412 0 : }
413 0 : }
414 :
415 0 : APCommandPage::~APCommandPage()
416 : {
417 0 : ::std::list< String > aCommands;
418 0 : OUString aLastCommand( m_aCommandBox.GetText() );
419 0 : for( int i = 0; i < m_aCommandBox.GetEntryCount(); i++ )
420 : {
421 0 : OUString aCommand( m_aCommandBox.GetEntry( i ) );
422 0 : if( aCommand != aLastCommand )
423 0 : aCommands.push_back( aCommand );
424 0 : }
425 0 : aCommands.push_back( aLastCommand );
426 0 : switch( m_eKind )
427 : {
428 0 : case DeviceKind::Printer: CommandStore::setPrintCommands( aCommands );break;
429 0 : case DeviceKind::Fax: CommandStore::setFaxCommands( aCommands );break;
430 0 : case DeviceKind::Pdf: CommandStore::setPdfCommands( aCommands );break;
431 0 : }
432 0 : }
433 :
434 0 : IMPL_LINK( APCommandPage, ClickBtnHdl, PushButton*, pButton )
435 : {
436 0 : if( pButton == &m_aHelpBtn )
437 : {
438 0 : InfoBox aBox( this, m_aHelpTxt );
439 0 : aBox.Execute();
440 : }
441 0 : else if( pButton == &m_aPdfDirBtn )
442 : {
443 0 : OUString aPath( m_aPdfDirEdt.GetText() );
444 0 : if( chooseDirectory( aPath ) )
445 0 : m_aPdfDirEdt.SetText( aPath );
446 : }
447 0 : return 0;
448 : }
449 :
450 0 : IMPL_LINK( APCommandPage, ModifyHdl, ComboBox*, pBox )
451 : {
452 0 : if( pBox == &m_aCommandBox )
453 : {
454 0 : m_pParent->enableNext( !m_aCommandBox.GetText().isEmpty() );
455 : }
456 0 : return 0;
457 : }
458 :
459 0 : bool APCommandPage::check()
460 : {
461 0 : return true;
462 : }
463 :
464 0 : void APCommandPage::fill( PrinterInfo& rInfo )
465 : {
466 0 : rInfo.m_aCommand = m_aCommandBox.GetText();
467 0 : }
468 :
469 : //--------------------------------------------------------------------
470 :
471 0 : APOldPrinterPage::APOldPrinterPage( AddPrinterDialog* pParent )
472 : : APTabPage( pParent, PaResId( RID_ADDP_PAGE_OLDPRINTERS ) ),
473 : m_aOldPrinterTxt( this, PaResId( RID_ADDP_OLD_TXT_PRINTERS ) ),
474 : m_aOldPrinterBox( this, PaResId( RID_ADDP_OLD_BOX_PRINTERS ) ),
475 0 : m_aSelectAllBtn( this, PaResId( RID_ADDP_OLD_BTN_SELECTALL ) )
476 : {
477 0 : FreeResource();
478 :
479 0 : m_aSelectAllBtn.SetClickHdl( LINK( this, APOldPrinterPage, ClickBtnHdl ) );
480 0 : rtl_TextEncoding aEncoding = osl_getThreadTextEncoding();
481 :
482 0 : OUString aFileName( AddPrinterDialog::getOldPrinterLocation() );
483 0 : Config aConfig( aFileName );
484 :
485 : // read defaults
486 0 : aConfig.SetGroup( "Xprinter,PostScript" );
487 0 : OString aDefPageSize( aConfig.ReadKey( "PageSize" ) );
488 0 : OString aDefOrientation( aConfig.ReadKey( "Orientation" ) );
489 0 : OString aDefMarginLeft( aConfig.ReadKey( "MarginLeft" ) );
490 0 : OString aDefMarginRight( aConfig.ReadKey( "MarginRight" ) );
491 0 : OString aDefMarginTop( aConfig.ReadKey( "MarginTop" ) );
492 0 : OString aDefMarginBottom( aConfig.ReadKey( "MarginBottom" ) );
493 0 : OString aDefScale( aConfig.ReadKey( "Scale" ) );
494 :
495 0 : aConfig.SetGroup( "devices" );
496 0 : int nDevices = aConfig.GetKeyCount();
497 0 : for( int nKey = 0; nKey < nDevices; nKey++ )
498 : {
499 0 : aConfig.SetGroup( "devices" );
500 0 : OString aPrinter(aConfig.GetKeyName(nKey));
501 0 : OString aValue(aConfig.ReadKey(aPrinter));
502 0 : OString aPort(aValue.getToken(1, ','));
503 0 : OString aDriver(aValue.getToken(0, ' '));
504 0 : OString aPS( aValue.getToken(0, ',').getToken(1, ' ') );
505 0 : OString aNewDriver(aDriver);
506 0 : if( aDriver == "GENERIC")
507 0 : aNewDriver = OString("SGENPRT");
508 :
509 0 : if( aPS != "PostScript" )
510 0 : continue;
511 :
512 0 : const PPDParser* pParser = PPDParser::getParser(OStringToOUString(aNewDriver, aEncoding));
513 0 : if( pParser == NULL )
514 : {
515 0 : OUString aText( PaResId( RID_TXT_DRIVERDOESNOTEXIST ) );
516 0 : aText = aText.replaceFirst( OUString( "%s1" ), OStringToOUString(aPrinter, aEncoding) );
517 0 : aText = aText.replaceFirst( OUString( "%s2" ), OStringToOUString(aDriver, aEncoding) );
518 0 : InfoBox aBox( this, aText );
519 0 : aBox.Execute();
520 0 : continue;
521 : }
522 :
523 : // read the command
524 0 : aConfig.SetGroup( "ports" );
525 0 : OString aCommand( aConfig.ReadKey( aPort ) );
526 0 : if (!aCommand.isEmpty())
527 : {
528 0 : OUString aText( PaResId( RID_TXT_PRINTERWITHOUTCOMMAND ) );
529 0 : aText = aText.replaceFirst( OUString( "%s" ), OStringToOUString(aPrinter, aEncoding) );
530 0 : InfoBox aBox( this, aText );
531 0 : aBox.Execute();
532 0 : continue;
533 : }
534 :
535 :
536 0 : String aUPrinter( AddPrinterDialog::uniquePrinterName(OStringToOUString(aPrinter, aEncoding)) );
537 :
538 0 : PrinterInfo aInfo;
539 0 : aInfo.m_aDriverName = OStringToOUString(aNewDriver, aEncoding);
540 0 : aInfo.m_pParser = pParser;
541 0 : aInfo.m_aContext.setParser( pParser );
542 0 : aInfo.m_aPrinterName = aUPrinter;
543 0 : aInfo.m_aCommand = OStringToOUString(aCommand, aEncoding);
544 :
545 : // read the printer settings
546 0 : OStringBuffer aGroup(aDriver);
547 0 : aGroup.append(",PostScript,");
548 0 : aGroup.append(aPort);
549 0 : aConfig.SetGroup(aGroup.makeStringAndClear());
550 :
551 0 : aValue = aConfig.ReadKey( "PageSize", aDefPageSize );
552 : int nLeft, nRight, nTop, nBottom;
553 0 : if( !aValue.isEmpty() &&
554 : aInfo.m_pParser->getMargins( OStringToOUString(aValue, aEncoding),
555 0 : nLeft, nRight, nTop, nBottom ) )
556 : {
557 0 : const PPDKey* pKey = aInfo.m_pParser->getKey( String( "PageSize" ) );
558 0 : const PPDValue* pValue = pKey ? pKey->getValue( OStringToOUString(aValue, aEncoding) ) : NULL;
559 0 : if( pKey && pValue )
560 0 : aInfo.m_aContext.setValue( pKey, pValue );
561 0 : aValue = aConfig.ReadKey( "MarginLeft", aDefMarginLeft );
562 0 : if (!aValue.isEmpty())
563 0 : aInfo.m_nLeftMarginAdjust = aValue.toInt32() - (int)((double)nLeft * 35.27777778 );
564 0 : aValue = aConfig.ReadKey( "MarginRight", aDefMarginRight );
565 0 : if (!aValue.isEmpty())
566 0 : aInfo.m_nRightMarginAdjust = aValue.toInt32() - (int)((double)nRight * 35.27777778 );
567 0 : aValue = aConfig.ReadKey( "MarginTop", aDefMarginTop );
568 0 : if (!aValue.isEmpty())
569 0 : aInfo.m_nTopMarginAdjust = aValue.toInt32() - (int)((double)nTop * 35.27777778 );
570 0 : aValue = aConfig.ReadKey( "MarginBottom", aDefMarginBottom );
571 0 : if (!aValue.isEmpty())
572 0 : aInfo.m_nBottomMarginAdjust = aValue.toInt32() - (int)((double)nBottom * 35.27777778 );
573 : }
574 :
575 0 : aValue = aConfig.ReadKey( "Copies", aDefScale );
576 0 : if (!aValue.isEmpty())
577 0 : aInfo.m_nCopies = aValue.toInt32();
578 :
579 0 : aValue = aConfig.ReadKey( "Comment" );
580 0 : aInfo.m_aComment = OStringToOUString(aValue, aEncoding);
581 :
582 0 : aValue = aConfig.ReadKey( "Level" );
583 0 : if (!aValue.isEmpty())
584 0 : aInfo.m_nPSLevel = aValue.toInt32();
585 :
586 0 : aValue = aConfig.ReadKey( "Orientation", aDefOrientation );
587 0 : if (!aValue.isEmpty())
588 0 : aInfo.m_eOrientation = aValue.equalsIgnoreAsciiCaseL(RTL_CONSTASCII_STRINGPARAM("landscape")) ? orientation::Landscape : orientation::Portrait;
589 0 : int nGroupKeys = aConfig.GetKeyCount();
590 0 : for( int nPPDKey = 0; nPPDKey < nGroupKeys; nPPDKey++ )
591 : {
592 0 : OString aPPDKey( aConfig.GetKeyName( nPPDKey ) );
593 : // ignore page region
594 : // there are some ppd keys in old Xpdefaults that
595 : // should never have been writte because they are defaults
596 : // PageRegion leads to problems in conjunction
597 : // with a not matching PageSize
598 0 : if (aPPDKey.match("PPD_") && aPPDKey != "PPD_PageRegion")
599 : {
600 0 : aValue = aConfig.ReadKey( nPPDKey );
601 0 : aPPDKey = aPPDKey.copy(4);
602 0 : const PPDKey* pKey = aInfo.m_pParser->getKey( OStringToOUString(aPPDKey, RTL_TEXTENCODING_ISO_8859_1) );
603 0 : const PPDValue* pValue = pKey ? ( aValue == "*nil" ? NULL : pKey->getValue(OStringToOUString(aValue, RTL_TEXTENCODING_ISO_8859_1)) ) : NULL;
604 0 : if( pKey )
605 0 : aInfo.m_aContext.setValue( pKey, pValue, true );
606 : }
607 0 : }
608 :
609 0 : m_aOldPrinters.push_back( aInfo );
610 0 : int nPos = m_aOldPrinterBox.InsertEntry( aInfo.m_aPrinterName );
611 0 : m_aOldPrinterBox.SetEntryData( nPos, & m_aOldPrinters.back() );
612 0 : }
613 0 : }
614 :
615 0 : APOldPrinterPage::~APOldPrinterPage()
616 : {
617 0 : }
618 :
619 0 : IMPL_LINK( APOldPrinterPage, ClickBtnHdl, PushButton*, pButton )
620 : {
621 0 : if( pButton == &m_aSelectAllBtn )
622 : {
623 0 : for( int i = 0; i < m_aOldPrinterBox.GetEntryCount(); i++ )
624 0 : m_aOldPrinterBox.SelectEntryPos( i );
625 : }
626 0 : return 0;
627 : }
628 :
629 0 : void APOldPrinterPage::addOldPrinters()
630 : {
631 0 : PrinterInfoManager& rManager( PrinterInfoManager::get() );
632 0 : for( int i = 0; i < m_aOldPrinterBox.GetSelectEntryCount(); i++ )
633 : {
634 0 : PrinterInfo* pInfo = (PrinterInfo*)m_aOldPrinterBox.GetEntryData( m_aOldPrinterBox.GetSelectEntryPos( i ) );
635 0 : pInfo->m_aPrinterName = AddPrinterDialog::uniquePrinterName( pInfo->m_aPrinterName );
636 0 : if( ! rManager.addPrinter( pInfo->m_aPrinterName, pInfo->m_aDriverName ) )
637 : {
638 0 : OUString aText( PaResId( RID_TXT_PRINTERADDFAILED ) );
639 0 : aText = aText.replaceFirst( OUString( "%s" ), pInfo->m_aPrinterName );
640 0 : ErrorBox aBox( this, WB_OK | WB_DEF_OK, aText );
641 0 : aBox.Execute();
642 0 : continue;
643 : }
644 0 : rManager.changePrinterInfo( pInfo->m_aPrinterName, *pInfo );
645 : }
646 0 : }
647 :
648 0 : bool APOldPrinterPage::check()
649 : {
650 0 : return m_aOldPrinterBox.GetEntryCount() > 0;
651 : }
652 :
653 0 : void APOldPrinterPage::fill( PrinterInfo& )
654 : {
655 0 : }
656 :
657 : //--------------------------------------------------------------------
658 :
659 0 : APFaxDriverPage::APFaxDriverPage( AddPrinterDialog* pParent )
660 : : APTabPage( pParent, PaResId( RID_ADDP_PAGE_FAXDRIVER ) ),
661 : m_aFaxTxt( this, PaResId( RID_ADDP_FAXDRV_TXT_DRIVER ) ),
662 : m_aDefBtn( this, PaResId( RID_ADDP_FAXDRV_BTN_DEFAULT ) ),
663 0 : m_aSelectBtn( this, PaResId( RID_ADDP_FAXDRV_BTN_SELECT ) )
664 : {
665 0 : FreeResource();
666 :
667 0 : m_aDefBtn.Check( sal_True );
668 0 : m_aSelectBtn.Check( sal_False );
669 0 : m_aSelectBtn.SetStyle( m_aSelectBtn.GetStyle() | WB_WORDBREAK );
670 0 : }
671 :
672 0 : APFaxDriverPage::~APFaxDriverPage()
673 : {
674 0 : }
675 :
676 0 : bool APFaxDriverPage::check()
677 : {
678 0 : return true;
679 : }
680 :
681 0 : void APFaxDriverPage::fill( PrinterInfo& rInfo )
682 : {
683 0 : if( isDefault() )
684 : {
685 0 : rInfo.m_aDriverName = OUString("SGENPRT");
686 : }
687 0 : }
688 :
689 : //--------------------------------------------------------------------
690 :
691 0 : APPdfDriverPage::APPdfDriverPage( AddPrinterDialog* pParent )
692 : : APTabPage( pParent, PaResId( RID_ADDP_PAGE_PDFDRIVER ) ),
693 : m_aPdfTxt( this, PaResId( RID_ADDP_PDFDRV_TXT_DRIVER ) ),
694 : m_aDefBtn( this, PaResId( RID_ADDP_PDFDRV_BTN_DEFAULT ) ),
695 : m_aDistBtn( this, PaResId( RID_ADDP_PDFDRV_BTN_DIST ) ),
696 0 : m_aSelectBtn( this, PaResId( RID_ADDP_PDFDRV_BTN_SELECT ) )
697 : {
698 0 : FreeResource();
699 :
700 0 : m_aDefBtn.Check( sal_True );
701 0 : m_aDistBtn.Check( sal_False );
702 0 : m_aSelectBtn.Check( sal_False );
703 0 : m_aSelectBtn.SetStyle( m_aSelectBtn.GetStyle() | WB_WORDBREAK );
704 0 : }
705 :
706 0 : APPdfDriverPage::~APPdfDriverPage()
707 : {
708 0 : }
709 :
710 0 : bool APPdfDriverPage::check()
711 : {
712 0 : return true;
713 : }
714 :
715 0 : void APPdfDriverPage::fill( PrinterInfo& rInfo )
716 : {
717 0 : if( isDefault() )
718 0 : rInfo.m_aDriverName = OUString("SGENPRT");
719 0 : else if( isDist() )
720 0 : rInfo.m_aDriverName = OUString("ADISTILL");
721 0 : }
722 :
723 : //--------------------------------------------------------------------
724 :
725 0 : AddPrinterDialog::AddPrinterDialog( Window* pParent )
726 : : ModalDialog( pParent, PaResId( RID_ADD_PRINTER_DIALOG ) ),
727 : m_aCancelPB( this, PaResId( RID_ADDP_BTN_CANCEL ) ),
728 : m_aPrevPB( this, PaResId( RID_ADDP_BTN_PREV ) ),
729 : m_aNextPB( this, PaResId( RID_ADDP_BTN_NEXT ) ),
730 : m_aFinishPB( this, PaResId( RID_ADDP_BTN_FINISH ) ),
731 : m_aLine( this, PaResId( RID_ADDP_LINE ) ),
732 : m_aTitleImage( this, PaResId( RID_ADDP_CTRL_TITLE ) ),
733 : m_pCurrentPage( NULL ),
734 : m_pChooseDevicePage( NULL ),
735 : m_pCommandPage( NULL ),
736 : m_pChooseDriverPage( NULL ),
737 : m_pNamePage( NULL ),
738 : m_pOldPrinterPage( NULL ),
739 : m_pFaxDriverPage( NULL ),
740 : m_pFaxSelectDriverPage( NULL ),
741 : m_pFaxNamePage( NULL ),
742 : m_pFaxCommandPage( NULL ),
743 : m_pPdfDriverPage( NULL ),
744 : m_pPdfSelectDriverPage( NULL ),
745 : m_pPdfNamePage( NULL ),
746 0 : m_pPdfCommandPage( NULL )
747 : {
748 0 : FreeResource();
749 0 : m_pCurrentPage = m_pChooseDevicePage = new APChooseDevicePage( this );
750 0 : m_pCurrentPage->Show( sal_True );
751 0 : m_aFinishPB.Enable( sal_False );
752 0 : m_aPrevPB.Enable( sal_False );
753 :
754 0 : m_aNextPB.SetClickHdl( LINK( this, AddPrinterDialog, ClickBtnHdl ) );
755 0 : m_aPrevPB.SetClickHdl( LINK( this, AddPrinterDialog, ClickBtnHdl ) );
756 0 : m_aFinishPB.SetClickHdl( LINK( this, AddPrinterDialog, ClickBtnHdl ) );
757 0 : m_aCancelPB.SetClickHdl( LINK( this, AddPrinterDialog, ClickBtnHdl ) );
758 :
759 0 : m_aTitleImage.SetBackgroundColor( Color( 0xff, 0xff, 0xff ) );
760 0 : m_aTitleImage.SetText( m_pCurrentPage->getTitle() );
761 0 : updateSettings();
762 0 : }
763 :
764 0 : AddPrinterDialog::~AddPrinterDialog()
765 : {
766 0 : if( m_pChooseDevicePage )
767 0 : delete m_pChooseDevicePage;
768 0 : if( m_pChooseDriverPage )
769 0 : delete m_pChooseDriverPage;
770 0 : if( m_pNamePage )
771 0 : delete m_pNamePage;
772 0 : if( m_pCommandPage )
773 0 : delete m_pCommandPage;
774 0 : if( m_pOldPrinterPage )
775 0 : delete m_pOldPrinterPage;
776 0 : if( m_pFaxDriverPage )
777 0 : delete m_pFaxDriverPage;
778 0 : if( m_pFaxSelectDriverPage )
779 0 : delete m_pFaxSelectDriverPage;
780 0 : if( m_pFaxCommandPage )
781 0 : delete m_pFaxCommandPage;
782 0 : if( m_pFaxNamePage )
783 0 : delete m_pFaxNamePage;
784 0 : if( m_pPdfDriverPage )
785 0 : delete m_pPdfDriverPage;
786 0 : if( m_pPdfSelectDriverPage )
787 0 : delete m_pPdfSelectDriverPage;
788 0 : if( m_pPdfNamePage )
789 0 : delete m_pPdfNamePage;
790 0 : if( m_pPdfCommandPage )
791 0 : delete m_pPdfCommandPage;
792 0 : }
793 :
794 0 : void AddPrinterDialog::updateSettings()
795 : {
796 0 : m_aTitleImage.SetImage( Image( BitmapEx( PaResId( RID_BMP_PRINTER ) ) ) );
797 0 : }
798 :
799 0 : void AddPrinterDialog::DataChanged( const DataChangedEvent& rEv )
800 : {
801 0 : ModalDialog::DataChanged( rEv );
802 0 : if( (rEv.GetType() == DATACHANGED_SETTINGS) &&
803 0 : (rEv.GetFlags() & SETTINGS_STYLE) )
804 : {
805 0 : updateSettings();
806 : }
807 0 : }
808 :
809 0 : void AddPrinterDialog::advance()
810 : {
811 0 : m_pCurrentPage->Show( sal_False );
812 0 : if( m_pCurrentPage == m_pChooseDevicePage )
813 : {
814 0 : if( m_pChooseDevicePage->isPrinter() )
815 : {
816 0 : if( ! m_pChooseDriverPage )
817 0 : m_pChooseDriverPage = new APChooseDriverPage( this );
818 0 : m_pCurrentPage = m_pChooseDriverPage;
819 0 : m_aPrevPB.Enable( sal_True );
820 : }
821 0 : else if( m_pChooseDevicePage->isOld() )
822 : {
823 0 : if( ! m_pOldPrinterPage )
824 0 : m_pOldPrinterPage = new APOldPrinterPage( this );
825 0 : m_pCurrentPage = m_pOldPrinterPage;
826 0 : m_aPrevPB.Enable( sal_True );
827 0 : m_aFinishPB.Enable( sal_True );
828 0 : m_aNextPB.Enable( sal_False );
829 : }
830 0 : else if( m_pChooseDevicePage->isFax() )
831 : {
832 0 : if( ! m_pFaxDriverPage )
833 0 : m_pFaxDriverPage = new APFaxDriverPage( this );
834 0 : m_pCurrentPage = m_pFaxDriverPage;
835 0 : m_aPrevPB.Enable( sal_True );
836 : }
837 0 : else if( m_pChooseDevicePage->isPDF() )
838 : {
839 0 : if( ! m_pPdfDriverPage )
840 0 : m_pPdfDriverPage = new APPdfDriverPage( this );
841 0 : m_pCurrentPage = m_pPdfDriverPage;
842 0 : m_aPrevPB.Enable( sal_True );
843 : }
844 : }
845 0 : else if( m_pCurrentPage == m_pChooseDriverPage )
846 : {
847 0 : if( ! m_pCommandPage )
848 0 : m_pCommandPage = new APCommandPage( this, DeviceKind::Printer );
849 0 : m_pCurrentPage = m_pCommandPage;
850 : }
851 0 : else if( m_pCurrentPage == m_pCommandPage )
852 : {
853 0 : if( ! m_pNamePage )
854 0 : m_pNamePage = new APNamePage( this, m_aPrinter.m_aPrinterName, DeviceKind::Printer );
855 : else
856 0 : m_pNamePage->setText( m_aPrinter.m_aPrinterName );
857 0 : m_pCurrentPage = m_pNamePage;
858 0 : m_aFinishPB.Enable( sal_True );
859 0 : m_aNextPB.Enable( sal_False );
860 : }
861 0 : else if( m_pCurrentPage == m_pFaxDriverPage )
862 : {
863 0 : if( ! m_pFaxDriverPage->isDefault() )
864 : {
865 0 : if( ! m_pFaxSelectDriverPage )
866 0 : m_pFaxSelectDriverPage = new APChooseDriverPage( this );
867 0 : m_pCurrentPage = m_pFaxSelectDriverPage;
868 : }
869 : else
870 : {
871 0 : if( ! m_pFaxCommandPage )
872 0 : m_pFaxCommandPage = new APCommandPage( this, DeviceKind::Fax );
873 0 : m_pCurrentPage = m_pFaxCommandPage;
874 : }
875 : }
876 0 : else if( m_pCurrentPage == m_pFaxSelectDriverPage )
877 : {
878 0 : if( ! m_pFaxCommandPage )
879 0 : m_pFaxCommandPage = new APCommandPage( this, DeviceKind::Fax );
880 0 : m_pCurrentPage = m_pFaxCommandPage;
881 : }
882 0 : else if( m_pCurrentPage == m_pFaxCommandPage )
883 : {
884 0 : if( ! m_pFaxNamePage )
885 0 : m_pFaxNamePage = new APNamePage( this, OUString(), DeviceKind::Fax );
886 0 : m_pCurrentPage = m_pFaxNamePage;
887 0 : m_aNextPB.Enable( sal_False );
888 0 : m_aFinishPB.Enable( sal_True );
889 : }
890 0 : else if( m_pCurrentPage == m_pPdfDriverPage )
891 : {
892 0 : if( ! m_pPdfDriverPage->isDefault() && ! m_pPdfDriverPage->isDist() )
893 : {
894 0 : if( ! m_pPdfSelectDriverPage )
895 0 : m_pPdfSelectDriverPage = new APChooseDriverPage( this );
896 0 : m_pCurrentPage = m_pPdfSelectDriverPage;
897 : }
898 : else
899 : {
900 0 : if( ! m_pPdfCommandPage )
901 0 : m_pPdfCommandPage = new APCommandPage( this, DeviceKind::Pdf );
902 0 : m_pCurrentPage = m_pPdfCommandPage;
903 : }
904 : }
905 0 : else if( m_pCurrentPage == m_pPdfSelectDriverPage )
906 : {
907 0 : if( ! m_pPdfCommandPage )
908 0 : m_pPdfCommandPage = new APCommandPage( this, DeviceKind::Pdf );
909 0 : m_pCurrentPage = m_pPdfCommandPage;
910 : }
911 0 : else if( m_pCurrentPage == m_pPdfCommandPage )
912 : {
913 0 : if( ! m_pPdfNamePage )
914 0 : m_pPdfNamePage = new APNamePage( this, OUString(), DeviceKind::Pdf );
915 0 : m_pCurrentPage = m_pPdfNamePage;
916 0 : m_aNextPB.Enable( sal_False );
917 0 : m_aFinishPB.Enable( sal_True );
918 : }
919 :
920 0 : m_pCurrentPage->Show( sal_True );
921 0 : m_aTitleImage.SetText( m_pCurrentPage->getTitle() );
922 0 : }
923 :
924 0 : void AddPrinterDialog::back()
925 : {
926 0 : m_pCurrentPage->Show( sal_False );
927 0 : if( m_pCurrentPage == m_pChooseDriverPage )
928 : {
929 0 : m_pCurrentPage = m_pChooseDevicePage;
930 0 : m_aPrevPB.Enable( sal_False );
931 : }
932 0 : else if( m_pCurrentPage == m_pNamePage )
933 : {
934 0 : m_pCurrentPage = m_pCommandPage;
935 0 : m_aNextPB.Enable( sal_True );
936 : }
937 0 : else if( m_pCurrentPage == m_pCommandPage )
938 : {
939 0 : m_pCurrentPage = m_pChooseDriverPage;
940 : }
941 0 : else if( m_pCurrentPage == m_pOldPrinterPage )
942 : {
943 0 : m_pCurrentPage = m_pChooseDevicePage;
944 0 : m_aPrevPB.Enable( sal_False );
945 0 : m_aNextPB.Enable( sal_True );
946 : }
947 0 : else if( m_pCurrentPage == m_pFaxDriverPage )
948 : {
949 0 : m_pCurrentPage = m_pChooseDevicePage;
950 0 : m_aPrevPB.Enable( sal_False );
951 : }
952 0 : else if( m_pCurrentPage == m_pFaxSelectDriverPage )
953 : {
954 0 : m_pCurrentPage = m_pFaxDriverPage;
955 : }
956 0 : else if( m_pCurrentPage == m_pFaxNamePage )
957 : {
958 0 : m_pCurrentPage = m_pFaxCommandPage;
959 0 : m_aNextPB.Enable( sal_True );
960 : }
961 0 : else if( m_pCurrentPage == m_pFaxCommandPage )
962 : {
963 0 : m_pCurrentPage = m_pFaxDriverPage->isDefault() ? (APTabPage*)m_pFaxDriverPage : (APTabPage*)m_pFaxSelectDriverPage;
964 0 : m_aNextPB.Enable( sal_True );
965 : }
966 0 : else if( m_pCurrentPage == m_pPdfDriverPage )
967 : {
968 0 : m_pCurrentPage = m_pChooseDevicePage;
969 0 : m_aPrevPB.Enable( sal_False );
970 : }
971 0 : else if( m_pCurrentPage == m_pPdfSelectDriverPage )
972 : {
973 0 : m_pCurrentPage = m_pPdfDriverPage;
974 : }
975 0 : else if( m_pCurrentPage == m_pPdfNamePage )
976 : {
977 0 : m_pCurrentPage = m_pPdfCommandPage;
978 0 : m_aNextPB.Enable( sal_True );
979 : }
980 0 : else if( m_pCurrentPage == m_pPdfCommandPage )
981 : {
982 0 : m_pCurrentPage = m_pPdfDriverPage->isDefault() || m_pPdfDriverPage->isDist() ? (APTabPage*)m_pPdfDriverPage : (APTabPage*)m_pPdfSelectDriverPage;
983 0 : m_aNextPB.Enable( sal_True );
984 : }
985 0 : m_pCurrentPage->Show( sal_True );
986 0 : m_aTitleImage.SetText( m_pCurrentPage->getTitle() );
987 0 : }
988 :
989 0 : void AddPrinterDialog::addPrinter()
990 : {
991 0 : PrinterInfoManager& rManager( PrinterInfoManager::get() );
992 0 : if( ! m_pChooseDevicePage->isOld() )
993 : {
994 0 : m_aPrinter.m_aPrinterName = uniquePrinterName( m_aPrinter.m_aPrinterName );
995 0 : if( rManager.addPrinter( m_aPrinter.m_aPrinterName, m_aPrinter.m_aDriverName ) )
996 : {
997 0 : PrinterInfo aInfo( rManager.getPrinterInfo( m_aPrinter.m_aPrinterName ) );
998 0 : aInfo.m_aCommand = m_aPrinter.m_aCommand;
999 0 : if( m_pChooseDevicePage->isPrinter() )
1000 : {
1001 0 : if( m_pNamePage->isDefault() )
1002 0 : rManager.setDefaultPrinter( m_aPrinter.m_aPrinterName );
1003 : }
1004 0 : else if( m_pChooseDevicePage->isFax() )
1005 : {
1006 0 : aInfo.m_aFeatures = OUString("fax=");
1007 0 : if( m_pFaxNamePage->isFaxSwallow() )
1008 0 : aInfo.m_aFeatures += "swallow";
1009 : }
1010 0 : else if( m_pChooseDevicePage->isPDF() )
1011 : {
1012 0 : OUString aPdf( "pdf=" );
1013 0 : aPdf += m_pPdfCommandPage->getPdfDir();
1014 0 : aInfo.m_aFeatures = aPdf;
1015 : }
1016 0 : rManager.changePrinterInfo( m_aPrinter.m_aPrinterName, aInfo );
1017 : }
1018 : }
1019 0 : else if( m_pOldPrinterPage )
1020 0 : m_pOldPrinterPage->addOldPrinters();
1021 0 : }
1022 :
1023 0 : IMPL_LINK( AddPrinterDialog, ClickBtnHdl, PushButton*, pButton )
1024 : {
1025 0 : if( pButton == &m_aNextPB )
1026 : {
1027 0 : if( m_pCurrentPage->check() )
1028 : {
1029 0 : m_pCurrentPage->fill( m_aPrinter );
1030 0 : advance();
1031 : }
1032 : }
1033 0 : else if( pButton == &m_aPrevPB )
1034 : {
1035 0 : if( m_pCurrentPage->check() )
1036 0 : m_pCurrentPage->fill( m_aPrinter );
1037 0 : back();
1038 : }
1039 0 : else if( pButton == &m_aFinishPB )
1040 : {
1041 0 : if( m_pCurrentPage->check() )
1042 : {
1043 0 : m_pCurrentPage->fill( m_aPrinter );
1044 0 : addPrinter();
1045 0 : PrinterInfoManager::get().writePrinterConfig();
1046 0 : EndDialog( 1 );
1047 : }
1048 : }
1049 0 : else if( pButton == &m_aCancelPB )
1050 0 : EndDialog( 0 );
1051 :
1052 0 : return 0;
1053 : }
1054 :
1055 0 : OUString AddPrinterDialog::uniquePrinterName( const OUString& rBase )
1056 : {
1057 0 : OUString aResult( rBase );
1058 :
1059 0 : PrinterInfoManager& rManager( PrinterInfoManager::get() );
1060 :
1061 0 : sal_Int32 nVersion = 1;
1062 0 : list< OUString > aPrinterList;
1063 0 : rManager.listPrinters( aPrinterList );
1064 0 : boost::unordered_set< OUString, OUStringHash > aPrinters;
1065 0 : for( list< OUString >::const_iterator it = aPrinterList.begin(); it != aPrinterList.end(); ++it )
1066 0 : aPrinters.insert( *it );
1067 0 : while( aPrinters.find( aResult ) != aPrinters.end() )
1068 : {
1069 0 : aResult = rBase;
1070 0 : aResult += "_" ;
1071 0 : aResult += OUString::valueOf(nVersion++);
1072 : }
1073 :
1074 0 : return aResult;
1075 : }
1076 :
1077 0 : String AddPrinterDialog::getOldPrinterLocation()
1078 : {
1079 0 : static const char* pHome = getenv( "HOME" );
1080 0 : OString aFileName;
1081 :
1082 0 : rtl_TextEncoding aEncoding = osl_getThreadTextEncoding();
1083 0 : if( pHome )
1084 : {
1085 0 : aFileName = OStringBuffer().append(pHome).
1086 0 : append("/.Xpdefaults").makeStringAndClear();
1087 0 : if (access(aFileName.getStr(), F_OK))
1088 : {
1089 0 : aFileName = OStringBuffer().append(pHome).
1090 0 : append("/.sversionrc").makeStringAndClear();
1091 0 : Config aSVer(OStringToOUString(aFileName, aEncoding));
1092 0 : aSVer.SetGroup( "Versions" );
1093 0 : aFileName = aSVer.ReadKey( "StarOffice 5.2" );
1094 0 : if (!aFileName.isEmpty())
1095 0 : aFileName = aFileName + OString("/share/xp3/Xpdefaults");
1096 0 : else if(
1097 0 : (aFileName = aSVer.ReadKey( "StarOffice 5.1" ) ).getLength()
1098 0 : ||
1099 0 : (aFileName = aSVer.ReadKey( "StarOffice 5.0" ) ).getLength()
1100 0 : ||
1101 0 : (aFileName = aSVer.ReadKey( "StarOffice 4.0" ) ).getLength()
1102 : )
1103 : {
1104 0 : aFileName = aFileName + OString("/xp3/Xpdefaults");
1105 : }
1106 0 : if (!aFileName.isEmpty() && access(aFileName.getStr(), F_OK))
1107 0 : aFileName = OString();
1108 : }
1109 : }
1110 :
1111 0 : return !aFileName.isEmpty() ? OStringToOUString(aFileName, aEncoding) : OUString();
1112 0 : }
1113 :
1114 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|