1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: filectrl2.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svtools.hxx"
34 // this file contains code from filectrl.cxx which needs to be compiled with enabled exception hanling
35 #include <filectrl.hxx>
36 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
37 #include <com/sun/star/ui/dialogs/XFilePicker.hpp>
38 #include <vcl/unohelp.hxx>
39 #include <tools/urlobj.hxx>
41 #include <vcl/stdtext.hxx>
42 #include <tools/debug.hxx>
44 using namespace ::com::sun::star::uno
;
45 using namespace ::com::sun::star::lang
;
46 using namespace ::com::sun::star::ui
;
48 void FileControl::ImplBrowseFile( )
54 const ::rtl::OUString sServiceName
= ::rtl::OUString::createFromAscii( "com.sun.star.ui.dialogs.FilePicker" );
56 Reference
< XMultiServiceFactory
> xMSF
= vcl::unohelper::GetMultiServiceFactory();
57 Reference
< dialogs::XFilePicker
> xFilePicker( xMSF
->createInstance( sServiceName
), UNO_QUERY
);
58 if ( xFilePicker
.is() )
60 // transform the system notation text into a file URL
61 ::rtl::OUString sSystemNotation
= GetText(), sFileURL
;
62 oslFileError nError
= osl_getFileURLFromSystemPath( sSystemNotation
.pData
, &sFileURL
.pData
);
63 if ( nError
== osl_File_E_INVAL
)
64 sFileURL
= GetText(); // #97709# Maybe URL is already a file URL...
66 //#90430# Check if URL is really a file URL
68 if ( osl_getSystemPathFromFileURL( sFileURL
.pData
, &aTmp
.pData
) == osl_File_E_None
)
70 // initially set this directory
71 xFilePicker
->setDisplayDirectory( sFileURL
);
74 if ( xFilePicker
.is() && xFilePicker
->execute() )
76 Sequence
< rtl::OUString
> aPathSeq
= xFilePicker
->getFiles();
78 if ( aPathSeq
.getLength() )
80 aNewText
= aPathSeq
[0];
81 INetURLObject
aObj( aNewText
);
82 if ( aObj
.GetProtocol() == INET_PROT_FILE
)
83 aNewText
= aObj
.PathToFileName();
85 maEdit
.GetModifyHdl().Call( &maEdit
);
90 ShowServiceNotAvailableError( this, sServiceName
, sal_True
);
92 catch( const Exception
& )
94 DBG_ERROR( "FileControl::ImplBrowseFile: caught an exception while executing the file picker!" );