| 1 | // Copyright (C) 2016 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QCUPS_P_H |
| 5 | #define QCUPS_P_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is not part of the Qt API. It exists purely as an |
| 12 | // implementation detail. This header file may change from version to |
| 13 | // version without notice, or even be removed. |
| 14 | // |
| 15 | // We mean it. |
| 16 | // |
| 17 | |
| 18 | #include <QtPrintSupport/private/qtprintsupportglobal_p.h> |
| 19 | #include <QtPrintSupport/private/qprint_p.h> |
| 20 | #include "QtCore/qstring.h" |
| 21 | #include "QtCore/qstringlist.h" |
| 22 | #include "QtPrintSupport/qprinter.h" |
| 23 | #include "QtCore/qdatetime.h" |
| 24 | |
| 25 | QT_REQUIRE_CONFIG(cups); |
| 26 | |
| 27 | QT_BEGIN_NAMESPACE |
| 28 | |
| 29 | class QPrintDevice; |
| 30 | |
| 31 | // HACK! Define these here temporarily so they can be used in the dialogs |
| 32 | // without a circular reference to QCupsPrintEngine in the plugin. |
| 33 | // Move back to qcupsprintengine_p.h in the plugin once all usage |
| 34 | // removed from the dialogs. |
| 35 | #define PPK_CupsOptions QPrintEngine::PrintEnginePropertyKey(0xfe00) |
| 36 | |
| 37 | #define PDPK_PpdFile QPrintDevice::PrintDevicePropertyKey(QPrintDevice::PDPK_CustomBase) |
| 38 | #define PDPK_PpdOption QPrintDevice::PrintDevicePropertyKey(QPrintDevice::PDPK_CustomBase + 1) |
| 39 | #define PDPK_CupsJobPriority QPrintDevice::PrintDevicePropertyKey(QPrintDevice::PDPK_CustomBase + 2) |
| 40 | #define PDPK_CupsJobSheets QPrintDevice::PrintDevicePropertyKey(QPrintDevice::PDPK_CustomBase + 3) |
| 41 | #define PDPK_CupsJobBilling QPrintDevice::PrintDevicePropertyKey(QPrintDevice::PDPK_CustomBase + 4) |
| 42 | #define PDPK_CupsJobHoldUntil QPrintDevice::PrintDevicePropertyKey(QPrintDevice::PDPK_CustomBase + 5) |
| 43 | #define PDPK_PpdChoiceIsInstallableConflict QPrintDevice::PrintDevicePropertyKey(QPrintDevice::PDPK_CustomBase + 6) |
| 44 | |
| 45 | class Q_PRINTSUPPORT_EXPORT QCUPSSupport |
| 46 | { |
| 47 | public: |
| 48 | // Enum for values of job-hold-until option |
| 49 | enum JobHoldUntil { |
| 50 | NoHold = 0, //CUPS Default |
| 51 | Indefinite, |
| 52 | DayTime, |
| 53 | Night, |
| 54 | SecondShift, |
| 55 | ThirdShift, |
| 56 | Weekend, |
| 57 | SpecificTime |
| 58 | }; |
| 59 | |
| 60 | // Enum for valid banner pages |
| 61 | enum BannerPage { |
| 62 | NoBanner = 0, //CUPS Default 'none' |
| 63 | Standard, |
| 64 | Unclassified, |
| 65 | Confidential, |
| 66 | Classified, |
| 67 | Secret, |
| 68 | TopSecret |
| 69 | }; |
| 70 | |
| 71 | // Enum for valid page set |
| 72 | enum PageSet { |
| 73 | AllPages = 0, //CUPS Default |
| 74 | OddPages, |
| 75 | EvenPages |
| 76 | }; |
| 77 | |
| 78 | // Enum for valid number of pages per sheet |
| 79 | enum PagesPerSheet { |
| 80 | OnePagePerSheet = 0, |
| 81 | TwoPagesPerSheet, |
| 82 | FourPagesPerSheet, |
| 83 | SixPagesPerSheet, |
| 84 | NinePagesPerSheet, |
| 85 | SixteenPagesPerSheet |
| 86 | }; |
| 87 | |
| 88 | // Enum for valid layouts of pages per sheet |
| 89 | enum PagesPerSheetLayout { |
| 90 | LeftToRightTopToBottom = 0, |
| 91 | LeftToRightBottomToTop, |
| 92 | RightToLeftTopToBottom, |
| 93 | RightToLeftBottomToTop, |
| 94 | BottomToTopLeftToRight, |
| 95 | BottomToTopRightToLeft, |
| 96 | TopToBottomLeftToRight, |
| 97 | TopToBottomRightToLeft |
| 98 | }; |
| 99 | |
| 100 | static void setCupsOption(QPrinter *printer, const QString &option, const QString &value); |
| 101 | static void clearCupsOption(QPrinter *printer, const QString &option); |
| 102 | static void clearCupsOptions(QPrinter *printer); |
| 103 | |
| 104 | static void setJobHold(QPrinter *printer, const JobHoldUntil jobHold = NoHold, QTime holdUntilTime = QTime()); |
| 105 | static void setJobBilling(QPrinter *printer, const QString &jobBilling = QString()); |
| 106 | static void setJobPriority(QPrinter *printer, int priority = 50); |
| 107 | static void setBannerPages(QPrinter *printer, const BannerPage startBannerPage, const BannerPage endBannerPage); |
| 108 | static void setPageSet(QPrinter *printer, const PageSet pageSet); |
| 109 | static void setPagesPerSheetLayout(QPrinter *printer, const PagesPerSheet pagesPerSheet, |
| 110 | const PagesPerSheetLayout pagesPerSheetLayout); |
| 111 | static void (QPrinter *printer, int pageFrom, int pageTo); |
| 112 | static void (QPrinter *printer, const QString &); |
| 113 | |
| 114 | struct JobSheets |
| 115 | { |
| 116 | JobSheets(BannerPage s = NoBanner, BannerPage e = NoBanner) |
| 117 | : startBannerPage(s), endBannerPage(e) {} |
| 118 | |
| 119 | BannerPage startBannerPage; |
| 120 | BannerPage endBannerPage; |
| 121 | }; |
| 122 | static JobSheets parseJobSheets(const QString &jobSheets); |
| 123 | |
| 124 | struct JobHoldUntilWithTime |
| 125 | { |
| 126 | JobHoldUntilWithTime(JobHoldUntil jh = NoHold, QTime t = QTime()) |
| 127 | : jobHold(jh), time(t) {} |
| 128 | |
| 129 | JobHoldUntil jobHold; |
| 130 | QTime time; |
| 131 | }; |
| 132 | static JobHoldUntilWithTime parseJobHoldUntil(const QString &jobHoldUntil); |
| 133 | |
| 134 | static ppd_option_t *findPpdOption(const char *optionName, QPrintDevice *printDevice); |
| 135 | }; |
| 136 | Q_DECLARE_TYPEINFO(QCUPSSupport::JobHoldUntil, Q_PRIMITIVE_TYPE); |
| 137 | Q_DECLARE_TYPEINFO(QCUPSSupport::BannerPage, Q_PRIMITIVE_TYPE); |
| 138 | Q_DECLARE_TYPEINFO(QCUPSSupport::PageSet, Q_PRIMITIVE_TYPE); |
| 139 | Q_DECLARE_TYPEINFO(QCUPSSupport::PagesPerSheetLayout, Q_PRIMITIVE_TYPE); |
| 140 | Q_DECLARE_TYPEINFO(QCUPSSupport::PagesPerSheet, Q_PRIMITIVE_TYPE); |
| 141 | |
| 142 | QT_END_NAMESPACE |
| 143 | |
| 144 | QT_DECL_METATYPE_EXTERN_TAGGED(QCUPSSupport::JobHoldUntil, |
| 145 | QCUPSSupport__JobHoldUntil, Q_PRINTSUPPORT_EXPORT) |
| 146 | QT_DECL_METATYPE_EXTERN_TAGGED(QCUPSSupport::BannerPage, |
| 147 | QCUPSSupport__BannerPage, Q_PRINTSUPPORT_EXPORT) |
| 148 | QT_DECL_METATYPE_EXTERN_TAGGED(QCUPSSupport::PageSet, QCUPSSupport__PageSet, Q_PRINTSUPPORT_EXPORT) |
| 149 | QT_DECL_METATYPE_EXTERN_TAGGED(QCUPSSupport::PagesPerSheetLayout, |
| 150 | QCUPSSupport__PagesPerSheetLayout, Q_PRINTSUPPORT_EXPORT) |
| 151 | QT_DECL_METATYPE_EXTERN_TAGGED(QCUPSSupport::PagesPerSheet, |
| 152 | QCUPSSupport__PagesPerSheet, Q_PRINTSUPPORT_EXPORT) |
| 153 | |
| 154 | #endif |
| 155 | |