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

tdeprint

  • tdeprint
kprinterpropertydialog.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 "kprinterpropertydialog.h"
21 #include "kprintdialogpage.h"
22 #include "kmfactory.h"
23 #include "kmuimanager.h"
24 #include "kmvirtualmanager.h"
25 #include "kmprinter.h"
26 #include "driver.h"
27 
28 #include <tdemessagebox.h>
29 #include <tqtabwidget.h>
30 #include <tdelocale.h>
31 #include <kpushbutton.h>
32 #include <kguiitem.h>
33 
34 KPrinterPropertyDialog::KPrinterPropertyDialog(KMPrinter *p, TQWidget *parent, const char *name)
35 : KDialogBase(parent, name, true, TQString::null, KDialogBase::Ok|KDialogBase::Cancel|KDialogBase::User1, KDialogBase::Ok, false, KStdGuiItem::save()),
36  m_printer(p), m_driver(0), m_current(0)
37 {
38  m_pages.setAutoDelete(false);
39 
40  // set a margin
41  m_tw = new TQTabWidget(this);
42  m_tw->setMargin(10);
43  connect(m_tw,TQ_SIGNAL(currentChanged(TQWidget*)),TQ_SLOT(slotCurrentChanged(TQWidget*)));
44  setMainWidget(m_tw);
45 
46  if (m_printer)
47  m_options = (m_printer->isEdited() ? m_printer->editedOptions() : m_printer->defaultOptions());
48 }
49 
50 KPrinterPropertyDialog::~KPrinterPropertyDialog()
51 {
52  delete m_driver;
53 }
54 
55 void KPrinterPropertyDialog::slotCurrentChanged(TQWidget *w)
56 {
57  if (m_current) m_current->getOptions(m_options,true);
58  m_current = (KPrintDialogPage*)w;
59  if (m_current) m_current->setOptions(m_options);
60 }
61 
62 void KPrinterPropertyDialog::addPage(KPrintDialogPage *page)
63 {
64  m_tw->addTab(page,page->title());
65  m_pages.append(page);
66 }
67 
68 bool KPrinterPropertyDialog::synchronize()
69 {
70  if (m_current) m_current->getOptions(m_options,true);
71  TQString msg;
72  TQPtrListIterator<KPrintDialogPage> it(m_pages);
73  for (;it.current();++it)
74  {
75  it.current()->setOptions(m_options);
76  if (!it.current()->isValid(msg))
77  {
78  KMessageBox::error(this, msg.prepend("<qt>").append("</qt>"), i18n("Printer Configuration"));
79  return false;
80  }
81  }
82  return true;
83 }
84 
85 void KPrinterPropertyDialog::setOptions(const TQMap<TQString,TQString>& opts)
86 {
87  // merge the 2 options sets
88  for (TQMap<TQString,TQString>::ConstIterator it=opts.begin(); it!=opts.end(); ++it)
89  m_options[it.key()] = it.data();
90  // update all existing pages
91  TQPtrListIterator<KPrintDialogPage> it(m_pages);
92  for (; it.current(); ++it)
93  it.current()->setOptions(m_options);
94 }
95 
96 void KPrinterPropertyDialog::getOptions(TQMap<TQString,TQString>& opts, bool incldef)
97 {
98  collectOptions(opts, incldef);
99 }
100 
101 void KPrinterPropertyDialog::collectOptions(TQMap<TQString,TQString>& opts, bool incldef)
102 {
103  TQPtrListIterator<KPrintDialogPage> it(m_pages);
104  for (;it.current();++it)
105  it.current()->getOptions(opts,incldef);
106 }
107 
108 void KPrinterPropertyDialog::slotOk()
109 {
110  if (!synchronize())
111  return;
112  KDialogBase::slotOk();
113 }
114 
115 void KPrinterPropertyDialog::slotUser1()
116 {
117  if (m_printer && synchronize())
118  {
119  TQMap<TQString,TQString> opts;
120  collectOptions(opts, false);
121  m_printer->setDefaultOptions(opts);
122  m_printer->setEditedOptions(TQMap<TQString,TQString>());
123  m_printer->setEdited(false);
124  KMFactory::self()->virtualManager()->triggerSave();
125  }
126 }
127 
128 void KPrinterPropertyDialog::enableSaveButton(bool state)
129 {
130  showButton(KDialogBase::User1, state);
131 }
132 
133 void KPrinterPropertyDialog::setupPrinter(KMPrinter *pr, TQWidget *parent)
134 {
135  KPrinterPropertyDialog dlg(pr,parent,"PropertyDialog");
136  KMFactory::self()->uiManager()->setupPropertyDialog(&dlg);
137  if (dlg.m_pages.count() == 0)
138  KMessageBox::information(parent,i18n("No configurable options for that printer."),i18n("Printer Configuration"));
139  else if (dlg.exec())
140  {
141  TQMap<TQString,TQString> opts;
142  dlg.collectOptions(opts, false);
143  pr->setEditedOptions(opts);
144  pr->setEdited(true);
145  }
146 }
147 #include "kprinterpropertydialog.moc"
KPrintDialogPage
This class is intended to be used as base class for customized print dialog page.
Definition: kprintdialogpage.h:91
KPrintDialogPage::title
TQString title() const
Get the page title.
Definition: kprintdialogpage.h:147

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.1
This website is maintained by Timothy Pearson.