20 #include "kprinterpropertydialog.h"
21 #include "kprintdialogpage.h"
22 #include "kmfactory.h"
23 #include "kmuimanager.h"
24 #include "kmvirtualmanager.h"
25 #include "kmprinter.h"
28 #include <tdemessagebox.h>
29 #include <tqtabwidget.h>
30 #include <tdelocale.h>
31 #include <kpushbutton.h>
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)
38 m_pages.setAutoDelete(
false);
41 m_tw =
new TQTabWidget(
this);
43 connect(m_tw,TQ_SIGNAL(currentChanged(TQWidget*)),TQ_SLOT(slotCurrentChanged(TQWidget*)));
47 m_options = (m_printer->isEdited() ? m_printer->editedOptions() : m_printer->defaultOptions());
50 KPrinterPropertyDialog::~KPrinterPropertyDialog()
55 void KPrinterPropertyDialog::slotCurrentChanged(TQWidget *w)
57 if (m_current) m_current->getOptions(m_options,
true);
59 if (m_current) m_current->setOptions(m_options);
64 m_tw->addTab(page,page->
title());
68 bool KPrinterPropertyDialog::synchronize()
70 if (m_current) m_current->getOptions(m_options,
true);
72 TQPtrListIterator<KPrintDialogPage> it(m_pages);
73 for (;it.current();++it)
75 it.current()->setOptions(m_options);
76 if (!it.current()->isValid(msg))
78 KMessageBox::error(
this, msg.prepend(
"<qt>").append(
"</qt>"), i18n(
"Printer Configuration"));
85 void KPrinterPropertyDialog::setOptions(
const TQMap<TQString,TQString>& opts)
88 for (TQMap<TQString,TQString>::ConstIterator it=opts.begin(); it!=opts.end(); ++it)
89 m_options[it.key()] = it.data();
91 TQPtrListIterator<KPrintDialogPage> it(m_pages);
92 for (; it.current(); ++it)
93 it.current()->setOptions(m_options);
96 void KPrinterPropertyDialog::getOptions(TQMap<TQString,TQString>& opts,
bool incldef)
98 collectOptions(opts, incldef);
101 void KPrinterPropertyDialog::collectOptions(TQMap<TQString,TQString>& opts,
bool incldef)
103 TQPtrListIterator<KPrintDialogPage> it(m_pages);
104 for (;it.current();++it)
105 it.current()->getOptions(opts,incldef);
108 void KPrinterPropertyDialog::slotOk()
112 KDialogBase::slotOk();
115 void KPrinterPropertyDialog::slotUser1()
117 if (m_printer && synchronize())
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();
128 void KPrinterPropertyDialog::enableSaveButton(
bool state)
130 showButton(KDialogBase::User1, state);
133 void KPrinterPropertyDialog::setupPrinter(KMPrinter *pr, TQWidget *parent)
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"));
141 TQMap<TQString,TQString> opts;
142 dlg.collectOptions(opts,
false);
143 pr->setEditedOptions(opts);
147 #include "kprinterpropertydialog.moc"
This class is intended to be used as base class for customized print dialog page.
TQString title() const
Get the page title.