You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
198 lines
6.2 KiB
198 lines
6.2 KiB
15 years ago
|
/*
|
||
|
* This file is part of the KDE libraries
|
||
13 years ago
|
* Copyright (c) 2001 Michael Goffioul <tdeprint@swing.be>
|
||
15 years ago
|
*
|
||
|
* This library is free software; you can redistribute it and/or
|
||
|
* modify it under the terms of the GNU Library General Public
|
||
|
* License version 2 as published by the Free Software Foundation.
|
||
|
*
|
||
|
* This library is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
* Library General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU Library General Public License
|
||
|
* along with this library; see the file COPYING.LIB. If not, write to
|
||
|
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
* Boston, MA 02110-1301, USA.
|
||
|
**/
|
||
|
|
||
|
#include "kmfoomaticmanager.h"
|
||
|
#include "kpipeprocess.h"
|
||
|
#include "driver.h"
|
||
|
|
||
15 years ago
|
#include <tqdom.h>
|
||
15 years ago
|
#include <klocale.h>
|
||
|
#include <kdebug.h>
|
||
|
#include <kprocess.h>
|
||
|
|
||
|
#include <unistd.h>
|
||
|
|
||
15 years ago
|
KMFoomaticManager::KMFoomaticManager(TQObject *parent, const char *name, const TQStringList & /*args*/)
|
||
15 years ago
|
: KMManager(parent,name)
|
||
|
{
|
||
|
setHasManagement(getuid() == 0);
|
||
|
setPrinterOperationMask(KMManager::PrinterConfigure);
|
||
|
}
|
||
|
|
||
|
KMFoomaticManager::~KMFoomaticManager()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
void KMFoomaticManager::listPrinters()
|
||
|
{
|
||
|
KPipeProcess proc("foomatic-configure -Q -q -r");
|
||
|
QDomDocument doc;
|
||
|
|
||
|
doc.setContent(&proc);
|
||
|
QDomElement docElem = doc.documentElement();
|
||
|
if (docElem.isNull() || docElem.tagName() != "queues")
|
||
|
return;
|
||
|
|
||
|
QDomNode queueNode = docElem.firstChild();
|
||
|
while (!queueNode.isNull())
|
||
|
{
|
||
|
QDomElement queueElem = queueNode.toElement();
|
||
|
if (!queueElem.isNull() && queueElem.tagName() == "queue")
|
||
|
{
|
||
|
KMPrinter *printer = createPrinterFromElement(&queueElem);
|
||
|
if (printer)
|
||
|
addPrinter(printer);
|
||
|
}
|
||
|
queueNode = queueNode.nextSibling();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
DrMain* KMFoomaticManager::loadPrinterDriver(KMPrinter *printer, bool)
|
||
|
{
|
||
|
if (printer->option("foomatic") != "1")
|
||
|
{
|
||
|
setErrorMsg(i18n("This is not a Foomatic printer"));
|
||
|
return NULL;
|
||
|
}
|
||
|
else if (printer->option("driver").isEmpty() || printer->option("printer").isEmpty())
|
||
|
{
|
||
|
setErrorMsg(i18n("Some printer information are missing"));
|
||
|
return NULL;
|
||
|
}
|
||
|
|
||
|
QString cmd = "foomatic-combo-xml -p ";
|
||
|
cmd += KProcess::quote(printer->option("printer"));
|
||
|
cmd += " -d ";
|
||
|
cmd += KProcess::quote(printer->option("driver"));
|
||
|
KPipeProcess proc(cmd);
|
||
|
QDomDocument doc;
|
||
|
doc.setContent(&proc);
|
||
|
QDomElement docElem = doc.documentElement();
|
||
|
return createDriverFromXML(&docElem);
|
||
|
}
|
||
|
|
||
15 years ago
|
KMPrinter* KMFoomaticManager::createPrinterFromElement(TQDomElement *elem)
|
||
15 years ago
|
{
|
||
|
QDomElement e = elem->namedItem("name").toElement();
|
||
|
if (!e.isNull())
|
||
|
{
|
||
|
KMPrinter *printer = new KMPrinter;
|
||
|
printer->setType(KMPrinter::Printer);
|
||
|
printer->setName(e.text());
|
||
|
printer->setPrinterName(e.text());
|
||
|
printer->setState(KMPrinter::Idle);
|
||
13 years ago
|
/*if (printer->name().find('/') != -1)
|
||
15 years ago
|
{
|
||
|
QString s(printer->name());
|
||
13 years ago
|
int p = s.find('/');
|
||
15 years ago
|
printer->setPrinterName(s.left(p));
|
||
|
printer->setInstanceName(s.mid(p+1));
|
||
|
printer->addType(KMPrinter::Virtual);
|
||
|
}*/
|
||
|
|
||
|
if (!(e=elem->namedItem("description").toElement()).isNull())
|
||
|
printer->setDescription(e.text());
|
||
|
if (!(e=elem->namedItem("location").toElement()).isNull())
|
||
|
printer->setLocation(e.text());
|
||
|
if (!(e=elem->namedItem("connect").toElement()).isNull())
|
||
|
printer->setDevice(e.text());
|
||
|
|
||
|
printer->setOption("foomatic", elem->attribute("foomatic"));
|
||
|
printer->setOption("spooler", elem->attribute("spooler"));
|
||
|
if (elem->attribute("foomatic") == "1")
|
||
|
{
|
||
|
if (!(e=elem->namedItem("printer").toElement()).isNull())
|
||
|
printer->setOption("printer", e.text());
|
||
|
if (!(e=elem->namedItem("driver").toElement()).isNull())
|
||
|
printer->setOption("driver", e.text());
|
||
|
}
|
||
|
|
||
|
return printer;
|
||
|
}
|
||
|
return NULL;
|
||
|
}
|
||
|
|
||
15 years ago
|
DrMain* KMFoomaticManager::createDriverFromXML(TQDomElement *elem)
|
||
15 years ago
|
{
|
||
|
DrMain *driver = new DrMain();
|
||
|
QDomElement pelem = elem->namedItem("printer").toElement(), delem = elem->namedItem("driver").toElement();
|
||
|
if (!pelem.isNull() && !delem.isNull())
|
||
|
{
|
||
|
driver->set("manufacturer", pelem.namedItem("make").toElement().text());
|
||
|
driver->set("model", pelem.namedItem("model").toElement().text());
|
||
14 years ago
|
QString s = TQString::tqfromLatin1("%1 %2 (%3)").arg(driver->get("manufacturer")).arg(driver->get("model")).arg(delem.namedItem("name").toElement().text());
|
||
15 years ago
|
driver->set("description", s);
|
||
|
driver->set("text", s);
|
||
|
|
||
|
QDomElement opts = elem->namedItem("options").toElement();
|
||
|
if (!opts.isNull())
|
||
|
{
|
||
|
QDomElement o = opts.firstChild().toElement();
|
||
|
while (!o.isNull())
|
||
|
{
|
||
|
if (o.tagName() == "option")
|
||
|
{
|
||
|
QString type = o.attribute("type");
|
||
|
DrBase *dropt(0);
|
||
|
|
||
|
if (type == "bool" || type == "enum")
|
||
|
{
|
||
|
if (type == "bool") dropt = new DrBooleanOption();
|
||
|
else dropt = new DrListOption();
|
||
|
QString defval = o.namedItem("arg_defval").toElement().text(), valuetext;
|
||
|
QDomNode val = o.namedItem("enum_vals").firstChild();
|
||
|
while (!val.isNull())
|
||
|
{
|
||
|
DrBase *choice = new DrBase();
|
||
|
choice->setName(val.namedItem("ev_shortname").namedItem("en").toElement().text());
|
||
|
choice->set("text", i18n(val.namedItem("ev_longname").namedItem("en").toElement().text().latin1()));
|
||
|
static_cast<DrListOption*>(dropt)->addChoice(choice);
|
||
|
if (val.toElement().attribute("id") == defval)
|
||
|
valuetext = choice->name();
|
||
|
|
||
|
val = val.nextSibling();
|
||
|
}
|
||
|
dropt->set("default", valuetext);
|
||
|
dropt->setValueText(valuetext);
|
||
|
}
|
||
|
else if (type == "int" || type == "float")
|
||
|
{
|
||
|
if (type == "int") dropt = new DrIntegerOption();
|
||
|
else dropt = new DrFloatOption();
|
||
|
dropt->set("minval", o.namedItem("arg_min").toElement().text());
|
||
|
dropt->set("maxval", o.namedItem("arg_max").toElement().text());
|
||
|
QString defval = o.namedItem("arg_defval").toElement().text();
|
||
|
dropt->set("default", defval);
|
||
|
dropt->setValueText(defval);
|
||
|
}
|
||
|
|
||
|
if (dropt)
|
||
|
{
|
||
|
dropt->setName(o.namedItem("arg_shortname").namedItem("en").toElement().text());
|
||
|
dropt->set("text", i18n(o.namedItem("arg_longname").namedItem("en").toElement().text().latin1()));
|
||
|
driver->addOption(dropt);
|
||
|
}
|
||
|
}
|
||
|
o = o.nextSibling().toElement();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
return driver;
|
||
|
}
|