remove LPR support leftovers

removes the NSL and NIS optional dependencies and effectively speeds up
the initialization of printing dialog and obtaining of information about
prineters. this change leaves CUPS as the only option to support
printing

Signed-off-by: Ivailo Monev <xakepa10@laimg.moc>
This commit is contained in:
Ivailo Monev 2020-03-07 22:20:18 +00:00
parent 7c0f7a8f11
commit 31b97f69d7
8 changed files with 3 additions and 902 deletions

View file

@ -100,9 +100,6 @@ set(KATIE_TOOLS_SUFFIX "" CACHE STRING "Tools (moc, uic, rcc, etc.) suffix")
katie_setup_paths()
# optional package
option(WITH_NIS "Build NIS support" ON)
add_feature_info(nis WITH_NIS "build NIS support")
option(WITH_CUPS "Build CUPS support" ON)
add_feature_info(cups WITH_CUPS "build CUPS support")
@ -137,9 +134,6 @@ add_feature_info(mysql WITH_MYSQL "build MySQL support")
option(WITH_RESOLV "Build resolv support" ON)
add_feature_info(resolv WITH_RESOLV "build resolv support")
option(WITH_NSL "Build NSL support" ON)
add_feature_info(nsl WITH_NSL "build NSL support")
option(WITH_UNWIND "Build Unwind support" OFF)
add_feature_info(unwind WITH_UNWIND "build Unwind support")
@ -320,14 +314,6 @@ set_package_properties(Threads PROPERTIES
TYPE REQUIRED
)
find_package(NIS)
set_package_properties(NIS PROPERTIES
PURPOSE "Required for Network Information Service support"
DESCRIPTION "Standard C library specific NIS implementation"
URL ""
TYPE RECOMMENDED
)
find_package(Resolv)
set_package_properties(Resolv PROPERTIES
PURPOSE "Required for domain resolving support"
@ -336,14 +322,6 @@ set_package_properties(Resolv PROPERTIES
TYPE RECOMMENDED
)
find_package(NSL)
set_package_properties(NSL PROPERTIES
PURPOSE "Required for printing information support"
DESCRIPTION "Standard C library specific NSL implementation"
URL ""
TYPE RECOMMENDED
)
# v1.5.4+ required for png_longjmp_ptr() without noreturn attribute
find_package(PNG 1.5.4)
set_package_properties(PNG PROPERTIES
@ -506,14 +484,6 @@ if(NOT WITH_RESOLV OR NOT RESOLV_FOUND)
katie_definition(-DQT_NO_RESOLV)
endif()
if(NOT WITH_NSL OR NOT NSL_FOUND)
katie_definition(-DQT_NO_NSL)
endif()
if(NOT WITH_NIS OR NOT NIS_FOUND)
katie_definition(-DQT_NO_NIS)
endif()
if(NOT WITH_JPEG OR NOT JPEG_FOUND)
katie_definition(-DQT_NO_IMAGEFORMAT_JPEG)
endif()

View file

@ -1,29 +0,0 @@
# - Try to find Network Information Service
# Once done this will define
#
# NIS_FOUND - system has NIS
# NIS_INCLUDES - the NIS include directory
# NIS_LIBRARIES - the libraries needed to use NIS
#
# Copyright (c) 2015-2020, Ivailo Monev, <xakepa10@gmail.com>
#
# Redistribution and use is allowed according to the terms of the BSD license.
# NIS does not provide pkg-config files
find_path(NIS_INCLUDES
NAMES rpc/rpc.h
HINTS $ENV{NISDIR}/include
)
find_library(NIS_LIBRARIES
NAMES nsl
HINTS $ENV{NISDIR}/lib
)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(NIS
REQUIRED_VARS NIS_LIBRARIES NIS_INCLUDES
)
mark_as_advanced(NIS_INCLUDES NIS_LIBRARIES)

View file

@ -1,29 +0,0 @@
# - Try to find NSL
# Once done this will define
#
# NSL_FOUND - system has NSL
# NSL_INCLUDES - the NSL include directory
# NSL_LIBRARIES - the libraries needed to use NSL
#
# Copyright (c) 2016-2020, Ivailo Monev, <xakepa10@gmail.com>
#
# Redistribution and use is allowed according to the terms of the BSD license.
# NSL does not provide pkg-config files
find_path(NSL_INCLUDES
NAMES rpcsvc/ypclnt.h
HINTS $ENV{NSLDIR}/include
)
find_library(NSL_LIBRARIES
NAMES nsl c
HINTS $ENV{NSLDIR}/lib
)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(NSL
REQUIRED_VARS NSL_LIBRARIES NSL_INCLUDES
)
mark_as_advanced(NSL_INCLUDES NSL_LIBRARIES)

View file

@ -91,6 +91,8 @@
#define QT_NO_GLIB
#define QT_NO_ICONV
#define QT_NO_LPR
#define QT_NO_NIS
#define QT_NO_NSL
// Not supported, used to bootstrap
#cmakedefine QT_NO_QOBJECT
@ -225,8 +227,6 @@
#cmakedefine QT_NO_NETWORKDISKCACHE
#cmakedefine QT_NO_NETWORKINTERFACE
#cmakedefine QT_NO_NETWORKPROXY
#cmakedefine QT_NO_NIS
#cmakedefine QT_NO_NSL
#cmakedefine QT_NO_PDF
#cmakedefine QT_NO_PLUGIN_CHECK
#cmakedefine QT_NO_PRINTDIALOG

View file

@ -944,22 +944,6 @@ foreach(x11ext Xshape Xinerama Xrandr Xrender Xfixes Xcursor Xext SM ICE)
endif()
endforeach()
if(WITH_NIS AND NIS_FOUND)
set(EXTRA_GUI_LIBS
${EXTRA_GUI_LIBS}
${NIS_LIBRARIES}
)
include_directories(${NIS_INCLUDES})
endif()
if(WITH_NSL AND NSL_FOUND)
set(EXTRA_GUI_LIBS
${EXTRA_GUI_LIBS}
${NSL_LIBRARIES}
)
include_directories(${NSL_INCLUDES})
endif()
if(PNG_FOUND)
set(EXTRA_GUI_LIBS
${EXTRA_GUI_LIBS}

View file

@ -120,7 +120,6 @@ public:
Ui::QPrintWidget widget;
QAbstractPrintDialog * q;
QPrinter *printer;
QList<QPrinterDescription> lprPrinters;
void updateWidget();
private:
@ -637,14 +636,6 @@ QUnixPrintWidgetPrivate::QUnixPrintWidgetPrivate(QUnixPrintWidget *p)
widget.properties->setEnabled(true);
}
currentPrinterIndex = cups->currentPrinterIndex();
} else {
#endif
currentPrinterIndex = qt_getLprPrinters(lprPrinters);
// populating printer combo
QList<QPrinterDescription>::const_iterator i = lprPrinters.constBegin();
for(; i != lprPrinters.constEnd(); ++i)
widget.printers->addItem((*i).name);
#if !defined(QT_NO_CUPS)
}
#endif
@ -765,16 +756,6 @@ void QUnixPrintWidgetPrivate::_q_printerChanged(int index)
} else {
if (optionsPane)
optionsPane->selectPrinter(0);
#endif
if (lprPrinters.count() > 0) {
QString type = lprPrinters.at(index).name + QLatin1Char('@') + lprPrinters.at(index).host;
if (!lprPrinters.at(index).comment.isEmpty())
type += QLatin1String(", ") + lprPrinters.at(index).comment;
widget.type->setText(type);
if (propertiesDialog)
propertiesDialog->selectPrinter();
}
#if !defined(QT_NO_CUPS)
}
#endif
}

