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"
66 #include "gwps-common.h"
70 #include "statusbar.h"
72 #include "buttonbar.h"
75 #ifdef HAVE_LCD_BITMAP
83 /* a table for the know file types */
84 const struct filetype filetypes
[] = {
85 { "mp3", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
86 { "mp2", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
87 { "mpa", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
88 #if CONFIG_CODEC == SWCODEC
89 /* Temporary hack to allow playlist creation */
90 { "mp1", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
91 { "ogg", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
92 { "wma", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
93 { "wav", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
94 { "flac",TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
95 { "ac3", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
96 { "a52", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
97 { "mpc", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
98 { "wv", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
99 { "m4a", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
100 { "mp4", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
101 { "shn", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
102 { "aif", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
103 { "aiff",TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
105 { "m3u", TREE_ATTR_M3U
, Icon_Playlist
, LANG_PLAYLIST
},
106 { "cfg", TREE_ATTR_CFG
, Icon_Config
, VOICE_EXT_CFG
},
107 { "wps", TREE_ATTR_WPS
, Icon_Wps
, VOICE_EXT_WPS
},
108 #ifdef HAVE_REMOTE_LCD
109 { "rwps", TREE_ATTR_RWPS
, Icon_Wps
, VOICE_EXT_RWPS
},
111 #ifdef HAVE_LCD_COLOR
112 { "bmp", TREE_ATTR_BMP
, Icon_Wps
, VOICE_EXT_WPS
},
115 { "fmr", TREE_ATTR_FMR
, Icon_Preset
, LANG_FMR
},
117 { "lng", TREE_ATTR_LNG
, Icon_Language
, LANG_LANGUAGE
},
118 { "rock",TREE_ATTR_ROCK
,Icon_Plugin
, VOICE_EXT_ROCK
},
119 #ifdef HAVE_LCD_BITMAP
120 { "fnt", TREE_ATTR_FONT
,Icon_Font
, VOICE_EXT_FONT
},
121 { "kbd", TREE_ATTR_KBD
, Icon_Keyboard
, VOICE_EXT_KBD
},
123 { "bmark",TREE_ATTR_BMARK
, Icon_Bookmark
, VOICE_EXT_BMARK
},
125 { BOOTFILE_EXT
, TREE_ATTR_MOD
, Icon_Firmware
, VOICE_EXT_AJZ
},
126 #endif /* #ifndef SIMULATOR */
129 struct gui_synclist tree_lists
;
131 /* I put it here because other files doesn't use it yet,
132 * but should be elsewhere since it will be used mostly everywhere */
134 struct gui_buttonbar tree_buttonbar
;
136 static struct tree_context tc
;
138 bool boot_changed
= false;
140 char lastfile
[MAX_PATH
];
141 static char lastdir
[MAX_PATH
];
142 static int lasttable
, lastextra
, lastfirstpos
;
143 static int max_files
= 0;
145 static bool reload_dir
= false;
147 static bool start_wps
= false;
148 static bool dirbrowse(void);
149 static int curr_context
= false;/* id3db or tree*/
152 * removes the extension of filename (if it doesn't start with a .)
153 * puts the result in buffer
155 char * strip_extension(char * filename
, char * buffer
)
158 char * dot
=strrchr(filename
, '.');
159 if(dot
!=0 && filename
[0]!='.')
161 dotpos
= dot
-filename
;
162 strncpy(buffer
, filename
, dotpos
);
169 char * tree_get_filename(int selected_item
, void * data
, char *buffer
)
171 struct tree_context
* local_tc
=(struct tree_context
*)data
;
174 bool id3db
= *(local_tc
->dirfilter
) == SHOW_ID3DB
;
178 return tagtree_get_entry(&tc
, selected_item
)->name
;
182 struct entry
* dc
= local_tc
->dircache
;
183 struct entry
* e
= &dc
[selected_item
];
187 /* if any file filter is on, and if it's not a directory,
188 * strip the extension */
190 if ( (*(local_tc
->dirfilter
) != SHOW_ID3DB
) && !(attr
& ATTR_DIRECTORY
)
191 && (*(local_tc
->dirfilter
) != SHOW_ALL
) )
193 return(strip_extension(name
, buffer
));
199 void tree_get_fileicon(int selected_item
, void * data
, ICON
* icon
)
201 struct tree_context
* local_tc
=(struct tree_context
*)data
;
202 bool id3db
= *(local_tc
->dirfilter
) == SHOW_ID3DB
;
204 *icon
= (ICON
)tagtree_get_icon(&tc
);
207 struct entry
* dc
= local_tc
->dircache
;
208 struct entry
* e
= &dc
[selected_item
];
209 *icon
= (ICON
)filetype_get_icon(e
->attr
);
213 bool check_rockboxdir(void)
215 DIR *dir
= opendir(ROCKBOX_DIR
);
217 { /* No need to localise this message.
218 If .rockbox is missing, it wouldn't work anyway */
221 screens
[i
].clear_display();
222 gui_syncsplash(HZ
*2, true, "No .rockbox directory");
224 screens
[i
].clear_display();
225 gui_syncsplash(HZ
*2, true, "Installation incomplete");
232 void browse_root(void)
234 gui_sync_wps_screen_init();
239 strcpy(tc
.currdir
, "/");
241 #ifdef HAVE_LCD_CHARCELLS
244 screens
[i
].double_height(false);
247 gui_buttonbar_init(&tree_buttonbar
);
248 /* since archos only have one screen, no need to create more than that */
249 gui_buttonbar_set_display(&tree_buttonbar
, &(screens
[SCREEN_MAIN
]) );
251 gui_synclist_init(&tree_lists
, &tree_get_filename
, &tc
, false, 1);
252 gui_synclist_set_icon_callback(&tree_lists
,
253 global_settings
.show_icons
?&tree_get_fileicon
:NULL
);
258 DEBUGF("No filesystem found. Have you forgotten to create it?\n");
263 void tree_get_filetypes(const struct filetype
** types
, int* count
)
266 *count
= sizeof(filetypes
) / sizeof(*filetypes
);
269 struct tree_context
* tree_get_context(void)
274 /* talkbox hovering delay, to avoid immediate disk activity */
275 #define HOVER_DELAY (HZ/2)
277 * Returns the position of a given file in the current directory
278 * returns -1 if not found
280 int tree_get_file_position(char * filename
)
284 /* use lastfile to determine the selected item (default=0) */
285 for (i
=0; i
< tc
.filesindir
; i
++)
287 struct entry
* dc
= tc
.dircache
;
288 struct entry
* e
= &dc
[i
];
289 if (!strcasecmp(e
->name
, filename
))
292 return(-1);/* no file can match, returns undefined */
296 * Called when a new dir is loaded (for example when returning from other apps ...)
297 * also completely redraws the tree
299 static int update_dir(void)
301 bool id3db
= *tc
.dirfilter
== SHOW_ID3DB
;
302 bool changed
= false;
303 /* Checks for changes */
305 if (tc
.currtable
!= lasttable
||
306 tc
.currextra
!= lastextra
||
307 tc
.firstpos
!= lastfirstpos
||
310 if (tagtree_load(&tc
) < 0)
313 lasttable
= tc
.currtable
;
314 lastextra
= tc
.currextra
;
315 lastfirstpos
= tc
.firstpos
;
320 /* if the tc.currdir has been changed, reload it ...*/
321 if (strncmp(tc
.currdir
, lastdir
, sizeof(lastdir
)) || reload_dir
) {
323 if (ft_load(&tc
, NULL
) < 0)
325 strcpy(lastdir
, tc
.currdir
);
329 /* if selected item is undefined */
330 if (tc
.selected_item
== -1)
332 /* use lastfile to determine the selected item */
333 tc
.selected_item
= tree_get_file_position(lastfile
);
335 /* If the file doesn't exists, select the first one (default) */
336 if(tc
.selected_item
< 0)
337 tc
.selected_item
= 0;
342 if(!id3db
&& (tc
.dirfull
||
343 tc
.filesindir
== global_settings
.max_files_in_dir
) )
345 gui_syncsplash(HZ
, true, str(LANG_SHOWDIR_BUFFER_FULL
));
348 gui_synclist_set_nb_items(&tree_lists
, tc
.filesindir
);
349 gui_synclist_set_icon_callback(&tree_lists
,
350 global_settings
.show_icons
?&tree_get_fileicon
:NULL
);
351 if( tc
.selected_item
>= tc
.filesindir
)
352 tc
.selected_item
=tc
.filesindir
-1;
354 gui_synclist_select_item(&tree_lists
, tc
.selected_item
);
356 if (global_settings
.buttonbar
) {
357 if (*tc
.dirfilter
< NUM_FILTER_MODES
)
358 gui_buttonbar_set(&tree_buttonbar
, str(LANG_DIRBROWSE_F1
),
359 str(LANG_DIRBROWSE_F2
),
360 str(LANG_DIRBROWSE_F3
));
362 gui_buttonbar_set(&tree_buttonbar
, "<<<", "", "");
363 gui_buttonbar_draw(&tree_buttonbar
);
366 gui_synclist_draw(&tree_lists
);
367 gui_syncstatusbar_draw(&statusbars
, true);
368 return tc
.filesindir
;
371 /* load tracks from specified directory to resume play */
372 void resume_directory(const char *dir
)
374 bool id3db
= *tc
.dirfilter
== SHOW_ID3DB
;
376 if (ft_load(&tc
, dir
) < 0)
380 ft_build_playlist(&tc
, 0);
386 /* Returns the current working directory and also writes cwd to buf if
387 non-NULL. In case of error, returns NULL. */
388 char *getcwd(char *buf
, int size
)
394 strncpy(buf
, tc
.currdir
, size
);
401 /* Force a reload of the directory next time directory browser is called */
402 void reload_directory(void)
407 static void start_resume(bool just_powered_on
)
409 bool do_resume
= false;
410 if ( global_settings
.resume_index
!= -1 ) {
411 DEBUGF("Resume index %X offset %X\n",
412 global_settings
.resume_index
,
413 global_settings
.resume_offset
);
415 #ifdef HAVE_ALARM_MOD
416 if ( rtc_check_alarm_started(true) ) {
417 rtc_enable_alarm(false);
423 if ( global_settings
.resume
|| ! just_powered_on
)
426 if (! do_resume
) return;
428 if (playlist_resume() != -1)
430 playlist_start(global_settings
.resume_index
,
431 global_settings
.resume_offset
);
437 else if (! just_powered_on
) {
438 gui_syncsplash(HZ
*2, true, str(LANG_NOTHING_TO_RESUME
));
442 /* Selects a file and update tree context properly */
443 void set_current_file(char *path
)
448 /* in ID3DB mode it is a bad idea to call this function */
449 /* (only happens with `follow playlist') */
450 if( *tc
.dirfilter
== SHOW_ID3DB
)
453 /* separate directory from filename */
454 /* gets the directory's name and put it into tc.currdir */
455 name
= strrchr(path
+1,'/');
459 strcpy(tc
.currdir
, path
);
465 strcpy(tc
.currdir
, "/");
469 strcpy(lastfile
, name
);
471 /* undefined item selected */
472 tc
.selected_item
= -1;
474 /* If we changed dir we must recalculate the dirlevel
475 and adjust the selected history properly */
476 if (strncmp(tc
.currdir
,lastdir
,sizeof(lastdir
)))
479 tc
.selected_item_history
[tc
.dirlevel
] = -1;
481 /* use '/' to calculate dirlevel */
482 /* FIXME : strlen(path) : crazy oO better to store it at
484 int path_len
= strlen(path
) + 1;
485 for (i
= 1; i
< path_len
; i
++)
490 tc
.selected_item_history
[tc
.dirlevel
] = -1;
496 static bool check_changed_id3mode(bool currmode
)
498 if (currmode
!= (global_settings
.dirfilter
== SHOW_ID3DB
)) {
499 currmode
= global_settings
.dirfilter
== SHOW_ID3DB
;
501 curr_context
=CONTEXT_ID3DB
;
506 curr_context
=CONTEXT_TREE
;
512 /* main loop, handles key events */
513 static bool dirbrowse(void)
519 bool reload_root
= false;
520 int lastfilter
= *tc
.dirfilter
;
521 bool lastsortcase
= global_settings
.sort_case
;
522 bool need_update
= true;
523 bool exit_func
= false;
524 long thumbnail_time
= -1; /* for delaying a thumbnail */
526 unsigned lastbutton
= 0;
527 char* currdir
= tc
.currdir
; /* just a shortcut */
528 bool id3db
= *tc
.dirfilter
== SHOW_ID3DB
;
531 curr_context
=CONTEXT_ID3DB
;
533 curr_context
=CONTEXT_TREE
;
534 tc
.selected_item
= 0;
541 if (*tc
.dirfilter
< NUM_FILTER_MODES
) {
542 #ifdef HAVE_RECORDING
544 if (global_settings
.rec_startup
) {
545 /* We fake being in the menu structure by calling
546 the appropriate parent when we drop out of each screen */
557 /* If we don't need to show the wps, draw the dir */
559 numentries
= update_dir();
560 if (numentries
== -1)
561 return false; /* currdir is not a directory */
563 if (*tc
.dirfilter
> NUM_FILTER_MODES
&& numentries
==0)
565 gui_syncsplash(HZ
*2, true, str(LANG_NO_FILES
));
566 return false; /* No files found for rockbox_browser() */
571 struct entry
*dircache
= tc
.dircache
;
572 bool restore
= false;
575 char *lines
[]={str(LANG_BOOT_CHANGED
), str(LANG_REBOOT_NOW
)};
576 struct text_message message
={lines
, 2};
577 if(gui_syncyesno_run(&message
, NULL
, NULL
)==YESNO_YES
)
578 rolo_load("/" BOOTFILE
);
580 boot_changed
= false;
583 button
= button_get_w_tmo(HZ
/5);
584 need_update
= gui_synclist_do_button(&tree_lists
, button
);
589 case TREE_ENTER
| BUTTON_REPEAT
:
596 if (((button
== TREE_RUN
)
597 #ifdef TREE_RC_RUN_PRE
598 || (button
== TREE_RC_RUN
))
599 && ((lastbutton
!= TREE_RC_RUN_PRE
)
601 && (lastbutton
!= TREE_RUN_PRE
)))
604 /* nothing to do if no files to display */
605 if ( numentries
== 0 )
608 switch (id3db
?tagtree_enter(&tc
):ft_enter(&tc
))
610 case 1: reload_dir
= true; break;
611 case 2: start_wps
= true; break;
612 case 3: exit_func
= true; break;
619 case TREE_EXIT
| BUTTON_REPEAT
:
623 if (*tc
.dirfilter
> NUM_FILTER_MODES
&& tc
.dirlevel
< 1) {
627 /* if we are in /, nothing to do */
628 if (tc
.dirlevel
== 0 && !strcmp(currdir
,"/"))
634 if (ft_exit(&tc
) == 3)
642 if (*tc
.dirfilter
< NUM_FILTER_MODES
)
644 /* Stop the music if it is playing */
646 if (!global_settings
.party_mode
) {
647 if (global_settings
.fade_on_stop
)
649 bookmark_autobookmark();
653 #if defined(CONFIG_CHARGING) && \
654 (CONFIG_KEYPAD == RECORDER_PAD) && !defined(HAVE_SW_POWEROFF)
656 if (!charger_inserted()) {
657 if(shutdown_screen())
667 #if defined(CONFIG_CHARGING) && !defined(HAVE_POWEROFF_WHILE_CHARGING)
668 case TREE_OFF
| BUTTON_REPEAT
:
669 if (charger_inserted()) {
675 #endif /* TREE_OFF */
681 if (lastbutton
!= TREE_MENU_PRE
682 #ifdef TREE_RC_MENU_PRE
683 && lastbutton
!= TREE_RC_MENU_PRE
688 /* don't enter menu from plugin browser */
689 if (*tc
.dirfilter
< NUM_FILTER_MODES
)
693 screens
[i
].stop_scroll();
698 id3db
= check_changed_id3mode(id3db
);
702 else /* use it as a quick exit instead */
711 if ((lastbutton
!= TREE_WPS_PRE
)
713 && (lastbutton
!= TREE_RC_WPS_PRE
)
718 /* don't enter wps from plugin browser etc */
719 if (*tc
.dirfilter
< NUM_FILTER_MODES
)
721 if (audio_status() & AUDIO_STATUS_PLAY
)
733 #ifdef HAVE_QUICKSCREEN
738 /* don't enter f2 from plugin browser */
739 if (*tc
.dirfilter
< NUM_FILTER_MODES
)
741 if (quick_screen_quick(button
))
745 id3db
= check_changed_id3mode(id3db
);
753 /* don't enter f3 from plugin browser */
754 if (*tc
.dirfilter
< NUM_FILTER_MODES
)
756 if (quick_screen_f3(button
))
764 #ifdef TREE_RC_CONTEXT
765 case TREE_RC_CONTEXT
:
775 onplay_result
= onplay(NULL
, 0, curr_context
);
779 if (tagtree_get_attr(&tc
) == TREE_ATTR_MPA
)
781 attr
= TREE_ATTR_MPA
;
782 tagtree_get_filename(&tc
, buf
, sizeof(buf
));
787 attr
= dircache
[tc
.selected_item
].attr
;
789 if (currdir
[1]) /* Not in / */
790 snprintf(buf
, sizeof buf
, "%s/%s",
792 dircache
[tc
.selected_item
].name
);
794 snprintf(buf
, sizeof buf
, "/%s",
795 dircache
[tc
.selected_item
].name
);
797 onplay_result
= onplay(buf
, attr
, curr_context
);
799 switch (onplay_result
)
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 */
826 attr
= tagtree_get_attr(&tc
);
827 name
= tagtree_get_entry(&tc
, lasti
)->name
;
831 attr
= dircache
[lasti
].attr
;
832 name
= dircache
[lasti
].name
;
835 if (attr
& ATTR_DIRECTORY
)
837 DEBUGF("Playing directory thumbnail: %s", currdir
);
838 res
= ft_play_dirname(name
);
839 if (res
< 0) /* failed, not existing */
840 { /* say the number instead, as a fallback */
841 talk_id(VOICE_DIR
, false);
842 talk_number(lasti
+1, true);
847 DEBUGF("Playing file thumbnail: %s/%s%s\n",
850 /* no fallback necessary, we knew in advance
851 that the file exists */
852 ft_play_filename(currdir
, name
);
854 thumbnail_time
= -1; /* job done */
856 gui_syncstatusbar_draw(&statusbars
, false);
863 /* The 'dir no longer valid' situation will be caught later
864 * by checking the showdir() result. */
869 if (default_event_handler(button
) == SYS_USB_CONNECTED
)
871 if(*tc
.dirfilter
> NUM_FILTER_MODES
)
872 /* leave sub-browsers after usb, doing otherwise
873 might be confusing to the user */
887 if (start_wps
&& audio_status() )
892 screens
[i
].stop_scroll();
894 if (gui_wps_show() == SYS_USB_CONNECTED
)
898 if (!id3db
) /* Try reload to catch 'no longer valid' case. */
901 #ifdef HAVE_LCD_COLOR
902 show_main_backdrop();
904 id3db
= check_changed_id3mode(id3db
);
910 /* do we need to rescan dir? */
911 if (reload_dir
|| reload_root
||
912 lastfilter
!= *tc
.dirfilter
||
913 lastsortcase
!= global_settings
.sort_case
)
916 strcpy(currdir
, "/");
927 gui_synclist_select_item(&tree_lists
, 0);
928 gui_synclist_draw(&tree_lists
);
929 tc
.selected_item
= 0;
933 lastfilter
= *tc
.dirfilter
;
934 lastsortcase
= global_settings
.sort_case
;
936 button_clear_queue(); /* clear button queue */
942 if (restore
|| reload_dir
) {
943 /* restore display */
944 numentries
= update_dir();
945 if (currdir
[1] && (numentries
< 0))
946 { /* not in root and reload failed */
947 reload_root
= true; /* try root */
956 tc
.selected_item
= gui_synclist_get_sel_pos(&tree_lists
);
958 if ( numentries
> 0 ) {
959 /* Voice the file if changed */
960 if(lasti
!= tc
.selected_item
|| restore
) {
964 lasti
= tc
.selected_item
;
965 thumbnail_time
= -1; /* Cancel whatever we were
970 attr
= tagtree_get_attr(&tc
);
971 name
= tagtree_get_entry(&tc
, tc
.selected_item
)->name
;
975 attr
= dircache
[tc
.selected_item
].attr
;
976 name
= dircache
[tc
.selected_item
].name
;
980 if (attr
& ATTR_DIRECTORY
)
982 /* play directory thumbnail */
983 switch (global_settings
.talk_dir
) {
984 case 1: /* dirs as numbers */
985 talk_id(VOICE_DIR
, false);
986 talk_number(tc
.selected_item
+1, true);
989 case 2: /* dirs spelled */
990 talk_spell(name
, false);
993 case 3: /* thumbnail clip */
994 /* "schedule" a thumbnail, to have a little
996 thumbnail_time
= current_tick
+ HOVER_DELAY
;
1005 switch (global_settings
.talk_file
) {
1006 case 1: /* files as numbers */
1008 tc
.selected_item
-tc
.dirsindir
+1,
1009 attr
& TREE_ATTR_MASK
);
1012 case 2: /* files spelled */
1013 talk_spell(name
, false);
1016 case 3: /* thumbnail clip */
1017 /* "schedule" a thumbnail, to have a little
1019 if (attr
& TREE_ATTR_THUMBNAIL
)
1020 thumbnail_time
= current_tick
+ HOVER_DELAY
;
1022 /* spell the number as fallback */
1023 talk_spell(name
, false);
1038 static int plsize
= 0;
1040 static bool add_dir(char* dirname
, int len
, int fd
)
1045 /* check for user abort */
1046 if (button_get(false) == TREE_ABORT
)
1049 dir
= opendir_cached(dirname
);
1054 struct dircache_entry
*entry
;
1056 entry
= readdir_cached(dir
);
1059 if (entry
->attribute
& ATTR_DIRECTORY
) {
1060 int dirlen
= strlen(dirname
);
1063 if (!strcmp((char *)entry
->d_name
, ".") ||
1064 !strcmp((char *)entry
->d_name
, ".."))
1068 snprintf(dirname
+dirlen
, len
-dirlen
, "/%s", entry
->d_name
);
1070 snprintf(dirname
, len
, "/%s", entry
->d_name
);
1072 result
= add_dir(dirname
, len
, fd
);
1073 dirname
[dirlen
] = '\0';
1080 int x
= strlen((char *)entry
->d_name
);
1082 char *cp
= strrchr((char *)entry
->d_name
,'.');
1087 /* add all supported audio files to playlists */
1088 for (i
=0; i
< sizeof(filetypes
)/sizeof(struct filetype
); i
++) {
1089 if (filetypes
[i
].tree_attr
== TREE_ATTR_MPA
) {
1090 if (!strcasecmp(cp
, filetypes
[i
].extension
)) {
1093 write(fd
, dirname
, strlen(dirname
));
1095 write(fd
, entry
->d_name
, x
);
1099 if(TIME_AFTER(current_tick
, pltick
+HZ
/4)) {
1100 pltick
= current_tick
;
1102 snprintf(buf
, sizeof buf
, "%d", plsize
);
1103 #ifdef HAVE_LCD_BITMAP
1106 screens
[i
].puts(0, 4, (unsigned char *)buf
);
1107 gui_textarea_update(&screens
[i
]);
1122 screens
[i
].puts(x
,0,buf
);
1133 closedir_cached(dir
);
1138 bool create_playlist(void)
1142 char filename
[MAX_PATH
];
1144 pltick
= current_tick
;
1146 snprintf(filename
, sizeof filename
, "%s.m3u",
1147 tc
.currdir
[1] ? tc
.currdir
: "/root");
1150 gui_textarea_clear(&screens
[i
]);
1151 screens
[i
].puts(0, 0, str(LANG_CREATING
));
1152 screens
[i
].puts_scroll(0, 1, (unsigned char *)filename
);
1153 #if defined(HAVE_LCD_BITMAP) || defined(SIMULATOR)
1154 gui_textarea_update(&screens
[i
]);
1157 fd
= creat(filename
, O_WRONLY
);
1161 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
1165 snprintf(filename
, sizeof(filename
), "%s",
1166 tc
.currdir
[1] ? tc
.currdir
: "/");
1168 add_dir(filename
, sizeof(filename
), fd
);
1171 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
1180 bool rockbox_browse(const char *root
, int dirfilter
)
1182 static struct tree_context backup
;
1186 memcpy(tc
.currdir
, root
, sizeof(tc
.currdir
));
1188 tc
.dirfilter
= &dirfilter
;
1196 void tree_init(void)
1198 /* We copy the settings value in case it is changed by the user. We can't
1199 use it until the next reboot. */
1200 max_files
= global_settings
.max_files_in_dir
;
1202 /* initialize tree context struct */
1203 memset(&tc
, 0, sizeof(tc
));
1204 tc
.dirfilter
= &global_settings
.dirfilter
;
1206 tc
.name_buffer_size
= AVERAGE_FILENAME_LENGTH
* max_files
;
1207 tc
.name_buffer
= buffer_alloc(tc
.name_buffer_size
);
1209 tc
.dircache_size
= max_files
* sizeof(struct entry
);
1210 tc
.dircache
= buffer_alloc(tc
.dircache_size
);
1213 void bookmark_play(char *resume_file
, int index
, int offset
, int seed
,
1217 int len
=strlen(resume_file
);
1219 if (!strcasecmp(&resume_file
[len
-4], ".m3u"))
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 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 int ft_play_dirname(char* name
)
1304 char dirname_mp3_filename
[MAX_PATH
+1];
1306 if (audio_status() & AUDIO_STATUS_PLAY
)
1309 snprintf(dirname_mp3_filename
, sizeof(dirname_mp3_filename
), "%s/%s/%s",
1310 tc
.currdir
[1] ? tc
.currdir
: "" , name
,
1311 dir_thumbnail_name
);
1313 DEBUGF("Checking for %s\n", dirname_mp3_filename
);
1315 fd
= open(dirname_mp3_filename
, O_RDONLY
);
1318 DEBUGF("Failed to find: %s\n", dirname_mp3_filename
);
1324 DEBUGF("Found: %s\n", dirname_mp3_filename
);
1326 talk_file(dirname_mp3_filename
, false);
1330 void ft_play_filename(char *dir
, char *file
)
1332 char name_mp3_filename
[MAX_PATH
+1];
1334 if (audio_status() & AUDIO_STATUS_PLAY
)
1337 if (strcasecmp(&file
[strlen(file
) - strlen(file_thumbnail_ext
)],
1338 file_thumbnail_ext
))
1339 { /* file has no .talk extension */
1340 snprintf(name_mp3_filename
, sizeof(name_mp3_filename
),
1341 "%s/%s%s", dir
, file
, file_thumbnail_ext
);
1343 talk_file(name_mp3_filename
, false);
1346 { /* it already is a .talk file, play this directly */
1347 snprintf(name_mp3_filename
, sizeof(name_mp3_filename
),
1348 "%s/%s", dir
, file
);
1349 talk_id(LANG_VOICE_DIR_HOVER
, false); /* prefix it */
1350 talk_file(name_mp3_filename
, true);
1354 /* These two functions are called by the USB and shutdown handlers */
1355 void tree_flush(void)
1357 tagcache_stop_scan();
1358 playlist_shutdown();
1360 #ifdef HAVE_DIRCACHE
1361 if (global_settings
.dircache
)
1363 if (dircache_is_enabled())
1364 global_settings
.dircache_size
= dircache_get_cache_size();
1369 global_settings
.dircache_size
= 0;
1375 void tree_restore(void)
1377 #ifdef HAVE_DIRCACHE
1378 if (global_settings
.dircache
)
1380 /* Print "Scanning disk..." to the display. */
1384 screens
[i
].putsxy((LCD_WIDTH
/2) -
1385 ((strlen(str(LANG_DIRCACHE_BUILDING
)) *
1386 screens
[i
].char_width
)/2),
1387 LCD_HEIGHT
-screens
[i
].char_height
*3,
1388 str(LANG_DIRCACHE_BUILDING
));
1389 gui_textarea_update(&screens
[i
]);
1392 dircache_build(global_settings
.dircache_size
);
1394 /* Clean the text when we are done. */
1397 gui_textarea_clear(&screens
[i
]);
1401 tagcache_start_scan();