kdeprint Library API Documentation

kmjobviewer.cpp

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