1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_fpicker.hxx" 30 31 //------------------------------------------------------------------------ 32 // includes 33 //------------------------------------------------------------------------ 34 35 #ifndef _WINDIRBROWSEIMPL_HXX_ 36 #include "WinFOPImpl.hxx" 37 #endif 38 #include <osl/diagnose.h> 39 #include <com/sun/star/lang/EventObject.hpp> 40 41 #ifndef _COM_SUN_STAR_UI_FILEDIALOGRESULTS_HPP_ 42 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp> 43 #endif 44 #include "FopEvtDisp.hxx" 45 #include <osl/file.hxx> 46 #include "FolderPicker.hxx" 47 48 //------------------------------------------------------------------------ 49 // namespace directives 50 //------------------------------------------------------------------------ 51 52 using com::sun::star::uno::RuntimeException; 53 using com::sun::star::lang::IllegalArgumentException; 54 using com::sun::star::lang::EventObject; 55 using rtl::OUString; 56 57 using namespace com::sun::star::ui::dialogs; 58 using osl::FileBase; 59 60 //------------------------------------------------------------------------ 61 // 62 //------------------------------------------------------------------------ 63 64 const OUString BACKSLASH = OUString::createFromAscii( "\\" ); 65 66 //------------------------------------------------------------------------ 67 // ctor 68 //------------------------------------------------------------------------ 69 70 CWinFolderPickerImpl::CWinFolderPickerImpl( CFolderPicker* aFolderPicker ) : 71 CMtaFolderPicker( BIF_RETURNONLYFSDIRS | BIF_RETURNFSANCESTORS | BIF_EDITBOX | BIF_VALIDATE ), 72 m_pFolderPicker( aFolderPicker ), 73 m_nLastDlgResult( ::com::sun::star::ui::dialogs::ExecutableDialogResults::CANCEL ) 74 { 75 } 76 77 //------------------------------------------------------------------------ 78 // get directory in URL format, convert it to system format and set the 79 // member variable 80 // If the given URL for the directory is invalid the function throws an 81 // IllegalArgumentException 82 // If the specified path is well formed but invalid for the underlying 83 // OS the FolderPicker starts in the root of the file system hierarchie 84 //------------------------------------------------------------------------ 85 86 void SAL_CALL CWinFolderPickerImpl::setDisplayDirectory( const OUString& aDirectory ) 87 throw( IllegalArgumentException, RuntimeException ) 88 { 89 OUString sysDir; 90 91 if( aDirectory.getLength( ) ) 92 { 93 // assuming that this function succeeds after successful execution 94 // of getAbsolutePath 95 ::osl::FileBase::RC rc = 96 ::osl::FileBase::getSystemPathFromFileURL( aDirectory, sysDir ); 97 98 if ( ::osl::FileBase::E_None != rc ) 99 throw IllegalArgumentException( 100 OUString::createFromAscii( "directory is not a valid file url" ), 101 static_cast< XFolderPicker* >( m_pFolderPicker ), 102 1 ); 103 104 // we ensure that there is a trailing '/' at the end of 105 // he given file url, because the windows functions only 106 // works correctly when providing "c:\" or an environment 107 // variable like "=c:=c:\.." etc. is set, else the 108 // FolderPicker would stand in the root of the shell 109 // hierarchie which is the desktop folder 110 if ( sysDir.lastIndexOf( BACKSLASH ) != (sysDir.getLength( ) - 1) ) 111 sysDir += BACKSLASH; 112 } 113 114 // call base class method 115 CMtaFolderPicker::setDisplayDirectory( sysDir ); 116 } 117 118 //------------------------------------------------------------------------ 119 // we return the directory in URL format 120 //------------------------------------------------------------------------ 121 122 OUString CWinFolderPickerImpl::getDisplayDirectory( ) 123 throw( RuntimeException ) 124 { 125 // call base class method to get the directory in system format 126 OUString displayDirectory = CMtaFolderPicker::getDisplayDirectory( ); 127 128 OUString displayDirectoryURL; 129 if ( displayDirectory.getLength( ) ) 130 ::osl::FileBase::getFileURLFromSystemPath( displayDirectory, displayDirectoryURL ); 131 132 return displayDirectoryURL; 133 } 134 135 //------------------------------------------------------------------------ 136 // 137 //------------------------------------------------------------------------ 138 139 OUString SAL_CALL CWinFolderPickerImpl::getDirectory( ) throw( RuntimeException ) 140 { 141 OUString sysDir = CMtaFolderPicker::getDirectory( ); 142 OUString dirURL; 143 144 if ( sysDir.getLength( ) ) 145 ::osl::FileBase::getFileURLFromSystemPath( sysDir, dirURL ); 146 147 return dirURL; 148 } 149 150 //------------------------------------------------------------------------ 151 // 152 //------------------------------------------------------------------------ 153 154 sal_Int16 SAL_CALL CWinFolderPickerImpl::execute( ) throw( RuntimeException ) 155 { 156 return m_nLastDlgResult = CMtaFolderPicker::browseForFolder( ) ? 157 ::com::sun::star::ui::dialogs::ExecutableDialogResults::OK : 158 ::com::sun::star::ui::dialogs::ExecutableDialogResults::CANCEL; 159 } 160 161 //--------------------------------------------------------------------- 162 // 163 //--------------------------------------------------------------------- 164 165 void CWinFolderPickerImpl::onSelChanged( const OUString& aNewPath ) 166 { 167 setStatusText( aNewPath ); 168 } 169