2013-08-14 12:16:49 +00:00
# pragma once
# include "pugiXML/pugixml.hpp"
# include <string>
# include <map>
# include "GuiComponent.h"
2013-09-28 17:51:16 +00:00
# include <boost/date_time.hpp>
2013-08-14 12:16:49 +00:00
enum MetaDataType
{
//generic types
MD_STRING ,
MD_INT ,
MD_FLOAT ,
//specialized types
2013-08-18 14:16:11 +00:00
MD_MULTILINE_STRING ,
2013-08-14 12:16:49 +00:00
MD_IMAGE_PATH ,
MD_RATING ,
2013-09-28 22:35:38 +00:00
MD_DATE ,
MD_TIME //used for lastplayed
2013-08-14 12:16:49 +00:00
} ;
struct MetaDataDecl
{
std : : string key ;
MetaDataType type ;
std : : string defaultValue ;
2013-09-28 17:51:16 +00:00
bool isStatistic ; //if true, ignore scraper values for this metadata
2013-08-14 12:16:49 +00:00
} ;
2013-09-28 22:35:38 +00:00
boost : : posix_time : : ptime string_to_ptime ( const std : : string & str , const std : : string & fmt = " %Y%m%dT%H%M%S%F%q " ) ;
2013-09-28 17:51:16 +00:00
2013-11-04 01:54:13 +00:00
enum MetaDataListType
2013-08-14 12:16:49 +00:00
{
2013-11-04 01:54:13 +00:00
GAME_METADATA ,
FOLDER_METADATA
} ;
2013-08-14 12:16:49 +00:00
2013-11-04 01:54:13 +00:00
const std : : vector < MetaDataDecl > & getMDDByType ( MetaDataListType type ) ;
2013-08-14 12:16:49 +00:00
2013-11-04 01:54:13 +00:00
class MetaDataList
{
public :
static MetaDataList createFromXML ( MetaDataListType type , pugi : : xml_node node ) ;
void appendToXML ( pugi : : xml_node parent , bool ignoreDefaults = false ) const ;
2013-08-14 12:16:49 +00:00
2013-11-04 01:54:13 +00:00
MetaDataList ( MetaDataListType type ) ;
2013-08-14 12:16:49 +00:00
void set ( const std : : string & key , const std : : string & value ) ;
2013-09-28 22:35:38 +00:00
void setTime ( const std : : string & key , const boost : : posix_time : : ptime & time ) ; //times are internally stored as ISO strings (e.g. boost::posix_time::to_iso_string(ptime))
2013-09-28 17:51:16 +00:00
2013-08-14 12:16:49 +00:00
const std : : string & get ( const std : : string & key ) const ;
int getInt ( const std : : string & key ) const ;
float getFloat ( const std : : string & key ) const ;
2013-09-28 17:51:16 +00:00
boost : : posix_time : : ptime getTime ( const std : : string & key ) const ;
2013-08-14 12:16:49 +00:00
2013-08-18 14:16:11 +00:00
static GuiComponent * makeDisplay ( Window * window , MetaDataType as ) ;
static GuiComponent * makeEditor ( Window * window , MetaDataType as ) ;
2013-08-14 12:16:49 +00:00
2013-11-04 01:54:13 +00:00
inline MetaDataListType getType ( ) const { return mType ; }
inline const std : : vector < MetaDataDecl > & getMDD ( ) const { return getMDDByType ( getType ( ) ) ; }
2013-08-14 12:16:49 +00:00
private :
2013-11-04 01:54:13 +00:00
MetaDataListType mType ;
2013-08-14 12:16:49 +00:00
std : : map < std : : string , std : : string > mMap ;
} ;
//options for storing metadata...
//store internally everything as a string - this is all going to be read to/from XML anyway, after all
2013-11-04 01:54:13 +00:00
// - problem: this does not play nice with lists of values
//store using individual get/set functions ala Settings - this is a fair amount of work but the most explicit and type-safe, for better or worse
2013-08-14 12:16:49 +00:00
//let's think about some of the special types we would like to support...
//image paths, sound paths, ratings, play counts
//these get represented behind-the-scenes as strings, floats, and integers, and are eventually saved as strings
//the only specialty is how they're edited and viewed, really
//so we need...
//to be able to iterate through the available metadata
//create components designed to either DISPLAY or EDIT a given piece of metadata
//save and load metadata