summaryrefslogtreecommitdiffstats
path: root/src/importers
diff options
context:
space:
mode:
authorMichele Calgaro <michele.calgaro@yahoo.it>2025-05-24 13:55:19 +0900
committerMichele Calgaro <michele.calgaro@yahoo.it>2025-08-03 13:26:11 +0900
commitfbc41d795b8251180e09d003171f346487e7ab25 (patch)
tree6199fae0522a9d4c22a917de9b0b00d31ac4faa4 /src/importers
parent9a622918b2f64e81006356124a045ba99cc3765d (diff)
downloadkrecipes-fbc41d79.tar.gz
krecipes-fbc41d79.zip
Fix importers/exporters bugs. Fix tests and add them to build process.
The file `mx2test.txt` is taken from KRecipes 2.1 source code. Other tests have been adjusted based on the tests in KRecipes 2.1 source code. Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it> Signed-off-by: Alexander Golubev <fatzer2@gmail.com> (cherry picked from commit dfbafdbb2f7369438a750327544f9084a765e407)
Diffstat (limited to 'src/importers')
-rw-r--r--src/importers/mx2importer.cpp37
-rw-r--r--src/importers/mxpimporter.cpp2
-rw-r--r--src/importers/rezkonvimporter.cpp7
3 files changed, 34 insertions, 12 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 );
diff --git a/src/importers/mxpimporter.cpp b/src/importers/mxpimporter.cpp
index 22a4db4..9a0221f 100644
--- a/src/importers/mxpimporter.cpp
+++ b/src/importers/mxpimporter.cpp
@@ -142,7 +142,7 @@ void MXPImporter::loadCategories( TQTextStream &stream, Recipe &recipe )
while ( current.stripWhiteSpace() != "Amount Measure Ingredient -- Preparation Method" && !stream.atEnd() ) {
if ( !tmp_str.isEmpty() ) {
- TQStringList categories = TQStringList::split( " ", tmp_str );
+ TQStringList categories = TQStringList::split( "\t", tmp_str );
for ( TQStringList::const_iterator it = categories.begin(); it != categories.end(); ++it ) {
Element new_cat( ( *it ).stripWhiteSpace() );
recipe.categoryList.append( new_cat );
diff --git a/src/importers/rezkonvimporter.cpp b/src/importers/rezkonvimporter.cpp
index 58e59c0..49a1e0b 100644
--- a/src/importers/rezkonvimporter.cpp
+++ b/src/importers/rezkonvimporter.cpp
@@ -198,6 +198,7 @@ void RezkonvImporter::loadInstructions( TQStringList::const_iterator &text_it, R
TQString instr;
TQRegExp rx_title( "^:{0,1}\\s*O-Titel\\s*:" );
TQString line;
+ text_it++;
while ( text_it != m_end_it ) {
line = *text_it;
@@ -216,12 +217,8 @@ void RezkonvImporter::loadInstructions( TQStringList::const_iterator &text_it, R
kdDebug() << "Found long title: " << recipe.title << endl;
}
else {
- if ( line.isEmpty() )
- instr += "\n\n";
-
- instr += line;
+ instr += line.stripWhiteSpace();
}
-
text_it++;
}