tdeprint
kmwippselect.cpp
00001
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 <tdelistbox.h>
00027 #include <tqlayout.h>
00028 #include <tdelocale.h>
00029 #include <kdebug.h>
00030 #include <kiconloader.h>
00031
00032 #include "config.h"
00033
00034 KMWIppSelect::KMWIppSelect(TQWidget *parent, const char *name)
00035 : KMWizardPage(parent,name)
00036 {
00037 m_ID = KMWizard::IPPSelect;
00038 m_title = i18n("Remote IPP Printer Selection");
00039 m_nextpage = KMWizard::Driver;
00040
00041 m_list = new TDEListBox(this);
00042
00043 TQVBoxLayout *lay = new TQVBoxLayout(this, 0, 0);
00044 lay->addWidget(m_list);
00045 }
00046
00047 bool KMWIppSelect::isValid(TQString& msg)
00048 {
00049 if (m_list->currentItem() == -1)
00050 {
00051 msg = i18n("You must select a printer.");
00052 return false;
00053 }
00054 return true;
00055 }
00056
00057 void KMWIppSelect::initPrinter(KMPrinter *p)
00058 {
00059
00060 TQString host, login, password;
00061 int port;
00062
00063
00064 host = CupsInfos::self()->host();
00065 login = CupsInfos::self()->login();
00066 password = CupsInfos::self()->password();
00067 port = CupsInfos::self()->port();
00068
00069 m_list->clear();
00070
00071
00072 KURL url = p->device();
00073 CupsInfos::self()->setHost(url.host());
00074 CupsInfos::self()->setLogin(url.user());
00075 CupsInfos::self()->setPassword(url.pass());
00076 CupsInfos::self()->setPort(url.port());
00077 IppRequest req;
00078 TQString uri;
00079 req.setOperation(CUPS_GET_PRINTERS);
00080 uri = TQString::fromLatin1("ipp://%1/printers/").arg(CupsInfos::self()->hostaddr());
00081 req.addURI(IPP_TAG_OPERATION,"printer-uri",uri);
00082 req.addKeyword(IPP_TAG_OPERATION,"requested-attributes",TQString::fromLatin1("printer-name"));
00083 if (req.doRequest("/printers/"))
00084 {
00085 ipp_attribute_t *attr = req.first();
00086 while (attr)
00087 {
00088 #ifdef HAVE_CUPS_1_6
00089 if (ippGetName(attr) && strcmp(ippGetName(attr),"printer-name") == 0)
00090 m_list->insertItem(SmallIcon("tdeprint_printer"),TQString::fromLatin1(ippGetString(attr, 0, NULL)));
00091 attr = ippNextAttribute(req.request());
00092 #else // HAVE_CUPS_1_6
00093 if (attr->name && strcmp(attr->name,"printer-name") == 0)
00094 m_list->insertItem(SmallIcon("tdeprint_printer"),TQString::fromLatin1(attr->values[0].string.text));
00095 attr = attr->next;
00096 #endif // HAVE_CUPS_1_6
00097 }
00098 m_list->sort();
00099 }
00100
00101
00102 CupsInfos::self()->setHost(host);
00103 CupsInfos::self()->setLogin(login);
00104 CupsInfos::self()->setPassword(password);
00105 CupsInfos::self()->setPort(port);
00106 }
00107
00108 void KMWIppSelect::updatePrinter(KMPrinter *p)
00109 {
00110 KURL url = p->device();
00111 TQString path = m_list->currentText();
00112 path.prepend("/printers/");
00113 url.setPath(path);
00114 p->setDevice(url.url());
00115 kdDebug(500) << url.url() << endl;
00116 }