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"
80 #include "quickscreen.h"
82 #include "root_menu.h"
84 #if (LCD_DEPTH > 1) || (defined(HAVE_LCD_REMOTE) && (LCD_REMOTE_DEPTH > 1))
88 static const struct filetype
*filetypes
;
89 static int filetypes_count
;
91 struct gui_synclist tree_lists
;
93 /* I put it here because other files doesn't use it yet,
94 * but should be elsewhere since it will be used mostly everywhere */
96 struct gui_buttonbar tree_buttonbar
;
98 static struct tree_context tc
;
100 bool boot_changed
= false;
102 char lastfile
[MAX_PATH
];
103 static char lastdir
[MAX_PATH
];
105 static int lasttable
, lastextra
, lastfirstpos
;
107 static int max_files
= 0;
109 static bool reload_dir
= false;
111 static bool start_wps
= false;
112 static int curr_context
= false;/* id3db or tree*/
114 static int dirbrowse(void);
115 static int ft_play_dirname(char* name
);
116 static void ft_play_filename(char *dir
, char *file
);
117 static void say_filetype(int attr
);
119 static char * tree_get_filename(int selected_item
, void * data
, char *buffer
)
121 struct tree_context
* local_tc
=(struct tree_context
*)data
;
124 bool stripit
= false;
126 bool id3db
= *(local_tc
->dirfilter
) == SHOW_ID3DB
;
130 return tagtree_get_entry(&tc
, selected_item
)->name
;
135 struct entry
* dc
= local_tc
->dircache
;
136 struct entry
* e
= &dc
[selected_item
];
141 if(!(attr
& ATTR_DIRECTORY
))
143 switch(global_settings
.show_filename_ext
)
146 /* show file extension: off */
150 /* show file extension: on */
153 /* show file extension: only unknown types */
154 stripit
= filetype_supported(attr
);
158 /* show file extension: only when viewing all */
159 stripit
= (*(local_tc
->dirfilter
) != SHOW_ID3DB
) &&
160 (*(local_tc
->dirfilter
) != SHOW_ALL
);
167 return(strip_extension(name
, buffer
));
172 #ifdef HAVE_LCD_COLOR
173 static int tree_get_filecolor(int selected_item
, void * data
)
175 if (*tc
.dirfilter
== SHOW_ID3DB
)
177 struct tree_context
* local_tc
=(struct tree_context
*)data
;
178 struct entry
* dc
= local_tc
->dircache
;
179 struct entry
* e
= &dc
[selected_item
];
180 return filetype_get_color(e
->name
, e
->attr
);
184 static int tree_get_fileicon(int selected_item
, void * data
)
186 struct tree_context
* local_tc
=(struct tree_context
*)data
;
188 bool id3db
= *(local_tc
->dirfilter
) == SHOW_ID3DB
;
190 return tagtree_get_icon(&tc
);
195 struct entry
* dc
= local_tc
->dircache
;
196 struct entry
* e
= &dc
[selected_item
];
197 return filetype_get_icon(e
->attr
);
201 static int tree_voice_cb(int selected_item
, void * data
)
203 struct tree_context
* local_tc
=(struct tree_context
*)data
;
207 bool id3db
= *(local_tc
->dirfilter
) == SHOW_ID3DB
;
211 attr
= tagtree_get_attr(local_tc
);
212 name
= tagtree_get_entry(local_tc
, selected_item
)->name
;
217 struct entry
* dc
= local_tc
->dircache
;
218 struct entry
* e
= &dc
[selected_item
];
222 bool is_dir
= (attr
& ATTR_DIRECTORY
);
223 bool did_clip
= false;
224 /* First the .talk clip case */
227 if(global_settings
.talk_dir_clip
)
229 DEBUGF("Playing directory thumbnail: %s", local_tc
->currdir
);
231 if(ft_play_dirname(name
) <0)
232 /* failed, not existing */
235 } else { /* it's a file */
236 if (global_settings
.talk_file_clip
&& (attr
& FILE_ATTR_THUMBNAIL
))
239 DEBUGF("Playing file thumbnail: %s/%s%s\n",
240 local_tc
->currdir
, name
, file_thumbnail_ext
);
241 ft_play_filename(local_tc
->currdir
, name
);
246 /* say the number or spell if required or as a fallback */
247 switch (is_dir
? global_settings
.talk_dir
: global_settings
.talk_file
)
249 case 1: /* as numbers */
250 talk_id(is_dir
? VOICE_DIR
: VOICE_FILE
, false);
251 talk_number(selected_item
+1 - (is_dir
? 0 : local_tc
->dirsindir
),
253 if(global_settings
.talk_filetype
254 && !is_dir
&& *local_tc
->dirfilter
< NUM_FILTER_MODES
)
257 case 2: /* spelled */
259 if(global_settings
.talk_filetype
)
262 talk_id(VOICE_DIR
, true);
263 else if(*local_tc
->dirfilter
< NUM_FILTER_MODES
)
266 talk_spell(name
, true);
273 bool check_rockboxdir(void)
275 DIR *dir
= opendir(ROCKBOX_DIR
);
277 { /* No need to localise this message.
278 If .rockbox is missing, it wouldn't work anyway */
281 screens
[i
].clear_display();
282 gui_syncsplash(HZ
*2, "No .rockbox directory");
284 screens
[i
].clear_display();
285 gui_syncsplash(HZ
*2, "Installation incomplete");
292 /* do this really late in the init sequence */
293 void tree_gui_init(void)
295 gui_sync_wps_screen_init();
299 strcpy(tc
.currdir
, "/");
301 #ifdef HAVE_LCD_CHARCELLS
304 screens
[i
].double_height(false);
307 gui_buttonbar_init(&tree_buttonbar
);
308 /* since archos only have one screen, no need to create more than that */
309 gui_buttonbar_set_display(&tree_buttonbar
, &(screens
[SCREEN_MAIN
]) );
311 gui_synclist_init(&tree_lists
, &tree_get_filename
, &tc
, false, 1);
312 gui_synclist_set_voice_callback(&tree_lists
, tree_voice_cb
);
313 gui_synclist_set_icon_callback(&tree_lists
, &tree_get_fileicon
);
314 #ifdef HAVE_LCD_COLOR
315 gui_list_set_color_callback(&tree_lists
,
316 &tree_get_filecolor
);
322 struct tree_context
* tree_get_context(void)
328 * Returns the position of a given file in the current directory
329 * returns -1 if not found
331 static int tree_get_file_position(char * filename
)
335 /* use lastfile to determine the selected item (default=0) */
336 for (i
=0; i
< tc
.filesindir
; i
++)
338 struct entry
* dc
= tc
.dircache
;
339 struct entry
* e
= &dc
[i
];
340 if (!strcasecmp(e
->name
, filename
))
343 return(-1);/* no file can match, returns undefined */
347 * Called when a new dir is loaded (for example when returning from other apps ...)
348 * also completely redraws the tree
350 static int update_dir(void)
352 bool changed
= false;
354 bool id3db
= *tc
.dirfilter
== SHOW_ID3DB
;
355 /* Checks for changes */
357 if (tc
.currtable
!= lasttable
||
358 tc
.currextra
!= lastextra
||
359 tc
.firstpos
!= lastfirstpos
||
362 if (tagtree_load(&tc
) < 0)
365 lasttable
= tc
.currtable
;
366 lastextra
= tc
.currextra
;
367 lastfirstpos
= tc
.firstpos
;
374 /* if the tc.currdir has been changed, reload it ...*/
375 if (strncmp(tc
.currdir
, lastdir
, sizeof(lastdir
)) || reload_dir
)
377 if (ft_load(&tc
, NULL
) < 0)
379 strcpy(lastdir
, tc
.currdir
);
383 /* if selected item is undefined */
384 if (tc
.selected_item
== -1)
386 /* use lastfile to determine the selected item */
387 tc
.selected_item
= tree_get_file_position(lastfile
);
389 /* If the file doesn't exists, select the first one (default) */
390 if(tc
.selected_item
< 0)
391 tc
.selected_item
= 0;
400 (tc
.dirfull
|| tc
.filesindir
== global_settings
.max_files_in_dir
) )
402 gui_syncsplash(HZ
, ID2P(LANG_SHOWDIR_BUFFER_FULL
));
408 #ifdef HAVE_LCD_BITMAP
409 if (global_settings
.show_path_in_browser
== SHOW_PATH_FULL
410 || global_settings
.show_path_in_browser
== SHOW_PATH_CURRENT
)
412 gui_synclist_set_title(&tree_lists
, tagtree_get_title(&tc
),
413 filetype_get_icon(ATTR_DIRECTORY
));
417 /* Must clear the title as the list is reused */
418 gui_synclist_set_title(&tree_lists
, NULL
, NOICON
);
425 #ifdef HAVE_LCD_BITMAP
426 if (global_settings
.show_path_in_browser
&&
427 *(tc
.dirfilter
) == SHOW_PLUGINS
)
430 if (!strcmp(tc
.currdir
, PLUGIN_GAMES_DIR
))
431 title
= str(LANG_PLUGIN_GAMES
);
432 else if (!strcmp(tc
.currdir
, PLUGIN_APPS_DIR
))
433 title
= str(LANG_PLUGIN_APPS
);
434 else if (!strcmp(tc
.currdir
, PLUGIN_DEMOS_DIR
))
435 title
= str(LANG_PLUGIN_DEMOS
);
436 else title
= str(LANG_PLUGINS
);
437 gui_synclist_set_title(&tree_lists
, title
, Icon_Plugin
);
439 else if (global_settings
.show_path_in_browser
== SHOW_PATH_FULL
)
441 gui_synclist_set_title(&tree_lists
, tc
.currdir
,
442 filetype_get_icon(ATTR_DIRECTORY
));
444 else if (global_settings
.show_path_in_browser
== SHOW_PATH_CURRENT
)
446 char *title
= strrchr(tc
.currdir
, '/') + 1;
449 /* Display "Files" for the root dir */
450 gui_synclist_set_title(&tree_lists
, str(LANG_DIR_BROWSER
),
451 filetype_get_icon(ATTR_DIRECTORY
));
454 gui_synclist_set_title(&tree_lists
, title
,
455 filetype_get_icon(ATTR_DIRECTORY
));
459 /* Must clear the title as the list is reused */
460 gui_synclist_set_title(&tree_lists
, NULL
, NOICON
);
465 gui_synclist_set_nb_items(&tree_lists
, tc
.filesindir
);
466 gui_synclist_set_icon_callback(&tree_lists
, tree_get_fileicon
);
467 if( tc
.selected_item
>= tc
.filesindir
)
468 tc
.selected_item
=tc
.filesindir
-1;
470 gui_synclist_select_item(&tree_lists
, tc
.selected_item
);
472 if (global_settings
.buttonbar
) {
473 if (*tc
.dirfilter
< NUM_FILTER_MODES
)
474 gui_buttonbar_set(&tree_buttonbar
, str(LANG_SYSFONT_DIRBROWSE_F1
),
475 str(LANG_SYSFONT_DIRBROWSE_F2
),
476 str(LANG_SYSFONT_DIRBROWSE_F3
));
478 gui_buttonbar_set(&tree_buttonbar
, "<<<", "", "");
479 gui_buttonbar_draw(&tree_buttonbar
);
482 gui_synclist_draw(&tree_lists
);
483 gui_synclist_speak_item(&tree_lists
);
484 gui_syncstatusbar_draw(&statusbars
, true);
485 return tc
.filesindir
;
488 /* load tracks from specified directory to resume play */
489 void resume_directory(const char *dir
)
492 bool id3db
= *tc
.dirfilter
== SHOW_ID3DB
;
495 if (ft_load(&tc
, dir
) < 0)
499 ft_build_playlist(&tc
, 0);
507 /* Returns the current working directory and also writes cwd to buf if
508 non-NULL. In case of error, returns NULL. */
509 char *getcwd(char *buf
, int size
)
515 strncpy(buf
, tc
.currdir
, size
);
522 /* Force a reload of the directory next time directory browser is called */
523 void reload_directory(void)
528 void get_current_file(char* buffer
, int buffer_len
)
531 /* in ID3DB mode it is a bad idea to call this function */
532 /* (only happens with `follow playlist') */
533 if( *tc
.dirfilter
== SHOW_ID3DB
)
537 struct entry
* dc
= tc
.dircache
;
538 struct entry
* e
= &dc
[tc
.selected_item
];
539 snprintf(buffer
, buffer_len
, "%s/%s", getcwd(NULL
,0),
540 tc
.dirlength
? e
->name
: "");
543 /* Allow apps to change our dirfilter directly (required for sub browsers)
544 if they're suddenly going to become a file browser for example */
545 void set_dirfilter(int l_dirfilter
)
547 *tc
.dirfilter
= l_dirfilter
;
550 /* Selects a file and update tree context properly */
551 void set_current_file(char *path
)
557 /* in ID3DB mode it is a bad idea to call this function */
558 /* (only happens with `follow playlist') */
559 if( *tc
.dirfilter
== SHOW_ID3DB
)
563 /* separate directory from filename */
564 /* gets the directory's name and put it into tc.currdir */
565 name
= strrchr(path
+1,'/');
569 strcpy(tc
.currdir
, path
);
575 strcpy(tc
.currdir
, "/");
579 strcpy(lastfile
, name
);
582 /* If we changed dir we must recalculate the dirlevel
583 and adjust the selected history properly */
584 if (strncmp(tc
.currdir
,lastdir
,sizeof(lastdir
)))
587 tc
.selected_item_history
[tc
.dirlevel
] = -1;
589 /* use '/' to calculate dirlevel */
590 for (i
= 1; path
[i
] != '\0'; i
++)
595 tc
.selected_item_history
[tc
.dirlevel
] = -1;
599 if (ft_load(&tc
, NULL
) >= 0)
601 tc
.selected_item
= tree_get_file_position(lastfile
);
606 /* main loop, handles key events */
607 static int dirbrowse()
611 unsigned button
, oldbutton
;
612 bool reload_root
= false;
613 int lastfilter
= *tc
.dirfilter
;
614 bool lastsortcase
= global_settings
.sort_case
;
615 bool exit_func
= false;
617 char* currdir
= tc
.currdir
; /* just a shortcut */
619 bool id3db
= *tc
.dirfilter
== SHOW_ID3DB
;
622 curr_context
=CONTEXT_ID3DB
;
625 curr_context
=CONTEXT_TREE
;
626 if (tc
.selected_item
< 0)
627 tc
.selected_item
= 0;
636 numentries
= update_dir();
638 if (numentries
== -1)
639 return GO_TO_PREVIOUS
; /* currdir is not a directory */
641 if (*tc
.dirfilter
> NUM_FILTER_MODES
&& numentries
==0)
643 gui_syncsplash(HZ
*2, ID2P(LANG_NO_FILES
));
644 return GO_TO_PREVIOUS
; /* No files found for rockbox_browser() */
648 struct entry
*dircache
= tc
.dircache
;
649 bool restore
= false;
651 tc
.dirlevel
= 0; /* shouldnt be needed.. this code needs work! */
654 char *lines
[]={ID2P(LANG_BOOT_CHANGED
), ID2P(LANG_REBOOT_NOW
)};
655 struct text_message message
={lines
, 2};
656 if(gui_syncyesno_run(&message
, NULL
, NULL
)==YESNO_YES
)
657 rolo_load("/" BOOTFILE
);
659 boot_changed
= false;
662 button
= get_action(CONTEXT_TREE
,
663 list_do_action_timeout(&tree_lists
, HZ
/2));
665 gui_synclist_do_button(&tree_lists
, &button
,LIST_WRAP_UNLESS_HELD
);
666 tc
.selected_item
= gui_synclist_get_sel_pos(&tree_lists
);
669 /* nothing to do if no files to display */
670 if ( numentries
== 0 )
674 switch (id3db
?tagtree_enter(&tc
):ft_enter(&tc
))
676 switch (ft_enter(&tc
))
679 case 1: reload_dir
= true; break;
680 case 2: start_wps
= true; break;
681 case 3: exit_func
= true; break;
687 case ACTION_STD_CANCEL
:
688 if (*tc
.dirfilter
> NUM_FILTER_MODES
&& tc
.dirlevel
< 1) {
692 if ((*tc
.dirfilter
== SHOW_ID3DB
&& tc
.dirlevel
== 0) ||
693 ((*tc
.dirfilter
!= SHOW_ID3DB
&& !strcmp(currdir
,"/"))))
695 #ifdef HAVE_LCD_BITMAP /* charcell doesnt have ACTION_TREE_PGLEFT so this isnt needed */
696 if (oldbutton
== ACTION_TREE_PGLEFT
)
708 if (ft_exit(&tc
) == 3)
714 case ACTION_TREE_STOP
:
715 if (list_stop_handler())
719 case ACTION_STD_MENU
:
723 #ifdef HAVE_RECORDING
725 return GO_TO_RECSCREEN
;
728 case ACTION_TREE_WPS
:
729 return GO_TO_PREVIOUS_MUSIC
;
731 #ifdef HAVE_QUICKSCREEN
732 case ACTION_STD_QUICKSCREEN
:
733 /* don't enter f2 from plugin browser */
734 if (*tc
.dirfilter
< NUM_FILTER_MODES
)
736 if (quick_screen_quick(button
))
744 /* don't enter f3 from plugin browser */
745 if (*tc
.dirfilter
< NUM_FILTER_MODES
)
747 if (quick_screen_f3(BUTTON_F3
))
754 case ACTION_STD_CONTEXT
:
760 onplay_result
= onplay(NULL
, 0, curr_context
);
765 if (tagtree_get_attr(&tc
) == FILE_ATTR_AUDIO
)
767 attr
= FILE_ATTR_AUDIO
;
768 tagtree_get_filename(&tc
, buf
, sizeof(buf
));
771 attr
= ATTR_DIRECTORY
;
776 attr
= dircache
[tc
.selected_item
].attr
;
778 if (currdir
[1]) /* Not in / */
779 snprintf(buf
, sizeof buf
, "%s/%s",
781 dircache
[tc
.selected_item
].name
);
783 snprintf(buf
, sizeof buf
, "/%s",
784 dircache
[tc
.selected_item
].name
);
786 onplay_result
= onplay(buf
, attr
, curr_context
);
788 switch (onplay_result
)
790 case ONPLAY_MAINMENU
:
797 case ONPLAY_RELOAD_DIR
:
801 case ONPLAY_START_PLAY
:
809 gui_syncstatusbar_draw(&statusbars
, false);
818 /* The 'dir no longer valid' situation will be caught later
819 * by checking the showdir() result. */
824 if (default_event_handler(button
) == SYS_USB_CONNECTED
)
826 if(*tc
.dirfilter
> NUM_FILTER_MODES
)
827 /* leave sub-browsers after usb, doing otherwise
828 might be confusing to the user */
844 /* do we need to rescan dir? */
845 if (reload_dir
|| reload_root
||
846 lastfilter
!= *tc
.dirfilter
||
847 lastsortcase
!= global_settings
.sort_case
)
850 strcpy(currdir
, "/");
863 gui_synclist_select_item(&tree_lists
, 0);
864 gui_synclist_draw(&tree_lists
);
865 tc
.selected_item
= 0;
869 lastfilter
= *tc
.dirfilter
;
870 lastsortcase
= global_settings
.sort_case
;
875 return GO_TO_PREVIOUS
;
877 if (restore
|| reload_dir
) {
878 /* restore display */
879 numentries
= update_dir();
881 if (currdir
[1] && (numentries
< 0))
882 { /* not in root and reload failed */
883 reload_root
= true; /* try root */
891 static int plsize
= 0;
893 static bool add_dir(char* dirname
, int len
, int fd
)
898 /* check for user abort */
899 if (action_userabort(TIMEOUT_NOBLOCK
))
902 dir
= opendir(dirname
);
907 struct dirent
*entry
;
909 entry
= readdir(dir
);
912 if (entry
->attribute
& ATTR_DIRECTORY
) {
913 int dirlen
= strlen(dirname
);
916 if (!strcmp((char *)entry
->d_name
, ".") ||
917 !strcmp((char *)entry
->d_name
, ".."))
921 snprintf(dirname
+dirlen
, len
-dirlen
, "/%s", entry
->d_name
);
923 snprintf(dirname
, len
, "/%s", entry
->d_name
);
925 result
= add_dir(dirname
, len
, fd
);
926 dirname
[dirlen
] = '\0';
933 int x
= strlen((char *)entry
->d_name
);
935 char *cp
= strrchr((char *)entry
->d_name
,'.');
940 /* add all supported audio files to playlists */
941 for (i
=0; i
< filetypes_count
; i
++) {
942 if (filetypes
[i
].tree_attr
== FILE_ATTR_AUDIO
) {
943 if (!strcasecmp(cp
, filetypes
[i
].extension
)) {
946 write(fd
, dirname
, strlen(dirname
));
948 write(fd
, entry
->d_name
, x
);
952 if(TIME_AFTER(current_tick
, pltick
+HZ
/4)) {
953 pltick
= current_tick
;
955 snprintf(buf
, sizeof buf
, "%d", plsize
);
956 #ifdef HAVE_LCD_BITMAP
959 screens
[i
].puts(0, 4, (unsigned char *)buf
);
960 gui_textarea_update(&screens
[i
]);
965 else if (plsize
> 99)
973 screens
[i
].puts(x
,0,buf
);
989 bool create_playlist(void)
993 char filename
[MAX_PATH
];
995 pltick
= current_tick
;
997 snprintf(filename
, sizeof filename
, "%s.m3u8",
998 tc
.currdir
[1] ? tc
.currdir
: "/root");
1001 gui_textarea_clear(&screens
[i
]);
1002 screens
[i
].puts(0, 0, str(LANG_CREATING
));
1003 screens
[i
].puts_scroll(0, 1, (unsigned char *)filename
);
1004 #if defined(HAVE_LCD_BITMAP) || defined(SIMULATOR)
1005 gui_textarea_update(&screens
[i
]);
1008 fd
= creat(filename
);
1012 trigger_cpu_boost();
1014 snprintf(filename
, sizeof(filename
), "%s",
1015 tc
.currdir
[1] ? tc
.currdir
: "/");
1017 add_dir(filename
, sizeof(filename
), fd
);
1026 int rockbox_browse(const char *root
, int dirfilter
)
1029 int *last_filter
= tc
.dirfilter
;
1030 tc
.dirfilter
= &dirfilter
;
1033 if (dirfilter
>= NUM_FILTER_MODES
)
1035 static struct tree_context backup
;
1039 tc
.selected_item
= 0;
1041 memcpy(tc
.currdir
, root
, sizeof(tc
.currdir
));
1043 last_context
= curr_context
;
1045 ret_val
= dirbrowse();
1047 curr_context
= last_context
;
1051 static char buf
[MAX_PATH
];
1052 if (dirfilter
!= SHOW_ID3DB
)
1053 tc
.dirfilter
= &global_settings
.dirfilter
;
1055 set_current_file(buf
);
1056 ret_val
= dirbrowse();
1058 tc
.dirfilter
= last_filter
;
1062 void tree_mem_init(void)
1064 /* We copy the settings value in case it is changed by the user. We can't
1065 use it until the next reboot. */
1066 max_files
= global_settings
.max_files_in_dir
;
1068 /* initialize tree context struct */
1069 memset(&tc
, 0, sizeof(tc
));
1070 tc
.dirfilter
= &global_settings
.dirfilter
;
1072 tc
.name_buffer_size
= AVERAGE_FILENAME_LENGTH
* max_files
;
1073 tc
.name_buffer
= buffer_alloc(tc
.name_buffer_size
);
1075 tc
.dircache_size
= max_files
* sizeof(struct entry
);
1076 tc
.dircache
= buffer_alloc(tc
.dircache_size
);
1077 tree_get_filetypes(&filetypes
, &filetypes_count
);
1080 void bookmark_play(char *resume_file
, int index
, int offset
, int seed
,
1084 char* suffix
= strrchr(resume_file
, '.');
1086 if (suffix
!= NULL
&&
1087 (!strcasecmp(suffix
, ".m3u") || !strcasecmp(suffix
, ".m3u8")))
1089 /* Playlist playback */
1091 /* check that the file exists */
1092 int fd
= open(resume_file
, O_RDONLY
);
1097 slash
= strrchr(resume_file
,'/');
1107 if (playlist_create(cp
, slash
+1) != -1)
1109 if (global_settings
.playlist_shuffle
)
1110 playlist_shuffle(seed
, -1);
1111 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())
1150 /* File not found, so bail out. Maybe not the best
1151 * message; perhaps "Bookmarked file not found"?
1153 gui_syncsplash(HZ
*2, ID2P(LANG_NOTHING_TO_RESUME
));
1157 playlist_start(index
,offset
);
1164 static void say_filetype(int attr
)
1166 /* try to find a voice ID for the extension, if known */
1168 attr
&= FILE_ATTR_MASK
; /* file type */
1169 for (j
=0; j
<filetypes_count
; j
++)
1170 if (attr
== filetypes
[j
].tree_attr
)
1172 talk_id(filetypes
[j
].voiceclip
, true);
1177 static int ft_play_dirname(char* name
)
1180 char dirname_mp3_filename
[MAX_PATH
+1];
1182 #if CONFIG_CODEC != SWCODEC
1183 if (audio_status() & AUDIO_STATUS_PLAY
)
1187 snprintf(dirname_mp3_filename
, sizeof(dirname_mp3_filename
), "%s/%s/%s",
1188 tc
.currdir
[1] ? tc
.currdir
: "" , name
,
1189 dir_thumbnail_name
);
1191 DEBUGF("Checking for %s\n", dirname_mp3_filename
);
1193 fd
= open(dirname_mp3_filename
, O_RDONLY
);
1196 DEBUGF("Failed to find: %s\n", dirname_mp3_filename
);
1202 DEBUGF("Found: %s\n", dirname_mp3_filename
);
1204 talk_file(dirname_mp3_filename
, false);
1205 if(global_settings
.talk_filetype
)
1206 talk_id(VOICE_DIR
, true);
1210 static void ft_play_filename(char *dir
, char *file
)
1212 char name_mp3_filename
[MAX_PATH
+1];
1214 #if CONFIG_CODEC != SWCODEC
1215 if (audio_status() & AUDIO_STATUS_PLAY
)
1219 if (strcasecmp(&file
[strlen(file
) - strlen(file_thumbnail_ext
)],
1220 file_thumbnail_ext
))
1221 { /* file has no .talk extension */
1222 snprintf(name_mp3_filename
, sizeof(name_mp3_filename
),
1223 "%s/%s%s", dir
, file
, file_thumbnail_ext
);
1225 talk_file(name_mp3_filename
, false);
1228 { /* it already is a .talk file, play this directly */
1229 snprintf(name_mp3_filename
, sizeof(name_mp3_filename
),
1230 "%s/%s", dir
, file
);
1231 talk_id(LANG_VOICE_DIR_HOVER
, false); /* prefix it */
1232 talk_file(name_mp3_filename
, true);
1236 /* These two functions are called by the USB and shutdown handlers */
1237 void tree_flush(void)
1239 scrobbler_shutdown();
1240 #ifdef HAVE_TAGCACHE
1241 tagcache_shutdown();
1243 playlist_shutdown();
1245 #ifdef HAVE_TC_RAMCACHE
1246 tagcache_unload_ramcache();
1249 #ifdef HAVE_DIRCACHE
1251 int old_val
= global_status
.dircache_size
;
1252 if (global_settings
.dircache
)
1254 if (!dircache_is_initializing())
1255 global_status
.dircache_size
= dircache_get_cache_size();
1256 # ifdef HAVE_EEPROM_SETTINGS
1257 if (firmware_settings
.initialized
)
1264 global_status
.dircache_size
= 0;
1266 if (old_val
!= global_status
.dircache_size
)
1272 void tree_restore(void)
1274 #ifdef HAVE_EEPROM_SETTINGS
1275 firmware_settings
.disk_clean
= false;
1278 #ifdef HAVE_TC_RAMCACHE
1279 remove(TAGCACHE_STATEFILE
);
1282 #ifdef HAVE_DIRCACHE
1283 remove(DIRCACHE_FILE
);
1284 if (global_settings
.dircache
)
1286 /* Print "Scanning disk..." to the display. */
1290 screens
[i
].putsxy((LCD_WIDTH
/2) -
1291 ((strlen(str(LANG_SCANNING_DISK
)) *
1292 screens
[i
].char_width
)/2),
1293 LCD_HEIGHT
-screens
[i
].char_height
*3,
1294 str(LANG_SCANNING_DISK
));
1295 gui_textarea_update(&screens
[i
]);
1297 cond_talk_ids_fq(LANG_SCANNING_DISK
);
1299 dircache_build(global_status
.dircache_size
);
1301 /* Clean the text when we are done. */
1304 gui_textarea_clear(&screens
[i
]);
1308 #ifdef HAVE_TAGCACHE
1309 tagcache_start_scan();