20 #include "kmspecialprinterdlg.h"
21 #include "kmprinter.h"
22 #include "tdeprintcheck.h"
23 #include "kmfactory.h"
24 #include "kmspecialmanager.h"
25 #include "kxmlcommandselector.h"
26 #include "kxmlcommand.h"
29 #include <tqpushbutton.h>
30 #include <tqlineedit.h>
31 #include <tqcheckbox.h>
32 #include <tqcombobox.h>
35 #include <tqwhatsthis.h>
36 #include <tqgroupbox.h>
37 #include <tdelocale.h>
38 #include <tdemessagebox.h>
39 #include <kicondialog.h>
40 #include <tdefiledialog.h>
41 #include <kseparator.h>
43 KMSpecialPrinterDlg::KMSpecialPrinterDlg(TQWidget *parent,
const char *name)
44 : KDialogBase(parent, name, true, TQString::null, Ok|Cancel, Ok)
46 setCaption(i18n(
"Add Special Printer"));
48 TQWidget *dummy =
new TQWidget(
this);
52 m_name =
new TQLineEdit(dummy);
53 connect(m_name, TQ_SIGNAL(textChanged (
const TQString & )),
this,TQ_SLOT(slotTextChanged(
const TQString & )));
54 m_description =
new TQLineEdit(dummy);
55 m_location =
new TQLineEdit(dummy);
56 TQLabel *m_namelabel =
new TQLabel(i18n(
"&Name:"), dummy);
57 TQLabel *m_desclabel =
new TQLabel(i18n(
"&Description:"), dummy);
58 TQLabel *m_loclabel =
new TQLabel(i18n(
"&Location:"), dummy);
59 m_namelabel->setBuddy(m_name);
60 m_desclabel->setBuddy(m_description);
61 m_loclabel->setBuddy(m_location);
63 KSeparator* sep =
new KSeparator( KSeparator::HLine, dummy);
65 sep->setFixedHeight(10);
66 TQGroupBox *m_gb =
new TQGroupBox(1, TQt::Horizontal, i18n(
"Command &Settings"), dummy);
67 m_command =
new KXmlCommandSelector(
true, m_gb,
"CommandSelector",
this);
69 TQGroupBox *m_outfile_gb =
new TQGroupBox( 0, TQt::Horizontal, i18n(
"Outp&ut File" ), dummy );
71 m_usefile =
new TQCheckBox( i18n(
"&Enable output file"), m_outfile_gb);
73 m_mimetype =
new TQComboBox(m_outfile_gb);
74 KMimeType::List list = KMimeType::allMimeTypes();
75 for (TQValueList<KMimeType::Ptr>::ConstIterator it=list.begin(); it!=list.end(); ++it)
77 TQString mimetype = (*it)->name();
78 m_mimelist << mimetype;
81 m_mimetype->insertStringList(m_mimelist);
83 TQLabel *m_mimetypelabel =
new TQLabel(i18n(
"&Format:"), m_outfile_gb);
84 m_mimetypelabel->setBuddy (m_mimetype);
86 m_extension =
new TQLineEdit(m_outfile_gb);
88 TQLabel *m_extensionlabel =
new TQLabel(i18n(
"Filename e&xtension:"), m_outfile_gb);
89 m_extensionlabel->setBuddy(m_extension);
91 m_icon =
new TDEIconButton(dummy);
92 m_icon->setIcon(
"document-print");
93 m_icon->setFixedSize(TQSize(48,48));
95 connect( m_usefile, TQ_SIGNAL( toggled(
bool ) ), m_mimetype, TQ_SLOT( setEnabled(
bool ) ) );
96 connect( m_usefile, TQ_SIGNAL( toggled(
bool ) ), m_extension, TQ_SLOT( setEnabled(
bool ) ) );
97 connect( m_usefile, TQ_SIGNAL( toggled(
bool ) ), m_mimetypelabel, TQ_SLOT( setEnabled(
bool ) ) );
98 connect( m_usefile, TQ_SIGNAL( toggled(
bool ) ), m_extensionlabel, TQ_SLOT( setEnabled(
bool ) ) );
99 m_mimetypelabel->setEnabled(
false );
100 m_mimetype->setEnabled(
false );
101 m_extensionlabel->setEnabled(
false );
102 m_extension->setEnabled(
false );
104 TQWhatsThis::add(m_usefile,
105 i18n(
"<p>The command will use an output file. If checked, make sure the "
106 "command contains an output tag.</p>"));
107 TQWhatsThis::add(m_command,
108 i18n(
"<p>The command to execute when printing on this special printer. Either enter "
109 "the command to execute directly, or associate/create a command object with/for "
110 "this special printer. The command object is the preferred method as it provides "
111 "support for advanced settings like mime type checking, configurable options and "
112 "requirement list (the plain command is only provided for backward compatibility). "
113 "When using a plain command, the following tags are recognized:</p>"
114 "<ul><li><b>%in</b>: the input file (required).</li>"
115 "<li><b>%out</b>: the output file (required if using an output file).</li>"
116 "<li><b>%psl</b>: the paper size in lower case.</li>"
117 "<li><b>%psu</b>: the paper size with the first letter in upper case.</li></ul>"));
118 TQString mimetypeWhatsThis = i18n(
"<p>The default mimetype for the output file (e.g. application/postscript).</p>");
119 TQWhatsThis::add(m_mimetypelabel, mimetypeWhatsThis);
120 TQWhatsThis::add(m_mimetype, mimetypeWhatsThis);
121 TQString extensionWhatsThis = i18n(
"<p>The default extension for the output file (e.g. ps, pdf, ps.gz).</p>");
122 TQWhatsThis::add(m_extensionlabel, extensionWhatsThis);
123 TQWhatsThis::add(m_extension, extensionWhatsThis);
126 TQVBoxLayout *l0 =
new TQVBoxLayout(dummy, 0, 10);
127 TQGridLayout *l1 =
new TQGridLayout(0, 3, 3, 0, 5);
129 l1->setColStretch(2,1);
130 l1->addColSpacing(0,60);
131 l1->addMultiCellWidget(m_icon, 0, 2, 0, 0, TQt::AlignCenter);
132 l1->addWidget(m_namelabel, 0, 1);
133 l1->addWidget(m_desclabel, 1, 1);
134 l1->addWidget(m_loclabel, 2, 1);
135 l1->addWidget(m_name, 0, 2);
136 l1->addWidget(m_description, 1, 2);
137 l1->addWidget(m_location, 2, 2);
140 l0->addWidget(m_outfile_gb);
141 TQGridLayout *l6 =
new TQGridLayout(m_outfile_gb->layout(), 3, 2, 10);
142 l6->addMultiCellWidget( m_usefile, 0, 0, 0, 1 );
143 l6->addWidget(m_mimetypelabel, 1, 0);
144 l6->addWidget(m_mimetype, 1, 1);
145 l6->addWidget(m_extensionlabel, 2, 0);
146 l6->addWidget(m_extension, 2, 1);
148 enableButton(Ok, !m_name->text().isEmpty());
154 void KMSpecialPrinterDlg::slotTextChanged(
const TQString & )
156 enableButton(Ok, !m_name->text().isEmpty());
159 void KMSpecialPrinterDlg::slotOk()
161 if (!checkSettings())
163 KDialogBase::slotOk();
166 bool KMSpecialPrinterDlg::checkSettings()
169 if (m_name->text().isEmpty())
170 msg = i18n(
"You must provide a non-empty name.");
172 KXmlCommandManager::self()->checkCommand(m_command->command(),
173 KXmlCommandManager::Basic,
174 (m_usefile->isChecked() ? KXmlCommandManager::Basic : KXmlCommandManager::None),
178 KMessageBox::error(
this, i18n(
"Invalid settings. %1.").arg(msg));
180 return (msg.isEmpty());
183 void KMSpecialPrinterDlg::setPrinter(KMPrinter *printer)
185 if (printer && printer->isSpecial())
187 m_command->setCommand(printer->option(
"kde-special-command"));
188 m_usefile->setChecked(printer->option(
"kde-special-file") ==
"1");
189 int index = m_mimelist.findIndex(printer->option(
"kde-special-mimetype"));
190 m_mimetype->setCurrentItem(index == -1 ? 0 : index);
191 m_extension->setText(printer->option(
"kde-special-extension"));
192 m_name->setText(printer->name());
193 m_description->setText(printer->description());
194 m_location->setText(printer->location());
195 m_icon->setIcon(printer->pixmap());
197 setCaption(i18n(
"Configuring %1").arg(printer->name()));
201 KMPrinter* KMSpecialPrinterDlg::printer()
203 KMPrinter *printer =
new KMPrinter();
204 printer->setName(m_name->text());
205 printer->setPrinterName(m_name->text());
206 printer->setPixmap(m_icon->icon());
207 printer->setDescription(m_description->text());
208 printer->setLocation(m_location->text());
209 printer->setOption(
"kde-special-command",m_command->command());
210 printer->setOption(
"kde-special-file",(m_usefile->isChecked() ?
"1" :
"0"));
211 if (m_usefile->isChecked ())
213 if (m_mimetype->currentText() !=
"all/all")
214 printer->setOption(
"kde-special-mimetype", m_mimetype->currentText());
215 printer->setOption(
"kde-special-extension",m_extension->text());
217 printer->setType(KMPrinter::Special);
218 printer->setState(KMPrinter::Idle);
222 #include "kmspecialprinterdlg.moc"