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
00133 KMTimer::self()->hold();
00134 createMessageWindow( i18n( "Initializing manager..." ) );
00135 m_manager->checkUpdatePossible();
00136 }
00137
00138 KMMainView::~KMMainView()
00139 {
00140 saveSettings();
00141
00142 }
00143
00144 void KMMainView::loadParameters()
00145 {
00146 }
00147
00148 void KMMainView::restoreSettings()
00149 {
00150 KConfig *conf = KMFactory::self()->printConfig();
00151 conf->setGroup("General");
00152 setViewType((KMPrinterView::ViewType)conf->readNumEntry("ViewType",KMPrinterView::Icons));
00153 setOrientation(conf->readNumEntry("Orientation", Qt::Vertical));
00154 bool view = conf->readBoolEntry("ViewToolBar",false);
00155 slotToggleToolBar(view);
00156 ((KToggleAction*)m_actions->action("view_toolbar"))->setChecked(view);
00157 view = conf->readBoolEntry( "ViewMenuBar", true );
00158 slotToggleMenuBar( view );
00159 static_cast<KToggleAction*>( m_actions->action( "view_menubar" ) )->setChecked( view );
00160 view = conf->readBoolEntry("ViewPrinterInfos",true);
00161 slotShowPrinterInfos(view);
00162 ((KToggleAction*)m_actions->action("view_printerinfos"))->setChecked(view);
00163 }
00164
00165 void KMMainView::saveSettings()
00166 {
00167 KConfig *conf = KMFactory::self()->printConfig();
00168 conf->setGroup("General");
00169 conf->writeEntry("ViewType",(int)m_printerview->viewType());
00170 conf->writeEntry("Orientation",(int)orientation());
00171 conf->writeEntry("ViewToolBar",((KToggleAction*)m_actions->action("view_toolbar"))->isChecked());
00172 conf->writeEntry("ViewMenuBar",static_cast<KToggleAction*>( m_actions->action("view_menubar") )->isChecked());
00173 conf->writeEntry("ViewPrinterInfos",((KToggleAction*)m_actions->action("view_printerinfos"))->isChecked());
00174 conf->sync();
00175 }
00176
00177 void KMMainView::initActions()
00178 {
00179 KIconSelectAction *vact = new KIconSelectAction(i18n("&View"),0,m_actions,"view_change");
00180 QStringList iconlst;
00181 iconlst << "view_icon" << "view_detailed" << "view_tree";
00182 vact->setItems(QStringList::split(',',i18n("&Icons,&List,&Tree"),false), iconlst);
00183 vact->setCurrentItem(0);
00184 connect(vact,SIGNAL(activated(int)),SLOT(slotChangeView(int)));
00185
00186 KActionMenu *stateAct = new KActionMenu(i18n("Start/Stop Printer"), "kdeprint_printstate", m_actions, "printer_state_change");
00187 stateAct->setDelayed(false);
00188 stateAct->insert(new KAction(i18n("&Start Printer"),"kdeprint_enableprinter",0,this,SLOT(slotChangePrinterState()),m_actions,"printer_start"));
00189 stateAct->insert(new KAction(i18n("Sto&p Printer"),"kdeprint_stopprinter",0,this,SLOT(slotChangePrinterState()),m_actions,"printer_stop"));
00190
00191 stateAct = new KActionMenu(i18n("Enable/Disable Job Spooling"), "kdeprint_queuestate", m_actions, "printer_spool_change");
00192 stateAct->setDelayed(false);
00193 stateAct->insert(new KAction(i18n("&Enable Job Spooling"),"kdeprint_enableprinter",0,this,SLOT(slotChangePrinterState()),m_actions,"printer_enable"));
00194 stateAct->insert(new KAction(i18n("&Disable Job Spooling"),"kdeprint_stopprinter",0,this,SLOT(slotChangePrinterState()),m_actions,"printer_disable"));
00195
00196 new KAction(i18n("&Remove"),"edittrash",0,this,SLOT(slotRemove()),m_actions,"printer_remove");
00197 new KAction(i18n("&Configure..."),"configure",0,this,SLOT(slotConfigure()),m_actions,"printer_configure");
00198 new KAction(i18n("Add &Printer/Class..."),"kdeprint_addprinter",0,this,SLOT(slotAdd()),m_actions,"printer_add");
00199 new KAction(i18n("Add &Special (pseudo) Printer..."),"kdeprint_addpseudo",0,this,SLOT(slotAddSpecial()),m_actions,"printer_add_special");
00200 new KAction(i18n("Set as &Local Default"),"kdeprint_defaulthard",0,this,SLOT(slotHardDefault()),m_actions,"printer_hard_default");
00201 new KAction(i18n("Set as &User Default"),"kdeprint_defaultsoft",0,this,SLOT(slotSoftDefault()),m_actions,"printer_soft_default");
00202 new KAction(i18n("&Test Printer..."),"kdeprint_testprinter",0,this,SLOT(slotTest()),m_actions,"printer_test");
00203 new KAction(i18n("Configure &Manager..."),"kdeprint_configmgr",0,this,SLOT(slotManagerConfigure()),m_actions,"manager_configure");
00204 new KAction(i18n("Initialize Manager/&View"),"reload",0,this,SLOT(slotInit()),m_actions,"view_refresh");
00205
00206 KIconSelectAction *dact = new KIconSelectAction(i18n("&Orientation"),0,m_actions,"orientation_change");
00207 iconlst.clear();
00208 iconlst << "view_top_bottom" << "view_left_right";
00209 dact->setItems(QStringList::split(',',i18n("&Vertical,&Horizontal"),false), iconlst);
00210 dact->setCurrentItem(0);
00211 connect(dact,SIGNAL(activated(int)),SLOT(slotChangeDirection(int)));
00212
00213 new KAction(i18n("R&estart Server"),"kdeprint_restartsrv",0,this,SLOT(slotServerRestart()),m_actions,"server_restart");
00214 new KAction(i18n("Configure &Server..."),"kdeprint_configsrv",0,this,SLOT(slotServerConfigure()),m_actions,"server_configure");
00215
00216 KToggleAction *tact = new KToggleAction(i18n("View &Toolbar"),0,m_actions,"view_toolbar");
00217 connect(tact,SIGNAL(toggled(bool)),SLOT(slotToggleToolBar(bool)));
00218 tact = new KToggleAction( i18n( "View Me&nu Toolbar" ), 0, m_actions, "view_menubar" );
00219 connect( tact, SIGNAL( toggled( bool ) ), SLOT( slotToggleMenuBar( bool ) ) );
00220 tact = new KToggleAction(i18n("Show/Hide Pr&inter Details"),"kdeprint_printer_infos", 0,m_actions,"view_printerinfos");
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
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
00271 QPopupMenu *menu = new QPopupMenu( this );
00272 m_actions->action( "printer_add" )->plug( menu );
00273 m_actions->action( "printer_add_special" )->plug( menu );
00274
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
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
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
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
00313 m_menubar->insertButton( "view_remove", 4, true, i18n( "View" ) );
00314 m_menubar->getButton( 4 )->setPopup( menu, true );
00315
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 KMTimer::self()->delay(10);
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 (!ok && m_first)
00338 {
00339 showErrorMsg(i18n("An error occurred while retrieving the printer list."));
00340 m_first = false;
00341 }
00342 }
00343
00344 void KMMainView::slotPrinterSelected(const QString& prname)
00345 {
00346 KMPrinter *p = KMManager::self()->findPrinter(prname);
00347 m_current = p;
00348 if (p && !p->isSpecial())
00349 KMFactory::self()->manager()->completePrinter(p);
00350 m_printerpages->setPrinter(p);
00351
00352
00353
00354
00355
00356 int mask = (m_manager->hasManagement() ? m_manager->printerOperationMask() : 0);
00357 bool sp = !(p && p->isSpecial());
00358 m_actions->action("printer_remove")->setEnabled(!sp || ((mask & KMManager::PrinterRemoval) && p && p->isLocal() && !p->isImplicit()));
00359 m_actions->action("printer_configure")->setEnabled(!sp || ((mask & KMManager::PrinterConfigure) && p && !p->isClass(true) ));
00360 m_actions->action("printer_hard_default")->setEnabled((sp && (mask & KMManager::PrinterDefault) && p && !p->isClass(true) && !p->isHardDefault() && p->isLocal()));
00361 m_actions->action("printer_soft_default")->setEnabled((sp && p && !p->isSoftDefault()));
00362 m_actions->action("printer_test")->setEnabled((sp && (mask & KMManager::PrinterTesting) && p && !p->isClass(true)));
00363 bool stmask = (sp && (mask & KMManager::PrinterEnabling) && p);
00364 m_actions->action("printer_state_change")->setEnabled(stmask && p->isLocal());
00365 m_actions->action("printer_spool_change")->setEnabled(stmask);
00366 m_actions->action("printer_start")->setEnabled((stmask && p->state() == KMPrinter::Stopped));
00367 m_actions->action("printer_stop")->setEnabled((stmask && p->state() != KMPrinter::Stopped));
00368 m_actions->action("printer_enable")->setEnabled((stmask && !p->acceptJobs()));
00369 m_actions->action("printer_disable")->setEnabled((stmask && p->acceptJobs()));
00370
00371 m_actions->action("printer_add")->setEnabled((mask & KMManager::PrinterCreation));
00372 mask = m_manager->serverOperationMask();
00373 m_actions->action("server_restart")->setEnabled((mask & KMManager::ServerRestarting));
00374 m_actions->action("server_configure")->setEnabled((mask & KMManager::ServerConfigure));
00375
00376 KMFactory::self()->manager()->validatePluginActions(m_actions, p);
00377
00378 m_actions->action("printer_tool")->setEnabled(p && !p->isClass(true) && !p->isRemote() && !p->isSpecial());
00379 }
00380
00381 void KMMainView::setViewType(int ID)
00382 {
00383 ((KSelectAction*)m_actions->action("view_change"))->setCurrentItem(ID);
00384 slotChangeView(ID);
00385 }
00386
00387 int KMMainView::viewType() const
00388 { return m_printerview->viewType(); }
00389
00390 void KMMainView::slotChangeView(int ID)
00391 {
00392 kdDebug() << "KMMainView::slotChangeView" << endl;
00393 if (ID >= KMPrinterView::Icons && ID <= KMPrinterView::Tree)
00394 m_printerview->setViewType((KMPrinterView::ViewType)ID);
00395 }
00396
00397 void KMMainView::slotRightButtonClicked(const QString& prname, const QPoint& p)
00398 {
00399 KMPrinter *printer = KMManager::self()->findPrinter(prname);
00400
00401 m_pop->clear();
00402 if (printer)
00403 {
00404 m_current = printer;
00405 if (!printer->isSpecial())
00406 {
00407 if (printer->isLocal())
00408 m_actions->action((printer->state() == KMPrinter::Stopped ? "printer_start" : "printer_stop"))->plug(m_pop);
00409 m_actions->action((printer->acceptJobs() ? "printer_disable" : "printer_enable"))->plug(m_pop);
00410 m_pop->insertSeparator();
00411 }
00412 if (!printer->isSoftDefault()) m_actions->action("printer_soft_default")->plug(m_pop);
00413 if (printer->isLocal() && !printer->isImplicit())
00414 {
00415 if (!printer->isHardDefault()) m_actions->action("printer_hard_default")->plug(m_pop);
00416 m_actions->action("printer_remove")->plug(m_pop);
00417 m_pop->insertSeparator();
00418 if (!printer->isClass(true))
00419 {
00420 m_actions->action("printer_configure")->plug(m_pop);
00421 m_actions->action("printer_test")->plug(m_pop);
00422 m_actions->action("printer_tool")->plug(m_pop);
00423 m_pop->insertSeparator();
00424 }
00425 }
00426 else
00427 {
00428 if (!printer->isClass(true))
00429 {
00430 m_actions->action("printer_configure")->plug(m_pop);
00431 m_actions->action("printer_test")->plug(m_pop);
00432 }
00433 m_pop->insertSeparator();
00434 }
00435 if (!printer->isSpecial())
00436 {
00437 QValueList<KAction*> pactions = m_actions->actions("plugin");
00438 for (QValueList<KAction*>::Iterator it=pactions.begin(); it!=pactions.end(); ++it)
00439 (*it)->plug(m_pop);
00440 if (pactions.count() > 0)
00441 m_pop->insertSeparator();
00442 }
00443 }
00444 else
00445 {
00446 m_actions->action("printer_add")->plug(m_pop);
00447 m_actions->action("printer_add_special")->plug(m_pop);
00448 m_pop->insertSeparator();
00449 m_actions->action("server_restart")->plug(m_pop);
00450 m_actions->action("server_configure")->plug(m_pop);
00451 m_pop->insertSeparator();
00452 m_actions->action("manager_configure")->plug(m_pop);
00453 m_actions->action("view_refresh")->plug(m_pop);
00454 m_pop->insertSeparator();
00455 }
00456 m_actions->action("view_printerinfos")->plug(m_pop);
00457 m_actions->action("view_change")->plug(m_pop);
00458 m_actions->action("orientation_change")->plug(m_pop);
00459 m_actions->action("view_toolbar")->plug(m_pop);
00460 m_actions->action("view_menubar")->plug(m_pop);
00461 m_pop->insertSeparator();
00462 m_actions->action("view_pfilter")->plug(m_pop);
00463
00464
00465 m_pop->popup(p);
00466 }
00467
00468 void KMMainView::slotChangePrinterState()
00469 {
00470 QString opname = sender()->name();
00471 if (m_current && opname.startsWith("printer_"))
00472 {
00473 opname = opname.mid(8);
00474 KMTimer::self()->hold();
00475 bool result(false);
00476 if (opname == "enable")
00477 result = m_manager->enablePrinter(m_current, true);
00478 else if (opname == "disable")
00479 result = m_manager->enablePrinter(m_current, false);
00480 else if (opname == "start")
00481 result = m_manager->startPrinter(m_current, true);
00482 else if (opname == "stop")
00483 result = m_manager->startPrinter(m_current, false);
00484 if (!result)
00485 showErrorMsg(i18n("Unable to modify the state of printer %1.").arg(m_current->printerName()));
00486 KMTimer::self()->release(result);
00487 }
00488 }
00489
00490 void KMMainView::slotRemove()
00491 {
00492 if (m_current)
00493 {
00494 KMTimer::self()->hold();
00495 bool result(false);
00496 if (KMessageBox::warningYesNo(this,i18n("Do you really want to remove %1?").arg(m_current->printerName())) == KMessageBox::Yes)
00497 if (m_current->isSpecial())
00498 {
00499 if (!(result=m_manager->removeSpecialPrinter(m_current)))
00500 showErrorMsg(i18n("Unable to remove special printer %1.").arg(m_current->printerName()));
00501 }
00502 else if (!(result=m_manager->removePrinter(m_current)))
00503 showErrorMsg(i18n("Unable to remove printer %1.").arg(m_current->printerName()));
00504 KMTimer::self()->release(result);
00505 }
00506 }
00507
00508 void KMMainView::slotConfigure()
00509 {
00510 if (m_current)
00511 {
00512 KMTimer::self()->hold();
00513 bool needRefresh(false);
00514 if (m_current->isSpecial())
00515 {
00516 KMSpecialPrinterDlg dlg(this);
00517 dlg.setPrinter(m_current);
00518 if (dlg.exec())
00519 {
00520 KMPrinter *prt = dlg.printer();
00521 if (prt->name() != m_current->name())
00522 m_manager->removeSpecialPrinter(m_current);
00523 m_manager->createSpecialPrinter(prt);
00524 needRefresh = true;
00525 }
00526 }
00527 else
00528 {
00529 DrMain *driver = m_manager->loadPrinterDriver(m_current, true);
00530 if (driver)
00531 {
00532 KMDriverDialog dlg(this);
00533 dlg.setCaption(i18n("Configure %1").arg(m_current->printerName()));
00534 dlg.setDriver(driver);
00535
00536 if (m_current->isRemote())
00537 dlg.enableButtonOK(false);
00538 if (dlg.exec())
00539 if (!m_manager->savePrinterDriver(m_current,driver))
00540 showErrorMsg(i18n("Unable to modify settings of printer %1.").arg(m_current->printerName()));
00541 delete driver;
00542 }
00543 else
00544 showErrorMsg(i18n("Unable to load a valid driver for printer %1.").arg(m_current->printerName()));
00545 }
00546 KMTimer::self()->release(needRefresh);
00547 }
00548 }
00549
00550 void KMMainView::slotAdd()
00551 {
00552 KMTimer::self()->hold();
00553
00554 int result(0);
00555 if ((result=kdeprint_management_add_printer_wizard(this)) == -1)
00556 showErrorMsg(i18n("Unable to create printer."));
00557
00558 KMTimer::self()->release((result == 1));
00559 }
00560
00561 void KMMainView::slotHardDefault()
00562 {
00563 if (m_current)
00564 {
00565 KMTimer::self()->hold();
00566 bool result = m_manager->setDefaultPrinter(m_current);
00567 if (!result)
00568 showErrorMsg(i18n("Unable to define printer %1 as default.").arg(m_current->printerName()));
00569 KMTimer::self()->release(result);
00570 }
00571 }
00572
00573 void KMMainView::slotSoftDefault()
00574 {
00575 if (m_current)
00576 {
00577 KMTimer::self()->hold();
00578 KMFactory::self()->virtualManager()->setAsDefault(m_current,QString::null);
00579 KMTimer::self()->release(true);
00580 }
00581 }
00582
00583 void KMMainView::setOrientation(int o)
00584 {
00585 int ID = (o == Qt::Horizontal ? 1 : 0);
00586 ((KSelectAction*)m_actions->action("orientation_change"))->setCurrentItem(ID);
00587 slotChangeDirection(ID);
00588 }
00589
00590 int KMMainView::orientation() const
00591 { return (m_boxlayout->direction() == QBoxLayout::LeftToRight ? Qt::Horizontal : Qt::Vertical); }
00592
00593 void KMMainView::slotChangeDirection(int d)
00594 {
00595 m_boxlayout->setDirection(d == 1 ? QBoxLayout::LeftToRight : QBoxLayout::TopToBottom);
00596 }
00597
00598 void KMMainView::slotTest()
00599 {
00600 if (m_current)
00601 {
00602 KMTimer::self()->hold();
00603 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)
00604 {
00605 if (KMFactory::self()->manager()->testPrinter(m_current))
00606 KMessageBox::information(this,i18n("Test page successfully sent to printer %1.").arg(m_current->printerName()));
00607 else
00608 showErrorMsg(i18n("Unable to test printer %1.").arg(m_current->printerName()));
00609 }
00610 KMTimer::self()->release(true);
00611 }
00612 }
00613
00614 void KMMainView::showErrorMsg(const QString& msg, bool usemgr)
00615 {
00616 QString s(msg);
00617 if (usemgr)
00618 {
00619 s.prepend("<p>");
00620 s.append(" ");
00621 s += i18n("Error message received from manager:</p><p>%1</p>");
00622 if (m_manager->errorMsg().isEmpty())
00623 s = s.arg(i18n("Internal error (no error message)."));
00624 else
00625 s = s.arg(m_manager->errorMsg());
00626
00627 m_manager->setErrorMsg(QString::null);
00628 }
00629 s.prepend("<qt>").append("</qt>");
00630 KMTimer::self()->hold();
00631 KMessageBox::error(this,s);
00632 KMTimer::self()->release();
00633 }
00634
00635 void KMMainView::slotServerRestart()
00636 {
00637 KMTimer::self()->hold();
00638 bool result = m_manager->restartServer();
00639 if (!result)
00640 {
00641 showErrorMsg(i18n("Unable to restart print server."));
00642 KMTimer::self()->release( false );
00643 }
00644 else
00645 {
00646 m_printerview->setPrinterList( 0 );
00647 createMessageWindow( i18n( "Restarting server..." ), 0 );
00648 m_manager->checkUpdatePossible();
00649 }
00650 }
00651
00652 void KMMainView::slotServerConfigure()
00653 {
00654 KMTimer::self()->hold();
00655 bool result = m_manager->configureServer(this);
00656 if (!result)
00657 {
00658 showErrorMsg(i18n("Unable to configure print server."));
00659 KMTimer::self()->release( false );
00660 }
00661 else
00662 {
00663 m_printerview->setPrinterList( 0 );
00664 createMessageWindow( i18n( "Configuring server..." ), 0 );
00665 m_manager->checkUpdatePossible();
00666 }
00667 }
00668
00669 void KMMainView::slotToggleToolBar(bool on)
00670 {
00671 if (on) m_toolbar->show();
00672 else m_toolbar->hide();
00673 }
00674
00675 void KMMainView::slotToggleMenuBar( bool on )
00676 {
00677 if ( on )
00678 m_menubar->show();
00679 else
00680 m_menubar->hide();
00681 }
00682
00683 void KMMainView::slotManagerConfigure()
00684 {
00685 KMTimer::self()->hold();
00686 KMConfigDialog dlg(this,"ConfigDialog");
00687 bool refresh(false);
00688 if ((refresh=dlg.exec()))
00689 {
00690 loadParameters();
00691 }
00692 KMTimer::self()->release(refresh);
00693 }
00694
00695 void KMMainView::slotAddSpecial()
00696 {
00697 KMTimer::self()->hold();
00698 KMSpecialPrinterDlg dlg(this);
00699 if (dlg.exec())
00700 {
00701 KMPrinter *prt = dlg.printer();
00702 m_manager->createSpecialPrinter(prt);
00703 }
00704 KMTimer::self()->release(true);
00705 }
00706
00707 void KMMainView::slotShowPrinterInfos(bool on)
00708 {
00709 if (on)
00710 m_printerpages->show();
00711 else
00712 m_printerpages->hide();
00713 m_actions->action("orientation_change")->setEnabled(on);
00714 }
00715
00716 void KMMainView::enableToolbar(bool on)
00717 {
00718 KToggleAction *act = (KToggleAction*)m_actions->action("view_toolbar");
00719 m_toolbar->setEnabled(on);
00720 act->setEnabled(on);
00721 if (on && act->isChecked())
00722 m_toolbar->show();
00723 else
00724 m_toolbar->hide();
00725 }
00726
00727 KAction* KMMainView::action(const char *name)
00728 {
00729 return m_actions->action(name);
00730 }
00731
00732
00733
00734
00735
00736
00737
00738
00739 void KMMainView::reload()
00740 {
00741 removePluginActions();
00742 loadPluginActions();
00743
00744
00745 connect( m_manager, SIGNAL( updatePossible( bool ) ), SLOT( slotUpdatePossible( bool ) ) );
00746
00747
00748
00749 KMTimer::self()->hold();
00750 m_printerview->setPrinterList( 0 );
00751 createMessageWindow( i18n( "Initializing manager..." ) );
00752 m_manager->checkUpdatePossible();
00753 }
00754
00755 void KMMainView::showPrinterInfos(bool on)
00756 {
00757 static_cast<KToggleAction*>(m_actions->action("view_printerinfos"))->setChecked(on);
00758 slotShowPrinterInfos(on);
00759 }
00760
00761 bool KMMainView::printerInfosShown() const
00762 {
00763 return (static_cast<KToggleAction*>(m_actions->action("view_printerinfos"))->isChecked());
00764 }
00765
00766 void KMMainView::loadPluginActions()
00767 {
00768 KMFactory::self()->manager()->createPluginActions(m_actions);
00769 QValueList<KAction*> pactions = m_actions->actions("plugin");
00770 int index = m_pactionsindex;
00771
00772 QPopupMenu *menu = m_menubar->getButton( 1 )->popup();
00773 for (QValueList<KAction*>::Iterator it=pactions.begin(); it!=pactions.end(); ++it)
00774 {
00775 (*it)->plug(m_toolbar, index++);
00776 ( *it )->plug( menu );
00777 }
00778 }
00779
00780 void KMMainView::removePluginActions()
00781 {
00782 QValueList<KAction*> pactions = m_actions->actions("plugin");
00783 for (QValueList<KAction*>::Iterator it=pactions.begin(); it!=pactions.end(); ++it)
00784 {
00785 (*it)->unplugAll();
00786 delete (*it);
00787 }
00788 }
00789
00790 void KMMainView::slotToolSelected(int ID)
00791 {
00792 KMTimer::self()->hold();
00793
00794 QString libname = m_toollist[ID];
00795 libname.prepend("kdeprint_tool_");
00796 if (m_current && !m_current->device().isEmpty() && !libname.isEmpty())
00797 {
00798 KLibFactory *factory = KLibLoader::self()->factory(libname.local8Bit());
00799 if (factory)
00800 {
00801 QStringList args;
00802 args << m_current->device() << m_current->printerName();
00803 KDialogBase *dlg = static_cast<KDialogBase*>(factory->create(this, "Tool", 0, args));
00804 if (dlg)
00805 dlg->exec();
00806 delete dlg;
00807 }
00808 }
00809 else
00810 KMessageBox::error(this,
00811 i18n("Unable to start printer tool. Possible reasons are: "
00812 "no printer selected, the selected printer doesn't have "
00813 "any local device defined (printer port), or the tool library "
00814 "could not be found."));
00815
00816 KMTimer::self()->release();
00817 }
00818
00819 void KMMainView::slotToggleFilter(bool on)
00820 {
00821 KMTimer::self()->hold();
00822 KMManager::self()->enableFilter(on);
00823 KMTimer::self()->release(true);
00824 }
00825
00826 void KMMainView::configChanged()
00827 {
00828 slotRefresh();
00829 }
00830
00831 void KMMainView::slotUpdatePossible( bool flag )
00832 {
00833 destroyMessageWindow();
00834 if ( !flag )
00835 showErrorMsg( i18n( "Unable to retrieve the printer list." ) );
00836 KMTimer::self()->release( true );
00837 }
00838
00839 void KMMainView::createMessageWindow( const QString& txt, int delay )
00840 {
00841 destroyMessageWindow();
00842 MessageWindow::add( m_printerview, txt, delay );
00843 }
00844
00845 void KMMainView::destroyMessageWindow()
00846 {
00847 MessageWindow::remove( m_printerview );
00848 }
00849
00850 void KMMainView::slotInit()
00851 {
00852 KMTimer::self()->hold();
00853 m_printerview->setPrinterList( 0 );
00854 createMessageWindow( i18n( "Initializing manager..." ) );
00855 m_manager->checkUpdatePossible();
00856 }
00857
00858 void KMMainView::slotHelp()
00859 {
00860 QString s = sender()->name();
00861 if ( s == "invoke_help" )
00862 kapp->invokeHelp( QString::null, "kdeprint" );
00863 else if ( s == "invoke_web" )
00864 {
00865 QStringList args;
00866 args << "exec" << "http://printing.kde.org";
00867 kapp->kdeinitExec( "kfmclient", args );
00868 }
00869 else
00870 kdDebug( 500 ) << "Unknown help invokator: " << s << endl;
00871 }
00872
00873 #include "kmmainview.moc"