1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20 #include <Qt5Instance.hxx>
21 #include <Qt5Printer.hxx>
22
23 #include <vcl/svapp.hxx>
24 #include <vcl/timer.hxx>
25 #include <printerinfomanager.hxx>
26
27 #include <jobset.h>
28 #include <print.h>
29 #include <salptype.hxx>
30 #include <saldatabasic.hxx>
31
32 #include <unx/genpspgraphics.h>
33
34 using namespace psp;
35
36 /*
37 * static helpers
38 */
39
getPdfDir(const PrinterInfo & rInfo)40 static OUString getPdfDir(const PrinterInfo& rInfo)
41 {
42 OUString aDir;
43 sal_Int32 nIndex = 0;
44 while (nIndex != -1)
45 {
46 OUString aToken(rInfo.m_aFeatures.getToken(0, ',', nIndex));
47 if (aToken.startsWith("pdf="))
48 {
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;
54 }
55 }
56 return aDir;
57 }
58
CreateInfoPrinter(SalPrinterQueueInfo * pQueueInfo,ImplJobSetup * pJobSetup)59 SalInfoPrinter* Qt5Instance::CreateInfoPrinter(SalPrinterQueueInfo* pQueueInfo,
60 ImplJobSetup* pJobSetup)
61 {
62 // create and initialize SalInfoPrinter
63 PspSalInfoPrinter* pPrinter = new PspSalInfoPrinter;
64 configurePspInfoPrinter(pPrinter, pQueueInfo, pJobSetup);
65
66 return pPrinter;
67 }
68
DestroyInfoPrinter(SalInfoPrinter * pPrinter)69 void Qt5Instance::DestroyInfoPrinter(SalInfoPrinter* pPrinter) { delete pPrinter; }
70
CreatePrinter(SalInfoPrinter * pInfoPrinter)71 std::unique_ptr<SalPrinter> Qt5Instance::CreatePrinter(SalInfoPrinter* pInfoPrinter)
72 {
73 // create and initialize SalPrinter
74 Qt5Printer* pPrinter = new Qt5Printer(pInfoPrinter);
75 pPrinter->m_aJobData = static_cast<PspSalInfoPrinter*>(pInfoPrinter)->m_aJobData;
76
77 return std::unique_ptr<SalPrinter>(pPrinter);
78 }
79
GetPrinterQueueInfo(ImplPrnQueueList * pList)80 void Qt5Instance::GetPrinterQueueInfo(ImplPrnQueueList* pList)
81 {
82 PrinterInfoManager& rManager(PrinterInfoManager::get());
83 static const char* pNoSyncDetection = getenv("SAL_DISABLE_SYNCHRONOUS_PRINTER_DETECTION");
84 if (!pNoSyncDetection || !*pNoSyncDetection)
85 {
86 // #i62663# synchronize possible asynchronouse printer detection now
87 rManager.checkPrintersChanged(true);
88 }
89 ::std::vector<OUString> aPrinters;
90 rManager.listPrinters(aPrinters);
91
92 for (const auto& rPrinter : aPrinters)
93 {
94 const PrinterInfo& rInfo(rManager.getPrinterInfo(rPrinter));
95 // create new entry
96 std::unique_ptr<SalPrinterQueueInfo> pInfo(new SalPrinterQueueInfo);
97 pInfo->maPrinterName = rPrinter;
98 pInfo->maDriver = rInfo.m_aDriverName;
99 pInfo->maLocation = rInfo.m_aLocation;
100 pInfo->maComment = rInfo.m_aComment;
101
102 sal_Int32 nIndex = 0;
103 while (nIndex != -1)
104 {
105 OUString aToken(rInfo.m_aFeatures.getToken(0, ',', nIndex));
106 if (aToken.startsWith("pdf="))
107 {
108 pInfo->maLocation = getPdfDir(rInfo);
109 break;
110 }
111 }
112
113 pList->Add(std::move(pInfo));
114 }
115 }
116
GetPrinterQueueState(SalPrinterQueueInfo *)117 void Qt5Instance::GetPrinterQueueState(SalPrinterQueueInfo*) {}
118
GetDefaultPrinter()119 OUString Qt5Instance::GetDefaultPrinter()
120 {
121 PrinterInfoManager& rManager(PrinterInfoManager::get());
122 return rManager.getDefaultPrinter();
123 }
124
PostPrintersChanged()125 void Qt5Instance::PostPrintersChanged() {}
126
CreatePrintGraphics()127 std::unique_ptr<GenPspGraphics> Qt5Instance::CreatePrintGraphics()
128 {
129 return std::make_unique<GenPspGraphics>();
130 }
131
132 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
133