vcl: Iterate directly over the PrinterInfoManager printer map

Instead of having PrinterInfoManager::listPrinters as a getter
that returns the keys in the std::unordered_map and then calling
PrinterInfoManager::getPrinterInfo for each of the keys to get
the corresponding entry again, add a new getter to return
a const ref to the map and iterate over that one directly
in SalGenericInstance::GetPrinterQueueInfo and
SvpSalInstance::GetPrinterQueueInfo.

Change-Id: I36a0ec712bd8f815c2de51afcdd7f7a605a28ab0
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/202842
Tested-by: Jenkins
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
This commit is contained in:
Michael Weghorn
2026-03-28 12:27:25 +01:00
parent da945e1343
commit 4d1d71b6b8
5 changed files with 6 additions and 23 deletions
+2 -4
View File
@@ -166,13 +166,11 @@ void SvpSalInstance::GetPrinterQueueInfo(ImplPrnQueueList& rList)
rManager.checkPrintersChanged( true );
}
std::vector<OUString> aPrinters = rManager.listPrinters();
for (auto const& printer : aPrinters)
for (const auto& [rPrinterName, rInfo] : rManager.getPrinters())
{
const PrinterInfo& rInfo( rManager.getPrinterInfo(printer) );
// create new entry
std::unique_ptr<SalPrinterQueueInfo> pInfo(new SalPrinterQueueInfo);
pInfo->maPrinterName = printer;
pInfo->maPrinterName = rPrinterName;
pInfo->maDriver = rInfo.m_aDriverName;
pInfo->maLocation = rInfo.m_aLocation;
pInfo->maComment = rInfo.m_aComment;
+2 -2
View File
@@ -115,8 +115,8 @@ public:
// get PrinterInfoManager type
Type getType() const { return m_eType; }
// lists the names of all known printers
std::vector<OUString> listPrinters() const;
// retrieve all known printers
const std::unordered_map<OUString, PrinterInfo>& getPrinters() const { return m_aPrinters; }
// gets info about a named printer
const PrinterInfo& getPrinterInfo( const OUString& rPrinter ) const;
-5
View File
@@ -62,11 +62,6 @@ void PrinterInfoManager::initialize()
// ???
}
std::vector<OUString> PrinterInfoManager::listPrinters() const
{
return {};
}
const PrinterInfo& PrinterInfoManager::getPrinterInfo(
[[maybe_unused]] const OUString& /* rPrinter */ ) const
{
+2 -4
View File
@@ -310,13 +310,11 @@ void SalGenericInstance::GetPrinterQueueInfo(ImplPrnQueueList& rList)
rManager.checkPrintersChanged( true );
}
std::vector<OUString> aPrinters = rManager.listPrinters();
for (auto const& printer : aPrinters)
for (const auto& [rPrinterName, rInfo] : rManager.getPrinters())
{
const PrinterInfo& rInfo( rManager.getPrinterInfo(printer) );
// create new entry
std::unique_ptr<SalPrinterQueueInfo> pInfo(new SalPrinterQueueInfo);
pInfo->maPrinterName = printer;
pInfo->maPrinterName = rPrinterName;
pInfo->maDriver = rInfo.m_aDriverName;
pInfo->maLocation = rInfo.m_aLocation;
pInfo->maComment = rInfo.m_aComment;
@@ -522,14 +522,6 @@ void PrinterInfoManager::initialize()
}
}
std::vector<OUString> PrinterInfoManager::listPrinters() const
{
std::vector<OUString> aPrinters;
for (auto const& printer : m_aPrinters)
aPrinters.push_back(printer.first);
return aPrinters;
}
const PrinterInfo& PrinterInfoManager::getPrinterInfo( const OUString& rPrinter ) const
{
static PrinterInfo aEmptyInfo;