Ejemplo n.º 1
0
QList<QPrinterInfo> QPrinterInfo::availablePrinters()
{
    QList<QPrinterInfo> printers;

    DWORD needed = 0;
    DWORD returned = 0;
    if (!EnumPrinters(PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS, NULL, 4, 0, 0, &needed, &returned)) {
        LPBYTE buffer = new BYTE[needed];
        if (EnumPrinters(PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS, NULL, 4, buffer, needed, &needed, &returned)) {
            PPRINTER_INFO_4 infoList = reinterpret_cast<PPRINTER_INFO_4>(buffer);
            QPrinterInfo defPrn = defaultPrinter();
            for (uint i = 0; i < returned; ++i) {
                QString printerName(QString::fromWCharArray(infoList[i].pPrinterName));

                QPrinterInfo printerInfo(printerName);
                if (printerInfo.printerName() == defPrn.printerName())
                    printerInfo.d_ptr->isDefault = true;
                printers.append(printerInfo);
            }
        }
        delete [] buffer;
    }

    return printers;
}
Ejemplo n.º 2
0
QList<QPrinterInfo> QPrinterInfo::availablePrinters()
{
    QList<QPrinterInfo> printers;

#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
    if (QCUPSSupport::isAvailable()) {
        QCUPSSupport cups;
        int cupsPrinterCount = cups.availablePrintersCount();
        const cups_dest_t* cupsPrinters = cups.availablePrinters();
        for (int i = 0; i < cupsPrinterCount; ++i) {
            QString printerName(QString::fromLocal8Bit(cupsPrinters[i].name));
            if (cupsPrinters[i].instance)
                printerName += QLatin1Char('/') + QString::fromLocal8Bit(cupsPrinters[i].instance);

            QPrinterInfo printerInfo(printerName);
            if (cupsPrinters[i].is_default)
                printerInfo.d_ptr->isDefault = true;
            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;
    }

    return printers;
}
Ejemplo n.º 3
0
QPrinterInfo QPrinterInfo::defaultPrinter()
{
    QString noPrinters(QLatin1String("qt_no_printers"));
    wchar_t buffer[256];
    GetProfileString(L"windows", L"device", (wchar_t*)noPrinters.utf16(), buffer, 256);
    QString output = QString::fromWCharArray(buffer);
    if (output != noPrinters) {
        // Filter out the name of the printer, which should be everything before a comma.
        QString printerName = output.split(QLatin1Char(',')).value(0);
        QPrinterInfo printerInfo(printerName);
        printerInfo.d_ptr->isDefault = true;
        return printerInfo;
    }

    return QPrinterInfo();
}