View file

@ -46,10 +46,6 @@
# include "qpdf_p.h"
#endif
#ifndef QT_NO_NSL
#include <rpcsvc/ypclnt.h>
#endif
#include "qprinterinfo_unix_p.h"
QT_BEGIN_NAMESPACE
@ -108,720 +104,6 @@ static inline QPrinter::PaperSize string2PaperSize(const char *name)
}
#endif
void qt_perhapsAddPrinter(QList<QPrinterDescription> *printers, const QString &name,
QString host, QString comment,
QStringList aliases)
{
for (int i = 0; i < printers->size(); ++i)
if (printers->at(i).samePrinter(name))
return;
#ifndef QT_NO_PRINTDIALOG
if (host.isEmpty())
host = QPrintDialog::tr("locally connected");
#endif
printers->append(QPrinterDescription(name.simplified(), host.simplified(), comment.simplified(), aliases));
}
void qt_parsePrinterDesc(QString printerDesc, QList<QPrinterDescription> *printers)
{
if (printerDesc.length() < 1)
return;
printerDesc = printerDesc.simplified();
int i = printerDesc.indexOf(QLatin1Char(':'));
QString printerName, printerComment, printerHost;
QStringList aliases;
if (i >= 0) {
// have ':' want '|'
int j = printerDesc.indexOf(QLatin1Char('|'));
if (j > 0 && j < i) {
printerName = printerDesc.left(j);
aliases = printerDesc.mid(j + 1, i - j - 1).split(QLatin1Char('|'));
#ifndef QT_NO_PRINTDIALOG
// try extracting a comment from the aliases
printerComment = QPrintDialog::tr("Aliases: %1")
.arg(aliases.join(QLatin1String(", ")));
#endif
} else {
printerName = printerDesc.left(i);
}
// look for lprng pseudo all printers entry
i = printerDesc.indexOf(QRegExp(QLatin1String(": *all *=")));
if (i >= 0)
printerName = QString();
// look for signs of this being a remote printer
i = printerDesc.indexOf(QRegExp(QLatin1String(": *rm *=")));
if (i >= 0) {
// point k at the end of remote host name
while (printerDesc[i] != QLatin1Char('='))
i++;
while (printerDesc[i] == QLatin1Char('=') || printerDesc[i].isSpace())
i++;
j = i;
while (j < (int)printerDesc.length() && printerDesc[j] != QLatin1Char(':'))
j++;
// and stuff that into the string
printerHost = printerDesc.mid(i, j - i);
}
}
if (printerName.length())
qt_perhapsAddPrinter(printers, printerName, printerHost, printerComment,
aliases);
}
int qt_parsePrintcap(QList<QPrinterDescription> *printers, const QString& fileName)
{
QFile printcap(fileName);
if (!printcap.open(QIODevice::ReadOnly))
return NotFound;
char *line_ascii = new char[1025];
line_ascii[1024] = '\0';
QString printerDesc;
bool atEnd = false;
while (!atEnd) {
if (printcap.atEnd() || printcap.readLine(line_ascii, 1024) <= 0)
atEnd = true;
QString line = QString::fromLocal8Bit(line_ascii);
line = line.trimmed();
if (line.length() >= 1 && line[int(line.length()) - 1] == QLatin1Char('\\'))
line.chop(1);
if (line[0] == QLatin1Char('#')) {
if (!atEnd)
continue;
} else if (line[0] == QLatin1Char('|') || line[0] == QLatin1Char(':')
|| line.isEmpty()) {
printerDesc += line;
if (!atEnd)
continue;
}
qt_parsePrinterDesc(printerDesc, printers);
// add the first line of the new printer definition
printerDesc = line;
}
delete[] line_ascii;
return Success;
}
/*!
\internal
Checks $HOME/.printers for a line matching '_default <name>' (where
<name> does not contain any white space). The first such match
results in <name> being returned.
If no lines match then an empty string is returned.
*/
QString qt_getDefaultFromHomePrinters()
{
QFile file(QDir::homePath() + QLatin1String("/.printers"));
if (!file.open(QIODevice::ReadOnly))
return QString();
QString all(QLatin1String(file.readAll()));
QStringList words = all.split(QRegExp(QLatin1String("\\W+")), QString::SkipEmptyParts);
const int i = words.indexOf(QLatin1String("_default"));
if (i != -1 && i < words.size() - 1)
return words.at(i + 1);
return QString();
}
// solaris, not 2.6
void qt_parseEtcLpPrinters(QList<QPrinterDescription> *printers)
{
QDir lp(QLatin1String("/etc/lp/printers"));
QFileInfoList dirs = lp.entryInfoList();
if (dirs.isEmpty())
return;
QString tmp;
for (int i = 0; i < dirs.size(); ++i) {
QFileInfo printer = dirs.at(i);
if (printer.isDir()) {
tmp.sprintf("/etc/lp/printers/%s/configuration",
printer.fileName().toAscii().data());
QFile configuration(tmp);
char *line = new char[1025];
QString remote(QLatin1String("Remote:"));
QString contentType(QLatin1String("Content types:"));
QString printerHost;
bool canPrintPostscript = false;
if (configuration.open(QIODevice::ReadOnly)) {
while (!configuration.atEnd() &&
configuration.readLine(line, 1024) > 0) {
if (QString::fromLatin1(line).startsWith(remote)) {
const char *p = line;
while (*p != ':')
p++;
p++;
while (isspace((uchar) *p))
p++;
printerHost = QString::fromLocal8Bit(p);
printerHost = printerHost.simplified();
} else if (QString::fromLatin1(line).startsWith(contentType)) {
char *p = line;
while (*p != ':')
p++;
p++;
char *e;
while (*p) {
while (isspace((uchar) *p))
p++;
if (*p) {
char s;
e = p;
while (isalnum((uchar) *e))
e++;
s = *e;
*e = '\0';
if (!qstrcmp(p, "postscript") ||
!qstrcmp(p, "any"))
canPrintPostscript = true;
*e = s;
if (s == ',')
e++;
p = e;
}
}
}
}
if (canPrintPostscript)
qt_perhapsAddPrinter(printers, printer.fileName(),
printerHost, QLatin1String(""));
}
delete[] line;
}
}
}
// solaris 2.6
char *qt_parsePrintersConf(QList<QPrinterDescription> *printers, bool *found)
{
QFile pc(QLatin1String("/etc/printers.conf"));
if (!pc.open(QIODevice::ReadOnly)) {
if (found)
*found = false;
return 0;
}
if (found)
*found = true;
char *line = new char[1025];
line[1024] = '\0';
QString printerDesc;
int lineLength = 0;
char *defaultPrinter = 0;
while (!pc.atEnd() &&
(lineLength=pc.readLine(line, 1024)) > 0) {
if (*line == '#') {
*line = '\0';
lineLength = 0;
}
if (lineLength >= 2 && line[lineLength-2] == '\\') {
line[lineLength-2] = '\0';
printerDesc += QString::fromLocal8Bit(line);
} else {
printerDesc += QString::fromLocal8Bit(line);
printerDesc = printerDesc.simplified();
int i = printerDesc.indexOf(QLatin1Char(':'));
QString printerName, printerHost, printerComment;
QStringList aliases;
if (i >= 0) {
// have : want |
int j = printerDesc.indexOf(QLatin1Char('|'));
if (j >= i)
j = -1;
printerName = printerDesc.mid(0, j < 0 ? i : j);
if (printerName == QLatin1String("_default")) {
i = printerDesc.indexOf(
QRegExp(QLatin1String(": *use *=")));
while (printerDesc[i] != QLatin1Char('='))
i++;
while (printerDesc[i] == QLatin1Char('=') || printerDesc[i].isSpace())
i++;
j = i;
while (j < (int)printerDesc.length() &&
printerDesc[j] != QLatin1Char(':') && printerDesc[j] != QLatin1Char(','))
j++;
// that's our default printer
defaultPrinter =
qstrdup(printerDesc.mid(i, j-i).toAscii().data());
printerName = QString();
printerDesc = QString();
} else if (printerName == QLatin1String("_all")) {
// skip it.. any other cases we want to skip?
printerName = QString();
printerDesc = QString();
}
if (j > 0) {
// try extracting a comment from the aliases
aliases = printerDesc.mid(j + 1, i - j - 1).split(QLatin1Char('|'));
#ifndef QT_NO_PRINTDIALOG
printerComment = QPrintDialog::tr("Aliases: %1")
.arg(aliases.join(QLatin1String(", ")));
#endif
}
// look for signs of this being a remote printer
i = printerDesc.indexOf(
QRegExp(QLatin1String(": *bsdaddr *=")));
if (i >= 0) {
// point k at the end of remote host name
while (printerDesc[i] != QLatin1Char('='))
i++;
while (printerDesc[i] == QLatin1Char('=') || printerDesc[i].isSpace())
i++;
j = i;
while (j < (int)printerDesc.length() &&
printerDesc[j] != QLatin1Char(':') && printerDesc[j] != QLatin1Char(','))
j++;
// and stuff that into the string
printerHost = printerDesc.mid(i, j-i);
// maybe stick the remote printer name into the comment
if (printerDesc[j] == QLatin1Char(',')) {
i = ++j;
while (printerDesc[i].isSpace())
i++;
j = i;
while (j < (int)printerDesc.length() &&
printerDesc[j] != QLatin1Char(':') && printerDesc[j] != QLatin1Char(','))
j++;
if (printerName != printerDesc.mid(i, j-i)) {
printerComment =
QLatin1String("Remote name: ");
printerComment += printerDesc.mid(i, j-i);
}
}
}
}
if (printerComment == QLatin1String(":"))
printerComment = QString(); // for cups
if (printerName.length())
qt_perhapsAddPrinter(printers, printerName, printerHost,
printerComment, aliases);
// chop away the line, for processing the next one
printerDesc = QString();
}
}
delete[] line;
return defaultPrinter;
}
#ifndef QT_NO_NIS
#if defined(Q_C_CALLBACKS)
extern "C" {
#endif
int qt_pd_foreach(int /*status */, char * /*key */, int /*keyLen */,
char *val, int valLen, char *data)
{
qt_parsePrinterDesc(QString::fromLatin1(val, valLen), (QList<QPrinterDescription> *)data);
return 0;
}
#if defined(Q_C_CALLBACKS)
}
#endif
int qt_retrieveNisPrinters(QList<QPrinterDescription> *printers)
{
#ifndef QT_NO_NSL
typedef int (*WildCast)(int, char *, int, char *, int, char *);
char printersConfByname[] = "printers.conf.byname";
char *domain;
int err;
err = yp_get_default_domain(&domain);
if (err == 0) {
ypall_callback cb;
// wild cast to support K&R-style system headers
(WildCast &) cb.foreach = (WildCast) qt_pd_foreach;
cb.data = (char *) printers;
err = yp_all(domain, printersConfByname, &cb);
}
if (!err)
return Success;
#endif //QT_NO_NSL
return Unavail;
}
#endif // QT_NO_NIS
char *qt_parseNsswitchPrintersEntry(QList<QPrinterDescription> *printers, char *line)
{
#define skipSpaces() \
while (line[k] != '\0' && isspace((uchar) line[k])) \
k++
char *defaultPrinter = 0;
bool stop = false;
int lastStatus = NotFound;
int k = 8;
skipSpaces();
if (line[k] != ':')
return 0;
k++;
char *cp = strchr(line, '#');
if (cp != 0)
*cp = '\0';
while (line[k] != '\0') {
if (isspace((uchar) line[k])) {
k++;
} else if (line[k] == '[') {
k++;
skipSpaces();
while (line[k] != '\0') {
char status = tolower(line[k]);
char action = '?';
while (line[k] != '=' && line[k] != ']' && line[k] != '\0')
k++;
if (line[k] == '=') {
k++;
skipSpaces();
action = tolower(line[k]);
while (line[k] != '\0' && !isspace((uchar) line[k]) && line[k] != ']')
k++;
} else if (line[k] == ']') {
k++;
break;
}
skipSpaces();
if (lastStatus == status)
stop = (action == (char) Return);
}
} else {
if (stop)
break;
QByteArray source;
while (line[k] != '\0' && !isspace((uchar) line[k]) && line[k] != '[') {
source += line[k];
k++;
}
if (source == "user") {
lastStatus = qt_parsePrintcap(printers,
QDir::homePath() + QLatin1String("/.printers"));
} else if (source == "files") {
bool found;
defaultPrinter = qt_parsePrintersConf(printers, &found);
if (found)
lastStatus = Success;
#ifndef QT_NO_NIS
} else if (source == "nis") {
lastStatus = qt_retrieveNisPrinters(printers);
#endif
} else {
// nisplus, dns, etc., are not implemented yet
lastStatus = NotFound;
}
stop = (lastStatus == Success);
}
}
return defaultPrinter;
}
char *qt_parseNsswitchConf(QList<QPrinterDescription> *printers)
{
QFile nc(QLatin1String("/etc/nsswitch.conf"));
if (!nc.open(QIODevice::ReadOnly))
return 0;
char *defaultPrinter = 0;
char *line = new char[1025];
line[1024] = '\0';
while (!nc.atEnd() &&
nc.readLine(line, 1024) > 0) {
if (qstrncmp(line, "printers", 8) == 0) {
defaultPrinter = qt_parseNsswitchPrintersEntry(printers, line);
delete[] line;
return defaultPrinter;
}
}
strcpy(line, "printers: user files nis nisplus xfn");
defaultPrinter = qt_parseNsswitchPrintersEntry(printers, line);
delete[] line;
return defaultPrinter;
}
// HP-UX
void qt_parseEtcLpMember(QList<QPrinterDescription> *printers)
{
QDir lp(QLatin1String("/etc/lp/member"));
if (!lp.exists())
return;
QFileInfoList dirs = lp.entryInfoList();
if (dirs.isEmpty())
return;
#ifdef QT_NO_PRINTDIALOG
Q_UNUSED(printers);
#else
QString tmp;
for (int i = 0; i < dirs.size(); ++i) {
QFileInfo printer = dirs.at(i);
// I haven't found any real documentation, so I'm guessing that
// since lpstat uses /etc/lp/member rather than one of the
// other directories, it's the one to use. I did not find a
// decent way to locate aliases and remote printers.
if (printer.isFile())
qt_perhapsAddPrinter(printers, printer.fileName(),
QPrintDialog::tr("unknown"),
QLatin1String(""));
}
#endif
}
// IRIX 6.x
void qt_parseSpoolInterface(QList<QPrinterDescription> *printers)
{
QDir lp(QLatin1String("/usr/spool/lp/interface"));
if (!lp.exists())
return;
QFileInfoList files = lp.entryInfoList();
if(files.isEmpty())
return;
for (int i = 0; i < files.size(); ++i) {
QFileInfo printer = files.at(i);
if (!printer.isFile())
continue;
// parse out some information
QFile configFile(printer.filePath());
if (!configFile.open(QIODevice::ReadOnly))
continue;
QByteArray line;
line.resize(1025);
QString namePrinter;
QString hostName;
QString hostPrinter;
QString printerType;
QString nameKey(QLatin1String("NAME="));
QString typeKey(QLatin1String("TYPE="));
QString hostKey(QLatin1String("HOSTNAME="));
QString hostPrinterKey(QLatin1String("HOSTPRINTER="));
while (!configFile.atEnd() &&
(configFile.readLine(line.data(), 1024)) > 0) {
QString uline = QString::fromLocal8Bit(line);
if (uline.startsWith(typeKey) ) {
printerType = uline.mid(nameKey.length());
printerType = printerType.simplified();
} else if (uline.startsWith(hostKey)) {
hostName = uline.mid(hostKey.length());
hostName = hostName.simplified();
} else if (uline.startsWith(hostPrinterKey)) {
hostPrinter = uline.mid(hostPrinterKey.length());
hostPrinter = hostPrinter.simplified();
} else if (uline.startsWith(nameKey)) {
namePrinter = uline.mid(nameKey.length());
namePrinter = namePrinter.simplified();
}
}
configFile.close();
printerType = printerType.trimmed();
if (printerType.indexOf(QLatin1String("postscript"), 0, Qt::CaseInsensitive) < 0)
continue;
int ii = 0;
while ((ii = namePrinter.indexOf(QLatin1Char('"'), ii)) >= 0)
namePrinter.remove(ii, 1);
if (hostName.isEmpty() || hostPrinter.isEmpty()) {
qt_perhapsAddPrinter(printers, printer.fileName(),
QLatin1String(""), namePrinter);
} else {
QString comment;
comment = namePrinter;
comment += QLatin1String(" (");
comment += hostPrinter;
comment += QLatin1Char(')');
qt_perhapsAddPrinter(printers, printer.fileName(),
hostName, comment);
}
}
}
// Every unix must have its own. It's a standard. Here is AIX.
void qt_parseQconfig(QList<QPrinterDescription> *printers)
{
QFile qconfig(QLatin1String("/etc/qconfig"));
if (!qconfig.open(QIODevice::ReadOnly))
return;
QTextStream ts(&qconfig);
QString line;
QString stanzaName; // either a queue or a device name
bool up = true; // queue up? default true, can be false
QString remoteHost; // null if local
QString deviceName; // null if remote
QRegExp newStanza(QLatin1String("^[0-z\\-]*:$"));
// our basic strategy here is to process each line, detecting new
// stanzas. each time we see a new stanza, we check if the
// previous stanza was a valid queue for a) a remote printer or b)
// a local printer. if it wasn't, we assume that what we see is
// the start of the first stanza, or that the previous stanza was
// a device stanza, or that there is some syntax error (we don't
// report those).
do {
line = ts.readLine();
bool indented = line[0].isSpace();
line = line.simplified();
int i = line.indexOf(QLatin1Char('='));
if (indented && i != -1) { // line in stanza
QString variable = line.left(i).simplified();
QString value=line.mid(i+1, line.length()).simplified();
if (variable == QLatin1String("device"))
deviceName = value;
else if (variable == QLatin1String("host"))
remoteHost = value;
else if (variable == QLatin1String("up"))
up = !(value.toLower() == QLatin1String("false"));
} else if (line[0] == QLatin1Char('*')) { // comment
// nothing to do
} else if (ts.atEnd() || // end of file, or beginning of new stanza
(!indented && line.contains(newStanza))) {
if (up && stanzaName.length() > 0 && stanzaName.length() < 21) {
if (remoteHost.length()) // remote printer
qt_perhapsAddPrinter(printers, stanzaName, remoteHost,
QString());
else if (deviceName.length()) // local printer
qt_perhapsAddPrinter(printers, stanzaName, QString(),
QString());
}
line.chop(1);
if (line.length() >= 1 && line.length() <= 20)
stanzaName = line;
up = true;
remoteHost.clear();
deviceName.clear();
} else {
// syntax error? ignore.
}
} while (!ts.atEnd());
}
int qt_getLprPrinters(QList<QPrinterDescription>& printers)
{
QByteArray etcLpDefault;
qt_parsePrintcap(&printers, QLatin1String("/etc/printcap"));
qt_parseEtcLpMember(&printers);
qt_parseSpoolInterface(&printers);
qt_parseQconfig(&printers);
QFileInfo f;
f.setFile(QLatin1String("/etc/lp/printers"));
if (f.isDir()) {
qt_parseEtcLpPrinters(&printers);
QFile def(QLatin1String("/etc/lp/default"));
if (def.open(QIODevice::ReadOnly)) {
etcLpDefault.resize(1025);
if (def.readLine(etcLpDefault.data(), 1024) > 0) {
QRegExp rx(QLatin1String("^(\\S+)"));
if (rx.indexIn(QString::fromLatin1(etcLpDefault)) != -1)
etcLpDefault = rx.cap(1).toAscii();
}
}
}
char *def = 0;
f.setFile(QLatin1String("/etc/nsswitch.conf"));
if (f.isFile()) {
def = qt_parseNsswitchConf(&printers);
} else {
f.setFile(QLatin1String("/etc/printers.conf"));
if (f.isFile())
def = qt_parsePrintersConf(&printers);
}
if (def) {
etcLpDefault = def;
delete [] def;
}
QString homePrintersDefault = qt_getDefaultFromHomePrinters();
// all printers hopefully known. try to find a good default
QString dollarPrinter;
{
dollarPrinter = QString::fromLocal8Bit(qgetenv("PRINTER"));
if (dollarPrinter.isEmpty())
dollarPrinter = QString::fromLocal8Bit(qgetenv("LPDEST"));
if (dollarPrinter.isEmpty())
dollarPrinter = QString::fromLocal8Bit(qgetenv("NPRINTER"));
if (dollarPrinter.isEmpty())
dollarPrinter = QString::fromLocal8Bit(qgetenv("NGPRINTER"));
#ifndef QT_NO_PRINTDIALOG
if (!dollarPrinter.isEmpty())
qt_perhapsAddPrinter(&printers, dollarPrinter,
QPrintDialog::tr("unknown"),
QLatin1String(""));
#endif
}
QRegExp ps(QLatin1String("[^a-z]ps(?:[^a-z]|$)"));
QRegExp lp(QLatin1String("[^a-z]lp(?:[^a-z]|$)"));
int quality = 0;
int best = 0;
for (int i = 0; i < printers.size(); ++i) {
QString name = printers.at(i).name;
QString comment = printers.at(i).comment;
if (quality < 5 && name == dollarPrinter) {
best = i;
quality = 5;
} else if (quality < 4 && !homePrintersDefault.isEmpty() &&
name == homePrintersDefault) {
best = i;
quality = 4;
} else if (quality < 3 && !etcLpDefault.isEmpty() &&
name == QLatin1String(etcLpDefault)) {
best = i;
quality = 3;
} else if (quality < 2 &&
(name == QLatin1String("ps") ||
ps.indexIn(comment) != -1)) {
best = i;
quality = 2;
} else if (quality < 1 &&
(name == QLatin1String("lp") ||
lp.indexIn(comment) > -1)) {
best = i;
quality = 1;
}
}
return best;
}
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
@ -845,17 +127,8 @@ QList<QPrinterInfo> QPrinterInfo::availablePrinters()
printerInfo.d_ptr->cupsPrinterIndex = i;
printers.append(printerInfo);
}
} else
#endif
{
QList<QPrinterDescription> lprPrinters;
int defprn = qt_getLprPrinters(lprPrinters);
// populating printer combo
foreach (const QPrinterDescription &description, lprPrinters)
printers.append(QPrinterInfo(description.name));
if (defprn >= 0 && defprn < printers.size())
printers[defprn].d_ptr->isDefault = true;
}
#endif
return printers;
}

