• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kdeprint
 

kdeprint

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

kdeprint

Skip menu "kdeprint"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

kdeprint

Skip menu "kdeprint"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kdeprint by doxygen 1.7.6.1
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |