diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/maingui/printergui.cpp | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/src/maingui/printergui.cpp b/src/maingui/printergui.cpp index bb6122f..528400e 100644 --- a/src/maingui/printergui.cpp +++ b/src/maingui/printergui.cpp @@ -114,17 +114,38 @@ void PrinterGui::initializeUI() // Fill treewidget with data from cups dests; cups_dest_t *dest = dests; - for (int i = num_dests; i>0; ++dest, --i ) + for (int i = num_dests; i > 0; ++dest, --i) { if (dest->instance == NULL) { + char uri[1000]; + ipp_t *req = ippNewRequest(IPP_OP_GET_PRINTER_ATTRIBUTES); + httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL, + "localhost", ippPort(), "/printers/%s", dest->name); + ippAddString(req, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", + NULL, uri); + ippAddString(req, IPP_TAG_OPERATION, IPP_TAG_NAME, + "requesting-user-name", + NULL, cupsUser()); + ipp_t *res = cupsDoRequest(CUPS_HTTP_DEFAULT, req, "/"); + ipp_attribute_t *attr = ippFindAttribute(res, "printer-location", IPP_TAG_TEXT); + const char *location = ""; + if (attr != NULL) { + location = ippGetString(attr, 0, NULL); + if (location == NULL) { + location = ""; + } + } QTreeWidgetItem *wi = new QTreeWidgetItem(); wi->setText(0, QString::fromUtf8(dest->name)); - wi->setText(1, QString::fromUtf8(cupsGetOption("printer-info", dest->num_options, dest->options))); - wi->setText(2, QString::fromUtf8(cupsGetOption("printer-location", dest->num_options, dest->options))); + wi->setText(1, QString::fromUtf8( + cupsGetOption("printer-info", dest->num_options, dest->options))); + wi->setText(2, QString::fromUtf8(location)); ui->printerList->addTopLevelItem(wi); if (dest->is_default) { ui->printerList->setCurrentItem(wi); } + ippDelete(res); } + } // Resize columns to contents for (int i = 0; i < 3; ++i) { @@ -240,7 +261,11 @@ void PrinterGui::on_printerList_currentItemChanged(QTreeWidgetItem *current, QTr { ui->printerList->setFocus(); - cups_dest_t *dest = cupsGetNamedDest(CUPS_HTTP_DEFAULT, current->text(0).toUtf8().constData(), NULL); + cups_dest_t *dest = cupsGetDest( + ui->printerList->currentItem()->text(0).toUtf8().constData(), + NULL, + num_dests, + dests); /* * Check printer properties (auth, color, duplex, copies) * */ |