kmwippselect.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "kmwippselect.h"
00021 #include "kmwizard.h"
00022 #include "kmprinter.h"
00023 #include "cupsinfos.h"
00024 #include "ipprequest.h"
00025
00026 #include <klistbox.h>
00027 #include <qlayout.h>
00028 #include <klocale.h>
00029 #include <kdebug.h>
00030 #include <kiconloader.h>
00031
00032 KMWIppSelect::KMWIppSelect(QWidget *parent, const char *name)
00033 : KMWizardPage(parent,name)
00034 {
00035 m_ID = KMWizard::IPPSelect;
00036 m_title = i18n("Remote IPP Printer Selection");
00037 m_nextpage = KMWizard::Driver;
00038
00039 m_list = new KListBox(this);
00040
00041 QVBoxLayout *lay = new QVBoxLayout(this, 0, 0);
00042 lay->addWidget(m_list);
00043 }
00044
00045 bool KMWIppSelect::isValid(QString& msg)
00046 {
00047 if (m_list->currentItem() == -1)
00048 {
00049 msg = i18n("You must select a printer.");
00050 return false;
00051 }
00052 return true;
00053 }
00054
00055 void KMWIppSelect::initPrinter(KMPrinter *p)
00056 {
00057
00058 QString host, login, password;
00059 int port;
00060
00061
00062 host = CupsInfos::self()->host();
00063 login = CupsInfos::self()->login();
00064 password = CupsInfos::self()->password();
00065 port = CupsInfos::self()->port();
00066
00067 m_list->clear();
00068
00069
00070 KURL url = p->device();
00071 CupsInfos::self()->setHost(url.host());
00072 CupsInfos::self()->setLogin(url.user());
00073 CupsInfos::self()->setPassword(url.pass());
00074 CupsInfos::self()->setPort(url.port());
00075 IppRequest req;
00076 QString uri;
00077 req.setOperation(CUPS_GET_PRINTERS);
00078 uri = QString::fromLatin1("ipp://%1/printers/").arg(CupsInfos::self()->hostaddr());
00079 req.addURI(IPP_TAG_OPERATION,"printer-uri",uri);
00080 req.addKeyword(IPP_TAG_OPERATION,"requested-attributes",QString::fromLatin1("printer-name"));
00081 if (req.doRequest("/printers/"))
00082 {
00083 ipp_attribute_t *attr = req.first();
00084 while (attr)
00085 {
00086 if (attr->name && strcmp(attr->name,"printer-name") == 0)
00087 m_list->insertItem(SmallIcon("kdeprint_printer"),QString::fromLatin1(attr->values[0].string.text));
00088 attr = attr->next;
00089 }
00090 m_list->sort();
00091 }
00092
00093
00094 CupsInfos::self()->setHost(host);
00095 CupsInfos::self()->setLogin(login);
00096 CupsInfos::self()->setPassword(password);
00097 CupsInfos::self()->setPort(port);
00098 }
00099
00100 void KMWIppSelect::updatePrinter(KMPrinter *p)
00101 {
00102 KURL url = p->device();
00103 QString path = m_list->currentText();
00104 path.prepend("/printers/");
00105 url.setPath(path);
00106 p->setDevice(url.url());
00107 kdDebug(500) << url.url() << endl;
00108 }
|