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

tdeprint

  • tdeprint
  • rlpr
kmrlprmanager.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 "kmrlprmanager.h"
21 #include "kmprinter.h"
22 
23 #include <tqfile.h>
24 #include <tqfileinfo.h>
25 #include <tqtextstream.h>
26 #include <tqmap.h>
27 
28 #include <kstandarddirs.h>
29 #include <tdelocale.h>
30 
31 KMRlprManager::KMRlprManager(TQObject *parent, const char *name, const TQStringList & /*args*/)
32 : KMManager(parent,name)
33 {
34  setHasManagement(true);
35  setPrinterOperationMask(KMManager::PrinterCreation|KMManager::PrinterRemoval|KMManager::PrinterTesting);
36 }
37 
38 KMRlprManager::~KMRlprManager()
39 {
40 }
41 
42 bool KMRlprManager::createPrinter(KMPrinter *p)
43 {
44  if (p->name().isEmpty())
45  setErrorMsg(i18n("Empty printer name."));
46  else if (p->option("host").isEmpty())
47  setErrorMsg(i18n("Empty host name."));
48  else if (p->option("queue").isEmpty())
49  setErrorMsg(i18n("Empty queue name."));
50  else
51  {
52  KMPrinter *pr = new KMPrinter(*p);
53  addPrinter(pr);
54  savePrinters();
55  return true;
56  }
57  return false;
58 }
59 
60 bool KMRlprManager::removePrinter(KMPrinter *p)
61 {
62  if (m_printers.findRef(p) == -1)
63  setErrorMsg(i18n("Printer not found."));
64  else
65  {
66  m_printers.removeRef(p);
67  savePrinters();
68  return true;
69  }
70  return false;
71 }
72 
73 bool KMRlprManager::testPrinter(KMPrinter *)
74 {
75  setErrorMsg(i18n("Not implemented yet."));
76  return false;
77 }
78 
79 void KMRlprManager::listPrinters()
80 {
81  TQFileInfo pfi(printerFile());
82  if (pfi.exists() && (!m_checktime.isValid() || m_checktime < pfi.lastModified()))
83  {
84  loadPrintersConf(pfi.absFilePath());
85  m_checktime = pfi.lastModified();
86  }
87  else
88  discardAllPrinters(false);
89 }
90 
91 void KMRlprManager::loadPrintersConf(const TQString& filename)
92 {
93  TQFile f(filename);
94  if (f.exists() && f.open(IO_ReadOnly))
95  {
96  TQTextStream t(&f);
97  TQString line;
98  while (!t.eof())
99  {
100  line = t.readLine().stripWhiteSpace();
101  if (line.isEmpty() || line[0] == '#')
102  continue;
103  TQStringList w = TQStringList::split('\t',line,true);
104  if (w.count() < 3)
105  continue;
106 
107  KMPrinter *printer = new KMPrinter;
108  printer->setName(w[0]);
109  printer->setPrinterName(w[0]);
110  printer->setType(KMPrinter::Printer);
111  printer->setOption("host",w[1]);
112  printer->setOption("queue",w[2]);
113  if (w.count() > 3)
114  {
115  printer->setDescription(w[3]);
116  if (w.count() > 4) printer->setLocation(w[4]);
117  }
118  printer->setState(KMPrinter::Idle);
119  printer->setDevice(TQString::fromLatin1("lpd://%1/%2").arg(w[1]).arg(w[2]));
120 
121  addPrinter(printer);
122  }
123  }
124 }
125 
126 void KMRlprManager::savePrinters()
127 {
128  savePrintersConf(printerFile());
129 }
130 
131 void KMRlprManager::savePrintersConf(const TQString& filename)
132 {
133  TQFile f(filename);
134  if (f.open(IO_WriteOnly))
135  {
136  TQTextStream t(&f);
137  t << "# File generated by TDE print system. Don't edit by hand." << endl;
138  TQPtrListIterator<KMPrinter> it(m_printers);
139  for (;it.current();++it)
140  {
141  if (!it.current()->name().isEmpty() && it.current()->instanceName().isEmpty())
142  {
143  TQString host = it.current()->option("host");
144  TQString queue = it.current()->option("queue");
145  if (!host.isEmpty() && !queue.isEmpty())
146  {
147  t << it.current()->name() << '\t' << host << '\t' << queue;
148  t << '\t' << it.current()->description() << '\t' << it.current()->location() << endl;
149  }
150  }
151  }
152  }
153 }
154 
155 TQString KMRlprManager::printerFile()
156 {
157  return locateLocal("data","tdeprint/printers.conf");
158 }

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.