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