summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Wilgus <wilgus.william@gmail.com>2022-11-22 01:41:58 -0500
committerWilliam Wilgus <me.theuser@yahoo.com>2022-11-22 15:19:45 -0500
commit1561b4ec9a5bd1d729622d7ca32f22e40b027f2d (patch)
tree1822b1a0499e3d80c5f8094b69425813fbcec324
parentdc47bf8ae2f07d48006b23db4647d426adfad8ea (diff)
downloadrockbox-1561b4ec9a5bd1d729622d7ca32f22e40b027f2d.tar.gz
rockbox-1561b4ec9a5bd1d729622d7ca32f22e40b027f2d.zip
filetypes.c clean-up
make icon a voice struct one Change-Id: I44df788d03e38fe1bca7ea50f32c8dc5941405ab
-rw-r--r--apps/filetypes.c113
-rw-r--r--apps/filetypes.h7
-rw-r--r--apps/tree.c4
3 files changed, 45 insertions, 79 deletions
diff --git a/apps/filetypes.c b/apps/filetypes.c
index 3ce3200e3c..d690b554fd 100644
--- a/apps/filetypes.c
+++ b/apps/filetypes.c
@@ -148,74 +148,42 @@ static const struct filetype inbuilt_filetypes[] = {
148#endif 148#endif
149}; 149};
150 150
151/* a table for the known file types voice clips */ 151struct fileattr_icon_voice {
152static const struct fileattr_voice inbuilt_attrvoices[] = { 152 int tree_attr;
153 { FILE_ATTR_AUDIO, VOICE_EXT_MPA },
154 { FILE_ATTR_M3U, LANG_PLAYLIST },
155 { FILE_ATTR_CFG, VOICE_EXT_CFG },
156 { FILE_ATTR_WPS, VOICE_EXT_WPS },
157#ifdef HAVE_REMOTE_LCD
158 { FILE_ATTR_RWPS, VOICE_EXT_RWPS },
159#endif
160#if CONFIG_TUNER
161 { FILE_ATTR_FMR, LANG_FMR },
162 { FILE_ATTR_FMS, VOICE_EXT_FMS },
163#endif
164 { FILE_ATTR_LNG, LANG_LANGUAGE },
165 { FILE_ATTR_ROCK, VOICE_EXT_ROCK },
166 { FILE_ATTR_LUA, VOICE_EXT_ROCK },
167 { FILE_ATTR_OPX, VOICE_EXT_ROCK },
168 { FILE_ATTR_FONT, VOICE_EXT_FONT },
169 { FILE_ATTR_KBD, VOICE_EXT_KBD },
170 { FILE_ATTR_BMARK, VOICE_EXT_BMARK },
171 { FILE_ATTR_CUE, VOICE_EXT_CUESHEET },
172 { FILE_ATTR_SBS, VOICE_EXT_SBS },
173#ifdef HAVE_REMOTE_LCD
174 { FILE_ATTR_RSBS, VOICE_EXT_RSBS },
175#if CONFIG_TUNER
176 { FILE_ATTR_RFMS, VOICE_EXT_RFMS },
177#endif
178#endif
179#if defined(BOOTFILE_EXT) || defined(BOOTFILE_EXT2)
180 { FILE_ATTR_MOD, VOICE_EXT_AJZ },
181#endif
182};
183
184struct attr_icon {
185 uint16_t tree_attr;
186 uint16_t icon; 153 uint16_t icon;
154 uint16_t voiceclip;
187}; 155};
188 156
189/* a table for the known file type icons */ 157/* a table for the known file types icons & voice clips */
190static const struct attr_icon inbuilt_attricons[] = { 158static const struct fileattr_icon_voice inbuilt_attr_icons_voices[] = {
191 { FILE_ATTR_AUDIO, Icon_Audio}, 159 { FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA },
192 { FILE_ATTR_M3U, Icon_Playlist}, 160 { FILE_ATTR_M3U, Icon_Playlist, LANG_PLAYLIST },
193 { FILE_ATTR_CFG, Icon_Config}, 161 { FILE_ATTR_CFG, Icon_Config, VOICE_EXT_CFG },
194 { FILE_ATTR_WPS, Icon_Wps}, 162 { FILE_ATTR_WPS, Icon_Wps, VOICE_EXT_WPS },
195#ifdef HAVE_REMOTE_LCD 163#ifdef HAVE_REMOTE_LCD
196 { FILE_ATTR_RWPS, Icon_Wps}, 164 {FILE_ATTR_RWPS, Icon_Wps, VOICE_EXT_RWPS },
197#endif 165#endif
198#if CONFIG_TUNER 166#if CONFIG_TUNER
199 { FILE_ATTR_FMR, Icon_Preset}, 167 { FILE_ATTR_FMR, Icon_Preset, LANG_FMR },
200 { FILE_ATTR_FMS, Icon_Wps}, 168 { FILE_ATTR_FMS, Icon_Wps, VOICE_EXT_FMS },
201#endif 169#endif
202 { FILE_ATTR_LNG, Icon_Language}, 170 { FILE_ATTR_LNG, Icon_Language, LANG_LANGUAGE },
203 { FILE_ATTR_ROCK, Icon_Plugin}, 171 { FILE_ATTR_ROCK, Icon_Plugin, VOICE_EXT_ROCK },
204 { FILE_ATTR_LUA, Icon_Plugin}, 172 { FILE_ATTR_LUA, Icon_Plugin, VOICE_EXT_ROCK },
205 { FILE_ATTR_OPX, Icon_Plugin}, 173 { FILE_ATTR_OPX, Icon_Plugin, VOICE_EXT_ROCK },
206 { FILE_ATTR_FONT, Icon_Font}, 174 { FILE_ATTR_FONT, Icon_Font, VOICE_EXT_FONT },
207 { FILE_ATTR_KBD, Icon_Keyboard}, 175 { FILE_ATTR_KBD, Icon_Keyboard, VOICE_EXT_KBD },
208 { FILE_ATTR_BMARK, Icon_Bookmark}, 176 { FILE_ATTR_BMARK, Icon_Bookmark, VOICE_EXT_BMARK },
209 { FILE_ATTR_CUE, Icon_Bookmark}, 177 { FILE_ATTR_CUE, Icon_Bookmark, VOICE_EXT_CUESHEET },
210 { FILE_ATTR_SBS, Icon_Wps}, 178 { FILE_ATTR_SBS, Icon_Wps, VOICE_EXT_SBS },
211#ifdef HAVE_REMOTE_LCD 179#ifdef HAVE_REMOTE_LCD
212 { FILE_ATTR_RSBS, Icon_Wps}, 180 { FILE_ATTR_RSBS, Icon_Wps, VOICE_EXT_RSBS },
213#if CONFIG_TUNER 181#if CONFIG_TUNER
214 { FILE_ATTR_RFMS, Icon_Wps}, 182 { FILE_ATTR_RFMS, Icon_Wps, VOICE_EXT_RFMS },
215#endif 183#endif
216#endif 184#endif
217#if defined(BOOTFILE_EXT) || defined(BOOTFILE_EXT2) 185#if defined(BOOTFILE_EXT) || defined(BOOTFILE_EXT2)
218 { FILE_ATTR_MOD, Icon_Firmware}, 186 { FILE_ATTR_MOD, Icon_Firmware, VOICE_EXT_AJZ },
219#endif 187#endif
220}; 188};
221 189
@@ -225,22 +193,25 @@ void tree_get_filetypes(const struct filetype** types, int* count)
225 *count = sizeof(inbuilt_filetypes) / sizeof(*inbuilt_filetypes); 193 *count = sizeof(inbuilt_filetypes) / sizeof(*inbuilt_filetypes);
226} 194}
227 195
228long tree_filetype_voiceclip(int attr) 196long tree_get_filetype_voiceclip(int attr)
229{ 197{
230 logf("%s attr %d", __func__, attr);
231 int j;
232 if (global_settings.talk_filetype) 198 if (global_settings.talk_filetype)
233 { 199 {
234 int count = sizeof(inbuilt_attrvoices)/sizeof(*inbuilt_attrvoices); 200 size_t count = ARRAY_SIZE(inbuilt_attr_icons_voices);
235 /* try to find a voice ID for the extension, if known */ 201 /* try to find a voice ID for the extension, if known */
236 attr &= FILE_ATTR_MASK; /* file type */ 202 attr &= FILE_ATTR_MASK; /* file type */
237 for (j=0; j<count; j++) 203
238 if (attr == inbuilt_attrvoices[j].tree_attr) 204 for (size_t i = count - 1; i < count; i--)
205 {
206 if (attr == inbuilt_attr_icons_voices[i].tree_attr)
239 { 207 {
240 logf("%s attr %d id %d", __func__, attr, inbuilt_attrvoices[j].voiceclip); 208 logf("%s found attr %d id %d", __func__, attr,
241 return inbuilt_attrvoices[j].voiceclip; 209 inbuilt_attr_icons_voices[i].voiceclip);
210 return inbuilt_attr_icons_voices[i].voiceclip;
242 } 211 }
212 }
243 } 213 }
214 logf("%s not found attr %d", __func__, attr);
244 return -1; 215 return -1;
245} 216}
246 217
@@ -489,10 +460,10 @@ static void rm_whitespaces(char* str)
489 460
490static void read_builtin_types(void) 461static void read_builtin_types(void)
491{ 462{
492 int i,j, tree_attr; 463 int tree_attr;
493 int count = sizeof(inbuilt_filetypes)/sizeof(*inbuilt_filetypes); 464 size_t count = ARRAY_SIZE(inbuilt_filetypes);
494 int icon_count = sizeof(inbuilt_attricons)/sizeof(*inbuilt_attricons); 465 size_t icon_count = ARRAY_SIZE(inbuilt_attr_icons_voices);
495 for(i=0; i<count && (filetype_count < MAX_FILETYPES); i++) 466 for(size_t i = 0; (i < count) && (filetype_count < MAX_FILETYPES); i++)
496 { 467 {
497 filetypes[filetype_count].extension = inbuilt_filetypes[i].extension; 468 filetypes[filetype_count].extension = inbuilt_filetypes[i].extension;
498 filetypes[filetype_count].plugin = NULL; 469 filetypes[filetype_count].plugin = NULL;
@@ -503,11 +474,11 @@ static void read_builtin_types(void)
503 highest_attr = filetypes[filetype_count].attr; 474 highest_attr = filetypes[filetype_count].attr;
504 475
505 filetypes[filetype_count].icon = unknown_file.icon; 476 filetypes[filetype_count].icon = unknown_file.icon;
506 for (j = 0; j < icon_count; j++) 477 for (size_t j = icon_count - 1; j < icon_count; j--)
507 { 478 {
508 if (tree_attr == inbuilt_attricons[j].tree_attr) 479 if (tree_attr == inbuilt_attr_icons_voices[j].tree_attr)
509 { 480 {
510 filetypes[filetype_count].icon = inbuilt_attricons[j].icon; 481 filetypes[filetype_count].icon = inbuilt_attr_icons_voices[j].icon;
511 break; 482 break;
512 } 483 }
513 } 484 }
diff --git a/apps/filetypes.h b/apps/filetypes.h
index fc1022a014..9013f81b02 100644
--- a/apps/filetypes.h
+++ b/apps/filetypes.h
@@ -55,13 +55,8 @@ struct filetype {
55 int tree_attr; 55 int tree_attr;
56}; 56};
57 57
58struct fileattr_voice {
59 int tree_attr;
60 int voiceclip;
61};
62
63void tree_get_filetypes(const struct filetype**, int*) INIT_ATTR; 58void tree_get_filetypes(const struct filetype**, int*) INIT_ATTR;
64long tree_filetype_voiceclip(int attr) INIT_ATTR; 59long tree_get_filetype_voiceclip(int attr) INIT_ATTR;
65 60
66/* init the filetypes structs. 61/* init the filetypes structs.
67 uses audio buffer for storage, so call early in init... */ 62 uses audio buffer for storage, so call early in init... */
diff --git a/apps/tree.c b/apps/tree.c
index 5085405002..4a80591201 100644
--- a/apps/tree.c
+++ b/apps/tree.c
@@ -1188,7 +1188,7 @@ bool bookmark_play(char *resume_file, int index, unsigned long elapsed,
1188 1188
1189static void say_filetype(int attr) 1189static void say_filetype(int attr)
1190{ 1190{
1191 talk_id(tree_filetype_voiceclip(attr), true); 1191 talk_id(tree_get_filetype_voiceclip(attr), true);
1192} 1192}
1193 1193
1194static int ft_play_dirname(char* name) 1194static int ft_play_dirname(char* name)
@@ -1206,7 +1206,7 @@ static int ft_play_filename(char *dir, char *file, int attr)
1206 file_thumbnail_ext)) 1206 file_thumbnail_ext))
1207 /* file has no .talk extension */ 1207 /* file has no .talk extension */
1208 return talk_file(dir, NULL, file, file_thumbnail_ext, 1208 return talk_file(dir, NULL, file, file_thumbnail_ext,
1209 TALK_IDARRAY(tree_filetype_voiceclip(attr)), false); 1209 TALK_IDARRAY(tree_get_filetype_voiceclip(attr)), false);
1210 1210
1211 /* it already is a .talk file, play this directly, but prefix it. */ 1211 /* it already is a .talk file, play this directly, but prefix it. */
1212 return talk_file(dir, NULL, file, NULL, 1212 return talk_file(dir, NULL, file, NULL,