summaryrefslogtreecommitdiffstats
path: root/krecipes/src/backends/recipedb.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'krecipes/src/backends/recipedb.cpp')
-rw-r--r--krecipes/src/backends/recipedb.cpp246
1 files changed, 123 insertions, 123 deletions
diff --git a/krecipes/src/backends/recipedb.cpp b/krecipes/src/backends/recipedb.cpp
index 9df42df..1f6be92 100644
--- a/krecipes/src/backends/recipedb.cpp
+++ b/krecipes/src/backends/recipedb.cpp
@@ -30,9 +30,9 @@
#include <kfilterdev.h>
#include <kmessagebox.h>
-#include <qfile.h>
-#include <qstringlist.h>
-#include <qtextstream.h>
+#include <ntqfile.h>
+#include <ntqstringlist.h>
+#include <ntqtextstream.h>
#include <map>
@@ -65,14 +65,14 @@
struct ingredient_nutrient_data
{
int usda_id;
- QString name;
- QValueList<double> data;
+ TQString name;
+ TQValueList<double> data;
WeightList weights;
};
RecipeDB::RecipeDB() :
DCOPObject(),
- QObject(), m_categoryCache(0), haltOperation(false)
+ TQObject(), m_categoryCache(0), haltOperation(false)
{
dbOK = false;
dbErr = "";
@@ -87,33 +87,33 @@ double RecipeDB::latestDBVersion() const
return 0.95;
}
-QString RecipeDB::krecipes_version() const
+TQString RecipeDB::krecipes_version() const
{
KInstance * this_instance = KGlobal::instance();
if ( this_instance && this_instance->aboutData() )
return this_instance->aboutData() ->version();
- return QString::null; //Oh, well. We couldn't get the version (shouldn't happen).
+ return TQString::null; //Oh, well. We couldn't get the version (shouldn't happen).
}
-RecipeDB* RecipeDB::createDatabase( const QString &dbType, const QString &file )
+RecipeDB* RecipeDB::createDatabase( const TQString &dbType, const TQString &file )
{
KConfig * config = kapp->config();
config->setGroup( "Server" );
- QString host = config->readEntry( "Host", "localhost" );
- QString user = config->readEntry( "Username", QString::null );
- QString pass = config->readEntry( "Password", QString::null );
- QString dbname = config->readEntry( "DBName", DEFAULT_DB_NAME );
+ TQString host = config->readEntry( "Host", "localhost" );
+ TQString user = config->readEntry( "Username", TQString::null );
+ TQString pass = config->readEntry( "Password", TQString::null );
+ TQString dbname = config->readEntry( "DBName", DEFAULT_DB_NAME );
int port = config->readNumEntry( "Port", 0 );
- QString f = file;
+ TQString f = file;
if ( f.isEmpty() )
f = config->readEntry( "DBFile", locateLocal ( "appdata", DB_FILENAME ) );
return createDatabase( dbType, host, user, pass, dbname, port, f );
}
-RecipeDB* RecipeDB::createDatabase( const QString &dbType, const QString &host, const QString &user, const QString &pass, const QString &dbname, int port, const QString &file )
+RecipeDB* RecipeDB::createDatabase( const TQString &dbType, const TQString &host, const TQString &user, const TQString &pass, const TQString &dbname, int port, const TQString &file )
{
RecipeDB * database = 0;
@@ -244,14 +244,14 @@ RecipeDB::ConversionStatus RecipeDB::convertIngredientUnits( const Ingredient &f
return Success;
}
else {
- QString to_str;
+ TQString to_str;
switch ( to.type ) {
case Unit::Other: to_str = "Other"; break;
case Unit::Mass: to_str = "Mass"; break;
case Unit::Volume: to_str = "Volume"; break;
case Unit::All: kdDebug()<<"Code error: trying to convert to unit of type 'All'"<<endl; return InvalidTypes;
}
- QString from_str;
+ TQString from_str;
switch ( from.units.type ) {
case Unit::Other: from_str = "Other"; break;
case Unit::Mass: from_str = "Mass"; break;
@@ -264,22 +264,22 @@ RecipeDB::ConversionStatus RecipeDB::convertIngredientUnits( const Ingredient &f
}
}
-bool RecipeDB::backup( const QString &backup_file, QString *errMsg )
+bool RecipeDB::backup( const TQString &backup_file, TQString *errMsg )
{
kdDebug()<<"Backing up current database to "<<backup_file<<endl;
KProcess *p = new KProcess;
//p->setUseShell(true);
- QIODevice *dumpFile = KFilterDev::deviceForFile(backup_file,"application/x-gzip");
+ TQIODevice *dumpFile = KFilterDev::deviceForFile(backup_file,"application/x-gzip");
if ( !dumpFile->open( IO_WriteOnly ) ) {
kdDebug()<<"Couldn't open "<<backup_file<<endl;
return false;
}
- dumpStream = new QTextStream( dumpFile );
+ dumpStream = new TQTextStream( dumpFile );
- QStringList command = backupCommand();
+ TQStringList command = backupCommand();
if ( command.count() == 0 ) {
kdDebug()<<"Backup not available for this database backend"<<endl;
return false;
@@ -295,21 +295,21 @@ bool RecipeDB::backup( const QString &backup_file, QString *errMsg )
kdDebug()<<"Running '"<<command.first()<<"' to create backup file"<<endl;
*p << command /*<< ">" << backup_file*/;
- QApplication::connect( p, SIGNAL(receivedStdout(KProcess*,char*,int)), this, SLOT(processDumpOutput(KProcess*,char*,int)) );
- QApplication::connect( p, SIGNAL(receivedStderr(KProcess*,char*,int)), this, SLOT(processDumpOutput(KProcess*,char*,int)) );
+ TQApplication::connect( p, SIGNAL(receivedStdout(KProcess*,char*,int)), this, SLOT(processDumpOutput(KProcess*,char*,int)) );
+ TQApplication::connect( p, SIGNAL(receivedStderr(KProcess*,char*,int)), this, SLOT(processDumpOutput(KProcess*,char*,int)) );
- emit progressBegin(0,QString::null,
- QString("<center><b>%1</b></center>%2")
+ emit progressBegin(0,TQString::null,
+ TQString("<center><b>%1</b></center>%2")
.arg(i18n("Creating complete backup"))
.arg(i18n("Depending on the number of recipes and amount of data, this could take some time.")),50);
bool success = p->start( KProcess::Block, KProcess::AllOutput );
if ( !success ) {
- if ( errMsg ) *errMsg = QString(i18n("Unable to find or run the program '%1'. Either it is not installed on your system or it is not in $PATH.")).arg(command.first());
+ if ( errMsg ) *errMsg = TQString(i18n("Unable to find or run the program '%1'. Either it is not installed on your system or it is not in $PATH.")).arg(command.first());
delete p;
delete dumpStream;
delete dumpFile;
- QFile::remove(backup_file);
+ TQFile::remove(backup_file);
emit progressDone();
return false;
}
@@ -320,15 +320,15 @@ bool RecipeDB::backup( const QString &backup_file, QString *errMsg )
//but delete the file we created
if ( !p->normalExit() ) {
kdDebug()<<"Process killed, deleting partial backup."<<endl;
- QFile::remove(backup_file);
+ TQFile::remove(backup_file);
}
if ( p->exitStatus() != 0 ) {
//Since the process failed, dumpStream should have output from the app as to why it did
- QString appOutput;
+ TQString appOutput;
dumpFile->close();
if ( dumpFile->open( IO_ReadOnly ) ) {
- QTextStream appErrStream( dumpFile );
+ TQTextStream appErrStream( dumpFile );
//ignore our own versioning output
appErrStream.readLine();
@@ -340,8 +340,8 @@ bool RecipeDB::backup( const QString &backup_file, QString *errMsg )
else
kdDebug()<<"Unable to open file to get error output."<<endl;
- if ( errMsg ) *errMsg = QString("%1\n%2").arg(i18n("Backup failed.")).arg(appOutput);
- QFile::remove(backup_file);
+ if ( errMsg ) *errMsg = TQString("%1\n%2").arg(i18n("Backup failed.")).arg(appOutput);
+ TQFile::remove(backup_file);
delete p;
delete dumpStream;
delete dumpFile;
@@ -369,24 +369,24 @@ void RecipeDB::initializeData( void )
// Populate with data
// Read the commands form the data file
- QFile datafile( KGlobal::dirs() ->findResource( "appdata", "data/data.sql" ) );
+ TQFile datafile( KGlobal::dirs() ->findResource( "appdata", "data/data.sql" ) );
if ( datafile.open( IO_ReadOnly ) ) {
- QTextStream stream( &datafile );
+ TQTextStream stream( &datafile );
execSQL(stream);
datafile.close();
}
}
-bool RecipeDB::restore( const QString &file, QString *errMsg )
+bool RecipeDB::restore( const TQString &file, TQString *errMsg )
{
- QIODevice *dumpFile = KFilterDev::deviceForFile(file,"application/x-gzip");
+ TQIODevice *dumpFile = KFilterDev::deviceForFile(file,"application/x-gzip");
if ( dumpFile->open( IO_ReadOnly ) ) {
- QTextStream stream( dumpFile );
- QString firstLine = stream.readLine().stripWhiteSpace();
- QString dbVersion = stream.readLine().stripWhiteSpace();
+ TQTextStream stream( dumpFile );
+ TQString firstLine = stream.readLine().stripWhiteSpace();
+ TQString dbVersion = stream.readLine().stripWhiteSpace();
dbVersion = dbVersion.right( dbVersion.length() - dbVersion.find(":") - 2 );
- if ( qRound(dbVersion.toDouble()*1e5) > qRound(latestDBVersion()*1e5) ) { //correct for float's imprecision
+ if ( tqRound(dbVersion.toDouble()*1e5) > tqRound(latestDBVersion()*1e5) ) { //correct for float's imprecision
if ( errMsg ) *errMsg = i18n( "This backup was created with a newer version of Krecipes and cannot be restored." );
delete dumpFile;
return false;
@@ -394,15 +394,15 @@ bool RecipeDB::restore( const QString &file, QString *errMsg )
KConfig * config = kapp->config();
config->setGroup( "DBType" );
- QString dbType = stream.readLine().stripWhiteSpace();
+ TQString dbType = stream.readLine().stripWhiteSpace();
dbType = dbType.right( dbType.length() - dbType.find(":") - 2 );
if ( dbType.isEmpty() || !firstLine.startsWith("-- Generated for Krecipes") ) {
if ( errMsg ) *errMsg = i18n("This file is not a Krecipes backup file or has become corrupt.");
delete dumpFile;
return false;
}
- else if ( dbType != config->readEntry("Type",QString::null) ) {
- if ( errMsg ) *errMsg = QString(i18n("This backup was created using the \"%1\" backend. It can only be restored into a database using this backend." )).arg(dbType);
+ else if ( dbType != config->readEntry("Type",TQString::null) ) {
+ if ( errMsg ) *errMsg = TQString(i18n("This backup was created using the \"%1\" backend. It can only be restored into a database using this backend." )).arg(dbType);
delete dumpFile;
return false;
}
@@ -416,19 +416,19 @@ bool RecipeDB::restore( const QString &file, QString *errMsg )
KProcIO *process = new KProcIO;
- QStringList command = restoreCommand();
+ TQStringList command = restoreCommand();
kdDebug()<<"Restoring backup using: "<<command[0]<<endl;
*process << command;
//process->setComm( KProcess::Stdin );
if ( process->start( KProcess::NotifyOnExit ) ) {
- emit progressBegin(0,QString::null,
- QString("<center><b>%1</b></center>%2")
+ emit progressBegin(0,TQString::null,
+ TQString("<center><b>%1</b></center>%2")
.arg(i18n("Restoring backup"))
.arg(i18n("Depending on the number of recipes and amount of data, this could take some time.")));
do {
- QByteArray array(4096);
+ TQByteArray array(4096);
int len = dumpFile->readBlock(array.data(),array.size());
array.resize(len);
@@ -486,17 +486,17 @@ bool RecipeDB::restore( const QString &file, QString *errMsg )
return true;
}
-void RecipeDB::execSQL( QTextStream &stream )
+void RecipeDB::execSQL( TQTextStream &stream )
{
- QString line, command;
- while ( (line = stream.readLine()) != QString::null ) {
+ TQString line, command;
+ while ( (line = stream.readLine()) != TQString::null ) {
command += " "+line;
if ( command.startsWith(" --") ) {
- command = QString::null;
+ command = TQString::null;
}
else if ( command.endsWith(";") ) {
execSQL( command );
- command = QString::null;
+ command = TQString::null;
}
}
}
@@ -504,7 +504,7 @@ void RecipeDB::execSQL( QTextStream &stream )
void RecipeDB::loadRecipe( Recipe *recipe, int items, int id )
{
RecipeList rlist;
- QValueList<int> ids; ids << id;
+ TQValueList<int> ids; ids << id;
loadRecipes( &rlist, items, ids );
*recipe = *rlist.begin();
@@ -537,7 +537,7 @@ int RecipeDB::unitCount()
void RecipeDB::importSamples()
{
- QString sample_recipes = locate( "appdata", "data/samples-" + KGlobal::locale() ->language() + ".kreml" );
+ TQString sample_recipes = locate( "appdata", "data/samples-" + KGlobal::locale() ->language() + ".kreml" );
if ( sample_recipes.isEmpty() ) {
//TODO: Make this a KMessageBox??
kdDebug() << "NOTICE: Samples recipes for the language \"" << KGlobal::locale() ->language() << "\" are not available. However, if you would like samples recipes for this language included in future releases of Krecipes, we invite you to submit your own. Just save your favorite recipes in the kreml format and e-mail them to jkivlighn@gmail.com." << endl;
@@ -547,7 +547,7 @@ void RecipeDB::importSamples()
if ( !sample_recipes.isEmpty() ) {
KreImporter importer;
- QStringList file;
+ TQStringList file;
file << sample_recipes;
importer.parseFiles( file );
@@ -557,24 +557,24 @@ void RecipeDB::importSamples()
kdDebug() << "Unable to find samples recipe file (samples-en_US.kreml)" << endl;
}
-void RecipeDB::getIDList( const CategoryTree *categoryTree, QStringList &ids )
+void RecipeDB::getIDList( const CategoryTree *categoryTree, TQStringList &ids )
{
for ( CategoryTree * child_it = categoryTree->firstChild(); child_it; child_it = child_it->nextSibling() ) {
- ids << QString::number(child_it->category.id);
+ ids << TQString::number(child_it->category.id);
getIDList(child_it,ids );
}
}
-QString RecipeDB::buildSearchQuery( const RecipeSearchParameters &p ) const
+TQString RecipeDB::buildSearchQuery( const RecipeSearchParameters &p ) const
{
- QStringList queryList, conditionList, tableList;
+ TQStringList queryList, conditionList, tableList;
if ( p.ingsOr.count() != 0 ) {
tableList << "ingredient_list il" << "ingredients i";
conditionList << "il.ingredient_id=i.id" << "il.recipe_id=r.id";
- QString condition = "(";
- for ( QStringList::const_iterator it = p.ingsOr.begin(); it != p.ingsOr.end();) {
+ TQString condition = "(";
+ for ( TQStringList::const_iterator it = p.ingsOr.begin(); it != p.ingsOr.end();) {
condition += "i.name LIKE '%"+escapeAndEncode(*it)+"%' ";
if ( ++it != p.ingsOr.end() ) {
condition += "OR ";
@@ -589,8 +589,8 @@ QString RecipeDB::buildSearchQuery( const RecipeSearchParameters &p ) const
tableList << "category_list cl" << "categories c";
conditionList << "cl.category_id=c.id" << "cl.recipe_id=r.id";
- QString condition = "(";
- for ( QStringList::const_iterator it = p.catsOr.begin(); it != p.catsOr.end();) {
+ TQString condition = "(";
+ for ( TQStringList::const_iterator it = p.catsOr.begin(); it != p.catsOr.end();) {
condition += "c.name LIKE '%"+escapeAndEncode(*it)+"%' ";
if ( ++it != p.catsOr.end() ) {
condition += "OR ";
@@ -605,8 +605,8 @@ QString RecipeDB::buildSearchQuery( const RecipeSearchParameters &p ) const
tableList << "author_list al" << "authors a";
conditionList << "al.author_id=a.id" << "al.recipe_id=r.id";
- QString condition = "(";
- for ( QStringList::const_iterator it = p.authorsOr.begin(); it != p.authorsOr.end();) {
+ TQString condition = "(";
+ for ( TQStringList::const_iterator it = p.authorsOr.begin(); it != p.authorsOr.end();) {
condition += "a.name LIKE '%"+escapeAndEncode(*it)+"%'";
if ( ++it != p.authorsOr.end() ) {
condition += "OR ";
@@ -618,10 +618,10 @@ QString RecipeDB::buildSearchQuery( const RecipeSearchParameters &p ) const
}
if ( p.titleKeywords.count() != 0 ) {
- QString op = (p.requireAllTitleWords) ? "AND " : "OR ";
+ TQString op = (p.requireAllTitleWords) ? "AND " : "OR ";
- QString condition = "(";
- for ( QStringList::const_iterator it = p.titleKeywords.begin(); it != p.titleKeywords.end();) {
+ TQString condition = "(";
+ for ( TQStringList::const_iterator it = p.titleKeywords.begin(); it != p.titleKeywords.end();) {
condition += "r.title LIKE '%"+escapeAndEncode(*it)+"%' ";
if ( ++it != p.titleKeywords.end() ) {
condition += op;
@@ -632,10 +632,10 @@ QString RecipeDB::buildSearchQuery( const RecipeSearchParameters &p ) const
}
if ( p.instructionsKeywords.count() != 0 ) {
- QString op = (p.requireAllInstructionsWords) ? "AND " : "OR ";
+ TQString op = (p.requireAllInstructionsWords) ? "AND " : "OR ";
- QString condition = "(";
- for ( QStringList::const_iterator it = p.instructionsKeywords.begin(); it != p.instructionsKeywords.end();) {
+ TQString condition = "(";
+ for ( TQStringList::const_iterator it = p.instructionsKeywords.begin(); it != p.instructionsKeywords.end();) {
condition += "r.instructions LIKE '%"+escapeAndEncode(*it)+"%' ";
if ( ++it != p.instructionsKeywords.end() ) {
condition += op;
@@ -646,12 +646,12 @@ QString RecipeDB::buildSearchQuery( const RecipeSearchParameters &p ) const
}
if ( !p.prep_time.isNull() ) {
- QString op;
+ TQString op;
switch ( p.prep_param ) {
case 0: op = "<= "+p.prep_time.toString( "'hh:mm:ss'" ); break;
case 1: //TODO: have a configurable 'about'. It tests within 15 minutes for now.
- QTime lower = p.prep_time; lower.addSecs( 60*15 );
- QTime upper = p.prep_time; upper.addSecs( 60*-15 );
+ TQTime lower = p.prep_time; lower.addSecs( 60*15 );
+ TQTime upper = p.prep_time; upper.addSecs( 60*-15 );
op = "BETWEEN "+lower.toString( "'hh:mm:ss'" )+" AND "+upper.toString( "'hh:mm:ss'" );
break;
}
@@ -659,87 +659,87 @@ QString RecipeDB::buildSearchQuery( const RecipeSearchParameters &p ) const
}
if ( p.servings > 0 ) {
- QString op;
+ TQString op;
switch ( p.servings_param ) {
- case 0: op = "> "+QString::number(p.servings); break;
- case 1: op = "< "+QString::number(p.servings); break;
- case 2: op = "BETWEEN "+QString::number(p.servings-5)+" AND "+QString::number(p.servings+5); break;
+ case 0: op = "> "+TQString::number(p.servings); break;
+ case 1: op = "< "+TQString::number(p.servings); break;
+ case 2: op = "BETWEEN "+TQString::number(p.servings-5)+" AND "+TQString::number(p.servings+5); break;
}
conditionList << "r.yield_amount "+op;
}
if ( p.createdDateBegin.isValid() ) {
if ( p.createdDateEnd.isValid() ) {
- conditionList << "r.ctime >= '"+p.createdDateBegin.toString(Qt::ISODate)+"'";
- conditionList << "r.ctime <= '"+p.createdDateEnd.toString(Qt::ISODate)+"'";
+ conditionList << "r.ctime >= '"+p.createdDateBegin.toString(TQt::ISODate)+"'";
+ conditionList << "r.ctime <= '"+p.createdDateEnd.toString(TQt::ISODate)+"'";
}
else {
if ( p.createdDateBegin.time().isNull() ) { //we just want something on a particular date, not time
- QDateTime end = p.createdDateBegin.addDays(1);
- conditionList << "r.ctime >= '"+p.createdDateBegin.toString(Qt::ISODate)+"'";
- conditionList << "r.ctime <= '"+end.toString(Qt::ISODate)+"'";
+ TQDateTime end = p.createdDateBegin.addDays(1);
+ conditionList << "r.ctime >= '"+p.createdDateBegin.toString(TQt::ISODate)+"'";
+ conditionList << "r.ctime <= '"+end.toString(TQt::ISODate)+"'";
}
else //use the exact time
- conditionList << "r.ctime = '"+p.createdDateBegin.toString(Qt::ISODate)+"'";
+ conditionList << "r.ctime = '"+p.createdDateBegin.toString(TQt::ISODate)+"'";
}
}
if ( p.modifiedDateBegin.isValid() ) {
if ( p.modifiedDateEnd.isValid() ) {
- conditionList << "r.mtime >= '"+p.modifiedDateBegin.toString(Qt::ISODate)+"'";
- conditionList << "r.mtime <= '"+p.modifiedDateEnd.toString(Qt::ISODate)+"'";
+ conditionList << "r.mtime >= '"+p.modifiedDateBegin.toString(TQt::ISODate)+"'";
+ conditionList << "r.mtime <= '"+p.modifiedDateEnd.toString(TQt::ISODate)+"'";
}
else {
if ( p.modifiedDateBegin.time().isNull() ) { //we just want something on a particular date, not time
- QDateTime end = p.modifiedDateBegin.addDays(1);
- conditionList << "r.mtime >= '"+p.modifiedDateBegin.toString(Qt::ISODate)+"'";
- conditionList << "r.mtime <= '"+end.toString(Qt::ISODate)+"'";
+ TQDateTime end = p.modifiedDateBegin.addDays(1);
+ conditionList << "r.mtime >= '"+p.modifiedDateBegin.toString(TQt::ISODate)+"'";
+ conditionList << "r.mtime <= '"+end.toString(TQt::ISODate)+"'";
}
else //use the exact time
- conditionList << "r.mtime = '"+p.modifiedDateBegin.toString(Qt::ISODate)+"'";
+ conditionList << "r.mtime = '"+p.modifiedDateBegin.toString(TQt::ISODate)+"'";
}
}
if ( p.accessedDateBegin.isValid() ) {
if ( p.accessedDateEnd.isValid() ) {
- conditionList << "r.atime >= '"+p.accessedDateBegin.toString(Qt::ISODate)+"'";
- conditionList << "r.atime <= '"+p.accessedDateEnd.toString(Qt::ISODate)+"'";
+ conditionList << "r.atime >= '"+p.accessedDateBegin.toString(TQt::ISODate)+"'";
+ conditionList << "r.atime <= '"+p.accessedDateEnd.toString(TQt::ISODate)+"'";
}
else {
if ( p.accessedDateBegin.time().isNull() ) { //we just want something on a particular date, not time
- QDateTime end = p.accessedDateBegin.addDays(1);
- conditionList << "r.atime >= '"+p.accessedDateBegin.toString(Qt::ISODate)+"'";
- conditionList << "r.atime <= '"+end.toString(Qt::ISODate)+"'";
+ TQDateTime end = p.accessedDateBegin.addDays(1);
+ conditionList << "r.atime >= '"+p.accessedDateBegin.toString(TQt::ISODate)+"'";
+ conditionList << "r.atime <= '"+end.toString(TQt::ISODate)+"'";
}
else //use the exact time
- conditionList << "r.atime = '"+p.accessedDateBegin.toString(Qt::ISODate)+"'";
+ conditionList << "r.atime = '"+p.accessedDateBegin.toString(TQt::ISODate)+"'";
}
}
- QString wholeQuery = "SELECT r.id FROM recipes r"
- +QString(tableList.count()!=0?","+tableList.join(","):"")
- +QString(conditionList.count()!=0?" WHERE "+conditionList.join(" AND "):"");
+ TQString wholeQuery = "SELECT r.id FROM recipes r"
+ +TQString(tableList.count()!=0?","+tableList.join(","):"")
+ +TQString(conditionList.count()!=0?" WHERE "+conditionList.join(" AND "):"");
kdDebug()<<"calling: "<<wholeQuery<<endl;
return wholeQuery+";";
}
//These are helper functions solely for use by the USDA data importer
-void getIngredientNameAndID( std::multimap<int, QString> * );
-int createUnit( const QString &name, Unit::Type, RecipeDB* );
-int createIngredient( const QString &name, int unit_g_id, int unit_mg_id, RecipeDB*, bool do_checks );
+void getIngredientNameAndID( std::multimap<int, TQString> * );
+int createUnit( const TQString &name, Unit::Type, RecipeDB* );
+int createIngredient( const TQString &name, int unit_g_id, int unit_mg_id, RecipeDB*, bool do_checks );
void create_properties( RecipeDB* );
void RecipeDB::importUSDADatabase()
{
//check if the data file even exists before we do anything
- QString abbrev_file = locate( "appdata", "data/abbrev.txt" );
+ TQString abbrev_file = locate( "appdata", "data/abbrev.txt" );
if ( abbrev_file.isEmpty() ) {
kdDebug() << "Unable to find abbrev.txt data file." << endl;
return ;
}
- QFile file( abbrev_file );
+ TQFile file( abbrev_file );
if ( !file.open( IO_ReadOnly ) ) {
kdDebug() << "Unable to open data file: " << abbrev_file << endl;
return ;
@@ -747,19 +747,19 @@ void RecipeDB::importUSDADatabase()
create_properties( this );
- std::multimap<int, QString> *ings_and_ids = new std::multimap<int, QString>;
+ std::multimap<int, TQString> *ings_and_ids = new std::multimap<int, TQString>;
getIngredientNameAndID( ings_and_ids );
- QTextStream stream( &file );
- QValueList<ingredient_nutrient_data> *data = new QValueList<ingredient_nutrient_data>;
+ TQTextStream stream( &file );
+ TQValueList<ingredient_nutrient_data> *data = new TQValueList<ingredient_nutrient_data>;
kdDebug() << "Parsing abbrev.txt" << endl;
while ( !stream.atEnd() ) {
- QStringList fields = QStringList::split( "^", stream.readLine(), true );
+ TQStringList fields = TQStringList::split( "^", stream.readLine(), true );
int id = fields[ 0 ].mid( 1, fields[ 0 ].length() - 2 ).toInt();
- std::multimap<int, QString>::iterator current_pair;
+ std::multimap<int, TQString>::iterator current_pair;
while ( ( current_pair = ings_and_ids->find( id ) ) != ings_and_ids->end() ) //there may be more than one ingredients with the same id
{
ingredient_nutrient_data current_ing;
@@ -771,12 +771,12 @@ void RecipeDB::importUSDADatabase()
Weight w;
w.weight = fields[ TOTAL_USDA_PROPERTIES + 2 ].toDouble();
- QString amountAndWeight = fields[ TOTAL_USDA_PROPERTIES + 3 ].mid( 1, fields[ TOTAL_USDA_PROPERTIES + 3 ].length() - 2 );
+ TQString amountAndWeight = fields[ TOTAL_USDA_PROPERTIES + 3 ].mid( 1, fields[ TOTAL_USDA_PROPERTIES + 3 ].length() - 2 );
if ( !amountAndWeight.isEmpty() ) {
int spaceIndex = amountAndWeight.find(" ");
w.perAmount = amountAndWeight.left(spaceIndex).toDouble();
- QString perAmountUnit = amountAndWeight.right(amountAndWeight.length()-spaceIndex-1);
+ TQString perAmountUnit = amountAndWeight.right(amountAndWeight.length()-spaceIndex-1);
if ( parseUSDAUnitAndPrep( perAmountUnit, w.perAmountUnit, w.prepMethod ) )
current_ing.weights << w;
@@ -788,7 +788,7 @@ void RecipeDB::importUSDADatabase()
if ( !amountAndWeight.isEmpty() ) {
int spaceIndex = amountAndWeight.find(" ");
w.perAmount = amountAndWeight.left(spaceIndex).toDouble();
- QString perAmountUnit = amountAndWeight.right(amountAndWeight.length()-spaceIndex-1);
+ TQString perAmountUnit = amountAndWeight.right(amountAndWeight.length()-spaceIndex-1);
if ( parseUSDAUnitAndPrep( perAmountUnit, w.perAmountUnit, w.prepMethod ) )
current_ing.weights << w;
@@ -823,8 +823,8 @@ void RecipeDB::importUSDADatabase()
int unit_g_id = createUnit( "g", Unit::Mass, this );
int unit_mg_id = createUnit( "mg", Unit::Mass, this );
- QValueList<ingredient_nutrient_data>::const_iterator it;
- QValueList<ingredient_nutrient_data>::const_iterator data_end = data->end();
+ TQValueList<ingredient_nutrient_data>::const_iterator it;
+ TQValueList<ingredient_nutrient_data>::const_iterator data_end = data->end();
const int total = data->count();
int counter = 0;
@@ -843,8 +843,8 @@ void RecipeDB::importUSDADatabase()
if ( do_checks ) loadProperties( &ing_properties, assigned_id );
if ( ing_properties.count() == 0 ) //ingredient doesn't already have any properties
{
- QValueList<double>::const_iterator property_it;
- QValueList<double>::const_iterator property_end = ( *it ).data.end();
+ TQValueList<double>::const_iterator property_it;
+ TQValueList<double>::const_iterator property_end = ( *it ).data.end();
int i = 0;
for ( property_it = ( *it ).data.begin(); property_it != property_end; ++property_it, ++i )
addPropertyToIngredient( assigned_id, property_data_list[ i ].id, ( *property_it ) / 100.0, unit_g_id );
@@ -889,13 +889,13 @@ void RecipeDB::importUSDADatabase()
emit progressDone();
}
-void getIngredientNameAndID( std::multimap<int, QString> *data )
+void getIngredientNameAndID( std::multimap<int, TQString> *data )
{
for ( int i = 0; !ingredient_data_list[ i ].name.isEmpty(); i++ )
data->insert( std::make_pair( ingredient_data_list[ i ].usda_id, ingredient_data_list[ i ].name ) );
}
-int createIngredient( const QString &name, int unit_g_id, int unit_mg_id, RecipeDB *database, bool do_checks )
+int createIngredient( const TQString &name, int unit_g_id, int unit_mg_id, RecipeDB *database, bool do_checks )
{
bool ingredientExisted = true;
int assigned_id = -1;
@@ -917,7 +917,7 @@ int createIngredient( const QString &name, int unit_g_id, int unit_mg_id, Recipe
return assigned_id;
}
-int createUnit( const QString &name, Unit::Type type, RecipeDB *database )
+int createUnit( const TQString &name, Unit::Type type, RecipeDB *database )
{
int assigned_id = database->findExistingUnitByName( name );
@@ -955,11 +955,11 @@ void create_properties( RecipeDB *database )
}
}
-bool parseUSDAUnitAndPrep( const QString &string, QString &unit, QString &prep )
+bool parseUSDAUnitAndPrep( const TQString &string, TQString &unit, TQString &prep )
{
int commaIndex = string.find(",");
- QString unitPart = string.left(commaIndex);
- QString prepPart = string.right(string.length()-commaIndex-2).stripWhiteSpace();
+ TQString unitPart = string.left(commaIndex);
+ TQString prepPart = string.right(string.length()-commaIndex-2).stripWhiteSpace();
bool acceptable = false;
for ( int i = 0; unit_data_list[ i ].name; ++i ) {
@@ -979,7 +979,7 @@ bool parseUSDAUnitAndPrep( const QString &string, QString &unit, QString &prep )
}
}
if ( !acceptable )
- prepPart = QString::null;
+ prepPart = TQString::null;
unit = unitPart;
prep = prepPart;