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"
62 #include "recorder/recording.h"
70 #include "gwps-common.h"
71 #include "eeprom_settings.h"
72 #include "scrobbler.h"
76 #include "statusbar.h"
78 #include "buttonbar.h"
82 #include "root_menu.h"
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 { "m4b", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
106 { "mp4", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
107 { "shn", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
108 { "aif", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
109 { "aiff",TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
110 { "spx" ,TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
111 { "sid", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
112 { "adx", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
113 { "nsf", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
114 { "nsfe", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
115 { "spc", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
117 { "m3u", TREE_ATTR_M3U
, Icon_Playlist
, LANG_PLAYLIST
},
118 { "m3u8", TREE_ATTR_M3U
, Icon_Playlist
, LANG_PLAYLIST
},
119 { "cfg", TREE_ATTR_CFG
, Icon_Config
, VOICE_EXT_CFG
},
120 { "wps", TREE_ATTR_WPS
, Icon_Wps
, VOICE_EXT_WPS
},
121 #ifdef HAVE_REMOTE_LCD
122 { "rwps", TREE_ATTR_RWPS
, Icon_Wps
, VOICE_EXT_RWPS
},
125 { "bmp", TREE_ATTR_BMP
, Icon_Wps
, VOICE_EXT_WPS
},
128 { "fmr", TREE_ATTR_FMR
, Icon_Preset
, LANG_FMR
},
130 { "lng", TREE_ATTR_LNG
, Icon_Language
, LANG_LANGUAGE
},
131 { "rock",TREE_ATTR_ROCK
,Icon_Plugin
, VOICE_EXT_ROCK
},
132 #ifdef HAVE_LCD_BITMAP
133 { "fnt", TREE_ATTR_FONT
,Icon_Font
, VOICE_EXT_FONT
},
134 { "kbd", TREE_ATTR_KBD
, Icon_Keyboard
, VOICE_EXT_KBD
},
136 { "bmark",TREE_ATTR_BMARK
, Icon_Bookmark
, VOICE_EXT_BMARK
},
137 { "cue", TREE_ATTR_CUE
, Icon_Bookmark
, LANG_CUESHEET
},
139 { BOOTFILE_EXT
, TREE_ATTR_MOD
, Icon_Firmware
, VOICE_EXT_AJZ
},
140 #endif /* #ifndef SIMULATOR */
143 struct gui_synclist tree_lists
;
145 /* I put it here because other files doesn't use it yet,
146 * but should be elsewhere since it will be used mostly everywhere */
148 struct gui_buttonbar tree_buttonbar
;
150 static struct tree_context tc
;
152 bool boot_changed
= false;
154 char lastfile
[MAX_PATH
];
155 static char lastdir
[MAX_PATH
];
157 static int lasttable
, lastextra
, lastfirstpos
;
159 static int max_files
= 0;
161 static bool reload_dir
= false;
163 static bool start_wps
= false;
164 static int curr_context
= false;/* id3db or tree*/
166 static int dirbrowse(void);
167 static int ft_play_filenumber(int pos
, int attr
);
168 static int ft_play_dirname(char* name
);
169 static void ft_play_filename(char *dir
, char *file
);
172 * removes the extension of filename (if it doesn't start with a .)
173 * puts the result in buffer
175 static char * strip_extension(char * filename
, char * buffer
)
178 char * dot
=strrchr(filename
, '.');
179 if(dot
!=0 && filename
[0]!='.')
181 dotpos
= dot
-filename
;
182 strncpy(buffer
, filename
, dotpos
);
190 static char * tree_get_filename(int selected_item
, void * data
, char *buffer
)
192 struct tree_context
* local_tc
=(struct tree_context
*)data
;
196 bool id3db
= *(local_tc
->dirfilter
) == SHOW_ID3DB
;
200 return tagtree_get_entry(&tc
, selected_item
)->name
;
205 struct entry
* dc
= local_tc
->dircache
;
206 struct entry
* e
= &dc
[selected_item
];
210 /* if any file filter is on, and if it's not a directory,
211 * strip the extension */
213 if ( (*(local_tc
->dirfilter
) != SHOW_ID3DB
) && !(attr
& ATTR_DIRECTORY
)
214 && (*(local_tc
->dirfilter
) != SHOW_ALL
) )
216 return(strip_extension(name
, buffer
));
222 static void tree_get_fileicon(int selected_item
, void * data
, ICON
* icon
)
224 struct tree_context
* local_tc
=(struct tree_context
*)data
;
226 bool id3db
= *(local_tc
->dirfilter
) == SHOW_ID3DB
;
228 *icon
= (ICON
)tagtree_get_icon(&tc
);
233 struct entry
* dc
= local_tc
->dircache
;
234 struct entry
* e
= &dc
[selected_item
];
235 *icon
= (ICON
)filetype_get_icon(e
->attr
);
239 bool check_rockboxdir(void)
241 DIR *dir
= opendir(ROCKBOX_DIR
);
243 { /* No need to localise this message.
244 If .rockbox is missing, it wouldn't work anyway */
247 screens
[i
].clear_display();
248 gui_syncsplash(HZ
*2, "No .rockbox directory");
250 screens
[i
].clear_display();
251 gui_syncsplash(HZ
*2, "Installation incomplete");
258 void browse_root(void)
260 gui_sync_wps_screen_init();
265 strcpy(tc
.currdir
, "/");
267 #ifdef HAVE_LCD_CHARCELLS
270 screens
[i
].double_height(false);
273 gui_buttonbar_init(&tree_buttonbar
);
274 /* since archos only have one screen, no need to create more than that */
275 gui_buttonbar_set_display(&tree_buttonbar
, &(screens
[SCREEN_MAIN
]) );
277 gui_synclist_init(&tree_lists
, &tree_get_filename
, &tc
, false, 1);
278 gui_synclist_set_icon_callback(&tree_lists
, &tree_get_fileicon
);
279 /* not the best place for this call... but... */
283 void tree_get_filetypes(const struct filetype
** types
, int* count
)
286 *count
= sizeof(filetypes
) / sizeof(*filetypes
);
289 struct tree_context
* tree_get_context(void)
294 /* talkbox hovering delay, to avoid immediate disk activity */
295 #define HOVER_DELAY (HZ/2)
297 * Returns the position of a given file in the current directory
298 * returns -1 if not found
300 static int tree_get_file_position(char * filename
)
304 /* use lastfile to determine the selected item (default=0) */
305 for (i
=0; i
< tc
.filesindir
; i
++)
307 struct entry
* dc
= tc
.dircache
;
308 struct entry
* e
= &dc
[i
];
309 if (!strcasecmp(e
->name
, filename
))
312 return(-1);/* no file can match, returns undefined */
316 * Called when a new dir is loaded (for example when returning from other apps ...)
317 * also completely redraws the tree
319 static int update_dir(void)
321 bool changed
= false;
323 bool id3db
= *tc
.dirfilter
== SHOW_ID3DB
;
324 /* Checks for changes */
326 if (tc
.currtable
!= lasttable
||
327 tc
.currextra
!= lastextra
||
328 tc
.firstpos
!= lastfirstpos
||
331 if (tagtree_load(&tc
) < 0)
334 lasttable
= tc
.currtable
;
335 lastextra
= tc
.currextra
;
336 lastfirstpos
= tc
.firstpos
;
343 /* if the tc.currdir has been changed, reload it ...*/
344 if (strncmp(tc
.currdir
, lastdir
, sizeof(lastdir
)) || reload_dir
) {
346 if (ft_load(&tc
, NULL
) < 0)
348 strcpy(lastdir
, tc
.currdir
);
352 /* if selected item is undefined */
353 if (tc
.selected_item
== -1)
355 /* use lastfile to determine the selected item */
356 tc
.selected_item
= tree_get_file_position(lastfile
);
358 /* If the file doesn't exists, select the first one (default) */
359 if(tc
.selected_item
< 0)
360 tc
.selected_item
= 0;
370 tc
.filesindir
== global_settings
.max_files_in_dir
) )
372 gui_syncsplash(HZ
, str(LANG_SHOWDIR_BUFFER_FULL
));
378 if (global_settings
.show_path_in_browser
== SHOW_PATH_FULL
379 || global_settings
.show_path_in_browser
== SHOW_PATH_CURRENT
)
381 gui_synclist_set_title(&tree_lists
, tagtree_get_title(&tc
),
382 filetype_get_icon(ATTR_DIRECTORY
));
386 /* Must clear the title as the list is reused */
387 gui_synclist_set_title(&tree_lists
, NULL
, NOICON
);
393 if (global_settings
.show_path_in_browser
== SHOW_PATH_FULL
)
395 gui_synclist_set_title(&tree_lists
, tc
.currdir
,
396 filetype_get_icon(ATTR_DIRECTORY
));
398 else if (global_settings
.show_path_in_browser
== SHOW_PATH_CURRENT
)
400 char *title
= strrchr(tc
.currdir
, '/') + 1;
403 /* Display "Files" for the root dir */
404 gui_synclist_set_title(&tree_lists
, str(LANG_DIR_BROWSER
),
405 filetype_get_icon(ATTR_DIRECTORY
));
408 gui_synclist_set_title(&tree_lists
, title
,
409 filetype_get_icon(ATTR_DIRECTORY
));
413 /* Must clear the title as the list is reused */
414 gui_synclist_set_title(&tree_lists
, NULL
, NOICON
);
418 gui_synclist_set_nb_items(&tree_lists
, tc
.filesindir
);
419 gui_synclist_set_icon_callback(&tree_lists
, tree_get_fileicon
);
420 if( tc
.selected_item
>= tc
.filesindir
)
421 tc
.selected_item
=tc
.filesindir
-1;
423 gui_synclist_select_item(&tree_lists
, tc
.selected_item
);
425 if (global_settings
.buttonbar
) {
426 if (*tc
.dirfilter
< NUM_FILTER_MODES
)
427 gui_buttonbar_set(&tree_buttonbar
, str(LANG_SYSFONT_DIRBROWSE_F1
),
428 str(LANG_SYSFONT_DIRBROWSE_F2
),
429 str(LANG_SYSFONT_DIRBROWSE_F3
));
431 gui_buttonbar_set(&tree_buttonbar
, "<<<", "", "");
432 gui_buttonbar_draw(&tree_buttonbar
);
435 gui_synclist_draw(&tree_lists
);
436 gui_syncstatusbar_draw(&statusbars
, true);
437 return tc
.filesindir
;
440 /* load tracks from specified directory to resume play */
441 void resume_directory(const char *dir
)
444 bool id3db
= *tc
.dirfilter
== SHOW_ID3DB
;
447 if (ft_load(&tc
, dir
) < 0)
451 ft_build_playlist(&tc
, 0);
459 /* Returns the current working directory and also writes cwd to buf if
460 non-NULL. In case of error, returns NULL. */
461 char *getcwd(char *buf
, int size
)
467 strncpy(buf
, tc
.currdir
, size
);
474 /* Force a reload of the directory next time directory browser is called */
475 void reload_directory(void)
480 void get_current_file(char* buffer
, int buffer_len
)
483 /* in ID3DB mode it is a bad idea to call this function */
484 /* (only happens with `follow playlist') */
485 if( *tc
.dirfilter
== SHOW_ID3DB
)
489 struct entry
* dc
= tc
.dircache
;
490 struct entry
* e
= &dc
[tc
.selected_item
];
491 snprintf(buffer
, buffer_len
, "%s/%s", getcwd(NULL
,0),
495 /* Selects a file and update tree context properly */
496 static void set_current_file(char *path
)
502 /* in ID3DB mode it is a bad idea to call this function */
503 /* (only happens with `follow playlist') */
504 if( *tc
.dirfilter
== SHOW_ID3DB
)
508 /* separate directory from filename */
509 /* gets the directory's name and put it into tc.currdir */
510 name
= strrchr(path
+1,'/');
514 strcpy(tc
.currdir
, path
);
520 strcpy(tc
.currdir
, "/");
524 strcpy(lastfile
, name
);
527 /* If we changed dir we must recalculate the dirlevel
528 and adjust the selected history properly */
529 if (strncmp(tc
.currdir
,lastdir
,sizeof(lastdir
)))
532 tc
.selected_item_history
[tc
.dirlevel
] = -1;
534 /* use '/' to calculate dirlevel */
535 for (i
= 1; path
[i
] != '\0'; i
++)
540 tc
.selected_item_history
[tc
.dirlevel
] = -1;
544 if (ft_load(&tc
, NULL
) >= 0)
546 tc
.selected_item
= tree_get_file_position(lastfile
);
550 #if defined(HAVE_TAGCACHE) && defined(HAVE_QUICKSCREEN)
551 static bool check_changed_id3mode(bool currmode
)
553 if (currmode
!= (global_settings
.dirfilter
== SHOW_ID3DB
)) {
554 currmode
= global_settings
.dirfilter
== SHOW_ID3DB
;
556 curr_context
=CONTEXT_ID3DB
;
563 curr_context
=CONTEXT_TREE
;
572 /* main loop, handles key events */
573 static int dirbrowse()
578 unsigned button
, returned_button
;
579 bool reload_root
= false;
580 int lastfilter
= *tc
.dirfilter
;
581 bool lastsortcase
= global_settings
.sort_case
;
582 bool need_update
= true;
583 bool exit_func
= false;
584 long thumbnail_time
= -1; /* for delaying a thumbnail */
585 long last_cancel
= 0;
587 char* currdir
= tc
.currdir
; /* just a shortcut */
589 bool id3db
= *tc
.dirfilter
== SHOW_ID3DB
;
592 curr_context
=CONTEXT_ID3DB
;
595 curr_context
=CONTEXT_TREE
;
596 if (tc
.selected_item
< 0)
597 tc
.selected_item
= 0;
606 numentries
= update_dir();
607 if (numentries
== -1)
608 return false; /* currdir is not a directory */
610 if (*tc
.dirfilter
> NUM_FILTER_MODES
&& numentries
==0)
612 gui_syncsplash(HZ
*2, str(LANG_NO_FILES
));
613 return false; /* No files found for rockbox_browser() */
617 struct entry
*dircache
= tc
.dircache
;
618 bool restore
= false;
620 tc
.dirlevel
= 0; /* shouldnt be needed.. this code needs work! */
623 char *lines
[]={str(LANG_BOOT_CHANGED
), str(LANG_REBOOT_NOW
)};
624 struct text_message message
={lines
, 2};
625 if(gui_syncyesno_run(&message
, NULL
, NULL
)==YESNO_YES
)
626 rolo_load("/" BOOTFILE
);
628 boot_changed
= false;
631 button
= get_action(CONTEXT_TREE
,HZ
/5);
632 returned_button
= gui_synclist_do_button(&tree_lists
, button
,LIST_WRAP_UNLESS_HELD
);
635 if (returned_button
== ACTION_STD_CANCEL
)
636 button
= ACTION_STD_CANCEL
;
638 tc
.selected_item
= gui_synclist_get_sel_pos(&tree_lists
);
641 /* nothing to do if no files to display */
642 if ( numentries
== 0 )
646 switch (id3db
?tagtree_enter(&tc
):ft_enter(&tc
))
648 switch (ft_enter(&tc
))
651 case 1: reload_dir
= true; break;
652 case 2: start_wps
= true; break;
653 case 3: exit_func
= true; break;
659 case ACTION_STD_CANCEL
:
660 if (*tc
.dirfilter
> NUM_FILTER_MODES
&& tc
.dirlevel
< 1) {
664 if ((*tc
.dirfilter
== SHOW_ID3DB
&& tc
.dirlevel
== 0) ||
665 ((*tc
.dirfilter
!= SHOW_ID3DB
&& !strcmp(currdir
,"/"))))
667 if (last_cancel
&& TIME_BEFORE(current_tick
, last_cancel
+HZ
/2))
670 action_signalscreenchange(); /* eat the cancel presses */
676 last_cancel
= current_tick
;
683 if (ft_exit(&tc
) == 3)
689 case ACTION_TREE_STOP
:
690 if (*tc
.dirfilter
< NUM_FILTER_MODES
)
692 /* Stop the music if it is playing */
694 if (!global_settings
.party_mode
) {
695 if (global_settings
.fade_on_stop
)
697 bookmark_autobookmark();
701 #if CONFIG_CHARGING && \
702 (CONFIG_KEYPAD == RECORDER_PAD) && !defined(HAVE_SW_POWEROFF)
704 if (!charger_inserted()) {
705 if(shutdown_screen())
714 #if CONFIG_CHARGING && !defined(HAVE_POWEROFF_WHILE_CHARGING)
716 static int last_off
= 0;
717 if (current_tick
- last_off
< 50) {
718 if (charger_inserted()) {
723 last_off
= current_tick
;
726 break; /* case ACTION_TREE_STOP: */
727 case ACTION_STD_MENU
:
731 case ACTION_TREE_WPS
:
732 return GO_TO_PREVIOUS_MUSIC
;
734 #ifdef HAVE_QUICKSCREEN
735 case ACTION_STD_QUICKSCREEN
:
736 /* don't enter f2 from plugin browser */
737 if (*tc
.dirfilter
< NUM_FILTER_MODES
)
739 if (quick_screen_quick(button
))
744 id3db
= check_changed_id3mode(id3db
);
752 /* don't enter f3 from plugin browser */
753 if (*tc
.dirfilter
< NUM_FILTER_MODES
)
755 if (quick_screen_f3(BUTTON_F3
))
762 case ACTION_STD_CONTEXT
:
768 onplay_result
= onplay(NULL
, 0, curr_context
);
773 if (tagtree_get_attr(&tc
) == TREE_ATTR_MPA
)
775 attr
= TREE_ATTR_MPA
;
776 tagtree_get_filename(&tc
, buf
, sizeof(buf
));
779 attr
= ATTR_DIRECTORY
;
784 attr
= dircache
[tc
.selected_item
].attr
;
786 if (currdir
[1]) /* Not in / */
787 snprintf(buf
, sizeof buf
, "%s/%s",
789 dircache
[tc
.selected_item
].name
);
791 snprintf(buf
, sizeof buf
, "/%s",
792 dircache
[tc
.selected_item
].name
);
794 onplay_result
= onplay(buf
, attr
, curr_context
);
796 switch (onplay_result
)
798 case ONPLAY_MAINMENU
:
805 case ONPLAY_RELOAD_DIR
:
809 case ONPLAY_START_PLAY
:
817 if (thumbnail_time
!= -1 &&
818 TIME_AFTER(current_tick
, thumbnail_time
))
819 { /* a delayed hovering thumbnail is due now */
827 attr
= tagtree_get_attr(&tc
);
828 name
= tagtree_get_entry(&tc
, lasti
)->name
;
833 attr
= dircache
[lasti
].attr
;
834 name
= dircache
[lasti
].name
;
837 if (attr
& ATTR_DIRECTORY
)
839 DEBUGF("Playing directory thumbnail: %s", currdir
);
840 res
= ft_play_dirname(name
);
841 if (res
< 0) /* failed, not existing */
842 { /* say the number instead, as a fallback */
843 talk_id(VOICE_DIR
, false);
844 talk_number(lasti
+1, true);
849 DEBUGF("Playing file thumbnail: %s/%s%s\n",
852 /* no fallback necessary, we knew in advance
853 that the file exists */
854 ft_play_filename(currdir
, name
);
856 thumbnail_time
= -1; /* job done */
858 gui_syncstatusbar_draw(&statusbars
, false);
867 /* The 'dir no longer valid' situation will be caught later
868 * by checking the showdir() result. */
873 if (default_event_handler(button
) == SYS_USB_CONNECTED
)
875 if(*tc
.dirfilter
> NUM_FILTER_MODES
)
876 /* leave sub-browsers after usb, doing otherwise
877 might be confusing to the user */
893 /* do we need to rescan dir? */
894 if (reload_dir
|| reload_root
||
895 lastfilter
!= *tc
.dirfilter
||
896 lastsortcase
!= global_settings
.sort_case
)
899 strcpy(currdir
, "/");
912 gui_synclist_select_item(&tree_lists
, 0);
913 gui_synclist_draw(&tree_lists
);
914 tc
.selected_item
= 0;
918 lastfilter
= *tc
.dirfilter
;
919 lastsortcase
= global_settings
.sort_case
;
924 return GO_TO_PREVIOUS
;
926 if (restore
|| reload_dir
) {
927 /* restore display */
928 numentries
= update_dir();
929 if (currdir
[1] && (numentries
< 0))
930 { /* not in root and reload failed */
931 reload_root
= true; /* try root */
941 if ( numentries
> 0 ) {
942 /* Voice the file if changed */
943 if(lasti
!= tc
.selected_item
|| restore
) {
947 lasti
= tc
.selected_item
;
948 thumbnail_time
= -1; /* Cancel whatever we were
954 attr
= tagtree_get_attr(&tc
);
955 name
= tagtree_get_entry(&tc
, tc
.selected_item
)->name
;
960 attr
= dircache
[tc
.selected_item
].attr
;
961 name
= dircache
[tc
.selected_item
].name
;
965 if (attr
& ATTR_DIRECTORY
)
967 /* play directory thumbnail */
968 switch (global_settings
.talk_dir
) {
969 case 1: /* dirs as numbers */
970 talk_id(VOICE_DIR
, false);
971 talk_number(tc
.selected_item
+1, true);
974 case 2: /* dirs spelled */
975 talk_spell(name
, false);
978 case 3: /* thumbnail clip */
979 /* "schedule" a thumbnail, to have a little
981 thumbnail_time
= current_tick
+ HOVER_DELAY
;
990 switch (global_settings
.talk_file
) {
991 case 1: /* files as numbers */
993 tc
.selected_item
-tc
.dirsindir
+1,
994 attr
& TREE_ATTR_MASK
);
997 case 2: /* files spelled */
998 talk_spell(name
, false);
1001 case 3: /* thumbnail clip */
1002 /* "schedule" a thumbnail, to have a little
1004 if (attr
& TREE_ATTR_THUMBNAIL
)
1005 thumbnail_time
= current_tick
+ HOVER_DELAY
;
1007 /* spell the number as fallback */
1008 talk_spell(name
, false);
1019 action_signalscreenchange();
1023 static int plsize
= 0;
1025 static bool add_dir(char* dirname
, int len
, int fd
)
1030 /* check for user abort */
1031 if (action_userabort(TIMEOUT_NOBLOCK
))
1034 dir
= opendir_cached(dirname
);
1039 struct dircache_entry
*entry
;
1041 entry
= readdir_cached(dir
);
1044 if (entry
->attribute
& ATTR_DIRECTORY
) {
1045 int dirlen
= strlen(dirname
);
1048 if (!strcmp((char *)entry
->d_name
, ".") ||
1049 !strcmp((char *)entry
->d_name
, ".."))
1053 snprintf(dirname
+dirlen
, len
-dirlen
, "/%s", entry
->d_name
);
1055 snprintf(dirname
, len
, "/%s", entry
->d_name
);
1057 result
= add_dir(dirname
, len
, fd
);
1058 dirname
[dirlen
] = '\0';
1065 int x
= strlen((char *)entry
->d_name
);
1067 char *cp
= strrchr((char *)entry
->d_name
,'.');
1072 /* add all supported audio files to playlists */
1073 for (i
=0; i
< sizeof(filetypes
)/sizeof(struct filetype
); i
++) {
1074 if (filetypes
[i
].tree_attr
== TREE_ATTR_MPA
) {
1075 if (!strcasecmp(cp
, filetypes
[i
].extension
)) {
1078 write(fd
, dirname
, strlen(dirname
));
1080 write(fd
, entry
->d_name
, x
);
1084 if(TIME_AFTER(current_tick
, pltick
+HZ
/4)) {
1085 pltick
= current_tick
;
1087 snprintf(buf
, sizeof buf
, "%d", plsize
);
1088 #ifdef HAVE_LCD_BITMAP
1091 screens
[i
].puts(0, 4, (unsigned char *)buf
);
1092 gui_textarea_update(&screens
[i
]);
1107 screens
[i
].puts(x
,0,buf
);
1118 closedir_cached(dir
);
1123 bool create_playlist(void)
1127 char filename
[MAX_PATH
];
1129 pltick
= current_tick
;
1131 snprintf(filename
, sizeof filename
, "%s.m3u8",
1132 tc
.currdir
[1] ? tc
.currdir
: "/root");
1135 gui_textarea_clear(&screens
[i
]);
1136 screens
[i
].puts(0, 0, str(LANG_CREATING
));
1137 screens
[i
].puts_scroll(0, 1, (unsigned char *)filename
);
1138 #if defined(HAVE_LCD_BITMAP) || defined(SIMULATOR)
1139 gui_textarea_update(&screens
[i
]);
1142 fd
= creat(filename
);
1146 trigger_cpu_boost();
1148 snprintf(filename
, sizeof(filename
), "%s",
1149 tc
.currdir
[1] ? tc
.currdir
: "/");
1151 add_dir(filename
, sizeof(filename
), fd
);
1159 int rockbox_browse(const char *root
, int dirfilter
)
1162 int *last_filter
= tc
.dirfilter
;
1163 tc
.dirfilter
= &dirfilter
;
1166 if (dirfilter
>= NUM_FILTER_MODES
)
1168 static struct tree_context backup
;
1172 tc
.selected_item
= 0;
1174 memcpy(tc
.currdir
, root
, sizeof(tc
.currdir
));
1176 last_context
= curr_context
;
1178 ret_val
= dirbrowse();
1180 curr_context
= last_context
;
1184 static char buf
[MAX_PATH
];
1185 if (dirfilter
!= SHOW_ID3DB
)
1186 tc
.dirfilter
= &global_settings
.dirfilter
;
1188 set_current_file(buf
);
1189 ret_val
= dirbrowse();
1191 tc
.dirfilter
= last_filter
;
1195 void tree_init(void)
1197 /* We copy the settings value in case it is changed by the user. We can't
1198 use it until the next reboot. */
1199 max_files
= global_settings
.max_files_in_dir
;
1201 /* initialize tree context struct */
1202 memset(&tc
, 0, sizeof(tc
));
1203 tc
.dirfilter
= &global_settings
.dirfilter
;
1205 tc
.name_buffer_size
= AVERAGE_FILENAME_LENGTH
* max_files
;
1206 tc
.name_buffer
= buffer_alloc(tc
.name_buffer_size
);
1208 tc
.dircache_size
= max_files
* sizeof(struct entry
);
1209 tc
.dircache
= buffer_alloc(tc
.dircache_size
);
1212 void bookmark_play(char *resume_file
, int index
, int offset
, int seed
,
1216 char* suffix
= strrchr(resume_file
, '.');
1218 if (suffix
!= NULL
&&
1219 (!strcasecmp(suffix
, ".m3u") || !strcasecmp(suffix
, ".m3u8")))
1221 /* Playlist playback */
1223 /* check that the file exists */
1224 int fd
= open(resume_file
, O_RDONLY
);
1229 slash
= strrchr(resume_file
,'/');
1239 if (playlist_create(cp
, slash
+1) != -1)
1241 if (global_settings
.playlist_shuffle
)
1242 playlist_shuffle(seed
, -1);
1243 playlist_start(index
,offset
);
1250 /* Directory playback */
1252 if (playlist_create(resume_file
, NULL
) != -1)
1254 resume_directory(resume_file
);
1255 if (global_settings
.playlist_shuffle
)
1256 playlist_shuffle(seed
, -1);
1258 /* Check if the file is at the same spot in the directory,
1259 else search for it */
1260 if ((strcmp(strrchr(playlist_peek(index
),'/') + 1,
1263 for ( i
=0; i
< playlist_amount(); i
++ )
1265 if ((strcmp(strrchr(playlist_peek(i
),'/') + 1,
1269 if (i
< playlist_amount())
1274 playlist_start(index
,offset
);
1281 static int ft_play_filenumber(int pos
, int attr
)
1283 /* try to find a voice ID for the extension, if known */
1285 int ext_id
= -1; /* default to none */
1286 for (j
=0; j
<sizeof(filetypes
)/sizeof(*filetypes
); j
++)
1288 if (attr
== filetypes
[j
].tree_attr
)
1290 ext_id
= filetypes
[j
].voiceclip
;
1295 talk_id(VOICE_FILE
, false);
1296 talk_number(pos
, true);
1297 talk_id(ext_id
, true);
1301 static int ft_play_dirname(char* name
)
1304 char dirname_mp3_filename
[MAX_PATH
+1];
1306 #if CONFIG_CODEC != SWCODEC
1307 if (audio_status() & AUDIO_STATUS_PLAY
)
1311 snprintf(dirname_mp3_filename
, sizeof(dirname_mp3_filename
), "%s/%s/%s",
1312 tc
.currdir
[1] ? tc
.currdir
: "" , name
,
1313 dir_thumbnail_name
);
1315 DEBUGF("Checking for %s\n", dirname_mp3_filename
);
1317 fd
= open(dirname_mp3_filename
, O_RDONLY
);
1320 DEBUGF("Failed to find: %s\n", dirname_mp3_filename
);
1326 DEBUGF("Found: %s\n", dirname_mp3_filename
);
1328 talk_file(dirname_mp3_filename
, false);
1332 static void ft_play_filename(char *dir
, char *file
)
1334 char name_mp3_filename
[MAX_PATH
+1];
1336 #if CONFIG_CODEC != SWCODEC
1337 if (audio_status() & AUDIO_STATUS_PLAY
)
1341 if (strcasecmp(&file
[strlen(file
) - strlen(file_thumbnail_ext
)],
1342 file_thumbnail_ext
))
1343 { /* file has no .talk extension */
1344 snprintf(name_mp3_filename
, sizeof(name_mp3_filename
),
1345 "%s/%s%s", dir
, file
, file_thumbnail_ext
);
1347 talk_file(name_mp3_filename
, false);
1350 { /* it already is a .talk file, play this directly */
1351 snprintf(name_mp3_filename
, sizeof(name_mp3_filename
),
1352 "%s/%s", dir
, file
);
1353 talk_id(LANG_VOICE_DIR_HOVER
, false); /* prefix it */
1354 talk_file(name_mp3_filename
, true);
1358 /* These two functions are called by the USB and shutdown handlers */
1359 void tree_flush(void)
1361 scrobbler_shutdown();
1362 #ifdef HAVE_TAGCACHE
1363 tagcache_shutdown();
1365 playlist_shutdown();
1367 #ifdef HAVE_TC_RAMCACHE
1368 tagcache_unload_ramcache();
1371 #ifdef HAVE_DIRCACHE
1373 int old_val
= global_status
.dircache_size
;
1374 if (global_settings
.dircache
)
1376 global_status
.dircache_size
= dircache_get_cache_size();
1377 # ifdef HAVE_EEPROM_SETTINGS
1384 global_status
.dircache_size
= 0;
1386 if (old_val
!= global_status
.dircache_size
)
1392 void tree_restore(void)
1394 #ifdef HAVE_EEPROM_SETTINGS
1395 firmware_settings
.disk_clean
= false;
1398 #ifdef HAVE_TC_RAMCACHE
1399 remove(TAGCACHE_STATEFILE
);
1402 #ifdef HAVE_DIRCACHE
1403 remove(DIRCACHE_FILE
);
1404 if (global_settings
.dircache
)
1406 /* Print "Scanning disk..." to the display. */
1410 screens
[i
].putsxy((LCD_WIDTH
/2) -
1411 ((strlen(str(LANG_DIRCACHE_BUILDING
)) *
1412 screens
[i
].char_width
)/2),
1413 LCD_HEIGHT
-screens
[i
].char_height
*3,
1414 str(LANG_DIRCACHE_BUILDING
));
1415 gui_textarea_update(&screens
[i
]);
1418 dircache_build(global_status
.dircache_size
);
1420 /* Clean the text when we are done. */
1423 gui_textarea_clear(&screens
[i
]);
1427 #ifdef HAVE_TAGCACHE
1428 tagcache_start_scan();