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 f5e65834c77162ac12d8bbcec82972e055aa3084 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 14:47:30 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/+/124058 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 ee3d3d6eefb7..872127048db1 100644 --- a/include/sfx2/objsh.hxx +++ b/include/sfx2/objsh.hxx @@ -350,7 +350,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 147d4a9a74a7..2a69aeb95510 100644 --- a/sfx2/source/doc/objserv.cxx +++ b/sfx2/source/doc/objserv.cxx @@ -1877,9 +1877,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 @@ -1889,6 +1890,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>()); @@ -1902,6 +1907,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); @@ -1934,7 +1951,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()); @@ -2031,7 +2048,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, @@ -2056,7 +2073,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 e8245c7ea674..c071cda333c5 100644 --- a/vcl/jsdialog/enabled.cxx +++ b/vcl/jsdialog/enabled.cxx @@ -52,7 +52,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 f062c7da9d8e..f49af516ba00 100644 --- a/xmlsecurity/inc/digitalsignaturesdialog.hxx +++ b/xmlsecurity/inc/digitalsignaturesdialog.hxx @@ -112,6 +112,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 b9066ea92cac..b4d8d7234a8c 100644 --- a/xmlsecurity/source/component/documentdigitalsignatures.cxx +++ b/xmlsecurity/source/component/documentdigitalsignatures.cxx @@ -433,19 +433,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 7c6ab0ef3be1..ac31d5ba3875 100644 --- a/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx +++ b/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx @@ -57,6 +57,7 @@ #include <bitmaps.hlst> #include <strings.hrc> #include <resourcemanager.hxx> +#include <comphelper/lok.hxx> #include <comphelper/xmlsechelper.hxx> #include <comphelper/processfactory.hxx> @@ -193,6 +194,13 @@ DigitalSignaturesDialog::DigitalSignaturesDialog( m_xHintPackageFT->show(); break; } + + if (comphelper::LibreOfficeKit::isActive()) + { + m_xAddBtn->hide(); + m_xRemoveBtn->hide(); + m_xStartCertMgrBtn->hide(); + } } DigitalSignaturesDialog::~DigitalSignaturesDialog() @@ -313,7 +321,7 @@ bool DigitalSignaturesDialog::canRemove() return (bRet && canAddRemove()); } -short DigitalSignaturesDialog::run() +void DigitalSignaturesDialog::beforeRun() { // Verify Signatures and add certificates to ListBox... mbVerifySignatures = true; @@ -338,7 +346,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(); }