Version 6.1.4.1, tag libreoffice-6.1.4.1
[LibreOffice.git] / vcl / qt5 / Qt5Instance_Print.cxx
blob802f2591ccfe44f533a90911629a88a829686ad3
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 "Qt5Instance.hxx"
21 #include "Qt5Printer.hxx"
23 #include <vcl/svapp.hxx>
24 #include <vcl/timer.hxx>
25 #include <printerinfomanager.hxx>
27 #include <jobset.h>
28 #include <print.h>
29 #include <salptype.hxx>
30 #include <saldatabasic.hxx>
32 #include <unx/genpspgraphics.h>
34 using namespace psp;
37 * static helpers
40 static OUString getPdfDir(const PrinterInfo& rInfo)
42 OUString aDir;
43 sal_Int32 nIndex = 0;
44 while (nIndex != -1)
46 OUString aToken(rInfo.m_aFeatures.getToken(0, ',', nIndex));
47 if (aToken.startsWith("pdf="))
49 sal_Int32 nPos = 0;
50 aDir = aToken.getToken(1, '=', nPos);
51 if (aDir.isEmpty())
52 aDir = OStringToOUString(OString(getenv("HOME")), osl_getThreadTextEncoding());
53 break;
56 return aDir;
59 inline int PtTo10Mu(int nPoints)
61 return static_cast<int>((static_cast<double>(nPoints) * 35.27777778) + 0.5);
64 static void copyJobDataToJobSetup(ImplJobSetup* pJobSetup, JobData& rData)
66 pJobSetup->SetOrientation(rData.m_eOrientation == orientation::Landscape
67 ? Orientation::Landscape
68 : Orientation::Portrait);
70 // copy page size
71 OUString aPaper;
72 int width, height;
74 rData.m_aContext.getPageSize(aPaper, width, height);
75 pJobSetup->SetPaperFormat(
76 PaperInfo::fromPSName(OUStringToOString(aPaper, RTL_TEXTENCODING_ISO_8859_1)));
77 pJobSetup->SetPaperWidth(0);
78 pJobSetup->SetPaperHeight(0);
79 if (pJobSetup->GetPaperFormat() == PAPER_USER)
81 // transform to 100dth mm
82 width = PtTo10Mu(width);
83 height = PtTo10Mu(height);
85 if (rData.m_eOrientation == psp::orientation::Portrait)
87 pJobSetup->SetPaperWidth(width);
88 pJobSetup->SetPaperHeight(height);
90 else
92 pJobSetup->SetPaperWidth(height);
93 pJobSetup->SetPaperHeight(width);
97 // copy input slot
98 const PPDKey* pKey = nullptr;
99 const PPDValue* pValue = nullptr;
101 pJobSetup->SetPaperBin(0xffff);
102 if (rData.m_pParser)
103 pKey = rData.m_pParser->getKey(OUString("InputSlot"));
104 if (pKey)
105 pValue = rData.m_aContext.getValue(pKey);
106 if (pKey && pValue)
108 int nPaperBin;
109 for (nPaperBin = 0; pValue != pKey->getValue(nPaperBin) && nPaperBin < pKey->countValues();
110 nPaperBin++)
112 pJobSetup->SetPaperBin(
113 (nPaperBin == pKey->countValues() || pValue == pKey->getDefaultValue()) ? 0xffff
114 : nPaperBin);
117 // copy duplex
118 pKey = nullptr;
119 pValue = nullptr;
121 pJobSetup->SetDuplexMode(DuplexMode::Unknown);
122 if (rData.m_pParser)
123 pKey = rData.m_pParser->getKey(OUString("Duplex"));
124 if (pKey)
125 pValue = rData.m_aContext.getValue(pKey);
126 if (pKey && pValue)
128 if (pValue->m_aOption.equalsIgnoreAsciiCase("None")
129 || pValue->m_aOption.startsWithIgnoreAsciiCase("Simplex"))
131 pJobSetup->SetDuplexMode(DuplexMode::Off);
133 else if (pValue->m_aOption.equalsIgnoreAsciiCase("DuplexNoTumble"))
135 pJobSetup->SetDuplexMode(DuplexMode::LongEdge);
137 else if (pValue->m_aOption.equalsIgnoreAsciiCase("DuplexTumble"))
139 pJobSetup->SetDuplexMode(DuplexMode::ShortEdge);
143 // copy the whole context
144 if (pJobSetup->GetDriverData())
145 rtl_freeMemory(const_cast<sal_uInt8*>(pJobSetup->GetDriverData()));
147 sal_uInt32 nBytes;
148 void* pBuffer = nullptr;
149 if (rData.getStreamBuffer(pBuffer, nBytes))
151 pJobSetup->SetDriverDataLen(nBytes);
152 pJobSetup->SetDriverData(static_cast<sal_uInt8*>(pBuffer));
154 else
156 pJobSetup->SetDriverDataLen(0);
157 pJobSetup->SetDriverData(nullptr);
161 SalInfoPrinter* Qt5Instance::CreateInfoPrinter(SalPrinterQueueInfo* pQueueInfo,
162 ImplJobSetup* pJobSetup)
164 // create and initialize SalInfoPrinter
165 Qt5InfoPrinter* pPrinter = new Qt5InfoPrinter;
167 if (pJobSetup)
169 PrinterInfoManager& rManager(PrinterInfoManager::get());
170 PrinterInfo aInfo(rManager.getPrinterInfo(pQueueInfo->maPrinterName));
171 pPrinter->m_aJobData = aInfo;
172 pPrinter->m_aPrinterGfx.Init(pPrinter->m_aJobData);
174 if (pJobSetup->GetDriverData())
175 JobData::constructFromStreamBuffer(pJobSetup->GetDriverData(),
176 pJobSetup->GetDriverDataLen(), aInfo);
178 pJobSetup->SetSystem(JOBSETUP_SYSTEM_UNIX);
179 pJobSetup->SetPrinterName(pQueueInfo->maPrinterName);
180 pJobSetup->SetDriver(aInfo.m_aDriverName);
181 copyJobDataToJobSetup(pJobSetup, aInfo);
184 return pPrinter;
187 void Qt5Instance::DestroyInfoPrinter(SalInfoPrinter* pPrinter) { delete pPrinter; }
189 SalPrinter* Qt5Instance::CreatePrinter(SalInfoPrinter* pInfoPrinter)
191 // create and initialize SalPrinter
192 Qt5Printer* pPrinter = new Qt5Printer(pInfoPrinter);
193 pPrinter->m_aJobData = static_cast<Qt5InfoPrinter*>(pInfoPrinter)->m_aJobData;
195 return pPrinter;
198 void Qt5Instance::DestroyPrinter(SalPrinter* pPrinter) { delete pPrinter; }
200 void Qt5Instance::GetPrinterQueueInfo(ImplPrnQueueList* pList)
202 PrinterInfoManager& rManager(PrinterInfoManager::get());
203 static const char* pNoSyncDetection = getenv("SAL_DISABLE_SYNCHRONOUS_PRINTER_DETECTION");
204 if (!pNoSyncDetection || !*pNoSyncDetection)
206 // #i62663# synchronize possible asynchronouse printer detection now
207 rManager.checkPrintersChanged(true);
209 ::std::vector<OUString> aPrinters;
210 rManager.listPrinters(aPrinters);
212 for (::std::vector<OUString>::iterator it = aPrinters.begin(); it != aPrinters.end(); ++it)
214 const PrinterInfo& rInfo(rManager.getPrinterInfo(*it));
215 // create new entry
216 SalPrinterQueueInfo* pInfo = new SalPrinterQueueInfo;
217 pInfo->maPrinterName = *it;
218 pInfo->maDriver = rInfo.m_aDriverName;
219 pInfo->maLocation = rInfo.m_aLocation;
220 pInfo->maComment = rInfo.m_aComment;
221 pInfo->mpSysData = nullptr;
223 sal_Int32 nIndex = 0;
224 while (nIndex != -1)
226 OUString aToken(rInfo.m_aFeatures.getToken(0, ',', nIndex));
227 if (aToken.startsWith("pdf="))
229 pInfo->maLocation = getPdfDir(rInfo);
230 break;
234 pList->Add(pInfo);
238 void Qt5Instance::DeletePrinterQueueInfo(SalPrinterQueueInfo* pInfo) { delete pInfo; }
240 void Qt5Instance::GetPrinterQueueState(SalPrinterQueueInfo*) {}
242 OUString Qt5Instance::GetDefaultPrinter()
244 PrinterInfoManager& rManager(PrinterInfoManager::get());
245 return rManager.getDefaultPrinter();
248 void Qt5Instance::PostPrintersChanged() {}
250 GenPspGraphics* Qt5Instance::CreatePrintGraphics() { return new GenPspGraphics(); }
252 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */