QtPrintSupport - Fix Mac printerName() use
Mac in Qt4 and 5 has been using the PMPrinter Name for the QPrinter and QPrinterInfo printerName() value, but this is incorrect. This is in fact the CUPS Description field, is in human readable form and is not guaranteed to be unique. The CUPS Name field is the PMPrinter ID value and should be used as the unique identifier when accessing printers. This has worked up to now due to an undocumented feature in the OSX api that accepted the Name when the ID should be used. Changing all uses of PMPrinterGetName to PMPrinterGetID fixes this and allows the QPrinterInfo test of names to pass without munging the names. Change-Id: I25322aa1a924bed9f67f4ad5e208274c8b700e17 Reviewed-by: Lars Knoll <lars.knoll@nokia.com> Reviewed-by: Bradley T. Hughes <bradley.hughes@nokia.com> Reviewed-by: John Layt <jlayt@kde.org>
This commit is contained in:
parent
e9d20b1951
commit
f3ad57e90e
@ -108,7 +108,7 @@ QList<QPrinterInfo> QCocoaPrinterSupport::availablePrinters()
|
||||
CFIndex count = CFArrayGetCount(printerList);
|
||||
for (CFIndex i = 0; i < count; ++i) {
|
||||
PMPrinter printer = static_cast<PMPrinter>(const_cast<void *>(CFArrayGetValueAtIndex(printerList, i)));
|
||||
QString printerName = QCFString::toQString(PMPrinterGetName(printer));
|
||||
QString printerName = QCFString::toQString(PMPrinterGetID(printer));
|
||||
returnValue += QPlatformPrinterSupport::printerInfo(printerName, PMPrinterIsDefault(printer));
|
||||
}
|
||||
}
|
||||
|
@ -626,7 +626,7 @@ void QMacPrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &va
|
||||
CFIndex count = CFArrayGetCount(printerList);
|
||||
for (CFIndex i=0; i<count; ++i) {
|
||||
PMPrinter printer = static_cast<PMPrinter>(const_cast<void *>(CFArrayGetValueAtIndex(printerList, i)));
|
||||
QString name = QCFString::toQString(PMPrinterGetName(printer));
|
||||
QString name = QCFString::toQString(PMPrinterGetID(printer));
|
||||
if (name == value.toString()) {
|
||||
status = PMSessionSetCurrentPMPrinter(d->session(), printer);
|
||||
printerNameSet = true;
|
||||
@ -777,7 +777,7 @@ QVariant QMacPrintEngine::property(PrintEnginePropertyKey key) const
|
||||
if (status != noErr)
|
||||
qWarning("QMacPrintEngine::printerName: Failed getting current PMPrinter: %ld", long(status));
|
||||
if (printer)
|
||||
ret = QCFString::toQString(PMPrinterGetName(printer));
|
||||
ret = QCFString::toQString(PMPrinterGetID(printer));
|
||||
break; }
|
||||
case PPK_Resolution: {
|
||||
ret = d->resolution.hRes;
|
||||
|
@ -70,7 +70,6 @@ private slots:
|
||||
void testAssignment();
|
||||
|
||||
private:
|
||||
void macFixNameFormat(QString *printerName);
|
||||
QString getDefaultPrinterFromSystem();
|
||||
QStringList getPrintersFromSystem();
|
||||
|
||||
@ -86,18 +85,6 @@ void tst_QPrinterInfo::initTestCase()
|
||||
|
||||
#else
|
||||
|
||||
void tst_QPrinterInfo::macFixNameFormat(QString *printerName)
|
||||
{
|
||||
// Modify the format of the printer name to match Qt, lpstat returns
|
||||
// foo___domain_no, Qt returns foo @ domain.no
|
||||
#ifdef Q_OS_MAC
|
||||
printerName->replace(QLatin1String("___"), QLatin1String(" @ "));
|
||||
printerName->replace(QLatin1String("_"), QLatin1String("."));
|
||||
#else
|
||||
Q_UNUSED(printerName);
|
||||
#endif
|
||||
}
|
||||
|
||||
QString tst_QPrinterInfo::getDefaultPrinterFromSystem()
|
||||
{
|
||||
QStringList command;
|
||||
@ -113,7 +100,6 @@ QString tst_QPrinterInfo::getDefaultPrinterFromSystem()
|
||||
QRegExp defaultReg("default.*: *([a-zA-Z0-9_-]+)");
|
||||
defaultReg.indexIn(output);
|
||||
QString printer = defaultReg.cap(1);
|
||||
macFixNameFormat(&printer);
|
||||
return printer;
|
||||
}
|
||||
|
||||
@ -130,7 +116,6 @@ QStringList tst_QPrinterInfo::getPrintersFromSystem()
|
||||
for (int c = 0; c < list.size(); ++c) {
|
||||
if (reg.indexIn(list[c]) >= 0) {
|
||||
QString printer = reg.cap(1);
|
||||
macFixNameFormat(&printer);
|
||||
ans << printer;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user