summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2017-01-11 16:17:41 +0100
committerSimon Rettberg2017-01-11 16:17:41 +0100
commitcf6187eb431055ea36e2af03a9c6c04707af391d (patch)
treeb9c7d9a3487e866a4c07941c3b387c389008422e
parent[maingui] Also set UseSecured and OptSecured if secure print is enabled (diff)
downloadprintergui-cf6187eb431055ea36e2af03a9c6c04707af391d.tar.gz
printergui-cf6187eb431055ea36e2af03a9c6c04707af391d.tar.xz
printergui-cf6187eb431055ea36e2af03a9c6c04707af391d.zip
[printergui] Fill location column by working around cups bug
CUPS docs say cupsGetDests should also fill in "printer-location" for all the printers, but in fact it doesn't. So query the printer attributes using ipp.
-rw-r--r--src/maingui/printergui.cpp33
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) * */