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>
41 #include <tqcombobox.h>
44 #include <tqpopupmenu.h>
45 #include <kmessagebox.h>
50 #include <ktoolbarbutton.h>
52 #include <kpopupmenu.h>
53 #include <klibloader.h>
54 #include <kdialogbase.h>
55 #include <ksimpleconfig.h>
56 #include <kstandarddirs.h>
57 #include <kapplication.h>
61 #define m_manager KMFactory::self()->manager()
63 int kdeprint_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, KActionCollection *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 KToolBar(
this,
"ToolBar");
92 m_toolbar->setMovingEnabled(
false);
93 m_plugin =
new PluginComboBox(
this,
"Plugin");
98 m_menubar =
new KToolBar(
this,
"MenuBar",
false,
false );
99 m_menubar->setIconText( KToolBar::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(),TQT_SIGNAL(timeout()),TQT_SLOT(slotTimer()));
115 connect(m_printerview,TQT_SIGNAL(printerSelected(
const TQString&)),TQT_SLOT(slotPrinterSelected(
const TQString&)));
116 connect(m_printerview,TQT_SIGNAL(rightButtonClicked(
const TQString&,
const TQPoint&)),TQT_SLOT(slotRightButtonClicked(
const TQString&,
const TQPoint&)));
117 connect(m_pop,TQT_SIGNAL(aboutToShow()),KMTimer::self(),TQT_SLOT(hold()));
118 connect(m_pop,TQT_SIGNAL(aboutToHide()),KMTimer::self(),TQT_SLOT(release()));
119 connect( m_manager, TQT_SIGNAL( updatePossible(
bool ) ), TQT_SLOT( slotUpdatePossible(
bool ) ) );
125 m_actions =
new KActionCollection(
this);
133 reset( i18n(
"Initializing manager..." ),
true,
true );
136 KMMainView::~KMMainView()
142 void KMMainView::loadParameters()
146 void KMMainView::restoreSettings()
148 KConfig *conf = KMFactory::self()->printConfig();
149 conf->setGroup(
"General");
150 setViewType((KMPrinterView::ViewType)conf->readNumEntry(
"ViewType",KMPrinterView::Icons));
151 setOrientation(conf->readNumEntry(
"Orientation", Qt::Vertical));
152 bool view = conf->readBoolEntry(
"ViewToolBar",
false);
153 slotToggleToolBar(view);
154 ((KToggleAction*)m_actions->action(
"view_toolbar"))->setChecked(view);
155 view = conf->readBoolEntry(
"ViewMenuBar",
true );
156 slotToggleMenuBar( view );
157 static_cast<KToggleAction*
>( m_actions->action(
"view_menubar" ) )->setChecked( view );
158 view = conf->readBoolEntry(
"ViewPrinterInfos",
true);
159 slotShowPrinterInfos(view);
160 ((KToggleAction*)m_actions->action(
"view_printerinfos"))->setChecked(view);
163 void KMMainView::saveSettings()
165 KConfig *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",((KToggleAction*)m_actions->action(
"view_toolbar"))->isChecked());
170 conf->writeEntry(
"ViewMenuBar",static_cast<KToggleAction*>( m_actions->action(
"view_menubar") )->isChecked());
171 conf->writeEntry(
"ViewPrinterInfos",((KToggleAction*)m_actions->action(
"view_printerinfos"))->isChecked());
175 void KMMainView::initActions()
177 KIconSelectAction *vact =
new KIconSelectAction(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,TQT_SIGNAL(activated(
int)),TQT_SLOT(slotChangeView(
int)));
184 KActionMenu *stateAct =
new KActionMenu(i18n(
"Start/Stop Printer"),
"kdeprint_printstate", m_actions,
"printer_state_change");
185 stateAct->setDelayed(
false);
186 stateAct->insert(
new KAction(i18n(
"&Start Printer"),
"kdeprint_enableprinter",0,TQT_TQOBJECT(
this),TQT_SLOT(slotChangePrinterState()),m_actions,
"printer_start"));
187 stateAct->insert(
new KAction(i18n(
"Sto&p Printer"),
"kdeprint_stopprinter",0,TQT_TQOBJECT(
this),TQT_SLOT(slotChangePrinterState()),m_actions,
"printer_stop"));
189 stateAct =
new KActionMenu(i18n(
"Enable/Disable Job Spooling"),
"kdeprint_queuestate", m_actions,
"printer_spool_change");
190 stateAct->setDelayed(
false);
191 stateAct->insert(
new KAction(i18n(
"&Enable Job Spooling"),
"kdeprint_enableprinter",0,TQT_TQOBJECT(
this),TQT_SLOT(slotChangePrinterState()),m_actions,
"printer_enable"));
192 stateAct->insert(
new KAction(i18n(
"&Disable Job Spooling"),
"kdeprint_stopprinter",0,TQT_TQOBJECT(
this),TQT_SLOT(slotChangePrinterState()),m_actions,
"printer_disable"));
194 new KAction(i18n(
"&Remove"),
"edittrash",0,TQT_TQOBJECT(
this),TQT_SLOT(slotRemove()),m_actions,
"printer_remove");
195 new KAction(i18n(
"&Configure..."),
"configure",0,TQT_TQOBJECT(
this),TQT_SLOT(slotConfigure()),m_actions,
"printer_configure");
196 new KAction(i18n(
"Add &Printer/Class..."),
"kdeprint_addprinter",0,TQT_TQOBJECT(
this),TQT_SLOT(slotAdd()),m_actions,
"printer_add");
197 new KAction(i18n(
"Add &Special (pseudo) Printer..."),
"kdeprint_addpseudo",0,TQT_TQOBJECT(
this),TQT_SLOT(slotAddSpecial()),m_actions,
"printer_add_special");
198 new KAction(i18n(
"Set as &Local Default"),
"kdeprint_defaulthard",0,TQT_TQOBJECT(
this),TQT_SLOT(slotHardDefault()),m_actions,
"printer_hard_default");
199 new KAction(i18n(
"Set as &User Default"),
"kdeprint_defaultsoft",0,TQT_TQOBJECT(
this),TQT_SLOT(slotSoftDefault()),m_actions,
"printer_soft_default");
200 new KAction(i18n(
"&Test Printer..."),
"kdeprint_testprinter",0,TQT_TQOBJECT(
this),TQT_SLOT(slotTest()),m_actions,
"printer_test");
201 new KAction(i18n(
"Configure &Manager..."),
"kdeprint_configmgr",0,TQT_TQOBJECT(
this),TQT_SLOT(slotManagerConfigure()),m_actions,
"manager_configure");
202 new KAction(i18n(
"Initialize Manager/&View"),
"reload",0,TQT_TQOBJECT(
this),TQT_SLOT(slotInit()),m_actions,
"view_refresh");
204 KIconSelectAction *dact =
new KIconSelectAction(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,TQT_SIGNAL(activated(
int)),TQT_SLOT(slotChangeDirection(
int)));
211 new KAction(i18n(
"R&estart Server"),
"kdeprint_restartsrv",0,TQT_TQOBJECT(
this),TQT_SLOT(slotServerRestart()),m_actions,
"server_restart");
212 new KAction(i18n(
"Configure &Server..."),
"kdeprint_configsrv",0,TQT_TQOBJECT(
this),TQT_SLOT(slotServerConfigure()),m_actions,
"server_configure");
213 new KAction(i18n(
"Configure Server Access..."),
"kdeprint_configsrv",0,TQT_TQOBJECT(
this),TQT_SLOT(slotServerAccessConfigure()),m_actions,
"server_access_configure");
215 KToggleAction *tact =
new KToggleAction(i18n(
"Show &Toolbar"),0,m_actions,
"view_toolbar");
216 tact->setCheckedState(i18n(
"Hide &Toolbar"));
217 connect(tact,TQT_SIGNAL(toggled(
bool)),TQT_SLOT(slotToggleToolBar(
bool)));
218 tact =
new KToggleAction( i18n(
"Show Me&nu Toolbar" ), 0, m_actions,
"view_menubar" );
219 tact->setCheckedState(i18n(
"Hide Me&nu Toolbar"));
220 connect( tact, TQT_SIGNAL( toggled(
bool ) ), TQT_SLOT( slotToggleMenuBar(
bool ) ) );
221 tact =
new KToggleAction(i18n(
"Show Pr&inter Details"),
"kdeprint_printer_infos", 0,m_actions,
"view_printerinfos");
222 tact->setCheckedState(KGuiItem(i18n(
"Hide Pr&inter Details"),
"kdeprint_printer_infos"));
223 tact->setChecked(
true);
224 connect(tact,TQT_SIGNAL(toggled(
bool)),TQT_SLOT(slotShowPrinterInfos(
bool)));
226 tact =
new KToggleAction(i18n(
"Toggle Printer &Filtering"),
"filter", 0, m_actions,
"view_pfilter");
227 tact->setChecked(KMManager::self()->isFilterEnabled());
228 connect(tact, TQT_SIGNAL(toggled(
bool)), TQT_SLOT(slotToggleFilter(
bool)));
230 new KAction( i18n(
"%1 &Handbook" ).arg(
"KDEPrint" ),
"contents", 0, TQT_TQOBJECT(
this), TQT_SLOT( slotHelp() ), m_actions,
"invoke_help" );
231 new KAction( i18n(
"%1 &Web Site" ).arg(
"KDEPrint" ),
"network", 0, TQT_TQOBJECT(
this), TQT_SLOT( slotHelp() ), m_actions,
"invoke_web" );
233 KActionMenu *mact =
new KActionMenu(i18n(
"Pri&nter Tools"),
"package_utilities", m_actions,
"printer_tool");
234 mact->setDelayed(
false);
235 connect(mact->popupMenu(), TQT_SIGNAL(activated(
int)), TQT_SLOT(slotToolSelected(
int)));
236 TQStringList files = KGlobal::dirs()->findAllResources(
"data",
"kdeprint/tools/*.desktop");
237 for (TQStringList::ConstIterator it=files.begin(); it!=files.end(); ++it)
239 KSimpleConfig conf(*it);
240 conf.setGroup(
"Desktop Entry");
241 mact->popupMenu()->insertItem(conf.readEntry(
"Name",
"Unnamed"), mact->popupMenu()->count());
242 m_toollist << conf.readEntry(
"X-KDE-Library");
246 m_actions->action(
"printer_add")->plug(m_toolbar);
247 m_actions->action(
"printer_add_special")->plug(m_toolbar);
248 m_toolbar->insertLineSeparator();
249 m_actions->action(
"printer_state_change")->plug(m_toolbar);
250 m_actions->action(
"printer_spool_change")->plug(m_toolbar);
251 m_toolbar->insertSeparator();
252 m_actions->action(
"printer_hard_default")->plug(m_toolbar);
253 m_actions->action(
"printer_soft_default")->plug(m_toolbar);
254 m_actions->action(
"printer_remove")->plug(m_toolbar);
255 m_toolbar->insertSeparator();
256 m_actions->action(
"printer_configure")->plug(m_toolbar);
257 m_actions->action(
"printer_test")->plug(m_toolbar);
258 m_actions->action(
"printer_tool")->plug(m_toolbar);
259 m_pactionsindex = m_toolbar->insertSeparator();
260 m_toolbar->insertLineSeparator();
261 m_actions->action(
"server_restart")->plug(m_toolbar);
262 m_actions->action(
"server_configure")->plug(m_toolbar);
263 m_toolbar->insertLineSeparator();
264 m_actions->action(
"manager_configure")->plug(m_toolbar);
265 m_actions->action(
"view_refresh")->plug(m_toolbar);
266 m_toolbar->insertLineSeparator();
267 m_actions->action(
"view_printerinfos")->plug(m_toolbar);
268 m_actions->action(
"view_change")->plug(m_toolbar);
269 m_actions->action(
"orientation_change")->plug(m_toolbar);
270 m_actions->action(
"view_pfilter")->plug(m_toolbar);
273 TQPopupMenu *menu =
new TQPopupMenu(
this );
274 m_actions->action(
"printer_add" )->plug( menu );
275 m_actions->action(
"printer_add_special" )->plug( menu );
277 m_menubar->insertButton(
"wizard", 0,
true, i18n(
"Add" ) );
278 m_menubar->getButton( 0 )->setPopup( menu,
true );
279 menu =
new TQPopupMenu(
this );
280 m_actions->action(
"printer_state_change")->plug( menu );
281 m_actions->action(
"printer_spool_change")->plug( menu );
282 menu->insertSeparator();
283 m_actions->action(
"printer_hard_default")->plug( menu );
284 m_actions->action(
"printer_soft_default")->plug( menu );
285 m_actions->action(
"printer_remove")->plug( menu );
286 menu->insertSeparator();
287 m_actions->action(
"printer_configure")->plug( menu );
288 m_actions->action(
"printer_test")->plug( menu );
289 m_actions->action(
"printer_tool")->plug( menu );
290 menu->insertSeparator();
292 m_menubar->insertButton(
"printer1", 1,
true, i18n(
"Printer" ) );
293 m_menubar->getButton( 1 )->setPopup( menu,
true );
294 menu =
new TQPopupMenu(
this );
295 m_actions->action(
"server_restart")->plug( menu );
296 m_actions->action(
"server_configure")->plug( menu );
298 m_menubar->insertButton(
"misc", 2,
true, i18n(
"Print Server" ) );
299 m_menubar->getButton( 2 )->setPopup( menu,
true );
300 menu =
new TQPopupMenu(
this );
301 m_actions->action(
"manager_configure")->plug( menu );
302 m_actions->action(
"view_refresh")->plug( menu );
304 m_menubar->insertButton(
"kdeprint_configmgr", 3,
true, i18n(
"Print Manager" ) );
305 m_menubar->getButton( 3 )->setPopup( menu,
true );
306 menu =
new TQPopupMenu(
this );
307 m_actions->action(
"view_printerinfos")->plug( menu );
308 m_actions->action(
"view_change")->plug( menu );
309 m_actions->action(
"orientation_change")->plug( menu );
310 m_actions->action(
"view_toolbar" )->plug ( menu );
311 m_actions->action(
"view_menubar" )->plug ( menu );
312 menu->insertSeparator();
313 m_actions->action(
"view_pfilter")->plug( menu );
315 m_menubar->insertButton(
"view_remove", 4,
true, i18n(
"View" ) );
316 m_menubar->getButton( 4 )->setPopup( menu,
true );
318 menu =
new TQPopupMenu(
this );
319 m_actions->action(
"invoke_help" )->plug( menu );
320 m_actions->action(
"invoke_web" )->plug( menu );
321 m_menubar->insertButton(
"help", 5,
true, i18n(
"Documentation" ) );
322 m_menubar->getButton( 5 )->setPopup( menu,
true );
325 slotPrinterSelected(TQString::null);
328 void KMMainView::slotRefresh()
333 void KMMainView::slotTimer()
335 kdDebug() <<
"KMMainView::slotTimer" << endl;
336 TQPtrList<KMPrinter> *printerlist = m_manager->printerList();
337 bool ok = m_manager->errorMsg().isEmpty();
338 m_printerview->setPrinterList(printerlist);
342 showErrorMsg(i18n(
"An error occurred while retrieving the printer list."));
350 TQPtrListIterator<KMPrinter> it( *printerlist );
351 KMPrinter *p1 = 0, *p2 = 0, *p3 = 0;
352 while ( it.current() )
354 if ( !it.current()->isVirtual() )
356 if ( it.current()->ownSoftDefault() )
361 else if ( it.current()->isHardDefault() )
368 if ( p1 || p2 || p3 )
369 m_printerview->setPrinter( p1 ? p1 : ( p2 ? p2 : p3 ) );
375 void KMMainView::slotPrinterSelected(
const TQString& prname)
377 KMPrinter *p = KMManager::self()->findPrinter(prname);
379 if (p && !p->isSpecial())
380 KMFactory::self()->manager()->completePrinter(p);
381 m_printerpages->setPrinter(p);
387 int mask = (m_manager->hasManagement() ? m_manager->printerOperationMask() : 0);
388 bool sp = !(p && p->isSpecial());
390 m_actions->action(
"printer_remove")->setEnabled(!sp || ((mask & KMManager::PrinterRemoval) && p && !p->isImplicit()));
391 m_actions->action(
"printer_configure")->setEnabled(!sp || ((mask & KMManager::PrinterConfigure) && p && !p->isClass(
true) ));
392 m_actions->action(
"printer_hard_default")->setEnabled((sp && (mask & KMManager::PrinterDefault) && p && !p->isClass(
true) && !p->isHardDefault() && p->isLocal()));
393 m_actions->action(
"printer_soft_default")->setEnabled((p && !p->isSoftDefault()));
394 m_actions->action(
"printer_test")->setEnabled((sp && (mask & KMManager::PrinterTesting) && p && !p->isClass(
true)));
395 bool stmask = (sp && (mask & KMManager::PrinterEnabling) && p);
396 m_actions->action(
"printer_state_change")->setEnabled(stmask && p->isLocal());
397 m_actions->action(
"printer_spool_change")->setEnabled(stmask);
398 m_actions->action(
"printer_start")->setEnabled((stmask && p->state() == KMPrinter::Stopped));
399 m_actions->action(
"printer_stop")->setEnabled((stmask && p->state() != KMPrinter::Stopped));
400 m_actions->action(
"printer_enable")->setEnabled((stmask && !p->acceptJobs()));
401 m_actions->action(
"printer_disable")->setEnabled((stmask && p->acceptJobs()));
403 m_actions->action(
"printer_add")->setEnabled((mask & KMManager::PrinterCreation));
404 mask = m_manager->serverOperationMask();
405 m_actions->action(
"server_restart")->setEnabled((mask & KMManager::ServerRestarting));
406 m_actions->action(
"server_configure")->setEnabled((mask & KMManager::ServerConfigure));
408 KMFactory::self()->manager()->validatePluginActions(m_actions, p);
410 m_actions->action(
"printer_tool")->setEnabled(p && !p->isClass(
true) && !p->isRemote() && !p->isSpecial());
413 void KMMainView::setViewType(
int ID)
415 ((KSelectAction*)m_actions->action(
"view_change"))->setCurrentItem(ID);
419 int KMMainView::viewType()
const
420 {
return m_printerview->viewType(); }
422 void KMMainView::slotChangeView(
int ID)
424 kdDebug() <<
"KMMainView::slotChangeView" << endl;
425 if (ID >= KMPrinterView::Icons && ID <= KMPrinterView::Tree)
426 m_printerview->setViewType((KMPrinterView::ViewType)ID);
429 void KMMainView::slotRightButtonClicked(
const TQString& prname,
const TQPoint& p)
431 KMPrinter *printer = KMManager::self()->findPrinter(prname);
437 if (!printer->isSpecial())
439 if (printer->isLocal())
440 m_actions->action((printer->state() == KMPrinter::Stopped ?
"printer_start" :
"printer_stop"))->plug(m_pop);
441 m_actions->action((printer->acceptJobs() ?
"printer_disable" :
"printer_enable"))->plug(m_pop);
442 m_pop->insertSeparator();
444 if (!printer->isSoftDefault()) m_actions->action(
"printer_soft_default")->plug(m_pop);
445 if (printer->isLocal() && !printer->isImplicit())
447 if (!printer->isHardDefault()) m_actions->action(
"printer_hard_default")->plug(m_pop);
448 m_actions->action(
"printer_remove")->plug(m_pop);
449 m_pop->insertSeparator();
450 if (!printer->isClass(
true))
452 m_actions->action(
"printer_configure")->plug(m_pop);
453 m_actions->action(
"printer_test")->plug(m_pop);
454 m_actions->action(
"printer_tool")->plug(m_pop);
455 m_pop->insertSeparator();
460 m_actions->action(
"printer_remove")->plug(m_pop);
461 m_pop->insertSeparator();
462 if (!printer->isClass(
true))
464 m_actions->action(
"printer_configure")->plug(m_pop);
465 m_actions->action(
"printer_test")->plug(m_pop);
467 m_pop->insertSeparator();
469 if (!printer->isSpecial())
471 TQValueList<KAction*> pactions = m_actions->actions(
"plugin");
472 for (TQValueList<KAction*>::Iterator it=pactions.begin(); it!=pactions.end(); ++it)
474 if (pactions.count() > 0)
475 m_pop->insertSeparator();
480 m_actions->action(
"printer_add")->plug(m_pop);
481 m_actions->action(
"printer_add_special")->plug(m_pop);
482 m_pop->insertSeparator();
483 m_actions->action(
"server_restart")->plug(m_pop);
484 m_actions->action(
"server_configure")->plug(m_pop);
485 m_pop->insertSeparator();
486 m_actions->action(
"manager_configure")->plug(m_pop);
487 m_actions->action(
"view_refresh")->plug(m_pop);
488 m_pop->insertSeparator();
490 m_actions->action(
"view_printerinfos")->plug(m_pop);
491 m_actions->action(
"view_change")->plug(m_pop);
492 m_actions->action(
"orientation_change")->plug(m_pop);
493 m_actions->action(
"view_toolbar")->plug(m_pop);
494 m_actions->action(
"view_menubar")->plug(m_pop);
495 m_pop->insertSeparator();
496 m_actions->action(
"view_pfilter")->plug(m_pop);
502 void KMMainView::slotChangePrinterState()
504 TQString opname = TQT_TQOBJECT_CONST(sender())->name();
505 if (m_current && opname.startsWith(
"printer_"))
507 opname = opname.mid(8);
508 KMTimer::self()->hold();
510 if (opname ==
"enable")
511 result = m_manager->enablePrinter(m_current,
true);
512 else if (opname ==
"disable")
513 result = m_manager->enablePrinter(m_current,
false);
514 else if (opname ==
"start")
515 result = m_manager->startPrinter(m_current,
true);
516 else if (opname ==
"stop")
517 result = m_manager->startPrinter(m_current,
false);
519 showErrorMsg(i18n(
"Unable to modify the state of printer %1.").arg(m_current->printerName()));
520 KMTimer::self()->release(result);
524 void KMMainView::slotRemove()
528 KMTimer::self()->hold();
530 if (KMessageBox::warningYesNo(
this,i18n(
"Do you really want to remove %1?").arg(m_current->printerName())) == KMessageBox::Yes)
531 if (m_current->isSpecial())
533 if (!(result=m_manager->removeSpecialPrinter(m_current)))
534 showErrorMsg(i18n(
"Unable to remove special printer %1.").arg(m_current->printerName()));
536 else if (!(result=m_manager->removePrinter(m_current)))
537 showErrorMsg(i18n(
"Unable to remove printer %1.").arg(m_current->printerName()));
538 KMTimer::self()->release(result);
542 void KMMainView::slotConfigure()
546 KMTimer::self()->hold();
547 bool needRefresh(
false);
548 if (m_current->isSpecial())
550 KMSpecialPrinterDlg dlg(
this);
551 dlg.setPrinter(m_current);
554 KMPrinter *prt = dlg.printer();
555 if (prt->name() != m_current->name())
556 m_manager->removeSpecialPrinter(m_current);
557 m_manager->createSpecialPrinter(prt);
563 DrMain *driver = m_manager->loadPrinterDriver(m_current,
true);
566 KMDriverDialog dlg(
this);
567 dlg.setCaption(i18n(
"Configure %1").arg(m_current->printerName()));
568 dlg.setDriver(driver);
570 if (m_current->isRemote())
571 dlg.enableButtonOK(
false);
573 if (!m_manager->savePrinterDriver(m_current,driver))
574 showErrorMsg(i18n(
"Unable to modify settings of printer %1.").arg(m_current->printerName()));
578 showErrorMsg(i18n(
"Unable to load a valid driver for printer %1.").arg(m_current->printerName()));
580 KMTimer::self()->release(needRefresh);
584 void KMMainView::slotAdd()
586 KMTimer::self()->hold();
589 if ((result=kdeprint_management_add_printer_wizard(
this)) == -1)
590 showErrorMsg(i18n(
"Unable to create printer."));
592 KMTimer::self()->release((result == 1));
595 void KMMainView::slotHardDefault()
599 KMTimer::self()->hold();
600 bool result = m_manager->setDefaultPrinter(m_current);
602 showErrorMsg(i18n(
"Unable to define printer %1 as default.").arg(m_current->printerName()));
603 KMTimer::self()->release(result);
607 void KMMainView::slotSoftDefault()
611 KMTimer::self()->hold();
612 KMFactory::self()->virtualManager()->setAsDefault(m_current,TQString::null);
613 KMTimer::self()->release(
true);
617 void KMMainView::setOrientation(
int o)
619 int ID = (o == Qt::Horizontal ? 1 : 0);
620 ((KSelectAction*)m_actions->action(
"orientation_change"))->setCurrentItem(ID);
621 slotChangeDirection(ID);
624 int KMMainView::orientation()
const
625 {
return (m_boxlayout->direction() == TQBoxLayout::LeftToRight ? Qt::Horizontal : Qt::Vertical); }
627 void KMMainView::slotChangeDirection(
int d)
629 m_boxlayout->setDirection(d == 1 ? TQBoxLayout::LeftToRight : TQBoxLayout::TopToBottom);
632 void KMMainView::slotTest()
636 KMTimer::self()->hold();
637 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)
639 if (KMFactory::self()->manager()->testPrinter(m_current))
640 KMessageBox::information(
this,i18n(
"Test page successfully sent to printer %1.").arg(m_current->printerName()));
642 showErrorMsg(i18n(
"Unable to test printer %1.").arg(m_current->printerName()));
644 KMTimer::self()->release(
true);
648 void KMMainView::showErrorMsg(
const TQString& msg,
bool usemgr)
655 s += i18n(
"Error message received from manager:</p><p>%1</p>");
656 if (m_manager->errorMsg().isEmpty())
657 s = s.arg(i18n(
"Internal error (no error message)."));
659 s = s.arg(m_manager->errorMsg());
661 m_manager->setErrorMsg(TQString::null);
663 s.prepend(
"<qt>").append(
"</qt>");
664 KMTimer::self()->hold();
665 KMessageBox::error(
this,s);
666 KMTimer::self()->release();
669 void KMMainView::slotServerRestart()
671 KMTimer::self()->hold();
672 bool result = m_manager->restartServer();
675 showErrorMsg(i18n(
"Unable to restart print server."));
676 KMTimer::self()->release(
false );
680 reset( i18n(
"Restarting server..." ),
false,
false );
684 void KMMainView::slotServerConfigure()
686 KMTimer::self()->hold();
687 bool result = m_manager->configureServer(
this);
690 showErrorMsg(i18n(
"Unable to configure print server."));
691 KMTimer::self()->release(
false );
695 reset( i18n(
"Configuring server..." ),
false,
false );
699 void KMMainView::slotServerConfigureAccess()
701 KProcess *proc =
new KProcess;
702 *proc <<
"/usr/bin/system-config-printer-kde";
703 proc->start(KProcess::DontCare);
706 void KMMainView::slotToggleToolBar(
bool on)
708 if (on) m_toolbar->show();
709 else m_toolbar->hide();
712 void KMMainView::slotToggleMenuBar(
bool on )
720 void KMMainView::slotManagerConfigure()
722 KMTimer::self()->hold();
723 KMConfigDialog dlg(
this,
"ConfigDialog");
734 KMTimer::self()->release(
false );
737 void KMMainView::slotAddSpecial()
739 KMTimer::self()->hold();
740 KMSpecialPrinterDlg dlg(
this);
743 KMPrinter *prt = dlg.printer();
744 m_manager->createSpecialPrinter(prt);
746 KMTimer::self()->release(
true);
749 void KMMainView::slotShowPrinterInfos(
bool on)
752 m_printerpages->show();
754 m_printerpages->hide();
755 m_actions->action(
"orientation_change")->setEnabled(on);
758 void KMMainView::enableToolbar(
bool on)
760 KToggleAction *act = (KToggleAction*)m_actions->action(
"view_toolbar");
761 m_toolbar->setEnabled(on);
763 if (on && act->isChecked())
769 KAction* KMMainView::action(
const char *name)
771 return m_actions->action(name);
781 void KMMainView::reload()
783 removePluginActions();
787 connect( m_manager, TQT_SIGNAL( updatePossible(
bool ) ), TQT_SLOT( slotUpdatePossible(
bool ) ) );
791 reset( i18n(
"Initializing manager..." ),
true,
true );
794 void KMMainView::showPrinterInfos(
bool on)
796 static_cast<KToggleAction*
>(m_actions->action(
"view_printerinfos"))->setChecked(on);
797 slotShowPrinterInfos(on);
800 bool KMMainView::printerInfosShown()
const
802 return (static_cast<KToggleAction*>(m_actions->action(
"view_printerinfos"))->isChecked());
805 void KMMainView::loadPluginActions()
807 KMFactory::self()->manager()->createPluginActions(m_actions);
808 TQValueList<KAction*> pactions = m_actions->actions(
"plugin");
809 int index = m_pactionsindex;
811 TQPopupMenu *menu = m_menubar->getButton( 1 )->popup();
812 for (TQValueList<KAction*>::Iterator it=pactions.begin(); it!=pactions.end(); ++it)
814 (*it)->plug(m_toolbar, index++);
815 ( *it )->plug( menu );
819 void KMMainView::removePluginActions()
821 TQValueList<KAction*> pactions = m_actions->actions(
"plugin");
822 for (TQValueList<KAction*>::Iterator it=pactions.begin(); it!=pactions.end(); ++it)
829 void KMMainView::slotToolSelected(
int ID)
831 KMTimer::self()->hold();
833 TQString libname = m_toollist[ID];
834 libname.prepend(
"kdeprint_tool_");
835 if (m_current && !m_current->device().isEmpty() && !libname.isEmpty())
837 KLibFactory *factory = KLibLoader::self()->factory(libname.local8Bit());
841 args << m_current->device() << m_current->printerName();
842 KDialogBase *dlg =
static_cast<KDialogBase*
>(TQT_TQWIDGET(factory->create(TQT_TQOBJECT(
this),
"Tool", 0, args)));
849 KMessageBox::error(
this,
850 i18n(
"Unable to start printer tool. Possible reasons are: "
851 "no printer selected, the selected printer doesn't have "
852 "any local device defined (printer port), or the tool library "
853 "could not be found."));
855 KMTimer::self()->release();
858 void KMMainView::slotToggleFilter(
bool on)
860 KMTimer::self()->hold();
861 KMManager::self()->enableFilter(on);
862 KMTimer::self()->release(
true);
865 void KMMainView::configChanged()
867 reset( i18n(
"Initializing manager..." ),
false,
true );
870 void KMMainView::slotUpdatePossible(
bool flag )
872 destroyMessageWindow();
874 showErrorMsg( i18n(
"Unable to retrieve the printer list." ) );
875 KMTimer::self()->release(
true );
878 void KMMainView::createMessageWindow(
const TQString& txt,
int delay )
880 destroyMessageWindow();
881 MessageWindow::add( m_printerview, txt, delay );
884 void KMMainView::destroyMessageWindow()
886 MessageWindow::remove( m_printerview );
889 void KMMainView::slotInit()
891 reset( i18n(
"Initializing manager..." ),
true,
true );
894 void KMMainView::reset(
const TQString& msg,
bool useDelay,
bool holdTimer )
897 KMTimer::self()->hold();
898 m_printerview->setPrinterList( 0 );
899 if ( !msg.isEmpty() )
900 createMessageWindow( msg, ( useDelay ? 500 : 0 ) );
902 m_manager->checkUpdatePossible();
905 void KMMainView::slotHelp()
907 TQString s = TQT_TQOBJECT_CONST(sender())->name();
908 if ( s ==
"invoke_help" )
909 kapp->invokeHelp( TQString::null,
"kdeprint" );
910 else if ( s ==
"invoke_web" )
913 args <<
"exec" <<
"http://printing.kde.org";
914 kapp->kdeinitExec(
"kfmclient", args );
917 kdDebug( 500 ) <<
"Unknown help invokator: " << s << endl;
920 #include "kmmainview.moc"