/* -*- 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: Exporter.h,v 1.9 2003/05/11 09:58:02 rjesse Exp $
 */
 
#ifndef EXPORTER_HPP
#define EXPORTER_HPP

#include "Error.h"
#include "Recipe.h"
#include <qobject.h>
#include <qstring.h>

// Disable some warnings of MSVC++.
#ifdef Q_OS_WIN32
# pragma warning( disable : 4290)   // C++ exception declaration ignored.
#endif

class RecipeModel;

/*!
  Abstract base class for exporting recipes / cookbooks to files.

  For each supported file format a new subclass needs to be created.
*/
class Exporter : public QObject {
	  Q_OBJECT
   public:
	  enum Type { UNSET_TYPE, RECIPE, COOKBOOK };

      Exporter();               //!< Constructs an exporter instance.
	  Exporter( RecipeModel* model); //!< Constructor.
	  Exporter( const Recipe& recipe); //!< Constructor.
	  virtual ~Exporter();      //!< Destructor.

	  //! Return recipe file extension we know of.
	  static QString getSupportedFileExtensions();
      //! Return file extension for a specific subclass.
      virtual QString getExtensions() = 0;

      /*!
        Set whether a single recipe or a whole cookbook should
        be exported. There should be no need to call this function
        directly as setCookbook() and setRecipe() already set the type.
      */	  
      void setType( const Type);
      void setRecipe( const Recipe&); //!< Set recipe to be exported.
      void setCookbook( RecipeModel*); //!< Set cookbook to be exported.
      virtual void apply() throw(Error) = 0; //!< Save it.
      
   public slots:
      void setFileName( const QString&);
	  
   protected:
	  virtual void createCookbookHeader() = 0;
      virtual void createRecipes() = 0;
	  virtual void createRecipeHeader() = 0;
      virtual void createRecipeBody() = 0;

      Type m_type;
      /*! Cookbook to be exported in case m_type is set to COOKBOOK. */
      RecipeModel* m_cookbook;
      /*! Recipe to be exported in case m_type is set to RECIPE. */
      Recipe m_recipe;
      QString m_fname;
};
#endif // EXPORTER_HPP
