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: fileopendialog.cxx,v $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 // MARKER(update_precomp.py): autogen include statement, do not remove
33 #include "precompiled_sdext.hxx"
35 #include "fileopendialog.hxx"
36 #include <sal/types.h>
37 #include "pppoptimizertoken.hxx"
38 #include <com/sun/star/lang/XInitialization.hpp>
39 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
40 #include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp>
41 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
42 #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
43 #include <com/sun/star/ui/dialogs/FilePreviewImageFormats.hpp>
44 #include <com/sun/star/ui/dialogs/ControlActions.hpp>
45 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
46 #include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
47 #include <com/sun/star/ui/dialogs/XFilePickerNotifier.hpp>
48 #include <com/sun/star/ui/dialogs/XFilePreview.hpp>
49 #include <com/sun/star/ui/dialogs/XFilterManager.hpp>
50 #include <com/sun/star/ui/dialogs/XFilterGroupManager.hpp>
51 #ifndef _COM_SUN_STAR_UI_DIALOGS_XFOLDERPICKER_HDL_
52 #include <com/sun/star/ui/dialogs/XFolderPicker.hpp>
54 #include <com/sun/star/lang/XServiceInfo.hpp>
55 #include <com/sun/star/beans/XPropertySet.hpp>
56 #include <com/sun/star/beans/PropertyValue.hpp>
57 #include <com/sun/star/beans/NamedValue.hpp>
58 #include <com/sun/star/embed/ElementModes.hpp>
59 #include <com/sun/star/container/XEnumeration.hpp>
60 #include <com/sun/star/container/XNameAccess.hpp>
61 #include <com/sun/star/container/XContainerQuery.hpp>
62 #include <com/sun/star/ucb/InteractiveAugmentedIOException.hpp>
63 #include <comphelper/types.hxx>
66 using namespace ::rtl
;
67 using namespace ::com::sun::star::uno
;
68 using namespace ::com::sun::star::lang
;
69 using namespace ::com::sun::star::beans
;
70 using namespace ::com::sun::star::container
;
71 using namespace ::com::sun::star::ui::dialogs
;
73 FileOpenDialog::FileOpenDialog( const Reference
< XComponentContext
>& rxMSF
) :
76 Sequence
< Any
> aInitPropSeq( 1 );
77 aInitPropSeq
[ 0 ] <<= (sal_Int16
)TemplateDescription::FILESAVE_AUTOEXTENSION
; // TemplateDescription.FILEOPEN_SIMPLE
79 mxFilePicker
= Reference
< XFilePicker
>( mxMSF
->getServiceManager()->createInstanceWithArgumentsAndContext(
80 OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.dialogs.FilePicker" ) ), aInitPropSeq
, rxMSF
),UNO_QUERY_THROW
);
81 mxFilePicker
->setMultiSelectionMode( sal_False
);
84 // collecting a list of impress filters
85 Reference
< XNameAccess
> xFilters( mxMSF
->getServiceManager()->createInstanceWithContext(
86 OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.FilterFactory" ) ), rxMSF
), UNO_QUERY_THROW
);
87 Sequence
< OUString
> aFilterList( xFilters
->getElementNames() );
88 for ( int i
= 0; i
< aFilterList
.getLength(); i
++ )
92 Sequence
< PropertyValue
> aFilterProperties
;
93 if ( xFilters
->getByName( aFilterList
[ i
] ) >>= aFilterProperties
)
95 FilterEntry aFilterEntry
;
96 sal_Bool bImpressFilter
= sal_False
;
97 for ( int j
= 0; j
< aFilterProperties
.getLength(); j
++ )
99 PropertyValue
& rProperty( aFilterProperties
[ j
] );
100 switch( TKGet( rProperty
.Name
) )
102 case TK_DocumentService
:
104 rtl::OUString sDocumentService
;
105 rProperty
.Value
>>= sDocumentService
;
106 if ( sDocumentService
== OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.presentation.PresentationDocument" ) ) )
107 bImpressFilter
= sal_True
;
109 j
= aFilterProperties
.getLength();
112 case TK_Name
: rProperty
.Value
>>= aFilterEntry
.maName
; break;
113 case TK_UIName
: rProperty
.Value
>>= aFilterEntry
.maUIName
; break;
114 case TK_Type
: rProperty
.Value
>>= aFilterEntry
.maType
; break;
115 case TK_Flags
: rProperty
.Value
>>= aFilterEntry
.maFlags
; break;
119 if ( bImpressFilter
&& ( ( aFilterEntry
.maFlags
& 3 ) == 3 ) )
121 aFilterEntryList
.push_back( aFilterEntry
);
130 Reference
< XNameAccess
> xTypes( mxMSF
->getServiceManager()->createInstanceWithContext(
131 OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.TypeDetection" ) ), rxMSF
), UNO_QUERY_THROW
);
132 Sequence
< OUString
> aTypeList( xFilters
->getElementNames() );
134 // mxFilePicker->setDefaultName( );
136 Reference
< XFilterManager
> xFilterManager( mxFilePicker
, UNO_QUERY_THROW
);
137 std::vector
< FilterEntry
>::iterator
aIter( aFilterEntryList
.begin() );
138 while( aIter
!= aFilterEntryList
.end() )
140 Sequence
< PropertyValue
> aTypeProperties
;
143 if ( xTypes
->getByName( aIter
->maType
) >>= aTypeProperties
)
145 Sequence
< OUString
> aExtensions
;
146 for ( int i
= 0; i
< aTypeProperties
.getLength(); i
++ )
148 switch( TKGet( aTypeProperties
[ i
].Name
) )
150 case TK_Extensions
: aTypeProperties
[ i
].Value
>>= aExtensions
; break;
154 if ( aExtensions
.getLength() )
156 xFilterManager
->appendFilter( aIter
->maUIName
, aExtensions
[ 0 ] );
157 if ( aIter
->maFlags
& 0x100 )
158 xFilterManager
->setCurrentFilter( aIter
->maUIName
);
168 FileOpenDialog::~FileOpenDialog()
171 sal_Int16
FileOpenDialog::execute()
173 return mxFilePicker
->execute();
175 void FileOpenDialog::setDefaultName( const rtl::OUString
& rDefaultName
)
177 mxFilePicker
->setDefaultName( rDefaultName
);
179 ::rtl::OUString
FileOpenDialog::getURL() const
181 Sequence
< OUString
> aFileSeq( mxFilePicker
->getFiles() );
182 return aFileSeq
.getLength() ? aFileSeq
[ 0 ] : OUString();
184 ::rtl::OUString
FileOpenDialog::getFilterName() const
186 rtl::OUString aFilterName
;
187 Reference
< XFilterManager
> xFilterManager( mxFilePicker
, UNO_QUERY_THROW
);
188 rtl::OUString
aUIName( xFilterManager
->getCurrentFilter() );
189 std::vector
< FilterEntry
>::const_iterator
aIter( aFilterEntryList
.begin() );
190 while( aIter
!= aFilterEntryList
.end() )
192 if ( aIter
->maUIName
== aUIName
)
194 aFilterName
= aIter
->maName
;