cui/source/dialogs/passwdomdlg.cxx   |   47 +++++----
 cui/source/factory/dlgfact.cxx       |    7 +
 cui/source/factory/dlgfact.hxx       |    3 
 cui/source/inc/passwdomdlg.hxx       |    2 
 include/sfx2/dinfdlg.hxx             |    2 
 include/sfx2/filedlghelper.hxx       |    4 
 include/vcl/abstdlg.hxx              |    1 
 sfx2/source/dialog/dinfdlg.cxx       |   31 +++++
 sfx2/source/dialog/filedlghelper.cxx |  182 +++++++++++++++++++----------------
 vcl/jsdialog/enabled.cxx             |    2 
 10 files changed, 173 insertions(+), 108 deletions(-)

New commits:
commit 67eb60672936a10fba840078e6aca918c3331f52
Author:     Mert Tumer <mert.tu...@collabora.com>
AuthorDate: Mon Sep 12 12:58:20 2022 +0300
Commit:     Szymon Kłos <szymon.k...@collabora.com>
CommitDate: Mon Nov 21 11:45:10 2022 +0100

    lok: make properties>change password dialog async
    
    * We now can set a password through properties->change password
      without having to have a password initially only for online
      because it needs a created file already, online works with files
      that are created before loading but the desktop does not need this.
    * The same dialog is still used as non-async for desktop version
      because it goes through an InteractionHandler and the result is
      expected not from the dialog but from the interaction handler.
      Therefore, making it async there did not make sense.
    
    Signed-off-by: Mert Tumer <mert.tu...@collabora.com>
    Change-Id: I3d02822be0b71836b1592abca191b3b1c5f6374e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139884
    Reviewed-by: Szymon Kłos <szymon.k...@collabora.com>
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142991
    Tested-by: Jenkins

