include/sfx2/objsh.hxx | 2 sfx2/source/doc/objserv.cxx | 27 ++++++++++--- vcl/jsdialog/enabled.cxx | 3 - xmlsecurity/inc/digitalsignaturesdialog.hxx | 1 xmlsecurity/source/component/documentdigitalsignatures.cxx | 19 ++++++--- xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx | 14 ++++++ 6 files changed, 52 insertions(+), 14 deletions(-)
New commits: commit 0a298aab1296c65c7b362ec9c34cff9960e5a6cc Author: Szymon Kłos <szymon.k...@collabora.com> AuthorDate: Wed Oct 20 11:01:41 2021 +0200 Commit: Szymon Kłos <szymon.k...@collabora.com> CommitDate: Fri Oct 29 10:23:54 2021 +0200 jsdialog: enable Digital Signatures dialog In LOK case run it in the readonly mode. In readonly mode we can run it asynchronously. Change-Id: I721dd14fa23d4e30255dd976e0cc2a4f30470a3b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/124253 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Szymon Kłos <szymon.k...@collabora.com> diff --git a/include/sfx2/objsh.hxx b/include/sfx2/objsh.hxx index 9c331092bda1..9ac09d96a02a 100644 --- a/include/sfx2/objsh.hxx +++ b/include/sfx2/objsh.hxx @@ -348,7 +348,7 @@ public: /** Returns to if preparing was successful, else false. */ bool PrepareForSigning(weld::Window* pDialogParent); - bool CheckIsReadonly(bool bSignScriptingContent); + bool CheckIsReadonly(bool bSignScriptingContent, weld::Window* pDialogParent = nullptr); void RecheckSignature(bool bAlsoRecheckScriptingSignature); void AfterSigning(bool bSignSuccess, bool bSignScriptingContent); bool HasValidSignatures() const; diff --git a/sfx2/source/doc/objserv.cxx b/sfx2/source/doc/objserv.cxx index 619054815bff..6963f62cf6b5 100644 --- a/sfx2/source/doc/objserv.cxx +++ b/sfx2/source/doc/objserv.cxx @@ -1851,9 +1851,10 @@ void SfxObjectShell::AfterSigning(bool bSignSuccess, bool bSignScriptingContent) EnableSetModified(); } -bool SfxObjectShell::CheckIsReadonly(bool bSignScriptingContent) +bool SfxObjectShell::CheckIsReadonly(bool bSignScriptingContent, weld::Window* pDialogParent) { - if (GetMedium()->IsOriginallyReadOnly()) + // in LOK case we support only viewer / readonly mode so far + if (GetMedium()->IsOriginallyReadOnly() || comphelper::LibreOfficeKit::isActive()) { // If the file is physically read-only, we just show the existing signatures try @@ -1863,6 +1864,10 @@ bool SfxObjectShell::CheckIsReadonly(bool bSignScriptingContent) uno::Reference<security::XDocumentDigitalSignatures> xSigner( security::DocumentDigitalSignatures::createWithVersionAndValidSignature( comphelper::getProcessComponentContext(), aODFVersion, HasValidSignatures())); + + if (pDialogParent) + xSigner->setParentWindow(pDialogParent->GetXWindow()); + if (bSignScriptingContent) xSigner->showScriptingContentSignatures(GetMedium()->GetZipStorageToSign_Impl(), uno::Reference<io::XInputStream>()); @@ -1876,6 +1881,18 @@ bool SfxObjectShell::CheckIsReadonly(bool bSignScriptingContent) { std::unique_ptr<SvStream> pStream( utl::UcbStreamHelper::CreateStream(GetName(), StreamMode::READ)); + + if (!pStream) + { + pStream = utl::UcbStreamHelper::CreateStream(GetMedium()->GetName(), StreamMode::READ); + + if (!pStream) + { + SAL_WARN( "sfx.doc", "Couldn't use signing functionality!" ); + return true; + } + } + uno::Reference<io::XInputStream> xStream(new utl::OStreamWrapper(*pStream)); xSigner->showDocumentContentSignatures(uno::Reference<embed::XStorage>(), xStream); @@ -1908,7 +1925,7 @@ void SfxObjectShell::SignDocumentContent(weld::Window* pDialogParent) if (!PrepareForSigning(pDialogParent)) return; - if (CheckIsReadonly(false)) + if (CheckIsReadonly(false, pDialogParent)) return; bool bSignSuccess = GetMedium()->SignContents_Impl(pDialogParent, false, HasValidSignatures()); @@ -2005,7 +2022,7 @@ void SfxObjectShell::SignSignatureLine(weld::Window* pDialogParent, if (!PrepareForSigning(pDialogParent)) return; - if (CheckIsReadonly(false)) + if (CheckIsReadonly(false, pDialogParent)) return; bool bSignSuccess = GetMedium()->SignContents_Impl(pDialogParent, @@ -2030,7 +2047,7 @@ void SfxObjectShell::SignScriptingContent(weld::Window* pDialogParent) if (!PrepareForSigning(pDialogParent)) return; - if (CheckIsReadonly(true)) + if (CheckIsReadonly(true, pDialogParent)) return; bool bSignSuccess = GetMedium()->SignContents_Impl(pDialogParent, true, HasValidSignatures()); diff --git a/vcl/jsdialog/enabled.cxx b/vcl/jsdialog/enabled.cxx index a82f75ea6e30..99df1bf6fc3f 100644 --- a/vcl/jsdialog/enabled.cxx +++ b/vcl/jsdialog/enabled.cxx @@ -50,7 +50,8 @@ bool isBuilderEnabled(const OUString& rUIFile, bool bMobile) || rUIFile == "modules/scalc/ui/datafieldoptionsdialog.ui" || rUIFile == "svx/ui/fontworkgallerydialog.ui" || rUIFile == "cui/ui/macroselectordialog.ui" || rUIFile == "uui/ui/macrowarnmedium.ui" - || rUIFile == "modules/scalc/ui/textimportcsv.ui") + || rUIFile == "modules/scalc/ui/textimportcsv.ui" + || rUIFile == "xmlsec/ui/digitalsignaturesdialog.ui") { return true; } diff --git a/xmlsecurity/inc/digitalsignaturesdialog.hxx b/xmlsecurity/inc/digitalsignaturesdialog.hxx index 59e699db7b69..f6991bcb61b5 100644 --- a/xmlsecurity/inc/digitalsignaturesdialog.hxx +++ b/xmlsecurity/inc/digitalsignaturesdialog.hxx @@ -119,6 +119,7 @@ public: void SetSignatureStream( const css::uno::Reference < css::io::XStream >& rxStream ); // Execute the dialog... + void beforeRun(); short run() override; // Did signatures change? diff --git a/xmlsecurity/source/component/documentdigitalsignatures.cxx b/xmlsecurity/source/component/documentdigitalsignatures.cxx index a3ace6a7528a..84b9a80b0c72 100644 --- a/xmlsecurity/source/component/documentdigitalsignatures.cxx +++ b/xmlsecurity/source/component/documentdigitalsignatures.cxx @@ -429,19 +429,26 @@ bool DocumentDigitalSignatures::ImplViewSignatures( DocumentSignatureMode eMode, bool bReadOnly ) { bool bChanges = false; - DigitalSignaturesDialog aSignaturesDialog( + auto xSignaturesDialog = std::make_shared<DigitalSignaturesDialog>( Application::GetFrameWeld(mxParentWindow), mxCtx, eMode, bReadOnly, m_sODFVersion, m_bHasDocumentSignature); - bool bInit = aSignaturesDialog.Init(); + bool bInit = xSignaturesDialog->Init(); SAL_WARN_IF( !bInit, "xmlsecurity.comp", "Error initializing security context!" ); if ( bInit ) { - aSignaturesDialog.SetStorage(rxStorage); + xSignaturesDialog->SetStorage(rxStorage); - aSignaturesDialog.SetSignatureStream( xSignStream ); - if (aSignaturesDialog.run() == RET_OK) + xSignaturesDialog->SetSignatureStream( xSignStream ); + + if (bReadOnly) + { + xSignaturesDialog->beforeRun(); + weld::DialogController::runAsync(xSignaturesDialog, [] (sal_Int32) {}); + return false; + } + else if (xSignaturesDialog->run() == RET_OK) { - if (aSignaturesDialog.SignaturesChanged()) + if (xSignaturesDialog->SignaturesChanged()) { bChanges = true; // If we have a storage and no stream, we are responsible for commit diff --git a/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx b/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx index 18ccaf2d2166..dfd40c2efbd3 100644 --- a/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx +++ b/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx @@ -52,6 +52,7 @@ #include <bitmaps.hlst> #include <strings.hrc> #include <resourcemanager.hxx> +#include <comphelper/lok.hxx> #include <comphelper/xmlsechelper.hxx> #include <comphelper/processfactory.hxx> @@ -188,6 +189,13 @@ DigitalSignaturesDialog::DigitalSignaturesDialog( m_xHintPackageFT->show(); break; } + + if (comphelper::LibreOfficeKit::isActive()) + { + m_xAddBtn->hide(); + m_xRemoveBtn->hide(); + m_xStartCertMgrBtn->hide(); + } } DigitalSignaturesDialog::~DigitalSignaturesDialog() @@ -308,7 +316,7 @@ bool DigitalSignaturesDialog::canRemove() return (bRet && canAddRemove()); } -short DigitalSignaturesDialog::run() +void DigitalSignaturesDialog::beforeRun() { // Verify Signatures and add certificates to ListBox... mbVerifySignatures = true; @@ -333,7 +341,11 @@ short DigitalSignaturesDialog::run() // Only verify once, content will not change. // But for refreshing signature information, StartVerifySignatureHdl will be called after each add/remove mbVerifySignatures = false; +} +short DigitalSignaturesDialog::run() +{ + beforeRun(); return GenericDialogController::run(); }