1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 Daniel Stenberg
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 ****************************************************************************/
26 #include "applimits.h"
54 #include "filetypes.h"
59 #include "recorder/recording.h"
67 #include "gwps-common.h"
68 #include "eeprom_settings.h"
69 #include "playlist_catalog.h"
74 #include "buttonbar.h"
75 #include "quickscreen.h"
77 #include "root_menu.h"
79 static const struct filetype
*filetypes
;
80 static int filetypes_count
;
82 struct gui_synclist tree_lists
;
84 /* I put it here because other files doesn't use it yet,
85 * but should be elsewhere since it will be used mostly everywhere */
87 struct gui_buttonbar tree_buttonbar
;
89 static struct tree_context tc
;
91 bool boot_changed
= false;
93 char lastfile
[MAX_PATH
];
94 static char lastdir
[MAX_PATH
];
96 static int lasttable
, lastextra
, lastfirstpos
;
98 static int max_files
= 0;
100 static bool reload_dir
= false;
102 static bool start_wps
= false;
103 static int curr_context
= false;/* id3db or tree*/
105 static int dirbrowse(void);
106 static int ft_play_dirname(char* name
);
107 static void ft_play_filename(char *dir
, char *file
);
108 static void say_filetype(int attr
);
110 static char * tree_get_filename(int selected_item
, void *data
,
111 char *buffer
, size_t buffer_len
)
113 struct tree_context
* local_tc
=(struct tree_context
*)data
;
116 bool stripit
= false;
118 bool id3db
= *(local_tc
->dirfilter
) == SHOW_ID3DB
;
122 return tagtree_get_entry(&tc
, selected_item
)->name
;
127 struct entry
* dc
= local_tc
->dircache
;
128 struct entry
* e
= &dc
[selected_item
];
133 if(!(attr
& ATTR_DIRECTORY
))
135 switch(global_settings
.show_filename_ext
)
138 /* show file extension: off */
142 /* show file extension: on */
145 /* show file extension: only unknown types */
146 stripit
= filetype_supported(attr
);
150 /* show file extension: only when viewing all */
151 stripit
= (*(local_tc
->dirfilter
) != SHOW_ID3DB
) &&
152 (*(local_tc
->dirfilter
) != SHOW_ALL
);
159 return(strip_extension(buffer
, buffer_len
, name
));
164 #ifdef HAVE_LCD_COLOR
165 static int tree_get_filecolor(int selected_item
, void * data
)
167 if (*tc
.dirfilter
== SHOW_ID3DB
)
169 struct tree_context
* local_tc
=(struct tree_context
*)data
;
170 struct entry
* dc
= local_tc
->dircache
;
171 struct entry
* e
= &dc
[selected_item
];
172 return filetype_get_color(e
->name
, e
->attr
);
176 static int tree_get_fileicon(int selected_item
, void * data
)
178 struct tree_context
* local_tc
=(struct tree_context
*)data
;
180 bool id3db
= *(local_tc
->dirfilter
) == SHOW_ID3DB
;
182 return tagtree_get_icon(&tc
);
187 struct entry
* dc
= local_tc
->dircache
;
188 struct entry
* e
= &dc
[selected_item
];
189 return filetype_get_icon(e
->attr
);
193 static int tree_voice_cb(int selected_item
, void * data
)
195 struct tree_context
* local_tc
=(struct tree_context
*)data
;
199 bool id3db
= *(local_tc
->dirfilter
) == SHOW_ID3DB
;
203 attr
= tagtree_get_attr(local_tc
);
204 name
= tagtree_get_entry(local_tc
, selected_item
)->name
;
209 struct entry
* dc
= local_tc
->dircache
;
210 struct entry
* e
= &dc
[selected_item
];
214 bool is_dir
= (attr
& ATTR_DIRECTORY
);
215 bool did_clip
= false;
216 /* First the .talk clip case */
219 if(global_settings
.talk_dir_clip
)
222 if(ft_play_dirname(name
) <0)
223 /* failed, not existing */
226 } else { /* it's a file */
227 if (global_settings
.talk_file_clip
&& (attr
& FILE_ATTR_THUMBNAIL
))
230 ft_play_filename(local_tc
->currdir
, name
);
235 /* say the number or spell if required or as a fallback */
236 switch (is_dir
? global_settings
.talk_dir
: global_settings
.talk_file
)
238 case 1: /* as numbers */
239 talk_id(is_dir
? VOICE_DIR
: VOICE_FILE
, false);
240 talk_number(selected_item
+1 - (is_dir
? 0 : local_tc
->dirsindir
),
242 if(global_settings
.talk_filetype
243 && !is_dir
&& *local_tc
->dirfilter
< NUM_FILTER_MODES
)
246 case 2: /* spelled */
248 if(global_settings
.talk_filetype
)
251 talk_id(VOICE_DIR
, true);
252 else if(*local_tc
->dirfilter
< NUM_FILTER_MODES
)
255 talk_spell(name
, true);
262 bool check_rockboxdir(void)
264 if(!dir_exists(ROCKBOX_DIR
))
265 { /* No need to localise this message.
266 If .rockbox is missing, it wouldn't work anyway */
269 screens
[i
].clear_display();
270 splash(HZ
*2, "No .rockbox directory");
272 screens
[i
].clear_display();
273 splash(HZ
*2, "Installation incomplete");
279 /* do this really late in the init sequence */
280 void tree_gui_init(void)
284 strcpy(tc
.currdir
, "/");
286 #ifdef HAVE_LCD_CHARCELLS
289 screens
[i
].double_height(false);
291 #ifdef HAVE_BUTTONBAR
292 gui_buttonbar_init(&tree_buttonbar
);
293 /* since archos only have one screen, no need to create more than that */
294 gui_buttonbar_set_display(&tree_buttonbar
, &(screens
[SCREEN_MAIN
]) );
296 gui_synclist_init(&tree_lists
, &tree_get_filename
, &tc
, false, 1, NULL
);
297 gui_synclist_set_voice_callback(&tree_lists
, tree_voice_cb
);
298 gui_synclist_set_icon_callback(&tree_lists
, &tree_get_fileicon
);
299 #ifdef HAVE_LCD_COLOR
300 gui_synclist_set_color_callback(&tree_lists
, &tree_get_filecolor
);
306 struct tree_context
* tree_get_context(void)
312 * Returns the position of a given file in the current directory
313 * returns -1 if not found
315 static int tree_get_file_position(char * filename
)
319 /* use lastfile to determine the selected item (default=0) */
320 for (i
=0; i
< tc
.filesindir
; i
++)
322 struct entry
* dc
= tc
.dircache
;
323 struct entry
* e
= &dc
[i
];
324 if (!strcasecmp(e
->name
, filename
))
327 return(-1);/* no file can match, returns undefined */
331 * Called when a new dir is loaded (for example when returning from other apps ...)
332 * also completely redraws the tree
334 static int update_dir(void)
336 bool changed
= false;
338 bool id3db
= *tc
.dirfilter
== SHOW_ID3DB
;
339 /* Checks for changes */
341 if (tc
.currtable
!= lasttable
||
342 tc
.currextra
!= lastextra
||
343 tc
.firstpos
!= lastfirstpos
||
346 if (tagtree_load(&tc
) < 0)
349 lasttable
= tc
.currtable
;
350 lastextra
= tc
.currextra
;
351 lastfirstpos
= tc
.firstpos
;
358 /* if the tc.currdir has been changed, reload it ...*/
359 if (strncmp(tc
.currdir
, lastdir
, sizeof(lastdir
)) || reload_dir
)
361 if (ft_load(&tc
, NULL
) < 0)
363 strcpy(lastdir
, tc
.currdir
);
367 /* if selected item is undefined */
368 if (tc
.selected_item
== -1)
370 /* use lastfile to determine the selected item */
371 tc
.selected_item
= tree_get_file_position(lastfile
);
373 /* If the file doesn't exists, select the first one (default) */
374 if(tc
.selected_item
< 0)
375 tc
.selected_item
= 0;
384 (tc
.dirfull
|| tc
.filesindir
== global_settings
.max_files_in_dir
) )
386 splash(HZ
, ID2P(LANG_SHOWDIR_BUFFER_FULL
));
392 #ifdef HAVE_LCD_BITMAP
393 if (global_settings
.show_path_in_browser
== SHOW_PATH_FULL
394 || global_settings
.show_path_in_browser
== SHOW_PATH_CURRENT
)
396 gui_synclist_set_title(&tree_lists
, tagtree_get_title(&tc
),
397 filetype_get_icon(ATTR_DIRECTORY
));
401 /* Must clear the title as the list is reused */
402 gui_synclist_set_title(&tree_lists
, NULL
, NOICON
);
409 #ifdef HAVE_LCD_BITMAP
410 if (global_settings
.show_path_in_browser
&&
411 *(tc
.dirfilter
) == SHOW_PLUGINS
)
414 if (!strcmp(tc
.currdir
, PLUGIN_GAMES_DIR
))
415 title
= str(LANG_PLUGIN_GAMES
);
416 else if (!strcmp(tc
.currdir
, PLUGIN_APPS_DIR
))
417 title
= str(LANG_PLUGIN_APPS
);
418 else if (!strcmp(tc
.currdir
, PLUGIN_DEMOS_DIR
))
419 title
= str(LANG_PLUGIN_DEMOS
);
420 else title
= str(LANG_PLUGINS
);
421 gui_synclist_set_title(&tree_lists
, title
, Icon_Plugin
);
423 else if (global_settings
.show_path_in_browser
== SHOW_PATH_FULL
)
425 gui_synclist_set_title(&tree_lists
, tc
.currdir
,
426 filetype_get_icon(ATTR_DIRECTORY
));
428 else if (global_settings
.show_path_in_browser
== SHOW_PATH_CURRENT
)
430 char *title
= strrchr(tc
.currdir
, '/') + 1;
433 /* Display "Files" for the root dir */
434 gui_synclist_set_title(&tree_lists
, str(LANG_DIR_BROWSER
),
435 filetype_get_icon(ATTR_DIRECTORY
));
438 gui_synclist_set_title(&tree_lists
, title
,
439 filetype_get_icon(ATTR_DIRECTORY
));
443 /* Must clear the title as the list is reused */
444 gui_synclist_set_title(&tree_lists
, NULL
, NOICON
);
449 gui_synclist_set_nb_items(&tree_lists
, tc
.filesindir
);
450 gui_synclist_set_icon_callback(&tree_lists
, tree_get_fileicon
);
451 if( tc
.selected_item
>= tc
.filesindir
)
452 tc
.selected_item
=tc
.filesindir
-1;
454 gui_synclist_select_item(&tree_lists
, tc
.selected_item
);
455 #ifdef HAVE_BUTTONBAR
456 if (global_settings
.buttonbar
) {
457 if (*tc
.dirfilter
< NUM_FILTER_MODES
)
458 gui_buttonbar_set(&tree_buttonbar
, str(LANG_SYSFONT_DIRBROWSE_F1
),
459 str(LANG_SYSFONT_DIRBROWSE_F2
),
460 str(LANG_SYSFONT_DIRBROWSE_F3
));
462 gui_buttonbar_set(&tree_buttonbar
, "<<<", "", "");
463 gui_buttonbar_draw(&tree_buttonbar
);
466 gui_synclist_draw(&tree_lists
);
467 gui_synclist_speak_item(&tree_lists
);
468 return tc
.filesindir
;
471 /* load tracks from specified directory to resume play */
472 void resume_directory(const char *dir
)
474 int dirfilter
= *tc
.dirfilter
;
477 bool id3db
= *tc
.dirfilter
== SHOW_ID3DB
;
479 /* make sure the dirfilter is sane. The only time it should be possible
480 * thats its not is when resume playlist is called from a plugin
485 *tc
.dirfilter
= global_settings
.dirfilter
;
486 ret
= ft_load(&tc
, dir
);
487 *tc
.dirfilter
= dirfilter
;
492 ft_build_playlist(&tc
, 0);
500 /* Returns the current working directory and also writes cwd to buf if
501 non-NULL. In case of error, returns NULL. */
502 char *getcwd(char *buf
, int size
)
508 strncpy(buf
, tc
.currdir
, size
);
515 /* Force a reload of the directory next time directory browser is called */
516 void reload_directory(void)
521 void get_current_file(char* buffer
, int buffer_len
)
524 /* in ID3DB mode it is a bad idea to call this function */
525 /* (only happens with `follow playlist') */
526 if( *tc
.dirfilter
== SHOW_ID3DB
)
530 struct entry
* dc
= tc
.dircache
;
531 struct entry
* e
= &dc
[tc
.selected_item
];
532 snprintf(buffer
, buffer_len
, "%s/%s", getcwd(NULL
,0),
533 tc
.dirlength
? e
->name
: "");
536 /* Allow apps to change our dirfilter directly (required for sub browsers)
537 if they're suddenly going to become a file browser for example */
538 void set_dirfilter(int l_dirfilter
)
540 *tc
.dirfilter
= l_dirfilter
;
543 /* Selects a file and update tree context properly */
544 void set_current_file(char *path
)
550 /* in ID3DB mode it is a bad idea to call this function */
551 /* (only happens with `follow playlist') */
552 if( *tc
.dirfilter
== SHOW_ID3DB
)
556 /* separate directory from filename */
557 /* gets the directory's name and put it into tc.currdir */
558 name
= strrchr(path
+1,'/');
562 strcpy(tc
.currdir
, path
);
568 strcpy(tc
.currdir
, "/");
572 strcpy(lastfile
, name
);
575 /* If we changed dir we must recalculate the dirlevel
576 and adjust the selected history properly */
577 if (strncmp(tc
.currdir
,lastdir
,sizeof(lastdir
)))
580 tc
.selected_item_history
[tc
.dirlevel
] = -1;
582 /* use '/' to calculate dirlevel */
583 for (i
= 1; path
[i
] != '\0'; i
++)
588 tc
.selected_item_history
[tc
.dirlevel
] = -1;
592 if (ft_load(&tc
, NULL
) >= 0)
594 tc
.selected_item
= tree_get_file_position(lastfile
);
599 /* main loop, handles key events */
600 static int dirbrowse()
604 int button
, oldbutton
;
605 bool reload_root
= false;
606 int lastfilter
= *tc
.dirfilter
;
607 bool lastsortcase
= global_settings
.sort_case
;
608 bool exit_func
= false;
610 char* currdir
= tc
.currdir
; /* just a shortcut */
612 bool id3db
= *tc
.dirfilter
== SHOW_ID3DB
;
615 curr_context
=CONTEXT_ID3DB
;
618 curr_context
=CONTEXT_TREE
;
619 if (tc
.selected_item
< 0)
620 tc
.selected_item
= 0;
629 numentries
= update_dir();
631 if (numentries
== -1)
632 return GO_TO_PREVIOUS
; /* currdir is not a directory */
634 if (*tc
.dirfilter
> NUM_FILTER_MODES
&& numentries
==0)
636 splash(HZ
*2, ID2P(LANG_NO_FILES
));
637 return GO_TO_PREVIOUS
; /* No files found for rockbox_browser() */
640 gui_synclist_draw(&tree_lists
);
642 struct entry
*dircache
= tc
.dircache
;
643 bool restore
= false;
645 tc
.dirlevel
= 0; /* shouldnt be needed.. this code needs work! */
648 static const char *lines
[]={ID2P(LANG_BOOT_CHANGED
), ID2P(LANG_REBOOT_NOW
)};
649 static const struct text_message message
={lines
, 2};
650 if(gui_syncyesno_run(&message
, NULL
, NULL
)==YESNO_YES
)
651 rolo_load("/" BOOTFILE
);
653 boot_changed
= false;
656 button
= get_action(CONTEXT_TREE
,
657 list_do_action_timeout(&tree_lists
, HZ
/2));
659 gui_synclist_do_button(&tree_lists
, &button
,LIST_WRAP_UNLESS_HELD
);
660 tc
.selected_item
= gui_synclist_get_sel_pos(&tree_lists
);
663 /* nothing to do if no files to display */
664 if ( numentries
== 0 )
668 switch (id3db
?tagtree_enter(&tc
):ft_enter(&tc
))
670 switch (ft_enter(&tc
))
673 case 1: reload_dir
= true; break;
674 case 2: start_wps
= true; break;
675 case 3: exit_func
= true; break;
681 case ACTION_STD_CANCEL
:
682 if (*tc
.dirfilter
> NUM_FILTER_MODES
&& tc
.dirlevel
< 1) {
686 if ((*tc
.dirfilter
== SHOW_ID3DB
&& tc
.dirlevel
== 0) ||
687 ((*tc
.dirfilter
!= SHOW_ID3DB
&& !strcmp(currdir
,"/"))))
689 #ifdef HAVE_LCD_BITMAP /* charcell doesnt have ACTION_TREE_PGLEFT so this isnt needed */
690 if (oldbutton
== ACTION_TREE_PGLEFT
)
702 if (ft_exit(&tc
) == 3)
708 case ACTION_TREE_STOP
:
709 if (list_stop_handler())
713 case ACTION_STD_MENU
:
717 #ifdef HAVE_RECORDING
719 return GO_TO_RECSCREEN
;
722 case ACTION_TREE_WPS
:
723 return GO_TO_PREVIOUS_MUSIC
;
725 #ifdef HAVE_QUICKSCREEN
726 case ACTION_STD_QUICKSCREEN
:
727 /* don't enter f2 from plugin browser */
728 if (*tc
.dirfilter
< NUM_FILTER_MODES
)
730 if (quick_screen_quick(button
))
738 /* don't enter f3 from plugin browser */
739 if (*tc
.dirfilter
< NUM_FILTER_MODES
)
741 if (quick_screen_f3(ACTION_F3
))
748 case ACTION_STD_CONTEXT
:
754 onplay_result
= onplay(NULL
, 0, curr_context
);
759 if (tagtree_get_attr(&tc
) == FILE_ATTR_AUDIO
)
761 attr
= FILE_ATTR_AUDIO
;
762 tagtree_get_filename(&tc
, buf
, sizeof(buf
));
765 attr
= ATTR_DIRECTORY
;
770 attr
= dircache
[tc
.selected_item
].attr
;
772 if (currdir
[1]) /* Not in / */
773 snprintf(buf
, sizeof buf
, "%s/%s",
775 dircache
[tc
.selected_item
].name
);
777 snprintf(buf
, sizeof buf
, "/%s",
778 dircache
[tc
.selected_item
].name
);
780 onplay_result
= onplay(buf
, attr
, curr_context
);
782 switch (onplay_result
)
784 case ONPLAY_MAINMENU
:
791 case ONPLAY_RELOAD_DIR
:
795 case ONPLAY_START_PLAY
:
808 /* The 'dir no longer valid' situation will be caught later
809 * by checking the showdir() result. */
814 if (default_event_handler(button
) == SYS_USB_CONNECTED
)
816 if(*tc
.dirfilter
> NUM_FILTER_MODES
)
817 /* leave sub-browsers after usb, doing otherwise
818 might be confusing to the user */
827 if (button
&& !IS_SYSEVENT(button
))
834 /* do we need to rescan dir? */
835 if (reload_dir
|| reload_root
||
836 lastfilter
!= *tc
.dirfilter
||
837 lastsortcase
!= global_settings
.sort_case
)
840 strcpy(currdir
, "/");
853 gui_synclist_select_item(&tree_lists
, 0);
854 gui_synclist_draw(&tree_lists
);
855 tc
.selected_item
= 0;
859 lastfilter
= *tc
.dirfilter
;
860 lastsortcase
= global_settings
.sort_case
;
865 return GO_TO_PREVIOUS
;
867 if (restore
|| reload_dir
) {
868 /* restore display */
869 numentries
= update_dir();
871 if (currdir
[1] && (numentries
< 0))
872 { /* not in root and reload failed */
873 reload_root
= true; /* try root */
881 bool create_playlist(void)
883 char filename
[MAX_PATH
];
885 snprintf(filename
, sizeof filename
, "%s.m3u8",
886 tc
.currdir
[1] ? tc
.currdir
: "/root");
887 splashf(0, "%s %s", str(LANG_CREATING
), filename
);
890 catalog_add_to_a_playlist(tc
.currdir
, ATTR_DIRECTORY
, true, filename
);
896 int rockbox_browse(const char *root
, int dirfilter
)
899 int *last_filter
= tc
.dirfilter
;
900 tc
.dirfilter
= &dirfilter
;
901 tc
.sort_dir
= global_settings
.sort_dir
;
904 if (dirfilter
>= NUM_FILTER_MODES
)
906 static struct tree_context backup
;
907 char current
[MAX_PATH
];
911 tc
.selected_item
= 0;
913 memcpy(tc
.currdir
, root
, sizeof(tc
.currdir
));
915 last_context
= curr_context
;
917 /* Center on the currently loaded language when browsing languages. */
918 if (dirfilter
== SHOW_LNG
)
920 if (global_settings
.lang_file
[0])
922 snprintf(current
, sizeof(current
), LANG_DIR
"/%s.lng",
923 global_settings
.lang_file
);
927 strncpy(current
, LANG_DIR
"/english.lng", sizeof(current
));
930 /* Center on currently loaded WPS */
931 else if (dirfilter
== SHOW_WPS
)
933 snprintf(current
, sizeof(current
), WPS_DIR
"/%s.wps",
934 global_settings
.wps_file
);
936 #ifdef HAVE_REMOTE_LCD
937 /* Center on currently loaded RWPS */
938 else if (dirfilter
== SHOW_RWPS
)
940 snprintf(current
, sizeof(current
), WPS_DIR
"/%s.rwps",
941 global_settings
.rwps_file
);
944 #ifdef HAVE_LCD_BITMAP
945 /* Center on the currently loaded font when browsing fonts */
946 else if (dirfilter
== SHOW_FONT
)
948 snprintf(current
, sizeof(current
), FONT_DIR
"/%s.fnt",
949 global_settings
.font_file
);
953 /* Center on the currently loaded FM preset when browsing those */
954 else if (dirfilter
== SHOW_FMR
)
956 snprintf(current
, sizeof(current
), FMPRESET_PATH
"/%s.fmr",
957 global_settings
.fmr_file
);
961 /* If we've found a file to center on, do it */
962 if (current
[0] == '/')
964 set_current_file(current
);
965 /* set_current_file changes dirlevel, change it back */
969 ret_val
= dirbrowse();
971 curr_context
= last_context
;
975 static char buf
[MAX_PATH
];
976 if (dirfilter
!= SHOW_ID3DB
)
977 tc
.dirfilter
= &global_settings
.dirfilter
;
979 set_current_file(buf
);
980 ret_val
= dirbrowse();
982 tc
.dirfilter
= last_filter
;
986 void tree_mem_init(void)
988 /* We copy the settings value in case it is changed by the user. We can't
989 use it until the next reboot. */
990 max_files
= global_settings
.max_files_in_dir
;
992 /* initialize tree context struct */
993 memset(&tc
, 0, sizeof(tc
));
994 tc
.dirfilter
= &global_settings
.dirfilter
;
995 tc
.sort_dir
= global_settings
.sort_dir
;
997 tc
.name_buffer_size
= AVERAGE_FILENAME_LENGTH
* max_files
;
998 tc
.name_buffer
= buffer_alloc(tc
.name_buffer_size
);
1000 tc
.dircache_size
= max_files
* sizeof(struct entry
);
1001 tc
.dircache
= buffer_alloc(tc
.dircache_size
);
1002 tree_get_filetypes(&filetypes
, &filetypes_count
);
1005 bool bookmark_play(char *resume_file
, int index
, int offset
, int seed
,
1009 char* suffix
= strrchr(resume_file
, '.');
1010 bool started
= false;
1012 if (suffix
!= NULL
&&
1013 (!strcasecmp(suffix
, ".m3u") || !strcasecmp(suffix
, ".m3u8")))
1015 /* Playlist playback */
1017 /* check that the file exists */
1018 if(!file_exists(resume_file
))
1021 slash
= strrchr(resume_file
,'/');
1031 if (playlist_create(cp
, slash
+1) != -1)
1033 if (global_settings
.playlist_shuffle
)
1034 playlist_shuffle(seed
, -1);
1035 playlist_start(index
,offset
);
1043 /* Directory playback */
1045 if (playlist_create(resume_file
, NULL
) != -1)
1047 char* peek_filename
;
1048 resume_directory(resume_file
);
1049 if (global_settings
.playlist_shuffle
)
1050 playlist_shuffle(seed
, -1);
1052 /* Check if the file is at the same spot in the directory,
1053 else search for it */
1054 peek_filename
= playlist_peek(index
);
1056 if (peek_filename
== NULL
)
1059 if (strcmp(strrchr(peek_filename
, '/') + 1, filename
))
1061 for ( i
=0; i
< playlist_amount(); i
++ )
1063 peek_filename
= playlist_peek(i
);
1065 if (peek_filename
== NULL
)
1068 if (!strcmp(strrchr(peek_filename
, '/') + 1, filename
))
1071 if (i
< playlist_amount())
1076 playlist_start(index
,offset
);
1086 static void say_filetype(int attr
)
1088 /* try to find a voice ID for the extension, if known */
1090 attr
&= FILE_ATTR_MASK
; /* file type */
1091 for (j
=0; j
<filetypes_count
; j
++)
1092 if (attr
== filetypes
[j
].tree_attr
)
1094 talk_id(filetypes
[j
].voiceclip
, true);
1099 static int ft_play_dirname(char* name
)
1101 #if CONFIG_CODEC != SWCODEC
1102 if (audio_status() & AUDIO_STATUS_PLAY
)
1106 if(talk_file(tc
.currdir
, name
, dir_thumbnail_name
, NULL
,
1109 if(global_settings
.talk_filetype
)
1110 talk_id(VOICE_DIR
, true);
1117 static void ft_play_filename(char *dir
, char *file
)
1119 #if CONFIG_CODEC != SWCODEC
1120 if (audio_status() & AUDIO_STATUS_PLAY
)
1124 if (strlen(file
) >= strlen(file_thumbnail_ext
)
1125 && strcasecmp(&file
[strlen(file
) - strlen(file_thumbnail_ext
)],
1126 file_thumbnail_ext
))
1127 /* file has no .talk extension */
1128 talk_file(dir
, NULL
, file
, file_thumbnail_ext
,
1131 /* it already is a .talk file, play this directly, but prefix it. */
1132 talk_file(dir
, NULL
, file
, NULL
,
1133 TALK_IDARRAY(LANG_VOICE_DIR_HOVER
), false);
1136 /* These two functions are called by the USB and shutdown handlers */
1137 void tree_flush(void)
1139 #ifdef HAVE_TAGCACHE
1140 tagcache_shutdown();
1143 #ifdef HAVE_TC_RAMCACHE
1144 tagcache_unload_ramcache();
1147 #ifdef HAVE_DIRCACHE
1149 int old_val
= global_status
.dircache_size
;
1150 if (global_settings
.dircache
)
1152 if (!dircache_is_initializing())
1153 global_status
.dircache_size
= dircache_get_cache_size();
1154 # ifdef HAVE_EEPROM_SETTINGS
1155 if (firmware_settings
.initialized
)
1162 global_status
.dircache_size
= 0;
1164 if (old_val
!= global_status
.dircache_size
)
1170 void tree_restore(void)
1172 #ifdef HAVE_EEPROM_SETTINGS
1173 firmware_settings
.disk_clean
= false;
1176 #ifdef HAVE_TC_RAMCACHE
1177 remove(TAGCACHE_STATEFILE
);
1180 #ifdef HAVE_DIRCACHE
1181 remove(DIRCACHE_FILE
);
1182 if (global_settings
.dircache
)
1184 /* Print "Scanning disk..." to the display. */
1185 splash(0, str(LANG_SCANNING_DISK
));
1187 dircache_build(global_status
.dircache_size
);
1190 #ifdef HAVE_TAGCACHE
1191 tagcache_start_scan();