• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kdeprint
 

kdeprint

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., 51 Franklin Street, Fifth Floor,
00017  *  Boston, MA 02110-1301, 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 <tqlayout.h>
00028 #include <klocale.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 KListBox(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     // storage variables
00060     TQString    host, login, password;
00061     int port;
00062 
00063     // save config
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     // retrieve printer list
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("kdeprint_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("kdeprint_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     // restore config
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 }

kdeprint

Skip menu "kdeprint"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

kdeprint

Skip menu "kdeprint"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kdeprint by doxygen 1.7.6.1
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |