52 #if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY) 53 # include <private/qcups_p.h> 54 # include <cups/cups.h> 55 # include <private/qpdf_p.h> 58 #include <private/qprinterinfo_unix_p.h> 64 #if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY) 129 for (
int i = 0; i < printers->
size(); ++i)
133 #ifndef QT_NO_PRINTDIALOG 142 if (printerDesc.
length() < 1)
147 QString printerName, printerComment, printerHost;
153 if (j > 0 && j < i) {
154 printerName = printerDesc.
left(j);
156 #ifndef QT_NO_PRINTDIALOG 162 printerName = printerDesc.
left(i);
174 while (printerDesc[i] ==
QLatin1Char(
'=') || printerDesc[i].isSpace())
181 printerHost = printerDesc.
mid(i, j - i);
191 QFile printcap(fileName);
195 char *line_ascii =
new char[1025];
196 line_ascii[1024] =
'\0';
202 if (printcap.
atEnd() || printcap.
readLine(line_ascii, 1024) <= 0)
246 if (i != -1 && i < words.
size() - 1)
247 return words.
at(i + 1);
260 for (
int i = 0; i < dirs.
size(); ++i) {
262 if (printer.
isDir()) {
263 tmp.
sprintf(
"/etc/lp/printers/%s/configuration",
265 QFile configuration(tmp);
266 char *line =
new char[1025];
270 bool canPrintPostscript =
false;
272 while (!configuration.
atEnd() &&
273 configuration.
readLine(line, 1024) > 0) {
275 const char *p = line;
279 while (isspace((
uchar) *p))
290 while (isspace((
uchar) *p))
295 while (isalnum((
uchar) *e))
299 if (!
qstrcmp(p,
"postscript") ||
301 canPrintPostscript =
true;
310 if (canPrintPostscript)
331 char *line =
new char[1025];
337 char *defaultPrinter = 0;
339 while (!pc.
atEnd() &&
340 (lineLength=pc.
readLine(line, 1024)) > 0) {
345 if (lineLength >= 2 && line[lineLength-2] ==
'\\') {
346 line[lineLength-2] =
'\0';
352 QString printerName, printerHost, printerComment;
359 printerName = printerDesc.
mid(0, j < 0 ? i : j);
365 while (printerDesc[i] ==
QLatin1Char(
'=') || printerDesc[i].isSpace())
368 while (j < (
int)printerDesc.
length() &&
385 #ifndef QT_NO_PRINTDIALOG 397 while (printerDesc[i] ==
QLatin1Char(
'=') || printerDesc[i].isSpace())
400 while (j < (
int)printerDesc.
length() &&
404 printerHost = printerDesc.
mid(i, j-i);
408 while (printerDesc[i].isSpace())
411 while (j < (
int)printerDesc.
length() &&
414 if (printerName != printerDesc.
mid(i, j-i)) {
417 printerComment += printerDesc.
mid(i, j-i);
426 printerComment, aliases);
432 return defaultPrinter;
437 #if defined(Q_C_CALLBACKS) 442 char *val,
int valLen,
char *
data)
448 #if defined(Q_C_CALLBACKS) 454 #ifndef QT_NO_LIBRARY 455 typedef int (*WildCast)(int,
char *, int,
char *, int,
char *);
456 char printersConfByname[] =
"printers.conf.byname";
461 typedef int (*ypGetDefaultDomain)(
char **);
462 ypGetDefaultDomain _ypGetDefaultDomain = (ypGetDefaultDomain)lib.
resolve(
"yp_get_default_domain");
463 typedef int (*ypAll)(
const char *,
const char *,
const struct ypall_callback *);
464 ypAll _ypAll = (ypAll)lib.
resolve(
"yp_all");
466 if (_ypGetDefaultDomain && _ypAll) {
467 err = _ypGetDefaultDomain(&domain);
472 cb.data = (
char *) printers;
473 err = _ypAll(domain, printersConfByname, &cb);
478 #endif //QT_NO_LIBRARY 486 #define skipSpaces() \ 487 while (line[k] != '\0' && isspace((uchar) line[k])) \ 490 char *defaultPrinter = 0;
500 char *cp = strchr(line,
'#');
504 while (line[k] !=
'\0') {
505 if (isspace((
uchar) line[k])) {
507 }
else if (line[k] ==
'[') {
510 while (line[k] !=
'\0') {
511 char status = tolower(line[k]);
514 while (line[k] !=
'=' && line[k] !=
']' && line[k] !=
'\0')
516 if (line[k] ==
'=') {
519 action = tolower(line[k]);
520 while (line[k] !=
'\0' && !isspace((
uchar) line[k]) && line[k] !=
']')
522 }
else if (line[k] ==
']') {
528 if (lastStatus == status)
529 stop = (action == (char)
Return);
536 while (line[k] !=
'\0' && !isspace((
uchar) line[k]) && line[k] !=
'[') {
541 if (source ==
"user") {
544 }
else if (source ==
"files") {
550 }
else if (source ==
"nis") {
557 stop = (lastStatus ==
Success);
560 return defaultPrinter;
569 char *defaultPrinter = 0;
571 char *line =
new char[1025];
574 while (!nc.
atEnd() &&
576 if (
qstrncmp(line,
"printers", 8) == 0) {
579 return defaultPrinter;
583 strcpy(line,
"printers: user files nis nisplus xfn");
586 return defaultPrinter;
599 #ifdef QT_NO_PRINTDIALOG 603 for (
int i = 0; i < dirs.
size(); ++i) {
627 for (
int i = 0; i < files.
size(); ++i) {
650 while (!configFile.atEnd() &&
651 (configFile.readLine(line.
data(), 1024)) > 0) {
654 printerType = uline.
mid(nameKey.
length());
659 }
else if (uline.
startsWith(hostPrinterKey)) {
660 hostPrinter = uline.
mid(hostPrinterKey.
length());
663 namePrinter = uline.
mid(nameKey.
length());
669 printerType = printerType.
trimmed();
675 namePrinter.
remove(ii, 1);
682 comment = namePrinter;
684 comment += hostPrinter;
720 bool indented = line[0].isSpace();
724 if (indented && i != -1) {
735 }
else if (ts.
atEnd() ||
736 (!indented && line.
contains(newStanza))) {
737 if (up && stanzaName.
length() > 0 && stanzaName.
length() < 21) {
741 else if (deviceName.
length())
754 }
while (!ts.
atEnd());
771 etcLpDefault.
resize(1025);
807 #ifndef QT_NO_PRINTDIALOG 820 for (
int i = 0; i < printers.
size(); ++i) {
823 if (quality < 5 && name == dollarPrinter) {
826 }
else if (quality < 4 && !homePrintersDefault.
isEmpty() &&
827 name == homePrintersDefault) {
830 }
else if (quality < 3 && !etcLpDefault.
isEmpty() &&
834 }
else if (quality < 2 &&
839 }
else if (quality < 1 &&
857 #if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY) 862 for (
int i = 0; i < cupsPrinterCount; ++i) {
864 if (cupsPrinters[i].instance)
868 if (cupsPrinters[i].is_default)
870 printerInfo.
d_ptr->cupsPrinterIndex = i;
871 printers.
append(printerInfo);
881 if (defprn >= 0 && defprn < printers.
size())
882 printers[defprn].d_ptr->isDefault =
true;
896 return printers.
value(0);
901 #if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY) 905 return d->paperSizes;
907 if (!
d->hasPaperSizes) {
908 d->hasPaperSizes =
true;
914 const ppd_option_t* sizes = cups.
pageSizes();
916 for (
int j = 0; j < sizes->num_choices; ++j)
922 return d->paperSizes;
928 #endif // QT_NO_PRINTER void qt_parseEtcLpMember(QList< QPrinterDescription > *printers)
The QDir class provides access to directory structures and their contents.
QBool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
static QPrinterInfo defaultPrinter()
Returns the default printer on the system.
QString & sprintf(const char *format,...)
Safely builds a formatted string from the format string cformat and an arbitrary list of arguments...
static QString fromLocal8Bit(const char *, int size=-1)
Returns a QString initialized with the first size characters of the 8-bit string str.
QList< QPrinter::PaperSize > supportedPaperSizes() const
Returns a list of supported paper sizes by the printer.
QString cap(int nth=0) const
Returns the text captured by the nth subexpression.
#define QT_END_NAMESPACE
This macro expands to.
int availablePrintersCount() const
QString readLine(qint64 maxlen=0)
Reads one line of text from the stream, and returns it as a QString.
char * data()
Returns a pointer to the data stored in the byte array.
The QRegExp class provides pattern matching using regular expressions.
int qt_pd_foreach(int, char *, int, char *val, int valLen, char *data)
bool open(OpenMode flags)
Opens the file using OpenMode mode, returning true if successful; otherwise false.
QString qt_getDefaultFromHomePrinters()
Checks $HOME/.
int qt_retrieveNisPrinters(QList< QPrinterDescription > *printers)
The QByteArray class provides an array of bytes.
void chop(int n)
Removes n characters from the end of the string.
int length() const
Returns the number of characters in this string.
QString fileName() const
Returns the name of the file, excluding the path.
void qt_parseSpoolInterface(QList< QPrinterDescription > *printers)
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
static LibLoadStatus status
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
Q_OUTOFLINE_TEMPLATE RandomAccessIterator qBinaryFind(RandomAccessIterator begin, RandomAccessIterator end, const T &value)
void * resolve(const char *symbol)
Returns the address of the exported symbol symbol.
The QString class provides a Unicode character string.
char * qt_parseNsswitchConf(QList< QPrinterDescription > *printers)
const cups_dest_t * availablePrinters() const
static bool isAvailable()
bool exists() const
Returns true if the directory exists; otherwise returns false.
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
void append(const T &t)
Inserts value at the end of the list.
int indexOf(const QRegExp &rx, int from=0) const
Returns the index position of the first exact match of rx in the list, searching forward from index p...
#define QT_BEGIN_NAMESPACE
This macro expands to.
const ppd_option_t * pageSizes() const
int indexIn(const QString &str, int offset=0, CaretMode caretMode=CaretAtZero) const
Attempts to find a match in str from position offset (0 by default).
bool isDir() const
Returns true if this object points to a directory or to a symbolic link to a directory; otherwise ret...
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
QString trimmed() const Q_REQUIRED_RESULT
Returns a string that has whitespace removed from the start and the end.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
int qt_getLprPrinters(QList< QPrinterDescription > &printers)
const T & at(int i) const
Returns the item at index position i in the list.
The QStringList class provides a list of strings.
void setFile(const QString &file)
Sets the file that the QFileInfo provides information about to file.
static const char * data(const QByteArray &arr)
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
QFileInfoList entryInfoList(Filters filters=NoFilter, SortFlags sort=NoSort) const
Returns a list of QFileInfo objects for all the files and directories in the directory, ordered according to the name and attribute filters previously set with setNameFilters() and setFilter(), and sorted according to the flags set with setSorting().
T value(int i) const
Returns the value at index position i in the list.
static const struct NamedPaperSize named_sizes_map[QPrinter::NPageSize]
void qt_parseEtcLpPrinters(QList< QPrinterDescription > *printers)
void qt_parsePrinterDesc(QString printerDesc, QList< QPrinterDescription > *printers)
bool isDefault() const
Returns whether this printer is the default printer.
The QPrinterInfo class gives access to information about existing printers.
QString join(const QString &sep) const
Joins all the string list's strings into a single string with each element separated by the given sep...
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
The QFile class provides an interface for reading from and writing to files.
const ppd_file_t * setCurrentPrinter(int index)
The QTextStream class provides a convenient interface for reading and writing text.
qint64 readLine(char *data, qint64 maxlen)
This function reads a line of ASCII characters from the device, up to a maximum of maxSize - 1 bytes...
QString simplified() const Q_REQUIRED_RESULT
Returns a string that has whitespace removed from the start and the end, and that has each sequence o...
void clear()
Clears the contents of the string and makes it empty.
Q_CORE_EXPORT char * qstrdup(const char *)
QScopedPointer< QPrinterInfoPrivate, QPrinterInfoPrivateDeleter > d_ptr
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
PaperSize
This enum type specifies what paper size QPrinter should use.
QString toLower() const Q_REQUIRED_RESULT
Returns a lowercase copy of the string.
void resize(int size)
Sets the size of the byte array to size bytes.
int size() const
Returns the number of items in the list.
QByteArray toAscii() const Q_REQUIRED_RESULT
Returns an 8-bit representation of the string as a QByteArray.
int qstrncmp(const char *str1, const char *str2, uint len)
static QList< QPrinterInfo > availablePrinters()
Returns a list of available printers on the system.
bool isFile() const
Returns true if this object points to a file or to a symbolic link to a file.
QByteArray readAll()
Reads all available data from the device, and returns it as a QByteArray.
bool samePrinter(const QString &printer) const
void qt_perhapsAddPrinter(QList< QPrinterDescription > *printers, const QString &name, QString host, QString comment, QStringList aliases)
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
QStringList split(const QString &sep, SplitBehavior behavior=KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const Q_REQUIRED_RESULT
Splits the string into substrings wherever sep occurs, and returns the list of those strings...
int qstrcmp(const QByteArray &str1, const char *str2)
int qt_parsePrintcap(QList< QPrinterDescription > *printers, const QString &fileName)
bool atEnd() const
Returns true if there is no more data to be read from the QTextStream; otherwise returns false...
QString & remove(int i, int len)
Removes n characters from the string, starting at the given position index, and returns a reference t...
bool operator<(const char *name, const NamedPaperSize &data)
The QFileInfo class provides system-independent file information.
bool atEnd() const
Returns true if the end of the file has been reached; otherwise returns false.
char * qt_parseNsswitchPrintersEntry(QList< QPrinterDescription > *printers, char *line)
static QPrinter::PaperSize string2PaperSize(const char *name)
QString filePath() const
Returns the file name, including the path (which may be absolute or relative).
void qt_parseQconfig(QList< QPrinterDescription > *printers)
static const char * paperSize2String(QPrinter::PaperSize size)
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
static QString fileName(const QString &fileUrl)
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
static bool isNull(const QVariant::Private *d)
The QLibrary class loads shared libraries at runtime.
char * qt_parsePrintersConf(QList< QPrinterDescription > *printers, bool *found)
static QString homePath()
Returns the absolute path of the user's home directory.