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

tdeprint

  • tdeprint
  • management
kmjobviewer.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 "kmjobviewer.h"
21 #include "kmjobmanager.h"
22 #include "kmfactory.h"
23 #include "kmjob.h"
24 #include "kmprinter.h"
25 #include "kmmanager.h"
26 #include "kmuimanager.h"
27 #include "jobitem.h"
28 #include "kmtimer.h"
29 #include "kmconfigjobs.h"
30 #include "kmconfigpage.h"
31 #include "kprinter.h"
32 
33 #include <tdelistview.h>
34 #include <kstatusbar.h>
35 #include <tqpopupmenu.h>
36 #include <tdemessagebox.h>
37 #include <tdelocale.h>
38 #include <tdepopupmenu.h>
39 #include <tdeaction.h>
40 #include <kstdaction.h>
41 #include <kiconloader.h>
42 #include <tdeapplication.h>
43 #include <kcursor.h>
44 #include <tdemenubar.h>
45 #include <kdebug.h>
46 #include <twin.h>
47 #include <tdeio/netaccess.h>
48 #include <tqtimer.h>
49 #include <tqlayout.h>
50 #include <stdlib.h>
51 #include <tqlineedit.h>
52 #include <kdialogbase.h>
53 #include <tqcheckbox.h>
54 #include <kurldrag.h>
55 #include <tdeconfig.h>
56 
57 #undef m_manager
58 #define m_manager KMFactory::self()->jobManager()
59 
60 class KJobListView : public TDEListView
61 {
62 public:
63  KJobListView( TQWidget *parent = 0, const char *name = 0 );
64 
65 protected:
66  bool acceptDrag( TQDropEvent* ) const;
67 };
68 
69 KJobListView::KJobListView( TQWidget *parent, const char *name )
70  : TDEListView( parent, name )
71 {
72  setAcceptDrops( true );
73  setDropVisualizer( false );
74 }
75 
76 bool KJobListView::acceptDrag( TQDropEvent *e ) const
77 {
78  if ( KURLDrag::canDecode( e ) )
79  return true;
80  else
81  return TDEListView::acceptDrag( e );
82 }
83 
84 KMJobViewer::KMJobViewer(TQWidget *parent, const char *name)
85 : TDEMainWindow(parent,name)
86 {
87  m_view = 0;
88  m_pop = 0;
89  m_jobs.setAutoDelete(false);
90  m_items.setAutoDelete(false);
91  m_printers.setAutoDelete(false);
92  m_type = KMJobManager::ActiveJobs;
93  m_stickybox = 0;
94  m_standalone = ( parent == NULL );
95 
96  setToolBarsMovable(false);
97  init();
98 
99  if (m_standalone)
100  {
101  setCaption(i18n("No Printer"));
102  TDEConfig *conf = KMFactory::self()->printConfig();
103  TQSize defSize( 550, 250 );
104  conf->setGroup( "Jobs" );
105  resize( conf->readSizeEntry( "Size", &defSize ) );
106  }
107 }
108 
109 KMJobViewer::~KMJobViewer()
110 {
111  if (m_standalone)
112  {
113  kdDebug( 500 ) << "Destroying stand-alone job viewer window" << endl;
114  TDEConfig *conf = KMFactory::self()->printConfig();
115  conf->setGroup( "Jobs" );
116  conf->writeEntry( "Size", size() );
117  emit viewerDestroyed(this);
118  }
119  removeFromManager();
120 }
121 
122 void KMJobViewer::setPrinter(KMPrinter *p)
123 {
124  setPrinter((p ? p->printerName() : TQString::null));
125 }
126 
127 void KMJobViewer::setPrinter(const TQString& prname)
128 {
129  // We need to trigger a refresh even if the printer
130  // has not changed, some jobs may have been canceled
131  // outside tdeprint. We can't return simply if
132  // prname == m_prname.
133  if (m_prname != prname)
134  {
135  removeFromManager();
136  m_prname = prname;
137  addToManager();
138  m_view->setAcceptDrops( prname != i18n( "All Printers" ) );
139  }
140  triggerRefresh();
141 }
142 
143 void KMJobViewer::updateCaption()
144 {
145  if (!m_standalone)
146  return;
147 
148  TQString pixname("document-print");
149  if (!m_prname.isEmpty())
150  {
151  setCaption(i18n("Print Jobs for %1").arg(m_prname));
152  KMPrinter *prt = KMManager::self()->findPrinter(m_prname);
153  if (prt)
154  pixname = prt->pixmap();
155  }
156  else
157  {
158  setCaption(i18n("No Printer"));
159  }
160  KWin::setIcons(winId(), DesktopIcon(pixname), SmallIcon(pixname));
161 }
162 
163 void KMJobViewer::updateStatusBar()
164 {
165  if (!m_standalone)
166  return;
167 
168  int limit = m_manager->limit();
169  if (limit == 0)
170  statusBar()->changeItem(i18n("Max.: %1").arg(i18n("Unlimited")), 0);
171  else
172  statusBar()->changeItem(i18n("Max.: %1").arg(limit), 0);
173 }
174 
175 void KMJobViewer::addToManager()
176 {
177  if (m_prname == i18n("All Printers"))
178  {
179  loadPrinters();
180  TQPtrListIterator<KMPrinter> it(m_printers);
181  for (; it.current(); ++it)
182  m_manager->addPrinter(it.current()->printerName(), (KMJobManager::JobType)m_type, it.current()->isSpecial());
183  }
184  else if (!m_prname.isEmpty())
185  {
186  KMPrinter *prt = KMManager::self()->findPrinter( m_prname );
187  bool isSpecial = ( prt ? prt->isSpecial() : false );
188  m_manager->addPrinter(m_prname, (KMJobManager::JobType)m_type, isSpecial);
189  }
190 }
191 
192 void KMJobViewer::removeFromManager()
193 {
194  if (m_prname == i18n("All Printers"))
195  {
196  TQPtrListIterator<KMPrinter> it(m_printers);
197  for (; it.current(); ++it)
198  m_manager->removePrinter(it.current()->printerName(), (KMJobManager::JobType)m_type);
199  }
200  else if (!m_prname.isEmpty())
201  {
202  m_manager->removePrinter(m_prname, (KMJobManager::JobType)m_type);
203  }
204 }
205 
206 void KMJobViewer::refresh(bool reload)
207 {
208  m_jobs.clear();
209  TQPtrListIterator<KMJob> it(m_manager->jobList(reload));
210  bool all = (m_prname == i18n("All Printers")), active = (m_type == KMJobManager::ActiveJobs);
211  for (; it.current(); ++it)
212  if ((all || it.current()->printer() == m_prname)
213  && ((it.current()->state() >= KMJob::Cancelled && !active)
214  || (it.current()->state() < KMJob::Cancelled && active))
215  && (m_username.isEmpty() || m_username == it.current()->owner()))
216  m_jobs.append(it.current());
217  updateJobs();
218 
219 
220  // update the caption and icon (doesn't do anything if it has a parent widget)
221  updateCaption();
222 
223  updateStatusBar();
224 
225  // do it last as this signal can cause this view to be destroyed. No
226  // code can be executed safely after that
227  emit jobsShown(this, (m_jobs.count() != 0));
228 }
229 
230 void KMJobViewer::init()
231 {
232  if (!m_view)
233  {
234  m_view = new KJobListView(this);
235  m_view->addColumn(i18n("Job ID"));
236  m_view->addColumn(i18n("Owner"));
237  m_view->addColumn(i18n("Name"), 150);
238  m_view->addColumn(i18n("Status", "State"));
239  m_view->addColumn(i18n("Size (KB)"));
240  m_view->addColumn(i18n("Page(s)"));
241  m_view->setColumnAlignment(5,Qt::AlignRight|Qt::AlignVCenter);
242  connect( m_view, TQT_SIGNAL( dropped( TQDropEvent*, TQListViewItem* ) ), TQT_SLOT( slotDropped( TQDropEvent*, TQListViewItem* ) ) );
243  //m_view->addColumn(i18n("Printer"));
244  //m_view->setColumnAlignment(6,Qt::AlignRight|Qt::AlignVCenter);
245  KMFactory::self()->uiManager()->setupJobViewer(m_view);
246  m_view->setFrameStyle(TQFrame::WinPanel|TQFrame::Sunken);
247  m_view->setLineWidth(1);
248  m_view->setSorting(0);
249  m_view->setAllColumnsShowFocus(true);
250  m_view->setSelectionMode(TQListView::Extended);
251  connect(m_view,TQT_SIGNAL(selectionChanged()),TQT_SLOT(slotSelectionChanged()));
252  connect(m_view,TQT_SIGNAL(rightButtonPressed(TQListViewItem*,const TQPoint&,int)),TQT_SLOT(slotRightClicked(TQListViewItem*,const TQPoint&,int)));
253  setCentralWidget(m_view);
254  }
255 
256  initActions();
257 }
258 
259 void KMJobViewer::initActions()
260 {
261  // job actions
262  TDEAction *hact = new TDEAction(i18n("&Hold"),"process-stop",0,TQT_TQOBJECT(this),TQT_SLOT(slotHold()),actionCollection(),"job_hold");
263  TDEAction *ract = new TDEAction(i18n("&Resume"),"system-run",0,TQT_TQOBJECT(this),TQT_SLOT(slotResume()),actionCollection(),"job_resume");
264  TDEAction *dact = new TDEAction(i18n("Remo&ve"),"edittrash",Qt::Key_Delete,TQT_TQOBJECT(this),TQT_SLOT(slotRemove()),actionCollection(),"job_remove");
265  TDEAction *sact = new TDEAction(i18n("Res&tart"),"edit-redo",0,TQT_TQOBJECT(this),TQT_SLOT(slotRestart()),actionCollection(),"job_restart");
266  TDEActionMenu *mact = new TDEActionMenu(i18n("&Move to Printer"),"document-print",actionCollection(),"job_move");
267  mact->setDelayed(false);
268  connect(mact->popupMenu(),TQT_SIGNAL(activated(int)),TQT_SLOT(slotMove(int)));
269  connect(mact->popupMenu(),TQT_SIGNAL(aboutToShow()),KMTimer::self(),TQT_SLOT(hold()));
270  connect(mact->popupMenu(),TQT_SIGNAL(aboutToHide()),KMTimer::self(),TQT_SLOT(release()));
271  connect(mact->popupMenu(),TQT_SIGNAL(aboutToShow()),TQT_SLOT(slotShowMoveMenu()));
272  TDEToggleAction *tact = new TDEToggleAction(i18n("&Toggle Completed Jobs"),"history",0,actionCollection(),"view_completed");
273  tact->setEnabled(m_manager->actions() & KMJob::ShowCompleted);
274  connect(tact,TQT_SIGNAL(toggled(bool)),TQT_SLOT(slotShowCompleted(bool)));
275  TDEToggleAction *uact = new TDEToggleAction(i18n("Show Only User Jobs"), "preferences-desktop-personal", 0, actionCollection(), "view_user_jobs");
276  uact->setCheckedState(KGuiItem(i18n("Hide Only User Jobs"),"preferences-desktop-personal"));
277  connect(uact, TQT_SIGNAL(toggled(bool)), TQT_SLOT(slotUserOnly(bool)));
278  m_userfield = new TQLineEdit(0);
279  m_userfield->setText(getenv("USER"));
280  connect(m_userfield, TQT_SIGNAL(returnPressed()), TQT_SLOT(slotUserChanged()));
281  connect(uact, TQT_SIGNAL(toggled(bool)), m_userfield, TQT_SLOT(setEnabled(bool)));
282  m_userfield->setEnabled(false);
283  m_userfield->setSizePolicy(TQSizePolicy(TQSizePolicy::Fixed, TQSizePolicy::Fixed));
284  KWidgetAction *ufact = new KWidgetAction(m_userfield, i18n("User Name"), 0, 0, 0, actionCollection(), "view_username");
285 
286  if (!m_pop)
287  {
288  m_pop = new TQPopupMenu(this);
289  connect(m_pop,TQT_SIGNAL(aboutToShow()),KMTimer::self(),TQT_SLOT(hold()));
290  connect(m_pop,TQT_SIGNAL(aboutToHide()),KMTimer::self(),TQT_SLOT(release()));
291  hact->plug(m_pop);
292  ract->plug(m_pop);
293  m_pop->insertSeparator();
294  dact->plug(m_pop);
295  mact->plug(m_pop);
296  m_pop->insertSeparator();
297  sact->plug(m_pop);
298  }
299 
300  // Filter actions
301  TDEActionMenu *fact = new TDEActionMenu(i18n("&Select Printer"), "tdeprint_printer", actionCollection(), "filter_modify");
302  fact->setDelayed(false);
303  connect(fact->popupMenu(),TQT_SIGNAL(activated(int)),TQT_SLOT(slotPrinterSelected(int)));
304  connect(fact->popupMenu(),TQT_SIGNAL(aboutToShow()),KMTimer::self(),TQT_SLOT(hold()));
305  connect(fact->popupMenu(),TQT_SIGNAL(aboutToHide()),KMTimer::self(),TQT_SLOT(release()));
306  connect(fact->popupMenu(),TQT_SIGNAL(aboutToShow()),TQT_SLOT(slotShowPrinterMenu()));
307 
308  if (!m_standalone)
309  {
310  TDEToolBar *toolbar = toolBar();
311  hact->plug(toolbar);
312  ract->plug(toolbar);
313  toolbar->insertSeparator();
314  dact->plug(toolbar);
315  mact->plug(toolbar);
316  toolbar->insertSeparator();
317  sact->plug(toolbar);
318  toolbar->insertSeparator();
319  tact->plug(toolbar);
320  uact->plug(toolbar);
321  ufact->plug(toolbar);
322  }
323  else
324  {// stand-alone application
325  KStdAction::quit(TQT_TQOBJECT(kapp),TQT_SLOT(quit()),actionCollection());
326  KStdAction::close(TQT_TQOBJECT(this),TQT_SLOT(slotClose()),actionCollection());
327  KStdAction::preferences(TQT_TQOBJECT(this), TQT_SLOT(slotConfigure()), actionCollection());
328 
329  // refresh action
330  new TDEAction(i18n("Refresh"),"reload",0,TQT_TQOBJECT(this),TQT_SLOT(slotRefresh()),actionCollection(),"refresh");
331 
332  // create status bar
333  KStatusBar *statusbar = statusBar();
334  m_stickybox = new TQCheckBox( i18n( "Keep window permanent" ), statusbar );
335  statusbar->addWidget( m_stickybox, 1, false );
336  statusbar->insertItem(" " + i18n("Max.: %1").arg(i18n("Unlimited"))+ " ", 0, 0, true);
337  statusbar->setItemFixed(0);
338  updateStatusBar();
339 
340  createGUI();
341  }
342 
343  loadPluginActions();
344  slotSelectionChanged();
345 }
346 
347 void KMJobViewer::buildPrinterMenu(TQPopupMenu *menu, bool use_all, bool use_specials)
348 {
349  loadPrinters();
350  menu->clear();
351 
352  TQPtrListIterator<KMPrinter> it(m_printers);
353  int i(0);
354  if (use_all)
355  {
356  menu->insertItem(SmallIcon("document-print"), i18n("All Printers"), i++);
357  menu->insertSeparator();
358  }
359  for (; it.current(); ++it, i++)
360  {
361  if ( !it.current()->instanceName().isEmpty() ||
362  ( it.current()->isSpecial() && !use_specials ) )
363  continue;
364  menu->insertItem(SmallIcon(it.current()->pixmap()), it.current()->printerName(), i);
365  }
366 }
367 
368 void KMJobViewer::slotShowMoveMenu()
369 {
370  TQPopupMenu *menu = static_cast<TDEActionMenu*>(actionCollection()->action("job_move"))->popupMenu();
371  buildPrinterMenu(menu, false, false);
372 }
373 
374 void KMJobViewer::slotShowPrinterMenu()
375 {
376  TQPopupMenu *menu = static_cast<TDEActionMenu*>(actionCollection()->action("filter_modify"))->popupMenu();
377  buildPrinterMenu(menu, true, true);
378 }
379 
380 void KMJobViewer::updateJobs()
381 {
382  TQPtrListIterator<JobItem> jit(m_items);
383  for (;jit.current();++jit)
384  jit.current()->setDiscarded(true);
385 
386  TQPtrListIterator<KMJob> it(m_jobs);
387  for (;it.current();++it)
388  {
389  KMJob *j(it.current());
390  JobItem *item = findItem(j->uri());
391  if (item)
392  {
393  item->setDiscarded(false);
394  item->init(j);
395  }
396  else
397  m_items.append(new JobItem(m_view,j));
398  }
399 
400  for (uint i=0; i<m_items.count(); i++)
401  if (m_items.at(i)->isDiscarded())
402  {
403  delete m_items.take(i);
404  i--;
405  }
406 
407  slotSelectionChanged();
408 }
409 
410 JobItem* KMJobViewer::findItem(const TQString& uri)
411 {
412  TQPtrListIterator<JobItem> it(m_items);
413  for (;it.current();++it)
414  if (it.current()->jobUri() == uri) return it.current();
415  return 0;
416 }
417 
418 void KMJobViewer::slotSelectionChanged()
419 {
420  int acts = m_manager->actions();
421  int state(-1);
422  int thread(0);
423  bool completed(true), remote(false);
424 
425  TQPtrListIterator<JobItem> it(m_items);
426  TQPtrList<KMJob> joblist;
427 
428  joblist.setAutoDelete(false);
429  for (;it.current();++it)
430  {
431  if (it.current()->isSelected())
432  {
433  // check if threaded job. "thread" value will be:
434  // 0 -> no jobs
435  // 1 -> only thread jobs
436  // 2 -> only system jobs
437  // 3 -> thread and system jobs
438  if (it.current()->job()->type() == KMJob::Threaded) thread |= 0x1;
439  else thread |= 0x2;
440 
441  if (state == -1) state = it.current()->job()->state();
442  else if (state != 0 && state != it.current()->job()->state()) state = 0;
443 
444  completed = (completed && it.current()->job()->isCompleted());
445  joblist.append(it.current()->job());
446  if (it.current()->job()->isRemote())
447  remote = true;
448  }
449  }
450  if (thread != 2)
451  joblist.clear();
452 
453  actionCollection()->action("job_remove")->setEnabled((thread == 1) || ( !completed && (state >= 0) && (acts & KMJob::Remove)));
454  actionCollection()->action("job_hold")->setEnabled( !completed && (thread == 2) && (state > 0) && (state != KMJob::Held) && (acts & KMJob::Hold));
455  actionCollection()->action("job_resume")->setEnabled( !completed && (thread == 2) && (state > 0) && (state == KMJob::Held) && (acts & KMJob::Resume));
456  actionCollection()->action("job_move")->setEnabled(!remote && !completed && (thread == 2) && (state >= 0) && (acts & KMJob::Move));
457  actionCollection()->action("job_restart")->setEnabled(!remote && (thread == 2) && (state >= 0) && (completed) && (acts & KMJob::Restart));
458 
459  m_manager->validatePluginActions(actionCollection(), joblist);
460 }
461 
462 void KMJobViewer::jobSelection(TQPtrList<KMJob>& l)
463 {
464  l.setAutoDelete(false);
465  TQPtrListIterator<JobItem> it(m_items);
466  for (;it.current();++it)
467  if (it.current()->isSelected())
468  l.append(it.current()->job());
469 }
470 
471 void KMJobViewer::send(int cmd, const TQString& name, const TQString& arg)
472 {
473  KMTimer::self()->hold();
474 
475  TQPtrList<KMJob> l;
476  jobSelection(l);
477  if (!m_manager->sendCommand(l,cmd,arg))
478  {
479  KMessageBox::error(this,"<qt>"+i18n("Unable to perform action \"%1\" on selected jobs. Error received from manager:").arg(name)+"<p>"+KMManager::self()->errorMsg()+"</p></qt>");
480  // error reported, clean it
481  KMManager::self()->setErrorMsg(TQString::null);
482  }
483 
484  triggerRefresh();
485 
486  KMTimer::self()->release();
487 }
488 
489 void KMJobViewer::slotHold()
490 {
491  send(KMJob::Hold,i18n("Hold"));
492 }
493 
494 void KMJobViewer::slotResume()
495 {
496  send(KMJob::Resume,i18n("Resume"));
497 }
498 
499 void KMJobViewer::slotRemove()
500 {
501  send(KMJob::Remove,i18n("Remove"));
502 }
503 
504 void KMJobViewer::slotRestart()
505 {
506  send(KMJob::Restart,i18n("Restart"));
507 }
508 
509 void KMJobViewer::slotMove(int prID)
510 {
511  if (prID >= 0 && prID < (int)(m_printers.count()))
512  {
513  KMPrinter *p = m_printers.at(prID);
514  send(KMJob::Move,i18n("Move to %1").arg(p->printerName()),p->printerName());
515  }
516 }
517 
518 void KMJobViewer::slotRightClicked(TQListViewItem*,const TQPoint& p,int)
519 {
520  if (m_pop) m_pop->popup(p);
521 }
522 
523 void KMJobViewer::loadPrinters()
524 {
525  m_printers.clear();
526 
527  // retrieve printer list without reloading it (faster)
528  TQPtrListIterator<KMPrinter> it(*(KMFactory::self()->manager()->printerList(false)));
529  for (;it.current();++it)
530  {
531  // keep only real printers (no instance, no implicit) and special printers
532  if ((it.current()->isPrinter() || it.current()->isClass(false) ||
533  ( it.current()->isSpecial() && it.current()->isValid() ) )
534  && (it.current()->name() == it.current()->printerName()))
535  m_printers.append(it.current());
536  }
537 }
538 
539 void KMJobViewer::slotPrinterSelected(int prID)
540 {
541  if (prID >= 0 && prID < (int)(m_printers.count()+1))
542  {
543  TQString prname = (prID == 0 ? i18n("All Printers") : m_printers.at(prID-1)->printerName());
544  emit printerChanged(this, prname);
545  }
546 }
547 
548 void KMJobViewer::slotRefresh()
549 {
550  triggerRefresh();
551 }
552 
553 void KMJobViewer::triggerRefresh()
554 {
555  // parent widget -> embedded in KControl and needs
556  // to update itself. Otherwise, it's standalone
557  // kjobviewer and we need to synchronize all possible
558  // opened windows -> do the job on higher level.
559  if (!m_standalone)
560  refresh(true);
561  else
562  emit refreshClicked();
563 }
564 
565 void KMJobViewer::slotShowCompleted(bool on)
566 {
567  removeFromManager();
568  m_type = (on ? KMJobManager::CompletedJobs : KMJobManager::ActiveJobs);
569  addToManager();
570  triggerRefresh();
571 }
572 
573 void KMJobViewer::slotClose()
574 {
575  delete this;
576 }
577 
578 void KMJobViewer::loadPluginActions()
579 {
580  int mpopindex(7), toolbarindex(!m_standalone?7:8), menuindex(7);
581  TQMenuData *menu(0);
582 
583  if (m_standalone)
584  {
585  // standalone window, insert actions into main menubar
586  TDEAction *act = actionCollection()->action("job_restart");
587  for (int i=0;i<act->containerCount();i++)
588  {
589  if (menuBar()->findItem(act->itemId(i), &menu))
590  {
591  menuindex = mpopindex = menu->indexOf(act->itemId(i))+1;
592  break;
593  }
594  }
595  }
596 
597  TQValueList<TDEAction*> acts = m_manager->createPluginActions(actionCollection());
598  for (TQValueListIterator<TDEAction*> it=acts.begin(); it!=acts.end(); ++it)
599  {
600  // connect the action to this
601  connect((*it), TQT_SIGNAL(activated(int)), TQT_SLOT(pluginActionActivated(int)));
602 
603  // should add it to the toolbar and menubar
604  (*it)->plug(toolBar(), toolbarindex++);
605  if (m_pop)
606  (*it)->plug(m_pop, mpopindex++);
607  if (menu)
608  (*it)->plug(static_cast<TQPopupMenu*>(menu), menuindex++);
609  }
610 }
611 
612 void KMJobViewer::removePluginActions()
613 {
614  TQValueList<TDEAction*> acts = actionCollection()->actions("plugin");
615  for (TQValueListIterator<TDEAction*> it=acts.begin(); it!=acts.end(); ++it)
616  {
617  (*it)->unplugAll();
618  delete (*it);
619  }
620 }
621 
622 /*
623 void KMJobViewer::aboutToReload()
624 {
625  if (m_view)
626  {
627  m_view->clear();
628  m_items.clear();
629  }
630  m_jobs.clear();
631 }
632 */
633 
634 void KMJobViewer::reload()
635 {
636  removePluginActions();
637  loadPluginActions();
638  // re-add the current printer to the job manager: the job
639  // manager has been destroyed, so the new one doesn't know
640  // which printer it has to list
641  addToManager();
642  // no refresh needed: view has been cleared before reloading
643  // and the actual refresh will be triggered either by the KControl
644  // module, or by KJobViewerApp using timer.
645 
646  // reload the columns needed: remove the old one
647  for (int c=m_view->columns()-1; c>5; c--)
648  m_view->removeColumn(c);
649  KMFactory::self()->uiManager()->setupJobViewer(m_view);
650 
651  // update the "History" action state
652  actionCollection()->action("view_completed")->setEnabled(m_manager->actions() & KMJob::ShowCompleted);
653  static_cast<TDEToggleAction*>(actionCollection()->action("view_completed"))->setChecked(false);
654 }
655 
656 void KMJobViewer::closeEvent(TQCloseEvent *e)
657 {
658  if (m_standalone && !kapp->sessionSaving())
659  {
660  hide();
661  e->ignore();
662  }
663  else
664  e->accept();
665 }
666 
667 void KMJobViewer::pluginActionActivated(int ID)
668 {
669  KMTimer::self()->hold();
670 
671  TQPtrList<KMJob> joblist;
672  jobSelection(joblist);
673  if (!m_manager->doPluginAction(ID, joblist))
674  KMessageBox::error(this, "<qt>"+i18n("Operation failed.")+"<p>"+KMManager::self()->errorMsg()+"</p></qt>");
675 
676  triggerRefresh();
677  KMTimer::self()->release();
678 }
679 
680 void KMJobViewer::slotUserOnly(bool on)
681 {
682  m_username = (on ? m_userfield->text() : TQString::null);
683  refresh(false);
684 }
685 
686 void KMJobViewer::slotUserChanged()
687 {
688  if (m_userfield->isEnabled())
689  {
690  m_username = m_userfield->text();
691  refresh(false);
692  }
693 }
694 
695 void KMJobViewer::slotConfigure()
696 {
697  KMTimer::self()->hold();
698 
699  KDialogBase dlg(this, 0, true, i18n("Print Job Settings"), KDialogBase::Ok|KDialogBase::Cancel);
700  KMConfigJobs *w = new KMConfigJobs(&dlg);
701  dlg.setMainWidget(w);
702  dlg.resize(300, 10);
703  TDEConfig *conf = KMFactory::self()->printConfig();
704  w->loadConfig(conf);
705  if (dlg.exec())
706  {
707  w->saveConfig(conf);
708  updateStatusBar();
709  refresh(true);
710  }
711 
712  KMTimer::self()->release();
713 }
714 
715 bool KMJobViewer::isSticky() const
716 {
717  return ( m_stickybox ? m_stickybox->isChecked() : false );
718 }
719 
720 void KMJobViewer::slotDropped( TQDropEvent *e, TQListViewItem* )
721 {
722  TQStringList files;
723  TQString target;
724 
725  KURL::List uris;
726  KURLDrag::decode( e, uris );
727  for ( KURL::List::ConstIterator it = uris.begin();
728  it != uris.end(); ++it)
729  {
730  if ( TDEIO::NetAccess::download( *it, target, 0 ) )
731  files << target;
732  }
733 
734  if ( files.count() > 0 )
735  {
736  KPrinter prt;
737  if ( prt.autoConfigure( m_prname, this ) )
738  prt.printFiles( files, false, false );
739  }
740 }
741 
742 #include "kmjobviewer.moc"
KPrinter::autoConfigure
bool autoConfigure(const TQString &prname=TQString::null, TQWidget *parent=0)
Configure the KPrinter object to be used with the printer named prname.
Definition: kprinter.cpp:667
KPrinter
This class is the main interface to access the TDE print framework.
Definition: kprinter.h:88
KPrinter::printFiles
bool printFiles(const TQStringList &files, bool removeafter=false, bool startviewer=true)
Prints the files given in argument.
Definition: kprinter.cpp:358

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.8.11
This website is maintained by Timothy Pearson.