00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
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
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
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
00095
00096
00097 m_menubar = new KToolBar( this, "MenuBar", false, false );
00098 m_menubar->setIconText( KToolBar::IconTextRight );
00099 m_menubar->setMovingEnabled( false );
00100
00101
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
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
00121 if (coll)
00122 m_actions = coll;
00123 else
00124 m_actions = new KActionCollection(this);
00125 initActions();
00126
00127
00128 restoreSettings();
00129 loadParameters();
00130
00131
00132 reset( i18n( "Initializing manager..." ), true, true );
00133 }
00134
00135 KMMainView::~KMMainView()
00136 {
00137 saveSettings();
00138
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("View &Toolbar"),0,m_actions,"view_toolbar");
00214 connect(tact,SIGNAL(toggled(bool)),SLOT(slotToggleToolBar(bool)));
00215 tact = new KToggleAction( i18n( "View Me&nu Toolbar" ), 0, m_actions, "view_menubar" );
00216 connect( tact, SIGNAL( toggled( bool ) ), SLOT( slotToggleMenuBar( bool ) ) );
00217 tact = new KToggleAction(i18n("Show/Hide Pr&inter Details"),"kdeprint_printer_infos", 0,m_actions,"view_printerinfos");
00218 tact->setChecked(true);
00219 connect(tact,SIGNAL(toggled(bool)),SLOT(slotShowPrinterInfos(bool)));
00220
00221 tact = new KToggleAction(i18n("Toggle Printer &Filtering"), "filter", 0, m_actions, "view_pfilter");
00222 tact->setChecked(KMManager::self()->isFilterEnabled());
00223 connect(tact, SIGNAL(toggled(bool)), SLOT(slotToggleFilter(bool)));
00224
00225 new KAction( i18n( "%1 &Handbook" ).arg( "KDEPrint" ), "contents", 0, this, SLOT( slotHelp() ), m_actions, "invoke_help" );
00226 new KAction( i18n( "%1 &Web Site" ).arg( "KDEPrint" ), "network", 0, this, SLOT( slotHelp() ), m_actions, "invoke_web" );
00227
00228 KActionMenu *mact = new KActionMenu(i18n("Pri&nter Tools"), "package_utilities", m_actions, "printer_tool");
00229 mact->setDelayed(false);
00230 connect(mact->popupMenu(), SIGNAL(activated(int)), SLOT(slotToolSelected(int)));
00231 QStringList files = KGlobal::dirs()->findAllResources("data", "kdeprint/tools/*.desktop");
00232 for (QStringList::ConstIterator it=files.begin(); it!=files.end(); ++it)
00233 {
00234 KSimpleConfig conf(*it);
00235 conf.setGroup("Desktop Entry");
00236 mact->popupMenu()->insertItem(conf.readEntry("Name", "Unnamed"), mact->popupMenu()->count());
00237 m_toollist << conf.readEntry("X-KDE-Library");
00238 }
00239
00240
00241 m_actions->action("printer_add")->plug(m_toolbar);
00242 m_actions->action("printer_add_special")->plug(m_toolbar);
00243 m_toolbar->insertLineSeparator();
00244 m_actions->action("printer_state_change")->plug(m_toolbar);
00245 m_actions->action("printer_spool_change")->plug(m_toolbar);
00246 m_toolbar->insertSeparator();
00247 m_actions->action("printer_hard_default")->plug(m_toolbar);
00248 m_actions->action("printer_soft_default")->plug(m_toolbar);
00249 m_actions->action("printer_remove")->plug(m_toolbar);
00250 m_toolbar->insertSeparator();
00251 m_actions->action("printer_configure")->plug(m_toolbar);
00252 m_actions->action("printer_test")->plug(m_toolbar);
00253 m_actions->action("printer_tool")->plug(m_toolbar);
00254 m_pactionsindex = m_toolbar->insertSeparator();
00255 m_toolbar->insertLineSeparator();
00256 m_actions->action("server_restart")->plug(m_toolbar);
00257 m_actions->action("server_configure")->plug(m_toolbar);
00258 m_toolbar->insertLineSeparator();
00259 m_actions->action("manager_configure")->plug(m_toolbar);
00260 m_actions->action("view_refresh")->plug(m_toolbar);
00261 m_toolbar->insertLineSeparator();
00262 m_actions->action("view_printerinfos")->plug(m_toolbar);
00263 m_actions->action("view_change")->plug(m_toolbar);
00264 m_actions->action("orientation_change")->plug(m_toolbar);
00265 m_actions->action("view_pfilter")->plug(m_toolbar);
00266
00267
00268 QPopupMenu *menu = new QPopupMenu( this );
00269 m_actions->action( "printer_add" )->plug( menu );
00270 m_actions->action( "printer_add_special" )->plug( menu );
00271
00272 m_menubar->insertButton( "wizard", 0, true, i18n( "Add" ) );
00273 m_menubar->getButton( 0 )->setPopup( menu, true );
00274 menu = new QPopupMenu( this );
00275 m_actions->action("printer_state_change")->plug( menu );
00276 m_actions->action("printer_spool_change")->plug( menu );
00277 menu->insertSeparator();
00278 m_actions->action("printer_hard_default")->plug( menu );
00279 m_actions->action("printer_soft_default")->plug( menu );
00280 m_actions->action("printer_remove")->plug( menu );
00281 menu->insertSeparator();
00282 m_actions->action("printer_configure")->plug( menu );
00283 m_actions->action("printer_test")->plug( menu );
00284 m_actions->action("printer_tool")->plug( menu );
00285 menu->insertSeparator();
00286
00287 m_menubar->insertButton( "printer2", 1, true, i18n( "Printer" ) );
00288 m_menubar->getButton( 1 )->setPopup( menu, true );
00289 menu = new QPopupMenu( this );
00290 m_actions->action("server_restart")->plug( menu );
00291 m_actions->action("server_configure")->plug( menu );
00292
00293 m_menubar->insertButton( "misc", 2, true, i18n( "Print Server" ) );
00294 m_menubar->getButton( 2 )->setPopup( menu, true );
00295 menu = new QPopupMenu( this );
00296 m_actions->action("manager_configure")->plug( menu );
00297 m_actions->action("view_refresh")->plug( menu );
00298
00299 m_menubar->insertButton( "konsole3", 3, true, i18n( "Print Manager" ) );
00300 m_menubar->getButton( 3 )->setPopup( menu, true );
00301 menu = new QPopupMenu( this );
00302 m_actions->action("view_printerinfos")->plug( menu );
00303 m_actions->action("view_change")->plug( menu );
00304 m_actions->action("orientation_change")->plug( menu );
00305 m_actions->action( "view_toolbar" )->plug ( menu );
00306 m_actions->action( "view_menubar" )->plug ( menu );
00307 menu->insertSeparator();
00308 m_actions->action("view_pfilter")->plug( menu );
00309
00310 m_menubar->insertButton( "view_remove", 4, true, i18n( "View" ) );
00311 m_menubar->getButton( 4 )->setPopup( menu, true );
00312
00313 menu = new QPopupMenu( this );
00314 m_actions->action( "invoke_help" )->plug( menu );
00315 m_actions->action( "invoke_web" )->plug( menu );
00316 m_menubar->insertButton( "help", 5, true, i18n( "Documentation" ) );
00317 m_menubar->getButton( 5 )->setPopup( menu, true );
00318
00319 loadPluginActions();
00320 slotPrinterSelected(QString::null);
00321 }
00322
00323 void KMMainView::slotRefresh()
00324 {
00325
00326 }
00327
00328 void KMMainView::slotTimer()
00329 {
00330 kdDebug() << "KMMainView::slotTimer" << endl;
00331 QPtrList<KMPrinter> *printerlist = m_manager->printerList();
00332 bool ok = m_manager->errorMsg().isEmpty();
00333 m_printerview->setPrinterList(printerlist);
00334 if ( m_first )
00335 {
00336 if ( !ok )
00337 showErrorMsg(i18n("An error occurred while retrieving the printer list."));
00338 else
00339 {
00340
00341
00342
00343
00344
00345 QPtrListIterator<KMPrinter> it( *printerlist );
00346 KMPrinter *p1 = 0, *p2 = 0, *p3 = 0;
00347 while ( it.current() )
00348 {
00349 if ( !it.current()->isVirtual() )
00350 {
00351 if ( it.current()->ownSoftDefault() )
00352 {
00353 p1 = it.current();
00354 break;
00355 }
00356 else if ( it.current()->isHardDefault() )
00357 p2 = it.current();
00358 else if ( !p3 )
00359 p3 = it.current();
00360 }
00361 ++it;
00362 }
00363 if ( p1 || p2 || p3 )
00364 m_printerview->setPrinter( p1 ? p1 : ( p2 ? p2 : p3 ) );
00365 }
00366 m_first = false;
00367 }
00368 }
00369
00370 void KMMainView::slotPrinterSelected(const QString& prname)
00371 {
00372 KMPrinter *p = KMManager::self()->findPrinter(prname);
00373 m_current = p;
00374 if (p && !p->isSpecial())
00375 KMFactory::self()->manager()->completePrinter(p);
00376 m_printerpages->setPrinter(p);
00377
00378
00379
00380
00381
00382 int mask = (m_manager->hasManagement() ? m_manager->printerOperationMask() : 0);
00383 bool sp = !(p && p->isSpecial());
00384 m_actions->action("printer_remove")->setEnabled(!sp || ((mask & KMManager::PrinterRemoval) && p && p->isLocal() && !p->isImplicit()));
00385 m_actions->action("printer_configure")->setEnabled(!sp || ((mask & KMManager::PrinterConfigure) && p && !p->isClass(true) ));
00386 m_actions->action("printer_hard_default")->setEnabled((sp && (mask & KMManager::PrinterDefault) && p && !p->isClass(true) && !p->isHardDefault() && p->isLocal()));
00387 m_actions->action("printer_soft_default")->setEnabled((p && !p->isSoftDefault()));
00388 m_actions->action("printer_test")->setEnabled((sp && (mask & KMManager::PrinterTesting) && p && !p->isClass(true)));
00389 bool stmask = (sp && (mask & KMManager::PrinterEnabling) && p);
00390 m_actions->action("printer_state_change")->setEnabled(stmask && p->isLocal());
00391 m_actions->action("printer_spool_change")->setEnabled(stmask);
00392 m_actions->action("printer_start")->setEnabled((stmask && p->state() == KMPrinter::Stopped));
00393 m_actions->action("printer_stop")->setEnabled((stmask && p->state() != KMPrinter::Stopped));
00394 m_actions->action("printer_enable")->setEnabled((stmask && !p->acceptJobs()));
00395 m_actions->action("printer_disable")->setEnabled((stmask && p->acceptJobs()));
00396
00397 m_actions->action("printer_add")->setEnabled((mask & KMManager::PrinterCreation));
00398 mask = m_manager->serverOperationMask();
00399 m_actions->action("server_restart")->setEnabled((mask & KMManager::ServerRestarting));
00400 m_actions->action("server_configure")->setEnabled((mask & KMManager::ServerConfigure));
00401
00402 KMFactory::self()->manager()->validatePluginActions(m_actions, p);
00403
00404 m_actions->action("printer_tool")->setEnabled(p && !p->isClass(true) && !p->isRemote() && !p->isSpecial());
00405 }
00406
00407 void KMMainView::setViewType(int ID)
00408 {
00409 ((KSelectAction*)m_actions->action("view_change"))->setCurrentItem(ID);
00410 slotChangeView(ID);
00411 }
00412
00413 int KMMainView::viewType() const
00414 { return m_printerview->viewType(); }
00415
00416 void KMMainView::slotChangeView(int ID)
00417 {
00418 kdDebug() << "KMMainView::slotChangeView" << endl;
00419 if (ID >= KMPrinterView::Icons && ID <= KMPrinterView::Tree)
00420 m_printerview->setViewType((KMPrinterView::ViewType)ID);
00421 }
00422
00423 void KMMainView::slotRightButtonClicked(const QString& prname, const QPoint& p)
00424 {
00425 KMPrinter *printer = KMManager::self()->findPrinter(prname);
00426
00427 m_pop->clear();
00428 if (printer)
00429 {
00430 m_current = printer;
00431 if (!printer->isSpecial())
00432 {
00433 if (printer->isLocal())
00434 m_actions->action((printer->state() == KMPrinter::Stopped ? "printer_start" : "printer_stop"))->plug(m_pop);
00435 m_actions->action((printer->acceptJobs() ? "printer_disable" : "printer_enable"))->plug(m_pop);
00436 m_pop->insertSeparator();
00437 }
00438 if (!printer->isSoftDefault()) m_actions->action("printer_soft_default")->plug(m_pop);
00439 if (printer->isLocal() && !printer->isImplicit())
00440 {
00441 if (!printer->isHardDefault()) m_actions->action("printer_hard_default")->plug(m_pop);
00442 m_actions->action("printer_remove")->plug(m_pop);
00443 m_pop->insertSeparator();
00444 if (!printer->isClass(true))
00445 {
00446 m_actions->action("printer_configure")->plug(m_pop);
00447 m_actions->action("printer_test")->plug(m_pop);
00448 m_actions->action("printer_tool")->plug(m_pop);
00449 m_pop->insertSeparator();
00450 }
00451 }
00452 else
00453 {
00454 if (!printer->isClass(true))
00455 {
00456 m_actions->action("printer_configure")->plug(m_pop);
00457 m_actions->action("printer_test")->plug(m_pop);
00458 }
00459 m_pop->insertSeparator();
00460 }
00461 if (!printer->isSpecial())
00462 {
00463 QValueList<KAction*> pactions = m_actions->actions("plugin");
00464 for (QValueList<KAction*>::Iterator it=pactions.begin(); it!=pactions.end(); ++it)
00465 (*it)->plug(m_pop);
00466 if (pactions.count() > 0)
00467 m_pop->insertSeparator();
00468 }
00469 }
00470 else
00471 {
00472 m_actions->action("printer_add")->plug(m_pop);
00473 m_actions->action("printer_add_special")->plug(m_pop);
00474 m_pop->insertSeparator();
00475 m_actions->action("server_restart")->plug(m_pop);
00476 m_actions->action("server_configure")->plug(m_pop);
00477 m_pop->insertSeparator();
00478 m_actions->action("manager_configure")->plug(m_pop);
00479 m_actions->action("view_refresh")->plug(m_pop);
00480 m_pop->insertSeparator();
00481 }
00482 m_actions->action("view_printerinfos")->plug(m_pop);
00483 m_actions->action("view_change")->plug(m_pop);
00484 m_actions->action("orientation_change")->plug(m_pop);
00485 m_actions->action("view_toolbar")->plug(m_pop);
00486 m_actions->action("view_menubar")->plug(m_pop);
00487 m_pop->insertSeparator();
00488 m_actions->action("view_pfilter")->plug(m_pop);
00489
00490
00491 m_pop->popup(p);
00492 }
00493
00494 void KMMainView::slotChangePrinterState()
00495 {
00496 QString opname = sender()->name();
00497 if (m_current && opname.startsWith("printer_"))
00498 {
00499 opname = opname.mid(8);
00500 KMTimer::self()->hold();
00501 bool result(false);
00502 if (opname == "enable")
00503 result = m_manager->enablePrinter(m_current, true);
00504 else if (opname == "disable")
00505 result = m_manager->enablePrinter(m_current, false);
00506 else if (opname == "start")
00507 result = m_manager->startPrinter(m_current, true);
00508 else if (opname == "stop")
00509 result = m_manager->startPrinter(m_current, false);
00510 if (!result)
00511 showErrorMsg(i18n("Unable to modify the state of printer %1.").arg(m_current->printerName()));
00512 KMTimer::self()->release(result);
00513 }
00514 }
00515
00516 void KMMainView::slotRemove()
00517 {
00518 if (m_current)
00519 {
00520 KMTimer::self()->hold();
00521 bool result(false);
00522 if (KMessageBox::warningYesNo(this,i18n("Do you really want to remove %1?").arg(m_current->printerName())) == KMessageBox::Yes)
00523 if (m_current->isSpecial())
00524 {
00525 if (!(result=m_manager->removeSpecialPrinter(m_current)))
00526 showErrorMsg(i18n("Unable to remove special printer %1.").arg(m_current->printerName()));
00527 }
00528 else if (!(result=m_manager->removePrinter(m_current)))
00529 showErrorMsg(i18n("Unable to remove printer %1.").arg(m_current->printerName()));
00530 KMTimer::self()->release(result);
00531 }
00532 }
00533
00534 void KMMainView::slotConfigure()
00535 {
00536 if (m_current)
00537 {
00538 KMTimer::self()->hold();
00539 bool needRefresh(false);
00540 if (m_current->isSpecial())
00541 {
00542 KMSpecialPrinterDlg dlg(this);
00543 dlg.setPrinter(m_current);
00544 if (dlg.exec())
00545 {
00546 KMPrinter *prt = dlg.printer();
00547 if (prt->name() != m_current->name())
00548 m_manager->removeSpecialPrinter(m_current);
00549 m_manager->createSpecialPrinter(prt);
00550 needRefresh = true;
00551 }
00552 }
00553 else
00554 {
00555 DrMain *driver = m_manager->loadPrinterDriver(m_current, true);
00556 if (driver)
00557 {
00558 KMDriverDialog dlg(this);
00559 dlg.setCaption(i18n("Configure %1").arg(m_current->printerName()));
00560 dlg.setDriver(driver);
00561
00562 if (m_current->isRemote())
00563 dlg.enableButtonOK(false);
00564 if (dlg.exec())
00565 if (!m_manager->savePrinterDriver(m_current,driver))
00566 showErrorMsg(i18n("Unable to modify settings of printer %1.").arg(m_current->printerName()));
00567 delete driver;
00568 }
00569 else
00570 showErrorMsg(i18n("Unable to load a valid driver for printer %1.").arg(m_current->printerName()));
00571 }
00572 KMTimer::self()->release(needRefresh);
00573 }
00574 }
00575
00576 void KMMainView::slotAdd()
00577 {
00578 KMTimer::self()->hold();
00579
00580 int result(0);
00581 if ((result=kdeprint_management_add_printer_wizard(this)) == -1)
00582 showErrorMsg(i18n("Unable to create printer."));
00583
00584 KMTimer::self()->release((result == 1));
00585 }
00586
00587 void KMMainView::slotHardDefault()
00588 {
00589 if (m_current)
00590 {
00591 KMTimer::self()->hold();
00592 bool result = m_manager->setDefaultPrinter(m_current);
00593 if (!result)
00594 showErrorMsg(i18n("Unable to define printer %1 as default.").arg(m_current->printerName()));
00595 KMTimer::self()->release(result);
00596 }
00597 }
00598
00599 void KMMainView::slotSoftDefault()
00600 {
00601 if (m_current)
00602 {
00603 KMTimer::self()->hold();
00604 KMFactory::self()->virtualManager()->setAsDefault(m_current,QString::null);
00605 KMTimer::self()->release(true);
00606 }
00607 }
00608
00609 void KMMainView::setOrientation(int o)
00610 {
00611 int ID = (o == Qt::Horizontal ? 1 : 0);
00612 ((KSelectAction*)m_actions->action("orientation_change"))->setCurrentItem(ID);
00613 slotChangeDirection(ID);
00614 }
00615
00616 int KMMainView::orientation() const
00617 { return (m_boxlayout->direction() == QBoxLayout::LeftToRight ? Qt::Horizontal : Qt::Vertical); }
00618
00619 void KMMainView::slotChangeDirection(int d)
00620 {
00621 m_boxlayout->setDirection(d == 1 ? QBoxLayout::LeftToRight : QBoxLayout::TopToBottom);
00622 }
00623
00624 void KMMainView::slotTest()
00625 {
00626 if (m_current)
00627 {
00628 KMTimer::self()->hold();
00629 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)
00630 {
00631 if (KMFactory::self()->manager()->testPrinter(m_current))
00632 KMessageBox::information(this,i18n("Test page successfully sent to printer %1.").arg(m_current->printerName()));
00633 else
00634 showErrorMsg(i18n("Unable to test printer %1.").arg(m_current->printerName()));
00635 }
00636 KMTimer::self()->release(true);
00637 }
00638 }
00639
00640 void KMMainView::showErrorMsg(const QString& msg, bool usemgr)
00641 {
00642 QString s(msg);
00643 if (usemgr)
00644 {
00645 s.prepend("<p>");
00646 s.append(" ");
00647 s += i18n("Error message received from manager:</p><p>%1</p>");
00648 if (m_manager->errorMsg().isEmpty())
00649 s = s.arg(i18n("Internal error (no error message)."));
00650 else
00651 s = s.arg(m_manager->errorMsg());
00652
00653 m_manager->setErrorMsg(QString::null);
00654 }
00655 s.prepend("<qt>").append("</qt>");
00656 KMTimer::self()->hold();
00657 KMessageBox::error(this,s);
00658 KMTimer::self()->release();
00659 }
00660
00661 void KMMainView::slotServerRestart()
00662 {
00663 KMTimer::self()->hold();
00664 bool result = m_manager->restartServer();
00665 if (!result)
00666 {
00667 showErrorMsg(i18n("Unable to restart print server."));
00668 KMTimer::self()->release( false );
00669 }
00670 else
00671 {
00672 reset( i18n( "Restarting server..." ), false, false );
00673 }
00674 }
00675
00676 void KMMainView::slotServerConfigure()
00677 {
00678 KMTimer::self()->hold();
00679 bool result = m_manager->configureServer(this);
00680 if (!result)
00681 {
00682 showErrorMsg(i18n("Unable to configure print server."));
00683 KMTimer::self()->release( false );
00684 }
00685 else
00686 {
00687 reset( i18n( "Configuring server..." ), false, false );
00688 }
00689 }
00690
00691 void KMMainView::slotToggleToolBar(bool on)
00692 {
00693 if (on) m_toolbar->show();
00694 else m_toolbar->hide();
00695 }
00696
00697 void KMMainView::slotToggleMenuBar( bool on )
00698 {
00699 if ( on )
00700 m_menubar->show();
00701 else
00702 m_menubar->hide();
00703 }
00704
00705 void KMMainView::slotManagerConfigure()
00706 {
00707 KMTimer::self()->hold();
00708 KMConfigDialog dlg(this,"ConfigDialog");
00709 if ( dlg.exec() )
00710 {
00711 loadParameters();
00712 }
00713
00714
00715
00716
00717
00718
00719 KMTimer::self()->release( false );
00720 }
00721
00722 void KMMainView::slotAddSpecial()
00723 {
00724 KMTimer::self()->hold();
00725 KMSpecialPrinterDlg dlg(this);
00726 if (dlg.exec())
00727 {
00728 KMPrinter *prt = dlg.printer();
00729 m_manager->createSpecialPrinter(prt);
00730 }
00731 KMTimer::self()->release(true);
00732 }
00733
00734 void KMMainView::slotShowPrinterInfos(bool on)
00735 {
00736 if (on)
00737 m_printerpages->show();
00738 else
00739 m_printerpages->hide();
00740 m_actions->action("orientation_change")->setEnabled(on);
00741 }
00742
00743 void KMMainView::enableToolbar(bool on)
00744 {
00745 KToggleAction *act = (KToggleAction*)m_actions->action("view_toolbar");
00746 m_toolbar->setEnabled(on);
00747 act->setEnabled(on);
00748 if (on && act->isChecked())
00749 m_toolbar->show();
00750 else
00751 m_toolbar->hide();
00752 }
00753
00754 KAction* KMMainView::action(const char *name)
00755 {
00756 return m_actions->action(name);
00757 }
00758
00759
00760
00761
00762
00763
00764
00765
00766 void KMMainView::reload()
00767 {
00768 removePluginActions();
00769 loadPluginActions();
00770
00771
00772 connect( m_manager, SIGNAL( updatePossible( bool ) ), SLOT( slotUpdatePossible( bool ) ) );
00773
00774
00775
00776 reset( i18n( "Initializing manager..." ), true, true );
00777 }
00778
00779 void KMMainView::showPrinterInfos(bool on)
00780 {
00781 static_cast<KToggleAction*>(m_actions->action("view_printerinfos"))->setChecked(on);
00782 slotShowPrinterInfos(on);
00783 }
00784
00785 bool KMMainView::printerInfosShown() const
00786 {
00787 return (static_cast<KToggleAction*>(m_actions->action("view_printerinfos"))->isChecked());
00788 }
00789
00790 void KMMainView::loadPluginActions()
00791 {
00792 KMFactory::self()->manager()->createPluginActions(m_actions);
00793 QValueList<KAction*> pactions = m_actions->actions("plugin");
00794 int index = m_pactionsindex;
00795
00796 QPopupMenu *menu = m_menubar->getButton( 1 )->popup();
00797 for (QValueList<KAction*>::Iterator it=pactions.begin(); it!=pactions.end(); ++it)
00798 {
00799 (*it)->plug(m_toolbar, index++);
00800 ( *it )->plug( menu );
00801 }
00802 }
00803
00804 void KMMainView::removePluginActions()
00805 {
00806 QValueList<KAction*> pactions = m_actions->actions("plugin");
00807 for (QValueList<KAction*>::Iterator it=pactions.begin(); it!=pactions.end(); ++it)
00808 {
00809 (*it)->unplugAll();
00810 delete (*it);
00811 }
00812 }
00813
00814 void KMMainView::slotToolSelected(int ID)
00815 {
00816 KMTimer::self()->hold();
00817
00818 QString libname = m_toollist[ID];
00819 libname.prepend("kdeprint_tool_");
00820 if (m_current && !m_current->device().isEmpty() && !libname.isEmpty())
00821 {
00822 KLibFactory *factory = KLibLoader::self()->factory(libname.local8Bit());
00823 if (factory)
00824 {
00825 QStringList args;
00826 args << m_current->device() << m_current->printerName();
00827 KDialogBase *dlg = static_cast<KDialogBase*>(factory->create(this, "Tool", 0, args));
00828 if (dlg)
00829 dlg->exec();
00830 delete dlg;
00831 }
00832 }
00833 else
00834 KMessageBox::error(this,
00835 i18n("Unable to start printer tool. Possible reasons are: "
00836 "no printer selected, the selected printer doesn't have "
00837 "any local device defined (printer port), or the tool library "
00838 "could not be found."));
00839
00840 KMTimer::self()->release();
00841 }
00842
00843 void KMMainView::slotToggleFilter(bool on)
00844 {
00845 KMTimer::self()->hold();
00846 KMManager::self()->enableFilter(on);
00847 KMTimer::self()->release(true);
00848 }
00849
00850 void KMMainView::configChanged()
00851 {
00852 reset( i18n( "Initializing manager..." ), false, true );
00853 }
00854
00855 void KMMainView::slotUpdatePossible( bool flag )
00856 {
00857 destroyMessageWindow();
00858 if ( !flag )
00859 showErrorMsg( i18n( "Unable to retrieve the printer list." ) );
00860 KMTimer::self()->release( true );
00861 }
00862
00863 void KMMainView::createMessageWindow( const QString& txt, int delay )
00864 {
00865 destroyMessageWindow();
00866 MessageWindow::add( m_printerview, txt, delay );
00867 }
00868
00869 void KMMainView::destroyMessageWindow()
00870 {
00871 MessageWindow::remove( m_printerview );
00872 }
00873
00874 void KMMainView::slotInit()
00875 {
00876 reset( i18n( "Initializing manager..." ), true, true );
00877 }
00878
00879 void KMMainView::reset( const QString& msg, bool useDelay, bool holdTimer )
00880 {
00881 if ( holdTimer )
00882 KMTimer::self()->hold();
00883 m_printerview->setPrinterList( 0 );
00884 if ( !msg.isEmpty() )
00885 createMessageWindow( msg, ( useDelay ? 500 : 0 ) );
00886 m_first = true;
00887 m_manager->checkUpdatePossible();
00888 }
00889
00890 void KMMainView::slotHelp()
00891 {
00892 QString s = sender()->name();
00893 if ( s == "invoke_help" )
00894 kapp->invokeHelp( QString::null, "kdeprint" );
00895 else if ( s == "invoke_web" )
00896 {
00897 QStringList args;
00898 args << "exec" << "http://printing.kde.org";
00899 kapp->kdeinitExec( "kfmclient", args );
00900 }
00901 else
00902 kdDebug( 500 ) << "Unknown help invokator: " << s << endl;
00903 }
00904
00905 #include "kmmainview.moc"