22 #include "kmcupsmanager.h"
23 #include "kmprinter.h"
24 #include "ipprequest.h"
25 #include "cupsinfos.h"
27 #include "kmfactory.h"
28 #include "kmdbentry.h"
29 #include "cupsaddsmb2.h"
30 #include "ippreportdlg.h"
31 #include "kpipeprocess.h"
33 #include "foomatic2loader.h"
34 #include "ppdloader.h"
37 #include <tqtextstream.h>
41 #include <tqdatetime.h>
44 #include <tdeapplication.h>
45 #include <tdelocale.h>
46 #include <tdeconfig.h>
47 #include <kstandarddirs.h>
48 #include <tdesocketbase.h>
49 #include <klibloader.h>
50 #include <tdemessagebox.h>
51 #include <tdeaction.h>
52 #include <kdialogbase.h>
53 #include <kextendedsocket.h>
55 #include <kbufferedsocket.h>
56 #include <kfilterdev.h>
57 #include <cups/cups.h>
61 #define ppdi18n(s) i18n(TQString::fromLocal8Bit(s).utf8())
63 static void extractMaticData(TQString& buf,
const TQString& filename);
64 static TQString printerURI(KMPrinter *p,
bool useExistingURI);
65 static TQString downloadDriver(KMPrinter *p);
67 static int trials = 5;
71 KMCupsManager::KMCupsManager(TQObject *parent,
const char *name,
const TQStringList & )
72 : KMManager(parent,name)
81 setHasManagement(
true);
82 setPrinterOperationMask(KMManager::PrinterAll);
83 setServerOperationMask(KMManager::ServerAll);
88 setenv(
"LANG",
"en_US.UTF-8", 1);
91 KMCupsManager::~KMCupsManager()
96 TQString KMCupsManager::driverDbCreationProgram()
98 return TQString(__TDE_BINDIR).append(TQString::fromLatin1(
"/make_driver_db_cups"));
101 TQString KMCupsManager::driverDirectory()
103 TQString d = cupsInstallDir();
105 #if defined(__OpenBSD__) || defined(__FreeBSD__)
111 d.append(
"/share/cups/model");
113 #if defined(__OpenBSD__) || defined(__FreeBSD__)
114 d.append(
":/usr/local/share/foomatic/db/source");
116 d.append(
":/usr/share/foomatic/db/source");
118 d.append(
":/usr/lib/cups/driver/foomatic-db-compressed-ppds");
123 TQString KMCupsManager::cupsInstallDir()
125 TDEConfig *conf= KMFactory::self()->printConfig();
126 conf->setGroup(
"CUPS");
127 TQString dir = conf->readPathEntry(
"InstallDir");
131 void KMCupsManager::reportIppError(IppRequest *req)
133 setErrorMsg(req->statusMessage());
136 bool KMCupsManager::createPrinter(KMPrinter *p)
138 bool isclass = p->isClass(
false), result(
false);
142 uri = printerURI(p,
false);
143 req.addURI(IPP_TAG_OPERATION,
"printer-uri",uri);
145 p->setUri(KURL(uri));
149 req.setOperation(CUPS_ADD_CLASS);
150 TQStringList members = p->members(), uris;
152 s = TQString::fromLocal8Bit(
"ipp://%1/printers/").arg(CupsInfos::self()->hostaddr());
153 for (TQStringList::ConstIterator it=members.begin(); it!=members.end(); ++it)
154 uris.append(s+(*it));
155 req.addURI(IPP_TAG_PRINTER,
"member-uris",uris);
159 req.setOperation(CUPS_ADD_PRINTER);
162 KMPrinter *otherP = findPrinter(p->printerName());
163 if (!otherP || otherP->device() != p->device())
170 req.addURI(IPP_TAG_PRINTER,
"device-uri",p->device());
172 if (!p->option(
"kde-banners").isEmpty())
174 TQStringList bans = TQStringList::split(
',',p->option(
"kde-banners"),
false);
175 while (bans.count() < 2)
177 req.addName(IPP_TAG_PRINTER,
"job-sheets-default",bans);
179 req.addInteger(IPP_TAG_PRINTER,
"job-quota-period",p->option(
"job-quota-period").toInt());
180 req.addInteger(IPP_TAG_PRINTER,
"job-k-limit",p->option(
"job-k-limit").toInt());
181 req.addInteger(IPP_TAG_PRINTER,
"job-page-limit",p->option(
"job-page-limit").toInt());
182 if (!p->option(
"requesting-user-name-denied").isEmpty())
183 req.addName(IPP_TAG_PRINTER,
"requesting-user-name-denied",TQStringList::split(
",",p->option(
"requesting-user-name-denied"),
false));
184 else if (!p->option(
"requesting-user-name-allowed").isEmpty())
185 req.addName(IPP_TAG_PRINTER,
"requesting-user-name-allowed",TQStringList::split(
",",p->option(
"requesting-user-name-allowed"),
false));
187 req.addName(IPP_TAG_PRINTER,
"requesting-user-name-allowed",TQString::fromLatin1(
"all"));
189 req.addText(IPP_TAG_PRINTER,
"printer-info",p->description());
190 req.addText(IPP_TAG_PRINTER,
"printer-location",p->location());
192 if (req.doRequest(
"/admin/"))
196 result = savePrinterDriver(p,p->driver());
200 else reportIppError(&req);
205 bool KMCupsManager::removePrinter(KMPrinter *p)
207 bool result = setPrinterState(p,CUPS_DELETE_PRINTER);
211 bool KMCupsManager::enablePrinter(KMPrinter *p,
bool state)
213 return setPrinterState(p, (state ? CUPS_ACCEPT_JOBS : CUPS_REJECT_JOBS));
216 bool KMCupsManager::startPrinter(KMPrinter *p,
bool state)
218 return setPrinterState(p, (state ? IPP_RESUME_PRINTER : IPP_PAUSE_PRINTER));
221 bool KMCupsManager::setDefaultPrinter(KMPrinter *p)
223 return setPrinterState(p,CUPS_SET_DEFAULT);
226 bool KMCupsManager::setPrinterState(KMPrinter *p,
int state)
231 req.setOperation(state);
232 uri = printerURI(p,
true);
233 req.addURI(IPP_TAG_OPERATION,
"printer-uri",uri);
234 if (req.doRequest(
"/admin/"))
236 reportIppError(&req);
240 bool KMCupsManager::completePrinter(KMPrinter *p)
242 if (completePrinterShort(p))
245 TQString ppdname = downloadDriver(p);
246 ppd_file_t *ppd = (ppdname.isEmpty() ? NULL : ppdOpenFile(ppdname.local8Bit()));
253 entry.manufacturer = ppd->manufacturer;
254 entry.model = ppd->shortnickname;
255 entry.modelname = ppd->modelname;
257 entry.validate(
false);
259 p->setManufacturer(entry.manufacturer);
260 p->setModel(entry.model);
261 p->setDriverInfo(TQString::fromLocal8Bit(ppd->nickname));
264 if (!ppdname.isEmpty())
265 TQFile::remove(ppdname);
272 bool KMCupsManager::completePrinterShort(KMPrinter *p)
278 req.setOperation(IPP_GET_PRINTER_ATTRIBUTES);
279 uri = printerURI(p,
true);
280 req.addURI(IPP_TAG_OPERATION,
"printer-uri",uri);
322 keys.append(
"printer-info");
323 keys.append(
"printer-make-and-model");
324 keys.append(
"job-sheets-default");
325 keys.append(
"job-sheets-supported");
326 keys.append(
"job-quota-period");
327 keys.append(
"job-k-limit");
328 keys.append(
"job-page-limit");
329 keys.append(
"requesting-user-name-allowed");
330 keys.append(
"requesting-user-name-denied");
331 if (p->isClass(
true))
333 keys.append(
"member-uris");
334 keys.append(
"member-names");
338 keys.append(
"device-uri");
339 keys.append(
"printer-device-id");
341 req.addKeyword(IPP_TAG_OPERATION,
"requested-attributes",keys);
343 if (req.doRequest(
"/printers/"))
346 if (req.text(
"printer-info",value)) p->setDescription(value);
349 if (req.text(
"printer-make-and-model",value)) p->setDriverInfo(value);
350 if (req.text(
"printer-device-id",value))
352 TQStringList fields = TQStringList::split(
";", value,
false);
353 for (
const TQString &field : fields)
355 int separator = field.find(
':');
361 TQString key = field.left(separator).stripWhiteSpace().upper();
362 TQString fieldValue = field.mid(separator + 1).stripWhiteSpace();
363 if (fieldValue.isEmpty())
367 if (key ==
"MFG" || key ==
"MANUFACTURER")
369 if (p->manufacturer().isEmpty())
371 p->setManufacturer(fieldValue);
374 else if (key ==
"MDL" || key ==
"MODEL")
376 if (p->model().isEmpty())
378 p->setModel(fieldValue);
383 if (req.uri(
"device-uri",value))
389 p->setDevice( value );
403 if (req.name(
"member-names",values))
404 p->setMembers(values);
406 req.name(
"job-sheets-default",values);
407 while (values.count() < 2) values.append(
"none");
408 p->setOption(
"kde-banners",values.join(TQString::fromLatin1(
",")));
409 if (req.name(
"job-sheets-supported",values)) p->setOption(
"kde-banners-supported",values.join(TQString::fromLatin1(
",")));
413 if (req.integer(
"job-quota-period",ival)) p->setOption(
"job-quota-period",TQString::number(ival));
414 if (req.integer(
"job-k-limit",ival)) p->setOption(
"job-k-limit",TQString::number(ival));
415 if (req.integer(
"job-page-limit",ival)) p->setOption(
"job-page-limit",TQString::number(ival));
418 if (req.name(
"requesting-user-name-allowed",values) && values.count() > 0)
420 p->removeOption(
"requesting-user-name-denied");
421 p->setOption(
"requesting-user-name-allowed",values.join(
","));
423 if (req.name(
"requesting-user-name-denied",values) && values.count() > 0)
425 p->removeOption(
"requesting-user-name-allowed");
426 p->setOption(
"requesting-user-name-denied",values.join(
","));
432 reportIppError(&req);
436 bool KMCupsManager::testPrinter(KMPrinter *p)
438 return KMManager::testPrinter(p);
463 void KMCupsManager::listPrinters()
465 loadServerPrinters();
468 void KMCupsManager::loadServerPrinters()
474 req.setOperation(CUPS_GET_PRINTERS);
475 keys.append(
"printer-name");
476 keys.append(
"printer-type");
477 keys.append(
"printer-state");
479 keys.append(
"printer-location");
480 keys.append(
"printer-uri-supported");
481 keys.append(
"printer-is-accepting-jobs");
482 req.addKeyword(IPP_TAG_OPERATION,
"requested-attributes",keys);
485 req.addName(IPP_TAG_OPERATION,
"requesting-user-name", TQString(cupsUser()));
487 if (req.doRequest(
"/printers/"))
489 processRequest(&req);
493 req.setOperation(CUPS_GET_CLASSES);
494 req.addKeyword(IPP_TAG_OPERATION,
"requested-attributes",keys);
496 if (req.doRequest(
"/classes/"))
498 processRequest(&req);
502 req.setOperation(CUPS_GET_DEFAULT);
503 req.addKeyword(IPP_TAG_OPERATION,
"requested-attributes",TQString::fromLatin1(
"printer-name"));
504 if (req.doRequest(
"/printers/"))
506 TQString s = TQString::null;
507 req.name(
"printer-name",s);
508 setHardDefault(findPrinter(s));
520 reportIppError(&req);
523 void KMCupsManager::processRequest(IppRequest* req)
525 ipp_attribute_t *attr = req->first();
526 ipp_attribute_t *nextAttr;
527 KMPrinter *printer =
new KMPrinter();
530 TQString attrname(ippGetName(attr));
531 if (attrname ==
"printer-name")
533 TQString value = TQString::fromLocal8Bit(ippGetString(attr, 0, NULL));
534 printer->setName(value);
535 printer->setPrinterName(value);
537 else if (attrname ==
"printer-type")
539 int value = ippGetInteger(attr, 0);
541 printer->addType(((value & CUPS_PRINTER_CLASS) || (value & CUPS_PRINTER_IMPLICIT) ? KMPrinter::Class : KMPrinter::Printer));
542 if ((value & CUPS_PRINTER_REMOTE)) printer->addType(KMPrinter::Remote);
543 if ((value & CUPS_PRINTER_IMPLICIT)) printer->addType(KMPrinter::Implicit);
546 printer->setPrinterCap( ( value & CUPS_PRINTER_OPTIONS ) >> 2 );
548 else if (attrname ==
"printer-state")
550 switch (ippGetInteger(attr, 0))
552 case IPP_PRINTER_IDLE: printer->setState(KMPrinter::Idle);
break;
553 case IPP_PRINTER_PROCESSING: printer->setState(KMPrinter::Processing);
break;
554 case IPP_PRINTER_STOPPED: printer->setState(KMPrinter::Stopped);
break;
557 else if (attrname ==
"printer-uri-supported")
559 printer->setUri(KURL(ippGetString(attr, 0, NULL)));
561 else if (attrname ==
"printer-location")
563 printer->setLocation(TQString::fromLocal8Bit(ippGetString(attr, 0, NULL)));
565 else if (attrname ==
"printer-is-accepting-jobs")
567 printer->setAcceptJobs(ippGetBoolean(attr, 0));
570 nextAttr = ippNextAttribute(req->request());
571 if (attrname.isEmpty() || (!nextAttr))
574 printer =
new KMPrinter();
581 DrMain* KMCupsManager::loadPrinterDriver(KMPrinter *p,
bool)
586 if (p->isClass(
true))
588 KMPrinter *first_class_member = NULL;
590 first_class_member = findPrinter(p->members().first());
592 if (first_class_member == NULL)
599 p = first_class_member;
603 TQString fname = downloadDriver(p);
605 if (!fname.isEmpty())
607 driver = loadDriverFile(fname);
609 driver->set(
"temporary",fname);
615 DrMain* KMCupsManager::loadFileDriver(
const TQString& filename)
617 if (filename.startsWith(
"ppd:"))
618 return loadDriverFile(filename.mid(4));
619 else if (filename.startsWith(
"compressed-ppd:"))
620 return loadDriverFile(filename);
621 else if (filename.startsWith(
"foomatic/"))
622 return loadMaticDriver(filename);
624 return loadDriverFile(filename);
627 DrMain* KMCupsManager::loadMaticDriver(
const TQString& drname)
629 TQStringList comps = TQStringList::split(
'/', drname,
false);
630 TQString tmpFile = locateLocal(
"tmp",
"foomatic_" + kapp->randomString(8));
631 #if defined(__OpenBSD__) || defined(__FreeBSD__)
632 TQString PATH = getenv(
"PATH") + TQString::fromLatin1(
":/usr/local/bin:/usr/sbin:/usr/local/sbin:/opt/sbin:/opt/local/sbin");
634 TQString PATH = getenv(
"PATH") + TQString::fromLatin1(
":/usr/sbin:/usr/local/sbin:/opt/sbin:/opt/local/sbin");
636 TQString exe = TDEStandardDirs::findExe(
"foomatic-datafile", PATH);
639 setErrorMsg(i18n(
"Unable to find the executable foomatic-datafile "
640 "in your PATH. Check that Foomatic is correctly installed."));
646 TQString cmd = TDEProcess::quote(exe);
647 cmd +=
" -t cups -d ";
648 cmd += TDEProcess::quote(comps[2]);
650 cmd += TDEProcess::quote(comps[1]);
651 if (in.open(cmd) && out.open(IO_WriteOnly))
653 TQTextStream tin(&in), tout(&out);
657 line = tin.readLine();
658 tout << line << endl;
663 DrMain *driver = loadDriverFile(tmpFile);
666 driver->set(
"template", tmpFile);
667 driver->set(
"temporary", tmpFile);
671 setErrorMsg(i18n(
"Unable to create the Foomatic driver [%1,%2]. "
672 "Either that driver does not exist, or you don't have "
673 "the required permissions to perform that operation.").arg(comps[1]).arg(comps[2]));
674 TQFile::remove(tmpFile);
678 DrMain* KMCupsManager::loadDriverFile(
const TQString& fname)
680 if ((fname.startsWith(
"compressed-ppd:")) || TQFile::exists(fname))
683 DrMain *driver = PPDLoader::loadDriver( fname, &msg );
686 driver->set(
"template", fname );
696 void KMCupsManager::saveDriverFile(DrMain *driver,
const TQString& filename)
698 kdDebug( 500 ) <<
"Saving PPD file with template=" << driver->get(
"template" ) << endl;
699 TQString templateFile = driver->get(
"template" );
700 if (templateFile.startsWith(
"compressed-ppd:")) {
701 templateFile = driver->get(
"temporary-cppd" );
703 TQIODevice *in = KFilterDev::deviceForFile( templateFile );
704 TQFile out(filename);
705 if (in && in->open(IO_ReadOnly) && out.open(IO_WriteOnly))
707 TQTextStream tin(in), tout(&out);
708 TQString line, keyword;
709 bool isnumeric(
false);
714 line = tin.readLine();
715 if (line.startsWith(
"*% COMDATA #"))
718 if ((p=line.find(
"'name'")) != -1)
720 p = line.find(
'\'',p+6)+1;
721 q = line.find(
'\'',p);
722 keyword = line.mid(p,q-p);
723 opt = driver->findOption(keyword);
724 if (opt && (opt->type() == DrBase::Integer || opt->type() == DrBase::Float))
737 else if ((p=line.find(
"'default'")) != -1 && !keyword.isEmpty() && opt && isnumeric)
739 TQString prefix = line.left(p+9);
740 tout << prefix <<
" => '" << opt->valueText() <<
'\'';
741 if (line.find(
',',p) != -1)
746 tout << line << endl;
748 else if (line.startsWith(
"*Default"))
750 int p = line.find(
':',8);
751 keyword = line.mid(8,p-8);
753 if ( keyword ==
"PageRegion" || keyword ==
"ImageableArea" || keyword ==
"PaperDimension" )
754 bopt = driver->findOption( TQString::fromLatin1(
"PageSize" ) );
756 bopt = driver->findOption( keyword );
758 switch (bopt->type())
761 case DrBase::Boolean:
763 DrListOption *opt =
static_cast<DrListOption*
>(bopt);
764 if (opt && opt->currentChoice())
765 tout <<
"*Default" << keyword <<
": " << opt->currentChoice()->name() << endl;
767 tout << line << endl;
770 case DrBase::Integer:
772 DrIntegerOption *opt =
static_cast<DrIntegerOption*
>(bopt);
773 tout <<
"*Default" << keyword <<
": " << opt->fixedVal() << endl;
778 DrFloatOption *opt =
static_cast<DrFloatOption*
>(bopt);
779 tout <<
"*Default" << keyword <<
": " << opt->fixedVal() << endl;
783 tout << line << endl;
787 tout << line << endl;
790 tout << line << endl;
796 bool KMCupsManager::savePrinterDriver(KMPrinter *p, DrMain *d)
798 TQString tmpfilename = locateLocal(
"tmp",
"print_") + kapp->randomString(8);
801 saveDriverFile(d,tmpfilename);
808 req.setOperation(CUPS_ADD_PRINTER);
809 uri = printerURI(p,
true);
810 req.addURI(IPP_TAG_OPERATION,
"printer-uri",uri);
811 result = req.doFileRequest(
"/admin/",tmpfilename);
814 TQFile::remove(tmpfilename);
817 reportIppError(&req);
821 void* KMCupsManager::loadCupsdConfFunction(
const char *name)
825 m_cupsdconf = KLibLoader::self()->library(
"cupsdconf");
828 setErrorMsg(i18n(
"Library cupsdconf not found. Check your installation."));
832 void* func = m_cupsdconf->symbol(name);
834 setErrorMsg(i18n(
"Symbol %1 not found in cupsdconf library.").arg(name));
838 void KMCupsManager::unloadCupsdConf()
842 KLibLoader::self()->unloadLibrary(
"libcupsdconf");
847 bool KMCupsManager::restartServer()
850 bool (*f1)(TQString&) = (
bool(*)(TQString&))loadCupsdConfFunction(
"restartServer");
855 if (!result) setErrorMsg(msg);
861 bool KMCupsManager::configureServer(TQWidget *parent)
864 bool (*f2)(TQWidget*, TQString&) = (
bool(*)(TQWidget*, TQString&))loadCupsdConfFunction(
"configureServer");
868 result = f2(parent, msg);
876 TQStringList KMCupsManager::detectLocalPrinters()
880 ipp_attribute_t *nextAttr;
881 req.setOperation(CUPS_GET_DEVICES);
882 if (req.doRequest(
"/"))
884 TQString desc, uri, printer, cl;
885 ipp_attribute_t *attr = req.first();
888 TQString attrname(ippGetName(attr));
889 if (attrname ==
"device-info") desc = ippGetString(attr, 0, NULL);
890 else if (attrname ==
"device-make-and-model") printer = ippGetString(attr, 0, NULL);
891 else if (attrname ==
"device-uri") uri = ippGetString(attr, 0, NULL);
892 else if ( attrname ==
"device-class" ) cl = ippGetString(attr, 0, NULL);
893 nextAttr = ippNextAttribute(req.request());
894 if (attrname.isEmpty() || (!nextAttr))
898 if (printer ==
"Unknown") printer = TQString::null;
899 list << cl << uri << desc << printer;
901 uri = desc = printer = cl = TQString::null;
909 void KMCupsManager::createPluginActions(TDEActionCollection *coll)
911 TDEAction *act =
new TDEAction(i18n(
"&Export Driver..."),
"tdeprint_uploadsmb", 0,
this, TQ_SLOT(exportDriver()), coll,
"plugin_export_driver");
912 act->setGroup(
"plugin");
913 act =
new TDEAction(i18n(
"&Printer IPP Report"),
"tdeprint_report", 0,
this, TQ_SLOT(printerIppReport()), coll,
"plugin_printer_ipp_report");
914 act->setGroup(
"plugin");
917 void KMCupsManager::validatePluginActions(TDEActionCollection *coll, KMPrinter *pr)
920 m_currentprinter = pr;
921 coll->action(
"plugin_export_driver")->setEnabled(pr && pr->isLocal() && !pr->isClass(
true) && !pr->isSpecial());
922 coll->action(
"plugin_printer_ipp_report")->setEnabled(pr && !pr->isSpecial());
925 void KMCupsManager::exportDriver()
927 if (m_currentprinter && m_currentprinter->isLocal() &&
928 !m_currentprinter->isClass(
true) && !m_currentprinter->isSpecial())
930 TQString path = cupsInstallDir();
931 if (path.isEmpty()) {
932 #if defined(__OpenBSD__) || defined(__FreeBSD__)
933 path =
"/usr/local/share/cups";
935 path =
"/usr/share/cups";
938 path +=
"/share/cups";
940 CupsAddSmb::exportDest(m_currentprinter->printerName(), path);
944 void KMCupsManager::printerIppReport()
946 if (m_currentprinter && !m_currentprinter->isSpecial())
951 req.setOperation(IPP_GET_PRINTER_ATTRIBUTES);
952 uri = printerURI(m_currentprinter,
true);
953 req.addURI(IPP_TAG_OPERATION,
"printer-uri",uri);
962 if (req.doRequest(
"/printers/"))
964 ippReport(req, IPP_TAG_PRINTER, i18n(
"IPP Report for %1").arg(m_currentprinter->printerName()));
968 KMessageBox::error(0,
"<p>"+i18n(
"Unable to retrieve printer information. Error received:")+
"</p>"+req.statusMessage());
973 void KMCupsManager::ippReport(IppRequest& req,
int group,
const TQString& caption)
975 IppReportDlg::report(&req, group, caption);
978 TQString KMCupsManager::stateInformation()
980 return TQString(
"%1: %2")
982 .arg(CupsInfos::self()->host()[0] !=
'/' ?
983 TQString(TQString(
"%1:%2").arg(CupsInfos::self()->host()).arg(CupsInfos::self()->port()))
984 : CupsInfos::self()->host());
987 void KMCupsManager::checkUpdatePossibleInternal()
989 kdDebug(500) <<
"Checking for update possible" << endl;
991 m_socket =
new KNetwork::TDEBufferedSocket;
992 m_socket->setTimeout( 1500 );
993 connect( m_socket, TQ_SIGNAL( connected(
const KResolverEntry&) ),
994 TQ_SLOT( slotConnectionSuccess() ) );
995 connect( m_socket, TQ_SIGNAL( gotError(
int ) ), TQ_SLOT( slotConnectionFailed(
int ) ) );
998 TQTimer::singleShot( 1,
this, TQ_SLOT( slotAsyncConnect() ) );
1001 void KMCupsManager::slotConnectionSuccess()
1003 kdDebug(500) <<
"Connection success, trying to send a request..." << endl;
1007 req.setOperation( CUPS_GET_PRINTERS );
1008 req.addKeyword( IPP_TAG_OPERATION,
"requested-attributes", TQString::fromLatin1(
"printer-name" ) );
1009 if ( req.doRequest(
"/printers/" ) )
1010 setUpdatePossible(
true );
1013 kdDebug(500) <<
"Unable to get printer list" << endl;
1017 TQTimer::singleShot( 1000,
this, TQ_SLOT( slotAsyncConnect() ) );
1021 setErrorMsg( i18n(
"Connection to CUPS server failed. Check that the CUPS server is correctly installed and running. "
1022 "Error: %1." ).arg( i18n(
"the IPP request failed for an unknown reason" ) ) );
1023 setUpdatePossible(
false );
1028 void KMCupsManager::slotAsyncConnect()
1030 kdDebug(500) <<
"Starting async connect to " << CupsInfos::self()->hostaddr() << endl;
1032 if (CupsInfos::self()->host().startsWith(
"/"))
1033 m_socket->connect( TQString(), CupsInfos::self()->host());
1035 m_socket->connectToHost( CupsInfos::self()->host(), CupsInfos::self()->port() );
1038 void KMCupsManager::slotConnectionFailed(
int errcode )
1040 kdDebug(500) <<
"Connection failed trials=" << trials << endl;
1047 TQTimer::singleShot( 1000,
this, TQ_SLOT( slotAsyncConnect() ) );
1054 case KNetwork::TDESocketBase::ConnectionRefused:
1055 case KNetwork::TDESocketBase::ConnectionTimedOut:
1056 einfo = i18n(
"connection refused") + TQString(
" (%1)").arg(errcode);
1058 case KNetwork::TDESocketBase::LookupFailure:
1059 einfo = i18n(
"host not found") + TQString(
" (%1)").arg(errcode);
1061 case KNetwork::TDESocketBase::WouldBlock:
1063 einfo = i18n(
"read failed (%1)").arg(errcode);
1067 setErrorMsg( i18n(
"Connection to CUPS server failed. Check that the CUPS server is correctly installed and running. "
1068 "Error: %2: %1." ).arg( einfo, CupsInfos::self()->host()));
1069 setUpdatePossible(
false );
1072 void KMCupsManager::hostPingSlot() {
1073 m_hostSuccess =
true;
1074 m_lookupDone =
true;
1077 void KMCupsManager::hostPingFailedSlot() {
1078 m_hostSuccess =
false;
1079 m_lookupDone =
true;
1084 static void extractMaticData(TQString& buf,
const TQString& filename)
1087 if (f.exists() && f.open(IO_ReadOnly))
1093 line = t.readLine();
1094 if (line.startsWith(
"*% COMDATA #"))
1095 buf.append(line.right(line.length()-12)).append(
'\n');
1100 static TQString printerURI(KMPrinter *p,
bool use)
1103 if (use && !p->uri().isEmpty())
1104 uri = p->uri().prettyURL();
1106 uri = TQString(
"ipp://%1/%3/%2").arg(CupsInfos::self()->hostaddr()).arg(p->printerName()).arg((p->isClass(
false) ?
"classes" :
"printers"));
1110 static TQString downloadDriver(KMPrinter *p)
1112 TQString driverfile, prname = p->printerName();
1113 bool changed(
false);
1132 driverfile = cupsGetPPD(prname.local8Bit());
1137 cupsSetServer(CupsInfos::self()->host().local8Bit());
1138 ippSetPort(CupsInfos::self()->port());
1144 #include "kmcupsmanager.moc"