/* newIngGraphs: * Create new ingraph state using supplied graphs. If sp is non-NULL, we * assume user is supplying memory. */ ingraph_state* newIngGraphs(ingraph_state * sp , Agraph_t** graphs, ingdisc *disc) { return new_ing(sp, 0, graphs, disc); }
void MX2Importer::readRecipe( const QDomNodeList& l, Recipe *recipe ) { for ( int i = 0; i < l.count(); i++ ) { QDomElement el = l.item( i ).toElement(); QString tagName = el.tagName(); if ( tagName == "Serv" ) { recipe->yield.setAmount(el.attribute( "qty" ).toInt()); recipe->yield.setType(i18n("servings")); } else if ( tagName == "PrpT" ) recipe->prepTime = QTime::fromString( el.attribute( "elapsed" ), "h:mm" ); else if ( tagName == "CatS" ) { QDomNodeList categories = el.childNodes(); for ( int j = 0; j < categories.count(); j++ ) { QDomElement c = categories.item( j ).toElement(); if ( c.tagName() == "CatT" ) { if ( c.text().length() > 0 ) { Element cat( c.text().trimmed() ); recipe->categoryList.append( cat ); } } } } else if ( tagName == "IngR" ) { double quantity1=0, quantity2=0, offset=0; QStringList qtyStrList = el.attribute( "qty" ).split( ' ' ); if ( !qtyStrList.isEmpty() ) { QValidator::State state; MixedNumber number; state = MixedNumber::fromString( qtyStrList.first(), number, false ); if ( state != QValidator::Acceptable ) quantity1 = 0; else quantity1 = number.toDouble(); state = MixedNumber::fromString( qtyStrList.last(), number, false ); if ( state != QValidator::Acceptable ) quantity2 = 0; else quantity2 = number.toDouble(); } offset = quantity2 - quantity1; Ingredient new_ing( el.attribute( "name" ), quantity1, Unit( el.attribute( "unit" ), quantity1 ) ); new_ing.amount_offset = offset; if ( el.hasChildNodes() ) { QDomNodeList iChilds = el.childNodes(); for ( int j = 0; j < iChilds.count(); j++ ) { QDomElement iChild = iChilds.item( j ).toElement(); if ( iChild.tagName() == "IPrp" ) { QString prepMethodStr = iChild.text().trimmed(); if ( !prepMethodStr.isEmpty() ) new_ing.prepMethodList.append( Element( prepMethodStr ) ); } else if ( iChild.tagName() == "INtI" ) { ; // TODO: What does it mean?... ingredient nutrient info? } } } recipe->ingList.append( new_ing ); } else if ( tagName == "DirS" ) { QStringList directions; QDomNodeList dirs = el.childNodes(); for ( int j = 0; j < dirs.count(); j++ ) { QDomElement dir = dirs.item( j ).toElement(); if ( dir.tagName() == "DirT" ) directions.append( dir.text().trimmed() ); } QString directionsText; // TODO This is copied from RecipeML, maybe a QStringList // for directions in Recipe instead? if ( directions.count() > 1 ) { for ( int i = 1; i <= directions.count(); i++ ) { if ( i != 1 ) { directionsText += "\n\n"; } QString sWith = QString( "%1. " ).arg( i ); QString text = directions[ i - 1 ]; if ( !text.trimmed().startsWith( sWith ) ) directionsText += sWith; directionsText += text; } } else directionsText = directions[ 0 ]; recipe->instructions = directionsText; } else if ( tagName == "SrvI" ) { // Don't know what to do with it, for now add it to directions // btw lets hope this is read after the directions recipe->instructions += "\n\n" + el.text().trimmed(); } else if ( tagName == "Note" ) { // Don't know what to do with it, for now add it to directions // btw lets hope this is read after the directions recipe->instructions += "\n\n" + el.text().trimmed(); } else if ( tagName == "Nutr" ) { //example: <Nutr>Per Serving (excluding unknown items): 51 Calories; 6g Fat (99.5% calories from fat); trace Protein; trace Carbohydrate; 0g Dietary Fiber; 16mg Cholesterol; 137mg Sodium. Exchanges: 1 Fat.</Nutr> // Don't know what to do with it, for now add it to directions // btw lets hope this is read after the directions recipe->instructions += "\n\n" + el.text().trimmed(); } /* tags to check for (example follows: <Srce>SARA'S SECRETS with Sara Moulton - (Show # SS-1B43) - from the TV FOOD NETWORK</Srce> <AltS label="Formatted for MC7" source="07-11-2003 by Joe Comiskey - Mad's Recipe Emporium"/> */ // TODO Have i missed some tag? } }
ingraph_state* newIng(ingraph_state * sp, char **files, ingdisc * disc) { return new_ing(sp, files, 0, disc); }