diff --git a/cui/source/dialogs/passwdomdlg.cxx 
b/cui/source/dialogs/passwdomdlg.cxx
index 8a8fcb35842f..163f3961f22e 100644
--- a/cui/source/dialogs/passwdomdlg.cxx
+++ b/cui/source/dialogs/passwdomdlg.cxx
@@ -29,10 +29,10 @@ IMPL_LINK_NOARG(PasswordToOpenModifyDialog, OkBtnClickHdl, 
weld::Button&, void)
             m_xPasswdToModifyED->get_text().isEmpty();
     if (bInvalidState)
     {
-        std::unique_ptr<weld::MessageDialog> 
xErrorBox(Application::CreateMessageDialog(m_xDialog.get(),
+        m_xErrorBox.reset(Application::CreateMessageDialog(m_xDialog.get(),
                                                        
VclMessageType::Warning, VclButtonsType::Ok,
                                                        m_bIsPasswordToModify? 
m_aInvalidStateForOkButton : m_aInvalidStateForOkButton_v2));
-        xErrorBox->run();
+        m_xErrorBox->runAsync(m_xErrorBox, [](sal_Int32 /*nResult*/) {});
     }
     else // check for mismatched passwords...
     {
@@ -41,26 +41,27 @@ IMPL_LINK_NOARG(PasswordToOpenModifyDialog, OkBtnClickHdl, 
weld::Button&, void)
         const int nMismatch = (bToOpenMatch? 0 : 1) + (bToModifyMatch? 0 : 1);
         if (nMismatch > 0)
         {
-            std::unique_ptr<weld::MessageDialog> 
xErrorBox(Application::CreateMessageDialog(m_xDialog.get(),
+            m_xErrorBox.reset(Application::CreateMessageDialog(m_xDialog.get(),
                                                            
VclMessageType::Warning, VclButtonsType::Ok,
                                                            nMismatch == 1 ? 
m_aOneMismatch : m_aTwoMismatch));
-            xErrorBox->run();
-
-            weld::Entry* pEdit = !bToOpenMatch ? m_xPasswdToOpenED.get() : 
m_xPasswdToModifyED.get();
-            weld::Entry* pRepeatEdit = !bToOpenMatch? 
m_xReenterPasswdToOpenED.get() : m_xReenterPasswdToModifyED.get();
-            if (nMismatch == 1)
-            {
-                pEdit->set_text( "" );
-                pRepeatEdit->set_text( "" );
-            }
-            else if (nMismatch == 2)
+            m_xErrorBox->runAsync(m_xErrorBox, [this, bToOpenMatch, 
nMismatch](sal_Int32 /*nResult*/)
             {
-                m_xPasswdToOpenED->set_text( "" );
-                m_xReenterPasswdToOpenED->set_text( "" );
-                m_xPasswdToModifyED->set_text( "" );
-                m_xReenterPasswdToModifyED->set_text( "" );
-            }
-            pEdit->grab_focus();
+                weld::Entry* pEdit = !bToOpenMatch ? m_xPasswdToOpenED.get() : 
m_xPasswdToModifyED.get();
+                weld::Entry* pRepeatEdit = !bToOpenMatch? 
m_xReenterPasswdToOpenED.get() : m_xReenterPasswdToModifyED.get();
+                if (nMismatch == 1)
+                {
+                    pEdit->set_text( "" );
+                    pRepeatEdit->set_text( "" );
+                }
+                else if (nMismatch == 2)
+                {
+                    m_xPasswdToOpenED->set_text( "" );
+                    m_xReenterPasswdToOpenED->set_text( "" );
+                    m_xPasswdToModifyED->set_text( "" );
+                    m_xReenterPasswdToModifyED->set_text( "" );
+                }
+                pEdit->grab_focus();
+            });
         }
         else
         {
@@ -136,6 +137,14 @@ 
PasswordToOpenModifyDialog::PasswordToOpenModifyDialog(weld::Window * pParent, s
     ReadonlyOnOffHdl(*m_xOpenReadonlyCB);
 }
 
+PasswordToOpenModifyDialog::~PasswordToOpenModifyDialog()
+{
+    if (m_xErrorBox)
+    {
+        m_xErrorBox->response(RET_CANCEL);
+    }
+}
+
 OUString PasswordToOpenModifyDialog::GetPasswordToOpen() const
 {
     const bool bPasswdOk =
diff --git a/cui/source/factory/dlgfact.cxx b/cui/source/factory/dlgfact.cxx
index 0cd8d39688ad..9bd3f0229be4 100644
--- a/cui/source/factory/dlgfact.cxx
+++ b/cui/source/factory/dlgfact.cxx
@@ -114,7 +114,6 @@ IMPL_ABSTDLG_CLASS(AbstractGraphicFilterDialog)
 IMPL_ABSTDLG_CLASS(AbstractHangulHanjaConversionDialog)
 IMPL_ABSTDLG_CLASS(AbstractInsertObjectDialog)
 IMPL_ABSTDLG_CLASS(AbstractLinksDialog)
-IMPL_ABSTDLG_CLASS(AbstractPasswordToOpenModifyDialog)
 IMPL_ABSTDLG_CLASS(AbstractQrCodeGenDialog)
 IMPL_ABSTDLG_CLASS(AbstractScreenshotAnnotationDlg)
 IMPL_ABSTDLG_CLASS(AbstractSignatureLineDialog)
@@ -133,6 +132,7 @@ IMPL_ABSTDLG_CLASS(AbstractSvxSearchSimilarityDialog)
 IMPL_ABSTDLG_CLASS(AbstractSvxZoomDialog)
 IMPL_ABSTDLG_CLASS(AbstractTitleDialog)
 IMPL_ABSTDLG_CLASS(AbstractURLDlg)
+IMPL_ABSTDLG_CLASS_ASYNC(AbstractPasswordToOpenModifyDialog,weld::DialogController)
 IMPL_ABSTDLG_CLASS_ASYNC(AbstractPasteDialog,SfxDialogController)
 IMPL_ABSTDLG_CLASS_ASYNC(AbstractScriptSelectorDialog,SfxDialogController)
 IMPL_ABSTDLG_CLASS_ASYNC(AbstractSpellDialog,SfxDialogController)
@@ -804,6 +804,11 @@ bool 
AbstractPasswordToOpenModifyDialog_Impl::IsRecommendToOpenReadonly() const
     return m_xDlg->IsRecommendToOpenReadonly();
 }
 
+void AbstractPasswordToOpenModifyDialog_Impl::Response(sal_Int32 nResult)
+{
+     m_xDlg->response(nResult);
+}
+
 // Create dialogs with simplest interface
 VclPtr<VclAbstractDialog> 
AbstractDialogFactory_Impl::CreateVclDialog(weld::Window* pParent, sal_uInt32 
nResId)
 {
diff --git a/cui/source/factory/dlgfact.hxx b/cui/source/factory/dlgfact.hxx
index eb52630d0199..071c71592b50 100644
--- a/cui/source/factory/dlgfact.hxx
+++ b/cui/source/factory/dlgfact.hxx
@@ -383,10 +383,11 @@ private:
 };
 
 // AbstractPasswordToOpenModifyDialog_Impl
-DECL_ABSTDLG_CLASS(AbstractPasswordToOpenModifyDialog,PasswordToOpenModifyDialog)
+DECL_ABSTDLG_CLASS_SHARED_ASYNC(AbstractPasswordToOpenModifyDialog,AbstractPasswordToOpenModifyDialog,
 PasswordToOpenModifyDialog)
     virtual OUString  GetPasswordToOpen() const override;
     virtual OUString  GetPasswordToModify() const override;
     virtual bool      IsRecommendToOpenReadonly() const override;
+    virtual void      Response(sal_Int32) override;
 };
 
 // AbstractSvxCharacterMapDialog_Impl
diff --git a/cui/source/inc/passwdomdlg.hxx b/cui/source/inc/passwdomdlg.hxx
index 2e13cc1b616c..9b1cd460ea7c 100644
--- a/cui/source/inc/passwdomdlg.hxx
+++ b/cui/source/inc/passwdomdlg.hxx
@@ -36,6 +36,7 @@ class PasswordToOpenModifyDialog : public SfxDialogController
     std::unique_ptr<weld::Label> m_xReenterPasswdToModifyFT;
     std::unique_ptr<weld::Entry> m_xReenterPasswdToModifyED;
     std::unique_ptr<weld::Label> m_xReenterPasswdToModifyInd;
+    std::shared_ptr<weld::MessageDialog> m_xErrorBox;
 
     OUString                    m_aOneMismatch;
     OUString                    m_aTwoMismatch;
@@ -57,6 +58,7 @@ public:
     PasswordToOpenModifyDialog(weld::Window* pParent,
             sal_uInt16 nMaxPasswdLen /* 0 -> no max len enforced */,
             bool bIsPasswordToModify );
+    ~PasswordToOpenModifyDialog();
 
     // AbstractPasswordToOpenModifyDialog
     OUString  GetPasswordToOpen() const;
diff --git a/include/sfx2/dinfdlg.hxx b/include/sfx2/dinfdlg.hxx
index 7cbf5433eaa7..4d7487f554f4 100644
--- a/include/sfx2/dinfdlg.hxx
+++ b/include/sfx2/dinfdlg.hxx
@@ -39,6 +39,7 @@
 
 #include <optional>
 #include <memory>
+#include <vcl/abstdlg.hxx>
 
 namespace com::sun::star::beans { struct PropertyValue; }
 
@@ -197,6 +198,7 @@ private:
 
     virtual bool        FillItemSet( SfxItemSet* ) override;
     virtual void        Reset( const SfxItemSet* ) override;
+    VclPtr<AbstractPasswordToOpenModifyDialog> m_xPasswordDialog;
 
 public:
     SfxDocumentPage(weld::Container* pPage, weld::DialogController* 
pController, const SfxItemSet&);
diff --git a/include/sfx2/filedlghelper.hxx b/include/sfx2/filedlghelper.hxx
index 13593bae0358..c89da31ab953 100644
--- a/include/sfx2/filedlghelper.hxx
+++ b/include/sfx2/filedlghelper.hxx
@@ -306,6 +306,10 @@ ErrCode FileOpenDialog_Impl( weld::Window* pParent,
 css::uno::Reference<css::ui::dialogs::XFolderPicker2> SFX2_DLLPUBLIC 
createFolderPicker(const css::uno::Reference<css::uno::XComponentContext>& 
rContext, weld::Window* pPreferredParent);
 
 ErrCode RequestPassword(const std::shared_ptr<const SfxFilter>& 
pCurrentFilter, OUString const & aURL, SfxItemSet* pSet, const 
css::uno::Reference<css::awt::XWindow>& rParent);
+ErrCode SetPassword(const std::shared_ptr<const SfxFilter>& pCurrentFilter,
+    SfxItemSet* pSet, const OUString& rPasswordToOpen, std::u16string_view 
rPasswordToModify);
+bool IsOOXML(const std::shared_ptr<const SfxFilter>& pCurrentFilter);
+bool IsMSType(const std::shared_ptr<const SfxFilter>& pCurrentFilter);
 }
 
 #endif
diff --git a/include/vcl/abstdlg.hxx b/include/vcl/abstdlg.hxx
index 79b2b32a9836..cb4de91f88e4 100644
--- a/include/vcl/abstdlg.hxx
+++ b/include/vcl/abstdlg.hxx
@@ -99,6 +99,7 @@ public:
     virtual OUString    GetPasswordToOpen() const   = 0;
     virtual OUString    GetPasswordToModify() const = 0;
     virtual bool        IsRecommendToOpenReadonly() const = 0;
+    virtual void        Response(sal_Int32) = 0;
 };
 
 class VCL_DLLPUBLIC AbstractScreenshotAnnotationDlg : public VclAbstractDialog
diff --git a/sfx2/source/dialog/dinfdlg.cxx b/sfx2/source/dialog/dinfdlg.cxx
index 3dd14c423af7..3d1ee1dadac5 100644
--- a/sfx2/source/dialog/dinfdlg.cxx
+++ b/sfx2/source/dialog/dinfdlg.cxx
@@ -70,6 +70,7 @@
 #include <helper.hxx>
 #include <sfx2/objsh.hxx>
 #include <sfx2/docfile.hxx>
+#include <vcl/abstdlg.hxx>
 
 #include <documentfontsdialog.hxx>
 #include <dinfdlg.hrc>
@@ -723,6 +724,11 @@ SfxDocumentPage::SfxDocumentPage(weld::Container* pPage, 
weld::DialogController*
 
 SfxDocumentPage::~SfxDocumentPage()
 {
+    if (m_xPasswordDialog)
+    {
+        m_xPasswordDialog->Response(RET_CANCEL);
+        m_xPasswordDialog.clear();
+    }
 }
 
 IMPL_LINK_NOARG(SfxDocumentPage, DeleteHdl, weld::Button&, void)
@@ -772,9 +778,26 @@ IMPL_LINK_NOARG(SfxDocumentPage, ChangePassHdl, 
weld::Button&, void)
         std::shared_ptr<const SfxFilter> pFilter = 
pShell->GetMedium()->GetFilter();
         if (!pFilter)
             break;
-
-        sfx2::RequestPassword(pFilter, OUString(), pMedSet, 
GetFrameWeld()->GetXWindow());
-        pShell->SetModified();
+        if (comphelper::LibreOfficeKit::isActive())
+        {
+            // MS Types support max len of 15 characters while OOXML is 
"unlimited"
+            const sal_uInt16 maxPwdLen = sfx2::IsMSType(pFilter) && 
!sfx2::IsOOXML(pFilter) ? 15 : 0;
+            // handle the pwd dialog asynchronously
+            VclAbstractDialogFactory * pFact = 
VclAbstractDialogFactory::Create();
+            m_xPasswordDialog = 
pFact->CreatePasswordToOpenModifyDialog(GetFrameWeld(), maxPwdLen, false);
+            m_xPasswordDialog->StartExecuteAsync([this, pFilter, pMedSet, 
pShell](sal_Int32 nResult)
+            {
+                if (nResult == RET_OK)
+                {
+                    sfx2::SetPassword(pFilter, pMedSet, 
m_xPasswordDialog->GetPasswordToOpen(), m_xPasswordDialog->GetPasswordToOpen());
+                    pShell->SetModified();
+                }
+                m_xPasswordDialog->disposeOnce();
+            });
+        } else {
+            sfx2::RequestPassword(pFilter, OUString(), pMedSet, 
GetFrameWeld()->GetXWindow());
+            pShell->SetModified();
+        }
     }
     while (false);
 }
@@ -838,7 +861,7 @@ void SfxDocumentPage::ImplCheckPasswordState()
         return;
     }
     while (false);
-    m_xChangePassBtn->set_sensitive(false);
+    m_xChangePassBtn->set_sensitive(comphelper::LibreOfficeKit::isActive());
 }
 
 std::unique_ptr<SfxTabPage> SfxDocumentPage::Create(weld::Container* pPage, 
weld::DialogController* pController, const SfxItemSet* rItemSet)
diff --git a/sfx2/source/dialog/filedlghelper.cxx 
b/sfx2/source/dialog/filedlghelper.cxx
index 0f9f4739596b..93505057779f 100644
--- a/sfx2/source/dialog/filedlghelper.cxx
+++ b/sfx2/source/dialog/filedlghelper.cxx
@@ -2865,21 +2865,109 @@ ErrCode FileOpenDialog_Impl( weld::Window* pParent,
     return nRet;
 }
 
