20 #include "kminstancepage.h"
21 #include "kmprinter.h"
22 #include "kmfactory.h"
23 #include "kmvirtualmanager.h"
24 #include "kmmanager.h"
25 #include "kprinterpropertydialog.h"
31 #include <tqwhatsthis.h>
32 #include <tqpushbutton.h>
33 #include <tdemessagebox.h>
34 #include <kinputdialog.h>
35 #include <tdelistbox.h>
36 #include <tdelocale.h>
37 #include <kiconloader.h>
38 #include <kstandarddirs.h>
41 KMInstancePage::KMInstancePage(TQWidget *parent,
const char *name)
42 : TQWidget(parent,name)
44 m_view =
new TDEListBox(
this);
49 TQHBoxLayout *main_ =
new TQHBoxLayout(
this, 0, 0);
50 main_->addWidget(m_view);
51 TQVBoxLayout *sub_ =
new TQVBoxLayout(0, 0, 0);
52 main_->addLayout(sub_);
53 for (TQValueList<TQButton*>::Iterator it=m_buttons.begin(); it!=m_buttons.end(); ++it)
60 TQWhatsThis::add(
this,
61 i18n(
"Define/Edit here instances for the current selected "
62 "printer. An instance is a combination of a real "
63 "(physical) printer and a set of predefined options. "
64 "For a single InkJet printer, you could define different "
65 "print formats like <i>DraftQuality</i>, <i>PhotoQuality</i> "
66 "or <i>TwoSided</i>. Those instances appear as normal "
67 "printers in the print dialog and allow you to quickly "
68 "select the print format you want."));
71 KMInstancePage::~KMInstancePage()
75 void KMInstancePage::addButton(
const TQString& txt,
const TQString& pixmap,
const char *receiver)
77 TQPushButton *btn =
new TQPushButton(
this, 0L);
79 btn->setIconSet(BarIconSet(pixmap));
81 connect(btn, TQ_SIGNAL(clicked()), receiver);
82 m_buttons.append(btn);
85 void KMInstancePage::initActions()
87 addButton(i18n(
"New..."),
"document-new", TQ_SLOT(slotNew()));
88 addButton(i18n(
"Copy..."),
"edit-copy", TQ_SLOT(slotCopy()));
89 addButton(i18n(
"Remove"),
"edittrash", TQ_SLOT(slotRemove()));
91 addButton(i18n(
"Set as Default"),
"application-x-executable", TQ_SLOT(slotDefault()));
92 addButton(i18n(
"Settings"),
"configure", TQ_SLOT(slotSettings()));
94 addButton(i18n(
"Test..."),
"document-print", TQ_SLOT(slotTest()));
97 void KMInstancePage::setPrinter(KMPrinter *p)
99 TQString oldText = m_view->currentText();
107 TQPtrList<KMPrinter> list;
108 KMFactory::self()->virtualManager()->virtualList(list,p->name());
109 TQPtrListIterator<KMPrinter> it(list);
110 for (;it.current();++it)
112 TQStringList pair = TQStringList::split(
'/',it.current()->name(),
false);
113 m_view->insertItem(SmallIcon((it.current()->isSoftDefault() ?
"application-x-executable" :
"document-print")),(pair.count() > 1 ? pair[1] : i18n(
"(Default)")));
118 for (TQValueList<TQButton*>::ConstIterator it=m_buttons.begin(); it!=m_buttons.end(); ++it)
120 (*it)->setEnabled(ok);
124 TQListBoxItem *item = m_view->findItem(oldText);
126 item = m_view->findItem(i18n(
"(Default)"));
128 m_view->setSelected(item,
true);
132 void KMInstancePage::slotNew()
134 KMTimer::self()->hold();
137 TQString name = KInputDialog::getText(i18n(
"Instance Name"),i18n(
"Enter name for new instance (leave untouched for default):"),
138 i18n(
"(Default)"),&ok,
this);
141 if (name.find(TQRegExp(
"[/\\s]")) != -1)
142 KMessageBox::error(
this, i18n(
"Instance name must not contain any spaces or slashes."));
145 if (name == i18n(
"(Default)"))
147 KMFactory::self()->virtualManager()->create(m_printer,name);
148 setPrinter(m_printer);
152 KMTimer::self()->release();
155 void KMInstancePage::slotRemove()
157 KMTimer::self()->hold();
160 TQString src = m_view->currentText();
161 TQString msg = (src != i18n(
"(Default)") ? i18n(
"Do you really want to remove instance %1?") : i18n(
"You can't remove the default instance. However all settings of %1 will be discarded. Continue?"));
162 if (!src.isEmpty() && KMessageBox::warningContinueCancel(
this,msg.arg(src),TQString(),KStdGuiItem::del()) == KMessageBox::Continue)
164 if (src == i18n(
"(Default)"))
166 reload = KMFactory::self()->virtualManager()->isDefault(m_printer,src);
167 KMFactory::self()->virtualManager()->remove(m_printer,src);
168 setPrinter(m_printer);
171 KMTimer::self()->release(reload);
174 void KMInstancePage::slotCopy()
176 KMTimer::self()->hold();
178 TQString src = m_view->currentText();
182 TQString name = KInputDialog::getText(i18n(
"Instance Name"),i18n(
"Enter name for new instance (leave untouched for default):"),
183 i18n(
"(Default)"),&ok,
this);
186 if (name.find(TQRegExp(
"[/\\s]")) != -1)
187 KMessageBox::error(
this, i18n(
"Instance name must not contain any spaces or slashes."));
190 if (src == i18n(
"(Default)"))
192 if (name == i18n(
"(Default)"))
194 KMFactory::self()->virtualManager()->copy(m_printer,src,name);
195 setPrinter(m_printer);
200 KMTimer::self()->release();
203 void KMInstancePage::slotSettings()
205 KMTimer::self()->hold();
207 TQString src = m_view->currentText();
210 if (src == i18n(
"(Default)")) src = TQString();
211 KMPrinter *pr = KMFactory::self()->virtualManager()->findInstance(m_printer,src);
213 KMessageBox::error(
this, i18n(
"Unable to find instance %1." ).arg( m_view->currentText() ) );
214 else if ( !pr->isSpecial() && !KMFactory::self()->manager()->completePrinterShort( pr ) )
215 KMessageBox::error(
this, i18n(
"Unable to retrieve printer information. Message from printing system: %1." ).arg( KMFactory::self()->manager()->errorMsg() ) );
218 int oldAppType = KMFactory::self()->settings()->application;
219 KMFactory::self()->settings()->application = -1;
220 KPrinterPropertyDialog::setupPrinter(pr,
this);
221 KMFactory::self()->settings()->application = oldAppType;
224 pr->setDefaultOptions(pr->editedOptions());
225 pr->setEditedOptions(TQMap<TQString,TQString>());
226 pr->setEdited(
false);
227 KMFactory::self()->virtualManager()->triggerSave();
232 KMessageBox::error(
this, i18n(
"The instance name is empty. Please select an instance." ) );
234 KMTimer::self()->release();
237 void KMInstancePage::slotDefault()
239 KMTimer::self()->hold();
241 TQString src = m_view->currentText();
244 if (src == i18n(
"(Default)"))
246 KMFactory::self()->virtualManager()->setAsDefault(m_printer,src);
247 setPrinter(m_printer);
250 KMTimer::self()->release(
true);
253 void KMInstancePage::slotTest()
255 KMTimer::self()->hold();
257 TQString src = m_view->currentText();
260 if (src == i18n(
"(Default)"))
262 KMPrinter *mpr = KMFactory::self()->virtualManager()->findInstance(m_printer,src);
264 KMessageBox::error(
this,i18n(
"Internal error: printer not found."));
265 else if (KMessageBox::warningContinueCancel(
this, i18n(
"You are about to print a test page on %1. Do you want to continue?").arg(mpr->printerName()), TQString(), i18n(
"Print Test Page"),
"printTestPage") == KMessageBox::Continue)
267 if (!KMFactory::self()->virtualManager()->testInstance(mpr))
268 KMessageBox::error(
this, i18n(
"Unable to send test page to %1.").arg(mpr->printerName()));
270 KMessageBox::information(
this,i18n(
"Test page successfully sent to printer %1.").arg(mpr->printerName()));
274 KMTimer::self()->release(
false);
276 #include "kminstancepage.moc"