[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    Re: Okular printing (WAS: Re: libkdeprint)
From:       John Layt <johnlayt () yahoo ! com ! au>
Date:       2007-11-18 3:01:18
Message-ID: 200711180301.18976.johnlayt () yahoo ! com ! au
[Download RAW message or body]

On Tuesday 13 November 2007, Alex Merry wrote:
> On Saturday 03 Nov 2007, John Layt wrote:
> > I'll get the last few margins kinks worked out today and we should be
> > good to go.
>
> How is this doing?  It doesn't seem to be in Okular at the moment.  I'd
> quite like to be able to change the status of printing at
> http://techbase.kde.org/Schedules/KDE4/4.0_Release_Beta_Goals#Printing
>
> Alex

Almost there, still to do:
* ps spectre backend to be completed
* Change namespace to okular (seeing as no other apps left to use it)
* Confirm with dvi maintainer that printing wasn't working before
* Under Win & OSX(?) disable print menu item for FilePrinter backends
* Print preview for ps files by cloning KPrintPreview and call kpart for ps
* Print to file option clean-up
* Revisit the Cups detection stuff

Should be done end of Sunday.

I've been wasting a lot of time trying to solve a problem with Landscape 
printing, which I now think may be a Qt4 bug.

Printing a Portrait PDF document works fine if you select Portrait in the 
Print Dialog, and if you select Landscape in the Print Dialog it is correctly 
oriented and scaled but slightly cut-off at the right margin.

Printing a Landscape PDF document and selecting Landscape in the Print Dialog 
results in a correctly rotated page but cut-off at Portrait length.  Instead, 
selecting Portrait in the Print Dialog produces perfect results.

I also get the same problem in QPainter/QPrinter based backends (e.g. jpegs 
and comicbook) with landscape images, and I'm getting it printing anything 
from the Qt4 Assistant in landscape.  Printing from KDE3 or QT3 Assistant is 
fine. I'm using openSuse 10.3, Qt 4.3.2.  

The Qt bug tracker has some old fixed bugs for what sounds like this problem, 
so I wonder if they've accidently regressed?

Can anyone else replicate this?  Simply fire up Qt4 Assistant and in the print 
dialog choose Landscape and then print and tell me if it comes out OK?  Or 
apply the attached patch and try a landscape format document/image.

Cheers!

John.

--


["okular-fileprinter.diff" (text/x-diff)]

Index: part.cpp
===================================================================
--- part.cpp	(revision 737924)
+++ part.cpp	(working copy)
@@ -968,6 +968,7 @@
         m_reload->setEnabled( true );
         m_copy->setEnabled( true );
         m_selectAll->setEnabled( true );
+
     }
     else
     {
@@ -1291,45 +1292,6 @@
 }
 
 
-void Part::slotPrintPreview()
-{
-    if (m_document->pages() == 0) return;
-
-    double width, height;
-    int landscape, portrait;
-    QPrinter printer;
-    const Okular::Page *page;
-
-//     printer.setMinMax(1, m_document->pages());
-//     printer.setPreviewOnly( true );
-
-    // if some pages are landscape and others are not the most common win as \
                kprinter does
-    // not accept a per page setting
-    landscape = 0;
-    portrait = 0;
-    for (uint i = 0; i < m_document->pages(); i++)
-    {
-        page = m_document->page(i);
-        width = page->width();
-        height = page->height();
-        if (page->orientation() == 90 || page->orientation() == 270) qSwap(width, \
                height);
-        if (width > height) landscape++;
-        else portrait++;
-    }
-    if (landscape > portrait)
-    {
-        //  printer.setOption("orientation-requested", "4");
-        printer.setOrientation( QPrinter::Landscape );
-    }
-
-    KPrintPreview previewdlg( &printer, widget() );
-
-    doPrint(printer);
-
-    previewdlg.exec();
-}
-
-
 void Part::slotShowMenu(const Okular::Page *page, const QPoint &point)
 {
     if (m_dummyMode) return;
@@ -1495,21 +1457,73 @@
 {
     if (m_document->pages() == 0) return;
 
-    double width, height;
-    int landscape, portrait;
     QPrinter printer;
-    const Okular::Page *page;
+    QPrintDialog *printDialog = 0;
+    QWidget *printConfigWidget = 0;
 
-/*  Disable as QPrinter does not support most of this page management stuff.
-    Besides no point sorting this out until we solve the main printFiles problem.
-    However leave basic printing in place as some formats still support it.
+    // Must do certain QPrinter setup before creating QPrintDialog
+    setupPrint( printer );
 
-    printer.setPageSelection(KPrinter::ApplicationSide);
-    printer.setMinMax(1, m_document->pages());
-    printer.setCurrentPage(m_document->currentPage()+1);
-*/
+    // Create the Print Dialog with extra config widgets if required
+    if ( m_document->canConfigurePrinter() )
+    {
+        printConfigWidget = m_document->printConfigurationWidget();
+    }
+    if ( printConfigWidget )
+    {
+        printDialog = KdePrint::createPrintDialog( &printer, QList<QWidget*>() << \
printConfigWidget, widget() ); +    }
+    else
+    {
+        printDialog = KdePrint::createPrintDialog( &printer, widget() );
+    }
 
-    // if some pages are landscape and others are not the most common win as \
kprinter does +    if ( printDialog ) {
+
+        // Set the available Print Range
+        printDialog->setMinMax( 1, m_document->pages() );
+        printDialog->setFromTo( 1, m_document->pages() );
+
+        // If the user has bookmarked pages for printing, then enable Selection
+        if ( !m_document->bookmarkedPageRange().isEmpty() ) {
+            printDialog->addEnabledOption( QAbstractPrintDialog::PrintSelection );
+        }
+
+        // If the Document type doesn't support export to both PS & PDF then disable \
the Print Dialog option +        if ( printDialog->isOptionEnabled( \
QAbstractPrintDialog::PrintToFile ) && +             \
!m_document->supportsPrintToFile() ) { +            printDialog->setEnabledOptions( \
printDialog->enabledOptions() ^ QAbstractPrintDialog::PrintToFile ); +        }
+
+        if ( printDialog->exec() )
+            doPrint( printer );
+
+    }
+}
+
+
+void Part::slotPrintPreview()
+{
+    if (m_document->pages() == 0) return;
+
+    QPrinter printer;
+    KPrintPreview previewdlg( &printer, widget() );
+
+    setupPrint( printer );
+
+    doPrint( printer );
+
+    previewdlg.exec();
+}
+
+
+void Part::setupPrint( QPrinter &printer )
+{
+    double width, height;
+    int landscape, portrait;
+    const Okular::Page *page;
+
+    // if some pages are landscape and others are not the most common win as \
QPrinter does  // not accept a per page setting
     landscape = 0;
     portrait = 0;
@@ -1524,50 +1538,6 @@
     }
     if (landscape > portrait) printer.setOrientation(QPrinter::Landscape);
 
-/*
-    // range detecting
-    QString range;
-    uint pages = m_document->pages();
-    int startId = -1;
-    int endId = -1;
-
-    for ( uint i = 0; i < pages; ++i )
-    {
-        if ( m_document->bookmarkManager()->isBookmarked( i ) )
-        {
-            if ( startId < 0 )
-                startId = i;
-            if ( endId < 0 )
-                endId = startId;
-            else
-                ++endId;
-        }
-        else if ( startId >= 0 && endId >= 0 )
-        {
-            if ( !range.isEmpty() )
-                range += ',';
-
-            if ( endId - startId > 0 )
-                range += QString( "%1-%2" ).arg( startId + 1 ).arg( endId + 1 );
-            else
-                range += QString::number( startId + 1 );
-            startId = -1;
-            endId = -1;
-        }
-    }
-    if ( startId >= 0 && endId >= 0 )
-    {
-        if ( !range.isEmpty() )
-            range += ',';
-
-        if ( endId - startId > 0 )
-            range += QString( "%1-%2" ).arg( startId + 1 ).arg( endId + 1 );
-        else
-            range += QString::number( startId + 1 );
-    }
-    printer.setOption( "kde-range", range );
-*/
-
     // title
     QString title = m_document->metaData( "DocumentTitle" ).toString();
     if ( title.isEmpty() )
@@ -1578,26 +1548,6 @@
     {
         printer.setDocName( title );
     }
-
-    QPrintDialog *printDialog;
-    QWidget * w;
-
-    if ( m_document->canConfigurePrinter() )
-    {
-        w = m_document->printConfigurationWidget();
-    }
-
-    if ( w )
-    {
-        printDialog = KdePrint::createPrintDialog( &printer, QList<QWidget*>() << w, \
                widget() );
-    }
-    else
-    {
-        printDialog = KdePrint::createPrintDialog( &printer, widget() );
-    }
-
-    if ( printDialog->exec() )
-        doPrint( printer );
 }
 
 
