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

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.