• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeprint
 

tdeprint

  • tdeprint
  • foomatic
kmfoomaticmanager.cpp
1 /*
2  * This file is part of the KDE libraries
3  * Copyright (c) 2001 Michael Goffioul <tdeprint@swing.be>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License version 2 as published by the Free Software Foundation.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public License
15  * along with this library; see the file COPYING.LIB. If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  **/
19 
20 #include "kmfoomaticmanager.h"
21 #include "kpipeprocess.h"
22 #include "driver.h"
23 
24 #include <tqdom.h>
25 #include <tdelocale.h>
26 #include <kdebug.h>
27 #include <tdeprocess.h>
28 
29 #include <unistd.h>
30 
31 KMFoomaticManager::KMFoomaticManager(TQObject *parent, const char *name, const TQStringList & /*args*/)
32 : KMManager(parent,name)
33 {
34  setHasManagement(getuid() == 0);
35  setPrinterOperationMask(KMManager::PrinterConfigure);
36 }
37 
38 KMFoomaticManager::~KMFoomaticManager()
39 {
40 }
41 
42 void KMFoomaticManager::listPrinters()
43 {
44  KPipeProcess proc("foomatic-configure -Q -q -r");
45  QDomDocument doc;
46 
47  doc.setContent(&proc);
48  QDomElement docElem = doc.documentElement();
49  if (docElem.isNull() || docElem.tagName() != "queues")
50  return;
51 
52  QDomNode queueNode = docElem.firstChild();
53  while (!queueNode.isNull())
54  {
55  QDomElement queueElem = queueNode.toElement();
56  if (!queueElem.isNull() && queueElem.tagName() == "queue")
57  {
58  KMPrinter *printer = createPrinterFromElement(&queueElem);
59  if (printer)
60  addPrinter(printer);
61  }
62  queueNode = queueNode.nextSibling();
63  }
64 }
65 
66 DrMain* KMFoomaticManager::loadPrinterDriver(KMPrinter *printer, bool)
67 {
68  if (printer->option("foomatic") != "1")
69  {
70  setErrorMsg(i18n("This is not a Foomatic printer"));
71  return NULL;
72  }
73  else if (printer->option("driver").isEmpty() || printer->option("printer").isEmpty())
74  {
75  setErrorMsg(i18n("Some printer information are missing"));
76  return NULL;
77  }
78 
79  TQString cmd = "foomatic-combo-xml -p ";
80  cmd += TDEProcess::quote(printer->option("printer"));
81  cmd += " -d ";
82  cmd += TDEProcess::quote(printer->option("driver"));
83  KPipeProcess proc(cmd);
84  QDomDocument doc;
85  doc.setContent(&proc);
86  QDomElement docElem = doc.documentElement();
87  return createDriverFromXML(&docElem);
88 }
89 
90 KMPrinter* KMFoomaticManager::createPrinterFromElement(TQDomElement *elem)
91 {
92  QDomElement e = elem->namedItem("name").toElement();
93  if (!e.isNull())
94  {
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);
100  /*if (printer->name().find('/') != -1)
101  {
102  TQString s(printer->name());
103  int p = s.find('/');
104  printer->setPrinterName(s.left(p));
105  printer->setInstanceName(s.mid(p+1));
106  printer->addType(KMPrinter::Virtual);
107  }*/
108 
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());
115 
116  printer->setOption("foomatic", elem->attribute("foomatic"));
117  printer->setOption("spooler", elem->attribute("spooler"));
118  if (elem->attribute("foomatic") == "1")
119  {
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());
124  }
125 
126  return printer;
127  }
128  return NULL;
129 }
130 
131 DrMain* KMFoomaticManager::createDriverFromXML(TQDomElement *elem)
132 {
133  DrMain *driver = new DrMain();
134  QDomElement pelem = elem->namedItem("printer").toElement(), delem = elem->namedItem("driver").toElement();
135  if (!pelem.isNull() && !delem.isNull())
136  {
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);
142 
143  QDomElement opts = elem->namedItem("options").toElement();
144  if (!opts.isNull())
145  {
146  QDomElement o = opts.firstChild().toElement();
147  while (!o.isNull())
148  {
149  if (o.tagName() == "option")
150  {
151  TQString type = o.attribute("type");
152  DrBase *dropt(0);
153 
154  if (type == "bool" || type == "enum")
155  {
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())
161  {
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();
168 
169  val = val.nextSibling();
170  }
171  dropt->set("default", valuetext);
172  dropt->setValueText(valuetext);
173  }
174  else if (type == "int" || type == "float")
175  {
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);
183  }
184 
185  if (dropt)
186  {
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);
190  }
191  }
192  o = o.nextSibling().toElement();
193  }
194  }
195  }
196  return driver;
197 }

tdeprint

Skip menu "tdeprint"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

tdeprint

Skip menu "tdeprint"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeprint by doxygen 1.9.1
This website is maintained by Timothy Pearson.