Index: core/document.cpp
===================================================================
--- core/document.cpp	(revision 737924)
+++ core/document.cpp	(working copy)
@@ -28,6 +28,7 @@
 #include <QtGui/QApplication>
 #include <QtGui/QLabel>
 #include <QtGui/QPrinter>
+#include <QtGui/QPrintDialog>
 
 #include <kaboutdata.h>
 #include <kauthorized.h>
@@ -1474,17 +1475,6 @@
     return d->m_generator;
 }
 
-bool Document::canConfigurePrinter( ) const
-{
-    if ( d->m_generator )
-    {
-        Okular::PrintInterface * iface = qobject_cast< Okular::PrintInterface * >( \
                d->m_generator );
-        return iface ? true : false;
-    }
-    else
-        return 0;
-}
-
 const DocumentInfo * Document::documentInfo() const
 {
     if ( d->m_generator )
@@ -2173,9 +2163,72 @@
 
 BookmarkManager * Document::bookmarkManager() const
 {
+
     return d->m_bookmarkManager;
 }
 
+QList<int> Document::bookmarkedPageList() const
+{
+    QList<int> list;
+    uint docPages = pages();
+
+    //pages are 0-indexed internally, but 1-indexed externally
+    for ( uint i = 0; i < docPages; i++ )
+    {
+        if ( bookmarkManager()->isBookmarked( i ) )
+        {
+            list << i + 1;
+        }
+    }
+    return list;
+}
+
+QString Document::bookmarkedPageRange() const
+{
+    // Code formerly in Part::slotPrint()
+    // range detecting
+    QString range;
+    uint docPages = pages();
+    int startId = -1;
+    int endId = -1;
+
+    for ( uint i = 0; i < docPages; ++i )
+    {
+        if ( bookmarkManager()->isBookmarked( i ) )
+        {
+            if ( startId < 0 )
+                startId = i;
+            if ( endId < 0 )
+                endId = startId;
+            else
+                ++endId;
+        }
+        else if ( startId >= 0 && endId >= 0 )
+        {
+            if ( !range.isEmpty() )
+                range += ',';
+
+            if ( endId - startId > 0 )
+                range += QString( "%1-%2" ).arg( startId + 1 ).arg( endId + 1 );
+            else
+                range += QString::number( startId + 1 );
+            startId = -1;
+            endId = -1;
+        }
+    }
+    if ( startId >= 0 && endId >= 0 )
+    {
+        if ( !range.isEmpty() )
+            range += ',';
+
+        if ( endId - startId > 0 )
+            range += QString( "%1-%2" ).arg( startId + 1 ).arg( endId + 1 );
+        else
+            range += QString::number( startId + 1 );
+    }
+    return range;
+}
+
 void Document::processAction( const Action * action )
 {
     if ( !action )
@@ -2386,6 +2439,27 @@
     QProcess::startDetached( p );
 }
 
+bool Document::canConfigurePrinter( ) const
+{
+    if ( d->m_generator )
+    {
+        Okular::PrintInterface * iface = qobject_cast< Okular::PrintInterface * >( \
d->m_generator ); +        return iface ? true : false;
+    }
+    else
+        return 0;
+}
+
+bool Document::supportsPrintNative() const
+{
+    return d->m_generator ? d->m_generator->hasFeature( Generator::PrintNative ) : \
false; +}
+
+bool Document::supportsPrintToFile() const
+{
+    return d->m_generator ? d->m_generator->hasFeature( Generator::PrintToFile ) : \
false; +}
+
 bool Document::print( QPrinter &printer )
 {
     return d->m_generator ? d->m_generator->print( printer ) : false;
Index: core/fileprinter.h
===================================================================
--- core/fileprinter.h	(revision 0)
+++ core/fileprinter.h	(revision 0)
@@ -0,0 +1,161 @@
+/***************************************************************************
+ *   Copyright (C) 2007 by John Layt <john@layt.net>                       *
+ *                                                                         *
+ *   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.                                   *
+ ***************************************************************************/
+
+#ifndef FILEPRINTER_H
+#define FILEPRINTER_H
+
+#include <QList>
+#include <QString>
+
+#include <okular/core/okular_export.h>
+
+class QPrinter;
+class QString;
+class QSize;
+
+class OKULAR_EXPORT FilePrinter
+{
+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 };
+
+    /** 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.
+     *
+     * @param printer the print settings to use
+     * @param file the file to print
+     * @param fileDeletePolicy if the application or system deletes the file
+     * @param pageSelectPolicy if the application or system selects the pages to \
print +     * @param pageRange page range to print if SystemSlectsPages and user \
chooses Selection in Print Dialog +     *
+     * @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
+     *          -2 if the KProcess could not be started
+     *          -1 if the KProcess crashed
+     *          otherwise the KProcess exit code
+     */
+
+    static int printFile( QPrinter &printer, const QString file,
+                          FileDeletePolicy fileDeletePolicy = \
FilePrinter::ApplicationDeletesFiles, +                          PageSelectPolicy \
pageSelectPolicy = FilePrinter::ApplicationSelectsPages, +                          \
const QString &pageRange = QString() ); +
+    /** Print a list of files using the settings in QPrinter
+     *
+     *  Only supports CUPS and LPR on *NIX.
+     *  Most settings unsupported by LPR, some settings unsupported by CUPS.
+     *
+     * @param printer the print settings to use
+     * @param fileList the files to print
+     * @param fileDeletePolicy if the application or system deletes the file
+     *
+     * @returns Returns exit code:
+     *          -9 if lpr not found
+     *          -8 if empty file list
+     *          -7 if unable to find a file
+     *          -6 if invalid printer state
+     *          -2 if the KProcess could not be started
+     *          -1 if the KProcess crashed
+     *          otherwise the KProcess exit code
+     */
+
+    static int printFiles( QPrinter &printer, const QStringList &fileList,
+                           FileDeletePolicy fileDeletePolicy = \
FilePrinter::ApplicationDeletesFiles ); +
+    /** 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, QList<int> \
selectedPageList ); +
+    /** 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, 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( QList<int> pageList );
+
+    /** 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 );
+
+protected:
+
+    static bool detectCupsService();
+    static bool detectCupsConfig();
+
+    static int doPrintFiles( QPrinter &printer, const QStringList fileList,
+                             FileDeletePolicy fileDeletePolicy, PageSelectPolicy \
pageSelectPolicy, +                             const QString &pageRange );
+
+    static QStringList printArguments( QPrinter &printer,
+                                       FileDeletePolicy fileDeletePolicy, \
PageSelectPolicy pageSelectPolicy, +                                       bool \
useCupsOptions, const QString &pageRange, const QString &version ); +
+    static QStringList destination( QPrinter &printer, const QString &version );
+    static QStringList copies( QPrinter &printer, const QString &version );
+    static QStringList jobname( QPrinter &printer, const QString &version );
+    static QStringList deleteFile( QPrinter &printer, FileDeletePolicy \
fileDeletePolicy, +                                   const QString &version );
+    static QStringList pages( QPrinter &printer, PageSelectPolicy pageSelectPolicy,
+                              const QString &pageRange, bool useCupsOptions, const \
QString &version ); +
+    static QStringList cupsOptions( QPrinter &printer );
+    static QStringList optionMedia( QPrinter &printer );
+    static QString mediaPageSize( QPrinter &printer );
+    static QString mediaPaperSource( QPrinter &printer );
+    static QStringList optionOrientation( QPrinter &printer );
+    static QStringList optionDoubleSidedPrinting( QPrinter &printer );
+    static QStringList optionPageOrder( QPrinter &printer );
+    static QStringList optionCollateCopies( QPrinter &printer );
+};
+
+#endif // FILEPRINTER_H
Index: core/generator.h
===================================================================
--- core/generator.h	(revision 737924)
+++ core/generator.h	(working copy)
@@ -33,6 +33,7 @@
 
 class QMutex;
 class QPrinter;
+class QPrintDialog;
 class KAboutData;
 class KComponentData;
 class KIcon;
@@ -196,7 +197,9 @@
             TextExtraction,    ///< Whether the Generator can extract text from the \
                document in the form of TextPage's
             ReadRawData,       ///< Whether the Generator can read a document \
                directly from its raw data.
             FontInfo,          ///< Whether the Generator can provide information \
                about the fonts used in the document
-            PageSizes          ///< Whether the Generator can change the size of the \
document pages. +            PageSizes,         ///< Whether the Generator can change \
the size of the document pages. +            PrintNative,       ///< Whether the \
Generator supports native cross-platform printing (QPainter-based). +            \
PrintToFile,       ///< Whether the Generator supports export to PDF & PS through the \
Print Dialog  };
 
         /**
Index: core/document.h
===================================================================
--- core/document.h	(revision 737924)
+++ core/document.h	(working copy)
@@ -24,6 +24,7 @@
 #include <kmimetype.h>
 
 class QPrinter;
+class QPrintDialog;
 class KComponentData;
 class KBookmark;
 class KConfigDialog;
@@ -416,6 +417,16 @@
         void processAction( const Action *action );
 
         /**
+         * Returns a list of the bookmarked.pages
+         */
+        QList<int> bookmarkedPageList() const;
+
+        /**
+         * Returns the range of the bookmarked.pages
+         */
+        QString bookmarkedPageRange() const;
+
+        /**
          * Processes/Executes the given source @p reference.
          */
         void processSourceReference( const SourceReference *reference );
@@ -426,6 +437,16 @@
         bool canConfigurePrinter() const;
 
         /**
+         * Returns whether the document supports native cross-platform printing.
+         */
+        bool supportsPrintNative() const;
+
+        /**
+         * Returns whether the document supports printing to both PDF and PS files.
+         */
+        bool supportsPrintToFile() const;
+
+        /**
          * Prints the document to the given @p printer.
          */
         bool print( QPrinter &printer );
Index: core/fileprinter.cpp
===================================================================
--- core/fileprinter.cpp	(revision 0)
+++ core/fileprinter.cpp	(revision 0)
@@ -0,0 +1,504 @@
+/***************************************************************************
+ *   Copyright (C) 2007 by John Layt <john@layt.net>                       *
+ *                                                                         *
+ *   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.                                   *
+ ***************************************************************************/
+
+#include "fileprinter.h"
+
+#include <QtGui/QPrinter>
+#include <QPrintEngine>
+#include <QStringList>
+#include <QFile>
+#include <QSize>
+
+#include <KProcess>
+#include <KShell>
+#include <klocalsocket.h>
+#include <kstandarddirs.h>
+#include <kdebug.h>
+
+int FilePrinter::printFile( QPrinter &printer, QString file, FileDeletePolicy \
fileDeletePolicy, +                            PageSelectPolicy pageSelectPolicy, \
const QString &pageRange ) +{
+    return doPrintFiles( printer, QStringList( file ), fileDeletePolicy, \
pageSelectPolicy, pageRange ); +}
+
+int FilePrinter::printFiles( QPrinter &printer, const QStringList &fileList, \
FileDeletePolicy fileDeletePolicy ) +{
+    return doPrintFiles( printer, fileList, fileDeletePolicy, \
FilePrinter::ApplicationSelectsPages, QString() ); +}
+
+int FilePrinter::doPrintFiles( QPrinter &printer, QStringList fileList, \
FileDeletePolicy fileDeletePolicy, +                               PageSelectPolicy \
pageSelectPolicy, const QString &pageRange ) +{
+    QString exe("lpr");
+
+    if ( KStandardDirs::findExe(exe).isEmpty() ) {
+        exe = "lp";
+    }
+
+    if ( KStandardDirs::findExe(exe).isEmpty() ) {
+        return -9;
+    }
+
+    if ( fileList.size() < 1 ) {
+        return -8;
+    }
+
+    for (QStringList::ConstIterator it = fileList.begin(); it != fileList.end(); \
++it) { +        if (!QFile::exists(*it)) {
+            return -7;
+        }
+    }
+
+    if ( printer.printerState() == QPrinter::Aborted || printer.printerState() == \
QPrinter::Error ) { +        return -6;
+    }
+
+    bool useCupsOptions = cupsAvailable();
+    QStringList argList = printArguments( printer, fileDeletePolicy, \
pageSelectPolicy, useCupsOptions, pageRange, exe ) +                          << \
fileList; +    kDebug() << "Executing " << exe << " with arguments" << argList;
+
+    int ret = KProcess::execute( exe, argList );
+
+    // If we used the Cups options and the command failed, try again without them in \
case Cups lpr/lp not installed. +    // I'm not convinced this will work, I don't \
think KProcess returns the result of the command, but rather +    // that it was able \
to be executed? +    if ( useCupsOptions && ret < 0 ) {
+
+        argList = printArguments( printer, fileDeletePolicy, pageSelectPolicy, \
useCupsOptions, pageRange, exe ) +                  << fileList;
+        kDebug() << "Retrying " << exe << " without cups arguments" << argList;
+
+        ret = KProcess::execute( exe, argList );
+    }
+
+    return ret;
+}
+
+QList<int> FilePrinter::pageList( QPrinter &printer, int lastPage, QList<int> \
selectedPageList ) +{
+    if ( printer.printRange() == QPrinter::Selection) {
+        return selectedPageList;
+    }
+
+    int startPage, endPage;
+    QList<int> list;
+
+    if ( printer.printRange() == QPrinter::PageRange ) {
+        startPage = printer.fromPage();
+        endPage = printer.toPage();
+    } else { //AllPages
+        startPage = 1;
+        endPage = lastPage;
+    }
+
+    for (int i = startPage; i <= endPage; i++ ) {
+        list << i;
+    }
+    return list;
+}
+
+QString FilePrinter::pageRange( QPrinter &printer, int lastPage, QList<int> \
selectedPageList ) +{
+    if ( printer.printRange() == QPrinter::Selection) {
+        return pageListToPageRange( selectedPageList );
+    }
+
+    if ( printer.printRange() == QPrinter::PageRange ) {
+        return QString("%1-%2").arg(printer.fromPage()).arg(printer.toPage());
+    }
+
+    return QString("1-%2").arg( lastPage );
+}
+
+QString FilePrinter::pageListToPageRange( QList<int> pageList )
+{
+    QString pageRange;
+    int count = pageList.count();
+    int i = 0;
+    int seqStart = i;
+    int seqEnd;
+
+    while ( i != count ) {
+
+        if ( i + 1 == count || pageList[i] + 1 != pageList[i+1] ) {
+
+            seqEnd = i;
+
+            if ( !pageRange.isEmpty() ) {
+                pageRange.append(",");
+            }
+
+            if ( seqStart == seqEnd ) {
+                pageRange.append(pageList[i]);
+            } else {
+                pageRange.append("%1-%2").arg(seqStart).arg(seqEnd);
+            }
+
+            seqStart = i + 1;
+        }
+
+        i++;
+    }
+
+    return pageRange;
+}
+
+bool FilePrinter::cupsAvailable()
+{
+    return ( detectCupsConfig() /*&& detectCupsService()*/ );
+}
+
+bool FilePrinter::detectCupsService()
+{
+    // copied from KdeprintChecker::checkService()
+    // Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+    // original license LGPL
+    KLocalSocket sock;
+    sock.connectToPath("/ipp");
+    kDebug() << "socket wait = " << sock.waitForConnected();
+    kDebug() << "socket error = " << sock.error();
+    kDebug() << "socket isOpen() = " << sock.isOpen();
+    return sock.isOpen();
+}
+
+bool FilePrinter::detectCupsConfig()
+{
+    if ( QFile::exists("/etc/cups/cupsd.conf") ) return true;
+    if ( QFile::exists("/usr/etc/cups/cupsd.conf") ) return true;
+    if ( QFile::exists("/usr/local/etc/cups/cupsd.conf") ) return true;
+    if ( QFile::exists("/opt/etc/cups/cupsd.conf") ) return true;
+    if ( QFile::exists("/opt/local/etc/cups/cupsd.conf") ) return true;
+    return false;
+}
+
+QSize FilePrinter::psPaperSize( QPrinter &printer )
+{
+    QSize size;
+
+    switch ( printer.pageSize() ) {
+    case QPrinter::A0:        size = QSize( 2384, 3370 ); break;
+    case QPrinter::A1:        size = QSize( 1684, 2384 ); break;
+    case QPrinter::A2:        size = QSize( 1191, 1684 ); break;
+    case QPrinter::A3:        size = QSize(  842, 1191 ); break;
+    case QPrinter::A4:        size = QSize(  595,  842 ); break;
+    case QPrinter::A5:        size = QSize(  420,  595 ); break;
+    case QPrinter::A6:        size = QSize(  298,  420 ); break;
+    case QPrinter::A7:        size = QSize(  210,  298 ); break;
+    case QPrinter::A8:        size = QSize(  147,  210 ); break;
+    case QPrinter::A9:        size = QSize(  105,  147 ); break;
+    case QPrinter::B0:        size = QSize( 2835, 4008 ); break;
+    case QPrinter::B1:        size = QSize( 2004, 2835 ); break;
+    case QPrinter::B2:        size = QSize( 1417, 2004 ); break;
+    case QPrinter::B3:        size = QSize( 1001, 1417 ); break;
+    case QPrinter::B4:        size = QSize(  709, 1001 ); break;
+    case QPrinter::B5:        size = QSize(  499,  709 ); break;
+    case QPrinter::B6:        size = QSize(  354,  499 ); break;
+    case QPrinter::B7:        size = QSize(  249,  354 ); break;
+    case QPrinter::B8:        size = QSize(  176,  249 ); break;
+    case QPrinter::B9:        size = QSize(  125,  176 ); break;
+    case QPrinter::B10:       size = QSize(   88,  125 ); break;
+    case QPrinter::C5E:       size = QSize(  459,  649 ); break;
+    case QPrinter::Comm10E:   size = QSize(  297,  684 ); break;
+    case QPrinter::DLE:       size = QSize(  312,  624 ); break;
+    case QPrinter::Executive: size = QSize(  522,  756 ); break;
+    case QPrinter::Folio:     size = QSize(  595,  935 ); break;
+    case QPrinter::Ledger:    size = QSize( 1224,  792 ); break;
+    case QPrinter::Legal:     size = QSize(  612, 1008 ); break;
+    case QPrinter::Letter:    size = QSize(  612,  792 ); break;
+    case QPrinter::Tabloid:   size = QSize(  792, 1224 ); break;
+    case QPrinter::Custom:    return QSize( (int) printer.widthMM() * ( 25.4 / 72 ),
+                                            (int) printer.heightMM() * ( 25.4 / 72 ) \
); +    default:                  return QSize();
+    }
+
+    if ( printer.orientation() == QPrinter::Landscape ) {
+        size.transpose();
+    }
+
+    return size;
+}
+
+
+
+
+QStringList FilePrinter::printArguments( QPrinter &printer, FileDeletePolicy \
fileDeletePolicy, +                                         PageSelectPolicy \
pageSelectPolicy, bool useCupsOptions, +                                         \
const QString &pageRange, const QString &version ) +{
+    QStringList argList;
+
+    if ( ! destination( printer, version ).isEmpty() ) {
+        argList << destination( printer, version );
+    }
+
+    if ( ! copies( printer, version ).isEmpty() ) {
+        argList << copies( printer, version );
+    }
+
+    if ( ! jobname( printer, version ).isEmpty() ) {
+        argList << jobname( printer, version );
+    }
+
+    if ( ! pages( printer, pageSelectPolicy, pageRange, useCupsOptions, version \
).isEmpty() ) { +        argList << pages( printer, pageSelectPolicy, pageRange, \
useCupsOptions, version ); +    }
+
+    if ( useCupsOptions && ! cupsOptions( printer ).isEmpty() ) {
+        argList << cupsOptions( printer );
+    }
+
+    if ( ! deleteFile( printer, fileDeletePolicy, version ).isEmpty() ) {
+        argList << deleteFile( printer, fileDeletePolicy, version );
+    }
+
+    if ( version == "lp" ) {
+        argList << "--";
+    }
+
+    return argList;
+}
+
+QStringList FilePrinter::destination( QPrinter &printer, const QString &version )
+{
+    if ( version == "lp" ) {
+        return QStringList("-d") << printer.printerName();
+    }
+
+    if ( version == "lpr" ) {
+        return QStringList("-P") << printer.printerName();
+    }
+
+    return QStringList();
+}
+
+QStringList FilePrinter::copies( QPrinter &printer, const QString &version )
+{
+    // Can't use QPrinter::numCopies(), as if CUPS will always return 1, not sure if \
this behaves same way as well? +    int cp = printer.printEngine()->property( \
QPrintEngine::PPK_NumberOfCopies ).toInt(); +
+    if ( version == "lp" ) {
+        return QStringList("-n") << QString("%1").arg( cp );
+    }
+
+    if ( version == "lpr" ) {
+        return QStringList() << QString("-#%1").arg( cp );
+    }
+
+    return QStringList();
+}
+
+QStringList FilePrinter::jobname( QPrinter &printer, const QString &version )
+{
+    if ( ! printer.docName().isEmpty() ) {
+
+        if ( version == "lp" ) {
+            return QStringList("-t") << printer.docName();
+        }
+
+        if ( version == "lpr" ) {
+            return QStringList("-J") << printer.docName();
+        }
+    }
+
+    return QStringList();
+}
+
+QStringList FilePrinter::deleteFile( QPrinter &printer, FileDeletePolicy \
fileDeletePolicy, const QString &version ) +{
+    if ( fileDeletePolicy == FilePrinter::SystemDeletesFiles && version == "lpr" ) {
+        return QStringList("-r");
+    }
+
+    return QStringList();
+}
+
+QStringList FilePrinter::pages( QPrinter &printer, PageSelectPolicy \
pageSelectPolicy, const QString &pageRange, +                                    bool \
useCupsOptions, const QString &version ) +{
+    if ( pageSelectPolicy == FilePrinter::SystemSelectsPages ) {
+
+        if ( printer.printRange() == QPrinter::Selection && ! pageRange.isEmpty() ) \
{ +
+            if ( version == "lp" ) {
+                return QStringList("-P") << pageRange ;
+            }
+
+            if ( version == "lpr" && useCupsOptions ) {
+                return QStringList("-o") << QString("page-ranges=%1").arg( pageRange \
); +            }
+
+        }
+
+        if ( printer.printRange() == QPrinter::PageRange ) {
+
+            if ( version == "lp" ) {
+                return QStringList("-P") << QString("%1-%2").arg( printer.fromPage() \
) +                                                            .arg( printer.toPage() \
); +            }
+
+            if ( version == "lpr" && useCupsOptions ) {
+                return QStringList("-o") << QString("page-ranges=%1-%2").arg( \
printer.fromPage() ) +                                                                \
.arg( printer.toPage() ); +            }
+
+        }
+
+    }
+
+    return QStringList(); // AllPages
+}
+
+QStringList FilePrinter::cupsOptions( QPrinter &printer )
+{
+    QStringList optionList;
+
+    if ( ! optionMedia( printer ).isEmpty() ) {
+        optionList << optionMedia( printer );
+    }
+
+    if ( ! optionOrientation( printer ).isEmpty() ) {
+        optionList << optionOrientation( printer );
+    }
+
+    if ( ! optionDoubleSidedPrinting( printer ).isEmpty() ) {
+        optionList << optionDoubleSidedPrinting( printer );
+    }
+
+    if ( ! optionPageOrder( printer ).isEmpty() ) {
+        optionList << optionPageOrder( printer );
+    }
+
+    if ( ! optionCollateCopies( printer ).isEmpty() ) {
+        optionList << optionCollateCopies( printer );
+    }
+
+    return optionList;
+}
+
+QStringList FilePrinter::optionMedia( QPrinter &printer )
+{
+    if ( ! mediaPageSize( printer ).isEmpty() && 
+         ! mediaPaperSource( printer ).isEmpty() ) {
+        return QStringList("-o") <<
+                QString("media=%1,%2").arg( mediaPageSize( printer ) )
+                                      .arg( mediaPaperSource( printer ) );
+    }
+
+    if ( ! mediaPageSize( printer ).isEmpty() ) {
+        return QStringList("-o") <<
+                QString("media=%1").arg( mediaPageSize( printer ) );
+    }
+
+    if ( ! mediaPaperSource( printer ).isEmpty() ) {
+        return QStringList("-o") <<
+                QString("media=%1").arg( mediaPaperSource( printer ) );
+    }
+
+    return QStringList();
+}
+
+QString FilePrinter::mediaPageSize( QPrinter &printer )
+{
+    switch ( printer.pageSize() ) {
+    case QPrinter::A0:         return "A0";
+    case QPrinter::A1:         return "A1";
+    case QPrinter::A2:         return "A2";
+    case QPrinter::A3:         return "A3";
+    case QPrinter::A4:         return "A4";
+    case QPrinter::A5:         return "A5";
+    case QPrinter::A6:         return "A6";
+    case QPrinter::A7:         return "A7";
+    case QPrinter::A8:         return "A8";
+    case QPrinter::A9:         return "A9";
+    case QPrinter::B0:         return "B0";
+    case QPrinter::B1:         return "B1";
+    case QPrinter::B10:        return "B10";
+    case QPrinter::B2:         return "B2";
+    case QPrinter::B3:         return "B3";
+    case QPrinter::B4:         return "B4";
+    case QPrinter::B5:         return "B5";
+    case QPrinter::B6:         return "B6";
+    case QPrinter::B7:         return "B7";
+    case QPrinter::B8:         return "B8";
+    case QPrinter::B9:         return "B9";
+    case QPrinter::C5E:        return "C5";     //Correct Translation?
+    case QPrinter::Comm10E:    return "Comm10"; //Correct Translation?
+    case QPrinter::DLE:        return "DL";     //Correct Translation?
+    case QPrinter::Executive:  return "Executive";
+    case QPrinter::Folio:      return "Folio";
+    case QPrinter::Ledger:     return "Ledger";
+    case QPrinter::Legal:      return "Legal";
+    case QPrinter::Letter:     return "Letter";
+    case QPrinter::Tabloid:    return "Tabloid";
+    case QPrinter::Custom:     return QString("Custom.%1x%2mm")
+                                            .arg( printer.heightMM() )
+                                            .arg( printer.widthMM() );
+    default:                   return QString();
+    }
+}
+
+// What about Upper and MultiPurpose?  And others in PPD???
+QString FilePrinter::mediaPaperSource( QPrinter &printer )
+{
+    switch ( printer.paperSource() ) {
+    case QPrinter::Auto:            return QString();
+    case QPrinter::Cassette:        return "Cassette";
+    case QPrinter::Envelope:        return "Envelope";
+    case QPrinter::EnvelopeManual:  return "EnvelopeManual";
+    case QPrinter::FormSource:      return "FormSource";
+    case QPrinter::LargeCapacity:   return "LargeCapacity";
+    case QPrinter::LargeFormat:     return "LargeFormat";
+    case QPrinter::Lower:           return "Lower";
+    case QPrinter::MaxPageSource:   return "MaxPageSource";
+    case QPrinter::Middle:          return "Middle";
+    case QPrinter::Manual:          return "Manual";
+    case QPrinter::OnlyOne:         return "OnlyOne";
+    case QPrinter::Tractor:         return "Tractor";
+    case QPrinter::SmallFormat:     return "SmallFormat";
+    default:                        return QString();
+    }
+}
+
+QStringList FilePrinter::optionOrientation( QPrinter &printer )
+{
+    switch ( printer.orientation() ) {
+    case QPrinter::Portrait:   return QStringList("-o") << "portrait";
+    case QPrinter::Landscape:  return QStringList("-o") << "landscape";
+    default:                   return QStringList();
+    }
+}
+
+QStringList FilePrinter::optionDoubleSidedPrinting( QPrinter &printer )
+{
+    if ( printer.doubleSidedPrinting() ) {
+        if ( printer.orientation() == QPrinter::Landscape ) {
+            return QStringList("-o") << "sides=two-sided-short-edge";
+        } else {
+            return QStringList("-o") << "sides=two-sided-long-edge";
+        }
+    }
+    return QStringList("-o") << "sides=one-sided";
+}
+
+QStringList FilePrinter::optionPageOrder( QPrinter &printer )
+{
+    if ( printer.pageOrder() == QPrinter::LastPageFirst ) {
+        return QStringList("-o") << "outputorder=reverse";
+    }
+    return QStringList("-o") << "outputorder=normal";
+}
+
+QStringList FilePrinter::optionCollateCopies( QPrinter &printer )
+{
+    if ( printer.collateCopies() ) {
+        return QStringList("-o") << "Collate=True";
+    }
+    return QStringList("-o") << "Collate=False";
+}
Index: core/generator.cpp
===================================================================
--- core/generator.cpp	(revision 737924)
+++ core/generator.cpp	(working copy)
@@ -12,6 +12,8 @@
 
 #include <qeventloop.h>
 #include <QtGui/QPrinter>
+#include <QtGui/QPrintDialog>
+#include <QFlags>
 
 #include <kaboutdata.h>
 #include <kcomponentdata.h>
Index: part.h
===================================================================
--- part.h	(revision 737924)
+++ part.h	(working copy)
@@ -164,7 +164,8 @@
         void psTransformEnded(int, QProcess::ExitStatus);
 
     private:
-        void doPrint( QPrinter& printer );
+        void setupPrint( QPrinter &printer );
+        void doPrint( QPrinter &printer );
         bool handleCompressed( QString &destpath, const QString &path, const QString \
&compressedMimetype );  void rebuildBookmarkMenu( bool unplugActions = true );
         void updateAboutBackendAction();
Index: generators/kimgio/generator_kimgio.cpp
===================================================================
--- generators/kimgio/generator_kimgio.cpp	(revision 737924)
+++ generators/kimgio/generator_kimgio.cpp	(working copy)
@@ -122,18 +122,12 @@
 {
     QPainter p( &printer );
 
-    uint left, top, right, bottom;
-    left = printer.paperRect().left() - printer.pageRect().left();
-    top = printer.paperRect().top() - printer.pageRect().top();
-    right = printer.paperRect().right() - printer.pageRect().right();
-    bottom = printer.paperRect().bottom() - printer.pageRect().bottom();
+    QImage image( m_img );
 
-    int pageWidth = printer.width() - right;
-    int pageHeight = printer.height() - bottom;
+    if ( ( image.width() > printer.width() ) || ( image.height() > printer.height() \
) )  
-    QImage image( m_img );
-    if ( (image.width() > pageWidth) || (image.height() > pageHeight) )
-        image = image.scaled( pageWidth, pageHeight, Qt::KeepAspectRatio, \
Qt::SmoothTransformation ); +        image = image.scaled( printer.width(), \
printer.height(), +                              Qt::KeepAspectRatio, \
Qt::SmoothTransformation );  
     p.drawImage( 0, 0, image );
 
Index: generators/poppler/generator_pdf.cpp
===================================================================
--- generators/poppler/generator_pdf.cpp	(revision 737924)
+++ generators/poppler/generator_pdf.cpp	(working copy)
@@ -36,6 +36,7 @@
 #include <okular/core/sound.h>
 #include <okular/core/sourcereference.h>
 #include <okular/core/textpage.h>
+#include <okular/core/fileprinter.h>
 
 #include <config-okular-poppler.h>
 
@@ -105,15 +106,14 @@
            layout->addStretch(1);
        }
 
-       void getOptions( QMap<QString,QString>& opts, bool incldef = false )
+       bool printForceRaster()
        {
-           Q_UNUSED(incldef);
-           opts[ "kde-okular-poppler-forceRaster" ] = QString::number( \
m_forceRaster->isChecked() ); +           return m_forceRaster->isChecked();
        }
 
-       void setOptions( const QMap<QString,QString>& opts )
+       void setPrintForceRaster( bool forceRaster )
        {
-           m_forceRaster->setChecked( opts[ "kde-okular-poppler-forceRaster" \
].toInt() ); +           m_forceRaster->setChecked( forceRaster );
        }
 
     private:
@@ -291,12 +291,13 @@
 PDFGenerator::PDFGenerator()
     : Generator(), pdfdoc( 0 ), ready( true ),
     pixmapRequest( 0 ), docInfoDirty( true ), docSynopsisDirty( true ),
-    docEmbeddedFilesDirty( true )
+    docEmbeddedFilesDirty( true ), pdfOptionsPage( 0 )
 {
     setFeature( TextExtraction );
     setFeature( FontInfo );
 #ifdef HAVE_POPPLER_0_6
     setFeature( ReadRawData );
+    pdfOptionsPage = new PDFOptionsPage();
 #endif
     // update the configuration
     reparseConfig();
@@ -313,6 +314,8 @@
         generatorThread->wait();
         delete generatorThread;
     }
+
+    delete pdfOptionsPage;
 }
 
 //BEGIN Generator inherited functions
@@ -830,119 +833,133 @@
 
 bool PDFGenerator::print( QPrinter& printer )
 {
-/*  This printing method unsupported in QPrinter, looking for alternative.
-    int width, height;
-    // PageSize is a CUPS artificially created setting 
-    QString ps = printer.option( "PageSize" );
-    QRegExp sizere( "w(\\d+)h(\\d+)" );
-    int marginTop, marginLeft, marginRight, marginBottom;
-    marginTop = (int)printer.option("kde-margin-top").toDouble();
-    marginLeft = (int)printer.option("kde-margin-left").toDouble();
-    marginRight = (int)printer.option("kde-margin-right").toDouble();
-    marginBottom = (int)printer.option("kde-margin-bottom").toDouble();
-    if ( sizere.exactMatch( ps ) )
-    {
-        // size not supported by Qt, CUPS gives us the size as wWIDTHhHEIGHT, at \
                least on the printers i tested
-        width = sizere.cap( 1 ).toInt();
-        height = sizere.cap( 2 ).toInt();
-    }
-    else
-    {
-        // size is supported by Qt, we get either the pageSize name or nothing \
                because the CUPS driver
-        // does not do any translation, then use KPrinter::pageSize to get the page \
                size
-        KPrinter::PageSize qtPageSize; 
-        if (!ps.isEmpty())
-        {
-            bool ok;
-            qtPageSize = pageNameToPageSize(ps, &ok);
-            // If we could not decode page size from the cups text try \
                KPrinter::pageSize as last resort :-D
-            if (!ok) qtPageSize = printer.pageSize();
-        }
-        else qtPageSize = printer.pageSize();
+    // Get the real page size to pass to the ps generator
+    QPrinter dummy( QPrinter::PrinterResolution );
+    dummy.setFullPage( true );
+    dummy.setOrientation( printer.orientation() );
+    int width = dummy.width();
+    int height = dummy.height();
 
-        QPrinter dummy(QPrinter::PrinterResolution);
-        dummy.setOrientation((QPrinter::Orientation)printer.orientation());
-        dummy.setFullPage(true);
-        dummy.setPageSize((QPrinter::PageSize)qtPageSize);
-
-        width = dummy.width();
-        height = dummy.height();
-    }
-
+    // Create the tempfile to send to FilePrinter, which will manage the deletion
     KTemporaryFile tf;
     tf.setSuffix( ".ps" );
     if ( !tf.open() )
         return false;
     QString tempfilename = tf.fileName();
-#if !POPPLER_HAVE_PSCONVERTER_SETOUTPUTDEVICE
+#if POPPLER_HAVE_PSCONVERTER_SETOUTPUTDEVICE
+    tf.setAutoRemove(false);
+#else
     tf.close();
 #endif
 
+    // Generate the list of pages to be printed as selected in the print dialog
     QList<int> pageList;
-    if (!printer.previewOnly()) pageList = printer.pageList();
-    else for(int i = 1; i <= pdfdoc->numPages(); i++) pageList.push_back(i);
-    
+    pageList = FilePrinter::pageList( printer, pdfdoc->numPages(), \
document()->bookmarkedPageList() ); +
     // TODO rotation
+
 #ifdef HAVE_POPPLER_0_6
-    double xScale = ((double)width - (double)marginLeft - (double)marginRight) / \
                (double)width;
-    double yScale = ((double)height - (double)marginBottom - (double)marginTop) / \
                (double)height;
-    bool strictMargins = false;
-    if ( abs((int)(xScale * 100) - (int)(yScale * 100)) > 5 ) {
-        int result = KMessageBox::questionYesNo(document()->widget(),
-                                               i18n("The margins you specified are \
changing the page aspect ratio. Do you want to print with the aspect ratio changed or \
                do you want the margins to be adapted so that aspect ratio is \
                preserved?"),
-                                               i18n("Aspect ratio change"),
-                                               KGuiItem( i18n("Print with specified \
                margins") ),
-                                               KGuiItem( i18n("Print adapting \
                margins to keep aspect ratio") ),
-                                               "kpdfStrictlyObeyMargins");
-        if (result == KMessageBox::Yes) strictMargins = true;
-    }
+
     QString pstitle = metaData(QLatin1String("Title"), QVariant()).toString();
     if ( pstitle.trimmed().isEmpty() )
     {
         pstitle = document()->currentDocument().fileName();
     }
-    bool forceRasterize = printer.option("kde-okular-poppler-forceRaster").toInt();
+
+    bool forceRasterize = pdfOptionsPage->printForceRaster();
+
     Poppler::PSConverter *psConverter = pdfdoc->psConverter();
+
 #if POPPLER_HAVE_PSCONVERTER_SETOUTPUTDEVICE
     psConverter->setOutputDevice(&tf);
 #else
     psConverter->setOutputFileName(tempfilename);
 #endif
+
     psConverter->setPageList(pageList);
     psConverter->setPaperWidth(width);
     psConverter->setPaperHeight(height);
-    psConverter->setRightMargin(marginRight);
-    psConverter->setBottomMargin(marginBottom);
-    psConverter->setLeftMargin(marginLeft);
-    psConverter->setTopMargin(marginTop);
-    psConverter->setStrictMargins(strictMargins);
+    psConverter->setRightMargin(0);
+    psConverter->setBottomMargin(0);
+    psConverter->setLeftMargin(0);
+    psConverter->setTopMargin(0);
+    psConverter->setStrictMargins(false);
     psConverter->setForceRasterize(forceRasterize);
     psConverter->setTitle(pstitle);
+
     userMutex()->lock();
     if (psConverter->convert())
     {
         userMutex()->unlock();
         delete psConverter;
-        return printer.printFiles(QStringList(tempfilename), true);
+        int ret = FilePrinter::printFile( printer, tempfilename,
+                                          FilePrinter::SystemDeletesFiles,
+                                          FilePrinter::ApplicationSelectsPages,
+                                          document()->bookmarkedPageRange() );
+        if ( ret >= 0 ) return true;
     }
     else
     {
         delete psConverter;
-#else
+        userMutex()->unlock();
+        return false;
+    }
+
+#else // Not HAVE_POPPLER_0_6
+
     userMutex()->lock();
-    if (pdfdoc->print(tempfilename, pageList, 72, 72, 0, width, height))
+
+    int rotate = 0;
+
+    /* This works around the weird situation with Landscape documents printing wrong
+       which I think is a Qt bug, so I don't really want to use this.
+    QPrinter::Orientation documentOrientation = QPrinter::Portrait;
+    double w, h;
+    int landscape, portrait;
+    const Okular::Page *page;
+    landscape = 0;
+    portrait = 0;
+    for (uint i = 0; i < document()->pages(); i++)
     {
+        page = document()->page(i);
+        w = page->width();
+        h = page->height();
+        if (page->orientation() == 90 || page->orientation() == 270) qSwap(w, h);
+        if (w > h) landscape++;
+        else portrait++;
+    }
+    if (landscape > portrait) documentOrientation = QPrinter::Landscape;
+
+    if ( documentOrientation == QPrinter::Landscape ) {
+        qSwap(width, height);
+        if ( printer.orientation() == QPrinter::Landscape ) {
+            printer.setOrientation( QPrinter::Portrait );
+        }
+        else
+        {
+            rotate = 90;
+            printer.setOrientation( QPrinter::Landscape );
+        }
+    }*/
+
+    if ( pdfdoc->print( tempfilename, pageList, 72, 72, rotate, width, height ) )
+    {
         userMutex()->unlock();
-        return printer.printFiles(QStringList(tempfilename), true);
+        int ret = FilePrinter::printFile( printer, tempfilename,
+                                          FilePrinter::SystemDeletesFiles,
+                                          FilePrinter::ApplicationSelectsPages,
+                                          document()->bookmarkedPageRange() );
+        if ( ret >= 0 ) return true;
     }
     else
     {
-#endif
         userMutex()->unlock();
         return false;
     }
-*/
-	return false;
+
+#endif // HAVE_POPPLER_0_6
+
+    return false;
 }
 
 QVariant PDFGenerator::metaData( const QString & key, const QVariant & option ) \
const @@ -1503,11 +1520,7 @@
 
 QWidget* PDFGenerator::printConfigurationWidget() const
 {
-#ifdef HAVE_POPPLER_0_6
-    return new PDFOptionsPage();
-#else
-    return 0;
-#endif
+    return pdfOptionsPage;
 }
 
 
Index: generators/poppler/generator_pdf.h
===================================================================
--- generators/poppler/generator_pdf.h	(revision 737924)
+++ generators/poppler/generator_pdf.h	(working copy)
@@ -26,6 +26,7 @@
 class ObjectRect;
 }
 
+class PDFOptionsPage;
 class PDFPixmapGeneratorThread;
 
 /**
@@ -131,6 +132,8 @@
         mutable QList<Okular::EmbeddedFile*> docEmbeddedFiles;
 
         QVector<bool> rectsGenerated;
+
+        PDFOptionsPage * pdfOptionsPage;
 };
 
 
Index: generators/dvi/dviexport.cpp
===================================================================
--- generators/dvi/dviexport.cpp	(revision 737924)
+++ generators/dvi/dviexport.cpp	(working copy)
@@ -478,9 +478,13 @@
 {
   if (printer_ && !output_name_.isEmpty()) {
     const QFileInfo output(output_name_);
-    if (output.exists() && output.isReadable())
-      //Unsupported in Qt
-      //printer_->printFiles(QStringList(output_name_), true);
+    if (output.exists() && output.isReadable()) {
+        // I'm not 100% sure on this, think we still need to select pages in export \
to ps above +        FilePrinter::printFile( printer_, output_name_,
+                                FilePrinter::ApplicationDeletesFiles,
+                                FilePrinter::ApplicationSelectsPages,
+                                QString() );
+    }
   }
 
 #ifndef DVIEXPORT_USE_QPROCESS
Index: generators/comicbook/generator_comicbook.cpp
===================================================================
--- generators/comicbook/generator_comicbook.cpp	(revision 737924)
+++ generators/comicbook/generator_comicbook.cpp	(working copy)
@@ -12,7 +12,9 @@
 #include <QtGui/QPainter>
 #include <QtGui/QPrinter>
 
+#include <okular/core/document.h>
 #include <okular/core/page.h>
+#include <okular/core/fileprinter.h>
 
 OKULAR_EXPORT_PLUGIN(ComicBookGenerator)
 
@@ -69,21 +71,18 @@
 bool ComicBookGenerator::print( QPrinter& printer )
 {
     QPainter p( &printer );
+    QList<int> pageList;
+    pageList = FilePrinter::pageList( printer, document()->pages(), \
document()->bookmarkedPageList() );  
-    for ( int i = 0; i < mDocument.pages(); ++i ) {
-        QImage image = mDocument.pageImage( i );
-        uint left, top, right, bottom;
-        left = printer.paperRect().left() - printer.pageRect().left();
-        top = printer.paperRect().top() - printer.pageRect().top();
-        right = printer.paperRect().right() - printer.pageRect().right();
-        bottom = printer.paperRect().bottom() - printer.pageRect().bottom();
+    for ( int i = 0; i < pageList.count(); ++i ) {
 
-        int pageWidth = printer.width() - right;
-        int pageHeight = printer.height() - bottom;
+        QImage image = mDocument.pageImage( pageList[i] - 1 );
 
-        if ( (image.width() > pageWidth) || (image.height() > pageHeight) )
-            image = image.scaled( pageWidth, pageHeight, Qt::IgnoreAspectRatio, \
Qt::SmoothTransformation ); +        if ( ( image.width() > printer.width() ) || ( \
image.height() > printer.height() ) )  
+            image = image.scaled( printer.width(), printer.height(),
+                                  Qt::KeepAspectRatio, Qt::SmoothTransformation );
+
         if ( i != 0 )
             printer.newPage();
 
Index: generators/spectre/generator_ghostview.cpp
===================================================================
--- generators/spectre/generator_ghostview.cpp	(revision 737924)
+++ generators/spectre/generator_ghostview.cpp	(working copy)
@@ -18,9 +18,11 @@
 #include <kconfigdialog.h>
 #include <kdebug.h>
 #include <kmimetype.h>
+#include <ktemporaryfile.h>
 
 #include <okular/core/document.h>
 #include <okular/core/page.h>
+#include <okular/core/fileprinter.h>
 
 #include "ui_gssettingswidget.h"
 #include "gssettings.h"
@@ -62,22 +64,35 @@
 
 bool GSGenerator::print( QPrinter& printer )
 {
-/*  This printing method unsupported in QPrinter, looking for alternative.
-
+    bool result = false;
     KTemporaryFile tf;
+    // printFiles will take care of deleting, otherwise the file disappears before \
able to print it??? +    // may not be needed, need to test with big document
+    tf.setAutoRemove(false);
     tf.setSuffix( ".ps" );
     if ( tf.open() )
     {
-        bool result = false;
-        if ( internalDoc->savePages( tf.fileName(), printer.pageList() ) )
+        QList<int> pageList = FilePrinter::pageList( printer,
+                                                     spectre_document_get_n_pages( \
m_internalDocument ), +                                                     \
document()->bookmarkedPageList() ); +
+        /*  Working under Ghostview, need Spectre equivalent of savePages()
+                spectre_exporter_new
+                spectre_exporter_begin
+                spectre_exporter_do_page
+                spectre_exporter_end
+                spectre_exporter_free
+        if ( internalDocument->savePages( tf.fileName(), pageList ) )
         {
-            result = printer.printFiles( QStringList( tf.fileName() ), true );
-        }
+            int ret = FilePrinter::printFile( printer, tf.fileName(),
+                                              FilePrinter::SystemDeletesFiles,
+                                              FilePrinter::ApplicationSelectsPages,
+                                              document()->bookmarkedPageRange() );
+            if ( ret >= 0 ) result = true;
+        }*/
         tf.close();
