7#include "private/qcups_p.h"
10#include <QtCore/QMimeDatabase>
14#include <cups/language.h>
32 m_cupsName = parts.
at(0).toUtf8();
34 m_cupsInstance = parts.
at(1).toUtf8();
37 m_cupsDest = cupsGetNamedDest(CUPS_HTTP_DEFAULT, m_cupsName, m_cupsInstance.
isNull() ?
nullptr : m_cupsInstance.
constData());
39 const char *ppdFile = cupsGetPPD(m_cupsName);
41 m_ppd = ppdOpenFile(ppdFile);
45 ppdMarkDefaults(m_ppd);
46 cupsMarkOptions(m_ppd, m_cupsDest->num_options, m_cupsDest->options);
51 m_customMargins =
QMarginsF(m_ppd->custom_margins[0], m_ppd->custom_margins[3],
52 m_ppd->custom_margins[2], m_ppd->custom_margins[1]);
55 m_name = printerOption(
"printer-info");
56 m_location = printerOption(
"printer-location");
58 cups_ptype_e
type = printerTypeFlags();
79 cupsFreeDests(1, m_cupsDest);
115 m_printableMargins.
clear();
117 ppd_option_t *pageSizes = ppdFindOption(m_ppd,
"PageSize");
119 for (
int i = 0;
i < pageSizes->num_choices; ++
i) {
120 const ppd_size_t *ppdSize = ppdPageSize(m_ppd, pageSizes->choices[
i].choice);
126 if (!
size.isEmpty()) {
130 m_printableMargins.
insert(
key,
QMarginsF(ppdSize->left, ppdSize->length - ppdSize->top,
131 ppdSize->width - ppdSize->right, ppdSize->bottom));
142 ppd_choice_t *defaultChoice = ppdFindMarkedChoice(m_ppd,
"PageSize");
144 ppd_size_t *ppdSize = ppdPageSize(m_ppd, defaultChoice->choice);
158 int resolution)
const
166 return m_printableMargins.
value(pageSize.
key());
167 return m_customMargins;
175 ppd_option_t *resolutions = ppdFindOption(m_ppd,
"Resolution");
177 for (
int i = 0;
i < resolutions->num_choices; ++
i) {
178 int res = QPrintUtils::parsePpdResolution(resolutions->choices[
i].choice);
185 resolutions = ppdFindOption(m_ppd,
"DefaultResolution");
187 int res = QPrintUtils::parsePpdResolution(resolutions->choices[0].choice);
194 resolutions = ppdFindOption(m_ppd,
"HPPrintQuality");
196 for (
int i = 0;
i < resolutions->num_choices; ++
i) {
197 int res = QPrintUtils::parsePpdResolution(resolutions->choices[
i].choice);
204 resolutions = ppdFindOption(m_ppd,
"DefaultHPPrintQuality");
206 int res = QPrintUtils::parsePpdResolution(resolutions->choices[0].choice);
217 ppd_option_t *resolution = ppdFindOption(m_ppd,
"DefaultResolution");
219 int res = QPrintUtils::parsePpdResolution(resolution->choices[0].choice);
224 ppd_choice_t *defaultChoice = ppdFindMarkedChoice(m_ppd,
"Resolution");
226 int res = QPrintUtils::parsePpdResolution(defaultChoice->choice);
231 resolution = ppdFindOption(m_ppd,
"DefaultHPPrintQuality");
233 int res = QPrintUtils::parsePpdResolution(resolution->choices[0].choice);
237 defaultChoice = ppdFindMarkedChoice(m_ppd,
"HPPrintQuality");
239 int res = QPrintUtils::parsePpdResolution(defaultChoice->choice);
257 ppd_option_t *inputSlots = ppdFindOption(m_ppd,
"InputSlot");
260 for (
int i = 0;
i < inputSlots->num_choices; ++
i)
265 inputSlots = ppdFindOption(m_ppd,
"DefaultInputSlot");
281 ppd_option_t *inputSlot = ppdFindOption(m_ppd,
"DefaultInputSlot");
283 return QPrintUtils::ppdChoiceToInputSlot(inputSlot->choices[0]);
285 ppd_choice_t *defaultChoice = ppdFindMarkedChoice(m_ppd,
"InputSlot");
287 return QPrintUtils::ppdChoiceToInputSlot(*defaultChoice);
298 ppd_option_t *outputBins = ppdFindOption(m_ppd,
"OutputBin");
301 for (
int i = 0;
i < outputBins->num_choices; ++
i)
306 outputBins = ppdFindOption(m_ppd,
"DefaultOutputBin");
322 ppd_option_t *outputBin = ppdFindOption(m_ppd,
"DefaultOutputBin");
324 return QPrintUtils::ppdChoiceToOutputBin(outputBin->choices[0]);
326 ppd_choice_t *defaultChoice = ppdFindMarkedChoice(m_ppd,
"OutputBin");
328 return QPrintUtils::ppdChoiceToOutputBin(*defaultChoice);
340 ppd_option_t *duplexModes = ppdFindOption(m_ppd,
"Duplex");
343 for (
int i = 0;
i < duplexModes->num_choices; ++
i) {
344 if (ppdInstallableConflict(m_ppd, duplexModes->keyword, duplexModes->choices[
i].choice) == 0) {
351 duplexModes = ppdFindOption(m_ppd,
"DefaultDuplex");
352 if (duplexModes && (ppdInstallableConflict(m_ppd, duplexModes->keyword, duplexModes->choices[0].choice) == 0)) {
370 ppd_option_t *inputSlot = ppdFindOption(m_ppd,
"DefaultDuplex");
372 return QPrintUtils::ppdChoiceToDuplexMode(inputSlot->choices[0].choice);
374 ppd_choice_t *defaultChoice = ppdFindMarkedChoice(m_ppd,
"Duplex");
376 return QPrintUtils::ppdChoiceToDuplexMode(defaultChoice->choice);
388 cups_ptype_e
type = printerTypeFlags();
389 if (
type & CUPS_PRINTER_BW)
391 if (
type & CUPS_PRINTER_COLOR)
402 ppd_option_t *colorModel = ppdFindOption(m_ppd,
"DefaultColorModel");
404 colorModel = ppdFindOption(m_ppd,
"ColorModel");
405 if (!colorModel ||
qstrcmp(colorModel->defchoice,
"Gray") != 0)
414 return QVariant::fromValue<ppd_file_t *>(m_ppd);
432 ppdMarkOption(m_ppd,
values[0].toLatin1(),
values[1].toLatin1());
445 return ppdInstallableConflict(m_ppd,
values[0].toLatin1(),
values[1].toLatin1());
451#if QT_CONFIG(mimetype)
452void QPpdPrintDevice::loadMimeTypes()
const
465 m_haveMimeTypes =
true;
471 return cupsGetOption(
key.toUtf8(), m_cupsDest->num_options, m_cupsDest->options);
474cups_ptype_e QPpdPrintDevice::printerTypeFlags()
const
476 return static_cast<cups_ptype_e
>(printerOption(
"printer-type").
toUInt());
const char * constData() const noexcept
Returns a pointer to the const data stored in the byte array.
char at(qsizetype i) const
Returns the byte at index position i in the byte array.
bool isNull() const noexcept
Returns true if this byte array is null; otherwise returns false.
static QString staticDefaultPrintDeviceId()
bool contains(const Key &key) const noexcept
Returns true if the hash contains an item with the key; otherwise returns false.
T value(const Key &key) const noexcept
void clear() noexcept(std::is_nothrow_destructible< Node >::value)
Removes all items from the hash and frees up all memory used by it.
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
qsizetype size() const noexcept
void reserve(qsizetype size)
void append(parameter_type t)
QMimeType mimeTypeForName(const QString &nameOrAlias) const
Returns a MIME type for nameOrAlias or an invalid one if none found.
Orientation
This enum type defines the page orientation.
bool isValid() const
Returns true if this page size is valid.
QString key() const
Returns the unique key of the page size.
void loadResolutions() const override
QPrint::InputSlot defaultInputSlot() const override
int defaultResolution() const override
QMarginsF printableMargins(const QPageSize &pageSize, QPageLayout::Orientation orientation, int resolution) const override
QPrint::OutputBin defaultOutputBin() const override
void loadPageSizes() const override
QPageSize defaultPageSize() const override
bool isFeatureAvailable(QPrintDevice::PrintDevicePropertyKey key, const QVariant ¶ms) const override
void loadInputSlots() const override
QPrint::DeviceState state() const override
void loadDuplexModes() const override
QPpdPrintDevice(const QString &id)
QPrint::ColorMode defaultColorMode() const override
void loadColorModes() const override
QVariant property(QPrintDevice::PrintDevicePropertyKey key) const override
QPrint::DuplexMode defaultDuplexMode() const override
void loadOutputBins() const override
virtual ~QPpdPrintDevice()
bool setProperty(QPrintDevice::PrintDevicePropertyKey key, const QVariant &value) override
bool isDefault() const override
bool isValid() const override
Q_CORE_EXPORT QList< QStringView > split(QStringView sep, Qt::SplitBehavior behavior=Qt::KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Splits the view into substring views wherever sep occurs, and returns the list of those string views.
\macro QT_RESTRICTED_CAST_FROM_ASCII
int toInt(bool *ok=nullptr, int base=10) const
Returns the string converted to an int using base base, which is 10 by default and must be between 2 ...
uint toUInt(bool *ok=nullptr, int base=10) const
Returns the string converted to an {unsigned int} using base base, which is 10 by default and must be...
static QString fromUtf8(QByteArrayView utf8)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Combined button and popup list for selecting options.
Q_CORE_EXPORT int qstrcmp(const char *str1, const char *str2)
#define QT_WARNING_DISABLE_DEPRECATED
#define PDPK_CupsJobBilling
#define PDPK_CupsJobPriority
#define PDPK_PpdChoiceIsInstallableConflict
#define PDPK_CupsJobHoldUntil
#define PDPK_CupsJobSheets
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
int qRound(qfloat16 d) noexcept
static bool contains(const QJsonArray &haystack, unsigned needle)
GLenum GLsizei GLsizei GLint * values
[15]
GLenum GLuint GLintptr GLsizeiptr size
[1]
#define QStringLiteral(str)
bool contains(const AT &t) const noexcept