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

kdeprint

  • kdeprint
  • management
kmmainview.cpp
1 /*
2  * This file is part of the KDE libraries
3  * Copyright (c) 2001 Michael Goffioul <kdeprint@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 <kmenubar.h>
40 #include <tqtimer.h>
41 #include <tqcombobox.h>
42 #include <tqlabel.h>
43 #include <tqlayout.h>
44 #include <tqpopupmenu.h>
45 #include <kmessagebox.h>
46 #include <kaction.h>
47 #include <klocale.h>
48 #include <kconfig.h>
49 #include <ktoolbar.h>
50 #include <ktoolbarbutton.h>
51 #include <kdebug.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>
58 #include <kprocess.h>
59 
60 #undef m_manager
61 #define m_manager KMFactory::self()->manager()
62 
63 int kdeprint_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 
81 KMMainView::KMMainView(TQWidget *parent, const char *name, KActionCollection *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 KToolBar(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 KToolBar( this, "MenuBar", false, false );
99  m_menubar->setIconText( KToolBar::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(),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 ) ) );
120 
121  // actions
122  if (coll)
123  m_actions = coll;
124  else
125  m_actions = new KActionCollection(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 
136 KMMainView::~KMMainView()
137 {
138  saveSettings();
139  //KMFactory::release();
140 }
141 
142 void KMMainView::loadParameters()
143 {
144 }
145 
146 void KMMainView::restoreSettings()
147 {
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);
161 }
162 
163 void KMMainView::saveSettings()
164 {
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());
172  conf->sync();
173 }
174 
175 void KMMainView::initActions()
176 {
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)));
183 
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"));
188 
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"));
193 
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");
203 
204  KIconSelectAction *dact = new KIconSelectAction(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,TQT_SIGNAL(activated(int)),TQT_SLOT(slotChangeDirection(int)));
210 
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");
214 
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)));
225 
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)));
229 
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" );
232 
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)
238  {
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");
243  }
244 
245  // add actions to the toolbar
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);
271 
272  // add actions to the menu bar
273  TQPopupMenu *menu = new TQPopupMenu( this );
274  m_actions->action( "printer_add" )->plug( menu );
275  m_actions->action( "printer_add_special" )->plug( menu );
276  //m_menubar->insertItem( i18n( "Add" ), 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();
291  //m_menubar->insertItem( i18n( "Printer" ), menu );
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 );
297  //m_menubar->insertItem( i18n( "Server" ), 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 );
303  //m_menubar->insertItem( i18n( "Manager" ), 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 );
314  //m_menubar->insertItem( i18n( "View" ), menu );
315  m_menubar->insertButton( "view_remove", 4, true, i18n( "View" ) );
316  m_menubar->getButton( 4 )->setPopup( menu, true );
317  //m_menubar->setMinimumHeight( m_menubar->heightForWidth( 1000 ) );
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 );
323 
324  loadPluginActions();
325  slotPrinterSelected(TQString::null);
326 }
327 
328 void KMMainView::slotRefresh()
329 {
330  // TODO: remove me
331 }
332 
333 void KMMainView::slotTimer()
334 {
335  kdDebug() << "KMMainView::slotTimer" << endl;
336  TQPtrList<KMPrinter> *printerlist = m_manager->printerList();
337  bool ok = m_manager->errorMsg().isEmpty();
338  m_printerview->setPrinterList(printerlist);
339  if ( m_first )
340  {
341  if ( !ok )
342  showErrorMsg(i18n("An error occurred while retrieving the printer list."));
343  else
344  {
345  /* try to select the most appropriate printer:
346  * - soft default owner printer
347  * - hard default printer
348  * - first printer
349  */
350  TQPtrListIterator<KMPrinter> it( *printerlist );
351  KMPrinter *p1 = 0, *p2 = 0, *p3 = 0;
352  while ( it.current() )
353  {
354  if ( !it.current()->isVirtual() )
355  {
356  if ( it.current()->ownSoftDefault() )
357  {
358  p1 = it.current();
359  break;
360  }
361  else if ( it.current()->isHardDefault() )
362  p2 = it.current();
363  else if ( !p3 )
364  p3 = it.current();
365  }
366  ++it;
367  }
368  if ( p1 || p2 || p3 )
369  m_printerview->setPrinter( p1 ? p1 : ( p2 ? p2 : p3 ) );
370  }
371  m_first = false;
372  }
373 }
374 
375 void KMMainView::slotPrinterSelected(const TQString& prname)
376 {
377  KMPrinter *p = KMManager::self()->findPrinter(prname);
378  m_current = p;
379  if (p && !p->isSpecial())
380  KMFactory::self()->manager()->completePrinter(p);
381  m_printerpages->setPrinter(p);
382 
383  // update actions state (only if toolbar enabled, workaround for toolbar
384  // problem).
385  //if (m_toolbar->isEnabled())
386  //{
387  int mask = (m_manager->hasManagement() ? m_manager->printerOperationMask() : 0);
388  bool sp = !(p && p->isSpecial());
389 // m_actions->action("printer_remove")->setEnabled(!sp || ((mask & KMManager::PrinterRemoval) && p && p->isLocal() && !p->isImplicit()));
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) /*&& p->isLocal()*/));
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()));
402 
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));
407 
408  KMFactory::self()->manager()->validatePluginActions(m_actions, p);
409  //}
410  m_actions->action("printer_tool")->setEnabled(p && !p->isClass(true) && !p->isRemote() && !p->isSpecial());
411 }
412 
413 void KMMainView::setViewType(int ID)
414 {
415  ((KSelectAction*)m_actions->action("view_change"))->setCurrentItem(ID);
416  slotChangeView(ID);
417 }
418 
419 int KMMainView::viewType() const
420 { return m_printerview->viewType(); }
421 
422 void KMMainView::slotChangeView(int ID)
423 {
424  kdDebug() << "KMMainView::slotChangeView" << endl;
425  if (ID >= KMPrinterView::Icons && ID <= KMPrinterView::Tree)
426  m_printerview->setViewType((KMPrinterView::ViewType)ID);
427 }
428 
429 void KMMainView::slotRightButtonClicked(const TQString& prname, const TQPoint& p)
430 {
431  KMPrinter *printer = KMManager::self()->findPrinter(prname);
432  // construct popup menu
433  m_pop->clear();
434  if (printer)
435  {
436  m_current = printer;
437  if (!printer->isSpecial())
438  {
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();
443  }
444  if (!printer->isSoftDefault()) m_actions->action("printer_soft_default")->plug(m_pop);
445  if (printer->isLocal() && !printer->isImplicit())
446  {
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))
451  {
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();
456  }
457  }
458  else
459  {
460  m_actions->action("printer_remove")->plug(m_pop);
461  m_pop->insertSeparator();
462  if (!printer->isClass(true))
463  {
464  m_actions->action("printer_configure")->plug(m_pop);
465  m_actions->action("printer_test")->plug(m_pop);
466  }
467  m_pop->insertSeparator();
468  }
469  if (!printer->isSpecial())
470  {
471  TQValueList<KAction*> pactions = m_actions->actions("plugin");
472  for (TQValueList<KAction*>::Iterator it=pactions.begin(); it!=pactions.end(); ++it)
473  (*it)->plug(m_pop);
474  if (pactions.count() > 0)
475  m_pop->insertSeparator();
476  }
477  }
478  else
479  {
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();
489  }
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);
497 
498  // pop the menu
499  m_pop->popup(p);
500 }
501 
502 void KMMainView::slotChangePrinterState()
503 {
504  TQString opname = TQT_TQOBJECT_CONST(sender())->name();
505  if (m_current && opname.startsWith("printer_"))
506  {
507  opname = opname.mid(8);
508  KMTimer::self()->hold();
509  bool result(false);
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);
518  if (!result)
519  showErrorMsg(i18n("Unable to modify the state of printer %1.").arg(m_current->printerName()));
520  KMTimer::self()->release(result);
521  }
522 }
523 
524 void KMMainView::slotRemove()
525 {
526  if (m_current)
527  {
528  KMTimer::self()->hold();
529  bool result(false);
530  if (KMessageBox::warningYesNo(this,i18n("Do you really want to remove %1?").arg(m_current->printerName())) == KMessageBox::Yes)
531  if (m_current->isSpecial())
532  {
533  if (!(result=m_manager->removeSpecialPrinter(m_current)))
534  showErrorMsg(i18n("Unable to remove special printer %1.").arg(m_current->printerName()));
535  }
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);
539  }
540 }
541 
542 void KMMainView::slotConfigure()
543 {
544  if (m_current)
545  {
546  KMTimer::self()->hold();
547  bool needRefresh(false);
548  if (m_current->isSpecial())
549  {
550  KMSpecialPrinterDlg dlg(this);
551  dlg.setPrinter(m_current);
552  if (dlg.exec())
553  {
554  KMPrinter *prt = dlg.printer();
555  if (prt->name() != m_current->name())
556  m_manager->removeSpecialPrinter(m_current);
557  m_manager->createSpecialPrinter(prt);
558  needRefresh = true;
559  }
560  }
561  else
562  {
563  DrMain *driver = m_manager->loadPrinterDriver(m_current, true);
564  if (driver)
565  {
566  KMDriverDialog dlg(this);
567  dlg.setCaption(i18n("Configure %1").arg(m_current->printerName()));
568  dlg.setDriver(driver);
569  // disable OK button for remote printer (read-only dialog)
570  if (m_current->isRemote())
571  dlg.enableButtonOK(false);
572  if (dlg.exec())
573  if (!m_manager->savePrinterDriver(m_current,driver))
574  showErrorMsg(i18n("Unable to modify settings of printer %1.").arg(m_current->printerName()));
575  delete driver;
576  }
577  else
578  showErrorMsg(i18n("Unable to load a valid driver for printer %1.").arg(m_current->printerName()));
579  }
580  KMTimer::self()->release(needRefresh);
581  }
582 }
583 
584 void KMMainView::slotAdd()
585 {
586  KMTimer::self()->hold();
587 
588  int result(0);
589  if ((result=kdeprint_management_add_printer_wizard(this)) == -1)
590  showErrorMsg(i18n("Unable to create printer."));
591 
592  KMTimer::self()->release((result == 1));
593 }
594 
595 void KMMainView::slotHardDefault()
596 {
597  if (m_current)
598  {
599  KMTimer::self()->hold();
600  bool result = m_manager->setDefaultPrinter(m_current);
601  if (!result)
602  showErrorMsg(i18n("Unable to define printer %1 as default.").arg(m_current->printerName()));
603  KMTimer::self()->release(result);
604  }
605 }
606 
607 void KMMainView::slotSoftDefault()
608 {
609  if (m_current)
610  {
611  KMTimer::self()->hold();
612  KMFactory::self()->virtualManager()->setAsDefault(m_current,TQString::null);
613  KMTimer::self()->release(true);
614  }
615 }
616 
617 void KMMainView::setOrientation(int o)
618 {
619  int ID = (o == Qt::Horizontal ? 1 : 0);
620  ((KSelectAction*)m_actions->action("orientation_change"))->setCurrentItem(ID);
621  slotChangeDirection(ID);
622 }
623 
624 int KMMainView::orientation() const
625 { return (m_boxlayout->direction() == TQBoxLayout::LeftToRight ? Qt::Horizontal : Qt::Vertical); }
626 
627 void KMMainView::slotChangeDirection(int d)
628 {
629  m_boxlayout->setDirection(d == 1 ? TQBoxLayout::LeftToRight : TQBoxLayout::TopToBottom);
630 }
631 
632 void KMMainView::slotTest()
633 {
634  if (m_current)
635  {
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)
638  {
639  if (KMFactory::self()->manager()->testPrinter(m_current))
640  KMessageBox::information(this,i18n("Test page successfully sent to printer %1.").arg(m_current->printerName()));
641  else
642  showErrorMsg(i18n("Unable to test printer %1.").arg(m_current->printerName()));
643  }
644  KMTimer::self()->release(true);
645  }
646 }
647 
648 void KMMainView::showErrorMsg(const TQString& msg, bool usemgr)
649 {
650  TQString s(msg);
651  if (usemgr)
652  {
653  s.prepend("<p>");
654  s.append(" ");
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)."));
658  else
659  s = s.arg(m_manager->errorMsg());
660  // clean up error message
661  m_manager->setErrorMsg(TQString::null);
662  }
663  s.prepend("<qt>").append("</qt>");
664  KMTimer::self()->hold();
665  KMessageBox::error(this,s);
666  KMTimer::self()->release();
667 }
668 
669 void KMMainView::slotServerRestart()
670 {
671  KMTimer::self()->hold();
672  bool result = m_manager->restartServer();
673  if (!result)
674  {
675  showErrorMsg(i18n("Unable to restart print server."));
676  KMTimer::self()->release( false );
677  }
678  else
679  {
680  reset( i18n( "Restarting server..." ), false, false );
681  }
682 }
683 
684 void KMMainView::slotServerConfigure()
685 {
686  KMTimer::self()->hold();
687  bool result = m_manager->configureServer(this);
688  if (!result)
689  {
690  showErrorMsg(i18n("Unable to configure print server."));
691  KMTimer::self()->release( false );
692  }
693  else
694  {
695  reset( i18n( "Configuring server..." ), false, false );
696  }
697 }
698 
699 void KMMainView::slotServerConfigureAccess()
700 {
701  KProcess *proc = new KProcess;
702  *proc << "/usr/bin/system-config-printer-kde";
703  proc->start(KProcess::DontCare);
704 }
705 
706 void KMMainView::slotToggleToolBar(bool on)
707 {
708  if (on) m_toolbar->show();
709  else m_toolbar->hide();
710 }
711 
712 void KMMainView::slotToggleMenuBar( bool on )
713 {
714  if ( on )
715  m_menubar->show();
716  else
717  m_menubar->hide();
718 }
719 
720 void KMMainView::slotManagerConfigure()
721 {
722  KMTimer::self()->hold();
723  KMConfigDialog dlg(this,"ConfigDialog");
724  if ( dlg.exec() )
725  {
726  loadParameters();
727  }
728  /* when "OK":
729  * => the config file is saved
730  * => triggering a DCOP signal
731  * => configChanged() called
732  * hence no need to refresh, just release the timer
733  */
734  KMTimer::self()->release( false );
735 }
736 
737 void KMMainView::slotAddSpecial()
738 {
739  KMTimer::self()->hold();
740  KMSpecialPrinterDlg dlg(this);
741  if (dlg.exec())
742  {
743  KMPrinter *prt = dlg.printer();
744  m_manager->createSpecialPrinter(prt);
745  }
746  KMTimer::self()->release(true);
747 }
748 
749 void KMMainView::slotShowPrinterInfos(bool on)
750 {
751  if (on)
752  m_printerpages->show();
753  else
754  m_printerpages->hide();
755  m_actions->action("orientation_change")->setEnabled(on);
756 }
757 
758 void KMMainView::enableToolbar(bool on)
759 {
760  KToggleAction *act = (KToggleAction*)m_actions->action("view_toolbar");
761  m_toolbar->setEnabled(on);
762  act->setEnabled(on);
763  if (on && act->isChecked())
764  m_toolbar->show();
765  else
766  m_toolbar->hide();
767 }
768 
769 KAction* KMMainView::action(const char *name)
770 {
771  return m_actions->action(name);
772 }
773 
774 /*
775 void KMMainView::aboutToReload()
776 {
777  m_printerview->setPrinterList(0);
778 }
779 */
780 
781 void KMMainView::reload()
782 {
783  removePluginActions();
784  loadPluginActions();
785 
786  // redo the connection as the old manager object has been removed
787  connect( m_manager, TQT_SIGNAL( updatePossible( bool ) ), TQT_SLOT( slotUpdatePossible( bool ) ) );
788 
789  // We must delay the refresh such that all objects has been
790  // correctly reloaded (otherwise, crash in KMJobViewer).
791  reset( i18n( "Initializing manager..." ), true, true );
792 }
793 
794 void KMMainView::showPrinterInfos(bool on)
795 {
796  static_cast<KToggleAction*>(m_actions->action("view_printerinfos"))->setChecked(on);
797  slotShowPrinterInfos(on);
798 }
799 
800 bool KMMainView::printerInfosShown() const
801 {
802  return (static_cast<KToggleAction*>(m_actions->action("view_printerinfos"))->isChecked());
803 }
804 
805 void KMMainView::loadPluginActions()
806 {
807  KMFactory::self()->manager()->createPluginActions(m_actions);
808  TQValueList<KAction*> pactions = m_actions->actions("plugin");
809  int index = m_pactionsindex;
810  //TQPopupMenu *menu = m_menubar->findItem( m_menubar->idAt( 1 ) )->popup();
811  TQPopupMenu *menu = m_menubar->getButton( 1 )->popup();
812  for (TQValueList<KAction*>::Iterator it=pactions.begin(); it!=pactions.end(); ++it)
813  {
814  (*it)->plug(m_toolbar, index++);
815  ( *it )->plug( menu );
816  }
817 }
818 
819 void KMMainView::removePluginActions()
820 {
821  TQValueList<KAction*> pactions = m_actions->actions("plugin");
822  for (TQValueList<KAction*>::Iterator it=pactions.begin(); it!=pactions.end(); ++it)
823  {
824  (*it)->unplugAll();
825  delete (*it);
826  }
827 }
828 
829 void KMMainView::slotToolSelected(int ID)
830 {
831  KMTimer::self()->hold();
832 
833  TQString libname = m_toollist[ID];
834  libname.prepend("kdeprint_tool_");
835  if (m_current && !m_current->device().isEmpty() && !libname.isEmpty())
836  {
837  KLibFactory *factory = KLibLoader::self()->factory(libname.local8Bit());
838  if (factory)
839  {
840  TQStringList args;
841  args << m_current->device() << m_current->printerName();
842  KDialogBase *dlg = static_cast<KDialogBase*>(TQT_TQWIDGET(factory->create(TQT_TQOBJECT(this), "Tool", 0, args)));
843  if (dlg)
844  dlg->exec();
845  delete dlg;
846  }
847  }
848  else
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."));
854 
855  KMTimer::self()->release();
856 }
857 
858 void KMMainView::slotToggleFilter(bool on)
859 {
860  KMTimer::self()->hold();
861  KMManager::self()->enableFilter(on);
862  KMTimer::self()->release(true);
863 }
864 
865 void KMMainView::configChanged()
866 {
867  reset( i18n( "Initializing manager..." ), false, true );
868 }
869 
870 void KMMainView::slotUpdatePossible( bool flag )
871 {
872  destroyMessageWindow();
873  if ( !flag )
874  showErrorMsg( i18n( "Unable to retrieve the printer list." ) );
875  KMTimer::self()->release( true );
876 }
877 
878 void KMMainView::createMessageWindow( const TQString& txt, int delay )
879 {
880  destroyMessageWindow();
881  MessageWindow::add( m_printerview, txt, delay );
882 }
883 
884 void KMMainView::destroyMessageWindow()
885 {
886  MessageWindow::remove( m_printerview );
887 }
888 
889 void KMMainView::slotInit()
890 {
891  reset( i18n( "Initializing manager..." ), true, true );
892 }
893 
894 void KMMainView::reset( const TQString& msg, bool useDelay, bool holdTimer )
895 {
896  if ( holdTimer )
897  KMTimer::self()->hold();
898  m_printerview->setPrinterList( 0 );
899  if ( !msg.isEmpty() )
900  createMessageWindow( msg, ( useDelay ? 500 : 0 ) );
901  m_first = true;
902  m_manager->checkUpdatePossible();
903 }
904 
905 void KMMainView::slotHelp()
906 {
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" )
911  {
912  TQStringList args;
913  args << "exec" << "http://printing.kde.org";
914  kapp->kdeinitExec( "kfmclient", args );
915  }
916  else
917  kdDebug( 500 ) << "Unknown help invokator: " << s << endl;
918 }
919 
920 #include "kmmainview.moc"

kdeprint

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

kdeprint

Skip menu "kdeprint"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kdeprint by doxygen 1.8.3.1
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |