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