diff options
-rw-r--r-- | cui/source/dialogs/SignSignatureLineDialog.cxx | 48 | ||||
-rw-r--r-- | cui/source/dialogs/SignatureLineDialog.cxx | 14 | ||||
-rw-r--r-- | cui/source/dialogs/SignatureLineDialogBase.cxx | 14 | ||||
-rw-r--r-- | cui/source/inc/SignatureLineDialogBase.hxx | 1 | ||||
-rw-r--r-- | include/svx/signaturelinehelper.hxx | 59 | ||||
-rw-r--r-- | svx/Library_svx.mk | 1 | ||||
-rw-r--r-- | svx/source/dialog/signaturelinehelper.cxx | 124 |
7 files changed, 195 insertions, 66 deletions
diff --git a/cui/source/dialogs/SignSignatureLineDialog.cxx b/cui/source/dialogs/SignSignatureLineDialog.cxx index 10f80f72983d..80e8f9815053 100644 --- a/cui/source/dialogs/SignSignatureLineDialog.cxx +++ b/cui/source/dialogs/SignSignatureLineDialog.cxx @@ -31,6 +31,7 @@ #include <utility> #include <vcl/graph.hxx> #include <vcl/weld.hxx> +#include <svx/signaturelinehelper.hxx> #include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/graphic/GraphicProvider.hpp> @@ -167,33 +168,14 @@ IMPL_LINK_NOARG(SignSignatureLineDialog, chooseCertificate, weld::Button&, void) if (!pShell->PrepareForSigning(m_xDialog.get())) return; - Reference<XDocumentDigitalSignatures> xSigner; - if (pShell->GetMedium()->GetFilter()->IsAlienFormat()) - { - xSigner - = DocumentDigitalSignatures::createDefault(comphelper::getProcessComponentContext()); - } - else - { - OUString const aODFVersion( - comphelper::OStorageHelper::GetODFVersionFromStorage(pShell->GetStorage())); - xSigner = DocumentDigitalSignatures::createWithVersion( - comphelper::getProcessComponentContext(), aODFVersion); - } - xSigner->setParentWindow(m_xDialog->GetXWindow()); - OUString aDescription; - CertificateKind certificateKind = CertificateKind_NONE; - // When signing ooxml, we only want X.509 certificates - if (pShell->GetMedium()->GetFilter()->IsAlienFormat()) - certificateKind = CertificateKind_X509; Reference<XCertificate> xSignCertificate - = xSigner->selectSigningCertificateWithType(certificateKind, aDescription); + = svx::SignatureLineHelper::getSignatureCertificate(pShell, m_xDialog.get()); if (xSignCertificate.is()) { m_xSelectedCertifate = xSignCertificate; - m_xBtnChooseCertificate->set_label(xmlsec::GetContentPart( - xSignCertificate->getSubjectName(), xSignCertificate->getCertificateKind())); + m_xBtnChooseCertificate->set_label( + svx::SignatureLineHelper::getSignerName(xSignCertificate)); } ValidateFields(); } @@ -229,15 +211,13 @@ void SignSignatureLineDialog::Apply() css::uno::Reference<css::graphic::XGraphic> SignSignatureLineDialog::getSignedGraphic(bool bValid) { // Read svg and replace placeholder texts - OUString aSvgImage(getSignatureImage()); + OUString aSvgImage(svx::SignatureLineHelper::getSignatureImage()); aSvgImage = aSvgImage.replaceAll("[SIGNER_NAME]", getCDataString(m_aSuggestedSignerName)); aSvgImage = aSvgImage.replaceAll("[SIGNER_TITLE]", getCDataString(m_aSuggestedSignerTitle)); OUString aIssuerLine = CuiResId(RID_SVXSTR_SIGNATURELINE_SIGNED_BY) - .replaceFirst("%1", - xmlsec::GetContentPart(m_xSelectedCertifate->getSubjectName(), - m_xSelectedCertifate->getCertificateKind())); + .replaceFirst("%1", svx::SignatureLineHelper::getSignerName(m_xSelectedCertifate)); aSvgImage = aSvgImage.replaceAll("[SIGNED_BY]", getCDataString(aIssuerLine)); if (bValid) aSvgImage = aSvgImage.replaceAll("[INVALID_SIGNATURE]", ""); @@ -245,10 +225,7 @@ css::uno::Reference<css::graphic::XGraphic> SignSignatureLineDialog::getSignedGr OUString aDate; if (m_bShowSignDate && bValid) { - const SvtSysLocale aSysLocale; - const LocaleDataWrapper& rLocaleData = aSysLocale.GetLocaleData(); - Date aDateTime(Date::SYSTEM); - aDate = rLocaleData.getDate(aDateTime); + aDate = svx::SignatureLineHelper::getLocalizedDate(); } aSvgImage = aSvgImage.replaceAll("[DATE]", aDate); @@ -278,16 +255,7 @@ css::uno::Reference<css::graphic::XGraphic> SignSignatureLineDialog::getSignedGr } // Create graphic - SvMemoryStream aSvgStream(4096, 4096); - aSvgStream.WriteOString(OUStringToOString(aSvgImage, RTL_TEXTENCODING_UTF8)); - Reference<XInputStream> xInputStream(new utl::OSeekableInputStreamWrapper(aSvgStream)); - Reference<XComponentContext> xContext(comphelper::getProcessComponentContext()); - Reference<XGraphicProvider> xProvider = css::graphic::GraphicProvider::create(xContext); - - Sequence<PropertyValue> aMediaProperties(1); - aMediaProperties[0].Name = "InputStream"; - aMediaProperties[0].Value <<= xInputStream; - return xProvider->queryGraphic(aMediaProperties); + return svx::SignatureLineHelper::importSVG(aSvgImage); } /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/cui/source/dialogs/SignatureLineDialog.cxx b/cui/source/dialogs/SignatureLineDialog.cxx index e295e288e388..7f6caabc49d9 100644 --- a/cui/source/dialogs/SignatureLineDialog.cxx +++ b/cui/source/dialogs/SignatureLineDialog.cxx @@ -15,6 +15,7 @@ #include <unotools/streamwrap.hxx> #include <utility> #include <vcl/weld.hxx> +#include <svx/signaturelinehelper.hxx> #include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/drawing/XDrawPageSupplier.hpp> @@ -111,7 +112,7 @@ void SignatureLineDialog::Apply() bool bShowSignDate(m_xCheckboxShowSignDate->get_active()); // Read svg and replace placeholder texts - OUString aSvgImage(getSignatureImage()); + OUString aSvgImage(svx::SignatureLineHelper::getSignatureImage()); aSvgImage = aSvgImage.replaceAll("[SIGNER_NAME]", getCDataString(aSignerName)); aSvgImage = aSvgImage.replaceAll("[SIGNER_TITLE]", getCDataString(aSignerTitle)); @@ -122,16 +123,7 @@ void SignatureLineDialog::Apply() aSvgImage = aSvgImage.replaceAll("[DATE]", ""); // Insert/Update graphic - SvMemoryStream aSvgStream(4096, 4096); - aSvgStream.WriteOString(OUStringToOString(aSvgImage, RTL_TEXTENCODING_UTF8)); - Reference<XInputStream> xInputStream(new utl::OSeekableInputStreamWrapper(aSvgStream)); - Reference<XComponentContext> xContext(comphelper::getProcessComponentContext()); - Reference<XGraphicProvider> xProvider = css::graphic::GraphicProvider::create(xContext); - - Sequence<PropertyValue> aMediaProperties(1); - aMediaProperties[0].Name = "InputStream"; - aMediaProperties[0].Value <<= xInputStream; - Reference<XGraphic> xGraphic(xProvider->queryGraphic(aMediaProperties)); + Reference<XGraphic> xGraphic = svx::SignatureLineHelper::importSVG(aSvgImage); bool bIsExistingSignatureLine = m_xExistingShapeProperties.is(); Reference<XPropertySet> xShapeProps; diff --git a/cui/source/dialogs/SignatureLineDialogBase.cxx b/cui/source/dialogs/SignatureLineDialogBase.cxx index d72fa7b93f1d..50214308fe10 100644 --- a/cui/source/dialogs/SignatureLineDialogBase.cxx +++ b/cui/source/dialogs/SignatureLineDialogBase.cxx @@ -41,18 +41,4 @@ OUString SignatureLineDialogBase::getCDataString(const OUString& rString) return "<![CDATA[" + rString + "]]>"; } -OUString SignatureLineDialogBase::getSignatureImage() -{ - OUString aPath("$BRAND_BASE_DIR/" LIBO_SHARE_FOLDER "/filter/signature-line.svg"); - rtl::Bootstrap::expandMacros(aPath); - SvFileStream aStream(aPath, StreamMode::READ); - if (aStream.GetError() != ERRCODE_NONE) - { - SAL_WARN("cui.dialogs", "failed to open signature-line.svg"); - } - - OString const svg = read_uInt8s_ToOString(aStream, aStream.remainingSize()); - return OUString::fromUtf8(svg); -} - /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/cui/source/inc/SignatureLineDialogBase.hxx b/cui/source/inc/SignatureLineDialogBase.hxx index 2e046d945d80..3b065fe87838 100644 --- a/cui/source/inc/SignatureLineDialogBase.hxx +++ b/cui/source/inc/SignatureLineDialogBase.hxx @@ -24,7 +24,6 @@ public: protected: css::uno::Reference<css::frame::XModel> m_xModel; - static OUString getSignatureImage(); virtual void Apply() = 0; static OUString getCDataString(const OUString& rString); }; diff --git a/include/svx/signaturelinehelper.hxx b/include/svx/signaturelinehelper.hxx new file mode 100644 index 000000000000..4cdb40651479 --- /dev/null +++ b/include/svx/signaturelinehelper.hxx @@ -0,0 +1,59 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef INCLUDED_SVX_SIGNATURELINEHELPER_HXX +#define INCLUDED_SVX_SIGNATURELINEHELPER_HXX + +#include <rtl/ustring.hxx> +#include <svx/svxdllapi.h> + +#include <com/sun/star/awt/XWindow.hpp> +#include <com/sun/star/graphic/XGraphic.hpp> +#include <com/sun/star/security/XCertificate.hpp> + +namespace weld +{ +class Window; +} +class SfxObjectShell; + +namespace svx::SignatureLineHelper +{ +/** + * Returns an SVG template. Once placeholders are replaced with real content, the result can be used + * as the graphic of a signature line shape. + */ +SVX_DLLPUBLIC OUString getSignatureImage(const OUString& rType = OUString()); + +/** + * Choose a signature for signature line purposes. + */ +SVX_DLLPUBLIC css::uno::Reference<css::security::XCertificate> +getSignatureCertificate(SfxObjectShell* pShell, weld::Window* pParent); + +/** + * Get a signer name out of a certificate. + */ +SVX_DLLPUBLIC OUString +getSignerName(const css::uno::Reference<css::security::XCertificate>& xCertificate); + +/** + * Gets a localized date string. + */ +SVX_DLLPUBLIC OUString getLocalizedDate(); + +/** + * Interprets rSVG as a graphic and gives back the resuling UNO wrapper. + */ +SVX_DLLPUBLIC css::uno::Reference<css::graphic::XGraphic> importSVG(const OUString& rSVG); +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svx/Library_svx.mk b/svx/Library_svx.mk index a378df63702d..ff2b06626b58 100644 --- a/svx/Library_svx.mk +++ b/svx/Library_svx.mk @@ -158,6 +158,7 @@ $(eval $(call gb_Library_add_exception_objects,svx,\ svx/source/dialog/txencbox \ svx/source/dialog/txenctab \ svx/source/dialog/weldeditview \ + svx/source/dialog/signaturelinehelper \ svx/source/engine3d/float3d \ svx/source/items/algitem \ svx/source/items/autoformathelper \ diff --git a/svx/source/dialog/signaturelinehelper.cxx b/svx/source/dialog/signaturelinehelper.cxx new file mode 100644 index 000000000000..69010ec09b10 --- /dev/null +++ b/svx/source/dialog/signaturelinehelper.cxx @@ -0,0 +1,124 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <svx/signaturelinehelper.hxx> + +#include <com/sun/star/graphic/GraphicProvider.hpp> +#include <com/sun/star/security/DocumentDigitalSignatures.hpp> +#include <com/sun/star/security/XCertificate.hpp> + +#include <comphelper/processfactory.hxx> +#include <comphelper/storagehelper.hxx> +#include <comphelper/xmlsechelper.hxx> +#include <config_folders.h> +#include <rtl/bootstrap.hxx> +#include <sal/log.hxx> +#include <sfx2/docfile.hxx> +#include <sfx2/docfilt.hxx> +#include <sfx2/objsh.hxx> +#include <tools/stream.hxx> +#include <unotools/localedatawrapper.hxx> +#include <unotools/streamwrap.hxx> +#include <unotools/syslocale.hxx> +#include <vcl/weld.hxx> + +using namespace com::sun::star; + +namespace svx::SignatureLineHelper +{ +OUString getSignatureImage(const OUString& rType) +{ + OUString aType = rType; + if (aType.isEmpty()) + { + aType = "signature-line.svg"; + } + OUString aPath("$BRAND_BASE_DIR/" LIBO_SHARE_FOLDER "/filter/" + aType); + rtl::Bootstrap::expandMacros(aPath); + SvFileStream aStream(aPath, StreamMode::READ); + if (aStream.GetError() != ERRCODE_NONE) + { + SAL_WARN("cui.dialogs", "failed to open " << aType); + } + + OString const svg = read_uInt8s_ToOString(aStream, aStream.remainingSize()); + return OUString::fromUtf8(svg); +} + +uno::Reference<security::XCertificate> getSignatureCertificate(SfxObjectShell* pShell, + weld::Window* pParent) +{ + if (!pShell) + { + return uno::Reference<security::XCertificate>(); + } + + if (!pParent) + { + return uno::Reference<security::XCertificate>(); + } + + uno::Reference<security::XDocumentDigitalSignatures> xSigner; + if (pShell->GetMedium()->GetFilter()->IsAlienFormat()) + { + xSigner = security::DocumentDigitalSignatures::createDefault( + comphelper::getProcessComponentContext()); + } + else + { + OUString const aODFVersion( + comphelper::OStorageHelper::GetODFVersionFromStorage(pShell->GetStorage())); + xSigner = security::DocumentDigitalSignatures::createWithVersion( + comphelper::getProcessComponentContext(), aODFVersion); + } + xSigner->setParentWindow(pParent->GetXWindow()); + OUString aDescription; + security::CertificateKind certificateKind = security::CertificateKind_NONE; + // When signing ooxml, we only want X.509 certificates + if (pShell->GetMedium()->GetFilter()->IsAlienFormat()) + { + certificateKind = security::CertificateKind_X509; + } + uno::Reference<security::XCertificate> xSignCertificate + = xSigner->selectSigningCertificateWithType(certificateKind, aDescription); + return xSignCertificate; +} + +OUString getSignerName(const css::uno::Reference<css::security::XCertificate>& xCertificate) +{ + return comphelper::xmlsec::GetContentPart(xCertificate->getSubjectName(), + xCertificate->getCertificateKind()); +} + +OUString getLocalizedDate() +{ + const SvtSysLocale aSysLocale; + const LocaleDataWrapper& rLocaleData = aSysLocale.GetLocaleData(); + Date aDateTime(Date::SYSTEM); + return rLocaleData.getDate(aDateTime); +} + +uno::Reference<graphic::XGraphic> importSVG(const OUString& rSVG) +{ + SvMemoryStream aSvgStream(4096, 4096); + aSvgStream.WriteOString(OUStringToOString(rSVG, RTL_TEXTENCODING_UTF8)); + uno::Reference<io::XInputStream> xInputStream(new utl::OSeekableInputStreamWrapper(aSvgStream)); + uno::Reference<uno::XComponentContext> xContext(comphelper::getProcessComponentContext()); + uno::Reference<graphic::XGraphicProvider> xProvider + = graphic::GraphicProvider::create(xContext); + + uno::Sequence<beans::PropertyValue> aMediaProperties(1); + aMediaProperties[0].Name = "InputStream"; + aMediaProperties[0].Value <<= xInputStream; + uno::Reference<graphic::XGraphic> xGraphic(xProvider->queryGraphic(aMediaProperties)); + return xGraphic; +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |