QPrintDialog - Remove CUPS specific code

We no longer use QLibrary to load CUPS, so remove checks.  Switch from
using QCupsSupport and QPrinterInfo to QPlatformPrintDevice.  The
remaining use of QCupsSupport is only for utilities to set CUPS specific
options which don't need to link to CUPS directly, these will be
replaced later with generic cross-platform API.

Change-Id: I6e3d9e9a59633c33af0555eb28443a9fc192b27c
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
This commit is contained in:
John Layt 2014-01-29 15:46:01 +01:00 committed by The Qt Project
parent 9393f744d4
commit aa76fcc301

View File

@ -52,8 +52,11 @@
#include <QtWidgets/qfilesystemmodel.h> #include <QtWidgets/qfilesystemmodel.h>
#include <QtWidgets/qstyleditemdelegate.h> #include <QtWidgets/qstyleditemdelegate.h>
#include <QtPrintSupport/qprinter.h> #include <QtPrintSupport/qprinter.h>
#include <QtPrintSupport/qprinterinfo.h>
#include <private/qprintengine_pdf_p.h> #include <qpa/qplatformprintplugin.h>
#include <qpa/qplatformprintersupport.h>
#include <private/qprintdevice_p.h>
#include <QtWidgets/qdialogbuttonbox.h> #include <QtWidgets/qdialogbuttonbox.h>
@ -62,12 +65,9 @@
#include "ui_qprintsettingsoutput.h" #include "ui_qprintsettingsoutput.h"
#include "ui_qprintwidget.h" #include "ui_qprintwidget.h"
#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY) #ifndef QT_NO_CUPS
# include <private/qcups_p.h> #include <private/qcups_p.h>
# include "qcupsjobwidget_p.h" #include "qcupsjobwidget_p.h"
#else
# include <QtCore/qlibrary.h>
# include <private/qprintengine_pdf_p.h>
#endif #endif
/* /*
@ -133,7 +133,7 @@ private:
friend class QUnixPrintWidgetPrivate; friend class QUnixPrintWidgetPrivate;
Ui::QPrintPropertiesWidget widget; Ui::QPrintPropertiesWidget widget;
QDialogButtonBox *m_buttons; QDialogButtonBox *m_buttons;
#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY) #ifndef QT_NO_CUPS
QCupsJobWidget *m_jobOptions; QCupsJobWidget *m_jobOptions;
#endif #endif
}; };
@ -180,6 +180,8 @@ public:
Ui::QPrintWidget widget; Ui::QPrintWidget widget;
QAbstractPrintDialog * q; QAbstractPrintDialog * q;
QPrinter *printer; QPrinter *printer;
QPrintDevice m_currentPrintDevice;
void updateWidget(); void updateWidget();
private: private:
@ -248,11 +250,9 @@ QPrintPropertiesDialog::QPrintPropertiesDialog(QAbstractPrintDialog *parent)
connect(m_buttons->button(QDialogButtonBox::Ok), SIGNAL(clicked()), this, SLOT(accept())); connect(m_buttons->button(QDialogButtonBox::Ok), SIGNAL(clicked()), this, SLOT(accept()));
connect(m_buttons->button(QDialogButtonBox::Cancel), SIGNAL(clicked()), this, SLOT(reject())); connect(m_buttons->button(QDialogButtonBox::Cancel), SIGNAL(clicked()), this, SLOT(reject()));
#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY) #ifndef QT_NO_CUPS
if (QCUPSSupport::isAvailable()) { m_jobOptions = new QCupsJobWidget();
m_jobOptions = new QCupsJobWidget(); widget.tabs->addTab(m_jobOptions, tr("Job Options"));
widget.tabs->addTab(m_jobOptions, tr("Job Options"));
}
#endif #endif
} }
@ -263,20 +263,16 @@ QPrintPropertiesDialog::~QPrintPropertiesDialog()
void QPrintPropertiesDialog::applyPrinterProperties(QPrinter *p) void QPrintPropertiesDialog::applyPrinterProperties(QPrinter *p)
{ {
widget.pageSetup->setPrinter(p); widget.pageSetup->setPrinter(p);
#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY) #ifndef QT_NO_CUPS
if (QCUPSSupport::isAvailable()) { m_jobOptions->setPrinter(p);
m_jobOptions->setPrinter(p);
}
#endif #endif
} }
void QPrintPropertiesDialog::setupPrinter() const void QPrintPropertiesDialog::setupPrinter() const
{ {
widget.pageSetup->setupPrinter(); widget.pageSetup->setupPrinter();
#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY) #ifndef QT_NO_CUPS
if (QCUPSSupport::isAvailable()) { m_jobOptions->setupPrinter();
m_jobOptions->setupPrinter();
}
#endif #endif
} }
@ -323,13 +319,11 @@ void QPrintDialogPrivate::init()
options.grayscale->setIconSize(QSize(32, 32)); options.grayscale->setIconSize(QSize(32, 32));
options.grayscale->setIcon(QIcon(QLatin1String(":/qt-project.org/dialogs/qprintdialog/images/status-gray-scale.png"))); options.grayscale->setIcon(QIcon(QLatin1String(":/qt-project.org/dialogs/qprintdialog/images/status-gray-scale.png")));
#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY) #ifndef QT_NO_CUPS
// Add Page Set widget if CUPS is available // Add Page Set widget if CUPS is available
if (QCUPSSupport::isAvailable()) { options.pageSetCombo->addItem(tr("All Pages"), QVariant::fromValue(QCUPSSupport::AllPages));
options.pageSetCombo->addItem(tr("All Pages"), QVariant::fromValue(QCUPSSupport::AllPages)); options.pageSetCombo->addItem(tr("Odd Pages"), QVariant::fromValue(QCUPSSupport::OddPages));
options.pageSetCombo->addItem(tr("Odd Pages"), QVariant::fromValue(QCUPSSupport::OddPages)); options.pageSetCombo->addItem(tr("Even Pages"), QVariant::fromValue(QCUPSSupport::EvenPages));
options.pageSetCombo->addItem(tr("Even Pages"), QVariant::fromValue(QCUPSSupport::EvenPages));
}
#endif #endif
top->d->setOptionsPane(this); top->d->setOptionsPane(this);
@ -447,24 +441,27 @@ void QPrintDialogPrivate::setupPrinter()
} }
} }
#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY) #ifndef QT_NO_CUPS
// page set // page set
if (QCUPSSupport::isAvailable()) { if (p->printRange() == QPrinter::AllPages || p->printRange() == QPrinter::PageRange) {
if (p->printRange() == QPrinter::AllPages || p->printRange() == QPrinter::PageRange) { //If the application is selecting pages and the first page number is even then need to adjust the odd-even accordingly
//If the application is selecting pages and the first page number is even then need to adjust the odd-even accordingly QCUPSSupport::PageSet pageSet = options.pageSetCombo->itemData(options.pageSetCombo->currentIndex()).value<QCUPSSupport::PageSet>();
QCUPSSupport::PageSet pageSet = options.pageSetCombo->itemData(options.pageSetCombo->currentIndex()).value<QCUPSSupport::PageSet>(); if (q->isOptionEnabled(QPrintDialog::PrintPageRange)
if (q->isOptionEnabled(QPrintDialog::PrintPageRange) && p->printRange() == QPrinter::PageRange
&& p->printRange() == QPrinter::PageRange && (q->fromPage() % 2 == 0)) {
&& (q->fromPage() % 2 == 0)) {
if (pageSet == QCUPSSupport::OddPages) switch (pageSet) {
QCUPSSupport::setPageSet(p, QCUPSSupport::EvenPages); case QCUPSSupport::AllPages:
else if (pageSet == QCUPSSupport::EvenPages) break;
QCUPSSupport::setPageSet(p, QCUPSSupport::OddPages); case QCUPSSupport::OddPages:
} else if (pageSet != QCUPSSupport::AllPages) { QCUPSSupport::setPageSet(p, QCUPSSupport::EvenPages);
QCUPSSupport::setPageSet(p, pageSet); break;
case QCUPSSupport::EvenPages:
QCUPSSupport::setPageSet(p, QCUPSSupport::OddPages);
break;
} }
} else if (pageSet != QCUPSSupport::AllPages) {
QCUPSSupport::setPageSet(p, pageSet);
} }
// server-side page range, since we set the page range on the printer to 0-0/AllPages above, // server-side page range, since we set the page range on the printer to 0-0/AllPages above,
@ -527,26 +524,22 @@ void QPrintDialogPrivate::updateWidgets()
options.printCurrentPage->setVisible(q->isOptionEnabled(QPrintDialog::PrintCurrentPage)); options.printCurrentPage->setVisible(q->isOptionEnabled(QPrintDialog::PrintCurrentPage));
options.collate->setVisible(q->isOptionEnabled(QPrintDialog::PrintCollateCopies)); options.collate->setVisible(q->isOptionEnabled(QPrintDialog::PrintCollateCopies));
#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY) #ifndef QT_NO_CUPS
if (QCUPSSupport::isAvailable()) { // Don't display Page Set if only Selection or Current Page are enabled
// Don't display Page Set if only Selection or Current Page are enabled if (!q->isOptionEnabled(QPrintDialog::PrintPageRange)
if (!q->isOptionEnabled(QPrintDialog::PrintPageRange) && ( && (q->isOptionEnabled(QPrintDialog::PrintSelection) || q->isOptionEnabled(QPrintDialog::PrintCurrentPage))) {
q->isOptionEnabled(QPrintDialog::PrintSelection) || options.pageSetCombo->setVisible(false);
q->isOptionEnabled(QPrintDialog::PrintCurrentPage))) { options.pageSetLabel->setVisible(false);
} else {
options.pageSetCombo->setVisible(true);
options.pageSetLabel->setVisible(true);
}
options.pageSetCombo->setVisible(false); if (!q->isOptionEnabled(QPrintDialog::PrintPageRange)) {
options.pageSetLabel->setVisible(false); // If we can do CUPS server side pages selection,
} else { // display the page range widgets
options.pageSetCombo->setVisible(true); options.gbPrintRange->setVisible(true);
options.pageSetLabel->setVisible(true); options.printRange->setEnabled(true);
}
if (!q->isOptionEnabled(QPrintDialog::PrintPageRange)) {
// If we can do CUPS server side pages selection,
// display the page range widgets
options.gbPrintRange->setVisible(true);
options.printRange->setEnabled(true);
}
} }
#endif #endif
@ -675,12 +668,17 @@ QUnixPrintWidgetPrivate::QUnixPrintWidgetPrivate(QUnixPrintWidget *p, QPrinter *
widget.setupUi(parent); widget.setupUi(parent);
int currentPrinterIndex = 0; int currentPrinterIndex = 0;
QList<QPrinterInfo> printers = QPrinterInfo::availablePrinters(); QStringList printers;
QString defaultPrinter;
QPlatformPrinterSupport *ps = QPlatformPrinterSupportPlugin::get();
if (ps) {
printers = ps->availablePrintDeviceIds();
defaultPrinter = ps->defaultPrintDeviceId();
}
for (int i = 0; i < printers.size(); ++i) { for (int i = 0; i < printers.size(); ++i) {
QPrinterInfo pInfo = printers.at(i); widget.printers->addItem(printers.at(i));
widget.printers->addItem(pInfo.printerName()); if (printers.at(i) == defaultPrinter)
if (pInfo.isDefault())
currentPrinterIndex = i; currentPrinterIndex = i;
} }
widget.properties->setEnabled(true); widget.properties->setEnabled(true);
@ -769,12 +767,14 @@ void QUnixPrintWidgetPrivate::_q_printerChanged(int index)
} }
if (printer) { if (printer) {
QString printerName = widget.printers->itemText(index); QPlatformPrinterSupport *ps = QPlatformPrinterSupportPlugin::get();
printer->setPrinterName(printerName); if (ps)
m_currentPrintDevice = ps->createPrintDevice(widget.printers->itemText(index));
QPrinterInfo printerInfo = QPrinterInfo::printerInfo(printer->printerName()); printer->setPrinterName(m_currentPrintDevice.id());
widget.location->setText(printerInfo.location());
widget.type->setText(printerInfo.makeAndModel()); widget.location->setText(m_currentPrintDevice.location());
widget.type->setText(m_currentPrintDevice.makeAndModel());
if (optionsPane) if (optionsPane)
optionsPane->selectPrinter(QPrinter::NativeFormat); optionsPane->selectPrinter(QPrinter::NativeFormat);
} }
@ -841,7 +841,7 @@ void QUnixPrintWidgetPrivate::applyPrinterProperties()
} }
} }
} }
// PDF and PS printers are not added to the dialog yet, we'll handle those cases in QUnixPrintWidgetPrivate::updateWidget // PDF printer not added to the dialog yet, we'll handle those cases in QUnixPrintWidgetPrivate::updateWidget
if (propertiesDialog) if (propertiesDialog)
propertiesDialog->applyPrinterProperties(printer); propertiesDialog->applyPrinterProperties(printer);
@ -878,7 +878,7 @@ bool QUnixPrintWidgetPrivate::checkFields()
} }
} }
#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY) #ifndef QT_NO_CUPS
if (propertiesDialogShown) { if (propertiesDialogShown) {
QCUPSSupport::PagesPerSheet pagesPerSheet = propertiesDialog->widget.pageSetup->m_ui.pagesPerSheetCombo QCUPSSupport::PagesPerSheet pagesPerSheet = propertiesDialog->widget.pageSetup->m_ui.pagesPerSheetCombo
->currentData().value<QCUPSSupport::PagesPerSheet>(); ->currentData().value<QCUPSSupport::PagesPerSheet>();