kdeprint Library API Documentation

kmwipp.cpp

00001 /*
00002  *  This file is part of the KDE libraries
00003  *  Copyright (c) 2001 Michael Goffioul <goffioul@imec.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 "kmwipp.h"
00021 #include "kmwizard.h"
00022 #include "kmprinter.h"
00023 
00024 #include <qlabel.h>
00025 #include <qlineedit.h>
00026 #include <klocale.h>
00027 
00028 #include <cups/http.h>
00029 
00030 KMWIpp::KMWIpp(QWidget *parent, const char *name)
00031 : KMWInfoBase(2,parent,name)
00032 {
00033     m_ID = KMWizard::IPP;
00034     m_title = i18n("Remote IPP server");
00035     m_nextpage = KMWizard::IPPSelect;
00036 
00037     setInfo(i18n("<p>Enter the information concerning the remote IPP server "
00038              "owning the targeted printer. This wizard will poll the server "
00039              "before continuing.</p>"));
00040     setLabel(0,i18n("Host:"));
00041     setLabel(1,i18n("Port:"));
00042 }
00043 
00044 bool KMWIpp::isValid(QString& msg)
00045 {
00046     // check informations
00047     if (text(0).isEmpty())
00048     {
00049         msg = i18n("Empty server name!");
00050         return false;
00051     }
00052     bool    ok(false);
00053     int p = text(1).toInt(&ok);
00054     if (!ok)
00055     {
00056         msg = i18n("Incorrect port number!");
00057         return false;
00058     }
00059 
00060     // check server
00061     http_t  *HTTP = httpConnect(text(0).latin1(),p);
00062     if (HTTP)
00063     {
00064         httpClose(HTTP);
00065         return true;
00066     }
00067     else
00068     {
00069         msg = i18n("<nobr>Unable to connect to <b>%1</b> on port <b>%2</b> !</nobr>").arg(text(0)).arg(p);
00070         return false;
00071     }
00072 }
00073 
00074 void KMWIpp::updatePrinter(KMPrinter *p)
00075 {
00076     KURL    url;
00077     url.setProtocol("ipp");
00078     url.setHost(text(0));
00079     url.setPort(text(1).toInt());
00080     if (!p->option("kde-login").isEmpty()) url.setUser(p->option("kde-login"));
00081     if (!p->option("kde-password").isEmpty()) url.setPass(p->option("kde-password"));
00082     p->setDevice(url.url());
00083 }
KDE Logo
This file is part of the documentation for kdeprint Library Version 3.2.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Feb 4 12:36:23 2004 by doxygen 1.2.18 written by Dimitri van Heesch, © 1997-2003