include/sfx2/objsh.hxx | 3 ++ sfx2/source/doc/objserv.cxx | 50 ++++++++++++++++++++++++++++++++++++++++++- sfx2/source/view/viewfrm.cxx | 32 ++------------------------- 3 files changed, 55 insertions(+), 30 deletions(-)
New commits: commit f03e70884a236200c4a6e52b5ccdbec40f552fd0 Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Mon Jun 15 09:54:26 2020 +0200 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Fri Jun 26 08:55:32 2020 +0200 sd signature line: create signature with pre-selected cert, if available This makes the "finish signing" button do what it says. The signature line shape is not yet in the output, though. (cherry picked from commit 5e040ad05012f91d0ea5116659e58222eea53668) Change-Id: I096210fe505b4c9eafb56eae6c4706e454bac45c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/97181 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Miklos Vajna <vmik...@collabora.com> diff --git a/include/sfx2/objsh.hxx b/include/sfx2/objsh.hxx index b3627a6b8788..4c0ea7f22f09 100644 --- a/include/sfx2/objsh.hxx +++ b/include/sfx2/objsh.hxx @@ -761,6 +761,9 @@ public: /// Is this read-only object shell opened via .uno:SignPDF? bool IsSignPDF() const; + + /// Gets the certificate that is already picked by the user but not yet used for signing. + css::uno::Reference<css::security::XCertificate> GetSignPDFCertificate() const; }; #define SFX_GLOBAL_CLASSID \ diff --git a/sfx2/source/doc/objserv.cxx b/sfx2/source/doc/objserv.cxx index 96c23314a5cb..09e4bba8bde8 100644 --- a/sfx2/source/doc/objserv.cxx +++ b/sfx2/source/doc/objserv.cxx @@ -122,6 +122,7 @@ #include <cppuhelper/implbase.hxx> #include <unotools/ucbstreamhelper.hxx> #include <unotools/streamwrap.hxx> +#include <comphelper/sequenceashashmap.hxx> #include <svx/unoshape.hxx> #include <svx/xlineit0.hxx> @@ -423,6 +424,36 @@ bool SfxObjectShell::IsSignPDF() const return false; } +uno::Reference<security::XCertificate> SfxObjectShell::GetSignPDFCertificate() const +{ + uno::Reference<frame::XModel> xModel = GetBaseModel(); + if (!xModel.is()) + { + return uno::Reference<security::XCertificate>(); + } + + uno::Reference<drawing::XShapes> xShapes(xModel->getCurrentSelection(), uno::UNO_QUERY); + if (!xShapes.is() || xShapes->getCount() < 1) + { + return uno::Reference<security::XCertificate>(); + } + + uno::Reference<beans::XPropertySet> xShapeProps(xShapes->getByIndex(0), uno::UNO_QUERY); + if (!xShapeProps.is()) + { + return uno::Reference<security::XCertificate>(); + } + + comphelper::SequenceAsHashMap aMap(xShapeProps->getPropertyValue("InteropGrabBag")); + auto it = aMap.find("SignatureCertificate"); + if (it == aMap.end()) + { + return uno::Reference<security::XCertificate>(); + } + + return uno::Reference<security::XCertificate>(it->second, uno::UNO_QUERY); +} + void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq) { weld::Window* pDialogParent = rReq.GetFrameWeld(); @@ -440,7 +471,24 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq) if( SID_SIGNATURE == nId || SID_MACRO_SIGNATURE == nId ) { if ( QueryHiddenInformation( HiddenWarningFact::WhenSigning, nullptr ) == RET_YES ) - ( SID_SIGNATURE == nId ) ? SignDocumentContent(pDialogParent) : SignScriptingContent(pDialogParent); + { + if (SID_SIGNATURE == nId) + { + uno::Reference<security::XCertificate> xCertificate = GetSignPDFCertificate(); + if (xCertificate.is()) + { + SignDocumentContentUsingCertificate(xCertificate); + } + else + { + SignDocumentContent(pDialogParent); + } + } + else + { + SignScriptingContent(pDialogParent); + } + } return; } diff --git a/sfx2/source/view/viewfrm.cxx b/sfx2/source/view/viewfrm.cxx index 8d0d94a6181d..75ec246b4fb6 100644 --- a/sfx2/source/view/viewfrm.cxx +++ b/sfx2/source/view/viewfrm.cxx @@ -1238,41 +1238,15 @@ const SvBorder& SfxViewFrame::GetBorderPixelImpl() const return m_pImpl->aBorder; } -namespace -{ -/// Does the current selection have a shape with an associated signing certificate? -bool IsSignWithCert(SfxViewShell* pViewShell) -{ - uno::Reference<frame::XModel> xModel = pViewShell->GetCurrentDocument(); - if (!xModel.is()) - { - return false; - } - - uno::Reference<drawing::XShapes> xShapes(xModel->getCurrentSelection(), uno::UNO_QUERY); - if (!xShapes.is() || xShapes->getCount() < 1) - { - return false; - } - - uno::Reference<beans::XPropertySet> xShapeProps(xShapes->getByIndex(0), uno::UNO_QUERY); - if (!xShapeProps.is()) - { - return false; - } - - comphelper::SequenceAsHashMap aMap(xShapeProps->getPropertyValue("InteropGrabBag")); - return aMap.find("SignatureCertificate") != aMap.end(); -} -} - void SfxViewFrame::AppendReadOnlyInfobar() { bool bSignPDF = m_xObjSh->IsSignPDF(); bool bSignWithCert = false; if (bSignPDF) { - bSignWithCert = IsSignWithCert(GetViewShell()); + SfxObjectShell* pObjectShell = GetObjectShell(); + uno::Reference<security::XCertificate> xCertificate = pObjectShell->GetSignPDFCertificate(); + bSignWithCert = xCertificate.is(); } auto pInfoBar = AppendInfoBar("readonly", "", _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits