kdeprint Library API Documentation

kmjobviewer.cpp

00001 /*
00002  *  This file is part of the KDE libraries
00003  *  Copyright (c) 2001 Michael Goffioul <kdeprint@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., 59 Temple Place - Suite 330,
00017  *  Boston, MA 02111-1307, 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 <klistview.h>
00034 #include <kstatusbar.h>
00035 #include <qpopupmenu.h>
00036 #include <kmessagebox.h>
00037 #include <klocale.h>
00038 #include <kpopupmenu.h>
00039 #include <kaction.h>
00040 #include <kstdaction.h>
00041 #include <kiconloader.h>
00042 #include <kapplication.h>
00043 #include <kcursor.h>
00044 #include <kmenubar.h>
00045 #include <kdebug.h>
00046 #include <kwin.h>
00047 #include <kio/netaccess.h>
00048 #include <qtimer.h>
00049 #include <qlayout.h>
00050 #include <stdlib.h>
00051 #include <qlineedit.h>
00052 #include <kdialogbase.h>
00053 #include <qcheckbox.h>
00054 #include <kurldrag.h>
00055 #include <kconfig.h>
00056 
00057 #undef m_manager
00058 #define m_manager   KMFactory::self()->jobManager()
00059 
00060 class KJobListView : public KListView
00061 {
00062 public:
00063     KJobListView( QWidget *parent = 0, const char *name = 0 );
00064 
00065 protected:
00066     bool acceptDrag( QDropEvent* ) const;
00067 };
00068 
00069 KJobListView::KJobListView( QWidget *parent, const char *name )
00070     : KListView( parent, name )
00071 {
00072     setAcceptDrops( true );
00073     setDropVisualizer( false );
00074 }
00075 
00076 bool KJobListView::acceptDrag( QDropEvent *e ) const
00077 {
00078     if ( KURLDrag::canDecode( e ) )
00079         return true;
00080     else
00081         return KListView::acceptDrag( e );
00082 }
00083 
00084 KMJobViewer::KMJobViewer(QWidget *parent, const char *name)
00085 : KMainWindow(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         KConfig *conf = KMFactory::self()->printConfig();
00103         QSize 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         KConfig *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() : QString::null));
00125 }
00126 
00127 void KMJobViewer::setPrinter(const QString& 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 kdeprint. 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     QString pixname("fileprint");
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         QPtrListIterator<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         QPtrListIterator<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     QPtrListIterator<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, SIGNAL( dropped( QDropEvent*, QListViewItem* ) ), SLOT( slotDropped( QDropEvent*, QListViewItem* ) ) );
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(QFrame::WinPanel|QFrame::Sunken);
00247         m_view->setLineWidth(1);
00248         m_view->setSorting(0);
00249         m_view->setAllColumnsShowFocus(true);
00250         m_view->setSelectionMode(QListView::Extended);
00251         connect(m_view,SIGNAL(selectionChanged()),SLOT(slotSelectionChanged()));
00252         connect(m_view,SIGNAL(rightButtonPressed(QListViewItem*,const QPoint&,int)),SLOT(slotRightClicked(QListViewItem*,const QPoint&,int)));
00253         setCentralWidget(m_view);
00254     }
00255 
00256     initActions();
00257 }
00258 
00259 void KMJobViewer::initActions()
00260 {
00261     // job actions
00262     KAction *hact = new KAction(i18n("&Hold"),"stop",0,this,SLOT(slotHold()),actionCollection(),"job_hold");
00263     KAction *ract = new KAction(i18n("&Resume"),"run",0,this,SLOT(slotResume()),actionCollection(),"job_resume");
00264     KAction *dact = new KAction(i18n("R&emove"),"edittrash",Qt::Key_Delete,this,SLOT(slotRemove()),actionCollection(),"job_remove");
00265     KAction *sact = new KAction(i18n("Res&tart"),"redo",0,this,SLOT(slotRestart()),actionCollection(),"job_restart");
00266     KActionMenu *mact = new KActionMenu(i18n("&Move to Printer..."),"fileprint",actionCollection(),"job_move");
00267     mact->setDelayed(false);
00268     connect(mact->popupMenu(),SIGNAL(activated(int)),SLOT(slotMove(int)));
00269     connect(mact->popupMenu(),SIGNAL(aboutToShow()),KMTimer::self(),SLOT(hold()));
00270     connect(mact->popupMenu(),SIGNAL(aboutToHide()),KMTimer::self(),SLOT(release()));
00271     connect(mact->popupMenu(),SIGNAL(aboutToShow()),SLOT(slotShowMoveMenu()));
00272     KToggleAction   *tact = new KToggleAction(i18n("&Toggle Completed Jobs"),"history",0,actionCollection(),"view_completed");
00273     tact->setEnabled(m_manager->actions() & KMJob::ShowCompleted);
00274     connect(tact,SIGNAL(toggled(bool)),SLOT(slotShowCompleted(bool)));
00275     KToggleAction   *uact = new KToggleAction(i18n("Show Only User Jobs"), "personal", 0, actionCollection(), "view_user_jobs");
00276     connect(uact, SIGNAL(toggled(bool)), SLOT(slotUserOnly(bool)));
00277     m_userfield = new QLineEdit(0);
00278     m_userfield->setText(getenv("USER"));
00279     connect(m_userfield, SIGNAL(returnPressed()), SLOT(slotUserChanged()));
00280     connect(uact, SIGNAL(toggled(bool)), m_userfield, SLOT(setEnabled(bool)));
00281     m_userfield->setEnabled(false);
00282     m_userfield->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
00283     KWidgetAction   *ufact = new KWidgetAction(m_userfield, i18n("User Name"), 0, 0, 0, actionCollection(), "view_username");
00284 
00285     if (!m_pop)
00286     {
00287         m_pop = new QPopupMenu(this);
00288         connect(m_pop,SIGNAL(aboutToShow()),KMTimer::self(),SLOT(hold()));
00289         connect(m_pop,SIGNAL(aboutToHide()),KMTimer::self(),SLOT(release()));
00290         hact->plug(m_pop);
00291         ract->plug(m_pop);
00292         m_pop->insertSeparator();
00293         dact->plug(m_pop);
00294         mact->plug(m_pop);
00295         m_pop->insertSeparator();
00296         sact->plug(m_pop);
00297     }
00298 
00299     // Filter actions
00300     KActionMenu *fact = new KActionMenu(i18n("&Select Printer"), "kdeprint_printer", actionCollection(), "filter_modify");
00301     fact->setDelayed(false);
00302     connect(fact->popupMenu(),SIGNAL(activated(int)),SLOT(slotPrinterSelected(int)));
00303     connect(fact->popupMenu(),SIGNAL(aboutToShow()),KMTimer::self(),SLOT(hold()));
00304     connect(fact->popupMenu(),SIGNAL(aboutToHide()),KMTimer::self(),SLOT(release()));
00305     connect(fact->popupMenu(),SIGNAL(aboutToShow()),SLOT(slotShowPrinterMenu()));
00306 
00307     if (!m_standalone)
00308     {
00309         KToolBar    *toolbar = toolBar();
00310         hact->plug(toolbar);
00311         ract->plug(toolbar);
00312         toolbar->insertSeparator();
00313         dact->plug(toolbar);
00314         mact->plug(toolbar);
00315         toolbar->insertSeparator();
00316         sact->plug(toolbar);
00317         toolbar->insertSeparator();
00318         tact->plug(toolbar);
00319         uact->plug(toolbar);
00320         ufact->plug(toolbar);
00321     }
00322     else
00323     {// stand-alone application
00324         KStdAction::quit(kapp,SLOT(quit()),actionCollection());
00325         KStdAction::close(this,SLOT(slotClose()),actionCollection());
00326         KStdAction::preferences(this, SLOT(slotConfigure()), actionCollection());
00327 
00328         // refresh action
00329         new KAction(i18n("Refresh"),"reload",0,this,SLOT(slotRefresh()),actionCollection(),"refresh");
00330 
00331         // create status bar
00332         KStatusBar  *statusbar = statusBar();
00333         m_stickybox = new QCheckBox( i18n( "Keep window permanent" ), statusbar );
00334         statusbar->addWidget( m_stickybox, 1, false );
00335         statusbar->insertItem(" " + i18n("Max.: %1").arg(i18n("Unlimited"))+ " ", 0, 0, true);
00336         statusbar->setItemFixed(0);
00337         updateStatusBar();
00338 
00339         createGUI();
00340     }
00341 
00342     loadPluginActions();
00343     slotSelectionChanged();
00344 }
00345 
00346 void KMJobViewer::buildPrinterMenu(QPopupMenu *menu, bool use_all, bool use_specials)
00347 {
00348     loadPrinters();
00349     menu->clear();
00350 
00351     QPtrListIterator<KMPrinter> it(m_printers);
00352     int i(0);
00353     if (use_all)
00354     {
00355         menu->insertItem(SmallIcon("fileprint"), i18n("All Printers"), i++);
00356         menu->insertSeparator();
00357     }
00358     for (; it.current(); ++it, i++)
00359     {
00360         if ( !it.current()->instanceName().isEmpty() ||
00361                 ( it.current()->isSpecial() && !use_specials ) )
00362             continue;
00363         menu->insertItem(SmallIcon(it.current()->pixmap()), it.current()->printerName(), i);
00364     }
00365 }
00366 
00367 void KMJobViewer::slotShowMoveMenu()
00368 {
00369     QPopupMenu  *menu = static_cast<KActionMenu*>(actionCollection()->action("job_move"))->popupMenu();
00370     buildPrinterMenu(menu, false, false);
00371 }
00372 
00373 void KMJobViewer::slotShowPrinterMenu()
00374 {
00375     QPopupMenu  *menu = static_cast<KActionMenu*>(actionCollection()->action("filter_modify"))->popupMenu();
00376     buildPrinterMenu(menu, true, true);
00377 }
00378 
00379 void KMJobViewer::updateJobs()
00380 {
00381     QPtrListIterator<JobItem>   jit(m_items);
00382     for (;jit.current();++jit)
00383         jit.current()->setDiscarded(true);
00384 
00385     QPtrListIterator<KMJob> it(m_jobs);
00386     for (;it.current();++it)
00387     {
00388         KMJob   *j(it.current());
00389         JobItem *item = findItem(j->uri());
00390         if (item)
00391         {
00392             item->setDiscarded(false);
00393             item->init(j);
00394         }
00395         else
00396             m_items.append(new JobItem(m_view,j));
00397     }
00398 
00399     for (uint i=0; i<m_items.count(); i++)
00400         if (m_items.at(i)->isDiscarded())
00401         {
00402             delete m_items.take(i);
00403             i--;
00404         }
00405 
00406     slotSelectionChanged();
00407 }
00408 
00409 JobItem* KMJobViewer::findItem(const QString& uri)
00410 {
00411     QPtrListIterator<JobItem>   it(m_items);
00412     for (;it.current();++it)
00413         if (it.current()->jobUri() == uri) return it.current();
00414     return 0;
00415 }
00416 
00417 void KMJobViewer::slotSelectionChanged()
00418 {
00419     int acts = m_manager->actions();
00420     int state(-1);
00421     int thread(0);
00422     bool    completed(true), remote(false);
00423 
00424     QPtrListIterator<JobItem>   it(m_items);
00425     QPtrList<KMJob> joblist;
00426 
00427     joblist.setAutoDelete(false);
00428     for (;it.current();++it)
00429     {
00430         if (it.current()->isSelected())
00431         {
00432             // check if threaded job. "thread" value will be:
00433             //  0 -> no jobs
00434             //  1 -> only thread jobs
00435             //  2 -> only system jobs
00436             //  3 -> thread and system jobs
00437             if (it.current()->job()->type() == KMJob::Threaded) thread |= 0x1;
00438             else thread |= 0x2;
00439 
00440             if (state == -1) state = it.current()->job()->state();
00441             else if (state != 0 && state != it.current()->job()->state()) state = 0;
00442 
00443             completed = (completed && it.current()->job()->isCompleted());
00444             joblist.append(it.current()->job());
00445             if (it.current()->job()->isRemote())
00446                 remote = true;
00447         }
00448     }
00449     if (thread != 2)
00450         joblist.clear();
00451 
00452     actionCollection()->action("job_remove")->setEnabled((thread == 1) || ( !completed && (state >= 0) && (acts & KMJob::Remove)));
00453     actionCollection()->action("job_hold")->setEnabled( !completed && (thread == 2) && (state > 0) && (state != KMJob::Held) && (acts & KMJob::Hold));
00454     actionCollection()->action("job_resume")->setEnabled( !completed && (thread == 2) && (state > 0) && (state == KMJob::Held) && (acts & KMJob::Resume));
00455     actionCollection()->action("job_move")->setEnabled(!remote && !completed && (thread == 2) && (state >= 0) && (acts & KMJob::Move));
00456     actionCollection()->action("job_restart")->setEnabled(!remote && (thread == 2) && (state >= 0) && (completed) && (acts & KMJob::Restart));
00457 
00458     m_manager->validatePluginActions(actionCollection(), joblist);
00459 }
00460 
00461 void KMJobViewer::jobSelection(QPtrList<KMJob>& l)
00462 {
00463     l.setAutoDelete(false);
00464     QPtrListIterator<JobItem>   it(m_items);
00465     for (;it.current();++it)
00466         if (it.current()->isSelected())
00467             l.append(it.current()->job());
00468 }
00469 
00470 void KMJobViewer::send(int cmd, const QString& name, const QString& arg)
00471 {
00472     KMTimer::self()->hold();
00473 
00474     QPtrList<KMJob> l;
00475     jobSelection(l);
00476     if (!m_manager->sendCommand(l,cmd,arg))
00477     {
00478         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>");
00479         // error reported, clean it
00480         KMManager::self()->setErrorMsg(QString::null);
00481     }
00482 
00483     triggerRefresh();
00484 
00485     KMTimer::self()->release();
00486 }
00487 
00488 void KMJobViewer::slotHold()
00489 {
00490     send(KMJob::Hold,i18n("Hold"));
00491 }
00492 
00493 void KMJobViewer::slotResume()
00494 {
00495     send(KMJob::Resume,i18n("Resume"));
00496 }
00497 
00498 void KMJobViewer::slotRemove()
00499 {
00500     send(KMJob::Remove,i18n("Remove"));
00501 }
00502 
00503 void KMJobViewer::slotRestart()
00504 {
00505     send(KMJob::Restart,i18n("Restart"));
00506 }
00507 
00508 void KMJobViewer::slotMove(int prID)
00509 {
00510     if (prID >= 0 && prID < (int)(m_printers.count()))
00511     {
00512         KMPrinter   *p = m_printers.at(prID);
00513         send(KMJob::Move,i18n("Move to %1").arg(p->printerName()),p->printerName());
00514     }
00515 }
00516 
00517 void KMJobViewer::slotRightClicked(QListViewItem*,const QPoint& p,int)
00518 {
00519     if (m_pop) m_pop->popup(p);
00520 }
00521 
00522 void KMJobViewer::loadPrinters()
00523 {
00524     m_printers.clear();
00525 
00526     // retrieve printer list without reloading it (faster)
00527     QPtrListIterator<KMPrinter> it(*(KMFactory::self()->manager()->printerList(false)));
00528     for (;it.current();++it)
00529     {
00530         // keep only real printers (no instance, no implicit) and special printers
00531         if ((it.current()->isPrinter() || it.current()->isClass(false) || 
00532                     ( it.current()->isSpecial() && it.current()->isValid() ) )
00533                 && (it.current()->name() == it.current()->printerName()))
00534             m_printers.append(it.current());
00535     }
00536 }
00537 
00538 void KMJobViewer::slotPrinterSelected(int prID)
00539 {
00540     if (prID >= 0 && prID < (int)(m_printers.count()+1))
00541     {
00542         QString prname = (prID == 0 ? i18n("All Printers") : m_printers.at(prID-1)->printerName());
00543         emit printerChanged(this, prname);
00544     }
00545 }
00546 
00547 void KMJobViewer::slotRefresh()
00548 {
00549     triggerRefresh();
00550 }
00551 
00552 void KMJobViewer::triggerRefresh()
00553 {
00554     // parent widget -> embedded in KControl and needs
00555     // to update itself. Otherwise, it's standalone
00556     // kjobviewer and we need to synchronize all possible
00557     // opened windows -> do the job on higher level.
00558     if (!m_standalone)
00559         refresh(true);
00560     else
00561         emit refreshClicked();
00562 }
00563 
00564 void KMJobViewer::slotShowCompleted(bool on)
00565 {
00566     removeFromManager();
00567     m_type = (on ? KMJobManager::CompletedJobs : KMJobManager::ActiveJobs);
00568     addToManager();
00569     triggerRefresh();
00570 }
00571 
00572 void KMJobViewer::slotClose()
00573 {
00574     delete this;
00575 }
00576 
00577 void KMJobViewer::loadPluginActions()
00578 {
00579     int mpopindex(7), toolbarindex(!m_standalone?7:8), menuindex(7);
00580     QMenuData   *menu(0);
00581 
00582     if (m_standalone)
00583     {
00584         // standalone window, insert actions into main menubar
00585         KAction *act = actionCollection()->action("job_restart");
00586         for (int i=0;i<act->containerCount();i++)
00587         {
00588             if (menuBar()->findItem(act->itemId(i), &menu))
00589             {
00590                 menuindex = mpopindex = menu->indexOf(act->itemId(i))+1;
00591                 break;
00592             }
00593         }
00594     }
00595 
00596     QValueList<KAction*>    acts = m_manager->createPluginActions(actionCollection());
00597     for (QValueListIterator<KAction*> it=acts.begin(); it!=acts.end(); ++it)
00598     {
00599         // connect the action to this
00600         connect((*it), SIGNAL(activated(int)), SLOT(pluginActionActivated(int)));
00601 
00602         // should add it to the toolbar and menubar
00603         (*it)->plug(toolBar(), toolbarindex++);
00604         if (m_pop)
00605             (*it)->plug(m_pop, mpopindex++);
00606         if (menu)
00607             (*it)->plug(static_cast<QPopupMenu*>(menu), menuindex++);
00608     }
00609 }
00610 
00611 void KMJobViewer::removePluginActions()
00612 {
00613     QValueList<KAction*>    acts = actionCollection()->actions("plugin");
00614     for (QValueListIterator<KAction*> it=acts.begin(); it!=acts.end(); ++it)
00615     {
00616         (*it)->unplugAll();
00617         delete (*it);
00618     }
00619 }
00620 
00621 /*
00622 void KMJobViewer::aboutToReload()
00623 {
00624     if (m_view)
00625     {
00626         m_view->clear();
00627         m_items.clear();
00628     }
00629     m_jobs.clear();
00630 }
00631 */
00632 
00633 void KMJobViewer::reload()
00634 {
00635     removePluginActions();
00636     loadPluginActions();
00637     // re-add the current printer to the job manager: the job
00638     // manager has been destroyed, so the new one doesn't know
00639     // which printer it has to list
00640     addToManager();
00641     // no refresh needed: view has been cleared before reloading
00642     // and the actual refresh will be triggered either by the KControl
00643     // module, or by KJobViewerApp using timer.
00644 
00645     // reload the columns needed: remove the old one
00646     for (int c=m_view->columns()-1; c>5; c--)
00647         m_view->removeColumn(c);
00648     KMFactory::self()->uiManager()->setupJobViewer(m_view);
00649 
00650     // update the "History" action state
00651     actionCollection()->action("view_completed")->setEnabled(m_manager->actions() & KMJob::ShowCompleted);
00652     static_cast<KToggleAction*>(actionCollection()->action("view_completed"))->setChecked(false);
00653 }
00654 
00655 void KMJobViewer::closeEvent(QCloseEvent *e)
00656 {
00657     if (m_standalone)
00658     {
00659         hide();
00660         e->ignore();
00661     }
00662     else
00663         e->accept();
00664 }
00665 
00666 void KMJobViewer::pluginActionActivated(int ID)
00667 {
00668     KMTimer::self()->hold();
00669 
00670     QPtrList<KMJob> joblist;
00671     jobSelection(joblist);
00672     if (!m_manager->doPluginAction(ID, joblist))
00673         KMessageBox::error(this, "<qt>"+i18n("Operation failed.")+"<p>"+KMManager::self()->errorMsg()+"</p></qt>");
00674 
00675     triggerRefresh();
00676     KMTimer::self()->release();
00677 }
00678 
00679 void KMJobViewer::slotUserOnly(bool on)
00680 {
00681     m_username = (on ? m_userfield->text() : QString::null);
00682     refresh(false);
00683 }
00684 
00685 void KMJobViewer::slotUserChanged()
00686 {
00687     if (m_userfield->isEnabled())
00688     {
00689         m_username = m_userfield->text();
00690         refresh(false);
00691     }
00692 }
00693 
00694 void KMJobViewer::slotConfigure()
00695 {
00696     KMTimer::self()->hold();
00697 
00698     KDialogBase dlg(this, 0, true, i18n("Print Job Settings"), KDialogBase::Ok|KDialogBase::Cancel);
00699     KMConfigJobs    *w = new KMConfigJobs(&dlg);
00700     dlg.setMainWidget(w);
00701     dlg.resize(300, 10);
00702     KConfig *conf = KMFactory::self()->printConfig();
00703     w->loadConfig(conf);
00704     if (dlg.exec())
00705     {
00706         w->saveConfig(conf);
00707         updateStatusBar();
00708         refresh(true);
00709     }
00710 
00711     KMTimer::self()->release();
00712 }
00713 
00714 bool KMJobViewer::isSticky() const
00715 {
00716     return ( m_stickybox ? m_stickybox->isChecked() : false );
00717 }
00718 
00719 void KMJobViewer::slotDropped( QDropEvent *e, QListViewItem* )
00720 {
00721     QStringList files;
00722     QString target;
00723 
00724         KURL::List uris;
00725     KURLDrag::decode( e, uris );
00726     for ( KURL::List::ConstIterator it = uris.begin();
00727           it != uris.end(); ++it)
00728     {
00729         if ( KIO::NetAccess::download( *it, target, 0 ) )
00730             files << target;
00731     }
00732 
00733     if ( files.count() > 0 )
00734     {
00735         KPrinter prt;
00736         if ( prt.autoConfigure( m_prname, this ) )
00737             prt.printFiles( files, false, false );
00738     }
00739 }
00740 
00741 #include "kmjobviewer.moc"
KDE Logo
This file is part of the documentation for kdeprint Library Version 3.2.3.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Sep 30 05:20:49 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2003