-        return result;
     }
-*/
-    return false; 
+    return result;
 }
 
 bool GSGenerator::loadDocument( const QString & fileName, QVector< Okular::Page * > \
                & pagesVector )
Index: generators/djvu/generator_djvu.cpp
===================================================================
--- generators/djvu/generator_djvu.cpp	(revision 737924)
+++ generators/djvu/generator_djvu.cpp	(working copy)
@@ -16,6 +16,7 @@
 #include <okular/core/page.h>
 #include <okular/core/textpage.h>
 #include <okular/core/utils.h>
+#include <okular/core/fileprinter.h>
 
 #include <qdom.h>
 #include <qmutex.h>
@@ -185,29 +186,26 @@
 
 bool DjVuGenerator::print( QPrinter& printer )
 {
-/*  This printing method unsupported in QPrinter, looking for alternative.
-
-    QList<int> pageList;
-    if ( !printer.previewOnly() )
-        pageList = printer.pageList();
-    else
-    {
-        int pages = m_djvu->pages().count();
-        for( int i = 1; i <= pages; ++i )
-            pageList.push_back(i);
-    }
-
     KTemporaryFile tf;
     tf.setSuffix( ".ps" );
     if ( !tf.open() )
         return false;
+    // printFiles will take care of deleting, otherwise the file disappears before \
able to print it??? +    // may not be needed, need to test with big document
+    tf.setAutoRemove(false);
 
     QMutexLocker locker( userMutex() );
+    QList<int> pageList = FilePrinter::pageList( printer, m_djvu->pages().count(),
+                                                 document()->bookmarkedPageList() );
     if ( m_djvu->exportAsPostScript( &tf, pageList ) )
     {
-        return printer.printFiles( QStringList( tf.fileName() ), false );
+        int ret = FilePrinter::printFile( printer, tf.fileName(),
+                                          FilePrinter::SystemDeletesFiles,
+                                          FilePrinter::ApplicationSelectsPages,
+                                          document()->bookmarkedPageRange() );
+        if ( ret >=0 ) return true;
     }
-*/
+
     return false;
 }
 
