Fix QPpdPrintDevice::isDefault

How to test:
 * Have two printers
 * Use lpoptions -d to set the default printer to be one and then the
other
 * Use lpstat -d to check setting the default printer worked
 * Use this simple test program and check the resulting values make
sense
    qDebug() << "DefaultPrinter" << QPrinterInfo::defaultPrinter().printerName();
    const QList<QPrinterInfo> list = QPrinterInfo::availablePrinters();
    for(const QPrinterInfo &pi : list) {
        qDebug() << pi.printerName() << pi.isDefault();
    }

Fixes: QTBUG-70317
Change-Id: I535d11451c568630a374f5c37d8cac32cbb6d3ab
Reviewed-by: Frederik Gladhorn <frederik.gladhorn@qt.io>
This commit is contained in:
Albert Astals Cid 2018-11-23 17:19:14 +01:00 committed by Frederik Gladhorn
parent 0cf5648ce6
commit 6d58a1cecb
3 changed files with 15 additions and 1 deletions

View File

@ -174,6 +174,11 @@ QStringList QCupsPrinterSupport::availablePrintDeviceIds() const
}
QString QCupsPrinterSupport::defaultPrintDeviceId() const
{
return staticDefaultPrintDeviceId();
}
QString QCupsPrinterSupport::staticDefaultPrintDeviceId()
{
QString printerId;
cups_dest_t *dests;

View File

@ -71,6 +71,8 @@ public:
QStringList availablePrintDeviceIds() const override;
QString defaultPrintDeviceId() const override;
static QString staticDefaultPrintDeviceId();
private:
QString cupsOption(int i, const QString &key) const;
};

View File

@ -39,6 +39,8 @@
#include "qppdprintdevice.h"
#include "qcupsprintersupport_p.h"
#include <QtCore/QMimeDatabase>
#include <qdebug.h>
@ -118,7 +120,12 @@ bool QPpdPrintDevice::isValid() const
bool QPpdPrintDevice::isDefault() const
{
return printerTypeFlags() & CUPS_PRINTER_DEFAULT;
// There seems to be a bug in cups in which printerTypeFlags
// returns CUPS_PRINTER_DEFAULT based only on system values, ignoring user lpoptions
// so we can't use that. And also there seems to be a bug in which dests returned
// by cupsGetNamedDest don't have is_default set at all so we can't use that either
// so go the long route and compare our id against the defaultPrintDeviceId
return id() == QCupsPrinterSupport::staticDefaultPrintDeviceId();
}
QPrint::DeviceState QPpdPrintDevice::state() const