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();
264 strcpy(tc
.currdir
, "/");
266 #ifdef HAVE_LCD_CHARCELLS
269 screens
[i
].double_height(false);
272 gui_buttonbar_init(&tree_buttonbar
);
273 /* since archos only have one screen, no need to create more than that */
274 gui_buttonbar_set_display(&tree_buttonbar
, &(screens
[SCREEN_MAIN
]) );
276 gui_synclist_init(&tree_lists
, &tree_get_filename
, &tc
, false, 1);
277 gui_synclist_set_icon_callback(&tree_lists
, &tree_get_fileicon
);
278 /* not the best place for this call... but... */
282 void tree_get_filetypes(const struct filetype
** types
, int* count
)
285 *count
= sizeof(filetypes
) / sizeof(*filetypes
);
288 struct tree_context
* tree_get_context(void)
293 /* talkbox hovering delay, to avoid immediate disk activity */
294 #define HOVER_DELAY (HZ/2)
296 * Returns the position of a given file in the current directory
297 * returns -1 if not found
299 static int tree_get_file_position(char * filename
)
303 /* use lastfile to determine the selected item (default=0) */
304 for (i
=0; i
< tc
.filesindir
; i
++)
306 struct entry
* dc
= tc
.dircache
;
307 struct entry
* e
= &dc
[i
];
308 if (!strcasecmp(e
->name
, filename
))
311 return(-1);/* no file can match, returns undefined */
315 * Called when a new dir is loaded (for example when returning from other apps ...)
316 * also completely redraws the tree
318 static int update_dir(void)
320 bool changed
= false;
322 bool id3db
= *tc
.dirfilter
== SHOW_ID3DB
;
323 /* Checks for changes */
325 if (tc
.currtable
!= lasttable
||
326 tc
.currextra
!= lastextra
||
327 tc
.firstpos
!= lastfirstpos
||
330 if (tagtree_load(&tc
) < 0)
333 lasttable
= tc
.currtable
;
334 lastextra
= tc
.currextra
;
335 lastfirstpos
= tc
.firstpos
;
342 /* if the tc.currdir has been changed, reload it ...*/
343 if (strncmp(tc
.currdir
, lastdir
, sizeof(lastdir
)) || reload_dir
) {
345 if (ft_load(&tc
, NULL
) < 0)
347 strcpy(lastdir
, tc
.currdir
);
351 /* if selected item is undefined */
352 if (tc
.selected_item
== -1)
354 /* use lastfile to determine the selected item */
355 tc
.selected_item
= tree_get_file_position(lastfile
);
357 /* If the file doesn't exists, select the first one (default) */
358 if(tc
.selected_item
< 0)
359 tc
.selected_item
= 0;
369 tc
.filesindir
== global_settings
.max_files_in_dir
) )
371 gui_syncsplash(HZ
, str(LANG_SHOWDIR_BUFFER_FULL
));
377 if (global_settings
.show_path_in_browser
== SHOW_PATH_FULL
378 || global_settings
.show_path_in_browser
== SHOW_PATH_CURRENT
)
380 gui_synclist_set_title(&tree_lists
, tagtree_get_title(&tc
),
381 filetype_get_icon(ATTR_DIRECTORY
));
385 /* Must clear the title as the list is reused */
386 gui_synclist_set_title(&tree_lists
, NULL
, NOICON
);
392 if (global_settings
.show_path_in_browser
== SHOW_PATH_FULL
)
394 gui_synclist_set_title(&tree_lists
, tc
.currdir
,
395 filetype_get_icon(ATTR_DIRECTORY
));
397 else if (global_settings
.show_path_in_browser
== SHOW_PATH_CURRENT
)
399 char *title
= strrchr(tc
.currdir
, '/') + 1;
402 /* Display "Files" for the root dir */
403 gui_synclist_set_title(&tree_lists
, str(LANG_DIR_BROWSER
),
404 filetype_get_icon(ATTR_DIRECTORY
));
407 gui_synclist_set_title(&tree_lists
, title
,
408 filetype_get_icon(ATTR_DIRECTORY
));
412 /* Must clear the title as the list is reused */
413 gui_synclist_set_title(&tree_lists
, NULL
, NOICON
);
417 gui_synclist_set_nb_items(&tree_lists
, tc
.filesindir
);
418 gui_synclist_set_icon_callback(&tree_lists
, tree_get_fileicon
);
419 if( tc
.selected_item
>= tc
.filesindir
)
420 tc
.selected_item
=tc
.filesindir
-1;
422 gui_synclist_select_item(&tree_lists
, tc
.selected_item
);
424 if (global_settings
.buttonbar
) {
425 if (*tc
.dirfilter
< NUM_FILTER_MODES
)
426 gui_buttonbar_set(&tree_buttonbar
, str(LANG_SYSFONT_DIRBROWSE_F1
),
427 str(LANG_SYSFONT_DIRBROWSE_F2
),
428 str(LANG_SYSFONT_DIRBROWSE_F3
));
430 gui_buttonbar_set(&tree_buttonbar
, "<<<", "", "");
431 gui_buttonbar_draw(&tree_buttonbar
);
434 gui_synclist_draw(&tree_lists
);
435 gui_syncstatusbar_draw(&statusbars
, true);
436 return tc
.filesindir
;
439 /* load tracks from specified directory to resume play */
440 void resume_directory(const char *dir
)
443 bool id3db
= *tc
.dirfilter
== SHOW_ID3DB
;
446 if (ft_load(&tc
, dir
) < 0)
450 ft_build_playlist(&tc
, 0);
458 /* Returns the current working directory and also writes cwd to buf if
459 non-NULL. In case of error, returns NULL. */
460 char *getcwd(char *buf
, int size
)
466 strncpy(buf
, tc
.currdir
, size
);
473 /* Force a reload of the directory next time directory browser is called */
474 void reload_directory(void)
479 void get_current_file(char* buffer
, int buffer_len
)
482 /* in ID3DB mode it is a bad idea to call this function */
483 /* (only happens with `follow playlist') */
484 if( *tc
.dirfilter
== SHOW_ID3DB
)
488 struct entry
* dc
= tc
.dircache
;
489 struct entry
* e
= &dc
[tc
.selected_item
];
490 snprintf(buffer
, buffer_len
, "%s/%s", getcwd(NULL
,0),
494 /* Selects a file and update tree context properly */
495 static void set_current_file(char *path
)
501 /* in ID3DB mode it is a bad idea to call this function */
502 /* (only happens with `follow playlist') */
503 if( *tc
.dirfilter
== SHOW_ID3DB
)
507 /* separate directory from filename */
508 /* gets the directory's name and put it into tc.currdir */
509 name
= strrchr(path
+1,'/');
513 strcpy(tc
.currdir
, path
);
519 strcpy(tc
.currdir
, "/");
523 strcpy(lastfile
, name
);
526 /* If we changed dir we must recalculate the dirlevel
527 and adjust the selected history properly */
528 if (strncmp(tc
.currdir
,lastdir
,sizeof(lastdir
)))
531 tc
.selected_item_history
[tc
.dirlevel
] = -1;
533 /* use '/' to calculate dirlevel */
534 for (i
= 1; path
[i
] != '\0'; i
++)
539 tc
.selected_item_history
[tc
.dirlevel
] = -1;
543 if (ft_load(&tc
, NULL
) >= 0)
545 tc
.selected_item
= tree_get_file_position(lastfile
);
550 /* main loop, handles key events */
551 static int dirbrowse()
556 unsigned button
, returned_button
;
557 bool reload_root
= false;
558 int lastfilter
= *tc
.dirfilter
;
559 bool lastsortcase
= global_settings
.sort_case
;
560 bool need_update
= true;
561 bool exit_func
= false;
562 long thumbnail_time
= -1; /* for delaying a thumbnail */
563 long last_cancel
= 0;
565 char* currdir
= tc
.currdir
; /* just a shortcut */
567 bool id3db
= *tc
.dirfilter
== SHOW_ID3DB
;
570 curr_context
=CONTEXT_ID3DB
;
573 curr_context
=CONTEXT_TREE
;
574 if (tc
.selected_item
< 0)
575 tc
.selected_item
= 0;
584 numentries
= update_dir();
585 if (numentries
== -1)
586 return false; /* currdir is not a directory */
588 if (*tc
.dirfilter
> NUM_FILTER_MODES
&& numentries
==0)
590 gui_syncsplash(HZ
*2, str(LANG_NO_FILES
));
591 return false; /* No files found for rockbox_browser() */
595 struct entry
*dircache
= tc
.dircache
;
596 bool restore
= false;
598 tc
.dirlevel
= 0; /* shouldnt be needed.. this code needs work! */
601 char *lines
[]={str(LANG_BOOT_CHANGED
), str(LANG_REBOOT_NOW
)};
602 struct text_message message
={lines
, 2};
603 if(gui_syncyesno_run(&message
, NULL
, NULL
)==YESNO_YES
)
604 rolo_load("/" BOOTFILE
);
606 boot_changed
= false;
609 button
= get_action(CONTEXT_TREE
,HZ
/5);
610 returned_button
= gui_synclist_do_button(&tree_lists
, button
,LIST_WRAP_UNLESS_HELD
);
613 if (returned_button
== ACTION_STD_CANCEL
)
614 button
= ACTION_STD_CANCEL
;
616 tc
.selected_item
= gui_synclist_get_sel_pos(&tree_lists
);
619 /* nothing to do if no files to display */
620 if ( numentries
== 0 )
624 switch (id3db
?tagtree_enter(&tc
):ft_enter(&tc
))
626 switch (ft_enter(&tc
))
629 case 1: reload_dir
= true; break;
630 case 2: start_wps
= true; break;
631 case 3: exit_func
= true; break;
637 case ACTION_STD_CANCEL
:
638 if (*tc
.dirfilter
> NUM_FILTER_MODES
&& tc
.dirlevel
< 1) {
642 if ((*tc
.dirfilter
== SHOW_ID3DB
&& tc
.dirlevel
== 0) ||
643 ((*tc
.dirfilter
!= SHOW_ID3DB
&& !strcmp(currdir
,"/"))))
645 if (last_cancel
&& TIME_BEFORE(current_tick
, last_cancel
+HZ
/2))
648 action_signalscreenchange(); /* eat the cancel presses */
654 last_cancel
= current_tick
;
661 if (ft_exit(&tc
) == 3)
667 case ACTION_TREE_STOP
:
668 if (*tc
.dirfilter
< NUM_FILTER_MODES
)
670 /* Stop the music if it is playing */
672 if (!global_settings
.party_mode
) {
673 if (global_settings
.fade_on_stop
)
675 bookmark_autobookmark();
679 #if CONFIG_CHARGING && \
680 (CONFIG_KEYPAD == RECORDER_PAD) && !defined(HAVE_SW_POWEROFF)
682 if (!charger_inserted()) {
683 if(shutdown_screen())
692 #if CONFIG_CHARGING && !defined(HAVE_POWEROFF_WHILE_CHARGING)
694 static int last_off
= 0;
695 if (current_tick
- last_off
< 50) {
696 if (charger_inserted()) {
701 last_off
= current_tick
;
704 break; /* case ACTION_TREE_STOP: */
705 case ACTION_STD_MENU
:
709 case ACTION_TREE_WPS
:
710 return GO_TO_PREVIOUS_MUSIC
;
712 #ifdef HAVE_QUICKSCREEN
713 case ACTION_STD_QUICKSCREEN
:
714 /* don't enter f2 from plugin browser */
715 if (*tc
.dirfilter
< NUM_FILTER_MODES
)
717 if (quick_screen_quick(button
))
725 /* don't enter f3 from plugin browser */
726 if (*tc
.dirfilter
< NUM_FILTER_MODES
)
728 if (quick_screen_f3(BUTTON_F3
))
735 case ACTION_STD_CONTEXT
:
741 onplay_result
= onplay(NULL
, 0, curr_context
);
746 if (tagtree_get_attr(&tc
) == TREE_ATTR_MPA
)
748 attr
= TREE_ATTR_MPA
;
749 tagtree_get_filename(&tc
, buf
, sizeof(buf
));
752 attr
= ATTR_DIRECTORY
;
757 attr
= dircache
[tc
.selected_item
].attr
;
759 if (currdir
[1]) /* Not in / */
760 snprintf(buf
, sizeof buf
, "%s/%s",
762 dircache
[tc
.selected_item
].name
);
764 snprintf(buf
, sizeof buf
, "/%s",
765 dircache
[tc
.selected_item
].name
);
767 onplay_result
= onplay(buf
, attr
, curr_context
);
769 switch (onplay_result
)
771 case ONPLAY_MAINMENU
:
778 case ONPLAY_RELOAD_DIR
:
782 case ONPLAY_START_PLAY
:
790 if (thumbnail_time
!= -1 &&
791 TIME_AFTER(current_tick
, thumbnail_time
))
792 { /* a delayed hovering thumbnail is due now */
800 attr
= tagtree_get_attr(&tc
);
801 name
= tagtree_get_entry(&tc
, lasti
)->name
;
806 attr
= dircache
[lasti
].attr
;
807 name
= dircache
[lasti
].name
;
810 if (attr
& ATTR_DIRECTORY
)
812 DEBUGF("Playing directory thumbnail: %s", currdir
);
813 res
= ft_play_dirname(name
);
814 if (res
< 0) /* failed, not existing */
815 { /* say the number instead, as a fallback */
816 talk_id(VOICE_DIR
, false);
817 talk_number(lasti
+1, true);
822 DEBUGF("Playing file thumbnail: %s/%s%s\n",
825 /* no fallback necessary, we knew in advance
826 that the file exists */
827 ft_play_filename(currdir
, name
);
829 thumbnail_time
= -1; /* job done */
831 gui_syncstatusbar_draw(&statusbars
, false);
840 /* The 'dir no longer valid' situation will be caught later
841 * by checking the showdir() result. */
846 if (default_event_handler(button
) == SYS_USB_CONNECTED
)
848 if(*tc
.dirfilter
> NUM_FILTER_MODES
)
849 /* leave sub-browsers after usb, doing otherwise
850 might be confusing to the user */
866 /* do we need to rescan dir? */
867 if (reload_dir
|| reload_root
||
868 lastfilter
!= *tc
.dirfilter
||
869 lastsortcase
!= global_settings
.sort_case
)
872 strcpy(currdir
, "/");
885 gui_synclist_select_item(&tree_lists
, 0);
886 gui_synclist_draw(&tree_lists
);
887 tc
.selected_item
= 0;
891 lastfilter
= *tc
.dirfilter
;
892 lastsortcase
= global_settings
.sort_case
;
897 return GO_TO_PREVIOUS
;
899 if (restore
|| reload_dir
) {
900 /* restore display */
901 numentries
= update_dir();
902 if (currdir
[1] && (numentries
< 0))
903 { /* not in root and reload failed */
904 reload_root
= true; /* try root */
914 if ( numentries
> 0 ) {
915 /* Voice the file if changed */
916 if(lasti
!= tc
.selected_item
|| restore
) {
920 lasti
= tc
.selected_item
;
921 thumbnail_time
= -1; /* Cancel whatever we were
927 attr
= tagtree_get_attr(&tc
);
928 name
= tagtree_get_entry(&tc
, tc
.selected_item
)->name
;
933 attr
= dircache
[tc
.selected_item
].attr
;
934 name
= dircache
[tc
.selected_item
].name
;
938 if (attr
& ATTR_DIRECTORY
)
940 /* play directory thumbnail */
941 switch (global_settings
.talk_dir
) {
942 case 1: /* dirs as numbers */
943 talk_id(VOICE_DIR
, false);
944 talk_number(tc
.selected_item
+1, true);
947 case 2: /* dirs spelled */
948 talk_spell(name
, false);
951 case 3: /* thumbnail clip */
952 /* "schedule" a thumbnail, to have a little
954 thumbnail_time
= current_tick
+ HOVER_DELAY
;
963 switch (global_settings
.talk_file
) {
964 case 1: /* files as numbers */
966 tc
.selected_item
-tc
.dirsindir
+1,
967 attr
& TREE_ATTR_MASK
);
970 case 2: /* files spelled */
971 talk_spell(name
, false);
974 case 3: /* thumbnail clip */
975 /* "schedule" a thumbnail, to have a little
977 if (attr
& TREE_ATTR_THUMBNAIL
)
978 thumbnail_time
= current_tick
+ HOVER_DELAY
;
980 /* spell the number as fallback */
981 talk_spell(name
, false);
992 action_signalscreenchange();
996 static int plsize
= 0;
998 static bool add_dir(char* dirname
, int len
, int fd
)
1003 /* check for user abort */
1004 if (action_userabort(TIMEOUT_NOBLOCK
))
1007 dir
= opendir_cached(dirname
);
1012 struct dircache_entry
*entry
;
1014 entry
= readdir_cached(dir
);
1017 if (entry
->attribute
& ATTR_DIRECTORY
) {
1018 int dirlen
= strlen(dirname
);
1021 if (!strcmp((char *)entry
->d_name
, ".") ||
1022 !strcmp((char *)entry
->d_name
, ".."))
1026 snprintf(dirname
+dirlen
, len
-dirlen
, "/%s", entry
->d_name
);
1028 snprintf(dirname
, len
, "/%s", entry
->d_name
);
1030 result
= add_dir(dirname
, len
, fd
);
1031 dirname
[dirlen
] = '\0';
1038 int x
= strlen((char *)entry
->d_name
);
1040 char *cp
= strrchr((char *)entry
->d_name
,'.');
1045 /* add all supported audio files to playlists */
1046 for (i
=0; i
< sizeof(filetypes
)/sizeof(struct filetype
); i
++) {
1047 if (filetypes
[i
].tree_attr
== TREE_ATTR_MPA
) {
1048 if (!strcasecmp(cp
, filetypes
[i
].extension
)) {
1051 write(fd
, dirname
, strlen(dirname
));
1053 write(fd
, entry
->d_name
, x
);
1057 if(TIME_AFTER(current_tick
, pltick
+HZ
/4)) {
1058 pltick
= current_tick
;
1060 snprintf(buf
, sizeof buf
, "%d", plsize
);
1061 #ifdef HAVE_LCD_BITMAP
1064 screens
[i
].puts(0, 4, (unsigned char *)buf
);
1065 gui_textarea_update(&screens
[i
]);
1080 screens
[i
].puts(x
,0,buf
);
1091 closedir_cached(dir
);
1096 bool create_playlist(void)
1100 char filename
[MAX_PATH
];
1102 pltick
= current_tick
;
1104 snprintf(filename
, sizeof filename
, "%s.m3u8",
1105 tc
.currdir
[1] ? tc
.currdir
: "/root");
1108 gui_textarea_clear(&screens
[i
]);
1109 screens
[i
].puts(0, 0, str(LANG_CREATING
));
1110 screens
[i
].puts_scroll(0, 1, (unsigned char *)filename
);
1111 #if defined(HAVE_LCD_BITMAP) || defined(SIMULATOR)
1112 gui_textarea_update(&screens
[i
]);
1115 fd
= creat(filename
);
1119 trigger_cpu_boost();
1121 snprintf(filename
, sizeof(filename
), "%s",
1122 tc
.currdir
[1] ? tc
.currdir
: "/");
1124 add_dir(filename
, sizeof(filename
), fd
);
1132 int rockbox_browse(const char *root
, int dirfilter
)
1135 int *last_filter
= tc
.dirfilter
;
1136 tc
.dirfilter
= &dirfilter
;
1139 if (dirfilter
>= NUM_FILTER_MODES
)
1141 static struct tree_context backup
;
1145 tc
.selected_item
= 0;
1147 memcpy(tc
.currdir
, root
, sizeof(tc
.currdir
));
1149 last_context
= curr_context
;
1151 ret_val
= dirbrowse();
1153 curr_context
= last_context
;
1157 static char buf
[MAX_PATH
];
1158 if (dirfilter
!= SHOW_ID3DB
)
1159 tc
.dirfilter
= &global_settings
.dirfilter
;
1161 set_current_file(buf
);
1162 ret_val
= dirbrowse();
1164 tc
.dirfilter
= last_filter
;
1168 void tree_init(void)
1170 /* We copy the settings value in case it is changed by the user. We can't
1171 use it until the next reboot. */
1172 max_files
= global_settings
.max_files_in_dir
;
1174 /* initialize tree context struct */
1175 memset(&tc
, 0, sizeof(tc
));
1176 tc
.dirfilter
= &global_settings
.dirfilter
;
1178 tc
.name_buffer_size
= AVERAGE_FILENAME_LENGTH
* max_files
;
1179 tc
.name_buffer
= buffer_alloc(tc
.name_buffer_size
);
1181 tc
.dircache_size
= max_files
* sizeof(struct entry
);
1182 tc
.dircache
= buffer_alloc(tc
.dircache_size
);
1185 void bookmark_play(char *resume_file
, int index
, int offset
, int seed
,
1189 char* suffix
= strrchr(resume_file
, '.');
1191 if (suffix
!= NULL
&&
1192 (!strcasecmp(suffix
, ".m3u") || !strcasecmp(suffix
, ".m3u8")))
1194 /* Playlist playback */
1196 /* check that the file exists */
1197 int fd
= open(resume_file
, O_RDONLY
);
1202 slash
= strrchr(resume_file
,'/');
1212 if (playlist_create(cp
, slash
+1) != -1)
1214 if (global_settings
.playlist_shuffle
)
1215 playlist_shuffle(seed
, -1);
1216 playlist_start(index
,offset
);
1223 /* Directory playback */
1225 if (playlist_create(resume_file
, NULL
) != -1)
1227 resume_directory(resume_file
);
1228 if (global_settings
.playlist_shuffle
)
1229 playlist_shuffle(seed
, -1);
1231 /* Check if the file is at the same spot in the directory,
1232 else search for it */
1233 if ((strcmp(strrchr(playlist_peek(index
),'/') + 1,
1236 for ( i
=0; i
< playlist_amount(); i
++ )
1238 if ((strcmp(strrchr(playlist_peek(i
),'/') + 1,
1242 if (i
< playlist_amount())
1247 playlist_start(index
,offset
);
1254 static int ft_play_filenumber(int pos
, int attr
)
1256 /* try to find a voice ID for the extension, if known */
1258 int ext_id
= -1; /* default to none */
1259 for (j
=0; j
<sizeof(filetypes
)/sizeof(*filetypes
); j
++)
1261 if (attr
== filetypes
[j
].tree_attr
)
1263 ext_id
= filetypes
[j
].voiceclip
;
1268 talk_id(VOICE_FILE
, false);
1269 talk_number(pos
, true);
1270 talk_id(ext_id
, true);
1274 static int ft_play_dirname(char* name
)
1277 char dirname_mp3_filename
[MAX_PATH
+1];
1279 #if CONFIG_CODEC != SWCODEC
1280 if (audio_status() & AUDIO_STATUS_PLAY
)
1284 snprintf(dirname_mp3_filename
, sizeof(dirname_mp3_filename
), "%s/%s/%s",
1285 tc
.currdir
[1] ? tc
.currdir
: "" , name
,
1286 dir_thumbnail_name
);
1288 DEBUGF("Checking for %s\n", dirname_mp3_filename
);
1290 fd
= open(dirname_mp3_filename
, O_RDONLY
);
1293 DEBUGF("Failed to find: %s\n", dirname_mp3_filename
);
1299 DEBUGF("Found: %s\n", dirname_mp3_filename
);
1301 talk_file(dirname_mp3_filename
, false);
1305 static void ft_play_filename(char *dir
, char *file
)
1307 char name_mp3_filename
[MAX_PATH
+1];
1309 #if CONFIG_CODEC != SWCODEC
1310 if (audio_status() & AUDIO_STATUS_PLAY
)
1314 if (strcasecmp(&file
[strlen(file
) - strlen(file_thumbnail_ext
)],
1315 file_thumbnail_ext
))
1316 { /* file has no .talk extension */
1317 snprintf(name_mp3_filename
, sizeof(name_mp3_filename
),
1318 "%s/%s%s", dir
, file
, file_thumbnail_ext
);
1320 talk_file(name_mp3_filename
, false);
1323 { /* it already is a .talk file, play this directly */
1324 snprintf(name_mp3_filename
, sizeof(name_mp3_filename
),
1325 "%s/%s", dir
, file
);
1326 talk_id(LANG_VOICE_DIR_HOVER
, false); /* prefix it */
1327 talk_file(name_mp3_filename
, true);
1331 /* These two functions are called by the USB and shutdown handlers */
1332 void tree_flush(void)
1334 scrobbler_shutdown();
1335 #ifdef HAVE_TAGCACHE
1336 tagcache_shutdown();
1338 playlist_shutdown();
1340 #ifdef HAVE_TC_RAMCACHE
1341 tagcache_unload_ramcache();
1344 #ifdef HAVE_DIRCACHE
1346 int old_val
= global_status
.dircache_size
;
1347 if (global_settings
.dircache
)
1349 global_status
.dircache_size
= dircache_get_cache_size();
1350 # ifdef HAVE_EEPROM_SETTINGS
1357 global_status
.dircache_size
= 0;
1359 if (old_val
!= global_status
.dircache_size
)
1365 void tree_restore(void)
1367 #ifdef HAVE_EEPROM_SETTINGS
1368 firmware_settings
.disk_clean
= false;
1371 #ifdef HAVE_TC_RAMCACHE
1372 remove(TAGCACHE_STATEFILE
);
1375 #ifdef HAVE_DIRCACHE
1376 remove(DIRCACHE_FILE
);
1377 if (global_settings
.dircache
)
1379 /* Print "Scanning disk..." to the display. */
1383 screens
[i
].putsxy((LCD_WIDTH
/2) -
1384 ((strlen(str(LANG_DIRCACHE_BUILDING
)) *
1385 screens
[i
].char_width
)/2),
1386 LCD_HEIGHT
-screens
[i
].char_height
*3,
1387 str(LANG_DIRCACHE_BUILDING
));
1388 gui_textarea_update(&screens
[i
]);
1391 dircache_build(global_status
.dircache_size
);
1393 /* Clean the text when we are done. */
1396 gui_textarea_clear(&screens
[i
]);
1400 #ifdef HAVE_TAGCACHE
1401 tagcache_start_scan();