LCOV - code coverage report
Current view: top level - padmin/source - adddlg.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 663 0.0 %
Date: 2012-08-25 Functions: 0 60 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

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

Generated by: LCOV version 1.10