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

tdeprint

  • tdeprint
kmspecialmanager.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 "kmspecialmanager.h"
21#include "kmmanager.h"
22#include "kmprinter.h"
23#include "tdeprintcheck.h"
24#include "kxmlcommand.h"
25#include "driver.h"
26
27#include <tqfile.h>
28#include <tdestandarddirs.h>
29#include <tdeglobal.h>
30#include <ksimpleconfig.h>
31#include <tdelocale.h>
32#include <kdebug.h>
33
34#include <unistd.h>
35#include <sys/types.h>
36#include <sys/stat.h>
37
38KMSpecialManager::KMSpecialManager(KMManager *parent, const char *name)
39: TQObject(parent,name), m_mgr(parent), m_loaded(false)
40{
41}
42
43bool KMSpecialManager::savePrinters()
44{
45 // for root, use a global location.
46 TQString confname;
47 if (getuid() == 0)
48 {
49 confname = locate("data", "tdeprint/specials.desktop");
50 if (confname.startsWith(TDEGlobal::dirs()->localtdedir()))
51 {
52 // seems there's a problem here
53 m_mgr->setErrorMsg(i18n("A file share/tdeprint/specials.desktop was found in your "
54 "local TDE directory. This file probably comes from a previous TDE "
55 "release and should be removed in order to manage global pseudo "
56 "printers."));
57 return false;
58 }
59 }
60 else
61 confname = locateLocal("data","tdeprint/specials.desktop");
62
63 KSimpleConfig conf(confname);
64
65 // first clear existing groups
66 conf.setGroup("General");
67 int n = conf.readNumEntry("Number",0);
68 for (int i=0;i<n;i++)
69 conf.deleteGroup(TQString::fromLatin1("Printer %1").arg(i),true);
70
71 // then add printers
72 n = 0;
73 TQPtrListIterator<KMPrinter> it(m_mgr->m_printers);
74 for (;it.current();++it)
75 {
76 if (!it.current()->isSpecial() || it.current()->isVirtual()) continue;
77 conf.setGroup(TQString::fromLatin1("Printer %1").arg(n));
78 conf.writeEntry("Name",it.current()->name());
79 conf.writeEntry("Description",it.current()->description());
80 conf.writeEntry("Comment",it.current()->location());
81 conf.writePathEntry("Command",it.current()->option("kde-special-command"));
82 conf.writePathEntry("File",it.current()->option("kde-special-file"));
83 conf.writeEntry("Icon",it.current()->pixmap());
84 conf.writeEntry("Extension",it.current()->option("kde-special-extension"));
85 conf.writeEntry("Mimetype",it.current()->option("kde-special-mimetype"));
86 conf.writeEntry("Require",it.current()->option("kde-special-require"));
87 n++;
88 }
89 conf.setGroup("General");
90 conf.writeEntry("Number",n);
91
92 // set read access for anybody in case of global location
93 if (getuid() == 0)
94 {
95 conf.sync();
96 ::chmod(TQFile::encodeName(confname), S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
97 }
98
99 // force reload on next update
100 m_loaded = false;
101
102 return true;
103}
104
105bool KMSpecialManager::loadPrinters()
106{
107 if (m_loaded) return true;
108
109 bool result(true);
110 TQString localDir = TDEGlobal::dirs()->localtdedir();
111 TQStringList files = TDEGlobal::dirs()->findAllResources("data", "tdeprint/specials.desktop");
112 // local files should processed last, so we need to reorder the list
113 // and put local files at the end
114 TQStringList orderedFiles;
115 for (TQStringList::ConstIterator it=files.begin(); it!=files.end(); ++it)
116 {
117 if ((*it).startsWith(localDir))
118 orderedFiles.append(*it);
119 else
120 orderedFiles.prepend(*it);
121 }
122 // then parse the ordered list
123 for (TQStringList::ConstIterator it=orderedFiles.begin(); it!=orderedFiles.end() && result; ++it)
124 {
125 // skip the local file for root
126 if (getuid() == 0 && (*it).startsWith(localDir))
127 break;
128 else
129 result = loadDesktopFile(*it);
130 }
131
132 return result;
133}
134
135bool KMSpecialManager::loadDesktopFile(const TQString& filename)
136{
137 KSimpleConfig conf(filename);
138 conf.setGroup("General");
139 int n = conf.readNumEntry("Number",0);
140 for (int i=0;i<n;i++)
141 {
142 TQString grpname = TQString::fromLatin1("Printer %1").arg(i);
143 if (!conf.hasGroup(grpname)) continue;
144 conf.setGroup(grpname);
145 KMPrinter *printer = new KMPrinter;
146 printer->setName(conf.readEntry("Name"));
147 printer->setPrinterName(printer->name());
148 printer->setDescription(conf.readEntry("Description"));
149 printer->setLocation(conf.readEntry("Comment"));
150 printer->setOption("kde-special-command",conf.readPathEntry("Command"));
151 printer->setOption("kde-special-file",conf.readPathEntry("File"));
152 printer->setOption("kde-special-extension",conf.readEntry("Extension"));
153 printer->setOption("kde-special-mimetype",conf.readEntry("Mimetype"));
154 printer->setOption("kde-special-require",conf.readEntry("Require"));
155 printer->setPixmap(conf.readEntry("Icon","unknown"));
156 printer->setType(KMPrinter::Special);
157 if ( !KdeprintChecker::check( &conf ) ||
158 !KXmlCommandManager::self()->checkCommand( printer->option( "kde-special-command" ),
159 KXmlCommandManager::None, KXmlCommandManager::None, 0 ) )
160 printer->addType(KMPrinter::Invalid);
161 printer->setState(KMPrinter::Idle);
162 printer->setAcceptJobs(true);
163 m_mgr->addPrinter(printer);
164 }
165
166 return true;
167}
168
169void KMSpecialManager::refresh()
170{
171 if (!m_loaded)
172 loadPrinters();
173 else
174 {
175 TQPtrListIterator<KMPrinter> it(m_mgr->m_printers);
176 for (;it.current();++it)
177 if (it.current()->isSpecial())
178 {
179 it.current()->setDiscarded(false);
180 it.current()->setType(KMPrinter::Special);
181 if (KdeprintChecker::check(TQStringList::split(',',it.current()->option("kde-special-require"),false)))
182 it.current()->addType(KMPrinter::Invalid);
183 }
184 }
185}
186
187KXmlCommand* KMSpecialManager::loadCommand(KMPrinter *pr)
188{
189 KXmlCommand *xmlCmd = loadCommand(pr->option("kde-special-command"));
190 if (xmlCmd && xmlCmd->driver())
191 xmlCmd->driver()->set("text", pr->printerName());
192 return xmlCmd;
193}
194
195KXmlCommand* KMSpecialManager::loadCommand(const TQString& xmlId)
196{
197 return KXmlCommandManager::self()->loadCommand(xmlId, true);
198}
199
200DrMain* KMSpecialManager::loadDriver(KMPrinter *pr)
201{
202 KXmlCommand *xmlCmd;
203 DrMain *driver(0);
204
205 if ((xmlCmd=loadCommand(pr)) != 0)
206 {
207 driver = xmlCmd->takeDriver();
208 delete xmlCmd;
209 }
210
211 return driver;
212}
213
214TQString KMSpecialManager::setupCommand(const TQString& cmd, const TQMap<TQString,TQString>& opts)
215{
216 TQString s(cmd);
217 if (!s.isEmpty())
218 {
219 KXmlCommand *xmlCmd = loadCommand(cmd);
220 if (xmlCmd)
221 {
222 s = xmlCmd->buildCommand(opts, false, false);
223 delete xmlCmd;
224 }
225 }
226
227 return s;
228}

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.4
This website is maintained by Timothy Pearson.