1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 Daniel Stenberg
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
24 #include "applimits.h"
29 #include "backlight.h"
56 #include "filetypes.h"
61 #include "recorder/recording.h"
69 #include "gwps-common.h"
70 #include "eeprom_settings.h"
71 #include "scrobbler.h"
75 #include "statusbar.h"
77 #include "buttonbar.h"
81 #include "root_menu.h"
83 #if (LCD_DEPTH > 1) || (defined(HAVE_LCD_REMOTE) && (LCD_REMOTE_DEPTH > 1))
87 static const struct filetype
*filetypes
;
88 static int filetypes_count
;
90 struct gui_synclist tree_lists
;
92 /* I put it here because other files doesn't use it yet,
93 * but should be elsewhere since it will be used mostly everywhere */
95 struct gui_buttonbar tree_buttonbar
;
97 static struct tree_context tc
;
99 bool boot_changed
= false;
101 char lastfile
[MAX_PATH
];
102 static char lastdir
[MAX_PATH
];
104 static int lasttable
, lastextra
, lastfirstpos
;
106 static int max_files
= 0;
108 static bool reload_dir
= false;
110 static bool start_wps
= false;
111 static int curr_context
= false;/* id3db or tree*/
113 static int dirbrowse(void);
114 static int ft_play_dirname(char* name
);
115 static void ft_play_filename(char *dir
, char *file
);
116 static void say_filetype(int attr
);
118 static char * tree_get_filename(int selected_item
, void * data
, char *buffer
)
120 struct tree_context
* local_tc
=(struct tree_context
*)data
;
123 bool stripit
= false;
125 bool id3db
= *(local_tc
->dirfilter
) == SHOW_ID3DB
;
129 return tagtree_get_entry(&tc
, selected_item
)->name
;
134 struct entry
* dc
= local_tc
->dircache
;
135 struct entry
* e
= &dc
[selected_item
];
140 if(!(attr
& ATTR_DIRECTORY
))
142 switch(global_settings
.show_filename_ext
)
145 /* show file extension: off */
149 /* show file extension: on */
152 /* show file extension: only unknown types */
153 stripit
= filetype_supported(attr
);
157 /* show file extension: only when viewing all */
158 stripit
= (*(local_tc
->dirfilter
) != SHOW_ID3DB
) &&
159 (*(local_tc
->dirfilter
) != SHOW_ALL
);
166 return(strip_extension(buffer
, MAX_PATH
, name
));
171 #ifdef HAVE_LCD_COLOR
172 static int tree_get_filecolor(int selected_item
, void * data
)
174 if (*tc
.dirfilter
== SHOW_ID3DB
)
176 struct tree_context
* local_tc
=(struct tree_context
*)data
;
177 struct entry
* dc
= local_tc
->dircache
;
178 struct entry
* e
= &dc
[selected_item
];
179 return filetype_get_color(e
->name
, e
->attr
);
183 static int tree_get_fileicon(int selected_item
, void * data
)
185 struct tree_context
* local_tc
=(struct tree_context
*)data
;
187 bool id3db
= *(local_tc
->dirfilter
) == SHOW_ID3DB
;
189 return tagtree_get_icon(&tc
);
194 struct entry
* dc
= local_tc
->dircache
;
195 struct entry
* e
= &dc
[selected_item
];
196 return filetype_get_icon(e
->attr
);
200 static int tree_voice_cb(int selected_item
, void * data
)
202 struct tree_context
* local_tc
=(struct tree_context
*)data
;
206 bool id3db
= *(local_tc
->dirfilter
) == SHOW_ID3DB
;
210 attr
= tagtree_get_attr(local_tc
);
211 name
= tagtree_get_entry(local_tc
, selected_item
)->name
;
216 struct entry
* dc
= local_tc
->dircache
;
217 struct entry
* e
= &dc
[selected_item
];
221 bool is_dir
= (attr
& ATTR_DIRECTORY
);
222 bool did_clip
= false;
223 /* First the .talk clip case */
226 if(global_settings
.talk_dir_clip
)
228 DEBUGF("Playing directory thumbnail: %s", local_tc
->currdir
);
230 if(ft_play_dirname(name
) <0)
231 /* failed, not existing */
234 } else { /* it's a file */
235 if (global_settings
.talk_file_clip
&& (attr
& FILE_ATTR_THUMBNAIL
))
238 DEBUGF("Playing file thumbnail: %s/%s%s\n",
239 local_tc
->currdir
, name
, file_thumbnail_ext
);
240 ft_play_filename(local_tc
->currdir
, name
);
245 /* say the number or spell if required or as a fallback */
246 switch (is_dir
? global_settings
.talk_dir
: global_settings
.talk_file
)
248 case 1: /* as numbers */
249 talk_id(is_dir
? VOICE_DIR
: VOICE_FILE
, false);
250 talk_number(selected_item
+1 - (is_dir
? 0 : local_tc
->dirsindir
),
252 if(global_settings
.talk_filetype
253 && !is_dir
&& *local_tc
->dirfilter
< NUM_FILTER_MODES
)
256 case 2: /* spelled */
258 if(global_settings
.talk_filetype
)
261 talk_id(VOICE_DIR
, true);
262 else if(*local_tc
->dirfilter
< NUM_FILTER_MODES
)
265 talk_spell(name
, true);
272 bool check_rockboxdir(void)
274 DIR *dir
= opendir(ROCKBOX_DIR
);
276 { /* No need to localise this message.
277 If .rockbox is missing, it wouldn't work anyway */
280 screens
[i
].clear_display();
281 gui_syncsplash(HZ
*2, "No .rockbox directory");
283 screens
[i
].clear_display();
284 gui_syncsplash(HZ
*2, "Installation incomplete");
291 /* do this really late in the init sequence */
292 void tree_gui_init(void)
294 gui_sync_wps_screen_init();
298 strcpy(tc
.currdir
, "/");
300 #ifdef HAVE_LCD_CHARCELLS
303 screens
[i
].double_height(false);
306 gui_buttonbar_init(&tree_buttonbar
);
307 /* since archos only have one screen, no need to create more than that */
308 gui_buttonbar_set_display(&tree_buttonbar
, &(screens
[SCREEN_MAIN
]) );
310 gui_synclist_init(&tree_lists
, &tree_get_filename
, &tc
, false, 1);
311 gui_synclist_set_voice_callback(&tree_lists
, tree_voice_cb
);
312 gui_synclist_set_icon_callback(&tree_lists
, &tree_get_fileicon
);
313 #ifdef HAVE_LCD_COLOR
314 gui_synclist_set_color_callback(&tree_lists
, &tree_get_filecolor
);
320 struct tree_context
* tree_get_context(void)
326 * Returns the position of a given file in the current directory
327 * returns -1 if not found
329 static int tree_get_file_position(char * filename
)
333 /* use lastfile to determine the selected item (default=0) */
334 for (i
=0; i
< tc
.filesindir
; i
++)
336 struct entry
* dc
= tc
.dircache
;
337 struct entry
* e
= &dc
[i
];
338 if (!strcasecmp(e
->name
, filename
))
341 return(-1);/* no file can match, returns undefined */
345 * Called when a new dir is loaded (for example when returning from other apps ...)
346 * also completely redraws the tree
348 static int update_dir(void)
350 bool changed
= false;
352 bool id3db
= *tc
.dirfilter
== SHOW_ID3DB
;
353 /* Checks for changes */
355 if (tc
.currtable
!= lasttable
||
356 tc
.currextra
!= lastextra
||
357 tc
.firstpos
!= lastfirstpos
||
360 if (tagtree_load(&tc
) < 0)
363 lasttable
= tc
.currtable
;
364 lastextra
= tc
.currextra
;
365 lastfirstpos
= tc
.firstpos
;
372 /* if the tc.currdir has been changed, reload it ...*/
373 if (strncmp(tc
.currdir
, lastdir
, sizeof(lastdir
)) || reload_dir
)
375 if (ft_load(&tc
, NULL
) < 0)
377 strcpy(lastdir
, tc
.currdir
);
381 /* if selected item is undefined */
382 if (tc
.selected_item
== -1)
384 /* use lastfile to determine the selected item */
385 tc
.selected_item
= tree_get_file_position(lastfile
);
387 /* If the file doesn't exists, select the first one (default) */
388 if(tc
.selected_item
< 0)
389 tc
.selected_item
= 0;
398 (tc
.dirfull
|| tc
.filesindir
== global_settings
.max_files_in_dir
) )
400 gui_syncsplash(HZ
, ID2P(LANG_SHOWDIR_BUFFER_FULL
));
406 #ifdef HAVE_LCD_BITMAP
407 if (global_settings
.show_path_in_browser
== SHOW_PATH_FULL
408 || global_settings
.show_path_in_browser
== SHOW_PATH_CURRENT
)
410 gui_synclist_set_title(&tree_lists
, tagtree_get_title(&tc
),
411 filetype_get_icon(ATTR_DIRECTORY
));
415 /* Must clear the title as the list is reused */
416 gui_synclist_set_title(&tree_lists
, NULL
, NOICON
);
423 #ifdef HAVE_LCD_BITMAP
424 if (global_settings
.show_path_in_browser
&&
425 *(tc
.dirfilter
) == SHOW_PLUGINS
)
428 if (!strcmp(tc
.currdir
, PLUGIN_GAMES_DIR
))
429 title
= str(LANG_PLUGIN_GAMES
);
430 else if (!strcmp(tc
.currdir
, PLUGIN_APPS_DIR
))
431 title
= str(LANG_PLUGIN_APPS
);
432 else if (!strcmp(tc
.currdir
, PLUGIN_DEMOS_DIR
))
433 title
= str(LANG_PLUGIN_DEMOS
);
434 else title
= str(LANG_PLUGINS
);
435 gui_synclist_set_title(&tree_lists
, title
, Icon_Plugin
);
437 else if (global_settings
.show_path_in_browser
== SHOW_PATH_FULL
)
439 gui_synclist_set_title(&tree_lists
, tc
.currdir
,
440 filetype_get_icon(ATTR_DIRECTORY
));
442 else if (global_settings
.show_path_in_browser
== SHOW_PATH_CURRENT
)
444 char *title
= strrchr(tc
.currdir
, '/') + 1;
447 /* Display "Files" for the root dir */
448 gui_synclist_set_title(&tree_lists
, str(LANG_DIR_BROWSER
),
449 filetype_get_icon(ATTR_DIRECTORY
));
452 gui_synclist_set_title(&tree_lists
, title
,
453 filetype_get_icon(ATTR_DIRECTORY
));
457 /* Must clear the title as the list is reused */
458 gui_synclist_set_title(&tree_lists
, NULL
, NOICON
);
463 gui_synclist_set_nb_items(&tree_lists
, tc
.filesindir
);
464 gui_synclist_set_icon_callback(&tree_lists
, tree_get_fileicon
);
465 if( tc
.selected_item
>= tc
.filesindir
)
466 tc
.selected_item
=tc
.filesindir
-1;
468 gui_synclist_select_item(&tree_lists
, tc
.selected_item
);
470 if (global_settings
.buttonbar
) {
471 if (*tc
.dirfilter
< NUM_FILTER_MODES
)
472 gui_buttonbar_set(&tree_buttonbar
, str(LANG_SYSFONT_DIRBROWSE_F1
),
473 str(LANG_SYSFONT_DIRBROWSE_F2
),
474 str(LANG_SYSFONT_DIRBROWSE_F3
));
476 gui_buttonbar_set(&tree_buttonbar
, "<<<", "", "");
477 gui_buttonbar_draw(&tree_buttonbar
);
480 gui_synclist_draw(&tree_lists
);
481 gui_synclist_speak_item(&tree_lists
);
482 gui_syncstatusbar_draw(&statusbars
, true);
483 return tc
.filesindir
;
486 /* load tracks from specified directory to resume play */
487 void resume_directory(const char *dir
)
490 bool id3db
= *tc
.dirfilter
== SHOW_ID3DB
;
493 if (ft_load(&tc
, dir
) < 0)
497 ft_build_playlist(&tc
, 0);
505 /* Returns the current working directory and also writes cwd to buf if
506 non-NULL. In case of error, returns NULL. */
507 char *getcwd(char *buf
, int size
)
513 strncpy(buf
, tc
.currdir
, size
);
520 /* Force a reload of the directory next time directory browser is called */
521 void reload_directory(void)
526 void get_current_file(char* buffer
, int buffer_len
)
529 /* in ID3DB mode it is a bad idea to call this function */
530 /* (only happens with `follow playlist') */
531 if( *tc
.dirfilter
== SHOW_ID3DB
)
535 struct entry
* dc
= tc
.dircache
;
536 struct entry
* e
= &dc
[tc
.selected_item
];
537 snprintf(buffer
, buffer_len
, "%s/%s", getcwd(NULL
,0),
538 tc
.dirlength
? e
->name
: "");
541 /* Allow apps to change our dirfilter directly (required for sub browsers)
542 if they're suddenly going to become a file browser for example */
543 void set_dirfilter(int l_dirfilter
)
545 *tc
.dirfilter
= l_dirfilter
;
548 /* Selects a file and update tree context properly */
549 void set_current_file(char *path
)
555 /* in ID3DB mode it is a bad idea to call this function */
556 /* (only happens with `follow playlist') */
557 if( *tc
.dirfilter
== SHOW_ID3DB
)
561 /* separate directory from filename */
562 /* gets the directory's name and put it into tc.currdir */
563 name
= strrchr(path
+1,'/');
567 strcpy(tc
.currdir
, path
);
573 strcpy(tc
.currdir
, "/");
577 strcpy(lastfile
, name
);
580 /* If we changed dir we must recalculate the dirlevel
581 and adjust the selected history properly */
582 if (strncmp(tc
.currdir
,lastdir
,sizeof(lastdir
)))
585 tc
.selected_item_history
[tc
.dirlevel
] = -1;
587 /* use '/' to calculate dirlevel */
588 for (i
= 1; path
[i
] != '\0'; i
++)
593 tc
.selected_item_history
[tc
.dirlevel
] = -1;
597 if (ft_load(&tc
, NULL
) >= 0)
599 tc
.selected_item
= tree_get_file_position(lastfile
);
604 /* main loop, handles key events */
605 static int dirbrowse()
609 unsigned button
, oldbutton
;
610 bool reload_root
= false;
611 int lastfilter
= *tc
.dirfilter
;
612 bool lastsortcase
= global_settings
.sort_case
;
613 bool exit_func
= false;
615 char* currdir
= tc
.currdir
; /* just a shortcut */
617 bool id3db
= *tc
.dirfilter
== SHOW_ID3DB
;
620 curr_context
=CONTEXT_ID3DB
;
623 curr_context
=CONTEXT_TREE
;
624 if (tc
.selected_item
< 0)
625 tc
.selected_item
= 0;
634 numentries
= update_dir();
636 if (numentries
== -1)
637 return GO_TO_PREVIOUS
; /* currdir is not a directory */
639 if (*tc
.dirfilter
> NUM_FILTER_MODES
&& numentries
==0)
641 gui_syncsplash(HZ
*2, ID2P(LANG_NO_FILES
));
642 return GO_TO_PREVIOUS
; /* No files found for rockbox_browser() */
646 struct entry
*dircache
= tc
.dircache
;
647 bool restore
= false;
649 tc
.dirlevel
= 0; /* shouldnt be needed.. this code needs work! */
652 char *lines
[]={ID2P(LANG_BOOT_CHANGED
), ID2P(LANG_REBOOT_NOW
)};
653 struct text_message message
={lines
, 2};
654 if(gui_syncyesno_run(&message
, NULL
, NULL
)==YESNO_YES
)
655 rolo_load("/" BOOTFILE
);
657 boot_changed
= false;
660 button
= get_action(CONTEXT_TREE
,
661 list_do_action_timeout(&tree_lists
, HZ
/2));
663 gui_synclist_do_button(&tree_lists
, &button
,LIST_WRAP_UNLESS_HELD
);
664 tc
.selected_item
= gui_synclist_get_sel_pos(&tree_lists
);
667 /* nothing to do if no files to display */
668 if ( numentries
== 0 )
672 switch (id3db
?tagtree_enter(&tc
):ft_enter(&tc
))
674 switch (ft_enter(&tc
))
677 case 1: reload_dir
= true; break;
678 case 2: start_wps
= true; break;
679 case 3: exit_func
= true; break;
685 case ACTION_STD_CANCEL
:
686 if (*tc
.dirfilter
> NUM_FILTER_MODES
&& tc
.dirlevel
< 1) {
690 if ((*tc
.dirfilter
== SHOW_ID3DB
&& tc
.dirlevel
== 0) ||
691 ((*tc
.dirfilter
!= SHOW_ID3DB
&& !strcmp(currdir
,"/"))))
693 #ifdef HAVE_LCD_BITMAP /* charcell doesnt have ACTION_TREE_PGLEFT so this isnt needed */
694 if (oldbutton
== ACTION_TREE_PGLEFT
)
706 if (ft_exit(&tc
) == 3)
712 case ACTION_TREE_STOP
:
713 if (list_stop_handler())
717 case ACTION_STD_MENU
:
721 #ifdef HAVE_RECORDING
723 return GO_TO_RECSCREEN
;
726 case ACTION_TREE_WPS
:
727 return GO_TO_PREVIOUS_MUSIC
;
729 #ifdef HAVE_QUICKSCREEN
730 case ACTION_STD_QUICKSCREEN
:
731 /* don't enter f2 from plugin browser */
732 if (*tc
.dirfilter
< NUM_FILTER_MODES
)
734 if (quick_screen_quick(button
))
742 /* don't enter f3 from plugin browser */
743 if (*tc
.dirfilter
< NUM_FILTER_MODES
)
745 if (quick_screen_f3(BUTTON_F3
))
752 case ACTION_STD_CONTEXT
:
758 onplay_result
= onplay(NULL
, 0, curr_context
);
763 if (tagtree_get_attr(&tc
) == FILE_ATTR_AUDIO
)
765 attr
= FILE_ATTR_AUDIO
;
766 tagtree_get_filename(&tc
, buf
, sizeof(buf
));
769 attr
= ATTR_DIRECTORY
;
774 attr
= dircache
[tc
.selected_item
].attr
;
776 if (currdir
[1]) /* Not in / */
777 snprintf(buf
, sizeof buf
, "%s/%s",
779 dircache
[tc
.selected_item
].name
);
781 snprintf(buf
, sizeof buf
, "/%s",
782 dircache
[tc
.selected_item
].name
);
784 onplay_result
= onplay(buf
, attr
, curr_context
);
786 switch (onplay_result
)
788 case ONPLAY_MAINMENU
:
795 case ONPLAY_RELOAD_DIR
:
799 case ONPLAY_START_PLAY
:
807 gui_syncstatusbar_draw(&statusbars
, false);
816 /* The 'dir no longer valid' situation will be caught later
817 * by checking the showdir() result. */
822 if (default_event_handler(button
) == SYS_USB_CONNECTED
)
824 if(*tc
.dirfilter
> NUM_FILTER_MODES
)
825 /* leave sub-browsers after usb, doing otherwise
826 might be confusing to the user */
842 /* do we need to rescan dir? */
843 if (reload_dir
|| reload_root
||
844 lastfilter
!= *tc
.dirfilter
||
845 lastsortcase
!= global_settings
.sort_case
)
848 strcpy(currdir
, "/");
861 gui_synclist_select_item(&tree_lists
, 0);
862 gui_synclist_draw(&tree_lists
);
863 tc
.selected_item
= 0;
867 lastfilter
= *tc
.dirfilter
;
868 lastsortcase
= global_settings
.sort_case
;
873 return GO_TO_PREVIOUS
;
875 if (restore
|| reload_dir
) {
876 /* restore display */
877 numentries
= update_dir();
879 if (currdir
[1] && (numentries
< 0))
880 { /* not in root and reload failed */
881 reload_root
= true; /* try root */
889 static int plsize
= 0;
891 static bool add_dir(char* dirname
, int len
, int fd
)
896 /* check for user abort */
897 if (action_userabort(TIMEOUT_NOBLOCK
))
900 dir
= opendir(dirname
);
905 struct dirent
*entry
;
907 entry
= readdir(dir
);
910 if (entry
->attribute
& ATTR_DIRECTORY
) {
911 int dirlen
= strlen(dirname
);
914 if (!strcmp((char *)entry
->d_name
, ".") ||
915 !strcmp((char *)entry
->d_name
, ".."))
919 snprintf(dirname
+dirlen
, len
-dirlen
, "/%s", entry
->d_name
);
921 snprintf(dirname
, len
, "/%s", entry
->d_name
);
923 result
= add_dir(dirname
, len
, fd
);
924 dirname
[dirlen
] = '\0';
931 int x
= strlen((char *)entry
->d_name
);
933 char *cp
= strrchr((char *)entry
->d_name
,'.');
938 /* add all supported audio files to playlists */
939 for (i
=0; i
< filetypes_count
; i
++) {
940 if (filetypes
[i
].tree_attr
== FILE_ATTR_AUDIO
) {
941 if (!strcasecmp(cp
, filetypes
[i
].extension
)) {
944 write(fd
, dirname
, strlen(dirname
));
946 write(fd
, entry
->d_name
, x
);
950 if(TIME_AFTER(current_tick
, pltick
+HZ
/4)) {
951 pltick
= current_tick
;
953 snprintf(buf
, sizeof buf
, "%d", plsize
);
954 #ifdef HAVE_LCD_BITMAP
957 screens
[i
].puts(0, 4, (unsigned char *)buf
);
958 gui_textarea_update(&screens
[i
]);
963 else if (plsize
> 99)
971 screens
[i
].puts(x
,0,buf
);
987 bool create_playlist(void)
991 char filename
[MAX_PATH
];
993 pltick
= current_tick
;
995 snprintf(filename
, sizeof filename
, "%s.m3u8",
996 tc
.currdir
[1] ? tc
.currdir
: "/root");
999 gui_textarea_clear(&screens
[i
]);
1000 screens
[i
].puts(0, 0, str(LANG_CREATING
));
1001 screens
[i
].puts_scroll(0, 1, (unsigned char *)filename
);
1002 #if defined(HAVE_LCD_BITMAP) || defined(SIMULATOR)
1003 gui_textarea_update(&screens
[i
]);
1006 fd
= creat(filename
);
1010 trigger_cpu_boost();
1012 snprintf(filename
, sizeof(filename
), "%s",
1013 tc
.currdir
[1] ? tc
.currdir
: "/");
1015 add_dir(filename
, sizeof(filename
), fd
);
1024 int rockbox_browse(const char *root
, int dirfilter
)
1027 int *last_filter
= tc
.dirfilter
;
1028 tc
.dirfilter
= &dirfilter
;
1031 if (dirfilter
>= NUM_FILTER_MODES
)
1033 static struct tree_context backup
;
1037 tc
.selected_item
= 0;
1039 memcpy(tc
.currdir
, root
, sizeof(tc
.currdir
));
1041 last_context
= curr_context
;
1043 ret_val
= dirbrowse();
1045 curr_context
= last_context
;
1049 static char buf
[MAX_PATH
];
1050 if (dirfilter
!= SHOW_ID3DB
)
1051 tc
.dirfilter
= &global_settings
.dirfilter
;
1053 set_current_file(buf
);
1054 ret_val
= dirbrowse();
1056 tc
.dirfilter
= last_filter
;
1060 void tree_mem_init(void)
1062 /* We copy the settings value in case it is changed by the user. We can't
1063 use it until the next reboot. */
1064 max_files
= global_settings
.max_files_in_dir
;
1066 /* initialize tree context struct */
1067 memset(&tc
, 0, sizeof(tc
));
1068 tc
.dirfilter
= &global_settings
.dirfilter
;
1070 tc
.name_buffer_size
= AVERAGE_FILENAME_LENGTH
* max_files
;
1071 tc
.name_buffer
= buffer_alloc(tc
.name_buffer_size
);
1073 tc
.dircache_size
= max_files
* sizeof(struct entry
);
1074 tc
.dircache
= buffer_alloc(tc
.dircache_size
);
1075 tree_get_filetypes(&filetypes
, &filetypes_count
);
1078 bool bookmark_play(char *resume_file
, int index
, int offset
, int seed
,
1082 char* suffix
= strrchr(resume_file
, '.');
1083 bool started
= false;
1085 if (suffix
!= NULL
&&
1086 (!strcasecmp(suffix
, ".m3u") || !strcasecmp(suffix
, ".m3u8")))
1088 /* Playlist playback */
1090 /* check that the file exists */
1091 int fd
= open(resume_file
, O_RDONLY
);
1096 slash
= strrchr(resume_file
,'/');
1106 if (playlist_create(cp
, slash
+1) != -1)
1108 if (global_settings
.playlist_shuffle
)
1109 playlist_shuffle(seed
, -1);
1110 playlist_start(index
,offset
);
1118 /* Directory playback */
1120 if (playlist_create(resume_file
, NULL
) != -1)
1122 char* peek_filename
;
1123 resume_directory(resume_file
);
1124 if (global_settings
.playlist_shuffle
)
1125 playlist_shuffle(seed
, -1);
1127 /* Check if the file is at the same spot in the directory,
1128 else search for it */
1129 peek_filename
= playlist_peek(index
);
1131 if (peek_filename
== NULL
)
1134 if (strcmp(strrchr(peek_filename
, '/') + 1, filename
))
1136 for ( i
=0; i
< playlist_amount(); i
++ )
1138 peek_filename
= playlist_peek(i
);
1140 if (peek_filename
== NULL
)
1143 if (!strcmp(strrchr(peek_filename
, '/') + 1, filename
))
1146 if (i
< playlist_amount())
1151 playlist_start(index
,offset
);
1161 static void say_filetype(int attr
)
1163 /* try to find a voice ID for the extension, if known */
1165 attr
&= FILE_ATTR_MASK
; /* file type */
1166 for (j
=0; j
<filetypes_count
; j
++)
1167 if (attr
== filetypes
[j
].tree_attr
)
1169 talk_id(filetypes
[j
].voiceclip
, true);
1174 static int ft_play_dirname(char* name
)
1177 char dirname_mp3_filename
[MAX_PATH
+1];
1179 #if CONFIG_CODEC != SWCODEC
1180 if (audio_status() & AUDIO_STATUS_PLAY
)
1184 snprintf(dirname_mp3_filename
, sizeof(dirname_mp3_filename
), "%s/%s/%s",
1185 tc
.currdir
[1] ? tc
.currdir
: "" , name
,
1186 dir_thumbnail_name
);
1188 DEBUGF("Checking for %s\n", dirname_mp3_filename
);
1190 fd
= open(dirname_mp3_filename
, O_RDONLY
);
1193 DEBUGF("Failed to find: %s\n", dirname_mp3_filename
);
1199 DEBUGF("Found: %s\n", dirname_mp3_filename
);
1201 talk_file(dirname_mp3_filename
, false);
1202 if(global_settings
.talk_filetype
)
1203 talk_id(VOICE_DIR
, true);
1207 static void ft_play_filename(char *dir
, char *file
)
1209 char name_mp3_filename
[MAX_PATH
+1];
1211 #if CONFIG_CODEC != SWCODEC
1212 if (audio_status() & AUDIO_STATUS_PLAY
)
1216 if (strcasecmp(&file
[strlen(file
) - strlen(file_thumbnail_ext
)],
1217 file_thumbnail_ext
))
1218 { /* file has no .talk extension */
1219 snprintf(name_mp3_filename
, sizeof(name_mp3_filename
),
1220 "%s/%s%s", dir
, file
, file_thumbnail_ext
);
1222 talk_file(name_mp3_filename
, false);
1225 { /* it already is a .talk file, play this directly */
1226 snprintf(name_mp3_filename
, sizeof(name_mp3_filename
),
1227 "%s/%s", dir
, file
);
1228 talk_id(LANG_VOICE_DIR_HOVER
, false); /* prefix it */
1229 talk_file(name_mp3_filename
, true);
1233 /* These two functions are called by the USB and shutdown handlers */
1234 void tree_flush(void)
1236 scrobbler_shutdown();
1237 #ifdef HAVE_TAGCACHE
1238 tagcache_shutdown();
1240 playlist_shutdown();
1242 #ifdef HAVE_TC_RAMCACHE
1243 tagcache_unload_ramcache();
1246 #ifdef HAVE_DIRCACHE
1248 int old_val
= global_status
.dircache_size
;
1249 if (global_settings
.dircache
)
1251 if (!dircache_is_initializing())
1252 global_status
.dircache_size
= dircache_get_cache_size();
1253 # ifdef HAVE_EEPROM_SETTINGS
1254 if (firmware_settings
.initialized
)
1261 global_status
.dircache_size
= 0;
1263 if (old_val
!= global_status
.dircache_size
)
1269 void tree_restore(void)
1271 #ifdef HAVE_EEPROM_SETTINGS
1272 firmware_settings
.disk_clean
= false;
1275 #ifdef HAVE_TC_RAMCACHE
1276 remove(TAGCACHE_STATEFILE
);
1279 #ifdef HAVE_DIRCACHE
1280 remove(DIRCACHE_FILE
);
1281 if (global_settings
.dircache
)
1283 /* Print "Scanning disk..." to the display. */
1287 screens
[i
].putsxy((LCD_WIDTH
/2) -
1288 ((strlen(str(LANG_SCANNING_DISK
)) *
1289 screens
[i
].char_width
)/2),
1290 LCD_HEIGHT
-screens
[i
].char_height
*3,
1291 str(LANG_SCANNING_DISK
));
1292 gui_textarea_update(&screens
[i
]);
1294 cond_talk_ids_fq(LANG_SCANNING_DISK
);
1296 dircache_build(global_status
.dircache_size
);
1298 /* Clean the text when we are done. */
1301 gui_textarea_clear(&screens
[i
]);
1305 #ifdef HAVE_TAGCACHE
1306 tagcache_start_scan();