• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeprint
 

tdeprint

  • tdeprint
  • management
kmmainview.cpp
1/*
2 * This file is part of the KDE libraries
3 * Copyright (c) 2001 Michael Goffioul <tdeprint@swing.be>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License version 2 as published by the Free Software Foundation.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 **/
19
20#include "kmmainview.h"
21#include "kmtimer.h"
22#include "kmprinterview.h"
23#include "kmpages.h"
24#include "kmmanager.h"
25#include "kmuimanager.h"
26#include "kmfactory.h"
27#include "kmvirtualmanager.h"
28#include "kmprinter.h"
29#include "driver.h"
30#include "kmdriverdialog.h"
31#include "kmwizard.h"
32#include "kmconfigdialog.h"
33#include "kmspecialprinterdlg.h"
34#include "plugincombobox.h"
35#include "kiconselectaction.h"
36#include "messagewindow.h"
37
38#include <tqdockarea.h>
39#include <tdemenubar.h>
40#include <tqtimer.h>
41#include <tqcombobox.h>
42#include <tqlabel.h>
43#include <tqlayout.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>
51#include <kdebug.h>
52#include <tdepopupmenu.h>
53#include <klibloader.h>
54#include <kdialogbase.h>
55#include <ksimpleconfig.h>
56#include <tdestandarddirs.h>
57#include <tdeapplication.h>
58#include <tdeprocess.h>
59
60#undef m_manager
61#define m_manager KMFactory::self()->manager()
62
63int tdeprint_management_add_printer_wizard( TQWidget* parent )
64{
65 KMWizard dlg(parent);
66 int flag(0);
67 if (dlg.exec())
68 {
69 flag = 1;
70 // check if the printer already exists, and ask confirmation if needed.
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)
73 flag = 0;
74 // try to add printer only if flag is true.
75 if (flag && !KMFactory::self()->manager()->createPrinter(dlg.printer()))
76 flag = -1;
77 }
78 return flag;
79}
80
81KMMainView::KMMainView(TQWidget *parent, const char *name, TDEActionCollection *coll)
82: TQWidget(parent, name)
83{
84 m_current = 0;
85 m_first = true;
86
87 // create widgets
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");
94 /*
95 m_menubar = new KMenuBar( this );
96 static_cast<KMenuBar*>( m_menubar )->setTopLevelMenu( false );
97 */
98 m_menubar = new TDEToolBar( this, "MenuBar", false, false );
99 m_menubar->setIconText( TDEToolBar::IconTextRight );
100 m_menubar->setMovingEnabled( false );
101
102 // layout
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);
112
113 // connections
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 ) ) );
120
121 // actions
122 if (coll)
123 m_actions = coll;
124 else
125 m_actions = new TDEActionCollection(this);
126 initActions();
127
128 // first update
129 restoreSettings();
130 loadParameters();
131
132 // delay first update until KMManager is ready
133 reset( i18n( "Initializing manager..." ), true, true );
134}
135
136KMMainView::~KMMainView()
137{
138 saveSettings();
139 //KMFactory::release();
140}
141
142void KMMainView::loadParameters()
143{
144}
145
146void KMMainView::restoreSettings()
147{
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);
161}
162
163void KMMainView::saveSettings()
164{
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());
172 conf->sync();
173}
174
175void KMMainView::initActions()
176{
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)));
183
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"));
188
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"));
193
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");
203
204 TDEIconSelectAction *dact = new TDEIconSelectAction(i18n("&Orientation"),0,m_actions,"orientation_change");
205 iconlst.clear();
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)));
210
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");
214
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)));
225
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)));
229
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)
235 {
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");
240 }
241
242 // add actions to the toolbar
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);
268
269 // add actions to the menu bar
270 TQPopupMenu *menu = new TQPopupMenu( this );
271 m_actions->action( "printer_add" )->plug( menu );
272 m_actions->action( "printer_add_special" )->plug( menu );
273 //m_menubar->insertItem( i18n( "Add" ), 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();
288 //m_menubar->insertItem( i18n( "Printer" ), menu );
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 );
294 //m_menubar->insertItem( i18n( "Server" ), 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 );
300 //m_menubar->insertItem( i18n( "Manager" ), 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 );
311 //m_menubar->insertItem( i18n( "View" ), menu );
312 m_menubar->insertButton( "view_remove", 4, true, i18n( "View" ) );
313 m_menubar->getButton( 4 )->setPopup( menu, true );
314 //m_menubar->setMinimumHeight( m_menubar->heightForWidth( 1000 ) );
315
316 loadPluginActions();
317 slotPrinterSelected(TQString::null);
318}
319
320void KMMainView::slotRefresh()
321{
322 // TODO: remove me
323}
324
325void KMMainView::slotTimer()
326{
327 kdDebug() << "KMMainView::slotTimer" << endl;
328 TQPtrList<KMPrinter> *printerlist = m_manager->printerList();
329 bool ok = m_manager->errorMsg().isEmpty();
330 m_printerview->setPrinterList(printerlist);
331 if ( m_first )
332 {
333 if ( !ok )
334 showErrorMsg(i18n("An error occurred while retrieving the printer list."));
335 else
336 {
337 /* try to select the most appropriate printer:
338 * - soft default owner printer
339 * - hard default printer
340 * - first printer
341 */
342 TQPtrListIterator<KMPrinter> it( *printerlist );
343 KMPrinter *p1 = 0, *p2 = 0, *p3 = 0;
344 while ( it.current() )
345 {
346 if ( !it.current()->isVirtual() )
347 {
348 if ( it.current()->ownSoftDefault() )
349 {
350 p1 = it.current();
351 break;
352 }
353 else if ( it.current()->isHardDefault() )
354 p2 = it.current();
355 else if ( !p3 )
356 p3 = it.current();
357 }
358 ++it;
359 }
360 if ( p1 || p2 || p3 )
361 m_printerview->setPrinter( p1 ? p1 : ( p2 ? p2 : p3 ) );
362 }
363 m_first = false;
364 }
365}
366
367void KMMainView::slotPrinterSelected(const TQString& prname)
368{
369 KMPrinter *p = KMManager::self()->findPrinter(prname);
370 m_current = p;
371 if (p && !p->isSpecial())
372 KMFactory::self()->manager()->completePrinter(p);
373 m_printerpages->setPrinter(p);
374
375 // update actions state (only if toolbar enabled, workaround for toolbar
376 // problem).
377 //if (m_toolbar->isEnabled())
378 //{
379 int mask = (m_manager->hasManagement() ? m_manager->printerOperationMask() : 0);
380 bool sp = !(p && p->isSpecial());
381// m_actions->action("printer_remove")->setEnabled(!sp || ((mask & KMManager::PrinterRemoval) && p && p->isLocal() && !p->isImplicit()));
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) /*&& p->isLocal()*/));
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()));
394
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));
399
400 KMFactory::self()->manager()->validatePluginActions(m_actions, p);
401 //}
402 m_actions->action("printer_tool")->setEnabled(p && !p->isClass(true) && !p->isRemote() && !p->isSpecial());
403}
404
405void KMMainView::setViewType(int ID)
406{
407 ((TDESelectAction*)m_actions->action("view_change"))->setCurrentItem(ID);
408 slotChangeView(ID);
409}
410
411int KMMainView::viewType() const
412{ return m_printerview->viewType(); }
413
414void KMMainView::slotChangeView(int ID)
415{
416 kdDebug() << "KMMainView::slotChangeView" << endl;
417 if (ID >= KMPrinterView::Icons && ID <= KMPrinterView::Tree)
418 m_printerview->setViewType((KMPrinterView::ViewType)ID);
419}
420
421void KMMainView::slotRightButtonClicked(const TQString& prname, const TQPoint& p)
422{
423 KMPrinter *printer = KMManager::self()->findPrinter(prname);
424 // construct popup menu
425 m_pop->clear();
426 if (printer)
427 {
428 m_current = printer;
429 if (!printer->isSpecial())
430 {
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();
435 }
436 if (!printer->isSoftDefault()) m_actions->action("printer_soft_default")->plug(m_pop);
437 if (printer->isLocal() && !printer->isImplicit())
438 {
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))
443 {
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();
448 }
449 }
450 else
451 {
452 m_actions->action("printer_remove")->plug(m_pop);
453 m_pop->insertSeparator();
454 if (!printer->isClass(true))
455 {
456 m_actions->action("printer_configure")->plug(m_pop);
457 m_actions->action("printer_test")->plug(m_pop);
458 }
459 m_pop->insertSeparator();
460 }
461 if (!printer->isSpecial())
462 {
463 TQValueList<TDEAction*> pactions = m_actions->actions("plugin");
464 for (TQValueList<TDEAction*>::Iterator it=pactions.begin(); it!=pactions.end(); ++it)
465 (*it)->plug(m_pop);
466 if (pactions.count() > 0)
467 m_pop->insertSeparator();
468 }
469 }
470 else
471 {
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();
481 }
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);
489
490 // pop the menu
491 m_pop->popup(p);
492}
493
494void KMMainView::slotChangePrinterState()
495{
496 TQString opname = sender()->name();
497 if (m_current && opname.startsWith("printer_"))
498 {
499 opname = opname.mid(8);
500 KMTimer::self()->hold();
501 bool result(false);
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);
510 if (!result)
511 showErrorMsg(i18n("Unable to modify the state of printer %1.").arg(m_current->printerName()));
512 KMTimer::self()->release(result);
513 }
514}
515
516void KMMainView::slotRemove()
517{
518 if (m_current)
519 {
520 KMTimer::self()->hold();
521 bool result(false);
522 if (KMessageBox::warningYesNo(this,i18n("Do you really want to remove %1?").arg(m_current->printerName())) == KMessageBox::Yes)
523 if (m_current->isSpecial())
524 {
525 if (!(result=m_manager->removeSpecialPrinter(m_current)))
526 showErrorMsg(i18n("Unable to remove special printer %1.").arg(m_current->printerName()));
527 }
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);
531 }
532}
533
534void KMMainView::slotConfigure()
535{
536 if (m_current)
537 {
538 KMTimer::self()->hold();
539 bool needRefresh(false);
540 if (m_current->isSpecial())
541 {
542 KMSpecialPrinterDlg dlg(this);
543 dlg.setPrinter(m_current);
544 if (dlg.exec())
545 {
546 KMPrinter *prt = dlg.printer();
547 if (prt->name() != m_current->name())
548 m_manager->removeSpecialPrinter(m_current);
549 m_manager->createSpecialPrinter(prt);
550 needRefresh = true;
551 }
552 }
553 else
554 {
555 DrMain *driver = m_manager->loadPrinterDriver(m_current, true);
556 if (driver)
557 {
558 KMDriverDialog dlg(this);
559 dlg.setCaption(i18n("Configure %1").arg(m_current->printerName()));
560 dlg.setDriver(driver);
561 // disable OK button for remote printer (read-only dialog)
562 if (m_current->isRemote())
563 dlg.enableButtonOK(false);
564 if (dlg.exec())
565 if (!m_manager->savePrinterDriver(m_current,driver))
566 showErrorMsg(i18n("Unable to modify settings of printer %1.").arg(m_current->printerName()));
567 delete driver;
568 }
569 else
570 showErrorMsg(i18n("Unable to load a valid driver for printer %1.").arg(m_current->printerName()));
571 }
572 KMTimer::self()->release(needRefresh);
573 }
574}
575
576void KMMainView::slotAdd()
577{
578 KMTimer::self()->hold();
579
580 int result(0);
581 if ((result=tdeprint_management_add_printer_wizard(this)) == -1)
582 showErrorMsg(i18n("Unable to create printer."));
583
584 KMTimer::self()->release((result == 1));
585}
586
587void KMMainView::slotHardDefault()
588{
589 if (m_current)
590 {
591 KMTimer::self()->hold();
592 bool result = m_manager->setDefaultPrinter(m_current);
593 if (!result)
594 showErrorMsg(i18n("Unable to define printer %1 as default.").arg(m_current->printerName()));
595 KMTimer::self()->release(result);
596 }
597}
598
599void KMMainView::slotSoftDefault()
600{
601 if (m_current)
602 {
603 KMTimer::self()->hold();
604 KMFactory::self()->virtualManager()->setAsDefault(m_current,TQString::null);
605 KMTimer::self()->release(true);
606 }
607}
608
609void KMMainView::setOrientation(int o)
610{
611 int ID = (o == TQt::Horizontal ? 1 : 0);
612 ((TDESelectAction*)m_actions->action("orientation_change"))->setCurrentItem(ID);
613 slotChangeDirection(ID);
614}
615
616int KMMainView::orientation() const
617{ return (m_boxlayout->direction() == TQBoxLayout::LeftToRight ? TQt::Horizontal : TQt::Vertical); }
618
619void KMMainView::slotChangeDirection(int d)
620{
621 m_boxlayout->setDirection(d == 1 ? TQBoxLayout::LeftToRight : TQBoxLayout::TopToBottom);
622}
623
624void KMMainView::slotTest()
625{
626 if (m_current)
627 {
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)
630 {
631 if (KMFactory::self()->manager()->testPrinter(m_current))
632 KMessageBox::information(this,i18n("Test page successfully sent to printer %1.").arg(m_current->printerName()));
633 else
634 showErrorMsg(i18n("Unable to test printer %1.").arg(m_current->printerName()));
635 }
636 KMTimer::self()->release(true);
637 }
638}
639
640void KMMainView::showErrorMsg(const TQString& msg, bool usemgr)
641{
642 TQString s(msg);
643 if (usemgr)
644 {
645 s.prepend("<p>");
646 s.append(" ");
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)."));
650 else
651 s = s.arg(m_manager->errorMsg());
652 // clean up error message
653 m_manager->setErrorMsg(TQString::null);
654 }
655 s.prepend("<qt>").append("</qt>");
656 KMTimer::self()->hold();
657 KMessageBox::error(this,s);
658 KMTimer::self()->release();
659}
660
661void KMMainView::slotServerRestart()
662{
663 KMTimer::self()->hold();
664 bool result = m_manager->restartServer();
665 if (!result)
666 {
667 showErrorMsg(i18n("Unable to restart print server."));
668 KMTimer::self()->release( false );
669 }
670 else
671 {
672 reset( i18n( "Restarting server..." ), false, false );
673 }
674}
675
676void KMMainView::slotServerConfigure()
677{
678 KMTimer::self()->hold();
679 bool result = m_manager->configureServer(this);
680 if (!result)
681 {
682 showErrorMsg(i18n("Unable to configure print server."));
683 KMTimer::self()->release( false );
684 }
685 else
686 {
687 reset( i18n( "Configuring server..." ), false, false );
688 }
689}
690
691void KMMainView::slotServerConfigureAccess()
692{
693 TDEProcess *proc = new TDEProcess;
694 *proc << "/usr/bin/system-config-printer-kde";
695 proc->start(TDEProcess::DontCare);
696}
697
698void KMMainView::slotToggleToolBar(bool on)
699{
700 if (on) m_toolbar->show();
701 else m_toolbar->hide();
702}
703
704void KMMainView::slotToggleMenuBar( bool on )
705{
706 if ( on )
707 m_menubar->show();
708 else
709 m_menubar->hide();
710}
711
712void KMMainView::slotManagerConfigure()
713{
714 KMTimer::self()->hold();
715 KMConfigDialog dlg(this,"ConfigDialog");
716 if ( dlg.exec() )
717 {
718 loadParameters();
719 }
720 /* when "OK":
721 * => the config file is saved
722 * => triggering a DCOP signal
723 * => configChanged() called
724 * hence no need to refresh, just release the timer
725 */
726 KMTimer::self()->release( false );
727}
728
729void KMMainView::slotAddSpecial()
730{
731 KMTimer::self()->hold();
732 KMSpecialPrinterDlg dlg(this);
733 if (dlg.exec())
734 {
735 KMPrinter *prt = dlg.printer();
736 m_manager->createSpecialPrinter(prt);
737 }
738 KMTimer::self()->release(true);
739}
740
741void KMMainView::slotShowPrinterInfos(bool on)
742{
743 if (on)
744 m_printerpages->show();
745 else
746 m_printerpages->hide();
747 m_actions->action("orientation_change")->setEnabled(on);
748}
749
750void KMMainView::enableToolbar(bool on)
751{
752 TDEToggleAction *act = (TDEToggleAction*)m_actions->action("view_toolbar");
753 m_toolbar->setEnabled(on);
754 act->setEnabled(on);
755 if (on && act->isChecked())
756 m_toolbar->show();
757 else
758 m_toolbar->hide();
759}
760
761TDEAction* KMMainView::action(const char *name)
762{
763 return m_actions->action(name);
764}
765
766/*
767void KMMainView::aboutToReload()
768{
769 m_printerview->setPrinterList(0);
770}
771*/
772
773void KMMainView::reload()
774{
775 removePluginActions();
776 loadPluginActions();
777
778 // redo the connection as the old manager object has been removed
779 connect( m_manager, TQ_SIGNAL( updatePossible( bool ) ), TQ_SLOT( slotUpdatePossible( bool ) ) );
780
781 // We must delay the refresh such that all objects has been
782 // correctly reloaded (otherwise, crash in KMJobViewer).
783 reset( i18n( "Initializing manager..." ), true, true );
784}
785
786void KMMainView::showPrinterInfos(bool on)
787{
788 static_cast<TDEToggleAction*>(m_actions->action("view_printerinfos"))->setChecked(on);
789 slotShowPrinterInfos(on);
790}
791
792bool KMMainView::printerInfosShown() const
793{
794 return (static_cast<TDEToggleAction*>(m_actions->action("view_printerinfos"))->isChecked());
795}
796
797void KMMainView::loadPluginActions()
798{
799 KMFactory::self()->manager()->createPluginActions(m_actions);
800 TQValueList<TDEAction*> pactions = m_actions->actions("plugin");
801 int index = m_pactionsindex;
802 //TQPopupMenu *menu = m_menubar->findItem( m_menubar->idAt( 1 ) )->popup();
803 TQPopupMenu *menu = m_menubar->getButton( 1 )->popup();
804 for (TQValueList<TDEAction*>::Iterator it=pactions.begin(); it!=pactions.end(); ++it)
805 {
806 (*it)->plug(m_toolbar, index++);
807 ( *it )->plug( menu );
808 }
809}
810
811void KMMainView::removePluginActions()
812{
813 TQValueList<TDEAction*> pactions = m_actions->actions("plugin");
814 for (TQValueList<TDEAction*>::Iterator it=pactions.begin(); it!=pactions.end(); ++it)
815 {
816 (*it)->unplugAll();
817 delete (*it);
818 }
819}
820
821void KMMainView::slotToolSelected(int ID)
822{
823 KMTimer::self()->hold();
824
825 TQString libname = m_toollist[ID];
826 libname.prepend("tdeprint_tool_");
827 if (m_current && !m_current->device().isEmpty() && !libname.isEmpty())
828 {
829 KLibFactory *factory = KLibLoader::self()->factory(libname.local8Bit());
830 if (factory)
831 {
832 TQStringList args;
833 args << m_current->device() << m_current->printerName();
834 KDialogBase *dlg = static_cast<KDialogBase*>(factory->create(this, "Tool", 0, args));
835 if (dlg)
836 dlg->exec();
837 delete dlg;
838 }
839 }
840 else
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."));
846
847 KMTimer::self()->release();
848}
849
850void KMMainView::slotToggleFilter(bool on)
851{
852 KMTimer::self()->hold();
853 KMManager::self()->enableFilter(on);
854 KMTimer::self()->release(true);
855}
856
857void KMMainView::configChanged()
858{
859 reset( i18n( "Initializing manager..." ), false, true );
860}
861
862void KMMainView::slotUpdatePossible( bool flag )
863{
864 destroyMessageWindow();
865 if ( !flag )
866 showErrorMsg( i18n( "Unable to retrieve the printer list." ) );
867 KMTimer::self()->release( true );
868}
869
870void KMMainView::createMessageWindow( const TQString& txt, int delay )
871{
872 destroyMessageWindow();
873 MessageWindow::add( m_printerview, txt, delay );
874}
875
876void KMMainView::destroyMessageWindow()
877{
878 MessageWindow::remove( m_printerview );
879}
880
881void KMMainView::slotInit()
882{
883 reset( i18n( "Initializing manager..." ), true, true );
884}
885
886void KMMainView::reset( const TQString& msg, bool useDelay, bool holdTimer )
887{
888 if ( holdTimer )
889 KMTimer::self()->hold();
890 m_printerview->setPrinterList( 0 );
891 if ( !msg.isEmpty() )
892 createMessageWindow( msg, ( useDelay ? 500 : 0 ) );
893 m_first = true;
894 m_manager->checkUpdatePossible();
895}
896
897#include "kmmainview.moc"

tdeprint

Skip menu "tdeprint"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

tdeprint

Skip menu "tdeprint"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeprint by doxygen 1.9.4
This website is maintained by Timothy Pearson.