build fix
[LibreOffice.git] / sfx2 / source / doc / guisaveas.cxx
blobc0b6491e015fc8f2eaa1a1ed13af3ac408bb1ab2
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
21 #include <com/sun/star/ui/dialogs/XFilePicker.hpp>
22 #include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
23 #include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp>
24 #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
25 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
26 #include <com/sun/star/view/XSelectionSupplier.hpp>
27 #include <com/sun/star/beans/XPropertyAccess.hpp>
28 #include <com/sun/star/beans/XPropertySet.hpp>
29 #include <com/sun/star/beans/XPropertyContainer.hpp>
30 #include <com/sun/star/beans/PropertyAttribute.hpp>
31 #include <com/sun/star/document/XExporter.hpp>
32 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
33 #include <com/sun/star/document/XDocumentProperties.hpp>
34 #include <com/sun/star/task/ErrorCodeIOException.hpp>
35 #include <com/sun/star/task/InteractionHandler.hpp>
36 #include <com/sun/star/util/DateTime.hpp>
37 #include <com/sun/star/util/URLTransformer.hpp>
38 #include <com/sun/star/util/XURLTransformer.hpp>
39 #include <com/sun/star/frame/ModuleManager.hpp>
40 #include <com/sun/star/frame/XStorable.hpp>
41 #include <com/sun/star/frame/XStorable2.hpp>
42 #include <com/sun/star/frame/XDispatchProvider.hpp>
43 #include <com/sun/star/frame/XDispatch.hpp>
44 #include <com/sun/star/frame/XTitle.hpp>
45 #include <com/sun/star/util/XModifyListener.hpp>
46 #include <com/sun/star/util/XModifiable.hpp>
47 #include <com/sun/star/util/XModifyBroadcaster.hpp>
49 #include <com/sun/star/util/XCloneable.hpp>
50 #include <com/sun/star/io/IOException.hpp>
52 #include "guisaveas.hxx"
54 #include <unotools/pathoptions.hxx>
55 #include <svl/itemset.hxx>
56 #include <svl/eitem.hxx>
57 #include <svl/stritem.hxx>
58 #include <svl/intitem.hxx>
59 #include <unotools/useroptions.hxx>
60 #include <unotools/saveopt.hxx>
61 #include <svtools/miscopt.hxx>
62 #include <tools/debug.hxx>
63 #include <tools/urlobj.hxx>
64 #include <comphelper/processfactory.hxx>
65 #include <comphelper/mimeconfighelper.hxx>
66 #include <vcl/layout.hxx>
67 #include <vcl/window.hxx>
68 #include <toolkit/awt/vclxwindow.hxx>
70 #include <sfx2/sfxsids.hrc>
71 #include <doc.hrc>
72 #include <sfx2/sfxresid.hxx>
73 #include <sfx2/docfilt.hxx>
74 #include <sfx2/filedlghelper.hxx>
75 #include <sfx2/app.hxx>
76 #include <sfx2/objsh.hxx>
77 #include <sfx2/dinfdlg.hxx>
78 #include <sfx2/request.hxx>
79 #include <sfxtypes.hxx>
80 #include "alienwarn.hxx"
82 #include <sfx2/docmacromode.hxx>
83 #include <comphelper/interaction.hxx>
84 #include <com/sun/star/task/ErrorCodeRequest.hpp>
85 #include <rtl/ref.hxx>
86 #include <framework/interaction.hxx>
87 #include <svtools/sfxecode.hxx>
88 #include "../appl/app.hrc"
90 #include <memory>
92 #include <com/sun/star/frame/Desktop.hpp>
94 #include <officecfg/Office/Common.hxx>
96 #include <vcl/FilterConfigItem.hxx>
97 #include <com/sun/star/system/SystemShellExecute.hpp>
98 #include <com/sun/star/system/SystemShellExecuteFlags.hpp>
100 #include <osl/file.hxx>
102 #ifdef _WIN32
103 #include <Shlobj.h>
104 #ifdef GetTempPath
105 #undef GetTempPath
106 #endif
107 #endif
109 // flags that specify requested operation
110 #define EXPORT_REQUESTED 1
111 #define PDFEXPORT_REQUESTED 2
112 #define PDFDIRECTEXPORT_REQUESTED 4
113 #define WIDEEXPORT_REQUESTED 8
114 #define SAVE_REQUESTED 16
115 #define SAVEAS_REQUESTED 32
116 #define SAVEACOPY_REQUESTED 64
117 #define SAVEASREMOTE_REQUESTED -1
119 // possible statuses of save operation
120 #define STATUS_NO_ACTION 0
121 #define STATUS_SAVE 1
122 #define STATUS_SAVEAS 2
123 #define STATUS_SAVEAS_STANDARDNAME 3
125 const char aFilterNameString[] = "FilterName";
126 const char aFilterOptionsString[] = "FilterOptions";
127 const char aFilterDataString[] = "FilterData";
129 using namespace ::com::sun::star;
130 using namespace css::system;
132 namespace {
134 sal_uInt16 getSlotIDFromMode( sal_Int8 nStoreMode )
136 // This is a temporary hardcoded solution must be removed when
137 // dialogs do not need parameters in SidSet representation any more
139 sal_uInt16 nResult = 0;
140 if ( nStoreMode == EXPORT_REQUESTED || nStoreMode == ( EXPORT_REQUESTED | SAVEACOPY_REQUESTED | WIDEEXPORT_REQUESTED ) )
141 nResult = SID_EXPORTDOC;
142 else if ( nStoreMode == ( EXPORT_REQUESTED | PDFEXPORT_REQUESTED ) )
143 nResult = SID_EXPORTDOCASPDF;
144 else if ( nStoreMode == ( EXPORT_REQUESTED | PDFEXPORT_REQUESTED | PDFDIRECTEXPORT_REQUESTED ) )
145 nResult = SID_DIRECTEXPORTDOCASPDF;
146 else if ( nStoreMode == SAVEAS_REQUESTED || nStoreMode == ( EXPORT_REQUESTED | WIDEEXPORT_REQUESTED ) )
147 nResult = SID_SAVEASDOC;
148 else if ( nStoreMode == SAVEASREMOTE_REQUESTED )
149 nResult = SID_SAVEASREMOTE;
150 else {
151 SAL_WARN( "sfx", "Unacceptable slot name is provided!\n" );
154 return nResult;
158 sal_Int8 getStoreModeFromSlotName( const OUString& aSlotName )
160 sal_Int8 nResult = 0;
161 if ( aSlotName == "ExportTo" )
162 nResult = EXPORT_REQUESTED;
163 else if ( aSlotName == "ExportToPDF" )
164 nResult = EXPORT_REQUESTED | PDFEXPORT_REQUESTED;
165 else if ( aSlotName == "ExportDirectToPDF" )
166 nResult = EXPORT_REQUESTED | PDFEXPORT_REQUESTED | PDFDIRECTEXPORT_REQUESTED;
167 else if ( aSlotName == "Save" )
168 nResult = SAVE_REQUESTED;
169 else if ( aSlotName == "SaveAs" )
170 nResult = SAVEAS_REQUESTED;
171 else if ( aSlotName == "SaveAsRemote" )
172 nResult = SAVEASREMOTE_REQUESTED;
173 else
174 throw task::ErrorCodeIOException(
175 ("getStoreModeFromSlotName(\"" + aSlotName
176 + "): ERRCODE_IO_INVALIDPARAMETER"),
177 uno::Reference< uno::XInterface >(), ERRCODE_IO_INVALIDPARAMETER );
179 return nResult;
183 SfxFilterFlags getMustFlags( sal_Int8 nStoreMode )
185 return ( SfxFilterFlags::EXPORT
186 | ( ( ( nStoreMode & EXPORT_REQUESTED ) && !( nStoreMode & WIDEEXPORT_REQUESTED ) ) ? SfxFilterFlags::NONE : SfxFilterFlags::IMPORT ) );
190 SfxFilterFlags getDontFlags( sal_Int8 nStoreMode )
192 return ( SfxFilterFlags::INTERNAL
193 | SfxFilterFlags::NOTINFILEDLG
194 | ( ( ( nStoreMode & EXPORT_REQUESTED ) && !( nStoreMode & WIDEEXPORT_REQUESTED ) ) ? SfxFilterFlags::IMPORT : SfxFilterFlags::NONE ) );
198 // class DocumentSettingsGuard
201 class DocumentSettingsGuard
203 uno::Reference< beans::XPropertySet > m_xDocumentSettings;
204 bool m_bPreserveReadOnly;
205 bool m_bReadOnlySupported;
207 bool m_bRestoreSettings;
208 public:
209 DocumentSettingsGuard( const uno::Reference< frame::XModel >& xModel, bool bReadOnly, bool bRestore )
210 : m_bPreserveReadOnly( false )
211 , m_bReadOnlySupported( false )
212 , m_bRestoreSettings( bRestore )
216 uno::Reference< lang::XMultiServiceFactory > xDocSettingsSupplier( xModel, uno::UNO_QUERY_THROW );
217 m_xDocumentSettings.set(
218 xDocSettingsSupplier->createInstance( "com.sun.star.document.Settings" ),
219 uno::UNO_QUERY_THROW );
221 OUString aLoadReadonlyString( "LoadReadonly" );
225 m_xDocumentSettings->getPropertyValue( aLoadReadonlyString ) >>= m_bPreserveReadOnly;
226 m_xDocumentSettings->setPropertyValue( aLoadReadonlyString, uno::makeAny( bReadOnly ) );
227 m_bReadOnlySupported = true;
229 catch( const uno::Exception& )
232 catch( const uno::Exception& )
235 if ( ( bReadOnly && !m_bReadOnlySupported ) )
236 throw uno::RuntimeException(); // the user could provide the data, so it must be stored
239 ~DocumentSettingsGuard()
241 if ( m_bRestoreSettings )
243 OUString aLoadReadonlyString( "LoadReadonly" );
247 if ( m_bReadOnlySupported )
248 m_xDocumentSettings->setPropertyValue( aLoadReadonlyString, uno::makeAny( m_bPreserveReadOnly ) );
250 catch( const uno::Exception& )
252 OSL_FAIL( "Unexpected exception!" );
257 } // anonymous namespace
260 // class ModelData_Impl
262 class ModelData_Impl
264 SfxStoringHelper* m_pOwner;
265 uno::Reference< frame::XModel > m_xModel;
266 uno::Reference< frame::XStorable > m_xStorable;
267 uno::Reference< frame::XStorable2 > m_xStorable2;
269 OUString m_aModuleName;
270 ::comphelper::SequenceAsHashMap* m_pDocumentPropsHM;
271 ::comphelper::SequenceAsHashMap* m_pModulePropsHM;
273 ::comphelper::SequenceAsHashMap m_aMediaDescrHM;
275 bool m_bRecommendReadOnly;
277 public:
278 ModelData_Impl( SfxStoringHelper& aOwner,
279 const uno::Reference< frame::XModel >& xModel,
280 const uno::Sequence< beans::PropertyValue >& aMediaDescr );
282 ~ModelData_Impl();
284 void FreeDocumentProps();
286 uno::Reference< frame::XModel > const & GetModel();
287 uno::Reference< frame::XStorable > const & GetStorable();
288 uno::Reference< frame::XStorable2 > const & GetStorable2();
290 ::comphelper::SequenceAsHashMap& GetMediaDescr() { return m_aMediaDescrHM; }
292 bool IsRecommendReadOnly() const { return m_bRecommendReadOnly; }
294 const ::comphelper::SequenceAsHashMap& GetDocProps();
296 OUString const & GetModuleName();
297 const ::comphelper::SequenceAsHashMap& GetModuleProps();
299 void CheckInteractionHandler();
302 OUString GetDocServiceName();
303 uno::Sequence< beans::PropertyValue > GetDocServiceDefaultFilterCheckFlags( SfxFilterFlags nMust, SfxFilterFlags nDont );
304 uno::Sequence< beans::PropertyValue > GetDocServiceAnyFilter( SfxFilterFlags nMust, SfxFilterFlags nDont );
305 uno::Sequence< beans::PropertyValue > GetPreselectedFilter_Impl( sal_Int8 nStoreMode );
306 uno::Sequence< beans::PropertyValue > GetDocServiceDefaultFilter();
308 bool ExecuteFilterDialog_Impl( const OUString& aFilterName );
310 sal_Int8 CheckSaveAcceptable( sal_Int8 nCurStatus );
311 sal_Int8 CheckStateForSave();
313 sal_Int8 CheckFilter( const OUString& );
315 bool CheckFilterOptionsDialogExistence();
317 bool OutputFileDialog( sal_Int8 nStoreMode,
318 const ::comphelper::SequenceAsHashMap& aPreselectedFilterPropsHM,
319 bool bSetStandardName,
320 OUString& aSuggestedName,
321 bool bPreselectPassword,
322 OUString& aSuggestedDir,
323 sal_Int16 nDialog,
324 const OUString& rStandardDir,
325 const css::uno::Sequence< OUString >& rBlackList
328 bool ShowDocumentInfoDialog();
330 static OUString GetRecommendedExtension( const OUString& aTypeName );
331 OUString GetRecommendedDir( const OUString& aSuggestedDir );
332 OUString GetRecommendedName( const OUString& aSuggestedName,
333 const OUString& aTypeName );
338 ModelData_Impl::ModelData_Impl( SfxStoringHelper& aOwner,
339 const uno::Reference< frame::XModel >& xModel,
340 const uno::Sequence< beans::PropertyValue >& aMediaDescr )
341 : m_pOwner( &aOwner )
342 , m_xModel( xModel )
343 , m_pDocumentPropsHM( nullptr )
344 , m_pModulePropsHM( nullptr )
345 , m_aMediaDescrHM( aMediaDescr )
346 , m_bRecommendReadOnly( false )
348 CheckInteractionHandler();
349 OUString sModuleName;
352 uno::Reference< lang::XComponent > xCurrentComponent = frame::Desktop::create( comphelper::getProcessComponentContext() )->getCurrentComponent();
353 sModuleName = aOwner.GetModuleManager()->identify(xCurrentComponent);
354 if(sModuleName == "com.sun.star.chart2.ChartDocument")
356 // let us switch the model and set the xStorable and
357 // XStorable2 to the old model.
358 // This is an ugly hack because we have no SfxObjectShell for chart2 yet.
359 // We need SfxObjectShell for the heavy work around ODF document creation
360 // because chart2 only writes the basic stream out.
361 // In future in might make sense to implement a full scale object shell in
362 // chart2 and make chart2 an own program.
363 m_xModel.set(xCurrentComponent, uno::UNO_QUERY_THROW );
364 m_xStorable.set(xModel, uno::UNO_QUERY_THROW );
365 m_xStorable2.set(xModel, uno::UNO_QUERY_THROW );
368 catch(...)
370 // we don't want to pass on any errors;
375 ModelData_Impl::~ModelData_Impl()
377 FreeDocumentProps();
378 delete m_pDocumentPropsHM;
379 delete m_pModulePropsHM;
383 void ModelData_Impl::FreeDocumentProps()
385 if ( m_pDocumentPropsHM )
387 delete m_pDocumentPropsHM;
388 m_pDocumentPropsHM = nullptr;
393 uno::Reference< frame::XModel > const & ModelData_Impl::GetModel()
395 if ( !m_xModel.is() )
396 throw uno::RuntimeException();
398 return m_xModel;
402 uno::Reference< frame::XStorable > const & ModelData_Impl::GetStorable()
404 if ( !m_xStorable.is() )
406 m_xStorable.set( m_xModel, uno::UNO_QUERY );
407 if ( !m_xStorable.is() )
408 throw uno::RuntimeException();
411 return m_xStorable;
415 uno::Reference< frame::XStorable2 > const & ModelData_Impl::GetStorable2()
417 if ( !m_xStorable2.is() )
419 m_xStorable2.set( m_xModel, uno::UNO_QUERY );
420 if ( !m_xStorable2.is() )
421 throw uno::RuntimeException();
424 return m_xStorable2;
428 const ::comphelper::SequenceAsHashMap& ModelData_Impl::GetDocProps()
430 if ( !m_pDocumentPropsHM )
431 m_pDocumentPropsHM = new ::comphelper::SequenceAsHashMap( GetModel()->getArgs() );
433 return *m_pDocumentPropsHM;
437 OUString const & ModelData_Impl::GetModuleName()
439 if ( m_aModuleName.isEmpty() )
441 m_aModuleName = m_pOwner->GetModuleManager()->identify(
442 uno::Reference< uno::XInterface >( m_xModel, uno::UNO_QUERY ) );
443 if ( m_aModuleName.isEmpty() )
444 throw uno::RuntimeException(); // TODO:
446 return m_aModuleName;
450 const ::comphelper::SequenceAsHashMap& ModelData_Impl::GetModuleProps()
452 if ( !m_pModulePropsHM )
454 uno::Sequence< beans::PropertyValue > aModuleProps;
455 m_pOwner->GetModuleManager()->getByName( GetModuleName() ) >>= aModuleProps;
456 if ( !aModuleProps.getLength() )
457 throw uno::RuntimeException(); // TODO;
458 m_pModulePropsHM = new ::comphelper::SequenceAsHashMap( aModuleProps );
461 return *m_pModulePropsHM;
465 OUString ModelData_Impl::GetDocServiceName()
467 return GetModuleProps().getUnpackedValueOrDefault("ooSetupFactoryDocumentService", OUString());
471 void ModelData_Impl::CheckInteractionHandler()
473 ::comphelper::SequenceAsHashMap::const_iterator aInteractIter =
474 m_aMediaDescrHM.find( OUString("InteractionHandler") );
476 if ( aInteractIter == m_aMediaDescrHM.end() )
478 try {
479 m_aMediaDescrHM[ OUString("InteractionHandler") ]
480 <<= task::InteractionHandler::createWithParent( comphelper::getProcessComponentContext(), nullptr);
482 catch( const uno::Exception& )
486 else
488 uno::Reference< task::XInteractionHandler > xInteract;
489 DBG_ASSERT( ( aInteractIter->second >>= xInteract ) && xInteract.is(), "Broken interaction handler is provided!\n" );
494 uno::Sequence< beans::PropertyValue > ModelData_Impl::GetDocServiceDefaultFilter()
496 uno::Sequence< beans::PropertyValue > aProps;
498 OUString aFilterName = GetModuleProps().getUnpackedValueOrDefault(
499 "ooSetupFactoryDefaultFilter",
500 OUString() );
502 m_pOwner->GetFilterConfiguration()->getByName( aFilterName ) >>= aProps;
504 return aProps;
508 uno::Sequence< beans::PropertyValue > ModelData_Impl::GetDocServiceDefaultFilterCheckFlags( SfxFilterFlags nMust,
509 SfxFilterFlags nDont )
511 uno::Sequence< beans::PropertyValue > aFilterProps;
512 uno::Sequence< beans::PropertyValue > aProps = GetDocServiceDefaultFilter();
513 if ( aProps.getLength() )
515 ::comphelper::SequenceAsHashMap aFiltHM( aProps );
516 SfxFilterFlags nFlags = static_cast<SfxFilterFlags>(aFiltHM.getUnpackedValueOrDefault("Flags",
517 (sal_Int32)0 ));
518 if ( ( ( nFlags & nMust ) == nMust ) && !( nFlags & nDont ) )
519 aFilterProps = aProps;
522 return aFilterProps;
526 uno::Sequence< beans::PropertyValue > ModelData_Impl::GetDocServiceAnyFilter( SfxFilterFlags nMust, SfxFilterFlags nDont )
528 uno::Sequence< beans::NamedValue > aSearchRequest { { "DocumentService", css::uno::makeAny(GetDocServiceName()) } };
530 return ::comphelper::MimeConfigurationHelper::SearchForFilter( m_pOwner->GetFilterQuery(), aSearchRequest, nMust, nDont );
534 uno::Sequence< beans::PropertyValue > ModelData_Impl::GetPreselectedFilter_Impl( sal_Int8 nStoreMode )
536 if ( nStoreMode == SAVEASREMOTE_REQUESTED )
537 nStoreMode = SAVEAS_REQUESTED;
539 uno::Sequence< beans::PropertyValue > aFilterProps;
541 SfxFilterFlags nMust = getMustFlags( nStoreMode );
542 SfxFilterFlags nDont = getDontFlags( nStoreMode );
544 if ( ( nStoreMode != SAVEASREMOTE_REQUESTED ) && ( nStoreMode & PDFEXPORT_REQUESTED ) )
546 // Preselect PDF-Filter for EXPORT
547 uno::Sequence< beans::NamedValue > aSearchRequest
549 { "Type", css::uno::makeAny(OUString("pdf_Portable_Document_Format")) },
550 { "DocumentService", css::uno::makeAny(GetDocServiceName()) }
553 aFilterProps = ::comphelper::MimeConfigurationHelper::SearchForFilter( m_pOwner->GetFilterQuery(), aSearchRequest, nMust, nDont );
555 else
557 aFilterProps = GetDocServiceDefaultFilterCheckFlags( nMust, nDont );
559 if ( !aFilterProps.getLength() )
561 // the default filter was not found, use just the first acceptable one
562 aFilterProps = GetDocServiceAnyFilter( nMust, nDont );
566 return aFilterProps;
570 bool ModelData_Impl::ExecuteFilterDialog_Impl( const OUString& aFilterName )
572 bool bDialogUsed = false;
574 try {
575 uno::Sequence < beans::PropertyValue > aProps;
576 uno::Any aAny = m_pOwner->GetFilterConfiguration()->getByName( aFilterName );
577 if ( aAny >>= aProps )
579 sal_Int32 nPropertyCount = aProps.getLength();
580 for( sal_Int32 nProperty=0; nProperty < nPropertyCount; ++nProperty )
582 if( aProps[nProperty].Name == "UIComponent" )
584 OUString aServiceName;
585 aProps[nProperty].Value >>= aServiceName;
586 if( !aServiceName.isEmpty() )
588 uno::Reference< ui::dialogs::XExecutableDialog > xFilterDialog(
589 comphelper::getProcessServiceFactory()->createInstance( aServiceName ), uno::UNO_QUERY );
590 uno::Reference< beans::XPropertyAccess > xFilterProperties( xFilterDialog, uno::UNO_QUERY );
592 if( xFilterDialog.is() && xFilterProperties.is() )
594 bDialogUsed = true;
596 uno::Reference< document::XExporter > xExporter( xFilterDialog, uno::UNO_QUERY );
597 if( xExporter.is() )
598 xExporter->setSourceDocument(
599 uno::Reference< lang::XComponent >( GetModel(), uno::UNO_QUERY ) );
601 uno::Sequence< beans::PropertyValue > aPropsForDialog;
602 GetMediaDescr() >> aPropsForDialog;
603 xFilterProperties->setPropertyValues( aPropsForDialog );
605 if( xFilterDialog->execute() )
607 uno::Sequence< beans::PropertyValue > aPropsFromDialog =
608 xFilterProperties->getPropertyValues();
609 for ( sal_Int32 nInd = 0; nInd < aPropsFromDialog.getLength(); nInd++ )
610 GetMediaDescr()[aPropsFromDialog[nInd].Name] = aPropsFromDialog[nInd].Value;
612 else
614 throw task::ErrorCodeIOException(
615 ("ModelData_Impl::ExecuteFilterDialog_Impl:"
616 " ERRCODE_IO_ABORT"),
617 uno::Reference< uno::XInterface >(),
618 ERRCODE_IO_ABORT);
623 break;
628 catch( const container::NoSuchElementException& e )
630 // the filter name is unknown
631 throw task::ErrorCodeIOException(
632 ("ModelData_Impl::ExecuteFilterDialog_Impl: NoSuchElementException"
633 " \"" + e.Message + "\": ERRCODE_IO_ABORT"),
634 uno::Reference< uno::XInterface >(), ERRCODE_IO_INVALIDPARAMETER);
636 catch( const task::ErrorCodeIOException& )
638 throw;
640 catch( const uno::Exception& e )
642 SAL_WARN("sfx.doc", "ignoring UNO exception " << e.Message);
645 return bDialogUsed;
649 sal_Int8 ModelData_Impl::CheckSaveAcceptable( sal_Int8 nCurStatus )
651 sal_Int8 nResult = nCurStatus;
653 if ( nResult != STATUS_NO_ACTION && GetStorable()->hasLocation() )
655 // the saving is acceptable
656 // in case the configuration entry is not set or set to false
657 // or in case of version creation
658 OUString aVersionCommentString = "VersionComment";
659 if ( officecfg::Office::Common::Save::Document::AlwaysSaveAs::get()
660 && GetMediaDescr().find( aVersionCommentString ) == GetMediaDescr().end() )
662 // notify the user that SaveAs is going to be done
663 vcl::Window* pWin = SfxStoringHelper::GetModelWindow( m_xModel );
664 ScopedVclPtrInstance<MessageDialog> aMessageBox(pWin, SfxResId(STR_NEW_FILENAME_SAVE),
665 VclMessageType::Question, VCL_BUTTONS_OK_CANCEL);
666 if ( aMessageBox->Execute() == RET_OK )
667 nResult = STATUS_SAVEAS;
668 else
669 nResult = STATUS_NO_ACTION;
673 return nResult;
677 sal_Int8 ModelData_Impl::CheckStateForSave()
679 // if the document is readonly or a new one a SaveAs operation must be used
680 if ( !GetStorable()->hasLocation() || GetStorable()->isReadonly() )
681 return STATUS_SAVEAS;
683 // check acceptable entries for media descriptor
684 ::comphelper::SequenceAsHashMap aAcceptedArgs;
686 OUString aVersionCommentString("VersionComment");
687 OUString aAuthorString("Author");
688 OUString aDontTerminateEdit("DontTerminateEdit");
689 OUString aInteractionHandlerString("InteractionHandler");
690 OUString aStatusIndicatorString("StatusIndicator");
691 OUString aFailOnWarningString("FailOnWarning");
693 if ( GetMediaDescr().find( aVersionCommentString ) != GetMediaDescr().end() )
694 aAcceptedArgs[ aVersionCommentString ] = GetMediaDescr()[ aVersionCommentString ];
695 if ( GetMediaDescr().find( aAuthorString ) != GetMediaDescr().end() )
696 aAcceptedArgs[ aAuthorString ] = GetMediaDescr()[ aAuthorString ];
697 if ( GetMediaDescr().find( aDontTerminateEdit ) != GetMediaDescr().end() )
698 aAcceptedArgs[ aDontTerminateEdit ] = GetMediaDescr()[ aDontTerminateEdit ];
699 if ( GetMediaDescr().find( aInteractionHandlerString ) != GetMediaDescr().end() )
700 aAcceptedArgs[ aInteractionHandlerString ] = GetMediaDescr()[ aInteractionHandlerString ];
701 if ( GetMediaDescr().find( aStatusIndicatorString ) != GetMediaDescr().end() )
702 aAcceptedArgs[ aStatusIndicatorString ] = GetMediaDescr()[ aStatusIndicatorString ];
703 if ( GetMediaDescr().find( aFailOnWarningString ) != GetMediaDescr().end() )
704 aAcceptedArgs[ aFailOnWarningString ] = GetMediaDescr()[ aFailOnWarningString ];
706 // remove unacceptable entry if there is any
707 DBG_ASSERT( GetMediaDescr().size() == aAcceptedArgs.size(),
708 "Unacceptable parameters are provided in Save request!\n" );
709 if ( GetMediaDescr().size() != aAcceptedArgs.size() )
710 GetMediaDescr() = aAcceptedArgs;
712 // check that the old filter is acceptable
713 OUString aOldFilterName = GetDocProps().getUnpackedValueOrDefault(
714 aFilterNameString,
715 OUString() );
716 sal_Int8 nResult = CheckFilter( aOldFilterName );
718 return nResult;
721 sal_Int8 ModelData_Impl::CheckFilter( const OUString& aFilterName )
723 ::comphelper::SequenceAsHashMap aFiltPropsHM;
724 SfxFilterFlags nFiltFlags = SfxFilterFlags::NONE;
725 if ( !aFilterName.isEmpty() )
727 // get properties of filter
728 uno::Sequence< beans::PropertyValue > aFilterProps;
729 if ( !aFilterName.isEmpty() )
730 m_pOwner->GetFilterConfiguration()->getByName( aFilterName ) >>= aFilterProps;
732 aFiltPropsHM = ::comphelper::SequenceAsHashMap( aFilterProps );
733 nFiltFlags = static_cast<SfxFilterFlags>(aFiltPropsHM.getUnpackedValueOrDefault("Flags", (sal_Int32)0 ));
736 // only a temporary solution until default filter retrieving feature is implemented
737 // then GetDocServiceDefaultFilter() must be used
738 ::comphelper::SequenceAsHashMap aDefFiltPropsHM = GetDocServiceDefaultFilterCheckFlags( SfxFilterFlags::IMPORT | SfxFilterFlags::EXPORT, SfxFilterFlags::NONE );
739 SfxFilterFlags nDefFiltFlags = static_cast<SfxFilterFlags>(aDefFiltPropsHM.getUnpackedValueOrDefault("Flags", (sal_Int32)0 ));
741 // if the old filter is not acceptable
742 // and there is no default filter or it is not acceptable for requested parameters then proceed with saveAs
743 if ( ( aFiltPropsHM.empty() || !( nFiltFlags & SfxFilterFlags::EXPORT ) )
744 && ( aDefFiltPropsHM.empty() || !( nDefFiltFlags & SfxFilterFlags::EXPORT ) || nDefFiltFlags & SfxFilterFlags::INTERNAL ) )
745 return STATUS_SAVEAS;
747 // so at this point there is either an acceptable old filter or default one
748 if ( aFiltPropsHM.empty() || !( nFiltFlags & SfxFilterFlags::EXPORT ) )
750 // so the default filter must be acceptable
751 return STATUS_SAVEAS_STANDARDNAME;
753 else if ( ( !( nFiltFlags & SfxFilterFlags::OWN ) || ( nFiltFlags & SfxFilterFlags::ALIEN ) )
754 && !aDefFiltPropsHM.empty()
755 && ( nDefFiltFlags & SfxFilterFlags::EXPORT ) && !( nDefFiltFlags & SfxFilterFlags::INTERNAL ))
757 // the default filter is acceptable and the old filter is alien one
758 // so ask to make a saveAs operation
759 OUString aUIName = aFiltPropsHM.getUnpackedValueOrDefault("UIName",
760 OUString() );
761 OUString aDefUIName = aDefFiltPropsHM.getUnpackedValueOrDefault("UIName",
762 OUString() );
763 OUString aPreusedFilterName = GetDocProps().getUnpackedValueOrDefault(
764 "PreusedFilterName",
765 OUString() );
767 OUString aDefType = aDefFiltPropsHM.getUnpackedValueOrDefault( "Type", OUString() );
768 OUString aDefExtension = GetRecommendedExtension( aDefType );
770 if ( !aPreusedFilterName.equals( aFilterName ) && !aUIName.equals( aDefUIName ) )
772 if ( !SfxStoringHelper::WarnUnacceptableFormat( GetModel(), aUIName, aDefUIName, aDefExtension,
773 true, (bool)( nDefFiltFlags & SfxFilterFlags::ALIEN ) ) )
774 return STATUS_SAVEAS_STANDARDNAME;
778 return STATUS_SAVE;
782 bool ModelData_Impl::CheckFilterOptionsDialogExistence()
784 uno::Sequence< beans::NamedValue > aSearchRequest { { "DocumentService", css::uno::makeAny(GetDocServiceName()) } };
786 uno::Reference< container::XEnumeration > xFilterEnum =
787 m_pOwner->GetFilterQuery()->createSubSetEnumerationByProperties( aSearchRequest );
789 while ( xFilterEnum->hasMoreElements() )
791 uno::Sequence< beans::PropertyValue > aProps;
792 if ( xFilterEnum->nextElement() >>= aProps )
794 ::comphelper::SequenceAsHashMap aPropsHM( aProps );
795 OUString aUIServName = aPropsHM.getUnpackedValueOrDefault(
796 "UIComponent",
797 OUString() );
798 if ( !aUIServName.isEmpty() )
799 return true;
803 return false;
807 bool ModelData_Impl::OutputFileDialog( sal_Int8 nStoreMode,
808 const ::comphelper::SequenceAsHashMap& aPreselectedFilterPropsHM,
809 bool bSetStandardName,
810 OUString& aSuggestedName,
811 bool bPreselectPassword,
812 OUString& aSuggestedDir,
813 sal_Int16 nDialog,
814 const OUString& rStandardDir,
815 const css::uno::Sequence< OUString >& rBlackList)
817 if ( nStoreMode == SAVEASREMOTE_REQUESTED )
818 nStoreMode = SAVEAS_REQUESTED;
820 bool bUseFilterOptions = false;
822 ::comphelper::SequenceAsHashMap::const_iterator aOverwriteIter =
823 GetMediaDescr().find( OUString("Overwrite") );
825 // the file name must be specified if overwrite option is set
826 if ( aOverwriteIter != GetMediaDescr().end() )
827 throw task::ErrorCodeIOException(
828 "ModelData_Impl::OutputFileDialog: ERRCODE_IO_INVALIDPARAMETER",
829 uno::Reference< uno::XInterface >(),
830 ERRCODE_IO_INVALIDPARAMETER);
832 // no target file name is specified
833 // we need to show the file dialog
835 // check if we have a filter which allows for filter options, so we need a corresponding checkbox in the dialog
836 bool bAllowOptions = false;
838 // in case of Export, filter options dialog is used if available
839 if( !( nStoreMode & EXPORT_REQUESTED ) || ( nStoreMode & WIDEEXPORT_REQUESTED ) )
840 bAllowOptions = CheckFilterOptionsDialogExistence();
842 // get the filename by dialog ...
843 // create the file dialog
844 sal_Int16 aDialogMode = bAllowOptions
845 ? (css::ui::dialogs::TemplateDescription::
846 FILESAVE_AUTOEXTENSION_PASSWORD_FILTEROPTIONS)
847 : (css::ui::dialogs::TemplateDescription::
848 FILESAVE_AUTOEXTENSION_PASSWORD);
849 FileDialogFlags aDialogFlags = FileDialogFlags::NONE;
851 if( ( nStoreMode & EXPORT_REQUESTED ) && !( nStoreMode & WIDEEXPORT_REQUESTED ) )
853 if ( nStoreMode & PDFEXPORT_REQUESTED )
854 aDialogMode = css::ui::dialogs::TemplateDescription::
855 FILESAVE_AUTOEXTENSION;
856 else
857 aDialogMode = css::ui::dialogs::TemplateDescription::
858 FILESAVE_AUTOEXTENSION_SELECTION;
859 aDialogFlags = FileDialogFlags::Export;
862 if( ( nStoreMode & EXPORT_REQUESTED ) && ( nStoreMode & SAVEACOPY_REQUESTED ) && ( nStoreMode & WIDEEXPORT_REQUESTED ) )
864 aDialogFlags = FileDialogFlags::SaveACopy;
867 std::unique_ptr<sfx2::FileDialogHelper> pFileDlg;
869 OUString aDocServiceName = GetDocServiceName();
870 DBG_ASSERT( !aDocServiceName.isEmpty(), "No document service for this module set!" );
872 SfxFilterFlags nMust = getMustFlags( nStoreMode );
873 SfxFilterFlags nDont = getDontFlags( nStoreMode );
874 sfx2::FileDialogHelper::Context eCtxt = sfx2::FileDialogHelper::UNKNOWN_CONTEXT;
876 if ( ( nStoreMode & EXPORT_REQUESTED ) && !( nStoreMode & WIDEEXPORT_REQUESTED ) )
878 if ( ( nStoreMode & PDFEXPORT_REQUESTED ) && !aPreselectedFilterPropsHM.empty() )
880 // this is a PDF export
881 // the filter options has been shown already
882 OUString aFilterUIName = aPreselectedFilterPropsHM.getUnpackedValueOrDefault(
883 "UIName",
884 OUString() );
886 pFileDlg.reset(new sfx2::FileDialogHelper( aDialogMode, aDialogFlags, aFilterUIName, OUString( "pdf" ), rStandardDir, rBlackList ));
887 pFileDlg->SetCurrentFilter( aFilterUIName );
889 else
891 // This is the normal dialog
892 pFileDlg.reset(new sfx2::FileDialogHelper( aDialogMode, aDialogFlags, aDocServiceName, nDialog, nMust, nDont, rStandardDir, rBlackList ));
895 if ( aDocServiceName == "com.sun.star.drawing.DrawingDocument" )
896 eCtxt = sfx2::FileDialogHelper::SD_EXPORT;
897 else if ( aDocServiceName == "com.sun.star.presentation.PresentationDocument" )
898 eCtxt = sfx2::FileDialogHelper::SI_EXPORT;
899 else if ( aDocServiceName == "com.sun.star.text.TextDocument" )
900 eCtxt = sfx2::FileDialogHelper::SW_EXPORT;
902 if ( eCtxt != sfx2::FileDialogHelper::UNKNOWN_CONTEXT )
903 pFileDlg->SetContext( eCtxt );
905 pFileDlg->CreateMatcher( aDocServiceName );
907 uno::Reference< ui::dialogs::XFilePicker2 > xFilePicker = pFileDlg->GetFilePicker();
908 uno::Reference< ui::dialogs::XFilePickerControlAccess > xControlAccess =
909 uno::Reference< ui::dialogs::XFilePickerControlAccess >( xFilePicker, uno::UNO_QUERY );
911 if ( xControlAccess.is() )
913 OUString aCtrlText = SfxResId(STR_EXPORTBUTTON).toString();
914 xControlAccess->setLabel( ui::dialogs::CommonFilePickerElementIds::PUSHBUTTON_OK, aCtrlText );
916 aCtrlText = SfxResId(STR_LABEL_FILEFORMAT).toString();
917 xControlAccess->setLabel( ui::dialogs::CommonFilePickerElementIds::LISTBOX_FILTER_LABEL, aCtrlText );
920 else
922 // This is the normal dialog
923 vcl::Window* pWin = SfxStoringHelper::GetModelWindow( m_xModel );
924 pFileDlg.reset(new sfx2::FileDialogHelper( aDialogMode, aDialogFlags, aDocServiceName, nDialog,
925 nMust, nDont, rStandardDir, rBlackList, pWin ));
926 pFileDlg->CreateMatcher( aDocServiceName );
929 OUString aAdjustToType;
931 const OUString sFilterNameString(aFilterNameString);
933 if ( ( nStoreMode & EXPORT_REQUESTED ) && !( nStoreMode & WIDEEXPORT_REQUESTED ) )
935 // it is export, set the preselected filter
936 OUString aFilterUIName = aPreselectedFilterPropsHM.getUnpackedValueOrDefault(
937 "UIName",
938 OUString() );
939 pFileDlg->SetCurrentFilter( aFilterUIName );
940 aAdjustToType = aPreselectedFilterPropsHM.getUnpackedValueOrDefault(
941 "Type",
942 OUString() );
944 // it is no export, bSetStandardName == true means that user agreed to store document in the default (default default ;-)) format
945 else if ( bSetStandardName || GetStorable()->hasLocation() )
947 uno::Sequence< beans::PropertyValue > aOldFilterProps;
948 OUString aOldFilterName = GetDocProps().getUnpackedValueOrDefault(
949 sFilterNameString,
950 OUString() );
952 if ( !aOldFilterName.isEmpty() )
953 m_pOwner->GetFilterConfiguration()->getByName( aOldFilterName ) >>= aOldFilterProps;
955 ::comphelper::SequenceAsHashMap aOldFiltPropsHM( aOldFilterProps );
956 SfxFilterFlags nOldFiltFlags = static_cast<SfxFilterFlags>(aOldFiltPropsHM.getUnpackedValueOrDefault("Flags", (sal_Int32)0 ));
958 if ( bSetStandardName || ( nOldFiltFlags & nMust ) != nMust || bool(nOldFiltFlags & nDont) )
960 // the suggested type will be changed, the extension should be adjusted
961 aAdjustToType = aPreselectedFilterPropsHM.getUnpackedValueOrDefault(
962 "Type",
963 OUString() );
965 OUString aFilterUIName = aPreselectedFilterPropsHM.getUnpackedValueOrDefault(
966 "UIName",
967 OUString() );
968 pFileDlg->SetCurrentFilter( aFilterUIName );
970 else
972 pFileDlg->SetCurrentFilter( aOldFiltPropsHM.getUnpackedValueOrDefault(
973 "UIName",
974 OUString() ) );
978 OUString aRecommendedDir = GetRecommendedDir( aSuggestedDir );
979 if ( !aRecommendedDir.isEmpty() )
980 pFileDlg->SetDisplayFolder( aRecommendedDir );
981 OUString aRecommendedName = GetRecommendedName( aSuggestedName, aAdjustToType );
982 if ( !aRecommendedName.isEmpty() )
983 pFileDlg->SetFileName( aRecommendedName );
985 uno::Reference < view::XSelectionSupplier > xSel( GetModel()->getCurrentController(), uno::UNO_QUERY );
986 if ( xSel.is() && xSel->getSelection().hasValue() )
987 GetMediaDescr()[OUString("SelectionOnly")] <<= true;
989 // This is a temporary hardcoded solution must be removed when
990 // dialogs do not need parameters in SidSet representation any more
991 sal_uInt16 nSlotID = getSlotIDFromMode( nStoreMode );
992 if ( !nSlotID )
993 throw lang::IllegalArgumentException(); // TODO:
995 // generate SidSet from MediaDescriptor and provide it into FileDialog
996 // than merge changed SidSet back
997 SfxAllItemSet aDialogParams( SfxGetpApp()->GetPool() );
998 SfxItemSet* pDialogParams = &aDialogParams;
999 TransformParameters( nSlotID,
1000 GetMediaDescr().getAsConstPropertyValueList(),
1001 aDialogParams );
1003 const SfxPoolItem* pItem = nullptr;
1004 if ( bPreselectPassword && aDialogParams.GetItemState( SID_ENCRYPTIONDATA, true, &pItem ) != SfxItemState::SET )
1006 // the file dialog preselects the password checkbox if the provided mediadescriptor has encryption data entry
1007 // after dialog execution the password interaction flag will be either removed or not
1008 aDialogParams.Put( SfxBoolItem( SID_PASSWORDINTERACTION, true ) );
1011 // aStringTypeFN is a pure output parameter, pDialogParams is an in/out parameter
1012 OUString aStringTypeFN;
1013 if ( pFileDlg->Execute( pDialogParams, aStringTypeFN ) != ERRCODE_NONE )
1015 throw task::ErrorCodeIOException(
1016 "ModelData_Impl::OutputFileDialog: ERRCODE_IO_ABORT",
1017 uno::Reference< uno::XInterface >(), ERRCODE_IO_ABORT);
1020 OUString aFilterName = aStringTypeFN;
1022 // the following two arguments can not be converted in MediaDescriptor,
1023 // so they should be removed from the ItemSet after retrieving
1024 const SfxBoolItem* pRecommendReadOnly = SfxItemSet::GetItem<SfxBoolItem>(pDialogParams, SID_RECOMMENDREADONLY, false);
1025 m_bRecommendReadOnly = ( pRecommendReadOnly && pRecommendReadOnly->GetValue() );
1026 pDialogParams->ClearItem( SID_RECOMMENDREADONLY );
1028 uno::Sequence< beans::PropertyValue > aPropsFromDialog;
1029 TransformItems( nSlotID, *pDialogParams, aPropsFromDialog );
1030 GetMediaDescr() << aPropsFromDialog;
1032 // get the path from the dialog
1033 INetURLObject aURL( pFileDlg->GetPath() );
1034 // the path should be provided outside since it might be used for further calls to the dialog
1035 aSuggestedName = aURL.GetName( INetURLObject::DECODE_WITH_CHARSET );
1036 aSuggestedDir = pFileDlg->GetDisplayDirectory();
1038 // old filter options should be cleared in case different filter is used
1040 OUString aFilterFromMediaDescr = GetMediaDescr().getUnpackedValueOrDefault(
1041 sFilterNameString,
1042 OUString() );
1043 OUString aOldFilterName = GetDocProps().getUnpackedValueOrDefault(
1044 sFilterNameString,
1045 OUString() );
1047 const OUString sFilterOptionsString(aFilterOptionsString);
1048 const OUString sFilterDataString(aFilterDataString);
1050 if ( aFilterName.equals( aFilterFromMediaDescr ) )
1052 // preserve current settings if any
1053 // if there no current settings and the name is the same
1054 // as old filter name use old filter settings
1056 if ( aFilterFromMediaDescr.equals( aOldFilterName ) )
1058 ::comphelper::SequenceAsHashMap::const_iterator aIter =
1059 GetDocProps().find( sFilterOptionsString );
1060 if ( aIter != GetDocProps().end()
1061 && GetMediaDescr().find( sFilterOptionsString ) == GetMediaDescr().end() )
1062 GetMediaDescr()[aIter->first] = aIter->second;
1064 aIter = GetDocProps().find( sFilterDataString );
1065 if ( aIter != GetDocProps().end()
1066 && GetMediaDescr().find( sFilterDataString ) == GetMediaDescr().end() )
1067 GetMediaDescr()[aIter->first] = aIter->second;
1070 else
1072 GetMediaDescr().erase( sFilterDataString );
1073 GetMediaDescr().erase( sFilterOptionsString );
1075 if ( aFilterName.equals( aOldFilterName ) )
1077 // merge filter option of the document filter
1079 ::comphelper::SequenceAsHashMap::const_iterator aIter =
1080 GetDocProps().find( sFilterOptionsString );
1081 if ( aIter != GetDocProps().end() )
1082 GetMediaDescr()[aIter->first] = aIter->second;
1084 aIter = GetDocProps().find( sFilterDataString );
1085 if ( aIter != GetDocProps().end() )
1086 GetMediaDescr()[aIter->first] = aIter->second;
1090 uno::Reference< ui::dialogs::XFilePickerControlAccess > xExtFileDlg( pFileDlg->GetFilePicker(), uno::UNO_QUERY );
1091 if ( xExtFileDlg.is() )
1093 if ( SfxStoringHelper::CheckFilterOptionsAppearence( m_pOwner->GetFilterConfiguration(), aFilterName ) )
1094 bUseFilterOptions = true;
1096 if ( ( !( nStoreMode & EXPORT_REQUESTED ) || ( nStoreMode & WIDEEXPORT_REQUESTED ) ) && bUseFilterOptions )
1100 // for exporters: always show dialog if format uses options
1101 // for save: show dialog if format uses options and no options given or if forced by user
1102 uno::Any aVal =
1103 xExtFileDlg->getValue( ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_FILTEROPTIONS, 0 );
1105 aVal >>= bUseFilterOptions;
1106 if ( !bUseFilterOptions )
1107 bUseFilterOptions =
1108 ( GetMediaDescr().find( sFilterDataString ) == GetMediaDescr().end()
1109 && GetMediaDescr().find( sFilterOptionsString ) == GetMediaDescr().end() );
1111 catch( const lang::IllegalArgumentException& )
1116 // merge in results of the dialog execution
1117 GetMediaDescr()[OUString("URL")] <<=
1118 OUString( aURL.GetMainURL( INetURLObject::NO_DECODE ));
1119 GetMediaDescr()[sFilterNameString] <<= aFilterName;
1121 return bUseFilterOptions;
1125 bool ModelData_Impl::ShowDocumentInfoDialog()
1127 bool bDialogUsed = false;
1129 try {
1130 uno::Reference< frame::XController > xController = GetModel()->getCurrentController();
1131 if ( xController.is() )
1133 uno::Reference< frame::XDispatchProvider > xFrameDispatch( xController->getFrame(), uno::UNO_QUERY );
1134 if ( xFrameDispatch.is() )
1136 util::URL aURL;
1137 aURL.Complete = ".uno:SetDocumentProperties";
1139 uno::Reference < util::XURLTransformer > xTransformer( util::URLTransformer::create( comphelper::getProcessComponentContext() ) );
1140 if ( xTransformer->parseStrict( aURL ) )
1142 uno::Reference< frame::XDispatch > xDispatch = xFrameDispatch->queryDispatch(
1143 aURL,
1144 "_self",
1145 0 );
1146 if ( xDispatch.is() )
1148 xDispatch->dispatch( aURL, uno::Sequence< beans::PropertyValue >() );
1149 bDialogUsed = true;
1155 catch ( const uno::Exception& )
1159 return bDialogUsed;
1163 OUString ModelData_Impl::GetRecommendedExtension( const OUString& aTypeName )
1165 if ( aTypeName.isEmpty() )
1166 return OUString();
1168 uno::Reference< container::XNameAccess > xTypeDetection(
1169 comphelper::getProcessServiceFactory()->createInstance("com.sun.star.document.TypeDetection"),
1170 uno::UNO_QUERY );
1171 if ( xTypeDetection.is() )
1173 uno::Sequence< beans::PropertyValue > aTypeNameProps;
1174 if ( ( xTypeDetection->getByName( aTypeName ) >>= aTypeNameProps ) && aTypeNameProps.getLength() )
1176 ::comphelper::SequenceAsHashMap aTypeNamePropsHM( aTypeNameProps );
1177 uno::Sequence< OUString > aExtensions = aTypeNamePropsHM.getUnpackedValueOrDefault(
1178 "Extensions",
1179 ::uno::Sequence< OUString >() );
1180 if ( aExtensions.getLength() )
1181 return aExtensions[0];
1185 return OUString();
1189 OUString ModelData_Impl::GetRecommendedDir( const OUString& aSuggestedDir )
1191 OUString aRecommendedDir;
1193 if ( ( !aSuggestedDir.isEmpty() || GetStorable()->hasLocation() )
1194 && !GetMediaDescr().getUnpackedValueOrDefault("RepairPackage", false ) )
1196 INetURLObject aLocation;
1197 if ( !aSuggestedDir.isEmpty() )
1198 aLocation = INetURLObject( aSuggestedDir );
1199 else
1201 OUString aOldURL = GetStorable()->getLocation();
1202 if ( !aOldURL.isEmpty() )
1204 INetURLObject aTmp( aOldURL );
1205 if ( aTmp.removeSegment() )
1206 aLocation = aTmp;
1209 if ( aLocation.HasError() )
1210 aLocation = INetURLObject( SvtPathOptions().GetWorkPath() );
1213 OUString sLocationURL( aLocation.GetMainURL( INetURLObject::NO_DECODE ) );
1214 bool bIsInTempPath( false );
1215 OUString sSysTempPath;
1216 if( osl::FileBase::getTempDirURL( sSysTempPath ) == osl::FileBase::E_None )
1217 bIsInTempPath = !sSysTempPath.isEmpty() && sLocationURL.startsWith( sSysTempPath );
1218 #ifdef _WIN32
1219 if( !bIsInTempPath )
1221 wchar_t sPath[MAX_PATH+1];
1222 HRESULT hRes = SHGetFolderPathW( NULL, CSIDL_INTERNET_CACHE, NULL, SHGFP_TYPE_CURRENT, sPath );
1223 if( SUCCEEDED(hRes) )
1225 OUString sTempINetFiles;
1226 if( osl::FileBase::getFileURLFromSystemPath(reinterpret_cast<sal_Unicode*>(sPath), sTempINetFiles) == osl::FileBase::E_None )
1227 bIsInTempPath = !sTempINetFiles.isEmpty() && sLocationURL.startsWith( sTempINetFiles );
1230 #endif
1231 // Suggest somewhere other than the system's temp directory
1232 if( bIsInTempPath )
1233 aLocation = INetURLObject( SvtPathOptions().GetWorkPath() );
1235 aLocation.setFinalSlash();
1236 if ( !aLocation.HasError() )
1237 aRecommendedDir = aLocation.GetMainURL( INetURLObject::NO_DECODE );
1239 else
1241 aRecommendedDir = INetURLObject( SvtPathOptions().GetWorkPath() ).GetMainURL( INetURLObject::NO_DECODE );
1244 return aRecommendedDir;
1248 OUString ModelData_Impl::GetRecommendedName( const OUString& aSuggestedName, const OUString& aTypeName )
1250 // the last used name might be provided by aSuggestedName from the old selection, or from the MediaDescriptor
1251 OUString aRecommendedName;
1253 if ( !aSuggestedName.isEmpty() )
1254 aRecommendedName = aSuggestedName;
1255 else
1257 aRecommendedName = INetURLObject( GetStorable()->getLocation() ).GetName( INetURLObject::DECODE_WITH_CHARSET );
1258 if ( aRecommendedName.isEmpty() )
1260 try {
1261 uno::Reference< frame::XTitle > xTitle( GetModel(), uno::UNO_QUERY_THROW );
1262 aRecommendedName = xTitle->getTitle();
1263 } catch( const uno::Exception& ) {}
1266 if ( !aRecommendedName.isEmpty() && !aTypeName.isEmpty() )
1268 // adjust the extension to the type
1269 uno::Reference< container::XNameAccess > xTypeDetection(
1270 comphelper::getProcessServiceFactory()->createInstance("com.sun.star.document.TypeDetection"),
1271 uno::UNO_QUERY );
1272 if ( xTypeDetection.is() )
1274 INetURLObject aObj( "c:/" + aRecommendedName, INetProtocol::File,
1275 INetURLObject::ENCODE_ALL, RTL_TEXTENCODING_UTF8, INetURLObject::FSYS_DOS );
1277 OUString aExtension = GetRecommendedExtension( aTypeName );
1278 if ( !aExtension.isEmpty() )
1279 aObj.SetExtension( aExtension );
1281 aRecommendedName = aObj.GetName( INetURLObject::DECODE_WITH_CHARSET );
1286 return aRecommendedName;
1290 // class SfxStoringHelper
1293 SfxStoringHelper::SfxStoringHelper()
1298 uno::Reference< container::XNameAccess > const & SfxStoringHelper::GetFilterConfiguration()
1300 if ( !m_xFilterCFG.is() )
1302 m_xFilterCFG.set( comphelper::getProcessServiceFactory()->createInstance("com.sun.star.document.FilterFactory"),
1303 uno::UNO_QUERY );
1305 if ( !m_xFilterCFG.is() )
1306 throw uno::RuntimeException();
1309 return m_xFilterCFG;
1313 uno::Reference< container::XContainerQuery > const & SfxStoringHelper::GetFilterQuery()
1315 if ( !m_xFilterQuery.is() )
1317 m_xFilterQuery.set( GetFilterConfiguration(), uno::UNO_QUERY );
1318 if ( !m_xFilterQuery.is() )
1319 throw uno::RuntimeException();
1322 return m_xFilterQuery;
1326 uno::Reference< css::frame::XModuleManager2 > const & SfxStoringHelper::GetModuleManager()
1328 if ( !m_xModuleManager.is() )
1330 m_xModuleManager = frame::ModuleManager::create(
1331 comphelper::getProcessComponentContext() );
1334 return m_xModuleManager;
1338 bool SfxStoringHelper::GUIStoreModel( const uno::Reference< frame::XModel >& xModel,
1339 const OUString& aSlotName,
1340 uno::Sequence< beans::PropertyValue >& aArgsSequence,
1341 bool bPreselectPassword,
1342 const OUString& _aSuggestedName,
1343 SignatureState nDocumentSignatureState )
1345 OUString aSuggestedName = _aSuggestedName;
1346 ModelData_Impl aModelData( *this, xModel, aArgsSequence );
1348 bool bDialogUsed = false;
1350 INetURLObject aURL;
1352 bool bSetStandardName = false; // can be set only for SaveAs
1354 // parse the slot name
1355 bool bRemote = false;
1356 sal_Int8 nStoreMode = getStoreModeFromSlotName( aSlotName );
1358 if ( nStoreMode == SAVEASREMOTE_REQUESTED )
1360 nStoreMode = SAVEAS_REQUESTED;
1361 bRemote = true;
1364 sal_Int8 nStatusSave = STATUS_NO_ACTION;
1366 ::comphelper::SequenceAsHashMap::const_iterator aSaveACopyIter =
1367 aModelData.GetMediaDescr().find( ::rtl::OUString("SaveACopy") );
1368 if ( aSaveACopyIter != aModelData.GetMediaDescr().end() )
1370 bool bSaveACopy = false;
1371 aSaveACopyIter->second >>= bSaveACopy;
1372 if ( bSaveACopy )
1373 nStoreMode = EXPORT_REQUESTED | SAVEACOPY_REQUESTED | WIDEEXPORT_REQUESTED;
1375 // handle the special cases
1376 if ( nStoreMode & SAVEAS_REQUESTED )
1378 ::comphelper::SequenceAsHashMap::const_iterator aSaveToIter =
1379 aModelData.GetMediaDescr().find( OUString("SaveTo") );
1380 if ( aSaveToIter != aModelData.GetMediaDescr().end() )
1382 bool bWideExport = false;
1383 aSaveToIter->second >>= bWideExport;
1384 if ( bWideExport )
1385 nStoreMode = EXPORT_REQUESTED | WIDEEXPORT_REQUESTED;
1388 // if saving is not acceptable the warning must be shown even in case of SaveAs operation
1389 if ( ( nStoreMode & SAVEAS_REQUESTED ) && aModelData.CheckSaveAcceptable( STATUS_SAVEAS ) == STATUS_NO_ACTION )
1390 throw task::ErrorCodeIOException(
1391 "SfxStoringHelper::GUIStoreModel: ERRCODE_IO_ABORT",
1392 uno::Reference< uno::XInterface >(), ERRCODE_IO_ABORT);
1394 else if ( nStoreMode & SAVE_REQUESTED )
1396 // if saving is not acceptable by the configuration the warning must be shown
1397 nStatusSave = aModelData.CheckSaveAcceptable( STATUS_SAVE );
1399 if ( nStatusSave == STATUS_NO_ACTION )
1400 throw task::ErrorCodeIOException(
1401 "SfxStoringHelper::GUIStoreModel: ERRCODE_IO_ABORT",
1402 uno::Reference< uno::XInterface >(), ERRCODE_IO_ABORT);
1403 else if ( nStatusSave == STATUS_SAVE )
1405 // check whether it is possible to use save operation
1406 nStatusSave = aModelData.CheckStateForSave();
1409 if ( nStatusSave == STATUS_NO_ACTION )
1411 throw task::ErrorCodeIOException(
1412 "SfxStoringHelper::GUIStoreModel: ERRCODE_IO_ABORT",
1413 uno::Reference< uno::XInterface >(), ERRCODE_IO_ABORT);
1415 else if ( nStatusSave != STATUS_SAVE )
1417 // this should be a usual SaveAs operation
1418 nStoreMode = SAVEAS_REQUESTED;
1419 if ( nStatusSave == STATUS_SAVEAS_STANDARDNAME )
1420 bSetStandardName = true;
1424 if ( !( nStoreMode & EXPORT_REQUESTED ) )
1426 // if it is no export, warn user that the signature will be removed
1427 if ( SignatureState::OK == nDocumentSignatureState
1428 || SignatureState::INVALID == nDocumentSignatureState
1429 || SignatureState::NOTVALIDATED == nDocumentSignatureState
1430 || SignatureState::PARTIAL_OK == nDocumentSignatureState)
1432 if (ScopedVclPtrInstance<MessageDialog>(nullptr, SfxResId(RID_SVXSTR_XMLSEC_QUERY_LOSINGSIGNATURE),
1433 VclMessageType::Question, VCL_BUTTONS_YES_NO)->Execute() != RET_YES)
1435 // the user has decided not to store the document
1436 throw task::ErrorCodeIOException(
1437 "SfxStoringHelper::GUIStoreModel: ERRCODE_IO_ABORT",
1438 uno::Reference< uno::XInterface >(), ERRCODE_IO_ABORT);
1443 if ( nStoreMode & SAVE_REQUESTED && nStatusSave == STATUS_SAVE )
1445 // Document properties can contain streams that should be freed before storing
1446 aModelData.FreeDocumentProps();
1448 if ( aModelData.GetStorable2().is() )
1452 aModelData.GetStorable2()->storeSelf( aModelData.GetMediaDescr().getAsConstPropertyValueList() );
1454 catch (const lang::IllegalArgumentException& e)
1456 SAL_WARN("sfx", "Ignoring parameters! "
1457 "ModelData considers this illegal: " << e.Message);
1458 aModelData.GetStorable()->store();
1461 else
1463 OSL_FAIL( "XStorable2 is not supported by the model!\n" );
1464 aModelData.GetStorable()->store();
1467 return false;
1470 // preselect a filter for the storing process
1471 uno::Sequence< beans::PropertyValue > aFilterProps = aModelData.GetPreselectedFilter_Impl( nStoreMode );
1473 DBG_ASSERT( aFilterProps.getLength(), "No filter for storing!\n" );
1474 if ( !aFilterProps.getLength() )
1475 throw task::ErrorCodeIOException(
1476 "SfxStoringHelper::GUIStoreModel: ERRCODE_IO_INVALIDPARAMETER",
1477 uno::Reference< uno::XInterface >(), ERRCODE_IO_INVALIDPARAMETER);
1479 ::comphelper::SequenceAsHashMap aFilterPropsHM( aFilterProps );
1480 OUString aFilterName = aFilterPropsHM.getUnpackedValueOrDefault(
1481 "Name",
1482 OUString() );
1484 const OUString sFilterNameString(aFilterNameString);
1486 OUString aFilterFromMediaDescr = aModelData.GetMediaDescr().getUnpackedValueOrDefault(
1487 sFilterNameString,
1488 OUString() );
1489 OUString aOldFilterName = aModelData.GetDocProps().getUnpackedValueOrDefault(
1490 sFilterNameString,
1491 OUString() );
1493 bool bUseFilterOptions = false;
1494 ::comphelper::SequenceAsHashMap::const_iterator aFileNameIter = aModelData.GetMediaDescr().find( OUString("URL") );
1496 const OUString sFilterOptionsString(aFilterOptionsString);
1497 const OUString sFilterDataString(aFilterDataString);
1498 const OUString sFilterFlagsString("FilterFlags");
1500 if ( ( nStoreMode & EXPORT_REQUESTED ) && ( nStoreMode & PDFEXPORT_REQUESTED ) && !( nStoreMode & PDFDIRECTEXPORT_REQUESTED ) )
1502 // this is PDF export, the filter options dialog should be shown before the export
1503 aModelData.GetMediaDescr()[sFilterNameString] <<= aFilterName;
1504 if ( aModelData.GetMediaDescr().find( sFilterFlagsString ) == aModelData.GetMediaDescr().end()
1505 && aModelData.GetMediaDescr().find( sFilterOptionsString ) == aModelData.GetMediaDescr().end()
1506 && aModelData.GetMediaDescr().find( sFilterDataString ) == aModelData.GetMediaDescr().end() )
1508 // execute filter options dialog since no options are set in the media descriptor
1509 if ( aModelData.ExecuteFilterDialog_Impl( aFilterName ) )
1510 bDialogUsed = true;
1514 if ( aFileNameIter == aModelData.GetMediaDescr().end() )
1516 sal_Int16 nDialog = SFX2_IMPL_DIALOG_CONFIG;
1518 if( bRemote )
1520 nDialog = SFX2_IMPL_DIALOG_REMOTE;
1522 else
1524 ::comphelper::SequenceAsHashMap::const_iterator aDlgIter =
1525 aModelData.GetMediaDescr().find( OUString("UseSystemDialog") );
1526 if ( aDlgIter != aModelData.GetMediaDescr().end() )
1528 bool bUseSystemDialog = true;
1529 if ( aDlgIter->second >>= bUseSystemDialog )
1531 if ( bUseSystemDialog )
1532 nDialog = SFX2_IMPL_DIALOG_SYSTEM;
1533 else
1534 nDialog = SFX2_IMPL_DIALOG_OOO;
1539 // The Dispatch supports parameter FolderName that overwrites SuggestedSaveAsDir
1540 OUString aSuggestedDir = aModelData.GetMediaDescr().getUnpackedValueOrDefault("FolderName", OUString() );
1541 if ( aSuggestedDir.isEmpty() )
1543 aSuggestedDir = aModelData.GetMediaDescr().getUnpackedValueOrDefault("SuggestedSaveAsDir", OUString() );
1544 if ( aSuggestedDir.isEmpty() )
1545 aSuggestedDir = aModelData.GetDocProps().getUnpackedValueOrDefault("SuggestedSaveAsDir", OUString() );
1548 aSuggestedName = aModelData.GetMediaDescr().getUnpackedValueOrDefault("SuggestedSaveAsName", OUString() );
1549 if ( aSuggestedName.isEmpty() )
1550 aSuggestedName = aModelData.GetDocProps().getUnpackedValueOrDefault("SuggestedSaveAsName", OUString() );
1552 OUString sStandardDir;
1553 ::comphelper::SequenceAsHashMap::const_iterator aStdDirIter =
1554 aModelData.GetMediaDescr().find( OUString("StandardDir") );
1555 if ( aStdDirIter != aModelData.GetMediaDescr().end() )
1556 aStdDirIter->second >>= sStandardDir;
1558 css::uno::Sequence< OUString > aBlackList;
1560 ::comphelper::SequenceAsHashMap::const_iterator aBlackListIter =
1561 aModelData.GetMediaDescr().find( OUString("BlackList") );
1562 if ( aBlackListIter != aModelData.GetMediaDescr().end() )
1563 aBlackListIter->second >>= aBlackList;
1565 bool bExit = false;
1566 while ( !bExit )
1568 // in case the dialog is opened a second time the folder should be the same as previously navigated to by the user, not what was handed over by initial parameters
1569 bUseFilterOptions = aModelData.OutputFileDialog( nStoreMode, aFilterProps, bSetStandardName, aSuggestedName, bPreselectPassword, aSuggestedDir, nDialog, sStandardDir, aBlackList );
1570 if ( nStoreMode == SAVEAS_REQUESTED )
1572 // in case of saving check filter for possible alien warning
1573 OUString aSelFilterName = aModelData.GetMediaDescr().getUnpackedValueOrDefault(
1574 sFilterNameString,
1575 OUString() );
1576 sal_Int8 nStatusFilterSave = aModelData.CheckFilter( aSelFilterName );
1577 if ( nStatusFilterSave == STATUS_SAVEAS_STANDARDNAME )
1579 // switch to best filter
1580 bSetStandardName = true;
1582 else if ( nStatusFilterSave == STATUS_SAVE )
1584 // user confirmed alien filter or "good" filter is used
1585 bExit = true;
1588 else
1589 bExit = true;
1592 bDialogUsed = true;
1593 aFileNameIter = aModelData.GetMediaDescr().find( OUString("URL") );
1595 else
1597 // the target file name is provided so check if new filter options
1598 // are provided or old options can be used
1599 if ( aFilterFromMediaDescr.equals( aOldFilterName ) )
1601 ::comphelper::SequenceAsHashMap::const_iterator aIter =
1602 aModelData.GetDocProps().find( sFilterOptionsString );
1603 if ( aIter != aModelData.GetDocProps().end()
1604 && aModelData.GetMediaDescr().find( sFilterOptionsString ) == aModelData.GetMediaDescr().end() )
1605 aModelData.GetMediaDescr()[aIter->first] = aIter->second;
1607 aIter = aModelData.GetDocProps().find( sFilterDataString );
1608 if ( aIter != aModelData.GetDocProps().end()
1609 && aModelData.GetMediaDescr().find( sFilterDataString ) == aModelData.GetMediaDescr().end() )
1610 aModelData.GetMediaDescr()[aIter->first] = aIter->second;
1614 if ( aFileNameIter != aModelData.GetMediaDescr().end() )
1616 OUString aFileName;
1617 aFileNameIter->second >>= aFileName;
1618 aURL.SetURL( aFileName );
1619 DBG_ASSERT( aURL.GetProtocol() != INetProtocol::NotValid, "Illegal URL!" );
1621 ::comphelper::SequenceAsHashMap::const_iterator aIter =
1622 aModelData.GetMediaDescr().find( sFilterNameString );
1624 if ( aIter != aModelData.GetMediaDescr().end() )
1625 aIter->second >>= aFilterName;
1626 else
1627 aModelData.GetMediaDescr()[sFilterNameString] <<= aFilterName;
1629 DBG_ASSERT( !aFilterName.isEmpty(), "Illegal filter!" );
1631 else
1633 SAL_WARN( "sfx", "This code must be unreachable!\n" );
1634 throw task::ErrorCodeIOException(
1635 "SfxStoringHelper::GUIStoreModel: ERRCODE_IO_INVALIDPARAMETER",
1636 uno::Reference< uno::XInterface >(), ERRCODE_IO_INVALIDPARAMETER);
1639 ::comphelper::SequenceAsHashMap::const_iterator aIter =
1640 aModelData.GetMediaDescr().find( OUString("FilterFlags") );
1641 bool bFilterFlagsSet = ( aIter != aModelData.GetMediaDescr().end() );
1643 if( !( nStoreMode & PDFEXPORT_REQUESTED ) && !bFilterFlagsSet
1644 && ( ( nStoreMode & EXPORT_REQUESTED ) || bUseFilterOptions ) )
1646 // execute filter options dialog
1647 if ( aModelData.ExecuteFilterDialog_Impl( aFilterName ) )
1648 bDialogUsed = true;
1651 // so the arguments will not change any more and can be stored to the main location
1652 aArgsSequence = aModelData.GetMediaDescr().getAsConstPropertyValueList();
1654 // store the document and handle it's docinfo
1655 SvtSaveOptions aOptions;
1657 DocumentSettingsGuard aSettingsGuard( aModelData.GetModel(), aModelData.IsRecommendReadOnly(), nStoreMode & EXPORT_REQUESTED );
1659 OSL_ENSURE( aModelData.GetMediaDescr().find( OUString( "Password" ) ) == aModelData.GetMediaDescr().end(), "The Password property of MediaDescriptor should not be used here!" );
1660 if ( aOptions.IsDocInfoSave()
1661 && ( !aModelData.GetStorable()->hasLocation()
1662 || INetURLObject( aModelData.GetStorable()->getLocation() ) != aURL ) )
1664 // this is definitely not a Save operation
1665 // so the document info can be updated
1667 // on export document info must be preserved
1668 uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
1669 aModelData.GetModel(), uno::UNO_QUERY_THROW);
1670 uno::Reference<util::XCloneable> xCloneable(
1671 xDPS->getDocumentProperties(), uno::UNO_QUERY_THROW);
1672 uno::Reference<document::XDocumentProperties> xOldDocProps(
1673 xCloneable->createClone(), uno::UNO_QUERY_THROW);
1675 // use dispatch API to show document info dialog
1676 if ( aModelData.ShowDocumentInfoDialog() )
1677 bDialogUsed = true;
1678 else
1680 OSL_FAIL( "Can't execute document info dialog!\n" );
1683 try {
1684 // Document properties can contain streams that should be freed before storing
1685 aModelData.FreeDocumentProps();
1686 if ( nStoreMode & EXPORT_REQUESTED )
1687 aModelData.GetStorable()->storeToURL( aURL.GetMainURL( INetURLObject::NO_DECODE ), aArgsSequence );
1688 else
1689 aModelData.GetStorable()->storeAsURL( aURL.GetMainURL( INetURLObject::NO_DECODE ), aArgsSequence );
1691 catch( const uno::Exception& )
1693 if ( nStoreMode & EXPORT_REQUESTED )
1695 SetDocInfoState(aModelData.GetModel(), xOldDocProps, true);
1697 throw;
1700 if ( nStoreMode & EXPORT_REQUESTED )
1702 SetDocInfoState(aModelData.GetModel(), xOldDocProps, true);
1705 else
1707 // Document properties can contain streams that should be freed before storing
1708 aModelData.FreeDocumentProps();
1710 // this is actually a save operation with different parameters
1711 // so storeTo or storeAs without DocInfo operations are used
1712 if ( nStoreMode & EXPORT_REQUESTED )
1713 aModelData.GetStorable()->storeToURL( aURL.GetMainURL( INetURLObject::NO_DECODE ), aArgsSequence );
1714 else
1715 aModelData.GetStorable()->storeAsURL( aURL.GetMainURL( INetURLObject::NO_DECODE ), aArgsSequence );
1718 // Launch PDF viewer
1719 if ( nStoreMode & PDFEXPORT_REQUESTED )
1721 FilterConfigItem aItem( "Office.Common/Filter/PDF/Export/" );
1722 bool aViewPDF = aItem.ReadBool( "ViewPDFAfterExport", false );
1724 if ( aViewPDF )
1726 uno::Reference<XSystemShellExecute> xSystemShellExecute(SystemShellExecute::create( ::comphelper::getProcessComponentContext() ) );
1727 xSystemShellExecute->execute( aURL.GetMainURL( INetURLObject::NO_DECODE ), "", SystemShellExecuteFlags::URIS_ONLY );
1731 return bDialogUsed;
1735 // static
1736 bool SfxStoringHelper::CheckFilterOptionsAppearence(
1737 const uno::Reference< container::XNameAccess >& xFilterCFG,
1738 const OUString& aFilterName )
1740 bool bUseFilterOptions = false;
1742 DBG_ASSERT( xFilterCFG.is(), "No filter configuration!\n" );
1743 if( xFilterCFG.is() )
1745 try {
1746 uno::Sequence < beans::PropertyValue > aProps;
1747 uno::Any aAny = xFilterCFG->getByName( aFilterName );
1748 if ( aAny >>= aProps )
1750 ::comphelper::SequenceAsHashMap aPropsHM( aProps );
1751 OUString aServiceName = aPropsHM.getUnpackedValueOrDefault(
1752 "UIComponent",
1753 OUString() );
1754 if( !aServiceName.isEmpty() )
1755 bUseFilterOptions = true;
1758 catch( const uno::Exception& )
1763 return bUseFilterOptions;
1767 // static
1768 void SfxStoringHelper::SetDocInfoState(
1769 const uno::Reference< frame::XModel >& xModel,
1770 const uno::Reference< document::XDocumentProperties>& i_xOldDocProps,
1771 bool bNoModify )
1773 uno::Reference<document::XDocumentPropertiesSupplier> const
1774 xModelDocPropsSupplier(xModel, uno::UNO_QUERY_THROW);
1775 uno::Reference<document::XDocumentProperties> const xDocPropsToFill =
1776 xModelDocPropsSupplier->getDocumentProperties();
1777 uno::Reference< beans::XPropertySet > const xPropSet(
1778 i_xOldDocProps->getUserDefinedProperties(), uno::UNO_QUERY_THROW);
1780 uno::Reference< util::XModifiable > xModifiable( xModel, uno::UNO_QUERY );
1781 if ( bNoModify && !xModifiable.is() )
1782 throw uno::RuntimeException();
1784 bool bIsModified = bNoModify && xModifiable->isModified();
1788 uno::Reference< beans::XPropertySet > const xSet(
1789 xDocPropsToFill->getUserDefinedProperties(), uno::UNO_QUERY);
1790 uno::Reference< beans::XPropertyContainer > xContainer( xSet, uno::UNO_QUERY );
1791 uno::Reference< beans::XPropertySetInfo > xSetInfo = xSet->getPropertySetInfo();
1792 uno::Sequence< beans::Property > lProps = xSetInfo->getProperties();
1793 const beans::Property* pProps = lProps.getConstArray();
1794 sal_Int32 c = lProps.getLength();
1795 sal_Int32 i = 0;
1796 for (i=0; i<c; ++i)
1798 uno::Any aValue = xPropSet->getPropertyValue( pProps[i].Name );
1799 if ( pProps[i].Attributes & css::beans::PropertyAttribute::REMOVABLE )
1803 // QUESTION: DefaultValue?!
1804 xContainer->addProperty( pProps[i].Name, pProps[i].Attributes, aValue );
1806 catch (beans::PropertyExistException const&) {}
1809 // it is possible that the propertysets from XML and binary files differ; we shouldn't break then
1810 xSet->setPropertyValue( pProps[i].Name, aValue );
1812 catch ( const uno::Exception& ) {}
1816 // sigh... have to set these manually I'm afraid... wonder why
1817 // SfxObjectShell doesn't handle this internally, should be easier
1818 xDocPropsToFill->setAuthor(i_xOldDocProps->getAuthor());
1819 xDocPropsToFill->setGenerator(i_xOldDocProps->getGenerator());
1820 xDocPropsToFill->setCreationDate(i_xOldDocProps->getCreationDate());
1821 xDocPropsToFill->setTitle(i_xOldDocProps->getTitle());
1822 xDocPropsToFill->setSubject(i_xOldDocProps->getSubject());
1823 xDocPropsToFill->setDescription(i_xOldDocProps->getDescription());
1824 xDocPropsToFill->setKeywords(i_xOldDocProps->getKeywords());
1825 xDocPropsToFill->setModifiedBy(i_xOldDocProps->getModifiedBy());
1826 xDocPropsToFill->setModificationDate(i_xOldDocProps->getModificationDate());
1827 xDocPropsToFill->setPrintedBy(i_xOldDocProps->getPrintedBy());
1828 xDocPropsToFill->setPrintDate(i_xOldDocProps->getPrintDate());
1829 xDocPropsToFill->setAutoloadURL(i_xOldDocProps->getAutoloadURL());
1830 xDocPropsToFill->setAutoloadSecs(i_xOldDocProps->getAutoloadSecs());
1831 xDocPropsToFill->setDefaultTarget(i_xOldDocProps->getDefaultTarget());
1832 xDocPropsToFill->setEditingCycles(i_xOldDocProps->getEditingCycles());
1833 xDocPropsToFill->setEditingDuration(i_xOldDocProps->getEditingDuration());
1834 // other attributes e.g. DocumentStatistics are not editable from dialog
1836 catch (const uno::Exception& e)
1838 SAL_INFO("sfx.doc", "SetDocInfoState: caught exception: " << e.Message);
1841 // set the modified flag back if required
1842 if ( (bNoModify && bIsModified) != bool(xModifiable->isModified()) )
1843 xModifiable->setModified( bIsModified );
1847 // static
1848 bool SfxStoringHelper::WarnUnacceptableFormat( const uno::Reference< frame::XModel >& xModel,
1849 const OUString& aOldUIName,
1850 const OUString& /*aDefUIName*/,
1851 const OUString& aDefExtension,
1852 bool /*bCanProceedFurther*/,
1853 bool bDefIsAlien )
1855 if ( !SvtSaveOptions().IsWarnAlienFormat() )
1856 return true;
1858 vcl::Window* pWin = SfxStoringHelper::GetModelWindow( xModel );
1859 ScopedVclPtrInstance< SfxAlienWarningDialog > aDlg( pWin, aOldUIName, aDefExtension, bDefIsAlien );
1861 return aDlg->Execute() == RET_OK;
1864 vcl::Window* SfxStoringHelper::GetModelWindow( const uno::Reference< frame::XModel >& xModel )
1866 VclPtr<vcl::Window> pWin;
1867 try {
1868 if ( xModel.is() )
1870 uno::Reference< frame::XController > xController = xModel->getCurrentController();
1871 if ( xController.is() )
1873 uno::Reference< frame::XFrame > xFrame = xController->getFrame();
1874 if ( xFrame.is() )
1876 uno::Reference< awt::XWindow > xWindow = xFrame->getContainerWindow();
1877 if ( xWindow.is() )
1879 VCLXWindow* pVCLWindow = VCLXWindow::GetImplementation( xWindow );
1880 if ( pVCLWindow )
1881 pWin = pVCLWindow->GetWindow();
1887 catch ( const uno::Exception& )
1891 return pWin;
1894 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */