void MXPImporter::loadCategories( QTextStream &stream, Recipe &recipe ) { //====================categories====================// stream.skipWhiteSpace(); QString current = stream.readLine().trimmed(); if ( current.mid( 0, current.indexOf( ":" ) ).simplified().toLower() == "categories" ) { QString tmp_str = current.mid( current.indexOf( ":" ) + 1, current.length() ).trimmed(); while ( current.trimmed() != "Amount Measure Ingredient -- Preparation Method" && !stream.atEnd() ) { if ( !tmp_str.isEmpty() ) { const QStringList categories = tmp_str.split( QRegExp("\t| "), QString::SkipEmptyParts ); for ( QStringList::const_iterator it = categories.constBegin(); it != categories.constEnd(); ++it ) { Element new_cat( ( *it ).trimmed() ); recipe.categoryList.append( new_cat ); kDebug()<<"Found category: "<<new_cat.name; } } current = stream.readLine(); tmp_str = current; } //else // kDebug()<<"No categories found."; } else { addWarningMsg(i18n( "While loading recipe \"%1\" " "the field \"Categories:\" is either missing or could not be detected.", recipe.title ) ); //the ingredient loaded will expect the last thing to have been read to be this header line while ( current.trimmed() != "Amount Measure Ingredient -- Preparation Method" && !stream.atEnd() ) current = stream.readLine(); } }
bool DBFileEntry::readLine(QTextStream& stream) { if (stream.status() != QTextStream::Ok || stream.atEnd()) { return false; } stream.skipWhiteSpace(); QString line = stream.readLine(); if (line.isNull()) { return false; } //This fails if the path contains a comma. //QStringList tokens = line.split(fieldSeparator); QStringList tokens = StringHelper::split(fieldSeparator, line, 5); if (tokens.count() < 5) { return false; } if (tokens[0].length() > 0) { m_linkType = tokens[0].at(0); } m_time = QDateTime::fromString(tokens[1], dateTimeFormat); m_hash = tokens[2]; m_hash = m_hash.toUpper(); bool ok; m_size = tokens[3].toULongLong(&ok, 10); if (!ok) { return false; } m_path = tokens[4]; return true; }
void MXPImporter::loadIngredients( QTextStream &stream, Recipe &recipe ) { //============ingredients=================// stream.skipWhiteSpace(); ( void ) stream.readLine(); QString current = stream.readLine(); if ( !current.contains( "NONE" ) && !current.isEmpty() ) { while ( !current.isEmpty() && !stream.atEnd() ) { Ingredient new_ingredient; //amount QString amount_str = current.mid( 0, 9 ).simplified(); if ( !amount_str.isEmpty() ) // case of amount_str.isEmpty() correctly handled by class default { MixedNumber amount; QValidator::State state; state = MixedNumber::fromString( amount_str, amount, false ); if ( state != QValidator::Acceptable ) { addWarningMsg( i18n( "While loading recipe \"%1\" Invalid amount \"%2\" in the line \"%3\"" , recipe.title, amount_str , current.trimmed() ) ); current = stream.readLine(); continue; } new_ingredient.amount = amount.toDouble(); } //units QString units( current.mid( 9, 13 ) ); new_ingredient.units = Unit( units.simplified(), new_ingredient.amount ); //name int dash_index = current.indexOf( "--" ); int length; if ( dash_index == -1 || dash_index == 24 ) //ignore a dash in the first position (index 24) length = current.length(); else length = dash_index - 22; QString ingredient_name( current.mid( 22, length ) ); new_ingredient.name = ingredient_name.trimmed(); //prep method if ( dash_index != -1 && dash_index != 24 ) //ignore a dash in the first position (index 24) new_ingredient.prepMethodList.append( Element(current.mid( dash_index + 2, current.length() ).trimmed()) ); recipe.ingList.append( new_ingredient ); //kDebug()<<"Found ingredient: amount="<<new_ingredient.amount // <<", unit:"<<new_ingredient.units // <<", name:"<<new_ingredient.name // <<", prep_method:"<<prep_method; current = stream.readLine(); } } //else // kDebug()<<"No ingredients found."; }
void ColorMap::loadMap( QTextStream& stream ) { ColorMapNode* pHead, *pTail, *node; double position, red, green, blue; int size; QString junk; stream.skipWhiteSpace(); junk = stream.readLine(); // ColorMap stream.skipWhiteSpace(); junk = stream.readLine(); // Number of nodes stream >> size; stream.skipWhiteSpace(); junk = stream.readLine(); // Position and R G B stream >> position >> red >> green >> blue; pHead = new ColorMapNode(position, red, green, blue, 0, 0); stream >> position >> red >> green >> blue; pTail = new ColorMapNode(position, red, green, blue, 0, 0); node = pHead; for( int i=1;i<size-1; i++ ) { stream >> position >> red >> green >> blue; node->m_pNext = new ColorMapNode(position, red, green, blue, node, 0); node = node->m_pNext; } node->m_pNext = pTail; pTail->m_pPrev = node; // if successful, replace lists delete m_pHead; m_pHead = pHead; m_pTail = pTail; m_Size = size; }
void MXPImporter::loadInstructions( QTextStream &stream, Recipe &recipe ) { //==========================instructions ( along with other optional fields... mxp format doesn't define end of ingredients and start of other fields )==============// stream.skipWhiteSpace(); QString current = stream.readLine().trimmed(); while ( !current.contains( "- - - -" ) && !stream.atEnd() ) { if ( current.trimmed() == "Source:" ) { Element new_author( getNextQuotedString( stream ) ); recipe.authorList.append( new_author ); //kDebug()<<"Found source: "<<new_author.name<<" (adding as author)"; } else if ( current.trimmed() == "Description:" ) { QString description = getNextQuotedString( stream ); //kDebug()<<"Found description: "<<m_description<<" (adding to end of instructions)"; recipe.instructions += "\n\nDescription: " + description; } else if ( current.trimmed() == "S(Internet Address):" ) { QString internet = getNextQuotedString( stream ); //kDebug()<<"Found internet address: "<<m_internet<<" (adding to end of instructions)"; recipe.instructions += "\n\nInternet address: " + internet; } else if ( current.trimmed() == "Yield:" ) { recipe.yield.setAmount(getNextQuotedString( stream ).trimmed().toInt()); recipe.yield.setType(i18n("servings")); //kDebug()<<"Found yield: "<<recipe.yield.amount<<" (adding as servings)"; } else if ( current.trimmed() == "T(Cook Time):" ) { ( void ) getNextQuotedString( stream ); //this would be prep time, but we don't use prep time at the moment //kDebug()<<"Found cook time: "<<m_prep_time<<" (adding as prep time)"; } else if ( current.trimmed() == "Cuisine:" ) { Element new_cat( getNextQuotedString( stream ) ); recipe.categoryList.append( new_cat ); //kDebug()<<"Found cuisine (adding as category): "<<new_cat.name; } else recipe.instructions += current + '\n'; current = stream.readLine().trimmed(); } recipe.instructions = recipe.instructions.trimmed(); //kDebug()<<"Found instructions: "<<m_instructions; }
bool B9LayoutProjectData::Open(QString filepath, bool withoutVisuals) //returns success { int i; int FileVersion; bool jumpout = false; double resx; double resy; double xp, yp, zp;//instance positions/rotations/scales double xr, yr, zr; double xs, ys, zs; bool flipped = false; int numSupports; int hasFoundation; QFile file(filepath); QTextStream in; QString buff;//for io operations QString modelpath;//current model this function is trying to load. //input file operations here if(!file.open(QIODevice::ReadOnly)) { return false; } //check file extension if(QFileInfo(filepath).completeSuffix().toLower() != "b9l") return false; SetDirtied(false);//presumably good from here so undirty the project in.setDevice(&file);//begin text streaming. in >> buff; if(buff == "ver")//we are looking at a post 1.4 b9 layout file { in >> buff; FileVersion = buff.toInt();//should be 14 or greater. in.skipWhiteSpace(); mfilename = in.readLine();//get project name }
QString MXPImporter::getNextQuotedString( QTextStream &stream ) { stream.skipWhiteSpace(); QString current = stream.readLine().trimmed(); QString return_str; if ( current.left( 1 ) == "\"" ) return_str = current.mid( 1, current.length() - 1 ); else return current; while ( current.right( 1 ) != "\"" && !stream.atEnd() ) { current = stream.readLine().trimmed(); return_str += '\n' + current; } //take off quote at end return_str = return_str.mid( 0, return_str.length() - 1 ); return return_str.trimmed(); }
Soprano::Node Soprano::N3NodeParser::parseNode( QTextStream& s, Node::N3ParserFlags flags ) const { clearError(); s.skipWhiteSpace(); Node node; // we treat the empty string as an empty node without an error if ( s.atEnd() ) { return Node(); } QChar c; s >> c; // parser resource node // ============================================ if ( c == '<' ) { QString str; if ( scanStream( s, &str, '>' ) ) { node = Soprano::Node( QUrl::fromEncoded( str.toLatin1(), flags&Node::StrictUris ? QUrl::StrictMode : QUrl::TolerantMode ) ); } } // parse blank node // ============================================ else if ( c == '_' ) { s >> c; if ( c == ':' ) { // TODO: restrict the charset QString str; s >> str; if ( !str.isEmpty() ) node = Soprano::Node::createBlankNode( str ); }
void MXPImporter::importMXP( QTextStream &stream ) { Recipe recipe; kapp->processEvents(); //don't want the user to think its frozen... especially for files with thousands of recipes //kDebug()<<"Found recipe MXP format: * Exported from MasterCook *"; QString current; // title stream.skipWhiteSpace(); recipe.title = stream.readLine().trimmed(); //kDebug()<<"Found title: "<<m_title; //author stream.skipWhiteSpace(); current = stream.readLine().trimmed(); if ( current.mid( 0, current.indexOf( ":" ) ).simplified().toLower() == "recipe by" ) { Element new_author( current.mid( current.indexOf( ":" ) + 1, current.length() ).trimmed() ); recipe.authorList.append( new_author ); //kDebug()<<"Found author: "<<new_author.name; } else { addWarningMsg( i18n( "While loading recipe \"%1\" " "the field \"Recipe By:\" is either missing or could not be detected.", recipe.title ) ); } //servings stream.skipWhiteSpace(); current = stream.readLine().trimmed(); if ( current.mid( 0, current.indexOf( ":" ) ).simplified().toLower() == "serving size" ) { //allows serving size to be loaded even if preparation time is missing int end_index; if ( current.contains( "preparation time", Qt::CaseInsensitive ) ) end_index = current.indexOf( "preparation time", 0, Qt::CaseInsensitive ) - 15; else end_index = current.length(); recipe.yield.setAmount(current.mid( current.indexOf( ":" ) + 1, end_index ).trimmed().toInt()); recipe.yield.setType(i18n("servings")); //kDebug()<<"Found serving size: "<<recipe.yield.amount; } else { addWarningMsg( i18n( "While loading recipe \"%1\" " "the field \"Serving Size:\" is either missing or could not be detected." , recipe.title ) ); } if ( current.contains( "preparation time", Qt::CaseInsensitive ) ) { QString prep_time = current.mid( current.indexOf( ":", current.indexOf( "preparation time", 0, Qt::CaseInsensitive ) ) + 1, current.length() ).trimmed(); recipe.prepTime = QTime( prep_time.section( ':', 0, 0 ).toInt(), prep_time.section( ':', 1, 1 ).toInt() ); kDebug() << "Found preparation time: " << prep_time ; } else { addWarningMsg( i18n( "While loading recipe \"%1\" " "the field \"Preparation Time:\" is either missing or could not be detected." , recipe.title ) ); } loadCategories( stream, recipe ); loadIngredients( stream, recipe ); loadInstructions( stream, recipe ); loadOptionalFields( stream, recipe ); add ( recipe ); if ( !stream.atEnd() ) { importMXP( stream ); return ; } }
void MXPImporter::loadOptionalFields( QTextStream &stream, Recipe &recipe ) { //=================after here, fields are optional=========================// stream.skipWhiteSpace(); QString current = stream.readLine().trimmed(); QString notes; //Note: we simplified() because some versions of MasterCook have "Exported from MasterCook" and others have "Exported from MasterCook". // This also could work around a typo or such. while ( !current.simplified().contains( "Exported from MasterCook" ) && !stream.atEnd() ) { //suggested wine if ( current.mid( 0, current.indexOf( ":" ) ).simplified().toLower() == "suggested wine" ) { QString wine = current.mid( current.indexOf( ":" ) + 1, current.length() ).trimmed(); //kDebug()<<"Found suggested wine: "<<m_wine<<" (adding to end of instructions)"; recipe.instructions += "\n\nSuggested wine: " + wine; } //Nutr. Assoc. if ( current.mid( 0, current.indexOf( ":" ) ).simplified().toLower() == "nutr. assoc." ) { QString nutr_assoc = current.mid( current.indexOf( ":" ) + 1, current.length() ).trimmed(); //kDebug()<<"Found nutrient association: "<<nutr_assoc<<" (adding to end of instructions)"; recipe.instructions += "\n\nNutrient Association: " + nutr_assoc; } else if ( current.mid( 0, current.indexOf( ":" ) ).simplified().toLower() == "per serving (excluding unknown items)" ) { //per serving... maybe we can do something with this info later QString per_serving_info = current.mid( current.indexOf( ":" ) + 1, current.length() ).trimmed(); //kDebug()<<"Found per serving (excluding unknown items): "<<per_serving_info<<" (adding to end of instructions)"; recipe.instructions += "\n\nPer Serving (excluding unknown items): " + per_serving_info; } else if ( current.mid( 0, current.indexOf( ":" ) ).simplified().toLower() == "per serving" ) { //per serving... maybe we can do something with this info later QString per_serving_info = current.mid( current.indexOf( ":" ) + 1, current.length() ).trimmed(); //kDebug()<<"Found per serving: "<<per_serving_info<<" (adding to end of instructions)"; recipe.instructions += "\n\nPer Serving: " + per_serving_info; } else if ( current.mid( 0, current.indexOf( ":" ) ).simplified().toLower() == "food exchanges" ) { //food exchanges... maybe we can do something with this info later QString food_exchange_info = current.mid( current.indexOf( ":" ) + 1, current.length() ).trimmed(); //kDebug()<<"Found food exchanges: "<<food_exchange_info<<" (adding to end of instructions)"; recipe.instructions += "\n\nFood Exchanges: " + food_exchange_info; } else if ( current.mid( 0, current.indexOf( ":" ) ).simplified().toLower() == "serving ideas" ) { //serving ideas QString serving_ideas = current.mid( current.indexOf( ":" ) + 1, current.length() ).trimmed(); //kDebug()<<"Found serving ideas: "<<m_serving_ideas<<" (adding to end of instructions)"; recipe.instructions += "\n\nServing ideas: " + serving_ideas; } else if ( current.mid( 0, current.indexOf( ":" ) ).simplified().toLower() == "notes" ) //notes notes = current.mid( current.indexOf( ":" ) + 1, current.length() ).trimmed(); else if ( !current.isEmpty() && current != "_____" ) //if it doesn't belong to any other field, assume it a part of a multi-line notes field notes += '\n' + current; current = stream.readLine().trimmed(); } /*possible fields to implement later: Nutr. Assoc. : 0 0 0 0 0 Ratings : Cholesterol Rating 5 Complete Meal 3 Cost 3 Depth 3 Difficulty 2 Fanciness 7 Fat Content 5 Good For Crowds 10 Intensity 5 Intricacy 2 Kid Appeal 3 Looks 5 Portability 3 Richness 7 Serving Temperature 8 Spicy Hotness 2 Tartness 7 */ if ( !notes.isEmpty() ) { //kDebug()<<"Found notes:" << m_notes << "(adding to end of instructions)"; recipe.instructions += "\n\nNotes: " + notes.trimmed(); } }
// // This method will convert the desired text into morse code bits: // void TorMorse::translateTextToBits( QTextStream &stream) { morseCodeBits.clear(); QChar c; while (!stream.atEnd()) { stream >> c; switch (c.toAscii()) { case 'a': case 'A': dot(); dash(); break; case 'b': case 'B': dash(); dot(); dot(); dot(); break; case 'c': case 'C': dash(); dot(); dash(); dot(); break; case 'd': case 'D': dash(); dot(); dot(); break; case 'e': case 'E': dot(); break; case 'f': case 'F': dot(); dot(); dash(); dot(); break; case 'g': case 'G': dash(); dash(); dot(); break; case 'h': case 'H': dot(); dot(); dot(); dot(); break; case 'i': case 'I': dot(); dot(); break; case 'j': case 'J': dot(); dash(); dash(); dash(); break; case 'k': case 'K': dash(); dot(); dash(); break; case 'l': case 'L': dot(); dash(); dot(); dot(); break; case 'm': case 'M': dash(); dash(); break; case 'n': case 'N': dash(); dot(); break; case 'o': case 'O': dash(); dash(); dash(); break; case 'p': case 'P': dot(); dash(); dash(); dot(); break; case 'q': case 'Q': dash(); dash(); dot(); dash(); break; case 'r': case 'R': dot(); dash(); dot(); break; case 's': case 'S': dot(); dot(); dot(); break; case 't': case 'T': dash(); break; case 'u': case 'U': dot(); dot(); dash(); break; case 'v': case 'V': dot(); dot(); dot(); dash(); break; case 'w': case 'W': dot(); dash(); dash(); break; case 'x': case 'X': dash(); dot(); dot(); dash(); break; case 'y': case 'Y': dash(); dot(); dash(); dash(); break; case 'z': case 'Z': dash(); dash(); dot(); dot(); break; case '0': dash(); dash(); dash(); dash(); dash(); break; case '1': dot(); dash(); dash(); dash(); dash(); break; case '2': dot(); dot(); dash(); dash(); dash(); break; case '3': dot(); dot(); dot(); dash(); dash(); break; case '4': dot(); dot(); dot(); dot(); dash(); break; case '5': dot(); dot(); dot(); dot(); dot(); break; case '6': dash(); dot(); dot(); dot(); dot(); break; case '7': dash(); dash(); dot(); dot(); dot(); break; case '8': dash(); dash(); dash(); dot(); dot(); break; case '9': dash(); dash(); dash(); dash(); dot(); break; case '.': dot(); dash(); dot(); dash(); dot(); dash(); break; case ',': dash(); dash(); dot(); dot(); dash(); dash(); break; case '?': dot(); dot(); dash(); dash(); dot(); dot(); break; case '\'': dot(); dash(); dash(); dash(); dash(); dot(); break; case '!': dash(); dot(); dash(); dot(); dash(); dash(); break; case '/': dash(); dot(); dot(); dash(); dot(); break; case '(': dash(); dot(); dash(); dash(); dot(); break; case ')': dash(); dot(); dash(); dash(); dot(); dash(); break; case '&': dot(); dash(); dot(); dot(); dot(); break; case ':': dash(); dash(); dash(); dot(); dot(); dot(); break; case ';': dash(); dot(); dash(); dot(); dash(); dot(); break; case '=': dash(); dot(); dot(); dot(); dash(); break; case '+': dot(); dash(); dot(); dash(); dot(); break; case '-': dash(); dot(); dot(); dot(); dot(); dash(); break; case '_': dot(); dot(); dash(); dash(); dot(); dash(); break; case '"': dot(); dash(); dot(); dot(); dash(); dot(); break; case '$': dot(); dot(); dot(); dash(); dot(); dot(); dash(); break; case '@': dot(); dash(); dash(); dot(); dash(); dot(); break; case ' ': // End of a word, so need to add 4 units to the 3-unit character gap: fourUnitGap(); // Also, clear out any extra whitespace chars: stream.skipWhiteSpace(); break; default: break; } // At the end of every character is a 3 unit gap: threeUnitGap(); } }
void NYCGenericImporter::importNYCGeneric( QTextStream &stream ) { kapp->processEvents(); //don't want the user to think its frozen... especially for files with thousands of recipes QString current; stream.skipWhiteSpace(); //title while ( !( current = stream.readLine() ).isEmpty() && !stream.atEnd() ) m_recipe.title = current; //categories while ( !( current = stream.readLine() ).isEmpty() && !stream.atEnd() ) { if ( current[ 0 ].isNumber() ) { loadIngredientLine( current ); break; } //oops, this is really an ingredient line (there was no category line) QStringList categories = current.split( ',', QString::SkipEmptyParts ); if ( categories.count() > 0 && categories[ 0 ].toUpper() == "none" ) //there are no categories break; for ( QStringList::const_iterator it = categories.constBegin(); it != categories.constEnd(); ++it ) { Element new_cat( QString( *it ).trimmed() ); kDebug() << "Found category: " << new_cat.name ; m_recipe.categoryList.append( new_cat ); } } //ingredients while ( !( current = stream.readLine() ).isEmpty() && !stream.atEnd() ) loadIngredientLine( current ); //everything else is the instructions with optional "contributor", "prep time" and "yield" bool found_next; while ( !( found_next = ( current = stream.readLine() ).startsWith( "@@@@@" ) ) && !stream.atEnd() ) { if ( current.startsWith( "Contributor:" ) ) { Element new_author( current.mid( current.indexOf( ':' ) + 1, current.length() ).trimmed() ); kDebug() << "Found author: " << new_author.name ; m_recipe.authorList.append( new_author ); } else if ( current.startsWith( "Preparation Time:" ) ) { m_recipe.prepTime = QTime::fromString( current.mid( current.indexOf( ':' ), current.length() ) ); } else if ( current.startsWith( "Yield:" ) ) { int colon_index = current.indexOf( ':' ); int amount_type_sep_index = current.indexOf(" ",colon_index+1); m_recipe.yield.setAmount(current.mid( colon_index+2, amount_type_sep_index-colon_index ).toDouble()); m_recipe.yield.setType(current.mid( amount_type_sep_index+3, current.length() )); } else if ( current.startsWith( "NYC Nutrition Analysis (per serving or yield unit):" ) ) { //m_recipe.instructions += current + '\n'; } else if ( current.startsWith( "NYC Nutrilink:" ) ) { //m_recipe.instructions += current + '\n'; } else if ( !current.trimmed().isEmpty() && !current.startsWith("** Exported from Now You're Cooking!") ) { m_recipe.instructions += current + '\n'; } } m_recipe.instructions = m_recipe.instructions.trimmed(); putDataInRecipe(); if ( found_next ) importNYCGeneric( stream ); }