• 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 
336  TDEConfig *conf = KMFactory::self()->printConfig();
337  conf->setGroup("Jobs");
338  m_stickybox->setChecked(conf->readBoolEntry("KeepWindow",true));
339  connect(m_stickybox, TQT_SIGNAL(toggled(bool)), TQT_SLOT(slotKeepWindowChange(bool)));
340  statusbar->addWidget( m_stickybox, 1, false );
341  statusbar->insertItem(" " + i18n("Max.: %1").arg(i18n("Unlimited"))+ " ", 0, 0, true);
342  statusbar->setItemFixed(0);
343  updateStatusBar();
344 
345  createGUI();
346  }
347 
348  loadPluginActions();
349  slotSelectionChanged();
350 }
351 
352 void KMJobViewer::buildPrinterMenu(TQPopupMenu *menu, bool use_all, bool use_specials)
353 {
354  loadPrinters();
355  menu->clear();
356 
357  TQPtrListIterator<KMPrinter> it(m_printers);
358  int i(0);
359  if (use_all)
360  {
361  menu->insertItem(SmallIcon("document-print"), i18n("All Printers"), i++);
362  menu->insertSeparator();
363  }
364  for (; it.current(); ++it, i++)
365  {
366  if ( !it.current()->instanceName().isEmpty() ||
367  ( it.current()->isSpecial() && !use_specials ) )
368  continue;
369  menu->insertItem(SmallIcon(it.current()->pixmap()), it.current()->printerName(), i);
370  }
371 }
372 
373 void KMJobViewer::slotKeepWindowChange( bool val )
374 {
375  TDEConfig *conf = KMFactory::self()->printConfig();
376  conf->setGroup("Jobs");
377  conf->writeEntry("KeepWindow",val);
378 }
379 
380 void KMJobViewer::slotShowMoveMenu()
381 {
382  TQPopupMenu *menu = static_cast<TDEActionMenu*>(actionCollection()->action("job_move"))->popupMenu();
383  buildPrinterMenu(menu, false, false);
384 }
385 
386 void KMJobViewer::slotShowPrinterMenu()
387 {
388  TQPopupMenu *menu = static_cast<TDEActionMenu*>(actionCollection()->action("filter_modify"))->popupMenu();
389  buildPrinterMenu(menu, true, true);
390 }
391 
392 void KMJobViewer::updateJobs()
393 {
394  TQPtrListIterator<JobItem> jit(m_items);
395  for (;jit.current();++jit)
396  jit.current()->setDiscarded(true);
397 
398  TQPtrListIterator<KMJob> it(m_jobs);
399  for (;it.current();++it)
400  {
401  KMJob *j(it.current());
402  JobItem *item = findItem(j->uri());
403  if (item)
404  {
405  item->setDiscarded(false);
406  item->init(j);
407  }
408  else
409  m_items.append(new JobItem(m_view,j));
410  }
411 
412  for (uint i=0; i<m_items.count(); i++)
413  if (m_items.at(i)->isDiscarded())
414  {
415  delete m_items.take(i);
416  i--;
417  }
418 
419  slotSelectionChanged();
420 }
421 
422 JobItem* KMJobViewer::findItem(const TQString& uri)
423 {
424  TQPtrListIterator<JobItem> it(m_items);
425  for (;it.current();++it)
426  if (it.current()->jobUri() == uri) return it.current();
427  return 0;
428 }
429 
430 void KMJobViewer::slotSelectionChanged()
431 {
432  int acts = m_manager->actions();
433  int state(-1);
434  int thread(0);
435  bool completed(true), remote(false);
436 
437  TQPtrListIterator<JobItem> it(m_items);
438  TQPtrList<KMJob> joblist;
439 
440  joblist.setAutoDelete(false);
441  for (;it.current();++it)
442  {
443  if (it.current()->isSelected())
444  {
445  // check if threaded job. "thread" value will be:
446  // 0 -> no jobs
447  // 1 -> only thread jobs
448  // 2 -> only system jobs
449  // 3 -> thread and system jobs
450  if (it.current()->job()->type() == KMJob::Threaded) thread |= 0x1;
451  else thread |= 0x2;
452 
453  if (state == -1) state = it.current()->job()->state();
454  else if (state != 0 && state != it.current()->job()->state()) state = 0;
455 
456  completed = (completed && it.current()->job()->isCompleted());
457  joblist.append(it.current()->job());
458  if (it.current()->job()->isRemote())
459  remote = true;
460  }
461  }
462  if (thread != 2)
463  joblist.clear();
464 
465  actionCollection()->action("job_remove")->setEnabled((thread == 1) || ( !completed && (state >= 0) && (acts & KMJob::Remove)));
466  actionCollection()->action("job_hold")->setEnabled( !completed && (thread == 2) && (state > 0) && (state != KMJob::Held) && (acts & KMJob::Hold));
467  actionCollection()->action("job_resume")->setEnabled( !completed && (thread == 2) && (state > 0) && (state == KMJob::Held) && (acts & KMJob::Resume));
468  actionCollection()->action("job_move")->setEnabled(!remote && !completed && (thread == 2) && (state >= 0) && (acts & KMJob::Move));
469  actionCollection()->action("job_restart")->setEnabled(!remote && (thread == 2) && (state >= 0) && (completed) && (acts & KMJob::Restart));
470 
471  m_manager->validatePluginActions(actionCollection(), joblist);
472 }
473 
474 void KMJobViewer::jobSelection(TQPtrList<KMJob>& l)
475 {
476  l.setAutoDelete(false);
477  TQPtrListIterator<JobItem> it(m_items);
478  for (;it.current();++it)
479  if (it.current()->isSelected())
480  l.append(it.current()->job());
481 }
482 
483 void KMJobViewer::send(int cmd, const TQString& name, const TQString& arg)
484 {
485  KMTimer::self()->hold();
486 
487  TQPtrList<KMJob> l;
488  jobSelection(l);
489  if (!m_manager->sendCommand(l,cmd,arg))
490  {
491  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>");
492  // error reported, clean it
493  KMManager::self()->setErrorMsg(TQString::null);
494  }
495 
496  triggerRefresh();
497 
498  KMTimer::self()->release();
499 }
500 
501 void KMJobViewer::slotHold()
502 {
503  send(KMJob::Hold,i18n("Hold"));
504 }
505 
506 void KMJobViewer::slotResume()
507 {
508  send(KMJob::Resume,i18n("Resume"));
509 }
510 
511 void KMJobViewer::slotRemove()
512 {
513  send(KMJob::Remove,i18n("Remove"));
514 }
515 
516 void KMJobViewer::slotRestart()
517 {
518  send(KMJob::Restart,i18n("Restart"));
519 }
520 
521 void KMJobViewer::slotMove(int prID)
522 {
523  if (prID >= 0 && prID < (int)(m_printers.count()))
524  {
525  KMPrinter *p = m_printers.at(prID);
526  send(KMJob::Move,i18n("Move to %1").arg(p->printerName()),p->printerName());
527  }
528 }
529 
530 void KMJobViewer::slotRightClicked(TQListViewItem*,const TQPoint& p,int)
531 {
532  if (m_pop) m_pop->popup(p);
533 }
534 
535 void KMJobViewer::loadPrinters()
536 {
537  m_printers.clear();
538 
539  // retrieve printer list without reloading it (faster)
540  TQPtrListIterator<KMPrinter> it(*(KMFactory::self()->manager()->printerList(false)));
541  for (;it.current();++it)
542  {
543  // keep only real printers (no instance, no implicit) and special printers
544  if ((it.current()->isPrinter() || it.current()->isClass(false) ||
545  ( it.current()->isSpecial() && it.current()->isValid() ) )
546  && (it.current()->name() == it.current()->printerName()))
547  m_printers.append(it.current());
548  }
549 }
550 
551 void KMJobViewer::slotPrinterSelected(int prID)
552 {
553  if (prID >= 0 && prID < (int)(m_printers.count()+1))
554  {
555  TQString prname = (prID == 0 ? i18n("All Printers") : m_printers.at(prID-1)->printerName());
556  emit printerChanged(this, prname);
557  }
558 }
559 
560 void KMJobViewer::slotRefresh()
561 {
562  triggerRefresh();
563 }
564 
565 void KMJobViewer::triggerRefresh()
566 {
567  // parent widget -> embedded in KControl and needs
568  // to update itself. Otherwise, it's standalone
569  // kjobviewer and we need to synchronize all possible
570  // opened windows -> do the job on higher level.
571  if (!m_standalone)
572  refresh(true);
573  else
574  emit refreshClicked();
575 }
576 
577 void KMJobViewer::slotShowCompleted(bool on)
578 {
579  removeFromManager();
580  m_type = (on ? KMJobManager::CompletedJobs : KMJobManager::ActiveJobs);
581  addToManager();
582  triggerRefresh();
583 }
584 
585 void KMJobViewer::slotClose()
586 {
587  delete this;
588 }
589 
590 void KMJobViewer::loadPluginActions()
591 {
592  int mpopindex(7), toolbarindex(!m_standalone?7:8), menuindex(7);
593  TQMenuData *menu(0);
594 
595  if (m_standalone)
596  {
597  // standalone window, insert actions into main menubar
598  TDEAction *act = actionCollection()->action("job_restart");
599  for (int i=0;i<act->containerCount();i++)
600  {
601  if (menuBar()->findItem(act->itemId(i), &menu))
602  {
603  menuindex = mpopindex = menu->indexOf(act->itemId(i))+1;
604  break;
605  }
606  }
607  }
608 
609  TQValueList<TDEAction*> acts = m_manager->createPluginActions(actionCollection());
610  for (TQValueListIterator<TDEAction*> it=acts.begin(); it!=acts.end(); ++it)
611  {
612  // connect the action to this
613  connect((*it), TQT_SIGNAL(activated(int)), TQT_SLOT(pluginActionActivated(int)));
614 
615  // should add it to the toolbar and menubar
616  (*it)->plug(toolBar(), toolbarindex++);
617  if (m_pop)
618  (*it)->plug(m_pop, mpopindex++);
619  if (menu)
620  (*it)->plug(static_cast<TQPopupMenu*>(menu), menuindex++);
621  }
622 }
623 
624 void KMJobViewer::removePluginActions()
625 {
626  TQValueList<TDEAction*> acts = actionCollection()->actions("plugin");
627  for (TQValueListIterator<TDEAction*> it=acts.begin(); it!=acts.end(); ++it)
628  {
629  (*it)->unplugAll();
630  delete (*it);
631  }
632 }
633 
634 /*
635 void KMJobViewer::aboutToReload()
636 {
637  if (m_view)
638  {
639  m_view->clear();
640  m_items.clear();
641  }
642  m_jobs.clear();
643 }
644 */
645 
646 void KMJobViewer::reload()
647 {
648  removePluginActions();
649  loadPluginActions();
650  // re-add the current printer to the job manager: the job
651  // manager has been destroyed, so the new one doesn't know
652  // which printer it has to list
653  addToManager();
654  // no refresh needed: view has been cleared before reloading
655  // and the actual refresh will be triggered either by the KControl
656  // module, or by KJobViewerApp using timer.
657 
658  // reload the columns needed: remove the old one
659  for (int c=m_view->columns()-1; c>5; c--)
660  m_view->removeColumn(c);
661  KMFactory::self()->uiManager()->setupJobViewer(m_view);
662 
663  // update the "History" action state
664  actionCollection()->action("view_completed")->setEnabled(m_manager->actions() & KMJob::ShowCompleted);
665  static_cast<TDEToggleAction*>(actionCollection()->action("view_completed"))->setChecked(false);
666 }
667 
668 void KMJobViewer::closeEvent(TQCloseEvent *e)
669 {
670  if (m_standalone && !kapp->sessionSaving())
671  {
672  hide();
673  e->ignore();
674  }
675  else
676  e->accept();
677 }
678 
679 void KMJobViewer::pluginActionActivated(int ID)
680 {
681  KMTimer::self()->hold();
682 
683  TQPtrList<KMJob> joblist;
684  jobSelection(joblist);
685  if (!m_manager->doPluginAction(ID, joblist))
686  KMessageBox::error(this, "<qt>"+i18n("Operation failed.")+"<p>"+KMManager::self()->errorMsg()+"</p></qt>");
687 
688  triggerRefresh();
689  KMTimer::self()->release();
690 }
691 
692 void KMJobViewer::slotUserOnly(bool on)
693 {
694  m_username = (on ? m_userfield->text() : TQString::null);
695  refresh(false);
696 }
697 
698 void KMJobViewer::slotUserChanged()
699 {
700  if (m_userfield->isEnabled())
701  {
702  m_username = m_userfield->text();
703  refresh(false);
704  }
705 }
706 
707 void KMJobViewer::slotConfigure()
708 {
709  KMTimer::self()->hold();
710 
711  KDialogBase dlg(this, 0, true, i18n("Print Job Settings"), KDialogBase::Ok|KDialogBase::Cancel);
712  KMConfigJobs *w = new KMConfigJobs(&dlg);
713  dlg.setMainWidget(w);
714  dlg.resize(300, 10);
715  TDEConfig *conf = KMFactory::self()->printConfig();
716  w->loadConfig(conf);
717  if (dlg.exec())
718  {
719  w->saveConfig(conf);
720  updateStatusBar();
721  refresh(true);
722  }
723 
724  KMTimer::self()->release();
725 }
726 
727 bool KMJobViewer::isSticky() const
728 {
729  return ( m_stickybox ? m_stickybox->isChecked() : false );
730 }
731 
732 void KMJobViewer::slotDropped( TQDropEvent *e, TQListViewItem* )
733 {
734  TQStringList files;
735  TQString target;
736 
737  KURL::List uris;
738  KURLDrag::decode( e, uris );
739  for ( KURL::List::ConstIterator it = uris.begin();
740  it != uris.end(); ++it)
741  {
742  if ( TDEIO::NetAccess::download( *it, target, 0 ) )
743  files << target;
744  }
745 
746  if ( files.count() > 0 )
747  {
748  KPrinter prt;
749  if ( prt.autoConfigure( m_prname, this ) )
750  prt.printFiles( files, false, false );
751  }
752 }
753 
754 #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.13
This website is maintained by Timothy Pearson.