# kdeprint Library API Documentation

Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

# kmwippselect.cpp

    00001 /*
    00002  *  This file is part of the KDE libraries
    00003  *  Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
    00004  *
    00005  *  This library is free software; you can redistribute it and/or
    00006  *  modify it under the terms of the GNU Library General Public
    00007  *  License version 2 as published by the Free Software Foundation.
    00008  *
    00009  *  This library is distributed in the hope that it will be useful,
    00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00012  *  Library General Public License for more details.
    00013  *
    00014  *  You should have received a copy of the GNU Library General Public License
    00015  *  along with this library; see the file COPYING.LIB.  If not, write to
    00016  *  the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00017  *  Boston, MA 02111-1307, USA.
    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     // storage variables
    00058     QString host, login, password;
    00059     int port;
    00060
    00061     // save config
    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     // retrieve printer list
    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:%2/printers/").arg(url.host()).arg(url.port());
    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     // restore config
    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 }

This file is part of the documentation for kdeprint Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:31:03 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003