20#include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
21#include <com/sun/star/ui/dialogs/XAsynchronousExecutableDialog.hpp>
22#include <com/sun/star/ui/dialogs/XFilePicker3.hpp>
23#include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
24#include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp>
25#include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
26#include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
27#include <com/sun/star/view/XSelectionSupplier.hpp>
28#include <com/sun/star/beans/PropertyExistException.hpp>
29#include <com/sun/star/beans/XPropertyAccess.hpp>
30#include <com/sun/star/beans/XPropertySet.hpp>
31#include <com/sun/star/beans/XPropertyContainer.hpp>
32#include <com/sun/star/beans/PropertyAttribute.hpp>
33#include <com/sun/star/document/XExporter.hpp>
34#include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
35#include <com/sun/star/document/XDocumentProperties.hpp>
36#include <com/sun/star/task/ErrorCodeIOException.hpp>
37#include <com/sun/star/task/InteractionHandler.hpp>
38#include <com/sun/star/util/URLTransformer.hpp>
39#include <com/sun/star/util/XURLTransformer.hpp>
40#include <com/sun/star/frame/ModuleManager.hpp>
41#include <com/sun/star/frame/XStorable.hpp>
42#include <com/sun/star/frame/XStorable2.hpp>
43#include <com/sun/star/frame/XDispatchProvider.hpp>
44#include <com/sun/star/frame/XDispatch.hpp>
45#include <com/sun/star/frame/XTitle.hpp>
46#include <com/sun/star/util/XModifiable.hpp>
47#include <com/sun/star/lang/XMultiServiceFactory.hpp>
49#include <com/sun/star/util/XCloneable.hpp>
67#include <LibreOfficeKit/LibreOfficeKitEnums.h>
76#include <sfx2/sfxsids.hrc>
77#include <sfx2/strings.hrc>
89#include <officecfg/Office/Common.hxx>
92#include <com/sun/star/system/SystemShellExecute.hpp>
93#include <com/sun/star/system/SystemShellExecuteFlags.hpp>
95#include <osl/file.hxx>
105#define EXPORT_REQUESTED 1
106#define PDFEXPORT_REQUESTED 2
107#define PDFDIRECTEXPORT_REQUESTED 4
108#define WIDEEXPORT_REQUESTED 8
109#define SAVE_REQUESTED 16
110#define SAVEAS_REQUESTED 32
111#define SAVEACOPY_REQUESTED 64
112#define EPUBEXPORT_REQUESTED 128
113#define EPUBDIRECTEXPORT_REQUESTED 256
114#define SAVEASREMOTE_REQUESTED -1
117#define STATUS_NO_ACTION 0
119#define STATUS_SAVEAS 2
120#define STATUS_SAVEAS_STANDARDNAME 3
127using namespace css::system;
131sal_uInt16 getSlotIDFromMode( sal_Int16 nStoreMode )
136 sal_uInt16 nResult = 0;
138 nResult = SID_EXPORTDOC;
140 nResult = SID_EXPORTDOCASPDF;
142 nResult = SID_EXPORTDOCASEPUB;
144 nResult = SID_DIRECTEXPORTDOCASPDF;
146 nResult = SID_DIRECTEXPORTDOCASEPUB;
148 nResult = SID_SAVEASDOC;
150 nResult = SID_SAVEASREMOTE;
152 SAL_WARN(
"sfx.doc",
"Unacceptable slot name is provided!" );
159sal_Int16 getStoreModeFromSlotName( std::u16string_view aSlotName )
161 sal_Int16 nResult = 0;
162 if ( aSlotName ==
u"ExportTo" )
164 else if ( aSlotName ==
u"ExportToPDF" )
166 else if ( aSlotName ==
u"ExportDirectToPDF" )
168 else if ( aSlotName ==
u"ExportToEPUB" )
170 else if ( aSlotName ==
u"ExportDirectToEPUB" )
172 else if ( aSlotName ==
u"Save" )
174 else if ( aSlotName ==
u"SaveAs" )
176 else if ( aSlotName ==
u"SaveAsRemote" )
179 throw task::ErrorCodeIOException(
180 (OUString::Concat(
"getStoreModeFromSlotName(\"") + aSlotName
181 +
"): ERRCODE_IO_INVALIDPARAMETER"),
190 return ( SfxFilterFlags::EXPORT
197 return ( SfxFilterFlags::INTERNAL
198 | SfxFilterFlags::NOTINFILEDLG
205class DocumentSettingsGuard
207 uno::Reference< beans::XPropertySet > m_xDocumentSettings;
208 bool m_bPreserveReadOnly;
209 bool m_bReadOnlySupported;
211 bool m_bRestoreSettings;
213 DocumentSettingsGuard(
const uno::Reference< frame::XModel >&
xModel,
bool bReadOnly,
bool bRestore )
214 : m_bPreserveReadOnly(
false )
215 , m_bReadOnlySupported(
false )
216 , m_bRestoreSettings( bRestore )
220 uno::Reference< lang::XMultiServiceFactory > xDocSettingsSupplier(
xModel, uno::UNO_QUERY_THROW );
221 m_xDocumentSettings.set(
222 xDocSettingsSupplier->createInstance(
"com.sun.star.document.Settings" ),
223 uno::UNO_QUERY_THROW );
227 OUString aLoadReadonlyString(
"LoadReadonly" );
228 m_xDocumentSettings->getPropertyValue( aLoadReadonlyString ) >>= m_bPreserveReadOnly;
229 m_xDocumentSettings->setPropertyValue( aLoadReadonlyString,
uno::Any(
bReadOnly ) );
230 m_bReadOnlySupported =
true;
232 catch(
const uno::Exception& )
235 catch(
const uno::Exception& )
238 if (
bReadOnly && !m_bReadOnlySupported )
239 throw uno::RuntimeException();
242 ~DocumentSettingsGuard()
244 if ( m_bRestoreSettings )
248 if ( m_bReadOnlySupported )
249 m_xDocumentSettings->setPropertyValue(
"LoadReadonly",
uno::Any( m_bPreserveReadOnly ) );
251 catch(
const uno::Exception& )
280 DECL_LINK(OptionsDialogClosedHdl, css::ui::dialogs::DialogClosedEvent*,
void);
284 uno::Reference< frame::XModel > xModel,
285 const uno::Sequence< beans::PropertyValue >& aMediaDescr );
291 uno::Reference< frame::XModel >
const &
GetModel()
const;
292 uno::Reference< frame::XStorable >
const &
GetStorable();
293 uno::Reference< frame::XStorable2 >
const &
GetStorable2();
299 const ::comphelper::SequenceAsHashMap&
GetDocProps();
323 const ::comphelper::SequenceAsHashMap& aPreselectedFilterPropsHM,
324 bool bSetStandardName,
325 OUString& aSuggestedName,
326 bool bPreselectPassword,
327 OUString& aSuggestedDir,
329 const OUString& rStandardDir,
330 const css::uno::Sequence< OUString >& rDenyList
338 const OUString& aTypeName );
343 uno::Reference< frame::XModel > xModel,
344 const uno::Sequence< beans::PropertyValue >& aMediaDescr )
347, m_aMediaDescrHM( aMediaDescr )
348, m_bRecommendReadOnly( false )
373 throw uno::RuntimeException();
415 uno::Reference< uno::XInterface >(
m_xModel, uno::UNO_QUERY ) );
417 throw uno::RuntimeException();
427 uno::Sequence< beans::PropertyValue > aModuleProps;
429 if ( !aModuleProps.hasElements() )
430 throw uno::RuntimeException();
431 m_pModulePropsHM.reset( new ::comphelper::SequenceAsHashMap( aModuleProps ) );
446 static constexpr OUStringLiteral sInteractionHandler {
u"InteractionHandler"};
456 catch(
const uno::Exception& )
462 uno::Reference< task::XInteractionHandler > xInteract;
463 DBG_ASSERT( ( aInteractIter->second >>= xInteract ) && xInteract.is(),
"Broken interaction handler is provided!\n" );
470 uno::Sequence< beans::PropertyValue > aProps;
483 uno::Sequence< beans::PropertyValue > aFilterProps;
485 if ( aProps.hasElements() )
490 if ( ( ( nFlags & nMust ) == nMust ) && !( nFlags & nDont ) )
491 aFilterProps = aProps;
500 uno::Sequence< beans::NamedValue > aSearchRequest { {
"DocumentService", css::uno::Any(
GetDocServiceName()) } };
502 return ::comphelper::MimeConfigurationHelper::SearchForFilter(
m_pOwner->
GetFilterQuery(), aSearchRequest, nMust, nDont );
511 uno::Sequence< beans::PropertyValue > aFilterProps;
519 uno::Sequence< beans::NamedValue > aSearchRequest
521 {
"Type", css::uno::Any(OUString(
"pdf_Portable_Document_Format")) },
530 uno::Sequence<beans::NamedValue> aSearchRequest
532 {
"Type", css::uno::Any(OUString(
"writer_EPUB_Document")) },
542 if ( !aFilterProps.hasElements() )
555 bool bDialogUsed =
false;
558 uno::Sequence < beans::PropertyValue > aProps;
560 if ( aAny >>= aProps )
562 auto pProp = std::find_if(std::cbegin(aProps), std::cend(aProps),
563 [](
const beans::PropertyValue& rProp) {
return rProp.Name ==
"UIComponent"; });
564 if (pProp != std::cend(aProps))
566 OUString aServiceName;
567 pProp->Value >>= aServiceName;
568 if( !aServiceName.isEmpty() )
575 uno::Reference< beans::XPropertyAccess > xFilterProperties;
576 uno::Reference< ui::dialogs::XExecutableDialog > xFilterDialog;
577 uno::Reference< ui::dialogs::XAsynchronousExecutableDialog > xAsyncFilterDialog;
578 uno::Reference< document::XExporter > xExporter;
582 xAsyncFilterDialog = uno::Reference< ui::dialogs::XAsynchronousExecutableDialog >(
584 OSL_ENSURE(xAsyncFilterDialog.is(),
"ModelData_Impl::ExecuteFilterDialog_Impl: Dialog is not async!");
585 xFilterProperties = uno::Reference< beans::XPropertyAccess >( xAsyncFilterDialog, uno::UNO_QUERY );
586 xExporter = uno::Reference< document::XExporter >( xAsyncFilterDialog, uno::UNO_QUERY );
590 xFilterDialog = uno::Reference< ui::dialogs::XExecutableDialog >(
592 xFilterProperties = uno::Reference< beans::XPropertyAccess >( xFilterDialog, uno::UNO_QUERY );
593 xExporter = uno::Reference< document::XExporter >( xFilterDialog, uno::UNO_QUERY );
596 if ( xFilterProperties.is() && ( xFilterDialog.is() || xAsyncFilterDialog.is() ) )
601 xExporter->setSourceDocument(
GetModel() );
603 uno::Sequence< beans::PropertyValue > aPropsForDialog;
605 xFilterProperties->setPropertyValues( aPropsForDialog );
613 aDialogClosedListener->SetDialogClosedLink(
LINK(
this,
ModelData_Impl, OptionsDialogClosedHdl ) );
619 if( !xFilterDialog->execute() )
621 throw task::ErrorCodeIOException(
622 (
"ModelData_Impl::ExecuteFilterDialog_Impl:"
623 " ERRCODE_IO_ABORT"),
624 uno::Reference< uno::XInterface >(),
628 const uno::Sequence< beans::PropertyValue > aPropsFromDialog =
629 xFilterProperties->getPropertyValues();
630 for (
const auto& rProp : aPropsFromDialog )
638 catch(
const container::NoSuchElementException& e )
641 throw task::ErrorCodeIOException(
642 (
"ModelData_Impl::ExecuteFilterDialog_Impl: NoSuchElementException"
643 " \"" + e.Message +
"\": ERRCODE_IO_ABORT"),
646 catch(
const task::ErrorCodeIOException& )
650 catch(
const uno::Exception& )
677 if (pEvt->DialogResult ==
RET_OK && m_xFilterProperties)
682 const uno::Sequence< beans::PropertyValue > aPropsFromDialog = m_xFilterProperties->getPropertyValues();
683 for (
const auto& rProp : aPropsFromDialog )
684 GetMediaDescr()[rProp.Name] = rProp.Value;
686 m_pOwner->CallFinishGUIStoreModel();
703 if ( officecfg::Office::Common::Save::Document::AlwaysSaveAs::get()
708 VclMessageType::Question, VclButtonsType::OkCancel,
SfxResId(STR_NEW_FILENAME_SAVE)));
709 if (xMessageBox->run() ==
RET_OK)
729 static constexpr OUStringLiteral aVersionCommentString(
u"VersionComment");
730 static constexpr OUStringLiteral aAuthorString(
u"Author");
731 static constexpr OUStringLiteral aDontTerminateEdit(
u"DontTerminateEdit");
732 static constexpr OUStringLiteral aInteractionHandlerString(
u"InteractionHandler");
733 static constexpr OUStringLiteral aStatusIndicatorString(
u"StatusIndicator");
734 static constexpr OUStringLiteral aFailOnWarningString(
u"FailOnWarning");
735 static constexpr OUStringLiteral aNoFileSync(
u"NoFileSync");
738 aAcceptedArgs[ aVersionCommentString ] =
GetMediaDescr()[ aVersionCommentString ];
740 aAcceptedArgs[ aAuthorString ] =
GetMediaDescr()[ aAuthorString ];
742 aAcceptedArgs[ aDontTerminateEdit ] =
GetMediaDescr()[ aDontTerminateEdit ];
744 aAcceptedArgs[ aInteractionHandlerString ] =
GetMediaDescr()[ aInteractionHandlerString ];
746 aAcceptedArgs[ aStatusIndicatorString ] =
GetMediaDescr()[ aStatusIndicatorString ];
748 aAcceptedArgs[ aFailOnWarningString ] =
GetMediaDescr()[ aFailOnWarningString ];
754 "Unacceptable parameters are provided in Save request!\n" );
766 if ( !aFilterName.isEmpty() )
769 uno::Sequence< beans::PropertyValue > aFilterProps;
785 if ( ( aFiltPropsHM.
empty() || !( nFiltFlags & SfxFilterFlags::EXPORT ) )
786 && ( aDefFiltPropsHM.
empty() || !( nDefFiltFlags & SfxFilterFlags::EXPORT ) || nDefFiltFlags & SfxFilterFlags::INTERNAL ) )
790 if ( aFiltPropsHM.
empty() || !( nFiltFlags & SfxFilterFlags::EXPORT ) )
795 else if ( ( !( nFiltFlags & SfxFilterFlags::OWN ) || ( nFiltFlags & SfxFilterFlags::ALIEN ) )
796 && !aDefFiltPropsHM.
empty()
797 && ( nDefFiltFlags & SfxFilterFlags::EXPORT ) && !( nDefFiltFlags & SfxFilterFlags::INTERNAL ))
804 OUString aSupportedFilters;
805 const ::comphelper::SequenceAsHashMap& rDocumentProperties =
GetDocProps();
806 const css::uno::Sequence<css::beans::NamedValue> aEncryptionData = rDocumentProperties.getUnpackedValueOrDefault(
"EncryptionData", css::uno::Sequence<css::beans::NamedValue>());
807 if (aEncryptionData != css::uno::Sequence<css::beans::NamedValue>())
809 for (
const css::beans::NamedValue& aNamedValue : aEncryptionData)
811 if (aNamedValue.Name ==
"SupportedFilters")
813 aNamedValue.Value >>= aSupportedFilters;
819 if (!aSupportedFilters.isEmpty())
823 aSupportedFilters =
";" + aSupportedFilters +
";";
824 const OUString aSearchToken =
";" + aSelectedFilter +
";";
825 bAsk = (aSupportedFilters.indexOf(aSearchToken) < 0);
839 if ( aPreusedFilterName != aFilterName &&
aUIName != aDefUIName )
842 static_cast<bool>( nDefFiltFlags & SfxFilterFlags::ALIEN ) ) )
853 uno::Sequence< beans::NamedValue > aSearchRequest { {
"DocumentService", css::uno::Any(
GetDocServiceName()) } };
855 uno::Reference< container::XEnumeration > xFilterEnum =
858 while ( xFilterEnum->hasMoreElements() )
860 uno::Sequence< beans::PropertyValue > aProps;
861 if ( xFilterEnum->nextElement() >>= aProps )
874 const ::comphelper::SequenceAsHashMap& aPreselectedFilterPropsHM,
875 bool bSetStandardName,
876 OUString& aSuggestedName,
877 bool bPreselectPassword,
878 OUString& aSuggestedDir,
880 const OUString& rStandardDir,
881 const css::uno::Sequence< OUString >& rDenyList)
886 bool bUseFilterOptions =
false;
893 throw task::ErrorCodeIOException(
894 "ModelData_Impl::OutputFileDialog: ERRCODE_IO_INVALIDPARAMETER",
895 uno::Reference< uno::XInterface >(),
902 bool bAllowOptions =
false;
910 sal_Int16 aDialogMode = bAllowOptions
911 ? css::ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION_PASSWORD_FILTEROPTIONS
912 : css::ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION_PASSWORD;
918 aDialogMode = css::ui::dialogs::TemplateDescription::
919 FILESAVE_AUTOEXTENSION;
921 aDialogMode = css::ui::dialogs::TemplateDescription::
922 FILESAVE_AUTOEXTENSION_SELECTION;
931 std::unique_ptr<sfx2::FileDialogHelper> pFileDlg;
934 DBG_ASSERT( !aDocServiceName.isEmpty(),
"No document service for this module set!" );
945 const OUString aFilterUIName = aPreselectedFilterPropsHM.getUnpackedValueOrDefault(
"UIName", OUString() );
946 pFileDlg.reset(
new sfx2::FileDialogHelper( aDialogMode, aDialogFlags, aFilterUIName,
u"pdf", rStandardDir, rDenyList, pFrameWin ));
947 pFileDlg->SetCurrentFilter( aFilterUIName );
952 const OUString aFilterUIName = aPreselectedFilterPropsHM.getUnpackedValueOrDefault(
"UIName", OUString() );
953 pFileDlg.reset(
new sfx2::FileDialogHelper(aDialogMode, aDialogFlags, aFilterUIName,
u"epub", rStandardDir, rDenyList, pFrameWin));
954 pFileDlg->SetCurrentFilter(aFilterUIName);
959 pFileDlg.reset(
new sfx2::FileDialogHelper( aDialogMode, aDialogFlags, aDocServiceName, nDialog, nMust, nDont, rStandardDir, rDenyList, pFrameWin ));
963 if ( aDocServiceName ==
"com.sun.star.drawing.DrawingDocument" )
965 else if ( aDocServiceName ==
"com.sun.star.presentation.PresentationDocument" )
967 else if ( aDocServiceName ==
"com.sun.star.text.TextDocument" )
969 else if ( aDocServiceName ==
"com.sun.star.sheet.SpreadsheetDocument" )
973 pFileDlg->SetContext( eCtxt );
975 pFileDlg->CreateMatcher( aDocServiceName );
977 uno::Reference< ui::dialogs::XFilePicker3 > xFilePicker = pFileDlg->GetFilePicker();
978 uno::Reference< ui::dialogs::XFilePickerControlAccess > xControlAccess( xFilePicker, uno::UNO_QUERY );
980 if ( xControlAccess.is() )
982 xControlAccess->setLabel( ui::dialogs::CommonFilePickerElementIds::PUSHBUTTON_OK,
SfxResId(STR_EXPORTBUTTON) );
983 xControlAccess->setLabel( ui::dialogs::CommonFilePickerElementIds::LISTBOX_FILTER_LABEL,
SfxResId(STR_LABEL_FILEFORMAT) );
990 nMust, nDont, rStandardDir, rDenyList, pFrameWin ));
991 pFileDlg->CreateMatcher( aDocServiceName );
994 if ( aDocServiceName ==
"com.sun.star.drawing.DrawingDocument" )
996 else if ( aDocServiceName ==
"com.sun.star.presentation.PresentationDocument" )
998 else if ( aDocServiceName ==
"com.sun.star.text.TextDocument" )
1000 else if ( aDocServiceName ==
"com.sun.star.sheet.SpreadsheetDocument" )
1004 pFileDlg->SetContext( eCtxt );
1007 OUString aAdjustToType;
1014 pFileDlg->SetCurrentFilter( aPreselectedFilterPropsHM.getUnpackedValueOrDefault(
"UIName", OUString() ) );
1015 aAdjustToType = aPreselectedFilterPropsHM.getUnpackedValueOrDefault(
"Type", OUString() );
1018 else if ( bSetStandardName ||
GetStorable()->hasLocation() )
1020 uno::Sequence< beans::PropertyValue > aOldFilterProps;
1023 if ( !aOldFilterName.isEmpty() )
1029 if ( bSetStandardName || ( nOldFiltFlags & nMust ) != nMust || bool(nOldFiltFlags & nDont) )
1032 aAdjustToType = aPreselectedFilterPropsHM.getUnpackedValueOrDefault(
"Type", OUString() );
1033 pFileDlg->SetCurrentFilter( aPreselectedFilterPropsHM.getUnpackedValueOrDefault(
"UIName", OUString() ) );
1044 if ( !aRecommendedDir.isEmpty() )
1045 pFileDlg->SetDisplayFolder( aRecommendedDir );
1046 const OUString aRecommendedName {
GetRecommendedName( aSuggestedName, aAdjustToType )};
1047 if ( !aRecommendedName.isEmpty() )
1048 pFileDlg->SetFileName( aRecommendedName );
1050 uno::Reference < view::XSelectionSupplier > xSel(
GetModel()->getCurrentController(), uno::UNO_QUERY );
1051 if ( xSel.is() && xSel->getSelection().hasValue() )
1056 sal_uInt16 nSlotID = getSlotIDFromMode( nStoreMode );
1058 throw lang::IllegalArgumentException();
1062 std::optional<SfxAllItemSet> pDialogParams(
SfxGetpApp()->GetPool() );
1067 if ( bPreselectPassword && !pDialogParams->HasItem( SID_ENCRYPTIONDATA ) )
1071 pDialogParams->Put(
SfxBoolItem( SID_PASSWORDINTERACTION,
true ) );
1075 OUString aFilterName;
1077 if ( pFileDlg->Execute( pDialogParams, aFilterName ) !=
ERRCODE_NONE
1080 throw task::ErrorCodeIOException(
1081 "ModelData_Impl::OutputFileDialog: ERRCODE_IO_ABORT",
1086 aFilterName = aPreselectedFilterPropsHM.getUnpackedValueOrDefault(
"Name", OUString() );
1091 const SfxBoolItem* pRecommendReadOnly = SfxItemSet::GetItem<SfxBoolItem>(&*pDialogParams, SID_RECOMMENDREADONLY,
false);
1093 pDialogParams->ClearItem( SID_RECOMMENDREADONLY );
1095 uno::Sequence< beans::PropertyValue > aPropsFromDialog;
1105 aSuggestedName = aRecommendedName;
1106 OUString aExtension;
1107 if (
size_t nPos = aSuggestedName.lastIndexOf(
'.') + 1)
1108 aExtension = aSuggestedName.copy(
nPos, aSuggestedName.getLength() -
nPos);
1109 aURL.SetExtension(aExtension);
1116 aSuggestedDir = pFileDlg->GetDisplayDirectory();
1123 if ( aFilterName == aFilterFromMediaDescr )
1129 if ( aFilterFromMediaDescr == aOldFilterName )
1148 if ( aFilterName == aOldFilterName )
1163 uno::Reference< ui::dialogs::XFilePickerControlAccess > xExtFileDlg( pFileDlg->GetFilePicker(), uno::UNO_QUERY );
1164 if ( xExtFileDlg.is() )
1167 bUseFilterOptions =
true;
1176 xExtFileDlg->getValue( ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_FILTEROPTIONS, 0 );
1178 aVal >>= bUseFilterOptions;
1179 if ( !bUseFilterOptions )
1184 catch(
const lang::IllegalArgumentException& )
1193 return bUseFilterOptions;
1199 bool bDialogUsed =
false;
1205 uno::Reference< frame::XDispatchProvider > xFrameDispatch(
xController->getFrame(), uno::UNO_QUERY );
1206 if ( xFrameDispatch.is() )
1209 aURL.Complete =
".uno:SetDocumentProperties";
1212 if ( xTransformer->parseStrict(
aURL ) )
1214 uno::Reference< frame::XDispatch >
xDispatch = xFrameDispatch->queryDispatch(
1224 uno::Sequence< beans::PropertyValue >
aProperties{
1234 catch (
const uno::Exception& )
1244 if ( aTypeName.isEmpty() )
1247 uno::Reference< container::XNameAccess > xTypeDetection(
1250 if ( xTypeDetection.is() )
1252 uno::Sequence< beans::PropertyValue > aTypeNameProps;
1253 if ( ( xTypeDetection->getByName( aTypeName ) >>= aTypeNameProps ) && aTypeNameProps.hasElements() )
1258 ::uno::Sequence< OUString >() );
1259 if ( aExtensions.hasElements() )
1260 return aExtensions[0];
1270 if ( ( !aSuggestedDir.isEmpty() ||
GetStorable()->hasLocation() )
1271 && !
GetMediaDescr().getUnpackedValueOrDefault(
"RepairPackage",
false ) )
1274 if ( !aSuggestedDir.isEmpty() )
1278 const OUString aOldURL =
GetStorable()->getLocation();
1279 if ( !aOldURL.isEmpty() )
1291 bool bIsInTempPath(
false );
1292 OUString sSysTempPath;
1293 if( osl::FileBase::getTempDirURL( sSysTempPath ) == osl::FileBase::E_None )
1294 bIsInTempPath = !sSysTempPath.isEmpty() && sLocationURL.startsWith( sSysTempPath );
1296 if( !bIsInTempPath )
1299 HRESULT hRes = SHGetFolderPathW(
nullptr, CSIDL_INTERNET_CACHE,
nullptr, SHGFP_TYPE_CURRENT, sPath );
1300 if( SUCCEEDED(hRes) )
1302 OUString sTempINetFiles;
1303 if( osl::FileBase::getFileURLFromSystemPath(OUString(o3tl::toU(sPath)), sTempINetFiles) == osl::FileBase::E_None )
1304 bIsInTempPath = !sTempINetFiles.isEmpty() && sLocationURL.startsWith( sTempINetFiles );
1326 if ( !aSuggestedName.isEmpty() )
1327 return aSuggestedName;
1331 if ( aRecommendedName.isEmpty() )
1334 uno::Reference< frame::XTitle > xTitle(
GetModel(), uno::UNO_QUERY_THROW );
1335 aRecommendedName = xTitle->getTitle();
1336 }
catch(
const uno::Exception& ) {}
1339 if ( !aRecommendedName.isEmpty() && !aTypeName.isEmpty() )
1342 uno::Reference< container::XNameAccess > xTypeDetection(
1345 if ( xTypeDetection.is() )
1347 INetURLObject aObj( rtl::Concat2View(
"c:/" + aRecommendedName), INetProtocol::File,
1351 if ( !aExtension.isEmpty() )
1358 return aRecommendedName;
1363 , m_bPreselectPassword(false)
1364 , m_bDialogUsed(false)
1365 , m_bSetStandardName(false)
1375 uno::UNO_QUERY_THROW );
1403 std::u16string_view aSlotName,
1404 uno::Sequence< beans::PropertyValue >& aArgsSequence,
1405 bool bPreselectPassword,
1434 bool bSaveACopy =
false;
1435 aSaveACopyIter->second >>= bSaveACopy;
1446 bool bWideExport =
false;
1447 aSaveToIter->second >>= bWideExport;
1454 throw task::ErrorCodeIOException(
1455 "SfxStoringHelper::GUIStoreModel: ERRCODE_IO_ABORT",
1464 throw task::ErrorCodeIOException(
1465 "SfxStoringHelper::GUIStoreModel: ERRCODE_IO_ABORT",
1475 throw task::ErrorCodeIOException(
1476 "SfxStoringHelper::GUIStoreModel: ERRCODE_IO_ABORT",
1500 VclMessageType::Question, VclButtonsType::YesNo,
SfxResId(RID_SVXSTR_XMLSEC_QUERY_LOSINGSIGNATURE)));
1501 if (xMessageBox->run() !=
RET_YES)
1504 throw task::ErrorCodeIOException(
1505 "SfxStoringHelper::GUIStoreModel: ERRCODE_IO_ABORT (Preserve Signature)",
1522 catch (
const lang::IllegalArgumentException&)
1530 OSL_FAIL(
"XStorable2 is not supported by the model!" );
1540 DBG_ASSERT( aFilterProps.hasElements(),
"No filter for storing!\n" );
1541 if ( !aFilterProps.hasElements() )
1542 throw task::ErrorCodeIOException(
1543 "SfxStoringHelper::GUIStoreModel: ERRCODE_IO_INVALIDPARAMETER",
1575 aFilterFromMediaDescr, aOldFilterName, aArgsSequence, aFilterName);
1580 uno::Sequence< beans::PropertyValue >& aFilterProps,
1581 bool bSetStandardName,
bool bPreselectPassword,
bool bDialogUsed,
1582 std::u16string_view aFilterFromMediaDescr,
1583 std::u16string_view aOldFilterName,
1584 uno::Sequence< beans::PropertyValue >& aArgsSequence,
1585 OUString aFilterName)
1590 bool bUseFilterOptions =
false;
1607 bool bUseSystemDialog =
true;
1608 if ( aDlgIter->second >>= bUseSystemDialog )
1610 if ( bUseSystemDialog )
1620 if ( aSuggestedDir.isEmpty() )
1623 if ( aSuggestedDir.isEmpty() )
1628 if ( aSuggestedName.isEmpty() )
1637 css::uno::Sequence< OUString > aDenyList;
1642 aDenyListIter->second >>= aDenyList;
1647 bUseFilterOptions = aModelData.
OutputFileDialog( nStoreMode, aFilterProps, bSetStandardName, aSuggestedName, bPreselectPassword, aSuggestedDir, nDialog,
sStandardDir, aDenyList );
1656 bSetStandardName =
true;
1675 if ( aFilterFromMediaDescr == aOldFilterName )
1693 aFileNameIter->second >>= aFileName;
1694 aURL.SetURL( aFileName );
1695 DBG_ASSERT(
aURL.GetProtocol() != INetProtocol::NotValid,
"Illegal URL!" );
1701 aIter->second >>= aFilterName;
1703 aModelData.
GetMediaDescr()[sFilterNameString] <<= aFilterName;
1705 DBG_ASSERT( !aFilterName.isEmpty(),
"Illegal filter!" );
1709 SAL_WARN(
"sfx.doc",
"This code must be unreachable!" );
1710 throw task::ErrorCodeIOException(
1711 "SfxStoringHelper::GUIStoreModel: ERRCODE_IO_INVALIDPARAMETER",
1728 if (aFilterName.endsWith(
"pdf_Export"))
1745 bool bResetESM =
false;
1747 if (bWasEnableSetModified
1748 && !officecfg::Office::Common::Print::PrintingModifiesDocument::get())
1754 uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
1755 aModelData.
GetModel(), uno::UNO_QUERY_THROW);
1756 uno::Reference<document::XDocumentProperties> xDocProps(xDPS->getDocumentProperties());
1759 OUString sPrintedBy(
SfxResId(STR_SFX_FILTERNAME_PDF));
1763 if (!sFullName.isEmpty())
1764 sPrintedBy +=
": " + sFullName;
1766 xDocProps->setPrintedBy(sPrintedBy);
1772 OSL_ENSURE( aModelData.
GetMediaDescr().
find( OUString(
"Password" ) ) == aModelData.
GetMediaDescr().
end(),
"The Password property of MediaDescriptor should not be used here!" );
1773 if ( officecfg::Office::Common::Save::Document::EditProperty::get()
1781 uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
1782 aModelData.
GetModel(), uno::UNO_QUERY_THROW);
1783 uno::Reference<util::XCloneable> xCloneable(
1784 xDPS->getDocumentProperties(), uno::UNO_QUERY_THROW);
1785 uno::Reference<document::XDocumentProperties> xOldDocProps(
1786 xCloneable->createClone(), uno::UNO_QUERY_THROW);
1793 OSL_FAIL(
"Can't execute document info dialog!" );
1804 catch(
const uno::Exception& )
1835 bool aViewPDF = aItem.
ReadBool(
"ViewPDFAfterExport",
false );
1839 uno::Reference<XSystemShellExecute> xSystemShellExecute(SystemShellExecute::create( ::comphelper::getProcessComponentContext() ) );
1849 pShell->libreOfficeKitViewCallback( LOK_CALLBACK_EXPORT_FILE, sURL.toUtf8() );
1859 const uno::Reference< container::XNameAccess >& xFilterCFG,
1860 const OUString& aFilterName )
1862 bool bUseFilterOptions =
false;
1864 DBG_ASSERT( xFilterCFG.is(),
"No filter configuration!\n" );
1865 if( xFilterCFG.is() )
1868 uno::Sequence < beans::PropertyValue > aProps;
1869 uno::Any aAny = xFilterCFG->getByName( aFilterName );
1870 if ( aAny >>= aProps )
1874 bUseFilterOptions =
true;
1877 catch(
const uno::Exception& )
1882 return bUseFilterOptions;
1888 const uno::Reference< frame::XModel >& xModel,
1889 const uno::Reference< document::XDocumentProperties>& i_xOldDocProps )
1891 uno::Reference<document::XDocumentPropertiesSupplier>
const
1892 xModelDocPropsSupplier(
xModel, uno::UNO_QUERY_THROW);
1893 uno::Reference<document::XDocumentProperties>
const xDocPropsToFill =
1894 xModelDocPropsSupplier->getDocumentProperties();
1895 uno::Reference< beans::XPropertySet >
const xPropSet(
1896 i_xOldDocProps->getUserDefinedProperties(), uno::UNO_QUERY_THROW);
1898 uno::Reference< util::XModifiable > xModifiable(
xModel, uno::UNO_QUERY );
1899 if ( !xModifiable.is() )
1900 throw uno::RuntimeException();
1902 bool bIsModified = xModifiable->isModified();
1906 uno::Reference< beans::XPropertySet >
const xSet(
1907 xDocPropsToFill->getUserDefinedProperties(), uno::UNO_QUERY);
1908 uno::Reference< beans::XPropertyContainer > xContainer( xSet, uno::UNO_QUERY );
1909 uno::Reference< beans::XPropertySetInfo > xSetInfo = xSet->getPropertySetInfo();
1910 const uno::Sequence< beans::Property > lProps = xSetInfo->getProperties();
1911 for (
const beans::Property& rProp : lProps)
1913 uno::Any aValue = xPropSet->getPropertyValue( rProp.Name );
1914 if ( rProp.Attributes & css::beans::PropertyAttribute::REMOVABLE )
1919 xContainer->addProperty( rProp.Name, rProp.Attributes, aValue );
1921 catch (beans::PropertyExistException
const&) {}
1925 xSet->setPropertyValue( rProp.Name, aValue );
1927 catch (
const uno::Exception& ) {}
1933 xDocPropsToFill->setAuthor(i_xOldDocProps->getAuthor());
1934 xDocPropsToFill->setGenerator(i_xOldDocProps->getGenerator());
1935 xDocPropsToFill->setCreationDate(i_xOldDocProps->getCreationDate());
1936 xDocPropsToFill->setTitle(i_xOldDocProps->getTitle());
1937 xDocPropsToFill->setSubject(i_xOldDocProps->getSubject());
1938 xDocPropsToFill->setDescription(i_xOldDocProps->getDescription());
1939 xDocPropsToFill->setKeywords(i_xOldDocProps->getKeywords());
1940 xDocPropsToFill->setModifiedBy(i_xOldDocProps->getModifiedBy());
1941 xDocPropsToFill->setModificationDate(i_xOldDocProps->getModificationDate());
1942 xDocPropsToFill->setPrintedBy(i_xOldDocProps->getPrintedBy());
1943 xDocPropsToFill->setPrintDate(i_xOldDocProps->getPrintDate());
1944 xDocPropsToFill->setAutoloadURL(i_xOldDocProps->getAutoloadURL());
1945 xDocPropsToFill->setAutoloadSecs(i_xOldDocProps->getAutoloadSecs());
1946 xDocPropsToFill->setDefaultTarget(i_xOldDocProps->getDefaultTarget());
1947 xDocPropsToFill->setEditingCycles(i_xOldDocProps->getEditingCycles());
1948 xDocPropsToFill->setEditingDuration(i_xOldDocProps->getEditingDuration());
1951 catch (
const uno::Exception&)
1957 if ( bIsModified !=
bool(xModifiable->isModified()) )
1958 xModifiable->setModified( bIsModified );
1964 std::u16string_view aOldUIName,
1965 const OUString& aDefExtension,
1968 if ( !officecfg::Office::Common::Save::Document::WarnAlienFormat::get() )
1982 uno::Reference< frame::XController >
xController =
xModel->getCurrentController();
1988 return xFrame->getContainerWindow();
1993 catch (
const uno::Exception& )
1997 return uno::Reference<awt::XWindow>();
2008 catch (
const uno::Exception&)
PropertiesInfo aProperties
HRESULT createInstance(REFIID iid, Ifc **ppIfc)
SfxApplication * SfxGetpApp()
void TransformItems(sal_uInt16 nSlotId, const SfxItemSet &rSet, uno::Sequence< beans::PropertyValue > &rArgs, const SfxSlot *pSlot)
void TransformParameters(sal_uInt16 nSlotId, const uno::Sequence< beans::PropertyValue > &rArgs, SfxAllItemSet &rSet, const SfxSlot *pSlot)
constexpr OUStringLiteral sStandardDir
static weld::Window * GetFrameWeld(const css::uno::Reference< css::awt::XWindow > &rWindow)
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, const ILibreOfficeKitNotifier *pNotifier=nullptr)
bool ReadBool(const OUString &rKey, bool bDefault)
void SetExtension(std::u16string_view rTheExtension)
OUString GetMainURL(DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
bool removeSegment(sal_Int32 nIndex=LAST_SEGMENT, bool bIgnoreFinalSlash=true)
OUString GetLastName(DecodeMechanism eMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
uno::Reference< frame::XModel > const & GetModel() const
uno::Sequence< beans::PropertyValue > GetDocServiceDefaultFilterCheckFlags(SfxFilterFlags nMust, SfxFilterFlags nDont)
const ::comphelper::SequenceAsHashMap & GetModuleProps()
uno::Sequence< beans::PropertyValue > GetDocServiceDefaultFilter()
uno::Reference< frame::XStorable > m_xStorable
bool m_bRecommendReadOnly
uno::Reference< beans::XPropertyAccess > m_xFilterProperties
bool IsRecommendReadOnly() const
uno::Sequence< beans::PropertyValue > GetDocServiceAnyFilter(SfxFilterFlags nMust, SfxFilterFlags nDont)
const ::comphelper::SequenceAsHashMap & GetDocProps()
bool CheckFilterOptionsDialogExistence()
sal_Int8 CheckFilter(const OUString &)
static OUString GetRecommendedExtension(const OUString &aTypeName)
OUString GetRecommendedDir(const OUString &aSuggestedDir)
DECL_LINK(OptionsDialogClosedHdl, css::ui::dialogs::DialogClosedEvent *, void)
sal_Int8 CheckStateForSave()
ModelData_Impl(SfxStoringHelper &aOwner, uno::Reference< frame::XModel > xModel, const uno::Sequence< beans::PropertyValue > &aMediaDescr)
bool OutputFileDialog(sal_Int16 nStoreMode, const ::comphelper::SequenceAsHashMap &aPreselectedFilterPropsHM, bool bSetStandardName, OUString &aSuggestedName, bool bPreselectPassword, OUString &aSuggestedDir, sal_Int16 nDialog, const OUString &rStandardDir, const css::uno::Sequence< OUString > &rDenyList)
uno::Reference< ui::dialogs::XAsynchronousExecutableDialog > m_xFilterDialog
OUString GetDocServiceName()
void CheckInteractionHandler()
uno::Reference< frame::XStorable > const & GetStorable()
OUString GetRecommendedName(const OUString &aSuggestedName, const OUString &aTypeName)
uno::Reference< frame::XStorable2 > const & GetStorable2()
::comphelper::SequenceAsHashMap m_aMediaDescrHM
std::unique_ptr<::comphelper::SequenceAsHashMap > m_pDocumentPropsHM
sal_Int8 CheckSaveAcceptable(sal_Int8 nCurStatus)
OUString const & GetModuleName()
bool ExecuteFilterDialog_Impl(const OUString &aFilterName, bool bAsync)
std::unique_ptr<::comphelper::SequenceAsHashMap > m_pModulePropsHM
SfxStoringHelper * m_pOwner
::comphelper::SequenceAsHashMap & GetMediaDescr()
bool ShowDocumentInfoDialog()
uno::Sequence< beans::PropertyValue > GetPreselectedFilter_Impl(sal_Int16 nStoreMode)
uno::Reference< frame::XStorable2 > m_xStorable2
uno::Reference< frame::XModel > m_xModel
bool IsEnableSetModified() const
bool IsUseUserData() const
void EnableSetModified(bool bEnable=true)
bool IsRememberingSignature() const
static css::uno::Reference< css::awt::XWindow > GetModelXWindow(const css::uno::Reference< css::frame::XModel > &rModel)
css::uno::Reference< css::container::XContainerQuery > const & GetFilterQuery()
css::uno::Reference< css::container::XNameAccess > const & GetFilterConfiguration()
css::uno::Reference< css::container::XNameAccess > m_xFilterCFG
bool GUIStoreModel(const css::uno::Reference< css::frame::XModel > &xModel, std::u16string_view aSlotName, css::uno::Sequence< css::beans::PropertyValue > &aArgsSequence, bool bPreselectPassword, SignatureState nDocumentSignatureState, bool bIsAsync)
static bool WarnUnacceptableFormat(const css::uno::Reference< css::frame::XModel > &xModel, std::u16string_view aOldUIName, const OUString &aDefExtension, bool rDefaultIsAlien)
static weld::Window * GetModelWindow(const css::uno::Reference< css::frame::XModel > &xModel)
static bool CheckFilterOptionsAppearance(const css::uno::Reference< css::container::XNameAccess > &xFilterCFG, const OUString &aFilterName)
static void SetDocInfoState(const css::uno::Reference< css::frame::XModel > &xModel, const css::uno::Reference< css::document::XDocumentProperties > &i_xOldDocInfo)
css::uno::Reference< css::container::XContainerQuery > m_xFilterQuery
bool m_bPreselectPassword
css::uno::Reference< css::frame::XModuleManager2 > const & GetModuleManager()
void CallFinishGUIStoreModel()
css::uno::Reference< css::frame::XModuleManager2 > m_xModuleManager
static bool FinishGUIStoreModel(::comphelper::SequenceAsHashMap::const_iterator &aFileNameIter, ModelData_Impl &aModelData, bool bRemote, sal_Int16 nStoreMode, css::uno::Sequence< css::beans::PropertyValue > &aFilterProps, bool bSetStandardName, bool bPreselectPassword, bool bDialogUsed, std::u16string_view aFilterFromMediaDescr, std::u16string_view aOldFilterName, css::uno::Sequence< css::beans::PropertyValue > &aArgsSequence, OUString aFilterName)
css::uno::Sequence< css::beans::PropertyValue > m_aArgsSequence
std::shared_ptr< ModelData_Impl > m_xModelData
One SfxViewShell more or less represents one edit window for a document, there can be multiple ones f...
virtual void libreOfficeKitViewCallback(int nType, const OString &pPayload) const override
Invokes the registered callback, if there are any.
void SetStoringHelper(std::shared_ptr< SfxStoringHelper > xHelper)
virtual SfxObjectShell * GetObjectShell() override
static SAL_WARN_UNUSED_RESULT SfxViewShell * Current()
static css::uno::Sequence< css::beans::PropertyValue > SearchForFilter(const css::uno::Reference< css::container::XContainerQuery > &xFilterQuery, const css::uno::Sequence< css::beans::NamedValue > &aSearchRequest, SfxFilterFlags nMustFlags, SfxFilterFlags nDontFlags)
iterator erase(iterator it)
TValueType getUnpackedValueOrDefault(const OUString &sKey, const TValueType &aDefault) const
iterator find(const OUString &rKey)
css::uno::Sequence< css::beans::PropertyValue > getAsConstPropertyValueList() const
SequenceAsHashMapBase::const_iterator const_iterator
#define DBG_ASSERT(sCon, aError)
#define TOOLS_WARN_EXCEPTION(area, stream)
#define TOOLS_INFO_EXCEPTION(area, stream)
Reference< XDispatch > xDispatch
Reference< frame::XModel > m_xModel
#define ERRCODE_IO_INVALIDPARAMETER
#define SFX2_IMPL_DIALOG_CONFIG
#define SFX2_IMPL_DIALOG_SYSTEM
#define SFX2_IMPL_DIALOG_OOO
#define SFX2_IMPL_DIALOG_REMOTE
#define EPUBEXPORT_REQUESTED
IMPL_LINK(ModelData_Impl, OptionsDialogClosedHdl, css::ui::dialogs::DialogClosedEvent *, pEvt, void)
#define EPUBDIRECTEXPORT_REQUESTED
constexpr OUStringLiteral aFilterDataString
#define WIDEEXPORT_REQUESTED
#define STATUS_SAVEAS_STANDARDNAME
#define PDFDIRECTEXPORT_REQUESTED
#define SAVEASREMOTE_REQUESTED
constexpr OUStringLiteral aFilterOptionsString
#define SAVEACOPY_REQUESTED
#define PDFEXPORT_REQUESTED
constexpr OUStringLiteral aFilterNameString
#define LINK(Instance, Class, Member)
#define SAL_WARN(area, stream)
css::uno::Sequence< css::uno::Any > InitAnyPropertySequence(::std::initializer_list< ::std::pair< OUString, css::uno::Any > > vInit)
Reference< XMultiServiceFactory > getProcessServiceFactory()
Reference< XComponentContext > getProcessComponentContext()
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
OSQLColumns::const_iterator find(const OSQLColumns::const_iterator &first, const OSQLColumns::const_iterator &last, std::u16string_view _rVal, const ::comphelper::UStringMixEqual &_rCase)
ContentProvider * m_pOwner
OUString SfxResId(TranslateId aId)
Reference< XController > xController
Reference< XFrame > xFrame
Reference< XModel > xModel