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*/
169 * removes the extension of filename (if it doesn't start with a .)
170 * puts the result in buffer
172 static char * strip_extension(char * filename
, char * buffer
)
175 char * dot
=strrchr(filename
, '.');
176 if(dot
!=0 && filename
[0]!='.')
178 dotpos
= dot
-filename
;
179 strncpy(buffer
, filename
, dotpos
);
187 static char * tree_get_filename(int selected_item
, void * data
, char *buffer
)
189 struct tree_context
* local_tc
=(struct tree_context
*)data
;
193 bool id3db
= *(local_tc
->dirfilter
) == SHOW_ID3DB
;
197 return tagtree_get_entry(&tc
, selected_item
)->name
;
202 struct entry
* dc
= local_tc
->dircache
;
203 struct entry
* e
= &dc
[selected_item
];
207 /* if any file filter is on, and if it's not a directory,
208 * strip the extension */
210 if ( (*(local_tc
->dirfilter
) != SHOW_ID3DB
) && !(attr
& ATTR_DIRECTORY
)
211 && (*(local_tc
->dirfilter
) != SHOW_ALL
) )
213 return(strip_extension(name
, buffer
));
219 static void tree_get_fileicon(int selected_item
, void * data
, ICON
* icon
)
221 struct tree_context
* local_tc
=(struct tree_context
*)data
;
223 bool id3db
= *(local_tc
->dirfilter
) == SHOW_ID3DB
;
225 *icon
= (ICON
)tagtree_get_icon(&tc
);
230 struct entry
* dc
= local_tc
->dircache
;
231 struct entry
* e
= &dc
[selected_item
];
232 *icon
= (ICON
)filetype_get_icon(e
->attr
);
236 bool check_rockboxdir(void)
238 DIR *dir
= opendir(ROCKBOX_DIR
);
240 { /* No need to localise this message.
241 If .rockbox is missing, it wouldn't work anyway */
244 screens
[i
].clear_display();
245 gui_syncsplash(HZ
*2, true, "No .rockbox directory");
247 screens
[i
].clear_display();
248 gui_syncsplash(HZ
*2, true, "Installation incomplete");
255 void browse_root(void)
257 gui_sync_wps_screen_init();
262 strcpy(tc
.currdir
, "/");
264 #ifdef HAVE_LCD_CHARCELLS
267 screens
[i
].double_height(false);
270 gui_buttonbar_init(&tree_buttonbar
);
271 /* since archos only have one screen, no need to create more than that */
272 gui_buttonbar_set_display(&tree_buttonbar
, &(screens
[SCREEN_MAIN
]) );
274 gui_synclist_init(&tree_lists
, &tree_get_filename
, &tc
, false, 1);
275 gui_synclist_set_icon_callback(&tree_lists
, &tree_get_fileicon
);
276 /* not the best place for this call... but... */
280 void tree_get_filetypes(const struct filetype
** types
, int* count
)
283 *count
= sizeof(filetypes
) / sizeof(*filetypes
);
286 struct tree_context
* tree_get_context(void)
291 /* talkbox hovering delay, to avoid immediate disk activity */
292 #define HOVER_DELAY (HZ/2)
294 * Returns the position of a given file in the current directory
295 * returns -1 if not found
297 static int tree_get_file_position(char * filename
)
301 /* use lastfile to determine the selected item (default=0) */
302 for (i
=0; i
< tc
.filesindir
; i
++)
304 struct entry
* dc
= tc
.dircache
;
305 struct entry
* e
= &dc
[i
];
306 if (!strcasecmp(e
->name
, filename
))
309 return(-1);/* no file can match, returns undefined */
313 * Called when a new dir is loaded (for example when returning from other apps ...)
314 * also completely redraws the tree
316 static int update_dir(void)
318 bool changed
= false;
320 bool id3db
= *tc
.dirfilter
== SHOW_ID3DB
;
321 /* Checks for changes */
323 if (tc
.currtable
!= lasttable
||
324 tc
.currextra
!= lastextra
||
325 tc
.firstpos
!= lastfirstpos
||
328 if (tagtree_load(&tc
) < 0)
331 lasttable
= tc
.currtable
;
332 lastextra
= tc
.currextra
;
333 lastfirstpos
= tc
.firstpos
;
340 /* if the tc.currdir has been changed, reload it ...*/
341 if (strncmp(tc
.currdir
, lastdir
, sizeof(lastdir
)) || reload_dir
) {
343 if (ft_load(&tc
, NULL
) < 0)
345 strcpy(lastdir
, tc
.currdir
);
349 /* if selected item is undefined */
350 if (tc
.selected_item
== -1)
352 /* use lastfile to determine the selected item */
353 tc
.selected_item
= tree_get_file_position(lastfile
);
355 /* If the file doesn't exists, select the first one (default) */
356 if(tc
.selected_item
< 0)
357 tc
.selected_item
= 0;
367 tc
.filesindir
== global_settings
.max_files_in_dir
) )
369 gui_syncsplash(HZ
, true, str(LANG_SHOWDIR_BUFFER_FULL
));
375 if (global_settings
.show_path_in_browser
== SHOW_PATH_FULL
376 || global_settings
.show_path_in_browser
== SHOW_PATH_CURRENT
)
378 gui_synclist_set_title(&tree_lists
, tagtree_get_title(&tc
),
379 filetype_get_icon(ATTR_DIRECTORY
));
383 /* Must clear the title as the list is reused */
384 gui_synclist_set_title(&tree_lists
, NULL
, NOICON
);
390 if (global_settings
.show_path_in_browser
== SHOW_PATH_FULL
)
392 gui_synclist_set_title(&tree_lists
, tc
.currdir
,
393 filetype_get_icon(ATTR_DIRECTORY
));
395 else if (global_settings
.show_path_in_browser
== SHOW_PATH_CURRENT
)
397 char *title
= strrchr(tc
.currdir
, '/') + 1;
400 /* Display "Files" for the root dir */
401 gui_synclist_set_title(&tree_lists
, str(LANG_DIR_BROWSER
),
402 filetype_get_icon(ATTR_DIRECTORY
));
405 gui_synclist_set_title(&tree_lists
, title
,
406 filetype_get_icon(ATTR_DIRECTORY
));
410 /* Must clear the title as the list is reused */
411 gui_synclist_set_title(&tree_lists
, NULL
, NOICON
);
415 gui_synclist_set_nb_items(&tree_lists
, tc
.filesindir
);
416 gui_synclist_set_icon_callback(&tree_lists
, tree_get_fileicon
);
417 if( tc
.selected_item
>= tc
.filesindir
)
418 tc
.selected_item
=tc
.filesindir
-1;
420 gui_synclist_select_item(&tree_lists
, tc
.selected_item
);
422 if (global_settings
.buttonbar
) {
423 if (*tc
.dirfilter
< NUM_FILTER_MODES
)
424 gui_buttonbar_set(&tree_buttonbar
, str(LANG_SYSFONT_DIRBROWSE_F1
),
425 str(LANG_SYSFONT_DIRBROWSE_F2
),
426 str(LANG_SYSFONT_DIRBROWSE_F3
));
428 gui_buttonbar_set(&tree_buttonbar
, "<<<", "", "");
429 gui_buttonbar_draw(&tree_buttonbar
);
432 gui_synclist_draw(&tree_lists
);
433 gui_syncstatusbar_draw(&statusbars
, true);
434 return tc
.filesindir
;
437 /* load tracks from specified directory to resume play */
438 void resume_directory(const char *dir
)
441 bool id3db
= *tc
.dirfilter
== SHOW_ID3DB
;
444 if (ft_load(&tc
, dir
) < 0)
448 ft_build_playlist(&tc
, 0);
456 /* Returns the current working directory and also writes cwd to buf if
457 non-NULL. In case of error, returns NULL. */
458 char *getcwd(char *buf
, int size
)
464 strncpy(buf
, tc
.currdir
, size
);
471 /* Force a reload of the directory next time directory browser is called */
472 void reload_directory(void)
477 /* Selects a file and update tree context properly */
478 void set_current_file(char *path
)
484 /* in ID3DB mode it is a bad idea to call this function */
485 /* (only happens with `follow playlist') */
486 if( *tc
.dirfilter
== SHOW_ID3DB
)
490 /* separate directory from filename */
491 /* gets the directory's name and put it into tc.currdir */
492 name
= strrchr(path
+1,'/');
496 strcpy(tc
.currdir
, path
);
502 strcpy(tc
.currdir
, "/");
506 strcpy(lastfile
, name
);
508 /* undefined item selected */
509 tc
.selected_item
= -1;
511 /* If we changed dir we must recalculate the dirlevel
512 and adjust the selected history properly */
513 if (strncmp(tc
.currdir
,lastdir
,sizeof(lastdir
)))
516 tc
.selected_item_history
[tc
.dirlevel
] = -1;
518 /* use '/' to calculate dirlevel */
519 for (i
= 1; path
[i
] != '\0'; i
++)
524 tc
.selected_item_history
[tc
.dirlevel
] = -1;
528 if (ft_load(&tc
, NULL
) >= 0)
530 tc
.selected_item
= tree_get_file_position(lastfile
);
534 #if defined(HAVE_TAGCACHE) && defined(HAVE_QUICKSCREEN)
535 static bool check_changed_id3mode(bool currmode
)
537 if (currmode
!= (global_settings
.dirfilter
== SHOW_ID3DB
)) {
538 currmode
= global_settings
.dirfilter
== SHOW_ID3DB
;
540 curr_context
=CONTEXT_ID3DB
;
547 curr_context
=CONTEXT_TREE
;
556 /* main loop, handles key events */
562 unsigned button
, returned_button
;
563 bool reload_root
= false;
564 int lastfilter
= *tc
.dirfilter
;
565 bool lastsortcase
= global_settings
.sort_case
;
566 bool need_update
= true;
567 bool exit_func
= false;
568 long thumbnail_time
= -1; /* for delaying a thumbnail */
569 long last_cancel
= 0;
571 char* currdir
= tc
.currdir
; /* just a shortcut */
573 bool id3db
= *tc
.dirfilter
== SHOW_ID3DB
;
576 curr_context
=CONTEXT_ID3DB
;
579 curr_context
=CONTEXT_TREE
;
580 if (tc
.selected_item
< 0)
581 tc
.selected_item
= 0;
590 numentries
= update_dir();
591 if (numentries
== -1)
592 return false; /* currdir is not a directory */
594 if (*tc
.dirfilter
> NUM_FILTER_MODES
&& numentries
==0)
596 gui_syncsplash(HZ
*2, true, str(LANG_NO_FILES
));
597 return false; /* No files found for rockbox_browser() */
601 struct entry
*dircache
= tc
.dircache
;
602 bool restore
= false;
604 tc
.dirlevel
= 0; /* shouldnt be needed.. this code needs work! */
607 char *lines
[]={str(LANG_BOOT_CHANGED
), str(LANG_REBOOT_NOW
)};
608 struct text_message message
={lines
, 2};
609 if(gui_syncyesno_run(&message
, NULL
, NULL
)==YESNO_YES
)
610 rolo_load("/" BOOTFILE
);
612 boot_changed
= false;
615 button
= get_action(CONTEXT_TREE
,HZ
/5);
616 returned_button
= gui_synclist_do_button(&tree_lists
, button
,LIST_WRAP_UNLESS_HELD
);
619 if (returned_button
== ACTION_STD_CANCEL
)
620 button
= ACTION_STD_CANCEL
;
624 /* nothing to do if no files to display */
625 if ( numentries
== 0 )
629 switch (id3db
?tagtree_enter(&tc
):ft_enter(&tc
))
631 switch (ft_enter(&tc
))
634 case 1: reload_dir
= true; break;
635 case 2: start_wps
= true; break;
636 case 3: exit_func
= true; break;
642 case ACTION_STD_CANCEL
:
643 if (*tc
.dirfilter
> NUM_FILTER_MODES
&& tc
.dirlevel
< 1) {
647 if ((*tc
.dirfilter
== SHOW_ID3DB
&& tc
.dirlevel
== 0) ||
648 ((*tc
.dirfilter
!= SHOW_ID3DB
&& !strcmp(currdir
,"/"))))
650 if (last_cancel
&& TIME_BEFORE(current_tick
, last_cancel
+HZ
/2))
653 action_signalscreenchange(); /* eat the cancel presses */
659 last_cancel
= current_tick
;
666 if (ft_exit(&tc
) == 3)
672 case ACTION_TREE_STOP
:
673 if (*tc
.dirfilter
< NUM_FILTER_MODES
)
675 /* Stop the music if it is playing */
677 if (!global_settings
.party_mode
) {
678 if (global_settings
.fade_on_stop
)
680 bookmark_autobookmark();
684 #if CONFIG_CHARGING && \
685 (CONFIG_KEYPAD == RECORDER_PAD) && !defined(HAVE_SW_POWEROFF)
687 if (!charger_inserted()) {
688 if(shutdown_screen())
697 #if CONFIG_CHARGING && !defined(HAVE_POWEROFF_WHILE_CHARGING)
699 static int last_off
= 0;
700 if (current_tick
- last_off
< 50) {
701 if (charger_inserted()) {
706 last_off
= current_tick
;
709 break; /* case ACTION_TREE_STOP: */
710 case ACTION_STD_MENU
:
714 case ACTION_TREE_WPS
:
715 return GO_TO_PREVIOUS_MUSIC
;
717 #ifdef HAVE_QUICKSCREEN
718 case ACTION_STD_QUICKSCREEN
:
719 /* don't enter f2 from plugin browser */
720 if (*tc
.dirfilter
< NUM_FILTER_MODES
)
722 if (quick_screen_quick(button
))
727 id3db
= check_changed_id3mode(id3db
);
735 /* don't enter f3 from plugin browser */
736 if (*tc
.dirfilter
< NUM_FILTER_MODES
)
738 if (quick_screen_f3(BUTTON_F3
))
745 case ACTION_STD_CONTEXT
:
751 onplay_result
= onplay(NULL
, 0, curr_context
);
756 if (tagtree_get_attr(&tc
) == TREE_ATTR_MPA
)
758 attr
= TREE_ATTR_MPA
;
759 tagtree_get_filename(&tc
, buf
, sizeof(buf
));
762 attr
= ATTR_DIRECTORY
;
767 attr
= dircache
[tc
.selected_item
].attr
;
769 if (currdir
[1]) /* Not in / */
770 snprintf(buf
, sizeof buf
, "%s/%s",
772 dircache
[tc
.selected_item
].name
);
774 snprintf(buf
, sizeof buf
, "/%s",
775 dircache
[tc
.selected_item
].name
);
777 onplay_result
= onplay(buf
, attr
, curr_context
);
779 switch (onplay_result
)
781 case ONPLAY_MAINMENU
:
788 case ONPLAY_RELOAD_DIR
:
792 case ONPLAY_START_PLAY
:
800 if (thumbnail_time
!= -1 &&
801 TIME_AFTER(current_tick
, thumbnail_time
))
802 { /* a delayed hovering thumbnail is due now */
810 attr
= tagtree_get_attr(&tc
);
811 name
= tagtree_get_entry(&tc
, lasti
)->name
;
816 attr
= dircache
[lasti
].attr
;
817 name
= dircache
[lasti
].name
;
820 if (attr
& ATTR_DIRECTORY
)
822 DEBUGF("Playing directory thumbnail: %s", currdir
);
823 res
= ft_play_dirname(name
);
824 if (res
< 0) /* failed, not existing */
825 { /* say the number instead, as a fallback */
826 talk_id(VOICE_DIR
, false);
827 talk_number(lasti
+1, true);
832 DEBUGF("Playing file thumbnail: %s/%s%s\n",
835 /* no fallback necessary, we knew in advance
836 that the file exists */
837 ft_play_filename(currdir
, name
);
839 thumbnail_time
= -1; /* job done */
841 gui_syncstatusbar_draw(&statusbars
, false);
850 /* The 'dir no longer valid' situation will be caught later
851 * by checking the showdir() result. */
856 if (default_event_handler(button
) == SYS_USB_CONNECTED
)
858 if(*tc
.dirfilter
> NUM_FILTER_MODES
)
859 /* leave sub-browsers after usb, doing otherwise
860 might be confusing to the user */
876 /* do we need to rescan dir? */
877 if (reload_dir
|| reload_root
||
878 lastfilter
!= *tc
.dirfilter
||
879 lastsortcase
!= global_settings
.sort_case
)
882 strcpy(currdir
, "/");
895 gui_synclist_select_item(&tree_lists
, 0);
896 gui_synclist_draw(&tree_lists
);
897 tc
.selected_item
= 0;
901 lastfilter
= *tc
.dirfilter
;
902 lastsortcase
= global_settings
.sort_case
;
907 return GO_TO_PREVIOUS
;
909 if (restore
|| reload_dir
) {
910 /* restore display */
911 numentries
= update_dir();
912 if (currdir
[1] && (numentries
< 0))
913 { /* not in root and reload failed */
914 reload_root
= true; /* try root */
923 tc
.selected_item
= gui_synclist_get_sel_pos(&tree_lists
);
925 if ( numentries
> 0 ) {
926 /* Voice the file if changed */
927 if(lasti
!= tc
.selected_item
|| restore
) {
931 lasti
= tc
.selected_item
;
932 thumbnail_time
= -1; /* Cancel whatever we were
938 attr
= tagtree_get_attr(&tc
);
939 name
= tagtree_get_entry(&tc
, tc
.selected_item
)->name
;
944 attr
= dircache
[tc
.selected_item
].attr
;
945 name
= dircache
[tc
.selected_item
].name
;
949 if (attr
& ATTR_DIRECTORY
)
951 /* play directory thumbnail */
952 switch (global_settings
.talk_dir
) {
953 case 1: /* dirs as numbers */
954 talk_id(VOICE_DIR
, false);
955 talk_number(tc
.selected_item
+1, true);
958 case 2: /* dirs spelled */
959 talk_spell(name
, false);
962 case 3: /* thumbnail clip */
963 /* "schedule" a thumbnail, to have a little
965 thumbnail_time
= current_tick
+ HOVER_DELAY
;
974 switch (global_settings
.talk_file
) {
975 case 1: /* files as numbers */
977 tc
.selected_item
-tc
.dirsindir
+1,
978 attr
& TREE_ATTR_MASK
);
981 case 2: /* files spelled */
982 talk_spell(name
, false);
985 case 3: /* thumbnail clip */
986 /* "schedule" a thumbnail, to have a little
988 if (attr
& TREE_ATTR_THUMBNAIL
)
989 thumbnail_time
= current_tick
+ HOVER_DELAY
;
991 /* spell the number as fallback */
992 talk_spell(name
, false);
1003 action_signalscreenchange();
1007 static int plsize
= 0;
1009 static bool add_dir(char* dirname
, int len
, int fd
)
1014 /* check for user abort */
1015 if (action_userabort(TIMEOUT_NOBLOCK
))
1018 dir
= opendir_cached(dirname
);
1023 struct dircache_entry
*entry
;
1025 entry
= readdir_cached(dir
);
1028 if (entry
->attribute
& ATTR_DIRECTORY
) {
1029 int dirlen
= strlen(dirname
);
1032 if (!strcmp((char *)entry
->d_name
, ".") ||
1033 !strcmp((char *)entry
->d_name
, ".."))
1037 snprintf(dirname
+dirlen
, len
-dirlen
, "/%s", entry
->d_name
);
1039 snprintf(dirname
, len
, "/%s", entry
->d_name
);
1041 result
= add_dir(dirname
, len
, fd
);
1042 dirname
[dirlen
] = '\0';
1049 int x
= strlen((char *)entry
->d_name
);
1051 char *cp
= strrchr((char *)entry
->d_name
,'.');
1056 /* add all supported audio files to playlists */
1057 for (i
=0; i
< sizeof(filetypes
)/sizeof(struct filetype
); i
++) {
1058 if (filetypes
[i
].tree_attr
== TREE_ATTR_MPA
) {
1059 if (!strcasecmp(cp
, filetypes
[i
].extension
)) {
1062 write(fd
, dirname
, strlen(dirname
));
1064 write(fd
, entry
->d_name
, x
);
1068 if(TIME_AFTER(current_tick
, pltick
+HZ
/4)) {
1069 pltick
= current_tick
;
1071 snprintf(buf
, sizeof buf
, "%d", plsize
);
1072 #ifdef HAVE_LCD_BITMAP
1075 screens
[i
].puts(0, 4, (unsigned char *)buf
);
1076 gui_textarea_update(&screens
[i
]);
1091 screens
[i
].puts(x
,0,buf
);
1102 closedir_cached(dir
);
1107 bool create_playlist(void)
1111 char filename
[MAX_PATH
];
1113 pltick
= current_tick
;
1115 snprintf(filename
, sizeof filename
, "%s.m3u8",
1116 tc
.currdir
[1] ? tc
.currdir
: "/root");
1119 gui_textarea_clear(&screens
[i
]);
1120 screens
[i
].puts(0, 0, str(LANG_CREATING
));
1121 screens
[i
].puts_scroll(0, 1, (unsigned char *)filename
);
1122 #if defined(HAVE_LCD_BITMAP) || defined(SIMULATOR)
1123 gui_textarea_update(&screens
[i
]);
1126 fd
= creat(filename
);
1130 trigger_cpu_boost();
1132 snprintf(filename
, sizeof(filename
), "%s",
1133 tc
.currdir
[1] ? tc
.currdir
: "/");
1135 add_dir(filename
, sizeof(filename
), fd
);
1143 int rockbox_browse(const char *root
, int dirfilter
)
1146 int *last_filter
= tc
.dirfilter
;
1147 tc
.dirfilter
= &dirfilter
;
1150 if (dirfilter
>= NUM_FILTER_MODES
)
1152 static struct tree_context backup
;
1157 memcpy(tc
.currdir
, root
, sizeof(tc
.currdir
));
1159 last_context
= curr_context
;
1161 ret_val
= dirbrowse();
1163 curr_context
= last_context
;
1167 static char buf
[MAX_PATH
];
1168 if (dirfilter
!= SHOW_ID3DB
)
1169 tc
.dirfilter
= &global_settings
.dirfilter
;
1171 set_current_file(buf
);
1172 ret_val
= dirbrowse();
1174 tc
.dirfilter
= last_filter
;
1178 void tree_init(void)
1180 /* We copy the settings value in case it is changed by the user. We can't
1181 use it until the next reboot. */
1182 max_files
= global_settings
.max_files_in_dir
;
1184 /* initialize tree context struct */
1185 memset(&tc
, 0, sizeof(tc
));
1186 tc
.dirfilter
= &global_settings
.dirfilter
;
1188 tc
.name_buffer_size
= AVERAGE_FILENAME_LENGTH
* max_files
;
1189 tc
.name_buffer
= buffer_alloc(tc
.name_buffer_size
);
1191 tc
.dircache_size
= max_files
* sizeof(struct entry
);
1192 tc
.dircache
= buffer_alloc(tc
.dircache_size
);
1195 void bookmark_play(char *resume_file
, int index
, int offset
, int seed
,
1199 char* suffix
= strrchr(resume_file
, '.');
1201 if (suffix
!= NULL
&&
1202 (!strcasecmp(suffix
, ".m3u") || !strcasecmp(suffix
, ".m3u8")))
1204 /* Playlist playback */
1206 /* check that the file exists */
1207 int fd
= open(resume_file
, O_RDONLY
);
1212 slash
= strrchr(resume_file
,'/');
1222 if (playlist_create(cp
, slash
+1) != -1)
1224 if (global_settings
.playlist_shuffle
)
1225 playlist_shuffle(seed
, -1);
1226 playlist_start(index
,offset
);
1233 /* Directory playback */
1235 if (playlist_create(resume_file
, NULL
) != -1)
1237 resume_directory(resume_file
);
1238 if (global_settings
.playlist_shuffle
)
1239 playlist_shuffle(seed
, -1);
1241 /* Check if the file is at the same spot in the directory,
1242 else search for it */
1243 if ((strcmp(strrchr(playlist_peek(index
),'/') + 1,
1246 for ( i
=0; i
< playlist_amount(); i
++ )
1248 if ((strcmp(strrchr(playlist_peek(i
),'/') + 1,
1252 if (i
< playlist_amount())
1257 playlist_start(index
,offset
);
1264 int ft_play_filenumber(int pos
, int attr
)
1266 /* try to find a voice ID for the extension, if known */
1268 int ext_id
= -1; /* default to none */
1269 for (j
=0; j
<sizeof(filetypes
)/sizeof(*filetypes
); j
++)
1271 if (attr
== filetypes
[j
].tree_attr
)
1273 ext_id
= filetypes
[j
].voiceclip
;
1278 talk_id(VOICE_FILE
, false);
1279 talk_number(pos
, true);
1280 talk_id(ext_id
, true);
1284 int ft_play_dirname(char* name
)
1287 char dirname_mp3_filename
[MAX_PATH
+1];
1289 #if CONFIG_CODEC != SWCODEC
1290 if (audio_status() & AUDIO_STATUS_PLAY
)
1294 snprintf(dirname_mp3_filename
, sizeof(dirname_mp3_filename
), "%s/%s/%s",
1295 tc
.currdir
[1] ? tc
.currdir
: "" , name
,
1296 dir_thumbnail_name
);
1298 DEBUGF("Checking for %s\n", dirname_mp3_filename
);
1300 fd
= open(dirname_mp3_filename
, O_RDONLY
);
1303 DEBUGF("Failed to find: %s\n", dirname_mp3_filename
);
1309 DEBUGF("Found: %s\n", dirname_mp3_filename
);
1311 talk_file(dirname_mp3_filename
, false);
1315 void ft_play_filename(char *dir
, char *file
)
1317 char name_mp3_filename
[MAX_PATH
+1];
1319 #if CONFIG_CODEC != SWCODEC
1320 if (audio_status() & AUDIO_STATUS_PLAY
)
1324 if (strcasecmp(&file
[strlen(file
) - strlen(file_thumbnail_ext
)],
1325 file_thumbnail_ext
))
1326 { /* file has no .talk extension */
1327 snprintf(name_mp3_filename
, sizeof(name_mp3_filename
),
1328 "%s/%s%s", dir
, file
, file_thumbnail_ext
);
1330 talk_file(name_mp3_filename
, false);
1333 { /* it already is a .talk file, play this directly */
1334 snprintf(name_mp3_filename
, sizeof(name_mp3_filename
),
1335 "%s/%s", dir
, file
);
1336 talk_id(LANG_VOICE_DIR_HOVER
, false); /* prefix it */
1337 talk_file(name_mp3_filename
, true);
1341 /* These two functions are called by the USB and shutdown handlers */
1342 void tree_flush(void)
1344 scrobbler_shutdown();
1345 #ifdef HAVE_TAGCACHE
1346 tagcache_shutdown();
1348 playlist_shutdown();
1350 #ifdef HAVE_TC_RAMCACHE
1351 tagcache_unload_ramcache();
1354 #ifdef HAVE_DIRCACHE
1356 int old_val
= global_status
.dircache_size
;
1357 if (global_settings
.dircache
)
1359 global_status
.dircache_size
= dircache_get_cache_size();
1360 # ifdef HAVE_EEPROM_SETTINGS
1367 global_status
.dircache_size
= 0;
1369 if (old_val
!= global_status
.dircache_size
)
1375 void tree_restore(void)
1377 #ifdef HAVE_EEPROM_SETTINGS
1378 firmware_settings
.disk_clean
= false;
1381 #ifdef HAVE_TC_RAMCACHE
1382 remove(TAGCACHE_STATEFILE
);
1385 #ifdef HAVE_DIRCACHE
1386 remove(DIRCACHE_FILE
);
1387 if (global_settings
.dircache
)
1389 /* Print "Scanning disk..." to the display. */
1393 screens
[i
].putsxy((LCD_WIDTH
/2) -
1394 ((strlen(str(LANG_DIRCACHE_BUILDING
)) *
1395 screens
[i
].char_width
)/2),
1396 LCD_HEIGHT
-screens
[i
].char_height
*3,
1397 str(LANG_DIRCACHE_BUILDING
));
1398 gui_textarea_update(&screens
[i
]);
1401 dircache_build(global_status
.dircache_size
);
1403 /* Clean the text when we are done. */
1406 gui_textarea_clear(&screens
[i
]);
1410 #ifdef HAVE_TAGCACHE
1411 tagcache_start_scan();