20 #include "kxmlcommanddlg.h"
22 #include "kxmlcommand.h"
27 #include <tqlineedit.h>
28 #include <tqcombobox.h>
29 #include <tqgroupbox.h>
30 #include <tqwidgetstack.h>
31 #include <tqtoolbutton.h>
32 #include <kpushbutton.h>
33 #include <tqtooltip.h>
34 #include <tqcheckbox.h>
35 #include <ktextedit.h>
37 #include <tqwhatsthis.h>
38 #include <tqapplication.h>
40 #include <tdelistview.h>
41 #include <tdelocale.h>
42 #include <kiconloader.h>
43 #include <kdialogbase.h>
44 #include <kseparator.h>
45 #include <tdelistbox.h>
46 #include <kmimetype.h>
47 #include <tdemessagebox.h>
48 #include <tdeapplication.h>
52 TQString generateId(
const TQMap<TQString, DrBase*>& map)
55 while (map.contains(TQString::fromLatin1(
"item%1").arg(++index))) ;
56 return TQString::fromLatin1(
"item%1").arg(index);
59 TQListViewItem* findPrev(TQListViewItem *item)
61 TQListViewItem *prev = item->itemAbove();
62 while (prev && prev->depth() > item->depth())
63 prev = prev->itemAbove();
64 if (prev && prev->depth() == item->depth())
70 TQListViewItem* findNext(TQListViewItem *item)
72 TQListViewItem *next = item->itemBelow();
73 while (next && next->depth() > item->depth())
74 next = next->itemBelow();
75 if (next && next->depth() == item->depth())
81 KXmlCommandAdvancedDlg::KXmlCommandAdvancedDlg(TQWidget *parent,
const char *name)
82 : TQWidget(parent, name)
86 m_command =
new TQLineEdit(
this);
87 m_view =
new TDEListView(
this);
88 m_view->addColumn(
"");
89 m_view->header()->hide();
90 m_view->setSorting(-1);
91 m_apply =
new TQToolButton(
this);
92 m_apply->setIconSet( TQApplication::reverseLayout()? SmallIconSet(
"forward" ) : SmallIconSet(
"back"));
93 m_addgrp =
new TQToolButton(
this);
94 m_addgrp->setIconSet(SmallIconSet(
"folder"));
95 m_addopt =
new TQToolButton(
this);
96 m_addopt->setIconSet(SmallIconSet(
"text-x-generic"));
97 m_delopt =
new TQToolButton(
this);
98 m_delopt->setIconSet(SmallIconSet(
"edit-delete"));
99 m_up =
new TQToolButton(
this);
100 m_up->setIconSet(SmallIconSet(
"go-up"));
101 m_down =
new TQToolButton(
this);
102 m_down->setIconSet(SmallIconSet(
"go-down"));
103 m_dummy =
new TQWidget(
this);
104 m_desc =
new TQLineEdit(m_dummy);
105 m_name =
new TQLineEdit(m_dummy);
106 m_type =
new TQComboBox(m_dummy);
107 m_type->insertItem(i18n(
"String"));
108 m_type->insertItem(i18n(
"Integer"));
109 m_type->insertItem(i18n(
"Float"));
110 m_type->insertItem(i18n(
"List"));
111 m_type->insertItem(i18n(
"Boolean"));
112 m_format =
new TQLineEdit(m_dummy);
113 m_default =
new TQLineEdit(m_dummy);
114 TQLabel *m_namelab =
new TQLabel(i18n(
"&Name:"), m_dummy);
115 TQLabel *m_desclab =
new TQLabel(i18n(
"&Description:"), m_dummy);
116 TQLabel *m_formatlab =
new TQLabel(i18n(
"&Format:"), m_dummy);
117 TQLabel *m_typelab =
new TQLabel(i18n(
"&Type:"), m_dummy);
118 TQLabel *m_defaultlab =
new TQLabel(i18n(
"Default &value:"), m_dummy);
119 TQLabel *m_commandlab =
new TQLabel(i18n(
"Co&mmand:"),
this);
120 m_namelab->setBuddy(m_name);
121 m_desclab->setBuddy(m_desc);
122 m_formatlab->setBuddy(m_format);
123 m_typelab->setBuddy(m_type);
124 m_defaultlab->setBuddy(m_default);
125 m_commandlab->setBuddy(m_command);
126 m_persistent =
new TQCheckBox( i18n(
"&Persistent option" ), m_dummy );
128 TQGroupBox *gb =
new TQGroupBox(0, TQt::Horizontal, i18n(
"Va&lues"), m_dummy);
129 m_stack =
new TQWidgetStack(gb);
130 TQWidget *w1 =
new TQWidget(m_stack), *w2 =
new TQWidget(m_stack), *w3 =
new TQWidget(m_stack);
131 m_stack->addWidget(w1, 1);
132 m_stack->addWidget(w2, 2);
133 m_stack->addWidget(w3, 3);
134 m_edit1 =
new TQLineEdit(w1);
135 m_edit2 =
new TQLineEdit(w1);
136 TQLabel *m_editlab1 =
new TQLabel(i18n(
"Minimum v&alue:"), w1);
137 TQLabel *m_editlab2 =
new TQLabel(i18n(
"Ma&ximum value:"), w1);
138 m_editlab1->setBuddy(m_edit1);
139 m_editlab2->setBuddy(m_edit2);
140 m_values =
new TDEListView(w2);
141 m_values->addColumn(i18n(
"Name"));
142 m_values->addColumn(i18n(
"Description"));
143 m_values->setAllColumnsShowFocus(
true);
144 m_values->setSorting(-1);
145 m_values->setMaximumHeight(110);
146 m_addval =
new TQToolButton(w2);
147 m_addval->setIconSet(SmallIconSet(
"edit-copy"));
148 m_delval =
new TQToolButton(w2);
149 m_delval->setIconSet(SmallIconSet(
"edit-delete"));
150 TQToolTip::add(m_addval, i18n(
"Add value"));
151 TQToolTip::add(m_delval, i18n(
"Delete value"));
153 TQToolTip::add(m_apply, i18n(
"Apply changes"));
154 TQToolTip::add(m_addgrp, i18n(
"Add group"));
155 TQToolTip::add(m_addopt, i18n(
"Add option"));
156 TQToolTip::add(m_delopt, i18n(
"Delete item"));
157 TQToolTip::add(m_up, i18n(
"Move up"));
158 TQToolTip::add(m_down, i18n(
"Move down"));
160 KSeparator *sep1 =
new KSeparator(KSeparator::HLine, m_dummy);
162 TQGroupBox *gb_input =
new TQGroupBox(0, TQt::Horizontal, i18n(
"&Input From"),
this);
163 TQGroupBox *gb_output =
new TQGroupBox(0, TQt::Horizontal, i18n(
"O&utput To"),
this);
164 TQLabel *m_inputfilelab =
new TQLabel(i18n(
"File:"), gb_input);
165 TQLabel *m_inputpipelab =
new TQLabel(i18n(
"Pipe:"), gb_input);
166 TQLabel *m_outputfilelab =
new TQLabel(i18n(
"File:"), gb_output);
167 TQLabel *m_outputpipelab =
new TQLabel(i18n(
"Pipe:"), gb_output);
168 m_inputfile =
new TQLineEdit(gb_input);
169 m_inputpipe =
new TQLineEdit(gb_input);
170 m_outputfile =
new TQLineEdit(gb_output);
171 m_outputpipe =
new TQLineEdit(gb_output);
173 m_comment =
new KTextEdit(
this );
174 m_comment->setTextFormat(TQt::RichText );
175 m_comment->setReadOnly(
true);
176 TQLabel *m_commentlab =
new TQLabel( i18n(
"Comment:" ),
this );
178 TQVBoxLayout *l2 =
new TQVBoxLayout(
this, 0, KDialog::spacingHint());
179 TQHBoxLayout *l3 =
new TQHBoxLayout(0, 0, KDialog::spacingHint());
180 TQVBoxLayout *l7 =
new TQVBoxLayout(0, 0, 0);
181 l2->addLayout(l3, 0);
182 l3->addWidget(m_commandlab);
183 l3->addWidget(m_command);
184 TQHBoxLayout *l0 =
new TQHBoxLayout(0, 0, KDialog::spacingHint());
185 TQGridLayout *l10 =
new TQGridLayout(0, 2, 2, 0, KDialog::spacingHint());
186 l2->addLayout(l0, 1);
188 l10->addMultiCellWidget(m_view, 0, 0, 0, 1);
189 l10->addWidget(gb_input, 1, 0);
190 l10->addWidget(gb_output, 1, 1);
191 l10->setRowStretch(0, 1);
193 l7->addWidget(m_apply);
195 l7->addWidget(m_addgrp);
196 l7->addWidget(m_addopt);
197 l7->addWidget(m_delopt);
200 l7->addWidget(m_down);
202 l0->addWidget(m_dummy, 1);
203 TQGridLayout *l1 =
new TQGridLayout(m_dummy, 9, 2, 0, KDialog::spacingHint());
204 l1->addWidget(m_desclab, 0, 0, TQt::AlignRight|TQt::AlignVCenter);
205 l1->addWidget(m_desc, 0, 1);
206 l1->addMultiCellWidget(sep1, 1, 1, 0, 1);
207 l1->addWidget(m_namelab, 2, 0, TQt::AlignRight|TQt::AlignVCenter);
208 l1->addWidget(m_name, 2, 1);
209 l1->addWidget(m_typelab, 3, 0, TQt::AlignRight|TQt::AlignVCenter);
210 l1->addWidget(m_type, 3, 1);
211 l1->addWidget(m_formatlab, 4, 0, TQt::AlignRight|TQt::AlignVCenter);
212 l1->addWidget(m_format, 4, 1);
213 l1->addWidget(m_defaultlab, 5, 0, TQt::AlignRight|TQt::AlignVCenter);
214 l1->addWidget(m_default, 5, 1);
215 l1->addWidget( m_persistent, 6, 1 );
216 l1->addMultiCellWidget(gb, 7, 7, 0, 1);
217 l1->setRowStretch(8, 1);
219 TQHBoxLayout *l4 =
new TQHBoxLayout(w2, 0, KDialog::spacingHint());
220 l4->addWidget(m_values);
221 TQVBoxLayout *l6 =
new TQVBoxLayout(0, 0, 0);
223 l6->addWidget(m_addval);
224 l6->addWidget(m_delval);
226 TQGridLayout *l5 =
new TQGridLayout(w1, 3, 2, 0, KDialog::spacingHint());
227 l5->setRowStretch(2, 1);
228 l5->addWidget(m_editlab1, 0, 0, TQt::AlignRight|TQt::AlignVCenter);
229 l5->addWidget(m_editlab2, 1, 0, TQt::AlignRight|TQt::AlignVCenter);
230 l5->addWidget(m_edit1, 0, 1);
231 l5->addWidget(m_edit2, 1, 1);
233 TQGridLayout *l8 =
new TQGridLayout(gb_input->layout(), 2, 2,
234 KDialog::spacingHint());
235 TQGridLayout *l9 =
new TQGridLayout(gb_output->layout(), 2, 2,
236 KDialog::spacingHint());
237 l8->addWidget(m_inputfilelab, 0, 0);
238 l8->addWidget(m_inputpipelab, 1, 0);
239 l8->addWidget(m_inputfile, 0, 1);
240 l8->addWidget(m_inputpipe, 1, 1);
241 l9->addWidget(m_outputfilelab, 0, 0);
242 l9->addWidget(m_outputpipelab, 1, 0);
243 l9->addWidget(m_outputfile, 0, 1);
244 l9->addWidget(m_outputpipe, 1, 1);
246 TQVBoxLayout *l11 =
new TQVBoxLayout(gb->layout());
247 l11->addWidget(m_stack);
249 TQVBoxLayout *l12 =
new TQVBoxLayout( 0, 0, 0 );
250 l2->addSpacing( 10 );
251 l2->addLayout( l12 );
252 l12->addWidget( m_commentlab );
253 l12->addWidget( m_comment );
255 connect(m_view, TQ_SIGNAL(selectionChanged(TQListViewItem*)), TQ_SLOT(slotSelectionChanged(TQListViewItem*)));
256 connect(m_values, TQ_SIGNAL(selectionChanged(TQListViewItem*)), TQ_SLOT(slotValueSelected(TQListViewItem*)));
257 connect(m_type, TQ_SIGNAL(activated(
int)), TQ_SLOT(slotTypeChanged(
int)));
258 connect(m_addval, TQ_SIGNAL(clicked()), TQ_SLOT(slotAddValue()));
259 connect(m_delval, TQ_SIGNAL(clicked()), TQ_SLOT(slotRemoveValue()));
260 connect(m_apply, TQ_SIGNAL(clicked()), TQ_SLOT(slotApplyChanges()));
261 connect(m_addgrp, TQ_SIGNAL(clicked()), TQ_SLOT(slotAddGroup()));
262 connect(m_addopt, TQ_SIGNAL(clicked()), TQ_SLOT(slotAddOption()));
263 connect(m_delopt, TQ_SIGNAL(clicked()), TQ_SLOT(slotRemoveItem()));
264 connect(m_up, TQ_SIGNAL(clicked()), TQ_SLOT(slotMoveUp()));
265 connect(m_down, TQ_SIGNAL(clicked()), TQ_SLOT(slotMoveDown()));
266 connect(m_command, TQ_SIGNAL(textChanged(
const TQString&)), TQ_SLOT(slotCommandChanged(
const TQString&)));
267 connect(m_view, TQ_SIGNAL(itemRenamed(TQListViewItem*,
int)), TQ_SLOT(slotOptionRenamed(TQListViewItem*,
int)));
268 connect(m_desc, TQ_SIGNAL(textChanged(
const TQString&)), TQ_SLOT(slotChanged()));
269 connect(m_name, TQ_SIGNAL(textChanged(
const TQString&)), TQ_SLOT(slotChanged()));
270 connect(m_format, TQ_SIGNAL(textChanged(
const TQString&)), TQ_SLOT(slotChanged()));
271 connect(m_default, TQ_SIGNAL(textChanged(
const TQString&)), TQ_SLOT(slotChanged()));
272 connect(m_edit1, TQ_SIGNAL(textChanged(
const TQString&)), TQ_SLOT(slotChanged()));
273 connect(m_edit2, TQ_SIGNAL(textChanged(
const TQString&)), TQ_SLOT(slotChanged()));
274 connect(m_type, TQ_SIGNAL(activated(
int)), TQ_SLOT(slotChanged()));
275 connect(m_addval, TQ_SIGNAL(clicked()), TQ_SLOT(slotChanged()));
276 connect(m_delval, TQ_SIGNAL(clicked()), TQ_SLOT(slotChanged()));
277 connect( m_persistent, TQ_SIGNAL( toggled(
bool) ), TQ_SLOT( slotChanged() ) );
278 m_dummy->setEnabled(
false);
284 TQWhatsThis::add( m_name, i18n(
285 "An identification string. Use only alphanumeric characters except spaces. "
286 "The string <b>__root__</b> is reserved for internal use." ) );
287 TQWhatsThis::add( m_namelab, TQWhatsThis::textFor( m_name ) );
288 TQWhatsThis::add( m_desc, i18n(
289 "A description string. This string is shown in the interface, and should "
290 "be explicit enough about the role of the corresponding option." ) );
291 TQWhatsThis::add( m_desclab, TQWhatsThis::textFor( m_desc ) );
292 TQWhatsThis::add( m_type, i18n(
293 "The type of the option. This determines how the option is presented "
294 "graphically to the user." ) );
295 TQWhatsThis::add( m_typelab, TQWhatsThis::textFor( m_type ) );
296 TQWhatsThis::add( m_format, i18n(
297 "The format of the option. This determines how the option is formatted "
298 "for inclusion in the global command line. The tag <b>%value</b> can be used "
299 "to represent the user selection. This tag will be replaced at run-time by a "
300 "string representation of the option value." ) );
301 TQWhatsThis::add( m_formatlab, TQWhatsThis::textFor( m_format ) );
302 TQWhatsThis::add( m_default, i18n(
303 "The default value of the option. For non persistent options, nothing is "
304 "added to the command line if the option has that default value. If this "
305 "value does not correspond to the actual default value of the underlying "
306 "utility, make the option persistent to avoid unwanted effects." ) );
307 TQWhatsThis::add( m_defaultlab, TQWhatsThis::textFor( m_default ) );
308 TQWhatsThis::add( m_persistent, i18n(
309 "Make the option persistent. A persistent option is always written to the "
310 "command line, whatever its value. This is useful when the chosen default "
311 "value does not match with the actual default value of the underlying utility." ) );
312 TQWhatsThis::add( m_command, i18n(
313 "The full command line to execute the associated underlying utility. This "
314 "command line is based on a mechanism of tags that are replaced at run-time. "
315 "The supported tags are:<ul>"
316 "<li><b>%filterargs</b>: command options</li>"
317 "<li><b>%filterinput</b>: input specification</li>"
318 "<li><b>%filteroutput</b>: output specification</li>"
319 "<li><b>%psu</b>: the page size in upper case</li>"
320 "<li><b>%psl</b>: the page size in lower case</li></ul>" ) );
321 TQWhatsThis::add( m_commandlab, TQWhatsThis::textFor( m_command ) );
322 TQWhatsThis::add( m_inputfile, i18n(
323 "Input specification when the underlying utility reads input data from a file. Use "
324 "the tag <b>%in</b> to represent the input filename." ) );
325 TQWhatsThis::add( m_inputfilelab, TQWhatsThis::textFor( m_inputfile ) );
326 TQWhatsThis::add( m_outputfile, i18n(
327 "Output specification when the underlying utility writes output data to a file. Use "
328 "the tag <b>%out</b> to represent the output filename." ) );
329 TQWhatsThis::add( m_outputfilelab, TQWhatsThis::textFor( m_outputfile ) );
330 TQWhatsThis::add( m_inputpipe, i18n(
331 "Input specification when the underlying utility reads input data from its "
332 "standard input." ) );
333 TQWhatsThis::add( m_inputpipelab, TQWhatsThis::textFor( m_inputpipe ) );
334 TQWhatsThis::add( m_outputpipe, i18n(
335 "Output specification when the underlying utility writes output data to its "
336 "standard output." ) );
337 TQWhatsThis::add( m_outputpipelab, TQWhatsThis::textFor( m_outputpipe ) );
338 TQWhatsThis::add( m_comment, i18n(
339 "A comment about the underlying utility, which can be viewed by the user "
340 "from the interface. This comment string supports basic HTML tags like "
341 "<a>, <b> or <i>." ) );
342 TQWhatsThis::add( m_commentlab, TQWhatsThis::textFor( m_comment ) );
347 KXmlCommandAdvancedDlg::~KXmlCommandAdvancedDlg()
349 if (m_opts.count() > 0)
351 kdDebug() <<
"KXmlCommandAdvancedDlg: " << m_opts.count() <<
" items remaining" << endl;
352 for (TQMap<TQString,DrBase*>::ConstIterator it=m_opts.begin(); it!=m_opts.end(); ++it)
360 void KXmlCommandAdvancedDlg::setCommand(KXmlCommand *xmlcmd)
364 parseXmlCommand(m_xmlcmd);
367 void KXmlCommandAdvancedDlg::parseXmlCommand(KXmlCommand *xmlcmd)
370 TQListViewItem *root =
new TQListViewItem(m_view, xmlcmd->name(), xmlcmd->name());
371 DrMain *driver = xmlcmd->driver();
373 root->setPixmap(0, SmallIcon(
"document-print"));
377 DrMain *clone = driver->cloneDriver();
378 if (!clone->get(
"text").isEmpty())
379 root->setText(0, clone->get(
"text"));
380 root->setText(1,
"__root__");
381 clone->setName(
"__root__");
382 m_opts[
"__root__"] = clone;
383 parseGroupItem(clone, root);
386 m_command->setText(xmlcmd->command());
387 m_inputfile->setText(xmlcmd->io(
true,
false));
388 m_inputpipe->setText(xmlcmd->io(
true,
true));
389 m_outputfile->setText(xmlcmd->io(
false,
false));
390 m_outputpipe->setText(xmlcmd->io(
false,
true));
391 m_comment->setText( xmlcmd->comment() );
396 void KXmlCommandAdvancedDlg::parseGroupItem(DrGroup *grp, TQListViewItem *parent)
398 TQListViewItem *item(0);
400 TQPtrListIterator<DrGroup> git(grp->groups());
401 for (; git.current(); ++git)
403 TQString namestr = git.current()->name();
404 if (namestr.isEmpty())
406 namestr =
"group_"+kapp->randomString(4);
408 git.current()->setName(namestr);
409 item =
new TQListViewItem(parent, item, git.current()->get(
"text"), git.current()->name());
410 item->setPixmap(0, SmallIcon(
"folder"));
412 item->setRenameEnabled(0,
true);
413 parseGroupItem(git.current(), item);
414 m_opts[namestr] = git.current();
417 TQPtrListIterator<DrBase> oit(grp->options());
418 for (; oit.current(); ++oit)
420 TQString namestr = oit.current()->name().mid(m_xmlcmd->name().length()+6);
421 if (namestr.isEmpty())
423 namestr =
"option_"+kapp->randomString(4);
425 oit.current()->setName(namestr);
426 item =
new TQListViewItem(parent, item, oit.current()->get(
"text"), namestr);
427 item->setPixmap(0, SmallIcon(
"text-x-generic"));
428 item->setRenameEnabled(0,
true);
429 m_opts[namestr] = oit.current();
433 void KXmlCommandAdvancedDlg::slotSelectionChanged(TQListViewItem *item)
435 if (item && item->depth() == 0)
440 void KXmlCommandAdvancedDlg::viewItem(TQListViewItem *item)
442 m_dummy->setEnabled((item != 0));
445 m_format->setText(
"");
446 m_default->setText(
"");
448 m_edit1->setText(
"");
449 m_edit2->setText(
"");
450 m_persistent->setChecked(
false );
454 m_name->setText(item->text(1));
455 m_desc->setText(item->text(0));
457 DrBase *opt = (m_opts.contains(item->text(1)) ? m_opts[item->text(1)] : 0);
460 bool isgroup = (opt->type() < DrBase::String);
463 m_type->setCurrentItem(opt->type() - DrBase::String);
464 typeId = m_type->currentItem();
465 m_format->setText(opt->get(
"format"));
466 m_default->setText(opt->get(
"default"));
468 m_type->setEnabled(!isgroup);
469 m_default->setEnabled(!isgroup);
470 m_format->setEnabled(!isgroup);
471 m_stack->setEnabled(!isgroup);
476 case DrBase::Integer:
477 m_edit1->setText(opt->get(
"minval"));
478 m_edit2->setText(opt->get(
"maxval"));
480 case DrBase::Boolean:
483 TQPtrListIterator<DrBase> it(*(
static_cast<DrListOption*
>(opt)->choices()));
484 TQListViewItem *item(0);
485 for (; it.current(); ++it)
487 item =
new TQListViewItem(m_values, item, it.current()->name(), it.current()->get(
"text"));
488 item->setRenameEnabled(0,
true);
489 item->setRenameEnabled(1,
true);
497 m_addgrp->setEnabled(isgroup);
498 m_addopt->setEnabled(isgroup);
500 TQListViewItem *prevItem = findPrev(item), *nextItem = findNext(item);
501 DrBase *prevOpt = (prevItem && m_opts.contains(prevItem->text(1)) ? m_opts[prevItem->text(1)] : 0);
502 DrBase *nextOpt = (nextItem && m_opts.contains(nextItem->text(1)) ? m_opts[nextItem->text(1)] : 0);
503 m_up->setEnabled(prevOpt && !(prevOpt->type() < DrBase::String && opt->type() >= DrBase::String));
504 m_down->setEnabled(nextOpt && !(isgroup && nextOpt->type() >= DrBase::String));
506 m_persistent->setChecked( opt->get(
"persistent" ) ==
"1" );
509 m_delopt->setEnabled(
true);
510 m_dummy->setEnabled(opt);
514 m_delopt->setEnabled(
false);
515 m_addopt->setEnabled(m_view->currentItem() && m_view->isEnabled());
516 m_addgrp->setEnabled(m_view->currentItem() && m_view->isEnabled());
517 m_up->setEnabled(
false);
518 m_down->setEnabled(
false);
520 slotTypeChanged(typeId);
521 m_apply->setEnabled(
false);
524 void KXmlCommandAdvancedDlg::slotTypeChanged(
int ID)
527 ID += DrBase::String;
531 case DrBase::Integer:
534 case DrBase::Boolean:
537 slotValueSelected(m_values->currentItem());
540 m_stack->raiseWidget(wId);
543 void KXmlCommandAdvancedDlg::slotAddValue()
545 TQListViewItem *item =
new TQListViewItem(m_values, m_values->lastItem(), i18n(
"Name"), i18n(
"Description"));
546 item->setRenameEnabled(0,
true);
547 item->setRenameEnabled(1,
true);
548 m_values->ensureItemVisible(item);
549 slotValueSelected(item);
550 item->startRename(0);
553 void KXmlCommandAdvancedDlg::slotRemoveValue()
555 TQListViewItem *item = m_values->currentItem();
558 slotValueSelected(m_values->currentItem());
561 void KXmlCommandAdvancedDlg::slotApplyChanges()
563 TQListViewItem *item = m_view->currentItem();
566 if (m_name->text().isEmpty() || m_name->text() ==
"__root__")
568 KMessageBox::error(
this, i18n(
"Invalid identification name. Empty strings and \"__root__\" are not allowed."));
572 m_apply->setEnabled(
false);
574 DrBase *opt = (m_opts.contains(item->text(1)) ? m_opts[item->text(1)] : 0);
575 m_opts.remove(item->text(1));
579 item->setText(0, m_desc->text());
580 item->setText(1, m_name->text());
583 if (m_type->isEnabled())
585 int type = m_type->currentItem() + DrBase::String;
588 case DrBase::Integer:
590 if (type == DrBase::Integer)
591 opt =
new DrIntegerOption;
593 opt =
new DrFloatOption;
594 opt->set(
"minval", m_edit1->text());
595 opt->set(
"maxval", m_edit2->text());
598 case DrBase::Boolean:
600 if (type == DrBase::List)
601 opt =
new DrListOption;
603 opt =
new DrBooleanOption;
604 DrListOption *lopt =
static_cast<DrListOption*
>(opt);
605 TQListViewItem *item = m_values->firstChild();
608 DrBase *choice =
new DrBase;
609 choice->setName(item->text(0));
610 choice->set(
"text", item->text(1));
611 lopt->addChoice(choice);
612 item = item->nextSibling();
617 opt =
new DrStringOption;
621 opt->set(
"format", m_format->text());
622 opt->set(
"default", m_default->text());
623 opt->setValueText(opt->get(
"default"));
628 opt->setName((m_name->text().isEmpty() ? generateId(m_opts) : m_name->text()));
629 opt->set(
"text", m_desc->text());
630 opt->set(
"persistent", m_persistent->isChecked() ?
"1" :
"0" );
632 m_opts[opt->name()] = opt;
636 void KXmlCommandAdvancedDlg::slotChanged()
638 m_apply->setEnabled(
true);
641 void KXmlCommandAdvancedDlg::slotAddGroup()
643 if (m_view->currentItem())
645 TQString ID = generateId(m_opts);
647 DrGroup *grp =
new DrGroup;
649 grp->set(
"text", i18n(
"New Group"));
652 TQListViewItem *item =
new TQListViewItem(m_view->currentItem(), i18n(
"New Group"), ID);
653 item->setRenameEnabled(0,
true);
654 item->setPixmap(0, SmallIcon(
"folder"));
655 m_view->ensureItemVisible(item);
656 item->startRename(0);
660 void KXmlCommandAdvancedDlg::slotAddOption()
662 if (m_view->currentItem())
664 TQString ID = generateId(m_opts);
666 DrBase *opt =
new DrStringOption;
668 opt->set(
"text", i18n(
"New Option"));
671 TQListViewItem *item =
new TQListViewItem(m_view->currentItem(), i18n(
"New Option"), ID);
672 item->setRenameEnabled(0,
true);
673 item->setPixmap(0, SmallIcon(
"text-x-generic"));
674 m_view->ensureItemVisible(item);
675 item->startRename(0);
679 void KXmlCommandAdvancedDlg::slotRemoveItem()
681 TQListViewItem *item = m_view->currentItem();
684 TQListViewItem *newCurrent(item->nextSibling());
686 newCurrent = item->parent();
689 m_view->setSelected(newCurrent,
true);
693 void KXmlCommandAdvancedDlg::removeItem(TQListViewItem *item)
695 delete m_opts[item->text(1)];
696 m_opts.remove(item->text(1));
697 TQListViewItem *child = item->firstChild();
698 while (child && item)
702 item = item->nextSibling();
706 void KXmlCommandAdvancedDlg::slotMoveUp()
708 TQListViewItem *item = m_view->currentItem(), *prev = 0;
709 if (item && (prev=findPrev(item)))
711 TQListViewItem *after(0);
712 if ((after=findPrev(prev)) != 0)
713 item->moveItem(after);
716 TQListViewItem *parent = item->parent();
717 parent->takeItem(item);
718 parent->insertItem(item);
720 m_view->setSelected(item,
true);
721 slotSelectionChanged(item);
725 void KXmlCommandAdvancedDlg::slotMoveDown()
727 TQListViewItem *item = m_view->currentItem(), *next = 0;
728 if (item && (next=findNext(item)))
730 item->moveItem(next);
731 m_view->setSelected(item,
true);
732 slotSelectionChanged(item);
736 void KXmlCommandAdvancedDlg::slotCommandChanged(
const TQString& cmd)
738 m_inputfile->parentWidget()->setEnabled(cmd.find(
"%filterinput") != -1);
739 m_outputfile->parentWidget()->setEnabled(cmd.find(
"%filteroutput") != -1);
740 m_view->setEnabled(cmd.find(
"%filterargs") != -1);
741 m_name->parentWidget()->setEnabled(m_view->isEnabled());
742 slotSelectionChanged((m_view->isEnabled() ? m_view->currentItem() : 0));
743 m_view->setOpen(m_view->firstChild(), m_view->isEnabled());
746 void KXmlCommandAdvancedDlg::slotValueSelected(TQListViewItem *item)
748 m_addval->setEnabled(m_type->currentItem() != 4 || m_values->childCount() < 2);
749 m_delval->setEnabled(item != 0);
752 void KXmlCommandAdvancedDlg::slotOptionRenamed(TQListViewItem *item,
int)
754 if (item && m_opts.contains(item->text(1)))
756 DrBase *opt = m_opts[item->text(1)];
757 opt->set(
"text", item->text(0));
758 slotSelectionChanged(item);
762 void KXmlCommandAdvancedDlg::recreateGroup(TQListViewItem *item, DrGroup *grp)
767 TQListViewItem *child = item->firstChild();
770 DrBase *opt = (m_opts.contains(child->text(1)) ? m_opts[child->text(1)] : 0);
773 if (opt->type() == DrBase::Group)
775 DrGroup *childGroup =
static_cast<DrGroup*
>(opt);
776 recreateGroup(child, childGroup);
777 grp->addGroup(childGroup);
781 opt->setName(
"_kde-"+m_xmlcmd->name()+
"-"+opt->name());
784 m_opts.remove(child->text(1));
786 child = child->nextSibling();
790 bool KXmlCommandAdvancedDlg::editCommand(KXmlCommand *xmlcmd, TQWidget *parent)
795 KDialogBase dlg(parent, 0,
true, i18n(
"Command Edit for %1").arg(xmlcmd->name()), KDialogBase::Ok|KDialogBase::Cancel, KDialogBase::Ok,
false);
796 KXmlCommandAdvancedDlg *xmldlg =
new KXmlCommandAdvancedDlg(&dlg);
797 dlg.setMainWidget(xmldlg);
799 xmldlg->setCommand(xmlcmd);
802 xmlcmd->setCommand(xmldlg->m_command->text());
803 xmlcmd->setIo(xmldlg->m_inputfile->text(),
true,
false);
804 xmlcmd->setIo(xmldlg->m_inputpipe->text(),
true,
true);
805 xmlcmd->setIo(xmldlg->m_outputfile->text(),
false,
false);
806 xmlcmd->setIo(xmldlg->m_outputpipe->text(),
false,
true);
807 xmlcmd->setComment( xmldlg->m_comment->text().replace( TQRegExp(
"\n" ),
" " ) );
810 DrMain *driver = (xmldlg->m_opts.contains(
"__root__") ?
static_cast<DrMain*
>(xmldlg->m_opts[
"__root__"]) : 0);
811 if (!driver && xmldlg->m_opts.count() > 0)
813 kdDebug() <<
"KXmlCommandAdvancedDlg: driver structure not found, creating one" << endl;
815 driver->setName(xmlcmd->name());
817 xmldlg->recreateGroup(xmldlg->m_view->firstChild(), driver);
818 xmldlg->m_opts.remove(
"__root__");
819 xmlcmd->setDriver(driver);
830 KXmlCommandDlg::KXmlCommandDlg(TQWidget *parent,
const char *name)
831 : KDialogBase(parent, name, true, TQString::null, Ok|Cancel|Details, Ok, true)
833 setButtonText(Details, i18n(
"&Mime Type Settings"));
836 TQWidget *dummy =
new TQWidget(
this,
"TopDetail");
837 TQWidget *topmain =
new TQWidget(
this,
"TopMain");
839 TQGroupBox *m_gb1 =
new TQGroupBox(0, TQt::Horizontal, i18n(
"Supported &Input Formats"), dummy);
840 TQGroupBox *m_gb2 =
new TQGroupBox(0, TQt::Horizontal, i18n(
"Requirements"), topmain);
842 m_description =
new TQLineEdit(topmain);
843 m_idname =
new TQLabel(topmain);
844 m_requirements =
new TDEListView(m_gb2);
845 m_requirements->addColumn(
"");
846 m_requirements->header()->hide();
847 m_addreq =
new TQToolButton(m_gb2);
848 m_addreq->setIconSet(SmallIconSet(
"document-new"));
849 m_removereq =
new TQToolButton(m_gb2);
850 m_removereq->setIconSet(SmallIconSet(
"edit-delete"));
851 TQPushButton *m_edit =
new KPushButton(KGuiItem(i18n(
"&Edit Command..."),
"edit"), topmain);
852 m_mimetype =
new TQComboBox(dummy);
853 m_availablemime =
new TDEListBox(m_gb1);
854 m_selectedmime =
new TDEListBox(m_gb1);
855 m_addmime =
new TQToolButton(m_gb1);
856 m_addmime->setIconSet(TQApplication::reverseLayout()? SmallIconSet(
"forward") : SmallIconSet(
"back"));
857 m_removemime =
new TQToolButton(m_gb1);
858 m_removemime->setIconSet(TQApplication::reverseLayout()? SmallIconSet(
"back" ) : SmallIconSet(
"forward"));
859 m_gb2->setMinimumWidth(380);
860 m_gb1->setMinimumHeight(180);
861 m_requirements->setMaximumHeight(80);
862 m_removereq->setEnabled(
false);
863 m_addmime->setEnabled(
false);
864 m_removemime->setEnabled(
false);
866 TQLabel *m_desclab =
new TQLabel(i18n(
"&Description:"), topmain);
867 m_desclab->setBuddy(m_description);
868 TQLabel *m_mimetypelab =
new TQLabel(i18n(
"Output &format:"), dummy);
869 m_mimetypelab->setBuddy(m_mimetype);
870 TQLabel *m_idnamelab =
new TQLabel(i18n(
"ID name:"), topmain);
872 TQFont f(m_idname->font());
874 m_idname->setFont(f);
876 KSeparator *sep1 =
new KSeparator(TQFrame::HLine, dummy);
878 TQVBoxLayout *l0 =
new TQVBoxLayout(topmain, 0, 10);
879 TQGridLayout *l5 =
new TQGridLayout(0, 2, 2, 0, 5);
881 l5->addWidget(m_idnamelab, 0, 0);
882 l5->addWidget(m_idname, 0, 1);
883 l5->addWidget(m_desclab, 1, 0);
884 l5->addWidget(m_description, 1, 1);
885 l0->addWidget(m_gb2);
886 TQHBoxLayout *l3 =
new TQHBoxLayout(0, 0, 0);
888 l3->addWidget(m_edit);
891 TQVBoxLayout *l7 =
new TQVBoxLayout(dummy, 0, 10);
892 TQHBoxLayout *l6 =
new TQHBoxLayout(0, 0, 5);
895 l6->addWidget(m_mimetypelab, 0);
896 l6->addWidget(m_mimetype, 1);
897 l7->addWidget(m_gb1);
898 TQGridLayout *l2 =
new TQGridLayout(m_gb1->layout(), 4, 3, 10);
899 l2->addMultiCellWidget(m_availablemime, 0, 3, 2, 2);
900 l2->addMultiCellWidget(m_selectedmime, 0, 3, 0, 0);
901 l2->addWidget(m_addmime, 1, 1);
902 l2->addWidget(m_removemime, 2, 1);
903 l2->setRowStretch(0, 1);
904 l2->setRowStretch(3, 1);
905 TQHBoxLayout *l4 =
new TQHBoxLayout(m_gb2->layout(), 10);
906 l4->addWidget(m_requirements);
907 TQVBoxLayout *l8 =
new TQVBoxLayout(0, 0, 0);
909 l8->addWidget(m_addreq);
910 l8->addWidget(m_removereq);
913 connect(m_addmime, TQ_SIGNAL(clicked()), TQ_SLOT(slotAddMime()));
914 connect(m_removemime, TQ_SIGNAL(clicked()), TQ_SLOT(slotRemoveMime()));
915 connect(m_edit, TQ_SIGNAL(clicked()), TQ_SLOT(slotEditCommand()));
916 connect(m_requirements, TQ_SIGNAL(selectionChanged(TQListViewItem*)), TQ_SLOT(slotReqSelected(TQListViewItem*)));
917 connect(m_availablemime, TQ_SIGNAL(selectionChanged(TQListBoxItem*)), TQ_SLOT(slotAvailableSelected(TQListBoxItem*)));
918 connect(m_selectedmime, TQ_SIGNAL(selectionChanged(TQListBoxItem*)), TQ_SLOT(slotSelectedSelected(TQListBoxItem*)));
919 connect(m_addreq, TQ_SIGNAL(clicked()), TQ_SLOT(slotAddReq()));
920 connect(m_removereq, TQ_SIGNAL(clicked()), TQ_SLOT(slotRemoveReq()));
922 KMimeType::List list = KMimeType::allMimeTypes();
923 for (TQValueList<KMimeType::Ptr>::ConstIterator it=list.begin(); it!=list.end(); ++it)
925 TQString mimetype = (*it)->name();
926 m_mimelist << mimetype;
930 m_mimetype->insertStringList(m_mimelist);
931 m_availablemime->insertStringList(m_mimelist);
933 setMainWidget(topmain);
934 setDetailsWidget(dummy);
937 void KXmlCommandDlg::setCommand(KXmlCommand *xmlCmd)
939 setCaption(i18n(
"Command Edit for %1").arg(xmlCmd->name()));
942 m_description->setText(i18n(xmlCmd->description().utf8()));
943 m_idname->setText(xmlCmd->name());
945 m_requirements->clear();
946 TQStringList list = xmlCmd->requirements();
947 TQListViewItem *item(0);
948 for (TQStringList::ConstIterator it=list.begin(); it!=list.end(); ++it)
950 item =
new TQListViewItem(m_requirements, item, *it);
951 item->setRenameEnabled(0,
true);
954 int index = m_mimelist.findIndex(xmlCmd->mimeType());
956 m_mimetype->setCurrentItem(index);
958 m_mimetype->setCurrentItem(0);
960 list = xmlCmd->inputMimeTypes();
961 m_selectedmime->clear();
962 m_availablemime->clear();
963 m_availablemime->insertStringList(m_mimelist);
964 for (TQStringList::ConstIterator it=list.begin(); it!=list.end(); ++it)
966 m_selectedmime->insertItem(*it);
967 delete m_availablemime->findItem(*it, TQt::ExactMatch);
971 void KXmlCommandDlg::slotOk()
975 m_cmd->setMimeType((m_mimetype->currentText() ==
"all/all" ? TQString::null : m_mimetype->currentText()));
976 m_cmd->setDescription(m_description->text());
978 TQListViewItem *item = m_requirements->firstChild();
982 item = item->nextSibling();
984 m_cmd->setRequirements(l);
986 for (uint i=0; i<m_selectedmime->count(); i++)
987 l << m_selectedmime->text(i);
988 m_cmd->setInputMimeTypes(l);
990 KDialogBase::slotOk();
993 bool KXmlCommandDlg::editCommand(KXmlCommand *xmlCmd, TQWidget *parent)
998 KXmlCommandDlg xmldlg(parent, 0);
999 xmldlg.setCommand(xmlCmd);
1001 return (xmldlg.exec() == Accepted);
1004 void KXmlCommandDlg::slotAddMime()
1006 int index = m_availablemime->currentItem();
1009 m_selectedmime->insertItem(m_availablemime->currentText());
1010 m_availablemime->removeItem(index);
1011 m_selectedmime->sort();
1015 void KXmlCommandDlg::slotRemoveMime()
1017 int index = m_selectedmime->currentItem();
1020 m_availablemime->insertItem(m_selectedmime->currentText());
1021 m_selectedmime->removeItem(index);
1022 m_availablemime->sort();
1026 void KXmlCommandDlg::slotEditCommand()
1028 KXmlCommandAdvancedDlg::editCommand(m_cmd, parentWidget());
1031 void KXmlCommandDlg::slotAddReq()
1033 TQListViewItem *item =
new TQListViewItem(m_requirements, m_requirements->lastItem(), i18n(
"exec:/"));
1034 item->setRenameEnabled(0,
true);
1035 m_requirements->ensureItemVisible(item);
1036 item->startRename(0);
1039 void KXmlCommandDlg::slotRemoveReq()
1041 delete m_requirements->currentItem();
1044 void KXmlCommandDlg::slotReqSelected(TQListViewItem *item)
1046 m_removereq->setEnabled(item);
1049 void KXmlCommandDlg::slotAvailableSelected(TQListBoxItem *item)
1051 m_addmime->setEnabled(item);
1054 void KXmlCommandDlg::slotSelectedSelected(TQListBoxItem *item)
1056 m_removemime->setEnabled(item);
1059 #include "kxmlcommanddlg.moc"