diff options
Diffstat (limited to 'sfx2/source/dialog/filedlghelper.cxx')
-rw-r--r-- | sfx2/source/dialog/filedlghelper.cxx | 101 |
1 files changed, 64 insertions, 37 deletions
diff --git a/sfx2/source/dialog/filedlghelper.cxx b/sfx2/source/dialog/filedlghelper.cxx index 7d177d0bbfd8..b0890a3ee781 100644 --- a/sfx2/source/dialog/filedlghelper.cxx +++ b/sfx2/source/dialog/filedlghelper.cxx @@ -81,11 +81,13 @@ #include <svtools/helpid.hrc> #include <svl/pickerhelper.hxx> #include <comphelper/docpasswordrequest.hxx> +#include <comphelper/docpasswordhelper.hxx> #include <ucbhelper/content.hxx> #include <ucbhelper/commandenvironment.hxx> #include <comphelper/storagehelper.hxx> #include <toolkit/helper/vclunohelper.hxx> #include <sfx2/app.hxx> +#include <sfx2/frame.hxx> #include <sfx2/docfile.hxx> #include <sfx2/docfac.hxx> #include "openflag.hxx" @@ -465,31 +467,6 @@ sal_Bool FileDialogHelper_Impl::isInOpenMode() const // ------------------------------------------------------------------------ -namespace { - -bool lclCheckODFPasswordCapability( const SfxFilter* pFilter ) -{ - return pFilter && pFilter->IsOwnFormat() && pFilter->UsesStorage() && (pFilter->GetVersion() >= SOFFICE_FILEFORMAT_60); -} - -bool lclCheckMSPasswordCapability( const SfxFilter* pFilter ) -{ - // TODO #i105076# this should be in the filter configuration!!! - return pFilter && CheckMSPasswordCapabilityForExport( pFilter->GetFilterName() ); -} - -bool lclCheckPasswordCapability( const SfxFilter* pFilter ) -{ - return - lclCheckODFPasswordCapability( pFilter ) || - // TODO #i105076# this should be in the filter configuration!!! - lclCheckMSPasswordCapability( pFilter ); -} - -} - -// ------------------------------------------------------------------------ - void FileDialogHelper_Impl::updateFilterOptionsBox() { if ( !m_bHaveFilterOptions ) @@ -546,10 +523,30 @@ void FileDialogHelper_Impl::updateSelectionBox() if ( !mbHasSelectionBox ) return; - const SfxFilter* pFilter = getCurentSfxFilter(); - mbSelectionFltrEnabled = updateExtendedControl( - ExtendedFilePickerElementIds::CHECKBOX_SELECTION, - ( mbSelectionEnabled && pFilter && ( pFilter->GetFilterFlags() & SFX_FILTER_SUPPORTSSELECTION ) != 0 ) ); + // Does the selection box exist? + sal_Bool bSelectionBoxFound = sal_False; + uno::Reference< XControlInformation > xCtrlInfo( mxFileDlg, UNO_QUERY ); + if ( xCtrlInfo.is() ) + { + Sequence< ::rtl::OUString > aCtrlList = xCtrlInfo->getSupportedControls(); + sal_uInt32 nCount = aCtrlList.getLength(); + for ( sal_uInt32 nCtrl = 0; nCtrl < nCount; ++nCtrl ) + if ( aCtrlList[ nCtrl ].equalsAscii("SelectionBox") ) + { + bSelectionBoxFound = sal_False; + break; + } + } + + if ( bSelectionBoxFound ) + { + const SfxFilter* pFilter = getCurentSfxFilter(); + mbSelectionFltrEnabled = updateExtendedControl( + ExtendedFilePickerElementIds::CHECKBOX_SELECTION, + ( mbSelectionEnabled && pFilter && ( pFilter->GetFilterFlags() & SFX_FILTER_SUPPORTSSELECTION ) != 0 ) ); + uno::Reference< XFilePickerControlAccess > xCtrlAccess( mxFileDlg, UNO_QUERY ); + xCtrlAccess->setValue( ExtendedFilePickerElementIds::CHECKBOX_SELECTION, 0, makeAny( (sal_Bool)mbSelection ) ); + } } // ------------------------------------------------------------------------ @@ -560,9 +557,10 @@ void FileDialogHelper_Impl::enablePasswordBox( sal_Bool bInit ) sal_Bool bWasEnabled = mbIsPwdEnabled; + const SfxFilter* pCurrentFilter = getCurentSfxFilter(); mbIsPwdEnabled = updateExtendedControl( ExtendedFilePickerElementIds::CHECKBOX_PASSWORD, - lclCheckPasswordCapability( getCurentSfxFilter() ) + pCurrentFilter && ( pCurrentFilter->GetFilterFlags() & SFX_FILTER_ENCRYPTION ) ); if( bInit ) @@ -1534,6 +1532,10 @@ ErrCode FileDialogHelper_Impl::execute( SvStringsDtor*& rpURLList, { SFX_ITEMSET_ARG( rpSet, pPassItem, SfxStringItem, SID_PASSWORD, FALSE ); mbPwdCheckBoxState = ( pPassItem != NULL ); + + // in case the document has password to modify, the dialog should be shown + SFX_ITEMSET_ARG( rpSet, pPassToModifyItem, SfxUnoAnyItem, SID_MODIFYPASSWORDINFO, FALSE ); + mbPwdCheckBoxState |= ( pPassToModifyItem && pPassToModifyItem->GetValue().hasValue() ); } SFX_ITEMSET_ARG( rpSet, pSelectItem, SfxBoolItem, SID_SELECTION, FALSE ); @@ -1544,6 +1546,9 @@ ErrCode FileDialogHelper_Impl::execute( SvStringsDtor*& rpURLList, // the password will be set in case user decide so rpSet->ClearItem( SID_PASSWORD ); + rpSet->ClearItem( SID_RECOMMENDREADONLY ); + rpSet->ClearItem( SID_MODIFYPASSWORDINFO ); + } if ( mbHasPassword && !mbPwdCheckBoxState ) @@ -1620,13 +1625,15 @@ ErrCode FileDialogHelper_Impl::execute( SvStringsDtor*& rpURLList, // set the filter getRealFilter( rFilter ); + const SfxFilter* pCurrentFilter = getCurentSfxFilter(); + // fill the rpURLList - implGetAndCacheFiles(mxFileDlg, rpURLList, getCurentSfxFilter()); + implGetAndCacheFiles( mxFileDlg, rpURLList, pCurrentFilter ); if ( rpURLList == NULL || rpURLList->GetObject(0) == NULL ) return ERRCODE_ABORT; // check, wether or not we have to display a password box - if ( mbHasPassword && mbIsPwdEnabled && xCtrlAccess.is() ) + if ( pCurrentFilter && mbHasPassword && mbIsPwdEnabled && xCtrlAccess.is() ) { try { @@ -1640,18 +1647,38 @@ ErrCode FileDialogHelper_Impl::execute( SvStringsDtor*& rpURLList, if( xInteractionHandler.is() ) { // TODO: need a save way to distinguish MS filters from other filters - bool bMSType = CheckMSPasswordCapabilityForExport( rFilter ); + // for now MS-filters are the only alien filters that support encryption + sal_Bool bMSType = !pCurrentFilter->IsOwnFormat(); ::comphelper::DocPasswordRequestType eType = bMSType ? ::comphelper::DocPasswordRequestType_MS : ::comphelper::DocPasswordRequestType_STANDARD; - ::comphelper::DocPasswordRequest* pPasswordRequest = new ::comphelper::DocPasswordRequest( - eType, ::com::sun::star::task::PasswordRequestMode_PASSWORD_CREATE, *(rpURLList->GetObject(0)) ); + ::rtl::Reference< ::comphelper::DocPasswordRequest > pPasswordRequest( new ::comphelper::DocPasswordRequest( eType, ::com::sun::star::task::PasswordRequestMode_PASSWORD_CREATE, *(rpURLList->GetObject(0)), ( pCurrentFilter->GetFilterFlags() & SFX_FILTER_PASSWORDTOMODIFY ) != 0 ) ); - uno::Reference< com::sun::star::task::XInteractionRequest > rRequest( pPasswordRequest ); + uno::Reference< com::sun::star::task::XInteractionRequest > rRequest( pPasswordRequest.get() ); xInteractionHandler->handle( rRequest ); if ( pPasswordRequest->isPassword() ) - rpSet->Put( SfxStringItem( SID_PASSWORD, pPasswordRequest->getPassword() ) ); + { + if ( pPasswordRequest->getPassword().getLength() ) + rpSet->Put( SfxStringItem( SID_PASSWORD, pPasswordRequest->getPassword() ) ); + + if ( pPasswordRequest->getRecommendReadOnly() ) + rpSet->Put( SfxBoolItem( SID_RECOMMENDREADONLY, sal_True ) ); + + if ( bMSType ) + { + // the empty password has 0 as Hash + sal_Int32 nHash = SfxMedium::CreatePasswordToModifyHash( pPasswordRequest->getPasswordToModify(), ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.text.TextDocument" ) ).equals( pCurrentFilter->GetServiceName() ) ); + if ( nHash ) + rpSet->Put( SfxUnoAnyItem( SID_MODIFYPASSWORDINFO, uno::makeAny( nHash ) ) ); + } + else + { + uno::Sequence< beans::PropertyValue > aModifyPasswordInfo = ::comphelper::DocPasswordHelper::GenerateNewModifyPasswordInfo( pPasswordRequest->getPasswordToModify() ); + if ( aModifyPasswordInfo.getLength() ) + rpSet->Put( SfxUnoAnyItem( SID_MODIFYPASSWORDINFO, uno::makeAny( aModifyPasswordInfo ) ) ); + } + } else return ERRCODE_ABORT; } |