summaryrefslogtreecommitdiffstats
path: root/src/importers/mx2importer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/importers/mx2importer.cpp')
-rw-r--r--src/importers/mx2importer.cpp37
1 files changed, 31 insertions, 6 deletions
diff --git a/src/importers/mx2importer.cpp b/src/importers/mx2importer.cpp
index 75f75a7..a93bff6 100644
--- a/src/importers/mx2importer.cpp
+++ b/src/importers/mx2importer.cpp
@@ -26,7 +26,9 @@ Foundation, Inc., 51 Franklin Steet, Fifth Floor, Boston, MA 02111-1307 USA
#include <tqstringlist.h>
#include <tqtextstream.h>
#include <tqdatetime.h>
+#include <tqvalidator.h>
+#include "datablocks/mixednumber.h"
#include "datablocks/recipe.h"
@@ -115,17 +117,40 @@ void MX2Importer::readRecipe( const TQDomNodeList& l, Recipe *recipe )
}
}
else if ( tagName == "IngR" ) {
+ double quantity1=0, quantity2=0, offset=0;
+ TQStringList qtyStrList = TQStringList::split( ' ', el.attribute( "qty" ) );
+ if ( !qtyStrList.isEmpty() ) {
+ TQValidator::State state;
+ MixedNumber number;
+ bool ok;
+ number = MixedNumber::fromString( qtyStrList.first(), &ok, false );
+ if ( !ok )
+ quantity1 = 0;
+ else
+ quantity1 = number.toDouble();
+ number = MixedNumber::fromString( qtyStrList.last(), &ok, false );
+ if ( !ok )
+ quantity2 = 0;
+ else
+ quantity2 = number.toDouble();
+ }
+ offset = quantity2 - quantity1;
Ingredient new_ing( el.attribute( "name" ),
- el.attribute( "qty" ).toDouble(),
- Unit( el.attribute( "unit" ), el.attribute( "qty" ).toDouble() ) );
+ quantity1,
+ Unit( el.attribute( "unit" ), quantity1 ) );
+ new_ing.amount_offset = offset;
if ( el.hasChildNodes() ) {
TQDomNodeList iChilds = el.childNodes();
- for ( unsigned j = 0; j < iChilds.count(); j++ ) {
+ for ( int j = 0; j < iChilds.count(); j++ ) {
TQDomElement iChild = iChilds.item( j ).toElement();
- if ( iChild.tagName() == "IPrp" )
- new_ing.prepMethodList.append( Element(iChild.text().stripWhiteSpace()) );
- else if ( iChild.tagName() == "INtI" )
+ if ( iChild.tagName() == "IPrp" ) {
+ TQString prepMethodStr = iChild.text().stripWhiteSpace();
+ 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 );