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_filenumber(int pos
, int attr
);
115 static int ft_play_dirname(char* name
);
116 static void ft_play_filename(char *dir
, char *file
);
119 * removes the extension of filename (if it doesn't start with a .)
120 * puts the result in buffer
122 static char * strip_extension(char * filename
, char * buffer
)
125 char * dot
=strrchr(filename
, '.');
126 if(dot
!=0 && filename
[0]!='.')
128 dotpos
= dot
-filename
;
129 strncpy(buffer
, filename
, dotpos
);
137 static char * tree_get_filename(int selected_item
, void * data
, char *buffer
)
139 struct tree_context
* local_tc
=(struct tree_context
*)data
;
142 bool stripit
= false;
144 bool id3db
= *(local_tc
->dirfilter
) == SHOW_ID3DB
;
148 return tagtree_get_entry(&tc
, selected_item
)->name
;
153 struct entry
* dc
= local_tc
->dircache
;
154 struct entry
* e
= &dc
[selected_item
];
159 if(!(attr
& ATTR_DIRECTORY
))
161 switch(global_settings
.show_filename_ext
)
164 /* show file extension: off */
168 /* show file extension: on */
171 /* show file extension: only unknown types */
172 stripit
= filetype_supported(attr
);
176 /* show file extension: only when viewing all */
177 stripit
= (*(local_tc
->dirfilter
) != SHOW_ID3DB
) &&
178 (*(local_tc
->dirfilter
) != SHOW_ALL
);
185 return(strip_extension(name
, buffer
));
190 #ifdef HAVE_LCD_COLOR
191 static int tree_get_filecolor(int selected_item
, void * data
)
193 if (*tc
.dirfilter
== SHOW_ID3DB
)
195 struct tree_context
* local_tc
=(struct tree_context
*)data
;
196 struct entry
* dc
= local_tc
->dircache
;
197 struct entry
* e
= &dc
[selected_item
];
198 return filetype_get_color(e
->name
, e
->attr
);
202 static int tree_get_fileicon(int selected_item
, void * data
)
204 struct tree_context
* local_tc
=(struct tree_context
*)data
;
206 bool id3db
= *(local_tc
->dirfilter
) == SHOW_ID3DB
;
208 return tagtree_get_icon(&tc
);
213 struct entry
* dc
= local_tc
->dircache
;
214 struct entry
* e
= &dc
[selected_item
];
215 return filetype_get_icon(e
->attr
);
219 bool check_rockboxdir(void)
221 DIR *dir
= opendir(ROCKBOX_DIR
);
223 { /* No need to localise this message.
224 If .rockbox is missing, it wouldn't work anyway */
227 screens
[i
].clear_display();
228 gui_syncsplash(HZ
*2, "No .rockbox directory");
230 screens
[i
].clear_display();
231 gui_syncsplash(HZ
*2, "Installation incomplete");
238 /* do this really late in the init sequence */
239 void tree_gui_init(void)
241 gui_sync_wps_screen_init();
245 strcpy(tc
.currdir
, "/");
247 #ifdef HAVE_LCD_CHARCELLS
250 screens
[i
].double_height(false);
253 gui_buttonbar_init(&tree_buttonbar
);
254 /* since archos only have one screen, no need to create more than that */
255 gui_buttonbar_set_display(&tree_buttonbar
, &(screens
[SCREEN_MAIN
]) );
257 gui_synclist_init(&tree_lists
, &tree_get_filename
, &tc
, false, 1);
258 gui_synclist_set_icon_callback(&tree_lists
, &tree_get_fileicon
);
259 #ifdef HAVE_LCD_COLOR
260 gui_list_set_color_callback(&tree_lists
.gui_list
[SCREEN_MAIN
],
261 &tree_get_filecolor
);
267 struct tree_context
* tree_get_context(void)
272 /* talkbox hovering delay, to avoid immediate disk activity */
273 #define HOVER_DELAY (HZ/2)
275 * Returns the position of a given file in the current directory
276 * returns -1 if not found
278 static int tree_get_file_position(char * filename
)
282 /* use lastfile to determine the selected item (default=0) */
283 for (i
=0; i
< tc
.filesindir
; i
++)
285 struct entry
* dc
= tc
.dircache
;
286 struct entry
* e
= &dc
[i
];
287 if (!strcasecmp(e
->name
, filename
))
290 return(-1);/* no file can match, returns undefined */
294 * Called when a new dir is loaded (for example when returning from other apps ...)
295 * also completely redraws the tree
297 static int update_dir(void)
299 bool changed
= false;
301 bool id3db
= *tc
.dirfilter
== SHOW_ID3DB
;
302 /* Checks for changes */
304 if (tc
.currtable
!= lasttable
||
305 tc
.currextra
!= lastextra
||
306 tc
.firstpos
!= lastfirstpos
||
309 if (tagtree_load(&tc
) < 0)
312 lasttable
= tc
.currtable
;
313 lastextra
= tc
.currextra
;
314 lastfirstpos
= tc
.firstpos
;
321 /* if the tc.currdir has been changed, reload it ...*/
322 if (strncmp(tc
.currdir
, lastdir
, sizeof(lastdir
)) || reload_dir
) {
324 if (ft_load(&tc
, NULL
) < 0)
326 strcpy(lastdir
, tc
.currdir
);
330 /* if selected item is undefined */
331 if (tc
.selected_item
== -1)
333 /* use lastfile to determine the selected item */
334 tc
.selected_item
= tree_get_file_position(lastfile
);
336 /* If the file doesn't exists, select the first one (default) */
337 if(tc
.selected_item
< 0)
338 tc
.selected_item
= 0;
348 tc
.filesindir
== global_settings
.max_files_in_dir
) )
350 gui_syncsplash(HZ
, ID2P(LANG_SHOWDIR_BUFFER_FULL
));
356 if (global_settings
.show_path_in_browser
== SHOW_PATH_FULL
357 || global_settings
.show_path_in_browser
== SHOW_PATH_CURRENT
)
359 gui_synclist_set_title(&tree_lists
, tagtree_get_title(&tc
),
360 filetype_get_icon(ATTR_DIRECTORY
));
364 /* Must clear the title as the list is reused */
365 gui_synclist_set_title(&tree_lists
, NULL
, NOICON
);
371 if (global_settings
.show_path_in_browser
&&
372 *(tc
.dirfilter
) == SHOW_PLUGINS
)
375 if (!strcmp(tc
.currdir
, PLUGIN_GAMES_DIR
))
376 title
= str(LANG_PLUGIN_GAMES
);
377 else if (!strcmp(tc
.currdir
, PLUGIN_APPS_DIR
))
378 title
= str(LANG_PLUGIN_APPS
);
379 else if (!strcmp(tc
.currdir
, PLUGIN_DEMOS_DIR
))
380 title
= str(LANG_PLUGIN_DEMOS
);
381 else title
= str(LANG_PLUGINS
);
382 gui_synclist_set_title(&tree_lists
, title
, Icon_Plugin
);
384 else if (global_settings
.show_path_in_browser
== SHOW_PATH_FULL
)
386 gui_synclist_set_title(&tree_lists
, tc
.currdir
,
387 filetype_get_icon(ATTR_DIRECTORY
));
389 else if (global_settings
.show_path_in_browser
== SHOW_PATH_CURRENT
)
391 char *title
= strrchr(tc
.currdir
, '/') + 1;
394 /* Display "Files" for the root dir */
395 gui_synclist_set_title(&tree_lists
, str(LANG_DIR_BROWSER
),
396 filetype_get_icon(ATTR_DIRECTORY
));
399 gui_synclist_set_title(&tree_lists
, title
,
400 filetype_get_icon(ATTR_DIRECTORY
));
404 /* Must clear the title as the list is reused */
405 gui_synclist_set_title(&tree_lists
, NULL
, NOICON
);
409 gui_synclist_set_nb_items(&tree_lists
, tc
.filesindir
);
410 gui_synclist_set_icon_callback(&tree_lists
, tree_get_fileicon
);
411 if( tc
.selected_item
>= tc
.filesindir
)
412 tc
.selected_item
=tc
.filesindir
-1;
414 gui_synclist_select_item(&tree_lists
, tc
.selected_item
);
416 if (global_settings
.buttonbar
) {
417 if (*tc
.dirfilter
< NUM_FILTER_MODES
)
418 gui_buttonbar_set(&tree_buttonbar
, str(LANG_SYSFONT_DIRBROWSE_F1
),
419 str(LANG_SYSFONT_DIRBROWSE_F2
),
420 str(LANG_SYSFONT_DIRBROWSE_F3
));
422 gui_buttonbar_set(&tree_buttonbar
, "<<<", "", "");
423 gui_buttonbar_draw(&tree_buttonbar
);
426 gui_synclist_draw(&tree_lists
);
427 gui_syncstatusbar_draw(&statusbars
, true);
428 return tc
.filesindir
;
431 /* load tracks from specified directory to resume play */
432 void resume_directory(const char *dir
)
435 bool id3db
= *tc
.dirfilter
== SHOW_ID3DB
;
438 if (ft_load(&tc
, dir
) < 0)
442 ft_build_playlist(&tc
, 0);
450 /* Returns the current working directory and also writes cwd to buf if
451 non-NULL. In case of error, returns NULL. */
452 char *getcwd(char *buf
, int size
)
458 strncpy(buf
, tc
.currdir
, size
);
465 /* Force a reload of the directory next time directory browser is called */
466 void reload_directory(void)
471 void get_current_file(char* buffer
, int buffer_len
)
474 /* in ID3DB mode it is a bad idea to call this function */
475 /* (only happens with `follow playlist') */
476 if( *tc
.dirfilter
== SHOW_ID3DB
)
480 struct entry
* dc
= tc
.dircache
;
481 struct entry
* e
= &dc
[tc
.selected_item
];
482 snprintf(buffer
, buffer_len
, "%s/%s", getcwd(NULL
,0),
483 tc
.dirlength
? e
->name
: "");
486 /* Allow apps to change our dirfilter directly (required for sub browsers)
487 if they're suddenly going to become a file browser for example */
488 void set_dirfilter(int l_dirfilter
)
490 *tc
.dirfilter
= l_dirfilter
;
493 /* Selects a file and update tree context properly */
494 void set_current_file(char *path
)
500 /* in ID3DB mode it is a bad idea to call this function */
501 /* (only happens with `follow playlist') */
502 if( *tc
.dirfilter
== SHOW_ID3DB
)
506 /* separate directory from filename */
507 /* gets the directory's name and put it into tc.currdir */
508 name
= strrchr(path
+1,'/');
512 strcpy(tc
.currdir
, path
);
518 strcpy(tc
.currdir
, "/");
522 strcpy(lastfile
, name
);
525 /* If we changed dir we must recalculate the dirlevel
526 and adjust the selected history properly */
527 if (strncmp(tc
.currdir
,lastdir
,sizeof(lastdir
)))
530 tc
.selected_item_history
[tc
.dirlevel
] = -1;
532 /* use '/' to calculate dirlevel */
533 for (i
= 1; path
[i
] != '\0'; i
++)
538 tc
.selected_item_history
[tc
.dirlevel
] = -1;
542 if (ft_load(&tc
, NULL
) >= 0)
544 tc
.selected_item
= tree_get_file_position(lastfile
);
549 /* main loop, handles key events */
550 static int dirbrowse()
555 unsigned button
, returned_button
;
556 bool reload_root
= false;
557 int lastfilter
= *tc
.dirfilter
;
558 bool lastsortcase
= global_settings
.sort_case
;
559 bool need_update
= true;
560 bool exit_func
= false;
561 long thumbnail_time
= -1; /* for delaying a thumbnail */
563 char* currdir
= tc
.currdir
; /* just a shortcut */
565 bool id3db
= *tc
.dirfilter
== SHOW_ID3DB
;
568 curr_context
=CONTEXT_ID3DB
;
571 curr_context
=CONTEXT_TREE
;
572 if (tc
.selected_item
< 0)
573 tc
.selected_item
= 0;
582 numentries
= update_dir();
583 if (numentries
== -1)
584 return false; /* currdir is not a directory */
586 if (*tc
.dirfilter
> NUM_FILTER_MODES
&& numentries
==0)
588 gui_syncsplash(HZ
*2, ID2P(LANG_NO_FILES
));
589 return false; /* No files found for rockbox_browser() */
593 struct entry
*dircache
= tc
.dircache
;
594 bool restore
= false;
596 tc
.dirlevel
= 0; /* shouldnt be needed.. this code needs work! */
599 char *lines
[]={ID2P(LANG_BOOT_CHANGED
), ID2P(LANG_REBOOT_NOW
)};
600 struct text_message message
={lines
, 2};
601 if(gui_syncyesno_run(&message
, NULL
, NULL
)==YESNO_YES
)
602 rolo_load("/" BOOTFILE
);
604 boot_changed
= false;
607 button
= get_action(CONTEXT_TREE
,HZ
/5);
608 returned_button
= gui_synclist_do_button(&tree_lists
, button
,LIST_WRAP_UNLESS_HELD
);
611 if (returned_button
== ACTION_STD_CANCEL
)
612 button
= ACTION_STD_CANCEL
;
614 tc
.selected_item
= gui_synclist_get_sel_pos(&tree_lists
);
617 /* nothing to do if no files to display */
618 if ( numentries
== 0 )
622 switch (id3db
?tagtree_enter(&tc
):ft_enter(&tc
))
624 switch (ft_enter(&tc
))
627 case 1: reload_dir
= true; break;
628 case 2: start_wps
= true; break;
629 case 3: exit_func
= true; break;
635 case ACTION_STD_CANCEL
:
636 if (*tc
.dirfilter
> NUM_FILTER_MODES
&& tc
.dirlevel
< 1) {
640 if ((*tc
.dirfilter
== SHOW_ID3DB
&& tc
.dirlevel
== 0) ||
641 ((*tc
.dirfilter
!= SHOW_ID3DB
&& !strcmp(currdir
,"/"))))
643 if (returned_button
== ACTION_STD_CANCEL
)
654 if (ft_exit(&tc
) == 3)
660 case ACTION_TREE_STOP
:
661 if (list_stop_handler())
665 case ACTION_STD_MENU
:
669 #ifdef HAVE_RECORDING
671 return GO_TO_RECSCREEN
;
674 case ACTION_TREE_WPS
:
675 return GO_TO_PREVIOUS_MUSIC
;
677 #ifdef HAVE_QUICKSCREEN
678 case ACTION_STD_QUICKSCREEN
:
679 /* don't enter f2 from plugin browser */
680 if (*tc
.dirfilter
< NUM_FILTER_MODES
)
682 if (quick_screen_quick(button
))
690 /* don't enter f3 from plugin browser */
691 if (*tc
.dirfilter
< NUM_FILTER_MODES
)
693 if (quick_screen_f3(BUTTON_F3
))
700 case ACTION_STD_CONTEXT
:
706 onplay_result
= onplay(NULL
, 0, curr_context
);
711 if (tagtree_get_attr(&tc
) == FILE_ATTR_AUDIO
)
713 attr
= FILE_ATTR_AUDIO
;
714 tagtree_get_filename(&tc
, buf
, sizeof(buf
));
717 attr
= ATTR_DIRECTORY
;
722 attr
= dircache
[tc
.selected_item
].attr
;
724 if (currdir
[1]) /* Not in / */
725 snprintf(buf
, sizeof buf
, "%s/%s",
727 dircache
[tc
.selected_item
].name
);
729 snprintf(buf
, sizeof buf
, "/%s",
730 dircache
[tc
.selected_item
].name
);
732 onplay_result
= onplay(buf
, attr
, curr_context
);
734 switch (onplay_result
)
736 case ONPLAY_MAINMENU
:
743 case ONPLAY_RELOAD_DIR
:
747 case ONPLAY_START_PLAY
:
755 if (thumbnail_time
!= -1 &&
756 TIME_AFTER(current_tick
, thumbnail_time
))
757 { /* a delayed hovering thumbnail is due now */
765 attr
= tagtree_get_attr(&tc
);
766 name
= tagtree_get_entry(&tc
, lasti
)->name
;
771 attr
= dircache
[lasti
].attr
;
772 name
= dircache
[lasti
].name
;
775 if (attr
& ATTR_DIRECTORY
)
777 DEBUGF("Playing directory thumbnail: %s", currdir
);
778 res
= ft_play_dirname(name
);
779 if (res
< 0) /* failed, not existing */
781 /* say the number or spell if required as a fallback */
782 switch (global_settings
.talk_dir
)
784 case 1: /* dirs as numbers */
785 talk_id(VOICE_DIR
, false);
786 talk_number(lasti
+1, true);
789 case 2: /* dirs spelled */
790 talk_spell(name
, false);
797 DEBUGF("Playing file thumbnail: %s/%s%s\n",
800 /* no fallback necessary, we knew in advance
801 that the file exists */
802 ft_play_filename(currdir
, name
);
804 thumbnail_time
= -1; /* job done */
806 gui_syncstatusbar_draw(&statusbars
, false);
815 /* The 'dir no longer valid' situation will be caught later
816 * by checking the showdir() result. */
821 if (default_event_handler(button
) == SYS_USB_CONNECTED
)
823 if(*tc
.dirfilter
> NUM_FILTER_MODES
)
824 /* leave sub-browsers after usb, doing otherwise
825 might be confusing to the user */
841 /* do we need to rescan dir? */
842 if (reload_dir
|| reload_root
||
843 lastfilter
!= *tc
.dirfilter
||
844 lastsortcase
!= global_settings
.sort_case
)
847 strcpy(currdir
, "/");
860 gui_synclist_select_item(&tree_lists
, 0);
861 gui_synclist_draw(&tree_lists
);
862 tc
.selected_item
= 0;
866 lastfilter
= *tc
.dirfilter
;
867 lastsortcase
= global_settings
.sort_case
;
872 return GO_TO_PREVIOUS
;
874 if (restore
|| reload_dir
) {
875 /* restore display */
876 numentries
= update_dir();
877 if (currdir
[1] && (numentries
< 0))
878 { /* not in root and reload failed */
879 reload_root
= true; /* try root */
889 if ( numentries
> 0 ) {
890 /* Voice the file if changed */
891 if(lasti
!= tc
.selected_item
|| restore
) {
895 lasti
= tc
.selected_item
;
896 thumbnail_time
= -1; /* Cancel whatever we were
902 attr
= tagtree_get_attr(&tc
);
903 name
= tagtree_get_entry(&tc
, tc
.selected_item
)->name
;
908 attr
= dircache
[tc
.selected_item
].attr
;
909 name
= dircache
[tc
.selected_item
].name
;
913 if (attr
& ATTR_DIRECTORY
)
915 /* schedule thumbnail playback if required */
916 if (global_settings
.talk_dir_clip
)
917 thumbnail_time
= current_tick
+ HOVER_DELAY
;
921 switch (global_settings
.talk_dir
)
923 case 1: /* dirs as numbers */
924 talk_id(VOICE_DIR
, false);
925 talk_number(tc
.selected_item
+1, true);
928 case 2: /* dirs spelled */
929 talk_spell(name
, false);
936 /* schedule thumbnail playback if required */
937 if (global_settings
.talk_file_clip
&& (attr
& FILE_ATTR_THUMBNAIL
))
938 thumbnail_time
= current_tick
+ HOVER_DELAY
;
942 switch (global_settings
.talk_file
)
944 case 1: /* files as numbers */
946 tc
.selected_item
-tc
.dirsindir
+1,
947 attr
& FILE_ATTR_MASK
);
950 case 2: /* files spelled */
951 talk_spell(name
, false);
963 static int plsize
= 0;
965 static bool add_dir(char* dirname
, int len
, int fd
)
970 /* check for user abort */
971 if (action_userabort(TIMEOUT_NOBLOCK
))
974 dir
= opendir(dirname
);
979 struct dirent
*entry
;
981 entry
= readdir(dir
);
984 if (entry
->attribute
& ATTR_DIRECTORY
) {
985 int dirlen
= strlen(dirname
);
988 if (!strcmp((char *)entry
->d_name
, ".") ||
989 !strcmp((char *)entry
->d_name
, ".."))
993 snprintf(dirname
+dirlen
, len
-dirlen
, "/%s", entry
->d_name
);
995 snprintf(dirname
, len
, "/%s", entry
->d_name
);
997 result
= add_dir(dirname
, len
, fd
);
998 dirname
[dirlen
] = '\0';
1005 int x
= strlen((char *)entry
->d_name
);
1007 char *cp
= strrchr((char *)entry
->d_name
,'.');
1012 /* add all supported audio files to playlists */
1013 for (i
=0; i
< filetypes_count
; i
++) {
1014 if (filetypes
[i
].tree_attr
== FILE_ATTR_AUDIO
) {
1015 if (!strcasecmp(cp
, filetypes
[i
].extension
)) {
1018 write(fd
, dirname
, strlen(dirname
));
1020 write(fd
, entry
->d_name
, x
);
1024 if(TIME_AFTER(current_tick
, pltick
+HZ
/4)) {
1025 pltick
= current_tick
;
1027 snprintf(buf
, sizeof buf
, "%d", plsize
);
1028 #ifdef HAVE_LCD_BITMAP
1031 screens
[i
].puts(0, 4, (unsigned char *)buf
);
1032 gui_textarea_update(&screens
[i
]);
1047 screens
[i
].puts(x
,0,buf
);
1063 bool create_playlist(void)
1067 char filename
[MAX_PATH
];
1069 pltick
= current_tick
;
1071 snprintf(filename
, sizeof filename
, "%s.m3u8",
1072 tc
.currdir
[1] ? tc
.currdir
: "/root");
1075 gui_textarea_clear(&screens
[i
]);
1076 screens
[i
].puts(0, 0, str(LANG_CREATING
));
1077 screens
[i
].puts_scroll(0, 1, (unsigned char *)filename
);
1078 #if defined(HAVE_LCD_BITMAP) || defined(SIMULATOR)
1079 gui_textarea_update(&screens
[i
]);
1082 fd
= creat(filename
);
1086 trigger_cpu_boost();
1088 snprintf(filename
, sizeof(filename
), "%s",
1089 tc
.currdir
[1] ? tc
.currdir
: "/");
1091 add_dir(filename
, sizeof(filename
), fd
);
1099 int rockbox_browse(const char *root
, int dirfilter
)
1102 int *last_filter
= tc
.dirfilter
;
1103 tc
.dirfilter
= &dirfilter
;
1106 if (dirfilter
>= NUM_FILTER_MODES
)
1108 static struct tree_context backup
;
1112 tc
.selected_item
= 0;
1114 memcpy(tc
.currdir
, root
, sizeof(tc
.currdir
));
1116 last_context
= curr_context
;
1118 ret_val
= dirbrowse();
1120 curr_context
= last_context
;
1124 static char buf
[MAX_PATH
];
1125 if (dirfilter
!= SHOW_ID3DB
)
1126 tc
.dirfilter
= &global_settings
.dirfilter
;
1128 set_current_file(buf
);
1129 ret_val
= dirbrowse();
1131 tc
.dirfilter
= last_filter
;
1135 void tree_mem_init(void)
1137 /* We copy the settings value in case it is changed by the user. We can't
1138 use it until the next reboot. */
1139 max_files
= global_settings
.max_files_in_dir
;
1141 /* initialize tree context struct */
1142 memset(&tc
, 0, sizeof(tc
));
1143 tc
.dirfilter
= &global_settings
.dirfilter
;
1145 tc
.name_buffer_size
= AVERAGE_FILENAME_LENGTH
* max_files
;
1146 tc
.name_buffer
= buffer_alloc(tc
.name_buffer_size
);
1148 tc
.dircache_size
= max_files
* sizeof(struct entry
);
1149 tc
.dircache
= buffer_alloc(tc
.dircache_size
);
1150 tree_get_filetypes(&filetypes
, &filetypes_count
);
1153 void bookmark_play(char *resume_file
, int index
, int offset
, int seed
,
1157 char* suffix
= strrchr(resume_file
, '.');
1159 if (suffix
!= NULL
&&
1160 (!strcasecmp(suffix
, ".m3u") || !strcasecmp(suffix
, ".m3u8")))
1162 /* Playlist playback */
1164 /* check that the file exists */
1165 int fd
= open(resume_file
, O_RDONLY
);
1170 slash
= strrchr(resume_file
,'/');
1180 if (playlist_create(cp
, slash
+1) != -1)
1182 if (global_settings
.playlist_shuffle
)
1183 playlist_shuffle(seed
, -1);
1184 playlist_start(index
,offset
);
1191 /* Directory playback */
1193 if (playlist_create(resume_file
, NULL
) != -1)
1195 char* peek_filename
;
1196 resume_directory(resume_file
);
1197 if (global_settings
.playlist_shuffle
)
1198 playlist_shuffle(seed
, -1);
1200 /* Check if the file is at the same spot in the directory,
1201 else search for it */
1202 peek_filename
= playlist_peek(index
);
1204 if (peek_filename
== NULL
)
1207 if (strcmp(strrchr(peek_filename
, '/') + 1, filename
))
1209 for ( i
=0; i
< playlist_amount(); i
++ )
1211 peek_filename
= playlist_peek(i
);
1213 if (peek_filename
== NULL
)
1216 if (!strcmp(strrchr(peek_filename
, '/') + 1, filename
))
1219 if (i
< playlist_amount())
1224 playlist_start(index
,offset
);
1231 static int ft_play_filenumber(int pos
, int attr
)
1233 /* try to find a voice ID for the extension, if known */
1235 int ext_id
= -1; /* default to none */
1236 for (j
=0; j
<filetypes_count
; j
++)
1238 if (attr
== filetypes
[j
].tree_attr
)
1240 ext_id
= filetypes
[j
].voiceclip
;
1245 talk_id(VOICE_FILE
, false);
1246 talk_number(pos
, true);
1247 talk_id(ext_id
, true);
1251 static int ft_play_dirname(char* name
)
1254 char dirname_mp3_filename
[MAX_PATH
+1];
1256 #if CONFIG_CODEC != SWCODEC
1257 if (audio_status() & AUDIO_STATUS_PLAY
)
1261 snprintf(dirname_mp3_filename
, sizeof(dirname_mp3_filename
), "%s/%s/%s",
1262 tc
.currdir
[1] ? tc
.currdir
: "" , name
,
1263 dir_thumbnail_name
);
1265 DEBUGF("Checking for %s\n", dirname_mp3_filename
);
1267 fd
= open(dirname_mp3_filename
, O_RDONLY
);
1270 DEBUGF("Failed to find: %s\n", dirname_mp3_filename
);
1276 DEBUGF("Found: %s\n", dirname_mp3_filename
);
1278 talk_file(dirname_mp3_filename
, false);
1282 static void ft_play_filename(char *dir
, char *file
)
1284 char name_mp3_filename
[MAX_PATH
+1];
1286 #if CONFIG_CODEC != SWCODEC
1287 if (audio_status() & AUDIO_STATUS_PLAY
)
1291 if (strcasecmp(&file
[strlen(file
) - strlen(file_thumbnail_ext
)],
1292 file_thumbnail_ext
))
1293 { /* file has no .talk extension */
1294 snprintf(name_mp3_filename
, sizeof(name_mp3_filename
),
1295 "%s/%s%s", dir
, file
, file_thumbnail_ext
);
1297 talk_file(name_mp3_filename
, false);
1300 { /* it already is a .talk file, play this directly */
1301 snprintf(name_mp3_filename
, sizeof(name_mp3_filename
),
1302 "%s/%s", dir
, file
);
1303 talk_id(LANG_VOICE_DIR_HOVER
, false); /* prefix it */
1304 talk_file(name_mp3_filename
, true);
1308 /* These two functions are called by the USB and shutdown handlers */
1309 void tree_flush(void)
1311 scrobbler_shutdown();
1312 #ifdef HAVE_TAGCACHE
1313 tagcache_shutdown();
1315 playlist_shutdown();
1317 #ifdef HAVE_TC_RAMCACHE
1318 tagcache_unload_ramcache();
1321 #ifdef HAVE_DIRCACHE
1323 int old_val
= global_status
.dircache_size
;
1324 if (global_settings
.dircache
)
1326 global_status
.dircache_size
= dircache_get_cache_size();
1327 # ifdef HAVE_EEPROM_SETTINGS
1328 if (firmware_settings
.initialized
)
1335 global_status
.dircache_size
= 0;
1337 if (old_val
!= global_status
.dircache_size
)
1343 void tree_restore(void)
1345 #ifdef HAVE_EEPROM_SETTINGS
1346 firmware_settings
.disk_clean
= false;
1349 #ifdef HAVE_TC_RAMCACHE
1350 remove(TAGCACHE_STATEFILE
);
1353 #ifdef HAVE_DIRCACHE
1354 remove(DIRCACHE_FILE
);
1355 if (global_settings
.dircache
)
1357 /* Print "Scanning disk..." to the display. */
1361 screens
[i
].putsxy((LCD_WIDTH
/2) -
1362 ((strlen(str(LANG_SCANNING_DISK
)) *
1363 screens
[i
].char_width
)/2),
1364 LCD_HEIGHT
-screens
[i
].char_height
*3,
1365 str(LANG_SCANNING_DISK
));
1366 gui_textarea_update(&screens
[i
]);
1368 cond_talk_ids_fq(LANG_SCANNING_DISK
);
1370 dircache_build(global_status
.dircache_size
);
1372 /* Clean the text when we are done. */
1375 gui_textarea_clear(&screens
[i
]);
1379 #ifdef HAVE_TAGCACHE
1380 tagcache_start_scan();