xref: /AOO41X/main/sfx2/source/doc/guisaveas.cxx (revision 5ba242785eb59bea42e5c20d42a82c057bb2d5f4)
1cdf0e10cSrcweir /*************************************************************************
2cdf0e10cSrcweir  *
3cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4cdf0e10cSrcweir  *
5cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6cdf0e10cSrcweir  *
7cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8cdf0e10cSrcweir  *
9cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10cdf0e10cSrcweir  *
11cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14cdf0e10cSrcweir  *
15cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20cdf0e10cSrcweir  *
21cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25cdf0e10cSrcweir  *
26cdf0e10cSrcweir  ************************************************************************/
27cdf0e10cSrcweir 
28cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29cdf0e10cSrcweir #include "precompiled_sfx2.hxx"
30cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
31cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XFilePicker.hpp>
32cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
33cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp>
34cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
35cdf0e10cSrcweir #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
36cdf0e10cSrcweir #include <com/sun/star/view/XSelectionSupplier.hpp>
37cdf0e10cSrcweir #include <com/sun/star/beans/XPropertyAccess.hpp>
38cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
39cdf0e10cSrcweir #include <com/sun/star/beans/XPropertyContainer.hpp>
40cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp>
41cdf0e10cSrcweir #include <com/sun/star/document/XExporter.hpp>
42cdf0e10cSrcweir #include <com/sun/star/document/XDocumentInfoSupplier.hpp>
43cdf0e10cSrcweir #include <com/sun/star/document/XDocumentInfo.hpp>
44cdf0e10cSrcweir #include <com/sun/star/task/XInteractionHandler.hpp>
45cdf0e10cSrcweir #include <com/sun/star/util/DateTime.hpp>
46cdf0e10cSrcweir #include <com/sun/star/util/XURLTransformer.hpp>
47cdf0e10cSrcweir #include <com/sun/star/frame/XStorable.hpp>
48cdf0e10cSrcweir #include <com/sun/star/frame/XStorable2.hpp>
49cdf0e10cSrcweir #include <com/sun/star/frame/XDispatchProvider.hpp>
50cdf0e10cSrcweir #include <com/sun/star/frame/XDispatch.hpp>
51cdf0e10cSrcweir #include <com/sun/star/frame/XTitle.hpp>
52cdf0e10cSrcweir #include <com/sun/star/util/XModifyListener.hpp>
53cdf0e10cSrcweir #include <com/sun/star/util/XModifiable.hpp>
54cdf0e10cSrcweir #include <com/sun/star/util/XModifyBroadcaster.hpp>
55cdf0e10cSrcweir 
56cdf0e10cSrcweir #include <com/sun/star/util/XCloneable.hpp>
57cdf0e10cSrcweir #include <com/sun/star/frame/XModuleManager.hpp>
58cdf0e10cSrcweir #include <com/sun/star/io/IOException.hpp>
59cdf0e10cSrcweir 
60cdf0e10cSrcweir #include "guisaveas.hxx"
61cdf0e10cSrcweir 
62cdf0e10cSrcweir #include <unotools/pathoptions.hxx>
63cdf0e10cSrcweir #include <unotools/pathoptions.hxx>
64cdf0e10cSrcweir #include <svl/itemset.hxx>
65cdf0e10cSrcweir #include <svl/eitem.hxx>
66cdf0e10cSrcweir #include <svl/stritem.hxx>
67cdf0e10cSrcweir #include <svl/intitem.hxx>
68cdf0e10cSrcweir #include <unotools/useroptions.hxx>
69cdf0e10cSrcweir #include <unotools/saveopt.hxx>
70cdf0e10cSrcweir #include <tools/debug.hxx>
71cdf0e10cSrcweir #include <tools/urlobj.hxx>
72cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
73cdf0e10cSrcweir #include <comphelper/configurationhelper.hxx>
74cdf0e10cSrcweir #include <comphelper/mimeconfighelper.hxx>
75cdf0e10cSrcweir #include <vcl/msgbox.hxx>
76cdf0e10cSrcweir #include <vcl/window.hxx>
77cdf0e10cSrcweir #include <toolkit/awt/vclxwindow.hxx>
78cdf0e10cSrcweir 
79cdf0e10cSrcweir #include <sfx2/sfxsids.hrc>
80cdf0e10cSrcweir #include <doc.hrc>
81cdf0e10cSrcweir #include <sfx2/sfxresid.hxx>
82cdf0e10cSrcweir #include <sfx2/docfilt.hxx>
83cdf0e10cSrcweir #include <sfx2/filedlghelper.hxx>
84cdf0e10cSrcweir #include <sfx2/app.hxx>
85cdf0e10cSrcweir #include <sfx2/objsh.hxx>
86cdf0e10cSrcweir #include <sfx2/dinfdlg.hxx>
87cdf0e10cSrcweir #include <sfx2/request.hxx>
88cdf0e10cSrcweir #include <sfxtypes.hxx>
89cdf0e10cSrcweir #include "alienwarn.hxx"
90cdf0e10cSrcweir 
91cdf0e10cSrcweir #include "../appl/app.hrc"
92cdf0e10cSrcweir 
93cdf0e10cSrcweir #define DOCPROPSNUM 17
94cdf0e10cSrcweir 
95cdf0e10cSrcweir // flags that specify requested operation
96cdf0e10cSrcweir #define EXPORT_REQUESTED 			1
97cdf0e10cSrcweir #define PDFEXPORT_REQUESTED			2
98cdf0e10cSrcweir #define PDFDIRECTEXPORT_REQUESTED	4
99cdf0e10cSrcweir #define WIDEEXPORT_REQUESTED		8
100cdf0e10cSrcweir #define SAVE_REQUESTED				16
101cdf0e10cSrcweir #define SAVEAS_REQUESTED			32
102cdf0e10cSrcweir 
103cdf0e10cSrcweir // possible statuses of save operation
104cdf0e10cSrcweir #define STATUS_NO_ACTION			0
105cdf0e10cSrcweir #define STATUS_SAVE					1
106cdf0e10cSrcweir #define STATUS_SAVEAS				2
107cdf0e10cSrcweir #define STATUS_SAVEAS_STANDARDNAME	3
108cdf0e10cSrcweir 
109cdf0e10cSrcweir const ::rtl::OUString aFilterNameString = ::rtl::OUString::createFromAscii( "FilterName" );
110cdf0e10cSrcweir const ::rtl::OUString aFilterOptionsString = ::rtl::OUString::createFromAscii( "FilterOptions" );
111cdf0e10cSrcweir const ::rtl::OUString aFilterDataString    = ::rtl::OUString::createFromAscii( "FilterData" );
112cdf0e10cSrcweir const ::rtl::OUString aFilterFlagsString   = ::rtl::OUString::createFromAscii( "FilterFlags" );
113cdf0e10cSrcweir 
114cdf0e10cSrcweir using namespace ::com::sun::star;
115cdf0e10cSrcweir 
116cdf0e10cSrcweir namespace {
117cdf0e10cSrcweir //-------------------------------------------------------------------------
118cdf0e10cSrcweir static sal_uInt16 getSlotIDFromMode( sal_Int8 nStoreMode )
119cdf0e10cSrcweir {
120cdf0e10cSrcweir 	// This is a temporary hardcoded solution must be removed when
121cdf0e10cSrcweir 	// dialogs do not need parameters in SidSet representation any more
122cdf0e10cSrcweir 
123cdf0e10cSrcweir 	sal_uInt16 nResult = 0;
124cdf0e10cSrcweir 	if ( nStoreMode == EXPORT_REQUESTED )
125cdf0e10cSrcweir 		nResult = SID_EXPORTDOC;
126cdf0e10cSrcweir 	else if ( nStoreMode == ( EXPORT_REQUESTED | PDFEXPORT_REQUESTED ) )
127cdf0e10cSrcweir 		nResult = SID_EXPORTDOCASPDF;
128cdf0e10cSrcweir 	else if ( nStoreMode == ( EXPORT_REQUESTED | PDFEXPORT_REQUESTED | PDFDIRECTEXPORT_REQUESTED ) )
129cdf0e10cSrcweir 		nResult = SID_DIRECTEXPORTDOCASPDF;
130cdf0e10cSrcweir 	else if ( nStoreMode == SAVEAS_REQUESTED || nStoreMode == ( EXPORT_REQUESTED | WIDEEXPORT_REQUESTED ) )
131cdf0e10cSrcweir 		nResult = SID_SAVEASDOC;
132cdf0e10cSrcweir 	else {
133cdf0e10cSrcweir 		DBG_ASSERT( sal_False, "Unacceptable slot name is provided!\n" );
134cdf0e10cSrcweir     }
135cdf0e10cSrcweir 
136cdf0e10cSrcweir 	return nResult;
137cdf0e10cSrcweir }
138cdf0e10cSrcweir 
139cdf0e10cSrcweir //-------------------------------------------------------------------------
140cdf0e10cSrcweir static sal_uInt8 getStoreModeFromSlotName( const ::rtl::OUString& aSlotName )
141cdf0e10cSrcweir {
142cdf0e10cSrcweir 	sal_uInt8 nResult = 0;
143cdf0e10cSrcweir 	if ( aSlotName.equalsAscii( "ExportTo" ) )
144cdf0e10cSrcweir 		nResult = EXPORT_REQUESTED;
145cdf0e10cSrcweir 	else if ( aSlotName.equalsAscii( "ExportToPDF" ) )
146cdf0e10cSrcweir 		nResult = EXPORT_REQUESTED | PDFEXPORT_REQUESTED;
147cdf0e10cSrcweir 	else if ( aSlotName.equalsAscii( "ExportDirectToPDF" ) )
148cdf0e10cSrcweir 		nResult = EXPORT_REQUESTED | PDFEXPORT_REQUESTED | PDFDIRECTEXPORT_REQUESTED;
149cdf0e10cSrcweir 	else if ( aSlotName.equalsAscii( "Save" ) )
150cdf0e10cSrcweir 		nResult = SAVE_REQUESTED;
151cdf0e10cSrcweir 	else if ( aSlotName.equalsAscii( "SaveAs" ) )
152cdf0e10cSrcweir 		nResult = SAVEAS_REQUESTED;
153cdf0e10cSrcweir 	else
154cdf0e10cSrcweir 		throw task::ErrorCodeIOException( ::rtl::OUString(),
155cdf0e10cSrcweir 											uno::Reference< uno::XInterface >(),
156cdf0e10cSrcweir 											ERRCODE_IO_INVALIDPARAMETER );
157cdf0e10cSrcweir 
158cdf0e10cSrcweir 	return nResult;
159cdf0e10cSrcweir }
160cdf0e10cSrcweir 
161cdf0e10cSrcweir //-------------------------------------------------------------------------
162cdf0e10cSrcweir static sal_Int32 getMustFlags( sal_Int8 nStoreMode )
163cdf0e10cSrcweir {
164cdf0e10cSrcweir 	return ( SFX_FILTER_EXPORT
165cdf0e10cSrcweir 			| ( ( ( nStoreMode & EXPORT_REQUESTED ) && !( nStoreMode & WIDEEXPORT_REQUESTED ) ) ? 0 : SFX_FILTER_IMPORT ) );
166cdf0e10cSrcweir }
167cdf0e10cSrcweir 
168cdf0e10cSrcweir //-------------------------------------------------------------------------
169cdf0e10cSrcweir static sal_Int32 getDontFlags( sal_Int8 nStoreMode )
170cdf0e10cSrcweir {
171cdf0e10cSrcweir 	return ( SFX_FILTER_INTERNAL
172cdf0e10cSrcweir 			| SFX_FILTER_NOTINFILEDLG
173cdf0e10cSrcweir 			| ( ( ( nStoreMode & EXPORT_REQUESTED ) && !( nStoreMode & WIDEEXPORT_REQUESTED ) ) ? SFX_FILTER_IMPORT : 0 ) );
174cdf0e10cSrcweir }
175cdf0e10cSrcweir 
176cdf0e10cSrcweir //=========================================================================
177cdf0e10cSrcweir // class DocumentSettingsGuard
178cdf0e10cSrcweir //=========================================================================
179cdf0e10cSrcweir 
180cdf0e10cSrcweir class DocumentSettingsGuard
181cdf0e10cSrcweir {
182cdf0e10cSrcweir     uno::Reference< beans::XPropertySet > m_xDocumentSettings;
183cdf0e10cSrcweir     sal_Bool m_bPreserveReadOnly;
184cdf0e10cSrcweir     sal_Bool m_bReadOnlySupported;
185cdf0e10cSrcweir 
186cdf0e10cSrcweir     sal_Bool m_bRestoreSettings;
187cdf0e10cSrcweir public:
188cdf0e10cSrcweir     DocumentSettingsGuard( const uno::Reference< frame::XModel >& xModel, sal_Bool bReadOnly, sal_Bool bRestore )
189cdf0e10cSrcweir     : m_bPreserveReadOnly( sal_False )
190cdf0e10cSrcweir     , m_bReadOnlySupported( sal_False )
191cdf0e10cSrcweir     , m_bRestoreSettings( bRestore )
192cdf0e10cSrcweir     {
193cdf0e10cSrcweir         try
194cdf0e10cSrcweir         {
195cdf0e10cSrcweir             uno::Reference< lang::XMultiServiceFactory > xDocSettingsSupplier( xModel, uno::UNO_QUERY_THROW );
196cdf0e10cSrcweir             m_xDocumentSettings.set(
197cdf0e10cSrcweir                 xDocSettingsSupplier->createInstance(
198cdf0e10cSrcweir                     ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.Settings" ) ) ),
199cdf0e10cSrcweir                 uno::UNO_QUERY_THROW );
200cdf0e10cSrcweir 
201cdf0e10cSrcweir             ::rtl::OUString aLoadReadonlyString( RTL_CONSTASCII_USTRINGPARAM( "LoadReadonly" ) );
202cdf0e10cSrcweir 
203cdf0e10cSrcweir             try
204cdf0e10cSrcweir             {
205cdf0e10cSrcweir                 m_xDocumentSettings->getPropertyValue( aLoadReadonlyString ) >>= m_bPreserveReadOnly;
206cdf0e10cSrcweir                 m_xDocumentSettings->setPropertyValue( aLoadReadonlyString, uno::makeAny( bReadOnly ) );
207cdf0e10cSrcweir                 m_bReadOnlySupported = sal_True;
208cdf0e10cSrcweir             }
209cdf0e10cSrcweir             catch( uno::Exception& )
210cdf0e10cSrcweir             {}
211cdf0e10cSrcweir         }
212cdf0e10cSrcweir         catch( uno::Exception& )
213cdf0e10cSrcweir         {}
214cdf0e10cSrcweir 
215cdf0e10cSrcweir         if ( ( bReadOnly && !m_bReadOnlySupported ) )
216cdf0e10cSrcweir             throw uno::RuntimeException(); // the user could provide the data, so it must be stored
217cdf0e10cSrcweir     }
218cdf0e10cSrcweir 
219cdf0e10cSrcweir     ~DocumentSettingsGuard()
220cdf0e10cSrcweir     {
221cdf0e10cSrcweir         if ( m_bRestoreSettings )
222cdf0e10cSrcweir         {
223cdf0e10cSrcweir             ::rtl::OUString aLoadReadonlyString( RTL_CONSTASCII_USTRINGPARAM( "LoadReadonly" ) );
224cdf0e10cSrcweir 
225cdf0e10cSrcweir             try
226cdf0e10cSrcweir             {
227cdf0e10cSrcweir                 if ( m_bReadOnlySupported )
228cdf0e10cSrcweir                     m_xDocumentSettings->setPropertyValue( aLoadReadonlyString, uno::makeAny( m_bPreserveReadOnly ) );
229cdf0e10cSrcweir             }
230cdf0e10cSrcweir             catch( uno::Exception& )
231cdf0e10cSrcweir             {
232cdf0e10cSrcweir                 OSL_ASSERT( "Unexpected exception!" );
233cdf0e10cSrcweir             }
234cdf0e10cSrcweir         }
235cdf0e10cSrcweir     }
236cdf0e10cSrcweir };
237cdf0e10cSrcweir } // anonymous namespace
238cdf0e10cSrcweir 
239cdf0e10cSrcweir //=========================================================================
240cdf0e10cSrcweir // class ModelData_Impl
241cdf0e10cSrcweir //=========================================================================
242cdf0e10cSrcweir class ModelData_Impl
243cdf0e10cSrcweir {
244cdf0e10cSrcweir 	SfxStoringHelper* m_pOwner;
245cdf0e10cSrcweir 	uno::Reference< frame::XModel > m_xModel;
246cdf0e10cSrcweir 	uno::Reference< frame::XStorable > m_xStorable;
247cdf0e10cSrcweir 	uno::Reference< frame::XStorable2 > m_xStorable2;
248cdf0e10cSrcweir 	uno::Reference< util::XModifiable > m_xModifiable;
249cdf0e10cSrcweir 
250cdf0e10cSrcweir 	::rtl::OUString m_aModuleName;
251cdf0e10cSrcweir 	::comphelper::SequenceAsHashMap* m_pDocumentPropsHM;
252cdf0e10cSrcweir 	::comphelper::SequenceAsHashMap* m_pModulePropsHM;
253cdf0e10cSrcweir 
254cdf0e10cSrcweir 	::comphelper::SequenceAsHashMap m_aMediaDescrHM;
255cdf0e10cSrcweir 
256cdf0e10cSrcweir     sal_Bool m_bRecommendReadOnly;
257cdf0e10cSrcweir 
258cdf0e10cSrcweir public:
259cdf0e10cSrcweir 	ModelData_Impl( SfxStoringHelper& aOwner,
260cdf0e10cSrcweir 					const uno::Reference< frame::XModel >& xModel,
261cdf0e10cSrcweir 					const uno::Sequence< beans::PropertyValue >& aMediaDescr );
262cdf0e10cSrcweir 
263cdf0e10cSrcweir 	~ModelData_Impl();
264cdf0e10cSrcweir 
265cdf0e10cSrcweir 	void FreeDocumentProps();
266cdf0e10cSrcweir 
267cdf0e10cSrcweir 	uno::Reference< frame::XModel > GetModel();
268cdf0e10cSrcweir 	uno::Reference< frame::XStorable > GetStorable();
269cdf0e10cSrcweir 	uno::Reference< frame::XStorable2 > GetStorable2();
270cdf0e10cSrcweir 	uno::Reference< util::XModifiable > GetModifiable();
271cdf0e10cSrcweir 
272cdf0e10cSrcweir 	::comphelper::SequenceAsHashMap& GetMediaDescr() { return m_aMediaDescrHM; }
273cdf0e10cSrcweir 
274cdf0e10cSrcweir     sal_Bool IsRecommendReadOnly() { return m_bRecommendReadOnly; }
275cdf0e10cSrcweir 
276cdf0e10cSrcweir 	const ::comphelper::SequenceAsHashMap& GetDocProps();
277cdf0e10cSrcweir 
278cdf0e10cSrcweir 	::rtl::OUString GetModuleName();
279cdf0e10cSrcweir 	const ::comphelper::SequenceAsHashMap& GetModuleProps();
280cdf0e10cSrcweir 
281cdf0e10cSrcweir 	void CheckInteractionHandler();
282cdf0e10cSrcweir 
283cdf0e10cSrcweir 
284cdf0e10cSrcweir 	::rtl::OUString GetDocServiceName();
285cdf0e10cSrcweir 	uno::Sequence< beans::PropertyValue > GetDocServiceDefaultFilterCheckFlags( sal_Int32 nMust, sal_Int32 nDont );
286cdf0e10cSrcweir 	uno::Sequence< beans::PropertyValue > GetDocServiceAnyFilter( sal_Int32 nMust, sal_Int32 nDont );
287cdf0e10cSrcweir 	uno::Sequence< beans::PropertyValue > GetPreselectedFilter_Impl( sal_Int8 nStoreMode );
288cdf0e10cSrcweir 	uno::Sequence< beans::PropertyValue > GetDocServiceDefaultFilter();
289cdf0e10cSrcweir 
290cdf0e10cSrcweir 	sal_Bool ExecuteFilterDialog_Impl( const ::rtl::OUString& aFilterName );
291cdf0e10cSrcweir 
292cdf0e10cSrcweir 	sal_Int8 CheckSaveAcceptable( sal_Int8 nCurStatus );
293cdf0e10cSrcweir     sal_Int8 CheckStateForSave();
294cdf0e10cSrcweir 
295cdf0e10cSrcweir     sal_Int8 CheckFilter( const ::rtl::OUString& );
296cdf0e10cSrcweir 
297cdf0e10cSrcweir 	sal_Bool CheckFilterOptionsDialogExistence();
298cdf0e10cSrcweir 
299cdf0e10cSrcweir 	sal_Bool OutputFileDialog( sal_Int8 nStoreMode,
300cdf0e10cSrcweir 								const ::comphelper::SequenceAsHashMap& aPreselectedFilterPropsHM,
301cdf0e10cSrcweir 								sal_Bool bSetStandardName,
302cdf0e10cSrcweir 								::rtl::OUString& aSuggestedName,
303cdf0e10cSrcweir                                 sal_Bool bPreselectPassword,
304cdf0e10cSrcweir 								const ::rtl::OUString& aSuggestedDir,
305cdf0e10cSrcweir 								sal_Int16 nDialog,
306cdf0e10cSrcweir 								const ::rtl::OUString& rStandardDir,
307cdf0e10cSrcweir 								const ::com::sun::star::uno::Sequence< ::rtl::OUString >& rBlackList
308cdf0e10cSrcweir 								);
309cdf0e10cSrcweir 
310cdf0e10cSrcweir 	sal_Bool ShowDocumentInfoDialog();
311cdf0e10cSrcweir 
312cdf0e10cSrcweir     ::rtl::OUString GetReccomendedDir( const ::rtl::OUString& aSuggestedDir,
313cdf0e10cSrcweir                                        const sfx2::FileDialogHelper::Context& aCtxt );
314cdf0e10cSrcweir     ::rtl::OUString GetReccomendedName( const ::rtl::OUString& aSuggestedName,
315cdf0e10cSrcweir                                         const ::rtl::OUString& aTypeName );
316cdf0e10cSrcweir 
317cdf0e10cSrcweir };
318cdf0e10cSrcweir 
319cdf0e10cSrcweir //-------------------------------------------------------------------------
320cdf0e10cSrcweir ModelData_Impl::ModelData_Impl( SfxStoringHelper& aOwner,
321cdf0e10cSrcweir 								const uno::Reference< frame::XModel >& xModel,
322cdf0e10cSrcweir 								const uno::Sequence< beans::PropertyValue >& aMediaDescr )
323cdf0e10cSrcweir : m_pOwner( &aOwner )
324cdf0e10cSrcweir , m_xModel( xModel )
325cdf0e10cSrcweir , m_pDocumentPropsHM( NULL )
326cdf0e10cSrcweir , m_pModulePropsHM( NULL )
327cdf0e10cSrcweir , m_aMediaDescrHM( aMediaDescr )
328cdf0e10cSrcweir , m_bRecommendReadOnly( sal_False )
329cdf0e10cSrcweir {
330cdf0e10cSrcweir 	CheckInteractionHandler();
331cdf0e10cSrcweir }
332cdf0e10cSrcweir 
333cdf0e10cSrcweir //-------------------------------------------------------------------------
334cdf0e10cSrcweir ModelData_Impl::~ModelData_Impl()
335cdf0e10cSrcweir {
336cdf0e10cSrcweir 	FreeDocumentProps();
337cdf0e10cSrcweir 	if ( m_pDocumentPropsHM )
338cdf0e10cSrcweir 		delete m_pDocumentPropsHM;
339cdf0e10cSrcweir 
340cdf0e10cSrcweir 	if ( m_pModulePropsHM )
341cdf0e10cSrcweir 		delete m_pModulePropsHM;
342cdf0e10cSrcweir }
343cdf0e10cSrcweir 
344cdf0e10cSrcweir //-------------------------------------------------------------------------
345cdf0e10cSrcweir void ModelData_Impl::FreeDocumentProps()
346cdf0e10cSrcweir {
347cdf0e10cSrcweir 	if ( m_pDocumentPropsHM )
348cdf0e10cSrcweir 	{
349cdf0e10cSrcweir 		delete m_pDocumentPropsHM;
350cdf0e10cSrcweir 		m_pDocumentPropsHM = NULL;
351cdf0e10cSrcweir 	}
352cdf0e10cSrcweir }
353cdf0e10cSrcweir 
354cdf0e10cSrcweir //-------------------------------------------------------------------------
355cdf0e10cSrcweir uno::Reference< frame::XModel > ModelData_Impl::GetModel()
356cdf0e10cSrcweir {
357cdf0e10cSrcweir 	if ( !m_xModel.is() )
358cdf0e10cSrcweir 		throw uno::RuntimeException();
359cdf0e10cSrcweir 
360cdf0e10cSrcweir 	return m_xModel;
361cdf0e10cSrcweir }
362cdf0e10cSrcweir 
363cdf0e10cSrcweir //-------------------------------------------------------------------------
364cdf0e10cSrcweir uno::Reference< frame::XStorable > ModelData_Impl::GetStorable()
365cdf0e10cSrcweir {
366cdf0e10cSrcweir 	if ( !m_xStorable.is() )
367cdf0e10cSrcweir 	{
368cdf0e10cSrcweir 		m_xStorable = uno::Reference< frame::XStorable >( m_xModel, uno::UNO_QUERY );
369cdf0e10cSrcweir 		if ( !m_xStorable.is() )
370cdf0e10cSrcweir 			throw uno::RuntimeException();
371cdf0e10cSrcweir 	}
372cdf0e10cSrcweir 
373cdf0e10cSrcweir 	return m_xStorable;
374cdf0e10cSrcweir }
375cdf0e10cSrcweir 
376cdf0e10cSrcweir //-------------------------------------------------------------------------
377cdf0e10cSrcweir uno::Reference< frame::XStorable2 > ModelData_Impl::GetStorable2()
378cdf0e10cSrcweir {
379cdf0e10cSrcweir 	if ( !m_xStorable2.is() )
380cdf0e10cSrcweir 	{
381cdf0e10cSrcweir 		m_xStorable2 = uno::Reference< frame::XStorable2 >( m_xModel, uno::UNO_QUERY );
382cdf0e10cSrcweir 		if ( !m_xStorable2.is() )
383cdf0e10cSrcweir 			throw uno::RuntimeException();
384cdf0e10cSrcweir 	}
385cdf0e10cSrcweir 
386cdf0e10cSrcweir 	return m_xStorable2;
387cdf0e10cSrcweir }
388cdf0e10cSrcweir 
389cdf0e10cSrcweir //-------------------------------------------------------------------------
390cdf0e10cSrcweir uno::Reference< util::XModifiable > ModelData_Impl::GetModifiable()
391cdf0e10cSrcweir {
392cdf0e10cSrcweir 	if ( !m_xModifiable.is() )
393cdf0e10cSrcweir 	{
394cdf0e10cSrcweir 		m_xModifiable = uno::Reference< util::XModifiable >( m_xModel, uno::UNO_QUERY );
395cdf0e10cSrcweir 		if ( !m_xModifiable.is() )
396cdf0e10cSrcweir 			throw uno::RuntimeException();
397cdf0e10cSrcweir 	}
398cdf0e10cSrcweir 
399cdf0e10cSrcweir 	return m_xModifiable;
400cdf0e10cSrcweir }
401cdf0e10cSrcweir 
402cdf0e10cSrcweir //-------------------------------------------------------------------------
403cdf0e10cSrcweir const ::comphelper::SequenceAsHashMap& ModelData_Impl::GetDocProps()
404cdf0e10cSrcweir {
405cdf0e10cSrcweir 	if ( !m_pDocumentPropsHM )
406cdf0e10cSrcweir 		m_pDocumentPropsHM = new ::comphelper::SequenceAsHashMap( GetModel()->getArgs() );
407cdf0e10cSrcweir 
408cdf0e10cSrcweir 	return *m_pDocumentPropsHM;
409cdf0e10cSrcweir }
410cdf0e10cSrcweir 
411cdf0e10cSrcweir //-------------------------------------------------------------------------
412cdf0e10cSrcweir ::rtl::OUString ModelData_Impl::GetModuleName()
413cdf0e10cSrcweir {
414cdf0e10cSrcweir 	if ( !m_aModuleName.getLength() )
415cdf0e10cSrcweir 	{
416cdf0e10cSrcweir 		m_aModuleName = m_pOwner->GetModuleManager()->identify(
417cdf0e10cSrcweir 												uno::Reference< uno::XInterface >( m_xModel, uno::UNO_QUERY ) );
418cdf0e10cSrcweir         if ( !m_aModuleName.getLength() )
419cdf0e10cSrcweir             throw uno::RuntimeException(); // TODO:
420cdf0e10cSrcweir 	}
421cdf0e10cSrcweir 	return m_aModuleName;
422cdf0e10cSrcweir }
423cdf0e10cSrcweir 
424cdf0e10cSrcweir //-------------------------------------------------------------------------
425cdf0e10cSrcweir const ::comphelper::SequenceAsHashMap& ModelData_Impl::GetModuleProps()
426cdf0e10cSrcweir {
427cdf0e10cSrcweir 	if ( !m_pModulePropsHM )
428cdf0e10cSrcweir 	{
429cdf0e10cSrcweir 		uno::Sequence< beans::PropertyValue > aModuleProps;
430cdf0e10cSrcweir 		m_pOwner->GetNamedModuleManager()->getByName( GetModuleName() ) >>= aModuleProps;
431cdf0e10cSrcweir         if ( !aModuleProps.getLength() )
432cdf0e10cSrcweir             throw uno::RuntimeException(); // TODO;
433cdf0e10cSrcweir 		m_pModulePropsHM = new ::comphelper::SequenceAsHashMap( aModuleProps );
434cdf0e10cSrcweir 	}
435cdf0e10cSrcweir 
436cdf0e10cSrcweir 	return *m_pModulePropsHM;
437cdf0e10cSrcweir }
438cdf0e10cSrcweir 
439cdf0e10cSrcweir //-------------------------------------------------------------------------
440cdf0e10cSrcweir ::rtl::OUString ModelData_Impl::GetDocServiceName()
441cdf0e10cSrcweir {
442cdf0e10cSrcweir     return GetModuleProps().getUnpackedValueOrDefault(::rtl::OUString::createFromAscii( "ooSetupFactoryDocumentService" ), ::rtl::OUString());
443cdf0e10cSrcweir }
444cdf0e10cSrcweir 
445cdf0e10cSrcweir //-------------------------------------------------------------------------
446cdf0e10cSrcweir void ModelData_Impl::CheckInteractionHandler()
447cdf0e10cSrcweir {
448cdf0e10cSrcweir 	::comphelper::SequenceAsHashMap::const_iterator aInteractIter =
449cdf0e10cSrcweir 			m_aMediaDescrHM.find( ::rtl::OUString::createFromAscii( "InteractionHandler" ) );
450cdf0e10cSrcweir 
451cdf0e10cSrcweir 	if ( aInteractIter == m_aMediaDescrHM.end() )
452cdf0e10cSrcweir 	{
453cdf0e10cSrcweir 		try {
454cdf0e10cSrcweir 			m_aMediaDescrHM[ ::rtl::OUString::createFromAscii( "InteractionHandler" ) ]
455cdf0e10cSrcweir 				<<= uno::Reference< task::XInteractionHandler >(
456cdf0e10cSrcweir 							m_pOwner->GetServiceFactory()->createInstance(
457cdf0e10cSrcweir 											DEFINE_CONST_UNICODE("com.sun.star.task.InteractionHandler") ),
458cdf0e10cSrcweir 							uno::UNO_QUERY );
459cdf0e10cSrcweir 		}
460cdf0e10cSrcweir 		catch( uno::Exception& )
461cdf0e10cSrcweir 		{
462cdf0e10cSrcweir 		}
463cdf0e10cSrcweir 	}
464cdf0e10cSrcweir 	else
465cdf0e10cSrcweir 	{
466cdf0e10cSrcweir 		uno::Reference< task::XInteractionHandler > xInteract;
467cdf0e10cSrcweir 		DBG_ASSERT( ( aInteractIter->second >>= xInteract ) && xInteract.is(), "Broken interaction handler is provided!\n" );
468cdf0e10cSrcweir 	}
469cdf0e10cSrcweir }
470cdf0e10cSrcweir 
471cdf0e10cSrcweir //-------------------------------------------------------------------------
472cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > ModelData_Impl::GetDocServiceDefaultFilter()
473cdf0e10cSrcweir {
474cdf0e10cSrcweir 	uno::Sequence< beans::PropertyValue > aProps;
475cdf0e10cSrcweir 
476cdf0e10cSrcweir 	::rtl::OUString aFilterName = GetModuleProps().getUnpackedValueOrDefault(
477cdf0e10cSrcweir 																::rtl::OUString::createFromAscii( "ooSetupFactoryDefaultFilter" ),
478cdf0e10cSrcweir 																::rtl::OUString() );
479cdf0e10cSrcweir 
480cdf0e10cSrcweir 	m_pOwner->GetFilterConfiguration()->getByName( aFilterName ) >>= aProps;
481cdf0e10cSrcweir 
482cdf0e10cSrcweir 	return aProps;
483cdf0e10cSrcweir }
484cdf0e10cSrcweir 
485cdf0e10cSrcweir //-------------------------------------------------------------------------
486cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > ModelData_Impl::GetDocServiceDefaultFilterCheckFlags( sal_Int32 nMust,
487cdf0e10cSrcweir 																								sal_Int32 nDont )
488cdf0e10cSrcweir {
489cdf0e10cSrcweir 	uno::Sequence< beans::PropertyValue > aFilterProps;
490cdf0e10cSrcweir 	uno::Sequence< beans::PropertyValue > aProps = GetDocServiceDefaultFilter();
491cdf0e10cSrcweir 	if ( aProps.getLength() )
492cdf0e10cSrcweir 	{
493cdf0e10cSrcweir 		::comphelper::SequenceAsHashMap aFiltHM( aProps );
494cdf0e10cSrcweir 		sal_Int32 nFlags = aFiltHM.getUnpackedValueOrDefault( ::rtl::OUString::createFromAscii( "Flags" ),
495cdf0e10cSrcweir 														(sal_Int32)0 );
496cdf0e10cSrcweir 		if ( ( ( nFlags & nMust ) == nMust ) && !( nFlags & nDont ) )
497cdf0e10cSrcweir 			aFilterProps = aProps;
498cdf0e10cSrcweir 	}
499cdf0e10cSrcweir 
500cdf0e10cSrcweir 	return aFilterProps;
501cdf0e10cSrcweir }
502cdf0e10cSrcweir 
503cdf0e10cSrcweir 
504cdf0e10cSrcweir //-------------------------------------------------------------------------
505cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > ModelData_Impl::GetDocServiceAnyFilter( sal_Int32 nMust, sal_Int32 nDont )
506cdf0e10cSrcweir {
507cdf0e10cSrcweir 	uno::Sequence< beans::NamedValue > aSearchRequest( 1 );
508cdf0e10cSrcweir 	aSearchRequest[0].Name = ::rtl::OUString::createFromAscii( "DocumentService" );
509cdf0e10cSrcweir 	aSearchRequest[0].Value <<= GetDocServiceName();
510cdf0e10cSrcweir 
511cdf0e10cSrcweir 	return ::comphelper::MimeConfigurationHelper::SearchForFilter( m_pOwner->GetFilterQuery(), aSearchRequest, nMust, nDont );
512cdf0e10cSrcweir }
513cdf0e10cSrcweir 
514cdf0e10cSrcweir //-------------------------------------------------------------------------
515cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > ModelData_Impl::GetPreselectedFilter_Impl( sal_Int8 nStoreMode )
516cdf0e10cSrcweir {
517cdf0e10cSrcweir 	uno::Sequence< beans::PropertyValue > aFilterProps;
518cdf0e10cSrcweir 
519cdf0e10cSrcweir 	sal_Int32 nMust = getMustFlags( nStoreMode );
520cdf0e10cSrcweir 	sal_Int32 nDont = getDontFlags( nStoreMode );
521cdf0e10cSrcweir 
522cdf0e10cSrcweir 	if ( nStoreMode & PDFEXPORT_REQUESTED )
523cdf0e10cSrcweir 	{
524cdf0e10cSrcweir 		// Preselect PDF-Filter for EXPORT
525cdf0e10cSrcweir 		uno::Sequence< beans::NamedValue > aSearchRequest( 2 );
526cdf0e10cSrcweir 		aSearchRequest[0].Name = ::rtl::OUString::createFromAscii( "Type" );
527cdf0e10cSrcweir 		aSearchRequest[0].Value <<= ::rtl::OUString::createFromAscii( "pdf_Portable_Document_Format" );
528cdf0e10cSrcweir 		aSearchRequest[1].Name = ::rtl::OUString::createFromAscii( "DocumentService" );
529cdf0e10cSrcweir 		aSearchRequest[1].Value <<= GetDocServiceName();
530cdf0e10cSrcweir 
531cdf0e10cSrcweir 		aFilterProps = ::comphelper::MimeConfigurationHelper::SearchForFilter( m_pOwner->GetFilterQuery(), aSearchRequest, nMust, nDont );
532cdf0e10cSrcweir 	}
533cdf0e10cSrcweir 	else
534cdf0e10cSrcweir 	{
535cdf0e10cSrcweir 		aFilterProps = GetDocServiceDefaultFilterCheckFlags( nMust, nDont );
536cdf0e10cSrcweir 
537cdf0e10cSrcweir 		if ( !aFilterProps.getLength() )
538cdf0e10cSrcweir 		{
539cdf0e10cSrcweir 			// the default filter was not faund, use just the first acceptable one
540cdf0e10cSrcweir 			aFilterProps = GetDocServiceAnyFilter( nMust, nDont );
541cdf0e10cSrcweir 		}
542cdf0e10cSrcweir 	}
543cdf0e10cSrcweir 
544cdf0e10cSrcweir 	return aFilterProps;
545cdf0e10cSrcweir }
546cdf0e10cSrcweir 
547cdf0e10cSrcweir //-------------------------------------------------------------------------
548cdf0e10cSrcweir sal_Bool ModelData_Impl::ExecuteFilterDialog_Impl( const ::rtl::OUString& aFilterName )
549cdf0e10cSrcweir {
550cdf0e10cSrcweir 	sal_Bool bDialogUsed = sal_False;
551cdf0e10cSrcweir 
552cdf0e10cSrcweir 	try {
553cdf0e10cSrcweir 		uno::Sequence < beans::PropertyValue > aProps;
554cdf0e10cSrcweir 	  	uno::Any aAny = m_pOwner->GetFilterConfiguration()->getByName( aFilterName );
555cdf0e10cSrcweir 	   	if ( aAny >>= aProps )
556cdf0e10cSrcweir 	   	{
557cdf0e10cSrcweir 	   		sal_Int32 nPropertyCount = aProps.getLength();
558cdf0e10cSrcweir 	   		for( sal_Int32 nProperty=0; nProperty < nPropertyCount; ++nProperty )
559cdf0e10cSrcweir 	   			if( aProps[nProperty].Name.equals( ::rtl::OUString::createFromAscii("UIComponent")) )
560cdf0e10cSrcweir 	   			{
561cdf0e10cSrcweir 					::rtl::OUString aServiceName;
562cdf0e10cSrcweir 	   			    aProps[nProperty].Value >>= aServiceName;
563cdf0e10cSrcweir 					if( aServiceName.getLength() )
564cdf0e10cSrcweir 					{
565cdf0e10cSrcweir 						uno::Reference< ui::dialogs::XExecutableDialog > xFilterDialog(
566cdf0e10cSrcweir 													m_pOwner->GetServiceFactory()->createInstance( aServiceName ), uno::UNO_QUERY );
567cdf0e10cSrcweir 						uno::Reference< beans::XPropertyAccess > xFilterProperties( xFilterDialog, uno::UNO_QUERY );
568cdf0e10cSrcweir 
569cdf0e10cSrcweir 						if( xFilterDialog.is() && xFilterProperties.is() )
570cdf0e10cSrcweir 						{
571cdf0e10cSrcweir 							bDialogUsed = sal_True;
572cdf0e10cSrcweir 
573cdf0e10cSrcweir 							uno::Reference< document::XExporter > xExporter( xFilterDialog, uno::UNO_QUERY );
574cdf0e10cSrcweir 							if( xExporter.is() )
575cdf0e10cSrcweir 								xExporter->setSourceDocument(
576cdf0e10cSrcweir 									uno::Reference< lang::XComponent >( GetModel(), uno::UNO_QUERY ) );
577cdf0e10cSrcweir 
578cdf0e10cSrcweir 							uno::Sequence< beans::PropertyValue > aPropsForDialog;
579cdf0e10cSrcweir 							GetMediaDescr() >> aPropsForDialog;
580cdf0e10cSrcweir 							xFilterProperties->setPropertyValues( aPropsForDialog );
581cdf0e10cSrcweir 
582cdf0e10cSrcweir 							if( xFilterDialog->execute() )
583cdf0e10cSrcweir 							{
584cdf0e10cSrcweir 								uno::Sequence< beans::PropertyValue > aPropsFromDialog =
585cdf0e10cSrcweir 																			xFilterProperties->getPropertyValues();
586cdf0e10cSrcweir 								for ( sal_Int32 nInd = 0; nInd < aPropsFromDialog.getLength(); nInd++ )
587cdf0e10cSrcweir 									GetMediaDescr()[aPropsFromDialog[nInd].Name] = aPropsFromDialog[nInd].Value;
588cdf0e10cSrcweir 							}
589cdf0e10cSrcweir 							else
590cdf0e10cSrcweir 							{
591cdf0e10cSrcweir 								throw task::ErrorCodeIOException( ::rtl::OUString(),
592cdf0e10cSrcweir 																	uno::Reference< uno::XInterface >(),
593cdf0e10cSrcweir 																	ERRCODE_IO_ABORT );
594cdf0e10cSrcweir 							}
595cdf0e10cSrcweir 						}
596cdf0e10cSrcweir 					}
597cdf0e10cSrcweir 
598cdf0e10cSrcweir 					break;
599cdf0e10cSrcweir 				}
600cdf0e10cSrcweir 		}
601cdf0e10cSrcweir 	}
602cdf0e10cSrcweir 	catch( container::NoSuchElementException& )
603cdf0e10cSrcweir 	{
604cdf0e10cSrcweir 		// the filter name is unknown
605cdf0e10cSrcweir 		throw task::ErrorCodeIOException( ::rtl::OUString(),
606cdf0e10cSrcweir 											uno::Reference< uno::XInterface >(),
607cdf0e10cSrcweir 											ERRCODE_IO_INVALIDPARAMETER );
608cdf0e10cSrcweir 	}
609cdf0e10cSrcweir     catch( task::ErrorCodeIOException& )
610cdf0e10cSrcweir     {
611cdf0e10cSrcweir         throw;
612cdf0e10cSrcweir     }
613cdf0e10cSrcweir 	catch( uno::Exception& )
614cdf0e10cSrcweir 	{
615cdf0e10cSrcweir 	}
616cdf0e10cSrcweir 
617cdf0e10cSrcweir 	return bDialogUsed;
618cdf0e10cSrcweir }
619cdf0e10cSrcweir 
620cdf0e10cSrcweir //-------------------------------------------------------------------------
621cdf0e10cSrcweir sal_Int8 ModelData_Impl::CheckSaveAcceptable( sal_Int8 nCurStatus )
622cdf0e10cSrcweir {
623cdf0e10cSrcweir 	sal_Int8 nResult = nCurStatus;
624cdf0e10cSrcweir 
625cdf0e10cSrcweir 	if ( nResult != STATUS_NO_ACTION && GetStorable()->hasLocation() )
626cdf0e10cSrcweir 	{
627cdf0e10cSrcweir 		// check whether save is acceptable by the configuration
628cdf0e10cSrcweir 		// it is done only for documents that have persistence already
629cdf0e10cSrcweir 		uno::Reference< uno::XInterface > xCommonConfig = ::comphelper::ConfigurationHelper::openConfig(
630cdf0e10cSrcweir 							m_pOwner->GetServiceFactory(),
631cdf0e10cSrcweir 							::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.Office.Common" ) ),
632cdf0e10cSrcweir 							::comphelper::ConfigurationHelper::E_STANDARD );
633cdf0e10cSrcweir 		if ( !xCommonConfig.is() )
634cdf0e10cSrcweir 			throw uno::RuntimeException(); // should the saving proceed as usual instead?
635cdf0e10cSrcweir 
636cdf0e10cSrcweir 		try
637cdf0e10cSrcweir 		{
638cdf0e10cSrcweir 			sal_Bool bAlwaysSaveAs = sal_False;
639cdf0e10cSrcweir 
640cdf0e10cSrcweir 			// the saving is acceptable
641cdf0e10cSrcweir 			// in case the configuration entry is not set or set to false
642cdf0e10cSrcweir 			// or in case of version creation
643cdf0e10cSrcweir 			::rtl::OUString aVersionCommentString = ::rtl::OUString::createFromAscii( "VersionComment" );
644cdf0e10cSrcweir 			if ( ( ::comphelper::ConfigurationHelper::readRelativeKey(
645cdf0e10cSrcweir 					xCommonConfig,
646cdf0e10cSrcweir 					::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Save/Document/" ) ),
647cdf0e10cSrcweir 					::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "AlwaysSaveAs" ) ) ) >>= bAlwaysSaveAs )
648cdf0e10cSrcweir 		  	&& bAlwaysSaveAs
649cdf0e10cSrcweir 			&& GetMediaDescr().find( aVersionCommentString ) == GetMediaDescr().end() )
650cdf0e10cSrcweir 			{
651cdf0e10cSrcweir 				// notify the user that SaveAs is going to be done
652cdf0e10cSrcweir 				String aString( SfxResId( STR_NEW_FILENAME_SAVE ) );
653cdf0e10cSrcweir 				Window* pWin = SfxStoringHelper::GetModelWindow( m_xModel );
654cdf0e10cSrcweir 				QueryBox aMessageBox( pWin, WB_OK_CANCEL | WB_DEF_OK, aString );
655cdf0e10cSrcweir 				if ( aMessageBox.Execute() == RET_OK )
656cdf0e10cSrcweir 					nResult = STATUS_SAVEAS;
657cdf0e10cSrcweir 				else
658cdf0e10cSrcweir 					nResult = STATUS_NO_ACTION;
659cdf0e10cSrcweir 			}
660cdf0e10cSrcweir 		}
661cdf0e10cSrcweir 		catch( uno::Exception& )
662cdf0e10cSrcweir 		{
663cdf0e10cSrcweir 			// impossibility to get the configuration access means normal saving flow for now
664cdf0e10cSrcweir 		}
665cdf0e10cSrcweir 	}
666cdf0e10cSrcweir 
667cdf0e10cSrcweir 	return nResult;
668cdf0e10cSrcweir }
669cdf0e10cSrcweir 
670cdf0e10cSrcweir //-------------------------------------------------------------------------
671cdf0e10cSrcweir sal_Int8 ModelData_Impl::CheckStateForSave()
672cdf0e10cSrcweir {
673cdf0e10cSrcweir     // if the document is readonly or a new one a SaveAs operation must be used
674cdf0e10cSrcweir     if ( !GetStorable()->hasLocation() || GetStorable()->isReadonly() )
675cdf0e10cSrcweir 		return STATUS_SAVEAS;
676cdf0e10cSrcweir 
677cdf0e10cSrcweir 	// check acceptable entries for media descriptor
678cdf0e10cSrcweir 	sal_Bool bVersInfoNeedsStore = sal_False;
679cdf0e10cSrcweir 	::comphelper::SequenceAsHashMap aAcceptedArgs;
680cdf0e10cSrcweir 
681cdf0e10cSrcweir 	::rtl::OUString aVersionCommentString = ::rtl::OUString::createFromAscii( "VersionComment" );
682cdf0e10cSrcweir 	::rtl::OUString aAuthorString = ::rtl::OUString::createFromAscii( "Author" );
683cdf0e10cSrcweir 	::rtl::OUString aInteractionHandlerString = ::rtl::OUString::createFromAscii( "InteractionHandler" );
684cdf0e10cSrcweir 	::rtl::OUString aStatusIndicatorString = ::rtl::OUString::createFromAscii( "StatusIndicator" );
685*5ba24278SMathias Bauer 	::rtl::OUString aFailOnWarningString = ::rtl::OUString::createFromAscii( "FailOnWarning" );
686cdf0e10cSrcweir 
687cdf0e10cSrcweir 	if ( GetMediaDescr().find( aVersionCommentString ) != GetMediaDescr().end() )
688cdf0e10cSrcweir 	{
689cdf0e10cSrcweir 		bVersInfoNeedsStore = sal_True;
690cdf0e10cSrcweir 		aAcceptedArgs[ aVersionCommentString ] = GetMediaDescr()[ aVersionCommentString ];
691cdf0e10cSrcweir 	}
692cdf0e10cSrcweir 	if ( GetMediaDescr().find( aAuthorString ) != GetMediaDescr().end() )
693cdf0e10cSrcweir 		aAcceptedArgs[ aAuthorString ] = GetMediaDescr()[ aAuthorString ];
694cdf0e10cSrcweir 	if ( GetMediaDescr().find( aInteractionHandlerString ) != GetMediaDescr().end() )
695cdf0e10cSrcweir 		aAcceptedArgs[ aInteractionHandlerString ] = GetMediaDescr()[ aInteractionHandlerString ];
696cdf0e10cSrcweir 	if ( GetMediaDescr().find( aStatusIndicatorString ) != GetMediaDescr().end() )
697cdf0e10cSrcweir 		aAcceptedArgs[ aStatusIndicatorString ] = GetMediaDescr()[ aStatusIndicatorString ];
698*5ba24278SMathias Bauer 	if ( GetMediaDescr().find( aFailOnWarningString ) != GetMediaDescr().end() )
699*5ba24278SMathias Bauer 		aAcceptedArgs[ aFailOnWarningString ] = GetMediaDescr()[ aFailOnWarningString ];
700cdf0e10cSrcweir 
701cdf0e10cSrcweir 	// remove unacceptable entry if there is any
702cdf0e10cSrcweir 	DBG_ASSERT( GetMediaDescr().size() == aAcceptedArgs.size(),
703cdf0e10cSrcweir 				"Unacceptable parameters are provided in Save request!\n" );
704cdf0e10cSrcweir 	if ( GetMediaDescr().size() != aAcceptedArgs.size() )
705cdf0e10cSrcweir 		GetMediaDescr() = aAcceptedArgs;
706cdf0e10cSrcweir 
707cdf0e10cSrcweir     // the document must be modified
708cdf0e10cSrcweir     if ( !GetModifiable()->isModified() && !bVersInfoNeedsStore )
709cdf0e10cSrcweir 		return STATUS_NO_ACTION;
710cdf0e10cSrcweir 
711cdf0e10cSrcweir     // check that the old filter is acceptable
712cdf0e10cSrcweir 	::rtl::OUString aOldFilterName = GetDocProps().getUnpackedValueOrDefault(
713cdf0e10cSrcweir 													aFilterNameString,
714cdf0e10cSrcweir 													::rtl::OUString() );
715cdf0e10cSrcweir     sal_Int8 nResult = CheckFilter( aOldFilterName );
716cdf0e10cSrcweir 
717cdf0e10cSrcweir 	return nResult;
718cdf0e10cSrcweir }
719cdf0e10cSrcweir 
720cdf0e10cSrcweir sal_Int8 ModelData_Impl::CheckFilter( const ::rtl::OUString& aFilterName )
721cdf0e10cSrcweir {
722cdf0e10cSrcweir     ::comphelper::SequenceAsHashMap aFiltPropsHM;
723cdf0e10cSrcweir     sal_Int32 nFiltFlags = 0;
724cdf0e10cSrcweir     if ( aFilterName.getLength() )
725cdf0e10cSrcweir 	{
726cdf0e10cSrcweir         // get properties of filter
727cdf0e10cSrcweir         uno::Sequence< beans::PropertyValue > aFilterProps;
728cdf0e10cSrcweir         if ( aFilterName.getLength() )
729cdf0e10cSrcweir             m_pOwner->GetFilterConfiguration()->getByName( aFilterName ) >>= aFilterProps;
730cdf0e10cSrcweir 
731cdf0e10cSrcweir         aFiltPropsHM = ::comphelper::SequenceAsHashMap( aFilterProps );
732cdf0e10cSrcweir         nFiltFlags = aFiltPropsHM.getUnpackedValueOrDefault( ::rtl::OUString::createFromAscii( "Flags" ), (sal_Int32)0 );
733cdf0e10cSrcweir 	}
734cdf0e10cSrcweir 
735cdf0e10cSrcweir     // only a temporary solution until default filter retrieving feature is implemented
736cdf0e10cSrcweir 	// then GetDocServiceDefaultFilter() must be used
737cdf0e10cSrcweir 	::comphelper::SequenceAsHashMap aDefFiltPropsHM = GetDocServiceDefaultFilterCheckFlags( 3, 0 );
738cdf0e10cSrcweir     sal_Int32 nDefFiltFlags = aDefFiltPropsHM.getUnpackedValueOrDefault( ::rtl::OUString::createFromAscii( "Flags" ), (sal_Int32)0 );
739cdf0e10cSrcweir 
740cdf0e10cSrcweir 	// if the old filter is not acceptable
741cdf0e10cSrcweir 	// and there is no default filter or it is not acceptable for requested parameters then proceed with saveAs
742cdf0e10cSrcweir     if ( ( !aFiltPropsHM.size() || !( nFiltFlags & SFX_FILTER_EXPORT ) )
743cdf0e10cSrcweir 	  && ( !aDefFiltPropsHM.size() || !( nDefFiltFlags & SFX_FILTER_EXPORT ) || nDefFiltFlags & SFX_FILTER_INTERNAL ) )
744cdf0e10cSrcweir 		return STATUS_SAVEAS;
745cdf0e10cSrcweir 
746cdf0e10cSrcweir 	// so at this point there is either an acceptable old filter or default one
747cdf0e10cSrcweir     if ( !aFiltPropsHM.size() || !( nFiltFlags & SFX_FILTER_EXPORT ) )
748cdf0e10cSrcweir 	{
749cdf0e10cSrcweir 		// so the default filter must be acceptable
750cdf0e10cSrcweir 		return STATUS_SAVEAS_STANDARDNAME;
751cdf0e10cSrcweir 	}
752cdf0e10cSrcweir     else if ( ( !( nFiltFlags & SFX_FILTER_OWN ) || ( nFiltFlags & SFX_FILTER_ALIEN ) )
753cdf0e10cSrcweir            && aDefFiltPropsHM.size()
754cdf0e10cSrcweir 		   && ( nDefFiltFlags & SFX_FILTER_EXPORT ) && !( nDefFiltFlags & SFX_FILTER_INTERNAL ))
755cdf0e10cSrcweir 	{
756cdf0e10cSrcweir 		// the default filter is acceptable and the old filter is alian one
757cdf0e10cSrcweir 		// so ask to make a saveAs operation
758cdf0e10cSrcweir         ::rtl::OUString aUIName = aFiltPropsHM.getUnpackedValueOrDefault( ::rtl::OUString::createFromAscii( "UIName" ),
759cdf0e10cSrcweir                                                                                 ::rtl::OUString() );
760cdf0e10cSrcweir         ::rtl::OUString aDefUIName = aDefFiltPropsHM.getUnpackedValueOrDefault( ::rtl::OUString::createFromAscii( "UIName" ),
761cdf0e10cSrcweir                                                                                 ::rtl::OUString() );
762cdf0e10cSrcweir 		::rtl::OUString aPreusedFilterName = GetDocProps().getUnpackedValueOrDefault(
763cdf0e10cSrcweir 													::rtl::OUString::createFromAscii( "PreusedFilterName" ),
764cdf0e10cSrcweir 													::rtl::OUString() );
765cdf0e10cSrcweir         if ( !aPreusedFilterName.equals( aFilterName ) && !aUIName.equals( aDefUIName ) )
766cdf0e10cSrcweir 		{
767cdf0e10cSrcweir             if ( !SfxStoringHelper::WarnUnacceptableFormat( GetModel(), aUIName, aDefUIName, sal_True ) )
768cdf0e10cSrcweir 				return STATUS_SAVEAS_STANDARDNAME;
769cdf0e10cSrcweir 		}
770cdf0e10cSrcweir 	}
771cdf0e10cSrcweir 
772cdf0e10cSrcweir 	return STATUS_SAVE;
773cdf0e10cSrcweir }
774cdf0e10cSrcweir 
775cdf0e10cSrcweir //-------------------------------------------------------------------------
776cdf0e10cSrcweir sal_Bool ModelData_Impl::CheckFilterOptionsDialogExistence()
777cdf0e10cSrcweir {
778cdf0e10cSrcweir 	uno::Sequence< beans::NamedValue > aSearchRequest( 1 );
779cdf0e10cSrcweir 	aSearchRequest[0].Name = ::rtl::OUString::createFromAscii( "DocumentService" );
780cdf0e10cSrcweir 	aSearchRequest[0].Value <<= GetDocServiceName();
781cdf0e10cSrcweir 
782cdf0e10cSrcweir 	uno::Reference< container::XEnumeration > xFilterEnum =
783cdf0e10cSrcweir 									m_pOwner->GetFilterQuery()->createSubSetEnumerationByProperties( aSearchRequest );
784cdf0e10cSrcweir 
785cdf0e10cSrcweir 	while ( xFilterEnum->hasMoreElements() )
786cdf0e10cSrcweir 	{
787cdf0e10cSrcweir 		uno::Sequence< beans::PropertyValue > pProps;
788cdf0e10cSrcweir 		if ( xFilterEnum->nextElement() >>= pProps )
789cdf0e10cSrcweir 		{
790cdf0e10cSrcweir 			::comphelper::SequenceAsHashMap aPropsHM( pProps );
791cdf0e10cSrcweir 			::rtl::OUString aUIServName = aPropsHM.getUnpackedValueOrDefault(
792cdf0e10cSrcweir 											::rtl::OUString::createFromAscii( "UIComponent" ),
793cdf0e10cSrcweir 											::rtl::OUString() );
794cdf0e10cSrcweir 			if ( aUIServName.getLength() )
795cdf0e10cSrcweir 				return sal_True;
796cdf0e10cSrcweir 		}
797cdf0e10cSrcweir 	}
798cdf0e10cSrcweir 
799cdf0e10cSrcweir 	return sal_False;
800cdf0e10cSrcweir }
801cdf0e10cSrcweir 
802cdf0e10cSrcweir //-------------------------------------------------------------------------
803cdf0e10cSrcweir sal_Bool ModelData_Impl::OutputFileDialog( sal_Int8 nStoreMode,
804cdf0e10cSrcweir 											const ::comphelper::SequenceAsHashMap& aPreselectedFilterPropsHM,
805cdf0e10cSrcweir 											sal_Bool bSetStandardName,
806cdf0e10cSrcweir 											::rtl::OUString& aSuggestedName,
807cdf0e10cSrcweir                                             sal_Bool bPreselectPassword,
808cdf0e10cSrcweir 											const ::rtl::OUString& aSuggestedDir,
809cdf0e10cSrcweir 											sal_Int16 nDialog,
810cdf0e10cSrcweir 											const ::rtl::OUString& rStandardDir,
811cdf0e10cSrcweir 											const ::com::sun::star::uno::Sequence< ::rtl::OUString >& rBlackList)
812cdf0e10cSrcweir {
813cdf0e10cSrcweir 	sal_Bool bUseFilterOptions = sal_False;
814cdf0e10cSrcweir 
815cdf0e10cSrcweir 	::comphelper::SequenceAsHashMap::const_iterator aOverwriteIter =
816cdf0e10cSrcweir 				GetMediaDescr().find( ::rtl::OUString::createFromAscii( "Overwrite" ) );
817cdf0e10cSrcweir 
818cdf0e10cSrcweir 	// the file name must be specified if overwrite option is set
819cdf0e10cSrcweir 	if ( aOverwriteIter != GetMediaDescr().end() )
820cdf0e10cSrcweir    		throw task::ErrorCodeIOException( ::rtl::OUString(),
821cdf0e10cSrcweir 											uno::Reference< uno::XInterface >(),
822cdf0e10cSrcweir 											ERRCODE_IO_INVALIDPARAMETER );
823cdf0e10cSrcweir 
824cdf0e10cSrcweir 	// no target file name is specified
825cdf0e10cSrcweir 	// we need to show the file dialog
826cdf0e10cSrcweir 
827cdf0e10cSrcweir 	// check if we have a filter which allows for filter options, so we need a corresponding checkbox in the dialog
828cdf0e10cSrcweir 	sal_Bool bAllowOptions = sal_False;
829cdf0e10cSrcweir 
830cdf0e10cSrcweir 	// in case of Export, filter options dialog is used if available
831cdf0e10cSrcweir 	if( !( nStoreMode & EXPORT_REQUESTED ) || ( nStoreMode & WIDEEXPORT_REQUESTED ) )
832cdf0e10cSrcweir 		bAllowOptions = CheckFilterOptionsDialogExistence();
833cdf0e10cSrcweir 
834cdf0e10cSrcweir 	// get the filename by dialog ...
835cdf0e10cSrcweir 	// create the file dialog
836cdf0e10cSrcweir 	sal_Int16  aDialogMode = bAllowOptions
837cdf0e10cSrcweir         ? (com::sun::star::ui::dialogs::TemplateDescription::
838cdf0e10cSrcweir            FILESAVE_AUTOEXTENSION_PASSWORD_FILTEROPTIONS)
839cdf0e10cSrcweir         : (com::sun::star::ui::dialogs::TemplateDescription::
840cdf0e10cSrcweir            FILESAVE_AUTOEXTENSION_PASSWORD);
841cdf0e10cSrcweir 	sal_Int64 aDialogFlags = 0;
842cdf0e10cSrcweir 
843cdf0e10cSrcweir 	if( ( nStoreMode & EXPORT_REQUESTED ) && !( nStoreMode & WIDEEXPORT_REQUESTED ) )
844cdf0e10cSrcweir 	{
845cdf0e10cSrcweir 		if ( nStoreMode & PDFEXPORT_REQUESTED )
846cdf0e10cSrcweir 			aDialogMode = com::sun::star::ui::dialogs::TemplateDescription::
847cdf0e10cSrcweir 				FILESAVE_AUTOEXTENSION;
848cdf0e10cSrcweir 		else
849cdf0e10cSrcweir 			aDialogMode = com::sun::star::ui::dialogs::TemplateDescription::
850cdf0e10cSrcweir 				FILESAVE_AUTOEXTENSION_SELECTION;
851cdf0e10cSrcweir 		aDialogFlags = SFXWB_EXPORT;
852cdf0e10cSrcweir 	}
853cdf0e10cSrcweir 
854cdf0e10cSrcweir 	sfx2::FileDialogHelper* pFileDlg = NULL;
855cdf0e10cSrcweir 
856cdf0e10cSrcweir 	::rtl::OUString aDocServiceName = GetDocServiceName();
857cdf0e10cSrcweir 	DBG_ASSERT( aDocServiceName.getLength(), "No document service for this module set!" );
858cdf0e10cSrcweir 
859cdf0e10cSrcweir 	sal_Int32 nMust = getMustFlags( nStoreMode );
860cdf0e10cSrcweir 	sal_Int32 nDont = getDontFlags( nStoreMode );
861cdf0e10cSrcweir     sfx2::FileDialogHelper::Context eCtxt = sfx2::FileDialogHelper::UNKNOWN_CONTEXT;
862cdf0e10cSrcweir 
863cdf0e10cSrcweir 	if ( ( nStoreMode & EXPORT_REQUESTED ) && !( nStoreMode & WIDEEXPORT_REQUESTED ) )
864cdf0e10cSrcweir 	{
865cdf0e10cSrcweir 		if ( ( nStoreMode & PDFEXPORT_REQUESTED ) && aPreselectedFilterPropsHM.size() )
866cdf0e10cSrcweir 		{
867cdf0e10cSrcweir 			// this is a PDF export
868cdf0e10cSrcweir 			// the filter options has been shown already
869cdf0e10cSrcweir 			::rtl::OUString aFilterUIName = aPreselectedFilterPropsHM.getUnpackedValueOrDefault(
870cdf0e10cSrcweir 														::rtl::OUString::createFromAscii( "UIName" ),
871cdf0e10cSrcweir 														::rtl::OUString() );
872cdf0e10cSrcweir 
873cdf0e10cSrcweir 			pFileDlg = new sfx2::FileDialogHelper( aDialogMode, aDialogFlags, aFilterUIName, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "pdf" ) ), rStandardDir, rBlackList );
874cdf0e10cSrcweir 			pFileDlg->SetCurrentFilter( aFilterUIName );
875cdf0e10cSrcweir 		}
876cdf0e10cSrcweir 		else
877cdf0e10cSrcweir 		{
878cdf0e10cSrcweir 			// This is the normal dialog
879cdf0e10cSrcweir 			pFileDlg = new sfx2::FileDialogHelper( aDialogMode, aDialogFlags, aDocServiceName, nDialog, nMust, nDont, rStandardDir, rBlackList );
880cdf0e10cSrcweir 		}
881cdf0e10cSrcweir 
882cdf0e10cSrcweir 		if( aDocServiceName.equalsAscii( "com.sun.star.drawing.DrawingDocument" ) )
883cdf0e10cSrcweir            	eCtxt = sfx2::FileDialogHelper::SD_EXPORT;
884cdf0e10cSrcweir         if( aDocServiceName.equalsAscii( "com.sun.star.presentation.PresentationDocument" ) )
885cdf0e10cSrcweir            	eCtxt = sfx2::FileDialogHelper::SI_EXPORT;
886cdf0e10cSrcweir         if( aDocServiceName.equalsAscii( "com.sun.star.text.TextDocument" ) )
887cdf0e10cSrcweir             eCtxt = sfx2::FileDialogHelper::SW_EXPORT;
888cdf0e10cSrcweir 
889cdf0e10cSrcweir         if ( eCtxt != sfx2::FileDialogHelper::UNKNOWN_CONTEXT )
890cdf0e10cSrcweir            	pFileDlg->SetContext( eCtxt );
891cdf0e10cSrcweir 
892cdf0e10cSrcweir 		pFileDlg->CreateMatcher( aDocServiceName );
893cdf0e10cSrcweir 
894cdf0e10cSrcweir 		uno::Reference< ui::dialogs::XFilePicker > xFilePicker = pFileDlg->GetFilePicker();
895cdf0e10cSrcweir 		uno::Reference< ui::dialogs::XFilePickerControlAccess > xControlAccess =
896cdf0e10cSrcweir 		uno::Reference< ui::dialogs::XFilePickerControlAccess >( xFilePicker, uno::UNO_QUERY );
897cdf0e10cSrcweir 
898cdf0e10cSrcweir 		if ( xControlAccess.is() )
899cdf0e10cSrcweir 		{
900cdf0e10cSrcweir 			::rtl::OUString aCtrlText = String( SfxResId( STR_EXPORTBUTTON ) );
901cdf0e10cSrcweir 			xControlAccess->setLabel( ui::dialogs::CommonFilePickerElementIds::PUSHBUTTON_OK, aCtrlText );
902cdf0e10cSrcweir 
903cdf0e10cSrcweir 			aCtrlText = ::rtl::OUString( String( SfxResId( STR_LABEL_FILEFORMAT ) ) );
904cdf0e10cSrcweir 			xControlAccess->setLabel( ui::dialogs::CommonFilePickerElementIds::LISTBOX_FILTER_LABEL, aCtrlText );
905cdf0e10cSrcweir 		}
906cdf0e10cSrcweir 	}
907cdf0e10cSrcweir 	else
908cdf0e10cSrcweir 	{
909cdf0e10cSrcweir 		// This is the normal dialog
910cdf0e10cSrcweir 		pFileDlg = new sfx2::FileDialogHelper( aDialogMode, aDialogFlags, aDocServiceName, nDialog, nMust, nDont, rStandardDir, rBlackList );
911cdf0e10cSrcweir 		pFileDlg->CreateMatcher( aDocServiceName );
912cdf0e10cSrcweir 	}
913cdf0e10cSrcweir 
914cdf0e10cSrcweir     ::rtl::OUString aAdjustToType;
915cdf0e10cSrcweir 
916cdf0e10cSrcweir     if ( ( nStoreMode & EXPORT_REQUESTED ) && !( nStoreMode & WIDEEXPORT_REQUESTED ) )
917cdf0e10cSrcweir     {
918cdf0e10cSrcweir         // it is export, set the preselected filter
919cdf0e10cSrcweir         ::rtl::OUString aFilterUIName = aPreselectedFilterPropsHM.getUnpackedValueOrDefault(
920cdf0e10cSrcweir                                         ::rtl::OUString::createFromAscii( "UIName" ),
921cdf0e10cSrcweir                                         ::rtl::OUString() );
922cdf0e10cSrcweir         pFileDlg->SetCurrentFilter( aFilterUIName );
923cdf0e10cSrcweir     }
924cdf0e10cSrcweir     // it is no export, bSetStandardName == true means that user agreed to store document in the default (default default ;-)) format
925cdf0e10cSrcweir     else if ( bSetStandardName || GetStorable()->hasLocation() )
926cdf0e10cSrcweir     {
927cdf0e10cSrcweir         uno::Sequence< beans::PropertyValue > aOldFilterProps;
928cdf0e10cSrcweir         ::rtl::OUString aOldFilterName = GetDocProps().getUnpackedValueOrDefault(
929cdf0e10cSrcweir                                                         aFilterNameString,
930cdf0e10cSrcweir                                                         ::rtl::OUString() );
931cdf0e10cSrcweir 
932cdf0e10cSrcweir 		if ( aOldFilterName.getLength() )
933cdf0e10cSrcweir 			m_pOwner->GetFilterConfiguration()->getByName( aOldFilterName ) >>= aOldFilterProps;
934cdf0e10cSrcweir 
935cdf0e10cSrcweir 		::comphelper::SequenceAsHashMap aOldFiltPropsHM( aOldFilterProps );
936cdf0e10cSrcweir 		sal_Int32 nOldFiltFlags = aOldFiltPropsHM.getUnpackedValueOrDefault( ::rtl::OUString::createFromAscii( "Flags" ), (sal_Int32)0 );
937cdf0e10cSrcweir 
938cdf0e10cSrcweir 		if ( bSetStandardName || ( nOldFiltFlags & nMust ) != nMust || nOldFiltFlags & nDont )
939cdf0e10cSrcweir 		{
940cdf0e10cSrcweir             // the suggested type will be changed, the extension should be adjusted
941cdf0e10cSrcweir             aAdjustToType = aPreselectedFilterPropsHM.getUnpackedValueOrDefault(
942cdf0e10cSrcweir                                             ::rtl::OUString::createFromAscii( "Type" ),
943cdf0e10cSrcweir                                             ::rtl::OUString() );
944cdf0e10cSrcweir 
945cdf0e10cSrcweir             ::rtl::OUString aFilterUIName = aPreselectedFilterPropsHM.getUnpackedValueOrDefault(
946cdf0e10cSrcweir                                             ::rtl::OUString::createFromAscii( "UIName" ),
947cdf0e10cSrcweir                                             ::rtl::OUString() );
948cdf0e10cSrcweir             pFileDlg->SetCurrentFilter( aFilterUIName );
949cdf0e10cSrcweir 		}
950cdf0e10cSrcweir 		else
951cdf0e10cSrcweir 		{
952cdf0e10cSrcweir 			pFileDlg->SetCurrentFilter( aOldFiltPropsHM.getUnpackedValueOrDefault(
953cdf0e10cSrcweir 														::rtl::OUString::createFromAscii( "UIName" ),
954cdf0e10cSrcweir 														::rtl::OUString() ) );
955cdf0e10cSrcweir 		}
956cdf0e10cSrcweir     }
957cdf0e10cSrcweir 
958cdf0e10cSrcweir     ::rtl::OUString aReccomendedDir = GetReccomendedDir( aSuggestedDir, eCtxt );
959cdf0e10cSrcweir     if ( aReccomendedDir.getLength() )
960cdf0e10cSrcweir         pFileDlg->SetDisplayDirectory( aReccomendedDir );
961cdf0e10cSrcweir     ::rtl::OUString aReccomendedName = GetReccomendedName( aSuggestedName, aAdjustToType );
962cdf0e10cSrcweir     if ( aReccomendedName.getLength() )
963cdf0e10cSrcweir         pFileDlg->SetFileName( aReccomendedName );
964cdf0e10cSrcweir 
965cdf0e10cSrcweir 	uno::Reference < view::XSelectionSupplier > xSel( GetModel()->getCurrentController(), uno::UNO_QUERY );
966cdf0e10cSrcweir 	if ( xSel.is() && xSel->getSelection().hasValue() )
967cdf0e10cSrcweir 		GetMediaDescr()[::rtl::OUString::createFromAscii( "SelectionOnly" )] <<= sal_True;
968cdf0e10cSrcweir 
969cdf0e10cSrcweir 	// This is a temporary hardcoded solution must be removed when
970cdf0e10cSrcweir 	// dialogs do not need parameters in SidSet representation any more
971cdf0e10cSrcweir 	sal_uInt16 nSlotID = getSlotIDFromMode( nStoreMode );
972cdf0e10cSrcweir     if ( !nSlotID )
973cdf0e10cSrcweir         throw lang::IllegalArgumentException(); // TODO:
974cdf0e10cSrcweir 
975cdf0e10cSrcweir 	// generate SidSet from MediaDescriptor and provide it into FileDialog
976cdf0e10cSrcweir 	// than merge changed SidSet back
977cdf0e10cSrcweir 	SfxAllItemSet aDialogParams( SFX_APP()->GetPool() );
978cdf0e10cSrcweir 	SfxItemSet* pDialogParams = &aDialogParams;
979cdf0e10cSrcweir 	TransformParameters( nSlotID,
980cdf0e10cSrcweir 						 GetMediaDescr().getAsConstPropertyValueList(),
981cdf0e10cSrcweir 						 aDialogParams,
982cdf0e10cSrcweir 						 NULL );
983cdf0e10cSrcweir 
984cdf0e10cSrcweir     const SfxPoolItem* pItem = NULL;
985cdf0e10cSrcweir     if ( bPreselectPassword && aDialogParams.GetItemState( SID_ENCRYPTIONDATA, sal_True, &pItem ) != SFX_ITEM_SET )
986cdf0e10cSrcweir     {
987cdf0e10cSrcweir         // the file dialog preselects the password checkbox if the provided mediadescriptor has encryption data entry
988cdf0e10cSrcweir         // after dialog execution the password interaction flag will be either removed or not
989cdf0e10cSrcweir         aDialogParams.Put( SfxBoolItem( SID_PASSWORDINTERACTION, sal_True ) );
990cdf0e10cSrcweir     }
991cdf0e10cSrcweir 
992cdf0e10cSrcweir     // aStringTypeFN is a pure output parameter, pDialogParams is an in/out parameter
993cdf0e10cSrcweir     String aStringTypeFN;
994cdf0e10cSrcweir 	if ( pFileDlg->Execute( pDialogParams, aStringTypeFN ) != ERRCODE_NONE )
995cdf0e10cSrcweir 	{
996cdf0e10cSrcweir 		delete pFileDlg;
997cdf0e10cSrcweir 		throw task::ErrorCodeIOException( ::rtl::OUString(), uno::Reference< uno::XInterface >(), ERRCODE_IO_ABORT );
998cdf0e10cSrcweir 	}
999cdf0e10cSrcweir 
1000cdf0e10cSrcweir     ::rtl::OUString aFilterName = aStringTypeFN;
1001cdf0e10cSrcweir 
1002cdf0e10cSrcweir     // the following two arguments can not be converted in MediaDescriptor,
1003cdf0e10cSrcweir     // so they should be removed from the ItemSet after retrieving
1004cdf0e10cSrcweir     SFX_ITEMSET_ARG( pDialogParams, pRecommendReadOnly, SfxBoolItem, SID_RECOMMENDREADONLY, sal_False );
1005cdf0e10cSrcweir     m_bRecommendReadOnly = ( pRecommendReadOnly && pRecommendReadOnly->GetValue() );
1006cdf0e10cSrcweir     pDialogParams->ClearItem( SID_RECOMMENDREADONLY );
1007cdf0e10cSrcweir 
1008cdf0e10cSrcweir 	uno::Sequence< beans::PropertyValue > aPropsFromDialog;
1009cdf0e10cSrcweir 	TransformItems( nSlotID, *pDialogParams, aPropsFromDialog, NULL );
1010cdf0e10cSrcweir     GetMediaDescr() << aPropsFromDialog;
1011cdf0e10cSrcweir 
1012cdf0e10cSrcweir 	// get the path from the dialog
1013cdf0e10cSrcweir 	INetURLObject aURL( pFileDlg->GetPath() );
1014cdf0e10cSrcweir 	// the path should be provided outside since it might be used for further calls to the dialog
1015cdf0e10cSrcweir 	aSuggestedName = aURL.GetName( INetURLObject::DECODE_WITH_CHARSET );
1016cdf0e10cSrcweir 
1017cdf0e10cSrcweir 	// old filter options should be cleared in case different filter is used
1018cdf0e10cSrcweir 
1019cdf0e10cSrcweir 	::rtl::OUString aFilterFromMediaDescr = GetMediaDescr().getUnpackedValueOrDefault(
1020cdf0e10cSrcweir 													aFilterNameString,
1021cdf0e10cSrcweir 													::rtl::OUString() );
1022cdf0e10cSrcweir 	::rtl::OUString aOldFilterName = GetDocProps().getUnpackedValueOrDefault(
1023cdf0e10cSrcweir 													aFilterNameString,
1024cdf0e10cSrcweir 													::rtl::OUString() );
1025cdf0e10cSrcweir 	if ( aFilterName.equals( aFilterFromMediaDescr ) )
1026cdf0e10cSrcweir 	{
1027cdf0e10cSrcweir 		// preserv current settings if any
1028cdf0e10cSrcweir 		// if there no current settings and the name is the same
1029cdf0e10cSrcweir 		// as old filter name use old filter settings
1030cdf0e10cSrcweir 
1031cdf0e10cSrcweir 		if ( aFilterFromMediaDescr.equals( aOldFilterName ) )
1032cdf0e10cSrcweir 		{
1033cdf0e10cSrcweir 			::comphelper::SequenceAsHashMap::const_iterator aIter =
1034cdf0e10cSrcweir 										GetDocProps().find( aFilterOptionsString );
1035cdf0e10cSrcweir 			if ( aIter != GetDocProps().end()
1036cdf0e10cSrcweir 			  && GetMediaDescr().find( aFilterOptionsString ) == GetMediaDescr().end() )
1037cdf0e10cSrcweir 				GetMediaDescr()[aIter->first] = aIter->second;
1038cdf0e10cSrcweir 
1039cdf0e10cSrcweir 			aIter = GetDocProps().find( aFilterDataString );
1040cdf0e10cSrcweir 			if ( aIter != GetDocProps().end()
1041cdf0e10cSrcweir 			  && GetMediaDescr().find( aFilterDataString ) == GetMediaDescr().end() )
1042cdf0e10cSrcweir 				GetMediaDescr()[aIter->first] = aIter->second;
1043cdf0e10cSrcweir 		}
1044cdf0e10cSrcweir 	}
1045cdf0e10cSrcweir 	else
1046cdf0e10cSrcweir 	{
1047cdf0e10cSrcweir 		GetMediaDescr().erase( aFilterDataString );
1048cdf0e10cSrcweir 		GetMediaDescr().erase( aFilterOptionsString );
1049cdf0e10cSrcweir 
1050cdf0e10cSrcweir 		if ( aFilterName.equals( aOldFilterName ) )
1051cdf0e10cSrcweir 		{
1052cdf0e10cSrcweir 			// merge filter option of the document filter
1053cdf0e10cSrcweir 
1054cdf0e10cSrcweir 			::comphelper::SequenceAsHashMap::const_iterator aIter =
1055cdf0e10cSrcweir 								GetDocProps().find( aFilterOptionsString );
1056cdf0e10cSrcweir 			if ( aIter != GetDocProps().end() )
1057cdf0e10cSrcweir 				GetMediaDescr()[aIter->first] = aIter->second;
1058cdf0e10cSrcweir 
1059cdf0e10cSrcweir 			aIter = GetDocProps().find( aFilterDataString );
1060cdf0e10cSrcweir 			if ( aIter != GetDocProps().end() )
1061cdf0e10cSrcweir 				GetMediaDescr()[aIter->first] = aIter->second;
1062cdf0e10cSrcweir 		}
1063cdf0e10cSrcweir 	}
1064cdf0e10cSrcweir 
1065cdf0e10cSrcweir 	uno::Reference< ui::dialogs::XFilePickerControlAccess > xExtFileDlg( pFileDlg->GetFilePicker(), uno::UNO_QUERY );
1066cdf0e10cSrcweir 	if ( xExtFileDlg.is() )
1067cdf0e10cSrcweir 	{
1068cdf0e10cSrcweir 		if ( SfxStoringHelper::CheckFilterOptionsAppearence( m_pOwner->GetFilterConfiguration(), aFilterName ) )
1069cdf0e10cSrcweir 			bUseFilterOptions = sal_True;
1070cdf0e10cSrcweir 
1071cdf0e10cSrcweir 		if ( ( !( nStoreMode & EXPORT_REQUESTED ) || ( nStoreMode & WIDEEXPORT_REQUESTED ) ) && bUseFilterOptions )
1072cdf0e10cSrcweir 		{
1073cdf0e10cSrcweir 			try
1074cdf0e10cSrcweir 			{
1075cdf0e10cSrcweir 				// for exporters: always show dialog if format uses options
1076cdf0e10cSrcweir 				// for save: show dialog if format uses options and no options given or if forced by user
1077cdf0e10cSrcweir 				uno::Any aVal =
1078cdf0e10cSrcweir 						xExtFileDlg->getValue( ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_FILTEROPTIONS, 0 );
1079cdf0e10cSrcweir 
1080cdf0e10cSrcweir 				aVal >>= bUseFilterOptions;
1081cdf0e10cSrcweir 				if ( !bUseFilterOptions )
1082cdf0e10cSrcweir 					bUseFilterOptions =
1083cdf0e10cSrcweir 					  ( GetMediaDescr().find( aFilterDataString ) == GetMediaDescr().end()
1084cdf0e10cSrcweir 					  && GetMediaDescr().find( aFilterOptionsString ) == GetMediaDescr().end() );
1085cdf0e10cSrcweir 			}
1086cdf0e10cSrcweir 			catch( lang::IllegalArgumentException& )
1087cdf0e10cSrcweir 			{}
1088cdf0e10cSrcweir 		}
1089cdf0e10cSrcweir 	}
1090cdf0e10cSrcweir 
1091cdf0e10cSrcweir 	delete pFileDlg;
1092cdf0e10cSrcweir 
1093cdf0e10cSrcweir 	// merge in results of the dialog execution
1094cdf0e10cSrcweir 	GetMediaDescr()[::rtl::OUString::createFromAscii( "URL" )] <<=
1095cdf0e10cSrcweir 												::rtl::OUString( aURL.GetMainURL( INetURLObject::NO_DECODE ));
1096cdf0e10cSrcweir 	GetMediaDescr()[aFilterNameString] <<= aFilterName;
1097cdf0e10cSrcweir 
1098cdf0e10cSrcweir 	return bUseFilterOptions;
1099cdf0e10cSrcweir }
1100cdf0e10cSrcweir 
1101cdf0e10cSrcweir //-------------------------------------------------------------------------
1102cdf0e10cSrcweir sal_Bool ModelData_Impl::ShowDocumentInfoDialog()
1103cdf0e10cSrcweir {
1104cdf0e10cSrcweir 	sal_Bool bDialogUsed = sal_False;
1105cdf0e10cSrcweir 
1106cdf0e10cSrcweir 	try {
1107cdf0e10cSrcweir 		uno::Reference< frame::XController > xController = GetModel()->getCurrentController();
1108cdf0e10cSrcweir 		if ( xController.is() )
1109cdf0e10cSrcweir 		{
1110cdf0e10cSrcweir 			uno::Reference< frame::XDispatchProvider > xFrameDispatch( xController->getFrame(), uno::UNO_QUERY );
1111cdf0e10cSrcweir 			if ( xFrameDispatch.is() )
1112cdf0e10cSrcweir 			{
1113cdf0e10cSrcweir 				util::URL aURL;
1114cdf0e10cSrcweir 				aURL.Complete = ::rtl::OUString::createFromAscii( ".uno:SetDocumentProperties" );
1115cdf0e10cSrcweir 
1116cdf0e10cSrcweir 				uno::Reference< util::XURLTransformer > xTransformer(
1117cdf0e10cSrcweir 							m_pOwner->GetServiceFactory()->createInstance(
1118cdf0e10cSrcweir 											DEFINE_CONST_UNICODE("com.sun.star.util.URLTransformer") ),
1119cdf0e10cSrcweir 							uno::UNO_QUERY );
1120cdf0e10cSrcweir 				if ( xTransformer.is() && xTransformer->parseStrict( aURL ) )
1121cdf0e10cSrcweir 				{
1122cdf0e10cSrcweir 					uno::Reference< frame::XDispatch > xDispatch = xFrameDispatch->queryDispatch(
1123cdf0e10cSrcweir 																				aURL,
1124cdf0e10cSrcweir 																				::rtl::OUString::createFromAscii( "_self" ),
1125cdf0e10cSrcweir 																				0 );
1126cdf0e10cSrcweir 					if ( xDispatch.is() )
1127cdf0e10cSrcweir 					{
1128cdf0e10cSrcweir 						xDispatch->dispatch( aURL, uno::Sequence< beans::PropertyValue >() );
1129cdf0e10cSrcweir 						bDialogUsed = sal_True;
1130cdf0e10cSrcweir 					}
1131cdf0e10cSrcweir 				}
1132cdf0e10cSrcweir 			}
1133cdf0e10cSrcweir 		}
1134cdf0e10cSrcweir 	}
1135cdf0e10cSrcweir 	catch ( uno::Exception& )
1136cdf0e10cSrcweir 	{
1137cdf0e10cSrcweir 	}
1138cdf0e10cSrcweir 
1139cdf0e10cSrcweir 	return bDialogUsed;
1140cdf0e10cSrcweir }
1141cdf0e10cSrcweir 
1142cdf0e10cSrcweir //-------------------------------------------------------------------------
1143cdf0e10cSrcweir ::rtl::OUString ModelData_Impl::GetReccomendedDir( const ::rtl::OUString& aSuggestedDir, const sfx2::FileDialogHelper::Context& aCtxt )
1144cdf0e10cSrcweir {
1145cdf0e10cSrcweir     ::rtl::OUString aReccomendedDir;
1146cdf0e10cSrcweir 
1147cdf0e10cSrcweir 	if ( ( aSuggestedDir.getLength() || GetStorable()->hasLocation() )
1148cdf0e10cSrcweir 	  && !GetMediaDescr().getUnpackedValueOrDefault( ::rtl::OUString::createFromAscii( "RepairPackage" ),
1149cdf0e10cSrcweir 	  																sal_False ) )
1150cdf0e10cSrcweir 	{
1151cdf0e10cSrcweir         INetURLObject aLocation;
1152cdf0e10cSrcweir         if ( aSuggestedDir.getLength() )
1153cdf0e10cSrcweir             aLocation = INetURLObject( aSuggestedDir );
1154cdf0e10cSrcweir         else
1155cdf0e10cSrcweir         {
1156cdf0e10cSrcweir             ::rtl::OUString aOldURL = GetStorable()->getLocation();
1157cdf0e10cSrcweir             if ( aOldURL.getLength() )
1158cdf0e10cSrcweir             {
1159cdf0e10cSrcweir                 INetURLObject aTmp( aOldURL );
1160cdf0e10cSrcweir                 if ( aTmp.removeSegment() )
1161cdf0e10cSrcweir                     aLocation = aTmp;
1162cdf0e10cSrcweir             }
1163cdf0e10cSrcweir 
1164cdf0e10cSrcweir             if ( aLocation.HasError() )
1165cdf0e10cSrcweir                 aLocation = INetURLObject( SvtPathOptions().GetWorkPath() );
1166cdf0e10cSrcweir         }
1167cdf0e10cSrcweir 
1168cdf0e10cSrcweir 	    aLocation.setFinalSlash();
1169cdf0e10cSrcweir         if ( !aLocation.HasError() )
1170cdf0e10cSrcweir             aReccomendedDir = aLocation.GetMainURL( INetURLObject::NO_DECODE );
1171cdf0e10cSrcweir 	}
1172cdf0e10cSrcweir 	else
1173cdf0e10cSrcweir 	{
1174cdf0e10cSrcweir         // pb: set graphic path if context == SD_EXPORT or SI_EXPORT else work path
1175cdf0e10cSrcweir         ::rtl::OUString aConfigSuggestion( ( aCtxt != sfx2::FileDialogHelper::UNKNOWN_CONTEXT ) ? SvtPathOptions().GetGraphicPath() : SvtPathOptions().GetWorkPath() );
1176cdf0e10cSrcweir         aReccomendedDir = INetURLObject( aConfigSuggestion ).GetMainURL( INetURLObject::NO_DECODE );
1177cdf0e10cSrcweir 	}
1178cdf0e10cSrcweir 
1179cdf0e10cSrcweir     return aReccomendedDir;
1180cdf0e10cSrcweir }
1181cdf0e10cSrcweir 
1182cdf0e10cSrcweir //-------------------------------------------------------------------------
1183cdf0e10cSrcweir ::rtl::OUString ModelData_Impl::GetReccomendedName( const ::rtl::OUString& aSuggestedName, const ::rtl::OUString& aTypeName )
1184cdf0e10cSrcweir {
1185cdf0e10cSrcweir 	// the last used name might be provided by aSuggestedName from the old selection, or from the MediaDescriptor
1186cdf0e10cSrcweir     ::rtl::OUString aReccomendedName;
1187cdf0e10cSrcweir 
1188cdf0e10cSrcweir     if ( aSuggestedName.getLength() )
1189cdf0e10cSrcweir         aReccomendedName = aSuggestedName;
1190cdf0e10cSrcweir     else
1191cdf0e10cSrcweir     {
1192cdf0e10cSrcweir         aReccomendedName = INetURLObject( GetStorable()->getLocation() ).GetName( INetURLObject::DECODE_WITH_CHARSET );
1193cdf0e10cSrcweir         if ( !aReccomendedName.getLength() )
1194cdf0e10cSrcweir         {
1195cdf0e10cSrcweir             try {
1196cdf0e10cSrcweir                 uno::Reference< frame::XTitle > xTitle( GetModel(), uno::UNO_QUERY_THROW );
1197cdf0e10cSrcweir                 aReccomendedName = xTitle->getTitle();
1198cdf0e10cSrcweir             } catch( uno::Exception& ) {}
1199cdf0e10cSrcweir         }
1200cdf0e10cSrcweir 
1201cdf0e10cSrcweir 		if ( aReccomendedName.getLength() && aTypeName.getLength() )
1202cdf0e10cSrcweir         {
1203cdf0e10cSrcweir             // adjust the extension to the type
1204cdf0e10cSrcweir             uno::Reference< container::XNameAccess > xTypeDetection = uno::Reference< container::XNameAccess >(
1205cdf0e10cSrcweir                 m_pOwner->GetServiceFactory()->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.document.TypeDetection" ) ),
1206cdf0e10cSrcweir                 uno::UNO_QUERY );
1207cdf0e10cSrcweir             if ( xTypeDetection.is() )
1208cdf0e10cSrcweir             {
1209cdf0e10cSrcweir                 INetURLObject aObj( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "file:///c:/" ) ) + aReccomendedName );
1210cdf0e10cSrcweir 
1211cdf0e10cSrcweir                 uno::Sequence< beans::PropertyValue > aTypeNameProps;
1212cdf0e10cSrcweir                 if ( ( xTypeDetection->getByName( aTypeName ) >>= aTypeNameProps ) && aTypeNameProps.getLength() )
1213cdf0e10cSrcweir                 {
1214cdf0e10cSrcweir                     ::comphelper::SequenceAsHashMap aTypeNamePropsHM( aTypeNameProps );
1215cdf0e10cSrcweir                     uno::Sequence< ::rtl::OUString > aExtensions = aTypeNamePropsHM.getUnpackedValueOrDefault(
1216cdf0e10cSrcweir                                                     ::rtl::OUString::createFromAscii( "Extensions" ),
1217cdf0e10cSrcweir                                                     ::uno::Sequence< ::rtl::OUString >() );
1218cdf0e10cSrcweir                     if ( aExtensions.getLength() )
1219cdf0e10cSrcweir                         aObj.SetExtension( aExtensions[0] );
1220cdf0e10cSrcweir                 }
1221cdf0e10cSrcweir 
1222cdf0e10cSrcweir 				aReccomendedName = aObj.GetName( INetURLObject::DECODE_WITH_CHARSET );
1223cdf0e10cSrcweir 			}
1224cdf0e10cSrcweir 		}
1225cdf0e10cSrcweir     }
1226cdf0e10cSrcweir 
1227cdf0e10cSrcweir     return aReccomendedName;
1228cdf0e10cSrcweir }
1229cdf0e10cSrcweir 
1230cdf0e10cSrcweir 
1231cdf0e10cSrcweir //=========================================================================
1232cdf0e10cSrcweir // class SfxStoringHelper
1233cdf0e10cSrcweir //=========================================================================
1234cdf0e10cSrcweir //-------------------------------------------------------------------------
1235cdf0e10cSrcweir SfxStoringHelper::SfxStoringHelper( const uno::Reference< lang::XMultiServiceFactory >& xFactory )
1236cdf0e10cSrcweir : m_xFactory( xFactory )
1237cdf0e10cSrcweir {
1238cdf0e10cSrcweir }
1239cdf0e10cSrcweir 
1240cdf0e10cSrcweir //-------------------------------------------------------------------------
1241cdf0e10cSrcweir uno::Reference< lang::XMultiServiceFactory > SfxStoringHelper::GetServiceFactory()
1242cdf0e10cSrcweir {
1243cdf0e10cSrcweir 	if ( !m_xFactory.is() )
1244cdf0e10cSrcweir 	{
1245cdf0e10cSrcweir 		m_xFactory = ::comphelper::getProcessServiceFactory();
1246cdf0e10cSrcweir         if( !m_xFactory.is() )
1247cdf0e10cSrcweir             throw uno::RuntimeException(); // TODO:
1248cdf0e10cSrcweir 	}
1249cdf0e10cSrcweir 
1250cdf0e10cSrcweir 	return m_xFactory;
1251cdf0e10cSrcweir }
1252cdf0e10cSrcweir 
1253cdf0e10cSrcweir //-------------------------------------------------------------------------
1254cdf0e10cSrcweir uno::Reference< container::XNameAccess > SfxStoringHelper::GetFilterConfiguration()
1255cdf0e10cSrcweir {
1256cdf0e10cSrcweir 	if ( !m_xFilterCFG.is() )
1257cdf0e10cSrcweir 	{
1258cdf0e10cSrcweir 		m_xFilterCFG = uno::Reference< container::XNameAccess >(
1259cdf0e10cSrcweir 			GetServiceFactory()->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.document.FilterFactory" ) ),
1260cdf0e10cSrcweir 			uno::UNO_QUERY );
1261cdf0e10cSrcweir 
1262cdf0e10cSrcweir 		if ( !m_xFilterCFG.is() )
1263cdf0e10cSrcweir 			throw uno::RuntimeException();
1264cdf0e10cSrcweir 	}
1265cdf0e10cSrcweir 
1266cdf0e10cSrcweir 	return m_xFilterCFG;
1267cdf0e10cSrcweir }
1268cdf0e10cSrcweir 
1269cdf0e10cSrcweir //-------------------------------------------------------------------------
1270cdf0e10cSrcweir uno::Reference< container::XContainerQuery > SfxStoringHelper::GetFilterQuery()
1271cdf0e10cSrcweir {
1272cdf0e10cSrcweir 	if ( !m_xFilterQuery.is() )
1273cdf0e10cSrcweir 	{
1274cdf0e10cSrcweir 		m_xFilterQuery = uno::Reference< container::XContainerQuery >( GetFilterConfiguration(), uno::UNO_QUERY );
1275cdf0e10cSrcweir 		if ( !m_xFilterQuery.is() )
1276cdf0e10cSrcweir 			throw uno::RuntimeException();
1277cdf0e10cSrcweir 	}
1278cdf0e10cSrcweir 
1279cdf0e10cSrcweir 	return m_xFilterQuery;
1280cdf0e10cSrcweir }
1281cdf0e10cSrcweir 
1282cdf0e10cSrcweir //-------------------------------------------------------------------------
1283cdf0e10cSrcweir uno::Reference< ::com::sun::star::frame::XModuleManager > SfxStoringHelper::GetModuleManager()
1284cdf0e10cSrcweir {
1285cdf0e10cSrcweir 	if ( !m_xModuleManager.is() )
1286cdf0e10cSrcweir 	{
1287cdf0e10cSrcweir 		m_xModuleManager = uno::Reference< ::com::sun::star::frame::XModuleManager >(
1288cdf0e10cSrcweir 			GetServiceFactory()->createInstance(
1289cdf0e10cSrcweir 					::rtl::OUString::createFromAscii( "com.sun.star.frame.ModuleManager" ) ),
1290cdf0e10cSrcweir 			uno::UNO_QUERY );
1291cdf0e10cSrcweir 
1292cdf0e10cSrcweir 		if ( !m_xModuleManager.is() )
1293cdf0e10cSrcweir 			throw uno::RuntimeException();
1294cdf0e10cSrcweir 	}
1295cdf0e10cSrcweir 
1296cdf0e10cSrcweir 	return m_xModuleManager;
1297cdf0e10cSrcweir }
1298cdf0e10cSrcweir 
1299cdf0e10cSrcweir //-------------------------------------------------------------------------
1300cdf0e10cSrcweir uno::Reference< container::XNameAccess > SfxStoringHelper::GetNamedModuleManager()
1301cdf0e10cSrcweir {
1302cdf0e10cSrcweir 	if ( !m_xNamedModManager.is() )
1303cdf0e10cSrcweir 	{
1304cdf0e10cSrcweir 		m_xNamedModManager = uno::Reference< container::XNameAccess >( GetModuleManager(), uno::UNO_QUERY );
1305cdf0e10cSrcweir 		if ( !m_xNamedModManager.is() )
1306cdf0e10cSrcweir 			throw uno::RuntimeException();
1307cdf0e10cSrcweir 	}
1308cdf0e10cSrcweir 
1309cdf0e10cSrcweir 	return m_xNamedModManager;
1310cdf0e10cSrcweir }
1311cdf0e10cSrcweir 
1312cdf0e10cSrcweir //-------------------------------------------------------------------------
1313cdf0e10cSrcweir sal_Bool SfxStoringHelper::GUIStoreModel( const uno::Reference< frame::XModel >& xModel,
1314cdf0e10cSrcweir 											const ::rtl::OUString& aSlotName,
1315cdf0e10cSrcweir 											uno::Sequence< beans::PropertyValue >& aArgsSequence,
1316cdf0e10cSrcweir                                             sal_Bool bPreselectPassword,
1317cdf0e10cSrcweir 		                                    ::rtl::OUString aSuggestedName,
1318cdf0e10cSrcweir                                             sal_uInt16 nDocumentSignatureState )
1319cdf0e10cSrcweir {
1320cdf0e10cSrcweir 	ModelData_Impl aModelData( *this, xModel, aArgsSequence );
1321cdf0e10cSrcweir 
1322cdf0e10cSrcweir 	sal_Bool bDialogUsed = sal_False;
1323cdf0e10cSrcweir 
1324cdf0e10cSrcweir 	INetURLObject aURL;
1325cdf0e10cSrcweir 
1326cdf0e10cSrcweir 	sal_Bool bSetStandardName = sal_False; // can be set only for SaveAs
1327cdf0e10cSrcweir 
1328cdf0e10cSrcweir 	// parse the slot name
1329cdf0e10cSrcweir 	sal_Int8 nStoreMode = getStoreModeFromSlotName( aSlotName );
1330cdf0e10cSrcweir     sal_Int8 nStatusSave = STATUS_NO_ACTION;
1331cdf0e10cSrcweir 
1332cdf0e10cSrcweir     // handle the special cases
1333cdf0e10cSrcweir     if ( nStoreMode & SAVEAS_REQUESTED )
1334cdf0e10cSrcweir     {
1335cdf0e10cSrcweir         ::comphelper::SequenceAsHashMap::const_iterator aSaveToIter =
1336cdf0e10cSrcweir                         aModelData.GetMediaDescr().find( ::rtl::OUString::createFromAscii( "SaveTo" ) );
1337cdf0e10cSrcweir         if ( aSaveToIter != aModelData.GetMediaDescr().end() )
1338cdf0e10cSrcweir         {
1339cdf0e10cSrcweir             sal_Bool bWideExport = sal_False;
1340cdf0e10cSrcweir             aSaveToIter->second >>= bWideExport;
1341cdf0e10cSrcweir             if ( bWideExport )
1342cdf0e10cSrcweir                 nStoreMode = EXPORT_REQUESTED | WIDEEXPORT_REQUESTED;
1343cdf0e10cSrcweir         }
1344cdf0e10cSrcweir 
1345cdf0e10cSrcweir         // if saving is not acceptable the warning must be shown even in case of SaveAs operation
1346cdf0e10cSrcweir         if ( ( nStoreMode & SAVEAS_REQUESTED ) && aModelData.CheckSaveAcceptable( STATUS_SAVEAS ) == STATUS_NO_ACTION )
1347cdf0e10cSrcweir             throw task::ErrorCodeIOException( ::rtl::OUString(), uno::Reference< uno::XInterface >(), ERRCODE_IO_ABORT );
1348cdf0e10cSrcweir     }
1349cdf0e10cSrcweir     else if ( nStoreMode & SAVE_REQUESTED )
1350cdf0e10cSrcweir     {
1351cdf0e10cSrcweir         // if saving is not acceptable by the configuration the warning must be shown
1352cdf0e10cSrcweir         nStatusSave = aModelData.CheckSaveAcceptable( STATUS_SAVE );
1353cdf0e10cSrcweir 
1354cdf0e10cSrcweir         if ( nStatusSave == STATUS_NO_ACTION )
1355cdf0e10cSrcweir             throw task::ErrorCodeIOException( ::rtl::OUString(), uno::Reference< uno::XInterface >(), ERRCODE_IO_ABORT );
1356cdf0e10cSrcweir         else if ( nStatusSave == STATUS_SAVE )
1357cdf0e10cSrcweir         {
1358cdf0e10cSrcweir             // check whether it is possible to use save operation
1359cdf0e10cSrcweir             nStatusSave = aModelData.CheckStateForSave();
1360cdf0e10cSrcweir         }
1361cdf0e10cSrcweir 
1362cdf0e10cSrcweir         if ( nStatusSave == STATUS_NO_ACTION )
1363cdf0e10cSrcweir         {
1364cdf0e10cSrcweir             throw task::ErrorCodeIOException( ::rtl::OUString(), uno::Reference< uno::XInterface >(), ERRCODE_IO_ABORT );
1365cdf0e10cSrcweir         }
1366cdf0e10cSrcweir         else if ( nStatusSave != STATUS_SAVE )
1367cdf0e10cSrcweir         {
1368cdf0e10cSrcweir             // this should be a usual SaveAs operation
1369cdf0e10cSrcweir             nStoreMode = SAVEAS_REQUESTED;
1370cdf0e10cSrcweir             if ( nStatusSave == STATUS_SAVEAS_STANDARDNAME )
1371cdf0e10cSrcweir                 bSetStandardName = sal_True;
1372cdf0e10cSrcweir         }
1373cdf0e10cSrcweir     }
1374cdf0e10cSrcweir 
1375cdf0e10cSrcweir     if ( !( nStoreMode & EXPORT_REQUESTED ) )
1376cdf0e10cSrcweir     {
1377cdf0e10cSrcweir         // if it is no export, warn user that the signature will be removed
1378cdf0e10cSrcweir         if (  SIGNATURESTATE_SIGNATURES_OK == nDocumentSignatureState
1379cdf0e10cSrcweir            || SIGNATURESTATE_SIGNATURES_INVALID == nDocumentSignatureState
1380cdf0e10cSrcweir            || SIGNATURESTATE_SIGNATURES_NOTVALIDATED == nDocumentSignatureState
1381cdf0e10cSrcweir            || SIGNATURESTATE_SIGNATURES_PARTIAL_OK == nDocumentSignatureState)
1382cdf0e10cSrcweir         {
1383cdf0e10cSrcweir             if ( QueryBox( NULL, SfxResId( RID_XMLSEC_QUERY_LOSINGSIGNATURE ) ).Execute() != RET_YES )
1384cdf0e10cSrcweir             {
1385cdf0e10cSrcweir                 // the user has decided not to store the document
1386cdf0e10cSrcweir                 throw task::ErrorCodeIOException( ::rtl::OUString(),
1387cdf0e10cSrcweir                                                   uno::Reference< uno::XInterface >(),
1388cdf0e10cSrcweir                                                   ERRCODE_IO_ABORT );
1389cdf0e10cSrcweir             }
1390cdf0e10cSrcweir         }
1391cdf0e10cSrcweir     }
1392cdf0e10cSrcweir 
1393cdf0e10cSrcweir     if ( nStoreMode & SAVE_REQUESTED && nStatusSave == STATUS_SAVE )
1394cdf0e10cSrcweir     {
1395cdf0e10cSrcweir         // Document properties can contain streams that should be freed before storing
1396cdf0e10cSrcweir         aModelData.FreeDocumentProps();
1397cdf0e10cSrcweir 
1398cdf0e10cSrcweir         if ( aModelData.GetStorable2().is() )
1399cdf0e10cSrcweir         {
1400cdf0e10cSrcweir             try
1401cdf0e10cSrcweir             {
1402cdf0e10cSrcweir                 aModelData.GetStorable2()->storeSelf( aModelData.GetMediaDescr().getAsConstPropertyValueList() );
1403cdf0e10cSrcweir             }
1404cdf0e10cSrcweir             catch( lang::IllegalArgumentException& )
1405cdf0e10cSrcweir             {
1406cdf0e10cSrcweir                 OSL_ENSURE( sal_False, "ModelData didn't handle illegal parameters, all the parameters are ignored!\n" );
1407cdf0e10cSrcweir                 aModelData.GetStorable()->store();
1408cdf0e10cSrcweir             }
1409cdf0e10cSrcweir         }
1410cdf0e10cSrcweir         else
1411cdf0e10cSrcweir         {
1412cdf0e10cSrcweir             OSL_ENSURE( sal_False, "XStorable2 is not supported by the model!\n" );
1413cdf0e10cSrcweir             aModelData.GetStorable()->store();
1414cdf0e10cSrcweir         }
1415cdf0e10cSrcweir 
1416cdf0e10cSrcweir         return sal_False;
1417cdf0e10cSrcweir     }
1418cdf0e10cSrcweir 
1419cdf0e10cSrcweir 	// preselect a filter for the storing process
1420cdf0e10cSrcweir 	uno::Sequence< beans::PropertyValue > aFilterProps = aModelData.GetPreselectedFilter_Impl( nStoreMode );
1421cdf0e10cSrcweir 
1422cdf0e10cSrcweir 	DBG_ASSERT( aFilterProps.getLength(), "No filter for storing!\n" );
1423cdf0e10cSrcweir 	if ( !aFilterProps.getLength() )
1424cdf0e10cSrcweir 		throw task::ErrorCodeIOException( ::rtl::OUString(),
1425cdf0e10cSrcweir 											uno::Reference< uno::XInterface >(),
1426cdf0e10cSrcweir 											ERRCODE_IO_INVALIDPARAMETER );
1427cdf0e10cSrcweir 
1428cdf0e10cSrcweir 	::comphelper::SequenceAsHashMap aFilterPropsHM( aFilterProps );
1429cdf0e10cSrcweir 	::rtl::OUString aFilterName = aFilterPropsHM.getUnpackedValueOrDefault(
1430cdf0e10cSrcweir 																	::rtl::OUString::createFromAscii( "Name" ),
1431cdf0e10cSrcweir 																	::rtl::OUString() );
1432cdf0e10cSrcweir 
1433cdf0e10cSrcweir 	::rtl::OUString aFilterFromMediaDescr = aModelData.GetMediaDescr().getUnpackedValueOrDefault(
1434cdf0e10cSrcweir 													aFilterNameString,
1435cdf0e10cSrcweir 													::rtl::OUString() );
1436cdf0e10cSrcweir 	::rtl::OUString aOldFilterName = aModelData.GetDocProps().getUnpackedValueOrDefault(
1437cdf0e10cSrcweir 													aFilterNameString,
1438cdf0e10cSrcweir 													::rtl::OUString() );
1439cdf0e10cSrcweir 
1440cdf0e10cSrcweir 	sal_Bool bUseFilterOptions = sal_False;
1441cdf0e10cSrcweir 	::comphelper::SequenceAsHashMap::const_iterator aFileNameIter = aModelData.GetMediaDescr().find( ::rtl::OUString::createFromAscii( "URL" ) );
1442cdf0e10cSrcweir 
1443cdf0e10cSrcweir 	if ( ( nStoreMode & EXPORT_REQUESTED ) && ( nStoreMode & PDFEXPORT_REQUESTED ) && !( nStoreMode & PDFDIRECTEXPORT_REQUESTED ) )
1444cdf0e10cSrcweir 	{
1445cdf0e10cSrcweir 		// this is PDF export, the filter options dialog should be shown before the export
1446cdf0e10cSrcweir 		aModelData.GetMediaDescr()[aFilterNameString] <<= aFilterName;
1447cdf0e10cSrcweir 		if ( aModelData.GetMediaDescr().find( aFilterFlagsString ) == aModelData.GetMediaDescr().end()
1448cdf0e10cSrcweir 		  && aModelData.GetMediaDescr().find( aFilterOptionsString ) == aModelData.GetMediaDescr().end()
1449cdf0e10cSrcweir 		  && aModelData.GetMediaDescr().find( aFilterDataString ) == aModelData.GetMediaDescr().end() )
1450cdf0e10cSrcweir 		{
1451cdf0e10cSrcweir 			// execute filter options dialog since no options are set in the media descriptor
1452cdf0e10cSrcweir 			if ( aModelData.ExecuteFilterDialog_Impl( aFilterName ) )
1453cdf0e10cSrcweir 				bDialogUsed = sal_True;
1454cdf0e10cSrcweir 		}
1455cdf0e10cSrcweir 	}
1456cdf0e10cSrcweir 
1457cdf0e10cSrcweir 	if ( aFileNameIter == aModelData.GetMediaDescr().end() )
1458cdf0e10cSrcweir 	{
1459cdf0e10cSrcweir 		sal_Int16 nDialog = SFX2_IMPL_DIALOG_CONFIG;
1460cdf0e10cSrcweir 		::comphelper::SequenceAsHashMap::const_iterator aDlgIter =
1461cdf0e10cSrcweir 			aModelData.GetMediaDescr().find( ::rtl::OUString::createFromAscii( "UseSystemDialog" ) );
1462cdf0e10cSrcweir 		if ( aDlgIter != aModelData.GetMediaDescr().end() )
1463cdf0e10cSrcweir 		{
1464cdf0e10cSrcweir 			sal_Bool bUseSystemDialog = sal_True;
1465cdf0e10cSrcweir 			if ( aDlgIter->second >>= bUseSystemDialog )
1466cdf0e10cSrcweir 			{
1467cdf0e10cSrcweir 				if ( bUseSystemDialog )
1468cdf0e10cSrcweir 					nDialog = SFX2_IMPL_DIALOG_SYSTEM;
1469cdf0e10cSrcweir 				else
1470cdf0e10cSrcweir 					nDialog = SFX2_IMPL_DIALOG_OOO;
1471cdf0e10cSrcweir 			}
1472cdf0e10cSrcweir 		}
1473cdf0e10cSrcweir 
1474cdf0e10cSrcweir         // The Dispatch supports parameter FolderName that overwrites SuggestedSaveAsDir
1475cdf0e10cSrcweir         ::rtl::OUString aSuggestedDir = aModelData.GetMediaDescr().getUnpackedValueOrDefault( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FolderName" ) ), ::rtl::OUString() );
1476cdf0e10cSrcweir         if ( !aSuggestedDir.getLength() )
1477cdf0e10cSrcweir         {
1478cdf0e10cSrcweir 		    aSuggestedDir = aModelData.GetMediaDescr().getUnpackedValueOrDefault( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SuggestedSaveAsDir" ) ), ::rtl::OUString() );
1479cdf0e10cSrcweir             if ( !aSuggestedDir.getLength() )
1480cdf0e10cSrcweir 		        aSuggestedDir = aModelData.GetDocProps().getUnpackedValueOrDefault( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SuggestedSaveAsDir" ) ), ::rtl::OUString() );
1481cdf0e10cSrcweir         }
1482cdf0e10cSrcweir 
1483cdf0e10cSrcweir 	aSuggestedName = aModelData.GetMediaDescr().getUnpackedValueOrDefault( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SuggestedSaveAsName" ) ), ::rtl::OUString() );
1484cdf0e10cSrcweir         if ( !aSuggestedName.getLength() )
1485cdf0e10cSrcweir 		    aSuggestedName = aModelData.GetDocProps().getUnpackedValueOrDefault( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SuggestedSaveAsName" ) ), ::rtl::OUString() );
1486cdf0e10cSrcweir 
1487cdf0e10cSrcweir 		::rtl::OUString sStandardDir;
1488cdf0e10cSrcweir 		::comphelper::SequenceAsHashMap::const_iterator aStdDirIter =
1489cdf0e10cSrcweir 			aModelData.GetMediaDescr().find( ::rtl::OUString::createFromAscii( "StandardDir" ) );
1490cdf0e10cSrcweir 		if ( aStdDirIter != aModelData.GetMediaDescr().end() )
1491cdf0e10cSrcweir 			aStdDirIter->second >>= sStandardDir;
1492cdf0e10cSrcweir 
1493cdf0e10cSrcweir 		::com::sun::star::uno::Sequence< ::rtl::OUString >	aBlackList;
1494cdf0e10cSrcweir 
1495cdf0e10cSrcweir 		::comphelper::SequenceAsHashMap::const_iterator aBlackListIter =
1496cdf0e10cSrcweir 			aModelData.GetMediaDescr().find( ::rtl::OUString::createFromAscii( "BlackList" ) );
1497cdf0e10cSrcweir 		if ( aBlackListIter != aModelData.GetMediaDescr().end() )
1498cdf0e10cSrcweir 			aBlackListIter->second >>= aBlackList;
1499cdf0e10cSrcweir 
1500cdf0e10cSrcweir         sal_Bool bExit = sal_False;
1501cdf0e10cSrcweir         while ( !bExit )
1502cdf0e10cSrcweir         {
1503cdf0e10cSrcweir             bUseFilterOptions = aModelData.OutputFileDialog( nStoreMode, aFilterProps, bSetStandardName, aSuggestedName, bPreselectPassword, aSuggestedDir, nDialog, sStandardDir, aBlackList );
1504cdf0e10cSrcweir 
1505cdf0e10cSrcweir 			// in case the dialog is opend a second time the folder should be the same as before, not what was handed over by parameters
1506cdf0e10cSrcweir 			aSuggestedDir = ::rtl::OUString();
1507cdf0e10cSrcweir             if ( nStoreMode == SAVEAS_REQUESTED )
1508cdf0e10cSrcweir             {
1509cdf0e10cSrcweir                 // in case of saving check filter for possible alien warning
1510cdf0e10cSrcweir                 ::rtl::OUString aSelFilterName = aModelData.GetMediaDescr().getUnpackedValueOrDefault(
1511cdf0e10cSrcweir                                                                                 aFilterNameString,
1512cdf0e10cSrcweir                                                                                 ::rtl::OUString() );
1513cdf0e10cSrcweir                 sal_Int8 nStatusFilterSave = aModelData.CheckFilter( aSelFilterName );
1514cdf0e10cSrcweir                 if ( nStatusFilterSave == STATUS_SAVEAS_STANDARDNAME )
1515cdf0e10cSrcweir                 {
1516cdf0e10cSrcweir                     // switch to best filter
1517cdf0e10cSrcweir                     bSetStandardName = sal_True;
1518cdf0e10cSrcweir                 }
1519cdf0e10cSrcweir                 else if ( nStatusFilterSave == STATUS_SAVE )
1520cdf0e10cSrcweir                 {
1521cdf0e10cSrcweir                     // user confirmed alien filter or "good" filter is used
1522cdf0e10cSrcweir                     bExit = sal_True;
1523cdf0e10cSrcweir                 }
1524cdf0e10cSrcweir             }
1525cdf0e10cSrcweir             else
1526cdf0e10cSrcweir                 bExit = sal_True;
1527cdf0e10cSrcweir         }
1528cdf0e10cSrcweir 
1529cdf0e10cSrcweir 		bDialogUsed = sal_True;
1530cdf0e10cSrcweir 		aFileNameIter = aModelData.GetMediaDescr().find( ::rtl::OUString::createFromAscii( "URL" ) );
1531cdf0e10cSrcweir 	}
1532cdf0e10cSrcweir 	else
1533cdf0e10cSrcweir 	{
1534cdf0e10cSrcweir 		// the target file name is provided so check if new filter options
1535cdf0e10cSrcweir 		// are provided or old options can be used
1536cdf0e10cSrcweir 		if ( aFilterFromMediaDescr.equals( aOldFilterName ) )
1537cdf0e10cSrcweir 		{
1538cdf0e10cSrcweir 			::comphelper::SequenceAsHashMap::const_iterator aIter =
1539cdf0e10cSrcweir 											aModelData.GetDocProps().find( aFilterOptionsString );
1540cdf0e10cSrcweir 			if ( aIter != aModelData.GetDocProps().end()
1541cdf0e10cSrcweir 			  && aModelData.GetMediaDescr().find( aFilterOptionsString ) == aModelData.GetMediaDescr().end() )
1542cdf0e10cSrcweir 				aModelData.GetMediaDescr()[aIter->first] = aIter->second;
1543cdf0e10cSrcweir 
1544cdf0e10cSrcweir 			aIter = aModelData.GetDocProps().find( aFilterDataString );
1545cdf0e10cSrcweir 			if ( aIter != aModelData.GetDocProps().end()
1546cdf0e10cSrcweir 			  && aModelData.GetMediaDescr().find( aFilterDataString ) == aModelData.GetMediaDescr().end() )
1547cdf0e10cSrcweir 				aModelData.GetMediaDescr()[aIter->first] = aIter->second;
1548cdf0e10cSrcweir 		}
1549cdf0e10cSrcweir 	}
1550cdf0e10cSrcweir 
1551cdf0e10cSrcweir 	if ( aFileNameIter != aModelData.GetMediaDescr().end() )
1552cdf0e10cSrcweir 	{
1553cdf0e10cSrcweir 		::rtl::OUString aFileName;
1554cdf0e10cSrcweir 		aFileNameIter->second >>= aFileName;
1555cdf0e10cSrcweir 		aURL.SetURL( aFileName );
1556cdf0e10cSrcweir 		DBG_ASSERT( aURL.GetProtocol() != INET_PROT_NOT_VALID, "Illegal URL!" );
1557cdf0e10cSrcweir 
1558cdf0e10cSrcweir 		::comphelper::SequenceAsHashMap::const_iterator aIter =
1559cdf0e10cSrcweir 								aModelData.GetMediaDescr().find( aFilterNameString );
1560cdf0e10cSrcweir 
1561cdf0e10cSrcweir 		if ( aIter != aModelData.GetMediaDescr().end() )
1562cdf0e10cSrcweir 			aIter->second >>= aFilterName;
1563cdf0e10cSrcweir 		else
1564cdf0e10cSrcweir 			aModelData.GetMediaDescr()[aFilterNameString] <<= aFilterName;
1565cdf0e10cSrcweir 
1566cdf0e10cSrcweir 		DBG_ASSERT( aFilterName.getLength(), "Illegal filter!" );
1567cdf0e10cSrcweir 	}
1568cdf0e10cSrcweir 	else
1569cdf0e10cSrcweir 	{
1570cdf0e10cSrcweir 		DBG_ASSERT( sal_False, "This code must be unreachable!\n" );
1571cdf0e10cSrcweir 		throw task::ErrorCodeIOException( ::rtl::OUString(),
1572cdf0e10cSrcweir 											uno::Reference< uno::XInterface >(),
1573cdf0e10cSrcweir 											ERRCODE_IO_INVALIDPARAMETER );
1574cdf0e10cSrcweir 	}
1575cdf0e10cSrcweir 
1576cdf0e10cSrcweir 	::comphelper::SequenceAsHashMap::const_iterator aIter =
1577cdf0e10cSrcweir 							aModelData.GetMediaDescr().find( ::rtl::OUString::createFromAscii( "FilterFlags" ) );
1578cdf0e10cSrcweir 	sal_Bool bFilterFlagsSet = ( aIter != aModelData.GetMediaDescr().end() );
1579cdf0e10cSrcweir 
1580cdf0e10cSrcweir 	if( !( nStoreMode & PDFEXPORT_REQUESTED ) && !bFilterFlagsSet
1581cdf0e10cSrcweir 		&& ( ( nStoreMode & EXPORT_REQUESTED ) || bUseFilterOptions ) )
1582cdf0e10cSrcweir 	{
1583cdf0e10cSrcweir 		// execute filter options dialog
1584cdf0e10cSrcweir 		if ( aModelData.ExecuteFilterDialog_Impl( aFilterName ) )
1585cdf0e10cSrcweir 			bDialogUsed = sal_True;
1586cdf0e10cSrcweir 	}
1587cdf0e10cSrcweir 
1588cdf0e10cSrcweir 	// so the arguments will not change any more and can be stored to the main location
1589cdf0e10cSrcweir 	aArgsSequence = aModelData.GetMediaDescr().getAsConstPropertyValueList();
1590cdf0e10cSrcweir 
1591cdf0e10cSrcweir 	// store the document and handle it's docinfo
1592cdf0e10cSrcweir 	SvtSaveOptions aOptions;
1593cdf0e10cSrcweir 
1594cdf0e10cSrcweir     DocumentSettingsGuard aSettingsGuard( aModelData.GetModel(), aModelData.IsRecommendReadOnly(), nStoreMode & EXPORT_REQUESTED );
1595cdf0e10cSrcweir 
1596cdf0e10cSrcweir     OSL_ENSURE( aModelData.GetMediaDescr().find( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Password" ) ) ) == aModelData.GetMediaDescr().end(), "The Password property of MediaDescriptor should not be used here!" );
1597cdf0e10cSrcweir 	if ( aOptions.IsDocInfoSave()
1598cdf0e10cSrcweir 	  && ( !aModelData.GetStorable()->hasLocation()
1599cdf0e10cSrcweir 		  || INetURLObject( aModelData.GetStorable()->getLocation() ) != aURL ) )
1600cdf0e10cSrcweir 	{
1601cdf0e10cSrcweir 		// this is defenitly not a Save operation
1602cdf0e10cSrcweir 		// so the document info can be updated
1603cdf0e10cSrcweir 
1604cdf0e10cSrcweir 		// on export document info must be preserved
1605cdf0e10cSrcweir         uno::Reference<document::XDocumentInfoSupplier> xDIS(
1606cdf0e10cSrcweir             aModelData.GetModel(), uno::UNO_QUERY_THROW);
1607cdf0e10cSrcweir         uno::Reference<util::XCloneable> xCloneable(
1608cdf0e10cSrcweir             xDIS->getDocumentInfo(), uno::UNO_QUERY_THROW);
1609cdf0e10cSrcweir         uno::Reference<document::XDocumentInfo> xOldDocInfo(
1610cdf0e10cSrcweir             xCloneable->createClone(), uno::UNO_QUERY_THROW);
1611cdf0e10cSrcweir 
1612cdf0e10cSrcweir 		// use dispatch API to show document info dialog
1613cdf0e10cSrcweir 		if ( aModelData.ShowDocumentInfoDialog() )
1614cdf0e10cSrcweir 			bDialogUsed = sal_True;
1615cdf0e10cSrcweir 		else
1616cdf0e10cSrcweir 		{
1617cdf0e10cSrcweir 			DBG_ERROR( "Can't execute document info dialog!\n" );
1618cdf0e10cSrcweir 		}
1619cdf0e10cSrcweir 
1620cdf0e10cSrcweir 		try {
1621cdf0e10cSrcweir 			// Document properties can contain streams that should be freed before storing
1622cdf0e10cSrcweir 			aModelData.FreeDocumentProps();
1623cdf0e10cSrcweir 			if ( ( nStoreMode & EXPORT_REQUESTED ) )
1624cdf0e10cSrcweir 				aModelData.GetStorable()->storeToURL( aURL.GetMainURL( INetURLObject::NO_DECODE ), aArgsSequence );
1625cdf0e10cSrcweir 			else
1626cdf0e10cSrcweir 				aModelData.GetStorable()->storeAsURL( aURL.GetMainURL( INetURLObject::NO_DECODE ), aArgsSequence );
1627cdf0e10cSrcweir 		}
1628cdf0e10cSrcweir 		catch( uno::Exception& )
1629cdf0e10cSrcweir 		{
1630cdf0e10cSrcweir 			if ( ( nStoreMode & EXPORT_REQUESTED ) )
1631cdf0e10cSrcweir 				SetDocInfoState( aModelData.GetModel(), xOldDocInfo, sal_True );
1632cdf0e10cSrcweir 
1633cdf0e10cSrcweir 			throw;
1634cdf0e10cSrcweir 		}
1635cdf0e10cSrcweir 
1636cdf0e10cSrcweir 		if ( ( nStoreMode & EXPORT_REQUESTED ) )
1637cdf0e10cSrcweir 			SetDocInfoState( aModelData.GetModel(), xOldDocInfo, sal_True );
1638cdf0e10cSrcweir 	}
1639cdf0e10cSrcweir 	else
1640cdf0e10cSrcweir 	{
1641cdf0e10cSrcweir 		// Document properties can contain streams that should be freed before storing
1642cdf0e10cSrcweir 		aModelData.FreeDocumentProps();
1643cdf0e10cSrcweir 
1644cdf0e10cSrcweir 		// this is actually a save operation with different parameters
1645cdf0e10cSrcweir 		// so storeTo or storeAs without DocInfo operations are used
1646cdf0e10cSrcweir 		if ( ( nStoreMode & EXPORT_REQUESTED ) )
1647cdf0e10cSrcweir 			aModelData.GetStorable()->storeToURL( aURL.GetMainURL( INetURLObject::NO_DECODE ), aArgsSequence );
1648cdf0e10cSrcweir 		else
1649cdf0e10cSrcweir 			aModelData.GetStorable()->storeAsURL( aURL.GetMainURL( INetURLObject::NO_DECODE ), aArgsSequence );
1650cdf0e10cSrcweir 	}
1651cdf0e10cSrcweir 
1652cdf0e10cSrcweir 	return bDialogUsed;
1653cdf0e10cSrcweir }
1654cdf0e10cSrcweir 
1655cdf0e10cSrcweir //-------------------------------------------------------------------------
1656cdf0e10cSrcweir // static
1657cdf0e10cSrcweir sal_Bool SfxStoringHelper::CheckFilterOptionsAppearence(
1658cdf0e10cSrcweir 													const uno::Reference< container::XNameAccess >& xFilterCFG,
1659cdf0e10cSrcweir 													const ::rtl::OUString& aFilterName )
1660cdf0e10cSrcweir {
1661cdf0e10cSrcweir 	sal_Bool bUseFilterOptions = sal_False;
1662cdf0e10cSrcweir 
1663cdf0e10cSrcweir 	DBG_ASSERT( xFilterCFG.is(), "No filter configuration!\n" );
1664cdf0e10cSrcweir 	if( xFilterCFG.is() )
1665cdf0e10cSrcweir 	{
1666cdf0e10cSrcweir 		try {
1667cdf0e10cSrcweir 	   		uno::Sequence < beans::PropertyValue > aProps;
1668cdf0e10cSrcweir 			uno::Any aAny = xFilterCFG->getByName( aFilterName );
1669cdf0e10cSrcweir 	   		if ( aAny >>= aProps )
1670cdf0e10cSrcweir 	   		{
1671cdf0e10cSrcweir 				::comphelper::SequenceAsHashMap aPropsHM( aProps );
1672cdf0e10cSrcweir 	   			::rtl::OUString aServiceName = aPropsHM.getUnpackedValueOrDefault(
1673cdf0e10cSrcweir 													::rtl::OUString::createFromAscii( "UIComponent" ),
1674cdf0e10cSrcweir 													::rtl::OUString() );
1675cdf0e10cSrcweir 				if( aServiceName.getLength() )
1676cdf0e10cSrcweir 				   	bUseFilterOptions = sal_True;
1677cdf0e10cSrcweir 			}
1678cdf0e10cSrcweir 		}
1679cdf0e10cSrcweir 		catch( uno::Exception& )
1680cdf0e10cSrcweir 		{
1681cdf0e10cSrcweir 		}
1682cdf0e10cSrcweir 	}
1683cdf0e10cSrcweir 
1684cdf0e10cSrcweir 	return bUseFilterOptions;
1685cdf0e10cSrcweir }
1686cdf0e10cSrcweir 
1687cdf0e10cSrcweir //-------------------------------------------------------------------------
1688cdf0e10cSrcweir // static
1689cdf0e10cSrcweir void SfxStoringHelper::SetDocInfoState(
1690cdf0e10cSrcweir         const uno::Reference< frame::XModel >& xModel,
1691cdf0e10cSrcweir         const uno::Reference< document::XDocumentInfo >& i_xOldDocInfo,
1692cdf0e10cSrcweir 		sal_Bool bNoModify )
1693cdf0e10cSrcweir {
1694cdf0e10cSrcweir 	uno::Reference< document::XDocumentInfoSupplier > xModelDocInfoSupplier( xModel, uno::UNO_QUERY );
1695cdf0e10cSrcweir     if ( !xModelDocInfoSupplier.is() )
1696cdf0e10cSrcweir         throw uno::RuntimeException(); // TODO:
1697cdf0e10cSrcweir 
1698cdf0e10cSrcweir     uno::Reference< document::XDocumentInfo > xDocInfoToFill = xModelDocInfoSupplier->getDocumentInfo();
1699cdf0e10cSrcweir 	uno::Reference< beans::XPropertySet > xPropSet( i_xOldDocInfo,
1700cdf0e10cSrcweir         uno::UNO_QUERY_THROW );
1701cdf0e10cSrcweir 
1702cdf0e10cSrcweir 	uno::Reference< util::XModifiable > xModifiable( xModel, uno::UNO_QUERY );
1703cdf0e10cSrcweir 	if ( bNoModify && !xModifiable.is() )
1704cdf0e10cSrcweir 		throw uno::RuntimeException();
1705cdf0e10cSrcweir 
1706cdf0e10cSrcweir 	sal_Bool bIsModified = bNoModify && xModifiable->isModified();
1707cdf0e10cSrcweir 
1708cdf0e10cSrcweir     try
1709cdf0e10cSrcweir     {
1710cdf0e10cSrcweir         uno::Reference< beans::XPropertySet > xSet( xDocInfoToFill, uno::UNO_QUERY );
1711cdf0e10cSrcweir         uno::Reference< beans::XPropertyContainer > xContainer( xSet, uno::UNO_QUERY );
1712cdf0e10cSrcweir         uno::Reference< beans::XPropertySetInfo > xSetInfo = xSet->getPropertySetInfo();
1713cdf0e10cSrcweir         uno::Sequence< beans::Property > lProps = xSetInfo->getProperties();
1714cdf0e10cSrcweir         const beans::Property* pProps = lProps.getConstArray();
1715cdf0e10cSrcweir         sal_Int32 c = lProps.getLength();
1716cdf0e10cSrcweir         sal_Int32 i = 0;
1717cdf0e10cSrcweir         for (i=0; i<c; ++i)
1718cdf0e10cSrcweir         {
1719cdf0e10cSrcweir             uno::Any aValue = xPropSet->getPropertyValue( pProps[i].Name );
1720cdf0e10cSrcweir             if ( pProps[i].Attributes & ::com::sun::star::beans::PropertyAttribute::REMOVABLE )
1721cdf0e10cSrcweir                 // QUESTION: DefaultValue?!
1722cdf0e10cSrcweir                 xContainer->addProperty( pProps[i].Name, pProps[i].Attributes, aValue );
1723cdf0e10cSrcweir             try
1724cdf0e10cSrcweir             {
1725cdf0e10cSrcweir                 // it is possible that the propertysets from XML and binary files differ; we shouldn't break then
1726cdf0e10cSrcweir                 xSet->setPropertyValue( pProps[i].Name, aValue );
1727cdf0e10cSrcweir             }
1728cdf0e10cSrcweir             catch ( uno::Exception& ) {}
1729cdf0e10cSrcweir         }
1730cdf0e10cSrcweir 
1731cdf0e10cSrcweir         sal_Int16 nCount = i_xOldDocInfo->getUserFieldCount();
1732cdf0e10cSrcweir         sal_Int16 nSupportedCount = xDocInfoToFill->getUserFieldCount();
1733cdf0e10cSrcweir         for ( sal_Int16 nInd = 0; nInd < nCount && nInd < nSupportedCount; nInd++ )
1734cdf0e10cSrcweir         {
1735cdf0e10cSrcweir             ::rtl::OUString aPropName = i_xOldDocInfo->getUserFieldName( nInd );
1736cdf0e10cSrcweir             xDocInfoToFill->setUserFieldName( nInd, aPropName );
1737cdf0e10cSrcweir             ::rtl::OUString aPropVal = i_xOldDocInfo->getUserFieldValue( nInd );
1738cdf0e10cSrcweir             xDocInfoToFill->setUserFieldValue( nInd, aPropVal );
1739cdf0e10cSrcweir         }
1740cdf0e10cSrcweir     }
1741cdf0e10cSrcweir     catch ( uno::Exception& ) {}
1742cdf0e10cSrcweir 
1743cdf0e10cSrcweir 	// set the modified flag back if required
1744cdf0e10cSrcweir 	if ( bNoModify && bIsModified != xModifiable->isModified() )
1745cdf0e10cSrcweir 		xModifiable->setModified( bIsModified );
1746cdf0e10cSrcweir }
1747cdf0e10cSrcweir 
1748cdf0e10cSrcweir //-------------------------------------------------------------------------
1749cdf0e10cSrcweir // static
1750cdf0e10cSrcweir sal_Bool SfxStoringHelper::WarnUnacceptableFormat( const uno::Reference< frame::XModel >& xModel,
1751cdf0e10cSrcweir 													::rtl::OUString aOldUIName,
1752cdf0e10cSrcweir 													::rtl::OUString /*aDefUIName*/,
1753cdf0e10cSrcweir 													sal_Bool /*bCanProceedFurther*/ )
1754cdf0e10cSrcweir {
1755cdf0e10cSrcweir     if ( !SvtSaveOptions().IsWarnAlienFormat() )
1756cdf0e10cSrcweir         return sal_True;
1757cdf0e10cSrcweir 
1758cdf0e10cSrcweir 	Window* pWin = SfxStoringHelper::GetModelWindow( xModel );
1759cdf0e10cSrcweir     SfxAlienWarningDialog aDlg( pWin, aOldUIName );
1760cdf0e10cSrcweir 
1761cdf0e10cSrcweir     return aDlg.Execute() == RET_OK;
1762cdf0e10cSrcweir }
1763cdf0e10cSrcweir 
1764cdf0e10cSrcweir // static
1765cdf0e10cSrcweir void SfxStoringHelper::ExecuteFilterDialog( SfxStoringHelper& _rStorageHelper
1766cdf0e10cSrcweir 											,const ::rtl::OUString& _sFilterName
1767cdf0e10cSrcweir 											,const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& _xModel
1768cdf0e10cSrcweir 											,/*OUT*/::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _rArgsSequence)
1769cdf0e10cSrcweir {
1770cdf0e10cSrcweir 	ModelData_Impl aModelData( _rStorageHelper, _xModel, _rArgsSequence );
1771cdf0e10cSrcweir 	if ( aModelData.ExecuteFilterDialog_Impl( _sFilterName ) )
1772cdf0e10cSrcweir 		_rArgsSequence = aModelData.GetMediaDescr().getAsConstPropertyValueList();
1773cdf0e10cSrcweir }
1774cdf0e10cSrcweir 
1775cdf0e10cSrcweir // static
1776cdf0e10cSrcweir Window* SfxStoringHelper::GetModelWindow( const uno::Reference< frame::XModel >& xModel )
1777cdf0e10cSrcweir {
1778cdf0e10cSrcweir 	Window* pWin = 0;
1779cdf0e10cSrcweir 	try {
1780cdf0e10cSrcweir 		if ( xModel.is() )
1781cdf0e10cSrcweir 		{
1782cdf0e10cSrcweir 			uno::Reference< frame::XController > xController = xModel->getCurrentController();
1783cdf0e10cSrcweir 			if ( xController.is() )
1784cdf0e10cSrcweir 			{
1785cdf0e10cSrcweir 				uno::Reference< frame::XFrame > xFrame = xController->getFrame();
1786cdf0e10cSrcweir 				if ( xFrame.is() )
1787cdf0e10cSrcweir 				{
1788cdf0e10cSrcweir 					uno::Reference< awt::XWindow > xWindow = xFrame->getContainerWindow();
1789cdf0e10cSrcweir 					if ( xWindow.is() )
1790cdf0e10cSrcweir 					{
1791cdf0e10cSrcweir 						VCLXWindow* pVCLWindow = VCLXWindow::GetImplementation( xWindow );
1792cdf0e10cSrcweir 						if ( pVCLWindow )
1793cdf0e10cSrcweir 							pWin = pVCLWindow->GetWindow();
1794cdf0e10cSrcweir 					}
1795cdf0e10cSrcweir 				}
1796cdf0e10cSrcweir 			}
1797cdf0e10cSrcweir 		}
1798cdf0e10cSrcweir 	}
1799cdf0e10cSrcweir 	catch ( uno::Exception& )
1800cdf0e10cSrcweir 	{
1801cdf0e10cSrcweir 	}
1802cdf0e10cSrcweir 
1803cdf0e10cSrcweir 	return pWin;
1804cdf0e10cSrcweir }
1805cdf0e10cSrcweir 
1806