Exemple #1
0
DrMain *DrMain::cloneDriver()
{
    DrMain *driver = static_cast< DrMain * >(clone());

    QPtrListIterator< DrConstraint > cit(m_constraints);
    for(; cit.current(); ++cit)
        driver->addConstraint(new DrConstraint(*(cit.current())));

    QDictIterator< DrPageSize > pit(m_pagesizes);
    for(; pit.current(); ++pit)
        driver->addPageSize(new DrPageSize(*(pit.current())));

    return driver;
}
Exemple #2
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;
}