1 /****************************************************************************
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 or version 3 as published by the Free
20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22 ** following information to ensure the GNU Lesser General Public License
23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 **
26 ** As a special exception, The Qt Company gives you certain additional
27 ** rights. These rights are described in The Qt Company LGPL Exception
28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 **
30 ** GNU General Public License Usage
31 ** Alternatively, this file may be used under the terms of the GNU
32 ** General Public License version 3.0 as published by the Free Software
33 ** Foundation and appearing in the file LICENSE.GPL included in the
34 ** packaging of this file.  Please review the following information to
35 ** ensure the GNU General Public License version 3.0 requirements will be
36 ** met: http://www.gnu.org/copyleft/gpl.html.
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QCUPS_P_H
43 #define QCUPS_P_H
44 
45 //
46 //  W A R N I N G
47 //  -------------
48 //
49 // This file is not part of the Qt API.  It exists purely as an
50 // implementation detail.  This header file may change from version to
51 // version without notice, or even be removed.
52 //
53 // We mean it.
54 //
55 #include "QtCore/qstring.h"
56 #include "QtCore/qstringlist.h"
57 #include "QtGui/qprinter.h"
58 
59 #ifndef QT_NO_CUPS
60 #include <QtCore/qlibrary.h>
61 #include <cups/cups.h>
62 #include <cups/ppd.h>
63 
64 QT_BEGIN_NAMESPACE
65 
66 Q_DECLARE_TYPEINFO(cups_option_t, Q_MOVABLE_TYPE | Q_PRIMITIVE_TYPE);
67 
68 class QCUPSSupport
69 {
70 public:
71     QCUPSSupport();
72     ~QCUPSSupport();
73 
74     static bool isAvailable();
cupsVersion()75     static int cupsVersion() { return isAvailable() ? CUPS_VERSION_MAJOR*10000+CUPS_VERSION_MINOR*100+CUPS_VERSION_PATCH : 0; }
76     int availablePrintersCount() const;
77     const cups_dest_t* availablePrinters() const;
78     int currentPrinterIndex() const;
79     const ppd_file_t* setCurrentPrinter(int index);
80 
81     const ppd_file_t* currentPPD() const;
82     const ppd_option_t* ppdOption(const char *key) const;
83 
84     const cups_option_t* printerOption(const QString &key) const;
85     const ppd_option_t* pageSizes() const;
86 
87     int markOption(const char* name, const char* value);
88     void saveOptions(QList<const ppd_option_t*> options, QList<const char*> markedOptions);
89 
90     QRect paperRect(const char *choice) const;
91     QRect pageRect(const char *choice) const;
92 
93     QStringList options() const;
94 
95     static bool printerHasPPD(const char *printerName);
96 
97     QString unicodeString(const char *s);
98 
99     QPair<int, QString> tempFd();
100     int printFile(const char * printerName, const char * filename, const char * title,
101                   int num_options, cups_option_t * options);
102 
103 private:
104     void collectMarkedOptions(QStringList& list, const ppd_group_t* group = 0) const;
105     void collectMarkedOptionsHelper(QStringList& list, const ppd_group_t* group) const;
106 
107     int prnCount;
108     cups_dest_t *printers;
109     const ppd_option_t* page_sizes;
110     int currPrinterIndex;
111     ppd_file_t *currPPD;
112 #ifndef QT_NO_TEXTCODEC
113     QTextCodec *codec;
114 #endif
115 };
116 
117 QT_END_NAMESPACE
118 
119 #endif // QT_NO_CUPS
120 
121 #endif
122