1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
8 * $Id: tag_table.c 26346 2010-05-28 02:30:27Z jdgordon $
10 * Copyright (C) 2010 Jonathan Gordon
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
29 #include "skin_parser.h"
30 #include "tag_table.h"
31 #include "skin_structs.h"
33 typedef int (tag_handler
)(struct skin
*skin
, struct skin_element
* element
, bool size_only
);
37 int handle_translate_string(struct skin
*skin
, struct skin_element
* element
, bool size_only
)
42 int handle_this_or_next_track(struct skin
*skin
, struct skin_element
* element
, bool size_only
)
44 if (element
->tag
->type
== SKIN_TOKEN_FILE_DIRECTORY
)
46 if (element
->params_count
!= 1 || element
->params
[0].type_code
!= NUMERIC
)
48 //token->value.i = element->params[0].data.numeric;
53 int handle_bar(struct skin
*skin
, struct skin_element
* element
, bool size_only
)
55 struct progressbar bar
;
56 /* %bar with no params is different for each one so handle that! */
57 if (element
->params_count
== 0)
61 if (element
->tag
->type
== SKIN_TOKEN_PROGRESSBAR
)
62 return sizeof(struct progressbar
);
70 return sizeof(struct progressbar
);
76 struct tag_handler_table
{
77 enum skin_token_type type
;
82 struct tag_handler_table table
[] = {
84 { SKIN_TOKEN_FILE_BITRATE
, 0, handle_this_or_next_track
},
85 { SKIN_TOKEN_FILE_CODEC
, 0, handle_this_or_next_track
},
86 { SKIN_TOKEN_FILE_FREQUENCY
, 0, handle_this_or_next_track
},
87 { SKIN_TOKEN_FILE_FREQUENCY_KHZ
, 0, handle_this_or_next_track
},
88 { SKIN_TOKEN_FILE_NAME_WITH_EXTENSION
, 0, handle_this_or_next_track
},
89 { SKIN_TOKEN_FILE_NAME
, 0, handle_this_or_next_track
},
90 { SKIN_TOKEN_FILE_PATH
, 0, handle_this_or_next_track
},
91 { SKIN_TOKEN_FILE_SIZE
, 0, handle_this_or_next_track
},
92 { SKIN_TOKEN_FILE_VBR
, 0, handle_this_or_next_track
},
93 { SKIN_TOKEN_FILE_DIRECTORY
, 0, handle_this_or_next_track
},
95 { SKIN_TOKEN_METADATA_ARTIST
, 0, handle_this_or_next_track
},
96 { SKIN_TOKEN_METADATA_COMPOSER
, 0, handle_this_or_next_track
},
97 { SKIN_TOKEN_METADATA_ALBUM
, 0, handle_this_or_next_track
},
98 { SKIN_TOKEN_METADATA_ALBUM_ARTIST
, 0, handle_this_or_next_track
},
99 { SKIN_TOKEN_METADATA_GROUPING
, 0, handle_this_or_next_track
},
100 { SKIN_TOKEN_METADATA_GENRE
, 0, handle_this_or_next_track
},
101 { SKIN_TOKEN_METADATA_DISC_NUMBER
, 0, handle_this_or_next_track
},
102 { SKIN_TOKEN_METADATA_TRACK_NUMBER
, 0, handle_this_or_next_track
},
103 { SKIN_TOKEN_METADATA_TRACK_TITLE
, 0, handle_this_or_next_track
},
104 { SKIN_TOKEN_METADATA_VERSION
, 0, handle_this_or_next_track
},
105 { SKIN_TOKEN_METADATA_YEAR
, 0, handle_this_or_next_track
},
106 { SKIN_TOKEN_METADATA_COMMENT
, 0, handle_this_or_next_track
},
108 { SKIN_TOKEN_TRANSLATEDSTRING
, 0, handle_translate_string
},
111 int handle_tree(struct skin
*skin
, struct skin_element
* tree
)
113 /* for later.. do this in two steps
114 * 1) count how much skin buffer is needed
115 * 2) do the actual tree->skin conversion
117 struct skin_element
* element
= tree
;
121 if (element
->type
== SUBLINES
)
123 struct subline
*subline
= malloc(sizeof(struct subline
));
124 subline
->current_line
= -1;
125 subline
->last_change_tick
= 0;
126 element
->data
= subline
;
128 if (element
->type
== TAG
)
131 for(i
=0;i
<sizeof(table
)/sizeof(*table
);i
++)
133 if (table
[i
].type
== element
->tag
->type
)
135 table
[i
].func(skin
, element
, false);
140 else if (element
->type
== TEXT
)
146 while (counter
< element
->children_count
)
148 int ret
= handle_tree(skin
, element
->children
[counter
]);
151 element
= element
->next
;