include/sfx2/objsh.hxx | 3 +- sfx2/source/dialog/dinfdlg.cxx | 6 ++-- sfx2/source/doc/objserv.cxx | 55 ++++++++++++++++++++++++++--------------- 3 files changed, 40 insertions(+), 24 deletions(-)
New commits: commit b256f3bc543ca165b5761197fb0e8c44d6e6b4ff Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Thu Sep 5 13:42:02 2024 +0200 Commit: Caolán McNamara <caolan.mcnam...@collabora.com> CommitDate: Mon Sep 9 11:13:54 2024 +0200 cool#9992 lok doc sign: add SfxObjectShell::AfterSignContent() Currently SfxObjectShell::CheckIsReadonly() has a hack for the LOK case to show the signatures dialog read-only, as only that is async. The first problem for the read-write signatures dialog is that SfxObjectShell::ExecFile_Impl() has code after invoking SfxObjectShell::SignDocumentContent(), which will be executed too early if the dialog is executed async. Fix the problem by moving the code in question into a new SfxObjectShell::AfterSignContent(), and only invoke that as a callback after the async run finished. The message dialog in the moved run is still non-async, but we can deal with that later. (cherry picked from commit 743d08d03317855907991c29534e81c9487ea67a) Conflicts: sfx2/source/doc/objserv.cxx Change-Id: I32f0895118ac0da72105ec3a24c0294e18c05545 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172931 Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com> Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> diff --git a/include/sfx2/objsh.hxx b/include/sfx2/objsh.hxx index 32d9afd6ed6f..b3b55286b349 100644 --- a/include/sfx2/objsh.hxx +++ b/include/sfx2/objsh.hxx @@ -359,7 +359,8 @@ public: void AfterSigning(bool bSignSuccess, bool bSignScriptingContent); bool HasValidSignatures() const; SignatureState GetDocumentSignatureState(); - bool SignDocumentContent(weld::Window* pDialogParent); + void SignDocumentContent(weld::Window* pDialogParent, const std::function<void(bool)>& rCallback); + void AfterSignContent(bool bHaveWeSigned, weld::Window* pDialogParent); css::uno::Sequence<css::security::DocumentSignatureInformation> GetDocumentSignatureInformation( bool bScriptingContent, const css::uno::Reference<css::security::XDocumentDigitalSignatures>& xSigner diff --git a/sfx2/source/dialog/dinfdlg.cxx b/sfx2/source/dialog/dinfdlg.cxx index d46a1a2bcc62..0e74ab6f0d30 100644 --- a/sfx2/source/dialog/dinfdlg.cxx +++ b/sfx2/source/dialog/dinfdlg.cxx @@ -870,9 +870,9 @@ IMPL_LINK_NOARG(SfxDocumentPage, SignatureHdl, weld::Button&, void) SfxObjectShell* pDoc = SfxObjectShell::Current(); if( pDoc ) { - pDoc->SignDocumentContent(GetFrameWeld()); - - ImplUpdateSignatures(); + pDoc->SignDocumentContent(GetFrameWeld(), [this] (bool /*bHaveWeSigned*/) { + ImplUpdateSignatures(); + }); } } diff --git a/sfx2/source/doc/objserv.cxx b/sfx2/source/doc/objserv.cxx index 3f29dff990e1..eaf8cf71cece 100644 --- a/sfx2/source/doc/objserv.cxx +++ b/sfx2/source/doc/objserv.cxx @@ -537,6 +537,25 @@ void SetDocProperties(const uno::Reference<document::XDocumentProperties>& xDP, } } +void SfxObjectShell::AfterSignContent(bool bHaveWeSigned, weld::Window* pDialogParent) +{ + if ( bHaveWeSigned && HasValidSignatures() ) + { + std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog( pDialogParent, + VclMessageType::Question, VclButtonsType::YesNo, SfxResId(STR_QUERY_REMEMBERSIGNATURE))); + if (xBox->run() == RET_YES) + { + rSignatureInfosRemembered = GetDocumentSignatureInformation(false); + bRememberSignature = true; + } + else + { + rSignatureInfosRemembered = uno::Sequence< security::DocumentSignatureInformation >(); + bRememberSignature = false; + } + } +} + void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq) { weld::Window* pDialogParent = rReq.GetFrameWeld(); @@ -589,7 +608,11 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq) } else { - bHaveWeSigned |= SignDocumentContent(pDialogParent); + // Async, all code before return has to go into the callback. + SignDocumentContent(pDialogParent, [this, pDialogParent] (bool bSigned) { + AfterSignContent(bSigned, pDialogParent); + }); + return; } } else @@ -597,21 +620,7 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq) bHaveWeSigned |= SignScriptingContent(pDialogParent); } - if ( bHaveWeSigned && HasValidSignatures() ) - { - std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog( pDialogParent, - VclMessageType::Question, VclButtonsType::YesNo, SfxResId(STR_QUERY_REMEMBERSIGNATURE))); - if (xBox->run() == RET_YES) - { - rSignatureInfosRemembered = GetDocumentSignatureInformation(false); - bRememberSignature = true; - } - else - { - rSignatureInfosRemembered = uno::Sequence< security::DocumentSignatureInformation >(); - bRememberSignature = false; - } - } + AfterSignContent(bHaveWeSigned, pDialogParent); return; } @@ -2119,19 +2128,25 @@ SignatureState SfxObjectShell::GetDocumentSignatureState() return ImplGetSignatureState(); } -bool SfxObjectShell::SignDocumentContent(weld::Window* pDialogParent) +void SfxObjectShell::SignDocumentContent(weld::Window* pDialogParent, const std::function<void(bool)>& rCallback) { if (!PrepareForSigning(pDialogParent)) - return false; + { + rCallback(false); + return; + } if (CheckIsReadonly(false, pDialogParent)) - return false; + { + rCallback(false); + return; + } bool bSignSuccess = GetMedium()->SignContents_Impl(pDialogParent, false, HasValidSignatures()); AfterSigning(bSignSuccess, false); - return bSignSuccess; + rCallback(bSignSuccess); } bool SfxObjectShell::ResignDocument(uno::Sequence< security::DocumentSignatureInformation >& rSignaturesInfo)