20 #include "kmfoomaticmanager.h"
21 #include "kpipeprocess.h"
25 #include <tdelocale.h>
27 #include <tdeprocess.h>
31 KMFoomaticManager::KMFoomaticManager(TQObject *parent,
const char *name,
const TQStringList & )
32 : KMManager(parent,name)
34 setHasManagement(getuid() == 0);
35 setPrinterOperationMask(KMManager::PrinterConfigure);
38 KMFoomaticManager::~KMFoomaticManager()
42 void KMFoomaticManager::listPrinters()
44 KPipeProcess proc(
"foomatic-configure -Q -q -r");
47 doc.setContent(&proc);
48 QDomElement docElem = doc.documentElement();
49 if (docElem.isNull() || docElem.tagName() !=
"queues")
52 QDomNode queueNode = docElem.firstChild();
53 while (!queueNode.isNull())
55 QDomElement queueElem = queueNode.toElement();
56 if (!queueElem.isNull() && queueElem.tagName() ==
"queue")
58 KMPrinter *printer = createPrinterFromElement(&queueElem);
62 queueNode = queueNode.nextSibling();
66 DrMain* KMFoomaticManager::loadPrinterDriver(KMPrinter *printer,
bool)
68 if (printer->option(
"foomatic") !=
"1")
70 setErrorMsg(i18n(
"This is not a Foomatic printer"));
73 else if (printer->option(
"driver").isEmpty() || printer->option(
"printer").isEmpty())
75 setErrorMsg(i18n(
"Some printer information are missing"));
79 TQString cmd =
"foomatic-combo-xml -p ";
80 cmd += TDEProcess::quote(printer->option(
"printer"));
82 cmd += TDEProcess::quote(printer->option(
"driver"));
83 KPipeProcess proc(cmd);
85 doc.setContent(&proc);
86 QDomElement docElem = doc.documentElement();
87 return createDriverFromXML(&docElem);
90 KMPrinter* KMFoomaticManager::createPrinterFromElement(TQDomElement *elem)
92 QDomElement e = elem->namedItem(
"name").toElement();
95 KMPrinter *printer =
new KMPrinter;
96 printer->setType(KMPrinter::Printer);
97 printer->setName(e.text());
98 printer->setPrinterName(e.text());
99 printer->setState(KMPrinter::Idle);
109 if (!(e=elem->namedItem(
"description").toElement()).isNull())
110 printer->setDescription(e.text());
111 if (!(e=elem->namedItem(
"location").toElement()).isNull())
112 printer->setLocation(e.text());
113 if (!(e=elem->namedItem(
"connect").toElement()).isNull())
114 printer->setDevice(e.text());
116 printer->setOption(
"foomatic", elem->attribute(
"foomatic"));
117 printer->setOption(
"spooler", elem->attribute(
"spooler"));
118 if (elem->attribute(
"foomatic") ==
"1")
120 if (!(e=elem->namedItem(
"printer").toElement()).isNull())
121 printer->setOption(
"printer", e.text());
122 if (!(e=elem->namedItem(
"driver").toElement()).isNull())
123 printer->setOption(
"driver", e.text());
131 DrMain* KMFoomaticManager::createDriverFromXML(TQDomElement *elem)
133 DrMain *driver =
new DrMain();
134 QDomElement pelem = elem->namedItem(
"printer").toElement(), delem = elem->namedItem(
"driver").toElement();
135 if (!pelem.isNull() && !delem.isNull())
137 driver->set(
"manufacturer", pelem.namedItem(
"make").toElement().text());
138 driver->set(
"model", pelem.namedItem(
"model").toElement().text());
139 TQString s = TQString::fromLatin1(
"%1 %2 (%3)").arg(driver->get(
"manufacturer")).arg(driver->get(
"model")).arg(delem.namedItem(
"name").toElement().text());
140 driver->set(
"description", s);
141 driver->set(
"text", s);
143 QDomElement opts = elem->namedItem(
"options").toElement();
146 QDomElement o = opts.firstChild().toElement();
149 if (o.tagName() ==
"option")
151 TQString type = o.attribute(
"type");
154 if (type ==
"bool" || type ==
"enum")
156 if (type ==
"bool") dropt =
new DrBooleanOption();
157 else dropt =
new DrListOption();
158 TQString defval = o.namedItem(
"arg_defval").toElement().text(), valuetext;
159 QDomNode val = o.namedItem(
"enum_vals").firstChild();
160 while (!val.isNull())
162 DrBase *choice =
new DrBase();
163 choice->setName(val.namedItem(
"ev_shortname").namedItem(
"en").toElement().text());
164 choice->set(
"text", i18n(val.namedItem(
"ev_longname").namedItem(
"en").toElement().text().latin1()));
165 static_cast<DrListOption*
>(dropt)->addChoice(choice);
166 if (val.toElement().attribute(
"id") == defval)
167 valuetext = choice->name();
169 val = val.nextSibling();
171 dropt->set(
"default", valuetext);
172 dropt->setValueText(valuetext);
174 else if (type ==
"int" || type ==
"float")
176 if (type ==
"int") dropt =
new DrIntegerOption();
177 else dropt =
new DrFloatOption();
178 dropt->set(
"minval", o.namedItem(
"arg_min").toElement().text());
179 dropt->set(
"maxval", o.namedItem(
"arg_max").toElement().text());
180 TQString defval = o.namedItem(
"arg_defval").toElement().text();
181 dropt->set(
"default", defval);
182 dropt->setValueText(defval);
187 dropt->setName(o.namedItem(
"arg_shortname").namedItem(
"en").toElement().text());
188 dropt->set(
"text", i18n(o.namedItem(
"arg_longname").namedItem(
"en").toElement().text().latin1()));
189 driver->addOption(dropt);
192 o = o.nextSibling().toElement();