1*b557fc96SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*b557fc96SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*b557fc96SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*b557fc96SAndrew Rist * distributed with this work for additional information 6*b557fc96SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*b557fc96SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*b557fc96SAndrew Rist * "License"); you may not use this file except in compliance 9*b557fc96SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*b557fc96SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*b557fc96SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*b557fc96SAndrew Rist * software distributed under the License is distributed on an 15*b557fc96SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*b557fc96SAndrew Rist * KIND, either express or implied. See the License for the 17*b557fc96SAndrew Rist * specific language governing permissions and limitations 18*b557fc96SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*b557fc96SAndrew Rist *************************************************************/ 21*b557fc96SAndrew Rist 22*b557fc96SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_fpicker.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "OfficeFolderPicker.hxx" 28cdf0e10cSrcweir 29cdf0e10cSrcweir #include "iodlg.hxx" 30cdf0e10cSrcweir 31cdf0e10cSrcweir #include <list> 32cdf0e10cSrcweir #include <tools/urlobj.hxx> 33cdf0e10cSrcweir 34cdf0e10cSrcweir #define _SVSTDARR_STRINGSDTOR 35cdf0e10cSrcweir #include "svl/svstdarr.hxx" 36cdf0e10cSrcweir #include <com/sun/star/container/XContentEnumerationAccess.hpp> 37cdf0e10cSrcweir #include <com/sun/star/container/XSet.hpp> 38cdf0e10cSrcweir #include <com/sun/star/uno/Any.hxx> 39cdf0e10cSrcweir #include <cppuhelper/factory.hxx> 40cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 41cdf0e10cSrcweir #include <unotools/pathoptions.hxx> 42cdf0e10cSrcweir 43cdf0e10cSrcweir // using ---------------------------------------------------------------- 44cdf0e10cSrcweir 45cdf0e10cSrcweir using namespace ::com::sun::star::container; 46cdf0e10cSrcweir using namespace ::com::sun::star::lang; 47cdf0e10cSrcweir using namespace ::com::sun::star::uno; 48cdf0e10cSrcweir using namespace ::com::sun::star::beans; 49cdf0e10cSrcweir 50cdf0e10cSrcweir //------------------------------------------------------------------------------------ 51cdf0e10cSrcweir // class SvtFolderPicker 52cdf0e10cSrcweir //------------------------------------------------------------------------------------ 53cdf0e10cSrcweir 54cdf0e10cSrcweir //------------------------------------------------------------------------------------ 55cdf0e10cSrcweir SvtFolderPicker::SvtFolderPicker( const Reference < XMultiServiceFactory >& _rxFactory ) 56cdf0e10cSrcweir :OCommonPicker( _rxFactory ) 57cdf0e10cSrcweir { 58cdf0e10cSrcweir } 59cdf0e10cSrcweir 60cdf0e10cSrcweir //------------------------------------------------------------------------------------ 61cdf0e10cSrcweir SvtFolderPicker::~SvtFolderPicker() 62cdf0e10cSrcweir { 63cdf0e10cSrcweir } 64cdf0e10cSrcweir 65cdf0e10cSrcweir //------------------------------------------------------------------------------------ 66cdf0e10cSrcweir // disambiguate XInterface 67cdf0e10cSrcweir //------------------------------------------------------------------------------------ 68cdf0e10cSrcweir IMPLEMENT_FORWARD_XINTERFACE2( SvtFolderPicker, OCommonPicker, SvtFolderPicker_Base ) 69cdf0e10cSrcweir 70cdf0e10cSrcweir //------------------------------------------------------------------------------------ 71cdf0e10cSrcweir // disambiguate XTypeProvider 72cdf0e10cSrcweir //------------------------------------------------------------------------------------ 73cdf0e10cSrcweir IMPLEMENT_FORWARD_XTYPEPROVIDER2( SvtFolderPicker, OCommonPicker, SvtFolderPicker_Base ) 74cdf0e10cSrcweir 75cdf0e10cSrcweir //------------------------------------------------------------------------------------ 76cdf0e10cSrcweir // XExecutableDialog functions 77cdf0e10cSrcweir //------------------------------------------------------------------------------------ 78cdf0e10cSrcweir 79cdf0e10cSrcweir //------------------------------------------------------------------------------------ 80cdf0e10cSrcweir void SAL_CALL SvtFolderPicker::setTitle( const ::rtl::OUString& _rTitle ) throw (RuntimeException) 81cdf0e10cSrcweir { 82cdf0e10cSrcweir OCommonPicker::setTitle( _rTitle ); 83cdf0e10cSrcweir } 84cdf0e10cSrcweir 85cdf0e10cSrcweir //------------------------------------------------------------------------------------ 86cdf0e10cSrcweir sal_Int16 SAL_CALL SvtFolderPicker::execute( ) throw (RuntimeException) 87cdf0e10cSrcweir { 88cdf0e10cSrcweir return OCommonPicker::execute(); 89cdf0e10cSrcweir } 90cdf0e10cSrcweir 91cdf0e10cSrcweir //------------------------------------------------------------------------------------ 92cdf0e10cSrcweir // XAsynchronousExecutableDialog functions 93cdf0e10cSrcweir //------------------------------------------------------------------------------------ 94cdf0e10cSrcweir 95cdf0e10cSrcweir //------------------------------------------------------------------------------------ 96cdf0e10cSrcweir void SAL_CALL SvtFolderPicker::setDialogTitle( const ::rtl::OUString& _rTitle) throw (RuntimeException) 97cdf0e10cSrcweir { 98cdf0e10cSrcweir setTitle( _rTitle ); 99cdf0e10cSrcweir } 100cdf0e10cSrcweir 101cdf0e10cSrcweir //------------------------------------------------------------------------------------ 102cdf0e10cSrcweir void SAL_CALL SvtFolderPicker::startExecuteModal( const Reference< ::com::sun::star::ui::dialogs::XDialogClosedListener >& xListener ) throw (RuntimeException) 103cdf0e10cSrcweir { 104cdf0e10cSrcweir m_xListener = xListener; 105cdf0e10cSrcweir prepareDialog(); 106cdf0e10cSrcweir prepareExecute(); 107cdf0e10cSrcweir getDialog()->EnableAutocompletion( sal_True ); 108cdf0e10cSrcweir getDialog()->StartExecuteModal( LINK( this, SvtFolderPicker, DialogClosedHdl ) ); 109cdf0e10cSrcweir } 110cdf0e10cSrcweir 111cdf0e10cSrcweir //------------------------------------------------------------------------------------ 112cdf0e10cSrcweir SvtFileDialog* SvtFolderPicker::implCreateDialog( Window* _pParent ) 113cdf0e10cSrcweir { 114cdf0e10cSrcweir return new SvtFileDialog( _pParent, SFXWB_PATHDIALOG ); 115cdf0e10cSrcweir } 116cdf0e10cSrcweir 117cdf0e10cSrcweir //------------------------------------------------------------------------------------ 118cdf0e10cSrcweir sal_Int16 SvtFolderPicker::implExecutePicker( ) 119cdf0e10cSrcweir { 120cdf0e10cSrcweir prepareExecute(); 121cdf0e10cSrcweir 122cdf0e10cSrcweir // now we are ready to execute the dialog 123cdf0e10cSrcweir getDialog()->EnableAutocompletion( sal_False ); 124cdf0e10cSrcweir sal_Int16 nRet = getDialog()->Execute(); 125cdf0e10cSrcweir 126cdf0e10cSrcweir return nRet; 127cdf0e10cSrcweir } 128cdf0e10cSrcweir 129cdf0e10cSrcweir //------------------------------------------------------------------------------------ 130cdf0e10cSrcweir void SvtFolderPicker::prepareExecute() 131cdf0e10cSrcweir { 132cdf0e10cSrcweir // set the default directory 133cdf0e10cSrcweir if ( m_aDisplayDirectory.getLength() > 0 ) 134cdf0e10cSrcweir getDialog()->SetPath( m_aDisplayDirectory ); 135cdf0e10cSrcweir else 136cdf0e10cSrcweir { 137cdf0e10cSrcweir // Default-Standard-Dir setzen 138cdf0e10cSrcweir INetURLObject aStdDirObj( SvtPathOptions().GetWorkPath() ); 139cdf0e10cSrcweir getDialog()->SetPath( aStdDirObj.GetMainURL( INetURLObject::NO_DECODE) ); 140cdf0e10cSrcweir } 141cdf0e10cSrcweir } 142cdf0e10cSrcweir 143cdf0e10cSrcweir //----------------------------------------------------------------------------- 144cdf0e10cSrcweir IMPL_LINK( SvtFolderPicker, DialogClosedHdl, Dialog*, pDlg ) 145cdf0e10cSrcweir { 146cdf0e10cSrcweir if ( m_xListener.is() ) 147cdf0e10cSrcweir { 148cdf0e10cSrcweir sal_Int16 nRet = static_cast< sal_Int16 >( pDlg->GetResult() ); 149cdf0e10cSrcweir ::com::sun::star::ui::dialogs::DialogClosedEvent aEvent( *this, nRet ); 150cdf0e10cSrcweir m_xListener->dialogClosed( aEvent ); 151cdf0e10cSrcweir m_xListener.clear(); 152cdf0e10cSrcweir } 153cdf0e10cSrcweir return 0; 154cdf0e10cSrcweir } 155cdf0e10cSrcweir 156cdf0e10cSrcweir //------------------------------------------------------------------------------------ 157cdf0e10cSrcweir // XFolderPicker functions 158cdf0e10cSrcweir //------------------------------------------------------------------------------------ 159cdf0e10cSrcweir 160cdf0e10cSrcweir void SAL_CALL SvtFolderPicker::setDisplayDirectory( const ::rtl::OUString& aDirectory ) 161cdf0e10cSrcweir throw( IllegalArgumentException, RuntimeException ) 162cdf0e10cSrcweir { 163cdf0e10cSrcweir m_aDisplayDirectory = aDirectory; 164cdf0e10cSrcweir } 165cdf0e10cSrcweir 166cdf0e10cSrcweir //------------------------------------------------------------------------------------ 167cdf0e10cSrcweir ::rtl::OUString SAL_CALL SvtFolderPicker::getDisplayDirectory() throw( RuntimeException ) 168cdf0e10cSrcweir { 169cdf0e10cSrcweir ::rtl::OUString aResult; 170cdf0e10cSrcweir 171cdf0e10cSrcweir if ( ! getDialog() ) 172cdf0e10cSrcweir return m_aDisplayDirectory; 173cdf0e10cSrcweir 174cdf0e10cSrcweir SvStringsDtor* pPathList = getDialog()->GetPathList(); 175cdf0e10cSrcweir 176cdf0e10cSrcweir if ( pPathList->Count() ) 177cdf0e10cSrcweir aResult = ::rtl::OUString( *pPathList->GetObject( 0 ) ); 178cdf0e10cSrcweir 179cdf0e10cSrcweir delete pPathList; 180cdf0e10cSrcweir 181cdf0e10cSrcweir return aResult; 182cdf0e10cSrcweir } 183cdf0e10cSrcweir 184cdf0e10cSrcweir //------------------------------------------------------------------------------------ 185cdf0e10cSrcweir ::rtl::OUString SAL_CALL SvtFolderPicker::getDirectory() throw( RuntimeException ) 186cdf0e10cSrcweir { 187cdf0e10cSrcweir ::rtl::OUString aResult; 188cdf0e10cSrcweir 189cdf0e10cSrcweir if ( ! getDialog() ) 190cdf0e10cSrcweir return m_aDisplayDirectory; 191cdf0e10cSrcweir 192cdf0e10cSrcweir SvStringsDtor* pPathList = getDialog()->GetPathList(); 193cdf0e10cSrcweir 194cdf0e10cSrcweir if ( pPathList->Count() ) 195cdf0e10cSrcweir aResult = ::rtl::OUString( *pPathList->GetObject( 0 ) ); 196cdf0e10cSrcweir 197cdf0e10cSrcweir delete pPathList; 198cdf0e10cSrcweir 199cdf0e10cSrcweir return aResult; 200cdf0e10cSrcweir } 201cdf0e10cSrcweir 202cdf0e10cSrcweir //------------------------------------------------------------------------------------ 203cdf0e10cSrcweir void SAL_CALL SvtFolderPicker::setDescription( const ::rtl::OUString& aDescription ) 204cdf0e10cSrcweir throw( RuntimeException ) 205cdf0e10cSrcweir { 206cdf0e10cSrcweir m_aDescription = aDescription; 207cdf0e10cSrcweir } 208cdf0e10cSrcweir 209cdf0e10cSrcweir //------------------------------------------------------------------------------------ 210cdf0e10cSrcweir // XServiceInfo 211cdf0e10cSrcweir //------------------------------------------------------------------------------------ 212cdf0e10cSrcweir 213cdf0e10cSrcweir /* XServiceInfo */ 214cdf0e10cSrcweir ::rtl::OUString SAL_CALL SvtFolderPicker::getImplementationName() throw( RuntimeException ) 215cdf0e10cSrcweir { 216cdf0e10cSrcweir return impl_getStaticImplementationName(); 217cdf0e10cSrcweir } 218cdf0e10cSrcweir 219cdf0e10cSrcweir /* XServiceInfo */ 220cdf0e10cSrcweir sal_Bool SAL_CALL SvtFolderPicker::supportsService( const ::rtl::OUString& sServiceName ) throw( RuntimeException ) 221cdf0e10cSrcweir { 222cdf0e10cSrcweir Sequence< ::rtl::OUString > seqServiceNames = getSupportedServiceNames(); 223cdf0e10cSrcweir const ::rtl::OUString* pArray = seqServiceNames.getConstArray(); 224cdf0e10cSrcweir for ( sal_Int32 i = 0; i < seqServiceNames.getLength(); i++ ) 225cdf0e10cSrcweir { 226cdf0e10cSrcweir if ( sServiceName == pArray[i] ) 227cdf0e10cSrcweir { 228cdf0e10cSrcweir return sal_True ; 229cdf0e10cSrcweir } 230cdf0e10cSrcweir } 231cdf0e10cSrcweir return sal_False ; 232cdf0e10cSrcweir } 233cdf0e10cSrcweir 234cdf0e10cSrcweir /* XServiceInfo */ 235cdf0e10cSrcweir Sequence< ::rtl::OUString > SAL_CALL SvtFolderPicker::getSupportedServiceNames() throw( RuntimeException ) 236cdf0e10cSrcweir { 237cdf0e10cSrcweir return impl_getStaticSupportedServiceNames(); 238cdf0e10cSrcweir } 239cdf0e10cSrcweir 240cdf0e10cSrcweir /* Helper for XServiceInfo */ 241cdf0e10cSrcweir Sequence< ::rtl::OUString > SvtFolderPicker::impl_getStaticSupportedServiceNames() 242cdf0e10cSrcweir { 243cdf0e10cSrcweir Sequence< ::rtl::OUString > seqServiceNames(1); 244cdf0e10cSrcweir seqServiceNames[0] = ::rtl::OUString::createFromAscii( "com.sun.star.ui.dialogs.OfficeFolderPicker" ); 245cdf0e10cSrcweir return seqServiceNames ; 246cdf0e10cSrcweir } 247cdf0e10cSrcweir 248cdf0e10cSrcweir /* Helper for XServiceInfo */ 249cdf0e10cSrcweir ::rtl::OUString SvtFolderPicker::impl_getStaticImplementationName() 250cdf0e10cSrcweir { 251cdf0e10cSrcweir return ::rtl::OUString::createFromAscii( "com.sun.star.svtools.OfficeFolderPicker" ); 252cdf0e10cSrcweir } 253cdf0e10cSrcweir 254cdf0e10cSrcweir /* Helper for registry */ 255cdf0e10cSrcweir Reference< XInterface > SAL_CALL SvtFolderPicker::impl_createInstance( const Reference< XComponentContext >& rxContext ) 256cdf0e10cSrcweir throw( Exception ) 257cdf0e10cSrcweir { 258cdf0e10cSrcweir Reference< XMultiServiceFactory > xServiceManager (rxContext->getServiceManager(), UNO_QUERY_THROW); 259cdf0e10cSrcweir return Reference< XInterface >( *new SvtFolderPicker( xServiceManager ) ); 260cdf0e10cSrcweir } 261cdf0e10cSrcweir 262