diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2020-06-15 09:54:26 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2020-06-15 12:19:16 +0200 |
commit | 5e040ad05012f91d0ea5116659e58222eea53668 (patch) | |
tree | 1d58806601fb71a6042ec1e12bacf51b77d23deb /sfx2 | |
parent | d570062ff9899e78553bfbe412bdf88ff62a5396 (diff) |
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.
Change-Id: I096210fe505b4c9eafb56eae6c4706e454bac45c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/96317
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
Diffstat (limited to 'sfx2')
-rw-r--r-- | sfx2/source/doc/objserv.cxx | 50 | ||||
-rw-r--r-- | sfx2/source/view/viewfrm.cxx | 32 |
2 files changed, 52 insertions, 30 deletions
diff --git a/sfx2/source/doc/objserv.cxx b/sfx2/source/doc/objserv.cxx index af439df22a4d..fcea15d3ee22 100644 --- a/sfx2/source/doc/objserv.cxx +++ b/sfx2/source/doc/objserv.cxx @@ -101,6 +101,7 @@ #include <cppuhelper/implbase.hxx> #include <unotools/ucbstreamhelper.hxx> #include <unotools/streamwrap.hxx> +#include <comphelper/sequenceashashmap.hxx> #include <autoredactdialog.hxx> @@ -405,6 +406,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(); @@ -422,7 +453,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 e7bb57bc9c29..027fb8285c08 100644 --- a/sfx2/source/view/viewfrm.cxx +++ b/sfx2/source/view/viewfrm.cxx @@ -1221,41 +1221,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", "", |