diff options
author | Caolán McNamara <caolan.mcnamara@collabora.com> | 2023-05-31 09:54:48 +0100 |
---|---|---|
committer | Caolán McNamara <caolan.mcnamara@collabora.com> | 2023-05-31 15:10:35 +0200 |
commit | f1ec565d4843284e43614d208b006420732b98e8 (patch) | |
tree | b5e35b9596f1ed199263b2042e474d082d210e57 /sfx2/source | |
parent | 2cda7933d1ed9e28153f6083e353df352851e235 (diff) |
Resolves: tdf#109149 don't poll the Default Printer Name on every query
We are queried on every change, so on every keystroke, and we are only
using this to fill in the printername inside the label of "Print
Directly (printer-name)" On Printer::GetDefaultPrinterName() is
implemented with GetDefaultPrinter so don't call this excessively. 5
mins seems a reasonable refresh time.
Change-Id: I71e87f26ed022241e09f9ab0eed94d09648ec9b9
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152415
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Diffstat (limited to 'sfx2/source')
-rw-r--r-- | sfx2/source/view/viewimp.hxx | 3 | ||||
-rw-r--r-- | sfx2/source/view/viewsh.cxx | 18 |
2 files changed, 20 insertions, 1 deletions
diff --git a/sfx2/source/view/viewimp.hxx b/sfx2/source/view/viewimp.hxx index 54e8267be658..aa0394591069 100644 --- a/sfx2/source/view/viewimp.hxx +++ b/sfx2/source/view/viewimp.hxx @@ -28,6 +28,7 @@ #include <svtools/acceleratorexecute.hxx> #include <rtl/ref.hxx> #include <vcl/print.hxx> +#include <chrono> #include <vector> class SfxBaseController; @@ -41,6 +42,8 @@ struct SfxViewShell_Impl aInterceptorContainer; SfxShellArr_Impl aArr; Size aMargin; + OUString m_sDefaultPrinterName; + std::chrono::steady_clock::time_point m_nDefaultPrinterNameFetchTime; bool m_bHasPrintOptions; sal_uInt16 m_nFamily; ::rtl::Reference<SfxBaseController> m_pController; diff --git a/sfx2/source/view/viewsh.cxx b/sfx2/source/view/viewsh.cxx index 934a12f0b5ba..4e414d9c65bf 100644 --- a/sfx2/source/view/viewsh.cxx +++ b/sfx2/source/view/viewsh.cxx @@ -706,7 +706,23 @@ void SfxViewShell::GetState_Impl( SfxItemSet &rSet ) if ( pPrinter != nullptr ) aPrinterName = pPrinter->GetName(); else - aPrinterName = Printer::GetDefaultPrinterName(); + { + // tdf#109149 don't poll the Default Printer Name on every query. + // We are queried on every change, so on every + // keystroke, and we are only using this to fill in the + // printername inside the label of "Print Directly (printer-name)" + // On Printer::GetDefaultPrinterName() is implemented with + // GetDefaultPrinter so don't call this excessively. 5 mins + // seems a reasonable refresh time. + std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now(); + std::chrono::minutes five_mins(5); + if (now > pImpl->m_nDefaultPrinterNameFetchTime + five_mins) + { + pImpl->m_sDefaultPrinterName = Printer::GetDefaultPrinterName(); + pImpl->m_nDefaultPrinterNameFetchTime = now; + } + aPrinterName = pImpl->m_sDefaultPrinterName; + } if ( !aPrinterName.isEmpty() ) { uno::Reference < frame::XFrame > xFrame( rFrame.GetFrame().GetFrameInterface() ); |