DrBase* Foomatic2Loader::createValue( const QString& name, const QMap<QString,QVariant>& m ) const { DrBase *choice = new DrBase; choice->setName( name ); choice->set( "text", m.operator[]( "comment" ).toString() ); return choice; }
void KXmlCommandAdvancedDlg::recreateGroup(TQListViewItem *item, DrGroup *grp) { if (!item) return; TQListViewItem *child = item->firstChild(); while (child) { DrBase *opt = (m_opts.contains(child->text(1)) ? m_opts[child->text(1)] : 0); if (opt) { if (opt->type() == DrBase::Group) { DrGroup *childGroup = static_cast<DrGroup*>(opt); recreateGroup(child, childGroup); grp->addGroup(childGroup); } else { opt->setName("_kde-"+m_xmlcmd->name()+"-"+opt->name()); grp->addOption(opt); } m_opts.remove(child->text(1)); } child = child->nextSibling(); } }
void DriverItem::updateText() { if(m_item) { QString s(m_item->get("text")); if(m_item->isOption()) s.append(QString::fromLatin1(": <%1>").arg(m_item->prettyText())); if(m_item->type() == DrBase::List) { // remove all children: something has changed (otherwise this // function would not be called), so it make sense to remove // those children in all cases. while(firstChild()) delete firstChild(); DrBase *ch = static_cast< DrListOption * >(m_item)->currentChoice(); if(ch && ch->type() == DrBase::ChoiceGroup) { // add new children static_cast< DrChoiceGroup * >(ch)->createItem(this); setOpen(true); } } setText(0, s); } else setText(0, "ERROR"); widthChanged(); }
void KXmlCommandAdvancedDlg::slotOptionRenamed(TQListViewItem *item, int) { if (item && m_opts.contains(item->text(1))) { DrBase *opt = m_opts[item->text(1)]; opt->set("text", item->text(0)); slotSelectionChanged(item); } }
void setupBooleanOption(DrBooleanOption *opt) { int i(0); while(pt_bool[i]) { DrBase *ch = new DrBase(); ch->setName(pt_bool[i++]); ch->set("text", pt_bool[i++]); opt->addChoice(ch); } }
void KXmlCommandAdvancedDlg::slotAddOption() { if (m_view->currentItem()) { TQString ID = generateId(m_opts); DrBase *opt = new DrStringOption; opt->setName(ID); opt->set("text", i18n("New Option")); m_opts[ID] = opt; TQListViewItem *item = new TQListViewItem(m_view->currentItem(), i18n("New Option"), ID); item->setRenameEnabled(0, true); item->setPixmap(0, SmallIcon("document")); m_view->ensureItemVisible(item); item->startRename(0); } }
DrMain* ApsHandler::loadDriver(KMPrinter *prt, PrintcapEntry *entry, bool config) { DrMain *driver = loadApsDriver(config); if (driver /* && config */ ) // Load resources in all case, to get the correct page size { TQMap<TQString,TQString> opts = loadResources(entry); if ( !config && opts.contains( "PAPERSIZE" ) ) { // this is needed to keep applications informed // about the current selected page size opts[ "PageSize" ] = opts[ "PAPERSIZE" ]; // default page size needs to be set to the actual // value of the printer driver, otherwise it's blocked // to A4 DrBase *opt = driver->findOption( "PageSize" ); if ( opt ) opt->set( "default", opts[ "PageSize" ] ); } driver->setOptions(opts); driver->set("gsdriver", opts["PRINTER"]); } return driver; }
bool PPDLoader::putFooProcessedData(const QVariant &var) { QMap< QString, QVariant >::ConstIterator it = var.mapFind("args_byname"); if(it != var.mapEnd()) { QVariant opts = it.data(); for(it = opts.mapBegin(); it != opts.mapEnd(); ++it) { QMap< QString, QVariant > opt = it.data().toMap(); QString type = opt["type"].toString(); if(type == "float" || type == "int") { DrBase *o; if(type == "float") o = new DrFloatOption; else o = new DrIntegerOption; o->setName(opt["name"].toString()); o->set("text", opt["comment"].toString()); o->set("minval", opt["min"].toString()); o->set("maxval", opt["max"].toString()); o->set("default", opt["default"].toString()); o->setValueText(o->get("default")); DrGroup *grp = 0; DrBase *old = m_groups.top()->findOption(o->name(), &grp); if(old) { if(old->type() == DrBase::List) { QStringList vals; QPtrListIterator< DrBase > it(*(static_cast< DrListOption * >(old)->choices())); for(; it.current(); ++it) vals.append(it.current()->name()); o->set("fixedvals", vals.join("|")); } grp->removeOption(o->name()); grp->addOption(o); } else { qWarning("Option %s not found in original PPD file", o->name().latin1()); delete o; } } } } return true; }
bool PPDLoader::putStatement(const QString &keyword, const QString &name, const QString &desc, const QStringList &values) { if(m_option) { if(!name.isEmpty() && m_option->name() == keyword) { if(m_option->type() >= DrBase::List) { DrBase *ch = new DrBase; ch->setName(name); if(desc.isEmpty()) ch->set("text", name); else ch->set("text", processLocaleString(desc)); static_cast< DrListOption * >(m_option)->addChoice(ch); } else { QString fv = m_option->get("fixedvals"); if(fv.isEmpty()) fv = name; else fv.append("|" + name); m_option->set("fixedvals", fv); } } else if(keyword == "FoomaticRIPOption" && name == m_option->name() && values.size() > 1) { QString type = values[0]; if(type == "float" || type == "int") { DrBase *opt = 0; if(type == "float") opt = new DrFloatOption; else opt = new DrIntegerOption; opt->setName(m_option->name()); opt->set("text", m_option->get("text")); opt->set("default", m_option->get("default")); if(m_option->type() == DrBase::List) { QStringList vals; QPtrListIterator< DrBase > it(*(static_cast< DrListOption * >(m_option)->choices())); for(; it.current(); ++it) vals.append(it.current()->name()); opt->set("fixedvals", vals.join("|")); } delete m_option; m_option = opt; } // FIXME: support other option types } else if(keyword == "FoomaticRIPOptionRange" && name == m_option->name() && values.size() >= 2 && (m_option->type() == DrBase::Float || m_option->type() == DrBase::Integer)) { m_option->set("minval", values[0]); m_option->set("maxval", values[1]); } } else if(keyword == "Font" && m_groups.size() > 0) { m_fonts << name; } return true; }
void KXmlCommandAdvancedDlg::slotApplyChanges() { TQListViewItem *item = m_view->currentItem(); if (item) { if (m_name->text().isEmpty() || m_name->text() == "__root__") { KMessageBox::error(this, i18n("Invalid identification name. Empty strings and \"__root__\" are not allowed.")); return; } m_apply->setEnabled(false); DrBase *opt = (m_opts.contains(item->text(1)) ? m_opts[item->text(1)] : 0); m_opts.remove(item->text(1)); delete opt; // update tree item item->setText(0, m_desc->text()); item->setText(1, m_name->text()); // recreate option if (m_type->isEnabled()) { int type = m_type->currentItem() + DrBase::String; switch (type) { case DrBase::Integer: case DrBase::Float: if (type == DrBase::Integer) opt = new DrIntegerOption; else opt = new DrFloatOption; opt->set("minval", m_edit1->text()); opt->set("maxval", m_edit2->text()); break; case DrBase::List: case DrBase::Boolean: { if (type == DrBase::List) opt = new DrListOption; else opt = new DrBooleanOption; DrListOption *lopt = static_cast<DrListOption*>(opt); TQListViewItem *item = m_values->firstChild(); while (item) { DrBase *choice = new DrBase; choice->setName(item->text(0)); choice->set("text", item->text(1)); lopt->addChoice(choice); item = item->nextSibling(); } break; } case DrBase::String: opt = new DrStringOption; break; } opt->set("format", m_format->text()); opt->set("default", m_default->text()); opt->setValueText(opt->get("default")); } else opt = new DrGroup; opt->setName((m_name->text().isEmpty() ? generateId(m_opts) : m_name->text())); opt->set("text", m_desc->text()); opt->set( "persistent", m_persistent->isChecked() ? "1" : "0" ); m_opts[opt->name()] = opt; } }
DrMain* Foomatic2Loader::buildDriver() const { if ( m_foodata.isEmpty() ) return NULL; QVariant v = m_foodata.find( "VAR" ).data(); if ( !v.isNull() && v.type() == QVariant::Map ) { DrMain *driver = new DrMain; QMap<QString,DrGroup*> groups; driver->set( "manufacturer", v.mapFind( "make" ).data().toString() ); driver->set( "model", v.mapFind( "model" ).data().toString() ); driver->set( "matic_printer", v.mapFind( "id" ).data().toString() ); driver->set( "matic_driver", v.mapFind( "driver" ).data().toString() ); driver->set( "text", QString( "%1 %2 (%3)" ).arg( driver->get( "manufacturer" ) ).arg( driver->get( "model" ) ).arg( driver->get( "matic_driver" ) ) ); if ( m_foodata.contains( "POSTPIPE" ) ) driver->set( "postpipe", m_foodata.find( "POSTPIPE" ).data().toString() ); v = v.mapFind( "args" ).data(); if ( !v.isNull() && v.type() == QVariant::List ) { QValueList<QVariant>::ConstIterator it = v.listBegin(); for ( ; it!=v.listEnd(); ++it ) { if ( ( *it ).type() != QVariant::Map ) continue; DrBase *opt = createOption( ( *it ).toMap() ); if ( opt ) { QString group = DrGroup::groupForOption( opt->name() ); DrGroup *grp = NULL; if ( !groups.contains( group ) ) { grp = new DrGroup; grp->set( "text", group ); driver->addGroup( grp ); groups.insert( group, grp ); } else grp = groups[ group ]; grp->addOption( opt ); if ( opt->name() == "PageSize" ) { // try to add the corresponding page sizes QVariant choices = ( *it ).mapFind( "vals_byname" ).data(); QRegExp re( "(\\d+) +(\\d+)" ); if ( choices.type() == QVariant::Map ) { QMap<QString,QVariant>::ConstIterator it = choices.mapBegin(); for ( ; it!=choices.mapEnd(); ++it ) { QString driverval = ( *it ).mapFind( "driverval" ).data().toString(); if ( re.exactMatch( driverval ) ) { driver->addPageSize( new DrPageSize( it.key(), re.cap( 1 ).toInt(), re.cap( 2 ).toInt(), 36, 24, 36, 24 ) ); } } } } } else kdWarning( 500 ) << "Failed to create option: " << ( *it ).toMap()[ "name" ].toString() << endl; } } return driver; } return NULL; }
void KPrinterImpl::preparePrinting(KPrinter *printer) { // page size -> try to find page size and margins from driver file // use "PageSize" as option name to find the wanted page size. It's // up to the driver loader to use that option name. KMManager *mgr = KMFactory::self()->manager(); DrMain *driver = mgr->loadPrinterDriver(mgr->findPrinter(printer->printerName()), false); if (driver) { // Find the page size: // 1) print option // 2) default driver option QString psname = printer->option("PageSize"); if (psname.isEmpty()) { DrListOption *opt = (DrListOption*)driver->findOption("PageSize"); if (opt) psname = opt->get("default"); } if (!psname.isEmpty()) { printer->setOption("kde-pagesize",TQString::number((int)pageNameToPageSize(psname))); DrPageSize *ps = driver->findPageSize(psname); if (ps) { printer->setRealPageSize( ps ); } } // Find the numerical resolution // 1) print option (Resolution) // 2) default driver option (Resolution) // 3) default printer resolution // The resolution must have the format: XXXdpi or XXXxYYYdpi. In the second // case the YYY value is used as resolution. TQString res = printer->option( "Resolution" ); if ( res.isEmpty() ) { DrBase *opt = driver->findOption( "Resolution" ); if ( opt ) res = opt->get( "default" ); if ( res.isEmpty() ) res = driver->get( "resolution" ); } if ( !res.isEmpty() ) { TQRegExp re( "(\\d+)(?:x(\\d+))?dpi" ); if ( re.search( res ) != -1 ) { if ( !re.cap( 2 ).isEmpty() ) printer->setOption( "kde-resolution", re.cap( 2 ) ); else printer->setOption( "kde-resolution", re.cap( 1 ) ); } } // Find the supported fonts TQString fonts = driver->get( "fonts" ); if ( !fonts.isEmpty() ) printer->setOption( "kde-fonts", fonts ); delete driver; } }
DrMain *KMFoomaticManager::createDriverFromXML(QDomElement *elem) { DrMain *driver = new DrMain(); QDomElement pelem = elem->namedItem("printer").toElement(), delem = elem->namedItem("driver").toElement(); if(!pelem.isNull() && !delem.isNull()) { driver->set("manufacturer", pelem.namedItem("make").toElement().text()); driver->set("model", pelem.namedItem("model").toElement().text()); QString s = QString::fromLatin1("%1 %2 (%3)") .arg(driver->get("manufacturer")) .arg(driver->get("model")) .arg(delem.namedItem("name").toElement().text()); driver->set("description", s); driver->set("text", s); QDomElement opts = elem->namedItem("options").toElement(); if(!opts.isNull()) { QDomElement o = opts.firstChild().toElement(); while(!o.isNull()) { if(o.tagName() == "option") { QString type = o.attribute("type"); DrBase *dropt(0); if(type == "bool" || type == "enum") { if(type == "bool") dropt = new DrBooleanOption(); else dropt = new DrListOption(); QString defval = o.namedItem("arg_defval").toElement().text(), valuetext; QDomNode val = o.namedItem("enum_vals").firstChild(); while(!val.isNull()) { DrBase *choice = new DrBase(); choice->setName(val.namedItem("ev_shortname").namedItem("en").toElement().text()); choice->set("text", i18n(val.namedItem("ev_longname").namedItem("en").toElement().text().latin1())); static_cast< DrListOption * >(dropt)->addChoice(choice); if(val.toElement().attribute("id") == defval) valuetext = choice->name(); val = val.nextSibling(); } dropt->set("default", valuetext); dropt->setValueText(valuetext); } else if(type == "int" || type == "float") { if(type == "int") dropt = new DrIntegerOption(); else dropt = new DrFloatOption(); dropt->set("minval", o.namedItem("arg_min").toElement().text()); dropt->set("maxval", o.namedItem("arg_max").toElement().text()); QString defval = o.namedItem("arg_defval").toElement().text(); dropt->set("default", defval); dropt->setValueText(defval); } if(dropt) { dropt->setName(o.namedItem("arg_shortname").namedItem("en").toElement().text()); dropt->set("text", i18n(o.namedItem("arg_longname").namedItem("en").toElement().text().latin1())); driver->addOption(dropt); } } o = o.nextSibling().toElement(); } } } return driver; }
DrBase* Foomatic2Loader::createOption( const QMap<QString,QVariant>& m ) const { QString type = m.operator[]( "type" ).toString(); DrBase *opt = NULL; if ( type == "enum" ) { DrListOption *lopt = new DrListOption; QVariant a = m.operator[]( "vals_byname" ); QMap<QString,QVariant>::ConstIterator it = a.mapBegin(); for ( ; it!=a.mapEnd(); ++it ) { if ( it.data().type() != QVariant::Map ) continue; DrBase *ch = createValue( it.key(), it.data().toMap() ); if ( ch ) lopt->addChoice( ch ); } opt = lopt; } else if ( type == "int" || type == "float" ) { if ( type == "int" ) opt = new DrIntegerOption; else opt = new DrFloatOption; opt->set( "minval", m.operator[]( "min" ).toString() ); opt->set( "maxval", m.operator[]( "max" ).toString() ); } else if ( type == "bool" ) { DrBooleanOption *bopt = new DrBooleanOption; DrBase *choice; // choice 1 choice = new DrBase; choice->setName( "0" ); choice->set( "text", m.operator[]( "name_false" ).toString() ); bopt->addChoice( choice ); choice = new DrBase; choice->setName( "1" ); choice->set( "text", m.operator[]( "name_true" ).toString() ); bopt->addChoice( choice ); opt = bopt; } else if ( type == "string" ) { opt = new DrStringOption; } if ( opt ) { opt->setName( m.operator[]( "name" ).toString() ); opt->set( "text", m.operator[]( "comment" ).toString() ); QString defval = m.operator[]( "default" ).toString(); if ( !defval.isEmpty() ) { opt->setValueText( defval ); opt->set( "default", defval ); } } return opt; }
DrMain* Foomatic2Loader::modifyDriver( DrMain *driver ) const { if ( !m_foodata.isEmpty() ) { QValueList<DrBase*> optList; DrGroup *grp = NULL; QVariant V = m_foodata.find( "VAR" ).data(); if ( !V.isNull() && V.type() == QVariant::Map ) { QVariant v = V.mapFind( "args" ).data(); if ( !v.isNull() && v.type() == QVariant::List ) { QValueList<QVariant>::ConstIterator it = v.listBegin(); for ( ; it!=v.listEnd(); ++it ) { if ( ( *it ).type() != QVariant::Map ) continue; DrBase *opt = createOption( ( *it ).toMap() ); if ( opt ) optList.append( opt ); else kdWarning( 500 ) << "Failed to create option: " << ( *it ).toMap()[ "name" ].toString() << endl; } } else { v = V.mapFind( "args_byname" ).data(); if ( !v.isNull() && v.type() == QVariant::Map ) { QMap<QString,QVariant>::ConstIterator it = v.mapBegin(); for ( ; it!=v.mapEnd(); ++it ) { if ( ( *it ).type() != QVariant::Map ) continue; DrBase *opt = createOption( ( *it ).toMap() ); if ( opt ) optList.append( opt ); else kdWarning( 500 ) << "Failed to create option: " << ( *it ).toMap()[ "name" ].toString() << endl; } } } } for ( QValueList<DrBase*>::ConstIterator it=optList.begin(); it!=optList.end(); ++it ) { DrBase *opt = ( *it ); if ( opt ) { switch ( opt->type() ) { case DrBase::List: case DrBase::Boolean: delete opt; break; default: { if ( !grp ) { grp = new DrGroup; grp->set( "text", i18n( "Adjustments" ) ); driver->addGroup( grp ); } DrBase *oldOpt = driver->findOption( opt->name() ); if ( oldOpt && oldOpt->type() == DrBase::List ) { QPtrListIterator<DrBase> it( *( static_cast<DrListOption*>( oldOpt )->choices() ) ); QString fixedvals; for ( ; it.current(); ++it ) { fixedvals.append( it.current()->name() ); if ( !it.atLast() ) fixedvals.append( "|" ); } opt->set( "fixedvals", fixedvals ); } driver->removeOptionGlobally( opt->name() ); grp->addOption( opt ); break; } } } } } return driver; }
DrMain* LprHandler::loadToolDriver(const QString& filename) { QFile f(filename); if (f.open(IO_ReadOnly)) { DrMain *driver = new DrMain; QValueStack<DrGroup*> groups; QTextStream t(&f); QStringList l; DrListOption *lopt(0); DrBase *opt(0); groups.push(driver); driver->set("text", "Tool Driver"); while (!t.atEnd()) { l = QStringList::split('|', t.readLine().stripWhiteSpace(), false); if (l.count() == 0) continue; if (l[0] == "GROUP") { DrGroup *grp = new DrGroup; grp->setName(l[1]); grp->set("text", l[2]); groups.top()->addGroup(grp); groups.push(grp); } else if (l[0] == "ENDGROUP") { groups.pop(); } else if (l[0] == "OPTION") { opt = 0; lopt = 0; if (l.count() > 3) { if (l[3] == "STRING") opt = new DrStringOption; else if (l[3] == "BOOLEAN") { lopt = new DrBooleanOption; opt = lopt; } } else { lopt = new DrListOption; opt = lopt; } if (opt) { opt->setName(l[1]); opt->set("text", l[2]); groups.top()->addOption(opt); } } else if (l[0] == "CHOICE" && lopt) { DrBase *ch = new DrBase; ch->setName(l[1]); ch->set("text", l[2]); lopt->addChoice(ch); } else if (l[0] == "DEFAULT" && opt) { opt->setValueText(l[1]); opt->set("default", l[1]); } } return driver; } return NULL; }
void KXmlCommandAdvancedDlg::viewItem(TQListViewItem *item) { m_dummy->setEnabled((item != 0)); m_name->setText(""); m_desc->setText(""); m_format->setText(""); m_default->setText(""); m_values->clear(); m_edit1->setText(""); m_edit2->setText(""); m_persistent->setChecked( false ); int typeId(-1); if (item) { m_name->setText(item->text(1)); m_desc->setText(item->text(0)); DrBase *opt = (m_opts.contains(item->text(1)) ? m_opts[item->text(1)] : 0); if (opt) { bool isgroup = (opt->type() < DrBase::String); if (!isgroup) { m_type->setCurrentItem(opt->type() - DrBase::String); typeId = m_type->currentItem(); m_format->setText(opt->get("format")); m_default->setText(opt->get("default")); } m_type->setEnabled(!isgroup); m_default->setEnabled(!isgroup); m_format->setEnabled(!isgroup); m_stack->setEnabled(!isgroup); switch (opt->type()) { case DrBase::Float: case DrBase::Integer: m_edit1->setText(opt->get("minval")); m_edit2->setText(opt->get("maxval")); break; case DrBase::Boolean: case DrBase::List: { TQPtrListIterator<DrBase> it(*(static_cast<DrListOption*>(opt)->choices())); TQListViewItem *item(0); for (; it.current(); ++it) { item = new TQListViewItem(m_values, item, it.current()->name(), it.current()->get("text")); item->setRenameEnabled(0, true); item->setRenameEnabled(1, true); } break; } default: break; } m_addgrp->setEnabled(isgroup); m_addopt->setEnabled(isgroup); TQListViewItem *prevItem = findPrev(item), *nextItem = findNext(item); DrBase *prevOpt = (prevItem && m_opts.contains(prevItem->text(1)) ? m_opts[prevItem->text(1)] : 0); DrBase *nextOpt = (nextItem && m_opts.contains(nextItem->text(1)) ? m_opts[nextItem->text(1)] : 0); m_up->setEnabled(prevOpt && !(prevOpt->type() < DrBase::String && opt->type() >= DrBase::String)); m_down->setEnabled(nextOpt && !(isgroup && nextOpt->type() >= DrBase::String)); m_persistent->setChecked( opt->get( "persistent" ) == "1" ); } m_delopt->setEnabled(true); m_dummy->setEnabled(opt); } else { m_delopt->setEnabled(false); m_addopt->setEnabled(m_view->currentItem() && m_view->isEnabled()); m_addgrp->setEnabled(m_view->currentItem() && m_view->isEnabled()); m_up->setEnabled(false); m_down->setEnabled(false); } slotTypeChanged(typeId); m_apply->setEnabled(false); }