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

tdeprint

  • tdeprint
kmjobmanager.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 "kmjobmanager.h"
21 #include "kmjob.h"
22 #include "kmthreadjob.h"
23 #include "kmfactory.h"
24 
25 #include <tdeaction.h>
26 #include <kdebug.h>
27 #include <tdeconfig.h>
28 
29 KMJobManager::KMJobManager(TQObject *parent, const char *name)
30 : TQObject(parent,name)
31 {
32  m_jobs.setAutoDelete(true);
33  m_threadjob = new KMThreadJob(this, "ThreadJob");
34  m_filter.setAutoDelete(true);
35 }
36 
37 KMJobManager::~KMJobManager()
38 {
39 }
40 
41 KMJobManager* KMJobManager::self()
42 {
43  return KMFactory::self()->jobManager();
44 }
45 
46 void KMJobManager::discardAllJobs()
47 {
48  TQPtrListIterator<KMJob> it(m_jobs);
49  for (;it.current();++it)
50  it.current()->setDiscarded(true);
51 }
52 
53 void KMJobManager::removeDiscardedJobs()
54 {
55  for (uint i=0;i<m_jobs.count();i++)
56  if (m_jobs.at(i)->isDiscarded())
57  {
58  m_jobs.remove(i);
59  i--;
60  }
61 }
62 
63 /*KMJob* KMJobManager::findJob(int ID)
64 {
65  TQPtrListIterator<KMJob> it(m_jobs);
66  for (;it.current();++it)
67  if (it.current()->id() == ID)
68  return it.current();
69  return 0;
70 }*/
71 
72 KMJob* KMJobManager::findJob(const TQString& uri)
73 {
74  TQPtrListIterator<KMJob> it(m_jobs);
75  for (;it.current();++it)
76  if (it.current()->uri() == uri)
77  return it.current();
78  return 0;
79 }
80 
81 void KMJobManager::addJob(KMJob *job)
82 {
83  // only keep it if "printer" is not empty, and in printer filter
84  if (!job->uri().isEmpty() && !job->printer().isEmpty())
85  {
86  KMJob *aJob = findJob(job->uri());
87  if (aJob)
88  {
89  aJob->copy(*job);
90  delete job;
91  }
92  else
93  {
94  job->setDiscarded(false);
95  m_jobs.append(job);
96  }
97  }
98  else
99  delete job;
100 }
101 
102 /*bool KMJobManager::sendCommand(int ID, int action, const TQString& arg)
103 {
104  KMJob *job = findJob(ID);
105  if (job)
106  {
107  TQPtrList<KMJob> l;
108  l.setAutoDelete(false);
109  l.append(job);
110  return sendCommand(l,action,arg);
111  }
112  return false;
113 }*/
114 
115 bool KMJobManager::sendCommand(const TQString& uri, int action, const TQString& arg)
116 {
117  KMJob *job = findJob(uri);
118  if (job)
119  {
120  TQPtrList<KMJob> l;
121  l.setAutoDelete(false);
122  l.append(job);
123  return sendCommand(l,action,arg);
124  }
125  return false;
126 }
127 
128 bool KMJobManager::sendCommand(const TQPtrList<KMJob>& jobs, int action, const TQString& args)
129 {
130  // split jobs in 2 classes
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());
138 
139  // perform operation on both classes
140  if (cthread.count() > 0 && !sendCommandThreadJob(cthread, action, args))
141  return false;
142  if (csystem.count() > 0 && !sendCommandSystemJob(csystem, action, args))
143  return false;
144  return true;
145 }
146 
147 bool KMJobManager::sendCommandSystemJob(const TQPtrList<KMJob>&, int, const TQString&)
148 {
149  return false;
150 }
151 
152 bool KMJobManager::sendCommandThreadJob(const TQPtrList<KMJob>& jobs, int action, const TQString&)
153 {
154  if (action != KMJob::Remove)
155  return false;
156 
157  TQPtrListIterator<KMJob> it(jobs);
158  bool result(true);
159  for (;it.current() && result; ++it)
160  result = m_threadjob->removeJob(it.current()->id());
161  return result;
162 }
163 
164 bool KMJobManager::listJobs(const TQString&, KMJobManager::JobType, int)
165 {
166  return true;
167 }
168 
169 const TQPtrList<KMJob>& KMJobManager::jobList(bool reload)
170 {
171  if (reload || m_jobs.count() == 0)
172  {
173  discardAllJobs();
174  TQDictIterator<JobFilter> it(m_filter);
175  int joblimit = limit();
176  bool threadjobs_updated = false;
177  for (; it.current(); ++it)
178  {
179  if ( it.current()->m_isspecial )
180  {
181  if ( !threadjobs_updated )
182  {
183  threadJob()->updateManager( this );
184  threadjobs_updated = true;
185  }
186  }
187  else
188  {
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);
193  }
194  }
195  m_threadjob->updateManager(this);
196  removeDiscardedJobs();
197  }
198  return m_jobs;
199 }
200 
201 int KMJobManager::actions()
202 {
203  return 0;
204 }
205 
206 TQValueList<TDEAction*> KMJobManager::createPluginActions(TDEActionCollection*)
207 {
208  return TQValueList<TDEAction*>();
209 }
210 
211 void KMJobManager::validatePluginActions(TDEActionCollection*, const TQPtrList<KMJob>&)
212 {
213 }
214 
215 void KMJobManager::addPrinter(const TQString& pr, KMJobManager::JobType type, bool isSpecial)
216 {
217  struct JobFilter *jf = m_filter.find(pr);
218  if (!jf)
219  {
220  jf = new JobFilter;
221  m_filter.insert(pr, jf);
222  }
223  jf->m_type[type]++;
224  jf->m_isspecial = isSpecial;
225 }
226 
227 void KMJobManager::removePrinter(const TQString& pr, KMJobManager::JobType type)
228 {
229  struct JobFilter *jf = m_filter.find(pr);
230  if (jf)
231  {
232  jf->m_type[type] = TQMAX(0, jf->m_type[type]-1);
233  if (!jf->m_type[0] && !jf->m_type[1])
234  m_filter.remove(pr);
235  }
236 }
237 
238 bool KMJobManager::doPluginAction(int, const TQPtrList<KMJob>&)
239 {
240  return true;
241 }
242 
243 void KMJobManager::setLimit(int val)
244 {
245  TDEConfig *conf = KMFactory::self()->printConfig();
246  conf->setGroup("Jobs");
247  conf->writeEntry("Limit", val);
248 }
249 
250 int KMJobManager::limit()
251 {
252  TDEConfig *conf = KMFactory::self()->printConfig();
253  conf->setGroup("Jobs");
254  return conf->readNumEntry("Limit", 0);
255 }
256 
257 #include "kmjobmanager.moc"

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
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeprint by doxygen 1.9.1
This website is maintained by Timothy Pearson.