You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
258 lines
5.7 KiB
258 lines
5.7 KiB
15 years ago
|
/*
|
||
|
* This file is part of the KDE libraries
|
||
13 years ago
|
* Copyright (c) 2001 Michael Goffioul <tdeprint@swing.be>
|
||
15 years ago
|
*
|
||
|
* 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 "kmjobmanager.h"
|
||
|
#include "kmjob.h"
|
||
|
#include "kmthreadjob.h"
|
||
|
#include "kmfactory.h"
|
||
|
|
||
|
#include <kaction.h>
|
||
|
#include <kdebug.h>
|
||
|
#include <kconfig.h>
|
||
|
|
||
15 years ago
|
KMJobManager::KMJobManager(TQObject *parent, const char *name)
|
||
|
: TQObject(parent,name)
|
||
15 years ago
|
{
|
||
|
m_jobs.setAutoDelete(true);
|
||
|
m_threadjob = new KMThreadJob(this, "ThreadJob");
|
||
|
m_filter.setAutoDelete(true);
|
||
|
}
|
||
|
|
||
|
KMJobManager::~KMJobManager()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
KMJobManager* KMJobManager::self()
|
||
|
{
|
||
|
return KMFactory::self()->jobManager();
|
||
|
}
|
||
|
|
||
|
void KMJobManager::discardAllJobs()
|
||
|
{
|
||
15 years ago
|
TQPtrListIterator<KMJob> it(m_jobs);
|
||
15 years ago
|
for (;it.current();++it)
|
||
|
it.current()->setDiscarded(true);
|
||
|
}
|
||
|
|
||
|
void KMJobManager::removeDiscardedJobs()
|
||
|
{
|
||
|
for (uint i=0;i<m_jobs.count();i++)
|
||
14 years ago
|
if (m_jobs.tqat(i)->isDiscarded())
|
||
15 years ago
|
{
|
||
|
m_jobs.remove(i);
|
||
|
i--;
|
||
|
}
|
||
|
}
|
||
|
|
||
14 years ago
|
/*KMJob* KMJobManager::findJob(int ID)
|
||
15 years ago
|
{
|
||
15 years ago
|
TQPtrListIterator<KMJob> it(m_jobs);
|
||
15 years ago
|
for (;it.current();++it)
|
||
|
if (it.current()->id() == ID)
|
||
|
return it.current();
|
||
|
return 0;
|
||
|
}*/
|
||
|
|
||
14 years ago
|
KMJob* KMJobManager::findJob(const TQString& uri)
|
||
15 years ago
|
{
|
||
15 years ago
|
TQPtrListIterator<KMJob> it(m_jobs);
|
||
15 years ago
|
for (;it.current();++it)
|
||
|
if (it.current()->uri() == uri)
|
||
|
return it.current();
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
void KMJobManager::addJob(KMJob *job)
|
||
|
{
|
||
|
// only keep it if "printer" is not empty, and in printer filter
|
||
|
if (!job->uri().isEmpty() && !job->printer().isEmpty())
|
||
|
{
|
||
14 years ago
|
KMJob *aJob = findJob(job->uri());
|
||
15 years ago
|
if (aJob)
|
||
|
{
|
||
|
aJob->copy(*job);
|
||
|
delete job;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
job->setDiscarded(false);
|
||
|
m_jobs.append(job);
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
delete job;
|
||
|
}
|
||
|
|
||
15 years ago
|
/*bool KMJobManager::sendCommand(int ID, int action, const TQString& arg)
|
||
15 years ago
|
{
|
||
14 years ago
|
KMJob *job = findJob(ID);
|
||
15 years ago
|
if (job)
|
||
|
{
|
||
15 years ago
|
TQPtrList<KMJob> l;
|
||
15 years ago
|
l.setAutoDelete(false);
|
||
|
l.append(job);
|
||
|
return sendCommand(l,action,arg);
|
||
|
}
|
||
|
return false;
|
||
|
}*/
|
||
|
|
||
15 years ago
|
bool KMJobManager::sendCommand(const TQString& uri, int action, const TQString& arg)
|
||
15 years ago
|
{
|
||
14 years ago
|
KMJob *job = findJob(uri);
|
||
15 years ago
|
if (job)
|
||
|
{
|
||
15 years ago
|
TQPtrList<KMJob> l;
|
||
15 years ago
|
l.setAutoDelete(false);
|
||
|
l.append(job);
|
||
|
return sendCommand(l,action,arg);
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
|
||
15 years ago
|
bool KMJobManager::sendCommand(const TQPtrList<KMJob>& jobs, int action, const TQString& args)
|
||
15 years ago
|
{
|
||
|
// split jobs in 2 classes
|
||
15 years ago
|
TQPtrList<KMJob> csystem, cthread;
|
||
15 years ago
|
csystem.setAutoDelete(false);
|
||
|
cthread.setAutoDelete(false);
|
||
15 years ago
|
TQPtrListIterator<KMJob> it(jobs);
|
||
15 years ago
|
for (;it.current();++it)
|
||
|
if (it.current()->type() == KMJob::Threaded) cthread.append(it.current());
|
||
|
else csystem.append(it.current());
|
||
|
|
||
|
// perform operation on both classes
|
||
|
if (cthread.count() > 0 && !sendCommandThreadJob(cthread, action, args))
|
||
|
return false;
|
||
|
if (csystem.count() > 0 && !sendCommandSystemJob(csystem, action, args))
|
||
|
return false;
|
||
|
return true;
|
||
|
}
|
||
|
|
||
15 years ago
|
bool KMJobManager::sendCommandSystemJob(const TQPtrList<KMJob>&, int, const TQString&)
|
||
15 years ago
|
{
|
||
|
return false;
|
||
|
}
|
||
|
|
||
15 years ago
|
bool KMJobManager::sendCommandThreadJob(const TQPtrList<KMJob>& jobs, int action, const TQString&)
|
||
15 years ago
|
{
|
||
|
if (action != KMJob::Remove)
|
||
|
return false;
|
||
|
|
||
15 years ago
|
TQPtrListIterator<KMJob> it(jobs);
|
||
15 years ago
|
bool result(true);
|
||
|
for (;it.current() && result; ++it)
|
||
|
result = m_threadjob->removeJob(it.current()->id());
|
||
|
return result;
|
||
|
}
|
||
|
|
||
15 years ago
|
bool KMJobManager::listJobs(const TQString&, KMJobManager::JobType, int)
|
||
15 years ago
|
{
|
||
|
return true;
|
||
|
}
|
||
|
|
||
15 years ago
|
const TQPtrList<KMJob>& KMJobManager::jobList(bool reload)
|
||
15 years ago
|
{
|
||
|
if (reload || m_jobs.count() == 0)
|
||
|
{
|
||
|
discardAllJobs();
|
||
15 years ago
|
TQDictIterator<JobFilter> it(m_filter);
|
||
15 years ago
|
int joblimit = limit();
|
||
|
bool threadjobs_updated = false;
|
||
|
for (; it.current(); ++it)
|
||
|
{
|
||
|
if ( it.current()->m_isspecial )
|
||
|
{
|
||
|
if ( !threadjobs_updated )
|
||
|
{
|
||
|
threadJob()->updateManager( this );
|
||
|
threadjobs_updated = true;
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
if (it.current()->m_type[ActiveJobs] > 0)
|
||
|
listJobs(it.currentKey(), ActiveJobs, joblimit);
|
||
|
if (it.current()->m_type[CompletedJobs] > 0)
|
||
|
listJobs(it.currentKey(), CompletedJobs, joblimit);
|
||
|
}
|
||
|
}
|
||
|
m_threadjob->updateManager(this);
|
||
|
removeDiscardedJobs();
|
||
|
}
|
||
|
return m_jobs;
|
||
|
}
|
||
|
|
||
|
int KMJobManager::actions()
|
||
|
{
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQValueList<KAction*> KMJobManager::createPluginActions(KActionCollection*)
|
||
15 years ago
|
{
|
||
15 years ago
|
return TQValueList<KAction*>();
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
void KMJobManager::validatePluginActions(KActionCollection*, const TQPtrList<KMJob>&)
|
||
15 years ago
|
{
|
||
|
}
|
||
|
|
||
15 years ago
|
void KMJobManager::addPrinter(const TQString& pr, KMJobManager::JobType type, bool isSpecial)
|
||
15 years ago
|
{
|
||
14 years ago
|
struct JobFilter *jf = m_filter.find(pr);
|
||
15 years ago
|
if (!jf)
|
||
|
{
|
||
|
jf = new JobFilter;
|
||
|
m_filter.insert(pr, jf);
|
||
|
}
|
||
|
jf->m_type[type]++;
|
||
|
jf->m_isspecial = isSpecial;
|
||
|
}
|
||
|
|
||
15 years ago
|
void KMJobManager::removePrinter(const TQString& pr, KMJobManager::JobType type)
|
||
15 years ago
|
{
|
||
14 years ago
|
struct JobFilter *jf = m_filter.find(pr);
|
||
15 years ago
|
if (jf)
|
||
|
{
|
||
|
jf->m_type[type] = QMAX(0, jf->m_type[type]-1);
|
||
|
if (!jf->m_type[0] && !jf->m_type[1])
|
||
|
m_filter.remove(pr);
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
bool KMJobManager::doPluginAction(int, const TQPtrList<KMJob>&)
|
||
15 years ago
|
{
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
void KMJobManager::setLimit(int val)
|
||
|
{
|
||
|
KConfig *conf = KMFactory::self()->printConfig();
|
||
|
conf->setGroup("Jobs");
|
||
|
conf->writeEntry("Limit", val);
|
||
|
}
|
||
|
|
||
|
int KMJobManager::limit()
|
||
|
{
|
||
|
KConfig *conf = KMFactory::self()->printConfig();
|
||
|
conf->setGroup("Jobs");
|
||
|
return conf->readNumEntry("Limit", 0);
|
||
|
}
|
||
|
|
||
|
#include "kmjobmanager.moc"
|