summaryrefslogtreecommitdiffstats
path: root/tdeprint/kmthreadjob.cpp
diff options
context:
space:
mode:
authorTimothy Pearson <kb9vqf@pearsoncomputing.net>2011-11-06 15:56:40 -0600
committerTimothy Pearson <kb9vqf@pearsoncomputing.net>2011-11-06 15:56:40 -0600
commite16866e072f94410321d70daedbcb855ea878cac (patch)
treeee3f52eabde7da1a0e6ca845fb9c2813cf1558cf /tdeprint/kmthreadjob.cpp
parenta58c20c1a7593631a1b50213c805507ebc16adaf (diff)
downloadtdelibs-e16866e072f94410321d70daedbcb855ea878cac.tar.gz
tdelibs-e16866e072f94410321d70daedbcb855ea878cac.zip
Actually move the kde files that were renamed in the last commit
Diffstat (limited to 'tdeprint/kmthreadjob.cpp')
-rw-r--r--tdeprint/kmthreadjob.cpp170
1 files changed, 170 insertions, 0 deletions
diff --git a/tdeprint/kmthreadjob.cpp b/tdeprint/kmthreadjob.cpp
new file mode 100644
index 000000000..fcee4877f
--- /dev/null
+++ b/tdeprint/kmthreadjob.cpp
@@ -0,0 +1,170 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <tdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#include "kmthreadjob.h"
+#include "kmjob.h"
+#include "kmjobmanager.h"
+
+#include <tqfile.h>
+#include <tqtextstream.h>
+#include <tqstringlist.h>
+#include <kstandarddirs.h>
+
+#include <errno.h>
+#include <sys/types.h>
+#include <signal.h>
+
+#define CHARSEP '$'
+
+KMThreadJob::KMThreadJob(TQObject *parent, const char *name)
+: TQObject(parent,name)
+{
+ m_jobs.setAutoDelete(true);
+}
+
+KMThreadJob::~KMThreadJob()
+{
+}
+
+TQString KMThreadJob::jobFile()
+{
+ QString f = locateLocal("data","tdeprint/printjobs");
+ return f;
+}
+
+bool KMThreadJob::saveJobs()
+{
+ TQFile f(jobFile());
+ if (f.open(IO_WriteOnly))
+ {
+ TQTextStream t(&f);
+ TQIntDictIterator<KMJob> it(m_jobs);
+ for (;it.current();++it)
+ t << it.current()->id() << CHARSEP << it.current()->name() << CHARSEP << it.current()->printer() << CHARSEP << it.current()->owner() << CHARSEP << it.current()->size() << endl;
+ return true;
+ }
+ return false;
+}
+
+bool KMThreadJob::loadJobs()
+{
+ TQFile f(jobFile());
+ if (f.exists() && f.open(IO_ReadOnly))
+ {
+ TQTextStream t(&f);
+ TQString line;
+
+ m_jobs.clear();
+ while (!t.eof())
+ {
+ line = t.readLine().stripWhiteSpace();
+ if (line.isEmpty())
+ continue;
+ QStringList ll = TQStringList::split(CHARSEP,line,true);
+ if (ll.count() == 5)
+ {
+ KMJob *job = new KMJob();
+ job->setId(ll[0].toInt());
+ job->setName(ll[1]);
+ job->setPrinter(ll[2]);
+ job->setOwner(ll[3]);
+ job->setSize(ll[4].toInt());
+ job->setState(KMJob::Printing);
+ job->setType(KMJob::Threaded);
+ job->setUri("proc:/"+ll[0]);
+ if (job->id() > 0 && checkJob(job->id()))
+ m_jobs.insert(job->id(),job);
+ else
+ delete job;
+ }
+ }
+ return true;
+ }
+ return false;
+}
+
+bool KMThreadJob::checkJob(int ID)
+{
+ return (kill((pid_t)ID,0) == 0 || errno == EPERM);
+}
+
+KMJob* KMThreadJob::findJob(int ID)
+{
+ return m_jobs.find(ID);
+}
+
+KMJob* KMThreadJob::findJob(const TQString& uri)
+{
+ if (uri.startsWith("proc:/"))
+ {
+ int pid = uri.mid(6).toInt();
+ if (pid > 0)
+ return m_jobs.find(pid);
+ }
+ return NULL;
+}
+
+bool KMThreadJob::removeJob(int ID)
+{
+ if (!checkJob(ID) || kill((pid_t)ID, SIGTERM) == 0)
+ {
+ m_jobs.remove(ID);
+ saveJobs();
+ return true;
+ }
+ else
+ return false;
+}
+
+void KMThreadJob::createJob(int ID, const TQString& printer, const TQString& name, const TQString& owner, int size)
+{
+ KMThreadJob mth(0);
+ KMJob *job = new KMJob();
+ job->setId(ID);
+ job->setPrinter(printer);
+ job->setName(name);
+ job->setOwner(owner);
+ job->setSize(size);
+ job->setType(KMJob::Threaded);
+ mth.createJob(job);
+}
+
+void KMThreadJob::createJob(KMJob *job)
+{
+ if (job->id() > 0)
+ {
+ loadJobs();
+ if (!m_jobs.find(job->id()))
+ {
+ m_jobs.insert(job->id(),job);
+ saveJobs();
+ }
+ }
+}
+
+void KMThreadJob::updateManager(KMJobManager *mgr)
+{
+ loadJobs();
+ TQIntDictIterator<KMJob> it(m_jobs);
+ for (;it.current();++it)
+ {
+ KMJob *job = new KMJob(*(it.current()));
+ mgr->addJob(job);
+ }
+}