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