summaryrefslogtreecommitdiff
path: root/xmlsecurity/source
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2024-09-26 09:07:41 +0200
committerMiklos Vajna <vmiklos@collabora.com>2024-09-26 11:06:06 +0200
commitc57434559cf5ffd82c3c72e8a0884d4874885dca (patch)
tree2189a287f7f455044b39de95866f4801fe7012c1 /xmlsecurity/source
parent2b68729253437600db43f5c24838677b963a8c2f (diff)
cool#9992 lok doc sign: conditionally show the add button in the sign dialog
Open the sign dialog, the Add button is hidden, even if the LOK clients initializes the view with a working signing certificate. SfxMedium::SignContents_Impl() knows the correct view, but by the time the execution arrives to the DigitalSignaturesDialog ctor, this info is lost, so we don't know what is the current view. Fix the problem by looking up the view of the object shell at UNO command dispatch time, and passing that around, so the signature dialog can also access it. If the view has a signing certificate configured, then allow signing. The certificate chooser triggered by this button still needs fixing. Change-Id: I1fae63cea27ea1e68e938879f4507f53ade484f1 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173964 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
Diffstat (limited to 'xmlsecurity/source')
-rw-r--r--xmlsecurity/source/component/documentdigitalsignatures.cxx13
-rw-r--r--xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx10
2 files changed, 16 insertions, 7 deletions
diff --git a/xmlsecurity/source/component/documentdigitalsignatures.cxx b/xmlsecurity/source/component/documentdigitalsignatures.cxx
index 07512080cf9e..af6551d7c7e5 100644
--- a/xmlsecurity/source/component/documentdigitalsignatures.cxx
+++ b/xmlsecurity/source/component/documentdigitalsignatures.cxx
@@ -85,6 +85,7 @@ private:
void ImplViewSignatures(const css::uno::Reference<css::embed::XStorage>& rxStorage,
const css::uno::Reference<css::io::XStream>& xSignStream,
DocumentSignatureMode eMode, bool bReadOnly,
+ SfxViewShell* pViewShell,
const std::function<void(bool)>& rCallback);
/// @throws css::uno::RuntimeException
void ImplViewSignatures(const css::uno::Reference<css::embed::XStorage>& rxStorage,
@@ -195,6 +196,7 @@ public:
/// See sfx2::DigitalSignatures::SignDocumentContentAsync().
void SignDocumentContentAsync(const css::uno::Reference<css::embed::XStorage>& xStorage,
const css::uno::Reference<css::io::XStream>& xSignStream,
+ SfxViewShell* pViewShell,
const std::function<void(bool)>& rCallback) override;
/// See sfx2::DigitalSignatures::SignScriptingContentAsync().
void SignScriptingContentAsync(const css::uno::Reference<css::embed::XStorage>& xStorage,
@@ -364,17 +366,17 @@ void DocumentDigitalSignatures::ImplViewSignatures(
Reference< io::XStream > xStream;
if ( xSignStream.is() )
xStream.set( xSignStream, UNO_QUERY );
- ImplViewSignatures( rxStorage, xStream, eMode, bReadOnly, [](bool /*bSuccess*/){} );
+ ImplViewSignatures( rxStorage, xStream, eMode, bReadOnly, nullptr, [](bool /*bSuccess*/){} );
}
void DocumentDigitalSignatures::ImplViewSignatures(
const Reference< css::embed::XStorage >& rxStorage, const Reference< css::io::XStream >& xSignStream,
- DocumentSignatureMode eMode, bool bReadOnly, const std::function<void(bool)>& rCallback )
+ DocumentSignatureMode eMode, bool bReadOnly, SfxViewShell* pViewShell, const std::function<void(bool)>& rCallback )
{
bool bChanges = false;
auto xSignaturesDialog = std::make_shared<DigitalSignaturesDialog>(
Application::GetFrameWeld(mxParentWindow), mxCtx, eMode, bReadOnly, m_sODFVersion,
- m_bHasDocumentSignature);
+ m_bHasDocumentSignature, pViewShell);
bool bInit = xSignaturesDialog->Init();
SAL_WARN_IF( !bInit, "xmlsecurity.comp", "Error initializing security context!" );
if ( bInit )
@@ -773,10 +775,11 @@ bool DocumentDigitalSignatures::SignModelWithCertificate(
void DocumentDigitalSignatures::SignDocumentContentAsync(const css::uno::Reference<css::embed::XStorage>& rxStorage,
const css::uno::Reference<css::io::XStream>& xSignStream,
+ SfxViewShell* pViewShell,
const std::function<void(bool)>& rCallback)
{
OSL_ENSURE(!m_sODFVersion.isEmpty(), "DocumentDigitalSignatures: ODF Version not set, assuming minimum 1.2");
- ImplViewSignatures( rxStorage, xSignStream, DocumentSignatureMode::Content, false, rCallback );
+ ImplViewSignatures( rxStorage, xSignStream, DocumentSignatureMode::Content, false, pViewShell, rCallback );
}
void DocumentDigitalSignatures::SignScriptingContentAsync(
@@ -785,7 +788,7 @@ void DocumentDigitalSignatures::SignScriptingContentAsync(
{
OSL_ENSURE(!m_sODFVersion.isEmpty(),"DocumentDigitalSignatures: ODF Version not set, assuming minimum 1.2");
OSL_ENSURE(m_nArgumentsCount == 2, "DocumentDigitalSignatures: Service was not initialized properly");
- ImplViewSignatures( rxStorage, xSignStream, DocumentSignatureMode::Macros, false, rCallback );
+ ImplViewSignatures( rxStorage, xSignStream, DocumentSignatureMode::Macros, false, nullptr, rCallback );
}
void DocumentDigitalSignatures::SetSignScriptingContent(
diff --git a/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx b/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx
index b66158e454ed..4dcd9d387ccc 100644
--- a/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx
+++ b/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx
@@ -52,6 +52,7 @@
#include <utility>
#include <vcl/weld.hxx>
#include <vcl/svapp.hxx>
+#include <sfx2/viewsh.hxx>
#ifdef _WIN32
#include <o3tl/char16_t2wchar_t.hxx>
@@ -192,7 +193,8 @@ bool IsThereCertificateMgr()
DigitalSignaturesDialog::DigitalSignaturesDialog(
weld::Window* pParent,
const uno::Reference< uno::XComponentContext >& rxCtx, DocumentSignatureMode eMode,
- bool bReadOnly, OUString sODFVersion, bool bHasDocumentSignature)
+ bool bReadOnly, OUString sODFVersion, bool bHasDocumentSignature,
+ SfxViewShell* pViewShell)
: GenericDialogController(pParent, u"xmlsec/ui/digitalsignaturesdialog.ui"_ustr, u"DigitalSignaturesDialog"_ustr)
, maSignatureManager(rxCtx, eMode)
, m_sODFVersion (std::move(sODFVersion))
@@ -259,7 +261,11 @@ DigitalSignaturesDialog::DigitalSignaturesDialog(
if (comphelper::LibreOfficeKit::isActive())
{
- m_xAddBtn->hide();
+ // If the view has a signing certificate, then allow adding a signature.
+ if (!pViewShell || !pViewShell->GetSigningCertificate().is())
+ {
+ m_xAddBtn->hide();
+ }
m_xStartCertMgrBtn->hide();
}