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; }
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 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 *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; }
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* 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; }