1*5900e8ecSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*5900e8ecSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*5900e8ecSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*5900e8ecSAndrew Rist  * distributed with this work for additional information
6*5900e8ecSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*5900e8ecSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*5900e8ecSAndrew Rist  * "License"); you may not use this file except in compliance
9*5900e8ecSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*5900e8ecSAndrew Rist  *
11*5900e8ecSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*5900e8ecSAndrew Rist  *
13*5900e8ecSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*5900e8ecSAndrew Rist  * software distributed under the License is distributed on an
15*5900e8ecSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*5900e8ecSAndrew Rist  * KIND, either express or implied.  See the License for the
17*5900e8ecSAndrew Rist  * specific language governing permissions and limitations
18*5900e8ecSAndrew Rist  * under the License.
19*5900e8ecSAndrew Rist  *
20*5900e8ecSAndrew Rist  *************************************************************/
21*5900e8ecSAndrew Rist 
22*5900e8ecSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svtools.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir // this file contains code from filectrl.cxx which needs to be compiled with enabled exception hanling
28cdf0e10cSrcweir #include <svtools/filectrl.hxx>
29cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
30cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XFilePicker.hpp>
31cdf0e10cSrcweir #include <vcl/unohelp.hxx>
32cdf0e10cSrcweir #include <tools/urlobj.hxx>
33cdf0e10cSrcweir #include <osl/file.h>
34cdf0e10cSrcweir #include <vcl/stdtext.hxx>
35cdf0e10cSrcweir #include <tools/debug.hxx>
36cdf0e10cSrcweir 
37cdf0e10cSrcweir using namespace ::com::sun::star::uno;
38cdf0e10cSrcweir using namespace ::com::sun::star::lang;
39cdf0e10cSrcweir using namespace ::com::sun::star::ui;
40cdf0e10cSrcweir 
ImplBrowseFile()41cdf0e10cSrcweir void FileControl::ImplBrowseFile( )
42cdf0e10cSrcweir {
43cdf0e10cSrcweir 	try
44cdf0e10cSrcweir 	{
45cdf0e10cSrcweir 		XubString aNewText;
46cdf0e10cSrcweir 
47cdf0e10cSrcweir 		const ::rtl::OUString sServiceName = ::rtl::OUString::createFromAscii( "com.sun.star.ui.dialogs.FilePicker" );
48cdf0e10cSrcweir 
49cdf0e10cSrcweir 		Reference< XMultiServiceFactory > xMSF = vcl::unohelper::GetMultiServiceFactory();
50cdf0e10cSrcweir 		Reference < dialogs::XFilePicker > xFilePicker( xMSF->createInstance( sServiceName ), UNO_QUERY );
51cdf0e10cSrcweir 		if ( xFilePicker.is() )
52cdf0e10cSrcweir 		{
53cdf0e10cSrcweir 			// transform the system notation text into a file URL
54cdf0e10cSrcweir 			::rtl::OUString sSystemNotation = GetText(), sFileURL;
55cdf0e10cSrcweir 			oslFileError nError = osl_getFileURLFromSystemPath( sSystemNotation.pData, &sFileURL.pData );
56cdf0e10cSrcweir             if ( nError == osl_File_E_INVAL )
57cdf0e10cSrcweir                 sFileURL = GetText();   // #97709# Maybe URL is already a file URL...
58cdf0e10cSrcweir 
59cdf0e10cSrcweir             //#90430# Check if URL is really a file URL
60cdf0e10cSrcweir             ::rtl::OUString aTmp;
61cdf0e10cSrcweir             if ( osl_getSystemPathFromFileURL( sFileURL.pData, &aTmp.pData ) == osl_File_E_None )
62cdf0e10cSrcweir             {
63cdf0e10cSrcweir 			    // initially set this directory
64cdf0e10cSrcweir 			    xFilePicker->setDisplayDirectory( sFileURL );
65cdf0e10cSrcweir             }
66cdf0e10cSrcweir 
67cdf0e10cSrcweir 			if ( xFilePicker.is() && xFilePicker->execute() )
68cdf0e10cSrcweir 			{
69cdf0e10cSrcweir 				Sequence < rtl::OUString > aPathSeq = xFilePicker->getFiles();
70cdf0e10cSrcweir 
71cdf0e10cSrcweir 				if ( aPathSeq.getLength() )
72cdf0e10cSrcweir 				{
73cdf0e10cSrcweir 					aNewText = aPathSeq[0];
74cdf0e10cSrcweir 					INetURLObject aObj( aNewText );
75cdf0e10cSrcweir 					if ( aObj.GetProtocol() == INET_PROT_FILE )
76cdf0e10cSrcweir 						aNewText = aObj.PathToFileName();
77cdf0e10cSrcweir 					SetText( aNewText );
78cdf0e10cSrcweir 					maEdit.GetModifyHdl().Call( &maEdit );
79cdf0e10cSrcweir 				}
80cdf0e10cSrcweir 			}
81cdf0e10cSrcweir 		}
82cdf0e10cSrcweir 		else
83cdf0e10cSrcweir 			ShowServiceNotAvailableError( this, sServiceName, sal_True );
84cdf0e10cSrcweir 	}
85cdf0e10cSrcweir 	catch( const Exception& )
86cdf0e10cSrcweir 	{
87cdf0e10cSrcweir 		DBG_ERROR( "FileControl::ImplBrowseFile: caught an exception while executing the file picker!" );
88cdf0e10cSrcweir 	}
89cdf0e10cSrcweir }
90cdf0e10cSrcweir 
91