00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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 <tqlistview.h>
00057 #include <tqwhatsthis.h>
00058 #include <tdelocale.h>
00059 #include <kdebug.h>
00060 #include <tdeaction.h>
00061 #include <tdemessagebox.h>
00062
00063 #include "config.h"
00064
00065 KMCupsUiManager::KMCupsUiManager(TQObject *parent, const char *name, const TQStringList & )
00066 : KMUiManager(parent,name)
00067 {
00068 }
00069
00070 KMCupsUiManager::~KMCupsUiManager()
00071 {
00072 }
00073
00074 void KMCupsUiManager::setupPropertyPages(KMPropertyPage *p)
00075 {
00076 p->addPropPage(new KMPropMembers(p, "Members"));
00077 p->addPropPage(new KMPropBackend(p, "Backend"));
00078 p->addPropPage(new KMPropDriver(p, "Driver"));
00079 p->addPropPage(new KMPropBanners(p, "Banners"));
00080 p->addPropPage(new KMPropQuota(p, "Quotas"));
00081 p->addPropPage(new KMPropUsers(p, "Users"));
00082 }
00083
00084 void KMCupsUiManager::setupWizard(KMWizard *wizard)
00085 {
00086 TQString whatsThisRemoteCUPSIPPBackend =
00087 i18n( "<qt><p>Print queue on remote CUPS server</p>"
00088 "<p>Use this for a print queue installed on a remote "
00089 "machine running a CUPS server. This allows to use "
00090 "remote printers when CUPS browsing is turned off.</p></qt>"
00091 );
00092
00093 TQString whatsThisRemotePrinterIPPBackend =
00094 i18n( "<qt><p>Network IPP printer</p>"
00095 "<p>Use this for a network-enabled printer using the "
00096 "IPP protocol. Modern high-end printers can use this mode. "
00097 "Use this mode instead of TCP if your printer can do both.</p></qt>"
00098 );
00099
00100 TQString whatsThisSerialFaxModemBackend =
00101 i18n( "<qt><p>Fax/Modem printer</p>"
00102 "<p>Use this for a fax/modem printer. This requires the installation "
00103 "of the <a href=\"http://vigna.dsi.unimi.it/fax4CUPS/\">fax4CUPS</a> backend. Documents sent on this printer will be faxed "
00104 "to the given target fax number.</p></qt>"
00105 );
00106
00107 TQString whatsThisOtherPrintertypeBackend =
00108 i18n( "<qt><p>Other printer</p>"
00109 "<p>Use this for any printer type. To use this option, you must know "
00110 "the URI of the printer you want to install. Refer to the CUPS documentation "
00111 "for more information about the printer URI. This option is mainly useful for "
00112 "printer types using 3rd party backends not covered by the other possibilities.</p></qt>"
00113 );
00114
00115 TQString whatsThisClassOfPrinters =
00116 i18n( "<qt><p>Class of printers</p>"
00117 "<p>Use this to create a class of printers. When sending a document to a class, "
00118 "the document is actually sent to the first available (idle) printer in the class. "
00119 "Refer to the CUPS documentation for more information about class of printers.</p></qt>"
00120 );
00121
00122 KMWBackend *backend = wizard->backendPage();
00123 if (!backend)
00124 return;
00125 backend->addBackend(KMWizard::Local,false);
00126 backend->addBackend(KMWizard::LPD,false);
00127 backend->addBackend(KMWizard::SMB,false,KMWizard::Password);
00128 backend->addBackend(KMWizard::TCP,false);
00129 backend->addBackend(KMWizard::IPP,i18n("Re&mote CUPS server (IPP/HTTP)"),false,whatsThisRemoteCUPSIPPBackend,KMWizard::Password);
00130 backend->addBackend(KMWizard::Custom+1,i18n("Network printer w/&IPP (IPP/HTTP)"),false,whatsThisRemotePrinterIPPBackend);
00131 backend->addBackend(KMWizard::Custom+2,i18n("S&erial Fax/Modem printer"),false,whatsThisSerialFaxModemBackend);
00132 backend->addBackend(KMWizard::Custom+5,i18n("Other &printer type"),false,whatsThisOtherPrintertypeBackend);
00133 backend->addBackend();
00134 backend->addBackend(KMWizard::Class,i18n("Cl&ass of printers"),false,whatsThisClassOfPrinters);
00135
00136 IppRequest req;
00137 QString uri;
00138
00139 req.setOperation(CUPS_GET_DEVICES);
00140 uri = TQString::fromLocal8Bit("ipp://%1/printers/").arg(CupsInfos::self()->hostaddr());
00141 req.addURI(IPP_TAG_OPERATION,"printer-uri",uri);
00142
00143 if (req.doRequest("/"))
00144 {
00145 ipp_attribute_t *attr = req.first();
00146 while (attr)
00147 {
00148 #ifdef HAVE_CUPS_1_6
00149 if (ippGetName(attr) && strcmp(ippGetName(attr),"device-uri") == 0)
00150 {
00151 if (strncmp(ippGetString(attr, 0, NULL),"socket",6) == 0) backend->enableBackend(KMWizard::TCP,true);
00152 else if (strncmp(ippGetString(attr, 0, NULL),"parallel",8) == 0) backend->enableBackend(KMWizard::Local,true);
00153 else if (strncmp(ippGetString(attr, 0, NULL),"serial",6) == 0) backend->enableBackend(KMWizard::Local,true);
00154 else if (strncmp(ippGetString(attr, 0, NULL),"smb",3) == 0) backend->enableBackend(KMWizard::SMB,true);
00155 else if (strncmp(ippGetString(attr, 0, NULL),"lpd",3) == 0) backend->enableBackend(KMWizard::LPD,true);
00156 else if (strncmp(ippGetString(attr, 0, NULL),"usb",3) == 0) backend->enableBackend(KMWizard::Local,true);
00157 else if (strncmp(ippGetString(attr, 0, NULL),"http",4) == 0 || strncmp(ippGetString(attr, 0, NULL),"ipp",3) == 0)
00158 {
00159 backend->enableBackend(KMWizard::IPP,true);
00160 backend->enableBackend(KMWizard::Custom+1,true);
00161 }
00162 else if (strncmp(ippGetString(attr, 0, NULL),"fax",3) == 0) backend->enableBackend(KMWizard::Custom+2,true);
00163 }
00164 attr = ippNextAttribute(req.request());
00165 #else // HAVE_CUPS_1_6
00166 if (attr->name && strcmp(attr->name,"device-uri") == 0)
00167 {
00168 if (strncmp(attr->values[0].string.text,"socket",6) == 0) backend->enableBackend(KMWizard::TCP,true);
00169 else if (strncmp(attr->values[0].string.text,"parallel",8) == 0) backend->enableBackend(KMWizard::Local,true);
00170 else if (strncmp(attr->values[0].string.text,"serial",6) == 0) backend->enableBackend(KMWizard::Local,true);
00171 else if (strncmp(attr->values[0].string.text,"smb",3) == 0) backend->enableBackend(KMWizard::SMB,true);
00172 else if (strncmp(attr->values[0].string.text,"lpd",3) == 0) backend->enableBackend(KMWizard::LPD,true);
00173 else if (strncmp(attr->values[0].string.text,"usb",3) == 0) backend->enableBackend(KMWizard::Local,true);
00174 else if (strncmp(attr->values[0].string.text,"http",4) == 0 || strncmp(attr->values[0].string.text,"ipp",3) == 0)
00175 {
00176 backend->enableBackend(KMWizard::IPP,true);
00177 backend->enableBackend(KMWizard::Custom+1,true);
00178 }
00179 else if (strncmp(attr->values[0].string.text,"fax",3) == 0) backend->enableBackend(KMWizard::Custom+2,true);
00180 }
00181 attr = attr->next;
00182 #endif // HAVE_CUPS_1_6
00183 }
00184 backend->enableBackend(KMWizard::Class, true);
00185 backend->enableBackend(KMWizard::Custom+5, true);
00186 }
00187 else
00188 KMessageBox::error(wizard,
00189 "<qt><nobr>" +
00190 i18n("An error occurred while retrieving the list of available backends:") +
00191 "</nobr><br><br>" + req.statusMessage() + "</qt>");
00192
00193
00194 wizard->addPage(new KMWBanners(wizard));
00195 wizard->setNextPage(KMWizard::DriverTest,KMWizard::Banners);
00196 wizard->addPage(new KMWIpp(wizard));
00197 wizard->addPage(new KMWIppSelect(wizard));
00198 wizard->addPage(new KMWIppPrinter(wizard));
00199 wizard->addPage(new KMWFax(wizard));
00200 wizard->addPage(new KMWQuota(wizard));
00201 wizard->addPage(new KMWUsers(wizard));
00202 wizard->addPage(new KMWOther(wizard));
00203 }
00204
00205 void KMCupsUiManager::setupPrinterPropertyDialog(KPrinterPropertyDialog *dlg)
00206 {
00207
00208 dlg->addPage(new KPGeneralPage(dlg->printer(),dlg->driver(),dlg,"GeneralPage"));
00209 if (KMFactory::self()->settings()->application != KPrinter::Dialog)
00210 {
00211 dlg->addPage(new KPImagePage(dlg->driver(), dlg, "ImagePage"));
00212 dlg->addPage(new KPTextPage(dlg->driver(), dlg, "TextPage"));
00213 dlg->addPage(new KPHpgl2Page(dlg, "Hpgl2Page"));
00214 }
00215 }
00216
00217 void KMCupsUiManager::setupConfigDialog(KMConfigDialog *dlg)
00218 {
00219 dlg->addConfigPage(new KMConfigCups(dlg));
00220 dlg->addConfigPage(new KMConfigCupsDir(dlg));
00221 }
00222
00223 int KMCupsUiManager::pluginPageCap()
00224 {
00225 return (KMUiManager::CopyAll & ~KMUiManager::Current);
00226 }
00227
00228 void KMCupsUiManager::setupPrintDialogPages(TQPtrList<KPrintDialogPage>* pages)
00229 {
00230 pages->append(new KPSchedulePage());
00231 pages->append(new KPTagsPage());
00232 }
00233
00234 void KMCupsUiManager::setupJobViewer(TQListView *lv)
00235 {
00236 lv->addColumn(i18n("Priority"));
00237 lv->setColumnAlignment(lv->columns()-1, Qt::AlignRight|Qt::AlignVCenter);
00238 lv->addColumn(i18n("Billing Information"));
00239 lv->setColumnAlignment(lv->columns()-1, Qt::AlignRight|Qt::AlignVCenter);
00240 }