1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 Daniel Stenberg
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
24 #include "applimits.h"
29 #include "backlight.h"
34 #include "main_menu.h"
57 #include "filetypes.h"
61 #include "recorder/recording.h"
68 #include "statusbar.h"
70 #include "buttonbar.h"
73 #ifdef HAVE_LCD_BITMAP
77 /* a table for the know file types */
78 const struct filetype filetypes
[] = {
79 { "mp3", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
80 { "mp2", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
81 { "mpa", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
82 #if CONFIG_CODEC == SWCODEC
83 /* Temporary hack to allow playlist creation */
84 { "mp1", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
85 { "ogg", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
86 { "wma", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
87 { "wav", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
88 { "flac",TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
89 { "ac3", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
90 { "a52", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
91 { "mpc", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
92 { "wv", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
93 { "m4a", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
94 { "mp4", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
95 { "shn", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
96 { "aif", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
97 { "aiff",TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
99 { "m3u", TREE_ATTR_M3U
, Icon_Playlist
, LANG_PLAYLIST
},
100 { "cfg", TREE_ATTR_CFG
, Icon_Config
, VOICE_EXT_CFG
},
101 { "wps", TREE_ATTR_WPS
, Icon_Wps
, VOICE_EXT_WPS
},
102 #ifdef HAVE_REMOTE_LCD
103 { "rwps", TREE_ATTR_RWPS
, Icon_Wps
, VOICE_EXT_RWPS
},
105 #ifdef HAVE_LCD_COLOR
106 { "bmp", TREE_ATTR_BMP
, Icon_Wps
, VOICE_EXT_WPS
},
108 { "lng", TREE_ATTR_LNG
, Icon_Language
, LANG_LANGUAGE
},
109 { "rock",TREE_ATTR_ROCK
,Icon_Plugin
, VOICE_EXT_ROCK
},
110 #ifdef HAVE_LCD_BITMAP
111 { "fnt", TREE_ATTR_FONT
,Icon_Font
, VOICE_EXT_FONT
},
113 { "bmark",TREE_ATTR_BMARK
, Icon_Bookmark
, VOICE_EXT_BMARK
},
115 { BOOTFILE_EXT
, TREE_ATTR_MOD
, Icon_Firmware
, VOICE_EXT_AJZ
},
116 #endif /* #ifndef SIMULATOR */
119 struct gui_synclist tree_lists
;
121 /* I put it here because other files doesn't use it yet,
122 * but should be elsewhere since it will be used mostly everywhere */
124 struct gui_buttonbar tree_buttonbar
;
126 static struct tree_context tc
;
128 bool boot_changed
= false;
130 char lastfile
[MAX_PATH
];
131 static char lastdir
[MAX_PATH
];
132 static int lasttable
, lastextra
, lastfirstpos
;
133 static int max_files
= 0;
135 static bool reload_dir
= false;
137 static bool start_wps
= false;
138 static bool dirbrowse(void);
139 static int curr_context
= false;/* id3db or tree*/
142 * removes the extension of filename (if it doesn't start with a .)
143 * puts the result in buffer
145 char * strip_extension(char * filename
, char * buffer
)
148 char * dot
=strrchr(filename
, '.');
149 if(dot
!=0 && filename
[0]!='.')
151 dotpos
= dot
-filename
;
152 strncpy(buffer
, filename
, dotpos
);
159 char * tree_get_filename(int selected_item
, void * data
, char *buffer
)
161 struct tree_context
* local_tc
=(struct tree_context
*)data
;
164 bool id3db
= *(local_tc
->dirfilter
) == SHOW_ID3DB
;
167 name
= ((char**)local_tc
->dircache
)[selected_item
* local_tc
->dentry_size
];
170 struct entry
* dc
= local_tc
->dircache
;
171 struct entry
* e
= &dc
[selected_item
];
175 /* if any file filter is on, and if it's not a directory,
176 * strip the extension */
178 if ( (*(local_tc
->dirfilter
) != SHOW_ID3DB
) && !(attr
& ATTR_DIRECTORY
)
179 && (*(local_tc
->dirfilter
) != SHOW_ALL
) )
181 return(strip_extension(name
, buffer
));
187 void tree_get_fileicon(int selected_item
, void * data
, ICON
* icon
)
189 struct tree_context
* local_tc
=(struct tree_context
*)data
;
190 bool id3db
= *(local_tc
->dirfilter
) == SHOW_ID3DB
;
192 *icon
= (ICON
)db_get_icon(&tc
);
195 struct entry
* dc
= local_tc
->dircache
;
196 struct entry
* e
= &dc
[selected_item
];
197 *icon
= (ICON
)filetype_get_icon(e
->attr
);
201 bool check_rockboxdir(void)
203 DIR *dir
= opendir(ROCKBOX_DIR
);
208 screens
[i
].clear_display();
209 gui_syncsplash(HZ
*2, true, str(LANG_NO_ROCKBOX_DIR
));
211 screens
[i
].clear_display();
212 gui_syncsplash(HZ
*2, true, str(LANG_INSTALLATION_INCOMPLETE
));
219 void browse_root(void)
221 gui_sync_wps_screen_init();
226 strcpy(tc
.currdir
, "/");
228 #ifdef HAVE_LCD_CHARCELLS
231 screens
[i
].double_height(false);
234 gui_buttonbar_init(&tree_buttonbar
);
235 /* since archos only have one screen, no need to create more than that */
236 gui_buttonbar_set_display(&tree_buttonbar
, &(screens
[SCREEN_MAIN
]) );
238 gui_synclist_init(&tree_lists
, &tree_get_filename
, &tc
);
239 gui_synclist_set_icon_callback(&tree_lists
,
240 global_settings
.show_icons
?&tree_get_fileicon
:NULL
);
245 DEBUGF("No filesystem found. Have you forgotten to create it?\n");
250 void tree_get_filetypes(const struct filetype
** types
, int* count
)
253 *count
= sizeof(filetypes
) / sizeof(*filetypes
);
256 struct tree_context
* tree_get_context(void)
261 /* talkbox hovering delay, to avoid immediate disk activity */
262 #define HOVER_DELAY (HZ/2)
264 * Returns the position of a given file in the current directory
265 * returns -1 if not found
267 int tree_get_file_position(char * filename
)
270 /* use lastfile to determine the selected item (default=0) */
271 for (i
=0; i
< tc
.filesindir
; i
++)
273 struct entry
* dc
= tc
.dircache
;
274 struct entry
* e
= &dc
[i
];
275 if (!strcasecmp(e
->name
, filename
))
278 return(-1);/* no file can match, returns undefined */
282 * Called when a new dir is loaded (for example when returning from other apps ...)
283 * also completely redraws the tree
285 static int update_dir(void)
287 bool id3db
= *tc
.dirfilter
== SHOW_ID3DB
;
288 bool changed
= false;
289 /* Checks for changes */
291 if (tc
.currtable
!= lasttable
||
292 tc
.currextra
!= lastextra
||
293 tc
.firstpos
!= lastfirstpos
)
295 if (db_load(&tc
) < 0)
298 lasttable
= tc
.currtable
;
299 lastextra
= tc
.currextra
;
300 lastfirstpos
= tc
.firstpos
;
305 /* if the tc.currdir has been changed, reload it ...*/
306 if (strncmp(tc
.currdir
, lastdir
, sizeof(lastdir
)) || reload_dir
) {
308 if (ft_load(&tc
, NULL
) < 0)
310 strcpy(lastdir
, tc
.currdir
);
314 /* if selected item is undefined */
315 if (tc
.selected_item
== -1)
317 /* use lastfile to determine the selected item */
318 tc
.selected_item
= tree_get_file_position(lastfile
);
320 /* If the file doesn't exists, select the first one (default) */
321 if(tc
.selected_item
< 0)
322 tc
.selected_item
= 0;
327 if(!id3db
&& (tc
.dirfull
||
328 tc
.filesindir
== global_settings
.max_files_in_dir
) )
334 gui_textarea_clear(&screens
[i
]);
335 #ifdef HAVE_LCD_CHARCELLS
336 screens
[i
].double_height(false);
338 screens
[i
].clear_display();
339 screens
[i
].puts(0,0,str(LANG_SHOWDIR_ERROR_BUFFER
));
340 screens
[i
].puts(0,1,str(LANG_SHOWDIR_ERROR_FULL
));
341 gui_textarea_update(&screens
[i
]);
345 gui_textarea_clear(&screens
[i
]);
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
);
355 gui_synclist_draw(&tree_lists
);
356 gui_syncstatusbar_draw(&statusbars
, true);
358 if (global_settings
.buttonbar
) {
359 if (*tc
.dirfilter
< NUM_FILTER_MODES
)
360 gui_buttonbar_set(&tree_buttonbar
, str(LANG_DIRBROWSE_F1
),
361 str(LANG_DIRBROWSE_F2
),
362 str(LANG_DIRBROWSE_F3
));
364 gui_buttonbar_set(&tree_buttonbar
, "<<<", "", "");
365 gui_buttonbar_draw(&tree_buttonbar
);
368 return tc
.filesindir
;
371 /* load tracks from specified directory to resume play */
372 void resume_directory(const char *dir
)
374 if (ft_load(&tc
, dir
) < 0)
378 ft_build_playlist(&tc
, 0);
381 /* Returns the current working directory and also writes cwd to buf if
382 non-NULL. In case of error, returns NULL. */
383 char *getcwd(char *buf
, int size
)
389 strncpy(buf
, tc
.currdir
, size
);
396 /* Force a reload of the directory next time directory browser is called */
397 void reload_directory(void)
402 static void start_resume(bool just_powered_on
)
404 bool do_resume
= false;
405 if ( global_settings
.resume_index
!= -1 ) {
406 DEBUGF("Resume index %X offset %X\n",
407 global_settings
.resume_index
,
408 global_settings
.resume_offset
);
410 #ifdef HAVE_ALARM_MOD
411 if ( rtc_check_alarm_started(true) ) {
412 rtc_enable_alarm(false);
418 if ( global_settings
.resume
|| ! just_powered_on
)
421 if (! do_resume
) return;
423 if (playlist_resume() != -1)
425 playlist_start(global_settings
.resume_index
,
426 global_settings
.resume_offset
);
432 else if (! just_powered_on
) {
433 gui_syncsplash(HZ
*2, true, str(LANG_NOTHING_TO_RESUME
));
437 /* Selects a file and update tree context properly */
438 void set_current_file(char *path
)
443 /* in ID3DB mode it is a bad idea to call this function */
444 /* (only happens with `follow playlist') */
445 if( *tc
.dirfilter
== SHOW_ID3DB
)
448 /* separate directory from filename */
449 /* gets the directory's name and put it into tc.currdir */
450 name
= strrchr(path
+1,'/');
454 strcpy(tc
.currdir
, path
);
460 strcpy(tc
.currdir
, "/");
464 strcpy(lastfile
, name
);
466 /* undefined item selected */
467 tc
.selected_item
= -1;
469 /* If we changed dir we must recalculate the dirlevel
470 and adjust the selected history properly */
471 if (strncmp(tc
.currdir
,lastdir
,sizeof(lastdir
)))
474 tc
.selected_item_history
[tc
.dirlevel
] = -1;
476 /* use '/' to calculate dirlevel */
477 /* FIXME : strlen(path) : crazy oO better to store it at
479 int path_len
= strlen(path
) + 1;
480 for (i
= 1; i
< path_len
; i
++)
485 tc
.selected_item_history
[tc
.dirlevel
] = -1;
491 static bool check_changed_id3mode(bool currmode
)
493 if (currmode
!= (global_settings
.dirfilter
== SHOW_ID3DB
)) {
494 currmode
= global_settings
.dirfilter
== SHOW_ID3DB
;
496 curr_context
=CONTEXT_ID3DB
;
501 curr_context
=CONTEXT_TREE
;
507 /* main loop, handles key events */
508 static bool dirbrowse(void)
514 bool reload_root
= false;
515 int lastfilter
= *tc
.dirfilter
;
516 bool lastsortcase
= global_settings
.sort_case
;
517 bool need_update
= true;
518 bool exit_func
= false;
519 long thumbnail_time
= -1; /* for delaying a thumbnail */
521 unsigned lastbutton
= 0;
522 char* currdir
= tc
.currdir
; /* just a shortcut */
523 bool id3db
= *tc
.dirfilter
== SHOW_ID3DB
;
526 curr_context
=CONTEXT_ID3DB
;
528 curr_context
=CONTEXT_TREE
;
529 tc
.selected_item
= 0;
536 if (*tc
.dirfilter
< NUM_FILTER_MODES
) {
537 #ifdef HAVE_RECORDING
539 if (global_settings
.rec_startup
) {
540 /* We fake being in the menu structure by calling
541 the appropriate parent when we drop out of each screen */
552 /* If we don't need to show the wps, draw the dir */
554 numentries
= update_dir();
555 if (numentries
== -1)
556 return false; /* currdir is not a directory */
558 if (*tc
.dirfilter
> NUM_FILTER_MODES
&& numentries
==0)
560 gui_syncsplash(HZ
*2, true, str(LANG_NO_FILES
));
561 return false; /* No files found for rockbox_browser() */
566 struct entry
*dircache
= tc
.dircache
;
567 bool restore
= false;
570 char *lines
[]={str(LANG_BOOT_CHANGED
), str(LANG_REBOOT_NOW
)};
571 struct text_message message
={lines
, 2};
572 if(gui_syncyesno_run(&message
, NULL
, NULL
)==YESNO_YES
)
573 rolo_load("/" BOOTFILE
);
575 boot_changed
= false;
578 button
= button_get_w_tmo(HZ
/5);
579 need_update
= gui_synclist_do_button(&tree_lists
, button
);
584 case TREE_ENTER
| BUTTON_REPEAT
:
591 if (((button
== TREE_RUN
)
592 #ifdef TREE_RC_RUN_PRE
593 || (button
== TREE_RC_RUN
))
594 && ((lastbutton
!= TREE_RC_RUN_PRE
)
596 && (lastbutton
!= TREE_RUN_PRE
)))
599 /* nothing to do if no files to display */
600 if ( numentries
== 0 )
603 switch (id3db
?db_enter(&tc
):ft_enter(&tc
))
605 case 1: reload_dir
= true; break;
606 case 2: start_wps
= true; break;
607 case 3: exit_func
= true; break;
614 case TREE_EXIT
| BUTTON_REPEAT
:
618 if (*tc
.dirfilter
> NUM_FILTER_MODES
&& tc
.dirlevel
< 1) {
622 /* if we are in /, nothing to do */
623 if (tc
.dirlevel
== 0)
629 if (ft_exit(&tc
) == 3)
637 if (*tc
.dirfilter
< NUM_FILTER_MODES
)
639 /* Stop the music if it is playing */
642 #if defined(HAVE_CHARGING) && \
643 (CONFIG_KEYPAD == RECORDER_PAD) && !defined(HAVE_SW_POWEROFF)
645 if (!charger_inserted()) {
646 if(shutdown_screen())
656 #if defined(HAVE_CHARGING) && !defined(HAVE_POWEROFF_WHILE_CHARGING)
657 case TREE_OFF
| BUTTON_REPEAT
:
658 if (charger_inserted()) {
664 #endif /* TREE_OFF */
670 if (lastbutton
!= TREE_MENU_PRE
671 #ifdef TREE_RC_MENU_PRE
672 && lastbutton
!= TREE_RC_MENU_PRE
677 /* don't enter menu from plugin browser */
678 if (*tc
.dirfilter
< NUM_FILTER_MODES
)
682 screens
[i
].stop_scroll();
687 id3db
= check_changed_id3mode(id3db
);
689 else /* use it as a quick exit instead */
698 if ((lastbutton
!= TREE_WPS_PRE
)
700 && (lastbutton
!= TREE_RC_WPS_PRE
)
705 /* don't enter wps from plugin browser etc */
706 if (*tc
.dirfilter
< NUM_FILTER_MODES
)
708 if (audio_status() & AUDIO_STATUS_PLAY
)
725 /* don't enter f2 from plugin browser */
726 if (*tc
.dirfilter
< NUM_FILTER_MODES
)
728 if (quick_screen_quick(button
))
732 id3db
= check_changed_id3mode(id3db
);
740 /* don't enter f3 from plugin browser */
741 if (*tc
.dirfilter
< NUM_FILTER_MODES
)
743 if (quick_screen_f3(button
))
751 #ifdef TREE_RC_CONTEXT
752 case TREE_RC_CONTEXT
:
762 onplay_result
= onplay(NULL
, 0, curr_context
);
766 switch (tc
.currtable
)
773 db_get_filename(&tc
, buf
, sizeof(buf
));
779 attr
= dircache
[tc
.selected_item
].attr
;
781 if (currdir
[1]) /* Not in / */
782 snprintf(buf
, sizeof buf
, "%s/%s",
784 dircache
[tc
.selected_item
].name
);
786 snprintf(buf
, sizeof buf
, "/%s",
787 dircache
[tc
.selected_item
].name
);
789 onplay_result
= onplay(buf
, attr
, curr_context
);
791 switch (onplay_result
)
797 case ONPLAY_RELOAD_DIR
:
801 case ONPLAY_START_PLAY
:
809 if (thumbnail_time
!= -1 &&
810 TIME_AFTER(current_tick
, thumbnail_time
))
811 { /* a delayed hovering thumbnail is due now */
813 if (dircache
[lasti
].attr
& ATTR_DIRECTORY
)
815 DEBUGF("Playing directory thumbnail: %s", currdir
);
816 res
= ft_play_dirname(lasti
);
817 if (res
< 0) /* failed, not existing */
818 { /* say the number instead, as a fallback */
819 talk_id(VOICE_DIR
, false);
820 talk_number(lasti
+1, true);
825 DEBUGF("Playing file thumbnail: %s/%s%s\n",
826 currdir
, dircache
[lasti
].name
,
828 /* no fallback necessary, we knew in advance
829 that the file exists */
830 ft_play_filename(currdir
, dircache
[lasti
].name
);
832 thumbnail_time
= -1; /* job done */
834 gui_syncstatusbar_draw(&statusbars
, false);
841 /* The 'dir no longer valid' situation will be caught later
842 * by checking the showdir() result. */
847 if (default_event_handler(button
) == SYS_USB_CONNECTED
)
849 if(*tc
.dirfilter
> NUM_FILTER_MODES
)
850 /* leave sub-browsers after usb, doing otherwise
851 might be confusing to the user */
865 if (start_wps
&& audio_status() )
868 #ifdef HAVE_LCD_COLOR
869 fb_data
* old_backdrop
;
873 screens
[i
].stop_scroll();
874 #ifdef HAVE_LCD_COLOR
875 old_backdrop
= lcd_get_backdrop();
877 if (gui_wps_show() == SYS_USB_CONNECTED
)
879 #ifdef HAVE_LCD_COLOR
880 lcd_set_backdrop(old_backdrop
);
884 if (!id3db
) /* Try reload to catch 'no longer valid' case. */
887 id3db
= check_changed_id3mode(id3db
);
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
, "/");
909 gui_synclist_select_item(&tree_lists
, 0);
910 gui_synclist_draw(&tree_lists
);
911 tc
.selected_item
= 0;
915 lastfilter
= *tc
.dirfilter
;
916 lastsortcase
= global_settings
.sort_case
;
918 button_clear_queue(); /* clear button queue */
924 if (restore
|| reload_dir
) {
925 /* restore display */
926 numentries
= update_dir();
927 if (currdir
[1] && (numentries
< 0))
928 { /* not in root and reload failed */
929 reload_root
= true; /* try root */
937 tc
.selected_item
= gui_synclist_get_sel_pos(&tree_lists
);
939 if ( numentries
> 0 ) {
940 /* Voice the file if changed */
941 if(lasti
!= tc
.selected_item
|| restore
) {
942 lasti
= tc
.selected_item
;
943 thumbnail_time
= -1; /* Cancel whatever we were
947 if (dircache
[tc
.selected_item
].attr
& ATTR_DIRECTORY
)
949 /* play directory thumbnail */
950 switch (global_settings
.talk_dir
) {
951 case 1: /* dirs as numbers */
952 talk_id(VOICE_DIR
, false);
953 talk_number(tc
.selected_item
+1, true);
956 case 2: /* dirs spelled */
957 talk_spell(dircache
[tc
.selected_item
].name
,
961 case 3: /* thumbnail clip */
962 /* "schedule" a thumbnail, to have a little
964 thumbnail_time
= current_tick
+ HOVER_DELAY
;
973 switch (global_settings
.talk_file
) {
974 case 1: /* files as numbers */
976 tc
.selected_item
-tc
.dirsindir
+1,
977 dircache
[tc
.selected_item
].attr
&
981 case 2: /* files spelled */
982 talk_spell(dircache
[tc
.selected_item
].name
,
986 case 3: /* thumbnail clip */
987 /* "schedule" a thumbnail, to have a little
989 if (dircache
[tc
.selected_item
].attr
&
991 thumbnail_time
= current_tick
+ HOVER_DELAY
;
993 /* spell the number as fallback */
994 talk_spell(dircache
[tc
.selected_item
].name
,
1010 static int plsize
= 0;
1012 static bool add_dir(char* dirname
, int len
, int fd
)
1017 /* check for user abort */
1018 if (button_get(false) == TREE_ABORT
)
1021 dir
= opendir_cached(dirname
);
1026 struct dircache_entry
*entry
;
1028 entry
= readdir_cached(dir
);
1031 if (entry
->attribute
& ATTR_DIRECTORY
) {
1032 int dirlen
= strlen(dirname
);
1035 if (!strcmp((char *)entry
->d_name
, ".") ||
1036 !strcmp((char *)entry
->d_name
, ".."))
1040 snprintf(dirname
+dirlen
, len
-dirlen
, "/%s", entry
->d_name
);
1042 snprintf(dirname
, len
, "/%s", entry
->d_name
);
1044 result
= add_dir(dirname
, len
, fd
);
1045 dirname
[dirlen
] = '\0';
1052 int x
= strlen((char *)entry
->d_name
);
1054 char *cp
= strrchr((char *)entry
->d_name
,'.');
1059 /* add all supported audio files to playlists */
1060 for (i
=0; i
< sizeof(filetypes
)/sizeof(struct filetype
); i
++) {
1061 if (filetypes
[i
].tree_attr
== TREE_ATTR_MPA
) {
1062 if (!strcasecmp(cp
, filetypes
[i
].extension
)) {
1065 write(fd
, dirname
, strlen(dirname
));
1067 write(fd
, entry
->d_name
, x
);
1071 if(TIME_AFTER(current_tick
, pltick
+HZ
/4)) {
1072 pltick
= current_tick
;
1074 snprintf(buf
, sizeof buf
, "%d", plsize
);
1075 #ifdef HAVE_LCD_BITMAP
1078 screens
[i
].puts(0, 4, (unsigned char *)buf
);
1079 gui_textarea_update(&screens
[i
]);
1094 screens
[i
].puts(x
,0,buf
);
1105 closedir_cached(dir
);
1110 bool create_playlist(void)
1114 char filename
[MAX_PATH
];
1116 pltick
= current_tick
;
1118 snprintf(filename
, sizeof filename
, "%s.m3u",
1119 tc
.currdir
[1] ? tc
.currdir
: "/root");
1122 gui_textarea_clear(&screens
[i
]);
1123 screens
[i
].puts(0, 0, str(LANG_CREATING
));
1124 screens
[i
].puts_scroll(0, 1, (unsigned char *)filename
);
1125 #if defined(HAVE_LCD_BITMAP) || defined(SIMULATOR)
1126 gui_textarea_update(&screens
[i
]);
1129 fd
= creat(filename
,0);
1133 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
1137 snprintf(filename
, sizeof(filename
), "%s",
1138 tc
.currdir
[1] ? tc
.currdir
: "/");
1140 add_dir(filename
, sizeof(filename
), fd
);
1143 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
1152 bool rockbox_browse(const char *root
, int dirfilter
)
1154 static struct tree_context backup
;
1158 memcpy(tc
.currdir
, root
, sizeof(tc
.currdir
));
1160 tc
.dirfilter
= &dirfilter
;
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
;
1180 tc
.name_buffer_size
= AVERAGE_FILENAME_LENGTH
* max_files
;
1181 tc
.name_buffer
= buffer_alloc(tc
.name_buffer_size
);
1183 tc
.dircache_size
= max_files
* sizeof(struct entry
);
1184 tc
.dircache
= buffer_alloc(tc
.dircache_size
);
1187 void bookmark_play(char *resume_file
, int index
, int offset
, int seed
,
1191 int len
=strlen(resume_file
);
1193 if (!strcasecmp(&resume_file
[len
-4], ".m3u"))
1195 /* Playlist playback */
1197 /* check that the file exists */
1198 int fd
= open(resume_file
, O_RDONLY
);
1203 slash
= strrchr(resume_file
,'/');
1213 if (playlist_create(cp
, slash
+1) != -1)
1215 if (global_settings
.playlist_shuffle
)
1216 playlist_shuffle(seed
, -1);
1217 playlist_start(index
,offset
);
1224 /* Directory playback */
1226 if (playlist_create(resume_file
, NULL
) != -1)
1228 resume_directory(resume_file
);
1229 if (global_settings
.playlist_shuffle
)
1230 playlist_shuffle(seed
, -1);
1232 /* Check if the file is at the same spot in the directory,
1233 else search for it */
1234 if ((strcmp(strrchr(playlist_peek(index
) + 1,'/') + 1,
1237 for ( i
=0; i
< playlist_amount(); i
++ )
1239 if ((strcmp(strrchr(playlist_peek(i
) + 1,'/') + 1,
1243 if (i
< playlist_amount())
1248 playlist_start(index
,offset
);
1255 int ft_play_filenumber(int pos
, int attr
)
1257 /* try to find a voice ID for the extension, if known */
1259 int ext_id
= -1; /* default to none */
1260 for (j
=0; j
<sizeof(filetypes
)/sizeof(*filetypes
); j
++)
1262 if (attr
== filetypes
[j
].tree_attr
)
1264 ext_id
= filetypes
[j
].voiceclip
;
1269 talk_id(VOICE_FILE
, false);
1270 talk_number(pos
, true);
1271 talk_id(ext_id
, true);
1275 int ft_play_dirname(int start_index
)
1278 char dirname_mp3_filename
[MAX_PATH
+1];
1279 struct entry
*dircache
= tc
.dircache
;
1281 if (audio_status() & AUDIO_STATUS_PLAY
)
1284 snprintf(dirname_mp3_filename
, sizeof(dirname_mp3_filename
), "%s/%s/%s",
1285 tc
.currdir
[1] ? tc
.currdir
: "" , dircache
[start_index
].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 void ft_play_filename(char *dir
, char *file
)
1307 char name_mp3_filename
[MAX_PATH
+1];
1309 if (audio_status() & AUDIO_STATUS_PLAY
)
1312 if (strcasecmp(&file
[strlen(file
) - strlen(file_thumbnail_ext
)],
1313 file_thumbnail_ext
))
1314 { /* file has no .talk extension */
1315 snprintf(name_mp3_filename
, sizeof(name_mp3_filename
),
1316 "%s/%s%s", dir
, file
, file_thumbnail_ext
);
1318 talk_file(name_mp3_filename
, false);
1321 { /* it already is a .talk file, play this directly */
1322 snprintf(name_mp3_filename
, sizeof(name_mp3_filename
),
1323 "%s/%s", dir
, file
);
1324 talk_id(LANG_VOICE_DIR_HOVER
, false); /* prefix it */
1325 talk_file(name_mp3_filename
, true);
1329 /* These two functions are called by the USB and shutdown handlers */
1330 void tree_flush(void)
1334 playlist_shutdown();
1335 #ifdef HAVE_DIRCACHE
1336 if (global_settings
.dircache
)
1338 if (dircache_is_enabled())
1339 global_settings
.dircache_size
= dircache_get_cache_size();
1344 global_settings
.dircache_size
= 0;
1350 void tree_restore(void)
1354 #ifdef HAVE_DIRCACHE
1355 if (global_settings
.dircache
)
1357 /* Print "Scanning disk..." to the display. */
1361 screens
[i
].putsxy((LCD_WIDTH
/2) -
1362 ((strlen(str(LANG_DIRCACHE_BUILDING
)) *
1363 screens
[i
].char_width
)/2),
1364 LCD_HEIGHT
-screens
[i
].char_height
*3,
1365 str(LANG_DIRCACHE_BUILDING
));
1366 gui_textarea_update(&screens
[i
]);
1369 dircache_build(global_settings
.dircache_size
);
1371 /* Clean the text when we are done. */
1374 gui_textarea_clear(&screens
[i
]);