summaryrefslogtreecommitdiffstats
path: root/src/importers/baseimporter.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/importers/baseimporter.h')
-rw-r--r--src/importers/baseimporter.h126
1 files changed, 126 insertions, 0 deletions
diff --git a/src/importers/baseimporter.h b/src/importers/baseimporter.h
new file mode 100644
index 0000000..944f50e
--- /dev/null
+++ b/src/importers/baseimporter.h
@@ -0,0 +1,126 @@
+/***************************************************************************
+* Copyright (C) 2003-2005 by *
+* Unai Garro <[email protected]> *
+* Cyril Bosselut ([email protected]) *
+* Jason Kivlighn ([email protected]) *
+* *
+* This program is free software; you can redistribute it and/or modify *
+* it under the terms of the GNU General Public License as published by *
+* the Free Software Foundation; either version 2 of the License, or *
+* (at your option) any later version. *
+***************************************************************************/
+
+#ifndef BASEIMPORTER_H
+#define BASEIMPORTER_H
+
+#include <tdelocale.h>
+
+#include <tqstring.h>
+#include <tqstringlist.h>
+
+#include "datablocks/recipelist.h"
+#include "datablocks/elementlist.h"
+#include "datablocks/unitratiolist.h"
+
+class Recipe;
+class RecipeDB;
+class CategoryTree;
+class IngredientData;
+
+class KProgressDialog;
+
+/** @brief Subclass this class to create an importer for a specific file type.
+ *
+ * Subclasses should take the file name of the file to import in their constructor
+ * and then parse the file. For every recipe found in the file, a Recipe object should
+ * be created and added to the importer using the @ref add() function.
+ *
+ * @author Jason Kivlighn
+ */
+class BaseImporter
+{
+public:
+ BaseImporter();
+ virtual ~BaseImporter();
+
+ TQString getMessages() const
+ {
+ return m_master_error + m_master_warning;
+ }
+ TQString getErrorMsg() const
+ {
+ return m_master_error;
+ }
+ TQString getWarningMsg() const
+ {
+ return m_master_warning;
+ }
+
+ void parseFiles( const TQStringList &filenames );
+
+ /** Import all the recipes into the given database. These recipes are the
+ * recipes added to this class by a subclass using the @ref add() method.
+ */
+ void import( RecipeDB *db, bool automatic = false );
+
+ RecipeList recipeList() const { return *m_recipe_list; }
+ void setRecipeList( const RecipeList &list ) { *m_recipe_list = list; }
+
+ const CategoryTree *categoryStructure() const { return m_cat_structure; }
+
+protected:
+ virtual void parseFile( const TQString &filename ) = 0;
+
+ void importRecipes( RecipeList &selected_recipes, RecipeDB *db, KProgressDialog *progess_dialog );
+
+ /** Add a recipe to be imported into the database */
+ void add( const Recipe &recipe );
+ void add( const RecipeList &recipe_list );
+
+ void setCategoryStructure( CategoryTree *cat_structure );
+ void setUnitRatioInfo( UnitRatioList &ratioList, UnitList &unitList );
+
+ int totalCount() const
+ {
+ return m_recipe_list->count();
+ }
+ int fileRecipeCount() const
+ {
+ return file_recipe_count;
+ }
+
+ void setErrorMsg( const TQString & s )
+ {
+ m_error_msgs.append( s );
+ }
+ void addWarningMsg( const TQString & s )
+ {
+ m_warning_msgs.append( s );
+ }
+
+private:
+ void importCategoryStructure( RecipeDB *, const CategoryTree * );
+ void importUnitRatios( RecipeDB * );
+ void importIngredient( IngredientData &ing, RecipeDB *db, KProgressDialog *progress_dialog );
+
+ void processMessages( const TQString &file );
+
+ RecipeList *m_recipe_list;
+ CategoryTree *m_cat_structure;
+ UnitRatioList m_ratioList;
+ UnitList m_unitList;
+
+ TQStringList m_warning_msgs;
+ TQStringList m_error_msgs;
+ TQString m_master_warning;
+ TQString m_master_error;
+
+ int file_recipe_count;
+ bool direct;
+
+ RecipeDB *m_database;
+ KProgressDialog *m_progress_dialog;
+ TQStringList m_filenames;
+};
+
+#endif //BASEIMPORTER_H