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

tdeprint

  • tdeprint
kmthreadjob.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 "kmthreadjob.h"
21 #include "kmjob.h"
22 #include "kmjobmanager.h"
23 
24 #include <tqfile.h>
25 #include <tqtextstream.h>
26 #include <tqstringlist.h>
27 #include <kstandarddirs.h>
28 
29 #include <errno.h>
30 #include <sys/types.h>
31 #include <signal.h>
32 
33 #define CHARSEP '$'
34 
35 KMThreadJob::KMThreadJob(TQObject *parent, const char *name)
36 : TQObject(parent,name)
37 {
38  m_jobs.setAutoDelete(true);
39 }
40 
41 KMThreadJob::~KMThreadJob()
42 {
43 }
44 
45 TQString KMThreadJob::jobFile()
46 {
47  QString f = locateLocal("data","tdeprint/printjobs");
48  return f;
49 }
50 
51 bool KMThreadJob::saveJobs()
52 {
53  TQFile f(jobFile());
54  if (f.open(IO_WriteOnly))
55  {
56  TQTextStream t(&f);
57  TQIntDictIterator<KMJob> it(m_jobs);
58  for (;it.current();++it)
59  t << it.current()->id() << CHARSEP << it.current()->name() << CHARSEP << it.current()->printer() << CHARSEP << it.current()->owner() << CHARSEP << it.current()->size() << endl;
60  return true;
61  }
62  return false;
63 }
64 
65 bool KMThreadJob::loadJobs()
66 {
67  TQFile f(jobFile());
68  if (f.exists() && f.open(IO_ReadOnly))
69  {
70  TQTextStream t(&f);
71  TQString line;
72 
73  m_jobs.clear();
74  while (!t.eof())
75  {
76  line = t.readLine().stripWhiteSpace();
77  if (line.isEmpty())
78  continue;
79  TQStringList ll = TQStringList::split(CHARSEP,line,true);
80  if (ll.count() == 5)
81  {
82  KMJob *job = new KMJob();
83  job->setId(ll[0].toInt());
84  job->setName(ll[1]);
85  job->setPrinter(ll[2]);
86  job->setOwner(ll[3]);
87  job->setSize(ll[4].toInt());
88  job->setState(KMJob::Printing);
89  job->setType(KMJob::Threaded);
90  job->setUri("proc:/"+ll[0]);
91  if (job->id() > 0 && checkJob(job->id()))
92  m_jobs.insert(job->id(),job);
93  else
94  delete job;
95  }
96  }
97  return true;
98  }
99  return false;
100 }
101 
102 bool KMThreadJob::checkJob(int ID)
103 {
104  return (kill((pid_t)ID,0) == 0 || errno == EPERM);
105 }
106 
107 KMJob* KMThreadJob::findJob(int ID)
108 {
109  return m_jobs.find(ID);
110 }
111 
112 KMJob* KMThreadJob::findJob(const TQString& uri)
113 {
114  if (uri.startsWith("proc:/"))
115  {
116  int pid = uri.mid(6).toInt();
117  if (pid > 0)
118  return m_jobs.find(pid);
119  }
120  return NULL;
121 }
122 
123 bool KMThreadJob::removeJob(int ID)
124 {
125  if (!checkJob(ID) || kill((pid_t)ID, SIGTERM) == 0)
126  {
127  m_jobs.remove(ID);
128  saveJobs();
129  return true;
130  }
131  else
132  return false;
133 }
134 
135 void KMThreadJob::createJob(int ID, const TQString& printer, const TQString& name, const TQString& owner, int size)
136 {
137  KMThreadJob mth(0);
138  KMJob *job = new KMJob();
139  job->setId(ID);
140  job->setPrinter(printer);
141  job->setName(name);
142  job->setOwner(owner);
143  job->setSize(size);
144  job->setType(KMJob::Threaded);
145  mth.createJob(job);
146 }
147 
148 void KMThreadJob::createJob(KMJob *job)
149 {
150  if (job->id() > 0)
151  {
152  loadJobs();
153  if (!m_jobs.find(job->id()))
154  {
155  m_jobs.insert(job->id(),job);
156  saveJobs();
157  }
158  }
159 }
160 
161 void KMThreadJob::updateManager(KMJobManager *mgr)
162 {
163  loadJobs();
164  TQIntDictIterator<KMJob> it(m_jobs);
165  for (;it.current();++it)
166  {
167  KMJob *job = new KMJob(*(it.current()));
168  mgr->addJob(job);
169  }
170 }

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.