/* libsswf_tag_info.c++ -- written by Alexis WILKE for Made to Order Software Corp. (c) 2002-2008 */

/*

Copyright (c) 2002-2008 Made to Order Software Corp.

Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and
associated documentation files (the "Software"), to
deal in the Software without restriction, including
without limitation the rights to use, copy, modify,
merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom
the Software is furnished to do so, subject to the
following conditions:

The above copyright notice and this permission notice
shall be included in all copies or substantial
portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

*/

/** \file
 *
 * \brief The implementation of the sswf::TagProductInfo class
 *
 * This file declares the body of the functions which are not
 * inline. It is part of the SSWF library.
 *
 * This file also includes the sswf::TagInfo which so far has
 * never been functional.
 */

#include	"sswf/libsswf.h"

using namespace sswf;



/////////////////////////////////////////// TagProductInfo



/** \class sswf::TagProductInfo
 *
 * \brief Information about the software creating the output animation
 *
 * This tag is used to define information about the software creating the
 * animation such as the build version, the build date, product number and
 * so on.
 *
 * Since I do not know of any way to get a product ID which is unique, I have
 * no idea how you can pretend that this would be unique...
 *
 * \sa <a href="../SWFalexref.html#tag_productinfo">SWF Alexis' Reference&mdash;Product Info</a>
 * \sa <a href="../SWFalexref.html#swf_tag">SWF Alexis' Reference&mdash;swf_tag</a>
 */


/** \brief Initializes the TagProductInfo
 *
 * By default, the TagProductInfo is set to all zeroes except for the major
 * version which is set to 1.
 *
 * \param[in] parent a TagHeader tag
 *
 * \sa void sswf::TagProductInfo::SetProduct(uint32_t product_id);
 * \sa void sswf::TagProductInfo::SetEdition(uint32_t edition);
 * \sa void sswf::TagProductInfo::SetVersion(int major, int minor);
 * \sa void sswf::TagProductInfo::SetBuild(int64_t build_number);
 * \sa void sswf::TagProductInfo::SetCompileDate(int64_t date);
 */
TagProductInfo::TagProductInfo(TagBase *parent)
	: TagBase("product_info", parent)
{
	f_product_id = 0;
	f_edition = 0;
	f_major = 1;
	f_minor = 0;
	f_build_number = 0;
	f_date = 0;
}


/** \brief The type of this tag
 *
 * The TagProductInfo is a DEFINE type.
 *
 * \return SWF_TYPE_DEFINE
 *
 * \sa TagBase::swf_type_t sswf::TagBase::TypeFlags(void) const
 */
TagBase::swf_type_t TagProductInfo::TypeFlags(void) const
{
	return SWF_TYPE_DEFINE;
}


/** \brief Set the product identifier
 *
 * This function saves your product identifier.
 *
 * There is no limit to the identifier, any 32 bits value is acceptable.
 *
 * We would need a way to define a unique identifier...
 *
 * \param[in] product The product identifier
 *
 * \sa void TagInfo::SetEdition(uint32_t edition)
 */
void TagProductInfo::SetProduct(long product)
{
	f_product_id = product;
}



/** \brief Set the edition identifier
 *
 * This function saves your product edition identifier.
 *
 * There is no limit to the identifier, any 32 bits value is acceptable.
 *
 * This is anything you'd like. If you have different editions of your
 * products (i.e. Free, Pro, Studio, Delux, etc.) use this field to
 * differenciate their output.
 *
 * \param[in] edition The product edition identifier
 *
 * \sa void TagInfo::SetProduct(uint32_t product)
 */
void TagProductInfo::SetEdition(long edition)
{
	f_edition = edition;
}



/** \brief Set the version of the tool saving this SWF file
 *
 * This function saves the version information.
 *
 * The version can be anything. Note that both numbers are
 * limited to a value from 0 to 255.
 *
 * By default, the TagProductInfo sets 1 in the major version
 * and 0 in the minor version.
 *
 * \param[in] major The major version of the tool saving this SWF animation
 * \param[in] minor The minor version of the tool saving this SWF animation
 */
void TagProductInfo::SetVersion(int major, int minor)
{
	f_major = major;
	f_minor = minor;
}


/** \brief Set the product build number
 *
 * This function saves your product build number.
 *
 * There is no limit to the build number, any 64 bits value is acceptable.
 *
 * This is usually not necessary for Linux products since we don't use
 * build numbers, just a version. Yet, some versions have more than 2
 * numbers, this build number can be used to include extraneous numbers.
 *
 * \param[in] build The product build number
 */
void TagProductInfo::SetBuild(int64_t build)
{
	f_build_number = build;
}



