# kdeprint Library API Documentation

Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

# 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("Remo&ve"),"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     uact->setCheckedState(KGuiItem(i18n("Hide Only User Jobs"),"personal"));
    00277     connect(uact, SIGNAL(toggled(bool)), SLOT(slotUserOnly(bool)));
    00278     m_userfield = new QLineEdit(0);
    00279     m_userfield->setText(getenv("USER"));
    00280     connect(m_userfield, SIGNAL(returnPressed()), SLOT(slotUserChanged()));
    00281     connect(uact, SIGNAL(toggled(bool)), m_userfield, SLOT(setEnabled(bool)));
    00282     m_userfield->setEnabled(false);
    00283     m_userfield->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::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 QPopupMenu(this);
    00289         connect(m_pop,SIGNAL(aboutToShow()),KMTimer::self(),SLOT(hold()));
    00290         connect(m_pop,SIGNAL(aboutToHide()),KMTimer::self(),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     KActionMenu *fact = new KActionMenu(i18n("&Select Printer"), "kdeprint_printer", actionCollection(), "filter_modify");
    00302     fact->setDelayed(false);
    00303     connect(fact->popupMenu(),SIGNAL(activated(int)),SLOT(slotPrinterSelected(int)));
    00304     connect(fact->popupMenu(),SIGNAL(aboutToShow()),KMTimer::self(),SLOT(hold()));
    00305     connect(fact->popupMenu(),SIGNAL(aboutToHide()),KMTimer::self(),SLOT(release()));
    00306     connect(fact->popupMenu(),SIGNAL(aboutToShow()),SLOT(slotShowPrinterMenu()));
    00307
    00308     if (!m_standalone)
    00309     {
    00310         KToolBar    *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(kapp,SLOT(quit()),actionCollection());
    00326         KStdAction::close(this,SLOT(slotClose()),actionCollection());
    00327         KStdAction::preferences(this, SLOT(slotConfigure()), actionCollection());
    00328
    00329         // refresh action
    00330         new KAction(i18n("Refresh"),"reload",0,this,SLOT(slotRefresh()),actionCollection(),"refresh");
    00331
    00332         // create status bar
    00333         KStatusBar  *statusbar = statusBar();
    00334         m_stickybox = new QCheckBox( i18n( "Keep window permanent" ), statusbar );
    00335         statusbar->addWidget( m_stickybox, 1, false );
    00336         statusbar->insertItem(" " + i18n("Max.: %1").arg(i18n("Unlimited"))+ " ", 0, 0, true);
    00337         statusbar->setItemFixed(0);
    00338         updateStatusBar();
    00339
    00340         createGUI();
    00341     }
    00342
    00343     loadPluginActions();
    00344     slotSelectionChanged();
    00345 }
    00346
    00347 void KMJobViewer::buildPrinterMenu(QPopupMenu *menu, bool use_all, bool use_specials)
    00348 {
    00349     loadPrinters();
    00350     menu->clear();
    00351
    00352     QPtrListIterator<KMPrinter> it(m_printers);
    00353     int i(0);
    00354     if (use_all)
    00355     {
    00356         menu->insertItem(SmallIcon("fileprint"), i18n("All Printers"), i++);
    00357         menu->insertSeparator();
    00358     }
    00359     for (; it.current(); ++it, i++)
    00360     {
    00361         if ( !it.current()->instanceName().isEmpty() ||
    00362                 ( it.current()->isSpecial() && !use_specials ) )
    00363             continue;
    00364         menu->insertItem(SmallIcon(it.current()->pixmap()), it.current()->printerName(), i);
    00365     }
    00366 }
    00367
    00368 void KMJobViewer::slotShowMoveMenu()
    00369 {
    00370     QPopupMenu  *menu = static_cast<KActionMenu*>(actionCollection()->action("job_move"))->popupMenu();
    00371     buildPrinterMenu(menu, false, false);
    00372 }
    00373
    00374 void KMJobViewer::slotShowPrinterMenu()
    00375 {
    00376     QPopupMenu  *menu = static_cast<KActionMenu*>(actionCollection()->action("filter_modify"))->popupMenu();
    00377     buildPrinterMenu(menu, true, true);
    00378 }
    00379
    00380 void KMJobViewer::updateJobs()
    00381 {
    00382     QPtrListIterator<JobItem>   jit(m_items);
    00383     for (;jit.current();++jit)
    00384         jit.current()->setDiscarded(true);
    00385
    00386     QPtrListIterator<KMJob> it(m_jobs);
    00387     for (;it.current();++it)
    00388     {
    00389         KMJob   *j(it.current());
    00390         JobItem *item = findItem(j->uri());
    00391         if (item)
    00392         {
    00393             item->setDiscarded(false);
    00394             item->init(j);
    00395         }
    00396         else
    00397             m_items.append(new JobItem(m_view,j));
    00398     }
    00399
    00400     for (uint i=0; i<m_items.count(); i++)
    00401         if (m_items.at(i)->isDiscarded())
    00402         {
    00403             delete m_items.take(i);
    00404             i--;
    00405         }
    00406
    00407     slotSelectionChanged();
    00408 }
    00409
    00410 JobItem* KMJobViewer::findItem(const QString& uri)
    00411 {
    00412     QPtrListIterator<JobItem>   it(m_items);
    00413     for (;it.current();++it)
    00414         if (it.current()->jobUri() == uri) return it.current();
    00415     return 0;
    00416 }
    00417
    00418 void KMJobViewer::slotSelectionChanged()
    00419 {
    00420     int acts = m_manager->actions();
    00421     int state(-1);
    00422     int thread(0);
    00423     bool    completed(true), remote(false);
    00424
    00425     QPtrListIterator<JobItem>   it(m_items);
    00426     QPtrList<KMJob> joblist;
    00427
    00428     joblist.setAutoDelete(false);
    00429     for (;it.current();++it)
    00430     {
    00431         if (it.current()->isSelected())
    00432         {
    00433             // check if threaded job. "thread" value will be:
    00434             //  0 -> no jobs
    00435             //  1 -> only thread jobs
    00436             //  2 -> only system jobs
    00437             //  3 -> thread and system jobs
    00438             if (it.current()->job()->type() == KMJob::Threaded) thread |= 0x1;
    00439             else thread |= 0x2;
    00440
    00441             if (state == -1) state = it.current()->job()->state();
    00442             else if (state != 0 && state != it.current()->job()->state()) state = 0;
    00443
    00444             completed = (completed && it.current()->job()->isCompleted());
    00445             joblist.append(it.current()->job());
    00446             if (it.current()->job()->isRemote())
    00447                 remote = true;
    00448         }
    00449     }
    00450     if (thread != 2)
    00451         joblist.clear();
    00452
    00453     actionCollection()->action("job_remove")->setEnabled((thread == 1) || ( !completed && (state >= 0) && (acts & KMJob::Remove)));
    00454     actionCollection()->action("job_hold")->setEnabled( !completed && (thread == 2) && (state > 0) && (state != KMJob::Held) && (acts & KMJob::Hold));
    00455     actionCollection()->action("job_resume")->setEnabled( !completed && (thread == 2) && (state > 0) && (state == KMJob::Held) && (acts & KMJob::Resume));
    00456     actionCollection()->action("job_move")->setEnabled(!remote && !completed && (thread == 2) && (state >= 0) && (acts & KMJob::Move));
    00457     actionCollection()->action("job_restart")->setEnabled(!remote && (thread == 2) && (state >= 0) && (completed) && (acts & KMJob::Restart));
    00458
    00459     m_manager->validatePluginActions(actionCollection(), joblist);
    00460 }
    00461
    00462 void KMJobViewer::jobSelection(QPtrList<KMJob>& l)
    00463 {
    00464     l.setAutoDelete(false);
    00465     QPtrListIterator<JobItem>   it(m_items);
    00466     for (;it.current();++it)
    00467         if (it.current()->isSelected())
    00468             l.append(it.current()->job());
    00469 }
    00470
    00471 void KMJobViewer::send(int cmd, const QString& name, const QString& arg)
    00472 {
    00473     KMTimer::self()->hold();
    00474
    00475     QPtrList<KMJob> l;
    00476     jobSelection(l);
    00477     if (!m_manager->sendCommand(l,cmd,arg))
    00478     {
    00479         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>");
    00480         // error reported, clean it
    00481         KMManager::self()->setErrorMsg(QString::null);
    00482     }
    00483
    00484     triggerRefresh();
    00485
    00486     KMTimer::self()->release();
    00487 }
    00488
    00489 void KMJobViewer::slotHold()
    00490 {
    00491     send(KMJob::Hold,i18n("Hold"));
    00492 }
    00493
    00494 void KMJobViewer::slotResume()
    00495 {
    00496     send(KMJob::Resume,i18n("Resume"));
    00497 }
    00498
    00499 void KMJobViewer::slotRemove()
    00500 {
    00501     send(KMJob::Remove,i18n("Remove"));
    00502 }
    00503
    00504 void KMJobViewer::slotRestart()
    00505 {
    00506     send(KMJob::Restart,i18n("Restart"));
    00507 }
    00508
    00509 void KMJobViewer::slotMove(int prID)
    00510 {
    00511     if (prID >= 0 && prID < (int)(m_printers.count()))
    00512     {
    00513         KMPrinter   *p = m_printers.at(prID);
    00514         send(KMJob::Move,i18n("Move to %1").arg(p->printerName()),p->printerName());
    00515     }
    00516 }
    00517
    00518 void KMJobViewer::slotRightClicked(QListViewItem*,const QPoint& p,int)
    00519 {
    00520     if (m_pop) m_pop->popup(p);
    00521 }
    00522
    00523 void KMJobViewer::loadPrinters()
    00524 {
    00525     m_printers.clear();
    00526
    00527     // retrieve printer list without reloading it (faster)
    00528     QPtrListIterator<KMPrinter> it(*(KMFactory::self()->manager()->printerList(false)));
    00529     for (;it.current();++it)
    00530     {
    00531         // keep only real printers (no instance, no implicit) and special printers
    00532         if ((it.current()->isPrinter() || it.current()->isClass(false) ||
    00533                     ( it.current()->isSpecial() && it.current()->isValid() ) )
    00534                 && (it.current()->name() == it.current()->printerName()))
    00535             m_printers.append(it.current());
    00536     }
    00537 }
    00538
    00539 void KMJobViewer::slotPrinterSelected(int prID)
    00540 {
    00541     if (prID >= 0 && prID < (int)(m_printers.count()+1))
    00542     {
    00543         QString prname = (prID == 0 ? i18n("All Printers") : m_printers.at(prID-1)->printerName());
    00544         emit printerChanged(this, prname);
    00545     }
    00546 }
    00547
    00548 void KMJobViewer::slotRefresh()
    00549 {
    00550     triggerRefresh();
    00551 }
    00552
    00553 void KMJobViewer::triggerRefresh()
    00554 {
    00555     // parent widget -> embedded in KControl and needs
    00556     // to update itself. Otherwise, it's standalone
    00557     // kjobviewer and we need to synchronize all possible
    00558     // opened windows -> do the job on higher level.
    00559     if (!m_standalone)
    00560         refresh(true);
    00561     else
    00562         emit refreshClicked();
    00563 }
    00564
    00565 void KMJobViewer::slotShowCompleted(bool on)
    00566 {
    00567     removeFromManager();
    00568     m_type = (on ? KMJobManager::CompletedJobs : KMJobManager::ActiveJobs);
    00569     addToManager();
    00570     triggerRefresh();
    00571 }
    00572
    00573 void KMJobViewer::slotClose()
    00574 {
    00575     delete this;
    00576 }
    00577
    00578 void KMJobViewer::loadPluginActions()
    00579 {
    00580     int mpopindex(7), toolbarindex(!m_standalone?7:8), menuindex(7);
    00581     QMenuData   *menu(0);
    00582
    00583     if (m_standalone)
    00584     {
    00585         // standalone window, insert actions into main menubar
    00586         KAction *act = actionCollection()->action("job_restart");
    00587         for (int i=0;i<act->containerCount();i++)
    00588         {
    00589             if (menuBar()->findItem(act->itemId(i), &menu))
    00590             {
    00591                 menuindex = mpopindex = menu->indexOf(act->itemId(i))+1;
    00592                 break;
    00593             }
    00594         }
    00595     }
    00596
    00597     QValueList<KAction*>    acts = m_manager->createPluginActions(actionCollection());
    00598     for (QValueListIterator<KAction*> it=acts.begin(); it!=acts.end(); ++it)
    00599     {
    00600         // connect the action to this
    00601         connect((*it), SIGNAL(activated(int)), SLOT(pluginActionActivated(int)));
    00602
    00603         // should add it to the toolbar and menubar
    00604         (*it)->plug(toolBar(), toolbarindex++);
    00605         if (m_pop)
    00606             (*it)->plug(m_pop, mpopindex++);
    00607         if (menu)
    00608             (*it)->plug(static_cast<QPopupMenu*>(menu), menuindex++);
    00609     }
    00610 }
    00611
    00612 void KMJobViewer::removePluginActions()
    00613 {
    00614     QValueList<KAction*>    acts = actionCollection()->actions("plugin");
    00615     for (QValueListIterator<KAction*> it=acts.begin(); it!=acts.end(); ++it)
    00616     {
    00617         (*it)->unplugAll();
    00618         delete (*it);
    00619     }
    00620 }
    00621
    00622 /*
    00623 void KMJobViewer::aboutToReload()
    00624 {
    00625     if (m_view)
    00626     {
    00627         m_view->clear();
    00628         m_items.clear();
    00629     }
    00630     m_jobs.clear();
    00631 }
    00632 */
    00633
    00634 void KMJobViewer::reload()
    00635 {
    00636     removePluginActions();
    00637     loadPluginActions();
    00638     // re-add the current printer to the job manager: the job
    00639     // manager has been destroyed, so the new one doesn't know
    00640     // which printer it has to list
    00641     addToManager();
    00642     // no refresh needed: view has been cleared before reloading
    00643     // and the actual refresh will be triggered either by the KControl
    00644     // module, or by KJobViewerApp using timer.
    00645
    00646     // reload the columns needed: remove the old one
    00647     for (int c=m_view->columns()-1; c>5; c--)
    00648         m_view->removeColumn(c);
    00649     KMFactory::self()->uiManager()->setupJobViewer(m_view);
    00650
    00651     // update the "History" action state
    00652     actionCollection()->action("view_completed")->setEnabled(m_manager->actions() & KMJob::ShowCompleted);
    00653     static_cast<KToggleAction*>(actionCollection()->action("view_completed"))->setChecked(false);
    00654 }
    00655
    00656 void KMJobViewer::closeEvent(QCloseEvent *e)
    00657 {
    00658     if (m_standalone)
    00659     {
    00660         hide();
    00661         e->ignore();
    00662     }
    00663     else
    00664         e->accept();
    00665 }
    00666
    00667 void KMJobViewer::pluginActionActivated(int ID)
    00668 {
    00669     KMTimer::self()->hold();
    00670
    00671     QPtrList<KMJob> joblist;
    00672     jobSelection(joblist);
    00673     if (!m_manager->doPluginAction(ID, joblist))
    00674         KMessageBox::error(this, "<qt>"+i18n("Operation failed.")+"<p>"+KMManager::self()->errorMsg()+"</p></qt>");
    00675
    00676     triggerRefresh();
    00677     KMTimer::self()->release();
    00678 }
    00679
    00680 void KMJobViewer::slotUserOnly(bool on)
    00681 {
    00682     m_username = (on ? m_userfield->text() : QString::null);
    00683     refresh(false);
    00684 }
    00685
    00686 void KMJobViewer::slotUserChanged()
    00687 {
    00688     if (m_userfield->isEnabled())
    00689     {
    00690         m_username = m_userfield->text();
    00691         refresh(false);
    00692     }
    00693 }
    00694
    00695 void KMJobViewer::slotConfigure()
    00696 {
    00697     KMTimer::self()->hold();
    00698
    00699     KDialogBase dlg(this, 0, true, i18n("Print Job Settings"), KDialogBase::Ok|KDialogBase::Cancel);
    00700     KMConfigJobs    *w = new KMConfigJobs(&dlg);
    00701     dlg.setMainWidget(w);
    00702     dlg.resize(300, 10);
    00703     KConfig *conf = KMFactory::self()->printConfig();
    00704     w->loadConfig(conf);
    00705     if (dlg.exec())
    00706     {
    00707         w->saveConfig(conf);
    00708         updateStatusBar();
    00709         refresh(true);
    00710     }
    00711
    00712     KMTimer::self()->release();
    00713 }
    00714
    00715 bool KMJobViewer::isSticky() const
    00716 {
    00717     return ( m_stickybox ? m_stickybox->isChecked() : false );
    00718 }
    00719
    00720 void KMJobViewer::slotDropped( QDropEvent *e, QListViewItem* )
    00721 {
    00722     QStringList files;
    00723     QString target;
    00724
    00725         KURL::List uris;
    00726     KURLDrag::decode( e, uris );
    00727     for ( KURL::List::ConstIterator it = uris.begin();
    00728           it != uris.end(); ++it)
    00729     {
    00730         if ( KIO::NetAccess::download( *it, target, 0 ) )
    00731             files << target;
    00732     }
    00733
    00734     if ( files.count() > 0 )
    00735     {
    00736         KPrinter prt;
    00737         if ( prt.autoConfigure( m_prname, this ) )
    00738             prt.printFiles( files, false, false );
    00739     }
    00740 }
    00741
    00742 #include "kmjobviewer.moc"

This file is part of the documentation for kdeprint Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:31:02 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003