View file

@ -34,23 +34,6 @@
#ifndef QPRINTERINFO_UNIX_P_H
#define QPRINTERINFO_UNIX_P_H
#ifndef QT_NO_NIS
# ifndef BOOL_DEFINED
# define BOOL_DEFINED
# endif
# include <sys/types.h>
# include <rpc/rpc.h>
# ifndef QT_NO_NSL
# include <rpcsvc/ypclnt.h>
# include <rpcsvc/yp_prot.h>
# endif // QT_NO_NSL
#endif // QT_NO_NIS
#ifdef Success
# undef Success
#endif
#include <ctype.h>
QT_BEGIN_NAMESPACE
@ -80,38 +63,6 @@ struct QPrinterDescription {
}
};
enum { Success = 's', Unavail = 'u', NotFound = 'n', TryAgain = 't' };
enum { Continue = 'c', Return = 'r' };
void qt_perhapsAddPrinter(QList<QPrinterDescription> *printers, const QString &name,
QString host, QString comment,
QStringList aliases = QStringList());
void qt_parsePrinterDesc(QString printerDesc, QList<QPrinterDescription> *printers);
int qt_parsePrintcap(QList<QPrinterDescription> *printers, const QString& fileName);
QString qt_getDefaultFromHomePrinters();
void qt_parseEtcLpPrinters(QList<QPrinterDescription> *printers);
char *qt_parsePrintersConf(QList<QPrinterDescription> *printers, bool *found = 0);
#ifndef QT_NO_NIS
#if defined(Q_C_CALLBACKS)
extern "C" {
#endif
int qt_pd_foreach(int /*status */, char * /*key */, int /*keyLen */,
char *val, int valLen, char *data);
#if defined(Q_C_CALLBACKS)
}
#endif
int qt_retrieveNisPrinters(QList<QPrinterDescription> *printers);
#endif // QT_NO_NIS
char *qt_parseNsswitchPrintersEntry(QList<QPrinterDescription> *printers, char *line);
char *qt_parseNsswitchConf(QList<QPrinterDescription> *printers);
void qt_parseEtcLpMember(QList<QPrinterDescription> *printers);
void qt_parseSpoolInterface(QList<QPrinterDescription> *printers);
void qt_parseQconfig(QList<QPrinterDescription> *printers);
int qt_getLprPrinters(QList<QPrinterDescription>& printers);
#endif // QT_NO_PRINTER
QT_END_NAMESPACE