Changeset View
Changeset View
Standalone View
Standalone View
core/fileprinter.cpp
Show All 27 Lines | |||||
28 | #include <QStandardPaths> | 28 | #include <QStandardPaths> | ||
29 | 29 | | |||
30 | #include "debug_p.h" | 30 | #include "debug_p.h" | ||
31 | 31 | | |||
32 | using namespace Okular; | 32 | using namespace Okular; | ||
33 | 33 | | |||
34 | int FilePrinter::printFile( QPrinter &printer, const QString file, | 34 | int FilePrinter::printFile( QPrinter &printer, const QString file, | ||
35 | QPrinter::Orientation documentOrientation, FileDeletePolicy fileDeletePolicy, | 35 | QPrinter::Orientation documentOrientation, FileDeletePolicy fileDeletePolicy, | ||
36 | PageSelectPolicy pageSelectPolicy, const QString &pageRange ) | 36 | PageSelectPolicy pageSelectPolicy, const QString &pageRange, bool doScaling ) | ||
37 | { | 37 | { | ||
38 | FilePrinter fp; | 38 | FilePrinter fp; | ||
39 | return fp.doPrintFiles( printer, QStringList( file ), fileDeletePolicy, pageSelectPolicy, pageRange, | 39 | return fp.doPrintFiles( printer, QStringList( file ), fileDeletePolicy, pageSelectPolicy, pageRange, | ||
40 | documentOrientation ); | 40 | documentOrientation, doScaling ); | ||
41 | } | 41 | } | ||
42 | 42 | | |||
43 | int FilePrinter::doPrintFiles( QPrinter &printer, QStringList fileList, FileDeletePolicy fileDeletePolicy, | 43 | int FilePrinter::doPrintFiles( QPrinter &printer, QStringList fileList, FileDeletePolicy fileDeletePolicy, | ||
44 | PageSelectPolicy pageSelectPolicy, const QString &pageRange, | 44 | PageSelectPolicy pageSelectPolicy, const QString &pageRange, | ||
45 | QPrinter::Orientation documentOrientation ) | 45 | QPrinter::Orientation documentOrientation, bool doScaling ) | ||
46 | { | 46 | { | ||
47 | 47 | | |||
48 | if ( fileList.size() < 1 ) { | 48 | if ( fileList.size() < 1 ) { | ||
49 | return -8; | 49 | return -8; | ||
50 | } | 50 | } | ||
51 | 51 | | |||
52 | for (QStringList::ConstIterator it = fileList.constBegin(); it != fileList.constEnd(); ++it) { | 52 | for (QStringList::ConstIterator it = fileList.constBegin(); it != fileList.constEnd(); ++it) { | ||
53 | if (!QFile::exists(*it)) { | 53 | if (!QFile::exists(*it)) { | ||
▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Line(s) | 113 | } else { // Print to a printer via lpr command | |||
125 | } else if ( !QStandardPaths::findExecutable(QStringLiteral("lp")).isEmpty() ) { | 125 | } else if ( !QStandardPaths::findExecutable(QStringLiteral("lp")).isEmpty() ) { | ||
126 | exe = QStringLiteral("lp"); | 126 | exe = QStringLiteral("lp"); | ||
127 | } else { | 127 | } else { | ||
128 | return -9; | 128 | return -9; | ||
129 | } | 129 | } | ||
130 | 130 | | |||
131 | bool useCupsOptions = cupsAvailable(); | 131 | bool useCupsOptions = cupsAvailable(); | ||
132 | argList = printArguments( printer, fileDeletePolicy, pageSelectPolicy, | 132 | argList = printArguments( printer, fileDeletePolicy, pageSelectPolicy, | ||
133 | useCupsOptions, pageRange, exe, documentOrientation ) << fileList; | 133 | useCupsOptions, pageRange, exe, documentOrientation, doScaling ) << fileList; | ||
134 | qCDebug(OkularCoreDebug) << "Executing" << exe << "with arguments" << argList; | 134 | qCDebug(OkularCoreDebug) << "Executing" << exe << "with arguments" << argList; | ||
135 | 135 | | |||
136 | ret = KProcess::execute( exe, argList ); | 136 | ret = KProcess::execute( exe, argList ); | ||
137 | 137 | | |||
138 | } | 138 | } | ||
139 | 139 | | |||
140 | return ret; | 140 | return ret; | ||
141 | } | 141 | } | ||
▲ Show 20 Lines • Show All 177 Lines • ▼ Show 20 Line(s) | 285 | { | |||
319 | return pe; | 319 | return pe; | ||
320 | } | 320 | } | ||
321 | 321 | | |||
322 | 322 | | |||
323 | 323 | | |||
324 | QStringList FilePrinter::printArguments( QPrinter &printer, FileDeletePolicy fileDeletePolicy, | 324 | QStringList FilePrinter::printArguments( QPrinter &printer, FileDeletePolicy fileDeletePolicy, | ||
325 | PageSelectPolicy pageSelectPolicy, bool useCupsOptions, | 325 | PageSelectPolicy pageSelectPolicy, bool useCupsOptions, | ||
326 | const QString &pageRange, const QString &version, | 326 | const QString &pageRange, const QString &version, | ||
327 | QPrinter::Orientation documentOrientation ) | 327 | QPrinter::Orientation documentOrientation, bool doScaling ) | ||
328 | { | 328 | { | ||
329 | QStringList argList; | 329 | QStringList argList; | ||
330 | 330 | | |||
331 | if ( ! destination( printer, version ).isEmpty() ) { | 331 | if ( ! destination( printer, version ).isEmpty() ) { | ||
332 | argList << destination( printer, version ); | 332 | argList << destination( printer, version ); | ||
333 | } | 333 | } | ||
334 | 334 | | |||
335 | if ( ! copies( printer, version ).isEmpty() ) { | 335 | if ( ! copies( printer, version ).isEmpty() ) { | ||
336 | argList << copies( printer, version ); | 336 | argList << copies( printer, version ); | ||
337 | } | 337 | } | ||
338 | 338 | | |||
339 | if ( ! jobname( printer, version ).isEmpty() ) { | 339 | if ( ! jobname( printer, version ).isEmpty() ) { | ||
340 | argList << jobname( printer, version ); | 340 | argList << jobname( printer, version ); | ||
341 | } | 341 | } | ||
342 | 342 | | |||
343 | if ( ! pages( printer, pageSelectPolicy, pageRange, useCupsOptions, version ).isEmpty() ) { | 343 | if ( ! pages( printer, pageSelectPolicy, pageRange, useCupsOptions, version ).isEmpty() ) { | ||
344 | argList << pages( printer, pageSelectPolicy, pageRange, useCupsOptions, version ); | 344 | argList << pages( printer, pageSelectPolicy, pageRange, useCupsOptions, version ); | ||
345 | } | 345 | } | ||
346 | 346 | | |||
347 | if ( useCupsOptions && ! cupsOptions( printer, documentOrientation ).isEmpty() ) { | 347 | if ( useCupsOptions && ! cupsOptions( printer, documentOrientation, doScaling ).isEmpty() ) { | ||
348 | argList << cupsOptions( printer, documentOrientation); | 348 | argList << cupsOptions( printer, documentOrientation, doScaling); | ||
349 | } | 349 | } | ||
350 | 350 | | |||
351 | if ( ! deleteFile( printer, fileDeletePolicy, version ).isEmpty() ) { | 351 | if ( ! deleteFile( printer, fileDeletePolicy, version ).isEmpty() ) { | ||
352 | argList << deleteFile( printer, fileDeletePolicy, version ); | 352 | argList << deleteFile( printer, fileDeletePolicy, version ); | ||
353 | } | 353 | } | ||
354 | 354 | | |||
355 | if ( version == QLatin1String("lp") ) { | 355 | if ( version == QLatin1String("lp") ) { | ||
356 | argList << QStringLiteral("--"); | 356 | argList << QStringLiteral("--"); | ||
▲ Show 20 Lines • Show All 87 Lines • ▼ Show 20 Line(s) | 419 | if ( pageSelectPolicy == FilePrinter::SystemSelectsPages ) { | |||
444 | 444 | | |||
445 | } | 445 | } | ||
446 | 446 | | |||
447 | } | 447 | } | ||
448 | 448 | | |||
449 | return QStringList(); // AllPages | 449 | return QStringList(); // AllPages | ||
450 | } | 450 | } | ||
451 | 451 | | |||
452 | QStringList FilePrinter::cupsOptions( QPrinter &printer, QPrinter::Orientation documentOrientation ) | 452 | QStringList FilePrinter::cupsOptions( QPrinter &printer, QPrinter::Orientation documentOrientation, bool doScaling ) | ||
453 | { | 453 | { | ||
454 | QStringList optionList; | 454 | QStringList optionList; | ||
455 | 455 | | |||
456 | if ( ! optionMedia( printer ).isEmpty() ) { | 456 | if ( ! optionMedia( printer ).isEmpty() ) { | ||
457 | optionList << optionMedia( printer ); | 457 | optionList << optionMedia( printer ); | ||
458 | } | 458 | } | ||
459 | 459 | | |||
460 | if ( ! optionOrientation( printer, documentOrientation ).isEmpty() ) { | 460 | if ( ! optionOrientation( printer, documentOrientation ).isEmpty() ) { | ||
461 | optionList << optionOrientation( printer, documentOrientation ); | 461 | optionList << optionOrientation( printer, documentOrientation ); | ||
462 | } | 462 | } | ||
463 | 463 | | |||
464 | if ( ! optionDoubleSidedPrinting( printer ).isEmpty() ) { | 464 | if ( ! optionDoubleSidedPrinting( printer ).isEmpty() ) { | ||
465 | optionList << optionDoubleSidedPrinting( printer ); | 465 | optionList << optionDoubleSidedPrinting( printer ); | ||
466 | } | 466 | } | ||
467 | 467 | | |||
468 | if ( ! optionPageOrder( printer ).isEmpty() ) { | 468 | if ( ! optionPageOrder( printer ).isEmpty() ) { | ||
469 | optionList << optionPageOrder( printer ); | 469 | optionList << optionPageOrder( printer ); | ||
470 | } | 470 | } | ||
471 | 471 | | |||
472 | if ( ! optionCollateCopies( printer ).isEmpty() ) { | 472 | if ( ! optionCollateCopies( printer ).isEmpty() ) { | ||
473 | optionList << optionCollateCopies( printer ); | 473 | optionList << optionCollateCopies( printer ); | ||
474 | } | 474 | } | ||
475 | 475 | | |||
476 | if ( ! optionPageMargins( printer ).isEmpty() ) { | 476 | if ( ! optionPageMargins( printer, doScaling ).isEmpty() ) { | ||
477 | optionList << optionPageMargins( printer ); | 477 | optionList << optionPageMargins( printer, doScaling ); | ||
478 | } | 478 | } | ||
479 | 479 | | |||
480 | optionList << optionCupsProperties( printer ); | 480 | optionList << optionCupsProperties( printer ); | ||
481 | 481 | | |||
482 | return optionList; | 482 | return optionList; | ||
483 | } | 483 | } | ||
484 | 484 | | |||
485 | QStringList FilePrinter::optionMedia( QPrinter &printer ) | 485 | QStringList FilePrinter::optionMedia( QPrinter &printer ) | ||
▲ Show 20 Lines • Show All 119 Lines • ▼ Show 20 Line(s) | |||||
605 | QStringList FilePrinter::optionCollateCopies( QPrinter &printer ) | 605 | QStringList FilePrinter::optionCollateCopies( QPrinter &printer ) | ||
606 | { | 606 | { | ||
607 | if ( printer.collateCopies() ) { | 607 | if ( printer.collateCopies() ) { | ||
608 | return QStringList(QStringLiteral("-o")) << QStringLiteral("Collate=True"); | 608 | return QStringList(QStringLiteral("-o")) << QStringLiteral("Collate=True"); | ||
609 | } | 609 | } | ||
610 | return QStringList(QStringLiteral("-o")) << QStringLiteral("Collate=False"); | 610 | return QStringList(QStringLiteral("-o")) << QStringLiteral("Collate=False"); | ||
611 | } | 611 | } | ||
612 | 612 | | |||
613 | QStringList FilePrinter::optionPageMargins( QPrinter &printer ) | 613 | QStringList FilePrinter::optionPageMargins( QPrinter &printer, bool doScaling ) | ||
614 | { | 614 | { | ||
615 | if (printer.printEngine()->property(QPrintEngine::PPK_PageMargins).isNull()) { | 615 | if (printer.printEngine()->property(QPrintEngine::PPK_PageMargins).isNull()) { | ||
616 | return QStringList(); | 616 | return QStringList(); | ||
617 | } else { | 617 | } else { | ||
618 | qreal l(0), t(0), r(0), b(0); | 618 | qreal l(0), t(0), r(0), b(0); | ||
619 | if (!printer.fullPage()) { | 619 | if (!printer.fullPage()) { | ||
620 | printer.getPageMargins( &l, &t, &r, &b, QPrinter::Point ); | 620 | printer.getPageMargins( &l, &t, &r, &b, QPrinter::Point ); | ||
621 | } | 621 | } | ||
622 | return QStringList(QStringLiteral("-o")) << QStringLiteral("page-left=%1").arg(l) | 622 | QStringList marginOptions; | ||
623 | marginOptions << (QStringLiteral("-o")) << QStringLiteral("page-left=%1").arg(l) | ||||
623 | << QStringLiteral("-o") << QStringLiteral("page-top=%1").arg(t) | 624 | << QStringLiteral("-o") << QStringLiteral("page-top=%1").arg(t) | ||
624 | << QStringLiteral("-o") << QStringLiteral("page-right=%1").arg(r) | 625 | << QStringLiteral("-o") << QStringLiteral("page-right=%1").arg(r) | ||
625 | << QStringLiteral("-o") << QStringLiteral("page-bottom=%1").arg(b) << QStringLiteral("-o") << QStringLiteral("fit-to-page"); | 626 | << QStringLiteral("-o") << QStringLiteral("page-bottom=%1").arg(b); | ||
627 | if (doScaling) { | ||||
628 | marginOptions << QStringLiteral("-o") << QStringLiteral("fit-to-page"); | ||||
629 | } | ||||
630 | | ||||
631 | return marginOptions; | ||||
626 | } | 632 | } | ||
627 | } | 633 | } | ||
628 | 634 | | |||
629 | QStringList FilePrinter::optionCupsProperties( QPrinter &printer ) | 635 | QStringList FilePrinter::optionCupsProperties( QPrinter &printer ) | ||
630 | { | 636 | { | ||
631 | QStringList dialogOptions = printer.printEngine()->property(QPrintEngine::PrintEnginePropertyKey(0xfe00)).toStringList(); | 637 | QStringList dialogOptions = printer.printEngine()->property(QPrintEngine::PrintEnginePropertyKey(0xfe00)).toStringList(); | ||
632 | QStringList cupsOptions; | 638 | QStringList cupsOptions; | ||
633 | 639 | | |||
Show All 12 Lines |