diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2020-06-08 17:14:14 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2020-06-08 20:15:06 +0200 |
commit | 85b68061a5a904ca82e5db40600af741d30f0bb8 (patch) | |
tree | b011d29dcc93f6102009003a98e8d5ddbdb75e74 /svx | |
parent | e0f058bcd5e185b89e4b7c680a7901bc7eb2a790 (diff) |
sd signature line: extract part of signature line UI from cui to svx
So the "sign existing pdf" code in sd can reuse that.
Change-Id: If51fae203ed0c68ed8e5e63368e60ae1c705bade
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95841
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
Diffstat (limited to 'svx')
-rw-r--r-- | svx/Library_svx.mk | 1 | ||||
-rw-r--r-- | svx/source/dialog/signaturelinehelper.cxx | 124 |
2 files changed, 125 insertions, 0 deletions
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: */ |