diff options
author | Szymon Kłos <szymon.klos@collabora.com> | 2022-10-14 14:54:15 +0200 |
---|---|---|
committer | Szymon Kłos <szymon.klos@collabora.com> | 2022-11-21 12:36:35 +0100 |
commit | 58ae6705deccb614f33d20bfa4b2ab0923d426e1 (patch) | |
tree | d122c478b44c3d63cb0b274453aa807a97d0259c | |
parent | be12f60b1055292ac655e53f4fb56567b5c15970 (diff) |
lok: allow password reset in properties>change password
Change-Id: I92a3c658e96f602549ff5282b6ed5bc9ee780bbd
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141372
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Andras Timar <andras.timar@collabora.com>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142992
Tested-by: Jenkins
Reviewed-by: Szymon Kłos <szymon.klos@collabora.com>
-rw-r--r-- | cui/source/dialogs/passwdomdlg.cxx | 8 | ||||
-rw-r--r-- | cui/source/factory/dlgfact.cxx | 5 | ||||
-rw-r--r-- | cui/source/factory/dlgfact.hxx | 1 | ||||
-rw-r--r-- | cui/source/inc/passwdomdlg.hxx | 2 | ||||
-rw-r--r-- | include/sfx2/filedlghelper.hxx | 5 | ||||
-rw-r--r-- | include/vcl/abstdlg.hxx | 1 | ||||
-rw-r--r-- | sfx2/source/dialog/dinfdlg.cxx | 4 | ||||
-rw-r--r-- | sfx2/source/dialog/filedlghelper.cxx | 15 |
8 files changed, 36 insertions, 5 deletions
diff --git a/cui/source/dialogs/passwdomdlg.cxx b/cui/source/dialogs/passwdomdlg.cxx index 163f3961f22e..579af0edc9aa 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) @@ -107,6 +107,7 @@ PasswordToOpenModifyDialog::PasswordToOpenModifyDialog(weld::Window * pParent, s , m_aInvalidStateForOkButton_v2( CuiResId( RID_CUISTR_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 9bd3f0229be4..f0177530fa70 100644 --- a/cui/source/factory/dlgfact.cxx +++ b/cui/source/factory/dlgfact.cxx @@ -809,6 +809,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 071c71592b50..991ec082ad48 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 c89da31ab953..ea84a9450de6 100644 --- a/include/sfx2/filedlghelper.hxx +++ b/include/sfx2/filedlghelper.hxx @@ -306,8 +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, std::u16string_view rPasswordToModify); +ErrCode SetPassword(const std::shared_ptr<const SfxFilter>& pCurrentFilter, SfxItemSet* pSet, + const OUString& rPasswordToOpen, std::u16string_view 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 cb4de91f88e4..9d61077a24c9 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 3d1ee1dadac5..3067229b96eb 100644 --- a/sfx2/source/dialog/dinfdlg.cxx +++ b/sfx2/source/dialog/dinfdlg.cxx @@ -785,11 +785,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 93505057779f..541d26a9ae29 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, std::u16string_view rPasswordToModify) +ErrCode SetPassword(const std::shared_ptr<const SfxFilter>& pCurrentFilter, SfxItemSet* pSet, + const OUString& rPasswordToOpen, std::u16string_view 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 ) { |