Example #1
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;
}
Example #2
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;
}
Example #3
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;
}
Example #4
0
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;
}