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

tdeprint

  • tdeprint
  • lpr
lprhandler.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 "lprhandler.h"
21 #include "kmprinter.h"
22 #include "printcapentry.h"
23 #include "kmmanager.h"
24 #include "lprsettings.h"
25 #include "driver.h"
26 
27 #include <tqfile.h>
28 #include <tqtextstream.h>
29 #include <tqvaluestack.h>
30 #include <tdelocale.h>
31 
32 #include <unistd.h>
33 
34 LprHandler::LprHandler(const TQString& name, KMManager *mgr)
35 : m_name(name), m_manager(mgr)
36 {
37 }
38 
39 LprHandler::~LprHandler()
40 {
41 }
42 
43 bool LprHandler::validate(PrintcapEntry*)
44 {
45  return true;
46 }
47 
48 KMPrinter* LprHandler::createPrinter(PrintcapEntry *entry)
49 {
50  KMPrinter *prt = new KMPrinter;
51  prt->setPrinterName(entry->name);
52  prt->setName(entry->name);
53  prt->setType(KMPrinter::Printer);
54  return prt;
55 }
56 
57 bool LprHandler::completePrinter(KMPrinter *prt, PrintcapEntry *entry, bool)
58 {
59  prt->setDescription(i18n("Unknown (unrecognized entry)"));
60  TQString val = entry->field("lp");
61  KURL uri;
62  if (!val.isEmpty() && val != "/dev/null")
63  {
64  int p = val.find('@');
65  if (p != -1)
66  {
67  prt->setLocation(i18n("Remote queue (%1) on %2").arg(val.left(p)).arg(val.mid(p+1)));
68  uri.setProtocol("lpd");
69  uri.setHost(val.mid(p+1));
70  uri.setPath("/" + val.left(p));
71  }
72  else if ((p = val.find('%')) != -1)
73  {
74  prt->setLocation(i18n("Network printer (%1)").arg("socket"));
75  uri.setProtocol("socket");
76  uri.setHost(val.left(p));
77  uri.setPort(val.mid(p+1).toInt());
78  }
79  else
80  {
81  prt->setLocation(i18n("Local printer on %1").arg(val));
82  uri.setProtocol("parallel");
83  uri.setPath(val);
84  }
85  }
86  else if (!(val = entry->field("rp")).isEmpty())
87  {
88  TQString rm = entry->has("rm") ?
89  entry->field("rm") :
90  LprSettings::self()->defaultRemoteHost();
91  prt->setLocation(i18n("Remote queue (%1) on %2").arg(val).arg(rm));
92  uri.setProtocol("lpd");
93  uri.setHost(rm);
94  uri.setPath("/" + val);
95  }
96  else
97  prt->setLocation(i18n("Unknown (unrecognized entry)"));
98  prt->setDevice(uri.url());
99  return true;
100 }
101 
102 DrMain* LprHandler::loadDriver(KMPrinter*, PrintcapEntry*, bool)
103 {
104  manager()->setErrorMsg(i18n("Unrecognized entry."));
105  return NULL;
106 }
107 
108 bool LprHandler::savePrinterDriver(KMPrinter*, PrintcapEntry*, DrMain*, bool*)
109 {
110  manager()->setErrorMsg(i18n("Unrecognized entry."));
111  return false;
112 }
113 
114 DrMain* LprHandler::loadDbDriver(const TQString&)
115 {
116  manager()->setErrorMsg(i18n("Unrecognized entry."));
117  return NULL;
118 }
119 
120 PrintcapEntry* LprHandler::createEntry(KMPrinter *prt)
121 {
122  // this default handler only supports local parallel and remote lpd URIs
123  KURL uri ( prt->device() );
124  TQString prot = uri.protocol();
125  if (!prot.isEmpty() && prot != "parallel" && prot != "file" && prot != "lpd" && prot != "socket")
126  {
127  manager()->setErrorMsg(i18n("Unsupported backend: %1.").arg(prot));
128  return NULL;
129  }
130  PrintcapEntry *entry = new PrintcapEntry;
131  entry->comment = "# Default handler";
132  if (prot == "lpd")
133  {
134  entry->addField("rm", Field::String, uri.host());
135  TQString rp = uri.path();
136  if (rp[0] == '/')
137  rp = rp.mid(1);
138  entry->addField("rp", Field::String, rp);
139  // force this entry to null (otherwise it seems it's redirected
140  // to /dev/lp0 by default)
141  entry->addField("lp", Field::String, TQString::null);
142  }
143  else if ( prot == "socket" )
144  {
145  TQString lp = uri.host();
146  if ( uri.port() == 0 )
147  lp.append( "%9100" );
148  else
149  lp.append( "%" ).append( TQString::number( uri.port() ) );
150  entry->addField("lp", Field::String, lp);
151  }
152  else
153  {
154  entry->addField("lp", Field::String, uri.path());
155  }
156  return entry;
157 }
158 
159 bool LprHandler::removePrinter(KMPrinter*, PrintcapEntry*)
160 {
161  return true;
162 }
163 
164 TQString LprHandler::printOptions(KPrinter*)
165 {
166  return TQString::null;
167 }
168 
169 void LprHandler::reset()
170 {
171 }
172 
173 DrMain* LprHandler::loadToolDriver(const TQString& filename)
174 {
175  TQFile f(filename);
176  if (f.open(IO_ReadOnly))
177  {
178  DrMain *driver = new DrMain;
179  TQValueStack<DrGroup*> groups;
180  TQTextStream t(&f);
181  TQStringList l;
182  DrListOption *lopt(0);
183  DrBase *opt(0);
184 
185  groups.push(driver);
186  driver->set("text", "Tool Driver");
187  while (!t.atEnd())
188  {
189  l = TQStringList::split('|', t.readLine().stripWhiteSpace(), false);
190  if (l.count() == 0)
191  continue;
192  if (l[0] == "GROUP")
193  {
194  DrGroup *grp = new DrGroup;
195  grp->setName(l[1]);
196  grp->set("text", l[2]);
197  groups.top()->addGroup(grp);
198  groups.push(grp);
199  }
200  else if (l[0] == "ENDGROUP")
201  {
202  groups.pop();
203  }
204  else if (l[0] == "OPTION")
205  {
206  opt = 0;
207  lopt = 0;
208  if (l.count() > 3)
209  {
210  if (l[3] == "STRING")
211  opt = new DrStringOption;
212  else if (l[3] == "BOOLEAN")
213  {
214  lopt = new DrBooleanOption;
215  opt = lopt;
216  }
217  }
218  else
219  {
220  lopt = new DrListOption;
221  opt = lopt;
222  }
223  if (opt)
224  {
225  opt->setName(l[1]);
226  opt->set("text", l[2]);
227  groups.top()->addOption(opt);
228  }
229  }
230  else if (l[0] == "CHOICE" && lopt)
231  {
232  DrBase *ch = new DrBase;
233  ch->setName(l[1]);
234  ch->set("text", l[2]);
235  lopt->addChoice(ch);
236  }
237  else if (l[0] == "DEFAULT" && opt)
238  {
239  opt->setValueText(l[1]);
240  opt->set("default", l[1]);
241  }
242  }
243  return driver;
244  }
245  return NULL;
246 }
247 
248 TQString LprHandler::driverDirectory()
249 {
250  if (m_cacheddriverdir.isEmpty())
251  m_cacheddriverdir = driverDirInternal();
252  return m_cacheddriverdir;
253 }
254 
255 TQString LprHandler::driverDirInternal()
256 {
257  return TQString::null;
258 }
259 
260 TQString LprHandler::locateDir(const TQString& dirname, const TQString& paths)
261 {
262  TQStringList pathlist = TQStringList::split(':', paths, false);
263  for (TQStringList::ConstIterator it=pathlist.begin(); it!=pathlist.end(); ++it)
264  {
265  TQString testpath = *it + "/" + dirname;
266  if (::access(TQFile::encodeName(testpath), F_OK) == 0)
267  return testpath;
268  }
269  return TQString::null;
270 }
KPrinter
This class is the main interface to access the TDE print framework.
Definition: kprinter.h:89

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.