• 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 <kstandarddirs.h>
57#include <tdeapplication.h>
58#include <kprocess.h>
59#include <tqfile.h>
60
61#include <stdlib.h>
62#include <sys/wait.h>
63#include <libintl.h>
64
65#undef m_manager
66#define m_manager KMFactory::self()->manager()
67
68int tdeprint_management_add_printer_wizard( TQWidget* parent )
69{
70 KMWizard dlg(parent);
71 int flag(0);
72 if (dlg.exec())
73 {
74 flag = 1;
75 // check if the printer already exists, and ask confirmation if needed.
76 if (KMFactory::self()->manager()->findPrinter(dlg.printer()->name()) != 0)
77 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)
78 flag = 0;
79 // try to add printer only if flag is true.
80 if (flag && !KMFactory::self()->manager()->createPrinter(dlg.printer()))
81 flag = -1;
82 }
83 return flag;
84}
85
86KMMainView::KMMainView(TQWidget *parent, const char *name, TDEActionCollection *coll)
87: TQWidget(parent, name)
88{
89 m_current = 0;
90 m_first = true;
91
92 // create widgets
93 m_printerview = new KMPrinterView(this, "PrinterView");
94 m_printerpages = new KMPages(this, "PrinterPages");
95 m_pop = new TQPopupMenu(this);
96 m_toolbar = new TDEToolBar(this, "ToolBar");
97 m_toolbar->setMovingEnabled(false);
98 m_plugin = new PluginComboBox(this, "Plugin");
99 /*
100 m_menubar = new KMenuBar( this );
101 static_cast<KMenuBar*>( m_menubar )->setTopLevelMenu( false );
102 */
103 m_menubar = new TDEToolBar( this, "MenuBar", false, false );
104 m_menubar->setIconText( TDEToolBar::IconTextRight );
105 m_menubar->setMovingEnabled( false );
106
107 // layout
108 TQVBoxLayout *m_layout = new TQVBoxLayout(this, 0, 0);
109 m_layout->addWidget(m_toolbar);
110 m_layout->addWidget( m_menubar );
111 m_boxlayout = new TQBoxLayout(TQBoxLayout::TopToBottom, 0, 0);
112 m_layout->addLayout(m_boxlayout);
113 m_boxlayout->addWidget(m_printerview);
114 m_boxlayout->addWidget(m_printerpages);
115 m_layout->addSpacing(5);
116 m_layout->addWidget(m_plugin, 0);
117
118 // connections
119 connect(KMTimer::self(),TQ_SIGNAL(timeout()),TQ_SLOT(slotTimer()));
120 connect(m_printerview,TQ_SIGNAL(printerSelected(const TQString&)),TQ_SLOT(slotPrinterSelected(const TQString&)));
121 connect(m_printerview,TQ_SIGNAL(rightButtonClicked(const TQString&,const TQPoint&)),TQ_SLOT(slotRightButtonClicked(const TQString&,const TQPoint&)));
122 connect(m_pop,TQ_SIGNAL(aboutToShow()),KMTimer::self(),TQ_SLOT(hold()));
123 connect(m_pop,TQ_SIGNAL(aboutToHide()),KMTimer::self(),TQ_SLOT(release()));
124 connect( m_manager, TQ_SIGNAL( updatePossible( bool ) ), TQ_SLOT( slotUpdatePossible( bool ) ) );
125
126 // actions
127 if (coll)
128 m_actions = coll;
129 else
130 m_actions = new TDEActionCollection(this);
131 initActions();
132
133 // first update
134 restoreSettings();
135 loadParameters();
136
137 // delay first update until KMManager is ready
138 reset( i18n( "Initializing manager..." ), true, true );
139}
140
141KMMainView::~KMMainView()
142{
143 saveSettings();
144 //KMFactory::release();
145}
146
147void KMMainView::loadParameters()
148{
149}
150
151void KMMainView::restoreSettings()
152{
153 TDEConfig *conf = KMFactory::self()->printConfig();
154 conf->setGroup("General");
155 setViewType((KMPrinterView::ViewType)conf->readNumEntry("ViewType",KMPrinterView::Icons));
156 setOrientation(conf->readNumEntry("Orientation", TQt::Vertical));
157 bool view = conf->readBoolEntry("ViewToolBar",false);
158 slotToggleToolBar(view);
159 ((TDEToggleAction*)m_actions->action("view_toolbar"))->setChecked(view);
160 view = conf->readBoolEntry( "ViewMenuBar", true );
161 slotToggleMenuBar( view );
162 static_cast<TDEToggleAction*>( m_actions->action( "view_menubar" ) )->setChecked( view );
163 view = conf->readBoolEntry("ViewPrinterInfos",true);
164 slotShowPrinterInfos(view);
165 ((TDEToggleAction*)m_actions->action("view_printerinfos"))->setChecked(view);
166}
167
168void KMMainView::saveSettings()
169{
170 TDEConfig *conf = KMFactory::self()->printConfig();
171 conf->setGroup("General");
172 conf->writeEntry("ViewType",(int)m_printerview->viewType());
173 conf->writeEntry("Orientation",(int)orientation());
174 conf->writeEntry("ViewToolBar",((TDEToggleAction*)m_actions->action("view_toolbar"))->isChecked());
175 conf->writeEntry("ViewMenuBar",static_cast<TDEToggleAction*>( m_actions->action("view_menubar") )->isChecked());
176 conf->writeEntry("ViewPrinterInfos",((TDEToggleAction*)m_actions->action("view_printerinfos"))->isChecked());
177 conf->sync();
178}
179
180void KMMainView::initActions()
181{
182 TDEIconSelectAction *vact = new TDEIconSelectAction(i18n("&View"),0,m_actions,"view_change");
183 TQStringList iconlst;
184 iconlst << "view_icon" << "view_detailed" << "view_tree";
185 vact->setItems(TQStringList::split(',',i18n("&Icons,&List,&Tree"),false), iconlst);
186 vact->setCurrentItem(0);
187 connect(vact,TQ_SIGNAL(activated(int)),TQ_SLOT(slotChangeView(int)));
188
189 TDEActionMenu *stateAct = new TDEActionMenu(i18n("Start/Stop Printer"), "tdeprint_printstate", m_actions, "printer_state_change");
190 stateAct->setDelayed(false);
191 stateAct->insert(new TDEAction(i18n("&Start Printer"),"tdeprint_enableprinter",0,this,TQ_SLOT(slotChangePrinterState()),m_actions,"printer_start"));
192 stateAct->insert(new TDEAction(i18n("Sto&p Printer"),"tdeprint_stopprinter",0,this,TQ_SLOT(slotChangePrinterState()),m_actions,"printer_stop"));
193
194 stateAct = new TDEActionMenu(i18n("Enable/Disable Job Spooling"), "tdeprint_queuestate", m_actions, "printer_spool_change");
195 stateAct->setDelayed(false);
196 stateAct->insert(new TDEAction(i18n("&Enable Job Spooling"),"tdeprint_enableprinter",0,this,TQ_SLOT(slotChangePrinterState()),m_actions,"printer_enable"));
197 stateAct->insert(new TDEAction(i18n("&Disable Job Spooling"),"tdeprint_stopprinter",0,this,TQ_SLOT(slotChangePrinterState()),m_actions,"printer_disable"));
198
199 new TDEAction(i18n("&Remove"),"edittrash",0,this,TQ_SLOT(slotRemove()),m_actions,"printer_remove");
200 new TDEAction(i18n("&Configure..."),"configure",0,this,TQ_SLOT(slotConfigure()),m_actions,"printer_configure");
201 new TDEAction(i18n("Add &Printer/Class..."),"tdeprint_addprinter",0,this,TQ_SLOT(slotAdd()),m_actions,"printer_add");
202 new TDEAction(i18n("Add &Special (pseudo) Printer..."),"tdeprint_addpseudo",0,this,TQ_SLOT(slotAddSpecial()),m_actions,"printer_add_special");
203 new TDEAction(i18n("Set as &Local Default"),"tdeprint_defaulthard",0,this,TQ_SLOT(slotHardDefault()),m_actions,"printer_hard_default");
204 new TDEAction(i18n("Set as &User Default"),"tdeprint_defaultsoft",0,this,TQ_SLOT(slotSoftDefault()),m_actions,"printer_soft_default");
205 new TDEAction(i18n("&Test Printer..."),"tdeprint_testprinter",0,this,TQ_SLOT(slotTest()),m_actions,"printer_test");
206 new TDEAction(i18n("Configure &Manager..."),"tdeprint_configmgr",0,this,TQ_SLOT(slotManagerConfigure()),m_actions,"manager_configure");
207 new TDEAction(i18n("Initialize Manager/&View"),"reload",0,this,TQ_SLOT(slotInit()),m_actions,"view_refresh");
208
209 TDEIconSelectAction *dact = new TDEIconSelectAction(i18n("&Orientation"),0,m_actions,"orientation_change");
210 iconlst.clear();
211 iconlst << "view_top_bottom" << "view_left_right";
212 dact->setItems(TQStringList::split(',',i18n("&Vertical,&Horizontal"),false), iconlst);
213 dact->setCurrentItem(0);
214 connect(dact,TQ_SIGNAL(activated(int)),TQ_SLOT(slotChangeDirection(int)));
215
216 new TDEAction(i18n("R&estart Server"),"tdeprint_restartsrv",0,this,TQ_SLOT(slotServerRestart()),m_actions,"server_restart");
217 new TDEAction(i18n("Configure &Server..."),"tdeprint_configsrv",0,this,TQ_SLOT(slotServerConfigure()),m_actions,"server_configure");
218 new TDEAction(i18n("Configure Server Access..."),"tdeprint_configsrv",0,this,TQ_SLOT(slotServerConfigureAccess()),m_actions,"server_access_configure");
219
220 TDEToggleAction *tact = new TDEToggleAction(i18n("Show &Toolbar"),0,m_actions,"view_toolbar");
221 tact->setCheckedState(i18n("Hide &Toolbar"));
222 connect(tact,TQ_SIGNAL(toggled(bool)),TQ_SLOT(slotToggleToolBar(bool)));
223 tact = new TDEToggleAction( i18n( "Show Me&nu Toolbar" ), 0, m_actions, "view_menubar" );
224 tact->setCheckedState(i18n("Hide Me&nu Toolbar"));
225 connect( tact, TQ_SIGNAL( toggled( bool ) ), TQ_SLOT( slotToggleMenuBar( bool ) ) );
226 tact = new TDEToggleAction(i18n("Show Pr&inter Details"),"tdeprint_printer_infos", 0,m_actions,"view_printerinfos");
227 tact->setCheckedState(KGuiItem(i18n("Hide Pr&inter Details"),"tdeprint_printer_infos"));
228 tact->setChecked(true);
229 connect(tact,TQ_SIGNAL(toggled(bool)),TQ_SLOT(slotShowPrinterInfos(bool)));
230
231 tact = new TDEToggleAction(i18n("Toggle Printer &Filtering"), "filter", 0, m_actions, "view_pfilter");
232 tact->setChecked(KMManager::self()->isFilterEnabled());
233 connect(tact, TQ_SIGNAL(toggled(bool)), TQ_SLOT(slotToggleFilter(bool)));
234
235 TDEActionMenu *mact = new TDEActionMenu(i18n("Pri&nter Tools"), "applications-utilities", m_actions, "printer_tool");
236 mact->setDelayed(false);
237 connect(mact->popupMenu(), TQ_SIGNAL(activated(int)), TQ_SLOT(slotToolSelected(int)));
238 TQStringList files = TDEGlobal::dirs()->findAllResources("data", "tdeprint/tools/*.desktop");
239 for (TQStringList::ConstIterator it=files.begin(); it!=files.end(); ++it)
240 {
241 KSimpleConfig conf(*it);
242 conf.setGroup("Desktop Entry");
243 mact->popupMenu()->insertItem(conf.readEntry("Name", "Unnamed"), mact->popupMenu()->count());
244 m_toollist << conf.readEntry("X-TDE-Library");
245 }
246
247 // add actions to the toolbar
248 m_actions->action("printer_add")->plug(m_toolbar);
249 m_actions->action("printer_add_special")->plug(m_toolbar);
250 m_toolbar->insertLineSeparator();
251 m_actions->action("printer_state_change")->plug(m_toolbar);
252 m_actions->action("printer_spool_change")->plug(m_toolbar);
253 m_toolbar->insertSeparator();
254 m_actions->action("printer_hard_default")->plug(m_toolbar);
255 m_actions->action("printer_soft_default")->plug(m_toolbar);
256 m_actions->action("printer_remove")->plug(m_toolbar);
257 m_toolbar->insertSeparator();
258 m_actions->action("printer_configure")->plug(m_toolbar);
259 m_actions->action("printer_test")->plug(m_toolbar);
260 m_actions->action("printer_tool")->plug(m_toolbar);
261 m_pactionsindex = m_toolbar->insertSeparator();
262 m_toolbar->insertLineSeparator();
263 m_actions->action("server_restart")->plug(m_toolbar);
264 m_actions->action("server_configure")->plug(m_toolbar);
265 m_toolbar->insertLineSeparator();
266 m_actions->action("manager_configure")->plug(m_toolbar);
267 m_actions->action("view_refresh")->plug(m_toolbar);
268 m_toolbar->insertLineSeparator();
269 m_actions->action("view_printerinfos")->plug(m_toolbar);
270 m_actions->action("view_change")->plug(m_toolbar);
271 m_actions->action("orientation_change")->plug(m_toolbar);
272 m_actions->action("view_pfilter")->plug(m_toolbar);
273
274 // add actions to the menu bar
275 TQPopupMenu *menu = new TQPopupMenu( this );
276 m_actions->action( "printer_add" )->plug( menu );
277 m_actions->action( "printer_add_special" )->plug( menu );
278 //m_menubar->insertItem( i18n( "Add" ), menu );
279 m_menubar->insertButton( "wizard", 0, true, i18n( "Add" ) );
280 m_menubar->getButton( 0 )->setPopup( menu, true );
281 menu = new TQPopupMenu( this );
282 m_actions->action("printer_state_change")->plug( menu );
283 m_actions->action("printer_spool_change")->plug( menu );
284 menu->insertSeparator();
285 m_actions->action("printer_hard_default")->plug( menu );
286 m_actions->action("printer_soft_default")->plug( menu );
287 m_actions->action("printer_remove")->plug( menu );
288 menu->insertSeparator();
289 m_actions->action("printer_configure")->plug( menu );
290 m_actions->action("printer_test")->plug( menu );
291 m_actions->action("printer_tool")->plug( menu );
292 menu->insertSeparator();
293 //m_menubar->insertItem( i18n( "Printer" ), menu );
294 m_menubar->insertButton( "printer", 1, true, i18n( "Printer" ) );
295 m_menubar->getButton( 1 )->setPopup( menu, true );
296 menu = new TQPopupMenu( this );
297 m_actions->action("server_restart")->plug( menu );
298 m_actions->action("server_configure")->plug( menu );
299 //m_menubar->insertItem( i18n( "Server" ), menu );
300 m_menubar->insertButton( "misc", 2, true, i18n( "Print Server" ) );
301 m_menubar->getButton( 2 )->setPopup( menu, true );
302 menu = new TQPopupMenu( this );
303 m_actions->action("manager_configure")->plug( menu );
304 m_actions->action("view_refresh")->plug( menu );
305 //m_menubar->insertItem( i18n( "Manager" ), menu );
306 m_menubar->insertButton( "tdeprint_configmgr", 3, true, i18n( "Print Manager" ) );
307 m_menubar->getButton( 3 )->setPopup( menu, true );
308 menu = new TQPopupMenu( this );
309 m_actions->action("view_printerinfos")->plug( menu );
310 m_actions->action("view_change")->plug( menu );
311 m_actions->action("orientation_change")->plug( menu );
312 m_actions->action( "view_toolbar" )->plug ( menu );
313 m_actions->action( "view_menubar" )->plug ( menu );
314 menu->insertSeparator();
315 m_actions->action("view_pfilter")->plug( menu );
316 //m_menubar->insertItem( i18n( "View" ), menu );
317 m_menubar->insertButton( "view_remove", 4, true, i18n( "View" ) );
318 m_menubar->getButton( 4 )->setPopup( menu, true );
319 //m_menubar->setMinimumHeight( m_menubar->heightForWidth( 1000 ) );
320
321 loadPluginActions();
322 slotPrinterSelected(TQString::null);
323}
324
325void KMMainView::slotRefresh()
326{
327 // TODO: remove me
328}
329
330void KMMainView::slotTimer()
331{
332 kdDebug() << "KMMainView::slotTimer" << endl;
333 TQPtrList<KMPrinter> *printerlist = m_manager->printerList();
334 bool ok = m_manager->errorMsg().isEmpty();
335 m_printerview->setPrinterList(printerlist);
336 if ( m_first )
337 {
338 if ( !ok )
339 showErrorMsg(i18n("An error occurred while retrieving the printer list."));
340 else
341 {
342 /* try to select the most appropriate printer:
343 * - soft default owner printer
344 * - hard default printer
345 * - first printer
346 */
347 TQPtrListIterator<KMPrinter> it( *printerlist );
348 KMPrinter *p1 = 0, *p2 = 0, *p3 = 0;
349 while ( it.current() )
350 {
351 if ( !it.current()->isVirtual() )
352 {
353 if ( it.current()->ownSoftDefault() )
354 {
355 p1 = it.current();
356 break;
357 }
358 else if ( it.current()->isHardDefault() )
359 p2 = it.current();
360 else if ( !p3 )
361 p3 = it.current();
362 }
363 ++it;
364 }
365 if ( p1 || p2 || p3 )
366 m_printerview->setPrinter( p1 ? p1 : ( p2 ? p2 : p3 ) );
367 }
368 m_first = false;
369 }
370}
371
372void KMMainView::slotPrinterSelected(const TQString& prname)
373{
374 KMPrinter *p = KMManager::self()->findPrinter(prname);
375 m_current = p;
376 if (p && !p->isSpecial())
377 KMFactory::self()->manager()->completePrinter(p);
378 m_printerpages->setPrinter(p);
379
380 // update actions state (only if toolbar enabled, workaround for toolbar
381 // problem).
382 //if (m_toolbar->isEnabled())
383 //{
384 int mask = (m_manager->hasManagement() ? m_manager->printerOperationMask() : 0);
385 bool sp = !(p && p->isSpecial());
386// m_actions->action("printer_remove")->setEnabled(!sp || ((mask & KMManager::PrinterRemoval) && p && p->isLocal() && !p->isImplicit()));
387 m_actions->action("printer_remove")->setEnabled(!sp || ((mask & KMManager::PrinterRemoval) && p && !p->isImplicit()));
388 m_actions->action("printer_configure")->setEnabled(!sp || ((mask & KMManager::PrinterConfigure) && p && !p->isClass(true) /*&& p->isLocal()*/));
389 m_actions->action("printer_hard_default")->setEnabled((sp && (mask & KMManager::PrinterDefault) && p && !p->isClass(true) && !p->isHardDefault() && p->isLocal()));
390 m_actions->action("printer_soft_default")->setEnabled((p && !p->isSoftDefault()));
391 m_actions->action("printer_test")->setEnabled((sp && (mask & KMManager::PrinterTesting) && p && !p->isClass(true)));
392 bool stmask = (sp && (mask & KMManager::PrinterEnabling) && p);
393 m_actions->action("printer_state_change")->setEnabled(stmask && p->isLocal());
394 m_actions->action("printer_spool_change")->setEnabled(stmask);
395 m_actions->action("printer_start")->setEnabled((stmask && p->state() == KMPrinter::Stopped));
396 m_actions->action("printer_stop")->setEnabled((stmask && p->state() != KMPrinter::Stopped));
397 m_actions->action("printer_enable")->setEnabled((stmask && !p->acceptJobs()));
398 m_actions->action("printer_disable")->setEnabled((stmask && p->acceptJobs()));
399
400 m_actions->action("printer_add")->setEnabled((mask & KMManager::PrinterCreation));
401 mask = m_manager->serverOperationMask();
402 m_actions->action("server_restart")->setEnabled((mask & KMManager::ServerRestarting));
403 m_actions->action("server_configure")->setEnabled((mask & KMManager::ServerConfigure));
404
405 KMFactory::self()->manager()->validatePluginActions(m_actions, p);
406 //}
407 m_actions->action("printer_tool")->setEnabled(p && !p->isClass(true) && !p->isRemote() && !p->isSpecial());
408}
409
410void KMMainView::setViewType(int ID)
411{
412 ((TDESelectAction*)m_actions->action("view_change"))->setCurrentItem(ID);
413 slotChangeView(ID);
414}
415
416int KMMainView::viewType() const
417{ return m_printerview->viewType(); }
418
419void KMMainView::slotChangeView(int ID)
420{
421 kdDebug() << "KMMainView::slotChangeView" << endl;
422 if (ID >= KMPrinterView::Icons && ID <= KMPrinterView::Tree)
423 m_printerview->setViewType((KMPrinterView::ViewType)ID);
424}
425
426void KMMainView::slotRightButtonClicked(const TQString& prname, const TQPoint& p)
427{
428 KMPrinter *printer = KMManager::self()->findPrinter(prname);
429 // construct popup menu
430 m_pop->clear();
431 if (printer)
432 {
433 m_current = printer;
434 if (!printer->isSpecial())
435 {
436 if (printer->isLocal())
437 m_actions->action((printer->state() == KMPrinter::Stopped ? "printer_start" : "printer_stop"))->plug(m_pop);
438 m_actions->action((printer->acceptJobs() ? "printer_disable" : "printer_enable"))->plug(m_pop);
439 m_pop->insertSeparator();
440 }
441 if (!printer->isSoftDefault()) m_actions->action("printer_soft_default")->plug(m_pop);
442 if (printer->isLocal() && !printer->isImplicit())
443 {
444 if (!printer->isHardDefault()) m_actions->action("printer_hard_default")->plug(m_pop);
445 m_actions->action("printer_remove")->plug(m_pop);
446 m_pop->insertSeparator();
447 if (!printer->isClass(true))
448 {
449 m_actions->action("printer_configure")->plug(m_pop);
450 m_actions->action("printer_test")->plug(m_pop);
451 m_actions->action("printer_tool")->plug(m_pop);
452 m_pop->insertSeparator();
453 }
454 }
455 else
456 {
457 m_actions->action("printer_remove")->plug(m_pop);
458 m_pop->insertSeparator();
459 if (!printer->isClass(true))
460 {
461 m_actions->action("printer_configure")->plug(m_pop);
462 m_actions->action("printer_test")->plug(m_pop);
463 }
464 m_pop->insertSeparator();
465 }
466 if (!printer->isSpecial())
467 {
468 TQValueList<TDEAction*> pactions = m_actions->actions("plugin");
469 for (TQValueList<TDEAction*>::Iterator it=pactions.begin(); it!=pactions.end(); ++it)
470 (*it)->plug(m_pop);
471 if (pactions.count() > 0)
472 m_pop->insertSeparator();
473 }
474 }
475 else
476 {
477 m_actions->action("printer_add")->plug(m_pop);
478 m_actions->action("printer_add_special")->plug(m_pop);
479 m_pop->insertSeparator();
480 m_actions->action("server_restart")->plug(m_pop);
481 m_actions->action("server_configure")->plug(m_pop);
482 m_pop->insertSeparator();
483 m_actions->action("manager_configure")->plug(m_pop);
484 m_actions->action("view_refresh")->plug(m_pop);
485 m_pop->insertSeparator();
486 }
487 m_actions->action("view_printerinfos")->plug(m_pop);
488 m_actions->action("view_change")->plug(m_pop);
489 m_actions->action("orientation_change")->plug(m_pop);
490 m_actions->action("view_toolbar")->plug(m_pop);
491 m_actions->action("view_menubar")->plug(m_pop);
492 m_pop->insertSeparator();
493 m_actions->action("view_pfilter")->plug(m_pop);
494
495 // pop the menu
496 m_pop->popup(p);
497}
498
499void KMMainView::slotChangePrinterState()
500{
501 TQString opname = sender()->name();
502 if (m_current && opname.startsWith("printer_"))
503 {
504 opname = opname.mid(8);
505 KMTimer::self()->hold();
506 bool result(false);
507 if (opname == "enable")
508 result = m_manager->enablePrinter(m_current, true);
509 else if (opname == "disable")
510 result = m_manager->enablePrinter(m_current, false);
511 else if (opname == "start")
512 result = m_manager->startPrinter(m_current, true);
513 else if (opname == "stop")
514 result = m_manager->startPrinter(m_current, false);
515 if (!result)
516 showErrorMsg(i18n("Unable to modify the state of printer %1.").arg(m_current->printerName()));
517 KMTimer::self()->release(result);
518 }
519}
520
521void KMMainView::slotRemove()
522{
523 if (m_current)
524 {
525 KMTimer::self()->hold();
526 bool result(false);
527 if (KMessageBox::warningYesNo(this,i18n("Do you really want to remove %1?").arg(m_current->printerName())) == KMessageBox::Yes)
528 if (m_current->isSpecial())
529 {
530 if (!(result=m_manager->removeSpecialPrinter(m_current)))
531 showErrorMsg(i18n("Unable to remove special printer %1.").arg(m_current->printerName()));
532 }
533 else if (!(result=m_manager->removePrinter(m_current)))
534 showErrorMsg(i18n("Unable to remove printer %1.").arg(m_current->printerName()));
535 KMTimer::self()->release(result);
536 }
537}
538
539void KMMainView::slotConfigure()
540{
541 if (m_current)
542 {
543 KMTimer::self()->hold();
544 bool needRefresh(false);
545 if (m_current->isSpecial())
546 {
547 KMSpecialPrinterDlg dlg(this);
548 dlg.setPrinter(m_current);
549 if (dlg.exec())
550 {
551 KMPrinter *prt = dlg.printer();
552 if (prt->name() != m_current->name())
553 m_manager->removeSpecialPrinter(m_current);
554 m_manager->createSpecialPrinter(prt);
555 needRefresh = true;
556 }
557 }
558 else
559 {
560 DrMain *driver = m_manager->loadPrinterDriver(m_current, true);
561 if (driver)
562 {
563 KMDriverDialog dlg(this);
564 dlg.setCaption(i18n("Configure %1").arg(m_current->printerName()));
565 dlg.setDriver(driver);
566 // disable OK button for remote printer (read-only dialog)
567 if (m_current->isRemote())
568 dlg.enableButtonOK(false);
569 if (dlg.exec())
570 if (!m_manager->savePrinterDriver(m_current,driver))
571 showErrorMsg(i18n("Unable to modify settings of printer %1.").arg(m_current->printerName()));
572 delete driver;
573 }
574 else
575 showErrorMsg(i18n("Unable to load a valid driver for printer %1.").arg(m_current->printerName()));
576 }
577 KMTimer::self()->release(needRefresh);
578 }
579}
580
581void KMMainView::slotAdd()
582{
583 KMTimer::self()->hold();
584
585 int result(0);
586 if ((result=tdeprint_management_add_printer_wizard(this)) == -1)
587 showErrorMsg(i18n("Unable to create printer."));
588
589 KMTimer::self()->release((result == 1));
590}
591
592void KMMainView::slotHardDefault()
593{
594 if (m_current)
595 {
596 KMTimer::self()->hold();
597 bool result = m_manager->setDefaultPrinter(m_current);
598 if (!result)
599 showErrorMsg(i18n("Unable to define printer %1 as default.").arg(m_current->printerName()));
600 KMTimer::self()->release(result);
601 }
602}
603
604void KMMainView::slotSoftDefault()
605{
606 if (m_current)
607 {
608 KMTimer::self()->hold();
609 KMFactory::self()->virtualManager()->setAsDefault(m_current,TQString::null);
610 KMTimer::self()->release(true);
611 }
612}
613
614void KMMainView::setOrientation(int o)
615{
616 int ID = (o == TQt::Horizontal ? 1 : 0);
617 ((TDESelectAction*)m_actions->action("orientation_change"))->setCurrentItem(ID);
618 slotChangeDirection(ID);
619}
620
621int KMMainView::orientation() const
622{ return (m_boxlayout->direction() == TQBoxLayout::LeftToRight ? TQt::Horizontal : TQt::Vertical); }
623
624void KMMainView::slotChangeDirection(int d)
625{
626 m_boxlayout->setDirection(d == 1 ? TQBoxLayout::LeftToRight : TQBoxLayout::TopToBottom);
627}
628
629void KMMainView::slotTest()
630{
631 if (m_current)
632 {
633 KMTimer::self()->hold();
634 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)
635 {
636 if (KMFactory::self()->manager()->testPrinter(m_current))
637 KMessageBox::information(this,i18n("Test page successfully sent to printer %1.").arg(m_current->printerName()));
638 else
639 showErrorMsg(i18n("Unable to test printer %1.").arg(m_current->printerName()));
640 }
641 KMTimer::self()->release(true);
642 }
643}
644
645void KMMainView::showErrorMsg(const TQString& msg, bool usemgr)
646{
647 TQString s(msg);
648 if (usemgr)
649 {
650 s.prepend("<p>");
651 s.append(" ");
652 s += i18n("Error message received from manager:</p><p>%1</p>");
653 if (m_manager->errorMsg().isEmpty())
654 s = s.arg(i18n("Internal error (no error message)."));
655 else
656 s = s.arg(m_manager->errorMsg());
657 // clean up error message
658 m_manager->setErrorMsg(TQString::null);
659 }
660 s.prepend("<qt>").append("</qt>");
661 KMTimer::self()->hold();
662 KMessageBox::error(this,s);
663 KMTimer::self()->release();
664}
665
666void KMMainView::slotServerRestart()
667{
668 KMTimer::self()->hold();
669 bool result = m_manager->restartServer();
670 if (!result)
671 {
672 showErrorMsg(i18n("Unable to restart print server."));
673 KMTimer::self()->release( false );
674 }
675 else
676 {
677 reset( i18n( "Restarting server..." ), false, false );
678 }
679}
680
681void KMMainView::slotServerConfigure()
682{
683 KMTimer::self()->hold();
684 bool result = m_manager->configureServer(this);
685 if (!result)
686 {
687 showErrorMsg(i18n("Unable to configure print server."));
688 KMTimer::self()->release( false );
689 }
690 else
691 {
692 reset( i18n( "Configuring server..." ), false, false );
693 }
694}
695
696void KMMainView::slotServerConfigureAccess()
697{
698 TDEProcess *proc = new TDEProcess;
699 *proc << "/usr/bin/system-config-printer-kde";
700 proc->start(TDEProcess::DontCare);
701}
702
703void KMMainView::slotToggleToolBar(bool on)
704{
705 if (on) m_toolbar->show();
706 else m_toolbar->hide();
707}
708
709void KMMainView::slotToggleMenuBar( bool on )
710{
711 if ( on )
712 m_menubar->show();
713 else
714 m_menubar->hide();
715}
716
717void KMMainView::slotManagerConfigure()
718{
719 KMTimer::self()->hold();
720 KMConfigDialog dlg(this,"ConfigDialog");
721 if ( dlg.exec() )
722 {
723 loadParameters();
724 }
725 /* when "OK":
726 * => the config file is saved
727 * => triggering a DCOP signal
728 * => configChanged() called
729 * hence no need to refresh, just release the timer
730 */
731 KMTimer::self()->release( false );
732}
733
734void KMMainView::slotAddSpecial()
735{
736 KMTimer::self()->hold();
737 KMSpecialPrinterDlg dlg(this);
738 if (dlg.exec())
739 {
740 KMPrinter *prt = dlg.printer();
741 m_manager->createSpecialPrinter(prt);
742 }
743 KMTimer::self()->release(true);
744}
745
746void KMMainView::slotShowPrinterInfos(bool on)
747{
748 if (on)
749 m_printerpages->show();
750 else
751 m_printerpages->hide();
752 m_actions->action("orientation_change")->setEnabled(on);
753}
754
755void KMMainView::enableToolbar(bool on)
756{
757 TDEToggleAction *act = (TDEToggleAction*)m_actions->action("view_toolbar");
758 m_toolbar->setEnabled(on);
759 act->setEnabled(on);
760 if (on && act->isChecked())
761 m_toolbar->show();
762 else
763 m_toolbar->hide();
764}
765
766TDEAction* KMMainView::action(const char *name)
767{
768 return m_actions->action(name);
769}
770
771/*
772void KMMainView::aboutToReload()
773{
774 m_printerview->setPrinterList(0);
775}
776*/
777
778void KMMainView::reload()
779{
780 removePluginActions();
781 loadPluginActions();
782
783 // redo the connection as the old manager object has been removed
784 connect( m_manager, TQ_SIGNAL( updatePossible( bool ) ), TQ_SLOT( slotUpdatePossible( bool ) ) );
785
786 // We must delay the refresh such that all objects has been
787 // correctly reloaded (otherwise, crash in KMJobViewer).
788 reset( i18n( "Initializing manager..." ), true, true );
789}
790
791void KMMainView::showPrinterInfos(bool on)
792{
793 static_cast<TDEToggleAction*>(m_actions->action("view_printerinfos"))->setChecked(on);
794 slotShowPrinterInfos(on);
795}
796
797bool KMMainView::printerInfosShown() const
798{
799 return (static_cast<TDEToggleAction*>(m_actions->action("view_printerinfos"))->isChecked());
800}
801
802void KMMainView::loadPluginActions()
803{
804 KMFactory::self()->manager()->createPluginActions(m_actions);
805 TQValueList<TDEAction*> pactions = m_actions->actions("plugin");
806 int index = m_pactionsindex;
807 //TQPopupMenu *menu = m_menubar->findItem( m_menubar->idAt( 1 ) )->popup();
808 TQPopupMenu *menu = m_menubar->getButton( 1 )->popup();
809 for (TQValueList<TDEAction*>::Iterator it=pactions.begin(); it!=pactions.end(); ++it)
810 {
811 (*it)->plug(m_toolbar, index++);
812 ( *it )->plug( menu );
813 }
814}
815
816void KMMainView::removePluginActions()
817{
818 TQValueList<TDEAction*> pactions = m_actions->actions("plugin");
819 for (TQValueList<TDEAction*>::Iterator it=pactions.begin(); it!=pactions.end(); ++it)
820 {
821 (*it)->unplugAll();
822 delete (*it);
823 }
824}
825
826void KMMainView::slotToolSelected(int ID)
827{
828 KMTimer::self()->hold();
829
830 TQString libname = m_toollist[ID];
831 libname.prepend("tdeprint_tool_");
832 if (m_current && !m_current->device().isEmpty() && !libname.isEmpty())
833 {
834 KLibFactory *factory = KLibLoader::self()->factory(libname.local8Bit());
835 if (factory)
836 {
837 TQStringList args;
838 args << m_current->device() << m_current->printerName();
839 KDialogBase *dlg = static_cast<KDialogBase*>(factory->create(this, "Tool", 0, args));
840 if (dlg)
841 dlg->exec();
842 delete dlg;
843 }
844 }
845 else
846 KMessageBox::error(this,
847 i18n("Unable to start printer tool. Possible reasons are: "
848 "no printer selected, the selected printer doesn't have "
849 "any local device defined (printer port), or the tool library "
850 "could not be found."));
851
852 KMTimer::self()->release();
853}
854
855void KMMainView::slotToggleFilter(bool on)
856{
857 KMTimer::self()->hold();
858 KMManager::self()->enableFilter(on);
859 KMTimer::self()->release(true);
860}
861
862void KMMainView::configChanged()
863{
864 reset( i18n( "Initializing manager..." ), false, true );
865}
866
867void KMMainView::slotUpdatePossible( bool flag )
868{
869 destroyMessageWindow();
870 if ( !flag )
871 {
872 bool cupsInstalled = ( WEXITSTATUS( system(
873 "dpkg --compare-versions \"$(dash /usr/share/apps/q4os_system/bin/print_package_version.sh cups)\" gt 0" ) ) == 0 );
874 if ( !cupsInstalled )
875 {
876 bindtextdomain( "q4os-base", "/usr/share/locale" );
877 bind_textdomain_codeset( "q4os-base", "UTF-8" );
878 textdomain( "q4os-base" );
879 TQString msg;
880 if ( TQFile::exists( "/etc/q4oslivemedia" ) )
881 {
882 msg = TQString::fromUtf8( gettext(
883 "Live media detected. Printers management may be limited within the live media environment. It will be fully available after Q4OS installation." ) );
884 }
885 else
886 {
887 msg = TQString( "<p>%1</p><p><b>cups, hplip, printer-driver-all</b></p><p>%2</p>" )
888 .arg( TQString::fromUtf8( gettext(
889 "Printing subsystem is now deactivated, you need to install <b>CUPS layer and printer driver</b> first. If you want to activate printing subsystem and full set of drivers, install following packages:" ) ) )
890 .arg( TQString::fromUtf8( gettext(
891 "For more detailed info read Q4OS documentation at https://www.q4os.org" ) ) );
892 }
893 KMessageBox::information( this, "<qt>" + msg + "</qt>" );
894 }
895 else
896 showErrorMsg( i18n( "Unable to retrieve the printer list." ) );
897 }
898 KMTimer::self()->release( true );
899}
900
901void KMMainView::createMessageWindow( const TQString& txt, int delay )
902{
903 destroyMessageWindow();
904 MessageWindow::add( m_printerview, txt, delay );
905}
906
907void KMMainView::destroyMessageWindow()
908{
909 MessageWindow::remove( m_printerview );
910}
911
912void KMMainView::slotInit()
913{
914 reset( i18n( "Initializing manager..." ), true, true );
915}
916
917void KMMainView::reset( const TQString& msg, bool useDelay, bool holdTimer )
918{
919 if ( holdTimer )
920 KMTimer::self()->hold();
921 m_printerview->setPrinterList( 0 );
922 if ( !msg.isEmpty() )
923 createMessageWindow( msg, ( useDelay ? 500 : 0 ) );
924 m_first = true;
925 m_manager->checkUpdatePossible();
926}
927
928#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.15.0
This website is maintained by Timothy Pearson.