[Libreoffice-commits] core.git: include/sfx2 sfx2/source
Miklos Vajna (via logerrit)
logerrit at kemper.freedesktop.org
Mon Jun 15 10:19:54 UTC 2020
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 5e040ad05012f91d0ea5116659e58222eea53668
Author: Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Mon Jun 15 09:54:26 2020 +0200
Commit: Miklos Vajna <vmiklos at collabora.com>
CommitDate: Mon Jun 15 12:19:16 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.
Change-Id: I096210fe505b4c9eafb56eae6c4706e454bac45c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/96317
Reviewed-by: Miklos Vajna <vmiklos at collabora.com>
Tested-by: Jenkins
diff --git a/include/sfx2/objsh.hxx b/include/sfx2/objsh.hxx
index 97622b799852..1bc1f5352c2c 100644
--- a/include/sfx2/objsh.hxx
+++ b/include/sfx2/objsh.hxx
@@ -772,6 +772,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 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", "",
More information about the Libreoffice-commits
mailing list