20 #include "kmmainview.h"
22 #include "kmprinterview.h"
24 #include "kmmanager.h"
25 #include "kmuimanager.h"
26 #include "kmfactory.h"
27 #include "kmvirtualmanager.h"
28 #include "kmprinter.h"
30 #include "kmdriverdialog.h"
32 #include "kmconfigdialog.h"
33 #include "kmspecialprinterdlg.h"
34 #include "plugincombobox.h"
35 #include "kiconselectaction.h"
36 #include "messagewindow.h"
38 #include <tqdockarea.h>
39 #include <tdemenubar.h>
41 #include <tqcombobox.h>
44 #include <tqpopupmenu.h>
45 #include <tdemessagebox.h>
46 #include <tdeaction.h>
47 #include <tdelocale.h>
48 #include <tdeconfig.h>
49 #include <tdetoolbar.h>
50 #include <tdetoolbarbutton.h>
52 #include <tdepopupmenu.h>
53 #include <klibloader.h>
54 #include <kdialogbase.h>
55 #include <ksimpleconfig.h>
56 #include <kstandarddirs.h>
57 #include <tdeapplication.h>
58 #include <tdeprocess.h>
61 #define m_manager KMFactory::self()->manager()
63 int tdeprint_management_add_printer_wizard( TQWidget* parent )
71 if (KMFactory::self()->manager()->findPrinter(dlg.printer()->name()) != 0)
72 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)
75 if (flag && !KMFactory::self()->manager()->createPrinter(dlg.printer()))
81 KMMainView::KMMainView(TQWidget *parent,
const char *name, TDEActionCollection *coll)
82 : TQWidget(parent, name)
88 m_printerview =
new KMPrinterView(
this,
"PrinterView");
89 m_printerpages =
new KMPages(
this,
"PrinterPages");
90 m_pop =
new TQPopupMenu(
this);
91 m_toolbar =
new TDEToolBar(
this,
"ToolBar");
92 m_toolbar->setMovingEnabled(
false);
93 m_plugin =
new PluginComboBox(
this,
"Plugin");
98 m_menubar =
new TDEToolBar(
this,
"MenuBar",
false,
false );
99 m_menubar->setIconText( TDEToolBar::IconTextRight );
100 m_menubar->setMovingEnabled(
false );
103 TQVBoxLayout *m_layout =
new TQVBoxLayout(
this, 0, 0);
104 m_layout->addWidget(m_toolbar);
105 m_layout->addWidget( m_menubar );
106 m_boxlayout =
new TQBoxLayout(TQBoxLayout::TopToBottom, 0, 0);
107 m_layout->addLayout(m_boxlayout);
108 m_boxlayout->addWidget(m_printerview);
109 m_boxlayout->addWidget(m_printerpages);
110 m_layout->addSpacing(5);
111 m_layout->addWidget(m_plugin, 0);
114 connect(KMTimer::self(),TQ_SIGNAL(timeout()),TQ_SLOT(slotTimer()));
115 connect(m_printerview,TQ_SIGNAL(printerSelected(
const TQString&)),TQ_SLOT(slotPrinterSelected(
const TQString&)));
116 connect(m_printerview,TQ_SIGNAL(rightButtonClicked(
const TQString&,
const TQPoint&)),TQ_SLOT(slotRightButtonClicked(
const TQString&,
const TQPoint&)));
117 connect(m_pop,TQ_SIGNAL(aboutToShow()),KMTimer::self(),TQ_SLOT(hold()));
118 connect(m_pop,TQ_SIGNAL(aboutToHide()),KMTimer::self(),TQ_SLOT(release()));
119 connect( m_manager, TQ_SIGNAL( updatePossible(
bool ) ), TQ_SLOT( slotUpdatePossible(
bool ) ) );
125 m_actions =
new TDEActionCollection(
this);
133 reset( i18n(
"Initializing manager..." ),
true,
true );
136 KMMainView::~KMMainView()
142 void KMMainView::loadParameters()
146 void KMMainView::restoreSettings()
148 TDEConfig *conf = KMFactory::self()->printConfig();
149 conf->setGroup(
"General");
150 setViewType((KMPrinterView::ViewType)conf->readNumEntry(
"ViewType",KMPrinterView::Icons));
151 setOrientation(conf->readNumEntry(
"Orientation", TQt::Vertical));
152 bool view = conf->readBoolEntry(
"ViewToolBar",
false);
153 slotToggleToolBar(view);
154 ((TDEToggleAction*)m_actions->action(
"view_toolbar"))->setChecked(view);
155 view = conf->readBoolEntry(
"ViewMenuBar",
true );
156 slotToggleMenuBar( view );
157 static_cast<TDEToggleAction*
>( m_actions->action(
"view_menubar" ) )->setChecked( view );
158 view = conf->readBoolEntry(
"ViewPrinterInfos",
true);
159 slotShowPrinterInfos(view);
160 ((TDEToggleAction*)m_actions->action(
"view_printerinfos"))->setChecked(view);
163 void KMMainView::saveSettings()
165 TDEConfig *conf = KMFactory::self()->printConfig();
166 conf->setGroup(
"General");
167 conf->writeEntry(
"ViewType",(
int)m_printerview->viewType());
168 conf->writeEntry(
"Orientation",(
int)orientation());
169 conf->writeEntry(
"ViewToolBar",((TDEToggleAction*)m_actions->action(
"view_toolbar"))->isChecked());
170 conf->writeEntry(
"ViewMenuBar",
static_cast<TDEToggleAction*
>( m_actions->action(
"view_menubar") )->isChecked());
171 conf->writeEntry(
"ViewPrinterInfos",((TDEToggleAction*)m_actions->action(
"view_printerinfos"))->isChecked());
175 void KMMainView::initActions()
177 TDEIconSelectAction *vact =
new TDEIconSelectAction(i18n(
"&View"),0,m_actions,
"view_change");
178 TQStringList iconlst;
179 iconlst <<
"view_icon" <<
"view_detailed" <<
"view_tree";
180 vact->setItems(TQStringList::split(
',',i18n(
"&Icons,&List,&Tree"),
false), iconlst);
181 vact->setCurrentItem(0);
182 connect(vact,TQ_SIGNAL(activated(
int)),TQ_SLOT(slotChangeView(
int)));
184 TDEActionMenu *stateAct =
new TDEActionMenu(i18n(
"Start/Stop Printer"),
"tdeprint_printstate", m_actions,
"printer_state_change");
185 stateAct->setDelayed(
false);
186 stateAct->insert(
new TDEAction(i18n(
"&Start Printer"),
"tdeprint_enableprinter",0,
this,TQ_SLOT(slotChangePrinterState()),m_actions,
"printer_start"));
187 stateAct->insert(
new TDEAction(i18n(
"Sto&p Printer"),
"tdeprint_stopprinter",0,
this,TQ_SLOT(slotChangePrinterState()),m_actions,
"printer_stop"));
189 stateAct =
new TDEActionMenu(i18n(
"Enable/Disable Job Spooling"),
"tdeprint_queuestate", m_actions,
"printer_spool_change");
190 stateAct->setDelayed(
false);
191 stateAct->insert(
new TDEAction(i18n(
"&Enable Job Spooling"),
"tdeprint_enableprinter",0,
this,TQ_SLOT(slotChangePrinterState()),m_actions,
"printer_enable"));
192 stateAct->insert(
new TDEAction(i18n(
"&Disable Job Spooling"),
"tdeprint_stopprinter",0,
this,TQ_SLOT(slotChangePrinterState()),m_actions,
"printer_disable"));
194 new TDEAction(i18n(
"&Remove"),
"edittrash",0,
this,TQ_SLOT(slotRemove()),m_actions,
"printer_remove");
195 new TDEAction(i18n(
"&Configure..."),
"configure",0,
this,TQ_SLOT(slotConfigure()),m_actions,
"printer_configure");
196 new TDEAction(i18n(
"Add &Printer/Class..."),
"tdeprint_addprinter",0,
this,TQ_SLOT(slotAdd()),m_actions,
"printer_add");
197 new TDEAction(i18n(
"Add &Special (pseudo) Printer..."),
"tdeprint_addpseudo",0,
this,TQ_SLOT(slotAddSpecial()),m_actions,
"printer_add_special");
198 new TDEAction(i18n(
"Set as &Local Default"),
"tdeprint_defaulthard",0,
this,TQ_SLOT(slotHardDefault()),m_actions,
"printer_hard_default");
199 new TDEAction(i18n(
"Set as &User Default"),
"tdeprint_defaultsoft",0,
this,TQ_SLOT(slotSoftDefault()),m_actions,
"printer_soft_default");
200 new TDEAction(i18n(
"&Test Printer..."),
"tdeprint_testprinter",0,
this,TQ_SLOT(slotTest()),m_actions,
"printer_test");
201 new TDEAction(i18n(
"Configure &Manager..."),
"tdeprint_configmgr",0,
this,TQ_SLOT(slotManagerConfigure()),m_actions,
"manager_configure");
202 new TDEAction(i18n(
"Initialize Manager/&View"),
"reload",0,
this,TQ_SLOT(slotInit()),m_actions,
"view_refresh");
204 TDEIconSelectAction *dact =
new TDEIconSelectAction(i18n(
"&Orientation"),0,m_actions,
"orientation_change");
206 iconlst <<
"view_top_bottom" <<
"view_left_right";
207 dact->setItems(TQStringList::split(
',',i18n(
"&Vertical,&Horizontal"),
false), iconlst);
208 dact->setCurrentItem(0);
209 connect(dact,TQ_SIGNAL(activated(
int)),TQ_SLOT(slotChangeDirection(
int)));
211 new TDEAction(i18n(
"R&estart Server"),
"tdeprint_restartsrv",0,
this,TQ_SLOT(slotServerRestart()),m_actions,
"server_restart");
212 new TDEAction(i18n(
"Configure &Server..."),
"tdeprint_configsrv",0,
this,TQ_SLOT(slotServerConfigure()),m_actions,
"server_configure");
213 new TDEAction(i18n(
"Configure Server Access..."),
"tdeprint_configsrv",0,
this,TQ_SLOT(slotServerConfigureAccess()),m_actions,
"server_access_configure");
215 TDEToggleAction *tact =
new TDEToggleAction(i18n(
"Show &Toolbar"),0,m_actions,
"view_toolbar");
216 tact->setCheckedState(i18n(
"Hide &Toolbar"));
217 connect(tact,TQ_SIGNAL(toggled(
bool)),TQ_SLOT(slotToggleToolBar(
bool)));
218 tact =
new TDEToggleAction( i18n(
"Show Me&nu Toolbar" ), 0, m_actions,
"view_menubar" );
219 tact->setCheckedState(i18n(
"Hide Me&nu Toolbar"));
220 connect( tact, TQ_SIGNAL( toggled(
bool ) ), TQ_SLOT( slotToggleMenuBar(
bool ) ) );
221 tact =
new TDEToggleAction(i18n(
"Show Pr&inter Details"),
"tdeprint_printer_infos", 0,m_actions,
"view_printerinfos");
222 tact->setCheckedState(KGuiItem(i18n(
"Hide Pr&inter Details"),
"tdeprint_printer_infos"));
223 tact->setChecked(
true);
224 connect(tact,TQ_SIGNAL(toggled(
bool)),TQ_SLOT(slotShowPrinterInfos(
bool)));
226 tact =
new TDEToggleAction(i18n(
"Toggle Printer &Filtering"),
"filter", 0, m_actions,
"view_pfilter");
227 tact->setChecked(KMManager::self()->isFilterEnabled());
228 connect(tact, TQ_SIGNAL(toggled(
bool)), TQ_SLOT(slotToggleFilter(
bool)));
230 TDEActionMenu *mact =
new TDEActionMenu(i18n(
"Pri&nter Tools"),
"applications-utilities", m_actions,
"printer_tool");
231 mact->setDelayed(
false);
232 connect(mact->popupMenu(), TQ_SIGNAL(activated(
int)), TQ_SLOT(slotToolSelected(
int)));
233 TQStringList files = TDEGlobal::dirs()->findAllResources(
"data",
"tdeprint/tools/*.desktop");
234 for (TQStringList::ConstIterator it=files.begin(); it!=files.end(); ++it)
236 KSimpleConfig conf(*it);
237 conf.setGroup(
"Desktop Entry");
238 mact->popupMenu()->insertItem(conf.readEntry(
"Name",
"Unnamed"), mact->popupMenu()->count());
239 m_toollist << conf.readEntry(
"X-TDE-Library");
243 m_actions->action(
"printer_add")->plug(m_toolbar);
244 m_actions->action(
"printer_add_special")->plug(m_toolbar);
245 m_toolbar->insertLineSeparator();
246 m_actions->action(
"printer_state_change")->plug(m_toolbar);
247 m_actions->action(
"printer_spool_change")->plug(m_toolbar);
248 m_toolbar->insertSeparator();
249 m_actions->action(
"printer_hard_default")->plug(m_toolbar);
250 m_actions->action(
"printer_soft_default")->plug(m_toolbar);
251 m_actions->action(
"printer_remove")->plug(m_toolbar);
252 m_toolbar->insertSeparator();
253 m_actions->action(
"printer_configure")->plug(m_toolbar);
254 m_actions->action(
"printer_test")->plug(m_toolbar);
255 m_actions->action(
"printer_tool")->plug(m_toolbar);
256 m_pactionsindex = m_toolbar->insertSeparator();
257 m_toolbar->insertLineSeparator();
258 m_actions->action(
"server_restart")->plug(m_toolbar);
259 m_actions->action(
"server_configure")->plug(m_toolbar);
260 m_toolbar->insertLineSeparator();
261 m_actions->action(
"manager_configure")->plug(m_toolbar);
262 m_actions->action(
"view_refresh")->plug(m_toolbar);
263 m_toolbar->insertLineSeparator();
264 m_actions->action(
"view_printerinfos")->plug(m_toolbar);
265 m_actions->action(
"view_change")->plug(m_toolbar);
266 m_actions->action(
"orientation_change")->plug(m_toolbar);
267 m_actions->action(
"view_pfilter")->plug(m_toolbar);
270 TQPopupMenu *menu =
new TQPopupMenu(
this );
271 m_actions->action(
"printer_add" )->plug( menu );
272 m_actions->action(
"printer_add_special" )->plug( menu );
274 m_menubar->insertButton(
"wizard", 0,
true, i18n(
"Add" ) );
275 m_menubar->getButton( 0 )->setPopup( menu,
true );
276 menu =
new TQPopupMenu(
this );
277 m_actions->action(
"printer_state_change")->plug( menu );
278 m_actions->action(
"printer_spool_change")->plug( menu );
279 menu->insertSeparator();
280 m_actions->action(
"printer_hard_default")->plug( menu );
281 m_actions->action(
"printer_soft_default")->plug( menu );
282 m_actions->action(
"printer_remove")->plug( menu );
283 menu->insertSeparator();
284 m_actions->action(
"printer_configure")->plug( menu );
285 m_actions->action(
"printer_test")->plug( menu );
286 m_actions->action(
"printer_tool")->plug( menu );
287 menu->insertSeparator();
289 m_menubar->insertButton(
"printer", 1,
true, i18n(
"Printer" ) );
290 m_menubar->getButton( 1 )->setPopup( menu,
true );
291 menu =
new TQPopupMenu(
this );
292 m_actions->action(
"server_restart")->plug( menu );
293 m_actions->action(
"server_configure")->plug( menu );
295 m_menubar->insertButton(
"misc", 2,
true, i18n(
"Print Server" ) );
296 m_menubar->getButton( 2 )->setPopup( menu,
true );
297 menu =
new TQPopupMenu(
this );
298 m_actions->action(
"manager_configure")->plug( menu );
299 m_actions->action(
"view_refresh")->plug( menu );
301 m_menubar->insertButton(
"tdeprint_configmgr", 3,
true, i18n(
"Print Manager" ) );
302 m_menubar->getButton( 3 )->setPopup( menu,
true );
303 menu =
new TQPopupMenu(
this );
304 m_actions->action(
"view_printerinfos")->plug( menu );
305 m_actions->action(
"view_change")->plug( menu );
306 m_actions->action(
"orientation_change")->plug( menu );
307 m_actions->action(
"view_toolbar" )->plug ( menu );
308 m_actions->action(
"view_menubar" )->plug ( menu );
309 menu->insertSeparator();
310 m_actions->action(
"view_pfilter")->plug( menu );
312 m_menubar->insertButton(
"view_remove", 4,
true, i18n(
"View" ) );
313 m_menubar->getButton( 4 )->setPopup( menu,
true );
317 slotPrinterSelected(TQString::null);
320 void KMMainView::slotRefresh()
325 void KMMainView::slotTimer()
327 kdDebug() <<
"KMMainView::slotTimer" << endl;
328 TQPtrList<KMPrinter> *printerlist = m_manager->printerList();
329 bool ok = m_manager->errorMsg().isEmpty();
330 m_printerview->setPrinterList(printerlist);
334 showErrorMsg(i18n(
"An error occurred while retrieving the printer list."));
342 TQPtrListIterator<KMPrinter> it( *printerlist );
343 KMPrinter *p1 = 0, *p2 = 0, *p3 = 0;
344 while ( it.current() )
346 if ( !it.current()->isVirtual() )
348 if ( it.current()->ownSoftDefault() )
353 else if ( it.current()->isHardDefault() )
360 if ( p1 || p2 || p3 )
361 m_printerview->setPrinter( p1 ? p1 : ( p2 ? p2 : p3 ) );
367 void KMMainView::slotPrinterSelected(
const TQString& prname)
369 KMPrinter *p = KMManager::self()->findPrinter(prname);
371 if (p && !p->isSpecial())
372 KMFactory::self()->manager()->completePrinter(p);
373 m_printerpages->setPrinter(p);
379 int mask = (m_manager->hasManagement() ? m_manager->printerOperationMask() : 0);
380 bool sp = !(p && p->isSpecial());
382 m_actions->action(
"printer_remove")->setEnabled(!sp || ((mask & KMManager::PrinterRemoval) && p && !p->isImplicit()));
383 m_actions->action(
"printer_configure")->setEnabled(!sp || ((mask & KMManager::PrinterConfigure) && p && !p->isClass(
true) ));
384 m_actions->action(
"printer_hard_default")->setEnabled((sp && (mask & KMManager::PrinterDefault) && p && !p->isClass(
true) && !p->isHardDefault() && p->isLocal()));
385 m_actions->action(
"printer_soft_default")->setEnabled((p && !p->isSoftDefault()));
386 m_actions->action(
"printer_test")->setEnabled((sp && (mask & KMManager::PrinterTesting) && p && !p->isClass(
true)));
387 bool stmask = (sp && (mask & KMManager::PrinterEnabling) && p);
388 m_actions->action(
"printer_state_change")->setEnabled(stmask && p->isLocal());
389 m_actions->action(
"printer_spool_change")->setEnabled(stmask);
390 m_actions->action(
"printer_start")->setEnabled((stmask && p->state() == KMPrinter::Stopped));
391 m_actions->action(
"printer_stop")->setEnabled((stmask && p->state() != KMPrinter::Stopped));
392 m_actions->action(
"printer_enable")->setEnabled((stmask && !p->acceptJobs()));
393 m_actions->action(
"printer_disable")->setEnabled((stmask && p->acceptJobs()));
395 m_actions->action(
"printer_add")->setEnabled((mask & KMManager::PrinterCreation));
396 mask = m_manager->serverOperationMask();
397 m_actions->action(
"server_restart")->setEnabled((mask & KMManager::ServerRestarting));
398 m_actions->action(
"server_configure")->setEnabled((mask & KMManager::ServerConfigure));
400 KMFactory::self()->manager()->validatePluginActions(m_actions, p);
402 m_actions->action(
"printer_tool")->setEnabled(p && !p->isClass(
true) && !p->isRemote() && !p->isSpecial());
405 void KMMainView::setViewType(
int ID)
407 ((TDESelectAction*)m_actions->action(
"view_change"))->setCurrentItem(ID);
411 int KMMainView::viewType()
const
412 {
return m_printerview->viewType(); }
414 void KMMainView::slotChangeView(
int ID)
416 kdDebug() <<
"KMMainView::slotChangeView" << endl;
417 if (ID >= KMPrinterView::Icons && ID <= KMPrinterView::Tree)
418 m_printerview->setViewType((KMPrinterView::ViewType)ID);
421 void KMMainView::slotRightButtonClicked(
const TQString& prname,
const TQPoint& p)
423 KMPrinter *printer = KMManager::self()->findPrinter(prname);
429 if (!printer->isSpecial())
431 if (printer->isLocal())
432 m_actions->action((printer->state() == KMPrinter::Stopped ?
"printer_start" :
"printer_stop"))->plug(m_pop);
433 m_actions->action((printer->acceptJobs() ?
"printer_disable" :
"printer_enable"))->plug(m_pop);
434 m_pop->insertSeparator();
436 if (!printer->isSoftDefault()) m_actions->action(
"printer_soft_default")->plug(m_pop);
437 if (printer->isLocal() && !printer->isImplicit())
439 if (!printer->isHardDefault()) m_actions->action(
"printer_hard_default")->plug(m_pop);
440 m_actions->action(
"printer_remove")->plug(m_pop);
441 m_pop->insertSeparator();
442 if (!printer->isClass(
true))
444 m_actions->action(
"printer_configure")->plug(m_pop);
445 m_actions->action(
"printer_test")->plug(m_pop);
446 m_actions->action(
"printer_tool")->plug(m_pop);
447 m_pop->insertSeparator();
452 m_actions->action(
"printer_remove")->plug(m_pop);
453 m_pop->insertSeparator();
454 if (!printer->isClass(
true))
456 m_actions->action(
"printer_configure")->plug(m_pop);
457 m_actions->action(
"printer_test")->plug(m_pop);
459 m_pop->insertSeparator();
461 if (!printer->isSpecial())
463 TQValueList<TDEAction*> pactions = m_actions->actions(
"plugin");
464 for (TQValueList<TDEAction*>::Iterator it=pactions.begin(); it!=pactions.end(); ++it)
466 if (pactions.count() > 0)
467 m_pop->insertSeparator();
472 m_actions->action(
"printer_add")->plug(m_pop);
473 m_actions->action(
"printer_add_special")->plug(m_pop);
474 m_pop->insertSeparator();
475 m_actions->action(
"server_restart")->plug(m_pop);
476 m_actions->action(
"server_configure")->plug(m_pop);
477 m_pop->insertSeparator();
478 m_actions->action(
"manager_configure")->plug(m_pop);
479 m_actions->action(
"view_refresh")->plug(m_pop);
480 m_pop->insertSeparator();
482 m_actions->action(
"view_printerinfos")->plug(m_pop);
483 m_actions->action(
"view_change")->plug(m_pop);
484 m_actions->action(
"orientation_change")->plug(m_pop);
485 m_actions->action(
"view_toolbar")->plug(m_pop);
486 m_actions->action(
"view_menubar")->plug(m_pop);
487 m_pop->insertSeparator();
488 m_actions->action(
"view_pfilter")->plug(m_pop);
494 void KMMainView::slotChangePrinterState()
496 TQString opname = sender()->name();
497 if (m_current && opname.startsWith(
"printer_"))
499 opname = opname.mid(8);
500 KMTimer::self()->hold();
502 if (opname ==
"enable")
503 result = m_manager->enablePrinter(m_current,
true);
504 else if (opname ==
"disable")
505 result = m_manager->enablePrinter(m_current,
false);
506 else if (opname ==
"start")
507 result = m_manager->startPrinter(m_current,
true);
508 else if (opname ==
"stop")
509 result = m_manager->startPrinter(m_current,
false);
511 showErrorMsg(i18n(
"Unable to modify the state of printer %1.").arg(m_current->printerName()));
512 KMTimer::self()->release(result);
516 void KMMainView::slotRemove()
520 KMTimer::self()->hold();
522 if (KMessageBox::warningYesNo(
this,i18n(
"Do you really want to remove %1?").arg(m_current->printerName())) == KMessageBox::Yes)
523 if (m_current->isSpecial())
525 if (!(result=m_manager->removeSpecialPrinter(m_current)))
526 showErrorMsg(i18n(
"Unable to remove special printer %1.").arg(m_current->printerName()));
528 else if (!(result=m_manager->removePrinter(m_current)))
529 showErrorMsg(i18n(
"Unable to remove printer %1.").arg(m_current->printerName()));
530 KMTimer::self()->release(result);
534 void KMMainView::slotConfigure()
538 KMTimer::self()->hold();
539 bool needRefresh(
false);
540 if (m_current->isSpecial())
542 KMSpecialPrinterDlg dlg(
this);
543 dlg.setPrinter(m_current);
546 KMPrinter *prt = dlg.printer();
547 if (prt->name() != m_current->name())
548 m_manager->removeSpecialPrinter(m_current);
549 m_manager->createSpecialPrinter(prt);
555 DrMain *driver = m_manager->loadPrinterDriver(m_current,
true);
558 KMDriverDialog dlg(
this);
559 dlg.setCaption(i18n(
"Configure %1").arg(m_current->printerName()));
560 dlg.setDriver(driver);
562 if (m_current->isRemote())
563 dlg.enableButtonOK(
false);
565 if (!m_manager->savePrinterDriver(m_current,driver))
566 showErrorMsg(i18n(
"Unable to modify settings of printer %1.").arg(m_current->printerName()));
570 showErrorMsg(i18n(
"Unable to load a valid driver for printer %1.").arg(m_current->printerName()));
572 KMTimer::self()->release(needRefresh);
576 void KMMainView::slotAdd()
578 KMTimer::self()->hold();
581 if ((result=tdeprint_management_add_printer_wizard(
this)) == -1)
582 showErrorMsg(i18n(
"Unable to create printer."));
584 KMTimer::self()->release((result == 1));
587 void KMMainView::slotHardDefault()
591 KMTimer::self()->hold();
592 bool result = m_manager->setDefaultPrinter(m_current);
594 showErrorMsg(i18n(
"Unable to define printer %1 as default.").arg(m_current->printerName()));
595 KMTimer::self()->release(result);
599 void KMMainView::slotSoftDefault()
603 KMTimer::self()->hold();
604 KMFactory::self()->virtualManager()->setAsDefault(m_current,TQString::null);
605 KMTimer::self()->release(
true);
609 void KMMainView::setOrientation(
int o)
611 int ID = (o == TQt::Horizontal ? 1 : 0);
612 ((TDESelectAction*)m_actions->action(
"orientation_change"))->setCurrentItem(ID);
613 slotChangeDirection(ID);
616 int KMMainView::orientation()
const
617 {
return (m_boxlayout->direction() == TQBoxLayout::LeftToRight ? TQt::Horizontal : TQt::Vertical); }
619 void KMMainView::slotChangeDirection(
int d)
621 m_boxlayout->setDirection(d == 1 ? TQBoxLayout::LeftToRight : TQBoxLayout::TopToBottom);
624 void KMMainView::slotTest()
628 KMTimer::self()->hold();
629 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)
631 if (KMFactory::self()->manager()->testPrinter(m_current))
632 KMessageBox::information(
this,i18n(
"Test page successfully sent to printer %1.").arg(m_current->printerName()));
634 showErrorMsg(i18n(
"Unable to test printer %1.").arg(m_current->printerName()));
636 KMTimer::self()->release(
true);
640 void KMMainView::showErrorMsg(
const TQString& msg,
bool usemgr)
647 s += i18n(
"Error message received from manager:</p><p>%1</p>");
648 if (m_manager->errorMsg().isEmpty())
649 s = s.arg(i18n(
"Internal error (no error message)."));
651 s = s.arg(m_manager->errorMsg());
653 m_manager->setErrorMsg(TQString::null);
655 s.prepend(
"<qt>").append(
"</qt>");
656 KMTimer::self()->hold();
657 KMessageBox::error(
this,s);
658 KMTimer::self()->release();
661 void KMMainView::slotServerRestart()
663 KMTimer::self()->hold();
664 bool result = m_manager->restartServer();
667 showErrorMsg(i18n(
"Unable to restart print server."));
668 KMTimer::self()->release(
false );
672 reset( i18n(
"Restarting server..." ),
false,
false );
676 void KMMainView::slotServerConfigure()
678 KMTimer::self()->hold();
679 bool result = m_manager->configureServer(
this);
682 showErrorMsg(i18n(
"Unable to configure print server."));
683 KMTimer::self()->release(
false );
687 reset( i18n(
"Configuring server..." ),
false,
false );
691 void KMMainView::slotServerConfigureAccess()
693 TDEProcess *proc =
new TDEProcess;
694 *proc <<
"/usr/bin/system-config-printer-kde";
695 proc->start(TDEProcess::DontCare);
698 void KMMainView::slotToggleToolBar(
bool on)
700 if (on) m_toolbar->show();
701 else m_toolbar->hide();
704 void KMMainView::slotToggleMenuBar(
bool on )
712 void KMMainView::slotManagerConfigure()
714 KMTimer::self()->hold();
715 KMConfigDialog dlg(
this,
"ConfigDialog");
726 KMTimer::self()->release(
false );
729 void KMMainView::slotAddSpecial()
731 KMTimer::self()->hold();
732 KMSpecialPrinterDlg dlg(
this);
735 KMPrinter *prt = dlg.printer();
736 m_manager->createSpecialPrinter(prt);
738 KMTimer::self()->release(
true);
741 void KMMainView::slotShowPrinterInfos(
bool on)
744 m_printerpages->show();
746 m_printerpages->hide();
747 m_actions->action(
"orientation_change")->setEnabled(on);
750 void KMMainView::enableToolbar(
bool on)
752 TDEToggleAction *act = (TDEToggleAction*)m_actions->action(
"view_toolbar");
753 m_toolbar->setEnabled(on);
755 if (on && act->isChecked())
761 TDEAction* KMMainView::action(
const char *name)
763 return m_actions->action(name);
773 void KMMainView::reload()
775 removePluginActions();
779 connect( m_manager, TQ_SIGNAL( updatePossible(
bool ) ), TQ_SLOT( slotUpdatePossible(
bool ) ) );
783 reset( i18n(
"Initializing manager..." ),
true,
true );
786 void KMMainView::showPrinterInfos(
bool on)
788 static_cast<TDEToggleAction*
>(m_actions->action(
"view_printerinfos"))->setChecked(on);
789 slotShowPrinterInfos(on);
792 bool KMMainView::printerInfosShown()
const
794 return (
static_cast<TDEToggleAction*
>(m_actions->action(
"view_printerinfos"))->isChecked());
797 void KMMainView::loadPluginActions()
799 KMFactory::self()->manager()->createPluginActions(m_actions);
800 TQValueList<TDEAction*> pactions = m_actions->actions(
"plugin");
801 int index = m_pactionsindex;
803 TQPopupMenu *menu = m_menubar->getButton( 1 )->popup();
804 for (TQValueList<TDEAction*>::Iterator it=pactions.begin(); it!=pactions.end(); ++it)
806 (*it)->plug(m_toolbar, index++);
807 ( *it )->plug( menu );
811 void KMMainView::removePluginActions()
813 TQValueList<TDEAction*> pactions = m_actions->actions(
"plugin");
814 for (TQValueList<TDEAction*>::Iterator it=pactions.begin(); it!=pactions.end(); ++it)
821 void KMMainView::slotToolSelected(
int ID)
823 KMTimer::self()->hold();
825 TQString libname = m_toollist[ID];
826 libname.prepend(
"tdeprint_tool_");
827 if (m_current && !m_current->device().isEmpty() && !libname.isEmpty())
829 KLibFactory *factory = KLibLoader::self()->factory(libname.local8Bit());
833 args << m_current->device() << m_current->printerName();
834 KDialogBase *dlg =
static_cast<KDialogBase*
>(factory->create(
this,
"Tool", 0, args));
841 KMessageBox::error(
this,
842 i18n(
"Unable to start printer tool. Possible reasons are: "
843 "no printer selected, the selected printer doesn't have "
844 "any local device defined (printer port), or the tool library "
845 "could not be found."));
847 KMTimer::self()->release();
850 void KMMainView::slotToggleFilter(
bool on)
852 KMTimer::self()->hold();
853 KMManager::self()->enableFilter(on);
854 KMTimer::self()->release(
true);
857 void KMMainView::configChanged()
859 reset( i18n(
"Initializing manager..." ),
false,
true );
862 void KMMainView::slotUpdatePossible(
bool flag )
864 destroyMessageWindow();
866 showErrorMsg( i18n(
"Unable to retrieve the printer list." ) );
867 KMTimer::self()->release(
true );
870 void KMMainView::createMessageWindow(
const TQString& txt,
int delay )
872 destroyMessageWindow();
873 MessageWindow::add( m_printerview, txt, delay );
876 void KMMainView::destroyMessageWindow()
878 MessageWindow::remove( m_printerview );
881 void KMMainView::slotInit()
883 reset( i18n(
"Initializing manager..." ),
true,
true );
886 void KMMainView::reset(
const TQString& msg,
bool useDelay,
bool holdTimer )
889 KMTimer::self()->hold();
890 m_printerview->setPrinterList( 0 );
891 if ( !msg.isEmpty() )
892 createMessageWindow( msg, ( useDelay ? 500 : 0 ) );
894 m_manager->checkUpdatePossible();
897 #include "kmmainview.moc"