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"
49 #include "core_alloc.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 char lastfile
[MAX_PATH
];
92 static char lastdir
[MAX_PATH
];
94 static int lasttable
, lastextra
, lastfirstpos
;
97 static bool reload_dir
= false;
99 static bool start_wps
= false;
100 static int curr_context
= false;/* id3db or tree*/
102 static int dirbrowse(void);
103 static int ft_play_dirname(char* name
);
104 static void ft_play_filename(char *dir
, char *file
);
105 static void say_filetype(int attr
);
107 struct entry
* tree_get_entries(struct tree_context
*t
)
109 return core_get_data(t
->cache
.entries_handle
);
112 struct entry
* tree_get_entry_at(struct tree_context
*t
, int index
)
114 struct entry
* entries
= tree_get_entries(t
);
115 return &entries
[index
];
119 static const char* tree_get_filename(int selected_item
, void *data
,
120 char *buffer
, size_t buffer_len
)
122 struct tree_context
* local_tc
=(struct tree_context
*)data
;
125 bool stripit
= false;
127 bool id3db
= *(local_tc
->dirfilter
) == SHOW_ID3DB
;
131 return tagtree_get_entry_name(&tc
, selected_item
, buffer
, buffer_len
);
136 struct entry
* e
= tree_get_entry_at(local_tc
, selected_item
);
141 if(!(attr
& ATTR_DIRECTORY
))
143 switch(global_settings
.show_filename_ext
)
146 /* show file extension: off */
150 /* show file extension: on */
153 /* show file extension: only unknown types */
154 stripit
= filetype_supported(attr
);
158 /* show file extension: only when viewing all */
159 stripit
= (*(local_tc
->dirfilter
) != SHOW_ID3DB
) &&
160 (*(local_tc
->dirfilter
) != SHOW_ALL
);
167 return(strip_extension(buffer
, buffer_len
, name
));
172 #ifdef HAVE_LCD_COLOR
173 static int tree_get_filecolor(int selected_item
, void * data
)
175 if (*tc
.dirfilter
== SHOW_ID3DB
)
177 struct tree_context
* local_tc
=(struct tree_context
*)data
;
178 struct entry
* e
= tree_get_entry_at(local_tc
, selected_item
);
179 return filetype_get_color(e
->name
, e
->attr
);
183 static enum themable_icons
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
* e
= tree_get_entry_at(local_tc
, selected_item
);
195 return filetype_get_icon(e
->attr
);
199 static int tree_voice_cb(int selected_item
, void * data
)
201 struct tree_context
* local_tc
=(struct tree_context
*)data
;
205 bool id3db
= *(local_tc
->dirfilter
) == SHOW_ID3DB
;
206 char buf
[AVERAGE_FILENAME_LENGTH
*2];
210 attr
= tagtree_get_attr(local_tc
);
211 name
= tagtree_get_entry_name(local_tc
, selected_item
, buf
, sizeof(buf
));
216 struct entry
* e
= tree_get_entry_at(local_tc
, selected_item
);
220 bool is_dir
= (attr
& ATTR_DIRECTORY
);
221 bool did_clip
= false;
222 /* First the .talk clip case */
225 if(global_settings
.talk_dir_clip
)
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 ft_play_filename(local_tc
->currdir
, name
);
241 /* say the number or spell if required or as a fallback */
242 switch (is_dir
? global_settings
.talk_dir
: global_settings
.talk_file
)
244 case 1: /* as numbers */
245 talk_id(is_dir
? VOICE_DIR
: VOICE_FILE
, false);
246 talk_number(selected_item
+1 - (is_dir
? 0 : local_tc
->dirsindir
),
248 if(global_settings
.talk_filetype
249 && !is_dir
&& *local_tc
->dirfilter
< NUM_FILTER_MODES
)
252 case 2: /* spelled */
254 if(global_settings
.talk_filetype
)
257 talk_id(VOICE_DIR
, true);
258 else if(*local_tc
->dirfilter
< NUM_FILTER_MODES
)
261 talk_spell(name
, true);
268 bool check_rockboxdir(void)
270 if(!dir_exists(ROCKBOX_DIR
))
271 { /* No need to localise this message.
272 If .rockbox is missing, it wouldn't work anyway */
275 screens
[i
].clear_display();
276 splash(HZ
*2, "No .rockbox directory");
278 screens
[i
].clear_display();
279 splash(HZ
*2, "Installation incomplete");
285 /* do this really late in the init sequence */
286 void tree_gui_init(void)
290 strcpy(tc
.currdir
, "/");
292 #ifdef HAVE_LCD_CHARCELLS
295 screens
[i
].double_height(false);
297 #ifdef HAVE_BUTTONBAR
298 gui_buttonbar_init(&tree_buttonbar
);
299 /* since archos only have one screen, no need to create more than that */
300 gui_buttonbar_set_display(&tree_buttonbar
, &(screens
[SCREEN_MAIN
]) );
302 gui_synclist_init(&tree_lists
, &tree_get_filename
, &tc
, false, 1, NULL
);
303 gui_synclist_set_voice_callback(&tree_lists
, tree_voice_cb
);
304 gui_synclist_set_icon_callback(&tree_lists
,
305 global_settings
.show_icons
?&tree_get_fileicon
:NULL
);
306 #ifdef HAVE_LCD_COLOR
307 gui_synclist_set_color_callback(&tree_lists
, &tree_get_filecolor
);
312 /* drawer function for the GUI_EVENT_REDRAW callback */
313 void tree_drawlists(void)
315 /* band-aid to fix the bar/list redrawing properly after leaving a plugin */
316 send_event(GUI_EVENT_THEME_CHANGED
, NULL
);
318 gui_synclist_draw(&tree_lists
);
322 struct tree_context
* tree_get_context(void)
328 * Returns the position of a given file in the current directory
329 * returns -1 if not found
331 static int tree_get_file_position(char * filename
)
336 /* use lastfile to determine the selected item (default=0) */
337 for (i
=0; i
< tc
.filesindir
; i
++)
339 e
= tree_get_entry_at(&tc
, i
);
340 if (!strcasecmp(e
->name
, filename
))
343 return(-1);/* no file can match, returns undefined */
347 * Called when a new dir is loaded (for example when returning from other apps ...)
348 * also completely redraws the tree
350 static int update_dir(void)
352 bool changed
= false;
354 bool id3db
= *tc
.dirfilter
== SHOW_ID3DB
;
355 /* Checks for changes */
357 if (tc
.currtable
!= lasttable
||
358 tc
.currextra
!= lastextra
||
359 tc
.firstpos
!= lastfirstpos
||
362 if (tagtree_load(&tc
) < 0)
365 lasttable
= tc
.currtable
;
366 lastextra
= tc
.currextra
;
367 lastfirstpos
= tc
.firstpos
;
374 /* if the tc.currdir has been changed, reload it ...*/
375 if (strncmp(tc
.currdir
, lastdir
, sizeof(lastdir
)) || reload_dir
)
377 if (ft_load(&tc
, NULL
) < 0)
379 strcpy(lastdir
, tc
.currdir
);
383 /* if selected item is undefined */
384 if (tc
.selected_item
== -1)
386 /* use lastfile to determine the selected item */
387 tc
.selected_item
= tree_get_file_position(lastfile
);
389 /* If the file doesn't exists, select the first one (default) */
390 if(tc
.selected_item
< 0)
391 tc
.selected_item
= 0;
402 splash(HZ
, ID2P(LANG_SHOWDIR_BUFFER_FULL
));
408 #ifdef HAVE_LCD_BITMAP
409 if (global_settings
.show_path_in_browser
== SHOW_PATH_FULL
410 || global_settings
.show_path_in_browser
== SHOW_PATH_CURRENT
)
412 gui_synclist_set_title(&tree_lists
, tagtree_get_title(&tc
),
413 filetype_get_icon(ATTR_DIRECTORY
));
417 /* Must clear the title as the list is reused */
418 gui_synclist_set_title(&tree_lists
, NULL
, NOICON
);
425 #ifdef HAVE_LCD_BITMAP
426 if (tc
.browse
&& tc
.browse
->title
)
428 int icon
= tc
.browse
->icon
;
430 icon
= filetype_get_icon(ATTR_DIRECTORY
);
431 gui_synclist_set_title(&tree_lists
, tc
.browse
->title
, icon
);
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
,
461 global_settings
.show_icons
?tree_get_fileicon
:NULL
);
462 if( tc
.selected_item
>= tc
.filesindir
)
463 tc
.selected_item
=tc
.filesindir
-1;
465 gui_synclist_select_item(&tree_lists
, tc
.selected_item
);
466 #ifdef HAVE_BUTTONBAR
467 if (global_settings
.buttonbar
) {
468 if (*tc
.dirfilter
< NUM_FILTER_MODES
)
469 gui_buttonbar_set(&tree_buttonbar
, str(LANG_SYSFONT_DIRBROWSE_F1
),
470 str(LANG_SYSFONT_DIRBROWSE_F2
),
471 str(LANG_SYSFONT_DIRBROWSE_F3
));
473 gui_buttonbar_set(&tree_buttonbar
, "<<<", "", "");
474 gui_buttonbar_draw(&tree_buttonbar
);
477 gui_synclist_draw(&tree_lists
);
478 gui_synclist_speak_item(&tree_lists
);
479 return tc
.filesindir
;
482 /* load tracks from specified directory to resume play */
483 void resume_directory(const char *dir
)
485 int dirfilter
= *tc
.dirfilter
;
488 bool id3db
= *tc
.dirfilter
== SHOW_ID3DB
;
490 /* make sure the dirfilter is sane. The only time it should be possible
491 * thats its not is when resume playlist is called from a plugin
496 *tc
.dirfilter
= global_settings
.dirfilter
;
497 ret
= ft_load(&tc
, dir
);
498 *tc
.dirfilter
= dirfilter
;
503 ft_build_playlist(&tc
, 0);
511 /* Returns the current working directory and also writes cwd to buf if
512 non-NULL. In case of error, returns NULL. */
513 char *getcwd(char *buf
, getcwd_size_t size
)
519 if ((getcwd_size_t
)strlcpy(buf
, tc
.currdir
, size
) < size
)
522 /* size == 0, or truncation in strlcpy */
526 /* Force a reload of the directory next time directory browser is called */
527 void reload_directory(void)
532 char* get_current_file(char* buffer
, size_t buffer_len
)
535 /* in ID3DB mode it is a bad idea to call this function */
536 /* (only happens with `follow playlist') */
537 if( *tc
.dirfilter
== SHOW_ID3DB
)
541 struct entry
* e
= tree_get_entry_at(&tc
, tc
.selected_item
);
542 if (getcwd(buffer
, buffer_len
))
546 if (buffer
[strlen(buffer
)-1] != '/')
547 strlcat(buffer
, "/", buffer_len
);
548 if (strlcat(buffer
, e
->name
, buffer_len
) >= buffer_len
)
556 /* Allow apps to change our dirfilter directly (required for sub browsers)
557 if they're suddenly going to become a file browser for example */
558 void set_dirfilter(int l_dirfilter
)
560 *tc
.dirfilter
= l_dirfilter
;
563 /* Selects a file and update tree context properly */
564 void set_current_file(const char *path
)
570 /* in ID3DB mode it is a bad idea to call this function */
571 /* (only happens with `follow playlist') */
572 if( *tc
.dirfilter
== SHOW_ID3DB
)
576 /* separate directory from filename */
577 /* gets the directory's name and put it into tc.currdir */
578 name
= strrchr(path
+1,'/');
581 strlcpy(tc
.currdir
, path
, name
- path
+ 1);
586 strcpy(tc
.currdir
, "/");
590 strcpy(lastfile
, name
);
593 /* If we changed dir we must recalculate the dirlevel
594 and adjust the selected history properly */
595 if (strncmp(tc
.currdir
,lastdir
,sizeof(lastdir
)))
598 tc
.selected_item_history
[tc
.dirlevel
] = -1;
600 /* use '/' to calculate dirlevel */
601 for (i
= 1; path
[i
] != '\0'; i
++)
606 tc
.selected_item_history
[tc
.dirlevel
] = -1;
610 if (ft_load(&tc
, NULL
) >= 0)
612 tc
.selected_item
= tree_get_file_position(lastfile
);
617 /* main loop, handles key events */
618 static int dirbrowse(void)
623 #ifdef HAVE_LCD_BITMAP
626 bool reload_root
= false;
627 int lastfilter
= *tc
.dirfilter
;
628 bool lastsortcase
= global_settings
.sort_case
;
629 bool exit_func
= false;
631 char* currdir
= tc
.currdir
; /* just a shortcut */
633 bool id3db
= *tc
.dirfilter
== SHOW_ID3DB
;
636 curr_context
=CONTEXT_ID3DB
;
639 curr_context
=CONTEXT_TREE
;
640 if (tc
.selected_item
< 0)
641 tc
.selected_item
= 0;
650 numentries
= update_dir();
652 if (numentries
== -1)
653 return GO_TO_PREVIOUS
; /* currdir is not a directory */
655 if (*tc
.dirfilter
> NUM_FILTER_MODES
&& numentries
==0)
657 splash(HZ
*2, ID2P(LANG_NO_FILES
));
658 return GO_TO_PREVIOUS
; /* No files found for rockbox_browse() */
661 gui_synclist_draw(&tree_lists
);
663 bool restore
= false;
665 tc
.dirlevel
= 0; /* shouldnt be needed.. this code needs work! */
667 button
= get_action(CONTEXT_TREE
,
668 list_do_action_timeout(&tree_lists
, HZ
/2));
669 #ifdef HAVE_LCD_BITMAP
672 gui_synclist_do_button(&tree_lists
, &button
,LIST_WRAP_UNLESS_HELD
);
673 tc
.selected_item
= gui_synclist_get_sel_pos(&tree_lists
);
676 /* nothing to do if no files to display */
677 if ( numentries
== 0 )
680 short attr
= tree_get_entry_at(&tc
, tc
.selected_item
)->attr
;
681 if ((tc
.browse
->flags
& BROWSE_SELECTONLY
) &&
682 !(attr
& ATTR_DIRECTORY
))
684 tc
.browse
->flags
|= BROWSE_SELECTED
;
685 get_current_file(tc
.browse
->buf
, tc
.browse
->bufsize
);
686 return GO_TO_PREVIOUS
;
690 switch (id3db
?tagtree_enter(&tc
):ft_enter(&tc
))
692 switch (ft_enter(&tc
))
695 case GO_TO_FILEBROWSER
: reload_dir
= true; break;
702 case GO_TO_ROOT
: exit_func
= true; break;
708 case ACTION_STD_CANCEL
:
709 if (*tc
.dirfilter
> NUM_FILTER_MODES
&& tc
.dirlevel
< 1) {
713 if ((*tc
.dirfilter
== SHOW_ID3DB
&& tc
.dirlevel
== 0) ||
714 ((*tc
.dirfilter
!= SHOW_ID3DB
&& !strcmp(currdir
,"/"))))
716 #ifdef HAVE_LCD_BITMAP /* charcell doesnt have ACTION_TREE_PGLEFT so this isnt needed */
717 if (oldbutton
== ACTION_TREE_PGLEFT
)
729 if (ft_exit(&tc
) == 3)
735 case ACTION_TREE_STOP
:
736 if (list_stop_handler())
740 case ACTION_STD_MENU
:
744 #ifdef HAVE_RECORDING
746 return GO_TO_RECSCREEN
;
749 case ACTION_TREE_WPS
:
750 return GO_TO_PREVIOUS_MUSIC
;
752 #ifdef HAVE_QUICKSCREEN
753 case ACTION_STD_QUICKSCREEN
:
754 /* don't enter f2 from plugin browser */
755 if (*tc
.dirfilter
< NUM_FILTER_MODES
)
757 if (quick_screen_quick(button
))
765 /* don't enter f3 from plugin browser */
766 if (*tc
.dirfilter
< NUM_FILTER_MODES
)
768 if (quick_screen_f3(ACTION_F3
))
776 case ACTION_TREE_HOTKEY
:
777 if (!global_settings
.hotkey_tree
)
781 case ACTION_STD_CONTEXT
:
783 bool hotkey
= button
== ACTION_TREE_HOTKEY
;
787 if (tc
.browse
->flags
& BROWSE_NO_CONTEXT_MENU
)
791 onplay_result
= onplay(NULL
, 0, curr_context
, hotkey
);
796 if (tagtree_get_attr(&tc
) == FILE_ATTR_AUDIO
)
798 attr
= FILE_ATTR_AUDIO
;
799 tagtree_get_filename(&tc
, buf
, sizeof(buf
));
802 attr
= ATTR_DIRECTORY
;
807 struct entry
*entry
= tree_get_entry_at(&tc
, tc
.selected_item
);
810 if (currdir
[1]) /* Not in / */
811 snprintf(buf
, sizeof buf
, "%s/%s",
812 currdir
, entry
->name
);
814 snprintf(buf
, sizeof buf
, "/%s", entry
->name
);
816 onplay_result
= onplay(buf
, attr
, curr_context
, hotkey
);
818 switch (onplay_result
)
820 case ONPLAY_MAINMENU
:
827 case ONPLAY_RELOAD_DIR
:
831 case ONPLAY_START_PLAY
:
844 /* The 'dir no longer valid' situation will be caught later
845 * by checking the showdir() result. */
850 if (default_event_handler(button
) == SYS_USB_CONNECTED
)
852 if(*tc
.dirfilter
> NUM_FILTER_MODES
)
853 /* leave sub-browsers after usb, doing otherwise
854 might be confusing to the user */
863 if (button
&& !IS_SYSEVENT(button
))
870 /* do we need to rescan dir? */
871 if (reload_dir
|| reload_root
||
872 lastfilter
!= *tc
.dirfilter
||
873 lastsortcase
!= global_settings
.sort_case
)
876 strcpy(currdir
, "/");
889 gui_synclist_select_item(&tree_lists
, 0);
890 gui_synclist_draw(&tree_lists
);
891 tc
.selected_item
= 0;
895 lastfilter
= *tc
.dirfilter
;
896 lastsortcase
= global_settings
.sort_case
;
901 return GO_TO_PREVIOUS
;
903 if (restore
|| reload_dir
) {
904 /* restore display */
905 numentries
= update_dir();
907 if (currdir
[1] && (numentries
< 0))
908 { /* not in root and reload failed */
909 reload_root
= true; /* try root */
917 bool create_playlist(void)
919 char filename
[MAX_PATH
];
922 snprintf(filename
, sizeof filename
, "%s.m3u8", tc
.currdir
);
924 snprintf(filename
, sizeof filename
, "%s/all.m3u8",
925 catalog_get_directory());
928 if (kbd_input(filename
, MAX_PATH
))
930 splashf(0, "%s %s", str(LANG_CREATING
), filename
);
933 catalog_add_to_a_playlist(tc
.currdir
, ATTR_DIRECTORY
, true, filename
);
939 void browse_context_init(struct browse_context
*browse
,
940 int dirfilter
, unsigned flags
,
941 char *title
, enum themable_icons icon
,
942 const char *root
, const char *selected
)
944 browse
->dirfilter
= dirfilter
;
945 browse
->flags
= flags
;
946 browse
->callback_show_item
= NULL
;
947 browse
->title
= title
;
950 browse
->selected
= selected
;
955 #define NUM_TC_BACKUP 3
956 static struct tree_context backups
[NUM_TC_BACKUP
];
957 /* do not make backup if it is not recursive call */
958 static int backup_count
= -1;
959 int rockbox_browse(struct browse_context
*browse
)
961 static char current
[MAX_PATH
];
963 int dirfilter
= browse
->dirfilter
;
965 if (backup_count
>= NUM_TC_BACKUP
)
966 return GO_TO_PREVIOUS
;
967 if (backup_count
>= 0)
968 backups
[backup_count
] = tc
;
971 tc
.dirfilter
= &dirfilter
;
972 tc
.sort_dir
= global_settings
.sort_dir
;
975 if (*tc
.dirfilter
>= NUM_FILTER_MODES
)
980 tc
.selected_item
= 0;
982 strlcpy(tc
.currdir
, browse
->root
, sizeof(tc
.currdir
));
984 last_context
= curr_context
;
986 if (browse
->selected
)
988 snprintf(current
, sizeof(current
), "%s/%s",
989 browse
->root
, browse
->selected
);
990 set_current_file(current
);
991 /* set_current_file changes dirlevel, change it back */
995 ret_val
= dirbrowse();
996 curr_context
= last_context
;
1000 if (dirfilter
!= SHOW_ID3DB
)
1001 tc
.dirfilter
= &global_settings
.dirfilter
;
1003 strcpy(current
, browse
->root
);
1004 set_current_file(current
);
1005 ret_val
= dirbrowse();
1008 if (backup_count
>= 0)
1009 tc
= backups
[backup_count
];
1013 static int move_callback(int handle
, void* current
, void* new)
1015 struct tree_cache
* cache
= &tc
.cache
;
1016 if (cache
->lock_count
> 0)
1017 return BUFLIB_CB_CANNOT_MOVE
;
1019 size_t diff
= new - current
;
1020 /* FIX_PTR makes sure to not accidentally update static allocations */
1021 #define FIX_PTR(x) \
1022 { if ((void*)x >= current && (void*)x < (current+cache->name_buffer_size)) x+= diff; }
1024 if (handle
== cache
->name_buffer_handle
)
1025 { /* update entry structs, *even if they are struct tagentry */
1026 struct entry
*this = core_get_data(cache
->entries_handle
);
1027 struct entry
*last
= this + cache
->max_entries
;
1028 for(; this < last
; this++)
1029 FIX_PTR(this->name
);
1031 /* nothing to do if entries moved */
1032 return BUFLIB_CB_OK
;
1035 static struct buflib_callbacks ops
= {
1036 .move_callback
= move_callback
,
1037 .shrink_callback
= NULL
,
1040 void tree_mem_init(void)
1042 /* initialize tree context struct */
1043 struct tree_cache
* cache
= &tc
.cache
;
1044 memset(&tc
, 0, sizeof(tc
));
1045 tc
.dirfilter
= &global_settings
.dirfilter
;
1046 tc
.sort_dir
= global_settings
.sort_dir
;
1048 cache
->name_buffer_size
= AVERAGE_FILENAME_LENGTH
*
1049 global_settings
.max_files_in_dir
;
1050 cache
->name_buffer_handle
= core_alloc_ex("tree names",
1051 cache
->name_buffer_size
,
1054 cache
->max_entries
= global_settings
.max_files_in_dir
;
1055 cache
->entries_handle
= core_alloc_ex("tree entries",
1056 cache
->max_entries
*(sizeof(struct entry
)),
1058 tree_get_filetypes(&filetypes
, &filetypes_count
);
1061 bool bookmark_play(char *resume_file
, int index
, int offset
, int seed
,
1065 char* suffix
= strrchr(resume_file
, '.');
1066 bool started
= false;
1068 if (suffix
!= NULL
&&
1069 (!strcasecmp(suffix
, ".m3u") || !strcasecmp(suffix
, ".m3u8")))
1071 /* Playlist playback */
1073 /* check that the file exists */
1074 if(!file_exists(resume_file
))
1077 slash
= strrchr(resume_file
,'/');
1087 if (playlist_create(cp
, slash
+1) != -1)
1089 if (global_settings
.playlist_shuffle
)
1090 playlist_shuffle(seed
, -1);
1091 playlist_start(index
,offset
);
1099 /* Directory playback */
1101 if (playlist_create(resume_file
, NULL
) != -1)
1103 char filename_buf
[MAX_PATH
+ 1];
1104 const char* peek_filename
;
1105 resume_directory(resume_file
);
1106 if (global_settings
.playlist_shuffle
)
1107 playlist_shuffle(seed
, -1);
1109 /* Check if the file is at the same spot in the directory,
1110 else search for it */
1111 peek_filename
= playlist_peek(index
, filename_buf
,
1112 sizeof(filename_buf
));
1114 if (peek_filename
== NULL
)
1116 /* playlist has shrunk, search from the top */
1118 peek_filename
= playlist_peek(index
, filename_buf
,
1119 sizeof(filename_buf
));
1120 if (peek_filename
== NULL
)
1124 if (strcmp(strrchr(peek_filename
, '/') + 1, filename
))
1126 for ( i
=0; i
< playlist_amount(); i
++ )
1128 peek_filename
= playlist_peek(i
, filename_buf
,
1129 sizeof(filename_buf
));
1131 if (peek_filename
== NULL
)
1134 if (!strcmp(strrchr(peek_filename
, '/') + 1, filename
))
1137 if (i
< playlist_amount())
1142 playlist_start(index
,offset
);
1152 static void say_filetype(int attr
)
1154 /* try to find a voice ID for the extension, if known */
1156 attr
&= FILE_ATTR_MASK
; /* file type */
1157 for (j
=0; j
<filetypes_count
; j
++)
1158 if (attr
== filetypes
[j
].tree_attr
)
1160 talk_id(filetypes
[j
].voiceclip
, true);
1165 static int ft_play_dirname(char* name
)
1167 #if CONFIG_CODEC != SWCODEC
1168 if (audio_status() & AUDIO_STATUS_PLAY
)
1172 if(talk_file(tc
.currdir
, name
, dir_thumbnail_name
, NULL
,
1175 if(global_settings
.talk_filetype
)
1176 talk_id(VOICE_DIR
, true);
1183 static void ft_play_filename(char *dir
, char *file
)
1185 #if CONFIG_CODEC != SWCODEC
1186 if (audio_status() & AUDIO_STATUS_PLAY
)
1190 if (strlen(file
) >= strlen(file_thumbnail_ext
)
1191 && strcasecmp(&file
[strlen(file
) - strlen(file_thumbnail_ext
)],
1192 file_thumbnail_ext
))
1193 /* file has no .talk extension */
1194 talk_file(dir
, NULL
, file
, file_thumbnail_ext
,
1197 /* it already is a .talk file, play this directly, but prefix it. */
1198 talk_file(dir
, NULL
, file
, NULL
,
1199 TALK_IDARRAY(LANG_VOICE_DIR_HOVER
), false);
1202 /* These two functions are called by the USB and shutdown handlers */
1203 void tree_flush(void)
1205 #ifdef HAVE_TAGCACHE
1206 tagcache_shutdown();
1209 #ifdef HAVE_TC_RAMCACHE
1210 tagcache_unload_ramcache();
1213 #ifdef HAVE_DIRCACHE
1215 int old_val
= global_status
.dircache_size
;
1216 if (global_settings
.dircache
)
1218 if (!dircache_is_initializing())
1219 global_status
.dircache_size
= dircache_get_cache_size();
1220 # ifdef HAVE_EEPROM_SETTINGS
1221 if (firmware_settings
.initialized
)
1228 global_status
.dircache_size
= 0;
1230 if (old_val
!= global_status
.dircache_size
)
1236 void tree_restore(void)
1238 #ifdef HAVE_EEPROM_SETTINGS
1239 firmware_settings
.disk_clean
= false;
1242 #ifdef HAVE_TC_RAMCACHE
1243 remove(TAGCACHE_STATEFILE
);
1246 #ifdef HAVE_DIRCACHE
1247 remove(DIRCACHE_FILE
);
1248 if (global_settings
.dircache
)
1250 /* Print "Scanning disk..." to the display. */
1251 splash(0, str(LANG_SCANNING_DISK
));
1253 dircache_build(global_status
.dircache_size
);
1256 #ifdef HAVE_TAGCACHE
1257 tagcache_start_scan();