Пример #1
0
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();
}
Пример #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
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;
}
Пример #4
0
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);
}
Пример #5
0
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;
}