kmjobviewer.cpp
00001 /* 00002 * This file is part of the KDE libraries 00003 * Copyright (c) 2001 Michael Goffioul <tdeprint@swing.be> 00004 * 00005 * This library is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU Library General Public 00007 * License version 2 as published by the Free Software Foundation. 00008 * 00009 * This library is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 * Library General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU Library General Public License 00015 * along with this library; see the file COPYING.LIB. If not, write to 00016 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00017 * Boston, MA 02110-1301, USA. 00018 **/ 00019 00020 #include "kmjobviewer.h" 00021 #include "kmjobmanager.h" 00022 #include "kmfactory.h" 00023 #include "kmjob.h" 00024 #include "kmprinter.h" 00025 #include "kmmanager.h" 00026 #include "kmuimanager.h" 00027 #include "jobitem.h" 00028 #include "kmtimer.h" 00029 #include "kmconfigjobs.h" 00030 #include "kmconfigpage.h" 00031 #include "kprinter.h" 00032 00033 #include <tdelistview.h> 00034 #include <kstatusbar.h> 00035 #include <tqpopupmenu.h> 00036 #include <tdemessagebox.h> 00037 #include <tdelocale.h> 00038 #include <tdepopupmenu.h> 00039 #include <tdeaction.h> 00040 #include <kstdaction.h> 00041 #include <kiconloader.h> 00042 #include <tdeapplication.h> 00043 #include <kcursor.h> 00044 #include <tdemenubar.h> 00045 #include <kdebug.h> 00046 #include <twin.h> 00047 #include <tdeio/netaccess.h> 00048 #include <tqtimer.h> 00049 #include <tqlayout.h> 00050 #include <stdlib.h> 00051 #include <tqlineedit.h> 00052 #include <kdialogbase.h> 00053 #include <tqcheckbox.h> 00054 #include <kurldrag.h> 00055 #include <tdeconfig.h> 00056 00057 #undef m_manager 00058 #define m_manager KMFactory::self()->jobManager() 00059 00060 class KJobListView : public TDEListView 00061 { 00062 public: 00063 KJobListView( TQWidget *parent = 0, const char *name = 0 ); 00064 00065 protected: 00066 bool acceptDrag( TQDropEvent* ) const; 00067 }; 00068 00069 KJobListView::KJobListView( TQWidget *parent, const char *name ) 00070 : TDEListView( parent, name ) 00071 { 00072 setAcceptDrops( true ); 00073 setDropVisualizer( false ); 00074 } 00075 00076 bool KJobListView::acceptDrag( TQDropEvent *e ) const 00077 { 00078 if ( KURLDrag::canDecode( e ) ) 00079 return true; 00080 else 00081 return TDEListView::acceptDrag( e ); 00082 } 00083 00084 KMJobViewer::KMJobViewer(TQWidget *parent, const char *name) 00085 : TDEMainWindow(parent,name) 00086 { 00087 m_view = 0; 00088 m_pop = 0; 00089 m_jobs.setAutoDelete(false); 00090 m_items.setAutoDelete(false); 00091 m_printers.setAutoDelete(false); 00092 m_type = KMJobManager::ActiveJobs; 00093 m_stickybox = 0; 00094 m_standalone = ( parent == NULL ); 00095 00096 setToolBarsMovable(false); 00097 init(); 00098 00099 if (m_standalone) 00100 { 00101 setCaption(i18n("No Printer")); 00102 TDEConfig *conf = KMFactory::self()->printConfig(); 00103 TQSize defSize( 550, 250 ); 00104 conf->setGroup( "Jobs" ); 00105 resize( conf->readSizeEntry( "Size", &defSize ) ); 00106 } 00107 } 00108 00109 KMJobViewer::~KMJobViewer() 00110 { 00111 if (m_standalone) 00112 { 00113 kdDebug( 500 ) << "Destroying stand-alone job viewer window" << endl; 00114 TDEConfig *conf = KMFactory::self()->printConfig(); 00115 conf->setGroup( "Jobs" ); 00116 conf->writeEntry( "Size", size() ); 00117 emit viewerDestroyed(this); 00118 } 00119 removeFromManager(); 00120 } 00121 00122 void KMJobViewer::setPrinter(KMPrinter *p) 00123 { 00124 setPrinter((p ? p->printerName() : TQString::null)); 00125 } 00126 00127 void KMJobViewer::setPrinter(const TQString& prname) 00128 { 00129 // We need to trigger a refresh even if the printer 00130 // has not changed, some jobs may have been canceled 00131 // outside tdeprint. We can't return simply if 00132 // prname == m_prname. 00133 if (m_prname != prname) 00134 { 00135 removeFromManager(); 00136 m_prname = prname; 00137 addToManager(); 00138 m_view->setAcceptDrops( prname != i18n( "All Printers" ) ); 00139 } 00140 triggerRefresh(); 00141 } 00142 00143 void KMJobViewer::updateCaption() 00144 { 00145 if (!m_standalone) 00146 return; 00147 00148 TQString pixname("document-print"); 00149 if (!m_prname.isEmpty()) 00150 { 00151 setCaption(i18n("Print Jobs for %1").arg(m_prname)); 00152 KMPrinter *prt = KMManager::self()->findPrinter(m_prname); 00153 if (prt) 00154 pixname = prt->pixmap(); 00155 } 00156 else 00157 { 00158 setCaption(i18n("No Printer")); 00159 } 00160 KWin::setIcons(winId(), DesktopIcon(pixname), SmallIcon(pixname)); 00161 } 00162 00163 void KMJobViewer::updateStatusBar() 00164 { 00165 if (!m_standalone) 00166 return; 00167 00168 int limit = m_manager->limit(); 00169 if (limit == 0) 00170 statusBar()->changeItem(i18n("Max.: %1").arg(i18n("Unlimited")), 0); 00171 else 00172 statusBar()->changeItem(i18n("Max.: %1").arg(limit), 0); 00173 } 00174 00175 void KMJobViewer::addToManager() 00176 { 00177 if (m_prname == i18n("All Printers")) 00178 { 00179 loadPrinters(); 00180 TQPtrListIterator<KMPrinter> it(m_printers); 00181 for (; it.current(); ++it) 00182 m_manager->addPrinter(it.current()->printerName(), (KMJobManager::JobType)m_type, it.current()->isSpecial()); 00183 } 00184 else if (!m_prname.isEmpty()) 00185 { 00186 KMPrinter *prt = KMManager::self()->findPrinter( m_prname ); 00187 bool isSpecial = ( prt ? prt->isSpecial() : false ); 00188 m_manager->addPrinter(m_prname, (KMJobManager::JobType)m_type, isSpecial); 00189 } 00190 } 00191 00192 void KMJobViewer::removeFromManager() 00193 { 00194 if (m_prname == i18n("All Printers")) 00195 { 00196 TQPtrListIterator<KMPrinter> it(m_printers); 00197 for (; it.current(); ++it) 00198 m_manager->removePrinter(it.current()->printerName(), (KMJobManager::JobType)m_type); 00199 } 00200 else if (!m_prname.isEmpty()) 00201 { 00202 m_manager->removePrinter(m_prname, (KMJobManager::JobType)m_type); 00203 } 00204 } 00205 00206 void KMJobViewer::refresh(bool reload) 00207 { 00208 m_jobs.clear(); 00209 TQPtrListIterator<KMJob> it(m_manager->jobList(reload)); 00210 bool all = (m_prname == i18n("All Printers")), active = (m_type == KMJobManager::ActiveJobs); 00211 for (; it.current(); ++it) 00212 if ((all || it.current()->printer() == m_prname) 00213 && ((it.current()->state() >= KMJob::Cancelled && !active) 00214 || (it.current()->state() < KMJob::Cancelled && active)) 00215 && (m_username.isEmpty() || m_username == it.current()->owner())) 00216 m_jobs.append(it.current()); 00217 updateJobs(); 00218 00219 00220 // update the caption and icon (doesn't do anything if it has a parent widget) 00221 updateCaption(); 00222 00223 updateStatusBar(); 00224 00225 // do it last as this signal can cause this view to be destroyed. No 00226 // code can be executed safely after that 00227 emit jobsShown(this, (m_jobs.count() != 0)); 00228 } 00229 00230 void KMJobViewer::init() 00231 { 00232 if (!m_view) 00233 { 00234 m_view = new KJobListView(this); 00235 m_view->addColumn(i18n("Job ID")); 00236 m_view->addColumn(i18n("Owner")); 00237 m_view->addColumn(i18n("Name"), 150); 00238 m_view->addColumn(i18n("Status", "State")); 00239 m_view->addColumn(i18n("Size (KB)")); 00240 m_view->addColumn(i18n("Page(s)")); 00241 m_view->setColumnAlignment(5,Qt::AlignRight|Qt::AlignVCenter); 00242 connect( m_view, TQT_SIGNAL( dropped( TQDropEvent*, TQListViewItem* ) ), TQT_SLOT( slotDropped( TQDropEvent*, TQListViewItem* ) ) ); 00243 //m_view->addColumn(i18n("Printer")); 00244 //m_view->setColumnAlignment(6,Qt::AlignRight|Qt::AlignVCenter); 00245 KMFactory::self()->uiManager()->setupJobViewer(m_view); 00246 m_view->setFrameStyle(TQFrame::WinPanel|TQFrame::Sunken); 00247 m_view->setLineWidth(1); 00248 m_view->setSorting(0); 00249 m_view->setAllColumnsShowFocus(true); 00250 m_view->setSelectionMode(TQListView::Extended); 00251 connect(m_view,TQT_SIGNAL(selectionChanged()),TQT_SLOT(slotSelectionChanged())); 00252 connect(m_view,TQT_SIGNAL(rightButtonPressed(TQListViewItem*,const TQPoint&,int)),TQT_SLOT(slotRightClicked(TQListViewItem*,const TQPoint&,int))); 00253 setCentralWidget(m_view); 00254 } 00255 00256 initActions(); 00257 } 00258 00259 void KMJobViewer::initActions() 00260 { 00261 // job actions 00262 TDEAction *hact = new TDEAction(i18n("&Hold"),"process-stop",0,TQT_TQOBJECT(this),TQT_SLOT(slotHold()),actionCollection(),"job_hold"); 00263 TDEAction *ract = new TDEAction(i18n("&Resume"),"system-run",0,TQT_TQOBJECT(this),TQT_SLOT(slotResume()),actionCollection(),"job_resume"); 00264 TDEAction *dact = new TDEAction(i18n("Remo&ve"),"edittrash",Qt::Key_Delete,TQT_TQOBJECT(this),TQT_SLOT(slotRemove()),actionCollection(),"job_remove"); 00265 TDEAction *sact = new TDEAction(i18n("Res&tart"),"edit-redo",0,TQT_TQOBJECT(this),TQT_SLOT(slotRestart()),actionCollection(),"job_restart"); 00266 TDEActionMenu *mact = new TDEActionMenu(i18n("&Move to Printer"),"document-print",actionCollection(),"job_move"); 00267 mact->setDelayed(false); 00268 connect(mact->popupMenu(),TQT_SIGNAL(activated(int)),TQT_SLOT(slotMove(int))); 00269 connect(mact->popupMenu(),TQT_SIGNAL(aboutToShow()),KMTimer::self(),TQT_SLOT(hold())); 00270 connect(mact->popupMenu(),TQT_SIGNAL(aboutToHide()),KMTimer::self(),TQT_SLOT(release())); 00271 connect(mact->popupMenu(),TQT_SIGNAL(aboutToShow()),TQT_SLOT(slotShowMoveMenu())); 00272 TDEToggleAction *tact = new TDEToggleAction(i18n("&Toggle Completed Jobs"),"history",0,actionCollection(),"view_completed"); 00273 tact->setEnabled(m_manager->actions() & KMJob::ShowCompleted); 00274 connect(tact,TQT_SIGNAL(toggled(bool)),TQT_SLOT(slotShowCompleted(bool))); 00275 TDEToggleAction *uact = new TDEToggleAction(i18n("Show Only User Jobs"), "preferences-desktop-personal", 0, actionCollection(), "view_user_jobs"); 00276 uact->setCheckedState(KGuiItem(i18n("Hide Only User Jobs"),"preferences-desktop-personal")); 00277 connect(uact, TQT_SIGNAL(toggled(bool)), TQT_SLOT(slotUserOnly(bool))); 00278 m_userfield = new TQLineEdit(0); 00279 m_userfield->setText(getenv("USER")); 00280 connect(m_userfield, TQT_SIGNAL(returnPressed()), TQT_SLOT(slotUserChanged())); 00281 connect(uact, TQT_SIGNAL(toggled(bool)), m_userfield, TQT_SLOT(setEnabled(bool))); 00282 m_userfield->setEnabled(false); 00283 m_userfield->setSizePolicy(TQSizePolicy(TQSizePolicy::Fixed, TQSizePolicy::Fixed)); 00284 KWidgetAction *ufact = new KWidgetAction(m_userfield, i18n("User Name"), 0, 0, 0, actionCollection(), "view_username"); 00285 00286 if (!m_pop) 00287 { 00288 m_pop = new TQPopupMenu(this); 00289 connect(m_pop,TQT_SIGNAL(aboutToShow()),KMTimer::self(),TQT_SLOT(hold())); 00290 connect(m_pop,TQT_SIGNAL(aboutToHide()),KMTimer::self(),TQT_SLOT(release())); 00291 hact->plug(m_pop); 00292 ract->plug(m_pop); 00293 m_pop->insertSeparator(); 00294 dact->plug(m_pop); 00295 mact->plug(m_pop); 00296 m_pop->insertSeparator(); 00297 sact->plug(m_pop); 00298 } 00299 00300 // Filter actions 00301 TDEActionMenu *fact = new TDEActionMenu(i18n("&Select Printer"), "tdeprint_printer", actionCollection(), "filter_modify"); 00302 fact->setDelayed(false); 00303 connect(fact->popupMenu(),TQT_SIGNAL(activated(int)),TQT_SLOT(slotPrinterSelected(int))); 00304 connect(fact->popupMenu(),TQT_SIGNAL(aboutToShow()),KMTimer::self(),TQT_SLOT(hold())); 00305 connect(fact->popupMenu(),TQT_SIGNAL(aboutToHide()),KMTimer::self(),TQT_SLOT(release())); 00306 connect(fact->popupMenu(),TQT_SIGNAL(aboutToShow()),TQT_SLOT(slotShowPrinterMenu())); 00307 00308 if (!m_standalone) 00309 { 00310 TDEToolBar *toolbar = toolBar(); 00311 hact->plug(toolbar); 00312 ract->plug(toolbar); 00313 toolbar->insertSeparator(); 00314 dact->plug(toolbar); 00315 mact->plug(toolbar); 00316 toolbar->insertSeparator(); 00317 sact->plug(toolbar); 00318 toolbar->insertSeparator(); 00319 tact->plug(toolbar); 00320 uact->plug(toolbar); 00321 ufact->plug(toolbar); 00322 } 00323 else 00324 {// stand-alone application 00325 KStdAction::quit(TQT_TQOBJECT(kapp),TQT_SLOT(quit()),actionCollection()); 00326 KStdAction::close(TQT_TQOBJECT(this),TQT_SLOT(slotClose()),actionCollection()); 00327 KStdAction::preferences(TQT_TQOBJECT(this), TQT_SLOT(slotConfigure()), actionCollection()); 00328 00329 // refresh action 00330 new TDEAction(i18n("Refresh"),"reload",0,TQT_TQOBJECT(this),TQT_SLOT(slotRefresh()),actionCollection(),"refresh"); 00331 00332 // create status bar 00333 KStatusBar *statusbar = statusBar(); 00334 m_stickybox = new TQCheckBox( i18n( "Keep window permanent" ), statusbar ); 00335 00336 TDEConfig *conf = KMFactory::self()->printConfig(); 00337 conf->setGroup("Jobs"); 00338 m_stickybox->setChecked(conf->readBoolEntry("KeepWindow",true)); 00339 connect(m_stickybox, TQT_SIGNAL(toggled(bool)), TQT_SLOT(slotKeepWindowChange(bool))); 00340 statusbar->addWidget( m_stickybox, 1, false ); 00341 statusbar->insertItem(" " + i18n("Max.: %1").arg(i18n("Unlimited"))+ " ", 0, 0, true); 00342 statusbar->setItemFixed(0); 00343 updateStatusBar(); 00344 00345 createGUI(); 00346 } 00347 00348 loadPluginActions(); 00349 slotSelectionChanged(); 00350 } 00351 00352 void KMJobViewer::buildPrinterMenu(TQPopupMenu *menu, bool use_all, bool use_specials) 00353 { 00354 loadPrinters(); 00355 menu->clear(); 00356 00357 TQPtrListIterator<KMPrinter> it(m_printers); 00358 int i(0); 00359 if (use_all) 00360 { 00361 menu->insertItem(SmallIcon("document-print"), i18n("All Printers"), i++); 00362 menu->insertSeparator(); 00363 } 00364 for (; it.current(); ++it, i++) 00365 { 00366 if ( !it.current()->instanceName().isEmpty() || 00367 ( it.current()->isSpecial() && !use_specials ) ) 00368 continue; 00369 menu->insertItem(SmallIcon(it.current()->pixmap()), it.current()->printerName(), i); 00370 } 00371 } 00372 00373 void KMJobViewer::slotKeepWindowChange( bool val ) 00374 { 00375 TDEConfig *conf = KMFactory::self()->printConfig(); 00376 conf->setGroup("Jobs"); 00377 conf->writeEntry("KeepWindow",val); 00378 } 00379 00380 void KMJobViewer::slotShowMoveMenu() 00381 { 00382 TQPopupMenu *menu = static_cast<TDEActionMenu*>(actionCollection()->action("job_move"))->popupMenu(); 00383 buildPrinterMenu(menu, false, false); 00384 } 00385 00386 void KMJobViewer::slotShowPrinterMenu() 00387 { 00388 TQPopupMenu *menu = static_cast<TDEActionMenu*>(actionCollection()->action("filter_modify"))->popupMenu(); 00389 buildPrinterMenu(menu, true, true); 00390 } 00391 00392 void KMJobViewer::updateJobs() 00393 { 00394 TQPtrListIterator<JobItem> jit(m_items); 00395 for (;jit.current();++jit) 00396 jit.current()->setDiscarded(true); 00397 00398 TQPtrListIterator<KMJob> it(m_jobs); 00399 for (;it.current();++it) 00400 { 00401 KMJob *j(it.current()); 00402 JobItem *item = findItem(j->uri()); 00403 if (item) 00404 { 00405 item->setDiscarded(false); 00406 item->init(j); 00407 } 00408 else 00409 m_items.append(new JobItem(m_view,j)); 00410 } 00411 00412 for (uint i=0; i<m_items.count(); i++) 00413 if (m_items.at(i)->isDiscarded()) 00414 { 00415 delete m_items.take(i); 00416 i--; 00417 } 00418 00419 slotSelectionChanged(); 00420 } 00421 00422 JobItem* KMJobViewer::findItem(const TQString& uri) 00423 { 00424 TQPtrListIterator<JobItem> it(m_items); 00425 for (;it.current();++it) 00426 if (it.current()->jobUri() == uri) return it.current(); 00427 return 0; 00428 } 00429 00430 void KMJobViewer::slotSelectionChanged() 00431 { 00432 int acts = m_manager->actions(); 00433 int state(-1); 00434 int thread(0); 00435 bool completed(true), remote(false); 00436 00437 TQPtrListIterator<JobItem> it(m_items); 00438 TQPtrList<KMJob> joblist; 00439 00440 joblist.setAutoDelete(false); 00441 for (;it.current();++it) 00442 { 00443 if (it.current()->isSelected()) 00444 { 00445 // check if threaded job. "thread" value will be: 00446 // 0 -> no jobs 00447 // 1 -> only thread jobs 00448 // 2 -> only system jobs 00449 // 3 -> thread and system jobs 00450 if (it.current()->job()->type() == KMJob::Threaded) thread |= 0x1; 00451 else thread |= 0x2; 00452 00453 if (state == -1) state = it.current()->job()->state(); 00454 else if (state != 0 && state != it.current()->job()->state()) state = 0; 00455 00456 completed = (completed && it.current()->job()->isCompleted()); 00457 joblist.append(it.current()->job()); 00458 if (it.current()->job()->isRemote()) 00459 remote = true; 00460 } 00461 } 00462 if (thread != 2) 00463 joblist.clear(); 00464 00465 actionCollection()->action("job_remove")->setEnabled((thread == 1) || ( !completed && (state >= 0) && (acts & KMJob::Remove))); 00466 actionCollection()->action("job_hold")->setEnabled( !completed && (thread == 2) && (state > 0) && (state != KMJob::Held) && (acts & KMJob::Hold)); 00467 actionCollection()->action("job_resume")->setEnabled( !completed && (thread == 2) && (state > 0) && (state == KMJob::Held) && (acts & KMJob::Resume)); 00468 actionCollection()->action("job_move")->setEnabled(!remote && !completed && (thread == 2) && (state >= 0) && (acts & KMJob::Move)); 00469 actionCollection()->action("job_restart")->setEnabled(!remote && (thread == 2) && (state >= 0) && (completed) && (acts & KMJob::Restart)); 00470 00471 m_manager->validatePluginActions(actionCollection(), joblist); 00472 } 00473 00474 void KMJobViewer::jobSelection(TQPtrList<KMJob>& l) 00475 { 00476 l.setAutoDelete(false); 00477 TQPtrListIterator<JobItem> it(m_items); 00478 for (;it.current();++it) 00479 if (it.current()->isSelected()) 00480 l.append(it.current()->job()); 00481 } 00482 00483 void KMJobViewer::send(int cmd, const TQString& name, const TQString& arg) 00484 { 00485 KMTimer::self()->hold(); 00486 00487 TQPtrList<KMJob> l; 00488 jobSelection(l); 00489 if (!m_manager->sendCommand(l,cmd,arg)) 00490 { 00491 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>"); 00492 // error reported, clean it 00493 KMManager::self()->setErrorMsg(TQString::null); 00494 } 00495 00496 triggerRefresh(); 00497 00498 KMTimer::self()->release(); 00499 } 00500 00501 void KMJobViewer::slotHold() 00502 { 00503 send(KMJob::Hold,i18n("Hold")); 00504 } 00505 00506 void KMJobViewer::slotResume() 00507 { 00508 send(KMJob::Resume,i18n("Resume")); 00509 } 00510 00511 void KMJobViewer::slotRemove() 00512 { 00513 send(KMJob::Remove,i18n("Remove")); 00514 } 00515 00516 void KMJobViewer::slotRestart() 00517 { 00518 send(KMJob::Restart,i18n("Restart")); 00519 } 00520 00521 void KMJobViewer::slotMove(int prID) 00522 { 00523 if (prID >= 0 && prID < (int)(m_printers.count())) 00524 { 00525 KMPrinter *p = m_printers.at(prID); 00526 send(KMJob::Move,i18n("Move to %1").arg(p->printerName()),p->printerName()); 00527 } 00528 } 00529 00530 void KMJobViewer::slotRightClicked(TQListViewItem*,const TQPoint& p,int) 00531 { 00532 if (m_pop) m_pop->popup(p); 00533 } 00534 00535 void KMJobViewer::loadPrinters() 00536 { 00537 m_printers.clear(); 00538 00539 // retrieve printer list without reloading it (faster) 00540 TQPtrListIterator<KMPrinter> it(*(KMFactory::self()->manager()->printerList(false))); 00541 for (;it.current();++it) 00542 { 00543 // keep only real printers (no instance, no implicit) and special printers 00544 if ((it.current()->isPrinter() || it.current()->isClass(false) || 00545 ( it.current()->isSpecial() && it.current()->isValid() ) ) 00546 && (it.current()->name() == it.current()->printerName())) 00547 m_printers.append(it.current()); 00548 } 00549 } 00550 00551 void KMJobViewer::slotPrinterSelected(int prID) 00552 { 00553 if (prID >= 0 && prID < (int)(m_printers.count()+1)) 00554 { 00555 TQString prname = (prID == 0 ? i18n("All Printers") : m_printers.at(prID-1)->printerName()); 00556 emit printerChanged(this, prname); 00557 } 00558 } 00559 00560 void KMJobViewer::slotRefresh() 00561 { 00562 triggerRefresh(); 00563 } 00564 00565 void KMJobViewer::triggerRefresh() 00566 { 00567 // parent widget -> embedded in KControl and needs 00568 // to update itself. Otherwise, it's standalone 00569 // kjobviewer and we need to synchronize all possible 00570 // opened windows -> do the job on higher level. 00571 if (!m_standalone) 00572 refresh(true); 00573 else 00574 emit refreshClicked(); 00575 } 00576 00577 void KMJobViewer::slotShowCompleted(bool on) 00578 { 00579 removeFromManager(); 00580 m_type = (on ? KMJobManager::CompletedJobs : KMJobManager::ActiveJobs); 00581 addToManager(); 00582 triggerRefresh(); 00583 } 00584 00585 void KMJobViewer::slotClose() 00586 { 00587 delete this; 00588 } 00589 00590 void KMJobViewer::loadPluginActions() 00591 { 00592 int mpopindex(7), toolbarindex(!m_standalone?7:8), menuindex(7); 00593 TQMenuData *menu(0); 00594 00595 if (m_standalone) 00596 { 00597 // standalone window, insert actions into main menubar 00598 TDEAction *act = actionCollection()->action("job_restart"); 00599 for (int i=0;i<act->containerCount();i++) 00600 { 00601 if (menuBar()->findItem(act->itemId(i), &menu)) 00602 { 00603 menuindex = mpopindex = menu->indexOf(act->itemId(i))+1; 00604 break; 00605 } 00606 } 00607 } 00608 00609 TQValueList<TDEAction*> acts = m_manager->createPluginActions(actionCollection()); 00610 for (TQValueListIterator<TDEAction*> it=acts.begin(); it!=acts.end(); ++it) 00611 { 00612 // connect the action to this 00613 connect((*it), TQT_SIGNAL(activated(int)), TQT_SLOT(pluginActionActivated(int))); 00614 00615 // should add it to the toolbar and menubar 00616 (*it)->plug(toolBar(), toolbarindex++); 00617 if (m_pop) 00618 (*it)->plug(m_pop, mpopindex++); 00619 if (menu) 00620 (*it)->plug(static_cast<TQPopupMenu*>(menu), menuindex++); 00621 } 00622 } 00623 00624 void KMJobViewer::removePluginActions() 00625 { 00626 TQValueList<TDEAction*> acts = actionCollection()->actions("plugin"); 00627 for (TQValueListIterator<TDEAction*> it=acts.begin(); it!=acts.end(); ++it) 00628 { 00629 (*it)->unplugAll(); 00630 delete (*it); 00631 } 00632 } 00633 00634 /* 00635 void KMJobViewer::aboutToReload() 00636 { 00637 if (m_view) 00638 { 00639 m_view->clear(); 00640 m_items.clear(); 00641 } 00642 m_jobs.clear(); 00643 } 00644 */ 00645 00646 void KMJobViewer::reload() 00647 { 00648 removePluginActions(); 00649 loadPluginActions(); 00650 // re-add the current printer to the job manager: the job 00651 // manager has been destroyed, so the new one doesn't know 00652 // which printer it has to list 00653 addToManager(); 00654 // no refresh needed: view has been cleared before reloading 00655 // and the actual refresh will be triggered either by the KControl 00656 // module, or by KJobViewerApp using timer. 00657 00658 // reload the columns needed: remove the old one 00659 for (int c=m_view->columns()-1; c>5; c--) 00660 m_view->removeColumn(c); 00661 KMFactory::self()->uiManager()->setupJobViewer(m_view); 00662 00663 // update the "History" action state 00664 actionCollection()->action("view_completed")->setEnabled(m_manager->actions() & KMJob::ShowCompleted); 00665 static_cast<TDEToggleAction*>(actionCollection()->action("view_completed"))->setChecked(false); 00666 } 00667 00668 void KMJobViewer::closeEvent(TQCloseEvent *e) 00669 { 00670 if (m_standalone && !kapp->sessionSaving()) 00671 { 00672 hide(); 00673 e->ignore(); 00674 } 00675 else 00676 e->accept(); 00677 } 00678 00679 void KMJobViewer::pluginActionActivated(int ID) 00680 { 00681 KMTimer::self()->hold(); 00682 00683 TQPtrList<KMJob> joblist; 00684 jobSelection(joblist); 00685 if (!m_manager->doPluginAction(ID, joblist)) 00686 KMessageBox::error(this, "<qt>"+i18n("Operation failed.")+"<p>"+KMManager::self()->errorMsg()+"</p></qt>"); 00687 00688 triggerRefresh(); 00689 KMTimer::self()->release(); 00690 } 00691 00692 void KMJobViewer::slotUserOnly(bool on) 00693 { 00694 m_username = (on ? m_userfield->text() : TQString::null); 00695 refresh(false); 00696 } 00697 00698 void KMJobViewer::slotUserChanged() 00699 { 00700 if (m_userfield->isEnabled()) 00701 { 00702 m_username = m_userfield->text(); 00703 refresh(false); 00704 } 00705 } 00706 00707 void KMJobViewer::slotConfigure() 00708 { 00709 KMTimer::self()->hold(); 00710 00711 KDialogBase dlg(this, 0, true, i18n("Print Job Settings"), KDialogBase::Ok|KDialogBase::Cancel); 00712 KMConfigJobs *w = new KMConfigJobs(&dlg); 00713 dlg.setMainWidget(w); 00714 dlg.resize(300, 10); 00715 TDEConfig *conf = KMFactory::self()->printConfig(); 00716 w->loadConfig(conf); 00717 if (dlg.exec()) 00718 { 00719 w->saveConfig(conf); 00720 updateStatusBar(); 00721 refresh(true); 00722 } 00723 00724 KMTimer::self()->release(); 00725 } 00726 00727 bool KMJobViewer::isSticky() const 00728 { 00729 return ( m_stickybox ? m_stickybox->isChecked() : false ); 00730 } 00731 00732 void KMJobViewer::slotDropped( TQDropEvent *e, TQListViewItem* ) 00733 { 00734 TQStringList files; 00735 TQString target; 00736 00737 KURL::List uris; 00738 KURLDrag::decode( e, uris ); 00739 for ( KURL::List::ConstIterator it = uris.begin(); 00740 it != uris.end(); ++it) 00741 { 00742 if ( TDEIO::NetAccess::download( *it, target, 0 ) ) 00743 files << target; 00744 } 00745 00746 if ( files.count() > 0 ) 00747 { 00748 KPrinter prt; 00749 if ( prt.autoConfigure( m_prname, this ) ) 00750 prt.printFiles( files, false, false ); 00751 } 00752 } 00753 00754 #include "kmjobviewer.moc"