cui/source/dialogs/passwdomdlg.cxx | 10 ++++++++-- cui/source/factory/dlgfact.cxx | 5 +++++ cui/source/factory/dlgfact.hxx | 1 + cui/source/inc/passwdomdlg.hxx | 2 ++ include/sfx2/filedlghelper.hxx | 4 +++- include/vcl/abstdlg.hxx | 1 + sfx2/source/dialog/dinfdlg.cxx | 4 +++- sfx2/source/dialog/filedlghelper.cxx | 15 ++++++++++++++- 8 files changed, 37 insertions(+), 5 deletions(-)
New commits: commit 8a84b5c024ed511548d6749a6038ae933e4d589d Author: Szymon Kłos <[email protected]> AuthorDate: Fri Oct 14 14:54:15 2022 +0200 Commit: Andras Timar <[email protected]> CommitDate: Tue Oct 18 21:19:28 2022 +0200 lok: allow password reset in properties>change password Change-Id: I92a3c658e96f602549ff5282b6ed5bc9ee780bbd Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141372 Tested-by: Jenkins CollaboraOffice <[email protected]> Reviewed-by: Andras Timar <[email protected]> diff --git a/cui/source/dialogs/passwdomdlg.cxx b/cui/source/dialogs/passwdomdlg.cxx index 31a69d3259e0..1bc76412b25c 100644 --- a/cui/source/dialogs/passwdomdlg.cxx +++ b/cui/source/dialogs/passwdomdlg.cxx @@ -24,7 +24,7 @@ IMPL_LINK_NOARG(PasswordToOpenModifyDialog, OkBtnClickHdl, weld::Button&, void) { - bool bInvalidState = !m_xOpenReadonlyCB->get_active() && + bool bInvalidState = !m_xOpenReadonlyCB->get_active() && !m_bAllowEmpty && m_xPasswdToOpenED->get_text().isEmpty() && m_xPasswdToModifyED->get_text().isEmpty(); if (bInvalidState) @@ -44,7 +44,7 @@ IMPL_LINK_NOARG(PasswordToOpenModifyDialog, OkBtnClickHdl, weld::Button&, void) m_xErrorBox.reset(Application::CreateMessageDialog(m_xDialog.get(), VclMessageType::Warning, VclButtonsType::Ok, nMismatch == 1 ? m_aOneMismatch : m_aTwoMismatch)); - m_xErrorBox->runAsync(m_xErrorBox, [this, bToOpenMatch, bToModifyMatch, nMismatch](sal_Int32 /*nResult*/) + m_xErrorBox->runAsync(m_xErrorBox, [this, bToOpenMatch, nMismatch](sal_Int32 /*nResult*/) { weld::Entry* pEdit = !bToOpenMatch ? m_xPasswdToOpenED.get() : m_xPasswdToModifyED.get(); weld::Entry* pRepeatEdit = !bToOpenMatch? m_xReenterPasswdToOpenED.get() : m_xReenterPasswdToModifyED.get(); @@ -107,6 +107,7 @@ PasswordToOpenModifyDialog::PasswordToOpenModifyDialog(weld::Window * pParent, s , m_aInvalidStateForOkButton_v2( CuiResId( RID_SVXSTR_INVALID_STATE_FOR_OK_BUTTON_V2 ) ) , m_nMaxPasswdLen(nMaxPasswdLen) , m_bIsPasswordToModify( bIsPasswordToModify ) + , m_bAllowEmpty( false ) { m_xOk->connect_clicked(LINK(this, PasswordToOpenModifyDialog, OkBtnClickHdl)); @@ -145,6 +146,11 @@ PasswordToOpenModifyDialog::~PasswordToOpenModifyDialog() } } +void PasswordToOpenModifyDialog::AllowEmpty() +{ + m_bAllowEmpty = true; +} + OUString PasswordToOpenModifyDialog::GetPasswordToOpen() const { const bool bPasswdOk = diff --git a/cui/source/factory/dlgfact.cxx b/cui/source/factory/dlgfact.cxx index d6c39e19fea4..5793cd47c5df 100644 --- a/cui/source/factory/dlgfact.cxx +++ b/cui/source/factory/dlgfact.cxx @@ -800,6 +800,11 @@ void AbstractPasswordToOpenModifyDialog_Impl::Response(sal_Int32 nResult) m_xDlg->response(nResult); } +void AbstractPasswordToOpenModifyDialog_Impl::AllowEmpty() +{ + m_xDlg->AllowEmpty(); +} + // 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 f17a0ab6171c..a583f2b474a3 100644 --- a/cui/source/factory/dlgfact.hxx +++ b/cui/source/factory/dlgfact.hxx @@ -388,6 +388,7 @@ DECL_ABSTDLG_CLASS_SHARED_ASYNC(AbstractPasswordToOpenModifyDialog,AbstractPassw virtual OUString GetPasswordToModify() const override; virtual bool IsRecommendToOpenReadonly() const override; virtual void Response(sal_Int32) override; + virtual void AllowEmpty() override; }; // AbstractSvxCharacterMapDialog_Impl diff --git a/cui/source/inc/passwdomdlg.hxx b/cui/source/inc/passwdomdlg.hxx index 9b1cd460ea7c..24a1c7b79264 100644 --- a/cui/source/inc/passwdomdlg.hxx +++ b/cui/source/inc/passwdomdlg.hxx @@ -45,6 +45,7 @@ class PasswordToOpenModifyDialog : public SfxDialogController int m_nMaxPasswdLen; bool m_bIsPasswordToModify; + bool m_bAllowEmpty; DECL_LINK(OkBtnClickHdl, weld::Button&, void); @@ -64,6 +65,7 @@ public: OUString GetPasswordToOpen() const; OUString GetPasswordToModify() const; bool IsRecommendToOpenReadonly() const; + void AllowEmpty(); }; /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/sfx2/filedlghelper.hxx b/include/sfx2/filedlghelper.hxx index d46520b6663c..5c5afca129c7 100644 --- a/include/sfx2/filedlghelper.hxx +++ b/include/sfx2/filedlghelper.hxx @@ -306,7 +306,9 @@ 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, const OUString& rPasswordToModify); +ErrCode SetPassword(const std::shared_ptr<const SfxFilter>& pCurrentFilter, SfxItemSet* pSet, + const OUString& rPasswordToOpen, const OUString& rPasswordToModify, + bool bAllowPasswordReset = false); bool IsOOXML(const std::shared_ptr<const SfxFilter>& pCurrentFilter); bool IsMSType(const std::shared_ptr<const SfxFilter>& pCurrentFilter); } diff --git a/include/vcl/abstdlg.hxx b/include/vcl/abstdlg.hxx index f85df163387d..1958fd728cc8 100644 --- a/include/vcl/abstdlg.hxx +++ b/include/vcl/abstdlg.hxx @@ -100,6 +100,7 @@ public: virtual OUString GetPasswordToModify() const = 0; virtual bool IsRecommendToOpenReadonly() const = 0; virtual void Response(sal_Int32) = 0; + virtual void AllowEmpty() = 0; }; class VCL_DLLPUBLIC AbstractScreenshotAnnotationDlg : public VclAbstractDialog diff --git a/sfx2/source/dialog/dinfdlg.cxx b/sfx2/source/dialog/dinfdlg.cxx index 26609290d9c5..799d8fbd3168 100644 --- a/sfx2/source/dialog/dinfdlg.cxx +++ b/sfx2/source/dialog/dinfdlg.cxx @@ -782,11 +782,13 @@ IMPL_LINK_NOARG(SfxDocumentPage, ChangePassHdl, weld::Button&, void) // handle the pwd dialog asynchronously VclAbstractDialogFactory * pFact = VclAbstractDialogFactory::Create(); m_xPasswordDialog = pFact->CreatePasswordToOpenModifyDialog(GetFrameWeld(), maxPwdLen, false); + m_xPasswordDialog->AllowEmpty(); // needed to remove password m_xPasswordDialog->StartExecuteAsync([this, pFilter, pMedSet, pShell](sal_Int32 nResult) { if (nResult == RET_OK) { - sfx2::SetPassword(pFilter, pMedSet, m_xPasswordDialog->GetPasswordToOpen(), m_xPasswordDialog->GetPasswordToOpen()); + sfx2::SetPassword(pFilter, pMedSet, m_xPasswordDialog->GetPasswordToOpen(), + m_xPasswordDialog->GetPasswordToOpen(), true); pShell->SetModified(); } m_xPasswordDialog->disposeOnce(); diff --git a/sfx2/source/dialog/filedlghelper.cxx b/sfx2/source/dialog/filedlghelper.cxx index 7cd4b3653c54..8239219ea20b 100644 --- a/sfx2/source/dialog/filedlghelper.cxx +++ b/sfx2/source/dialog/filedlghelper.cxx @@ -2878,7 +2878,9 @@ bool IsOOXML(const std::shared_ptr<const SfxFilter>& pCurrentFilter) return IsMSType(pCurrentFilter) && lclSupportsOOXMLEncryption( pCurrentFilter->GetFilterName()); } -ErrCode SetPassword(const std::shared_ptr<const SfxFilter>& pCurrentFilter, SfxItemSet* pSet, const OUString& rPasswordToOpen, const OUString& rPasswordToModify) +ErrCode SetPassword(const std::shared_ptr<const SfxFilter>& pCurrentFilter, SfxItemSet* pSet, + const OUString& rPasswordToOpen, const OUString& rPasswordToModify, + bool bAllowPasswordReset) { const bool bMSType = IsMSType(pCurrentFilter); const bool bOOXML = IsOOXML(pCurrentFilter); @@ -2924,6 +2926,17 @@ ErrCode SetPassword(const std::shared_ptr<const SfxFilter>& pCurrentFilter, SfxI aEncryptionData, comphelper::OStorageHelper::CreatePackageEncryptionData( rPasswordToOpen))))); } + else if (bAllowPasswordReset) + { + // Remove password + + if (pSet->HasItem(SID_ENCRYPTIONDATA)) + pSet->ClearItem(SID_MODIFYPASSWORDINFO); + if (pSet->HasItem(SID_ENCRYPTIONDATA)) + pSet->ClearItem(SID_ENCRYPTIONDATA); + + return ERRCODE_NONE; + } if ( bMSType ) {
