From 74918534ee4243d2849f74c4eaf91eb610999413 Mon Sep 17 00:00:00 2001 From: Samuel Mehrbrodt Date: Thu, 28 Jul 2022 14:01:45 +0200 Subject: Add 'JobName' to PrintOptions Allow users to specify a job name which is sent to the printer (by default this is the current document name). Usage: Sub PrintWithCustomJobname Dim mPOpts(1) As New com.sun.star.beans.PropertyValue mPOpts(0).Name = "JobName" mPOpts(0).Value = "My Job Name" ThisComponent.Print(mPOpts()) End Sub Change-Id: Id7c1c0da7f581b1c050bb3e6d61dd01b7e8205f0 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137562 Tested-by: Jenkins Reviewed-by: Thorsten Behrens --- sfx2/source/doc/printhelper.cxx | 9 +++++++++ sfx2/source/view/viewprn.cxx | 12 ++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) (limited to 'sfx2') diff --git a/sfx2/source/doc/printhelper.cxx b/sfx2/source/doc/printhelper.cxx index 64f17e15bd37..1557cc567b2f 100644 --- a/sfx2/source/doc/printhelper.cxx +++ b/sfx2/source/doc/printhelper.cxx @@ -694,6 +694,15 @@ void SAL_CALL SfxPrintHelper::print(const uno::Sequence< beans::PropertyValue >& pCheckedArgs[nProps++].Value <<= bTemp; } + else if ( rProp.Name == "JobName" ) + { + OUString sTemp; + if( !(rProp.Value >>= sTemp) ) + throw css::lang::IllegalArgumentException(); + pCheckedArgs[nProps].Name = rProp.Name; + pCheckedArgs[nProps++].Value <<= sTemp; + } + // Pages-Property else if ( rProp.Name == "Pages" ) { diff --git a/sfx2/source/view/viewprn.cxx b/sfx2/source/view/viewprn.cxx index bdc85c81a8ee..9476dd22edec 100644 --- a/sfx2/source/view/viewprn.cxx +++ b/sfx2/source/view/viewprn.cxx @@ -604,10 +604,14 @@ void SfxViewShell::StartPrint( const uno::Sequence < beans::PropertyValue >& rPr )); pImpl->m_xPrinterController = xNewController; - SfxObjectShell *pObjShell = GetObjectShell(); - xNewController->setValue( "JobName", - Any( pObjShell->GetTitle(1) ) ); - xNewController->setPrinterModified( mbPrinterSettingsModified ); + // When no JobName was specified via com::sun::star::view::PrintOptions::JobName , + // use the document title as default job name + css::beans::PropertyValue* pJobNameVal = xNewController->getValue("JobName"); + if (!pJobNameVal) + { + xNewController->setValue("JobName", Any(GetObjectShell()->GetTitle(1))); + xNewController->setPrinterModified(mbPrinterSettingsModified); + } } void SfxViewShell::ExecPrint( const uno::Sequence < beans::PropertyValue >& rProps, bool bIsAPI, bool bIsDirect ) -- cgit