20 #include "kmjobmanager.h"
22 #include "kmthreadjob.h"
23 #include "kmfactory.h"
25 #include <tdeaction.h>
27 #include <tdeconfig.h>
29 KMJobManager::KMJobManager(TQObject *parent,
const char *name)
30 : TQObject(parent,name)
32 m_jobs.setAutoDelete(
true);
33 m_threadjob =
new KMThreadJob(
this,
"ThreadJob");
34 m_filter.setAutoDelete(
true);
37 KMJobManager::~KMJobManager()
41 KMJobManager* KMJobManager::self()
43 return KMFactory::self()->jobManager();
46 void KMJobManager::discardAllJobs()
48 TQPtrListIterator<KMJob> it(m_jobs);
49 for (;it.current();++it)
50 it.current()->setDiscarded(
true);
53 void KMJobManager::removeDiscardedJobs()
55 for (uint i=0;i<m_jobs.count();i++)
56 if (m_jobs.at(i)->isDiscarded())
72 KMJob* KMJobManager::findJob(
const TQString& uri)
74 TQPtrListIterator<KMJob> it(m_jobs);
75 for (;it.current();++it)
76 if (it.current()->uri() == uri)
81 void KMJobManager::addJob(KMJob *job)
84 if (!job->uri().isEmpty() && !job->printer().isEmpty())
86 KMJob *aJob = findJob(job->uri());
94 job->setDiscarded(
false);
115 bool KMJobManager::sendCommand(
const TQString& uri,
int action,
const TQString& arg)
117 KMJob *job = findJob(uri);
121 l.setAutoDelete(
false);
123 return sendCommand(l,action,arg);
128 bool KMJobManager::sendCommand(
const TQPtrList<KMJob>& jobs,
int action,
const TQString& args)
131 TQPtrList<KMJob> csystem, cthread;
132 csystem.setAutoDelete(
false);
133 cthread.setAutoDelete(
false);
134 TQPtrListIterator<KMJob> it(jobs);
135 for (;it.current();++it)
136 if (it.current()->type() == KMJob::Threaded) cthread.append(it.current());
137 else csystem.append(it.current());
140 if (cthread.count() > 0 && !sendCommandThreadJob(cthread, action, args))
142 if (csystem.count() > 0 && !sendCommandSystemJob(csystem, action, args))
147 bool KMJobManager::sendCommandSystemJob(
const TQPtrList<KMJob>&,
int,
const TQString&)
152 bool KMJobManager::sendCommandThreadJob(
const TQPtrList<KMJob>& jobs,
int action,
const TQString&)
154 if (action != KMJob::Remove)
157 TQPtrListIterator<KMJob> it(jobs);
159 for (;it.current() && result; ++it)
160 result = m_threadjob->removeJob(it.current()->id());
164 bool KMJobManager::listJobs(
const TQString&, KMJobManager::JobType,
int)
169 const TQPtrList<KMJob>& KMJobManager::jobList(
bool reload)
171 if (reload || m_jobs.count() == 0)
174 TQDictIterator<JobFilter> it(m_filter);
175 int joblimit = limit();
176 bool threadjobs_updated =
false;
177 for (; it.current(); ++it)
179 if ( it.current()->m_isspecial )
181 if ( !threadjobs_updated )
183 threadJob()->updateManager(
this );
184 threadjobs_updated =
true;
189 if (it.current()->m_type[ActiveJobs] > 0)
190 listJobs(it.currentKey(), ActiveJobs, joblimit);
191 if (it.current()->m_type[CompletedJobs] > 0)
192 listJobs(it.currentKey(), CompletedJobs, joblimit);
195 m_threadjob->updateManager(
this);
196 removeDiscardedJobs();
201 int KMJobManager::actions()
206 TQValueList<TDEAction*> KMJobManager::createPluginActions(TDEActionCollection*)
208 return TQValueList<TDEAction*>();
211 void KMJobManager::validatePluginActions(TDEActionCollection*,
const TQPtrList<KMJob>&)
215 void KMJobManager::addPrinter(
const TQString& pr, KMJobManager::JobType type,
bool isSpecial)
217 struct JobFilter *jf = m_filter.find(pr);
221 m_filter.insert(pr, jf);
224 jf->m_isspecial = isSpecial;
227 void KMJobManager::removePrinter(
const TQString& pr, KMJobManager::JobType type)
229 struct JobFilter *jf = m_filter.find(pr);
232 jf->m_type[type] = TQMAX(0, jf->m_type[type]-1);
233 if (!jf->m_type[0] && !jf->m_type[1])
238 bool KMJobManager::doPluginAction(
int,
const TQPtrList<KMJob>&)
243 void KMJobManager::setLimit(
int val)
245 TDEConfig *conf = KMFactory::self()->printConfig();
246 conf->setGroup(
"Jobs");
247 conf->writeEntry(
"Limit", val);
250 int KMJobManager::limit()
252 TDEConfig *conf = KMFactory::self()->printConfig();
253 conf->setGroup(
"Jobs");
254 return conf->readNumEntry(
"Limit", 0);
257 #include "kmjobmanager.moc"