1 /***************************************************************************
2 * Copyright (C) 2007 by John Layt <john@layt.net> *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 ***************************************************************************/
10 // This Class is a temporary addition to Okular for the duration of KDE 4.0.
11 // In KDE 4.1 this class will either be moved to kdelibs if still required,
12 // or replaced with a Qt 4.4 based solution.
17 #include <QtCore/QList>
18 #include <QtCore/QString>
20 #include <okular/core/okular_export.h>
27 class OKULAR_EXPORT FilePrinter
31 /** Whether file(s) get deleted by the application or by the print system.
33 * You may need to chose system deletion if your temp file clean-up
34 * deletes the file before the print system is finished with it.
36 enum FileDeletePolicy
{ ApplicationDeletesFiles
, SystemDeletesFiles
};
38 /** Whether pages to be printed are selected by the application or the print system.
40 * If application side, then the generated file will only contain those pages
41 * selected by the user, so FilePrinter will print all the pages in the file.
43 * If system side, then the file will contain all the pages in the document, and
44 * the print system will print the users selected print range from out of the file.
46 * Note system side only works in CUPS, not LPR.
48 enum PageSelectPolicy
{ ApplicationSelectsPages
, SystemSelectsPages
};
50 /** Print a file using the settings in QPrinter
52 * Only supports CUPS and LPR on *NIX. Page Range only supported in CUPS.
53 * Most settings unsupported by LPR, some settings unsupported by CUPS.
55 * @param printer the print settings to use
56 * @param file the file to print
57 * @param fileDeletePolicy if the application or system deletes the file
58 * @param pageSelectPolicy if the application or system selects the pages to print
59 * @param pageRange page range to print if SystemSlectsPages and user chooses Selection in Print Dialog
61 * @returns Returns exit code:
63 * -8 if empty file name
64 * -7 if unable to find file
65 * -6 if invalid printer state
66 * -2 if the KProcess could not be started
67 * -1 if the KProcess crashed
68 * otherwise the KProcess exit code
71 static int printFile( QPrinter
&printer
, const QString file
,
72 FileDeletePolicy fileDeletePolicy
= FilePrinter::ApplicationDeletesFiles
,
73 PageSelectPolicy pageSelectPolicy
= FilePrinter::ApplicationSelectsPages
,
74 const QString
&pageRange
= QString() );
76 /** Print a list of files using the settings in QPrinter
78 * Only supports CUPS and LPR on *NIX.
79 * Most settings unsupported by LPR, some settings unsupported by CUPS.
81 * @param printer the print settings to use
82 * @param fileList the files to print
83 * @param fileDeletePolicy if the application or system deletes the file
85 * @returns Returns exit code:
87 * -8 if empty file list
88 * -7 if unable to find a file
89 * -6 if invalid printer state
90 * -2 if the KProcess could not be started
91 * -1 if the KProcess crashed
92 * otherwise the KProcess exit code
95 static int printFiles( QPrinter
&printer
, const QStringList
&fileList
,
96 FileDeletePolicy fileDeletePolicy
= FilePrinter::ApplicationDeletesFiles
);
98 /** Return the list of pages selected by the user in the Print Dialog
100 * @param printer the print settings to use
101 * @param lastPage the last page number, needed if AllPages option is selected
102 * @param selectedPageList list of pages to use if Selection option is selected
103 * @returns Returns list of pages to print
105 static QList
<int> pageList( QPrinter
&printer
, int lastPage
, const QList
<int> &selectedPageList
);
107 /** Return the range of pages selected by the user in the Print Dialog
109 * @param printer the print settings to use
110 * @param lastPage the last page number, needed if AllPages option is selected
111 * @param selectedPageList list of pages to use if Selection option is selected
112 * @returns Returns range of pages to print
114 static QString
pageRange( QPrinter
&printer
, int lastPage
, const QList
<int> &selectedPageList
);
116 /** convert a Page List into a Page Range
118 * @param pageList list of pages to convert
119 * @returns Returns equivalent page range
121 static QString
pageListToPageRange( const QList
<int> &pageList
);
123 /** Return if Ghostscript ps2pdf is available on this system
125 * @returns Returns true if Ghostscript ps2pdf available
127 static bool ps2pdfAvailable();
129 /** Return if Ghostscript pdf2ps is available on this system
131 * @returns Returns true if Ghostscript pdf2ps available
133 static bool pdf2psAvailable();
135 /** Return if CUPS Print System is available on this system
137 * @returns Returns true if CUPS available
139 static bool cupsAvailable();
141 /** Returns the postscript standard page size
143 * @returns Returns paper size in ps points
145 static QSize
psPaperSize( QPrinter
&printer
);
149 bool detectCupsService();
150 bool detectCupsConfig();
152 int doPrintFiles( QPrinter
&printer
, const QStringList fileList
,
153 FileDeletePolicy fileDeletePolicy
, PageSelectPolicy pageSelectPolicy
,
154 const QString
&pageRange
);
156 QStringList
printArguments( QPrinter
&printer
,
157 FileDeletePolicy fileDeletePolicy
, PageSelectPolicy pageSelectPolicy
,
158 bool useCupsOptions
, const QString
&pageRange
, const QString
&version
);
160 QStringList
destination( QPrinter
&printer
, const QString
&version
);
161 QStringList
copies( QPrinter
&printer
, const QString
&version
);
162 QStringList
jobname( QPrinter
&printer
, const QString
&version
);
163 QStringList
deleteFile( QPrinter
&printer
, FileDeletePolicy fileDeletePolicy
,
164 const QString
&version
);
165 QStringList
pages( QPrinter
&printer
, PageSelectPolicy pageSelectPolicy
,
166 const QString
&pageRange
, bool useCupsOptions
, const QString
&version
);
168 QStringList
cupsOptions( QPrinter
&printer
);
169 QStringList
optionMedia( QPrinter
&printer
);
170 QString
mediaPageSize( QPrinter
&printer
);
171 QString
mediaPaperSource( QPrinter
&printer
);
172 QStringList
optionOrientation( QPrinter
&printer
);
173 QStringList
optionDoubleSidedPrinting( QPrinter
&printer
);
174 QStringList
optionPageOrder( QPrinter
&printer
);
175 QStringList
optionCollateCopies( QPrinter
&printer
);
176 QStringList
optionPageMargins( QPrinter
&printer
);
177 QStringList
optionCupsProperties( QPrinter
&printer
);
182 #endif // FILEPRINTER_H