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