/* -*- mode: c++; indent-tabs-mode: nil; -*-
 *
 * This file is part of the Mango recipe management distribution.
 * Copyright (c) 2000-2003, Roland Jesse
 * All rights reserved.
 *
 * For license and copyright information see the file COPYRIGHT or 
 * <http://www.opensource.org/licenses/bsd-license.html>.
 *
 * $Id: CMLImportHandler.h,v 1.3 2003/10/17 15:27:16 rjesse Exp $
 */

#ifndef CML_IMPORT_HANDLER_H
#define CML_IMPORT_HANDLER_H

#include "Ingredient.h"
#include "Menu.h"
#include "Recipe.h"
#include <qdatetime.h>
#include <qxml.h>

class RecipeModel;

/*!
  This class handles the SAX 2 reading of CookML documents.
  The contents of such a document is stored in a RecipeModel instance.
*/
class CMLImportHandler : public QXmlDefaultHandler {
   public:
      CMLImportHandler( RecipeModel*);
      bool startElement( const QString&, const QString&, const QString&, const QXmlAttributes&);
      bool endElement( const QString&, const QString&, const QString&);
      bool characters( const QString&);

   private:
      RecipeModel* m_model;
            
      QString m_curRemarkUserName;
      QStringList m_curRemarkLines;
      
      QString m_curIngredientGroupName;
      Ingredient m_curIngredient;
      Recipe m_curRecipe;
      Menu m_curMenu;
      MenuRecipe m_curMenuRecipe;

      enum DescElement {
         NO_DESC_ELEMENT = 0,
         DESC_PICBIN = 1,
         DESC_MRECIPE = 2
      };
      DescElement m_curDescElement;
      QString m_curImageDesc;      
      
      QString m_curElement;     //!< Stores the name of the current element.
      QMap<QString, QString> m_data; //!< Stores the data of the currently active elements.

      QDateTime extractDateTime( const QString&) const;
      void addCurIng2Recipe();
};
#endif // CML_IMPORT_HANDLER_H
