tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / vcl / qt5 / QtInstance_Print.cxx
blob5719e6702994a319de6581b843aca0854ec31356
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sal/config.h>
22 #include <string_view>
24 #include <QtInstance.hxx>
25 #include <QtPrinter.hxx>
27 #include <vcl/svapp.hxx>
28 #include <vcl/timer.hxx>
29 #include <vcl/QueueInfo.hxx>
30 #include <printerinfomanager.hxx>
32 #include <jobset.h>
33 #include <print.h>
34 #include <salptype.hxx>
36 #include <unx/genpspgraphics.h>
38 using namespace psp;
41 * static helpers
44 static OUString getPdfDir(const PrinterInfo& rInfo)
46 OUString aDir;
47 sal_Int32 nIndex = 0;
48 while (nIndex != -1)
50 OUString aToken(rInfo.m_aFeatures.getToken(0, ',', nIndex));
51 if (aToken.startsWith("pdf="))
53 sal_Int32 nPos = 0;
54 aDir = aToken.getToken(1, '=', nPos);
55 if (aDir.isEmpty())
56 if (auto const env = getenv("HOME"))
58 aDir = OStringToOUString(std::string_view(env), osl_getThreadTextEncoding());
60 break;
63 return aDir;
66 SalInfoPrinter* QtInstance::CreateInfoPrinter(SalPrinterQueueInfo* pQueueInfo,
67 ImplJobSetup* pJobSetup)
69 // create and initialize SalInfoPrinter
70 PspSalInfoPrinter* pPrinter = new PspSalInfoPrinter;
71 configurePspInfoPrinter(pPrinter, pQueueInfo, pJobSetup);
73 return pPrinter;
76 void QtInstance::DestroyInfoPrinter(SalInfoPrinter* pPrinter) { delete pPrinter; }
78 std::unique_ptr<SalPrinter> QtInstance::CreatePrinter(SalInfoPrinter* pInfoPrinter)
80 // create and initialize SalPrinter
81 QtPrinter* pPrinter = new QtPrinter(pInfoPrinter);
82 pPrinter->m_aJobData = static_cast<PspSalInfoPrinter*>(pInfoPrinter)->m_aJobData;
84 return std::unique_ptr<SalPrinter>(pPrinter);
87 void QtInstance::GetPrinterQueueInfo(ImplPrnQueueList* pList)
89 PrinterInfoManager& rManager(PrinterInfoManager::get());
90 static const char* pNoSyncDetection = getenv("SAL_DISABLE_SYNCHRONOUS_PRINTER_DETECTION");
91 if (!pNoSyncDetection || !*pNoSyncDetection)
93 // #i62663# synchronize possible asynchronouse printer detection now
94 rManager.checkPrintersChanged(true);
96 ::std::vector<OUString> aPrinters;
97 rManager.listPrinters(aPrinters);
99 for (const auto& rPrinter : aPrinters)
101 const PrinterInfo& rInfo(rManager.getPrinterInfo(rPrinter));
102 // create new entry
103 std::unique_ptr<SalPrinterQueueInfo> pInfo(new SalPrinterQueueInfo);
104 pInfo->maPrinterName = rPrinter;
105 pInfo->maDriver = rInfo.m_aDriverName;
106 pInfo->maLocation = rInfo.m_aLocation;
107 pInfo->maComment = rInfo.m_aComment;
109 sal_Int32 nIndex = 0;
110 while (nIndex != -1)
112 OUString aToken(rInfo.m_aFeatures.getToken(0, ',', nIndex));
113 if (aToken.startsWith("pdf="))
115 pInfo->maLocation = getPdfDir(rInfo);
116 break;
120 pList->Add(std::move(pInfo));
124 void QtInstance::GetPrinterQueueState(SalPrinterQueueInfo*) {}
126 OUString QtInstance::GetDefaultPrinter()
128 PrinterInfoManager& rManager(PrinterInfoManager::get());
129 return rManager.getDefaultPrinter();
132 void QtInstance::PostPrintersChanged() {}
134 std::unique_ptr<GenPspGraphics> QtInstance::CreatePrintGraphics()
136 return std::make_unique<GenPspGraphics>();
139 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */