21 #include "driveritem.h"
24 #include <tqstringlist.h>
26 #include <tdelocale.h>
35 : m_type(DrBase::Base), m_conflict(false)
43 TQString DrBase::valueText()
45 return TQString::null;
48 TQString DrBase::prettyText()
53 void DrBase::setValueText(
const TQString&)
57 DriverItem* DrBase::createItem(DriverItem *parent, DriverItem *after)
59 return new DriverItem(parent, after,
this);
62 void DrBase::setOptions(
const TQMap<TQString,TQString>& opts)
64 if (opts.contains(name())) setValueText(opts[name()]);
67 void DrBase::getOptions(TQMap<TQString,TQString>& opts,
bool incldef)
69 TQString val = valueText();
70 if ( incldef || get(
"persistent" ) ==
"1" || get(
"default") != val )
74 DrBase* DrBase::clone()
79 case Main: opt =
new DrMain;
break;
80 case Group: opt =
new DrGroup;
break;
81 case String: opt =
new DrStringOption;
break;
82 case Integer: opt =
new DrIntegerOption;
break;
83 case Float: opt =
new DrFloatOption;
break;
84 case List: opt =
new DrListOption;
break;
85 case Boolean: opt =
new DrBooleanOption;
break;
86 default: opt =
new DrBase;
break;
90 opt->m_conflict = m_conflict;
91 opt->setValueText(valueText());
103 m_type = DrBase::Main;
104 m_constraints.setAutoDelete(
true);
105 m_pagesizes.setAutoDelete(
true);
111 if (has(
"temporary"))
112 TQFile::remove(get(
"temporary"));
113 if (has(
"temporary-cppd"))
114 TQFile::remove(get(
"temporary-cppd"));
117 DriverItem* DrMain::createTreeView(TQListView *parent)
119 DriverItem *root =
new DriverItem(parent,
this);
124 int DrMain::checkConstraints()
128 TQPtrListIterator<DrConstraint> it(m_constraints);
129 for (;it.current();++it)
130 if (it.current()->check(
this))
135 void DrMain::addPageSize(DrPageSize *ps)
137 m_pagesizes.insert(ps->pageName(),ps);
140 void DrMain::removeOptionGlobally(
const TQString& name)
143 DrBase *opt = findOption(name, &grp);
147 grp->removeOption(name);
153 void DrMain::removeGroupGlobally(DrGroup *grp)
156 if (findGroup(grp, &parent) && parent)
158 parent->removeGroup(grp);
159 if (parent->isEmpty() && parent !=
this)
160 removeGroupGlobally(parent);
164 TQMap<TQString, DrBase*> DrMain::flatten()
166 TQMap<TQString, DrBase*> optmap;
168 flattenGroup(optmap, index);
172 DrMain* DrMain::cloneDriver()
174 DrMain *driver =
static_cast<DrMain*
>(clone());
176 TQPtrListIterator<DrConstraint> cit(m_constraints);
177 for (; cit.current(); ++cit)
178 driver->addConstraint(
new DrConstraint(*(cit.current())));
180 TQDictIterator<DrPageSize> pit(m_pagesizes);
181 for (; pit.current(); ++pit)
182 driver->addPageSize(
new DrPageSize(*(pit.current())));
194 m_type = DrBase::Group;
196 m_subgroups.setAutoDelete(
true);
197 m_options.setAutoDelete(
true);
198 m_listoptions.setAutoDelete(
false);
205 void DrGroup::addOption(DrBase *opt)
207 if (!opt->name().isEmpty())
209 m_options.insert(opt->name(),opt);
210 m_listoptions.append(opt);
214 void DrGroup::addGroup(DrGroup *grp)
216 m_subgroups.append(grp);
219 void DrGroup::addObject(DrBase *optgrp)
221 if (optgrp->isOption())
223 else if (optgrp->type() == DrBase::Group)
224 addGroup(
static_cast<DrGroup*
>(optgrp));
227 void DrGroup::removeOption(
const TQString& name)
229 DrBase *opt = m_options.find(name);
232 m_listoptions.removeRef(opt);
233 m_options.remove(name);
237 void DrGroup::removeGroup(DrGroup *grp)
239 m_subgroups.removeRef(grp);
242 bool DrGroup::isEmpty()
244 return (m_options.count()+m_subgroups.count() == 0);
247 DriverItem* DrGroup::createItem(DriverItem *parent, DriverItem *after)
249 DriverItem *item = DrBase::createItem(parent, after);
254 void DrGroup::createTree(DriverItem *parent)
258 TQPtrListIterator<DrGroup> lit(m_subgroups);
259 for (;lit.current();++lit)
260 item = lit.current()->createItem(parent, item);
262 TQPtrListIterator<DrBase> dit(m_listoptions);
263 for (;dit.current();++dit)
264 item = dit.current()->createItem(parent, item);
267 DrBase* DrGroup::findOption(
const TQString& name, DrGroup **parentGroup)
269 DrBase *opt = m_options.find(name);
272 TQPtrListIterator<DrGroup> it(m_subgroups);
273 for (;it.current() && !opt; ++it)
274 opt = it.current()->findOption(name, parentGroup);
276 else if (parentGroup)
281 DrGroup* DrGroup::findGroup(DrGroup *grp, DrGroup ** parentGroup)
283 DrGroup *group = (m_subgroups.findRef(grp) == -1 ? 0 : grp);
286 TQPtrListIterator<DrGroup> it(m_subgroups);
287 for (;it.current() && !group; ++it)
288 group = it.current()->findGroup(grp, parentGroup);
290 else if (parentGroup)
295 void DrGroup::clearConflict()
297 TQDictIterator<DrBase> dit(m_options);
298 for (;dit.current();++dit)
299 dit.current()->setConflict(
false);
301 TQPtrListIterator<DrGroup> lit(m_subgroups);
302 for (;lit.current();++lit)
303 lit.current()->clearConflict();
306 void DrGroup::setOptions(
const TQMap<TQString,TQString>& opts)
308 TQDictIterator<DrBase> dit(m_options);
309 for (;dit.current();++dit)
310 dit.current()->setOptions(opts);
312 TQPtrListIterator<DrGroup> lit(m_subgroups);
313 for (;lit.current();++lit)
314 lit.current()->setOptions(opts);
317 void DrGroup::getOptions(TQMap<TQString,TQString>& opts,
bool incldef)
319 TQDictIterator<DrBase> dit(m_options);
320 for (;dit.current();++dit)
321 dit.current()->getOptions(opts,incldef);
323 TQPtrListIterator<DrGroup> lit(m_subgroups);
324 for (;lit.current();++lit)
325 lit.current()->getOptions(opts,incldef);
328 void DrGroup::flattenGroup(TQMap<TQString, DrBase*>& optmap,
int& index)
330 TQPtrListIterator<DrGroup> git(m_subgroups);
331 for (; git.current(); ++git)
332 git.current()->flattenGroup(optmap, index);
334 TQDictIterator<DrBase> oit(m_options);
335 for (; oit.current(); ++oit)
336 optmap[oit.current()->name()] = oit.current();
338 if (name().isEmpty())
339 optmap[TQString::fromLatin1(
"group%1").arg(index++)] =
this;
341 optmap[name()] =
this;
343 m_subgroups.setAutoDelete(
false);
344 m_options.setAutoDelete(
false);
347 m_listoptions.clear();
348 m_subgroups.setAutoDelete(
true);
349 m_options.setAutoDelete(
true);
352 DrBase* DrGroup::clone()
354 DrGroup *grp =
static_cast<DrGroup*
>(DrBase::clone());
356 TQPtrListIterator<DrGroup> git(m_subgroups);
357 for (; git.current(); ++git)
358 grp->addGroup(
static_cast<DrGroup*
>(git.current()->clone()));
360 TQPtrListIterator<DrBase> oit(m_listoptions);
361 for (; oit.current(); ++oit)
362 grp->addOption(oit.current()->clone());
364 return static_cast<DrBase*
>(grp);
367 TQString DrGroup::groupForOption(
const TQString& optname )
370 if ( optname ==
"PageSize" ||
371 optname ==
"InputSlot" ||
372 optname ==
"ManualFeed" ||
373 optname ==
"MediaType" ||
374 optname ==
"MediaColor" ||
375 optname ==
"MediaWeight" ||
376 optname ==
"Duplex" ||
377 optname ==
"DoubleSided" ||
378 optname ==
"Copies" )
379 grpname = i18n(
"General" );
380 else if ( optname.startsWith(
"stp" ) ||
382 optname ==
"Yellow" ||
383 optname ==
"Magenta" ||
384 optname ==
"Black" ||
385 optname ==
"Density" ||
386 optname ==
"Contrast" )
387 grpname = i18n(
"Adjustments" );
388 else if ( optname.startsWith(
"JCL" ) )
389 grpname = i18n(
"JCL" );
391 grpname = i18n(
"Others" );
399 DrChoiceGroup::DrChoiceGroup()
402 m_type = DrBase::ChoiceGroup;
405 DrChoiceGroup::~DrChoiceGroup()
409 DriverItem* DrChoiceGroup::createItem(DriverItem *parent, DriverItem*)
419 DrStringOption::DrStringOption()
422 m_type = DrBase::String;
425 DrStringOption::~DrStringOption()
429 TQString DrStringOption::valueText()
434 void DrStringOption::setValueText(
const TQString& s)
443 DrIntegerOption::DrIntegerOption()
446 m_type = DrBase::Integer;
452 DrIntegerOption::~DrIntegerOption()
456 TQString DrIntegerOption::valueText()
458 TQString s = TQString::number(m_value);
462 void DrIntegerOption::setValueText(
const TQString& s)
467 TQString DrIntegerOption::fixedVal()
469 TQStringList vals = TQStringList::split(
"|", get(
"fixedvals"),
false);
470 if (vals.count() == 0)
474 for (TQStringList::Iterator it=vals.begin(); it!=vals.end(); ++it)
476 int thisVal = (*it).toInt();
477 if (val.isEmpty() || abs(thisVal - m_value) < d)
479 d = abs(thisVal - m_value);
493 DrFloatOption::DrFloatOption()
496 m_type = DrBase::Float;
502 DrFloatOption::~DrFloatOption()
506 TQString DrFloatOption::valueText()
508 TQString s = TQString::number(m_value,
'f',3);
512 void DrFloatOption::setValueText(
const TQString& s)
514 m_value = s.toFloat();
517 TQString DrFloatOption::fixedVal()
519 TQStringList vals = TQStringList::split(
"|", get(
"fixedvals"),
false);
520 if (vals.count() == 0)
524 for (TQStringList::Iterator it=vals.begin(); it!=vals.end(); ++it)
526 float thisVal = (*it).toFloat();
527 if (val.isEmpty() || fabs(thisVal - m_value) < d)
529 d = fabs(thisVal - m_value);
543 DrListOption::DrListOption()
546 m_type = DrBase::List;
548 m_choices.setAutoDelete(
true);
552 DrListOption::~DrListOption()
556 TQString DrListOption::valueText()
558 TQString s = (m_current ? m_current->name() : TQString::null);
562 TQString DrListOption::prettyText()
565 return m_current->get(
"text");
567 return TQString::null;
570 void DrListOption::setValueText(
const TQString& s)
572 m_current = findChoice(s);
576 int index = s.toInt(&ok);
582 DrBase* DrListOption::findChoice(
const TQString& txt)
584 TQPtrListIterator<DrBase> it(m_choices);
585 for (;it.current();++it)
586 if (it.current()->name() == txt)
591 DrBase* DrListOption::clone()
593 DrListOption *opt =
static_cast<DrListOption*
>(DrBase::clone());
595 TQPtrListIterator<DrBase> it(m_choices);
596 for (; it.current(); ++it)
597 opt->addChoice(it.current()->clone());
599 opt->setValueText(valueText());
601 return static_cast<DrBase*
>(opt);
604 void DrListOption::getOptions(TQMap<TQString,TQString>& opts,
bool incldef)
606 DrBase::getOptions(opts, incldef);
607 if (currentChoice() && currentChoice()->type() == DrBase::ChoiceGroup)
608 currentChoice()->getOptions(opts, incldef);
611 void DrListOption::setOptions(
const TQMap<TQString,TQString>& opts)
613 DrBase::setOptions(opts);
614 if (currentChoice() && currentChoice()->type() == DrBase::ChoiceGroup)
615 currentChoice()->setOptions(opts);
618 DriverItem* DrListOption::createItem(DriverItem *parent, DriverItem *after)
620 DriverItem *item = DrBase::createItem(parent, after);
628 void DrListOption::setChoice(
int choicenum)
630 if (choicenum >= 0 && choicenum < (
int)m_choices.count())
632 setValueText(m_choices.at(choicenum)->name());
640 DrConstraint::DrConstraint(
const TQString& o1,
const TQString& o2,
const TQString& c1,
const TQString& c2)
641 : m_opt1(o1), m_opt2(o2), m_choice1(c1), m_choice2(c2), m_option1(0), m_option2(0)
645 DrConstraint::DrConstraint(
const DrConstraint& d)
646 : m_opt1(d.m_opt1), m_opt2(d.m_opt2), m_choice1(d.m_choice1), m_choice2(d.m_choice2), m_option1(0), m_option2(0)
650 bool DrConstraint::check(DrMain *driver)
652 if (!m_option1) m_option1 = (DrListOption*)driver->findOption(m_opt1);
653 if (!m_option2) m_option2 = (DrListOption*)driver->findOption(m_opt2);
654 if (m_option1 && m_option2 && m_option1->currentChoice() && m_option2->currentChoice())
656 bool f1(
false), f2(
false);
657 TQString c1(m_option1->currentChoice()->name()), c2(m_option2->currentChoice()->name());
659 if (m_choice1.isEmpty())
660 f1 = (c1 !=
"None" && c1 !=
"Off" && c1 !=
"False");
662 f1 = (c1 == m_choice1);
663 if (m_choice2.isEmpty())
664 f2 = (c2 !=
"None" && c2 !=
"Off" && c2 !=
"False");
666 f2 = (c2 == m_choice2);
668 TQString s((f1 && f2 ?
"1" :
"0"));
669 if (!m_option1->conflict()) m_option1->setConflict(f1 && f2);
670 if (!m_option2->conflict()) m_option2->setConflict(f1 && f2);
681 DrPageSize::DrPageSize(
const TQString& s,
float width,
float height,
float left,
float bottom,
float right,
float top)
692 DrPageSize::DrPageSize(
const DrPageSize& d)
694 m_width( d.m_width ),
695 m_height( d.m_height ),
697 m_bottom( d.m_bottom ),
698 m_right( d.m_right ),
703 TQSize DrPageSize::pageSize()
const
705 return TQSize( (
int )m_width, (
int )m_height );
708 TQRect DrPageSize::pageRect()
const
710 return TQRect( (
int )( m_left+0.5 ), (
int )( m_top+0.5 ), (
int )( m_width-m_left-m_right ), (
int )( m_height-m_top-m_bottom ) );
713 TQSize DrPageSize::margins()
const
715 return TQSize( (
int )( m_left+0.5 ), (
int )( m_top+0.5 ) );