7#include <QtCore/private/qohoslogger_p.h>
9#include <BasicServicesKit/ohprint.h>
11#include <ohprint/print_base.h>
21 switch (nativeDuplexMode) {
22 case DUPLEX_MODE_ONE_SIDED:
23 return QPrint::DuplexNone;
24 case DUPLEX_MODE_TWO_SIDED_LONG_EDGE:
25 return QPrint::DuplexLongSide;
26 case DUPLEX_MODE_TWO_SIDED_SHORT_EDGE:
27 return QPrint::DuplexShortSide;
33 switch (nativeColorMode) {
34 case COLOR_MODE_MONOCHROME:
35 return QPrint::GrayScale;
36 case COLOR_MODE_COLOR:
40 return QPrint::GrayScale;
56 m_name = printerInfo.name;
57 m_location = printerInfo.location;
58 m_makeAndModel = printerInfo.makeAndModel;
59 m_supportsMultipleCopies = printerInfo.capabilities.supportedCopies > 1;
67 QStringList printerIdList;
68 if (!QOhosNativePrint::queryPrinterIdList(printerIdList))
70 return printerIdList.contains(m_id);
76 if (!QOhosNativePrint::queryPrinterInfo(m_id, printerInfo)) {
77 qOhosCritical(QtForOhos) <<
"QOhosPrintDevice::isDefault: Failed to get printerInfo";
90 if (!QOhosNativePrint::queryPrinterInfo(m_id, pi)) {
91 qOhosCritical(QtForOhos) <<
"Failed to get printerInfo";
100 return QPrint::Active;
102 case PRINTER_UNAVAILABLE:
103 return QPrint::Error;
109 auto __dbg = make_QCScopedDebug(
"QOhosPrintDevice::defaultPageSize");
113 for (
const auto &pageSize : supportedPageSizes()) {
114 if (pageSize.key() == printerInfo.defaultValues.pageSizeId)
124 QString isoA4OhosId = QString::fromLocal8Bit(
"ISO_A4");
125 QString isoA4OhosName = QString::fromLocal8Bit(
"iso_a4_210x297mm");
126 return createPageSize(isoA4OhosId, QPageSize(QPageSize::A4).sizePoints(), isoA4OhosName);
131 auto __dbg = make_QCScopedDebug(
"QOhosPrintDevice::defaultDuplexMode");
134 if (!QOhosNativePrint::queryPrinterInfo(m_id, printerInfo)) {
135 qOhosCritical(QtForOhos) <<
"Failed to get printerInfo";
136 return QPrint::DuplexNone;
139 return convertOhosToQtDuplexMode(printerInfo.defaultValues.duplexMode);
144 auto __dbg = make_QCScopedDebug(
"QOhosPrintDevice::defaultColorMode");
147 if (!QOhosNativePrint::queryPrinterInfo(m_id, printerInfo)) {
148 qOhosCritical(QtForOhos) <<
"Failed to get printerInfo";
149 return QPrint::GrayScale;
152 return convertOhosToQtColorMode(printerInfo.defaultValues.colorMode);
157 auto __dbg = make_QCScopedDebug(
"QOhosPrintDevice::defaultResolution");
160 if (!QOhosNativePrint::queryPrinterInfo(m_id, printerInfo)) {
161 qOhosCritical(QtForOhos) <<
"Failed to get printerInfo";
165 return printerInfo.defaultValues.resolution.verticalDpi;
170 auto __dbg = make_QCScopedDebug(
"QOhosPrintDevice::availablePrintDeviceIds");
172 QStringList printerIdList;
173 if (!QOhosNativePrint::queryPrinterIdList(printerIdList))
176 return printerIdList;
181 auto __dbg = make_QCScopedDebug(
"QOhosPrintDevice::defaultPrintDeviceId");
183 for (
const auto &printerId : availablePrintDeviceIds()) {
184 QOhosNativePrint::PrinterInfo printerInfo;
185 if (QOhosNativePrint::queryPrinterInfo(printerId, printerInfo) && printerInfo.isDefault)
194 auto __dbg = make_QCScopedDebug(
"QOhosPrintDevice::loadPageSizes");
197 if (!QOhosNativePrint::queryPrinterInfo(m_id, printerInfo)) {
198 qOhosCritical(QtForOhos) <<
"Failed to get printerInfo";
202 qOhosDebug(QtForOhos) <<
"Available page sizes:";
205 for (
const auto &nativePageSize : printerInfo.capabilities.supportedPageSizes) {
207 QOhosNativePrint::convertPixelsPerThousandDpiToPoints(nativePageSize.width),
208 QOhosNativePrint::convertPixelsPerThousandDpiToPoints(nativePageSize.height));
209 QPageSize pageSize = createPageSize(nativePageSize.id, size, nativePageSize.name);
211 qOhosDebug(QtForOhos) <<
"\t*" << pageSize;
213 m_pageSizes.append(pageSize);
216 m_havePageSizes =
true;
221 auto __dbg = make_QCScopedDebug(
"QOhosPrintDevice::loadDuplexModes");
224 if (!QOhosNativePrint::queryPrinterInfo(m_id, printerInfo)) {
225 qOhosCritical(QtForOhos) <<
"Failed to get printerInfo";
229 qOhosDebug(QtForOhos) <<
"Available duplex modes:";
231 m_duplexModes.clear();
232 for (
auto nativeDuplexMode : printerInfo.capabilities.supportedDuplexModes) {
233 auto duplexMode = convertOhosToQtDuplexMode(nativeDuplexMode);
235 qOhosDebug(QtForOhos) <<
"\t*" << duplexMode;
237 m_duplexModes.append(duplexMode);
240 m_haveDuplexModes =
true;
245 auto __dbg = make_QCScopedDebug(
"QOhosPrintDevice::loadColorModes");
248 if (!QOhosNativePrint::queryPrinterInfo(m_id, printerInfo)) {
249 qOhosCritical(QtForOhos) <<
"Failed to get printerInfo";
253 qOhosDebug(QtForOhos) <<
"Printer colorModes:";
255 m_colorModes.clear();
256 for (
auto nativeColorMode : printerInfo.capabilities.supportedColorModes) {
257 auto colorMode = convertOhosToQtColorMode(nativeColorMode);
259 qOhosDebug(QtForOhos) <<
"\t*" << colorMode;
261 m_colorModes.append(colorMode);
264 m_haveColorModes =
true;
269 auto __dbg = make_QCScopedDebug(
"QOhosPrintDevice::loadResolutions");
272 if (!QOhosNativePrint::queryPrinterInfo(m_id, printerInfo)) {
273 qOhosCritical(QtForOhos) <<
"Failed to get printerInfo";
277 qOhosDebug(QtForOhos) <<
"Printer resolutions:";
279 m_resolutions.clear();
280 for (
const auto &nativeResolution : printerInfo.capabilities.supportedResolutions) {
281 auto resolution = nativeResolution.verticalDpi;
283 qOhosDebug(QtForOhos) <<
"\t*" << resolution;
285 m_resolutions.append(resolution);
288 m_haveResolutions =
true;
void loadDuplexModes() const override
void loadResolutions() const override
QPrint::ColorMode defaultColorMode() const override
QPageSize defaultPageSize() const override
QOhosPrintDevice(const QString &id)
int defaultResolution() const override
bool isValid() const override
QPrint::DeviceState state() const override
QPrint::DuplexMode defaultDuplexMode() const override
void loadColorModes() const override
void loadPageSizes() const override
virtual ~QOhosPrintDevice()
bool isDefault() const override
bool queryPrinterInfo(const QString &printerId, PrinterInfo &printerInfo)
Combined button and popup list for selecting options.
QPrint::ColorMode convertOhosToQtColorMode(Print_ColorMode nativeColorMode)
QPrint::DuplexMode convertOhosToQtDuplexMode(Print_DuplexMode nativeDuplexMode)