⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qprintdialog_unix.cpp

📁 qt-x11-opensource-src-4.1.4.tar.gz源码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
            *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(':');            QString printerName, printerHost, printerComment;            QStringList aliases;            if (i >= 0) {                // have : want |                int j = printerDesc.indexOf('|');                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] != '=')                        i++;                    while (printerDesc[i] == '=' || printerDesc[i].isSpace())                        i++;                    j = i;                    while (j < (int)printerDesc.length() &&                            printerDesc[j] != ':' && printerDesc[j] != ',')                        j++;                    // that's our default printer                    defaultPrinter =                        qstrdup(printerDesc.mid(i, j-i).toAscii().data());                    printerName = "";                    printerDesc = "";                } else if (printerName == QLatin1String("_all")) {                    // skip it.. any other cases we want to skip?                    printerName = "";                    printerDesc = "";                }                if (j > 0) {                    // try extracting a comment from the aliases                    aliases = printerDesc.mid(j + 1, i - j - 1).split('|');                    printerComment = QPrintDialog::tr("Aliases: %1")                                     .arg(aliases.join(", "));                }                // 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] != '=')                        i++;                    while (printerDesc[i] == '=' || printerDesc[i].isSpace())                        i++;                    j = i;                    while (j < (int)printerDesc.length() &&                            printerDesc[j] != ':' && printerDesc[j] != ',')                        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] == ',') {                        i = ++j;                        while (printerDesc[i].isSpace())                            i++;                        j = i;                        while (j < (int)printerDesc.length() &&                                printerDesc[j] != ':' && printerDesc[j] != ',')                            j++;                        if (printerName != printerDesc.mid(i, j-i)) {                            printerComment =                                QLatin1String("Remote name: ");                            printerComment += printerDesc.mid(i, j-i);                        }                    }                }            }            if (printerComment == ":")                printerComment = ""; // for cups            if (printerName.length())                perhapsAddPrinter(printers, printerName, printerHost,                                   printerComment, aliases);            // chop away the line, for processing the next one            printerDesc = "";        }    }    delete[] line;    return defaultPrinter;}#ifndef QT_NO_NIS#if defined(Q_C_CALLBACKS)extern "C" {#endifstatic int pd_foreach(int /*status */, char * /*key */, int /*keyLen */,                    char *val, int valLen, char *data){    parsePrinterDesc(QString::fromLatin1(val, valLen), (QList<QPrinterDescription> *)data);    return 0;}#if defined(Q_C_CALLBACKS)}#endifstatic int retrieveNisPrinters(QList<QPrinterDescription> *printers){    typedef int (*WildCast)(int, char *, int, char *, int, char *);    char printersConfByname[] = "printers.conf.byname";    char *domain;    int err;    QLibrary lib("nsl");    typedef int (*ypGetDefaultDomain)(char **);    ypGetDefaultDomain _ypGetDefaultDomain = (ypGetDefaultDomain)lib.resolve("yp_get_default_domain");    typedef int (*ypAll)(const char *, const char *, const struct ypall_callback *);    ypAll _ypAll = (ypAll)lib.resolve("yp_all");    if (_ypGetDefaultDomain && _ypAll) {        err = _ypGetDefaultDomain(&domain);        if (err == 0) {            ypall_callback cb;            // wild cast to support K&R-style system headers            (WildCast &) cb.foreach = (WildCast) pd_foreach;            cb.data = (char *) printers;            err = _ypAll(domain, printersConfByname, &cb);        }        if (!err)            return Success;    }    return Unavail;}#endif // QT_NO_NISstatic char *parseNsswitchPrintersEntry(QList<QPrinterDescription> *printers, char *line){#define skipSpaces() \    while (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 (!isspace((uchar) line[k]) && line[k] != '[') {                source += line[k];                k++;            }            if (source == "user") {                lastStatus = parsePrintcap(printers,                        QDir::homePath() + "/.printers");            } else if (source == "files") {                bool found;                defaultPrinter = parsePrintersConf(printers, &found);                if (found)                    lastStatus = Success;#ifndef QT_NO_NIS            } else if (source == "nis") {                lastStatus = retrieveNisPrinters(printers);#endif            } else {                // nisplus, dns, etc., are not implemented yet                lastStatus = NotFound;            }            stop = (lastStatus == Success);        }    }    return defaultPrinter;}static char *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 (strncmp(line, "printers", 8) == 0) {            defaultPrinter = parseNsswitchPrintersEntry(printers, line);            delete[] line;            return defaultPrinter;        }    }    strcpy(line, "printers: user files nis nisplus xfn");    defaultPrinter = parseNsswitchPrintersEntry(printers, line);    delete[] line;    return defaultPrinter;}// HP-UXstatic void parseEtcLpMember(QList<QPrinterDescription> *printers){    QDir lp(QLatin1String("/etc/lp/member"));    if (!lp.exists())        return;    QFileInfoList dirs = lp.entryInfoList();    if (dirs.isEmpty())        return;    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())            perhapsAddPrinter(printers, printer.fileName(),                               QPrintDialog::tr("unknown"),                               QLatin1String(""));    }}// IRIX 6.xstatic void 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 = line;            if (uline.startsWith(typeKey) ) {                printerType = line.mid(nameKey.length());                printerType = printerType.simplified();            } else if (uline.startsWith(hostKey)) {                hostName = line.mid(hostKey.length());                hostName = hostName.simplified();            } else if (uline.startsWith(hostPrinterKey)) {                hostPrinter = line.mid(hostPrinterKey.length());                hostPrinter = hostPrinter.simplified();            } else if (uline.startsWith(nameKey)) {                namePrinter = line.mid(nameKey.length());                namePrinter = namePrinter.simplified();            }        }        configFile.close();        printerType = printerType.trimmed();        if (printerType.indexOf("postscript", 0, Qt::CaseInsensitive) < 0)            continue;        int ii = 0;        while ((ii = namePrinter.indexOf('"', ii)) >= 0)            namePrinter.remove(ii, 1);        if (hostName.isEmpty() || hostPrinter.isEmpty()) {            perhapsAddPrinter(printers, printer.fileName(),                               QLatin1String(""), namePrinter);        } else {            QString comment;            comment = namePrinter;            comment += " (";            comment += hostPrinter;            comment += ")";            perhapsAddPrinter(printers, printer.fileName(),                               hostName, comment);        }    }}// Every unix must have its own.  It's a standard.  Here is AIX.static void 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('=');        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] == '*') { // 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                    perhapsAddPrinter(printers, stanzaName, remoteHost,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -