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 // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_fpicker.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include "OfficeFolderPicker.hxx" 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir #include "iodlg.hxx" 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir #include <list> 36*cdf0e10cSrcweir #include <tools/urlobj.hxx> 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir #define _SVSTDARR_STRINGSDTOR 39*cdf0e10cSrcweir #include "svl/svstdarr.hxx" 40*cdf0e10cSrcweir #include <com/sun/star/container/XContentEnumerationAccess.hpp> 41*cdf0e10cSrcweir #include <com/sun/star/container/XSet.hpp> 42*cdf0e10cSrcweir #include <com/sun/star/uno/Any.hxx> 43*cdf0e10cSrcweir #include <cppuhelper/factory.hxx> 44*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 45*cdf0e10cSrcweir #include <unotools/pathoptions.hxx> 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir // using ---------------------------------------------------------------- 48*cdf0e10cSrcweir 49*cdf0e10cSrcweir using namespace ::com::sun::star::container; 50*cdf0e10cSrcweir using namespace ::com::sun::star::lang; 51*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 52*cdf0e10cSrcweir using namespace ::com::sun::star::beans; 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir //------------------------------------------------------------------------------------ 55*cdf0e10cSrcweir // class SvtFolderPicker 56*cdf0e10cSrcweir //------------------------------------------------------------------------------------ 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir //------------------------------------------------------------------------------------ 59*cdf0e10cSrcweir SvtFolderPicker::SvtFolderPicker( const Reference < XMultiServiceFactory >& _rxFactory ) 60*cdf0e10cSrcweir :OCommonPicker( _rxFactory ) 61*cdf0e10cSrcweir { 62*cdf0e10cSrcweir } 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir //------------------------------------------------------------------------------------ 65*cdf0e10cSrcweir SvtFolderPicker::~SvtFolderPicker() 66*cdf0e10cSrcweir { 67*cdf0e10cSrcweir } 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir //------------------------------------------------------------------------------------ 70*cdf0e10cSrcweir // disambiguate XInterface 71*cdf0e10cSrcweir //------------------------------------------------------------------------------------ 72*cdf0e10cSrcweir IMPLEMENT_FORWARD_XINTERFACE2( SvtFolderPicker, OCommonPicker, SvtFolderPicker_Base ) 73*cdf0e10cSrcweir 74*cdf0e10cSrcweir //------------------------------------------------------------------------------------ 75*cdf0e10cSrcweir // disambiguate XTypeProvider 76*cdf0e10cSrcweir //------------------------------------------------------------------------------------ 77*cdf0e10cSrcweir IMPLEMENT_FORWARD_XTYPEPROVIDER2( SvtFolderPicker, OCommonPicker, SvtFolderPicker_Base ) 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir //------------------------------------------------------------------------------------ 80*cdf0e10cSrcweir // XExecutableDialog functions 81*cdf0e10cSrcweir //------------------------------------------------------------------------------------ 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir //------------------------------------------------------------------------------------ 84*cdf0e10cSrcweir void SAL_CALL SvtFolderPicker::setTitle( const ::rtl::OUString& _rTitle ) throw (RuntimeException) 85*cdf0e10cSrcweir { 86*cdf0e10cSrcweir OCommonPicker::setTitle( _rTitle ); 87*cdf0e10cSrcweir } 88*cdf0e10cSrcweir 89*cdf0e10cSrcweir //------------------------------------------------------------------------------------ 90*cdf0e10cSrcweir sal_Int16 SAL_CALL SvtFolderPicker::execute( ) throw (RuntimeException) 91*cdf0e10cSrcweir { 92*cdf0e10cSrcweir return OCommonPicker::execute(); 93*cdf0e10cSrcweir } 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir //------------------------------------------------------------------------------------ 96*cdf0e10cSrcweir // XAsynchronousExecutableDialog functions 97*cdf0e10cSrcweir //------------------------------------------------------------------------------------ 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir //------------------------------------------------------------------------------------ 100*cdf0e10cSrcweir void SAL_CALL SvtFolderPicker::setDialogTitle( const ::rtl::OUString& _rTitle) throw (RuntimeException) 101*cdf0e10cSrcweir { 102*cdf0e10cSrcweir setTitle( _rTitle ); 103*cdf0e10cSrcweir } 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir //------------------------------------------------------------------------------------ 106*cdf0e10cSrcweir void SAL_CALL SvtFolderPicker::startExecuteModal( const Reference< ::com::sun::star::ui::dialogs::XDialogClosedListener >& xListener ) throw (RuntimeException) 107*cdf0e10cSrcweir { 108*cdf0e10cSrcweir m_xListener = xListener; 109*cdf0e10cSrcweir prepareDialog(); 110*cdf0e10cSrcweir prepareExecute(); 111*cdf0e10cSrcweir getDialog()->EnableAutocompletion( sal_True ); 112*cdf0e10cSrcweir getDialog()->StartExecuteModal( LINK( this, SvtFolderPicker, DialogClosedHdl ) ); 113*cdf0e10cSrcweir } 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir //------------------------------------------------------------------------------------ 116*cdf0e10cSrcweir SvtFileDialog* SvtFolderPicker::implCreateDialog( Window* _pParent ) 117*cdf0e10cSrcweir { 118*cdf0e10cSrcweir return new SvtFileDialog( _pParent, SFXWB_PATHDIALOG ); 119*cdf0e10cSrcweir } 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir //------------------------------------------------------------------------------------ 122*cdf0e10cSrcweir sal_Int16 SvtFolderPicker::implExecutePicker( ) 123*cdf0e10cSrcweir { 124*cdf0e10cSrcweir prepareExecute(); 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir // now we are ready to execute the dialog 127*cdf0e10cSrcweir getDialog()->EnableAutocompletion( sal_False ); 128*cdf0e10cSrcweir sal_Int16 nRet = getDialog()->Execute(); 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir return nRet; 131*cdf0e10cSrcweir } 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir //------------------------------------------------------------------------------------ 134*cdf0e10cSrcweir void SvtFolderPicker::prepareExecute() 135*cdf0e10cSrcweir { 136*cdf0e10cSrcweir // set the default directory 137*cdf0e10cSrcweir if ( m_aDisplayDirectory.getLength() > 0 ) 138*cdf0e10cSrcweir getDialog()->SetPath( m_aDisplayDirectory ); 139*cdf0e10cSrcweir else 140*cdf0e10cSrcweir { 141*cdf0e10cSrcweir // Default-Standard-Dir setzen 142*cdf0e10cSrcweir INetURLObject aStdDirObj( SvtPathOptions().GetWorkPath() ); 143*cdf0e10cSrcweir getDialog()->SetPath( aStdDirObj.GetMainURL( INetURLObject::NO_DECODE) ); 144*cdf0e10cSrcweir } 145*cdf0e10cSrcweir } 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir //----------------------------------------------------------------------------- 148*cdf0e10cSrcweir IMPL_LINK( SvtFolderPicker, DialogClosedHdl, Dialog*, pDlg ) 149*cdf0e10cSrcweir { 150*cdf0e10cSrcweir if ( m_xListener.is() ) 151*cdf0e10cSrcweir { 152*cdf0e10cSrcweir sal_Int16 nRet = static_cast< sal_Int16 >( pDlg->GetResult() ); 153*cdf0e10cSrcweir ::com::sun::star::ui::dialogs::DialogClosedEvent aEvent( *this, nRet ); 154*cdf0e10cSrcweir m_xListener->dialogClosed( aEvent ); 155*cdf0e10cSrcweir m_xListener.clear(); 156*cdf0e10cSrcweir } 157*cdf0e10cSrcweir return 0; 158*cdf0e10cSrcweir } 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir //------------------------------------------------------------------------------------ 161*cdf0e10cSrcweir // XFolderPicker functions 162*cdf0e10cSrcweir //------------------------------------------------------------------------------------ 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir void SAL_CALL SvtFolderPicker::setDisplayDirectory( const ::rtl::OUString& aDirectory ) 165*cdf0e10cSrcweir throw( IllegalArgumentException, RuntimeException ) 166*cdf0e10cSrcweir { 167*cdf0e10cSrcweir m_aDisplayDirectory = aDirectory; 168*cdf0e10cSrcweir } 169*cdf0e10cSrcweir 170*cdf0e10cSrcweir //------------------------------------------------------------------------------------ 171*cdf0e10cSrcweir ::rtl::OUString SAL_CALL SvtFolderPicker::getDisplayDirectory() throw( RuntimeException ) 172*cdf0e10cSrcweir { 173*cdf0e10cSrcweir ::rtl::OUString aResult; 174*cdf0e10cSrcweir 175*cdf0e10cSrcweir if ( ! getDialog() ) 176*cdf0e10cSrcweir return m_aDisplayDirectory; 177*cdf0e10cSrcweir 178*cdf0e10cSrcweir SvStringsDtor* pPathList = getDialog()->GetPathList(); 179*cdf0e10cSrcweir 180*cdf0e10cSrcweir if ( pPathList->Count() ) 181*cdf0e10cSrcweir aResult = ::rtl::OUString( *pPathList->GetObject( 0 ) ); 182*cdf0e10cSrcweir 183*cdf0e10cSrcweir delete pPathList; 184*cdf0e10cSrcweir 185*cdf0e10cSrcweir return aResult; 186*cdf0e10cSrcweir } 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir //------------------------------------------------------------------------------------ 189*cdf0e10cSrcweir ::rtl::OUString SAL_CALL SvtFolderPicker::getDirectory() throw( RuntimeException ) 190*cdf0e10cSrcweir { 191*cdf0e10cSrcweir ::rtl::OUString aResult; 192*cdf0e10cSrcweir 193*cdf0e10cSrcweir if ( ! getDialog() ) 194*cdf0e10cSrcweir return m_aDisplayDirectory; 195*cdf0e10cSrcweir 196*cdf0e10cSrcweir SvStringsDtor* pPathList = getDialog()->GetPathList(); 197*cdf0e10cSrcweir 198*cdf0e10cSrcweir if ( pPathList->Count() ) 199*cdf0e10cSrcweir aResult = ::rtl::OUString( *pPathList->GetObject( 0 ) ); 200*cdf0e10cSrcweir 201*cdf0e10cSrcweir delete pPathList; 202*cdf0e10cSrcweir 203*cdf0e10cSrcweir return aResult; 204*cdf0e10cSrcweir } 205*cdf0e10cSrcweir 206*cdf0e10cSrcweir //------------------------------------------------------------------------------------ 207*cdf0e10cSrcweir void SAL_CALL SvtFolderPicker::setDescription( const ::rtl::OUString& aDescription ) 208*cdf0e10cSrcweir throw( RuntimeException ) 209*cdf0e10cSrcweir { 210*cdf0e10cSrcweir m_aDescription = aDescription; 211*cdf0e10cSrcweir } 212*cdf0e10cSrcweir 213*cdf0e10cSrcweir //------------------------------------------------------------------------------------ 214*cdf0e10cSrcweir // XServiceInfo 215*cdf0e10cSrcweir //------------------------------------------------------------------------------------ 216*cdf0e10cSrcweir 217*cdf0e10cSrcweir /* XServiceInfo */ 218*cdf0e10cSrcweir ::rtl::OUString SAL_CALL SvtFolderPicker::getImplementationName() throw( RuntimeException ) 219*cdf0e10cSrcweir { 220*cdf0e10cSrcweir return impl_getStaticImplementationName(); 221*cdf0e10cSrcweir } 222*cdf0e10cSrcweir 223*cdf0e10cSrcweir /* XServiceInfo */ 224*cdf0e10cSrcweir sal_Bool SAL_CALL SvtFolderPicker::supportsService( const ::rtl::OUString& sServiceName ) throw( RuntimeException ) 225*cdf0e10cSrcweir { 226*cdf0e10cSrcweir Sequence< ::rtl::OUString > seqServiceNames = getSupportedServiceNames(); 227*cdf0e10cSrcweir const ::rtl::OUString* pArray = seqServiceNames.getConstArray(); 228*cdf0e10cSrcweir for ( sal_Int32 i = 0; i < seqServiceNames.getLength(); i++ ) 229*cdf0e10cSrcweir { 230*cdf0e10cSrcweir if ( sServiceName == pArray[i] ) 231*cdf0e10cSrcweir { 232*cdf0e10cSrcweir return sal_True ; 233*cdf0e10cSrcweir } 234*cdf0e10cSrcweir } 235*cdf0e10cSrcweir return sal_False ; 236*cdf0e10cSrcweir } 237*cdf0e10cSrcweir 238*cdf0e10cSrcweir /* XServiceInfo */ 239*cdf0e10cSrcweir Sequence< ::rtl::OUString > SAL_CALL SvtFolderPicker::getSupportedServiceNames() throw( RuntimeException ) 240*cdf0e10cSrcweir { 241*cdf0e10cSrcweir return impl_getStaticSupportedServiceNames(); 242*cdf0e10cSrcweir } 243*cdf0e10cSrcweir 244*cdf0e10cSrcweir /* Helper for XServiceInfo */ 245*cdf0e10cSrcweir Sequence< ::rtl::OUString > SvtFolderPicker::impl_getStaticSupportedServiceNames() 246*cdf0e10cSrcweir { 247*cdf0e10cSrcweir Sequence< ::rtl::OUString > seqServiceNames(1); 248*cdf0e10cSrcweir seqServiceNames[0] = ::rtl::OUString::createFromAscii( "com.sun.star.ui.dialogs.OfficeFolderPicker" ); 249*cdf0e10cSrcweir return seqServiceNames ; 250*cdf0e10cSrcweir } 251*cdf0e10cSrcweir 252*cdf0e10cSrcweir /* Helper for XServiceInfo */ 253*cdf0e10cSrcweir ::rtl::OUString SvtFolderPicker::impl_getStaticImplementationName() 254*cdf0e10cSrcweir { 255*cdf0e10cSrcweir return ::rtl::OUString::createFromAscii( "com.sun.star.svtools.OfficeFolderPicker" ); 256*cdf0e10cSrcweir } 257*cdf0e10cSrcweir 258*cdf0e10cSrcweir /* Helper for registry */ 259*cdf0e10cSrcweir Reference< XInterface > SAL_CALL SvtFolderPicker::impl_createInstance( const Reference< XComponentContext >& rxContext ) 260*cdf0e10cSrcweir throw( Exception ) 261*cdf0e10cSrcweir { 262*cdf0e10cSrcweir Reference< XMultiServiceFactory > xServiceManager (rxContext->getServiceManager(), UNO_QUERY_THROW); 263*cdf0e10cSrcweir return Reference< XInterface >( *new SvtFolderPicker( xServiceManager ) ); 264*cdf0e10cSrcweir } 265*cdf0e10cSrcweir 266