2007-11-26 21:43:54 +00:00
|
|
|
/***************************************************************************
|
2010-06-04 08:25:25 +00:00
|
|
|
* Copyright (C) 2007, 2010 by John Layt <john@layt.net> *
|
2007-11-26 21:43:54 +00:00
|
|
|
* *
|
|
|
|
* 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
|
|
|
|
|
2018-08-31 09:23:45 +00:00
|
|
|
#include <QList>
|
|
|
|
#include <QPrinter>
|
|
|
|
#include <QString>
|
2011-06-05 22:40:22 +00:00
|
|
|
|
2011-06-01 08:31:44 +00:00
|
|
|
#include "generator.h"
|
2014-10-27 21:35:06 +00:00
|
|
|
#include "okularcore_export.h"
|
2007-11-26 21:43:54 +00:00
|
|
|
|
|
|
|
class QSize;
|
|
|
|
|
|
|
|
namespace Okular
|
|
|
|
{
|
2014-10-27 21:35:06 +00:00
|
|
|
class OKULARCORE_EXPORT FilePrinter
|
2007-11-26 21:43:54 +00:00
|
|
|
{
|
|
|
|
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 };
|
|
|
|
|
2019-04-15 03:08:59 +00:00
|
|
|
/** 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 };
|
|
|
|
|
2007-11-26 21:43:54 +00:00
|
|
|
/** 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.
|
|
|
|
*
|
2011-06-05 22:40:22 +00:00
|
|
|
* The documentOrientation parameter was added in version 0.14.
|
|
|
|
*
|
2007-11-26 21:43:54 +00:00
|
|
|
* @param printer the print settings to use
|
|
|
|
* @param file the file to print
|
2011-06-05 22:40:22 +00:00
|
|
|
* @param documentOrientation the orientation stored in the document itself
|
2019-04-15 03:08:59 +00:00
|
|
|
* @param scaleMode scale mode to use
|
2007-11-26 21:43:54 +00:00
|
|
|
* @param fileDeletePolicy if the application or system deletes the file
|
|
|
|
* @param pageSelectPolicy if the application or system selects the pages to print
|
2015-03-14 15:10:09 +00:00
|
|
|
* @param pageRange page range to print if SystemSelectsPages and user chooses Selection in Print Dialog
|
2007-11-26 21:43:54 +00:00
|
|
|
*
|
|
|
|
* @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
|
2009-12-24 14:39:49 +00:00
|
|
|
* -5 if print to file copy failed
|
2007-11-26 21:43:54 +00:00
|
|
|
* -2 if the KProcess could not be started
|
|
|
|
* -1 if the KProcess crashed
|
|
|
|
* otherwise the KProcess exit code
|
2011-06-05 22:40:22 +00:00
|
|
|
*
|
2019-04-15 03:08:59 +00:00
|
|
|
* @since 1.8
|
2007-11-26 21:43:54 +00:00
|
|
|
*/
|
2020-01-02 13:27:11 +00:00
|
|
|
// TODO make file const QString & when a BIC change happens somehwere else
|
2019-04-15 03:08:59 +00:00
|
|
|
static int printFile(QPrinter &printer, const QString file, QPrinter::Orientation documentOrientation, FileDeletePolicy fileDeletePolicy, PageSelectPolicy pageSelectPolicy, const QString &pageRange, ScaleMode scaleMode);
|
2007-11-26 21:43:54 +00:00
|
|
|
|
2019-04-15 03:08:59 +00:00
|
|
|
/** 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
|
2008-01-12 18:52:27 +00:00
|
|
|
static int printFile(QPrinter &printer,
|
|
|
|
const QString file,
|
2011-06-05 22:40:22 +00:00
|
|
|
QPrinter::Orientation documentOrientation,
|
2007-11-26 21:43:54 +00:00
|
|
|
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
|
2010-06-04 19:04:05 +00:00
|
|
|
* @param currentPage the current page number, needed if CurrentPage option is selected
|
2007-11-26 21:43:54 +00:00
|
|
|
* @param selectedPageList list of pages to use if Selection option is selected
|
|
|
|
* @returns Returns list of pages to print
|
|
|
|
*/
|
2010-06-04 08:25:25 +00:00
|
|
|
static QList<int> pageList(QPrinter &printer, int lastPage, int currentPage, const QList<int> &selectedPageList);
|
2007-11-26 21:43:54 +00:00
|
|
|
|
2010-06-04 19:04:05 +00:00
|
|
|
/** 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);
|
|
|
|
|
2007-11-26 21:43:54 +00:00
|
|
|
/** 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);
|
|
|
|
|
2008-12-14 23:18:52 +00:00
|
|
|
/** 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();
|
|
|
|
|
2007-11-26 21:43:54 +00:00
|
|
|
/** 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);
|
|
|
|
|
2010-04-16 21:56:16 +00:00
|
|
|
/**
|
|
|
|
* Convert the code returned by printFile* to PrintError
|
|
|
|
* @since 0.11 (KDE 4.5)
|
|
|
|
*/
|
|
|
|
static Generator::PrintError printError(int c);
|
|
|
|
|
2007-11-26 21:43:54 +00:00
|
|
|
protected:
|
|
|
|
bool detectCupsService();
|
|
|
|
bool detectCupsConfig();
|
|
|
|
|
2020-01-02 13:27:11 +00:00
|
|
|
// TODO make fileList const QStringList & when a BIC change happens somehwere else
|
2007-11-26 21:43:54 +00:00
|
|
|
int doPrintFiles(QPrinter &printer, const QStringList fileList, FileDeletePolicy fileDeletePolicy, PageSelectPolicy pageSelectPolicy, const QString &pageRange, QPrinter::Orientation documentOrientation);
|
2019-04-15 03:08:59 +00:00
|
|
|
// 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);
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2011-06-05 22:40:22 +00:00
|
|
|
QStringList printArguments(QPrinter &printer, FileDeletePolicy fileDeletePolicy, PageSelectPolicy pageSelectPolicy, bool useCupsOptions, const QString &pageRange, const QString &version, QPrinter::Orientation documentOrientation);
|
2019-04-15 03:08:59 +00:00
|
|
|
// 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);
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2007-11-26 21:43:54 +00:00
|
|
|
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);
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2011-06-05 22:40:22 +00:00
|
|
|
QStringList cupsOptions(QPrinter &printer, QPrinter::Orientation documentOrientation);
|
2019-04-15 03:08:59 +00:00
|
|
|
// TODO merge with function above when a BIC change happens somehwere else
|
|
|
|
/// @since 1.8
|
|
|
|
QStringList cupsOptions(QPrinter &printer, QPrinter::Orientation documentOrientation, ScaleMode scaleMode);
|
2007-11-26 21:43:54 +00:00
|
|
|
QStringList optionMedia(QPrinter &printer);
|
|
|
|
QString mediaPageSize(QPrinter &printer);
|
|
|
|
QString mediaPaperSource(QPrinter &printer);
|
2011-06-05 22:40:22 +00:00
|
|
|
QStringList optionOrientation(QPrinter &printer, QPrinter::Orientation documentOrientation);
|
2007-11-26 21:43:54 +00:00
|
|
|
QStringList optionDoubleSidedPrinting(QPrinter &printer);
|
|
|
|
QStringList optionPageOrder(QPrinter &printer);
|
|
|
|
QStringList optionCollateCopies(QPrinter &printer);
|
2008-12-11 23:04:07 +00:00
|
|
|
QStringList optionPageMargins(QPrinter &printer);
|
2019-04-15 03:08:59 +00:00
|
|
|
// TODO merge with function above when a BIC change happens somehwere else
|
|
|
|
/// @since 1.8
|
|
|
|
QStringList optionPageMargins(QPrinter &printer, ScaleMode scaleMode);
|
2008-06-05 23:06:21 +00:00
|
|
|
QStringList optionCupsProperties(QPrinter &printer);
|
2007-11-26 21:43:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // FILEPRINTER_H
|