20 #include "kmthreadjob.h"
22 #include "kmjobmanager.h"
25 #include <tqtextstream.h>
26 #include <tqstringlist.h>
27 #include <kstandarddirs.h>
30 #include <sys/types.h>
35 KMThreadJob::KMThreadJob(TQObject *parent,
const char *name)
36 : TQObject(parent,name)
38 m_jobs.setAutoDelete(
true);
41 KMThreadJob::~KMThreadJob()
45 TQString KMThreadJob::jobFile()
47 TQString f = locateLocal(
"data",
"tdeprint/printjobs");
51 bool KMThreadJob::saveJobs()
54 if (f.open(IO_WriteOnly))
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;
65 bool KMThreadJob::loadJobs()
68 if (f.exists() && f.open(IO_ReadOnly))
76 line = t.readLine().stripWhiteSpace();
79 TQStringList ll = TQStringList::split(CHARSEP,line,
true);
82 KMJob *job =
new KMJob();
83 job->setId(ll[0].toInt());
85 job->setPrinter(ll[2]);
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);
102 bool KMThreadJob::checkJob(
int ID)
104 return (kill((pid_t)ID,0) == 0 || errno == EPERM);
107 KMJob* KMThreadJob::findJob(
int ID)
109 return m_jobs.find(ID);
112 KMJob* KMThreadJob::findJob(
const TQString& uri)
114 if (uri.startsWith(
"proc:/"))
116 int pid = uri.mid(6).toInt();
118 return m_jobs.find(pid);
123 bool KMThreadJob::removeJob(
int ID)
125 if (!checkJob(ID) || kill((pid_t)ID, SIGTERM) == 0)
135 void KMThreadJob::createJob(
int ID,
const TQString& printer,
const TQString& name,
const TQString& owner,
int size)
138 KMJob *job =
new KMJob();
140 job->setPrinter(printer);
142 job->setOwner(owner);
144 job->setType(KMJob::Threaded);
148 void KMThreadJob::createJob(KMJob *job)
153 if (!m_jobs.find(job->id()))
155 m_jobs.insert(job->id(),job);
161 void KMThreadJob::updateManager(KMJobManager *mgr)
164 TQIntDictIterator<KMJob> it(m_jobs);
165 for (;it.current();++it)
167 KMJob *job =
new KMJob(*(it.current()));