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 : : #include "fileopendialog.hxx"
31 : : #include <sal/types.h>
32 : : #include "pppoptimizertoken.hxx"
33 : : #include <com/sun/star/lang/XInitialization.hpp>
34 : : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
35 : : #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
36 : : #include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp>
37 : : #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
38 : : #include <com/sun/star/ui/dialogs/FilePreviewImageFormats.hpp>
39 : : #include <com/sun/star/ui/dialogs/ControlActions.hpp>
40 : : #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
41 : : #include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
42 : : #include <com/sun/star/ui/dialogs/XFilePickerNotifier.hpp>
43 : : #include <com/sun/star/ui/dialogs/XFilePreview.hpp>
44 : : #include <com/sun/star/ui/dialogs/XFilterManager.hpp>
45 : : #include <com/sun/star/ui/dialogs/XFilterGroupManager.hpp>
46 : : #include <com/sun/star/ui/dialogs/XFolderPicker.hpp>
47 : : #include <com/sun/star/lang/XServiceInfo.hpp>
48 : : #include <com/sun/star/beans/XPropertySet.hpp>
49 : : #include <com/sun/star/beans/PropertyValue.hpp>
50 : : #include <com/sun/star/beans/NamedValue.hpp>
51 : : #include <com/sun/star/embed/ElementModes.hpp>
52 : : #include <com/sun/star/container/XEnumeration.hpp>
53 : : #include <com/sun/star/container/XNameAccess.hpp>
54 : : #include <com/sun/star/container/XContainerQuery.hpp>
55 : : #include <com/sun/star/view/XControlAccess.hpp>
56 : : #include <com/sun/star/ucb/InteractiveAugmentedIOException.hpp>
57 : :
58 : :
59 : : using namespace ::rtl;
60 : : using namespace ::com::sun::star::uno;
61 : : using namespace ::com::sun::star::lang;
62 : : using namespace ::com::sun::star::beans;
63 : : using namespace ::com::sun::star::container;
64 : : using namespace ::com::sun::star::view;
65 : : using namespace ::com::sun::star::ui::dialogs;
66 : :
67 : 0 : FileOpenDialog::FileOpenDialog( const Reference< XComponentContext >& rxMSF ) :
68 : 0 : mxMSF( rxMSF )
69 : : {
70 : 0 : Sequence< Any > aInitPropSeq( 1 );
71 : 0 : aInitPropSeq[ 0 ] <<= (sal_Int16)TemplateDescription::FILESAVE_AUTOEXTENSION; // TemplateDescription.FILEOPEN_SIMPLE
72 : :
73 : 0 : mxFilePicker = Reference < XFilePicker >( mxMSF->getServiceManager()->createInstanceWithArgumentsAndContext(
74 : 0 : OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.dialogs.FilePicker" ) ), aInitPropSeq, rxMSF ),UNO_QUERY_THROW );
75 : 0 : mxFilePicker->setMultiSelectionMode( sal_False );
76 : :
77 : 0 : Reference< XFilePickerControlAccess > xAccess( mxFilePicker, UNO_QUERY );
78 : 0 : if ( xAccess.is() )
79 : : {
80 : 0 : Any aValue( static_cast< sal_Bool >( sal_True ) );
81 : : try
82 : : {
83 : 0 : xAccess->setValue( ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION, 0, aValue );
84 : : }
85 : 0 : catch( com::sun::star::uno::Exception& )
86 : 0 : {}
87 : : }
88 : :
89 : : // collecting a list of impress filters
90 : 0 : Reference< XNameAccess > xFilters( mxMSF->getServiceManager()->createInstanceWithContext(
91 : 0 : OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.FilterFactory" ) ), rxMSF ), UNO_QUERY_THROW );
92 : 0 : Sequence< OUString > aFilterList( xFilters->getElementNames() );
93 : 0 : for ( int i = 0; i < aFilterList.getLength(); i++ )
94 : : {
95 : : try
96 : : {
97 : 0 : Sequence< PropertyValue > aFilterProperties;
98 : 0 : if ( xFilters->getByName( aFilterList[ i ] ) >>= aFilterProperties )
99 : : {
100 : 0 : FilterEntry aFilterEntry;
101 : 0 : sal_Bool bImpressFilter = sal_False;
102 : 0 : for ( int j = 0; j < aFilterProperties.getLength(); j++ )
103 : : {
104 : 0 : PropertyValue& rProperty( aFilterProperties[ j ] );
105 : 0 : switch( TKGet( rProperty.Name ) )
106 : : {
107 : : case TK_DocumentService :
108 : : {
109 : 0 : rtl::OUString sDocumentService;
110 : 0 : rProperty.Value >>= sDocumentService;
111 : 0 : if ( sDocumentService == "com.sun.star.presentation.PresentationDocument" )
112 : 0 : bImpressFilter = sal_True;
113 : : else
114 : 0 : j = aFilterProperties.getLength();
115 : : }
116 : 0 : break;
117 : 0 : case TK_Name : rProperty.Value >>= aFilterEntry.maName; break;
118 : 0 : case TK_UIName : rProperty.Value >>= aFilterEntry.maUIName; break;
119 : 0 : case TK_Type : rProperty.Value >>= aFilterEntry.maType; break;
120 : 0 : case TK_Flags : rProperty.Value >>= aFilterEntry.maFlags; break;
121 : 0 : default : break;
122 : : }
123 : : }
124 : 0 : if ( bImpressFilter && ( ( aFilterEntry.maFlags & 3 ) == 3 ) )
125 : : {
126 : 0 : aFilterEntryList.push_back( aFilterEntry );
127 : 0 : }
128 : 0 : }
129 : : }
130 : 0 : catch( Exception& )
131 : : {
132 : : }
133 : : }
134 : :
135 : 0 : Reference< XNameAccess > xTypes( mxMSF->getServiceManager()->createInstanceWithContext(
136 : 0 : OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.TypeDetection" ) ), rxMSF ), UNO_QUERY_THROW );
137 : 0 : Sequence< OUString > aTypeList( xFilters->getElementNames() );
138 : :
139 : : // mxFilePicker->setDefaultName( );
140 : :
141 : 0 : Reference< XFilterManager > xFilterManager( mxFilePicker, UNO_QUERY_THROW );
142 : 0 : std::vector< FilterEntry >::iterator aIter( aFilterEntryList.begin() );
143 : 0 : while( aIter != aFilterEntryList.end() )
144 : : {
145 : 0 : Sequence< PropertyValue > aTypeProperties;
146 : : try
147 : : {
148 : 0 : if ( xTypes->getByName( aIter->maType ) >>= aTypeProperties )
149 : : {
150 : 0 : Sequence< OUString > aExtensions;
151 : 0 : for ( int i = 0; i < aTypeProperties.getLength(); i++ )
152 : : {
153 : 0 : switch( TKGet( aTypeProperties[ i ].Name ) )
154 : : {
155 : 0 : case TK_Extensions : aTypeProperties[ i ].Value >>= aExtensions; break;
156 : 0 : default: break;
157 : : }
158 : : }
159 : 0 : if ( aExtensions.getLength() )
160 : : {
161 : 0 : xFilterManager->appendFilter( aIter->maUIName, aExtensions[ 0 ] );
162 : 0 : if ( aIter->maFlags & 0x100 )
163 : 0 : xFilterManager->setCurrentFilter( aIter->maUIName );
164 : 0 : }
165 : : }
166 : : }
167 : 0 : catch ( Exception& )
168 : : {
169 : : }
170 : 0 : aIter++;
171 : 0 : }
172 : 0 : }
173 : 0 : FileOpenDialog::~FileOpenDialog()
174 : : {
175 : 0 : }
176 : 0 : sal_Int16 FileOpenDialog::execute()
177 : : {
178 : 0 : return mxFilePicker->execute();
179 : : }
180 : 0 : void FileOpenDialog::setDefaultName( const rtl::OUString& rDefaultName )
181 : : {
182 : 0 : mxFilePicker->setDefaultName( rDefaultName );
183 : 0 : }
184 : 0 : ::rtl::OUString FileOpenDialog::getURL() const
185 : : {
186 : 0 : Sequence< OUString > aFileSeq( mxFilePicker->getFiles() );
187 : 0 : return aFileSeq.getLength() ? aFileSeq[ 0 ] : OUString();
188 : : };
189 : 0 : ::rtl::OUString FileOpenDialog::getFilterName() const
190 : : {
191 : 0 : rtl::OUString aFilterName;
192 : 0 : Reference< XFilterManager > xFilterManager( mxFilePicker, UNO_QUERY_THROW );
193 : 0 : rtl::OUString aUIName( xFilterManager->getCurrentFilter() );
194 : 0 : std::vector< FilterEntry >::const_iterator aIter( aFilterEntryList.begin() );
195 : 0 : while( aIter != aFilterEntryList.end() )
196 : : {
197 : 0 : if ( aIter->maUIName == aUIName )
198 : : {
199 : 0 : aFilterName = aIter->maName;
200 : 0 : break;
201 : : }
202 : 0 : aIter++;
203 : : }
204 : 0 : return aFilterName;
205 : : };
206 : :
207 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|