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"
40 #include "wps-display.h"
58 #include "filetypes.h"
62 #include "recorder/recording.h"
68 #include "statusbar.h"
70 #include "buttonbar.h"
72 #ifdef HAVE_LCD_BITMAP
76 /* a table for the know file types */
77 const struct filetype filetypes
[] = {
78 { "mp3", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
79 { "mp2", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
80 { "mpa", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
81 #if CONFIG_CODEC == SWCODEC
82 /* Temporary hack to allow playlist creation */
83 { "mp1", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
84 { "ogg", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
85 { "wma", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
86 { "wav", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
87 { "flac", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
88 { "ac3", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
89 { "a52", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
90 { "mpc", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
91 { "wv", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
92 { "m4a", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
94 { "m3u", TREE_ATTR_M3U
, Icon_Playlist
, LANG_PLAYLIST
},
95 { "cfg", TREE_ATTR_CFG
, Icon_Config
, VOICE_EXT_CFG
},
96 { "wps", TREE_ATTR_WPS
, Icon_Wps
, VOICE_EXT_WPS
},
97 { "lng", TREE_ATTR_LNG
, Icon_Language
, LANG_LANGUAGE
},
98 { "rock",TREE_ATTR_ROCK
,Icon_Plugin
, VOICE_EXT_ROCK
},
99 #ifdef HAVE_LCD_BITMAP
100 { "fnt", TREE_ATTR_FONT
,Icon_Font
, VOICE_EXT_FONT
},
102 { "bmark",TREE_ATTR_BMARK
, Icon_Bookmark
, VOICE_EXT_BMARK
},
104 { BOOTFILE_EXT
, TREE_ATTR_MOD
, Icon_Firmware
, VOICE_EXT_AJZ
},
105 #endif /* #ifndef SIMULATOR */
108 struct gui_synclist tree_lists
;
110 /* I put it here because other files doesn't use it yet,
111 * but should be elsewhere since it will be used mostly everywhere */
112 struct gui_syncstatusbar statusbars
;
114 struct gui_buttonbar tree_buttonbar
;
116 static struct tree_context tc
;
118 bool boot_changed
= false;
120 char lastfile
[MAX_PATH
];
121 static char lastdir
[MAX_PATH
];
122 static int lasttable
, lastextra
, lastfirstpos
;
123 static int max_files
= 0;
125 static bool reload_dir
= false;
127 static bool start_wps
= false;
128 static bool dirbrowse(void);
129 static int curr_context
= false;/* id3db or tree*/
132 * removes the extension of filename (if it doesn't start with a .)
133 * puts the result in buffer
135 char * strip_extension(char * filename
, char * buffer
)
138 char * dot
=strrchr(filename
, '.');
139 if(dot
!=0 && filename
[0]!='.')
141 dotpos
= dot
-filename
;
142 strncpy(buffer
, filename
, dotpos
);
149 char * tree_get_filename(int selected_item
, void * data
, char *buffer
)
151 struct tree_context
* local_tc
=(struct tree_context
*)data
;
154 bool id3db
= *(local_tc
->dirfilter
) == SHOW_ID3DB
;
157 name
= ((char**)local_tc
->dircache
)[selected_item
* local_tc
->dentry_size
];
160 struct entry
* dc
= local_tc
->dircache
;
161 struct entry
* e
= &dc
[selected_item
];
165 /* if any file filter is on, and if it's not a directory,
166 * strip the extension */
168 if ( (*(local_tc
->dirfilter
) != SHOW_ID3DB
) && !(attr
& ATTR_DIRECTORY
)
169 && (*(local_tc
->dirfilter
) != SHOW_ALL
) )
171 return(strip_extension(name
, buffer
));
177 void tree_get_fileicon(int selected_item
, void * data
, ICON
* icon
)
179 struct tree_context
* local_tc
=(struct tree_context
*)data
;
180 bool id3db
= *(local_tc
->dirfilter
) == SHOW_ID3DB
;
182 *icon
= db_get_icon(&tc
);
185 struct entry
* dc
= local_tc
->dircache
;
186 struct entry
* e
= &dc
[selected_item
];
187 *icon
= filetype_get_icon(e
->attr
);
191 bool check_rockboxdir(void)
193 DIR *dir
= opendir(ROCKBOX_DIR
);
197 for(i
= 0;i
< NB_SCREENS
;++i
)
198 screens
[i
].clear_display();
199 gui_syncsplash(HZ
*2, true, str(LANG_NO_ROCKBOX_DIR
));
200 for(i
= 0;i
< NB_SCREENS
;++i
)
201 screens
[i
].clear_display();
202 gui_syncsplash(HZ
*2, true, str(LANG_INSTALLATION_INCOMPLETE
));
209 void browse_root(void)
211 /* essential to all programs that wants to display things */
212 screen_access_init();
217 strcpy(tc
.currdir
, "/");
219 #ifdef HAVE_LCD_CHARCELLS
221 for(i
= 0;i
< NB_SCREENS
;++i
)
222 screens
[i
].double_height(false);
225 gui_buttonbar_init(&tree_buttonbar
);
226 /* since archos only have one screen, no need to create more than that */
227 gui_buttonbar_set_display(&tree_buttonbar
, &(screens
[SCREEN_MAIN
]) );
229 gui_syncstatusbar_init(&statusbars
);
230 gui_synclist_init(&tree_lists
, &tree_get_fileicon
, &tree_get_filename
, &tc
);
235 DEBUGF("No filesystem found. Have you forgotten to create it?\n");
240 void tree_get_filetypes(const struct filetype
** types
, int* count
)
243 *count
= sizeof(filetypes
) / sizeof(*filetypes
);
246 struct tree_context
* tree_get_context(void)
251 /* talkbox hovering delay, to avoid immediate disk activity */
252 #define HOVER_DELAY (HZ/2)
254 * Returns the position of a given file in the current directory
255 * returns -1 if not found
257 int tree_get_file_position(char * filename
)
260 /* use lastfile to determine the selected item (default=0) */
261 for (i
=0; i
< tc
.filesindir
; i
++)
263 struct entry
* dc
= tc
.dircache
;
264 struct entry
* e
= &dc
[i
];
265 if (!strcasecmp(e
->name
, filename
))
268 return(-1);/* no file can match, returns undefined */
272 * Called when a new dir is loaded (for example when returning from other apps ...)
273 * also completely redraws the tree
275 static int update_dir(void)
277 bool id3db
= *tc
.dirfilter
== SHOW_ID3DB
;
278 bool changed
= false;
279 /* Checks for changes */
281 if (tc
.currtable
!= lasttable
||
282 tc
.currextra
!= lastextra
||
283 tc
.firstpos
!= lastfirstpos
)
285 if (db_load(&tc
) < 0)
288 lasttable
= tc
.currtable
;
289 lastextra
= tc
.currextra
;
290 lastfirstpos
= tc
.firstpos
;
295 /* if the tc.currdir has been changed, reload it ...*/
296 if (strncmp(tc
.currdir
, lastdir
, sizeof(lastdir
)) || reload_dir
) {
298 if (ft_load(&tc
, NULL
) < 0)
300 strcpy(lastdir
, tc
.currdir
);
304 /* if selected item is undefined */
305 if (tc
.selected_item
== -1)
307 /* use lastfile to determine the selected item */
308 tc
.selected_item
= tree_get_file_position(lastfile
);
310 /* If the file doesn't exists, select the first one (default) */
311 if(tc
.selected_item
< 0)
312 tc
.selected_item
= 0;
317 if(!id3db
&& (tc
.dirfull
||
318 tc
.filesindir
== global_settings
.max_files_in_dir
) )
322 for(i
= 0;i
< NB_SCREENS
;++i
)
324 #ifdef HAVE_LCD_CHARCELLS
325 screens
[i
].double_height(false);
327 screens
[i
].clear_display();
328 screens
[i
].puts(0,0,str(LANG_SHOWDIR_ERROR_BUFFER
));
329 screens
[i
].puts(0,1,str(LANG_SHOWDIR_ERROR_FULL
));
330 #if defined(HAVE_LCD_BITMAP) || defined(SIMULATOR)
335 for(i
= 0;i
< NB_SCREENS
;++i
)
336 screens
[i
].clear_display();
339 gui_synclist_set_nb_items(&tree_lists
, tc
.filesindir
);
340 gui_synclist_select_item(&tree_lists
, tc
.selected_item
);
341 gui_synclist_draw(&tree_lists
);
342 gui_syncstatusbar_draw(&statusbars
, true);
344 if (global_settings
.buttonbar
) {
345 if (*tc
.dirfilter
< NUM_FILTER_MODES
)
346 gui_buttonbar_set(&tree_buttonbar
, str(LANG_DIRBROWSE_F1
),
347 str(LANG_DIRBROWSE_F2
),
348 str(LANG_DIRBROWSE_F3
));
350 gui_buttonbar_set(&tree_buttonbar
, "<<<", "", "");
351 gui_buttonbar_draw(&tree_buttonbar
);
354 return tc
.filesindir
;
357 /* load tracks from specified directory to resume play */
358 void resume_directory(const char *dir
)
360 if (ft_load(&tc
, dir
) < 0)
364 ft_build_playlist(&tc
, 0);
367 /* Returns the current working directory and also writes cwd to buf if
368 non-NULL. In case of error, returns NULL. */
369 char *getcwd(char *buf
, int size
)
375 strncpy(buf
, tc
.currdir
, size
);
382 /* Force a reload of the directory next time directory browser is called */
383 void reload_directory(void)
388 static void start_resume(bool just_powered_on
)
390 bool do_resume
= false;
391 if ( global_settings
.resume_index
!= -1 ) {
392 DEBUGF("Resume index %X offset %X\n",
393 global_settings
.resume_index
,
394 global_settings
.resume_offset
);
396 #ifdef HAVE_ALARM_MOD
397 if ( rtc_check_alarm_started(true) ) {
398 rtc_enable_alarm(false);
404 if ( global_settings
.resume
|| ! just_powered_on
)
407 if (! do_resume
) return;
409 if (playlist_resume() != -1)
411 playlist_start(global_settings
.resume_index
,
412 global_settings
.resume_offset
);
417 } else if (! just_powered_on
) {
418 gui_syncsplash(HZ
*2, true, str(LANG_NOTHING_TO_RESUME
));
422 /* Selects a file and update tree context properly */
423 void set_current_file(char *path
)
428 /* in ID3DB mode it is a bad idea to call this function */
429 /* (only happens with `follow playlist') */
430 if( *tc
.dirfilter
== SHOW_ID3DB
)
433 /* separate directory from filename */
434 /* gets the directory's name and put it into tc.currdir */
435 name
= strrchr(path
+1,'/');
439 strcpy(tc
.currdir
, path
);
445 strcpy(tc
.currdir
, "/");
449 strcpy(lastfile
, name
);
451 /* undefined item selected */
452 tc
.selected_item
= -1;
454 /* If we changed dir we must recalculate the dirlevel
455 and adjust the selected history properly */
456 if (strncmp(tc
.currdir
,lastdir
,sizeof(lastdir
)))
459 tc
.selected_item_history
[tc
.dirlevel
] = -1;
461 /* use '/' to calculate dirlevel */
462 /* FIXME : strlen(path) : crazy oO better to store it at
464 int path_len
= strlen(path
) + 1;
465 for (i
= 1; i
< path_len
; i
++)
470 tc
.selected_item_history
[tc
.dirlevel
] = -1;
476 static bool check_changed_id3mode(bool currmode
)
478 if (currmode
!= (global_settings
.dirfilter
== SHOW_ID3DB
)) {
479 currmode
= global_settings
.dirfilter
== SHOW_ID3DB
;
481 curr_context
=CONTEXT_ID3DB
;
486 curr_context
=CONTEXT_TREE
;
492 /* main loop, handles key events */
493 static bool dirbrowse(void)
499 bool reload_root
= false;
500 int lastfilter
= *tc
.dirfilter
;
501 bool lastsortcase
= global_settings
.sort_case
;
502 bool need_update
= true;
503 bool exit_func
= false;
504 long thumbnail_time
= -1; /* for delaying a thumbnail */
506 unsigned lastbutton
= 0;
507 char* currdir
= tc
.currdir
; /* just a shortcut */
508 bool id3db
= *tc
.dirfilter
== SHOW_ID3DB
;
511 curr_context
=CONTEXT_ID3DB
;
513 curr_context
=CONTEXT_TREE
;
514 #ifdef HAVE_LCD_BITMAP
515 screen_access_update_nb_lines();
517 tc
.selected_item
= 0;
524 if (*tc
.dirfilter
< NUM_FILTER_MODES
) {
525 #ifdef HAVE_RECORDING
527 if (global_settings
.rec_startup
) {
528 /* We fake being in the menu structure by calling
529 the appropriate parent when we drop out of each screen */
540 /* If we don't need to show the wps, draw the dir */
542 numentries
= update_dir();
543 if (numentries
== -1)
544 return false; /* currdir is not a directory */
546 if (*tc
.dirfilter
> NUM_FILTER_MODES
&& numentries
==0)
548 gui_syncsplash(HZ
*2, true, str(LANG_NO_FILES
));
549 return false; /* No files found for rockbox_browser() */
554 struct entry
*dircache
= tc
.dircache
;
555 bool restore
= false;
557 button
= button_get_w_tmo(HZ
/5);
564 for(i
= 0;i
< NB_SCREENS
;++i
)
566 screens
[i
].clear_display();
567 screens
[i
].puts(0,0,str(LANG_BOOT_CHANGED
));
568 screens
[i
].puts(0,1,str(LANG_REBOOT_NOW
));
569 #ifdef HAVE_LCD_BITMAP
570 screens
[i
].puts(0,3,str(LANG_CONFIRM_WITH_PLAY_RECORDER
));
571 screens
[i
].puts(0,4,str(LANG_CANCEL_WITH_ANY_RECORDER
));
576 button
= button_get(true);
582 rolo_load("/" BOOTFILE
);
587 if(default_event_handler(button
) ||
588 (button
& BUTTON_REL
))
595 boot_changed
= false;
598 need_update
= gui_synclist_do_button(&tree_lists
, button
);
603 case TREE_ENTER
| BUTTON_REPEAT
:
610 if (((button
== TREE_RUN
)
611 #ifdef TREE_RC_RUN_PRE
612 || (button
== TREE_RC_RUN
))
613 && ((lastbutton
!= TREE_RC_RUN_PRE
)
615 && (lastbutton
!= TREE_RUN_PRE
)))
618 /* nothing to do if no files to display */
619 if ( numentries
== 0 )
622 switch (id3db
?db_enter(&tc
):ft_enter(&tc
))
624 case 1: reload_dir
= true; break;
625 case 2: start_wps
= true; break;
626 case 3: exit_func
= true; break;
633 case TREE_EXIT
| BUTTON_REPEAT
:
637 if (*tc
.dirfilter
> NUM_FILTER_MODES
&& tc
.dirlevel
< 1) {
641 /* if we are in /, nothing to do */
642 if (tc
.dirlevel
== 0)
648 if (ft_exit(&tc
) == 3)
656 if (*tc
.dirfilter
< NUM_FILTER_MODES
)
658 /* Stop the music if it is playing */
661 #if (CONFIG_KEYPAD == RECORDER_PAD) && !defined(HAVE_SW_POWEROFF)
663 if (!charger_inserted()) {
664 if(shutdown_screen())
674 #if defined(HAVE_CHARGING) && !defined(HAVE_POWEROFF_WHILE_CHARGING)
675 case TREE_OFF
| BUTTON_REPEAT
:
676 if (charger_inserted()) {
682 #endif /* TREE_OFF */
688 if (lastbutton
!= TREE_MENU_PRE
)
691 /* don't enter menu from plugin browser */
692 if (*tc
.dirfilter
< NUM_FILTER_MODES
)
695 for(i
= 0;i
< NB_SCREENS
;++i
)
696 screens
[i
].stop_scroll();
701 id3db
= check_changed_id3mode(id3db
);
703 else /* use it as a quick exit instead */
712 if ((lastbutton
!= TREE_WPS_PRE
)
714 && (lastbutton
!= TREE_RC_WPS_PRE
)
719 /* don't enter wps from plugin browser etc */
720 if (*tc
.dirfilter
< NUM_FILTER_MODES
)
722 if (audio_status() & AUDIO_STATUS_PLAY
)
736 /* don't enter f2 from plugin browser */
737 if (*tc
.dirfilter
< NUM_FILTER_MODES
)
739 if (quick_screen(curr_context
, TREE_QUICK
))
743 id3db
= check_changed_id3mode(id3db
);
751 /* don't enter f3 from plugin browser */
752 if (*tc
.dirfilter
< NUM_FILTER_MODES
)
754 if (quick_screen(curr_context
, BUTTON_F3
))
756 screen_access_update_nb_lines();
763 #ifdef TREE_RC_CONTEXT
764 case TREE_RC_CONTEXT
:
774 onplay_result
= onplay(NULL
, 0, curr_context
);
778 switch (tc
.currtable
)
785 db_get_filename(&tc
, buf
, sizeof(buf
));
791 attr
= dircache
[tc
.selected_item
].attr
;
793 if (currdir
[1]) /* Not in / */
794 snprintf(buf
, sizeof buf
, "%s/%s",
796 dircache
[tc
.selected_item
].name
);
798 snprintf(buf
, sizeof buf
, "/%s",
799 dircache
[tc
.selected_item
].name
);
801 onplay_result
= onplay(buf
, attr
, curr_context
);
804 switch (onplay_result
)
810 case ONPLAY_RELOAD_DIR
:
814 case ONPLAY_START_PLAY
:
822 if (thumbnail_time
!= -1 &&
823 TIME_AFTER(current_tick
, thumbnail_time
))
824 { /* a delayed hovering thumbnail is due now */
826 if (dircache
[lasti
].attr
& ATTR_DIRECTORY
)
828 DEBUGF("Playing directory thumbnail: %s", currdir
);
829 res
= ft_play_dirname(lasti
);
830 if (res
< 0) /* failed, not existing */
831 { /* say the number instead, as a fallback */
832 talk_id(VOICE_DIR
, false);
833 talk_number(lasti
+1, true);
838 DEBUGF("Playing file thumbnail: %s/%s%s\n",
839 currdir
, dircache
[lasti
].name
, file_thumbnail_ext
);
840 /* no fallback necessary, we knew in advance
841 that the file exists */
842 ft_play_filename(currdir
, dircache
[lasti
].name
);
844 thumbnail_time
= -1; /* job done */
846 gui_syncstatusbar_draw(&statusbars
, false);
853 /* The 'dir no longer valid' situation will be caught later
854 * by checking the showdir() result. */
859 if (default_event_handler(button
) == SYS_USB_CONNECTED
)
861 if(*tc
.dirfilter
> NUM_FILTER_MODES
)
862 /* leave sub-browsers after usb, doing otherwise
863 might be confusing to the user */
877 if (start_wps
&& audio_status() )
880 for(i
= 0;i
< NB_SCREENS
;++i
)
881 screens
[i
].stop_scroll();
882 if (wps_show() == SYS_USB_CONNECTED
)
886 if (!id3db
) /* Try reload to catch 'no longer valid' case. */
889 #ifdef HAVE_LCD_BITMAP
890 screen_access_update_nb_lines();
892 id3db
= check_changed_id3mode(id3db
);
898 /* do we need to rescan dir? */
899 if (reload_dir
|| reload_root
||
900 lastfilter
!= *tc
.dirfilter
||
901 lastsortcase
!= global_settings
.sort_case
)
904 strcpy(currdir
, "/");
914 gui_synclist_select_item(&tree_lists
, 0);
915 gui_synclist_draw(&tree_lists
);
916 tc
.selected_item
= 0;
920 lastfilter
= *tc
.dirfilter
;
921 lastsortcase
= global_settings
.sort_case
;
923 button_clear_queue(); /* clear button queue */
929 if (restore
|| reload_dir
) {
930 /* restore display */
931 #ifdef HAVE_LCD_BITMAP
932 screen_access_update_nb_lines();
934 numentries
= update_dir();
935 if (currdir
[1] && (numentries
< 0))
936 { /* not in root and reload failed */
937 reload_root
= true; /* try root */
945 tc
.selected_item
= gui_synclist_get_sel_pos(&tree_lists
);
947 if ( numentries
> 0 ) {
948 /* Voice the file if changed */
949 if(lasti
!= tc
.selected_item
|| restore
) {
950 lasti
= tc
.selected_item
;
951 thumbnail_time
= -1; /* Cancel whatever we were
955 if (dircache
[tc
.selected_item
].attr
& ATTR_DIRECTORY
)
957 /* play directory thumbnail */
958 switch (global_settings
.talk_dir
) {
959 case 1: /* dirs as numbers */
960 talk_id(VOICE_DIR
, false);
961 talk_number(tc
.selected_item
+1, true);
964 case 2: /* dirs spelled */
965 talk_spell(dircache
[tc
.selected_item
].name
,
969 case 3: /* thumbnail clip */
970 /* "schedule" a thumbnail, to have a little
972 thumbnail_time
= current_tick
+ HOVER_DELAY
;
981 switch (global_settings
.talk_file
) {
982 case 1: /* files as numbers */
984 tc
.selected_item
-tc
.dirsindir
+1,
985 dircache
[tc
.selected_item
].attr
&
989 case 2: /* files spelled */
990 talk_spell(dircache
[tc
.selected_item
].name
,
994 case 3: /* thumbnail clip */
995 /* "schedule" a thumbnail, to have a little
997 if (dircache
[tc
.selected_item
].attr
&
999 thumbnail_time
= current_tick
+ HOVER_DELAY
;
1001 /* spell the number as fallback */
1002 talk_spell(dircache
[tc
.selected_item
].name
,
1018 static int plsize
= 0;
1019 static bool add_dir(char* dirname
, int len
, int fd
)
1024 /* check for user abort */
1026 if (button_get(false) == BUTTON_STOP
)
1028 if (button_get(false) == BUTTON_OFF
)
1032 dir
= opendir_cached(dirname
);
1037 struct dircache_entry
*entry
;
1039 entry
= readdir_cached(dir
);
1042 if (entry
->attribute
& ATTR_DIRECTORY
) {
1043 int dirlen
= strlen(dirname
);
1046 if (!strcmp(entry
->d_name
, ".") ||
1047 !strcmp(entry
->d_name
, ".."))
1051 snprintf(dirname
+dirlen
, len
-dirlen
, "/%s", entry
->d_name
);
1053 snprintf(dirname
, len
, "/%s", entry
->d_name
);
1055 result
= add_dir(dirname
, len
, fd
);
1056 dirname
[dirlen
] = '\0';
1063 int x
= strlen(entry
->d_name
);
1065 char *cp
= strrchr(entry
->d_name
,'.');
1070 /* add all supported audio files to playlists */
1071 for (i
=0; i
< sizeof(filetypes
); i
++) {
1072 if (filetypes
[i
].tree_attr
== TREE_ATTR_MPA
) {
1073 if (!strcasecmp(cp
, filetypes
[i
].extension
))
1077 write(fd
, dirname
, strlen(dirname
));
1079 write(fd
, entry
->d_name
, x
);
1083 snprintf(buf
, sizeof buf
, "%d", plsize
);
1084 #ifdef HAVE_LCD_BITMAP
1085 for(i
= 0;i
< NB_SCREENS
;++i
)
1087 screens
[i
].puts(0,4,buf
);
1088 screens
[i
].update();
1102 for(i
= 0;i
< NB_SCREENS
;++i
)
1103 screens
[i
].puts(x
,0,buf
);
1112 closedir_cached(dir
);
1117 bool create_playlist(void)
1121 char filename
[MAX_PATH
];
1123 snprintf(filename
, sizeof filename
, "%s.m3u",
1124 tc
.currdir
[1] ? tc
.currdir
: "/root");
1125 for(i
= 0;i
< NB_SCREENS
;++i
)
1127 screens
[i
].clear_display();
1128 screens
[i
].puts(0,0,str(LANG_CREATING
));
1129 screens
[i
].puts_scroll(0,1,filename
);
1130 #if defined(HAVE_LCD_BITMAP) || defined(SIMULATOR)
1131 screens
[i
].update();
1134 fd
= creat(filename
,0);
1138 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
1142 snprintf(filename
, sizeof(filename
), "%s",
1143 tc
.currdir
[1] ? tc
.currdir
: "/");
1145 add_dir(filename
, sizeof(filename
), fd
);
1148 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
1157 bool rockbox_browse(const char *root
, int dirfilter
)
1159 static struct tree_context backup
;
1163 memcpy(tc
.currdir
, root
, sizeof(tc
.currdir
));
1165 tc
.dirfilter
= &dirfilter
;
1173 void tree_init(void)
1175 /* We copy the settings value in case it is changed by the user. We can't
1176 use it until the next reboot. */
1177 max_files
= global_settings
.max_files_in_dir
;
1179 /* initialize tree context struct */
1180 memset(&tc
, 0, sizeof(tc
));
1181 tc
.dirfilter
= &global_settings
.dirfilter
;
1185 tc
.name_buffer_size
= AVERAGE_FILENAME_LENGTH
* max_files
;
1186 tc
.name_buffer
= buffer_alloc(tc
.name_buffer_size
);
1188 tc
.dircache_size
= max_files
* sizeof(struct entry
);
1189 tc
.dircache
= buffer_alloc(tc
.dircache_size
);
1192 void bookmark_play(char *resume_file
, int index
, int offset
, int seed
,
1196 int len
=strlen(resume_file
);
1198 if (!strcasecmp(&resume_file
[len
-4], ".m3u"))
1200 /* Playlist playback */
1202 /* check that the file exists */
1203 int fd
= open(resume_file
, O_RDONLY
);
1208 slash
= strrchr(resume_file
,'/');
1218 if (playlist_create(cp
, slash
+1) != -1)
1220 if (global_settings
.playlist_shuffle
)
1221 playlist_shuffle(seed
, -1);
1222 playlist_start(index
,offset
);
1229 /* Directory playback */
1231 if (playlist_create(resume_file
, NULL
) != -1)
1233 resume_directory(resume_file
);
1234 if (global_settings
.playlist_shuffle
)
1235 playlist_shuffle(seed
, -1);
1237 /* Check if the file is at the same spot in the directory,
1238 else search for it */
1239 if ((strcmp(strrchr(playlist_peek(index
) + 1,'/') + 1,
1242 for ( i
=0; i
< playlist_amount(); i
++ )
1244 if ((strcmp(strrchr(playlist_peek(i
) + 1,'/') + 1,
1248 if (i
< playlist_amount())
1253 playlist_start(index
,offset
);
1260 int ft_play_filenumber(int pos
, int attr
)
1262 /* try to find a voice ID for the extension, if known */
1264 int ext_id
= -1; /* default to none */
1265 for (j
=0; j
<sizeof(filetypes
)/sizeof(*filetypes
); j
++)
1267 if (attr
== filetypes
[j
].tree_attr
)
1269 ext_id
= filetypes
[j
].voiceclip
;
1274 talk_id(VOICE_FILE
, false);
1275 talk_number(pos
, true);
1276 talk_id(ext_id
, true);
1280 int ft_play_dirname(int start_index
)
1283 char dirname_mp3_filename
[MAX_PATH
+1];
1284 struct entry
*dircache
= tc
.dircache
;
1286 if (audio_status() & AUDIO_STATUS_PLAY
)
1289 snprintf(dirname_mp3_filename
, sizeof(dirname_mp3_filename
), "%s/%s/%s",
1290 tc
.currdir
[1] ? tc
.currdir
: "" , dircache
[start_index
].name
,
1291 dir_thumbnail_name
);
1293 DEBUGF("Checking for %s\n", dirname_mp3_filename
);
1295 fd
= open(dirname_mp3_filename
, O_RDONLY
);
1298 DEBUGF("Failed to find: %s\n", dirname_mp3_filename
);
1304 DEBUGF("Found: %s\n", dirname_mp3_filename
);
1306 talk_file(dirname_mp3_filename
, false);
1310 void ft_play_filename(char *dir
, char *file
)
1312 char name_mp3_filename
[MAX_PATH
+1];
1314 if (audio_status() & AUDIO_STATUS_PLAY
)
1317 if (strcasecmp(&file
[strlen(file
) - strlen(file_thumbnail_ext
)],
1318 file_thumbnail_ext
))
1319 { /* file has no .talk extension */
1320 snprintf(name_mp3_filename
, sizeof(name_mp3_filename
),
1321 "%s/%s%s", dir
, file
, file_thumbnail_ext
);
1323 talk_file(name_mp3_filename
, false);
1326 { /* it already is a .talk file, play this directly */
1327 snprintf(name_mp3_filename
, sizeof(name_mp3_filename
),
1328 "%s/%s", dir
, file
);
1329 talk_id(LANG_VOICE_DIR_HOVER
, false); /* prefix it */
1330 talk_file(name_mp3_filename
, true);
1334 /* These two functions are called by the USB and shutdown handlers */
1335 void tree_flush(void)
1339 #ifdef HAVE_DIRCACHE
1340 if (global_settings
.dircache
)
1342 if (dircache_is_enabled())
1343 global_settings
.dircache_size
= dircache_get_cache_size();
1348 global_settings
.dircache_size
= 0;
1354 void tree_restore(void)
1358 #ifdef HAVE_DIRCACHE
1359 if (global_settings
.dircache
)
1361 /* Print "Scanning disk..." to the display. */
1363 for(i
= 0;i
< NB_SCREENS
;++i
)
1365 screens
[i
].putsxy((LCD_WIDTH
/2) -
1366 ((strlen(str(LANG_DIRCACHE_BUILDING
)) *
1367 screens
[i
].char_width
)/2),
1368 LCD_HEIGHT
-screens
[i
].char_height
*3,
1369 str(LANG_DIRCACHE_BUILDING
));
1370 screens
[i
].update();
1372 dircache_build(global_settings
.dircache_size
);
1373 /* Clean the text when we are done. */
1374 for(i
=0;i
<NB_SCREENS
;++i
)
1376 screens
[i
].set_drawmode(DRMODE_SOLID
|DRMODE_INVERSEVID
);
1377 screens
[i
].fillrect(0, LCD_HEIGHT
-screens
[i
].char_height
*3,
1378 LCD_WIDTH
, screens
[i
].char_height
);
1379 screens
[i
].set_drawmode(DRMODE_SOLID
);
1380 screens
[i
].update();