예제 #1
0
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;
}
예제 #2
0
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();
	}
}
예제 #3
0
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;
}
예제 #4
0
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);
    }
}
예제 #5
0
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;
}
예제 #6
0
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);
	}
}
예제 #7
0
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;
}
예제 #8
0
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;
}
예제 #9
0
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;
	}
}
예제 #10
0
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;
}