Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : // this file contains code from filectrl.cxx which needs to be compiled with enabled exception hanling
31 : : #include <svtools/filectrl.hxx>
32 : : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
33 : : #include <com/sun/star/ui/dialogs/XFilePicker.hpp>
34 : : #include <vcl/unohelp.hxx>
35 : : #include <tools/urlobj.hxx>
36 : : #include <osl/file.h>
37 : : #include <vcl/stdtext.hxx>
38 : :
39 : : using namespace ::com::sun::star::uno;
40 : : using namespace ::com::sun::star::lang;
41 : : using namespace ::com::sun::star::ui;
42 : :
43 : 0 : void FileControl::ImplBrowseFile( )
44 : : {
45 : : try
46 : : {
47 [ # # ]: 0 : XubString aNewText;
48 : :
49 [ # # ]: 0 : const ::rtl::OUString sServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.dialogs.FilePicker" ));
50 : :
51 [ # # ]: 0 : Reference< XMultiServiceFactory > xMSF = vcl::unohelper::GetMultiServiceFactory();
52 [ # # ][ # # ]: 0 : Reference < dialogs::XFilePicker > xFilePicker( xMSF->createInstance( sServiceName ), UNO_QUERY );
[ # # ]
53 [ # # ]: 0 : if ( xFilePicker.is() )
54 : : {
55 : : // transform the system notation text into a file URL
56 [ # # ][ # # ]: 0 : ::rtl::OUString sSystemNotation = GetText(), sFileURL;
[ # # ]
57 [ # # ]: 0 : oslFileError nError = osl_getFileURLFromSystemPath( sSystemNotation.pData, &sFileURL.pData );
58 [ # # ]: 0 : if ( nError == osl_File_E_INVAL )
59 [ # # ][ # # ]: 0 : sFileURL = GetText(); // #97709# Maybe URL is already a file URL...
[ # # ]
60 : :
61 : : //#90430# Check if URL is really a file URL
62 : 0 : ::rtl::OUString aTmp;
63 [ # # ][ # # ]: 0 : if ( osl_getSystemPathFromFileURL( sFileURL.pData, &aTmp.pData ) == osl_File_E_None )
64 : : {
65 : : // initially set this directory
66 [ # # ][ # # ]: 0 : xFilePicker->setDisplayDirectory( sFileURL );
67 : : }
68 : :
69 [ # # ][ # # ]: 0 : if ( xFilePicker.is() && xFilePicker->execute() )
[ # # ][ # # ]
[ # # ]
70 : : {
71 [ # # ][ # # ]: 0 : Sequence < rtl::OUString > aPathSeq = xFilePicker->getFiles();
72 : :
73 [ # # ]: 0 : if ( aPathSeq.getLength() )
74 : : {
75 [ # # ][ # # ]: 0 : aNewText = aPathSeq[0];
76 [ # # ][ # # ]: 0 : INetURLObject aObj( aNewText );
77 [ # # ]: 0 : if ( aObj.GetProtocol() == INET_PROT_FILE )
78 [ # # ][ # # ]: 0 : aNewText = aObj.PathToFileName();
79 [ # # ]: 0 : SetText( aNewText );
80 [ # # ][ # # ]: 0 : maEdit.GetModifyHdl().Call( &maEdit );
81 [ # # ]: 0 : }
82 : 0 : }
83 : : }
84 : : else
85 [ # # ][ # # ]: 0 : ShowServiceNotAvailableError( this, sServiceName, sal_True );
[ # # ][ # # ]
[ # # ]
86 : : }
87 : 0 : catch( const Exception& )
88 : : {
89 : : OSL_FAIL( "FileControl::ImplBrowseFile: caught an exception while executing the file picker!" );
90 : : }
91 : 0 : }
92 : :
93 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|