QtPrintSupport - Add QPrinterInfo api for more printer details

A previous commit changed the Mac behaviour for printerName()
from returning the CUPS Description to returning the CUPS Name.
In case anyone was relying on this for a human-readable name
add new api to return the CUPS Description.  Also add the
Location and Make and Model which will be used in the Unix
print dialog instead of directly calling CUPS.

Change-Id: I9901bf8d6368466adf111580f5db5a3f01ca9170
Reviewed-by: Teemu Katajisto <teemu.katajisto@digia.com>
Reviewed-by: Bradley T. Hughes <bradley.hughes@nokia.com>
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Reviewed-by: John Layt <jlayt@kde.org>
bb10
John Layt 2012-05-14 21:02:13 +01:00 committed by Qt by Nokia
parent b7104d6645
commit 44f7df439f
5 changed files with 63 additions and 1 deletions

View File

@ -129,6 +129,12 @@ QPrinterInfo QCocoaPrinterSupport::printerInfoFromPMPrinter(const PMPrinter &pri
return QPrinterInfo();
QPrinterInfo pi = QPrinterInfo(QCFString::toQString(PMPrinterGetID(printer)));
pi.d_func()->description = QCFString::toQString(PMPrinterGetName(printer));
pi.d_func()->location = QCFString::toQString(PMPrinterGetLocation(printer));
CFStringRef makeAndModel;
PMPrinterGetMakeAndModelName(printer, &makeAndModel);
pi.d_func()->makeAndModel = QCFString::toQString(makeAndModel);
pi.d_func()->isDefault = PMPrinterIsDefault(printer);
return pi;

View File

@ -137,6 +137,9 @@ QPrinterInfo &QPrinterInfo::operator=(const QPrinterInfo &other)
/*!
Returns the name of the printer.
This is a unique id to identify the printer and may not be human-readable.
\sa QPrinterInfo::description()
\sa QPrinter::setPrinterName()
*/
QString QPrinterInfo::printerName() const
@ -145,6 +148,44 @@ QString QPrinterInfo::printerName() const
return d->name;
}
/*!
\fn QString QPrinterInfo::description()
\since 5.0
Returns the human-readable description of the printer.
\sa QPrinterInfo::printerName()
*/
QString QPrinterInfo::description() const
{
const Q_D(QPrinterInfo);
return d->description;
}
/*!
\fn QString QPrinterInfo::location()
\since 5.0
Returns the human-readable location of the printer.
*/
QString QPrinterInfo::location() const
{
const Q_D(QPrinterInfo);
return d->location;
}
/*!
\fn QString QPrinterInfo::makeAndModel()
\since 5.0
Returns the human-readable make and model of the printer.
*/
QString QPrinterInfo::makeAndModel() const
{
const Q_D(QPrinterInfo);
return d->makeAndModel;
}
/*!
Returns whether this QPrinterInfo object holds a printer definition.

View File

@ -65,8 +65,13 @@ public:
QPrinterInfo &operator=(const QPrinterInfo &other);
QString printerName() const;
QString description() const;
QString location() const;
QString makeAndModel() const;
bool isNull() const;
bool isDefault() const;
QList<QPrinter::PaperSize> supportedPaperSizes() const;
static QList<QPrinterInfo> availablePrinters();

View File

@ -77,6 +77,9 @@ public:
static QPrinterInfoPrivate shared_null;
QString name;
QString description;
QString location;
QString makeAndModel;
bool isDefault;
#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)

View File

@ -296,6 +296,9 @@ void tst_QPrinterInfo::testAssignment()
QCOMPARE(copy.printerName(), printers.at(i).printerName());
QCOMPARE(copy.isNull(), printers.at(i).isNull());
QCOMPARE(copy.isDefault(), printers.at(i).isDefault());
QCOMPARE(copy.description(), printers.at(i).description());
QCOMPARE(copy.location(), printers.at(i).location());
QCOMPARE(copy.makeAndModel(), printers.at(i).makeAndModel());
QCOMPARE(copy.supportedPaperSizes(), printers.at(i).supportedPaperSizes());
}
}
@ -308,9 +311,13 @@ void tst_QPrinterInfo::namedPrinter()
foreach (const QPrinterInfo &pi, printers) {
QPrinterInfo pi2 = QPrinterInfo::printerInfo(pi.printerName());
qDebug() << "Printer: " << pi2.printerName() << " : "
qDebug() << "Printer: " << pi2.printerName() << " : " << pi2.description() << " : "
<< pi2.location() << " : " << pi2.makeAndModel() << " : "
<< pi2.isNull() << " : " << pi2.isDefault();
QCOMPARE(pi2.printerName(), pi.printerName());
QCOMPARE(pi2.description(), pi.description());
QCOMPARE(pi2.location(), pi.location());
QCOMPARE(pi2.makeAndModel(), pi.makeAndModel());
QCOMPARE(pi2.supportedPaperSizes(), pi.supportedPaperSizes());
QCOMPARE(pi2.isNull(), pi.isNull());
QCOMPARE(pi2.isDefault(), pi.isDefault());