| # kdeprint Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

# kmmainview.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 "kmmainview.h"
    00021 #include "kmtimer.h"
    00022 #include "kmprinterview.h"
    00023 #include "kmpages.h"
    00024 #include "kmmanager.h"
    00025 #include "kmuimanager.h"
    00026 #include "kmfactory.h"
    00027 #include "kmvirtualmanager.h"
    00028 #include "kmprinter.h"
    00029 #include "driver.h"
    00030 #include "kmdriverdialog.h"
    00031 #include "kmwizard.h"
    00032 #include "kmconfigdialog.h"
    00033 #include "kmspecialprinterdlg.h"
    00034 #include "plugincombobox.h"
    00035 #include "kiconselectaction.h"
    00036 #include "messagewindow.h"
    00037
    00038 #include <qdockarea.h>
    00039 #include <kmenubar.h>
    00040 #include <qtimer.h>
    00041 #include <qcombobox.h>
    00042 #include <qlabel.h>
    00043 #include <qlayout.h>
    00044 #include <qpopupmenu.h>
    00045 #include <kmessagebox.h>
    00046 #include <kaction.h>
    00047 #include <klocale.h>
    00048 #include <kconfig.h>
    00049 #include <ktoolbar.h>
    00050 #include <ktoolbarbutton.h>
    00051 #include <kdebug.h>
    00052 #include <kpopupmenu.h>
    00053 #include <klibloader.h>
    00054 #include <kdialogbase.h>
    00055 #include <ksimpleconfig.h>
    00056 #include <kstandarddirs.h>
    00057 #include <kapplication.h>
    00058
    00059 #undef m_manager
    00060 #define m_manager   KMFactory::self()->manager()
    00061
    00062 int kdeprint_management_add_printer_wizard( QWidget* parent )
    00063 {
    00064         KMWizard    dlg(parent);
    00065         int     flag(0);
    00066         if (dlg.exec())
    00067         {
    00068             flag = 1;
    00069             // check if the printer already exists, and ask confirmation if needed.
    00070             if (KMFactory::self()->manager()->findPrinter(dlg.printer()->name()) != 0)
    00071                 if (KMessageBox::warningYesNo(parent,i18n("The printer %1 already exists. Continuing will overwrite existing printer. Do you want to continue?").arg(dlg.printer()->name())) == KMessageBox::No)
    00072                     flag = 0;
    00073             // try to add printer only if flag is true.
    00074             if (flag && !KMFactory::self()->manager()->createPrinter(dlg.printer()))
    00075                 flag = -1;
    00076         }
    00077         return flag;
    00078 }
    00079
    00080 KMMainView::KMMainView(QWidget *parent, const char *name, KActionCollection *coll)
    00081 : QWidget(parent, name)
    00082 {
    00083     m_current = 0;
    00084     m_first = true;
    00085
    00086     // create widgets
    00087     m_printerview = new KMPrinterView(this, "PrinterView");
    00088     m_printerpages = new KMPages(this, "PrinterPages");
    00089     m_pop = new QPopupMenu(this);
    00090     m_toolbar = new KToolBar(this, "ToolBar");
    00091     m_toolbar->setMovingEnabled(false);
    00092     m_plugin = new PluginComboBox(this, "Plugin");
    00093     /*
    00094     m_menubar = new KMenuBar( this );
    00095     static_cast<KMenuBar*>( m_menubar )->setTopLevelMenu( false );
    00096     */
    00097     m_menubar = new KToolBar( this, "MenuBar", false, false );
    00098     m_menubar->setIconText( KToolBar::IconTextRight );
    00099     m_menubar->setMovingEnabled( false );
    00100
    00101     // layout
    00102     QVBoxLayout *m_layout = new QVBoxLayout(this, 0, 0);
    00103     m_layout->addWidget(m_toolbar);
    00104     m_layout->addWidget( m_menubar );
    00105     m_boxlayout = new QBoxLayout(QBoxLayout::TopToBottom, 0, 0);
    00106     m_layout->addLayout(m_boxlayout);
    00107     m_boxlayout->addWidget(m_printerview);
    00108     m_boxlayout->addWidget(m_printerpages);
    00109     m_layout->addSpacing(5);
    00110     m_layout->addWidget(m_plugin, 0);
    00111
    00112     // connections
    00113     connect(KMTimer::self(),SIGNAL(timeout()),SLOT(slotTimer()));
    00114     connect(m_printerview,SIGNAL(printerSelected(const QString&)),SLOT(slotPrinterSelected(const QString&)));
    00115     connect(m_printerview,SIGNAL(rightButtonClicked(const QString&,const QPoint&)),SLOT(slotRightButtonClicked(const QString&,const QPoint&)));
    00116     connect(m_pop,SIGNAL(aboutToShow()),KMTimer::self(),SLOT(hold()));
    00117     connect(m_pop,SIGNAL(aboutToHide()),KMTimer::self(),SLOT(release()));
    00118     connect( m_manager, SIGNAL( updatePossible( bool ) ), SLOT( slotUpdatePossible( bool ) ) );
    00119
    00120     // actions
    00121     if (coll)
    00122         m_actions = coll;
    00123     else
    00124         m_actions = new KActionCollection(this);
    00125     initActions();
    00126
    00127     // first update
    00128     restoreSettings();
    00129     loadParameters();
    00130
    00131     // delay first update until KMManager is ready
    00132     reset( i18n( "Initializing manager..." ), true, true );
    00133 }
    00134
    00135 KMMainView::~KMMainView()
    00136 {
    00137     saveSettings();
    00138     //KMFactory::release();
    00139 }
    00140
    00141 void KMMainView::loadParameters()
    00142 {
    00143 }
    00144
    00145 void KMMainView::restoreSettings()
    00146 {
    00147     KConfig *conf = KMFactory::self()->printConfig();
    00148     conf->setGroup("General");
    00149     setViewType((KMPrinterView::ViewType)conf->readNumEntry("ViewType",KMPrinterView::Icons));
    00150     setOrientation(conf->readNumEntry("Orientation", Qt::Vertical));
    00151     bool    view = conf->readBoolEntry("ViewToolBar",false);
    00152     slotToggleToolBar(view);
    00153     ((KToggleAction*)m_actions->action("view_toolbar"))->setChecked(view);
    00154     view = conf->readBoolEntry( "ViewMenuBar", true );
    00155     slotToggleMenuBar( view );
    00156     static_cast<KToggleAction*>( m_actions->action( "view_menubar" ) )->setChecked( view );
    00157     view = conf->readBoolEntry("ViewPrinterInfos",true);
    00158     slotShowPrinterInfos(view);
    00159     ((KToggleAction*)m_actions->action("view_printerinfos"))->setChecked(view);
    00160 }
    00161
    00162 void KMMainView::saveSettings()
    00163 {
    00164     KConfig *conf = KMFactory::self()->printConfig();
    00165     conf->setGroup("General");
    00166     conf->writeEntry("ViewType",(int)m_printerview->viewType());
    00167     conf->writeEntry("Orientation",(int)orientation());
    00168     conf->writeEntry("ViewToolBar",((KToggleAction*)m_actions->action("view_toolbar"))->isChecked());
    00169     conf->writeEntry("ViewMenuBar",static_cast<KToggleAction*>( m_actions->action("view_menubar") )->isChecked());
    00170     conf->writeEntry("ViewPrinterInfos",((KToggleAction*)m_actions->action("view_printerinfos"))->isChecked());
    00171     conf->sync();
    00172 }
    00173
    00174 void KMMainView::initActions()
    00175 {
    00176     KIconSelectAction   *vact = new KIconSelectAction(i18n("&View"),0,m_actions,"view_change");
    00177     QStringList iconlst;
    00178     iconlst << "view_icon" << "view_detailed" << "view_tree";
    00179     vact->setItems(QStringList::split(',',i18n("&Icons,&List,&Tree"),false), iconlst);
    00180     vact->setCurrentItem(0);
    00181     connect(vact,SIGNAL(activated(int)),SLOT(slotChangeView(int)));
    00182
    00183     KActionMenu *stateAct = new KActionMenu(i18n("Start/Stop Printer"), "kdeprint_printstate", m_actions, "printer_state_change");
    00184     stateAct->setDelayed(false);
    00185     stateAct->insert(new KAction(i18n("&Start Printer"),"kdeprint_enableprinter",0,this,SLOT(slotChangePrinterState()),m_actions,"printer_start"));
    00186     stateAct->insert(new KAction(i18n("Sto&p Printer"),"kdeprint_stopprinter",0,this,SLOT(slotChangePrinterState()),m_actions,"printer_stop"));
    00187
    00188     stateAct = new KActionMenu(i18n("Enable/Disable Job Spooling"), "kdeprint_queuestate", m_actions, "printer_spool_change");
    00189     stateAct->setDelayed(false);
    00190     stateAct->insert(new KAction(i18n("&Enable Job Spooling"),"kdeprint_enableprinter",0,this,SLOT(slotChangePrinterState()),m_actions,"printer_enable"));
    00191     stateAct->insert(new KAction(i18n("&Disable Job Spooling"),"kdeprint_stopprinter",0,this,SLOT(slotChangePrinterState()),m_actions,"printer_disable"));
    00192
    00193     new KAction(i18n("&Remove"),"edittrash",0,this,SLOT(slotRemove()),m_actions,"printer_remove");
    00194     new KAction(i18n("&Configure..."),"configure",0,this,SLOT(slotConfigure()),m_actions,"printer_configure");
    00195     new KAction(i18n("Add &Printer/Class..."),"kdeprint_addprinter",0,this,SLOT(slotAdd()),m_actions,"printer_add");
    00196     new KAction(i18n("Add &Special (pseudo) Printer..."),"kdeprint_addpseudo",0,this,SLOT(slotAddSpecial()),m_actions,"printer_add_special");
    00197     new KAction(i18n("Set as &Local Default"),"kdeprint_defaulthard",0,this,SLOT(slotHardDefault()),m_actions,"printer_hard_default");
    00198     new KAction(i18n("Set as &User Default"),"kdeprint_defaultsoft",0,this,SLOT(slotSoftDefault()),m_actions,"printer_soft_default");
    00199     new KAction(i18n("&Test Printer..."),"kdeprint_testprinter",0,this,SLOT(slotTest()),m_actions,"printer_test");
    00200     new KAction(i18n("Configure &Manager..."),"kdeprint_configmgr",0,this,SLOT(slotManagerConfigure()),m_actions,"manager_configure");
    00201     new KAction(i18n("Initialize Manager/&View"),"reload",0,this,SLOT(slotInit()),m_actions,"view_refresh");
    00202
    00203     KIconSelectAction   *dact = new KIconSelectAction(i18n("&Orientation"),0,m_actions,"orientation_change");
    00204     iconlst.clear();
    00205     iconlst << "view_top_bottom" << "view_left_right";
    00206     dact->setItems(QStringList::split(',',i18n("&Vertical,&Horizontal"),false), iconlst);
    00207     dact->setCurrentItem(0);
    00208     connect(dact,SIGNAL(activated(int)),SLOT(slotChangeDirection(int)));
    00209
    00210     new KAction(i18n("R&estart Server"),"kdeprint_restartsrv",0,this,SLOT(slotServerRestart()),m_actions,"server_restart");
    00211     new KAction(i18n("Configure &Server..."),"kdeprint_configsrv",0,this,SLOT(slotServerConfigure()),m_actions,"server_configure");
    00212
    00213     KToggleAction   *tact = new KToggleAction(i18n("Show &Toolbar"),0,m_actions,"view_toolbar");
    00214     tact->setCheckedState(i18n("Hide &Toolbar"));
    00215     connect(tact,SIGNAL(toggled(bool)),SLOT(slotToggleToolBar(bool)));
    00216     tact = new KToggleAction( i18n( "Show Me&nu Toolbar" ), 0, m_actions, "view_menubar" );
    00217     tact->setCheckedState(i18n("Hide Me&nu Toolbar"));
    00218     connect( tact, SIGNAL( toggled( bool ) ), SLOT( slotToggleMenuBar( bool ) ) );
    00219     tact = new KToggleAction(i18n("Show Pr&inter Details"),"kdeprint_printer_infos", 0,m_actions,"view_printerinfos");
    00220     tact->setCheckedState(KGuiItem(i18n("Hide Pr&inter Details"),"kdeprint_printer_infos"));
    00221     tact->setChecked(true);
    00222     connect(tact,SIGNAL(toggled(bool)),SLOT(slotShowPrinterInfos(bool)));
    00223
    00224     tact = new KToggleAction(i18n("Toggle Printer &Filtering"), "filter", 0, m_actions, "view_pfilter");
    00225     tact->setChecked(KMManager::self()->isFilterEnabled());
    00226     connect(tact, SIGNAL(toggled(bool)), SLOT(slotToggleFilter(bool)));
    00227
    00228     new KAction( i18n( "%1 &Handbook" ).arg( "KDEPrint" ), "contents", 0, this, SLOT( slotHelp() ), m_actions, "invoke_help" );
    00229     new KAction( i18n( "%1 &Web Site" ).arg( "KDEPrint" ), "network", 0, this, SLOT( slotHelp() ), m_actions, "invoke_web" );
    00230
    00231     KActionMenu *mact = new KActionMenu(i18n("Pri&nter Tools"), "package_utilities", m_actions, "printer_tool");
    00232     mact->setDelayed(false);
    00233     connect(mact->popupMenu(), SIGNAL(activated(int)), SLOT(slotToolSelected(int)));
    00234     QStringList files = KGlobal::dirs()->findAllResources("data", "kdeprint/tools/*.desktop");
    00235     for (QStringList::ConstIterator it=files.begin(); it!=files.end(); ++it)
    00236     {
    00237         KSimpleConfig   conf(*it);
    00238         conf.setGroup("Desktop Entry");
    00239         mact->popupMenu()->insertItem(conf.readEntry("Name", "Unnamed"), mact->popupMenu()->count());
    00240         m_toollist << conf.readEntry("X-KDE-Library");
    00241     }
    00242
    00243     // add actions to the toolbar
    00244     m_actions->action("printer_add")->plug(m_toolbar);
    00245     m_actions->action("printer_add_special")->plug(m_toolbar);
    00246     m_toolbar->insertLineSeparator();
    00247     m_actions->action("printer_state_change")->plug(m_toolbar);
    00248     m_actions->action("printer_spool_change")->plug(m_toolbar);
    00249     m_toolbar->insertSeparator();
    00250     m_actions->action("printer_hard_default")->plug(m_toolbar);
    00251     m_actions->action("printer_soft_default")->plug(m_toolbar);
    00252     m_actions->action("printer_remove")->plug(m_toolbar);
    00253     m_toolbar->insertSeparator();
    00254     m_actions->action("printer_configure")->plug(m_toolbar);
    00255     m_actions->action("printer_test")->plug(m_toolbar);
    00256     m_actions->action("printer_tool")->plug(m_toolbar);
    00257     m_pactionsindex = m_toolbar->insertSeparator();
    00258     m_toolbar->insertLineSeparator();
    00259     m_actions->action("server_restart")->plug(m_toolbar);
    00260     m_actions->action("server_configure")->plug(m_toolbar);
    00261     m_toolbar->insertLineSeparator();
    00262     m_actions->action("manager_configure")->plug(m_toolbar);
    00263     m_actions->action("view_refresh")->plug(m_toolbar);
    00264     m_toolbar->insertLineSeparator();
    00265     m_actions->action("view_printerinfos")->plug(m_toolbar);
    00266     m_actions->action("view_change")->plug(m_toolbar);
    00267     m_actions->action("orientation_change")->plug(m_toolbar);
    00268     m_actions->action("view_pfilter")->plug(m_toolbar);
    00269
    00270     // add actions to the menu bar
    00271     QPopupMenu *menu = new QPopupMenu( this );
    00272     m_actions->action( "printer_add" )->plug( menu );
    00273     m_actions->action( "printer_add_special" )->plug( menu );
    00274     //m_menubar->insertItem( i18n( "Add" ), menu );
    00275     m_menubar->insertButton( "wizard", 0, true, i18n( "Add" ) );
    00276     m_menubar->getButton( 0 )->setPopup( menu, true );
    00277     menu = new QPopupMenu( this );
    00278     m_actions->action("printer_state_change")->plug( menu );
    00279     m_actions->action("printer_spool_change")->plug( menu );
    00280     menu->insertSeparator();
    00281     m_actions->action("printer_hard_default")->plug( menu );
    00282     m_actions->action("printer_soft_default")->plug( menu );
    00283     m_actions->action("printer_remove")->plug( menu );
    00284     menu->insertSeparator();
    00285     m_actions->action("printer_configure")->plug( menu );
    00286     m_actions->action("printer_test")->plug( menu );
    00287     m_actions->action("printer_tool")->plug( menu );
    00288     menu->insertSeparator();
    00289     //m_menubar->insertItem( i18n( "Printer" ), menu );
    00290     m_menubar->insertButton( "printer2", 1, true, i18n( "Printer" ) );
    00291     m_menubar->getButton( 1 )->setPopup( menu, true );
    00292     menu = new QPopupMenu( this );
    00293     m_actions->action("server_restart")->plug( menu );
    00294     m_actions->action("server_configure")->plug( menu );
    00295     //m_menubar->insertItem( i18n( "Server" ), menu );
    00296     m_menubar->insertButton( "misc", 2, true, i18n( "Print Server" ) );
    00297     m_menubar->getButton( 2 )->setPopup( menu, true );
    00298     menu = new QPopupMenu( this );
    00299     m_actions->action("manager_configure")->plug( menu );
    00300     m_actions->action("view_refresh")->plug( menu );
    00301     //m_menubar->insertItem( i18n( "Manager" ), menu );
    00302     m_menubar->insertButton( "konsole3", 3, true, i18n( "Print Manager" ) );
    00303     m_menubar->getButton( 3 )->setPopup( menu, true );
    00304     menu = new QPopupMenu( this );
    00305     m_actions->action("view_printerinfos")->plug( menu );
    00306     m_actions->action("view_change")->plug( menu );
    00307     m_actions->action("orientation_change")->plug( menu );
    00308     m_actions->action( "view_toolbar" )->plug ( menu );
    00309     m_actions->action( "view_menubar" )->plug ( menu );
    00310     menu->insertSeparator();
    00311     m_actions->action("view_pfilter")->plug( menu );
    00312     //m_menubar->insertItem( i18n( "View" ), menu );
    00313     m_menubar->insertButton( "view_remove", 4, true, i18n( "View" ) );
    00314     m_menubar->getButton( 4 )->setPopup( menu, true );
    00315     //m_menubar->setMinimumHeight( m_menubar->heightForWidth( 1000 ) );
    00316     menu = new QPopupMenu( this );
    00317     m_actions->action( "invoke_help" )->plug( menu );
    00318     m_actions->action( "invoke_web" )->plug( menu );
    00319     m_menubar->insertButton( "help", 5, true, i18n( "Documentation" ) );
    00320     m_menubar->getButton( 5 )->setPopup( menu, true );
    00321
    00322     loadPluginActions();
    00323     slotPrinterSelected(QString::null);
    00324 }
    00325
    00326 void KMMainView::slotRefresh()
    00327 {
    00328     // TODO: remove me
    00329 }
    00330
    00331 void KMMainView::slotTimer()
    00332 {
    00333     kdDebug() << "KMMainView::slotTimer" << endl;
    00334     QPtrList<KMPrinter> *printerlist = m_manager->printerList();
    00335     bool ok = m_manager->errorMsg().isEmpty();
    00336     m_printerview->setPrinterList(printerlist);
    00337     if ( m_first )
    00338     {
    00339         if ( !ok )
    00340             showErrorMsg(i18n("An error occurred while retrieving the printer list."));
    00341         else
    00342         {
    00343             /* try to select the most appropriate printer:
    00344              *    - soft default owner printer
    00345              *    - hard default printer
    00346              *    - first printer
    00347              */
    00348             QPtrListIterator<KMPrinter> it( *printerlist );
    00349             KMPrinter *p1 = 0, *p2 = 0, *p3 = 0;
    00350             while ( it.current() )
    00351             {
    00352                 if ( !it.current()->isVirtual() )
    00353                 {
    00354                     if ( it.current()->ownSoftDefault() )
    00355                     {
    00356                         p1 = it.current();
    00357                         break;
    00358                     }
    00359                     else if ( it.current()->isHardDefault() )
    00360                         p2 = it.current();
    00361                     else if ( !p3 )
    00362                         p3 = it.current();
    00363                 }
    00364                 ++it;
    00365             }
    00366             if ( p1 || p2 || p3 )
    00367                 m_printerview->setPrinter( p1 ? p1 : ( p2 ? p2 : p3 ) );
    00368         }
    00369         m_first = false;
    00370     }
    00371 }
    00372
    00373 void KMMainView::slotPrinterSelected(const QString& prname)
    00374 {
    00375     KMPrinter   *p = KMManager::self()->findPrinter(prname);
    00376     m_current = p;
    00377     if (p && !p->isSpecial())
    00378         KMFactory::self()->manager()->completePrinter(p);
    00379     m_printerpages->setPrinter(p);
    00380
    00381     // update actions state (only if toolbar enabled, workaround for toolbar
    00382     // problem).
    00383     //if (m_toolbar->isEnabled())
    00384     //{
    00385         int     mask = (m_manager->hasManagement() ? m_manager->printerOperationMask() : 0);
    00386         bool    sp = !(p && p->isSpecial());
    00387         m_actions->action("printer_remove")->setEnabled(!sp || ((mask & KMManager::PrinterRemoval) && p && p->isLocal() && !p->isImplicit()));
    00388         m_actions->action("printer_configure")->setEnabled(!sp || ((mask & KMManager::PrinterConfigure) && p && !p->isClass(true) /*&& p->isLocal()*/));
    00389         m_actions->action("printer_hard_default")->setEnabled((sp && (mask & KMManager::PrinterDefault) && p && !p->isClass(true) && !p->isHardDefault() && p->isLocal()));
    00390         m_actions->action("printer_soft_default")->setEnabled((p && !p->isSoftDefault()));
    00391         m_actions->action("printer_test")->setEnabled((sp && (mask & KMManager::PrinterTesting) && p && !p->isClass(true)));
    00392         bool    stmask = (sp && (mask & KMManager::PrinterEnabling) && p);
    00393         m_actions->action("printer_state_change")->setEnabled(stmask && p->isLocal());
    00394         m_actions->action("printer_spool_change")->setEnabled(stmask);
    00395         m_actions->action("printer_start")->setEnabled((stmask && p->state() == KMPrinter::Stopped));
    00396         m_actions->action("printer_stop")->setEnabled((stmask && p->state() != KMPrinter::Stopped));
    00397         m_actions->action("printer_enable")->setEnabled((stmask && !p->acceptJobs()));
    00398         m_actions->action("printer_disable")->setEnabled((stmask && p->acceptJobs()));
    00399
    00400         m_actions->action("printer_add")->setEnabled((mask & KMManager::PrinterCreation));
    00401         mask = m_manager->serverOperationMask();
    00402         m_actions->action("server_restart")->setEnabled((mask & KMManager::ServerRestarting));
    00403         m_actions->action("server_configure")->setEnabled((mask & KMManager::ServerConfigure));
    00404
    00405         KMFactory::self()->manager()->validatePluginActions(m_actions, p);
    00406     //}
    00407     m_actions->action("printer_tool")->setEnabled(p && !p->isClass(true) && !p->isRemote() && !p->isSpecial());
    00408 }
    00409
    00410 void KMMainView::setViewType(int ID)
    00411 {
    00412     ((KSelectAction*)m_actions->action("view_change"))->setCurrentItem(ID);
    00413     slotChangeView(ID);
    00414 }
    00415
    00416 int KMMainView::viewType() const
    00417 { return m_printerview->viewType(); }
    00418
    00419 void KMMainView::slotChangeView(int ID)
    00420 {
    00421     kdDebug() << "KMMainView::slotChangeView" << endl;
    00422     if (ID >= KMPrinterView::Icons && ID <= KMPrinterView::Tree)
    00423         m_printerview->setViewType((KMPrinterView::ViewType)ID);
    00424 }
    00425
    00426 void KMMainView::slotRightButtonClicked(const QString& prname, const QPoint& p)
    00427 {
    00428     KMPrinter   *printer = KMManager::self()->findPrinter(prname);
    00429     // construct popup menu
    00430     m_pop->clear();
    00431     if (printer)
    00432     {
    00433         m_current = printer;
    00434         if (!printer->isSpecial())
    00435         {
    00436             if (printer->isLocal())
    00437                 m_actions->action((printer->state() == KMPrinter::Stopped ? "printer_start" : "printer_stop"))->plug(m_pop);
    00438             m_actions->action((printer->acceptJobs() ? "printer_disable" : "printer_enable"))->plug(m_pop);
    00439             m_pop->insertSeparator();
    00440         }
    00441         if (!printer->isSoftDefault()) m_actions->action("printer_soft_default")->plug(m_pop);
    00442         if (printer->isLocal() && !printer->isImplicit())
    00443         {
    00444             if (!printer->isHardDefault()) m_actions->action("printer_hard_default")->plug(m_pop);
    00445             m_actions->action("printer_remove")->plug(m_pop);
    00446             m_pop->insertSeparator();
    00447             if (!printer->isClass(true))
    00448             {
    00449                 m_actions->action("printer_configure")->plug(m_pop);
    00450                 m_actions->action("printer_test")->plug(m_pop);
    00451                 m_actions->action("printer_tool")->plug(m_pop);
    00452                 m_pop->insertSeparator();
    00453             }
    00454         }
    00455         else
    00456         {
    00457             if (!printer->isClass(true))
    00458             {
    00459                 m_actions->action("printer_configure")->plug(m_pop);
    00460                 m_actions->action("printer_test")->plug(m_pop);
    00461             }
    00462             m_pop->insertSeparator();
    00463         }
    00464         if (!printer->isSpecial())
    00465         {
    00466             QValueList<KAction*>    pactions = m_actions->actions("plugin");
    00467             for (QValueList<KAction*>::Iterator it=pactions.begin(); it!=pactions.end(); ++it)
    00468                 (*it)->plug(m_pop);
    00469             if (pactions.count() > 0)
    00470                 m_pop->insertSeparator();
    00471         }
    00472     }
    00473     else
    00474     {
    00475         m_actions->action("printer_add")->plug(m_pop);
    00476         m_actions->action("printer_add_special")->plug(m_pop);
    00477         m_pop->insertSeparator();
    00478         m_actions->action("server_restart")->plug(m_pop);
    00479         m_actions->action("server_configure")->plug(m_pop);
    00480         m_pop->insertSeparator();
    00481         m_actions->action("manager_configure")->plug(m_pop);
    00482         m_actions->action("view_refresh")->plug(m_pop);
    00483         m_pop->insertSeparator();
    00484     }
    00485     m_actions->action("view_printerinfos")->plug(m_pop);
    00486     m_actions->action("view_change")->plug(m_pop);
    00487     m_actions->action("orientation_change")->plug(m_pop);
    00488     m_actions->action("view_toolbar")->plug(m_pop);
    00489     m_actions->action("view_menubar")->plug(m_pop);
    00490     m_pop->insertSeparator();
    00491     m_actions->action("view_pfilter")->plug(m_pop);
    00492
    00493     // pop the menu
    00494     m_pop->popup(p);
    00495 }
    00496
    00497 void KMMainView::slotChangePrinterState()
    00498 {
    00499     QString opname = sender()->name();
    00500     if (m_current && opname.startsWith("printer_"))
    00501     {
    00502         opname = opname.mid(8);
    00503         KMTimer::self()->hold();
    00504         bool    result(false);
    00505         if (opname == "enable")
    00506             result = m_manager->enablePrinter(m_current, true);
    00507         else if (opname == "disable")
    00508             result = m_manager->enablePrinter(m_current, false);
    00509         else if (opname == "start")
    00510             result = m_manager->startPrinter(m_current, true);
    00511         else if (opname == "stop")
    00512             result = m_manager->startPrinter(m_current, false);
    00513         if (!result)
    00514             showErrorMsg(i18n("Unable to modify the state of printer %1.").arg(m_current->printerName()));
    00515         KMTimer::self()->release(result);
    00516     }
    00517 }
    00518
    00519 void KMMainView::slotRemove()
    00520 {
    00521     if (m_current)
    00522     {
    00523         KMTimer::self()->hold();
    00524         bool    result(false);
    00525         if (KMessageBox::warningYesNo(this,i18n("Do you really want to remove %1?").arg(m_current->printerName())) == KMessageBox::Yes)
    00526             if (m_current->isSpecial())
    00527             {
    00528                 if (!(result=m_manager->removeSpecialPrinter(m_current)))
    00529                     showErrorMsg(i18n("Unable to remove special printer %1.").arg(m_current->printerName()));
    00530             }
    00531             else if (!(result=m_manager->removePrinter(m_current)))
    00532                 showErrorMsg(i18n("Unable to remove printer %1.").arg(m_current->printerName()));
    00533         KMTimer::self()->release(result);
    00534     }
    00535 }
    00536
    00537 void KMMainView::slotConfigure()
    00538 {
    00539     if (m_current)
    00540     {
    00541         KMTimer::self()->hold();
    00542         bool    needRefresh(false);
    00543         if (m_current->isSpecial())
    00544         {
    00545             KMSpecialPrinterDlg dlg(this);
    00546             dlg.setPrinter(m_current);
    00547             if (dlg.exec())
    00548             {
    00549                 KMPrinter   *prt = dlg.printer();
    00550                 if (prt->name() != m_current->name())
    00551                     m_manager->removeSpecialPrinter(m_current);
    00552                 m_manager->createSpecialPrinter(prt);
    00553                 needRefresh = true;
    00554             }
    00555         }
    00556         else
    00557         {
    00558             DrMain  *driver = m_manager->loadPrinterDriver(m_current, true);
    00559             if (driver)
    00560             {
    00561                 KMDriverDialog  dlg(this);
    00562                 dlg.setCaption(i18n("Configure %1").arg(m_current->printerName()));
    00563                 dlg.setDriver(driver);
    00564                 // disable OK button for remote printer (read-only dialog)
    00565                 if (m_current->isRemote())
    00566                     dlg.enableButtonOK(false);
    00567                 if (dlg.exec())
    00568                     if (!m_manager->savePrinterDriver(m_current,driver))
    00569                         showErrorMsg(i18n("Unable to modify settings of printer %1.").arg(m_current->printerName()));
    00570                 delete driver;
    00571             }
    00572             else
    00573                 showErrorMsg(i18n("Unable to load a valid driver for printer %1.").arg(m_current->printerName()));
    00574         }
    00575         KMTimer::self()->release(needRefresh);
    00576     }
    00577 }
    00578
    00579 void KMMainView::slotAdd()
    00580 {
    00581     KMTimer::self()->hold();
    00582
    00583     int result(0);
    00584     if ((result=kdeprint_management_add_printer_wizard(this)) == -1)
    00585         showErrorMsg(i18n("Unable to create printer."));
    00586
    00587     KMTimer::self()->release((result == 1));
    00588 }
    00589
    00590 void KMMainView::slotHardDefault()
    00591 {
    00592     if (m_current)
    00593     {
    00594         KMTimer::self()->hold();
    00595         bool    result = m_manager->setDefaultPrinter(m_current);
    00596         if (!result)
    00597             showErrorMsg(i18n("Unable to define printer %1 as default.").arg(m_current->printerName()));
    00598         KMTimer::self()->release(result);
    00599     }
    00600 }
    00601
    00602 void KMMainView::slotSoftDefault()
    00603 {
    00604     if (m_current)
    00605     {
    00606         KMTimer::self()->hold();
    00607         KMFactory::self()->virtualManager()->setAsDefault(m_current,QString::null);
    00608         KMTimer::self()->release(true);
    00609     }
    00610 }
    00611
    00612 void KMMainView::setOrientation(int o)
    00613 {
    00614     int     ID = (o == Qt::Horizontal ? 1 : 0);
    00615     ((KSelectAction*)m_actions->action("orientation_change"))->setCurrentItem(ID);
    00616     slotChangeDirection(ID);
    00617 }
    00618
    00619 int KMMainView::orientation() const
    00620 { return (m_boxlayout->direction() == QBoxLayout::LeftToRight ? Qt::Horizontal : Qt::Vertical);  }
    00621
    00622 void KMMainView::slotChangeDirection(int d)
    00623 {
    00624     m_boxlayout->setDirection(d == 1 ? QBoxLayout::LeftToRight : QBoxLayout::TopToBottom);
    00625 }
    00626
    00627 void KMMainView::slotTest()
    00628 {
    00629     if (m_current)
    00630     {
    00631         KMTimer::self()->hold();
    00632         if (KMessageBox::warningContinueCancel(this, i18n("You are about to print a test page on %1. Do you want to continue?").arg(m_current->printerName()), QString::null, i18n("Print Test Page"), "printTestPage") == KMessageBox::Continue)
    00633         {
    00634             if (KMFactory::self()->manager()->testPrinter(m_current))
    00635                 KMessageBox::information(this,i18n("Test page successfully sent to printer %1.").arg(m_current->printerName()));
    00636             else
    00637                 showErrorMsg(i18n("Unable to test printer %1.").arg(m_current->printerName()));
    00638         }
    00639         KMTimer::self()->release(true);
    00640     }
    00641 }
    00642
    00643 void KMMainView::showErrorMsg(const QString& msg, bool usemgr)
    00644 {
    00645     QString s(msg);
    00646     if (usemgr)
    00647     {
    00648         s.prepend("<p>");
    00649         s.append(" ");
    00650         s += i18n("Error message received from manager:</p><p>%1</p>");
    00651         if (m_manager->errorMsg().isEmpty())
    00652             s = s.arg(i18n("Internal error (no error message)."));
    00653         else
    00654             s = s.arg(m_manager->errorMsg());
    00655         // clean up error message
    00656         m_manager->setErrorMsg(QString::null);
    00657     }
    00658     s.prepend("<qt>").append("</qt>");
    00659     KMTimer::self()->hold();
    00660     KMessageBox::error(this,s);
    00661     KMTimer::self()->release();
    00662 }
    00663
    00664 void KMMainView::slotServerRestart()
    00665 {
    00666     KMTimer::self()->hold();
    00667     bool    result = m_manager->restartServer();
    00668     if (!result)
    00669     {
    00670         showErrorMsg(i18n("Unable to restart print server."));
    00671         KMTimer::self()->release( false );
    00672     }
    00673     else
    00674     {
    00675         reset( i18n( "Restarting server..." ), false, false );
    00676     }
    00677 }
    00678
    00679 void KMMainView::slotServerConfigure()
    00680 {
    00681     KMTimer::self()->hold();
    00682     bool    result = m_manager->configureServer(this);
    00683     if (!result)
    00684     {
    00685         showErrorMsg(i18n("Unable to configure print server."));
    00686         KMTimer::self()->release( false );
    00687     }
    00688     else
    00689     {
    00690         reset( i18n( "Configuring server..." ), false, false );
    00691     }
    00692 }
    00693
    00694 void KMMainView::slotToggleToolBar(bool on)
    00695 {
    00696     if (on) m_toolbar->show();
    00697     else m_toolbar->hide();
    00698 }
    00699
    00700 void KMMainView::slotToggleMenuBar( bool on )
    00701 {
    00702     if ( on )
    00703         m_menubar->show();
    00704     else
    00705         m_menubar->hide();
    00706 }
    00707
    00708 void KMMainView::slotManagerConfigure()
    00709 {
    00710     KMTimer::self()->hold();
    00711     KMConfigDialog  dlg(this,"ConfigDialog");
    00712     if ( dlg.exec() )
    00713     {
    00714         loadParameters();
    00715     }
    00716     /* when "OK":
    00717      *  => the config file is saved
    00718      *  => triggering a DCOP signal
    00719      *  => configChanged() called
    00720      * hence no need to refresh, just release the timer
    00721      */
    00722     KMTimer::self()->release( false );
    00723 }
    00724
    00725 void KMMainView::slotAddSpecial()
    00726 {
    00727     KMTimer::self()->hold();
    00728     KMSpecialPrinterDlg dlg(this);
    00729     if (dlg.exec())
    00730     {
    00731         KMPrinter   *prt = dlg.printer();
    00732         m_manager->createSpecialPrinter(prt);
    00733     }
    00734     KMTimer::self()->release(true);
    00735 }
    00736
    00737 void KMMainView::slotShowPrinterInfos(bool on)
    00738 {
    00739     if (on)
    00740         m_printerpages->show();
    00741     else
    00742         m_printerpages->hide();
    00743     m_actions->action("orientation_change")->setEnabled(on);
    00744 }
    00745
    00746 void KMMainView::enableToolbar(bool on)
    00747 {
    00748     KToggleAction   *act = (KToggleAction*)m_actions->action("view_toolbar");
    00749     m_toolbar->setEnabled(on);
    00750     act->setEnabled(on);
    00751     if (on && act->isChecked())
    00752         m_toolbar->show();
    00753     else
    00754         m_toolbar->hide();
    00755 }
    00756
    00757 KAction* KMMainView::action(const char *name)
    00758 {
    00759     return m_actions->action(name);
    00760 }
    00761
    00762 /*
    00763 void KMMainView::aboutToReload()
    00764 {
    00765     m_printerview->setPrinterList(0);
    00766 }
    00767 */
    00768
    00769 void KMMainView::reload()
    00770 {
    00771     removePluginActions();
    00772     loadPluginActions();
    00773
    00774     // redo the connection as the old manager object has been removed
    00775     connect( m_manager, SIGNAL( updatePossible( bool ) ), SLOT( slotUpdatePossible( bool ) ) );
    00776
    00777     // We must delay the refresh such that all objects has been
    00778     // correctly reloaded (otherwise, crash in KMJobViewer).
    00779     reset( i18n( "Initializing manager..." ), true, true );
    00780 }
    00781
    00782 void KMMainView::showPrinterInfos(bool on)
    00783 {
    00784     static_cast<KToggleAction*>(m_actions->action("view_printerinfos"))->setChecked(on);
    00785     slotShowPrinterInfos(on);
    00786 }
    00787
    00788 bool KMMainView::printerInfosShown() const
    00789 {
    00790     return (static_cast<KToggleAction*>(m_actions->action("view_printerinfos"))->isChecked());
    00791 }
    00792
    00793 void KMMainView::loadPluginActions()
    00794 {
    00795     KMFactory::self()->manager()->createPluginActions(m_actions);
    00796     QValueList<KAction*>    pactions = m_actions->actions("plugin");
    00797     int index = m_pactionsindex;
    00798     //QPopupMenu *menu = m_menubar->findItem( m_menubar->idAt( 1 ) )->popup();
    00799     QPopupMenu *menu = m_menubar->getButton( 1 )->popup();
    00800     for (QValueList<KAction*>::Iterator it=pactions.begin(); it!=pactions.end(); ++it)
    00801     {
    00802         (*it)->plug(m_toolbar, index++);
    00803         ( *it )->plug( menu );
    00804     }
    00805 }
    00806
    00807 void KMMainView::removePluginActions()
    00808 {
    00809     QValueList<KAction*>    pactions = m_actions->actions("plugin");
    00810     for (QValueList<KAction*>::Iterator it=pactions.begin(); it!=pactions.end(); ++it)
    00811     {
    00812         (*it)->unplugAll();
    00813         delete (*it);
    00814     }
    00815 }
    00816
    00817 void KMMainView::slotToolSelected(int ID)
    00818 {
    00819     KMTimer::self()->hold();
    00820
    00821     QString libname = m_toollist[ID];
    00822     libname.prepend("kdeprint_tool_");
    00823     if (m_current && !m_current->device().isEmpty() && !libname.isEmpty())
    00824     {
    00825         KLibFactory *factory = KLibLoader::self()->factory(libname.local8Bit());
    00826         if (factory)
    00827         {
    00828             QStringList args;
    00829             args << m_current->device() << m_current->printerName();
    00830             KDialogBase *dlg = static_cast<KDialogBase*>(factory->create(this, "Tool", 0, args));
    00831             if (dlg)
    00832                 dlg->exec();
    00833             delete dlg;
    00834         }
    00835     }
    00836     else
    00837         KMessageBox::error(this,
    00838             i18n("Unable to start printer tool. Possible reasons are: "
    00839                  "no printer selected, the selected printer doesn't have "
    00840                  "any local device defined (printer port), or the tool library "
    00841                  "could not be found."));
    00842
    00843     KMTimer::self()->release();
    00844 }
    00845
    00846 void KMMainView::slotToggleFilter(bool on)
    00847 {
    00848     KMTimer::self()->hold();
    00849     KMManager::self()->enableFilter(on);
    00850     KMTimer::self()->release(true);
    00851 }
    00852
    00853 void KMMainView::configChanged()
    00854 {
    00855     reset( i18n( "Initializing manager..." ), false, true );
    00856 }
    00857
    00858 void KMMainView::slotUpdatePossible( bool flag )
    00859 {
    00860     destroyMessageWindow();
    00861     if ( !flag )
    00862         showErrorMsg( i18n( "Unable to retrieve the printer list." ) );
    00863     KMTimer::self()->release( true );
    00864 }
    00865
    00866 void KMMainView::createMessageWindow( const QString& txt, int delay )
    00867 {
    00868     destroyMessageWindow();
    00869     MessageWindow::add( m_printerview, txt, delay );
    00870 }
    00871
    00872 void KMMainView::destroyMessageWindow()
    00873 {
    00874     MessageWindow::remove( m_printerview );
    00875 }
    00876
    00877 void KMMainView::slotInit()
    00878 {
    00879     reset( i18n( "Initializing manager..." ), true, true );
    00880 }
    00881
    00882 void KMMainView::reset( const QString& msg, bool useDelay, bool holdTimer )
    00883 {
    00884     if ( holdTimer )
    00885         KMTimer::self()->hold();
    00886     m_printerview->setPrinterList( 0 );
    00887     if ( !msg.isEmpty() )
    00888         createMessageWindow( msg, ( useDelay ? 500 : 0 ) );
    00889     m_first = true;
    00890     m_manager->checkUpdatePossible();
    00891 }
    00892
    00893 void KMMainView::slotHelp()
    00894 {
    00895     QString s = sender()->name();
    00896     if ( s == "invoke_help" )
    00897         kapp->invokeHelp( QString::null, "kdeprint" );
    00898     else if ( s == "invoke_web" )
    00899     {
    00900         QStringList args;
    00901         args << "exec" << "http://printing.kde.org";
    00902         kapp->kdeinitExec( "kfmclient", args );
    00903     }
    00904     else
    00905         kdDebug( 500 ) << "Unknown help invokator: " << s << endl;
    00906 }
    00907
    00908 #include "kmmainview.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:03 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003