sfx2/source/dialog/filedlghelper.cxx | 36 +++++++++++++++++++++++++++++++++++ sfx2/source/dialog/filedlgimpl.hxx | 3 ++ 2 files changed, 39 insertions(+)
New commits: commit 76f4e6d9764048d98f3fdd1620b0e0a6787385c1 Author: Moritz Duge <moritz.d...@allotropia.de> AuthorDate: Thu May 23 18:12:34 2024 +0200 Commit: Thorsten Behrens <thorsten.behr...@allotropia.de> CommitDate: Mon Jul 15 20:45:16 2024 +0200 tdf#121140: GPG checkbox only for file formats with GPGENCRYPTION flag Only ODF-1.2 and ODF 1.3 support GPG encryption. Flat ODF and other formats do NOT, so lets not offer an option that subsequent code path ignores. Change-Id: Ie43be433fbcaa56c76b25e12b58b084ea9bcfd6a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168001 Reviewed-by: Thorsten Behrens <thorsten.behr...@allotropia.de> Tested-by: Jenkins diff --git a/sfx2/source/dialog/filedlghelper.cxx b/sfx2/source/dialog/filedlghelper.cxx index 70199c8dffd0..a9a7fb0c65c2 100644 --- a/sfx2/source/dialog/filedlghelper.cxx +++ b/sfx2/source/dialog/filedlghelper.cxx @@ -282,6 +282,7 @@ void FileDialogHelper_Impl::handleControlStateChanged( const FilePickerEvent& aE case CommonFilePickerElementIds::LISTBOX_FILTER: updateFilterOptionsBox(); enablePasswordBox( false ); + enableGpgEncrBox( false ); updateSelectionBox(); // only use it for export and with our own dialog if ( mbExport && !mbSystemPicker ) @@ -538,6 +539,37 @@ void FileDialogHelper_Impl::enablePasswordBox( bool bInit ) } } +void FileDialogHelper_Impl::enableGpgEncrBox( bool bInit ) +{ + if ( ! mbHasPassword ) // CHECKBOX_GPGENCRYPTION is visible if CHECKBOX_PASSWORD is visible + return; + + // in case of initialization assume previous state to be false + bool bWasEnabled = !bInit && mbIsGpgEncrEnabled; + + std::shared_ptr<const SfxFilter> pCurrentFilter = getCurrentSfxFilter(); + mbIsGpgEncrEnabled = updateExtendedControl( + ExtendedFilePickerElementIds::CHECKBOX_GPGENCRYPTION, + pCurrentFilter && ( pCurrentFilter->GetFilterFlags() & SfxFilterFlags::GPGENCRYPTION ) + ); + + if( !bWasEnabled && mbIsGpgEncrEnabled ) + { + uno::Reference< XFilePickerControlAccess > xCtrlAccess( mxFileDlg, UNO_QUERY ); + if( mbGpgCheckBoxState ) + xCtrlAccess->setValue( ExtendedFilePickerElementIds::CHECKBOX_GPGENCRYPTION, 0, Any( true ) ); + } + else if( bWasEnabled && !mbIsGpgEncrEnabled ) + { + // remember user settings until checkbox is enabled + uno::Reference< XFilePickerControlAccess > xCtrlAccess( mxFileDlg, UNO_QUERY ); + Any aValue = xCtrlAccess->getValue( ExtendedFilePickerElementIds::CHECKBOX_GPGENCRYPTION, 0 ); + bool bGpgEncryption = false; + mbGpgCheckBoxState = ( aValue >>= bGpgEncryption ) && bGpgEncryption; + xCtrlAccess->setValue( ExtendedFilePickerElementIds::CHECKBOX_GPGENCRYPTION, 0, Any( false ) ); + } +} + void FileDialogHelper_Impl::updatePreviewState( bool _bUpdatePreviewWindow ) { if ( !mbHasPreview ) @@ -888,6 +920,7 @@ FileDialogHelper_Impl::FileDialogHelper_Impl( mbHasPassword = false; m_bHaveFilterOptions = false; mbIsPwdEnabled = true; + mbIsGpgEncrEnabled = true; mbHasVersions = false; mbHasPreview = false; mbShowPreview = false; @@ -898,6 +931,7 @@ FileDialogHelper_Impl::FileDialogHelper_Impl( mbExport = bool(nFlags & FileDialogFlags::Export); mbIsSaveDlg = false; mbPwdCheckBoxState = false; + mbGpgCheckBoxState = false; mbSelection = false; mbSelectionEnabled = true; mbHasSelectionBox = false; @@ -1220,6 +1254,7 @@ IMPL_LINK_NOARG( FileDialogHelper_Impl, InitControls, void*, void ) { mnPostUserEventId = nullptr; enablePasswordBox( true ); + enableGpgEncrBox( true ); updateFilterOptionsBox( ); updateSelectionBox( ); } @@ -1243,6 +1278,7 @@ void FileDialogHelper_Impl::preExecute() // However, the macOS implementation's pickers run modally in execute and so the event doesn't // get through in time... so we call the methods directly enablePasswordBox( true ); + enableGpgEncrBox( true ); updateFilterOptionsBox( ); updateSelectionBox( ); #endif diff --git a/sfx2/source/dialog/filedlgimpl.hxx b/sfx2/source/dialog/filedlgimpl.hxx index fe9e8f7a99a5..60fb312e2b17 100644 --- a/sfx2/source/dialog/filedlgimpl.hxx +++ b/sfx2/source/dialog/filedlgimpl.hxx @@ -76,6 +76,7 @@ namespace sfx2 bool mbHasPassword : 1; // checkbox is visible bool mbIsPwdEnabled : 1; // password checkbox is not grayed out + bool mbIsGpgEncrEnabled : 1; // GPG checkbox is not grayed out bool m_bHaveFilterOptions : 1; bool mbHasVersions : 1; bool mbHasAutoExt : 1; @@ -89,6 +90,7 @@ namespace sfx2 bool mbSystemPicker : 1; bool mbAsyncPicker : 1; bool mbPwdCheckBoxState : 1; + bool mbGpgCheckBoxState : 1; bool mbSelection : 1; bool mbSelectionEnabled : 1; bool mbHasSelectionBox : 1; @@ -102,6 +104,7 @@ namespace sfx2 const OUString& rExtension ); void addGraphicFilter(); void enablePasswordBox( bool bInit ); + void enableGpgEncrBox( bool bInit ); void updateFilterOptionsBox(); void updateExportButton(); void updateSelectionBox();