Index: generators/tiff/generator_tiff.cpp
===================================================================
--- generators/tiff/generator_tiff.cpp	(revision 737924)
+++ generators/tiff/generator_tiff.cpp	(working copy)
@@ -22,6 +22,7 @@
 
 #include <okular/core/document.h>
 #include <okular/core/page.h>
+#include <okular/core/fileprinter.h>
 
 #include <tiff.h>
 #include <tiffio.h>
@@ -219,10 +220,13 @@
     tdir_t dirs = TIFFNumberOfDirectories( d->tiff );
 
     QPainter p( &printer );
+    QList<int> pageList;
 
-    for ( tdir_t i = 0; i < dirs; ++i )
+    pageList = FilePrinter::pageList( printer, document()->pages(), \
document()->bookmarkedPageList() ); +
+    for ( tdir_t i = 0; i < pageList.count(); ++i )
     {
-        if ( !TIFFSetDirectory( d->tiff, i ) )
+        if ( !TIFFSetDirectory( d->tiff, pageList[i] - 1 ) )
             continue;
 
         if ( TIFFGetField( d->tiff, TIFFTAG_IMAGEWIDTH, &width ) != 1 ||
Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt	(revision 737924)
+++ CMakeLists.txt	(working copy)
@@ -43,6 +43,7 @@
    core/textdocumentgenerator.cpp
    core/textpage.cpp
    core/utils.cpp
+   core/fileprinter.cpp
 )
 
 install( FILES
@@ -64,6 +65,7 @@
            core/textdocumentgenerator.h
            core/textpage.h
            core/utils.h
+           core/fileprinter.h
          DESTINATION ${INCLUDE_INSTALL_DIR}/okular/core )
 
 install( FILES


Send instant messages to your online friends http://au.messenger.yahoo.com 

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic