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

tdeprint

  • tdeprint
  • management
kxmlcommanddlg.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 "kxmlcommanddlg.h"
21 #include "driver.h"
22 #include "kxmlcommand.h"
23 
24 #include <tqlayout.h>
25 #include <tqheader.h>
26 #include <tqlabel.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>
36 #include <tqregexp.h>
37 #include <tqwhatsthis.h>
38 #include <tqapplication.h>
39 
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>
49 #include <kdebug.h>
50 #include <kguiitem.h>
51 
52 TQString generateId(const TQMap<TQString, DrBase*>& map)
53 {
54  int index(-1);
55  while (map.contains(TQString::fromLatin1("item%1").arg(++index))) ;
56  return TQString::fromLatin1("item%1").arg(index);
57 }
58 
59 TQListViewItem* findPrev(TQListViewItem *item)
60 {
61  TQListViewItem *prev = item->itemAbove();
62  while (prev && prev->depth() > item->depth())
63  prev = prev->itemAbove();
64  if (prev && prev->depth() == item->depth())
65  return prev;
66  else
67  return 0;
68 }
69 
70 TQListViewItem* findNext(TQListViewItem *item)
71 {
72  TQListViewItem *next = item->itemBelow();
73  while (next && next->depth() > item->depth())
74  next = next->itemBelow();
75  if (next && next->depth() == item->depth())
76  return next;
77  else
78  return 0;
79 }
80 
81 KXmlCommandAdvancedDlg::KXmlCommandAdvancedDlg(TQWidget *parent, const char *name)
82 : TQWidget(parent, name)
83 {
84  m_xmlcmd = 0;
85 
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 );
127 
128  TQGroupBox *gb = new TQGroupBox(0, Qt::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"));
152 
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"));
159 
160  KSeparator *sep1 = new KSeparator(KSeparator::HLine, m_dummy);
161 
162  TQGroupBox *gb_input = new TQGroupBox(0, Qt::Horizontal, i18n("&Input From"), this);
163  TQGroupBox *gb_output = new TQGroupBox(0, Qt::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);
172 
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 );
177 
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);
187  l0->addLayout(TQT_TQLAYOUT(l10));
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);
192  l0->addLayout(l7);
193  l7->addWidget(m_apply);
194  l7->addSpacing(5);
195  l7->addWidget(m_addgrp);
196  l7->addWidget(m_addopt);
197  l7->addWidget(m_delopt);
198  l7->addSpacing(5);
199  l7->addWidget(m_up);
200  l7->addWidget(m_down);
201  l7->addStretch(1);
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, Qt::AlignRight|Qt::AlignVCenter);
205  l1->addWidget(m_desc, 0, 1);
206  l1->addMultiCellWidget(sep1, 1, 1, 0, 1);
207  l1->addWidget(m_namelab, 2, 0, Qt::AlignRight|Qt::AlignVCenter);
208  l1->addWidget(m_name, 2, 1);
209  l1->addWidget(m_typelab, 3, 0, Qt::AlignRight|Qt::AlignVCenter);
210  l1->addWidget(m_type, 3, 1);
211  l1->addWidget(m_formatlab, 4, 0, Qt::AlignRight|Qt::AlignVCenter);
212  l1->addWidget(m_format, 4, 1);
213  l1->addWidget(m_defaultlab, 5, 0, Qt::AlignRight|Qt::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);
218 
219  TQHBoxLayout *l4 = new TQHBoxLayout(w2, 0, KDialog::spacingHint());
220  l4->addWidget(m_values);
221  TQVBoxLayout *l6 = new TQVBoxLayout(0, 0, 0);
222  l4->addLayout(l6);
223  l6->addWidget(m_addval);
224  l6->addWidget(m_delval);
225  l6->addStretch(1);
226  TQGridLayout *l5 = new TQGridLayout(w1, 3, 2, 0, KDialog::spacingHint());
227  l5->setRowStretch(2, 1);
228  l5->addWidget(m_editlab1, 0, 0, Qt::AlignRight|Qt::AlignVCenter);
229  l5->addWidget(m_editlab2, 1, 0, Qt::AlignRight|Qt::AlignVCenter);
230  l5->addWidget(m_edit1, 0, 1);
231  l5->addWidget(m_edit2, 1, 1);
232 
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);
245 
246  TQVBoxLayout *l11 = new TQVBoxLayout(TQT_TQLAYOUT(gb->layout()));
247  l11->addWidget(m_stack);
248 
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 );
254 
255  connect(m_view, TQT_SIGNAL(selectionChanged(TQListViewItem*)), TQT_SLOT(slotSelectionChanged(TQListViewItem*)));
256  connect(m_values, TQT_SIGNAL(selectionChanged(TQListViewItem*)), TQT_SLOT(slotValueSelected(TQListViewItem*)));
257  connect(m_type, TQT_SIGNAL(activated(int)), TQT_SLOT(slotTypeChanged(int)));
258  connect(m_addval, TQT_SIGNAL(clicked()), TQT_SLOT(slotAddValue()));
259  connect(m_delval, TQT_SIGNAL(clicked()), TQT_SLOT(slotRemoveValue()));
260  connect(m_apply, TQT_SIGNAL(clicked()), TQT_SLOT(slotApplyChanges()));
261  connect(m_addgrp, TQT_SIGNAL(clicked()), TQT_SLOT(slotAddGroup()));
262  connect(m_addopt, TQT_SIGNAL(clicked()), TQT_SLOT(slotAddOption()));
263  connect(m_delopt, TQT_SIGNAL(clicked()), TQT_SLOT(slotRemoveItem()));
264  connect(m_up, TQT_SIGNAL(clicked()), TQT_SLOT(slotMoveUp()));
265  connect(m_down, TQT_SIGNAL(clicked()), TQT_SLOT(slotMoveDown()));
266  connect(m_command, TQT_SIGNAL(textChanged(const TQString&)), TQT_SLOT(slotCommandChanged(const TQString&)));
267  connect(m_view, TQT_SIGNAL(itemRenamed(TQListViewItem*,int)), TQT_SLOT(slotOptionRenamed(TQListViewItem*,int)));
268  connect(m_desc, TQT_SIGNAL(textChanged(const TQString&)), TQT_SLOT(slotChanged()));
269  connect(m_name, TQT_SIGNAL(textChanged(const TQString&)), TQT_SLOT(slotChanged()));
270  connect(m_format, TQT_SIGNAL(textChanged(const TQString&)), TQT_SLOT(slotChanged()));
271  connect(m_default, TQT_SIGNAL(textChanged(const TQString&)), TQT_SLOT(slotChanged()));
272  connect(m_edit1, TQT_SIGNAL(textChanged(const TQString&)), TQT_SLOT(slotChanged()));
273  connect(m_edit2, TQT_SIGNAL(textChanged(const TQString&)), TQT_SLOT(slotChanged()));
274  connect(m_type, TQT_SIGNAL(activated(int)), TQT_SLOT(slotChanged()));
275  connect(m_addval, TQT_SIGNAL(clicked()), TQT_SLOT(slotChanged()));
276  connect(m_delval, TQT_SIGNAL(clicked()), TQT_SLOT(slotChanged()));
277  connect( m_persistent, TQT_SIGNAL( toggled(bool) ), TQT_SLOT( slotChanged() ) );
278  m_dummy->setEnabled(false);
279  viewItem(0);
280 
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  "&lt;a&gt;, &lt;b&gt; or &lt;i&gt;." ) );
342  TQWhatsThis::add( m_commentlab, TQWhatsThis::textFor( m_comment ) );
343 
344  resize(660, 200);
345 }
346 
347 KXmlCommandAdvancedDlg::~KXmlCommandAdvancedDlg()
348 {
349  if (m_opts.count() > 0)
350  {
351  kdDebug() << "KXmlCommandAdvancedDlg: " << m_opts.count() << " items remaining" << endl;
352  for (TQMap<TQString,DrBase*>::ConstIterator it=m_opts.begin(); it!=m_opts.end(); ++it)
353  {
354  //kdDebug() << "Item: name=" << (*it)->name() << endl;
355  delete (*it);
356  }
357  }
358 }
359 
360 void KXmlCommandAdvancedDlg::setCommand(KXmlCommand *xmlcmd)
361 {
362  m_xmlcmd = xmlcmd;
363  if (m_xmlcmd)
364  parseXmlCommand(m_xmlcmd);
365 }
366 
367 void KXmlCommandAdvancedDlg::parseXmlCommand(KXmlCommand *xmlcmd)
368 {
369  m_view->clear();
370  TQListViewItem *root = new TQListViewItem(m_view, xmlcmd->name(), xmlcmd->name());
371  DrMain *driver = xmlcmd->driver();
372 
373  root->setPixmap(0, SmallIcon("document-print"));
374  root->setOpen(true);
375  if (driver)
376  {
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);
384  clone->flatten();
385  }
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() );
392 
393  viewItem(0);
394 }
395 
396 void KXmlCommandAdvancedDlg::parseGroupItem(DrGroup *grp, TQListViewItem *parent)
397 {
398  TQListViewItem *item(0);
399 
400  TQPtrListIterator<DrGroup> git(grp->groups());
401  for (; git.current(); ++git)
402  {
403  TQString namestr = git.current()->name();
404  if (namestr.isEmpty())
405  {
406  namestr = "group_"+kapp->randomString(4);
407  }
408  git.current()->setName(namestr);
409  item = new TQListViewItem(parent, item, git.current()->get("text"), git.current()->name());
410  item->setPixmap(0, SmallIcon("folder"));
411  item->setOpen(true);
412  item->setRenameEnabled(0, true);
413  parseGroupItem(git.current(), item);
414  m_opts[namestr] = git.current();
415  }
416 
417  TQPtrListIterator<DrBase> oit(grp->options());
418  for (; oit.current(); ++oit)
419  {
420  TQString namestr = oit.current()->name().mid(m_xmlcmd->name().length()+6);
421  if (namestr.isEmpty())
422  {
423  namestr = "option_"+kapp->randomString(4);
424  }
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();
430  }
431 }
432 
433 void KXmlCommandAdvancedDlg::slotSelectionChanged(TQListViewItem *item)
434 {
435  if (item && item->depth() == 0)
436  item = 0;
437  viewItem(item);
438 }
439 
440 void KXmlCommandAdvancedDlg::viewItem(TQListViewItem *item)
441 {
442  m_dummy->setEnabled((item != 0));
443  m_name->setText("");
444  m_desc->setText("");
445  m_format->setText("");
446  m_default->setText("");
447  m_values->clear();
448  m_edit1->setText("");
449  m_edit2->setText("");
450  m_persistent->setChecked( false );
451  int typeId(-1);
452  if (item)
453  {
454  m_name->setText(item->text(1));
455  m_desc->setText(item->text(0));
456 
457  DrBase *opt = (m_opts.contains(item->text(1)) ? m_opts[item->text(1)] : 0);
458  if (opt)
459  {
460  bool isgroup = (opt->type() < DrBase::String);
461  if (!isgroup)
462  {
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"));
467  }
468  m_type->setEnabled(!isgroup);
469  m_default->setEnabled(!isgroup);
470  m_format->setEnabled(!isgroup);
471  m_stack->setEnabled(!isgroup);
472 
473  switch (opt->type())
474  {
475  case DrBase::Float:
476  case DrBase::Integer:
477  m_edit1->setText(opt->get("minval"));
478  m_edit2->setText(opt->get("maxval"));
479  break;
480  case DrBase::Boolean:
481  case DrBase::List:
482  {
483  TQPtrListIterator<DrBase> it(*(static_cast<DrListOption*>(opt)->choices()));
484  TQListViewItem *item(0);
485  for (; it.current(); ++it)
486  {
487  item = new TQListViewItem(m_values, item, it.current()->name(), it.current()->get("text"));
488  item->setRenameEnabled(0, true);
489  item->setRenameEnabled(1, true);
490  }
491  break;
492  }
493  default:
494  break;
495  }
496 
497  m_addgrp->setEnabled(isgroup);
498  m_addopt->setEnabled(isgroup);
499 
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));
505 
506  m_persistent->setChecked( opt->get( "persistent" ) == "1" );
507  }
508 
509  m_delopt->setEnabled(true);
510  m_dummy->setEnabled(opt);
511  }
512  else
513  {
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);
519  }
520  slotTypeChanged(typeId);
521  m_apply->setEnabled(false);
522 }
523 
524 void KXmlCommandAdvancedDlg::slotTypeChanged(int ID)
525 {
526  int wId(3);
527  ID += DrBase::String;
528  switch (ID)
529  {
530  case DrBase::Float:
531  case DrBase::Integer:
532  wId = 1;
533  break;
534  case DrBase::Boolean:
535  case DrBase::List:
536  wId = 2;
537  slotValueSelected(m_values->currentItem());
538  break;
539  }
540  m_stack->raiseWidget(wId);
541 }
542 
543 void KXmlCommandAdvancedDlg::slotAddValue()
544 {
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);
551 }
552 
553 void KXmlCommandAdvancedDlg::slotRemoveValue()
554 {
555  TQListViewItem *item = m_values->currentItem();
556  if (item)
557  delete item;
558  slotValueSelected(m_values->currentItem());
559 }
560 
561 void KXmlCommandAdvancedDlg::slotApplyChanges()
562 {
563  TQListViewItem *item = m_view->currentItem();
564  if (item)
565  {
566  if (m_name->text().isEmpty() || m_name->text() == "__root__")
567  {
568  KMessageBox::error(this, i18n("Invalid identification name. Empty strings and \"__root__\" are not allowed."));
569  return;
570  }
571 
572  m_apply->setEnabled(false);
573 
574  DrBase *opt = (m_opts.contains(item->text(1)) ? m_opts[item->text(1)] : 0);
575  m_opts.remove(item->text(1));
576  delete opt;
577 
578  // update tree item
579  item->setText(0, m_desc->text());
580  item->setText(1, m_name->text());
581 
582  // recreate option
583  if (m_type->isEnabled())
584  {
585  int type = m_type->currentItem() + DrBase::String;
586  switch (type)
587  {
588  case DrBase::Integer:
589  case DrBase::Float:
590  if (type == DrBase::Integer)
591  opt = new DrIntegerOption;
592  else
593  opt = new DrFloatOption;
594  opt->set("minval", m_edit1->text());
595  opt->set("maxval", m_edit2->text());
596  break;
597  case DrBase::List:
598  case DrBase::Boolean:
599  {
600  if (type == DrBase::List)
601  opt = new DrListOption;
602  else
603  opt = new DrBooleanOption;
604  DrListOption *lopt = static_cast<DrListOption*>(opt);
605  TQListViewItem *item = m_values->firstChild();
606  while (item)
607  {
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();
613  }
614  break;
615  }
616  case DrBase::String:
617  opt = new DrStringOption;
618  break;
619 
620  }
621  opt->set("format", m_format->text());
622  opt->set("default", m_default->text());
623  opt->setValueText(opt->get("default"));
624  }
625  else
626  opt = new DrGroup;
627 
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" );
631 
632  m_opts[opt->name()] = opt;
633  }
634 }
635 
636 void KXmlCommandAdvancedDlg::slotChanged()
637 {
638  m_apply->setEnabled(true);
639 }
640 
641 void KXmlCommandAdvancedDlg::slotAddGroup()
642 {
643  if (m_view->currentItem())
644  {
645  TQString ID = generateId(m_opts);
646 
647  DrGroup *grp = new DrGroup;
648  grp->setName(ID);
649  grp->set("text", i18n("New Group"));
650  m_opts[ID] = grp;
651 
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);
657  }
658 }
659 
660 void KXmlCommandAdvancedDlg::slotAddOption()
661 {
662  if (m_view->currentItem())
663  {
664  TQString ID = generateId(m_opts);
665 
666  DrBase *opt = new DrStringOption;
667  opt->setName(ID);
668  opt->set("text", i18n("New Option"));
669  m_opts[ID] = opt;
670 
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);
676  }
677 }
678 
679 void KXmlCommandAdvancedDlg::slotRemoveItem()
680 {
681  TQListViewItem *item = m_view->currentItem();
682  if (item)
683  {
684  TQListViewItem *newCurrent(item->nextSibling());
685  if (!newCurrent)
686  newCurrent = item->parent();
687  removeItem(item);
688  delete item;
689  m_view->setSelected(newCurrent, true);
690  }
691 }
692 
693 void KXmlCommandAdvancedDlg::removeItem(TQListViewItem *item)
694 {
695  delete m_opts[item->text(1)];
696  m_opts.remove(item->text(1));
697  TQListViewItem *child = item->firstChild();
698  while (child && item)
699  {
700  removeItem(child);
701  if ( item )
702  item = item->nextSibling();
703  }
704 }
705 
706 void KXmlCommandAdvancedDlg::slotMoveUp()
707 {
708  TQListViewItem *item = m_view->currentItem(), *prev = 0;
709  if (item && (prev=findPrev(item)))
710  {
711  TQListViewItem *after(0);
712  if ((after=findPrev(prev)) != 0)
713  item->moveItem(after);
714  else
715  {
716  TQListViewItem *parent = item->parent();
717  parent->takeItem(item);
718  parent->insertItem(item);
719  }
720  m_view->setSelected(item, true);
721  slotSelectionChanged(item);
722  }
723 }
724 
725 void KXmlCommandAdvancedDlg::slotMoveDown()
726 {
727  TQListViewItem *item = m_view->currentItem(), *next = 0;
728  if (item && (next=findNext(item)))
729  {
730  item->moveItem(next);
731  m_view->setSelected(item, true);
732  slotSelectionChanged(item);
733  }
734 }
735 
736 void KXmlCommandAdvancedDlg::slotCommandChanged(const TQString& cmd)
737 {
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());
744 }
745 
746 void KXmlCommandAdvancedDlg::slotValueSelected(TQListViewItem *item)
747 {
748  m_addval->setEnabled(m_type->currentItem() != 4 || m_values->childCount() < 2);
749  m_delval->setEnabled(item != 0);
750 }
751 
752 void KXmlCommandAdvancedDlg::slotOptionRenamed(TQListViewItem *item, int)
753 {
754  if (item && m_opts.contains(item->text(1)))
755  {
756  DrBase *opt = m_opts[item->text(1)];
757  opt->set("text", item->text(0));
758  slotSelectionChanged(item);
759  }
760 }
761 
762 void KXmlCommandAdvancedDlg::recreateGroup(TQListViewItem *item, DrGroup *grp)
763 {
764  if (!item)
765  return;
766 
767  TQListViewItem *child = item->firstChild();
768  while (child)
769  {
770  DrBase *opt = (m_opts.contains(child->text(1)) ? m_opts[child->text(1)] : 0);
771  if (opt)
772  {
773  if (opt->type() == DrBase::Group)
774  {
775  DrGroup *childGroup = static_cast<DrGroup*>(opt);
776  recreateGroup(child, childGroup);
777  grp->addGroup(childGroup);
778  }
779  else
780  {
781  opt->setName("_kde-"+m_xmlcmd->name()+"-"+opt->name());
782  grp->addOption(opt);
783  }
784  m_opts.remove(child->text(1));
785  }
786  child = child->nextSibling();
787  }
788 }
789 
790 bool KXmlCommandAdvancedDlg::editCommand(KXmlCommand *xmlcmd, TQWidget *parent)
791 {
792  if (!xmlcmd)
793  return false;
794 
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);
798  //dlg.enableButton(KDialogBase::Ok, false);
799  xmldlg->setCommand(xmlcmd);
800  if (dlg.exec())
801  {
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" ), " " ) );
808 
809  // need to recreate the driver tree structure
810  DrMain *driver = (xmldlg->m_opts.contains("__root__") ? static_cast<DrMain*>(xmldlg->m_opts["__root__"]) : 0);
811  if (!driver && xmldlg->m_opts.count() > 0)
812  {
813  kdDebug() << "KXmlCommandAdvancedDlg: driver structure not found, creating one" << endl;
814  driver = new DrMain;
815  driver->setName(xmlcmd->name());
816  }
817  xmldlg->recreateGroup(xmldlg->m_view->firstChild(), driver);
818  xmldlg->m_opts.remove("__root__");
819  xmlcmd->setDriver(driver);
820 
821  // remaining options will be removed in destructor
822 
823  return true;
824  }
825  return false;
826 }
827 
828 //-----------------------------------------------------------------------------------------------------
829 
830 KXmlCommandDlg::KXmlCommandDlg(TQWidget *parent, const char *name)
831 : KDialogBase(parent, name, true, TQString::null, Ok|Cancel|Details, Ok, true)
832 {
833  setButtonText(Details, i18n("&Mime Type Settings"));
834  m_cmd = 0;
835 
836  TQWidget *dummy = new TQWidget(this, "TopDetail");
837  TQWidget *topmain = new TQWidget(this, "TopMain");
838 
839  TQGroupBox *m_gb1 = new TQGroupBox(0, Qt::Horizontal, i18n("Supported &Input Formats"), dummy);
840  TQGroupBox *m_gb2 = new TQGroupBox(0, Qt::Horizontal, i18n("Requirements"), topmain);
841 
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);
865 
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);
871 
872  TQFont f(m_idname->font());
873  f.setBold(true);
874  m_idname->setFont(f);
875 
876  KSeparator *sep1 = new KSeparator(TQFrame::HLine, dummy);
877 
878  TQVBoxLayout *l0 = new TQVBoxLayout(topmain, 0, 10);
879  TQGridLayout *l5 = new TQGridLayout(0, 2, 2, 0, 5);
880  l0->addLayout(TQT_TQLAYOUT(l5));
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);
887  l0->addLayout(l3);
888  l3->addWidget(m_edit);
889  l3->addStretch(1);
890 
891  TQVBoxLayout *l7 = new TQVBoxLayout(dummy, 0, 10);
892  TQHBoxLayout *l6 = new TQHBoxLayout(0, 0, 5);
893  l7->addWidget(sep1);
894  l7->addLayout(l6);
895  l6->addWidget(m_mimetypelab, 0);
896  l6->addWidget(m_mimetype, 1);
897  l7->addWidget(m_gb1);
898  TQGridLayout *l2 = new TQGridLayout(TQT_TQLAYOUT(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(TQT_TQLAYOUT(m_gb2->layout()), 10);
906  l4->addWidget(m_requirements);
907  TQVBoxLayout *l8 = new TQVBoxLayout(0, 0, 0);
908  l4->addLayout(l8);
909  l8->addWidget(m_addreq);
910  l8->addWidget(m_removereq);
911  l8->addStretch(1);
912 
913  connect(m_addmime, TQT_SIGNAL(clicked()), TQT_SLOT(slotAddMime()));
914  connect(m_removemime, TQT_SIGNAL(clicked()), TQT_SLOT(slotRemoveMime()));
915  connect(m_edit, TQT_SIGNAL(clicked()), TQT_SLOT(slotEditCommand()));
916  connect(m_requirements, TQT_SIGNAL(selectionChanged(TQListViewItem*)), TQT_SLOT(slotReqSelected(TQListViewItem*)));
917  connect(m_availablemime, TQT_SIGNAL(selectionChanged(TQListBoxItem*)), TQT_SLOT(slotAvailableSelected(TQListBoxItem*)));
918  connect(m_selectedmime, TQT_SIGNAL(selectionChanged(TQListBoxItem*)), TQT_SLOT(slotSelectedSelected(TQListBoxItem*)));
919  connect(m_addreq, TQT_SIGNAL(clicked()), TQT_SLOT(slotAddReq()));
920  connect(m_removereq, TQT_SIGNAL(clicked()), TQT_SLOT(slotRemoveReq()));
921 
922  KMimeType::List list = KMimeType::allMimeTypes();
923  for (TQValueList<KMimeType::Ptr>::ConstIterator it=list.begin(); it!=list.end(); ++it)
924  {
925  TQString mimetype = (*it)->name();
926  m_mimelist << mimetype;
927  }
928 
929  m_mimelist.sort();
930  m_mimetype->insertStringList(m_mimelist);
931  m_availablemime->insertStringList(m_mimelist);
932 
933  setMainWidget(topmain);
934  setDetailsWidget(dummy);
935 }
936 
937 void KXmlCommandDlg::setCommand(KXmlCommand *xmlCmd)
938 {
939  setCaption(i18n("Command Edit for %1").arg(xmlCmd->name()));
940 
941  m_cmd = xmlCmd;
942  m_description->setText(i18n(xmlCmd->description().utf8()));
943  m_idname->setText(xmlCmd->name());
944 
945  m_requirements->clear();
946  TQStringList list = xmlCmd->requirements();
947  TQListViewItem *item(0);
948  for (TQStringList::ConstIterator it=list.begin(); it!=list.end(); ++it)
949  {
950  item = new TQListViewItem(m_requirements, item, *it);
951  item->setRenameEnabled(0, true);
952  }
953 
954  int index = m_mimelist.findIndex(xmlCmd->mimeType());
955  if (index != -1)
956  m_mimetype->setCurrentItem(index);
957  else
958  m_mimetype->setCurrentItem(0);
959 
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)
965  {
966  m_selectedmime->insertItem(*it);
967  delete m_availablemime->findItem(*it, TQt::ExactMatch);
968  }
969 }
970 
971 void KXmlCommandDlg::slotOk()
972 {
973  if (m_cmd)
974  {
975  m_cmd->setMimeType((m_mimetype->currentText() == "all/all" ? TQString::null : m_mimetype->currentText()));
976  m_cmd->setDescription(m_description->text());
977  TQStringList l;
978  TQListViewItem *item = m_requirements->firstChild();
979  while (item)
980  {
981  l << item->text(0);
982  item = item->nextSibling();
983  }
984  m_cmd->setRequirements(l);
985  l.clear();
986  for (uint i=0; i<m_selectedmime->count(); i++)
987  l << m_selectedmime->text(i);
988  m_cmd->setInputMimeTypes(l);
989  }
990  KDialogBase::slotOk();
991 }
992 
993 bool KXmlCommandDlg::editCommand(KXmlCommand *xmlCmd, TQWidget *parent)
994 {
995  if (!xmlCmd)
996  return false;
997 
998  KXmlCommandDlg xmldlg(parent, 0);
999  xmldlg.setCommand(xmlCmd);
1000 
1001  return (xmldlg.exec() == Accepted);
1002 }
1003 
1004 void KXmlCommandDlg::slotAddMime()
1005 {
1006  int index = m_availablemime->currentItem();
1007  if (index != -1)
1008  {
1009  m_selectedmime->insertItem(m_availablemime->currentText());
1010  m_availablemime->removeItem(index);
1011  m_selectedmime->sort();
1012  }
1013 }
1014 
1015 void KXmlCommandDlg::slotRemoveMime()
1016 {
1017  int index = m_selectedmime->currentItem();
1018  if (index != -1)
1019  {
1020  m_availablemime->insertItem(m_selectedmime->currentText());
1021  m_selectedmime->removeItem(index);
1022  m_availablemime->sort();
1023  }
1024 }
1025 
1026 void KXmlCommandDlg::slotEditCommand()
1027 {
1028  KXmlCommandAdvancedDlg::editCommand(m_cmd, parentWidget());
1029 }
1030 
1031 void KXmlCommandDlg::slotAddReq()
1032 {
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);
1037 }
1038 
1039 void KXmlCommandDlg::slotRemoveReq()
1040 {
1041  delete m_requirements->currentItem();
1042 }
1043 
1044 void KXmlCommandDlg::slotReqSelected(TQListViewItem *item)
1045 {
1046  m_removereq->setEnabled(item);
1047 }
1048 
1049 void KXmlCommandDlg::slotAvailableSelected(TQListBoxItem *item)
1050 {
1051  m_addmime->setEnabled(item);
1052 }
1053 
1054 void KXmlCommandDlg::slotSelectedSelected(TQListBoxItem *item)
1055 {
1056  m_removemime->setEnabled(item);
1057 }
1058 
1059 #include "kxmlcommanddlg.moc"

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
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeprint by doxygen 1.8.8
This website is maintained by Timothy Pearson.