| 51 | } |
| 52 | |
| 53 | Document::PrintError |
| 54 | FilePrinter::doPrintFiles(QPrinter &printer, const QStringList &fileList, FileDeletePolicy fileDeletePolicy, PageSelectPolicy pageSelectPolicy, const QString &pageRange, QPageLayout::Orientation documentOrientation, ScaleMode scaleMode) |
| 55 | { |
| 56 | if (fileList.size() < 1) { |
| 57 | return Document::NoFileToPrintError; |
| 58 | } |
| 59 | |
| 60 | for (QStringList::ConstIterator it = fileList.constBegin(); it != fileList.constEnd(); ++it) { |
| 61 | if (!QFile::exists(*it)) { |
| 62 | return Document::UnableToFindFilePrintError; |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | if (printer.printerState() == QPrinter::Aborted || printer.printerState() == QPrinter::Error) { |
| 67 | return Document::InvalidPrinterStatePrintError; |
| 68 | } |
| 69 | |
| 70 | QString exe; |
| 71 | QStringList argList; |
| 72 | Document::PrintError ret; |
| 73 | |
| 74 | // Print to File if a filename set, assumes there must be only 1 file |
| 75 | if (!printer.outputFileName().isEmpty()) { |
| 76 | if (QFile::exists(printer.outputFileName())) { |
| 77 | QFile::remove(printer.outputFileName()); |
| 78 | } |
| 79 | |
| 80 | QFileInfo inputFileInfo = QFileInfo(fileList[0]); |
| 81 | QFileInfo outputFileInfo = QFileInfo(printer.outputFileName()); |
| 82 | |
| 83 | bool doDeleteFile = (fileDeletePolicy == FilePrinter::SystemDeletesFiles); |
| 84 | if (inputFileInfo.suffix() == outputFileInfo.suffix()) { |
| 85 | if (doDeleteFile) { |
| 86 | bool res = QFile::rename(fileList[0], printer.outputFileName()); |
| 87 | if (res) { |
| 88 | doDeleteFile = false; |
| 89 | ret = Document::NoPrintError; |
| 90 | } else { |
| 91 | ret = Document::PrintToFilePrintError; |
| 92 | } |
| 93 | } else { |
| 94 | bool res = QFile::copy(fileList[0], printer.outputFileName()); |
| 95 | if (res) { |
| 96 | ret = Document::NoPrintError; |
| 97 | } else { |
| 98 | ret = Document::PrintToFilePrintError; |
| 99 | } |
| 100 | } |
| 101 | } else if (inputFileInfo.suffix() == QLatin1String("ps") && printer.outputFormat() == QPrinter::PdfFormat && ps2pdfAvailable()) { |
| 102 | exe = QStringLiteral("ps2pdf"); |
| 103 | argList << fileList[0] << printer.outputFileName(); |
| 104 | qCDebug(OkularCoreDebug) << "Executing" << exe << "with arguments" << argList; |
| 105 | ret = doKProcessExecute(exe, argList); |
| 106 | } else if (inputFileInfo.suffix() == QLatin1String("pdf") && printer.outputFormat() == QPrinter::NativeFormat && pdf2psAvailable()) { |
| 107 | exe = QStringLiteral("pdf2ps"); |
| 108 | argList << fileList[0] << printer.outputFileName(); |
| 109 | qCDebug(OkularCoreDebug) << "Executing" << exe << "with arguments" << argList; |
| 110 | ret = doKProcessExecute(exe, argList); |
no test coverage detected