fileprinter.h 10.3 KB
Newer Older
John Layt's avatar
John Layt committed
1
/***************************************************************************
2
 *   Copyright (C) 2007, 2010 by John Layt <john@layt.net>                 *
John Layt's avatar
John Layt committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 ***************************************************************************/

// This Class is a temporary addition to Okular for the duration of KDE 4.0.
// In KDE 4.1 this class will either be moved to kdelibs if still required,
// or replaced  with a Qt 4.4 based solution.

#ifndef FILEPRINTER_H
#define FILEPRINTER_H

Yuri Chornoivan's avatar
Yuri Chornoivan committed
17 18 19
#include <QList>
#include <QString>
#include <QPrinter>
20

21
#include "okularcore_export.h"
22
#include "generator.h"
John Layt's avatar
John Layt committed
23 24 25 26 27

class QSize;

namespace Okular {

28
class OKULARCORE_EXPORT FilePrinter
John Layt's avatar
John Layt committed
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
{
public:

    /** Whether file(s) get deleted by the application or by the print system.
     *
     *  You may need to chose system deletion if your temp file clean-up
     *  deletes the file before the print system is finished with it.
     */
    enum FileDeletePolicy { ApplicationDeletesFiles, SystemDeletesFiles };

    /** Whether pages to be printed are selected by the application or the print system.
     *
     *  If application side, then the generated file will only contain those pages
     *  selected by the user, so FilePrinter will print all the pages in the file.
     *
     *  If system side, then the file will contain all the pages in the document, and
     *  the print system will print the users selected print range from out of the file.
     *
     *  Note system side only works in CUPS, not LPR.
     */
    enum PageSelectPolicy { ApplicationSelectsPages, SystemSelectsPages };

51 52 53 54 55 56 57 58 59 60 61 62 63 64
    /** Whether to apply scaling when printing.
     *
     * 'NoScaling' indicates that no scaling should be applied.
     * 'FitToPrintArea' indicates that the document should be scaled to the
     * area that is available for printing. Whether or not this includes the printer's
     * hardware margins depends on the value of 'QPrinter::fullPage()' for the given printer.
     *
     * @since 1.8
     */
    enum ScaleMode {
        NoScaling = 0,
        FitToPrintArea = 1
    };

John Layt's avatar
John Layt committed
65 66 67 68 69
    /** Print a file using the settings in QPrinter
     *
     *  Only supports CUPS and LPR on *NIX.  Page Range only supported in CUPS.
     *  Most settings unsupported by LPR, some settings unsupported by CUPS.
     *
70 71
     *  The documentOrientation parameter was added in version 0.14.
     *
John Layt's avatar
John Layt committed
72 73
     * @param printer the print settings to use
     * @param file the file to print
74
     * @param documentOrientation the orientation stored in the document itself
75
     * @param scaleMode scale mode to use
John Layt's avatar
John Layt committed
76 77
     * @param fileDeletePolicy if the application or system deletes the file
     * @param pageSelectPolicy if the application or system selects the pages to print
Albert Astals Cid's avatar
Albert Astals Cid committed
78
     * @param pageRange page range to print if SystemSelectsPages and user chooses Selection in Print Dialog
John Layt's avatar
John Layt committed
79 80 81 82 83 84
     *
     * @returns Returns exit code:
     *          -9 if lpr not found
     *          -8 if empty file name
     *          -7 if unable to find file
     *          -6 if invalid printer state
85
     *          -5 if print to file copy failed
John Layt's avatar
John Layt committed
86 87 88
     *          -2 if the KProcess could not be started
     *          -1 if the KProcess crashed
     *          otherwise the KProcess exit code
89
     *
90
     * @since 1.8
John Layt's avatar
John Layt committed
91
     */
92 93 94 95 96 97 98
    static int printFile( QPrinter &printer, const QString file,
                          QPrinter::Orientation documentOrientation,
                          FileDeletePolicy fileDeletePolicy,
                          PageSelectPolicy pageSelectPolicy,
                          const QString &pageRange,
                          ScaleMode scaleMode
                        );
John Layt's avatar
John Layt committed
99

100 101 102 103 104 105 106 107
    /** Print a file using the settings in QPrinter
     *
     *  Same as 'printFile()' with 7 parameters, but always using a 'scaleMode' of
     * 'FitToPrintArea'.
     *
     * @since 0.14 (KDE 4.8)
     */
    // TODO merge with function above when a BIC change happens somehwere else
108
    static int printFile( QPrinter &printer, const QString file,
109
                          QPrinter::Orientation documentOrientation,
John Layt's avatar
John Layt committed
110 111 112 113 114 115 116 117
                          FileDeletePolicy fileDeletePolicy = FilePrinter::ApplicationDeletesFiles,
                          PageSelectPolicy pageSelectPolicy = FilePrinter::ApplicationSelectsPages,
                          const QString &pageRange = QString() );

    /** Return the list of pages selected by the user in the Print Dialog
     *
     * @param printer the print settings to use
     * @param lastPage the last page number, needed if AllPages option is selected
118
     * @param currentPage the current page number, needed if CurrentPage option is selected
John Layt's avatar
John Layt committed
119 120 121
     * @param selectedPageList list of pages to use if Selection option is selected
     * @returns Returns list of pages to print
     */
122 123
    static QList<int> pageList( QPrinter &printer, int lastPage,
                                int currentPage, const QList<int> &selectedPageList );
John Layt's avatar
John Layt committed
124

125 126 127 128 129 130 131 132 133
    /** Return the list of pages selected by the user in the Print Dialog
     *
     * @param printer the print settings to use
     * @param lastPage the last page number, needed if AllPages option is selected
     * @param selectedPageList list of pages to use if Selection option is selected
     * @returns Returns list of pages to print
     */
    static QList<int> pageList( QPrinter &printer, int lastPage, const QList<int> &selectedPageList );

John Layt's avatar
John Layt committed
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
    /** Return the range of pages selected by the user in the Print Dialog
     *
     * @param printer the print settings to use
     * @param lastPage the last page number, needed if AllPages option is selected
     * @param selectedPageList list of pages to use if Selection option is selected
     * @returns Returns range of pages to print
     */
    static QString pageRange( QPrinter &printer, int lastPage, const QList<int> &selectedPageList );

    /** convert a Page List into a Page Range
     *
     * @param pageList list of pages to convert
     * @returns Returns equivalent page range
     */
    static QString pageListToPageRange( const QList<int> &pageList );

150 151 152 153 154 155 156 157 158 159 160 161
    /** Return if Ghostscript ps2pdf is available on this system
     *
     * @returns Returns true if Ghostscript ps2pdf available
     */
     static bool ps2pdfAvailable();

    /** Return if Ghostscript pdf2ps is available on this system
     *
     * @returns Returns true if Ghostscript pdf2ps available
     */
     static bool pdf2psAvailable();

John Layt's avatar
John Layt committed
162 163 164 165 166 167 168 169 170 171 172 173
    /** Return if CUPS Print System is available on this system
     *
     * @returns Returns true if CUPS available
     */
    static bool cupsAvailable();

    /** Returns the postscript standard page size
     *
     * @returns Returns paper size in ps points
     */
    static QSize psPaperSize( QPrinter &printer );

174 175 176 177 178 179
    /**
     * Convert the code returned by printFile* to PrintError
     * @since 0.11 (KDE 4.5)
     */
    static Generator::PrintError printError( int c );

John Layt's avatar
John Layt committed
180 181 182 183 184
protected:

    bool detectCupsService();
    bool detectCupsConfig();

185
    int doPrintFiles( QPrinter &printer, const QStringList fileList,
John Layt's avatar
John Layt committed
186
                             FileDeletePolicy fileDeletePolicy, PageSelectPolicy pageSelectPolicy,
187 188
                             const QString &pageRange,
                             QPrinter::Orientation documentOrientation );
189 190 191 192 193 194
    // TODO merge with function above when a BIC change happens somehwere else
    /// @since 1.8
    int doPrintFiles( QPrinter &printer, const QStringList fileList,
                             FileDeletePolicy fileDeletePolicy, PageSelectPolicy pageSelectPolicy,
                             const QString &pageRange,
                             QPrinter::Orientation documentOrientation, ScaleMode scaleMode );
John Layt's avatar
John Layt committed
195 196 197

    QStringList printArguments( QPrinter &printer,
                                       FileDeletePolicy fileDeletePolicy, PageSelectPolicy pageSelectPolicy,
198 199
                                       bool useCupsOptions, const QString &pageRange, const QString &version,
                                       QPrinter::Orientation documentOrientation );
200 201 202 203 204 205
    // TODO merge with function above when a BIC change happens somehwere else
    /// @since 1.8
    QStringList printArguments( QPrinter &printer,
                                       FileDeletePolicy fileDeletePolicy, PageSelectPolicy pageSelectPolicy,
                                       bool useCupsOptions, const QString &pageRange, const QString &version,
                                       QPrinter::Orientation documentOrientation, ScaleMode scaleMode );
John Layt's avatar
John Layt committed
206 207 208 209 210 211 212 213 214

    QStringList destination( QPrinter &printer, const QString &version );
    QStringList copies( QPrinter &printer, const QString &version );
    QStringList jobname( QPrinter &printer, const QString &version );
    QStringList deleteFile( QPrinter &printer, FileDeletePolicy fileDeletePolicy,
                                   const QString &version );
    QStringList pages( QPrinter &printer, PageSelectPolicy pageSelectPolicy,
                              const QString &pageRange, bool useCupsOptions, const QString &version );

215
    QStringList cupsOptions( QPrinter &printer, QPrinter::Orientation documentOrientation );
216 217 218
    // TODO merge with function above when a BIC change happens somehwere else
    /// @since 1.8
    QStringList cupsOptions( QPrinter &printer, QPrinter::Orientation documentOrientation, ScaleMode scaleMode );
John Layt's avatar
John Layt committed
219 220 221
    QStringList optionMedia( QPrinter &printer );
    QString mediaPageSize( QPrinter &printer );
    QString mediaPaperSource( QPrinter &printer );
222
    QStringList optionOrientation( QPrinter &printer, QPrinter::Orientation documentOrientation );
John Layt's avatar
John Layt committed
223 224 225
    QStringList optionDoubleSidedPrinting( QPrinter &printer );
    QStringList optionPageOrder( QPrinter &printer );
    QStringList optionCollateCopies( QPrinter &printer );
John Layt's avatar
John Layt committed
226
    QStringList optionPageMargins( QPrinter &printer );
227 228 229
    // TODO merge with function above when a BIC change happens somehwere else
    /// @since 1.8
    QStringList optionPageMargins( QPrinter &printer, ScaleMode scaleMode );
230
    QStringList optionCupsProperties( QPrinter &printer );
John Layt's avatar
John Layt committed
231 232 233 234 235
};

}

#endif // FILEPRINTER_H