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

tdeprint

  • tdeprint
  • lpd
lpdtools.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 "lpdtools.h"
21 #include "driver.h"
22 #include "kmprinter.h"
23 
24 #include <tqfile.h>
25 #include <tdelocale.h>
26 
27 static const char *pt_pagesize[] = {
28  "ledger", I18N_NOOP("Ledger"),
29  "legal", I18N_NOOP("US Legal"),
30  "letter", I18N_NOOP("US Letter"),
31  "a4", I18N_NOOP("A4"),
32  "a3", I18N_NOOP("A3"),
33  "b4", I18N_NOOP("B4"),
34  "b5", I18N_NOOP("B5"),
35  0
36 };
37 static int pt_nup[] = { 1, 2, 4, 8, -1 };
38 static const char *pt_bool[] = {
39  "YES", I18N_NOOP("Enabled"),
40  "NO", I18N_NOOP("Disabled"),
41  0
42 };
43 
44 void setupBooleanOption(DrBooleanOption *opt)
45 {
46  int i(0);
47  while (pt_bool[i])
48  {
49  DrBase *ch = new DrBase();
50  ch->setName(pt_bool[i++]);
51  ch->set("text",pt_bool[i++]);
52  opt->addChoice(ch);
53  }
54 }
55 
56 TQString nextWord(const TQString& s, int& pos)
57 {
58  int p1(pos), p2(0);
59  while (s[p1].isSpace() && p1 < (int)s.length()) p1++;
60  if (s[p1] == '{')
61  {
62  p1++;
63  p2 = s.find('}',p1);
64  }
65  else
66  {
67  p2 = p1;
68  while (!s[p2].isSpace() && p2 < (int)s.length()) p2++;
69  }
70  pos = (p2+1);
71  return s.mid(p1,p2-p1);
72 }
73 
74 //************************************************************************************************
75 
76 bool PrintcapEntry::readLine(const TQString& line)
77 {
78  QStringList l = TQStringList::split(':',line,false);
79  if (l.count() > 0)
80  {
81  m_name = l[0];
82  int p(-1);
83  // discard aliases
84  if ((p=m_name.find('|')) != -1)
85  m_name = m_name.left(p);
86  m_args.clear();
87  for (uint i=1; i<l.count(); i++)
88  {
89  int p = l[i].find('=');
90  if (p == -1) p = 2;
91  QString key = l[i].left(p);
92  QString value = l[i].right(l[i].length()-(l[i][p] == '=' ? p+1 : p));
93  m_args[key] = value;
94  }
95  return true;
96  }
97  return false;
98 }
99 
100 void PrintcapEntry::writeEntry(TQTextStream& t)
101 {
102  if (m_comment.isEmpty()) t << "# Entry for printer " << m_name << endl;
103  else t << m_comment << endl;
104  t << m_name << ":";
105  for (TQMap<TQString,TQString>::ConstIterator it=m_args.begin(); it!=m_args.end(); ++it)
106  {
107  t << "\\\n\t:" << it.key();
108  if (!it.data().isEmpty())
109  t << ((*it)[0] == '#' ? "" : "=") << *it;
110  t << ":";
111  }
112  t << endl << endl;
113 }
114 
115 TQString PrintcapEntry::comment(int index)
116 {
117  QString w;
118  if (m_comment.startsWith("##PRINTTOOL3##"))
119  {
120  int p(0);
121  for (int i=0;i<index;i++)
122  w = nextWord(m_comment,p);
123  }
124  return w;
125 }
126 
127 KMPrinter* PrintcapEntry::createPrinter()
128 {
129  KMPrinter *printer = new KMPrinter();
130  printer->setName(m_name);
131  printer->setPrinterName(m_name);
132  printer->setInstanceName(TQString::null);
133  printer->setState(KMPrinter::Idle);
134  printer->setType(KMPrinter::Printer);
135  return printer;
136 }
137 
138 //************************************************************************************************
139 
140 TQStringList splitPrinttoolLine(const TQString& line)
141 {
142  QStringList l;
143  int p = line.find(':');
144  if (p != -1)
145  {
146  l.append(line.left(p));
147  p = line.find('{',p);
148  if (p == -1)
149  l.append(line.right(line.length()-l[0].length()-1).stripWhiteSpace());
150  else
151  {
152  while (p != -1)
153  {
154  int q = line.find('}',p);
155  if (q != -1)
156  {
157  l.append(line.mid(p+1,q-p-1));
158  p = line.find('{',q);
159  }
160  else break;
161  }
162  }
163  }
164  return l;
165 }
166 
167 bool PrinttoolEntry::readEntry(TQTextStream& t)
168 {
169  QString line;
170  QStringList args;
171 
172  m_resolutions.setAutoDelete(true);
173  m_depths.setAutoDelete(true);
174  m_resolutions.clear();
175  m_depths.clear();
176  while (!t.eof())
177  {
178  line = getPrintcapLine(t);
179  if (line.isEmpty())
180  break;
181  if (line == "EndEntry")
182  return !m_name.isEmpty();
183  QStringList l = splitPrinttoolLine(line);
184  if (l.count() > 1)
185  {
186  if (l[0] == "StartEntry") m_name = l[1];
187  else if (l[0] == "GSDriver") m_gsdriver = l[1];
188  else if (l[0] == "About") m_about = l[1];
189  else if (l[0] == "Description") m_description = l[1];
190  else if (l[0] == "Resolution" && l.count() > 2)
191  {
192  Resolution *resol = new Resolution;
193  bool ok(false);
194  resol->xdpi = l[1].toInt(&ok);
195  if (ok) resol->ydpi = l[2].toInt(&ok);
196  if (l.count() > 3)
197  resol->comment = l[3];
198  if (ok) m_resolutions.append(resol);
199  else delete resol;
200  }
201  else if (l[0] == "BitsPerPixel" && l.count() > 1)
202  {
203  BitsPerPixel *dpth = new BitsPerPixel;
204  dpth->bpp = l[1];
205  if (l.count() > 2)
206  dpth->comment = l[2];
207  m_depths.append(dpth);
208  }
209  }
210  }
211  return false;
212 }
213 
214 DrMain* PrinttoolEntry::createDriver()
215 {
216  // create driver
217  DrMain *dr = new DrMain();
218  dr->setName(m_name);
219  dr->set("description",m_description);
220  dr->set("text",m_description);
221  dr->set("drtype","printtool");
222 
223  DrGroup *gr(0);
224  DrListOption *lopt(0);
225  DrStringOption *sopt(0);
226  DrBooleanOption *bopt(0);
227  DrBase *ch(0);
228 
229  if (m_gsdriver != "TEXT")
230  {
231  // create GS group
232  gr = new DrGroup();
233  gr->set("text",i18n("GhostScript settings"));
234  dr->addGroup(gr);
235 
236  // Pseudo option to have access to GS driver
237  lopt = new DrListOption();
238  lopt->setName("GSDEVICE");
239  lopt->set("text",i18n("Driver"));
240  lopt->set("default",m_gsdriver);
241  gr->addOption(lopt);
242  ch = new DrBase();
243  ch->setName(m_gsdriver);
244  ch->set("text",m_gsdriver);
245  lopt->addChoice(ch);
246  lopt->setValueText(m_gsdriver);
247 
248 
249  // Resolutions
250  if (m_resolutions.count() > 0)
251  {
252  lopt = new DrListOption();
253  lopt->setName("RESOLUTION");
254  lopt->set("text",i18n("Resolution"));
255  gr->addOption(lopt);
256  TQPtrListIterator<Resolution> it(m_resolutions);
257  for (int i=0;it.current();++it,i++)
258  {
259  ch = new DrBase;
260  ch->setName(TQString::fromLatin1("%1x%2").arg(it.current()->xdpi).arg(it.current()->ydpi));
261  if (it.current()->comment.isEmpty())
262  ch->set("text",TQString::fromLatin1("%1x%2 DPI").arg(it.current()->xdpi).arg(it.current()->ydpi));
263  else
264  ch->set("text",TQString::fromLatin1("%2x%3 DPI (%1)").arg(it.current()->comment).arg(it.current()->xdpi).arg(it.current()->ydpi));
265  lopt->addChoice(ch);
266  }
267  QString defval = lopt->choices()->first()->name();
268  lopt->set("default",defval);
269  lopt->setValueText(defval);
270  }
271 
272  // BitsPerPixels
273  if (m_depths.count() > 0)
274  {
275  lopt = new DrListOption();
276  lopt->setName("COLOR");
277  lopt->set("text",i18n("Color depth"));
278  gr->addOption(lopt);
279  TQPtrListIterator<BitsPerPixel> it(m_depths);
280  for (int i=0;it.current();++it,i++)
281  {
282  ch = new DrBase;
283  if (m_gsdriver != "uniprint")
284  ch->setName(TQString::fromLatin1("-dBitsPerPixel=%1").arg(it.current()->bpp));
285  else
286  ch->setName(it.current()->bpp);
287  if (it.current()->comment.isEmpty())
288  ch->set("text",it.current()->bpp);
289  else
290  ch->set("text",TQString::fromLatin1("%1 - %2").arg(it.current()->bpp).arg(it.current()->comment));
291  lopt->addChoice(ch);
292  }
293  QString defval = lopt->choices()->first()->name();
294  lopt->set("default",defval);
295  lopt->setValueText(defval);
296  }
297 
298  // additional GS options
299  sopt = new DrStringOption;
300  sopt->setName("EXTRA_GS_OPTIONS");
301  sopt->set("text",i18n("Additional GS options"));
302  gr->addOption(sopt);
303  }
304 
305  // General group
306  gr = new DrGroup();
307  gr->set("text",i18n("General"));
308  dr->addGroup(gr);
309 
310  // Page size
311  lopt = new DrListOption();
312  lopt->setName("PAPERSIZE");
313  lopt->set("text",i18n("Page size"));
314  lopt->set("default","letter");
315  gr->addOption(lopt);
316  int i(0);
317  while (pt_pagesize[i])
318  {
319  ch = new DrBase();
320  ch->setName(pt_pagesize[i++]);
321  ch->set("text",i18n(pt_pagesize[i++]));
322  lopt->addChoice(ch);
323  }
324  lopt->setValueText("letter");
325 
326  // Nup
327  lopt = new DrListOption();
328  lopt->setName("NUP");
329  lopt->set("text",i18n("Pages per sheet"));
330  lopt->set("default","1");
331  gr->addOption(lopt);
332  i = 0;
333  while (pt_nup[i] != -1)
334  {
335  ch = new DrBase();
336  ch->setName(TQString::number(pt_nup[i++]));
337  ch->set("text",ch->name());
338  lopt->addChoice(ch);
339  }
340  lopt->setValueText("1");
341 
342  // Margins
343  sopt = new DrStringOption();
344  sopt->setName("RTLFTMAR");
345  sopt->set("text",i18n("Left/right margin (1/72 in)"));
346  sopt->setValueText("18");
347  gr->addOption(sopt);
348  sopt = new DrStringOption();
349  sopt->setName("TOPBOTMAR");
350  sopt->set("text",i18n("Top/bottom margin (1/72 in)"));
351  sopt->setValueText("18");
352  gr->addOption(sopt);
353 
354  // Text group
355  gr = new DrGroup();
356  gr->set("text",i18n("Text options"));
357  dr->addGroup(gr);
358 
359  // Send EOF
360  bopt = new DrBooleanOption();
361  bopt->setName("TEXT_SEND_EOF");
362  bopt->set("text",i18n("Send EOF after job to eject page"));
363  gr->addOption(bopt);
364  setupBooleanOption(bopt);
365  bopt->setValueText("NO");
366 
367  // Fix stair-stepping
368  bopt = new DrBooleanOption();
369  bopt->setName("CRLFTRANS");
370  bopt->set("text",i18n("Fix stair-stepping text"));
371  gr->addOption(bopt);
372  setupBooleanOption(bopt);
373  bopt->choices()->first()->setName("1");
374  bopt->choices()->last()->setName("0");
375  bopt->setValueText("0");
376 
377  if (m_gsdriver != "POSTSCRIPT")
378  {
379  // Fast text printing
380  bopt = new DrBooleanOption();
381  bopt->setName("ASCII_TO_PS");
382  bopt->set("text",i18n("Fast text printing (non-PS printers only)"));
383  gr->addOption(bopt);
384  setupBooleanOption(bopt);
385  bopt->choices()->first()->setName("NO");
386  bopt->choices()->last()->setName("YES");
387  bopt->setValueText("NO");
388  }
389 
390  return dr;
391 }
392 
393 //************************************************************************************************
394 
395 TQString getPrintcapLine(TQTextStream& t, TQString *lastcomment)
396 {
397  QString line, buffer, comm;
398  while (!t.eof())
399  {
400  buffer = t.readLine().stripWhiteSpace();
401  if (buffer.isEmpty() || buffer[0] == '#')
402  {
403  comm = buffer;
404  continue;
405  }
406  line.append(buffer);
407  if (line.right(1) == "\\")
408  {
409  line.truncate(line.length()-1);
410  line = line.stripWhiteSpace();
411  }
412  else break;
413  }
414  if (lastcomment)
415  *lastcomment = comm;
416  return line;
417 }

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
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeprint by doxygen 1.8.8
This website is maintained by Timothy Pearson.