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