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 <kapplication.h>
47 #include <kstandarddirs.h>
48 #include <ksocketbase.h>
49 #include <klibloader.h>
50 #include <kmessagebox.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(__KDE_BINDIR).append(TQString::fromLatin1(
"/make_driver_db_cups"));
101 TQString KMCupsManager::driverDirectory()
103 TQString d = cupsInstallDir();
106 d.append(
"/share/cups/model");
108 d.append(
":/usr/share/foomatic/db/source");
112 TQString KMCupsManager::cupsInstallDir()
114 KConfig *conf= KMFactory::self()->printConfig();
115 conf->setGroup(
"CUPS");
116 TQString dir = conf->readPathEntry(
"InstallDir");
120 void KMCupsManager::reportIppError(IppRequest *req)
122 setErrorMsg(req->statusMessage());
125 bool KMCupsManager::createPrinter(KMPrinter *p)
127 bool isclass = p->isClass(
false), result(
false);
131 uri = printerURI(p,
false);
132 req.addURI(IPP_TAG_OPERATION,
"printer-uri",uri);
134 p->setUri(KURL(uri));
138 req.setOperation(CUPS_ADD_CLASS);
139 TQStringList members = p->members(), uris;
141 s = TQString::fromLocal8Bit(
"ipp://%1/printers/").arg(CupsInfos::self()->hostaddr());
142 for (TQStringList::ConstIterator it=members.begin(); it!=members.end(); ++it)
143 uris.append(s+(*it));
144 req.addURI(IPP_TAG_PRINTER,
"member-uris",uris);
148 req.setOperation(CUPS_ADD_PRINTER);
151 KMPrinter *otherP = findPrinter(p->printerName());
152 if (!otherP || otherP->device() != p->device())
159 req.addURI(IPP_TAG_PRINTER,
"device-uri",p->device());
161 if (!p->option(
"kde-banners").isEmpty())
163 TQStringList bans = TQStringList::split(
',',p->option(
"kde-banners"),
false);
164 while (bans.count() < 2)
166 req.addName(IPP_TAG_PRINTER,
"job-sheets-default",bans);
168 req.addInteger(IPP_TAG_PRINTER,
"job-quota-period",p->option(
"job-quota-period").toInt());
169 req.addInteger(IPP_TAG_PRINTER,
"job-k-limit",p->option(
"job-k-limit").toInt());
170 req.addInteger(IPP_TAG_PRINTER,
"job-page-limit",p->option(
"job-page-limit").toInt());
171 if (!p->option(
"requesting-user-name-denied").isEmpty())
172 req.addName(IPP_TAG_PRINTER,
"requesting-user-name-denied",TQStringList::split(
",",p->option(
"requesting-user-name-denied"),
false));
173 else if (!p->option(
"requesting-user-name-allowed").isEmpty())
174 req.addName(IPP_TAG_PRINTER,
"requesting-user-name-allowed",TQStringList::split(
",",p->option(
"requesting-user-name-allowed"),
false));
176 req.addName(IPP_TAG_PRINTER,
"requesting-user-name-allowed",TQString::fromLatin1(
"all"));
178 req.addText(IPP_TAG_PRINTER,
"printer-info",p->description());
179 req.addText(IPP_TAG_PRINTER,
"printer-location",p->location());
181 if (req.doRequest(
"/admin/"))
185 result = savePrinterDriver(p,p->driver());
189 else reportIppError(&req);
194 bool KMCupsManager::removePrinter(KMPrinter *p)
196 bool result = setPrinterState(p,CUPS_DELETE_PRINTER);
200 bool KMCupsManager::enablePrinter(KMPrinter *p,
bool state)
202 return setPrinterState(p, (state ? CUPS_ACCEPT_JOBS : CUPS_REJECT_JOBS));
205 bool KMCupsManager::startPrinter(KMPrinter *p,
bool state)
207 return setPrinterState(p, (state ? IPP_RESUME_PRINTER : IPP_PAUSE_PRINTER));
210 bool KMCupsManager::setDefaultPrinter(KMPrinter *p)
212 return setPrinterState(p,CUPS_SET_DEFAULT);
215 bool KMCupsManager::setPrinterState(KMPrinter *p,
int state)
220 req.setOperation(state);
221 uri = printerURI(p,
true);
222 req.addURI(IPP_TAG_OPERATION,
"printer-uri",uri);
223 if (req.doRequest(
"/admin/"))
225 reportIppError(&req);
229 bool KMCupsManager::completePrinter(KMPrinter *p)
231 if (completePrinterShort(p))
234 TQString ppdname = downloadDriver(p);
235 ppd_file_t *ppd = (ppdname.isEmpty() ? NULL : ppdOpenFile(ppdname.local8Bit()));
242 entry.manufacturer = ppd->manufacturer;
243 entry.model = ppd->shortnickname;
244 entry.modelname = ppd->modelname;
246 entry.validate(
false);
248 p->setManufacturer(entry.manufacturer);
249 p->setModel(entry.model);
250 p->setDriverInfo(TQString::fromLocal8Bit(ppd->nickname));
253 if (!ppdname.isEmpty())
254 TQFile::remove(ppdname);
261 bool KMCupsManager::completePrinterShort(KMPrinter *p)
267 req.setOperation(IPP_GET_PRINTER_ATTRIBUTES);
268 uri = printerURI(p,
true);
269 req.addURI(IPP_TAG_OPERATION,
"printer-uri",uri);
311 keys.append(
"printer-info");
312 keys.append(
"printer-make-and-model");
313 keys.append(
"job-sheets-default");
314 keys.append(
"job-sheets-supported");
315 keys.append(
"job-quota-period");
316 keys.append(
"job-k-limit");
317 keys.append(
"job-page-limit");
318 keys.append(
"requesting-user-name-allowed");
319 keys.append(
"requesting-user-name-denied");
320 if (p->isClass(
true))
322 keys.append(
"member-uris");
323 keys.append(
"member-names");
326 keys.append(
"device-uri");
327 req.addKeyword(IPP_TAG_OPERATION,
"requested-attributes",keys);
329 if (req.doRequest(
"/printers/"))
332 if (req.text(
"printer-info",value)) p->setDescription(value);
335 if (req.text(
"printer-make-and-model",value)) p->setDriverInfo(value);
336 if (req.uri(
"device-uri",value))
342 p->setDevice( value );
356 if (req.name(
"member-names",values))
357 p->setMembers(values);
359 req.name(
"job-sheets-default",values);
360 while (values.count() < 2) values.append(
"none");
361 p->setOption(
"kde-banners",values.join(TQString::fromLatin1(
",")));
362 if (req.name(
"job-sheets-supported",values)) p->setOption(
"kde-banners-supported",values.join(TQString::fromLatin1(
",")));
366 if (req.integer(
"job-quota-period",ival)) p->setOption(
"job-quota-period",TQString::number(ival));
367 if (req.integer(
"job-k-limit",ival)) p->setOption(
"job-k-limit",TQString::number(ival));
368 if (req.integer(
"job-page-limit",ival)) p->setOption(
"job-page-limit",TQString::number(ival));
371 if (req.name(
"requesting-user-name-allowed",values) && values.count() > 0)
373 p->removeOption(
"requesting-user-name-denied");
374 p->setOption(
"requesting-user-name-allowed",values.join(
","));
376 if (req.name(
"requesting-user-name-denied",values) && values.count() > 0)
378 p->removeOption(
"requesting-user-name-allowed");
379 p->setOption(
"requesting-user-name-denied",values.join(
","));
385 reportIppError(&req);
389 bool KMCupsManager::testPrinter(KMPrinter *p)
391 return KMManager::testPrinter(p);
416 void KMCupsManager::listPrinters()
418 loadServerPrinters();
421 void KMCupsManager::loadServerPrinters()
427 req.setOperation(CUPS_GET_PRINTERS);
428 keys.append(
"printer-name");
429 keys.append(
"printer-type");
430 keys.append(
"printer-state");
432 keys.append(
"printer-location");
433 keys.append(
"printer-uri-supported");
434 keys.append(
"printer-is-accepting-jobs");
435 req.addKeyword(IPP_TAG_OPERATION,
"requested-attributes",keys);
438 req.addName(IPP_TAG_OPERATION,
"requesting-user-name", TQString(cupsUser()));
440 if (req.doRequest(
"/printers/"))
442 processRequest(&req);
446 req.setOperation(CUPS_GET_CLASSES);
447 req.addKeyword(IPP_TAG_OPERATION,
"requested-attributes",keys);
449 if (req.doRequest(
"/classes/"))
451 processRequest(&req);
455 req.setOperation(CUPS_GET_DEFAULT);
456 req.addKeyword(IPP_TAG_OPERATION,
"requested-attributes",TQString::fromLatin1(
"printer-name"));
457 if (req.doRequest(
"/printers/"))
459 TQString s = TQString::null;
460 req.name(
"printer-name",s);
461 setHardDefault(findPrinter(s));
473 reportIppError(&req);
476 void KMCupsManager::processRequest(IppRequest* req)
478 ipp_attribute_t *attr = req->first();
479 ipp_attribute_t *nextAttr;
480 KMPrinter *printer =
new KMPrinter();
484 TQString attrname(ippGetName(attr));
485 if (attrname ==
"printer-name")
487 TQString value = TQString::fromLocal8Bit(ippGetString(attr, 0, NULL));
488 printer->setName(value);
489 printer->setPrinterName(value);
491 else if (attrname ==
"printer-type")
493 int value = ippGetInteger(attr, 0);
495 printer->addType(((value & CUPS_PRINTER_CLASS) || (value & CUPS_PRINTER_IMPLICIT) ? KMPrinter::Class : KMPrinter::Printer));
496 if ((value & CUPS_PRINTER_REMOTE)) printer->addType(KMPrinter::Remote);
497 if ((value & CUPS_PRINTER_IMPLICIT)) printer->addType(KMPrinter::Implicit);
500 printer->setPrinterCap( ( value & CUPS_PRINTER_OPTIONS ) >> 2 );
502 else if (attrname ==
"printer-state")
504 switch (ippGetInteger(attr, 0))
506 case IPP_PRINTER_IDLE: printer->setState(KMPrinter::Idle);
break;
507 case IPP_PRINTER_PROCESSING: printer->setState(KMPrinter::Processing);
break;
508 case IPP_PRINTER_STOPPED: printer->setState(KMPrinter::Stopped);
break;
511 else if (attrname ==
"printer-uri-supported")
513 printer->setUri(KURL(ippGetString(attr, 0, NULL)));
515 else if (attrname ==
"printer-location")
517 printer->setLocation(TQString::fromLocal8Bit(ippGetString(attr, 0, NULL)));
519 else if (attrname ==
"printer-is-accepting-jobs")
521 printer->setAcceptJobs(ippGetBoolean(attr, 0));
524 nextAttr = ippNextAttribute(req->request());
525 if (attrname.isEmpty() || (!nextAttr))
528 printer =
new KMPrinter();
531 #else // HAVE_CUPS_1_6
532 TQString attrname(attr->name);
533 if (attrname ==
"printer-name")
535 TQString value = TQString::fromLocal8Bit(attr->values[0].string.text);
536 printer->setName(value);
537 printer->setPrinterName(value);
539 else if (attrname ==
"printer-type")
541 int value = attr->values[0].integer;
543 printer->addType(((value & CUPS_PRINTER_CLASS) || (value & CUPS_PRINTER_IMPLICIT) ? KMPrinter::Class : KMPrinter::Printer));
544 if ((value & CUPS_PRINTER_REMOTE)) printer->addType(KMPrinter::Remote);
545 if ((value & CUPS_PRINTER_IMPLICIT)) printer->addType(KMPrinter::Implicit);
548 printer->setPrinterCap( ( value & CUPS_PRINTER_OPTIONS ) >> 2 );
550 else if (attrname ==
"printer-state")
552 switch (attr->values[0].integer)
554 case IPP_PRINTER_IDLE: printer->setState(KMPrinter::Idle);
break;
555 case IPP_PRINTER_PROCESSING: printer->setState(KMPrinter::Processing);
break;
556 case IPP_PRINTER_STOPPED: printer->setState(KMPrinter::Stopped);
break;
559 else if (attrname ==
"printer-uri-supported")
561 printer->setUri(KURL(attr->values[0].string.text));
563 else if (attrname ==
"printer-location")
565 printer->setLocation(TQString::fromLocal8Bit(attr->values[0].string.text));
567 else if (attrname ==
"printer-is-accepting-jobs")
569 printer->setAcceptJobs(attr->values[0].boolean);
571 if (attrname.isEmpty() || attr == req->last())
574 printer =
new KMPrinter();
577 #endif // HAVE_CUPS_1_6
582 DrMain* KMCupsManager::loadPrinterDriver(KMPrinter *p,
bool)
587 if (p->isClass(
true))
589 KMPrinter *first_class_member = NULL;
591 first_class_member = findPrinter(p->members().first());
593 if (first_class_member == NULL)
600 p = first_class_member;
604 TQString fname = downloadDriver(p);
606 if (!fname.isEmpty())
608 driver = loadDriverFile(fname);
610 driver->set(
"temporary",fname);
616 DrMain* KMCupsManager::loadFileDriver(
const TQString& filename)
618 if (filename.startsWith(
"ppd:"))
619 return loadDriverFile(filename.mid(4));
620 else if (filename.startsWith(
"foomatic/"))
621 return loadMaticDriver(filename);
623 return loadDriverFile(filename);
626 DrMain* KMCupsManager::loadMaticDriver(
const TQString& drname)
628 TQStringList comps = TQStringList::split(
'/', drname,
false);
629 TQString tmpFile = locateLocal(
"tmp",
"foomatic_" + kapp->randomString(8));
630 TQString PATH = getenv(
"PATH") + TQString::fromLatin1(
":/usr/sbin:/usr/local/sbin:/opt/sbin:/opt/local/sbin");
631 TQString exe = KStandardDirs::findExe(
"foomatic-datafile", PATH);
634 setErrorMsg(i18n(
"Unable to find the executable foomatic-datafile "
635 "in your PATH. Check that Foomatic is correctly installed."));
641 TQString cmd = KProcess::quote(exe);
642 cmd +=
" -t cups -d ";
643 cmd += KProcess::quote(comps[2]);
645 cmd += KProcess::quote(comps[1]);
646 if (in.open(cmd) && out.open(IO_WriteOnly))
648 TQTextStream tin(&in), tout(&out);
652 line = tin.readLine();
653 tout << line << endl;
658 DrMain *driver = loadDriverFile(tmpFile);
661 driver->set(
"template", tmpFile);
662 driver->set(
"temporary", tmpFile);
666 setErrorMsg(i18n(
"Unable to create the Foomatic driver [%1,%2]. "
667 "Either that driver does not exist, or you don't have "
668 "the required permissions to perform that operation.").arg(comps[1]).arg(comps[2]));
669 TQFile::remove(tmpFile);
673 DrMain* KMCupsManager::loadDriverFile(
const TQString& fname)
675 if (TQFile::exists(fname))
678 DrMain *driver = PPDLoader::loadDriver( fname, &msg );
681 driver->set(
"template", fname );
691 void KMCupsManager::saveDriverFile(DrMain *driver,
const TQString& filename)
693 kdDebug( 500 ) <<
"Saving PPD file with template=" << driver->get(
"template" ) << endl;
694 TQIODevice *in = KFilterDev::deviceForFile( driver->get(
"template" ) );
695 TQFile out(filename);
696 if (in && in->open(IO_ReadOnly) && out.open(IO_WriteOnly))
698 TQTextStream tin(in), tout(&out);
699 TQString line, keyword;
700 bool isnumeric(
false);
705 line = tin.readLine();
706 if (line.startsWith(
"*% COMDATA #"))
709 if ((p=line.find(
"'name'")) != -1)
711 p = line.find(
'\'',p+6)+1;
712 q = line.find(
'\'',p);
713 keyword = line.mid(p,q-p);
714 opt = driver->findOption(keyword);
715 if (opt && (opt->type() == DrBase::Integer || opt->type() == DrBase::Float))
728 else if ((p=line.find(
"'default'")) != -1 && !keyword.isEmpty() && opt && isnumeric)
730 TQString prefix = line.left(p+9);
731 tout << prefix <<
" => '" << opt->valueText() <<
'\'';
732 if (line.find(
',',p) != -1)
737 tout << line << endl;
739 else if (line.startsWith(
"*Default"))
741 int p = line.find(
':',8);
742 keyword = line.mid(8,p-8);
744 if ( keyword ==
"PageRegion" || keyword ==
"ImageableArea" || keyword ==
"PaperDimension" )
745 bopt = driver->findOption( TQString::fromLatin1(
"PageSize" ) );
747 bopt = driver->findOption( keyword );
749 switch (bopt->type())
752 case DrBase::Boolean:
754 DrListOption *opt =
static_cast<DrListOption*
>(bopt);
755 if (opt && opt->currentChoice())
756 tout <<
"*Default" << keyword <<
": " << opt->currentChoice()->name() << endl;
758 tout << line << endl;
761 case DrBase::Integer:
763 DrIntegerOption *opt =
static_cast<DrIntegerOption*
>(bopt);
764 tout <<
"*Default" << keyword <<
": " << opt->fixedVal() << endl;
769 DrFloatOption *opt =
static_cast<DrFloatOption*
>(bopt);
770 tout <<
"*Default" << keyword <<
": " << opt->fixedVal() << endl;
774 tout << line << endl;
778 tout << line << endl;
781 tout << line << endl;
787 bool KMCupsManager::savePrinterDriver(KMPrinter *p, DrMain *d)
789 TQString tmpfilename = locateLocal(
"tmp",
"print_") + kapp->randomString(8);
792 saveDriverFile(d,tmpfilename);
799 req.setOperation(CUPS_ADD_PRINTER);
800 uri = printerURI(p,
true);
801 req.addURI(IPP_TAG_OPERATION,
"printer-uri",uri);
802 result = req.doFileRequest(
"/admin/",tmpfilename);
805 TQFile::remove(tmpfilename);
808 reportIppError(&req);
812 void* KMCupsManager::loadCupsdConfFunction(
const char *name)
816 m_cupsdconf = KLibLoader::self()->library(
"cupsdconf");
819 setErrorMsg(i18n(
"Library cupsdconf not found. Check your installation."));
823 void* func = m_cupsdconf->symbol(name);
825 setErrorMsg(i18n(
"Symbol %1 not found in cupsdconf library.").arg(name));
829 void KMCupsManager::unloadCupsdConf()
833 KLibLoader::self()->unloadLibrary(
"libcupsdconf");
838 bool KMCupsManager::restartServer()
841 bool (*f1)(TQString&) = (
bool(*)(TQString&))loadCupsdConfFunction(
"restartServer");
846 if (!result) setErrorMsg(msg);
852 bool KMCupsManager::configureServer(TQWidget *parent)
855 bool (*f2)(TQWidget*, TQString&) = (
bool(*)(TQWidget*, TQString&))loadCupsdConfFunction(
"configureServer");
859 result = f2(parent, msg);
867 TQStringList KMCupsManager::detectLocalPrinters()
871 ipp_attribute_t *nextAttr;
872 req.setOperation(CUPS_GET_DEVICES);
873 if (req.doRequest(
"/"))
875 TQString desc, uri, printer, cl;
876 ipp_attribute_t *attr = req.first();
880 TQString attrname(ippGetName(attr));
881 if (attrname ==
"device-info") desc = ippGetString(attr, 0, NULL);
882 else if (attrname ==
"device-make-and-model") printer = ippGetString(attr, 0, NULL);
883 else if (attrname ==
"device-uri") uri = ippGetString(attr, 0, NULL);
884 else if ( attrname ==
"device-class" ) cl = ippGetString(attr, 0, NULL);
885 nextAttr = ippNextAttribute(req.request());
886 if (attrname.isEmpty() || (!nextAttr))
890 if (printer ==
"Unknown") printer = TQString::null;
891 list << cl << uri << desc << printer;
893 uri = desc = printer = cl = TQString::null;
896 #else // HAVE_CUPS_1_6
897 TQString attrname(attr->name);
898 if (attrname ==
"device-info") desc = attr->values[0].string.text;
899 else if (attrname ==
"device-make-and-model") printer = attr->values[0].string.text;
900 else if (attrname ==
"device-uri") uri = attr->values[0].string.text;
901 else if ( attrname ==
"device-class" ) cl = attr->values[ 0 ].string.text;
902 if (attrname.isEmpty() || attr == req.last())
906 if (printer ==
"Unknown") printer = TQString::null;
907 list << cl << uri << desc << printer;
909 uri = desc = printer = cl = TQString::null;
912 #endif // HAVE_CUPS_1_6
918 void KMCupsManager::createPluginActions(KActionCollection *coll)
920 KAction *act =
new KAction(i18n(
"&Export Driver..."),
"kdeprint_uploadsmb", 0,
this, TQT_SLOT(exportDriver()), coll,
"plugin_export_driver");
921 act->setGroup(
"plugin");
922 act =
new KAction(i18n(
"&Printer IPP Report"),
"kdeprint_report", 0,
this, TQT_SLOT(printerIppReport()), coll,
"plugin_printer_ipp_report");
923 act->setGroup(
"plugin");
926 void KMCupsManager::validatePluginActions(KActionCollection *coll, KMPrinter *pr)
929 m_currentprinter = pr;
930 coll->action(
"plugin_export_driver")->setEnabled(pr && pr->isLocal() && !pr->isClass(
true) && !pr->isSpecial());
931 coll->action(
"plugin_printer_ipp_report")->setEnabled(pr && !pr->isSpecial());
934 void KMCupsManager::exportDriver()
936 if (m_currentprinter && m_currentprinter->isLocal() &&
937 !m_currentprinter->isClass(
true) && !m_currentprinter->isSpecial())
939 TQString path = cupsInstallDir();
941 path =
"/usr/share/cups";
943 path +=
"/share/cups";
944 CupsAddSmb::exportDest(m_currentprinter->printerName(), path);
948 void KMCupsManager::printerIppReport()
950 if (m_currentprinter && !m_currentprinter->isSpecial())
955 req.setOperation(IPP_GET_PRINTER_ATTRIBUTES);
956 uri = printerURI(m_currentprinter,
true);
957 req.addURI(IPP_TAG_OPERATION,
"printer-uri",uri);
966 if (req.doRequest(
"/printers/"))
968 ippReport(req, IPP_TAG_PRINTER, i18n(
"IPP Report for %1").arg(m_currentprinter->printerName()));
972 KMessageBox::error(0,
"<p>"+i18n(
"Unable to retrieve printer information. Error received:")+
"</p>"+req.statusMessage());
977 void KMCupsManager::ippReport(IppRequest& req,
int group,
const TQString& caption)
979 IppReportDlg::report(&req, group, caption);
982 TQString KMCupsManager::stateInformation()
984 return TQString(
"%1: %2")
986 .arg(CupsInfos::self()->host()[0] !=
'/' ?
987 TQString(TQString(
"%1:%2").arg(CupsInfos::self()->host()).arg(CupsInfos::self()->port()))
988 : CupsInfos::self()->host());
991 void KMCupsManager::checkUpdatePossibleInternal()
993 kdDebug(500) <<
"Checking for update possible" << endl;
995 m_socket =
new KNetwork::KBufferedSocket;
996 m_socket->setTimeout( 1500 );
997 connect( m_socket, TQT_SIGNAL( connected(
const KResolverEntry&) ),
998 TQT_SLOT( slotConnectionSuccess() ) );
999 connect( m_socket, TQT_SIGNAL( gotError(
int ) ), TQT_SLOT( slotConnectionFailed(
int ) ) );
1002 TQTimer::singleShot( 1,
this, TQT_SLOT( slotAsyncConnect() ) );
1005 void KMCupsManager::slotConnectionSuccess()
1007 kdDebug(500) <<
"Connection success, trying to send a request..." << endl;
1011 req.setOperation( CUPS_GET_PRINTERS );
1012 req.addKeyword( IPP_TAG_OPERATION,
"requested-attributes", TQString::fromLatin1(
"printer-name" ) );
1013 if ( req.doRequest(
"/printers/" ) )
1014 setUpdatePossible(
true );
1017 kdDebug(500) <<
"Unable to get printer list" << endl;
1021 TQTimer::singleShot( 1000,
this, TQT_SLOT( slotAsyncConnect() ) );
1025 setErrorMsg( i18n(
"Connection to CUPS server failed. Check that the CUPS server is correctly installed and running. "
1026 "Error: %1." ).arg( i18n(
"the IPP request failed for an unknown reason" ) ) );
1027 setUpdatePossible(
false );
1032 void KMCupsManager::slotAsyncConnect()
1034 kdDebug(500) <<
"Starting async connect to " << CupsInfos::self()->hostaddr() << endl;
1036 if (CupsInfos::self()->host().startsWith(
"/"))
1037 m_socket->connect( TQString(), CupsInfos::self()->host());
1039 m_socket->connectToHost( CupsInfos::self()->host(), CupsInfos::self()->port() );
1042 void KMCupsManager::slotConnectionFailed(
int errcode )
1044 kdDebug(500) <<
"Connection failed trials=" << trials << endl;
1051 TQTimer::singleShot( 1000,
this, TQT_SLOT( slotAsyncConnect() ) );
1058 case KNetwork::KSocketBase::ConnectionRefused:
1059 case KNetwork::KSocketBase::ConnectionTimedOut:
1060 einfo = i18n(
"connection refused") + TQString(
" (%1)").arg(errcode);
1062 case KNetwork::KSocketBase::LookupFailure:
1063 einfo = i18n(
"host not found") + TQString(
" (%1)").arg(errcode);
1065 case KNetwork::KSocketBase::WouldBlock:
1067 einfo = i18n(
"read failed (%1)").arg(errcode);
1071 setErrorMsg( i18n(
"Connection to CUPS server failed. Check that the CUPS server is correctly installed and running. "
1072 "Error: %2: %1." ).arg( einfo, CupsInfos::self()->host()));
1073 setUpdatePossible(
false );
1076 void KMCupsManager::hostPingSlot() {
1077 m_hostSuccess =
true;
1078 m_lookupDone =
true;
1081 void KMCupsManager::hostPingFailedSlot() {
1082 m_hostSuccess =
false;
1083 m_lookupDone =
true;
1088 static void extractMaticData(TQString& buf,
const TQString& filename)
1091 if (f.exists() && f.open(IO_ReadOnly))
1097 line = t.readLine();
1098 if (line.startsWith(
"*% COMDATA #"))
1099 buf.append(line.right(line.length()-12)).append(
'\n');
1104 static TQString printerURI(KMPrinter *p,
bool use)
1107 if (use && !p->uri().isEmpty())
1108 uri = p->uri().prettyURL();
1110 uri = TQString(
"ipp://%1/%3/%2").arg(CupsInfos::self()->hostaddr()).arg(p->printerName()).arg((p->isClass(
false) ?
"classes" :
"printers"));
1114 static TQString downloadDriver(KMPrinter *p)
1116 TQString driverfile, prname = p->printerName();
1117 bool changed(
false);
1136 driverfile = cupsGetPPD(prname.local8Bit());
1141 cupsSetServer(CupsInfos::self()->host().local8Bit());
1142 ippSetPort(CupsInfos::self()->port());
1148 #include "kmcupsmanager.moc"