20 #include "kmwippselect.h"
22 #include "kmprinter.h"
23 #include "cupsinfos.h"
24 #include "ipprequest.h"
26 #include <tdelistbox.h>
28 #include <tdelocale.h>
30 #include <kiconloader.h>
34 KMWIppSelect::KMWIppSelect(TQWidget *parent,
const char *name)
35 : KMWizardPage(parent,name)
37 m_ID = KMWizard::IPPSelect;
38 m_title = i18n(
"Remote IPP Printer Selection");
39 m_nextpage = KMWizard::Driver;
41 m_list =
new TDEListBox(
this);
43 TQVBoxLayout *lay =
new TQVBoxLayout(
this, 0, 0);
44 lay->addWidget(m_list);
47 bool KMWIppSelect::isValid(TQString& msg)
49 if (m_list->currentItem() == -1)
51 msg = i18n(
"You must select a printer.");
57 void KMWIppSelect::initPrinter(KMPrinter *p)
60 TQString host, login, password;
64 host = CupsInfos::self()->host();
65 login = CupsInfos::self()->login();
66 password = CupsInfos::self()->password();
67 port = CupsInfos::self()->port();
72 KURL url = p->device();
73 CupsInfos::self()->setHost(url.host());
74 CupsInfos::self()->setLogin(url.user());
75 CupsInfos::self()->setPassword(url.pass());
76 CupsInfos::self()->setPort(url.port());
79 req.setOperation(CUPS_GET_PRINTERS);
80 uri = TQString::fromLatin1(
"ipp://%1/printers/").arg(CupsInfos::self()->hostaddr());
81 req.addURI(IPP_TAG_OPERATION,
"printer-uri",uri);
82 req.addKeyword(IPP_TAG_OPERATION,
"requested-attributes",TQString::fromLatin1(
"printer-name"));
83 if (req.doRequest(
"/printers/"))
85 ipp_attribute_t *attr = req.first();
89 if (ippGetName(attr) && strcmp(ippGetName(attr),
"printer-name") == 0)
90 m_list->insertItem(SmallIcon(
"tdeprint_printer"),TQString::fromLatin1(ippGetString(attr, 0, NULL)));
91 attr = ippNextAttribute(req.request());
93 if (attr->name && strcmp(attr->name,
"printer-name") == 0)
94 m_list->insertItem(SmallIcon(
"tdeprint_printer"),TQString::fromLatin1(attr->values[0].string.text));
102 CupsInfos::self()->setHost(host);
103 CupsInfos::self()->setLogin(login);
104 CupsInfos::self()->setPassword(password);
105 CupsInfos::self()->setPort(port);
108 void KMWIppSelect::updatePrinter(KMPrinter *p)
110 KURL url = p->device();
111 TQString path = m_list->currentText();
112 path.prepend(
"/printers/");
114 p->setDevice(url.url());
115 kdDebug(500) << url.url() << endl;