Okular

fileprinter.h
1 /*
2  SPDX-FileCopyrightText: 2007, 2010 John Layt <[email protected]>
3 
4  SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 // This Class is a temporary addition to Okular for the duration of KDE 4.0.
8 // In KDE 4.1 this class will either be moved to kdelibs if still required,
9 // or replaced with a Qt 4.4 based solution.
10 
11 #ifndef FILEPRINTER_H
12 #define FILEPRINTER_H
13 
14 #include <QList>
15 #include <QPrinter>
16 #include <QString>
17 
18 #include "document.h"
19 #include "okularcore_export.h"
20 
21 class QSize;
22 
23 namespace Okular
24 {
25 class OKULARCORE_EXPORT FilePrinter
26 {
27 public:
28  /** Whether file(s) get deleted by the application or by the print system.
29  *
30  * You may need to chose system deletion if your temp file clean-up
31  * deletes the file before the print system is finished with it.
32  */
33  enum FileDeletePolicy { ApplicationDeletesFiles, SystemDeletesFiles };
34 
35  /** Whether pages to be printed are selected by the application or the print system.
36  *
37  * If application side, then the generated file will only contain those pages
38  * selected by the user, so FilePrinter will print all the pages in the file.
39  *
40  * If system side, then the file will contain all the pages in the document, and
41  * the print system will print the users selected print range from out of the file.
42  *
43  * Note system side only works in CUPS, not LPR.
44  */
45  enum PageSelectPolicy { ApplicationSelectsPages, SystemSelectsPages };
46 
47  /** Whether to apply scaling when printing.
48  *
49  * 'NoScaling' indicates that no scaling should be applied.
50  * 'FitToPrintArea' indicates that the document should be scaled to the
51  * area that is available for printing. Whether or not this includes the printer's
52  * hardware margins depends on the value of 'QPrinter::fullPage()' for the given printer.
53  *
54  * @since 1.8
55  */
56  enum ScaleMode { NoScaling = 0, FitToPrintArea = 1 };
57 
58  /** Print a file using the settings in QPrinter
59  *
60  * Only supports CUPS and LPR on *NIX. Page Range only supported in CUPS.
61  * Most settings unsupported by LPR, some settings unsupported by CUPS.
62  *
63  * The documentOrientation parameter was added in version 0.14.
64  *
65  * @param printer the print settings to use
66  * @param file the file to print
67  * @param documentOrientation the orientation stored in the document itself
68  * @param scaleMode scale mode to use
69  * @param fileDeletePolicy if the application or system deletes the file
70  * @param pageSelectPolicy if the application or system selects the pages to print
71  * @param pageRange page range to print if SystemSelectsPages and user chooses Selection in Print Dialog
72  *
73  * @returns Returns exit code:
74  * -9 if lpr not found
75  * -8 if empty file name
76  * -7 if unable to find file
77  * -6 if invalid printer state
78  * -5 if print to file copy failed
79  * -2 if the KProcess could not be started
80  * -1 if the KProcess crashed
81  * otherwise the KProcess exit code
82  *
83  * @since 1.8
84  */
85  static Document::PrintError printFile(QPrinter &printer,
86  const QString &file,
87  QPrinter::Orientation documentOrientation,
88  FileDeletePolicy fileDeletePolicy = FilePrinter::ApplicationDeletesFiles,
89  PageSelectPolicy pageSelectPolicy = FilePrinter::ApplicationSelectsPages,
90  const QString &pageRange = QString(),
91  ScaleMode scaleMode = ScaleMode::FitToPrintArea);
92 
93  /** Return the list of pages selected by the user in the Print Dialog
94  *
95  * @param printer the print settings to use
96  * @param lastPage the last page number, needed if AllPages option is selected
97  * @param currentPage the current page number, needed if CurrentPage option is selected
98  * @param selectedPageList list of pages to use if Selection option is selected
99  * @returns Returns list of pages to print
100  */
101  static QList<int> pageList(QPrinter &printer, int lastPage, int currentPage, const QList<int> &selectedPageList);
102 
103  /** Return the list of pages selected by the user in the Print Dialog
104  *
105  * @param printer the print settings to use
106  * @param lastPage the last page number, needed if AllPages option is selected
107  * @param selectedPageList list of pages to use if Selection option is selected
108  * @returns Returns list of pages to print
109  */
110  static QList<int> pageList(QPrinter &printer, int lastPage, const QList<int> &selectedPageList);
111 
112  /** Return the range of pages selected by the user in the Print Dialog
113  *
114  * @param printer the print settings to use
115  * @param lastPage the last page number, needed if AllPages option is selected
116  * @param selectedPageList list of pages to use if Selection option is selected
117  * @returns Returns range of pages to print
118  */
119  static QString pageRange(QPrinter &printer, int lastPage, const QList<int> &selectedPageList);
120 
121  /** convert a Page List into a Page Range
122  *
123  * @param pageList list of pages to convert
124  * @returns Returns equivalent page range
125  */
126  static QString pageListToPageRange(const QList<int> &pageList);
127 
128  /** Return if Ghostscript ps2pdf is available on this system
129  *
130  * @returns Returns true if Ghostscript ps2pdf available
131  */
132  static bool ps2pdfAvailable();
133 
134  /** Return if Ghostscript pdf2ps is available on this system
135  *
136  * @returns Returns true if Ghostscript pdf2ps available
137  */
138  static bool pdf2psAvailable();
139 
140  /** Return if CUPS Print System is available on this system
141  *
142  * @returns Returns true if CUPS available
143  */
144  static bool cupsAvailable();
145 
146  /** Returns the postscript standard page size
147  *
148  * @returns Returns paper size in ps points
149  */
150  static QSize psPaperSize(QPrinter &printer);
151 
152 protected:
153  bool detectCupsService();
154  bool detectCupsConfig();
155 
157  doPrintFiles(QPrinter &printer, const QStringList &fileList, FileDeletePolicy fileDeletePolicy, PageSelectPolicy pageSelectPolicy, const QString &pageRange, QPrinter::Orientation documentOrientation, ScaleMode scaleMode);
158 
159  /// @since 1.8
160  QStringList printArguments(QPrinter &printer,
161  FileDeletePolicy fileDeletePolicy,
162  PageSelectPolicy pageSelectPolicy,
163  bool useCupsOptions,
164  const QString &pageRange,
165  const QString &version,
166  QPrinter::Orientation documentOrientation,
167  ScaleMode scaleMode);
168 
169  QStringList destination(QPrinter &printer, const QString &version);
170  QStringList copies(QPrinter &printer, const QString &version);
171  QStringList jobname(QPrinter &printer, const QString &version);
172  QStringList deleteFile(QPrinter &printer, FileDeletePolicy fileDeletePolicy, const QString &version);
173  QStringList pages(QPrinter &printer, PageSelectPolicy pageSelectPolicy, const QString &pageRange, bool useCupsOptions, const QString &version);
174 
175  /// @since 1.8
176  QStringList cupsOptions(QPrinter &printer, QPrinter::Orientation documentOrientation, ScaleMode scaleMode);
177  QStringList optionMedia(QPrinter &printer);
178  QString mediaPageSize(QPrinter &printer);
179  QString mediaPaperSource(QPrinter &printer);
180  QStringList optionOrientation(QPrinter &printer, QPrinter::Orientation documentOrientation);
181  QStringList optionDoubleSidedPrinting(QPrinter &printer);
182  QStringList optionPageOrder(QPrinter &printer);
183  QStringList optionCollateCopies(QPrinter &printer);
184  /// @since 1.8
185  QStringList optionPageMargins(QPrinter &printer, ScaleMode scaleMode);
186  QStringList optionCupsProperties(QPrinter &printer);
187 };
188 
189 }
190 
191 #endif // FILEPRINTER_H
The documentation to the global Okular namespace.
Definition: action.h:16
QAction * deleteFile(const QObject *recvr, const char *slot, QObject *parent)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Thu Mar 23 2023 04:04:24 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.