sfx2/source/doc/guisaveas.cxx | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+)
New commits: commit 99a88c9e55872214ce01d89447d18708e47e956b Author: Justin Luth <jl...@mail.com> AuthorDate: Thu May 11 15:28:55 2023 -0400 Commit: Justin Luth <jl...@mail.com> CommitDate: Fri May 12 02:00:56 2023 +0200 tdf#134901: update print statistics on PDF export From a modern point of view, a PDF export could be considered a print event. If one agrees with that point of view, then updating the print statistics whenever a PDF is generated makes sense. That is what the bug report requested, and what this patch does. That is what MS Word does also. Downsides: -there is no setting for a user to disagree with this bug's POV. -doesn't work for Send - Email a PDF -open a doc: export to PDF: close -> "Do you want to save changes?" -I tested on --headless --convert-to pdf -> no problems -a setting does exist to avoid modified status by printing. -that setting defaults to avoid modifying the status - YAY! -the print date is changed even if the export fails -NEEDS to be changed before export: time needed in PDF itself -didn't seem important enough to waste the time coding it. -for real printers the old print date is restored on failure. Change-Id: I0d1387c1c2c925f3be772c5bdad7187f9f6a4d7c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151682 Reviewed-by: Justin Luth <jl...@mail.com> Tested-by: Jenkins Tested-by: Justin Luth <jl...@mail.com> diff --git a/sfx2/source/doc/guisaveas.cxx b/sfx2/source/doc/guisaveas.cxx index 3785585b44d8..b6d4ce61d8a6 100644 --- a/sfx2/source/doc/guisaveas.cxx +++ b/sfx2/source/doc/guisaveas.cxx @@ -70,7 +70,9 @@ #include <vcl/weld.hxx> #include <o3tl/char16_t2wchar_t.hxx> #include <unotools/tempfile.hxx> +#include <unotools/useroptions.hxx> +#include <sfx2/objsh.hxx> #include <sfx2/sfxsids.hrc> #include <sfx2/strings.hrc> #include <sfx2/sfxresid.hxx> @@ -1732,6 +1734,38 @@ bool SfxStoringHelper::FinishGUIStoreModel(::comphelper::SequenceAsHashMap::cons DocumentSettingsGuard aSettingsGuard( aModelData.GetModel(), aModelData.IsRecommendReadOnly(), nStoreMode & EXPORT_REQUESTED ); + // Treat attempted PDF export like a print: update document print statistics + if ((nStoreMode & PDFEXPORT_REQUESTED) && SfxViewShell::Current()) + { + SfxObjectShell* pDocShell = SfxViewShell::Current()->GetObjectShell(); + const bool bWasEnableSetModified = pDocShell && pDocShell->IsEnableSetModified(); + bool bResetESM = false; + + if (bWasEnableSetModified + && !officecfg::Office::Common::Print::PrintingModifiesDocument::get()) + { + pDocShell->EnableSetModified(false); // don't let export mark document as modified + bResetESM = true; + } + + uno::Reference<document::XDocumentPropertiesSupplier> xDPS( + aModelData.GetModel(), uno::UNO_QUERY_THROW); + uno::Reference<document::XDocumentProperties> xDocProps(xDPS->getDocumentProperties()); + xDocProps->setPrintDate(DateTime(DateTime::SYSTEM).GetUNODateTime()); + + OUString sPrintedBy(SfxResId(STR_SFX_FILTERNAME_PDF)); + if (pDocShell && pDocShell->IsUseUserData()) + { + const OUString& sFullName = SvtUserOptions().GetFullName(); + if (!sFullName.isEmpty()) + sPrintedBy += ": " + sFullName; + } + xDocProps->setPrintedBy(sPrintedBy); + + if (bResetESM) + pDocShell->EnableSetModified(true); + } + OSL_ENSURE( aModelData.GetMediaDescr().find( OUString( "Password" ) ) == aModelData.GetMediaDescr().end(), "The Password property of MediaDescriptor should not be used here!" ); if ( officecfg::Office::Common::Save::Document::EditProperty::get() && ( !aModelData.GetStorable()->hasLocation()