sfx2/source/dialog/filedlghelper.cxx |   36 +++++++++++++++++++++++++++++++++++
 sfx2/source/dialog/filedlgimpl.hxx   |    3 ++
 2 files changed, 39 insertions(+)

New commits:
commit 24c16b9ea8b9e19150887f79938fcbb3386dd54a
Author:     Moritz Duge <moritz.d...@allotropia.de>
AuthorDate: Thu May 23 18:12:34 2024 +0200
Commit:     Thorsten Behrens <thorsten.behr...@allotropia.de>
CommitDate: Wed Jul 17 20:59:05 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
    (cherry picked from commit 76f4e6d9764048d98f3fdd1620b0e0a6787385c1)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170343

diff --git a/sfx2/source/dialog/filedlghelper.cxx 
b/sfx2/source/dialog/filedlghelper.cxx
index 96955837c8a6..77e6fff88a57 100644
--- a/sfx2/source/dialog/filedlghelper.cxx
+++ b/sfx2/source/dialog/filedlghelper.cxx
@@ -285,6 +285,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 )
@@ -550,6 +551,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 )
@@ -900,6 +932,7 @@ FileDialogHelper_Impl::FileDialogHelper_Impl(
     mbHasPassword           = false;
     m_bHaveFilterOptions    = false;
     mbIsPwdEnabled          = true;
+    mbIsGpgEncrEnabled      = true;
     mbHasVersions           = false;
     mbHasPreview            = false;
     mbShowPreview           = false;
@@ -910,6 +943,7 @@ FileDialogHelper_Impl::FileDialogHelper_Impl(
     mbExport                = bool(nFlags & FileDialogFlags::Export);
     mbIsSaveDlg             = false;
     mbPwdCheckBoxState      = false;
+    mbGpgCheckBoxState      = false;
     mbSelection             = false;
     mbSelectionEnabled      = true;
     mbHasSelectionBox       = false;
@@ -1232,6 +1266,7 @@ IMPL_LINK_NOARG( FileDialogHelper_Impl, InitControls, 
void*, void )
 {
     mnPostUserEventId = nullptr;
     enablePasswordBox( true );
+    enableGpgEncrBox( true );
     updateFilterOptionsBox( );
     updateSelectionBox( );
 }
@@ -1255,6 +1290,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 20a4cc42f382..07f1906ba3e8 100644
--- a/sfx2/source/dialog/filedlgimpl.hxx
+++ b/sfx2/source/dialog/filedlgimpl.hxx
@@ -76,6 +76,7 @@ namespace sfx2
 
         bool                    mbHasPassword           : 1;
         bool                    mbIsPwdEnabled          : 1;
+        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();

Reply via email to