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"
34 #include "main_menu.h"
57 #include "filetypes.h"
61 #include "recorder/recording.h"
68 #include "gwps-common.h"
69 #include "eeprom_settings.h"
70 #include "scrobbler.h"
74 #include "statusbar.h"
76 #include "buttonbar.h"
80 #ifdef HAVE_LCD_BITMAP
88 /* a table for the know file types */
89 const struct filetype filetypes
[] = {
90 { "mp3", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
91 { "mp2", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
92 { "mpa", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
93 #if CONFIG_CODEC == SWCODEC
94 /* Temporary hack to allow playlist creation */
95 { "mp1", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
96 { "ogg", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
97 { "wma", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
98 { "wav", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
99 { "flac",TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
100 { "ac3", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
101 { "a52", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
102 { "mpc", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
103 { "wv", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
104 { "m4a", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
105 { "mp4", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
106 { "shn", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
107 { "aif", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
108 { "aiff",TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
109 { "sid", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
110 { "adx", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
112 { "m3u", TREE_ATTR_M3U
, Icon_Playlist
, LANG_PLAYLIST
},
113 { "m3u8", TREE_ATTR_M3U
, Icon_Playlist
, LANG_PLAYLIST
},
114 { "cfg", TREE_ATTR_CFG
, Icon_Config
, VOICE_EXT_CFG
},
115 { "wps", TREE_ATTR_WPS
, Icon_Wps
, VOICE_EXT_WPS
},
116 #ifdef HAVE_REMOTE_LCD
117 { "rwps", TREE_ATTR_RWPS
, Icon_Wps
, VOICE_EXT_RWPS
},
119 #ifdef HAVE_LCD_COLOR
120 { "bmp", TREE_ATTR_BMP
, Icon_Wps
, VOICE_EXT_WPS
},
123 { "fmr", TREE_ATTR_FMR
, Icon_Preset
, LANG_FMR
},
125 { "lng", TREE_ATTR_LNG
, Icon_Language
, LANG_LANGUAGE
},
126 { "rock",TREE_ATTR_ROCK
,Icon_Plugin
, VOICE_EXT_ROCK
},
127 #ifdef HAVE_LCD_BITMAP
128 { "fnt", TREE_ATTR_FONT
,Icon_Font
, VOICE_EXT_FONT
},
129 { "kbd", TREE_ATTR_KBD
, Icon_Keyboard
, VOICE_EXT_KBD
},
131 { "bmark",TREE_ATTR_BMARK
, Icon_Bookmark
, VOICE_EXT_BMARK
},
133 { BOOTFILE_EXT
, TREE_ATTR_MOD
, Icon_Firmware
, VOICE_EXT_AJZ
},
134 #endif /* #ifndef SIMULATOR */
137 struct gui_synclist tree_lists
;
139 /* I put it here because other files doesn't use it yet,
140 * but should be elsewhere since it will be used mostly everywhere */
142 struct gui_buttonbar tree_buttonbar
;
144 static struct tree_context tc
;
146 bool boot_changed
= false;
148 char lastfile
[MAX_PATH
];
149 static char lastdir
[MAX_PATH
];
150 static int lasttable
, lastextra
, lastfirstpos
;
151 static int max_files
= 0;
153 static bool reload_dir
= false;
155 static bool start_wps
= false;
156 static bool dirbrowse(void);
157 static int curr_context
= false;/* id3db or tree*/
160 * removes the extension of filename (if it doesn't start with a .)
161 * puts the result in buffer
163 char * strip_extension(char * filename
, char * buffer
)
166 char * dot
=strrchr(filename
, '.');
167 if(dot
!=0 && filename
[0]!='.')
169 dotpos
= dot
-filename
;
170 strncpy(buffer
, filename
, dotpos
);
177 char * tree_get_filename(int selected_item
, void * data
, char *buffer
)
179 struct tree_context
* local_tc
=(struct tree_context
*)data
;
183 bool id3db
= *(local_tc
->dirfilter
) == SHOW_ID3DB
;
187 return tagtree_get_entry(&tc
, selected_item
)->name
;
192 struct entry
* dc
= local_tc
->dircache
;
193 struct entry
* e
= &dc
[selected_item
];
197 /* if any file filter is on, and if it's not a directory,
198 * strip the extension */
200 if ( (*(local_tc
->dirfilter
) != SHOW_ID3DB
) && !(attr
& ATTR_DIRECTORY
)
201 && (*(local_tc
->dirfilter
) != SHOW_ALL
) )
203 return(strip_extension(name
, buffer
));
209 void tree_get_fileicon(int selected_item
, void * data
, ICON
* icon
)
211 struct tree_context
* local_tc
=(struct tree_context
*)data
;
213 bool id3db
= *(local_tc
->dirfilter
) == SHOW_ID3DB
;
215 *icon
= (ICON
)tagtree_get_icon(&tc
);
220 struct entry
* dc
= local_tc
->dircache
;
221 struct entry
* e
= &dc
[selected_item
];
222 *icon
= (ICON
)filetype_get_icon(e
->attr
);
226 bool check_rockboxdir(void)
228 DIR *dir
= opendir(ROCKBOX_DIR
);
230 { /* No need to localise this message.
231 If .rockbox is missing, it wouldn't work anyway */
234 screens
[i
].clear_display();
235 gui_syncsplash(HZ
*2, true, "No .rockbox directory");
237 screens
[i
].clear_display();
238 gui_syncsplash(HZ
*2, true, "Installation incomplete");
245 void browse_root(void)
247 gui_sync_wps_screen_init();
252 strcpy(tc
.currdir
, "/");
254 #ifdef HAVE_LCD_CHARCELLS
257 screens
[i
].double_height(false);
260 gui_buttonbar_init(&tree_buttonbar
);
261 /* since archos only have one screen, no need to create more than that */
262 gui_buttonbar_set_display(&tree_buttonbar
, &(screens
[SCREEN_MAIN
]) );
264 gui_synclist_init(&tree_lists
, &tree_get_filename
, &tc
, false, 1);
265 gui_synclist_set_icon_callback(&tree_lists
,
266 global_settings
.show_icons
?&tree_get_fileicon
:NULL
);
271 DEBUGF("No filesystem found. Have you forgotten to create it?\n");
276 void tree_get_filetypes(const struct filetype
** types
, int* count
)
279 *count
= sizeof(filetypes
) / sizeof(*filetypes
);
282 struct tree_context
* tree_get_context(void)
287 /* talkbox hovering delay, to avoid immediate disk activity */
288 #define HOVER_DELAY (HZ/2)
290 * Returns the position of a given file in the current directory
291 * returns -1 if not found
293 int tree_get_file_position(char * filename
)
297 /* use lastfile to determine the selected item (default=0) */
298 for (i
=0; i
< tc
.filesindir
; i
++)
300 struct entry
* dc
= tc
.dircache
;
301 struct entry
* e
= &dc
[i
];
302 if (!strcasecmp(e
->name
, filename
))
305 return(-1);/* no file can match, returns undefined */
309 * Called when a new dir is loaded (for example when returning from other apps ...)
310 * also completely redraws the tree
312 static int update_dir(void)
314 bool changed
= false;
316 bool id3db
= *tc
.dirfilter
== SHOW_ID3DB
;
317 /* Checks for changes */
319 if (tc
.currtable
!= lasttable
||
320 tc
.currextra
!= lastextra
||
321 tc
.firstpos
!= lastfirstpos
||
324 if (tagtree_load(&tc
) < 0)
327 lasttable
= tc
.currtable
;
328 lastextra
= tc
.currextra
;
329 lastfirstpos
= tc
.firstpos
;
336 /* if the tc.currdir has been changed, reload it ...*/
337 if (strncmp(tc
.currdir
, lastdir
, sizeof(lastdir
)) || reload_dir
) {
339 if (ft_load(&tc
, NULL
) < 0)
341 strcpy(lastdir
, tc
.currdir
);
345 /* if selected item is undefined */
346 if (tc
.selected_item
== -1)
348 /* use lastfile to determine the selected item */
349 tc
.selected_item
= tree_get_file_position(lastfile
);
351 /* If the file doesn't exists, select the first one (default) */
352 if(tc
.selected_item
< 0)
353 tc
.selected_item
= 0;
363 tc
.filesindir
== global_settings
.max_files_in_dir
) )
365 gui_syncsplash(HZ
, true, str(LANG_SHOWDIR_BUFFER_FULL
));
371 if (global_settings
.show_path_in_browser
== SHOW_PATH_FULL
372 || global_settings
.show_path_in_browser
== SHOW_PATH_CURRENT
)
374 gui_synclist_set_title(&tree_lists
, tagtree_get_title(&tc
),
375 filetype_get_icon(ATTR_DIRECTORY
));
379 /* Must clear the title as the list is reused */
380 gui_synclist_set_title(&tree_lists
, NULL
, NOICON
);
386 if (global_settings
.show_path_in_browser
== SHOW_PATH_FULL
)
388 gui_synclist_set_title(&tree_lists
, tc
.currdir
,
389 filetype_get_icon(ATTR_DIRECTORY
));
391 else if (global_settings
.show_path_in_browser
== SHOW_PATH_CURRENT
)
393 char *title
= strrchr(tc
.currdir
, '/') + 1;
396 /* Display nothing for the root dir */
397 gui_synclist_set_title(&tree_lists
, NULL
, NOICON
);
400 gui_synclist_set_title(&tree_lists
, title
,
401 filetype_get_icon(ATTR_DIRECTORY
));
405 /* Must clear the title as the list is reused */
406 gui_synclist_set_title(&tree_lists
, NULL
, NOICON
);
410 gui_synclist_set_nb_items(&tree_lists
, tc
.filesindir
);
411 gui_synclist_set_icon_callback(&tree_lists
,
412 global_settings
.show_icons
?&tree_get_fileicon
:NULL
);
413 if( tc
.selected_item
>= tc
.filesindir
)
414 tc
.selected_item
=tc
.filesindir
-1;
416 gui_synclist_select_item(&tree_lists
, tc
.selected_item
);
418 if (global_settings
.buttonbar
) {
419 if (*tc
.dirfilter
< NUM_FILTER_MODES
)
420 gui_buttonbar_set(&tree_buttonbar
, str(LANG_SYSFONT_DIRBROWSE_F1
),
421 str(LANG_SYSFONT_DIRBROWSE_F2
),
422 str(LANG_SYSFONT_DIRBROWSE_F3
));
424 gui_buttonbar_set(&tree_buttonbar
, "<<<", "", "");
425 gui_buttonbar_draw(&tree_buttonbar
);
428 gui_synclist_draw(&tree_lists
);
429 gui_syncstatusbar_draw(&statusbars
, true);
430 return tc
.filesindir
;
433 /* load tracks from specified directory to resume play */
434 void resume_directory(const char *dir
)
437 bool id3db
= *tc
.dirfilter
== SHOW_ID3DB
;
440 if (ft_load(&tc
, dir
) < 0)
444 ft_build_playlist(&tc
, 0);
452 /* Returns the current working directory and also writes cwd to buf if
453 non-NULL. In case of error, returns NULL. */
454 char *getcwd(char *buf
, int size
)
460 strncpy(buf
, tc
.currdir
, size
);
467 /* Force a reload of the directory next time directory browser is called */
468 void reload_directory(void)
473 static void start_resume(bool just_powered_on
)
475 bool do_resume
= false;
476 if ( global_settings
.resume_index
!= -1 ) {
477 DEBUGF("Resume index %X offset %X\n",
478 global_settings
.resume_index
,
479 global_settings
.resume_offset
);
481 #ifdef HAVE_ALARM_MOD
482 if ( rtc_check_alarm_started(true) ) {
483 rtc_enable_alarm(false);
489 if ( global_settings
.resume
|| ! just_powered_on
)
490 #ifdef HAVE_HEADPHONE_DETECTION
492 if ( just_powered_on
)
494 if ( !global_settings
.unplug_autoresume
495 || headphones_inserted() )
505 if (! do_resume
) return;
507 if (playlist_resume() != -1)
509 playlist_start(global_settings
.resume_index
,
510 global_settings
.resume_offset
);
516 else if (! just_powered_on
) {
517 gui_syncsplash(HZ
*2, true, str(LANG_NOTHING_TO_RESUME
));
521 /* Selects a file and update tree context properly */
522 void set_current_file(char *path
)
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 /* separate directory from filename */
535 /* gets the directory's name and put it into tc.currdir */
536 name
= strrchr(path
+1,'/');
540 strcpy(tc
.currdir
, path
);
546 strcpy(tc
.currdir
, "/");
550 strcpy(lastfile
, name
);
552 /* undefined item selected */
553 tc
.selected_item
= -1;
555 /* If we changed dir we must recalculate the dirlevel
556 and adjust the selected history properly */
557 if (strncmp(tc
.currdir
,lastdir
,sizeof(lastdir
)))
560 tc
.selected_item_history
[tc
.dirlevel
] = -1;
562 /* use '/' to calculate dirlevel */
563 /* FIXME : strlen(path) : crazy oO better to store it at
565 int path_len
= strlen(path
) + 1;
566 for (i
= 1; i
< path_len
; i
++)
571 tc
.selected_item_history
[tc
.dirlevel
] = -1;
578 static bool check_changed_id3mode(bool currmode
)
580 if (currmode
!= (global_settings
.dirfilter
== SHOW_ID3DB
)) {
581 currmode
= global_settings
.dirfilter
== SHOW_ID3DB
;
583 curr_context
=CONTEXT_ID3DB
;
590 curr_context
=CONTEXT_TREE
;
599 /* main loop, handles key events */
600 static bool dirbrowse(void)
605 unsigned button
, returned_button
;
606 bool reload_root
= false;
607 int lastfilter
= *tc
.dirfilter
;
608 bool lastsortcase
= global_settings
.sort_case
;
609 bool need_update
= true;
610 bool exit_func
= false;
611 long thumbnail_time
= -1; /* for delaying a thumbnail */
613 char* currdir
= tc
.currdir
; /* just a shortcut */
615 bool id3db
= *tc
.dirfilter
== SHOW_ID3DB
;
618 curr_context
=CONTEXT_ID3DB
;
621 curr_context
=CONTEXT_TREE
;
622 tc
.selected_item
= 0;
629 if (*tc
.dirfilter
< NUM_FILTER_MODES
) {
630 #ifdef HAVE_RECORDING
632 if (global_settings
.rec_startup
) {
633 /* We fake being in the menu structure by calling
634 the appropriate parent when we drop out of each screen */
635 #if CONFIG_CODEC == SWCODEC
636 /* Put in a 1 sec pause to slow bootup or the recording codecs
640 recording_screen(false);
650 /* If we don't need to show the wps, draw the dir */
652 numentries
= update_dir();
653 if (numentries
== -1)
654 return false; /* currdir is not a directory */
656 if (*tc
.dirfilter
> NUM_FILTER_MODES
&& numentries
==0)
658 gui_syncsplash(HZ
*2, true, str(LANG_NO_FILES
));
659 return false; /* No files found for rockbox_browser() */
664 struct entry
*dircache
= tc
.dircache
;
665 bool restore
= false;
668 char *lines
[]={str(LANG_BOOT_CHANGED
), str(LANG_REBOOT_NOW
)};
669 struct text_message message
={lines
, 2};
670 if(gui_syncyesno_run(&message
, NULL
, NULL
)==YESNO_YES
)
671 rolo_load("/" BOOTFILE
);
673 boot_changed
= false;
676 button
= get_action(CONTEXT_TREE
,HZ
/5);
677 returned_button
= gui_synclist_do_button(&tree_lists
, button
);
680 if (returned_button
== ACTION_STD_CANCEL
)
681 button
= ACTION_STD_CANCEL
;
685 /* nothing to do if no files to display */
686 if ( numentries
== 0 )
690 switch (id3db
?tagtree_enter(&tc
):ft_enter(&tc
))
692 switch (ft_enter(&tc
))
695 case 1: reload_dir
= true; break;
696 case 2: start_wps
= true; break;
697 case 3: exit_func
= true; break;
703 case ACTION_STD_CANCEL
:
704 if (*tc
.dirfilter
> NUM_FILTER_MODES
&& tc
.dirlevel
< 1) {
708 /* if we are in /, nothing to do */
709 if (tc
.dirlevel
== 0 && !strcmp(currdir
,"/"))
717 if (ft_exit(&tc
) == 3)
723 case ACTION_TREE_STOP
:
724 if (*tc
.dirfilter
< NUM_FILTER_MODES
)
726 /* Stop the music if it is playing */
728 if (!global_settings
.party_mode
) {
729 if (global_settings
.fade_on_stop
)
731 bookmark_autobookmark();
735 #if defined(CONFIG_CHARGING) && \
736 (CONFIG_KEYPAD == RECORDER_PAD) && !defined(HAVE_SW_POWEROFF)
738 if (!charger_inserted()) {
739 if(shutdown_screen())
748 #if defined(CONFIG_CHARGING) && !defined(HAVE_POWEROFF_WHILE_CHARGING)
750 static int last_off
= 0;
751 if (current_tick
- last_off
< 50) {
752 if (charger_inserted()) {
757 last_off
= current_tick
;
760 break; /* case ACTION_TREE_STOP: */
761 case ACTION_STD_MENU
:
762 /* don't enter menu from plugin browser */
763 if (*tc
.dirfilter
< NUM_FILTER_MODES
)
767 screens
[i
].stop_scroll();
768 action_signalscreenchange();
774 id3db
= check_changed_id3mode(id3db
);
779 else /* use it as a quick exit instead */
783 case ACTION_TREE_WPS
:
784 /* don't enter wps from plugin browser etc */
785 if (*tc
.dirfilter
< NUM_FILTER_MODES
)
787 if (audio_status() & AUDIO_STATUS_PLAY
)
798 #ifdef HAVE_QUICKSCREEN
799 case ACTION_STD_QUICKSCREEN
:
800 /* don't enter f2 from plugin browser */
801 if (*tc
.dirfilter
< NUM_FILTER_MODES
)
803 if (quick_screen_quick(button
))
808 id3db
= check_changed_id3mode(id3db
);
816 /* don't enter f3 from plugin browser */
817 if (*tc
.dirfilter
< NUM_FILTER_MODES
)
819 if (quick_screen_f3(BUTTON_F3
))
826 case ACTION_STD_CONTEXT
:
832 onplay_result
= onplay(NULL
, 0, curr_context
);
837 if (tagtree_get_attr(&tc
) == TREE_ATTR_MPA
)
839 attr
= TREE_ATTR_MPA
;
840 tagtree_get_filename(&tc
, buf
, sizeof(buf
));
843 attr
= ATTR_DIRECTORY
;
848 attr
= dircache
[tc
.selected_item
].attr
;
850 if (currdir
[1]) /* Not in / */
851 snprintf(buf
, sizeof buf
, "%s/%s",
853 dircache
[tc
.selected_item
].name
);
855 snprintf(buf
, sizeof buf
, "/%s",
856 dircache
[tc
.selected_item
].name
);
858 onplay_result
= onplay(buf
, attr
, curr_context
);
860 switch (onplay_result
)
866 case ONPLAY_RELOAD_DIR
:
870 case ONPLAY_START_PLAY
:
878 if (thumbnail_time
!= -1 &&
879 TIME_AFTER(current_tick
, thumbnail_time
))
880 { /* a delayed hovering thumbnail is due now */
888 attr
= tagtree_get_attr(&tc
);
889 name
= tagtree_get_entry(&tc
, lasti
)->name
;
894 attr
= dircache
[lasti
].attr
;
895 name
= dircache
[lasti
].name
;
898 if (attr
& ATTR_DIRECTORY
)
900 DEBUGF("Playing directory thumbnail: %s", currdir
);
901 res
= ft_play_dirname(name
);
902 if (res
< 0) /* failed, not existing */
903 { /* say the number instead, as a fallback */
904 talk_id(VOICE_DIR
, false);
905 talk_number(lasti
+1, true);
910 DEBUGF("Playing file thumbnail: %s/%s%s\n",
913 /* no fallback necessary, we knew in advance
914 that the file exists */
915 ft_play_filename(currdir
, name
);
917 thumbnail_time
= -1; /* job done */
919 gui_syncstatusbar_draw(&statusbars
, false);
928 /* The 'dir no longer valid' situation will be caught later
929 * by checking the showdir() result. */
934 if (default_event_handler(button
) == SYS_USB_CONNECTED
)
936 if(*tc
.dirfilter
> NUM_FILTER_MODES
)
937 /* leave sub-browsers after usb, doing otherwise
938 might be confusing to the user */
951 if (start_wps
&& audio_status() )
956 screens
[i
].stop_scroll();
958 if (gui_wps_show() == SYS_USB_CONNECTED
)
963 if (!id3db
) /* Try reload to catch 'no longer valid' case. */
967 #ifdef HAVE_LCD_COLOR
968 show_main_backdrop();
971 id3db
= check_changed_id3mode(id3db
);
978 /* do we need to rescan dir? */
979 if (reload_dir
|| reload_root
||
980 lastfilter
!= *tc
.dirfilter
||
981 lastsortcase
!= global_settings
.sort_case
)
984 strcpy(currdir
, "/");
995 gui_synclist_select_item(&tree_lists
, 0);
996 gui_synclist_draw(&tree_lists
);
997 tc
.selected_item
= 0;
1001 lastfilter
= *tc
.dirfilter
;
1002 lastsortcase
= global_settings
.sort_case
;
1009 if (restore
|| reload_dir
) {
1010 /* restore display */
1011 numentries
= update_dir();
1012 if (currdir
[1] && (numentries
< 0))
1013 { /* not in root and reload failed */
1014 reload_root
= true; /* try root */
1023 tc
.selected_item
= gui_synclist_get_sel_pos(&tree_lists
);
1025 if ( numentries
> 0 ) {
1026 /* Voice the file if changed */
1027 if(lasti
!= tc
.selected_item
|| restore
) {
1031 lasti
= tc
.selected_item
;
1032 thumbnail_time
= -1; /* Cancel whatever we were
1035 #ifdef HAVE_TAGCACHE
1038 attr
= tagtree_get_attr(&tc
);
1039 name
= tagtree_get_entry(&tc
, tc
.selected_item
)->name
;
1044 attr
= dircache
[tc
.selected_item
].attr
;
1045 name
= dircache
[tc
.selected_item
].name
;
1049 if (attr
& ATTR_DIRECTORY
)
1051 /* play directory thumbnail */
1052 switch (global_settings
.talk_dir
) {
1053 case 1: /* dirs as numbers */
1054 talk_id(VOICE_DIR
, false);
1055 talk_number(tc
.selected_item
+1, true);
1058 case 2: /* dirs spelled */
1059 talk_spell(name
, false);
1062 case 3: /* thumbnail clip */
1063 /* "schedule" a thumbnail, to have a little
1065 thumbnail_time
= current_tick
+ HOVER_DELAY
;
1074 switch (global_settings
.talk_file
) {
1075 case 1: /* files as numbers */
1077 tc
.selected_item
-tc
.dirsindir
+1,
1078 attr
& TREE_ATTR_MASK
);
1081 case 2: /* files spelled */
1082 talk_spell(name
, false);
1085 case 3: /* thumbnail clip */
1086 /* "schedule" a thumbnail, to have a little
1088 if (attr
& TREE_ATTR_THUMBNAIL
)
1089 thumbnail_time
= current_tick
+ HOVER_DELAY
;
1091 /* spell the number as fallback */
1092 talk_spell(name
, false);
1103 action_signalscreenchange();
1107 static int plsize
= 0;
1109 static bool add_dir(char* dirname
, int len
, int fd
)
1114 /* check for user abort */
1115 if (action_userabort(TIMEOUT_NOBLOCK
))
1118 dir
= opendir_cached(dirname
);
1123 struct dircache_entry
*entry
;
1125 entry
= readdir_cached(dir
);
1128 if (entry
->attribute
& ATTR_DIRECTORY
) {
1129 int dirlen
= strlen(dirname
);
1132 if (!strcmp((char *)entry
->d_name
, ".") ||
1133 !strcmp((char *)entry
->d_name
, ".."))
1137 snprintf(dirname
+dirlen
, len
-dirlen
, "/%s", entry
->d_name
);
1139 snprintf(dirname
, len
, "/%s", entry
->d_name
);
1141 result
= add_dir(dirname
, len
, fd
);
1142 dirname
[dirlen
] = '\0';
1149 int x
= strlen((char *)entry
->d_name
);
1151 char *cp
= strrchr((char *)entry
->d_name
,'.');
1156 /* add all supported audio files to playlists */
1157 for (i
=0; i
< sizeof(filetypes
)/sizeof(struct filetype
); i
++) {
1158 if (filetypes
[i
].tree_attr
== TREE_ATTR_MPA
) {
1159 if (!strcasecmp(cp
, filetypes
[i
].extension
)) {
1162 write(fd
, dirname
, strlen(dirname
));
1164 write(fd
, entry
->d_name
, x
);
1168 if(TIME_AFTER(current_tick
, pltick
+HZ
/4)) {
1169 pltick
= current_tick
;
1171 snprintf(buf
, sizeof buf
, "%d", plsize
);
1172 #ifdef HAVE_LCD_BITMAP
1175 screens
[i
].puts(0, 4, (unsigned char *)buf
);
1176 gui_textarea_update(&screens
[i
]);
1191 screens
[i
].puts(x
,0,buf
);
1202 closedir_cached(dir
);
1207 bool create_playlist(void)
1211 char filename
[MAX_PATH
];
1213 pltick
= current_tick
;
1215 snprintf(filename
, sizeof filename
, "%s.m3u",
1216 tc
.currdir
[1] ? tc
.currdir
: "/root");
1219 gui_textarea_clear(&screens
[i
]);
1220 screens
[i
].puts(0, 0, str(LANG_CREATING
));
1221 screens
[i
].puts_scroll(0, 1, (unsigned char *)filename
);
1222 #if defined(HAVE_LCD_BITMAP) || defined(SIMULATOR)
1223 gui_textarea_update(&screens
[i
]);
1226 fd
= creat(filename
, O_WRONLY
);
1230 cpu_boost_id(true, CPUBOOSTID_TREE
);
1232 snprintf(filename
, sizeof(filename
), "%s",
1233 tc
.currdir
[1] ? tc
.currdir
: "/");
1235 add_dir(filename
, sizeof(filename
), fd
);
1238 cpu_boost_id(false, CPUBOOSTID_TREE
);
1245 bool rockbox_browse(const char *root
, int dirfilter
)
1247 static struct tree_context backup
;
1252 memcpy(tc
.currdir
, root
, sizeof(tc
.currdir
));
1254 tc
.dirfilter
= &dirfilter
;
1255 last_context
= curr_context
;
1260 curr_context
= last_context
;
1265 void tree_init(void)
1267 /* We copy the settings value in case it is changed by the user. We can't
1268 use it until the next reboot. */
1269 max_files
= global_settings
.max_files_in_dir
;
1271 /* initialize tree context struct */
1272 memset(&tc
, 0, sizeof(tc
));
1273 tc
.dirfilter
= &global_settings
.dirfilter
;
1275 tc
.name_buffer_size
= AVERAGE_FILENAME_LENGTH
* max_files
;
1276 tc
.name_buffer
= buffer_alloc(tc
.name_buffer_size
);
1278 tc
.dircache_size
= max_files
* sizeof(struct entry
);
1279 tc
.dircache
= buffer_alloc(tc
.dircache_size
);
1282 void bookmark_play(char *resume_file
, int index
, int offset
, int seed
,
1286 char* suffix
= strrchr(resume_file
, '.');
1288 if (suffix
!= NULL
&&
1289 (!strcasecmp(suffix
, ".m3u") || !strcasecmp(suffix
, ".m3u8")))
1291 /* Playlist playback */
1293 /* check that the file exists */
1294 int fd
= open(resume_file
, O_RDONLY
);
1299 slash
= strrchr(resume_file
,'/');
1309 if (playlist_create(cp
, slash
+1) != -1)
1311 if (global_settings
.playlist_shuffle
)
1312 playlist_shuffle(seed
, -1);
1313 playlist_start(index
,offset
);
1320 /* Directory playback */
1322 if (playlist_create(resume_file
, NULL
) != -1)
1324 resume_directory(resume_file
);
1325 if (global_settings
.playlist_shuffle
)
1326 playlist_shuffle(seed
, -1);
1328 /* Check if the file is at the same spot in the directory,
1329 else search for it */
1330 if ((strcmp(strrchr(playlist_peek(index
),'/') + 1,
1333 for ( i
=0; i
< playlist_amount(); i
++ )
1335 if ((strcmp(strrchr(playlist_peek(i
),'/') + 1,
1339 if (i
< playlist_amount())
1344 playlist_start(index
,offset
);
1351 int ft_play_filenumber(int pos
, int attr
)
1353 /* try to find a voice ID for the extension, if known */
1355 int ext_id
= -1; /* default to none */
1356 for (j
=0; j
<sizeof(filetypes
)/sizeof(*filetypes
); j
++)
1358 if (attr
== filetypes
[j
].tree_attr
)
1360 ext_id
= filetypes
[j
].voiceclip
;
1365 talk_id(VOICE_FILE
, false);
1366 talk_number(pos
, true);
1367 talk_id(ext_id
, true);
1371 int ft_play_dirname(char* name
)
1374 char dirname_mp3_filename
[MAX_PATH
+1];
1376 #if CONFIG_CODEC != SWCODEC
1377 if (audio_status() & AUDIO_STATUS_PLAY
)
1381 snprintf(dirname_mp3_filename
, sizeof(dirname_mp3_filename
), "%s/%s/%s",
1382 tc
.currdir
[1] ? tc
.currdir
: "" , name
,
1383 dir_thumbnail_name
);
1385 DEBUGF("Checking for %s\n", dirname_mp3_filename
);
1387 fd
= open(dirname_mp3_filename
, O_RDONLY
);
1390 DEBUGF("Failed to find: %s\n", dirname_mp3_filename
);
1396 DEBUGF("Found: %s\n", dirname_mp3_filename
);
1398 talk_file(dirname_mp3_filename
, false);
1402 void ft_play_filename(char *dir
, char *file
)
1404 char name_mp3_filename
[MAX_PATH
+1];
1406 #if CONFIG_CODEC != SWCODEC
1407 if (audio_status() & AUDIO_STATUS_PLAY
)
1411 if (strcasecmp(&file
[strlen(file
) - strlen(file_thumbnail_ext
)],
1412 file_thumbnail_ext
))
1413 { /* file has no .talk extension */
1414 snprintf(name_mp3_filename
, sizeof(name_mp3_filename
),
1415 "%s/%s%s", dir
, file
, file_thumbnail_ext
);
1417 talk_file(name_mp3_filename
, false);
1420 { /* it already is a .talk file, play this directly */
1421 snprintf(name_mp3_filename
, sizeof(name_mp3_filename
),
1422 "%s/%s", dir
, file
);
1423 talk_id(LANG_VOICE_DIR_HOVER
, false); /* prefix it */
1424 talk_file(name_mp3_filename
, true);
1428 /* These two functions are called by the USB and shutdown handlers */
1429 void tree_flush(void)
1431 scrobbler_shutdown();
1432 #ifdef HAVE_TAGCACHE
1433 tagcache_shutdown();
1435 playlist_shutdown();
1437 #ifdef HAVE_TC_RAMCACHE
1438 tagcache_unload_ramcache();
1441 #ifdef HAVE_DIRCACHE
1442 if (global_settings
.dircache
)
1444 global_settings
.dircache_size
= dircache_get_cache_size();
1445 # ifdef HAVE_EEPROM_SETTINGS
1446 if (dircache_is_enabled() && firmware_settings
.initialized
)
1447 dircache_save(DIRCACHE_FILE
);
1453 global_settings
.dircache_size
= 0;
1459 void tree_restore(void)
1461 #ifdef HAVE_EEPROM_SETTINGS
1462 firmware_settings
.disk_clean
= false;
1465 #ifdef HAVE_TC_RAMCACHE
1466 remove(TAGCACHE_STATEFILE
);
1469 #ifdef HAVE_DIRCACHE
1470 remove(DIRCACHE_FILE
);
1471 if (global_settings
.dircache
)
1473 /* Print "Scanning disk..." to the display. */
1477 screens
[i
].putsxy((LCD_WIDTH
/2) -
1478 ((strlen(str(LANG_DIRCACHE_BUILDING
)) *
1479 screens
[i
].char_width
)/2),
1480 LCD_HEIGHT
-screens
[i
].char_height
*3,
1481 str(LANG_DIRCACHE_BUILDING
));
1482 gui_textarea_update(&screens
[i
]);
1485 dircache_build(global_settings
.dircache_size
);
1487 /* Clean the text when we are done. */
1490 gui_textarea_clear(&screens
[i
]);
1494 #ifdef HAVE_TAGCACHE
1495 tagcache_start_scan();