diff options
author | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2012-08-10 16:51:25 -0500 |
---|---|---|
committer | Slávek Banko <slavek.banko@axis.cz> | 2012-08-16 00:18:33 +0200 |
commit | 6fc204a0c45bb866ddab08baf83a1f50684250d4 (patch) | |
tree | 93a6fa4897c067cc89628591df7bc96aee2613fa /kdeprint/cups/kmcupsmanager.cpp | |
parent | 1eb94c672d7341deaee4fb09b31905e3a009c079 (diff) | |
download | tdelibs-6fc204a0c45bb866ddab08baf83a1f50684250d4.tar.gz tdelibs-6fc204a0c45bb866ddab08baf83a1f50684250d4.zip |
Update to new CUPS 1.6 API
(cherry picked from commit 9bc0d2cd9d38750658770e69bf0445dc5162beb7)
Diffstat (limited to 'kdeprint/cups/kmcupsmanager.cpp')
-rw-r--r-- | kdeprint/cups/kmcupsmanager.cpp | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/kdeprint/cups/kmcupsmanager.cpp b/kdeprint/cups/kmcupsmanager.cpp index 7a66a52a8..69f14bfd2 100644 --- a/kdeprint/cups/kmcupsmanager.cpp +++ b/kdeprint/cups/kmcupsmanager.cpp @@ -476,9 +476,59 @@ void KMCupsManager::loadServerPrinters() void KMCupsManager::processRequest(IppRequest* req) { ipp_attribute_t *attr = req->first(); + ipp_attribute_t *nextAttr; KMPrinter *printer = new KMPrinter(); while (attr) { +#ifdef HAVE_CUPS_1_6 + TQString attrname(ippGetName(attr)); + if (attrname == "printer-name") + { + TQString value = TQString::fromLocal8Bit(ippGetString(attr, 0, NULL)); + printer->setName(value); + printer->setPrinterName(value); + } + else if (attrname == "printer-type") + { + int value = ippGetInteger(attr, 0); + printer->setType(0); + printer->addType(((value & CUPS_PRINTER_CLASS) || (value & CUPS_PRINTER_IMPLICIT) ? KMPrinter::Class : KMPrinter::Printer)); + if ((value & CUPS_PRINTER_REMOTE)) printer->addType(KMPrinter::Remote); + if ((value & CUPS_PRINTER_IMPLICIT)) printer->addType(KMPrinter::Implicit); + + // convert printer-type attribute + printer->setPrinterCap( ( value & CUPS_PRINTER_OPTIONS ) >> 2 ); + } + else if (attrname == "printer-state") + { + switch (ippGetInteger(attr, 0)) + { + case IPP_PRINTER_IDLE: printer->setState(KMPrinter::Idle); break; + case IPP_PRINTER_PROCESSING: printer->setState(KMPrinter::Processing); break; + case IPP_PRINTER_STOPPED: printer->setState(KMPrinter::Stopped); break; + } + } + else if (attrname == "printer-uri-supported") + { + printer->setUri(KURL(ippGetString(attr, 0, NULL))); + } + else if (attrname == "printer-location") + { + printer->setLocation(TQString::fromLocal8Bit(ippGetString(attr, 0, NULL))); + } + else if (attrname == "printer-is-accepting-jobs") + { + printer->setAcceptJobs(ippGetBoolean(attr, 0)); + } + + nextAttr = ippNextAttribute(req->request()); + if (attrname.isEmpty() || (!nextAttr)) + { + addPrinter(printer); + printer = new KMPrinter(); + } + attr = nextAttr; +#else // HAVE_CUPS_1_6 TQString attrname(attr->name); if (attrname == "printer-name") { @@ -524,6 +574,7 @@ void KMCupsManager::processRequest(IppRequest* req) printer = new KMPrinter(); } attr = attr->next; +#endif // HAVE_CUPS_1_6 } delete printer; } @@ -817,6 +868,7 @@ TQStringList KMCupsManager::detectLocalPrinters() { TQStringList list; IppRequest req; + ipp_attribute_t *nextAttr; req.setOperation(CUPS_GET_DEVICES); if (req.doRequest("/")) { @@ -824,6 +876,24 @@ TQStringList KMCupsManager::detectLocalPrinters() ipp_attribute_t *attr = req.first(); while (attr) { +#ifdef HAVE_CUPS_1_6 + TQString attrname(ippGetName(attr)); + if (attrname == "device-info") desc = ippGetString(attr, 0, NULL); + else if (attrname == "device-make-and-model") printer = ippGetString(attr, 0, NULL); + else if (attrname == "device-uri") uri = ippGetString(attr, 0, NULL); + else if ( attrname == "device-class" ) cl = ippGetString(attr, 0, NULL); + nextAttr = ippNextAttribute(req.request()); + if (attrname.isEmpty() || (!nextAttr)) + { + if (!uri.isEmpty()) + { + if (printer == "Unknown") printer = TQString::null; + list << cl << uri << desc << printer; + } + uri = desc = printer = cl = TQString::null; + } + attr = nextAttr; +#else // HAVE_CUPS_1_6 TQString attrname(attr->name); if (attrname == "device-info") desc = attr->values[0].string.text; else if (attrname == "device-make-and-model") printer = attr->values[0].string.text; @@ -839,6 +909,7 @@ TQStringList KMCupsManager::detectLocalPrinters() uri = desc = printer = cl = TQString::null; } attr = attr->next; +#endif // HAVE_CUPS_1_6 } } return list; |