File indexing completed on 2024-04-28 04:32:42

0001 /*
0002     SPDX-FileCopyrightText: 2007, 2010 John Layt <john@layt.net>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 // This Class is a temporary addition to Okular for the duration of KDE 4.0.
0008 // In KDE 4.1 this class will either be moved to kdelibs if still required,
0009 // or replaced  with a Qt 4.4 based solution.
0010 
0011 #ifndef FILEPRINTER_H
0012 #define FILEPRINTER_H
0013 
0014 #include <QList>
0015 #include <QPrinter>
0016 #include <QString>
0017 
0018 #include "document.h"
0019 #include "okularcore_export.h"
0020 
0021 class QSize;
0022 
0023 namespace Okular
0024 {
0025 class OKULARCORE_EXPORT FilePrinter
0026 {
0027 public:
0028     /** Whether file(s) get deleted by the application or by the print system.
0029      *
0030      *  You may need to chose system deletion if your temp file clean-up
0031      *  deletes the file before the print system is finished with it.
0032      */
0033     enum FileDeletePolicy { ApplicationDeletesFiles, SystemDeletesFiles };
0034 
0035     /** Whether pages to be printed are selected by the application or the print system.
0036      *
0037      *  If application side, then the generated file will only contain those pages
0038      *  selected by the user, so FilePrinter will print all the pages in the file.
0039      *
0040      *  If system side, then the file will contain all the pages in the document, and
0041      *  the print system will print the users selected print range from out of the file.
0042      *
0043      *  Note system side only works in CUPS, not LPR.
0044      */
0045     enum PageSelectPolicy { ApplicationSelectsPages, SystemSelectsPages };
0046 
0047     /** Whether to apply scaling when printing.
0048      *
0049      * 'NoScaling' indicates that no scaling should be applied.
0050      * 'FitToPrintArea' indicates that the document should be scaled to the
0051      * area that is available for printing. Whether or not this includes the printer's
0052      * hardware margins depends on the value of 'QPrinter::fullPage()' for the given printer.
0053      *
0054      * @since 1.8
0055      */
0056     enum ScaleMode { NoScaling = 0, FitToPrintArea = 1 };
0057 
0058     /** Print a file using the settings in QPrinter
0059      *
0060      *  Only supports CUPS and LPR on *NIX.  Page Range only supported in CUPS.
0061      *  Most settings unsupported by LPR, some settings unsupported by CUPS.
0062      *
0063      *  The documentOrientation parameter was added in version 0.14.
0064      *
0065      * @param printer the print settings to use
0066      * @param file the file to print
0067      * @param documentOrientation the orientation stored in the document itself
0068      * @param scaleMode scale mode to use
0069      * @param fileDeletePolicy if the application or system deletes the file
0070      * @param pageSelectPolicy if the application or system selects the pages to print
0071      * @param pageRange page range to print if SystemSelectsPages and user chooses Selection in Print Dialog
0072      *
0073      * @returns Returns exit code:
0074      *          -9 if lpr not found
0075      *          -8 if empty file name
0076      *          -7 if unable to find file
0077      *          -6 if invalid printer state
0078      *          -5 if print to file copy failed
0079      *          -2 if the KProcess could not be started
0080      *          -1 if the KProcess crashed
0081      *          otherwise the KProcess exit code
0082      *
0083      * @since 1.8
0084      */
0085     static Document::PrintError printFile(QPrinter &printer,
0086                                           const QString &file,
0087                                           QPageLayout::Orientation documentOrientation,
0088                                           FileDeletePolicy fileDeletePolicy = FilePrinter::ApplicationDeletesFiles,
0089                                           PageSelectPolicy pageSelectPolicy = FilePrinter::ApplicationSelectsPages,
0090                                           const QString &pageRange = QString(),
0091                                           ScaleMode scaleMode = ScaleMode::FitToPrintArea);
0092 
0093     /** Return the list of pages selected by the user in the Print Dialog
0094      *
0095      * @param printer the print settings to use
0096      * @param lastPage the last page number, needed if AllPages option is selected
0097      * @param currentPage the current page number, needed if CurrentPage option is selected
0098      * @param selectedPageList list of pages to use if Selection option is selected
0099      * @returns Returns list of pages to print
0100      */
0101     static QList<int> pageList(QPrinter &printer, int lastPage, int currentPage, const QList<int> &selectedPageList);
0102 
0103     /** Return if Ghostscript ps2pdf is available on this system
0104      *
0105      * @returns Returns true if Ghostscript ps2pdf available
0106      */
0107     static bool ps2pdfAvailable();
0108 
0109     /** Return if Ghostscript pdf2ps is available on this system
0110      *
0111      * @returns Returns true if Ghostscript pdf2ps available
0112      */
0113     static bool pdf2psAvailable();
0114 
0115 private:
0116     /** Return if CUPS Print System is available on this system
0117      *
0118      * @returns Returns true if CUPS available
0119      */
0120     static bool cupsAvailable();
0121 
0122     Document::PrintError
0123     doPrintFiles(QPrinter &printer, const QStringList &fileList, FileDeletePolicy fileDeletePolicy, PageSelectPolicy pageSelectPolicy, const QString &pageRange, QPageLayout::Orientation documentOrientation, ScaleMode scaleMode);
0124 
0125     /// @since 1.8
0126     QStringList printArguments(QPrinter &printer,
0127                                FileDeletePolicy fileDeletePolicy,
0128                                PageSelectPolicy pageSelectPolicy,
0129                                bool useCupsOptions,
0130                                const QString &pageRange,
0131                                const QString &version,
0132                                QPageLayout::Orientation documentOrientation,
0133                                ScaleMode scaleMode);
0134 
0135     QStringList destination(QPrinter &printer, const QString &version);
0136     QStringList copies(QPrinter &printer, const QString &version);
0137     QStringList jobname(QPrinter &printer, const QString &version);
0138     QStringList deleteFile(QPrinter &printer, FileDeletePolicy fileDeletePolicy, const QString &version);
0139     QStringList pages(QPrinter &printer, PageSelectPolicy pageSelectPolicy, const QString &pageRange, bool useCupsOptions, const QString &version);
0140 
0141     /// @since 1.8
0142     QStringList cupsOptions(QPrinter &printer, QPageLayout::Orientation documentOrientation, ScaleMode scaleMode);
0143     QStringList optionMedia(QPrinter &printer);
0144     QString mediaPageSize(QPrinter &printer);
0145     QString mediaPaperSource(QPrinter &printer);
0146     QStringList optionOrientation(QPrinter &printer, QPageLayout::Orientation documentOrientation);
0147     QStringList optionDoubleSidedPrinting(QPrinter &printer);
0148     QStringList optionPageOrder(QPrinter &printer);
0149     QStringList optionCollateCopies(QPrinter &printer);
0150     /// @since 1.8
0151     QStringList optionPageMargins(QPrinter &printer, ScaleMode scaleMode);
0152     QStringList optionCupsProperties(QPrinter &printer);
0153 };
0154 
0155 }
0156 
0157 #endif // FILEPRINTER_H