-ErrCode RequestPassword(const std::shared_ptr<const SfxFilter>& 
pCurrentFilter, OUString const & aURL, SfxItemSet* pSet, const 
css::uno::Reference<css::awt::XWindow>& rParent)
+bool IsMSType(const std::shared_ptr<const SfxFilter>& pCurrentFilter)
 {
-    uno::Reference<task::XInteractionHandler2> xInteractionHandler = 
task::InteractionHandler::createWithParent(::comphelper::getProcessComponentContext(),
 rParent);
     // TODO: need a save way to distinguish MS filters from other filters
     // for now MS-filters are the only alien filters that support encryption
-    const bool bMSType = !pCurrentFilter->IsOwnFormat();
+    return !pCurrentFilter->IsOwnFormat();
+}
+
+bool IsOOXML(const std::shared_ptr<const SfxFilter>& pCurrentFilter)
+{
     // For OOXML we can use the standard password ("unlimited" characters)
-    // request, otherwise the MS limited password request is needed.
-    const bool bOOXML = bMSType && lclSupportsOOXMLEncryption( 
pCurrentFilter->GetFilterName());
-    const ::comphelper::DocPasswordRequestType eType = bMSType && !bOOXML ?
+    return IsMSType(pCurrentFilter) && lclSupportsOOXMLEncryption( 
pCurrentFilter->GetFilterName());
+}
+
+ErrCode SetPassword(const std::shared_ptr<const SfxFilter>& pCurrentFilter, 
SfxItemSet* pSet, const OUString& rPasswordToOpen, std::u16string_view 
rPasswordToModify)
+{
+    const bool bMSType = IsMSType(pCurrentFilter);
+    const bool bOOXML = IsOOXML(pCurrentFilter);
+
+    if ( rPasswordToOpen.getLength() )
+    {
+        css::uno::Sequence< css::beans::NamedValue > aEncryptionData;
+
+        if ( bMSType )
+        {
+            if (bOOXML)
+            {
+                ::comphelper::SequenceAsHashMap aHashData;
+                aHashData[ OUString( "OOXPassword" ) ] <<= rPasswordToOpen;
+                aHashData[ OUString( "CryptoType" ) ] <<= OUString( "Standard" 
);
+                aEncryptionData = aHashData.getAsConstNamedValueList();
+            }
+            else
+            {
+                uno::Sequence< sal_Int8 > aUniqueID = 
::comphelper::DocPasswordHelper::GenerateRandomByteSequence( 16 );
+                uno::Sequence< sal_Int8 > aEncryptionKey = 
::comphelper::DocPasswordHelper::GenerateStd97Key( rPasswordToOpen, aUniqueID );
+
+                if ( aEncryptionKey.hasElements() )
+                {
+                    ::comphelper::SequenceAsHashMap aHashData;
+                    aHashData[ OUString( "STD97EncryptionKey"  ) ] <<= 
aEncryptionKey;
+                    aHashData[ OUString( "STD97UniqueID"  ) ] <<= aUniqueID;
+
+                    aEncryptionData = aHashData.getAsConstNamedValueList();
+                }
+                else
+                {
+                    return ERRCODE_IO_NOTSUPPORTED;
+                }
+            }
+        }
+
+        // tdf#118639: We need ODF encryption data for autorecovery where 
password will already
+        // be unavailable, even for non-ODF documents, so append it here 
unconditionally
+        pSet->Put(SfxUnoAnyItem(
+            SID_ENCRYPTIONDATA,
+            uno::Any(comphelper::concatSequences(
+                aEncryptionData, 
comphelper::OStorageHelper::CreatePackageEncryptionData(
+                                    rPasswordToOpen)))));
+    }
+
+    if ( bMSType )
+    {
+        if (bOOXML)
+        {
+            uno::Sequence<beans::PropertyValue> aModifyPasswordInfo
+                = 
::comphelper::DocPasswordHelper::GenerateNewModifyPasswordInfoOOXML(
+                    rPasswordToModify);
+            if (aModifyPasswordInfo.hasElements() && pSet)
+                pSet->Put(
+                    SfxUnoAnyItem(SID_MODIFYPASSWORDINFO, 
uno::Any(aModifyPasswordInfo)));
+        }
+        else
+        {
+            // the empty password has 0 as Hash
+            sal_Int32 nHash = SfxMedium::CreatePasswordToModifyHash(
+                rPasswordToModify,
+                pCurrentFilter->GetServiceName() == 
"com.sun.star.text.TextDocument");
+            if (nHash && pSet)
+                pSet->Put(SfxUnoAnyItem(SID_MODIFYPASSWORDINFO, 
uno::Any(nHash)));
+        }
+    }
+    else
+    {
+        uno::Sequence< beans::PropertyValue > aModifyPasswordInfo = 
::comphelper::DocPasswordHelper::GenerateNewModifyPasswordInfo( 
rPasswordToModify );
+        if ( aModifyPasswordInfo.hasElements() && pSet)
+            pSet->Put( SfxUnoAnyItem( SID_MODIFYPASSWORDINFO, uno::Any( 
aModifyPasswordInfo ) ) );
+    }
+    return ERRCODE_NONE;
+}
+
+
+
+ErrCode RequestPassword(const std::shared_ptr<const SfxFilter>& 
pCurrentFilter, OUString const & aURL, SfxItemSet* pSet, const 
css::uno::Reference<css::awt::XWindow>& rParent)
+{
+    uno::Reference<task::XInteractionHandler2> xInteractionHandler = 
task::InteractionHandler::createWithParent(::comphelper::getProcessComponentContext(),
 rParent);
+    const auto eType = IsMSType(pCurrentFilter) && !IsOOXML(pCurrentFilter) ?
         ::comphelper::DocPasswordRequestType::MS :
         ::comphelper::DocPasswordRequestType::Standard;
 
     ::rtl::Reference< ::comphelper::DocPasswordRequest > pPasswordRequest( new 
::comphelper::DocPasswordRequest( eType, 
css::task::PasswordRequestMode_PASSWORD_CREATE, aURL, bool( 
pCurrentFilter->GetFilterFlags() & SfxFilterFlags::PASSWORDTOMODIFY ) ) );
 
+    const bool bMSType = IsMSType(pCurrentFilter);
+
     uno::Reference< css::task::XInteractionRequest > rRequest( 
pPasswordRequest );
     do
     {
@@ -2902,85 +2990,15 @@ ErrCode RequestPassword(const std::shared_ptr<const 
SfxFilter>& pCurrentFilter,
         xBox->run();
     }
     while (true);
-    if ( pPasswordRequest->isPassword() )
-    {
-        if ( pPasswordRequest->getPassword().getLength() )
-        {
-            css::uno::Sequence< css::beans::NamedValue > aEncryptionData;
-
-            // TODO/LATER: The filters should show the password dialog 
themself in future
-            if ( bMSType )
-            {
-                if (bOOXML)
-                {
-                    ::comphelper::SequenceAsHashMap aHashData;
-                    aHashData[ OUString( "OOXPassword" ) ] <<= 
pPasswordRequest->getPassword();
-                    aHashData[ OUString( "CryptoType" ) ] <<= OUString( 
"Standard" );
-                    aEncryptionData = aHashData.getAsConstNamedValueList();
-                }
-                else
-                {
-                    uno::Sequence< sal_Int8 > aUniqueID = 
::comphelper::DocPasswordHelper::GenerateRandomByteSequence( 16 );
-                    uno::Sequence< sal_Int8 > aEncryptionKey = 
::comphelper::DocPasswordHelper::GenerateStd97Key( 
pPasswordRequest->getPassword(), aUniqueID );
-
-                    if ( aEncryptionKey.hasElements() )
-                    {
-                        ::comphelper::SequenceAsHashMap aHashData;
-                        aHashData[ OUString( "STD97EncryptionKey"  ) ] <<= 
aEncryptionKey;
-                        aHashData[ OUString( "STD97UniqueID"  ) ] <<= 
aUniqueID;
-
-                        aEncryptionData = aHashData.getAsConstNamedValueList();
-                    }
-                    else
-                    {
-                        return ERRCODE_IO_NOTSUPPORTED;
-                    }
-                }
-            }
+    if ( !pPasswordRequest->isPassword() )
+        return ERRCODE_ABORT;
 
-            // tdf#118639: We need ODF encryption data for autorecovery where 
password will already
-            // be unavailable, even for non-ODF documents, so append it here 
unconditionally
-            pSet->Put(SfxUnoAnyItem(
-                SID_ENCRYPTIONDATA,
-                uno::Any(comphelper::concatSequences(
-                    aEncryptionData, 
comphelper::OStorageHelper::CreatePackageEncryptionData(
-                                         pPasswordRequest->getPassword())))));
-        }
+    const auto result = SetPassword(pCurrentFilter, pSet, 
pPasswordRequest->getPassword(), pPasswordRequest->getPasswordToModify());
 
-        if ( pPasswordRequest->getRecommendReadOnly() )
-            pSet->Put( SfxBoolItem( SID_RECOMMENDREADONLY, true ) );
+    if ( result != ERRCODE_IO_NOTSUPPORTED && 
pPasswordRequest->getRecommendReadOnly() )
+        pSet->Put( SfxBoolItem( SID_RECOMMENDREADONLY, true ) );
 
-        if ( bMSType )
-        {
-            if (bOOXML)
-            {
-                uno::Sequence<beans::PropertyValue> aModifyPasswordInfo
-                    = 
::comphelper::DocPasswordHelper::GenerateNewModifyPasswordInfoOOXML(
-                        pPasswordRequest->getPasswordToModify());
-                if (aModifyPasswordInfo.hasElements())
-                    pSet->Put(
-                        SfxUnoAnyItem(SID_MODIFYPASSWORDINFO, 
uno::Any(aModifyPasswordInfo)));
-            }
-            else
-            {
-                // the empty password has 0 as Hash
-                sal_Int32 nHash = SfxMedium::CreatePasswordToModifyHash(
-                    pPasswordRequest->getPasswordToModify(),
-                    pCurrentFilter->GetServiceName() == 
"com.sun.star.text.TextDocument");
-                if (nHash)
-                    pSet->Put(SfxUnoAnyItem(SID_MODIFYPASSWORDINFO, 
uno::Any(nHash)));
-            }
-        }
-        else
-        {
-            uno::Sequence< beans::PropertyValue > aModifyPasswordInfo = 
::comphelper::DocPasswordHelper::GenerateNewModifyPasswordInfo( 
pPasswordRequest->getPasswordToModify() );
-            if ( aModifyPasswordInfo.hasElements() )
-                pSet->Put( SfxUnoAnyItem( SID_MODIFYPASSWORDINFO, uno::Any( 
aModifyPasswordInfo ) ) );
-        }
-    }
-    else
-        return ERRCODE_ABORT;
-    return ERRCODE_NONE;
+    return result;
 }
 
 OUString EncodeSpaces_Impl( const OUString& rSource )
diff --git a/vcl/jsdialog/enabled.cxx b/vcl/jsdialog/enabled.cxx
index ca930621ea31..375023636916 100644
--- a/vcl/jsdialog/enabled.cxx
+++ b/vcl/jsdialog/enabled.cxx
@@ -72,7 +72,7 @@ bool isBuilderEnabled(std::u16string_view rUIFile, bool 
bMobile)
         || rUIFile == u"sfx/ui/linefragment.ui" || rUIFile == 
u"sfx/ui/editdurationdialog.ui"
         || rUIFile == u"modules/swriter/ui/insertcaption.ui"
         || rUIFile == u"modules/swriter/ui/captionoptions.ui"
-        || rUIFile == u"cui/ui/formatnumberdialog.ui"
+        || rUIFile == u"cui/ui/formatnumberdialog.ui" || rUIFile == 
u"cui/ui/password.ui"
         || rUIFile == u"cui/ui/numberingformatpage.ui")
     {
         return true;

Reply via email to