/** \brief Set the date when the product was compiled
 *
 * This function saves the date when your product was compiled.
 *
 * The date is saved on 64 bits.
 *
 * At this time I do not know what the unit/structure of this
 * date is. (seconds, milliseconds or microseconds?)
 *
 * \param date The date when the product was compiled
 */
void TagProductInfo::SetCompileDate(int64_t date)
{
	f_date = date;
}



/** \brief Presumably, this tag appeared in version 3 of SWF
 *
 * Tells the TagHeader that a version 3+ movie is required.
 *
 * \return ErrorManager::ERROR_CODE_NONE or some other ErrorManager error
 */
ErrorManager::error_code_t TagProductInfo::PreSave(void)
{
	// It looks like this would have appeared in version 3
	// but there is no docs about this tag...
	MinimumVersion(3);

	return ErrorManager::ERROR_CODE_NONE;
}


/** \brief Save the product info tag in the Data buffer
 *
 * This function saves the product info in the
 * Data output buffer.
 *
 * \param[in,out] data The Data buffer where the result is saved
 *
 * \return And ErrorManager error (ErrorManager::ERROR_CODE_NONE when no errors)
 */
ErrorManager::error_code_t TagProductInfo::Save(Data& data)
{
	SaveTag(data, SWF_TAG_PRODUCT_INFO, 26);

	data.PutLong(f_product_id);
	data.PutLong(f_edition);
	data.PutByte(f_major);
	data.PutByte(f_minor);
	data.PutDLong(f_build_number);
	data.PutDLong(f_date);

	return ErrorManager::ERROR_CODE_NONE;
}






/////////////////////////////////////////// TagInfo



/** \class sswf::TagInfo
 *
 * \brief An attempt in creating a TagInfo
 *
 * This class is an attempt in generating a valid TagInfo
 * (also called a GeneratorCommand tag).
 *
 * At this time, this generates errors and the movie does not
 * play correctly.
 */


/** \brief Initializes the TagInfo
 *
 * By default, the TagInfo has no info and no version defined.
 *
 * \param[in] parent a TagHeader tag
 *
 * \sa void sswf::TagInfoSetInfo(const char *info)
 * \sa void sswf::TagInfoSetVersion(long version)
 */
TagInfo::TagInfo(TagBase *parent)
	: TagBase("info", parent)
{
	f_info = 0;
	f_version = 0;
}


/** \brief The type of this tag
 *
 * The TagInfo is a DEFINE type.
 *
 * \return SWF_TYPE_DEFINE
 *
 * \sa TagBase::swf_type_t sswf::TagBase::TypeFlags(void) const
 */
TagBase::swf_type_t TagInfo::TypeFlags(void) const
{
	return SWF_TYPE_DEFINE;
}


/** \brief Set the info string
 *
 * This function saves the string passed as a parameter and
 * saves it as the information string.
 *
 * \param[in] info The info string to save in the TagInfo
 *
 * \sa void TagInfo::SetVersion(long version)
 */
void TagInfo::SetInfo(const char *info)
{
	MemFree(f_info);
	f_info = StrDup(info);
}



/** \brief Set the version of the tool saving this SWF file
 *
 * This function saves the version information.
 *
 * The version can be anything, there are no specific test
 * on that one.
 *
 * \param[in] version The version of the tool saving this SWF animation
 *
 * \sa void TagInfo::SetInfo(const char *info)
 */
void TagInfo::SetVersion(long version)
{
	f_version = version;
}


/** \brief This tag appeared in version 3 of SWF
 *
 * Tells the TagHeader that a version 3+ movie is required.
 *
 * \return ErrorManager::ERROR_CODE_NONE or some other error
 */
ErrorManager::error_code_t TagInfo::PreSave(void)
{
	MinimumVersion(3);

	return ErrorManager::ERROR_CODE_NONE;
}


/** \brief Save the info tag in the Data buffer
 *
 * This function saves the info version and string in the
 * Data output buffer.
 *
 * \param[in,out] data The Data buffer where the result is saved
 *
 * \return Zero when no errors occurs and non-zero otherwise
 */
ErrorManager::error_code_t TagInfo::Save(Data& data)
{
	int		l;

	if(f_info == 0) {
		l = sizeof(long) + 1;
	}
	else {
		l = strlen(f_info) + sizeof(long) + 1;
	}

	SaveTag(data, SWF_TAG_DEFINE_INFO, 0);

	data.PutLong(f_version);
	if(SaveString(data, f_info) < 0) {
		// TODO: an error occured and this string
		// wasn't saved!
	}

	return ErrorManager::ERROR_CODE_NONE;
}





/* The following options fold the documentation; use 'zi' to turn on and off
 *
 * vim: foldexpr=getline(v\:lnum)!~'^/\\*\\*'&&getline(v\:lnum)!~'^\ \\*'?0\:1 foldcolumn=2 foldmethod=expr
 */
