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"
84 static const struct filetype
*filetypes
;
85 static int filetypes_count
;
87 struct gui_synclist tree_lists
;
89 /* I put it here because other files doesn't use it yet,
90 * but should be elsewhere since it will be used mostly everywhere */
92 struct gui_buttonbar tree_buttonbar
;
94 static struct tree_context tc
;
96 bool boot_changed
= false;
98 char lastfile
[MAX_PATH
];
99 static char lastdir
[MAX_PATH
];
101 static int lasttable
, lastextra
, lastfirstpos
;
103 static int max_files
= 0;
105 static bool reload_dir
= false;
107 static bool start_wps
= false;
108 static int curr_context
= false;/* id3db or tree*/
110 static int dirbrowse(void);
111 static int ft_play_dirname(char* name
);
112 static void ft_play_filename(char *dir
, char *file
);
113 static void say_filetype(int attr
);
115 static char * tree_get_filename(int selected_item
, void *data
,
116 char *buffer
, size_t buffer_len
)
118 struct tree_context
* local_tc
=(struct tree_context
*)data
;
121 bool stripit
= false;
123 bool id3db
= *(local_tc
->dirfilter
) == SHOW_ID3DB
;
127 return tagtree_get_entry(&tc
, selected_item
)->name
;
132 struct entry
* dc
= local_tc
->dircache
;
133 struct entry
* e
= &dc
[selected_item
];
138 if(!(attr
& ATTR_DIRECTORY
))
140 switch(global_settings
.show_filename_ext
)
143 /* show file extension: off */
147 /* show file extension: on */
150 /* show file extension: only unknown types */
151 stripit
= filetype_supported(attr
);
155 /* show file extension: only when viewing all */
156 stripit
= (*(local_tc
->dirfilter
) != SHOW_ID3DB
) &&
157 (*(local_tc
->dirfilter
) != SHOW_ALL
);
164 return(strip_extension(buffer
, buffer_len
, name
));
169 #ifdef HAVE_LCD_COLOR
170 static int tree_get_filecolor(int selected_item
, void * data
)
172 if (*tc
.dirfilter
== SHOW_ID3DB
)
174 struct tree_context
* local_tc
=(struct tree_context
*)data
;
175 struct entry
* dc
= local_tc
->dircache
;
176 struct entry
* e
= &dc
[selected_item
];
177 return filetype_get_color(e
->name
, e
->attr
);
181 static int tree_get_fileicon(int selected_item
, void * data
)
183 struct tree_context
* local_tc
=(struct tree_context
*)data
;
185 bool id3db
= *(local_tc
->dirfilter
) == SHOW_ID3DB
;
187 return tagtree_get_icon(&tc
);
192 struct entry
* dc
= local_tc
->dircache
;
193 struct entry
* e
= &dc
[selected_item
];
194 return filetype_get_icon(e
->attr
);
198 static int tree_voice_cb(int selected_item
, void * data
)
200 struct tree_context
* local_tc
=(struct tree_context
*)data
;
204 bool id3db
= *(local_tc
->dirfilter
) == SHOW_ID3DB
;
208 attr
= tagtree_get_attr(local_tc
);
209 name
= tagtree_get_entry(local_tc
, selected_item
)->name
;
214 struct entry
* dc
= local_tc
->dircache
;
215 struct entry
* e
= &dc
[selected_item
];
219 bool is_dir
= (attr
& ATTR_DIRECTORY
);
220 bool did_clip
= false;
221 /* First the .talk clip case */
224 if(global_settings
.talk_dir_clip
)
226 DEBUGF("Playing directory thumbnail: %s", local_tc
->currdir
);
228 if(ft_play_dirname(name
) <0)
229 /* failed, not existing */
232 } else { /* it's a file */
233 if (global_settings
.talk_file_clip
&& (attr
& FILE_ATTR_THUMBNAIL
))
236 DEBUGF("Playing file thumbnail: %s/%s%s\n",
237 local_tc
->currdir
, name
, file_thumbnail_ext
);
238 ft_play_filename(local_tc
->currdir
, name
);
243 /* say the number or spell if required or as a fallback */
244 switch (is_dir
? global_settings
.talk_dir
: global_settings
.talk_file
)
246 case 1: /* as numbers */
247 talk_id(is_dir
? VOICE_DIR
: VOICE_FILE
, false);
248 talk_number(selected_item
+1 - (is_dir
? 0 : local_tc
->dirsindir
),
250 if(global_settings
.talk_filetype
251 && !is_dir
&& *local_tc
->dirfilter
< NUM_FILTER_MODES
)
254 case 2: /* spelled */
256 if(global_settings
.talk_filetype
)
259 talk_id(VOICE_DIR
, true);
260 else if(*local_tc
->dirfilter
< NUM_FILTER_MODES
)
263 talk_spell(name
, true);
270 bool check_rockboxdir(void)
272 if(!dir_exists(ROCKBOX_DIR
))
273 { /* No need to localise this message.
274 If .rockbox is missing, it wouldn't work anyway */
277 screens
[i
].clear_display();
278 gui_syncsplash(HZ
*2, "No .rockbox directory");
280 screens
[i
].clear_display();
281 gui_syncsplash(HZ
*2, "Installation incomplete");
287 /* do this really late in the init sequence */
288 void tree_gui_init(void)
290 gui_sync_wps_screen_init();
294 strcpy(tc
.currdir
, "/");
296 #ifdef HAVE_LCD_CHARCELLS
299 screens
[i
].double_height(false);
302 gui_buttonbar_init(&tree_buttonbar
);
303 /* since archos only have one screen, no need to create more than that */
304 gui_buttonbar_set_display(&tree_buttonbar
, &(screens
[SCREEN_MAIN
]) );
306 gui_synclist_init(&tree_lists
, &tree_get_filename
, &tc
, false, 1, NULL
);
307 gui_synclist_set_voice_callback(&tree_lists
, tree_voice_cb
);
308 gui_synclist_set_icon_callback(&tree_lists
, &tree_get_fileicon
);
309 #ifdef HAVE_LCD_COLOR
310 gui_synclist_set_color_callback(&tree_lists
, &tree_get_filecolor
);
316 struct tree_context
* tree_get_context(void)
322 * Returns the position of a given file in the current directory
323 * returns -1 if not found
325 static int tree_get_file_position(char * filename
)
329 /* use lastfile to determine the selected item (default=0) */
330 for (i
=0; i
< tc
.filesindir
; i
++)
332 struct entry
* dc
= tc
.dircache
;
333 struct entry
* e
= &dc
[i
];
334 if (!strcasecmp(e
->name
, filename
))
337 return(-1);/* no file can match, returns undefined */
341 * Called when a new dir is loaded (for example when returning from other apps ...)
342 * also completely redraws the tree
344 static int update_dir(void)
346 bool changed
= false;
348 bool id3db
= *tc
.dirfilter
== SHOW_ID3DB
;
349 /* Checks for changes */
351 if (tc
.currtable
!= lasttable
||
352 tc
.currextra
!= lastextra
||
353 tc
.firstpos
!= lastfirstpos
||
356 if (tagtree_load(&tc
) < 0)
359 lasttable
= tc
.currtable
;
360 lastextra
= tc
.currextra
;
361 lastfirstpos
= tc
.firstpos
;
368 /* if the tc.currdir has been changed, reload it ...*/
369 if (strncmp(tc
.currdir
, lastdir
, sizeof(lastdir
)) || reload_dir
)
371 if (ft_load(&tc
, NULL
) < 0)
373 strcpy(lastdir
, tc
.currdir
);
377 /* if selected item is undefined */
378 if (tc
.selected_item
== -1)
380 /* use lastfile to determine the selected item */
381 tc
.selected_item
= tree_get_file_position(lastfile
);
383 /* If the file doesn't exists, select the first one (default) */
384 if(tc
.selected_item
< 0)
385 tc
.selected_item
= 0;
394 (tc
.dirfull
|| tc
.filesindir
== global_settings
.max_files_in_dir
) )
396 gui_syncsplash(HZ
, ID2P(LANG_SHOWDIR_BUFFER_FULL
));
402 #ifdef HAVE_LCD_BITMAP
403 if (global_settings
.show_path_in_browser
== SHOW_PATH_FULL
404 || global_settings
.show_path_in_browser
== SHOW_PATH_CURRENT
)
406 gui_synclist_set_title(&tree_lists
, tagtree_get_title(&tc
),
407 filetype_get_icon(ATTR_DIRECTORY
));
411 /* Must clear the title as the list is reused */
412 gui_synclist_set_title(&tree_lists
, NULL
, NOICON
);
419 #ifdef HAVE_LCD_BITMAP
420 if (global_settings
.show_path_in_browser
&&
421 *(tc
.dirfilter
) == SHOW_PLUGINS
)
424 if (!strcmp(tc
.currdir
, PLUGIN_GAMES_DIR
))
425 title
= str(LANG_PLUGIN_GAMES
);
426 else if (!strcmp(tc
.currdir
, PLUGIN_APPS_DIR
))
427 title
= str(LANG_PLUGIN_APPS
);
428 else if (!strcmp(tc
.currdir
, PLUGIN_DEMOS_DIR
))
429 title
= str(LANG_PLUGIN_DEMOS
);
430 else title
= str(LANG_PLUGINS
);
431 gui_synclist_set_title(&tree_lists
, title
, Icon_Plugin
);
433 else if (global_settings
.show_path_in_browser
== SHOW_PATH_FULL
)
435 gui_synclist_set_title(&tree_lists
, tc
.currdir
,
436 filetype_get_icon(ATTR_DIRECTORY
));
438 else if (global_settings
.show_path_in_browser
== SHOW_PATH_CURRENT
)
440 char *title
= strrchr(tc
.currdir
, '/') + 1;
443 /* Display "Files" for the root dir */
444 gui_synclist_set_title(&tree_lists
, str(LANG_DIR_BROWSER
),
445 filetype_get_icon(ATTR_DIRECTORY
));
448 gui_synclist_set_title(&tree_lists
, title
,
449 filetype_get_icon(ATTR_DIRECTORY
));
453 /* Must clear the title as the list is reused */
454 gui_synclist_set_title(&tree_lists
, NULL
, NOICON
);
459 gui_synclist_set_nb_items(&tree_lists
, tc
.filesindir
);
460 gui_synclist_set_icon_callback(&tree_lists
, tree_get_fileicon
);
461 if( tc
.selected_item
>= tc
.filesindir
)
462 tc
.selected_item
=tc
.filesindir
-1;
464 gui_synclist_select_item(&tree_lists
, tc
.selected_item
);
466 if (global_settings
.buttonbar
) {
467 if (*tc
.dirfilter
< NUM_FILTER_MODES
)
468 gui_buttonbar_set(&tree_buttonbar
, str(LANG_SYSFONT_DIRBROWSE_F1
),
469 str(LANG_SYSFONT_DIRBROWSE_F2
),
470 str(LANG_SYSFONT_DIRBROWSE_F3
));
472 gui_buttonbar_set(&tree_buttonbar
, "<<<", "", "");
473 gui_buttonbar_draw(&tree_buttonbar
);
476 gui_synclist_draw(&tree_lists
);
477 gui_synclist_speak_item(&tree_lists
);
478 gui_syncstatusbar_draw(&statusbars
, true);
479 return tc
.filesindir
;
482 /* load tracks from specified directory to resume play */
483 void resume_directory(const char *dir
)
486 bool id3db
= *tc
.dirfilter
== SHOW_ID3DB
;
489 if (ft_load(&tc
, dir
) < 0)
493 ft_build_playlist(&tc
, 0);
501 /* Returns the current working directory and also writes cwd to buf if
502 non-NULL. In case of error, returns NULL. */
503 char *getcwd(char *buf
, int size
)
509 strncpy(buf
, tc
.currdir
, size
);
516 /* Force a reload of the directory next time directory browser is called */
517 void reload_directory(void)
522 void get_current_file(char* buffer
, int buffer_len
)
525 /* in ID3DB mode it is a bad idea to call this function */
526 /* (only happens with `follow playlist') */
527 if( *tc
.dirfilter
== SHOW_ID3DB
)
531 struct entry
* dc
= tc
.dircache
;
532 struct entry
* e
= &dc
[tc
.selected_item
];
533 snprintf(buffer
, buffer_len
, "%s/%s", getcwd(NULL
,0),
534 tc
.dirlength
? e
->name
: "");
537 /* Allow apps to change our dirfilter directly (required for sub browsers)
538 if they're suddenly going to become a file browser for example */
539 void set_dirfilter(int l_dirfilter
)
541 *tc
.dirfilter
= l_dirfilter
;
544 /* Selects a file and update tree context properly */
545 void set_current_file(char *path
)
551 /* in ID3DB mode it is a bad idea to call this function */
552 /* (only happens with `follow playlist') */
553 if( *tc
.dirfilter
== SHOW_ID3DB
)
557 /* separate directory from filename */
558 /* gets the directory's name and put it into tc.currdir */
559 name
= strrchr(path
+1,'/');
563 strcpy(tc
.currdir
, path
);
569 strcpy(tc
.currdir
, "/");
573 strcpy(lastfile
, name
);
576 /* If we changed dir we must recalculate the dirlevel
577 and adjust the selected history properly */
578 if (strncmp(tc
.currdir
,lastdir
,sizeof(lastdir
)))
581 tc
.selected_item_history
[tc
.dirlevel
] = -1;
583 /* use '/' to calculate dirlevel */
584 for (i
= 1; path
[i
] != '\0'; i
++)
589 tc
.selected_item_history
[tc
.dirlevel
] = -1;
593 if (ft_load(&tc
, NULL
) >= 0)
595 tc
.selected_item
= tree_get_file_position(lastfile
);
600 /* main loop, handles key events */
601 static int dirbrowse()
605 unsigned button
, oldbutton
;
606 bool reload_root
= false;
607 int lastfilter
= *tc
.dirfilter
;
608 bool lastsortcase
= global_settings
.sort_case
;
609 bool exit_func
= false;
611 char* currdir
= tc
.currdir
; /* just a shortcut */
613 bool id3db
= *tc
.dirfilter
== SHOW_ID3DB
;
616 curr_context
=CONTEXT_ID3DB
;
619 curr_context
=CONTEXT_TREE
;
620 if (tc
.selected_item
< 0)
621 tc
.selected_item
= 0;
630 numentries
= update_dir();
632 if (numentries
== -1)
633 return GO_TO_PREVIOUS
; /* currdir is not a directory */
635 if (*tc
.dirfilter
> NUM_FILTER_MODES
&& numentries
==0)
637 gui_syncsplash(HZ
*2, ID2P(LANG_NO_FILES
));
638 return GO_TO_PREVIOUS
; /* No files found for rockbox_browser() */
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
:
803 gui_syncstatusbar_draw(&statusbars
, false);
812 /* The 'dir no longer valid' situation will be caught later
813 * by checking the showdir() result. */
818 if (default_event_handler(button
) == SYS_USB_CONNECTED
)
820 if(*tc
.dirfilter
> NUM_FILTER_MODES
)
821 /* leave sub-browsers after usb, doing otherwise
822 might be confusing to the user */
838 /* do we need to rescan dir? */
839 if (reload_dir
|| reload_root
||
840 lastfilter
!= *tc
.dirfilter
||
841 lastsortcase
!= global_settings
.sort_case
)
844 strcpy(currdir
, "/");
857 gui_synclist_select_item(&tree_lists
, 0);
858 gui_synclist_draw(&tree_lists
);
859 tc
.selected_item
= 0;
863 lastfilter
= *tc
.dirfilter
;
864 lastsortcase
= global_settings
.sort_case
;
869 return GO_TO_PREVIOUS
;
871 if (restore
|| reload_dir
) {
872 /* restore display */
873 numentries
= update_dir();
875 if (currdir
[1] && (numentries
< 0))
876 { /* not in root and reload failed */
877 reload_root
= true; /* try root */
885 static int plsize
= 0;
887 static bool add_dir(char* dirname
, int len
, int fd
)
892 /* check for user abort */
893 if (action_userabort(TIMEOUT_NOBLOCK
))
896 dir
= opendir(dirname
);
901 struct dirent
*entry
;
903 entry
= readdir(dir
);
906 if (entry
->attribute
& ATTR_DIRECTORY
) {
907 int dirlen
= strlen(dirname
);
910 if (!strcmp((char *)entry
->d_name
, ".") ||
911 !strcmp((char *)entry
->d_name
, ".."))
915 snprintf(dirname
+dirlen
, len
-dirlen
, "/%s", entry
->d_name
);
917 snprintf(dirname
, len
, "/%s", entry
->d_name
);
919 result
= add_dir(dirname
, len
, fd
);
920 dirname
[dirlen
] = '\0';
927 int x
= strlen((char *)entry
->d_name
);
929 char *cp
= strrchr((char *)entry
->d_name
,'.');
934 /* add all supported audio files to playlists */
935 for (i
=0; i
< filetypes_count
; i
++) {
936 if (filetypes
[i
].tree_attr
== FILE_ATTR_AUDIO
) {
937 if (!strcasecmp(cp
, filetypes
[i
].extension
)) {
940 write(fd
, dirname
, strlen(dirname
));
942 write(fd
, entry
->d_name
, x
);
946 if(TIME_AFTER(current_tick
, pltick
+HZ
/4)) {
947 pltick
= current_tick
;
949 snprintf(buf
, sizeof buf
, "%d", plsize
);
950 #ifdef HAVE_LCD_BITMAP
953 screens
[i
].puts(0, 4, (unsigned char *)buf
);
954 gui_textarea_update(&screens
[i
]);
959 else if (plsize
> 99)
967 screens
[i
].puts(x
,0,buf
);
983 bool create_playlist(void)
987 char filename
[MAX_PATH
];
989 pltick
= current_tick
;
991 snprintf(filename
, sizeof filename
, "%s.m3u8",
992 tc
.currdir
[1] ? tc
.currdir
: "/root");
995 gui_textarea_clear(&screens
[i
]);
996 screens
[i
].puts(0, 0, str(LANG_CREATING
));
997 screens
[i
].puts_scroll(0, 1, (unsigned char *)filename
);
998 #if defined(HAVE_LCD_BITMAP) || defined(SIMULATOR)
999 gui_textarea_update(&screens
[i
]);
1002 fd
= creat(filename
);
1006 trigger_cpu_boost();
1008 snprintf(filename
, sizeof(filename
), "%s",
1009 tc
.currdir
[1] ? tc
.currdir
: "/");
1011 add_dir(filename
, sizeof(filename
), fd
);
1020 int rockbox_browse(const char *root
, int dirfilter
)
1023 int *last_filter
= tc
.dirfilter
;
1024 tc
.dirfilter
= &dirfilter
;
1027 if (dirfilter
>= NUM_FILTER_MODES
)
1029 static struct tree_context backup
;
1033 tc
.selected_item
= 0;
1035 memcpy(tc
.currdir
, root
, sizeof(tc
.currdir
));
1037 last_context
= curr_context
;
1039 ret_val
= dirbrowse();
1041 curr_context
= last_context
;
1045 static char buf
[MAX_PATH
];
1046 if (dirfilter
!= SHOW_ID3DB
)
1047 tc
.dirfilter
= &global_settings
.dirfilter
;
1049 set_current_file(buf
);
1050 ret_val
= dirbrowse();
1052 tc
.dirfilter
= last_filter
;
1056 void tree_mem_init(void)
1058 /* We copy the settings value in case it is changed by the user. We can't
1059 use it until the next reboot. */
1060 max_files
= global_settings
.max_files_in_dir
;
1062 /* initialize tree context struct */
1063 memset(&tc
, 0, sizeof(tc
));
1064 tc
.dirfilter
= &global_settings
.dirfilter
;
1066 tc
.name_buffer_size
= AVERAGE_FILENAME_LENGTH
* max_files
;
1067 tc
.name_buffer
= buffer_alloc(tc
.name_buffer_size
);
1069 tc
.dircache_size
= max_files
* sizeof(struct entry
);
1070 tc
.dircache
= buffer_alloc(tc
.dircache_size
);
1071 tree_get_filetypes(&filetypes
, &filetypes_count
);
1074 bool bookmark_play(char *resume_file
, int index
, int offset
, int seed
,
1078 char* suffix
= strrchr(resume_file
, '.');
1079 bool started
= false;
1081 if (suffix
!= NULL
&&
1082 (!strcasecmp(suffix
, ".m3u") || !strcasecmp(suffix
, ".m3u8")))
1084 /* Playlist playback */
1086 /* check that the file exists */
1087 if(!file_exists(resume_file
))
1090 slash
= strrchr(resume_file
,'/');
1100 if (playlist_create(cp
, slash
+1) != -1)
1102 if (global_settings
.playlist_shuffle
)
1103 playlist_shuffle(seed
, -1);
1104 playlist_start(index
,offset
);
1112 /* Directory playback */
1114 if (playlist_create(resume_file
, NULL
) != -1)
1116 char* peek_filename
;
1117 resume_directory(resume_file
);
1118 if (global_settings
.playlist_shuffle
)
1119 playlist_shuffle(seed
, -1);
1121 /* Check if the file is at the same spot in the directory,
1122 else search for it */
1123 peek_filename
= playlist_peek(index
);
1125 if (peek_filename
== NULL
)
1128 if (strcmp(strrchr(peek_filename
, '/') + 1, filename
))
1130 for ( i
=0; i
< playlist_amount(); i
++ )
1132 peek_filename
= playlist_peek(i
);
1134 if (peek_filename
== NULL
)
1137 if (!strcmp(strrchr(peek_filename
, '/') + 1, filename
))
1140 if (i
< playlist_amount())
1145 playlist_start(index
,offset
);
1155 static void say_filetype(int attr
)
1157 /* try to find a voice ID for the extension, if known */
1159 attr
&= FILE_ATTR_MASK
; /* file type */
1160 for (j
=0; j
<filetypes_count
; j
++)
1161 if (attr
== filetypes
[j
].tree_attr
)
1163 talk_id(filetypes
[j
].voiceclip
, true);
1168 static int ft_play_dirname(char* name
)
1170 char dirname_mp3_filename
[MAX_PATH
+1];
1172 #if CONFIG_CODEC != SWCODEC
1173 if (audio_status() & AUDIO_STATUS_PLAY
)
1177 snprintf(dirname_mp3_filename
, sizeof(dirname_mp3_filename
), "%s/%s/%s",
1178 tc
.currdir
[1] ? tc
.currdir
: "" , name
,
1179 dir_thumbnail_name
);
1181 DEBUGF("Checking for %s\n", dirname_mp3_filename
);
1183 if (!file_exists(dirname_mp3_filename
))
1185 DEBUGF("Failed to find: %s\n", dirname_mp3_filename
);
1189 DEBUGF("Found: %s\n", dirname_mp3_filename
);
1191 talk_file(dirname_mp3_filename
, false);
1192 if(global_settings
.talk_filetype
)
1193 talk_id(VOICE_DIR
, true);
1197 static void ft_play_filename(char *dir
, char *file
)
1199 char name_mp3_filename
[MAX_PATH
+1];
1201 #if CONFIG_CODEC != SWCODEC
1202 if (audio_status() & AUDIO_STATUS_PLAY
)
1206 if (strcasecmp(&file
[strlen(file
) - strlen(file_thumbnail_ext
)],
1207 file_thumbnail_ext
))
1208 { /* file has no .talk extension */
1209 snprintf(name_mp3_filename
, sizeof(name_mp3_filename
),
1210 "%s/%s%s", dir
, file
, file_thumbnail_ext
);
1212 talk_file(name_mp3_filename
, false);
1215 { /* it already is a .talk file, play this directly */
1216 snprintf(name_mp3_filename
, sizeof(name_mp3_filename
),
1217 "%s/%s", dir
, file
);
1218 talk_id(LANG_VOICE_DIR_HOVER
, false); /* prefix it */
1219 talk_file(name_mp3_filename
, true);
1223 /* These two functions are called by the USB and shutdown handlers */
1224 void tree_flush(void)
1226 scrobbler_shutdown();
1227 #ifdef HAVE_TAGCACHE
1228 tagcache_shutdown();
1230 playlist_shutdown();
1232 #ifdef HAVE_TC_RAMCACHE
1233 tagcache_unload_ramcache();
1236 #ifdef HAVE_DIRCACHE
1238 int old_val
= global_status
.dircache_size
;
1239 if (global_settings
.dircache
)
1241 if (!dircache_is_initializing())
1242 global_status
.dircache_size
= dircache_get_cache_size();
1243 # ifdef HAVE_EEPROM_SETTINGS
1244 if (firmware_settings
.initialized
)
1251 global_status
.dircache_size
= 0;
1253 if (old_val
!= global_status
.dircache_size
)
1259 void tree_restore(void)
1261 #ifdef HAVE_EEPROM_SETTINGS
1262 firmware_settings
.disk_clean
= false;
1265 #ifdef HAVE_TC_RAMCACHE
1266 remove(TAGCACHE_STATEFILE
);
1269 #ifdef HAVE_DIRCACHE
1270 remove(DIRCACHE_FILE
);
1271 if (global_settings
.dircache
)
1273 /* Print "Scanning disk..." to the display. */
1277 screens
[i
].putsxy((LCD_WIDTH
/2) -
1278 ((strlen(str(LANG_SCANNING_DISK
)) *
1279 screens
[i
].char_width
)/2),
1280 LCD_HEIGHT
-screens
[i
].char_height
*3,
1281 str(LANG_SCANNING_DISK
));
1282 gui_textarea_update(&screens
[i
]);
1284 cond_talk_ids_fq(LANG_SCANNING_DISK
);
1286 dircache_build(global_status
.dircache_size
);
1288 /* Clean the text when we are done. */
1291 gui_textarea_clear(&screens
[i
]);
1295 #ifdef HAVE_TAGCACHE
1296 tagcache_start_scan();