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