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(name
, buffer
));
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_list_set_color_callback(&tree_lists
,
315 &tree_get_filecolor
);
321 struct tree_context
* tree_get_context(void)
327 * Returns the position of a given file in the current directory
328 * returns -1 if not found
330 static int tree_get_file_position(char * filename
)
334 /* use lastfile to determine the selected item (default=0) */
335 for (i
=0; i
< tc
.filesindir
; i
++)
337 struct entry
* dc
= tc
.dircache
;
338 struct entry
* e
= &dc
[i
];
339 if (!strcasecmp(e
->name
, filename
))
342 return(-1);/* no file can match, returns undefined */
346 * Called when a new dir is loaded (for example when returning from other apps ...)
347 * also completely redraws the tree
349 static int update_dir(void)
351 bool changed
= false;
353 bool id3db
= *tc
.dirfilter
== SHOW_ID3DB
;
354 /* Checks for changes */
356 if (tc
.currtable
!= lasttable
||
357 tc
.currextra
!= lastextra
||
358 tc
.firstpos
!= lastfirstpos
||
361 if (tagtree_load(&tc
) < 0)
364 lasttable
= tc
.currtable
;
365 lastextra
= tc
.currextra
;
366 lastfirstpos
= tc
.firstpos
;
373 /* if the tc.currdir has been changed, reload it ...*/
374 if (strncmp(tc
.currdir
, lastdir
, sizeof(lastdir
)) || reload_dir
)
376 if (ft_load(&tc
, NULL
) < 0)
378 strcpy(lastdir
, tc
.currdir
);
382 /* if selected item is undefined */
383 if (tc
.selected_item
== -1)
385 /* use lastfile to determine the selected item */
386 tc
.selected_item
= tree_get_file_position(lastfile
);
388 /* If the file doesn't exists, select the first one (default) */
389 if(tc
.selected_item
< 0)
390 tc
.selected_item
= 0;
399 (tc
.dirfull
|| tc
.filesindir
== global_settings
.max_files_in_dir
) )
401 gui_syncsplash(HZ
, ID2P(LANG_SHOWDIR_BUFFER_FULL
));
407 #ifdef HAVE_LCD_BITMAP
408 if (global_settings
.show_path_in_browser
== SHOW_PATH_FULL
409 || global_settings
.show_path_in_browser
== SHOW_PATH_CURRENT
)
411 gui_synclist_set_title(&tree_lists
, tagtree_get_title(&tc
),
412 filetype_get_icon(ATTR_DIRECTORY
));
416 /* Must clear the title as the list is reused */
417 gui_synclist_set_title(&tree_lists
, NULL
, NOICON
);
424 #ifdef HAVE_LCD_BITMAP
425 if (global_settings
.show_path_in_browser
&&
426 *(tc
.dirfilter
) == SHOW_PLUGINS
)
429 if (!strcmp(tc
.currdir
, PLUGIN_GAMES_DIR
))
430 title
= str(LANG_PLUGIN_GAMES
);
431 else if (!strcmp(tc
.currdir
, PLUGIN_APPS_DIR
))
432 title
= str(LANG_PLUGIN_APPS
);
433 else if (!strcmp(tc
.currdir
, PLUGIN_DEMOS_DIR
))
434 title
= str(LANG_PLUGIN_DEMOS
);
435 else title
= str(LANG_PLUGINS
);
436 gui_synclist_set_title(&tree_lists
, title
, Icon_Plugin
);
438 else if (global_settings
.show_path_in_browser
== SHOW_PATH_FULL
)
440 gui_synclist_set_title(&tree_lists
, tc
.currdir
,
441 filetype_get_icon(ATTR_DIRECTORY
));
443 else if (global_settings
.show_path_in_browser
== SHOW_PATH_CURRENT
)
445 char *title
= strrchr(tc
.currdir
, '/') + 1;
448 /* Display "Files" for the root dir */
449 gui_synclist_set_title(&tree_lists
, str(LANG_DIR_BROWSER
),
450 filetype_get_icon(ATTR_DIRECTORY
));
453 gui_synclist_set_title(&tree_lists
, title
,
454 filetype_get_icon(ATTR_DIRECTORY
));
458 /* Must clear the title as the list is reused */
459 gui_synclist_set_title(&tree_lists
, NULL
, NOICON
);
464 gui_synclist_set_nb_items(&tree_lists
, tc
.filesindir
);
465 gui_synclist_set_icon_callback(&tree_lists
, tree_get_fileicon
);
466 if( tc
.selected_item
>= tc
.filesindir
)
467 tc
.selected_item
=tc
.filesindir
-1;
469 gui_synclist_select_item(&tree_lists
, tc
.selected_item
);
471 if (global_settings
.buttonbar
) {
472 if (*tc
.dirfilter
< NUM_FILTER_MODES
)
473 gui_buttonbar_set(&tree_buttonbar
, str(LANG_SYSFONT_DIRBROWSE_F1
),
474 str(LANG_SYSFONT_DIRBROWSE_F2
),
475 str(LANG_SYSFONT_DIRBROWSE_F3
));
477 gui_buttonbar_set(&tree_buttonbar
, "<<<", "", "");
478 gui_buttonbar_draw(&tree_buttonbar
);
481 gui_synclist_draw(&tree_lists
);
482 gui_synclist_speak_item(&tree_lists
);
483 gui_syncstatusbar_draw(&statusbars
, true);
484 return tc
.filesindir
;
487 /* load tracks from specified directory to resume play */
488 void resume_directory(const char *dir
)
491 bool id3db
= *tc
.dirfilter
== SHOW_ID3DB
;
494 if (ft_load(&tc
, dir
) < 0)
498 ft_build_playlist(&tc
, 0);
506 /* Returns the current working directory and also writes cwd to buf if
507 non-NULL. In case of error, returns NULL. */
508 char *getcwd(char *buf
, int size
)
514 strncpy(buf
, tc
.currdir
, size
);
521 /* Force a reload of the directory next time directory browser is called */
522 void reload_directory(void)
527 void get_current_file(char* buffer
, int buffer_len
)
530 /* in ID3DB mode it is a bad idea to call this function */
531 /* (only happens with `follow playlist') */
532 if( *tc
.dirfilter
== SHOW_ID3DB
)
536 struct entry
* dc
= tc
.dircache
;
537 struct entry
* e
= &dc
[tc
.selected_item
];
538 snprintf(buffer
, buffer_len
, "%s/%s", getcwd(NULL
,0),
539 tc
.dirlength
? e
->name
: "");
542 /* Allow apps to change our dirfilter directly (required for sub browsers)
543 if they're suddenly going to become a file browser for example */
544 void set_dirfilter(int l_dirfilter
)
546 *tc
.dirfilter
= l_dirfilter
;
549 /* Selects a file and update tree context properly */
550 void set_current_file(char *path
)
556 /* in ID3DB mode it is a bad idea to call this function */
557 /* (only happens with `follow playlist') */
558 if( *tc
.dirfilter
== SHOW_ID3DB
)
562 /* separate directory from filename */
563 /* gets the directory's name and put it into tc.currdir */
564 name
= strrchr(path
+1,'/');
568 strcpy(tc
.currdir
, path
);
574 strcpy(tc
.currdir
, "/");
578 strcpy(lastfile
, name
);
581 /* If we changed dir we must recalculate the dirlevel
582 and adjust the selected history properly */
583 if (strncmp(tc
.currdir
,lastdir
,sizeof(lastdir
)))
586 tc
.selected_item_history
[tc
.dirlevel
] = -1;
588 /* use '/' to calculate dirlevel */
589 for (i
= 1; path
[i
] != '\0'; i
++)
594 tc
.selected_item_history
[tc
.dirlevel
] = -1;
598 if (ft_load(&tc
, NULL
) >= 0)
600 tc
.selected_item
= tree_get_file_position(lastfile
);
605 /* main loop, handles key events */
606 static int dirbrowse()
610 unsigned button
, oldbutton
;
611 bool reload_root
= false;
612 int lastfilter
= *tc
.dirfilter
;
613 bool lastsortcase
= global_settings
.sort_case
;
614 bool exit_func
= false;
616 char* currdir
= tc
.currdir
; /* just a shortcut */
618 bool id3db
= *tc
.dirfilter
== SHOW_ID3DB
;
621 curr_context
=CONTEXT_ID3DB
;
624 curr_context
=CONTEXT_TREE
;
625 if (tc
.selected_item
< 0)
626 tc
.selected_item
= 0;
635 numentries
= update_dir();
637 if (numentries
== -1)
638 return GO_TO_PREVIOUS
; /* currdir is not a directory */
640 if (*tc
.dirfilter
> NUM_FILTER_MODES
&& numentries
==0)
642 gui_syncsplash(HZ
*2, ID2P(LANG_NO_FILES
));
643 return GO_TO_PREVIOUS
; /* No files found for rockbox_browser() */
647 struct entry
*dircache
= tc
.dircache
;
648 bool restore
= false;
650 tc
.dirlevel
= 0; /* shouldnt be needed.. this code needs work! */
653 char *lines
[]={ID2P(LANG_BOOT_CHANGED
), ID2P(LANG_REBOOT_NOW
)};
654 struct text_message message
={lines
, 2};
655 if(gui_syncyesno_run(&message
, NULL
, NULL
)==YESNO_YES
)
656 rolo_load("/" BOOTFILE
);
658 boot_changed
= false;
661 button
= get_action(CONTEXT_TREE
,
662 list_do_action_timeout(&tree_lists
, HZ
/2));
664 gui_synclist_do_button(&tree_lists
, &button
,LIST_WRAP_UNLESS_HELD
);
665 tc
.selected_item
= gui_synclist_get_sel_pos(&tree_lists
);
668 /* nothing to do if no files to display */
669 if ( numentries
== 0 )
673 switch (id3db
?tagtree_enter(&tc
):ft_enter(&tc
))
675 switch (ft_enter(&tc
))
678 case 1: reload_dir
= true; break;
679 case 2: start_wps
= true; break;
680 case 3: exit_func
= true; break;
686 case ACTION_STD_CANCEL
:
687 if (*tc
.dirfilter
> NUM_FILTER_MODES
&& tc
.dirlevel
< 1) {
691 if ((*tc
.dirfilter
== SHOW_ID3DB
&& tc
.dirlevel
== 0) ||
692 ((*tc
.dirfilter
!= SHOW_ID3DB
&& !strcmp(currdir
,"/"))))
694 #ifdef HAVE_LCD_BITMAP /* charcell doesnt have ACTION_TREE_PGLEFT so this isnt needed */
695 if (oldbutton
== ACTION_TREE_PGLEFT
)
707 if (ft_exit(&tc
) == 3)
713 case ACTION_TREE_STOP
:
714 if (list_stop_handler())
718 case ACTION_STD_MENU
:
722 #ifdef HAVE_RECORDING
724 return GO_TO_RECSCREEN
;
727 case ACTION_TREE_WPS
:
728 return GO_TO_PREVIOUS_MUSIC
;
730 #ifdef HAVE_QUICKSCREEN
731 case ACTION_STD_QUICKSCREEN
:
732 /* don't enter f2 from plugin browser */
733 if (*tc
.dirfilter
< NUM_FILTER_MODES
)
735 if (quick_screen_quick(button
))
743 /* don't enter f3 from plugin browser */
744 if (*tc
.dirfilter
< NUM_FILTER_MODES
)
746 if (quick_screen_f3(BUTTON_F3
))
753 case ACTION_STD_CONTEXT
:
759 onplay_result
= onplay(NULL
, 0, curr_context
);
764 if (tagtree_get_attr(&tc
) == FILE_ATTR_AUDIO
)
766 attr
= FILE_ATTR_AUDIO
;
767 tagtree_get_filename(&tc
, buf
, sizeof(buf
));
770 attr
= ATTR_DIRECTORY
;
775 attr
= dircache
[tc
.selected_item
].attr
;
777 if (currdir
[1]) /* Not in / */
778 snprintf(buf
, sizeof buf
, "%s/%s",
780 dircache
[tc
.selected_item
].name
);
782 snprintf(buf
, sizeof buf
, "/%s",
783 dircache
[tc
.selected_item
].name
);
785 onplay_result
= onplay(buf
, attr
, curr_context
);
787 switch (onplay_result
)
789 case ONPLAY_MAINMENU
:
796 case ONPLAY_RELOAD_DIR
:
800 case ONPLAY_START_PLAY
:
808 gui_syncstatusbar_draw(&statusbars
, false);
817 /* The 'dir no longer valid' situation will be caught later
818 * by checking the showdir() result. */
823 if (default_event_handler(button
) == SYS_USB_CONNECTED
)
825 if(*tc
.dirfilter
> NUM_FILTER_MODES
)
826 /* leave sub-browsers after usb, doing otherwise
827 might be confusing to the user */
843 /* do we need to rescan dir? */
844 if (reload_dir
|| reload_root
||
845 lastfilter
!= *tc
.dirfilter
||
846 lastsortcase
!= global_settings
.sort_case
)
849 strcpy(currdir
, "/");
862 gui_synclist_select_item(&tree_lists
, 0);
863 gui_synclist_draw(&tree_lists
);
864 tc
.selected_item
= 0;
868 lastfilter
= *tc
.dirfilter
;
869 lastsortcase
= global_settings
.sort_case
;
874 return GO_TO_PREVIOUS
;
876 if (restore
|| reload_dir
) {
877 /* restore display */
878 numentries
= update_dir();
880 if (currdir
[1] && (numentries
< 0))
881 { /* not in root and reload failed */
882 reload_root
= true; /* try root */
890 static int plsize
= 0;
892 static bool add_dir(char* dirname
, int len
, int fd
)
897 /* check for user abort */
898 if (action_userabort(TIMEOUT_NOBLOCK
))
901 dir
= opendir(dirname
);
906 struct dirent
*entry
;
908 entry
= readdir(dir
);
911 if (entry
->attribute
& ATTR_DIRECTORY
) {
912 int dirlen
= strlen(dirname
);
915 if (!strcmp((char *)entry
->d_name
, ".") ||
916 !strcmp((char *)entry
->d_name
, ".."))
920 snprintf(dirname
+dirlen
, len
-dirlen
, "/%s", entry
->d_name
);
922 snprintf(dirname
, len
, "/%s", entry
->d_name
);
924 result
= add_dir(dirname
, len
, fd
);
925 dirname
[dirlen
] = '\0';
932 int x
= strlen((char *)entry
->d_name
);
934 char *cp
= strrchr((char *)entry
->d_name
,'.');
939 /* add all supported audio files to playlists */
940 for (i
=0; i
< filetypes_count
; i
++) {
941 if (filetypes
[i
].tree_attr
== FILE_ATTR_AUDIO
) {
942 if (!strcasecmp(cp
, filetypes
[i
].extension
)) {
945 write(fd
, dirname
, strlen(dirname
));
947 write(fd
, entry
->d_name
, x
);
951 if(TIME_AFTER(current_tick
, pltick
+HZ
/4)) {
952 pltick
= current_tick
;
954 snprintf(buf
, sizeof buf
, "%d", plsize
);
955 #ifdef HAVE_LCD_BITMAP
958 screens
[i
].puts(0, 4, (unsigned char *)buf
);
959 gui_textarea_update(&screens
[i
]);
964 else if (plsize
> 99)
972 screens
[i
].puts(x
,0,buf
);
988 bool create_playlist(void)
992 char filename
[MAX_PATH
];
994 pltick
= current_tick
;
996 snprintf(filename
, sizeof filename
, "%s.m3u8",
997 tc
.currdir
[1] ? tc
.currdir
: "/root");
1000 gui_textarea_clear(&screens
[i
]);
1001 screens
[i
].puts(0, 0, str(LANG_CREATING
));
1002 screens
[i
].puts_scroll(0, 1, (unsigned char *)filename
);
1003 #if defined(HAVE_LCD_BITMAP) || defined(SIMULATOR)
1004 gui_textarea_update(&screens
[i
]);
1007 fd
= creat(filename
);
1011 trigger_cpu_boost();
1013 snprintf(filename
, sizeof(filename
), "%s",
1014 tc
.currdir
[1] ? tc
.currdir
: "/");
1016 add_dir(filename
, sizeof(filename
), fd
);
1025 int rockbox_browse(const char *root
, int dirfilter
)
1028 int *last_filter
= tc
.dirfilter
;
1029 tc
.dirfilter
= &dirfilter
;
1032 if (dirfilter
>= NUM_FILTER_MODES
)
1034 static struct tree_context backup
;
1038 tc
.selected_item
= 0;
1040 memcpy(tc
.currdir
, root
, sizeof(tc
.currdir
));
1042 last_context
= curr_context
;
1044 ret_val
= dirbrowse();
1046 curr_context
= last_context
;
1050 static char buf
[MAX_PATH
];
1051 if (dirfilter
!= SHOW_ID3DB
)
1052 tc
.dirfilter
= &global_settings
.dirfilter
;
1054 set_current_file(buf
);
1055 ret_val
= dirbrowse();
1057 tc
.dirfilter
= last_filter
;
1061 void tree_mem_init(void)
1063 /* We copy the settings value in case it is changed by the user. We can't
1064 use it until the next reboot. */
1065 max_files
= global_settings
.max_files_in_dir
;
1067 /* initialize tree context struct */
1068 memset(&tc
, 0, sizeof(tc
));
1069 tc
.dirfilter
= &global_settings
.dirfilter
;
1071 tc
.name_buffer_size
= AVERAGE_FILENAME_LENGTH
* max_files
;
1072 tc
.name_buffer
= buffer_alloc(tc
.name_buffer_size
);
1074 tc
.dircache_size
= max_files
* sizeof(struct entry
);
1075 tc
.dircache
= buffer_alloc(tc
.dircache_size
);
1076 tree_get_filetypes(&filetypes
, &filetypes_count
);
1079 void bookmark_play(char *resume_file
, int index
, int offset
, int seed
,
1083 char* suffix
= strrchr(resume_file
, '.');
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
);
1117 /* Directory playback */
1119 if (playlist_create(resume_file
, NULL
) != -1)
1121 char* peek_filename
;
1122 resume_directory(resume_file
);
1123 if (global_settings
.playlist_shuffle
)
1124 playlist_shuffle(seed
, -1);
1126 /* Check if the file is at the same spot in the directory,
1127 else search for it */
1128 peek_filename
= playlist_peek(index
);
1130 if (peek_filename
== NULL
)
1133 if (strcmp(strrchr(peek_filename
, '/') + 1, filename
))
1135 for ( i
=0; i
< playlist_amount(); i
++ )
1137 peek_filename
= playlist_peek(i
);
1139 if (peek_filename
== NULL
)
1142 if (!strcmp(strrchr(peek_filename
, '/') + 1, filename
))
1145 if (i
< playlist_amount())
1150 playlist_start(index
,offset
);
1157 static void say_filetype(int attr
)
1159 /* try to find a voice ID for the extension, if known */
1161 attr
&= FILE_ATTR_MASK
; /* file type */
1162 for (j
=0; j
<filetypes_count
; j
++)
1163 if (attr
== filetypes
[j
].tree_attr
)
1165 talk_id(filetypes
[j
].voiceclip
, true);
1170 static int ft_play_dirname(char* name
)
1173 char dirname_mp3_filename
[MAX_PATH
+1];
1175 #if CONFIG_CODEC != SWCODEC
1176 if (audio_status() & AUDIO_STATUS_PLAY
)
1180 snprintf(dirname_mp3_filename
, sizeof(dirname_mp3_filename
), "%s/%s/%s",
1181 tc
.currdir
[1] ? tc
.currdir
: "" , name
,
1182 dir_thumbnail_name
);
1184 DEBUGF("Checking for %s\n", dirname_mp3_filename
);
1186 fd
= open(dirname_mp3_filename
, O_RDONLY
);
1189 DEBUGF("Failed to find: %s\n", dirname_mp3_filename
);
1195 DEBUGF("Found: %s\n", dirname_mp3_filename
);
1197 talk_file(dirname_mp3_filename
, false);
1198 if(global_settings
.talk_filetype
)
1199 talk_id(VOICE_DIR
, true);
1203 static void ft_play_filename(char *dir
, char *file
)
1205 char name_mp3_filename
[MAX_PATH
+1];
1207 #if CONFIG_CODEC != SWCODEC
1208 if (audio_status() & AUDIO_STATUS_PLAY
)
1212 if (strcasecmp(&file
[strlen(file
) - strlen(file_thumbnail_ext
)],
1213 file_thumbnail_ext
))
1214 { /* file has no .talk extension */
1215 snprintf(name_mp3_filename
, sizeof(name_mp3_filename
),
1216 "%s/%s%s", dir
, file
, file_thumbnail_ext
);
1218 talk_file(name_mp3_filename
, false);
1221 { /* it already is a .talk file, play this directly */
1222 snprintf(name_mp3_filename
, sizeof(name_mp3_filename
),
1223 "%s/%s", dir
, file
);
1224 talk_id(LANG_VOICE_DIR_HOVER
, false); /* prefix it */
1225 talk_file(name_mp3_filename
, true);
1229 /* These two functions are called by the USB and shutdown handlers */
1230 void tree_flush(void)
1232 scrobbler_shutdown();
1233 #ifdef HAVE_TAGCACHE
1234 tagcache_shutdown();
1236 playlist_shutdown();
1238 #ifdef HAVE_TC_RAMCACHE
1239 tagcache_unload_ramcache();
1242 #ifdef HAVE_DIRCACHE
1244 int old_val
= global_status
.dircache_size
;
1245 if (global_settings
.dircache
)
1247 if (!dircache_is_initializing())
1248 global_status
.dircache_size
= dircache_get_cache_size();
1249 # ifdef HAVE_EEPROM_SETTINGS
1250 if (firmware_settings
.initialized
)
1257 global_status
.dircache_size
= 0;
1259 if (old_val
!= global_status
.dircache_size
)
1265 void tree_restore(void)
1267 #ifdef HAVE_EEPROM_SETTINGS
1268 firmware_settings
.disk_clean
= false;
1271 #ifdef HAVE_TC_RAMCACHE
1272 remove(TAGCACHE_STATEFILE
);
1275 #ifdef HAVE_DIRCACHE
1276 remove(DIRCACHE_FILE
);
1277 if (global_settings
.dircache
)
1279 /* Print "Scanning disk..." to the display. */
1283 screens
[i
].putsxy((LCD_WIDTH
/2) -
1284 ((strlen(str(LANG_SCANNING_DISK
)) *
1285 screens
[i
].char_width
)/2),
1286 LCD_HEIGHT
-screens
[i
].char_height
*3,
1287 str(LANG_SCANNING_DISK
));
1288 gui_textarea_update(&screens
[i
]);
1290 cond_talk_ids_fq(LANG_SCANNING_DISK
);
1292 dircache_build(global_status
.dircache_size
);
1294 /* Clean the text when we are done. */
1297 gui_textarea_clear(&screens
[i
]);
1301 #ifdef HAVE_TAGCACHE
1302 tagcache_start_scan();