1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 Daniel Stenberg
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
24 #include "string-extra.h"
26 #include "applimits.h"
38 #include "skin_engine/skin_engine.h"
53 #include "filetypes.h"
55 #include "filefuncs.h"
59 #include "recorder/recording.h"
67 #include "eeprom_settings.h"
68 #include "playlist_catalog.h"
73 #include "buttonbar.h"
74 #include "quickscreen.h"
75 #include "appevents.h"
77 #include "root_menu.h"
79 static const struct filetype
*filetypes
;
80 static int filetypes_count
;
82 struct gui_synclist tree_lists
;
84 /* I put it here because other files doesn't use it yet,
85 * but should be elsewhere since it will be used mostly everywhere */
87 static struct gui_buttonbar tree_buttonbar
;
89 static struct tree_context tc
;
91 bool boot_changed
= false;
93 char lastfile
[MAX_PATH
];
94 static char lastdir
[MAX_PATH
];
96 static int lasttable
, lastextra
, lastfirstpos
;
99 static bool reload_dir
= false;
101 static bool start_wps
= false;
102 static int curr_context
= false;/* id3db or tree*/
104 static int dirbrowse(void);
105 static int ft_play_dirname(char* name
);
106 static void ft_play_filename(char *dir
, char *file
);
107 static void say_filetype(int attr
);
109 static const char* tree_get_filename(int selected_item
, void *data
,
110 char *buffer
, size_t buffer_len
)
112 struct tree_context
* local_tc
=(struct tree_context
*)data
;
115 bool stripit
= false;
117 bool id3db
= *(local_tc
->dirfilter
) == SHOW_ID3DB
;
121 return tagtree_get_entry(&tc
, selected_item
)->name
;
126 struct entry
* dc
= local_tc
->dircache
;
127 struct entry
* e
= &dc
[selected_item
];
132 if(!(attr
& ATTR_DIRECTORY
))
134 switch(global_settings
.show_filename_ext
)
137 /* show file extension: off */
141 /* show file extension: on */
144 /* show file extension: only unknown types */
145 stripit
= filetype_supported(attr
);
149 /* show file extension: only when viewing all */
150 stripit
= (*(local_tc
->dirfilter
) != SHOW_ID3DB
) &&
151 (*(local_tc
->dirfilter
) != SHOW_ALL
);
158 return(strip_extension(buffer
, buffer_len
, name
));
163 #ifdef HAVE_LCD_COLOR
164 static int tree_get_filecolor(int selected_item
, void * data
)
166 if (*tc
.dirfilter
== SHOW_ID3DB
)
168 struct tree_context
* local_tc
=(struct tree_context
*)data
;
169 struct entry
* dc
= local_tc
->dircache
;
170 struct entry
* e
= &dc
[selected_item
];
171 return filetype_get_color(e
->name
, e
->attr
);
175 static enum themable_icons
tree_get_fileicon(int selected_item
, void * data
)
177 struct tree_context
* local_tc
=(struct tree_context
*)data
;
179 bool id3db
= *(local_tc
->dirfilter
) == SHOW_ID3DB
;
181 return tagtree_get_icon(&tc
);
186 struct entry
* dc
= local_tc
->dircache
;
187 struct entry
* e
= &dc
[selected_item
];
188 return filetype_get_icon(e
->attr
);
192 static int tree_voice_cb(int selected_item
, void * data
)
194 struct tree_context
* local_tc
=(struct tree_context
*)data
;
198 bool id3db
= *(local_tc
->dirfilter
) == SHOW_ID3DB
;
202 attr
= tagtree_get_attr(local_tc
);
203 name
= tagtree_get_entry(local_tc
, selected_item
)->name
;
208 struct entry
* dc
= local_tc
->dircache
;
209 struct entry
* e
= &dc
[selected_item
];
213 bool is_dir
= (attr
& ATTR_DIRECTORY
);
214 bool did_clip
= false;
215 /* First the .talk clip case */
218 if(global_settings
.talk_dir_clip
)
221 if(ft_play_dirname(name
) <0)
222 /* failed, not existing */
225 } else { /* it's a file */
226 if (global_settings
.talk_file_clip
&& (attr
& FILE_ATTR_THUMBNAIL
))
229 ft_play_filename(local_tc
->currdir
, name
);
234 /* say the number or spell if required or as a fallback */
235 switch (is_dir
? global_settings
.talk_dir
: global_settings
.talk_file
)
237 case 1: /* as numbers */
238 talk_id(is_dir
? VOICE_DIR
: VOICE_FILE
, false);
239 talk_number(selected_item
+1 - (is_dir
? 0 : local_tc
->dirsindir
),
241 if(global_settings
.talk_filetype
242 && !is_dir
&& *local_tc
->dirfilter
< NUM_FILTER_MODES
)
245 case 2: /* spelled */
247 if(global_settings
.talk_filetype
)
250 talk_id(VOICE_DIR
, true);
251 else if(*local_tc
->dirfilter
< NUM_FILTER_MODES
)
254 talk_spell(name
, true);
261 bool check_rockboxdir(void)
263 if(!dir_exists(ROCKBOX_DIR
))
264 { /* No need to localise this message.
265 If .rockbox is missing, it wouldn't work anyway */
268 screens
[i
].clear_display();
269 splash(HZ
*2, "No .rockbox directory");
271 screens
[i
].clear_display();
272 splash(HZ
*2, "Installation incomplete");
278 /* do this really late in the init sequence */
279 void tree_gui_init(void)
283 strcpy(tc
.currdir
, "/");
285 #ifdef HAVE_LCD_CHARCELLS
288 screens
[i
].double_height(false);
290 #ifdef HAVE_BUTTONBAR
291 gui_buttonbar_init(&tree_buttonbar
);
292 /* since archos only have one screen, no need to create more than that */
293 gui_buttonbar_set_display(&tree_buttonbar
, &(screens
[SCREEN_MAIN
]) );
295 gui_synclist_init(&tree_lists
, &tree_get_filename
, &tc
, false, 1, NULL
);
296 gui_synclist_set_voice_callback(&tree_lists
, tree_voice_cb
);
297 gui_synclist_set_icon_callback(&tree_lists
,
298 global_settings
.show_icons
?&tree_get_fileicon
:NULL
);
299 #ifdef HAVE_LCD_COLOR
300 gui_synclist_set_color_callback(&tree_lists
, &tree_get_filecolor
);
305 /* drawer function for the GUI_EVENT_REDRAW callback */
306 void tree_drawlists(void)
308 /* band-aid to fix the bar/list redrawing properly after leaving a plugin */
309 send_event(GUI_EVENT_THEME_CHANGED
, NULL
);
311 gui_synclist_draw(&tree_lists
);
315 struct tree_context
* tree_get_context(void)
321 * Returns the position of a given file in the current directory
322 * returns -1 if not found
324 static int tree_get_file_position(char * filename
)
328 /* use lastfile to determine the selected item (default=0) */
329 for (i
=0; i
< tc
.filesindir
; i
++)
331 struct entry
* dc
= tc
.dircache
;
332 struct entry
* e
= &dc
[i
];
333 if (!strcasecmp(e
->name
, filename
))
336 return(-1);/* no file can match, returns undefined */
340 * Called when a new dir is loaded (for example when returning from other apps ...)
341 * also completely redraws the tree
343 static int update_dir(void)
345 bool changed
= false;
347 bool id3db
= *tc
.dirfilter
== SHOW_ID3DB
;
348 /* Checks for changes */
350 if (tc
.currtable
!= lasttable
||
351 tc
.currextra
!= lastextra
||
352 tc
.firstpos
!= lastfirstpos
||
355 if (tagtree_load(&tc
) < 0)
358 lasttable
= tc
.currtable
;
359 lastextra
= tc
.currextra
;
360 lastfirstpos
= tc
.firstpos
;
367 /* if the tc.currdir has been changed, reload it ...*/
368 if (strncmp(tc
.currdir
, lastdir
, sizeof(lastdir
)) || reload_dir
)
370 if (ft_load(&tc
, NULL
) < 0)
372 strcpy(lastdir
, tc
.currdir
);
376 /* if selected item is undefined */
377 if (tc
.selected_item
== -1)
379 /* use lastfile to determine the selected item */
380 tc
.selected_item
= tree_get_file_position(lastfile
);
382 /* If the file doesn't exists, select the first one (default) */
383 if(tc
.selected_item
< 0)
384 tc
.selected_item
= 0;
395 splash(HZ
, ID2P(LANG_SHOWDIR_BUFFER_FULL
));
401 #ifdef HAVE_LCD_BITMAP
402 if (global_settings
.show_path_in_browser
== SHOW_PATH_FULL
403 || global_settings
.show_path_in_browser
== SHOW_PATH_CURRENT
)
405 gui_synclist_set_title(&tree_lists
, tagtree_get_title(&tc
),
406 filetype_get_icon(ATTR_DIRECTORY
));
410 /* Must clear the title as the list is reused */
411 gui_synclist_set_title(&tree_lists
, NULL
, NOICON
);
418 #ifdef HAVE_LCD_BITMAP
419 if (tc
.browse
&& tc
.browse
->title
)
421 int icon
= tc
.browse
->icon
;
423 icon
= filetype_get_icon(ATTR_DIRECTORY
);
424 gui_synclist_set_title(&tree_lists
, tc
.browse
->title
, icon
);
426 else if (global_settings
.show_path_in_browser
== SHOW_PATH_FULL
)
428 gui_synclist_set_title(&tree_lists
, tc
.currdir
,
429 filetype_get_icon(ATTR_DIRECTORY
));
431 else if (global_settings
.show_path_in_browser
== SHOW_PATH_CURRENT
)
433 char *title
= strrchr(tc
.currdir
, '/') + 1;
436 /* Display "Files" for the root dir */
437 gui_synclist_set_title(&tree_lists
, str(LANG_DIR_BROWSER
),
438 filetype_get_icon(ATTR_DIRECTORY
));
441 gui_synclist_set_title(&tree_lists
, title
,
442 filetype_get_icon(ATTR_DIRECTORY
));
446 /* Must clear the title as the list is reused */
447 gui_synclist_set_title(&tree_lists
, NULL
, NOICON
);
452 gui_synclist_set_nb_items(&tree_lists
, tc
.filesindir
);
453 gui_synclist_set_icon_callback(&tree_lists
,
454 global_settings
.show_icons
?tree_get_fileicon
:NULL
);
455 if( tc
.selected_item
>= tc
.filesindir
)
456 tc
.selected_item
=tc
.filesindir
-1;
458 gui_synclist_select_item(&tree_lists
, tc
.selected_item
);
459 #ifdef HAVE_BUTTONBAR
460 if (global_settings
.buttonbar
) {
461 if (*tc
.dirfilter
< NUM_FILTER_MODES
)
462 gui_buttonbar_set(&tree_buttonbar
, str(LANG_SYSFONT_DIRBROWSE_F1
),
463 str(LANG_SYSFONT_DIRBROWSE_F2
),
464 str(LANG_SYSFONT_DIRBROWSE_F3
));
466 gui_buttonbar_set(&tree_buttonbar
, "<<<", "", "");
467 gui_buttonbar_draw(&tree_buttonbar
);
470 gui_synclist_draw(&tree_lists
);
471 gui_synclist_speak_item(&tree_lists
);
472 return tc
.filesindir
;
475 /* load tracks from specified directory to resume play */
476 void resume_directory(const char *dir
)
478 int dirfilter
= *tc
.dirfilter
;
481 bool id3db
= *tc
.dirfilter
== SHOW_ID3DB
;
483 /* make sure the dirfilter is sane. The only time it should be possible
484 * thats its not is when resume playlist is called from a plugin
489 *tc
.dirfilter
= global_settings
.dirfilter
;
490 ret
= ft_load(&tc
, dir
);
491 *tc
.dirfilter
= dirfilter
;
496 ft_build_playlist(&tc
, 0);
504 /* Returns the current working directory and also writes cwd to buf if
505 non-NULL. In case of error, returns NULL. */
506 char *getcwd(char *buf
, getcwd_size_t size
)
512 if ((getcwd_size_t
)strlcpy(buf
, tc
.currdir
, size
) < size
)
515 /* size == 0, or truncation in strlcpy */
519 /* Force a reload of the directory next time directory browser is called */
520 void reload_directory(void)
525 char* get_current_file(char* buffer
, size_t buffer_len
)
528 /* in ID3DB mode it is a bad idea to call this function */
529 /* (only happens with `follow playlist') */
530 if( *tc
.dirfilter
== SHOW_ID3DB
)
534 struct entry
* dc
= tc
.dircache
;
535 struct entry
* e
= &dc
[tc
.selected_item
];
536 if (getcwd(buffer
, buffer_len
))
540 if (buffer
[strlen(buffer
)-1] != '/')
541 strlcat(buffer
, "/", buffer_len
);
542 if (strlcat(buffer
, e
->name
, buffer_len
) >= buffer_len
)
550 /* Allow apps to change our dirfilter directly (required for sub browsers)
551 if they're suddenly going to become a file browser for example */
552 void set_dirfilter(int l_dirfilter
)
554 *tc
.dirfilter
= l_dirfilter
;
557 /* Selects a file and update tree context properly */
558 void set_current_file(const char *path
)
564 /* in ID3DB mode it is a bad idea to call this function */
565 /* (only happens with `follow playlist') */
566 if( *tc
.dirfilter
== SHOW_ID3DB
)
570 /* separate directory from filename */
571 /* gets the directory's name and put it into tc.currdir */
572 name
= strrchr(path
+1,'/');
575 strlcpy(tc
.currdir
, path
, name
- path
+ 1);
580 strcpy(tc
.currdir
, "/");
584 strcpy(lastfile
, name
);
587 /* If we changed dir we must recalculate the dirlevel
588 and adjust the selected history properly */
589 if (strncmp(tc
.currdir
,lastdir
,sizeof(lastdir
)))
592 tc
.selected_item_history
[tc
.dirlevel
] = -1;
594 /* use '/' to calculate dirlevel */
595 for (i
= 1; path
[i
] != '\0'; i
++)
600 tc
.selected_item_history
[tc
.dirlevel
] = -1;
604 if (ft_load(&tc
, NULL
) >= 0)
606 tc
.selected_item
= tree_get_file_position(lastfile
);
611 /* main loop, handles key events */
612 static int dirbrowse(void)
616 int button
, oldbutton
;
617 bool reload_root
= false;
618 int lastfilter
= *tc
.dirfilter
;
619 bool lastsortcase
= global_settings
.sort_case
;
620 bool exit_func
= false;
622 char* currdir
= tc
.currdir
; /* just a shortcut */
624 bool id3db
= *tc
.dirfilter
== SHOW_ID3DB
;
627 curr_context
=CONTEXT_ID3DB
;
630 curr_context
=CONTEXT_TREE
;
631 if (tc
.selected_item
< 0)
632 tc
.selected_item
= 0;
641 numentries
= update_dir();
643 if (numentries
== -1)
644 return GO_TO_PREVIOUS
; /* currdir is not a directory */
646 if (*tc
.dirfilter
> NUM_FILTER_MODES
&& numentries
==0)
648 splash(HZ
*2, ID2P(LANG_NO_FILES
));
649 return GO_TO_PREVIOUS
; /* No files found for rockbox_browse() */
652 gui_synclist_draw(&tree_lists
);
654 struct entry
*dircache
= tc
.dircache
;
655 bool restore
= false;
657 tc
.dirlevel
= 0; /* shouldnt be needed.. this code needs work! */
660 static const char *lines
[]={ID2P(LANG_BOOT_CHANGED
), ID2P(LANG_REBOOT_NOW
)};
661 static const struct text_message message
={lines
, 2};
662 if(gui_syncyesno_run(&message
, NULL
, NULL
)==YESNO_YES
)
663 rolo_load("/" BOOTFILE
);
665 boot_changed
= false;
668 button
= get_action(CONTEXT_TREE
,
669 list_do_action_timeout(&tree_lists
, HZ
/2));
671 gui_synclist_do_button(&tree_lists
, &button
,LIST_WRAP_UNLESS_HELD
);
672 tc
.selected_item
= gui_synclist_get_sel_pos(&tree_lists
);
675 /* nothing to do if no files to display */
676 if ( numentries
== 0 )
679 if ((tc
.browse
->flags
& BROWSE_SELECTONLY
) &&
680 !(dircache
[tc
.selected_item
].attr
& ATTR_DIRECTORY
))
682 tc
.browse
->flags
|= BROWSE_SELECTED
;
683 get_current_file(tc
.browse
->buf
, tc
.browse
->bufsize
);
684 return GO_TO_PREVIOUS
;
688 switch (id3db
?tagtree_enter(&tc
):ft_enter(&tc
))
690 switch (ft_enter(&tc
))
693 case GO_TO_FILEBROWSER
: reload_dir
= true; break;
700 case GO_TO_ROOT
: exit_func
= true; break;
706 case ACTION_STD_CANCEL
:
707 if (*tc
.dirfilter
> NUM_FILTER_MODES
&& tc
.dirlevel
< 1) {
711 if ((*tc
.dirfilter
== SHOW_ID3DB
&& tc
.dirlevel
== 0) ||
712 ((*tc
.dirfilter
!= SHOW_ID3DB
&& !strcmp(currdir
,"/"))))
714 #ifdef HAVE_LCD_BITMAP /* charcell doesnt have ACTION_TREE_PGLEFT so this isnt needed */
715 if (oldbutton
== ACTION_TREE_PGLEFT
)
727 if (ft_exit(&tc
) == 3)
733 case ACTION_TREE_STOP
:
734 if (list_stop_handler())
738 case ACTION_STD_MENU
:
742 #ifdef HAVE_RECORDING
744 return GO_TO_RECSCREEN
;
747 case ACTION_TREE_WPS
:
748 return GO_TO_PREVIOUS_MUSIC
;
750 #ifdef HAVE_QUICKSCREEN
751 case ACTION_STD_QUICKSCREEN
:
752 /* don't enter f2 from plugin browser */
753 if (*tc
.dirfilter
< NUM_FILTER_MODES
)
755 if (quick_screen_quick(button
))
763 /* don't enter f3 from plugin browser */
764 if (*tc
.dirfilter
< NUM_FILTER_MODES
)
766 if (quick_screen_f3(ACTION_F3
))
774 case ACTION_TREE_HOTKEY
:
775 if (!global_settings
.hotkey_tree
)
779 case ACTION_STD_CONTEXT
:
781 bool hotkey
= button
== ACTION_TREE_HOTKEY
;
785 if (tc
.browse
->flags
& BROWSE_NO_CONTEXT_MENU
)
789 onplay_result
= onplay(NULL
, 0, curr_context
, hotkey
);
794 if (tagtree_get_attr(&tc
) == FILE_ATTR_AUDIO
)
796 attr
= FILE_ATTR_AUDIO
;
797 tagtree_get_filename(&tc
, buf
, sizeof(buf
));
800 attr
= ATTR_DIRECTORY
;
805 attr
= dircache
[tc
.selected_item
].attr
;
807 if (currdir
[1]) /* Not in / */
808 snprintf(buf
, sizeof buf
, "%s/%s",
810 dircache
[tc
.selected_item
].name
);
812 snprintf(buf
, sizeof buf
, "/%s",
813 dircache
[tc
.selected_item
].name
);
815 onplay_result
= onplay(buf
, attr
, curr_context
, hotkey
);
817 switch (onplay_result
)
819 case ONPLAY_MAINMENU
:
826 case ONPLAY_RELOAD_DIR
:
830 case ONPLAY_START_PLAY
:
843 /* The 'dir no longer valid' situation will be caught later
844 * by checking the showdir() result. */
849 if (default_event_handler(button
) == SYS_USB_CONNECTED
)
851 if(*tc
.dirfilter
> NUM_FILTER_MODES
)
852 /* leave sub-browsers after usb, doing otherwise
853 might be confusing to the user */
862 if (button
&& !IS_SYSEVENT(button
))
869 /* do we need to rescan dir? */
870 if (reload_dir
|| reload_root
||
871 lastfilter
!= *tc
.dirfilter
||
872 lastsortcase
!= global_settings
.sort_case
)
875 strcpy(currdir
, "/");
888 gui_synclist_select_item(&tree_lists
, 0);
889 gui_synclist_draw(&tree_lists
);
890 tc
.selected_item
= 0;
894 lastfilter
= *tc
.dirfilter
;
895 lastsortcase
= global_settings
.sort_case
;
900 return GO_TO_PREVIOUS
;
902 if (restore
|| reload_dir
) {
903 /* restore display */
904 numentries
= update_dir();
906 if (currdir
[1] && (numentries
< 0))
907 { /* not in root and reload failed */
908 reload_root
= true; /* try root */
916 bool create_playlist(void)
918 char filename
[MAX_PATH
];
920 snprintf(filename
, sizeof filename
, "%s.m3u8",
921 tc
.currdir
[1] ? tc
.currdir
: "/root");
922 splashf(0, "%s %s", str(LANG_CREATING
), filename
);
925 catalog_add_to_a_playlist(tc
.currdir
, ATTR_DIRECTORY
, true, filename
);
931 void browse_context_init(struct browse_context
*browse
,
932 int dirfilter
, unsigned flags
,
933 char *title
, enum themable_icons icon
,
934 const char *root
, const char *selected
)
936 browse
->dirfilter
= dirfilter
;
937 browse
->flags
= flags
;
938 browse
->callback_show_item
= NULL
;
939 browse
->title
= title
;
942 browse
->selected
= selected
;
947 #define NUM_TC_BACKUP 3
948 static struct tree_context backups
[NUM_TC_BACKUP
];
949 /* do not make backup if it is not recursive call */
950 static int backup_count
= -1;
951 int rockbox_browse(struct browse_context
*browse
)
953 static char current
[MAX_PATH
];
955 int dirfilter
= browse
->dirfilter
;
957 if (backup_count
>= NUM_TC_BACKUP
)
958 return GO_TO_PREVIOUS
;
959 if (backup_count
>= 0)
960 backups
[backup_count
] = tc
;
963 tc
.dirfilter
= &dirfilter
;
964 tc
.sort_dir
= global_settings
.sort_dir
;
967 if (*tc
.dirfilter
>= NUM_FILTER_MODES
)
972 tc
.selected_item
= 0;
974 strlcpy(tc
.currdir
, browse
->root
, sizeof(tc
.currdir
));
976 last_context
= curr_context
;
978 if (browse
->selected
)
980 snprintf(current
, sizeof(current
), "%s/%s",
981 browse
->root
, browse
->selected
);
982 set_current_file(current
);
983 /* set_current_file changes dirlevel, change it back */
987 ret_val
= dirbrowse();
988 curr_context
= last_context
;
992 if (dirfilter
!= SHOW_ID3DB
)
993 tc
.dirfilter
= &global_settings
.dirfilter
;
995 strcpy(current
, browse
->root
);
996 set_current_file(current
);
997 ret_val
= dirbrowse();
1000 if (backup_count
>= 0)
1001 tc
= backups
[backup_count
];
1005 void tree_mem_init(void)
1007 /* initialize tree context struct */
1008 memset(&tc
, 0, sizeof(tc
));
1009 tc
.dirfilter
= &global_settings
.dirfilter
;
1010 tc
.sort_dir
= global_settings
.sort_dir
;
1012 tc
.name_buffer_size
= AVERAGE_FILENAME_LENGTH
*
1013 global_settings
.max_files_in_dir
;
1014 tc
.name_buffer
= buffer_alloc(tc
.name_buffer_size
);
1016 tc
.dircache_count
= global_settings
.max_files_in_dir
;
1017 tc
.dircache
= buffer_alloc(global_settings
.max_files_in_dir
*
1018 sizeof(struct entry
));
1019 tree_get_filetypes(&filetypes
, &filetypes_count
);
1022 bool bookmark_play(char *resume_file
, int index
, int offset
, int seed
,
1026 char* suffix
= strrchr(resume_file
, '.');
1027 bool started
= false;
1029 if (suffix
!= NULL
&&
1030 (!strcasecmp(suffix
, ".m3u") || !strcasecmp(suffix
, ".m3u8")))
1032 /* Playlist playback */
1034 /* check that the file exists */
1035 if(!file_exists(resume_file
))
1038 slash
= strrchr(resume_file
,'/');
1048 if (playlist_create(cp
, slash
+1) != -1)
1050 if (global_settings
.playlist_shuffle
)
1051 playlist_shuffle(seed
, -1);
1052 playlist_start(index
,offset
);
1060 /* Directory playback */
1062 if (playlist_create(resume_file
, NULL
) != -1)
1064 char filename_buf
[MAX_PATH
+ 1];
1065 const char* peek_filename
;
1066 resume_directory(resume_file
);
1067 if (global_settings
.playlist_shuffle
)
1068 playlist_shuffle(seed
, -1);
1070 /* Check if the file is at the same spot in the directory,
1071 else search for it */
1072 peek_filename
= playlist_peek(index
, filename_buf
,
1073 sizeof(filename_buf
));
1075 if (peek_filename
== NULL
)
1077 /* playlist has shrunk, search from the top */
1079 peek_filename
= playlist_peek(index
, filename_buf
,
1080 sizeof(filename_buf
));
1081 if (peek_filename
== NULL
)
1085 if (strcmp(strrchr(peek_filename
, '/') + 1, filename
))
1087 for ( i
=0; i
< playlist_amount(); i
++ )
1089 peek_filename
= playlist_peek(i
, filename_buf
,
1090 sizeof(filename_buf
));
1092 if (peek_filename
== NULL
)
1095 if (!strcmp(strrchr(peek_filename
, '/') + 1, filename
))
1098 if (i
< playlist_amount())
1103 playlist_start(index
,offset
);
1113 static void say_filetype(int attr
)
1115 /* try to find a voice ID for the extension, if known */
1117 attr
&= FILE_ATTR_MASK
; /* file type */
1118 for (j
=0; j
<filetypes_count
; j
++)
1119 if (attr
== filetypes
[j
].tree_attr
)
1121 talk_id(filetypes
[j
].voiceclip
, true);
1126 static int ft_play_dirname(char* name
)
1128 #if CONFIG_CODEC != SWCODEC
1129 if (audio_status() & AUDIO_STATUS_PLAY
)
1133 if(talk_file(tc
.currdir
, name
, dir_thumbnail_name
, NULL
,
1136 if(global_settings
.talk_filetype
)
1137 talk_id(VOICE_DIR
, true);
1144 static void ft_play_filename(char *dir
, char *file
)
1146 #if CONFIG_CODEC != SWCODEC
1147 if (audio_status() & AUDIO_STATUS_PLAY
)
1151 if (strlen(file
) >= strlen(file_thumbnail_ext
)
1152 && strcasecmp(&file
[strlen(file
) - strlen(file_thumbnail_ext
)],
1153 file_thumbnail_ext
))
1154 /* file has no .talk extension */
1155 talk_file(dir
, NULL
, file
, file_thumbnail_ext
,
1158 /* it already is a .talk file, play this directly, but prefix it. */
1159 talk_file(dir
, NULL
, file
, NULL
,
1160 TALK_IDARRAY(LANG_VOICE_DIR_HOVER
), false);
1163 /* These two functions are called by the USB and shutdown handlers */
1164 void tree_flush(void)
1166 #ifdef HAVE_TAGCACHE
1167 tagcache_shutdown();
1170 #ifdef HAVE_TC_RAMCACHE
1171 tagcache_unload_ramcache();
1174 #ifdef HAVE_DIRCACHE
1176 int old_val
= global_status
.dircache_size
;
1177 if (global_settings
.dircache
)
1179 if (!dircache_is_initializing())
1180 global_status
.dircache_size
= dircache_get_cache_size();
1181 # ifdef HAVE_EEPROM_SETTINGS
1182 if (firmware_settings
.initialized
)
1189 global_status
.dircache_size
= 0;
1191 if (old_val
!= global_status
.dircache_size
)
1197 void tree_restore(void)
1199 #ifdef HAVE_EEPROM_SETTINGS
1200 firmware_settings
.disk_clean
= false;
1203 #ifdef HAVE_TC_RAMCACHE
1204 remove(TAGCACHE_STATEFILE
);
1207 #ifdef HAVE_DIRCACHE
1208 remove(DIRCACHE_FILE
);
1209 if (global_settings
.dircache
)
1211 /* Print "Scanning disk..." to the display. */
1212 splash(0, str(LANG_SCANNING_DISK
));
1214 dircache_build(global_status
.dircache_size
);
1217 #ifdef HAVE_TAGCACHE
1218 tagcache_start_scan();