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