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 <tqdockarea.h>
00039 #include <tdemenubar.h>
00040 #include <tqtimer.h>
00041 #include <tqcombobox.h>
00042 #include <tqlabel.h>
00043 #include <tqlayout.h>
00044 #include <tqpopupmenu.h>
00045 #include <tdemessagebox.h>
00046 #include <tdeaction.h>
00047 #include <tdelocale.h>
00048 #include <tdeconfig.h>
00049 #include <tdetoolbar.h>
00050 #include <tdetoolbarbutton.h>
00051 #include <kdebug.h>
00052 #include <tdepopupmenu.h>
00053 #include <klibloader.h>
00054 #include <kdialogbase.h>
00055 #include <ksimpleconfig.h>
00056 #include <kstandarddirs.h>
00057 #include <tdeapplication.h>
00058 #include <kprocess.h>
00059
00060 #undef m_manager
00061 #define m_manager KMFactory::self()->manager()
00062
00063 int tdeprint_management_add_printer_wizard( TQWidget* parent )
00064 {
00065 KMWizard dlg(parent);
00066 int flag(0);
00067 if (dlg.exec())
00068 {
00069 flag = 1;
00070
00071 if (KMFactory::self()->manager()->findPrinter(dlg.printer()->name()) != 0)
00072 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)
00073 flag = 0;
00074
00075 if (flag && !KMFactory::self()->manager()->createPrinter(dlg.printer()))
00076 flag = -1;
00077 }
00078 return flag;
00079 }
00080
00081 KMMainView::KMMainView(TQWidget *parent, const char *name, TDEActionCollection *coll)
00082 : TQWidget(parent, name)
00083 {
00084 m_current = 0;
00085 m_first = true;
00086
00087
00088 m_printerview = new KMPrinterView(this, "PrinterView");
00089 m_printerpages = new KMPages(this, "PrinterPages");
00090 m_pop = new TQPopupMenu(this);
00091 m_toolbar = new TDEToolBar(this, "ToolBar");
00092 m_toolbar->setMovingEnabled(false);
00093 m_plugin = new PluginComboBox(this, "Plugin");
00094
00095
00096
00097
00098 m_menubar = new TDEToolBar( this, "MenuBar", false, false );
00099 m_menubar->setIconText( TDEToolBar::IconTextRight );
00100 m_menubar->setMovingEnabled( false );
00101
00102
00103 TQVBoxLayout *m_layout = new TQVBoxLayout(this, 0, 0);
00104 m_layout->addWidget(m_toolbar);
00105 m_layout->addWidget( m_menubar );
00106 m_boxlayout = new TQBoxLayout(TQBoxLayout::TopToBottom, 0, 0);
00107 m_layout->addLayout(m_boxlayout);
00108 m_boxlayout->addWidget(m_printerview);
00109 m_boxlayout->addWidget(m_printerpages);
00110 m_layout->addSpacing(5);
00111 m_layout->addWidget(m_plugin, 0);
00112
00113
00114 connect(KMTimer::self(),TQT_SIGNAL(timeout()),TQT_SLOT(slotTimer()));
00115 connect(m_printerview,TQT_SIGNAL(printerSelected(const TQString&)),TQT_SLOT(slotPrinterSelected(const TQString&)));
00116 connect(m_printerview,TQT_SIGNAL(rightButtonClicked(const TQString&,const TQPoint&)),TQT_SLOT(slotRightButtonClicked(const TQString&,const TQPoint&)));
00117 connect(m_pop,TQT_SIGNAL(aboutToShow()),KMTimer::self(),TQT_SLOT(hold()));
00118 connect(m_pop,TQT_SIGNAL(aboutToHide()),KMTimer::self(),TQT_SLOT(release()));
00119 connect( m_manager, TQT_SIGNAL( updatePossible( bool ) ), TQT_SLOT( slotUpdatePossible( bool ) ) );
00120
00121
00122 if (coll)
00123 m_actions = coll;
00124 else
00125 m_actions = new TDEActionCollection(this);
00126 initActions();
00127
00128
00129 restoreSettings();
00130 loadParameters();
00131
00132
00133 reset( i18n( "Initializing manager..." ), true, true );
00134 }
00135
00136 KMMainView::~KMMainView()
00137 {
00138 saveSettings();
00139
00140 }
00141
00142 void KMMainView::loadParameters()
00143 {
00144 }
00145
00146 void KMMainView::restoreSettings()
00147 {
00148 TDEConfig *conf = KMFactory::self()->printConfig();
00149 conf->setGroup("General");
00150 setViewType((KMPrinterView::ViewType)conf->readNumEntry("ViewType",KMPrinterView::Icons));
00151 setOrientation(conf->readNumEntry("Orientation", Qt::Vertical));
00152 bool view = conf->readBoolEntry("ViewToolBar",false);
00153 slotToggleToolBar(view);
00154 ((TDEToggleAction*)m_actions->action("view_toolbar"))->setChecked(view);
00155 view = conf->readBoolEntry( "ViewMenuBar", true );
00156 slotToggleMenuBar( view );
00157 static_cast<TDEToggleAction*>( m_actions->action( "view_menubar" ) )->setChecked( view );
00158 view = conf->readBoolEntry("ViewPrinterInfos",true);
00159 slotShowPrinterInfos(view);
00160 ((TDEToggleAction*)m_actions->action("view_printerinfos"))->setChecked(view);
00161 }
00162
00163 void KMMainView::saveSettings()
00164 {
00165 TDEConfig *conf = KMFactory::self()->printConfig();
00166 conf->setGroup("General");
00167 conf->writeEntry("ViewType",(int)m_printerview->viewType());
00168 conf->writeEntry("Orientation",(int)orientation());
00169 conf->writeEntry("ViewToolBar",((TDEToggleAction*)m_actions->action("view_toolbar"))->isChecked());
00170 conf->writeEntry("ViewMenuBar",static_cast<TDEToggleAction*>( m_actions->action("view_menubar") )->isChecked());
00171 conf->writeEntry("ViewPrinterInfos",((TDEToggleAction*)m_actions->action("view_printerinfos"))->isChecked());
00172 conf->sync();
00173 }
00174
00175 void KMMainView::initActions()
00176 {
00177 TDEIconSelectAction *vact = new TDEIconSelectAction(i18n("&View"),0,m_actions,"view_change");
00178 TQStringList iconlst;
00179 iconlst << "view_icon" << "view_detailed" << "view_tree";
00180 vact->setItems(TQStringList::split(',',i18n("&Icons,&List,&Tree"),false), iconlst);
00181 vact->setCurrentItem(0);
00182 connect(vact,TQT_SIGNAL(activated(int)),TQT_SLOT(slotChangeView(int)));
00183
00184 TDEActionMenu *stateAct = new TDEActionMenu(i18n("Start/Stop Printer"), "tdeprint_printstate", m_actions, "printer_state_change");
00185 stateAct->setDelayed(false);
00186 stateAct->insert(new TDEAction(i18n("&Start Printer"),"tdeprint_enableprinter",0,TQT_TQOBJECT(this),TQT_SLOT(slotChangePrinterState()),m_actions,"printer_start"));
00187 stateAct->insert(new TDEAction(i18n("Sto&p Printer"),"tdeprint_stopprinter",0,TQT_TQOBJECT(this),TQT_SLOT(slotChangePrinterState()),m_actions,"printer_stop"));
00188
00189 stateAct = new TDEActionMenu(i18n("Enable/Disable Job Spooling"), "tdeprint_queuestate", m_actions, "printer_spool_change");
00190 stateAct->setDelayed(false);
00191 stateAct->insert(new TDEAction(i18n("&Enable Job Spooling"),"tdeprint_enableprinter",0,TQT_TQOBJECT(this),TQT_SLOT(slotChangePrinterState()),m_actions,"printer_enable"));
00192 stateAct->insert(new TDEAction(i18n("&Disable Job Spooling"),"tdeprint_stopprinter",0,TQT_TQOBJECT(this),TQT_SLOT(slotChangePrinterState()),m_actions,"printer_disable"));
00193
00194 new TDEAction(i18n("&Remove"),"edittrash",0,TQT_TQOBJECT(this),TQT_SLOT(slotRemove()),m_actions,"printer_remove");
00195 new TDEAction(i18n("&Configure..."),"configure",0,TQT_TQOBJECT(this),TQT_SLOT(slotConfigure()),m_actions,"printer_configure");
00196 new TDEAction(i18n("Add &Printer/Class..."),"tdeprint_addprinter",0,TQT_TQOBJECT(this),TQT_SLOT(slotAdd()),m_actions,"printer_add");
00197 new TDEAction(i18n("Add &Special (pseudo) Printer..."),"tdeprint_addpseudo",0,TQT_TQOBJECT(this),TQT_SLOT(slotAddSpecial()),m_actions,"printer_add_special");
00198 new TDEAction(i18n("Set as &Local Default"),"tdeprint_defaulthard",0,TQT_TQOBJECT(this),TQT_SLOT(slotHardDefault()),m_actions,"printer_hard_default");
00199 new TDEAction(i18n("Set as &User Default"),"tdeprint_defaultsoft",0,TQT_TQOBJECT(this),TQT_SLOT(slotSoftDefault()),m_actions,"printer_soft_default");
00200 new TDEAction(i18n("&Test Printer..."),"tdeprint_testprinter",0,TQT_TQOBJECT(this),TQT_SLOT(slotTest()),m_actions,"printer_test");
00201 new TDEAction(i18n("Configure &Manager..."),"tdeprint_configmgr",0,TQT_TQOBJECT(this),TQT_SLOT(slotManagerConfigure()),m_actions,"manager_configure");
00202 new TDEAction(i18n("Initialize Manager/&View"),"reload",0,TQT_TQOBJECT(this),TQT_SLOT(slotInit()),m_actions,"view_refresh");
00203
00204 TDEIconSelectAction *dact = new TDEIconSelectAction(i18n("&Orientation"),0,m_actions,"orientation_change");
00205 iconlst.clear();
00206 iconlst << "view_top_bottom" << "view_left_right";
00207 dact->setItems(TQStringList::split(',',i18n("&Vertical,&Horizontal"),false), iconlst);
00208 dact->setCurrentItem(0);
00209 connect(dact,TQT_SIGNAL(activated(int)),TQT_SLOT(slotChangeDirection(int)));
00210
00211 new TDEAction(i18n("R&estart Server"),"tdeprint_restartsrv",0,TQT_TQOBJECT(this),TQT_SLOT(slotServerRestart()),m_actions,"server_restart");
00212 new TDEAction(i18n("Configure &Server..."),"tdeprint_configsrv",0,TQT_TQOBJECT(this),TQT_SLOT(slotServerConfigure()),m_actions,"server_configure");
00213 new TDEAction(i18n("Configure Server Access..."),"tdeprint_configsrv",0,TQT_TQOBJECT(this),TQT_SLOT(slotServerConfigureAccess()),m_actions,"server_access_configure");
00214
00215 TDEToggleAction *tact = new TDEToggleAction(i18n("Show &Toolbar"),0,m_actions,"view_toolbar");
00216 tact->setCheckedState(i18n("Hide &Toolbar"));
00217 connect(tact,TQT_SIGNAL(toggled(bool)),TQT_SLOT(slotToggleToolBar(bool)));
00218 tact = new TDEToggleAction( i18n( "Show Me&nu Toolbar" ), 0, m_actions, "view_menubar" );
00219 tact->setCheckedState(i18n("Hide Me&nu Toolbar"));
00220 connect( tact, TQT_SIGNAL( toggled( bool ) ), TQT_SLOT( slotToggleMenuBar( bool ) ) );
00221 tact = new TDEToggleAction(i18n("Show Pr&inter Details"),"tdeprint_printer_infos", 0,m_actions,"view_printerinfos");
00222 tact->setCheckedState(KGuiItem(i18n("Hide Pr&inter Details"),"tdeprint_printer_infos"));
00223 tact->setChecked(true);
00224 connect(tact,TQT_SIGNAL(toggled(bool)),TQT_SLOT(slotShowPrinterInfos(bool)));
00225
00226 tact = new TDEToggleAction(i18n("Toggle Printer &Filtering"), "filter", 0, m_actions, "view_pfilter");
00227 tact->setChecked(KMManager::self()->isFilterEnabled());
00228 connect(tact, TQT_SIGNAL(toggled(bool)), TQT_SLOT(slotToggleFilter(bool)));
00229
00230 TDEActionMenu *mact = new TDEActionMenu(i18n("Pri&nter Tools"), "applications-utilities", m_actions, "printer_tool");
00231 mact->setDelayed(false);
00232 connect(mact->popupMenu(), TQT_SIGNAL(activated(int)), TQT_SLOT(slotToolSelected(int)));
00233 TQStringList files = TDEGlobal::dirs()->findAllResources("data", "tdeprint/tools/*.desktop");
00234 for (TQStringList::ConstIterator it=files.begin(); it!=files.end(); ++it)
00235 {
00236 KSimpleConfig conf(*it);
00237 conf.setGroup("Desktop Entry");
00238 mact->popupMenu()->insertItem(conf.readEntry("Name", "Unnamed"), mact->popupMenu()->count());
00239 m_toollist << conf.readEntry("X-TDE-Library");
00240 }
00241
00242
00243 m_actions->action("printer_add")->plug(m_toolbar);
00244 m_actions->action("printer_add_special")->plug(m_toolbar);
00245 m_toolbar->insertLineSeparator();
00246 m_actions->action("printer_state_change")->plug(m_toolbar);
00247 m_actions->action("printer_spool_change")->plug(m_toolbar);
00248 m_toolbar->insertSeparator();
00249 m_actions->action("printer_hard_default")->plug(m_toolbar);
00250 m_actions->action("printer_soft_default")->plug(m_toolbar);
00251 m_actions->action("printer_remove")->plug(m_toolbar);
00252 m_toolbar->insertSeparator();
00253 m_actions->action("printer_configure")->plug(m_toolbar);
00254 m_actions->action("printer_test")->plug(m_toolbar);
00255 m_actions->action("printer_tool")->plug(m_toolbar);
00256 m_pactionsindex = m_toolbar->insertSeparator();
00257 m_toolbar->insertLineSeparator();
00258 m_actions->action("server_restart")->plug(m_toolbar);
00259 m_actions->action("server_configure")->plug(m_toolbar);
00260 m_toolbar->insertLineSeparator();
00261 m_actions->action("manager_configure")->plug(m_toolbar);
00262 m_actions->action("view_refresh")->plug(m_toolbar);
00263 m_toolbar->insertLineSeparator();
00264 m_actions->action("view_printerinfos")->plug(m_toolbar);
00265 m_actions->action("view_change")->plug(m_toolbar);
00266 m_actions->action("orientation_change")->plug(m_toolbar);
00267 m_actions->action("view_pfilter")->plug(m_toolbar);
00268
00269
00270 TQPopupMenu *menu = new TQPopupMenu( this );
00271 m_actions->action( "printer_add" )->plug( menu );
00272 m_actions->action( "printer_add_special" )->plug( menu );
00273
00274 m_menubar->insertButton( "wizard", 0, true, i18n( "Add" ) );
00275 m_menubar->getButton( 0 )->setPopup( menu, true );
00276 menu = new TQPopupMenu( this );
00277 m_actions->action("printer_state_change")->plug( menu );
00278 m_actions->action("printer_spool_change")->plug( menu );
00279 menu->insertSeparator();
00280 m_actions->action("printer_hard_default")->plug( menu );
00281 m_actions->action("printer_soft_default")->plug( menu );
00282 m_actions->action("printer_remove")->plug( menu );
00283 menu->insertSeparator();
00284 m_actions->action("printer_configure")->plug( menu );
00285 m_actions->action("printer_test")->plug( menu );
00286 m_actions->action("printer_tool")->plug( menu );
00287 menu->insertSeparator();
00288
00289 m_menubar->insertButton( "printer", 1, true, i18n( "Printer" ) );
00290 m_menubar->getButton( 1 )->setPopup( menu, true );
00291 menu = new TQPopupMenu( this );
00292 m_actions->action("server_restart")->plug( menu );
00293 m_actions->action("server_configure")->plug( menu );
00294
00295 m_menubar->insertButton( "misc", 2, true, i18n( "Print Server" ) );
00296 m_menubar->getButton( 2 )->setPopup( menu, true );
00297 menu = new TQPopupMenu( this );
00298 m_actions->action("manager_configure")->plug( menu );
00299 m_actions->action("view_refresh")->plug( menu );
00300
00301 m_menubar->insertButton( "tdeprint_configmgr", 3, true, i18n( "Print Manager" ) );
00302 m_menubar->getButton( 3 )->setPopup( menu, true );
00303 menu = new TQPopupMenu( this );
00304 m_actions->action("view_printerinfos")->plug( menu );
00305 m_actions->action("view_change")->plug( menu );
00306 m_actions->action("orientation_change")->plug( menu );
00307 m_actions->action( "view_toolbar" )->plug ( menu );
00308 m_actions->action( "view_menubar" )->plug ( menu );
00309 menu->insertSeparator();
00310 m_actions->action("view_pfilter")->plug( menu );
00311
00312 m_menubar->insertButton( "view_remove", 4, true, i18n( "View" ) );
00313 m_menubar->getButton( 4 )->setPopup( menu, true );
00314
00315
00316 loadPluginActions();
00317 slotPrinterSelected(TQString::null);
00318 }
00319
00320 void KMMainView::slotRefresh()
00321 {
00322
00323 }
00324
00325 void KMMainView::slotTimer()
00326 {
00327 kdDebug() << "KMMainView::slotTimer" << endl;
00328 TQPtrList<KMPrinter> *printerlist = m_manager->printerList();
00329 bool ok = m_manager->errorMsg().isEmpty();
00330 m_printerview->setPrinterList(printerlist);
00331 if ( m_first )
00332 {
00333 if ( !ok )
00334 showErrorMsg(i18n("An error occurred while retrieving the printer list."));
00335 else
00336 {
00337
00338
00339
00340
00341
00342 TQPtrListIterator<KMPrinter> it( *printerlist );
00343 KMPrinter *p1 = 0, *p2 = 0, *p3 = 0;
00344 while ( it.current() )
00345 {
00346 if ( !it.current()->isVirtual() )
00347 {
00348 if ( it.current()->ownSoftDefault() )
00349 {
00350 p1 = it.current();
00351 break;
00352 }
00353 else if ( it.current()->isHardDefault() )
00354 p2 = it.current();
00355 else if ( !p3 )
00356 p3 = it.current();
00357 }
00358 ++it;
00359 }
00360 if ( p1 || p2 || p3 )
00361 m_printerview->setPrinter( p1 ? p1 : ( p2 ? p2 : p3 ) );
00362 }
00363 m_first = false;
00364 }
00365 }
00366
00367 void KMMainView::slotPrinterSelected(const TQString& prname)
00368 {
00369 KMPrinter *p = KMManager::self()->findPrinter(prname);
00370 m_current = p;
00371 if (p && !p->isSpecial())
00372 KMFactory::self()->manager()->completePrinter(p);
00373 m_printerpages->setPrinter(p);
00374
00375
00376
00377
00378
00379 int mask = (m_manager->hasManagement() ? m_manager->printerOperationMask() : 0);
00380 bool sp = !(p && p->isSpecial());
00381
00382 m_actions->action("printer_remove")->setEnabled(!sp || ((mask & KMManager::PrinterRemoval) && p && !p->isImplicit()));
00383 m_actions->action("printer_configure")->setEnabled(!sp || ((mask & KMManager::PrinterConfigure) && p && !p->isClass(true) ));
00384 m_actions->action("printer_hard_default")->setEnabled((sp && (mask & KMManager::PrinterDefault) && p && !p->isClass(true) && !p->isHardDefault() && p->isLocal()));
00385 m_actions->action("printer_soft_default")->setEnabled((p && !p->isSoftDefault()));
00386 m_actions->action("printer_test")->setEnabled((sp && (mask & KMManager::PrinterTesting) && p && !p->isClass(true)));
00387 bool stmask = (sp && (mask & KMManager::PrinterEnabling) && p);
00388 m_actions->action("printer_state_change")->setEnabled(stmask && p->isLocal());
00389 m_actions->action("printer_spool_change")->setEnabled(stmask);
00390 m_actions->action("printer_start")->setEnabled((stmask && p->state() == KMPrinter::Stopped));
00391 m_actions->action("printer_stop")->setEnabled((stmask && p->state() != KMPrinter::Stopped));
00392 m_actions->action("printer_enable")->setEnabled((stmask && !p->acceptJobs()));
00393 m_actions->action("printer_disable")->setEnabled((stmask && p->acceptJobs()));
00394
00395 m_actions->action("printer_add")->setEnabled((mask & KMManager::PrinterCreation));
00396 mask = m_manager->serverOperationMask();
00397 m_actions->action("server_restart")->setEnabled((mask & KMManager::ServerRestarting));
00398 m_actions->action("server_configure")->setEnabled((mask & KMManager::ServerConfigure));
00399
00400 KMFactory::self()->manager()->validatePluginActions(m_actions, p);
00401
00402 m_actions->action("printer_tool")->setEnabled(p && !p->isClass(true) && !p->isRemote() && !p->isSpecial());
00403 }
00404
00405 void KMMainView::setViewType(int ID)
00406 {
00407 ((TDESelectAction*)m_actions->action("view_change"))->setCurrentItem(ID);
00408 slotChangeView(ID);
00409 }
00410
00411 int KMMainView::viewType() const
00412 { return m_printerview->viewType(); }
00413
00414 void KMMainView::slotChangeView(int ID)
00415 {
00416 kdDebug() << "KMMainView::slotChangeView" << endl;
00417 if (ID >= KMPrinterView::Icons && ID <= KMPrinterView::Tree)
00418 m_printerview->setViewType((KMPrinterView::ViewType)ID);
00419 }
00420
00421 void KMMainView::slotRightButtonClicked(const TQString& prname, const TQPoint& p)
00422 {
00423 KMPrinter *printer = KMManager::self()->findPrinter(prname);
00424
00425 m_pop->clear();
00426 if (printer)
00427 {
00428 m_current = printer;
00429 if (!printer->isSpecial())
00430 {
00431 if (printer->isLocal())
00432 m_actions->action((printer->state() == KMPrinter::Stopped ? "printer_start" : "printer_stop"))->plug(m_pop);
00433 m_actions->action((printer->acceptJobs() ? "printer_disable" : "printer_enable"))->plug(m_pop);
00434 m_pop->insertSeparator();
00435 }
00436 if (!printer->isSoftDefault()) m_actions->action("printer_soft_default")->plug(m_pop);
00437 if (printer->isLocal() && !printer->isImplicit())
00438 {
00439 if (!printer->isHardDefault()) m_actions->action("printer_hard_default")->plug(m_pop);
00440 m_actions->action("printer_remove")->plug(m_pop);
00441 m_pop->insertSeparator();
00442 if (!printer->isClass(true))
00443 {
00444 m_actions->action("printer_configure")->plug(m_pop);
00445 m_actions->action("printer_test")->plug(m_pop);
00446 m_actions->action("printer_tool")->plug(m_pop);
00447 m_pop->insertSeparator();
00448 }
00449 }
00450 else
00451 {
00452 m_actions->action("printer_remove")->plug(m_pop);
00453 m_pop->insertSeparator();
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 TQValueList<TDEAction*> pactions = m_actions->actions("plugin");
00464 for (TQValueList<TDEAction*>::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 TQString opname = TQT_TQOBJECT_CONST(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=tdeprint_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,TQString::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 ((TDESelectAction*)m_actions->action("orientation_change"))->setCurrentItem(ID);
00613 slotChangeDirection(ID);
00614 }
00615
00616 int KMMainView::orientation() const
00617 { return (m_boxlayout->direction() == TQBoxLayout::LeftToRight ? Qt::Horizontal : Qt::Vertical); }
00618
00619 void KMMainView::slotChangeDirection(int d)
00620 {
00621 m_boxlayout->setDirection(d == 1 ? TQBoxLayout::LeftToRight : TQBoxLayout::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()), TQString::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 TQString& msg, bool usemgr)
00641 {
00642 TQString 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(TQString::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::slotServerConfigureAccess()
00692 {
00693 TDEProcess *proc = new TDEProcess;
00694 *proc << "/usr/bin/system-config-printer-kde";
00695 proc->start(TDEProcess::DontCare);
00696 }
00697
00698 void KMMainView::slotToggleToolBar(bool on)
00699 {
00700 if (on) m_toolbar->show();
00701 else m_toolbar->hide();
00702 }
00703
00704 void KMMainView::slotToggleMenuBar( bool on )
00705 {
00706 if ( on )
00707 m_menubar->show();
00708 else
00709 m_menubar->hide();
00710 }
00711
00712 void KMMainView::slotManagerConfigure()
00713 {
00714 KMTimer::self()->hold();
00715 KMConfigDialog dlg(this,"ConfigDialog");
00716 if ( dlg.exec() )
00717 {
00718 loadParameters();
00719 }
00720
00721
00722
00723
00724
00725
00726 KMTimer::self()->release( false );
00727 }
00728
00729 void KMMainView::slotAddSpecial()
00730 {
00731 KMTimer::self()->hold();
00732 KMSpecialPrinterDlg dlg(this);
00733 if (dlg.exec())
00734 {
00735 KMPrinter *prt = dlg.printer();
00736 m_manager->createSpecialPrinter(prt);
00737 }
00738 KMTimer::self()->release(true);
00739 }
00740
00741 void KMMainView::slotShowPrinterInfos(bool on)
00742 {
00743 if (on)
00744 m_printerpages->show();
00745 else
00746 m_printerpages->hide();
00747 m_actions->action("orientation_change")->setEnabled(on);
00748 }
00749
00750 void KMMainView::enableToolbar(bool on)
00751 {
00752 TDEToggleAction *act = (TDEToggleAction*)m_actions->action("view_toolbar");
00753 m_toolbar->setEnabled(on);
00754 act->setEnabled(on);
00755 if (on && act->isChecked())
00756 m_toolbar->show();
00757 else
00758 m_toolbar->hide();
00759 }
00760
00761 TDEAction* KMMainView::action(const char *name)
00762 {
00763 return m_actions->action(name);
00764 }
00765
00766
00767
00768
00769
00770
00771
00772
00773 void KMMainView::reload()
00774 {
00775 removePluginActions();
00776 loadPluginActions();
00777
00778
00779 connect( m_manager, TQT_SIGNAL( updatePossible( bool ) ), TQT_SLOT( slotUpdatePossible( bool ) ) );
00780
00781
00782
00783 reset( i18n( "Initializing manager..." ), true, true );
00784 }
00785
00786 void KMMainView::showPrinterInfos(bool on)
00787 {
00788 static_cast<TDEToggleAction*>(m_actions->action("view_printerinfos"))->setChecked(on);
00789 slotShowPrinterInfos(on);
00790 }
00791
00792 bool KMMainView::printerInfosShown() const
00793 {
00794 return (static_cast<TDEToggleAction*>(m_actions->action("view_printerinfos"))->isChecked());
00795 }
00796
00797 void KMMainView::loadPluginActions()
00798 {
00799 KMFactory::self()->manager()->createPluginActions(m_actions);
00800 TQValueList<TDEAction*> pactions = m_actions->actions("plugin");
00801 int index = m_pactionsindex;
00802
00803 TQPopupMenu *menu = m_menubar->getButton( 1 )->popup();
00804 for (TQValueList<TDEAction*>::Iterator it=pactions.begin(); it!=pactions.end(); ++it)
00805 {
00806 (*it)->plug(m_toolbar, index++);
00807 ( *it )->plug( menu );
00808 }
00809 }
00810
00811 void KMMainView::removePluginActions()
00812 {
00813 TQValueList<TDEAction*> pactions = m_actions->actions("plugin");
00814 for (TQValueList<TDEAction*>::Iterator it=pactions.begin(); it!=pactions.end(); ++it)
00815 {
00816 (*it)->unplugAll();
00817 delete (*it);
00818 }
00819 }
00820
00821 void KMMainView::slotToolSelected(int ID)
00822 {
00823 KMTimer::self()->hold();
00824
00825 TQString libname = m_toollist[ID];
00826 libname.prepend("tdeprint_tool_");
00827 if (m_current && !m_current->device().isEmpty() && !libname.isEmpty())
00828 {
00829 KLibFactory *factory = KLibLoader::self()->factory(libname.local8Bit());
00830 if (factory)
00831 {
00832 TQStringList args;
00833 args << m_current->device() << m_current->printerName();
00834 KDialogBase *dlg = static_cast<KDialogBase*>(TQT_TQWIDGET(factory->create(TQT_TQOBJECT(this), "Tool", 0, args)));
00835 if (dlg)
00836 dlg->exec();
00837 delete dlg;
00838 }
00839 }
00840 else
00841 KMessageBox::error(this,
00842 i18n("Unable to start printer tool. Possible reasons are: "
00843 "no printer selected, the selected printer doesn't have "
00844 "any local device defined (printer port), or the tool library "
00845 "could not be found."));
00846
00847 KMTimer::self()->release();
00848 }
00849
00850 void KMMainView::slotToggleFilter(bool on)
00851 {
00852 KMTimer::self()->hold();
00853 KMManager::self()->enableFilter(on);
00854 KMTimer::self()->release(true);
00855 }
00856
00857 void KMMainView::configChanged()
00858 {
00859 reset( i18n( "Initializing manager..." ), false, true );
00860 }
00861
00862 void KMMainView::slotUpdatePossible( bool flag )
00863 {
00864 destroyMessageWindow();
00865 if ( !flag )
00866 showErrorMsg( i18n( "Unable to retrieve the printer list." ) );
00867 KMTimer::self()->release( true );
00868 }
00869
00870 void KMMainView::createMessageWindow( const TQString& txt, int delay )
00871 {
00872 destroyMessageWindow();
00873 MessageWindow::add( m_printerview, txt, delay );
00874 }
00875
00876 void KMMainView::destroyMessageWindow()
00877 {
00878 MessageWindow::remove( m_printerview );
00879 }
00880
00881 void KMMainView::slotInit()
00882 {
00883 reset( i18n( "Initializing manager..." ), true, true );
00884 }
00885
00886 void KMMainView::reset( const TQString& msg, bool useDelay, bool holdTimer )
00887 {
00888 if ( holdTimer )
00889 KMTimer::self()->hold();
00890 m_printerview->setPrinterList( 0 );
00891 if ( !msg.isEmpty() )
00892 createMessageWindow( msg, ( useDelay ? 500 : 0 ) );
00893 m_first = true;
00894 m_manager->checkUpdatePossible();
00895 }
00896
00897 #include "kmmainview.moc"