diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2020-06-10 18:09:55 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2020-06-11 02:03:01 +0200 |
commit | a201ab6f47c2d5a7ba4c5f998b0aa231cae82010 (patch) | |
tree | a790e7571b32dd26f194671a182e98885cf214fd /sfx2/source/view/viewfrm.cxx | |
parent | f1e4d462c4a5686bccb3e7bfd615865c18c0efa6 (diff) |
sd signature line: inform infobar if a cert is already selected
In case a pdf is opened for signing, the infobar has a button to start
the signing. If a signature line is already inserted and the user picked
a certificate, then let's call the infobar button's action "finish
signing", since the signature list and the certificate chooser won't
appear in this case.
(The actual behavior when you click on the button is still unchanged,
though.)
Change-Id: I50ee2455c91cdee26612a6b8239dbb6772401877
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/96060
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
Diffstat (limited to 'sfx2/source/view/viewfrm.cxx')
-rw-r--r-- | sfx2/source/view/viewfrm.cxx | 108 |
1 files changed, 79 insertions, 29 deletions
diff --git a/sfx2/source/view/viewfrm.cxx b/sfx2/source/view/viewfrm.cxx index 190d10d7e323..e7bb57bc9c29 100644 --- a/sfx2/source/view/viewfrm.cxx +++ b/sfx2/source/view/viewfrm.cxx @@ -32,6 +32,7 @@ #include <com/sun/star/frame/XLoadable.hpp> #include <com/sun/star/frame/XLayoutManager.hpp> #include <com/sun/star/frame/XComponentLoader.hpp> +#include <com/sun/star/drawing/XShapes.hpp> #include <officecfg/Office/Common.hxx> #include <officecfg/Setup.hxx> #include <toolkit/helper/vclunohelper.hxx> @@ -88,6 +89,7 @@ #include <optional> #include <unotools/configmgr.hxx> +#include <comphelper/sequenceashashmap.hxx> using namespace ::com::sun::star; using namespace ::com::sun::star::uno; @@ -1219,6 +1221,82 @@ 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()); + } + + auto pInfoBar = AppendInfoBar("readonly", "", + SfxResId(bSignPDF ? STR_READONLY_PDF : STR_READONLY_DOCUMENT), + InfobarType::INFO); + if (pInfoBar) + { + if (bSignPDF) + { + // SID_SIGNPDF opened a read-write PDF + // read-only for signing purposes. + VclPtrInstance<PushButton> xSignButton(&GetWindow()); + if (bSignWithCert) + { + xSignButton->SetText(SfxResId(STR_READONLY_FINISH_SIGN)); + } + else + { + xSignButton->SetText(SfxResId(STR_READONLY_SIGN)); + } + + xSignButton->SetSizePixel(xSignButton->GetOptimalSize()); + xSignButton->SetClickHdl(LINK(this, SfxViewFrame, SignDocumentHandler)); + pInfoBar->addButton(xSignButton); + } + + bool showEditDocumentButton = true; + if (m_xObjSh->isEditDocLocked()) + showEditDocumentButton = false; + + if (showEditDocumentButton) + { + VclPtrInstance<PushButton> xBtn(&GetWindow()); + xBtn->SetText(SfxResId(STR_READONLY_EDIT)); + xBtn->SetSizePixel(xBtn->GetOptimalSize()); + xBtn->SetClickHdl(LINK(this, SfxViewFrame, SwitchReadOnlyHandler)); + pInfoBar->addButton(xBtn); + } + } +} + void SfxViewFrame::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) { if(m_pImpl->bIsDowning) @@ -1364,35 +1442,7 @@ void SfxViewFrame::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) ( m_xObjSh->GetCreateMode() != SfxObjectCreateMode::EMBEDDED || (( pVSh = m_xObjSh->GetViewShell()) && (pFSh = pVSh->GetFormShell()) && pFSh->IsDesignMode()))) { - bool bSignPDF = m_xObjSh->IsSignPDF(); - - auto pInfoBar = AppendInfoBar("readonly", "", SfxResId(bSignPDF ? STR_READONLY_PDF : STR_READONLY_DOCUMENT), InfobarType::INFO); - if (pInfoBar) - { - if (bSignPDF) - { - // SID_SIGNPDF opened a read-write PDF - // read-only for signing purposes. - VclPtrInstance<PushButton> xSignButton(&GetWindow()); - xSignButton->SetText(SfxResId(STR_READONLY_SIGN)); - xSignButton->SetSizePixel(xSignButton->GetOptimalSize()); - xSignButton->SetClickHdl(LINK(this, SfxViewFrame, SignDocumentHandler)); - pInfoBar->addButton(xSignButton); - } - - bool showEditDocumentButton = true; - if (m_xObjSh->isEditDocLocked()) - showEditDocumentButton = false; - - if (showEditDocumentButton) - { - VclPtrInstance<PushButton> xBtn(&GetWindow()); - xBtn->SetText(SfxResId(STR_READONLY_EDIT)); - xBtn->SetSizePixel(xBtn->GetOptimalSize()); - xBtn->SetClickHdl(LINK(this, SfxViewFrame, SwitchReadOnlyHandler)); - pInfoBar->addButton(xBtn); - } - } + AppendReadOnlyInfobar(); } if (vcl::CommandInfoProvider::GetModuleIdentifier(GetFrame().GetFrameInterface()) == "com.sun.star.text.TextDocument") |