kmwfax.cpp
00001 /* 00002 * This file is part of the KDE libraries 00003 * Copyright (c) 2001 Michael Goffioul <tdeprint@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 "kmwfax.h" 00021 #include "kmwizard.h" 00022 #include "kmprinter.h" 00023 #include "ipprequest.h" 00024 #include "cupsinfos.h" 00025 00026 #include <tqlabel.h> 00027 #include <tqlayout.h> 00028 #include <tdelistbox.h> 00029 #include <tdelocale.h> 00030 #include <kiconloader.h> 00031 #include <kurl.h> 00032 00033 #include "config.h" 00034 00035 KMWFax::KMWFax(TQWidget *parent, const char *name) 00036 : KMWizardPage(parent,name) 00037 { 00038 m_ID = KMWizard::Custom+2; 00039 m_title = i18n("Fax Serial Device"); 00040 m_nextpage = KMWizard::Driver; 00041 00042 TQLabel *lab = new TQLabel(this); 00043 lab->setText(i18n("<p>Select the device which your serial Fax/Modem is connected to.</p>")); 00044 m_list = new TDEListBox(this); 00045 00046 TQVBoxLayout *l1 = new TQVBoxLayout(this,0,10); 00047 l1->addWidget(lab,0); 00048 l1->addWidget(m_list,1); 00049 00050 // initialize 00051 IppRequest req; 00052 req.setOperation(CUPS_GET_DEVICES); 00053 TQString uri = TQString::fromLatin1("ipp://%1/printers/").arg(CupsInfos::self()->hostaddr()); 00054 req.addURI(IPP_TAG_OPERATION,"printer-uri",uri); 00055 if (req.doRequest("/")) 00056 { 00057 ipp_attribute_t *attr = req.first(); 00058 while (attr) 00059 { 00060 #ifdef HAVE_CUPS_1_6 00061 if (ippGetName(attr) && strcmp(ippGetName(attr),"device-uri") == 0 && strncmp(ippGetString(attr, 0, NULL),"fax",3) == 0) 00062 { 00063 m_list->insertItem(SmallIcon("blockdevice"),TQString::fromLatin1(ippGetString(attr, 0, NULL))); 00064 } 00065 attr = ippNextAttribute(req.request()); 00066 #else // HAVE_CUPS_1_6 00067 if (attr->name && strcmp(attr->name,"device-uri") == 0 && strncmp(attr->values[0].string.text,"fax",3) == 0) 00068 { 00069 m_list->insertItem(SmallIcon("blockdevice"),TQString::fromLatin1(attr->values[0].string.text)); 00070 } 00071 attr = attr->next; 00072 #endif // HAVE_CUPS_1_6 00073 } 00074 } 00075 } 00076 00077 bool KMWFax::isValid(TQString& msg) 00078 { 00079 if (m_list->currentItem() == -1) 00080 { 00081 msg = i18n("You must select a device."); 00082 return false; 00083 } 00084 return true; 00085 } 00086 00087 void KMWFax::updatePrinter(KMPrinter *printer) 00088 { 00089 TQString uri = m_list->currentText(); 00090 printer->setDevice(uri); 00091 }