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 DIR *dir
= opendir(ROCKBOX_DIR
);
274 { /* No need to localise this message.
275 If .rockbox is missing, it wouldn't work anyway */
278 screens
[i
].clear_display();
279 gui_syncsplash(HZ
*2, "No .rockbox directory");
281 screens
[i
].clear_display();
282 gui_syncsplash(HZ
*2, "Installation incomplete");
289 /* do this really late in the init sequence */
290 void tree_gui_init(void)
292 gui_sync_wps_screen_init();
296 strcpy(tc
.currdir
, "/");
298 #ifdef HAVE_LCD_CHARCELLS
301 screens
[i
].double_height(false);
304 gui_buttonbar_init(&tree_buttonbar
);
305 /* since archos only have one screen, no need to create more than that */
306 gui_buttonbar_set_display(&tree_buttonbar
, &(screens
[SCREEN_MAIN
]) );
308 gui_synclist_init(&tree_lists
, &tree_get_filename
, &tc
, false, 1, NULL
);
309 gui_synclist_set_voice_callback(&tree_lists
, tree_voice_cb
);
310 gui_synclist_set_icon_callback(&tree_lists
, &tree_get_fileicon
);
311 #ifdef HAVE_LCD_COLOR
312 gui_synclist_set_color_callback(&tree_lists
, &tree_get_filecolor
);
318 struct tree_context
* tree_get_context(void)
324 * Returns the position of a given file in the current directory
325 * returns -1 if not found
327 static int tree_get_file_position(char * filename
)
331 /* use lastfile to determine the selected item (default=0) */
332 for (i
=0; i
< tc
.filesindir
; i
++)
334 struct entry
* dc
= tc
.dircache
;
335 struct entry
* e
= &dc
[i
];
336 if (!strcasecmp(e
->name
, filename
))
339 return(-1);/* no file can match, returns undefined */
343 * Called when a new dir is loaded (for example when returning from other apps ...)
344 * also completely redraws the tree
346 static int update_dir(void)
348 bool changed
= false;
350 bool id3db
= *tc
.dirfilter
== SHOW_ID3DB
;
351 /* Checks for changes */
353 if (tc
.currtable
!= lasttable
||
354 tc
.currextra
!= lastextra
||
355 tc
.firstpos
!= lastfirstpos
||
358 if (tagtree_load(&tc
) < 0)
361 lasttable
= tc
.currtable
;
362 lastextra
= tc
.currextra
;
363 lastfirstpos
= tc
.firstpos
;
370 /* if the tc.currdir has been changed, reload it ...*/
371 if (strncmp(tc
.currdir
, lastdir
, sizeof(lastdir
)) || reload_dir
)
373 if (ft_load(&tc
, NULL
) < 0)
375 strcpy(lastdir
, tc
.currdir
);
379 /* if selected item is undefined */
380 if (tc
.selected_item
== -1)
382 /* use lastfile to determine the selected item */
383 tc
.selected_item
= tree_get_file_position(lastfile
);
385 /* If the file doesn't exists, select the first one (default) */
386 if(tc
.selected_item
< 0)
387 tc
.selected_item
= 0;
396 (tc
.dirfull
|| tc
.filesindir
== global_settings
.max_files_in_dir
) )
398 gui_syncsplash(HZ
, ID2P(LANG_SHOWDIR_BUFFER_FULL
));
404 #ifdef HAVE_LCD_BITMAP
405 if (global_settings
.show_path_in_browser
== SHOW_PATH_FULL
406 || global_settings
.show_path_in_browser
== SHOW_PATH_CURRENT
)
408 gui_synclist_set_title(&tree_lists
, tagtree_get_title(&tc
),
409 filetype_get_icon(ATTR_DIRECTORY
));
413 /* Must clear the title as the list is reused */
414 gui_synclist_set_title(&tree_lists
, NULL
, NOICON
);
421 #ifdef HAVE_LCD_BITMAP
422 if (global_settings
.show_path_in_browser
&&
423 *(tc
.dirfilter
) == SHOW_PLUGINS
)
426 if (!strcmp(tc
.currdir
, PLUGIN_GAMES_DIR
))
427 title
= str(LANG_PLUGIN_GAMES
);
428 else if (!strcmp(tc
.currdir
, PLUGIN_APPS_DIR
))
429 title
= str(LANG_PLUGIN_APPS
);
430 else if (!strcmp(tc
.currdir
, PLUGIN_DEMOS_DIR
))
431 title
= str(LANG_PLUGIN_DEMOS
);
432 else title
= str(LANG_PLUGINS
);
433 gui_synclist_set_title(&tree_lists
, title
, Icon_Plugin
);
435 else if (global_settings
.show_path_in_browser
== SHOW_PATH_FULL
)
437 gui_synclist_set_title(&tree_lists
, tc
.currdir
,
438 filetype_get_icon(ATTR_DIRECTORY
));
440 else if (global_settings
.show_path_in_browser
== SHOW_PATH_CURRENT
)
442 char *title
= strrchr(tc
.currdir
, '/') + 1;
445 /* Display "Files" for the root dir */
446 gui_synclist_set_title(&tree_lists
, str(LANG_DIR_BROWSER
),
447 filetype_get_icon(ATTR_DIRECTORY
));
450 gui_synclist_set_title(&tree_lists
, title
,
451 filetype_get_icon(ATTR_DIRECTORY
));
455 /* Must clear the title as the list is reused */
456 gui_synclist_set_title(&tree_lists
, NULL
, NOICON
);
461 gui_synclist_set_nb_items(&tree_lists
, tc
.filesindir
);
462 gui_synclist_set_icon_callback(&tree_lists
, tree_get_fileicon
);
463 if( tc
.selected_item
>= tc
.filesindir
)
464 tc
.selected_item
=tc
.filesindir
-1;
466 gui_synclist_select_item(&tree_lists
, tc
.selected_item
);
468 if (global_settings
.buttonbar
) {
469 if (*tc
.dirfilter
< NUM_FILTER_MODES
)
470 gui_buttonbar_set(&tree_buttonbar
, str(LANG_SYSFONT_DIRBROWSE_F1
),
471 str(LANG_SYSFONT_DIRBROWSE_F2
),
472 str(LANG_SYSFONT_DIRBROWSE_F3
));
474 gui_buttonbar_set(&tree_buttonbar
, "<<<", "", "");
475 gui_buttonbar_draw(&tree_buttonbar
);
478 gui_synclist_draw(&tree_lists
);
479 gui_synclist_speak_item(&tree_lists
);
480 gui_syncstatusbar_draw(&statusbars
, true);
481 return tc
.filesindir
;
484 /* load tracks from specified directory to resume play */
485 void resume_directory(const char *dir
)
488 bool id3db
= *tc
.dirfilter
== SHOW_ID3DB
;
491 if (ft_load(&tc
, dir
) < 0)
495 ft_build_playlist(&tc
, 0);
503 /* Returns the current working directory and also writes cwd to buf if
504 non-NULL. In case of error, returns NULL. */
505 char *getcwd(char *buf
, int size
)
511 strncpy(buf
, tc
.currdir
, size
);
518 /* Force a reload of the directory next time directory browser is called */
519 void reload_directory(void)
524 void get_current_file(char* buffer
, int buffer_len
)
527 /* in ID3DB mode it is a bad idea to call this function */
528 /* (only happens with `follow playlist') */
529 if( *tc
.dirfilter
== SHOW_ID3DB
)
533 struct entry
* dc
= tc
.dircache
;
534 struct entry
* e
= &dc
[tc
.selected_item
];
535 snprintf(buffer
, buffer_len
, "%s/%s", getcwd(NULL
,0),
536 tc
.dirlength
? e
->name
: "");
539 /* Allow apps to change our dirfilter directly (required for sub browsers)
540 if they're suddenly going to become a file browser for example */
541 void set_dirfilter(int l_dirfilter
)
543 *tc
.dirfilter
= l_dirfilter
;
546 /* Selects a file and update tree context properly */
547 void set_current_file(char *path
)
553 /* in ID3DB mode it is a bad idea to call this function */
554 /* (only happens with `follow playlist') */
555 if( *tc
.dirfilter
== SHOW_ID3DB
)
559 /* separate directory from filename */
560 /* gets the directory's name and put it into tc.currdir */
561 name
= strrchr(path
+1,'/');
565 strcpy(tc
.currdir
, path
);
571 strcpy(tc
.currdir
, "/");
575 strcpy(lastfile
, name
);
578 /* If we changed dir we must recalculate the dirlevel
579 and adjust the selected history properly */
580 if (strncmp(tc
.currdir
,lastdir
,sizeof(lastdir
)))
583 tc
.selected_item_history
[tc
.dirlevel
] = -1;
585 /* use '/' to calculate dirlevel */
586 for (i
= 1; path
[i
] != '\0'; i
++)
591 tc
.selected_item_history
[tc
.dirlevel
] = -1;
595 if (ft_load(&tc
, NULL
) >= 0)
597 tc
.selected_item
= tree_get_file_position(lastfile
);
602 /* main loop, handles key events */
603 static int dirbrowse()
607 unsigned button
, oldbutton
;
608 bool reload_root
= false;
609 int lastfilter
= *tc
.dirfilter
;
610 bool lastsortcase
= global_settings
.sort_case
;
611 bool exit_func
= false;
613 char* currdir
= tc
.currdir
; /* just a shortcut */
615 bool id3db
= *tc
.dirfilter
== SHOW_ID3DB
;
618 curr_context
=CONTEXT_ID3DB
;
621 curr_context
=CONTEXT_TREE
;
622 if (tc
.selected_item
< 0)
623 tc
.selected_item
= 0;
632 numentries
= update_dir();
634 if (numentries
== -1)
635 return GO_TO_PREVIOUS
; /* currdir is not a directory */
637 if (*tc
.dirfilter
> NUM_FILTER_MODES
&& numentries
==0)
639 gui_syncsplash(HZ
*2, ID2P(LANG_NO_FILES
));
640 return GO_TO_PREVIOUS
; /* No files found for rockbox_browser() */
644 struct entry
*dircache
= tc
.dircache
;
645 bool restore
= false;
647 tc
.dirlevel
= 0; /* shouldnt be needed.. this code needs work! */
650 char *lines
[]={ID2P(LANG_BOOT_CHANGED
), ID2P(LANG_REBOOT_NOW
)};
651 struct text_message message
={lines
, 2};
652 if(gui_syncyesno_run(&message
, NULL
, NULL
)==YESNO_YES
)
653 rolo_load("/" BOOTFILE
);
655 boot_changed
= false;
658 button
= get_action(CONTEXT_TREE
,
659 list_do_action_timeout(&tree_lists
, HZ
/2));
661 gui_synclist_do_button(&tree_lists
, &button
,LIST_WRAP_UNLESS_HELD
);
662 tc
.selected_item
= gui_synclist_get_sel_pos(&tree_lists
);
665 /* nothing to do if no files to display */
666 if ( numentries
== 0 )
670 switch (id3db
?tagtree_enter(&tc
):ft_enter(&tc
))
672 switch (ft_enter(&tc
))
675 case 1: reload_dir
= true; break;
676 case 2: start_wps
= true; break;
677 case 3: exit_func
= true; break;
683 case ACTION_STD_CANCEL
:
684 if (*tc
.dirfilter
> NUM_FILTER_MODES
&& tc
.dirlevel
< 1) {
688 if ((*tc
.dirfilter
== SHOW_ID3DB
&& tc
.dirlevel
== 0) ||
689 ((*tc
.dirfilter
!= SHOW_ID3DB
&& !strcmp(currdir
,"/"))))
691 #ifdef HAVE_LCD_BITMAP /* charcell doesnt have ACTION_TREE_PGLEFT so this isnt needed */
692 if (oldbutton
== ACTION_TREE_PGLEFT
)
704 if (ft_exit(&tc
) == 3)
710 case ACTION_TREE_STOP
:
711 if (list_stop_handler())
715 case ACTION_STD_MENU
:
719 #ifdef HAVE_RECORDING
721 return GO_TO_RECSCREEN
;
724 case ACTION_TREE_WPS
:
725 return GO_TO_PREVIOUS_MUSIC
;
727 #ifdef HAVE_QUICKSCREEN
728 case ACTION_STD_QUICKSCREEN
:
729 /* don't enter f2 from plugin browser */
730 if (*tc
.dirfilter
< NUM_FILTER_MODES
)
732 if (quick_screen_quick(button
))
740 /* don't enter f3 from plugin browser */
741 if (*tc
.dirfilter
< NUM_FILTER_MODES
)
743 if (quick_screen_f3(ACTION_F3
))
750 case ACTION_STD_CONTEXT
:
756 onplay_result
= onplay(NULL
, 0, curr_context
);
761 if (tagtree_get_attr(&tc
) == FILE_ATTR_AUDIO
)
763 attr
= FILE_ATTR_AUDIO
;
764 tagtree_get_filename(&tc
, buf
, sizeof(buf
));
767 attr
= ATTR_DIRECTORY
;
772 attr
= dircache
[tc
.selected_item
].attr
;
774 if (currdir
[1]) /* Not in / */
775 snprintf(buf
, sizeof buf
, "%s/%s",
777 dircache
[tc
.selected_item
].name
);
779 snprintf(buf
, sizeof buf
, "/%s",
780 dircache
[tc
.selected_item
].name
);
782 onplay_result
= onplay(buf
, attr
, curr_context
);
784 switch (onplay_result
)
786 case ONPLAY_MAINMENU
:
793 case ONPLAY_RELOAD_DIR
:
797 case ONPLAY_START_PLAY
:
805 gui_syncstatusbar_draw(&statusbars
, false);
814 /* The 'dir no longer valid' situation will be caught later
815 * by checking the showdir() result. */
820 if (default_event_handler(button
) == SYS_USB_CONNECTED
)
822 if(*tc
.dirfilter
> NUM_FILTER_MODES
)
823 /* leave sub-browsers after usb, doing otherwise
824 might be confusing to the user */
840 /* do we need to rescan dir? */
841 if (reload_dir
|| reload_root
||
842 lastfilter
!= *tc
.dirfilter
||
843 lastsortcase
!= global_settings
.sort_case
)
846 strcpy(currdir
, "/");
859 gui_synclist_select_item(&tree_lists
, 0);
860 gui_synclist_draw(&tree_lists
);
861 tc
.selected_item
= 0;
865 lastfilter
= *tc
.dirfilter
;
866 lastsortcase
= global_settings
.sort_case
;
871 return GO_TO_PREVIOUS
;
873 if (restore
|| reload_dir
) {
874 /* restore display */
875 numentries
= update_dir();
877 if (currdir
[1] && (numentries
< 0))
878 { /* not in root and reload failed */
879 reload_root
= true; /* try root */
887 static int plsize
= 0;
889 static bool add_dir(char* dirname
, int len
, int fd
)
894 /* check for user abort */
895 if (action_userabort(TIMEOUT_NOBLOCK
))
898 dir
= opendir(dirname
);
903 struct dirent
*entry
;
905 entry
= readdir(dir
);
908 if (entry
->attribute
& ATTR_DIRECTORY
) {
909 int dirlen
= strlen(dirname
);
912 if (!strcmp((char *)entry
->d_name
, ".") ||
913 !strcmp((char *)entry
->d_name
, ".."))
917 snprintf(dirname
+dirlen
, len
-dirlen
, "/%s", entry
->d_name
);
919 snprintf(dirname
, len
, "/%s", entry
->d_name
);
921 result
= add_dir(dirname
, len
, fd
);
922 dirname
[dirlen
] = '\0';
929 int x
= strlen((char *)entry
->d_name
);
931 char *cp
= strrchr((char *)entry
->d_name
,'.');
936 /* add all supported audio files to playlists */
937 for (i
=0; i
< filetypes_count
; i
++) {
938 if (filetypes
[i
].tree_attr
== FILE_ATTR_AUDIO
) {
939 if (!strcasecmp(cp
, filetypes
[i
].extension
)) {
942 write(fd
, dirname
, strlen(dirname
));
944 write(fd
, entry
->d_name
, x
);
948 if(TIME_AFTER(current_tick
, pltick
+HZ
/4)) {
949 pltick
= current_tick
;
951 snprintf(buf
, sizeof buf
, "%d", plsize
);
952 #ifdef HAVE_LCD_BITMAP
955 screens
[i
].puts(0, 4, (unsigned char *)buf
);
956 gui_textarea_update(&screens
[i
]);
961 else if (plsize
> 99)
969 screens
[i
].puts(x
,0,buf
);
985 bool create_playlist(void)
989 char filename
[MAX_PATH
];
991 pltick
= current_tick
;
993 snprintf(filename
, sizeof filename
, "%s.m3u8",
994 tc
.currdir
[1] ? tc
.currdir
: "/root");
997 gui_textarea_clear(&screens
[i
]);
998 screens
[i
].puts(0, 0, str(LANG_CREATING
));
999 screens
[i
].puts_scroll(0, 1, (unsigned char *)filename
);
1000 #if defined(HAVE_LCD_BITMAP) || defined(SIMULATOR)
1001 gui_textarea_update(&screens
[i
]);
1004 fd
= creat(filename
);
1008 trigger_cpu_boost();
1010 snprintf(filename
, sizeof(filename
), "%s",
1011 tc
.currdir
[1] ? tc
.currdir
: "/");
1013 add_dir(filename
, sizeof(filename
), fd
);
1022 int rockbox_browse(const char *root
, int dirfilter
)
1025 int *last_filter
= tc
.dirfilter
;
1026 tc
.dirfilter
= &dirfilter
;
1029 if (dirfilter
>= NUM_FILTER_MODES
)
1031 static struct tree_context backup
;
1035 tc
.selected_item
= 0;
1037 memcpy(tc
.currdir
, root
, sizeof(tc
.currdir
));
1039 last_context
= curr_context
;
1041 ret_val
= dirbrowse();
1043 curr_context
= last_context
;
1047 static char buf
[MAX_PATH
];
1048 if (dirfilter
!= SHOW_ID3DB
)
1049 tc
.dirfilter
= &global_settings
.dirfilter
;
1051 set_current_file(buf
);
1052 ret_val
= dirbrowse();
1054 tc
.dirfilter
= last_filter
;
1058 void tree_mem_init(void)
1060 /* We copy the settings value in case it is changed by the user. We can't
1061 use it until the next reboot. */
1062 max_files
= global_settings
.max_files_in_dir
;
1064 /* initialize tree context struct */
1065 memset(&tc
, 0, sizeof(tc
));
1066 tc
.dirfilter
= &global_settings
.dirfilter
;
1068 tc
.name_buffer_size
= AVERAGE_FILENAME_LENGTH
* max_files
;
1069 tc
.name_buffer
= buffer_alloc(tc
.name_buffer_size
);
1071 tc
.dircache_size
= max_files
* sizeof(struct entry
);
1072 tc
.dircache
= buffer_alloc(tc
.dircache_size
);
1073 tree_get_filetypes(&filetypes
, &filetypes_count
);
1076 bool bookmark_play(char *resume_file
, int index
, int offset
, int seed
,
1080 char* suffix
= strrchr(resume_file
, '.');
1081 bool started
= false;
1083 if (suffix
!= NULL
&&
1084 (!strcasecmp(suffix
, ".m3u") || !strcasecmp(suffix
, ".m3u8")))
1086 /* Playlist playback */
1088 /* check that the file exists */
1089 int fd
= open(resume_file
, O_RDONLY
);
1094 slash
= strrchr(resume_file
,'/');
1104 if (playlist_create(cp
, slash
+1) != -1)
1106 if (global_settings
.playlist_shuffle
)
1107 playlist_shuffle(seed
, -1);
1108 playlist_start(index
,offset
);
1116 /* Directory playback */
1118 if (playlist_create(resume_file
, NULL
) != -1)
1120 char* peek_filename
;
1121 resume_directory(resume_file
);
1122 if (global_settings
.playlist_shuffle
)
1123 playlist_shuffle(seed
, -1);
1125 /* Check if the file is at the same spot in the directory,
1126 else search for it */
1127 peek_filename
= playlist_peek(index
);
1129 if (peek_filename
== NULL
)
1132 if (strcmp(strrchr(peek_filename
, '/') + 1, filename
))
1134 for ( i
=0; i
< playlist_amount(); i
++ )
1136 peek_filename
= playlist_peek(i
);
1138 if (peek_filename
== NULL
)
1141 if (!strcmp(strrchr(peek_filename
, '/') + 1, filename
))
1144 if (i
< playlist_amount())
1149 playlist_start(index
,offset
);
1159 static void say_filetype(int attr
)
1161 /* try to find a voice ID for the extension, if known */
1163 attr
&= FILE_ATTR_MASK
; /* file type */
1164 for (j
=0; j
<filetypes_count
; j
++)
1165 if (attr
== filetypes
[j
].tree_attr
)
1167 talk_id(filetypes
[j
].voiceclip
, true);
1172 static int ft_play_dirname(char* name
)
1175 char dirname_mp3_filename
[MAX_PATH
+1];
1177 #if CONFIG_CODEC != SWCODEC
1178 if (audio_status() & AUDIO_STATUS_PLAY
)
1182 snprintf(dirname_mp3_filename
, sizeof(dirname_mp3_filename
), "%s/%s/%s",
1183 tc
.currdir
[1] ? tc
.currdir
: "" , name
,
1184 dir_thumbnail_name
);
1186 DEBUGF("Checking for %s\n", dirname_mp3_filename
);
1188 fd
= open(dirname_mp3_filename
, O_RDONLY
);
1191 DEBUGF("Failed to find: %s\n", dirname_mp3_filename
);
1197 DEBUGF("Found: %s\n", dirname_mp3_filename
);
1199 talk_file(dirname_mp3_filename
, false);
1200 if(global_settings
.talk_filetype
)
1201 talk_id(VOICE_DIR
, true);
1205 static void ft_play_filename(char *dir
, char *file
)
1207 char name_mp3_filename
[MAX_PATH
+1];
1209 #if CONFIG_CODEC != SWCODEC
1210 if (audio_status() & AUDIO_STATUS_PLAY
)
1214 if (strcasecmp(&file
[strlen(file
) - strlen(file_thumbnail_ext
)],
1215 file_thumbnail_ext
))
1216 { /* file has no .talk extension */
1217 snprintf(name_mp3_filename
, sizeof(name_mp3_filename
),
1218 "%s/%s%s", dir
, file
, file_thumbnail_ext
);
1220 talk_file(name_mp3_filename
, false);
1223 { /* it already is a .talk file, play this directly */
1224 snprintf(name_mp3_filename
, sizeof(name_mp3_filename
),
1225 "%s/%s", dir
, file
);
1226 talk_id(LANG_VOICE_DIR_HOVER
, false); /* prefix it */
1227 talk_file(name_mp3_filename
, true);
1231 /* These two functions are called by the USB and shutdown handlers */
1232 void tree_flush(void)
1234 scrobbler_shutdown();
1235 #ifdef HAVE_TAGCACHE
1236 tagcache_shutdown();
1238 playlist_shutdown();
1240 #ifdef HAVE_TC_RAMCACHE
1241 tagcache_unload_ramcache();
1244 #ifdef HAVE_DIRCACHE
1246 int old_val
= global_status
.dircache_size
;
1247 if (global_settings
.dircache
)
1249 if (!dircache_is_initializing())
1250 global_status
.dircache_size
= dircache_get_cache_size();
1251 # ifdef HAVE_EEPROM_SETTINGS
1252 if (firmware_settings
.initialized
)
1259 global_status
.dircache_size
= 0;
1261 if (old_val
!= global_status
.dircache_size
)
1267 void tree_restore(void)
1269 #ifdef HAVE_EEPROM_SETTINGS
1270 firmware_settings
.disk_clean
= false;
1273 #ifdef HAVE_TC_RAMCACHE
1274 remove(TAGCACHE_STATEFILE
);
1277 #ifdef HAVE_DIRCACHE
1278 remove(DIRCACHE_FILE
);
1279 if (global_settings
.dircache
)
1281 /* Print "Scanning disk..." to the display. */
1285 screens
[i
].putsxy((LCD_WIDTH
/2) -
1286 ((strlen(str(LANG_SCANNING_DISK
)) *
1287 screens
[i
].char_width
)/2),
1288 LCD_HEIGHT
-screens
[i
].char_height
*3,
1289 str(LANG_SCANNING_DISK
));
1290 gui_textarea_update(&screens
[i
]);
1292 cond_talk_ids_fq(LANG_SCANNING_DISK
);
1294 dircache_build(global_status
.dircache_size
);
1296 /* Clean the text when we are done. */
1299 gui_textarea_clear(&screens
[i
]);
1303 #ifdef HAVE_TAGCACHE
1304 tagcache_start_scan();