kmcupsuimanager.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 "kmcupsuimanager.h" 00021 #include "kmpropertypage.h" 00022 #include "kmwizard.h" 00023 #include "kmconfigdialog.h" 00024 #include "kmwbackend.h" 00025 #include "kmfactory.h" 00026 #include "kprinter.h" 00027 00028 #include "kmpropbanners.h" 00029 #include "kmpropmembers.h" 00030 #include "kmpropbackend.h" 00031 #include "kmpropdriver.h" 00032 #include "kmwbanners.h" 00033 #include "kmwipp.h" 00034 #include "kmwippselect.h" 00035 #include "kmwippprinter.h" 00036 #include "kmconfigcups.h" 00037 #include "kmconfigcupsdir.h" 00038 #include "kmwfax.h" 00039 #include "kmwother.h" 00040 #include "kmwquota.h" 00041 #include "kmpropquota.h" 00042 #include "kmwusers.h" 00043 #include "kmpropusers.h" 00044 #include "kpschedulepage.h" 00045 #include "kptagspage.h" 00046 00047 #include "kprinterpropertydialog.h" 00048 #include "kpgeneralpage.h" 00049 #include "kpimagepage.h" 00050 #include "kptextpage.h" 00051 #include "kphpgl2page.h" 00052 00053 #include "ipprequest.h" 00054 #include "cupsinfos.h" 00055 00056 #include <qlistview.h> 00057 #include <qwhatsthis.h> 00058 #include <klocale.h> 00059 #include <kdebug.h> 00060 #include <kaction.h> 00061 #include <kmessagebox.h> 00062 00063 KMCupsUiManager::KMCupsUiManager(QObject *parent, const char *name, const QStringList & /*args*/) 00064 : KMUiManager(parent,name) 00065 { 00066 } 00067 00068 KMCupsUiManager::~KMCupsUiManager() 00069 { 00070 } 00071 00072 void KMCupsUiManager::setupPropertyPages(KMPropertyPage *p) 00073 { 00074 p->addPropPage(new KMPropMembers(p, "Members")); 00075 p->addPropPage(new KMPropBackend(p, "Backend")); 00076 p->addPropPage(new KMPropDriver(p, "Driver")); 00077 p->addPropPage(new KMPropBanners(p, "Banners")); 00078 p->addPropPage(new KMPropQuota(p, "Quotas")); 00079 p->addPropPage(new KMPropUsers(p, "Users")); 00080 } 00081 00082 void KMCupsUiManager::setupWizard(KMWizard *wizard) 00083 { 00084 QString whatsThisRemoteCUPSIPPBackend = 00085 i18n( "<qt><p>Print queue on remote CUPS server</p>" 00086 "<p>Use this for a print queue installed on a remote " 00087 "machine running a CUPS server. This allows to use " 00088 "remote printers when CUPS browsing is turned off.</p></qt>" 00089 ); 00090 00091 QString whatsThisRemotePrinterIPPBackend = 00092 i18n( "<qt><p>Network IPP printer</p>" 00093 "<p>Use this for a network-enabled printer using the " 00094 "IPP protocol. Modern high-end printers can use this mode. " 00095 "Use this mode instead of TCP if your printer can do both.</p></qt>" 00096 ); 00097 00098 QString whatsThisSerialFaxModemBackend = 00099 i18n( "<qt><p>Fax/Modem printer</p>" 00100 "<p>Use this for a fax/modem printer. This requires the installation " 00101 "of the <a href=\"http://vigna.dsi.unimi.it/fax4CUPS/\">fax4CUPS</a> backend. Documents sent on this printer will be faxed " 00102 "to the given target fax number.</p></qt>" 00103 ); 00104 00105 QString whatsThisOtherPrintertypeBackend = 00106 i18n( "<qt><p>Other printer</p>" 00107 "<p>Use this for any printer type. To use this option, you must know " 00108 "the URI of the printer you want to install. Refer to the CUPS documentation " 00109 "for more information about the printer URI. This option is mainly useful for " 00110 "printer types using 3rd party backends not covered by the other possibilities.</p></qt>" 00111 ); 00112 00113 QString whatsThisClassOfPrinters = 00114 i18n( "<qt><p>Class of printers</p>" 00115 "<p>Use this to create a class of printers. When sending a document to a class, " 00116 "the document is actually sent to the first available (idle) printer in the class. " 00117 "Refer to the CUPS documentation for more information about class of printers.</p></qt>" 00118 ); 00119 00120 KMWBackend *backend = wizard->backendPage(); 00121 if (!backend) 00122 return; 00123 backend->addBackend(KMWizard::Local,false); 00124 backend->addBackend(KMWizard::LPD,false); 00125 backend->addBackend(KMWizard::SMB,false,KMWizard::Password); 00126 backend->addBackend(KMWizard::TCP,false); 00127 backend->addBackend(KMWizard::IPP,i18n("Re&mote CUPS server (IPP/HTTP)"),false,whatsThisRemoteCUPSIPPBackend,KMWizard::Password); 00128 backend->addBackend(KMWizard::Custom+1,i18n("Network printer w/&IPP (IPP/HTTP)"),false,whatsThisRemotePrinterIPPBackend); 00129 backend->addBackend(KMWizard::Custom+2,i18n("S&erial Fax/Modem printer"),false,whatsThisSerialFaxModemBackend); 00130 backend->addBackend(KMWizard::Custom+5,i18n("Other &printer type"),false,whatsThisOtherPrintertypeBackend); 00131 backend->addBackend(); 00132 backend->addBackend(KMWizard::Class,i18n("Cl&ass of printers"),false,whatsThisClassOfPrinters); 00133 00134 IppRequest req; 00135 QString uri; 00136 00137 req.setOperation(CUPS_GET_DEVICES); 00138 uri = QString::fromLocal8Bit("ipp://%1/printers/").arg(CupsInfos::self()->hostaddr()); 00139 req.addURI(IPP_TAG_OPERATION,"printer-uri",uri); 00140 00141 if (req.doRequest("/")) 00142 { 00143 ipp_attribute_t *attr = req.first(); 00144 while (attr) 00145 { 00146 if (attr->name && strcmp(attr->name,"device-uri") == 0) 00147 { 00148 if (strncmp(attr->values[0].string.text,"socket",6) == 0) backend->enableBackend(KMWizard::TCP,true); 00149 else if (strncmp(attr->values[0].string.text,"parallel",8) == 0) backend->enableBackend(KMWizard::Local,true); 00150 else if (strncmp(attr->values[0].string.text,"serial",6) == 0) backend->enableBackend(KMWizard::Local,true); 00151 else if (strncmp(attr->values[0].string.text,"smb",3) == 0) backend->enableBackend(KMWizard::SMB,true); 00152 else if (strncmp(attr->values[0].string.text,"lpd",3) == 0) backend->enableBackend(KMWizard::LPD,true); 00153 else if (strncmp(attr->values[0].string.text,"usb",3) == 0) backend->enableBackend(KMWizard::Local,true); 00154 else if (strncmp(attr->values[0].string.text,"http",4) == 0 || strncmp(attr->values[0].string.text,"ipp",3) == 0) 00155 { 00156 backend->enableBackend(KMWizard::IPP,true); 00157 backend->enableBackend(KMWizard::Custom+1,true); 00158 } 00159 else if (strncmp(attr->values[0].string.text,"fax",3) == 0) backend->enableBackend(KMWizard::Custom+2,true); 00160 } 00161 attr = attr->next; 00162 } 00163 backend->enableBackend(KMWizard::Class, true); 00164 backend->enableBackend(KMWizard::Custom+5, true); 00165 } 00166 else 00167 KMessageBox::error(wizard, 00168 "<qt><nobr>" + 00169 i18n("An error occurred while retrieving the list of available backends:") + 00170 "</nobr><br><br>" + req.statusMessage() + "</qt>"); 00171 00172 // banners page 00173 wizard->addPage(new KMWBanners(wizard)); 00174 wizard->setNextPage(KMWizard::DriverTest,KMWizard::Banners); 00175 wizard->addPage(new KMWIpp(wizard)); 00176 wizard->addPage(new KMWIppSelect(wizard)); 00177 wizard->addPage(new KMWIppPrinter(wizard)); 00178 wizard->addPage(new KMWFax(wizard)); 00179 wizard->addPage(new KMWQuota(wizard)); 00180 wizard->addPage(new KMWUsers(wizard)); 00181 wizard->addPage(new KMWOther(wizard)); 00182 } 00183 00184 void KMCupsUiManager::setupPrinterPropertyDialog(KPrinterPropertyDialog *dlg) 00185 { 00186 // add general page 00187 dlg->addPage(new KPGeneralPage(dlg->printer(),dlg->driver(),dlg,"GeneralPage")); 00188 if (KMFactory::self()->settings()->application != KPrinter::Dialog) 00189 { 00190 dlg->addPage(new KPImagePage(dlg->driver(), dlg, "ImagePage")); 00191 dlg->addPage(new KPTextPage(dlg->driver(), dlg, "TextPage")); 00192 dlg->addPage(new KPHpgl2Page(dlg, "Hpgl2Page")); 00193 } 00194 } 00195 00196 void KMCupsUiManager::setupConfigDialog(KMConfigDialog *dlg) 00197 { 00198 dlg->addConfigPage(new KMConfigCups(dlg)); 00199 dlg->addConfigPage(new KMConfigCupsDir(dlg)); 00200 } 00201 00202 int KMCupsUiManager::pluginPageCap() 00203 { 00204 return (KMUiManager::CopyAll & ~KMUiManager::Current); 00205 } 00206 00207 void KMCupsUiManager::setupPrintDialogPages(QPtrList<KPrintDialogPage>* pages) 00208 { 00209 pages->append(new KPSchedulePage()); 00210 pages->append(new KPTagsPage()); 00211 } 00212 00213 void KMCupsUiManager::setupJobViewer(QListView *lv) 00214 { 00215 lv->addColumn(i18n("Priority")); 00216 lv->setColumnAlignment(lv->columns()-1, Qt::AlignRight|Qt::AlignVCenter); 00217 lv->addColumn(i18n("Billing Information")); 00218 lv->setColumnAlignment(lv->columns()-1, Qt::AlignRight|Qt::AlignVCenter); 00219 }