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"
63 #ifdef HAVE_LCD_BITMAP
67 /* a table for the know file types */
68 const struct filetype filetypes
[] = {
69 { ".mp3", TREE_ATTR_MPA
, File
, VOICE_EXT_MPA
},
70 { ".mp2", TREE_ATTR_MPA
, File
, VOICE_EXT_MPA
},
71 { ".mpa", TREE_ATTR_MPA
, File
, VOICE_EXT_MPA
},
72 { ".m3u", TREE_ATTR_M3U
, Playlist
, LANG_PLAYINDICES_PLAYLIST
},
73 { ".cfg", TREE_ATTR_CFG
, Config
, VOICE_EXT_CFG
},
74 { ".wps", TREE_ATTR_WPS
, Wps
, VOICE_EXT_WPS
},
75 { ".lng", TREE_ATTR_LNG
, Language
, LANG_LANGUAGE
},
76 { ".rock",TREE_ATTR_ROCK
,Plugin
, VOICE_EXT_ROCK
},
77 #ifdef HAVE_LCD_BITMAP
78 { ".fnt", TREE_ATTR_FONT
,Font
, VOICE_EXT_FONT
},
80 { ".bmark",TREE_ATTR_BMARK
, Bookmark
, VOICE_EXT_BMARK
},
82 #ifdef HAVE_LCD_BITMAP
83 { ".ajz", TREE_ATTR_MOD
, Mod_Ajz
, VOICE_EXT_AJZ
},
85 { ".mod", TREE_ATTR_MOD
, Mod_Ajz
, VOICE_EXT_AJZ
},
87 #endif /* #ifndef SIMULATOR */
90 static struct tree_context tc
;
92 bool boot_changed
= false;
94 char lastfile
[MAX_PATH
];
95 char lastdir
[MAX_PATH
];
97 static bool reload_dir
= false;
99 static bool start_wps
= false;
100 static bool dirbrowse(void);
102 bool check_rockboxdir(void)
104 DIR *dir
= opendir(ROCKBOX_DIR
);
108 splash(HZ
*2, true, str(LANG_NO_ROCKBOX_DIR
));
110 splash(HZ
*2, true, str(LANG_INSTALLATION_INCOMPLETE
));
117 void browse_root(void)
122 strcpy(tc
.currdir
, "/");
129 DEBUGF("No filesystem found. Have you forgotten to create it?\n");
134 void tree_get_filetypes(const struct filetype
** types
, int* count
)
137 *count
= sizeof(filetypes
) / sizeof(*filetypes
);
140 struct tree_context
* tree_get_context(void)
145 #ifdef HAVE_LCD_BITMAP
148 #define MARGIN_X (global_settings.scrollbar && \
149 tc.filesindir > tree_max_on_screen ? SCROLLBAR_WIDTH : 0) + \
150 CURSOR_WIDTH + (global_settings.show_icons && ICON_WIDTH > 0 ? ICON_WIDTH :0)
151 #define MARGIN_Y (global_settings.statusbar ? STATUSBAR_HEIGHT : 0)
153 /* position the entry-list starts at */
155 #define LINE_Y (global_settings.statusbar ? 1 : 0)
157 #define CURSOR_X (global_settings.scrollbar && \
158 tc.filesindir > tree_max_on_screen ? 1 : 0)
159 #define CURSOR_Y 0 /* the cursor is not positioned in regard to
160 the margins, so this is the amount of lines
161 we add to the cursor Y position to position
163 #define CURSOR_WIDTH (global_settings.invert_cursor ? 0 : 4)
167 #define SCROLLBAR_X 0
168 #define SCROLLBAR_Y lcd_getymargin()
169 #define SCROLLBAR_WIDTH 6
171 #else /* HAVE_LCD_BITMAP */
173 #define TREE_MAX_ON_SCREEN 2
174 #define TREE_MAX_LEN_DISPLAY 11 /* max length that fits on screen */
175 #define LINE_X 2 /* X position the entry-list starts at */
176 #define LINE_Y 0 /* Y position the entry-list starts at */
179 #define CURSOR_Y 0 /* not really used for players */
181 #endif /* HAVE_LCD_BITMAP */
183 /* talkbox hovering delay, to avoid immediate disk activity */
184 #define HOVER_DELAY (HZ/2)
186 static void showfileline(int line
, char* name
, int attr
, bool scroll
)
191 #ifdef HAVE_LCD_CHARCELLS
192 if (!global_settings
.show_icons
)
196 /* if any file filter is on, strip the extension */
197 if (*tc
.dirfilter
!= SHOW_ID3DB
&&
198 *tc
.dirfilter
!= SHOW_ALL
&&
199 !(attr
& ATTR_DIRECTORY
))
201 dotpos
= strrchr(name
, '.');
208 #ifdef HAVE_LCD_BITMAP
209 lcd_setfont(FONT_UI
);
210 if (global_settings
.invert_cursor
)
211 lcd_puts_scroll_style(xpos
, line
, name
, STYLE_INVERT
);
214 lcd_puts_scroll(xpos
, line
, name
);
216 lcd_puts(xpos
, line
, name
);
218 /* Restore the dot before the extension if it was removed */
223 #ifdef HAVE_LCD_BITMAP
224 static int recalc_screen_height(void)
227 int height
= LCD_HEIGHT
;
229 lcd_setfont(FONT_UI
);
230 lcd_getstringsize("A", &fw
, &fh
);
231 if(global_settings
.statusbar
)
232 height
-= STATUSBAR_HEIGHT
;
234 #if CONFIG_KEYPAD == RECORDER_PAD
235 if(global_settings
.buttonbar
)
236 height
-= BUTTONBAR_HEIGHT
;
243 static int showdir(void)
245 struct entry
*dircache
= tc
.dircache
;
247 int tree_max_on_screen
;
248 bool dir_buffer_full
= false;
249 int start
= tc
.dirstart
;
250 bool id3db
= global_settings
.dirfilter
== SHOW_ID3DB
;
252 #ifdef HAVE_LCD_BITMAP
256 lcd_setfont(FONT_UI
);
257 lcd_getstringsize("A", &fw
, &fh
);
258 tree_max_on_screen
= recalc_screen_height();
262 tree_max_on_screen
= TREE_MAX_ON_SCREEN
;
265 /* new file dir? load it */
267 if (db_load(&tc
, &dir_buffer_full
) < 0)
271 if (strncmp(tc
.currdir
, lastdir
, sizeof(lastdir
)) || reload_dir
) {
272 if (ft_load(&tc
, &dir_buffer_full
) < 0)
277 if ( dir_buffer_full
|| tc
.filesindir
== global_settings
.max_files_in_dir
) {
278 #ifdef HAVE_LCD_CHARCELLS
279 lcd_double_height(false);
282 lcd_puts(0,0,str(LANG_SHOWDIR_ERROR_BUFFER
));
283 lcd_puts(0,1,str(LANG_SHOWDIR_ERROR_FULL
));
293 /* use lastfile to determine start (default=0) */
296 for (i
=0; i
< tc
.filesindir
; i
++)
298 struct entry
*dircache
= tc
.dircache
;
300 if (!strcasecmp(dircache
[i
].name
, lastfile
))
307 diff_files
= tc
.filesindir
- start
;
308 if (diff_files
< tree_max_on_screen
)
310 int oldstart
= start
;
312 start
-= (tree_max_on_screen
- diff_files
);
316 tc
.dircursor
= oldstart
- start
;
322 /* The cursor might point to an invalid line, for example if someone
323 deleted the last file in the dir */
326 while (start
+ tc
.dircursor
>= tc
.filesindir
)
337 #ifdef HAVE_LCD_CHARCELLS
339 lcd_double_height(false);
342 #ifdef HAVE_LCD_BITMAP
343 lcd_setmargins(MARGIN_X
,MARGIN_Y
); /* leave room for cursor and icon */
344 lcd_setfont(FONT_UI
);
348 for ( i
=start
; i
< start
+tree_max_on_screen
&& i
< tc
.filesindir
; i
++ ) {
349 int line
= i
- start
;
354 name
= ((char**)tc
.dircache
)[i
* 2];
355 icon
= db_get_icon(&tc
);
358 struct entry
* dc
= tc
.dircache
;
359 struct entry
* e
= &dc
[i
];
362 icon
= filetype_get_icon(dircache
[i
].attr
);
366 if (icon
&& global_settings
.show_icons
) {
367 #ifdef HAVE_LCD_BITMAP
369 if ( line_height
> 8 )
370 offset
= (line_height
- 8) / 2;
372 CURSOR_X
* 6 + CURSOR_WIDTH
,
373 MARGIN_Y
+(i
-start
)*line_height
+ offset
,
378 lcd_putc(LINE_X
-1, i
-start
, icon
);
382 showfileline(line
, name
, attr
, false); /* no scroll */
385 #ifdef HAVE_LCD_BITMAP
386 if (global_settings
.scrollbar
&& (tc
.filesindir
> tree_max_on_screen
))
387 scrollbar(SCROLLBAR_X
, SCROLLBAR_Y
, SCROLLBAR_WIDTH
- 1,
388 tree_max_on_screen
* line_height
, tc
.filesindir
, start
,
389 start
+ tree_max_on_screen
, VERTICAL
);
391 #if CONFIG_KEYPAD == RECORDER_PAD
392 if(global_settings
.buttonbar
) {
393 buttonbar_set(*tc
.dirfilter
< NUM_FILTER_MODES
?
394 str(LANG_DIRBROWSE_F1
) : (unsigned char *) "",
395 str(LANG_DIRBROWSE_F2
),
396 str(LANG_DIRBROWSE_F3
));
403 return tc
.filesindir
;
406 static bool ask_resume(bool ask_once
)
410 static bool ignore_power
= true;
412 #ifdef HAVE_LCD_CHARCELLS
413 lcd_double_height(false);
417 default_event_handler(SYS_USB_CONNECTED
);
422 if ( global_settings
.resume
== RESUME_ON
)
426 lcd_puts(0,0,str(LANG_RESUME_ASK
));
427 #ifdef HAVE_LCD_CHARCELLS
429 lcd_puts(0,1,str(LANG_RESUME_CONFIRM_PLAYER
));
431 lcd_puts(0,1,str(LANG_CONFIRM_WITH_PLAY_RECORDER
));
432 lcd_puts(0,2,str(LANG_CANCEL_WITH_ANY_RECORDER
));
437 button
= button_get(true);
440 case TREE_RUN_PRE
: /* catch the press, not the release */
447 ignore_power
= false;
448 /* Don't ignore the power button for subsequent calls */
451 #ifdef TREE_POWER_BTN
452 /* Initially ignore the button which powers on the box. It
453 might still be pressed since booting. */
455 case TREE_POWER_BTN
| BUTTON_REPEAT
:
460 /* No longer ignore the power button after it was released */
461 case TREE_POWER_BTN
| BUTTON_REL
:
462 ignore_power
= false;
465 /* Handle sys events, ignore button releases */
467 if(default_event_handler(button
) || !(button
& BUTTON_REL
))
473 if ( global_settings
.resume
== RESUME_ASK_ONCE
&& ask_once
) {
474 global_settings
.resume_index
= -1;
478 ignore_power
= false;
479 /* Don't ignore the power button for subsequent calls */
483 /* load tracks from specified directory to resume play */
484 void resume_directory(const char *dir
)
488 strcpy(tc
.currdir
, dir
);
489 if (!ft_load(&tc
, &buffer_full
))
493 ft_build_playlist(&tc
, 0);
496 /* Returns the current working directory and also writes cwd to buf if
497 non-NULL. In case of error, returns NULL. */
498 char *getcwd(char *buf
, int size
)
504 strncpy(buf
, tc
.currdir
, size
);
511 /* Force a reload of the directory next time directory browser is called */
512 void reload_directory(void)
517 static void start_resume(bool ask_once
)
519 if ( global_settings
.resume
&&
520 global_settings
.resume_index
!= -1 ) {
521 DEBUGF("Resume index %X offset %X\n",
522 global_settings
.resume_index
,
523 global_settings
.resume_offset
);
525 if (!ask_resume(ask_once
))
528 if (playlist_resume() != -1)
530 playlist_start(global_settings
.resume_index
,
531 global_settings
.resume_offset
);
540 void set_current_file(char *path
)
545 /* separate directory from filename */
546 name
= strrchr(path
+1,'/');
550 strcpy(tc
.currdir
, path
);
556 strcpy(tc
.currdir
, "/");
560 strcpy(lastfile
, name
);
565 if (strncmp(tc
.currdir
,lastdir
,sizeof(lastdir
)))
568 tc
.dirpos
[tc
.dirlevel
] = -1;
569 tc
.cursorpos
[tc
.dirlevel
] = 0;
571 /* use '/' to calculate dirlevel */
572 for (i
=1; i
<strlen(path
)+1; i
++)
577 tc
.dirpos
[tc
.dirlevel
] = -1;
578 tc
.cursorpos
[tc
.dirlevel
] = 0;
584 static bool check_changed_id3mode(bool currmode
)
586 if (currmode
!= (global_settings
.dirfilter
== SHOW_ID3DB
)) {
587 currmode
= global_settings
.dirfilter
== SHOW_ID3DB
;
597 static bool dirbrowse(void)
604 int tree_max_on_screen
;
605 bool reload_root
= false;
606 int lastfilter
= *tc
.dirfilter
;
607 bool lastsortcase
= global_settings
.sort_case
;
608 int lastdircursor
=-1;
609 bool need_update
= true;
610 bool exit_func
= false;
611 long thumbnail_time
= -1; /* for delaying a thumbnail */
612 bool update_all
= false; /* set this to true when the whole file list
613 has been refreshed on screen */
615 char* currdir
= tc
.currdir
; /* just a shortcut */
616 bool id3db
= global_settings
.dirfilter
== SHOW_ID3DB
;
618 #ifdef HAVE_LCD_BITMAP
619 tree_max_on_screen
= recalc_screen_height();
621 tree_max_on_screen
= TREE_MAX_ON_SCREEN
;
628 if (*tc
.dirfilter
< NUM_FILTER_MODES
)
631 numentries
= showdir();
632 if (numentries
== -1)
633 return false; /* currdir is not a directory */
635 if (*tc
.dirfilter
> NUM_FILTER_MODES
&& numentries
==0)
637 splash(HZ
*2, true, str(LANG_NO_FILES
));
638 return false; /* No files found for rockbox_browser() */
642 put_cursorxy(CURSOR_X
, CURSOR_Y
+ tc
.dircursor
, true);
645 struct entry
*dircache
= tc
.dircache
;
647 bool restore
= false;
649 button
= button_get_w_tmo(HZ
/5);
657 lcd_puts(0,0,str(LANG_BOOT_CHANGED
));
658 lcd_puts(0,1,str(LANG_REBOOT_NOW
));
659 #ifdef HAVE_LCD_BITMAP
660 lcd_puts(0,3,str(LANG_CONFIRM_WITH_PLAY_RECORDER
));
661 lcd_puts(0,4,str(LANG_CANCEL_WITH_ANY_RECORDER
));
665 button
= button_get(true);
668 rolo_load("/" BOOTFILE
);
673 if(default_event_handler(button
) ||
674 (button
& BUTTON_REL
))
681 boot_changed
= false;
688 case TREE_ENTER
| BUTTON_REPEAT
:
695 if ((button
== TREE_RUN
) &&
696 (lastbutton
!= TREE_RUN_PRE
))
705 switch (ft_enter(&tc
))
707 case 1: reload_dir
= true; break;
708 case 2: reload_root
= true; break;
709 case 3: start_wps
= true; break;
710 case 4: exit_func
= true; break;
714 #ifdef HAVE_LCD_BITMAP
715 /* maybe we have a new font */
716 tree_max_on_screen
= recalc_screen_height();
720 /* make sure cursor is on screen */
721 while ( tc
.dircursor
> tree_max_on_screen
)
731 case TREE_EXIT
| BUTTON_REPEAT
:
741 if (ft_exit(&tc
) == 4)
748 #ifndef HAVE_SW_POWEROFF
750 if (*tc
.dirfilter
< NUM_FILTER_MODES
)
752 /* Stop the music if it is playing, else show the shutdown
757 if (!charger_inserted()) {
767 case TREE_OFF
| BUTTON_REPEAT
:
768 if (charger_inserted()) {
776 case TREE_PREV
| BUTTON_REPEAT
:
779 case TREE_RC_PREV
| BUTTON_REPEAT
:
783 put_cursorxy(CURSOR_X
, CURSOR_Y
+ tc
.dircursor
, false);
785 put_cursorxy(CURSOR_X
, CURSOR_Y
+ tc
.dircursor
, true);
790 numentries
= showdir();
792 put_cursorxy(CURSOR_X
, CURSOR_Y
+ tc
.dircursor
, true);
795 if (numentries
< tree_max_on_screen
) {
796 put_cursorxy(CURSOR_X
, CURSOR_Y
+ tc
.dircursor
,
798 tc
.dircursor
= numentries
- 1;
799 put_cursorxy(CURSOR_X
, CURSOR_Y
+ tc
.dircursor
,
803 tc
.dirstart
= numentries
- tree_max_on_screen
;
804 tc
.dircursor
= tree_max_on_screen
- 1;
805 numentries
= showdir();
807 put_cursorxy(CURSOR_X
, CURSOR_Y
+
808 tree_max_on_screen
- 1, true);
817 case TREE_NEXT
| BUTTON_REPEAT
:
820 case TREE_RC_NEXT
| BUTTON_REPEAT
:
824 if (tc
.dircursor
+ tc
.dirstart
+ 1 < numentries
) {
825 if(tc
.dircursor
+1 < tree_max_on_screen
) {
826 put_cursorxy(CURSOR_X
, CURSOR_Y
+ tc
.dircursor
, false);
828 put_cursorxy(CURSOR_X
, CURSOR_Y
+ tc
.dircursor
, true);
832 numentries
= showdir();
834 put_cursorxy(CURSOR_X
, CURSOR_Y
+ tc
.dircursor
, true);
838 if(numentries
< tree_max_on_screen
) {
839 put_cursorxy(CURSOR_X
, CURSOR_Y
+ tc
.dircursor
, false);
840 tc
.dirstart
= tc
.dircursor
= 0;
841 put_cursorxy(CURSOR_X
, CURSOR_Y
+ tc
.dircursor
, true);
844 tc
.dirstart
= tc
.dircursor
= 0;
845 numentries
= showdir();
847 put_cursorxy(CURSOR_X
, CURSOR_Y
+ tc
.dircursor
, true);
856 case TREE_PGUP
| BUTTON_REPEAT
:
858 tc
.dirstart
-= tree_max_on_screen
;
859 if ( tc
.dirstart
< 0 )
868 case TREE_PGDN
| BUTTON_REPEAT
:
869 if ( tc
.dirstart
< numentries
- tree_max_on_screen
) {
870 tc
.dirstart
+= tree_max_on_screen
;
872 numentries
- tree_max_on_screen
)
873 tc
.dirstart
= numentries
- tree_max_on_screen
;
876 tc
.dircursor
= numentries
- tc
.dirstart
- 1;
883 if (lastbutton
!= TREE_MENU_PRE
)
886 /* don't enter menu from plugin browser */
887 if (*tc
.dirfilter
< NUM_FILTER_MODES
)
894 id3db
= check_changed_id3mode(id3db
);
900 if (lastbutton
!= TREE_WPS_PRE
)
903 /* don't enter wps from plugin browser etc */
904 if (*tc
.dirfilter
< NUM_FILTER_MODES
)
906 if (mpeg_status() & MPEG_STATUS_PLAY
)
920 /* don't enter f2 from plugin browser */
921 if (*tc
.dirfilter
< NUM_FILTER_MODES
)
923 if (quick_screen(CONTEXT_TREE
, BUTTON_F2
))
927 id3db
= check_changed_id3mode(id3db
);
932 /* don't enter f3 from plugin browser */
933 if (*tc
.dirfilter
< NUM_FILTER_MODES
)
935 if (quick_screen(CONTEXT_TREE
, BUTTON_F3
))
937 tree_max_on_screen
= recalc_screen_height();
951 onplay_result
= onplay(NULL
, 0);
954 snprintf(buf
, sizeof buf
, "%s/%s",
955 currdir
, dircache
[tc
.dircursor
+tc
.dirstart
].name
);
957 snprintf(buf
, sizeof buf
, "/%s",
958 dircache
[tc
.dircursor
+tc
.dirstart
].name
);
959 onplay_result
= onplay(buf
,
960 dircache
[tc
.dircursor
+tc
.dirstart
].attr
);
963 switch (onplay_result
)
969 case ONPLAY_RELOAD_DIR
:
973 case ONPLAY_START_PLAY
:
981 if (thumbnail_time
!= -1 &&
982 TIME_AFTER(current_tick
, thumbnail_time
))
983 { /* a delayed hovering thumbnail is due now */
985 if (dircache
[lasti
].attr
& ATTR_DIRECTORY
)
987 DEBUGF("Playing directory thumbnail: %s", currdir
);
988 res
= ft_play_dirname(lasti
);
989 if (res
< 0) /* failed, not existing */
990 { /* say the number instead, as a fallback */
991 talk_id(VOICE_DIR
, false);
992 talk_number(lasti
+1, true);
997 DEBUGF("Playing file thumbnail: %s/%s%s\n",
998 currdir
, dircache
[lasti
].name
, file_thumbnail_ext
);
999 /* no fallback necessary, we knew in advance
1000 that the file exists */
1001 ft_play_filename(currdir
, dircache
[lasti
].name
);
1003 thumbnail_time
= -1; /* job done */
1009 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
1011 if(*tc
.dirfilter
> NUM_FILTER_MODES
)
1012 /* leave sub-browsers after usb, doing otherwise
1013 might be confusing to the user */
1024 lastbutton
= button
;
1030 if (wps_show() == SYS_USB_CONNECTED
)
1032 #ifdef HAVE_LCD_BITMAP
1033 tree_max_on_screen
= recalc_screen_height();
1039 /* do we need to rescan dir? */
1040 if (reload_dir
|| reload_root
||
1041 lastfilter
!= *tc
.dirfilter
||
1042 lastsortcase
!= global_settings
.sort_case
)
1044 if ( reload_root
) {
1045 strcpy(currdir
, "/");
1047 reload_root
= false;
1056 lastfilter
= *tc
.dirfilter
;
1057 lastsortcase
= global_settings
.sort_case
;
1059 while (button_get(false)); /* clear button queue */
1065 if (restore
|| reload_dir
) {
1066 /* restore display */
1068 #ifdef HAVE_LCD_BITMAP
1069 tree_max_on_screen
= recalc_screen_height();
1072 /* We need to adjust if the number of lines on screen have
1073 changed because of a status bar change */
1074 if(CURSOR_Y
+LINE_Y
+tc
.dircursor
>tree_max_on_screen
) {
1078 #ifdef HAVE_LCD_BITMAP
1079 /* the sub-screen might've ruined the margins */
1080 lcd_setmargins(MARGIN_X
,MARGIN_Y
); /* leave room for cursor and
1082 lcd_setfont(FONT_UI
);
1084 numentries
= showdir();
1086 put_cursorxy(CURSOR_X
, CURSOR_Y
+ tc
.dircursor
, true);
1092 if ( numentries
&& need_update
) {
1093 i
= tc
.dirstart
+tc
.dircursor
;
1095 /* if MP3 filter is on, cut off the extension */
1096 if(lasti
!=i
|| restore
) {
1101 name
= ((char**)tc
.dircache
)[lasti
* 2];
1103 struct entry
* dc
= tc
.dircache
;
1104 struct entry
* e
= &dc
[lasti
];
1111 /* So if lastdircursor and dircursor differ, and then full
1112 screen was not refreshed, restore the previous line */
1113 if ((lastdircursor
!= tc
.dircursor
) && !update_all
) {
1114 showfileline(lastdircursor
, name
, attr
, false); /* no scroll */
1117 lastdircursor
=tc
.dircursor
;
1118 thumbnail_time
= -1; /* cancel whatever we were about to say */
1121 name
= ((char**)tc
.dircache
)[lasti
* 2];
1123 struct entry
* dc
= tc
.dircache
;
1124 struct entry
* e
= &dc
[lasti
];
1128 showfileline(tc
.dircursor
, name
, attr
, true); /* scroll please */
1131 if (dircache
[i
].attr
& ATTR_DIRECTORY
) /* directory? */
1133 /* play directory thumbnail */
1134 switch (global_settings
.talk_dir
) {
1135 case 1: /* dirs as numbers */
1136 talk_id(VOICE_DIR
, false);
1137 talk_number(i
+1, true);
1140 case 2: /* dirs spelled */
1141 talk_spell(dircache
[i
].name
, false);
1144 case 3: /* thumbnail clip */
1145 /* "schedule" a thumbnail, to have a little dalay */
1146 thumbnail_time
= current_tick
+ HOVER_DELAY
;
1155 switch (global_settings
.talk_file
) {
1156 case 1: /* files as numbers */
1157 ft_play_filenumber(i
-tc
.dirsindir
+1,
1158 dircache
[i
].attr
& TREE_ATTR_MASK
);
1161 case 2: /* files spelled */
1162 talk_spell(dircache
[i
].name
, false);
1165 case 3: /* thumbnail clip */
1166 /* "schedule" a thumbnail, to have a little delay */
1167 if (dircache
[i
].attr
& TREE_ATTR_THUMBNAIL
)
1168 thumbnail_time
= current_tick
+ HOVER_DELAY
;
1170 /* spell the number as fallback */
1171 talk_spell(dircache
[i
].name
, false);
1184 need_update
= false;
1192 static int plsize
= 0;
1193 static bool add_dir(char* dirname
, int len
, int fd
)
1198 /* check for user abort */
1200 if (button_get(false) == BUTTON_STOP
)
1202 if (button_get(false) == BUTTON_OFF
)
1206 dir
= opendir(dirname
);
1211 struct dirent
*entry
;
1213 entry
= readdir(dir
);
1216 if (entry
->attribute
& ATTR_DIRECTORY
) {
1217 int dirlen
= strlen(dirname
);
1220 if (!strcmp(entry
->d_name
, ".") ||
1221 !strcmp(entry
->d_name
, ".."))
1225 snprintf(dirname
+dirlen
, len
-dirlen
, "/%s", entry
->d_name
);
1227 snprintf(dirname
, len
, "/%s", entry
->d_name
);
1229 result
= add_dir(dirname
, len
, fd
);
1230 dirname
[dirlen
] = '\0';
1237 int x
= strlen(entry
->d_name
);
1238 if ((!strcasecmp(&entry
->d_name
[x
-4], ".mp3")) ||
1239 (!strcasecmp(&entry
->d_name
[x
-4], ".mp2")) ||
1240 (!strcasecmp(&entry
->d_name
[x
-4], ".mpa")))
1243 write(fd
, dirname
, strlen(dirname
));
1245 write(fd
, entry
->d_name
, x
);
1249 snprintf(buf
, sizeof buf
, "%d", plsize
);
1250 #ifdef HAVE_LCD_BITMAP
1275 bool create_playlist(void)
1278 char filename
[MAX_PATH
];
1280 snprintf(filename
, sizeof filename
, "%s.m3u",
1281 tc
.currdir
[1] ? tc
.currdir
: "/root");
1283 lcd_clear_display();
1284 lcd_puts(0,0,str(LANG_CREATING
));
1285 lcd_puts_scroll(0,1,filename
);
1288 fd
= creat(filename
,0);
1292 snprintf(filename
, sizeof(filename
), "%s",
1293 tc
.currdir
[1] ? tc
.currdir
: "/");
1295 add_dir(filename
, sizeof(filename
), fd
);
1302 bool rockbox_browse(const char *root
, int dirfilter
)
1305 int dircursor_save
= tc
.dircursor
;
1306 int dirstart_save
= tc
.dirstart
;
1307 int dirlevel_save
= tc
.dirlevel
;
1308 int dirpos_save
= tc
.dirpos
[0];
1309 int cursorpos_save
= tc
.cursorpos
[0];
1310 int* dirfilter_save
= tc
.dirfilter
;
1311 static char currdir_save
[MAX_PATH
];
1313 memcpy(currdir_save
, tc
.currdir
, sizeof(tc
.currdir
));
1315 memcpy(tc
.currdir
, root
, sizeof(tc
.currdir
));
1317 tc
.dirfilter
= &dirfilter
;
1321 memcpy(tc
.currdir
, currdir_save
, sizeof(tc
.currdir
));
1323 tc
.dirstart
= dirstart_save
;
1324 tc
.cursorpos
[0] = cursorpos_save
;
1325 tc
.dirlevel
= dirlevel_save
;
1326 tc
.dircursor
= dircursor_save
;
1327 tc
.dirpos
[0] = dirpos_save
;
1328 tc
.dirfilter
= dirfilter_save
;
1333 void tree_init(void)
1335 /* We copy the settings value in case it is changed by the user. We can't
1336 use it until the next reboot. */
1337 int max_files
= global_settings
.max_files_in_dir
;
1339 /* initialize tree context struct */
1340 memset(&tc
, 0, sizeof(tc
));
1341 tc
.dirfilter
= &global_settings
.dirfilter
;
1345 tc
.name_buffer_size
= AVERAGE_FILENAME_LENGTH
* max_files
;
1346 tc
.name_buffer
= buffer_alloc(tc
.name_buffer_size
);
1348 tc
.dircache_size
= max_files
* sizeof(struct entry
);
1349 tc
.dircache
= buffer_alloc(tc
.dircache_size
);
1352 void bookmark_play(char *resume_file
, int index
, int offset
, int seed
,
1356 int len
=strlen(resume_file
);
1358 if (!strcasecmp(&resume_file
[len
-4], ".m3u"))
1360 /* Playlist playback */
1362 // check that the file exists
1363 int fd
= open(resume_file
, O_RDONLY
);
1368 slash
= strrchr(resume_file
,'/');
1378 if (playlist_create(cp
, slash
+1) != -1)
1380 if (global_settings
.playlist_shuffle
)
1381 playlist_shuffle(seed
, -1);
1382 playlist_start(index
,offset
);
1389 /* Directory playback */
1391 if (playlist_create(resume_file
, NULL
) != -1)
1393 resume_directory(resume_file
);
1394 if (global_settings
.playlist_shuffle
)
1395 playlist_shuffle(seed
, -1);
1397 /* Check if the file is at the same spot in the directory,
1398 else search for it */
1399 if ((strcmp(strrchr(playlist_peek(index
) + 1,'/') + 1,
1402 for ( i
=0; i
< playlist_amount(); i
++ )
1404 if ((strcmp(strrchr(playlist_peek(i
) + 1,'/') + 1,
1408 if (i
< playlist_amount())
1413 playlist_start(index
,offset
);
1420 int ft_play_filenumber(int pos
, int attr
)
1422 /* try to find a voice ID for the extension, if known */
1424 int ext_id
= -1; /* default to none */
1425 for (j
=0; j
<sizeof(filetypes
)/sizeof(*filetypes
); j
++)
1427 if (attr
== filetypes
[j
].tree_attr
)
1429 ext_id
= filetypes
[j
].voiceclip
;
1434 talk_id(VOICE_FILE
, false);
1435 talk_number(pos
, true);
1436 talk_id(ext_id
, true);
1440 int ft_play_dirname(int start_index
)
1443 char dirname_mp3_filename
[MAX_PATH
+1];
1444 struct entry
*dircache
= tc
.dircache
;
1446 if (mpeg_status() & MPEG_STATUS_PLAY
)
1449 snprintf(dirname_mp3_filename
, sizeof(dirname_mp3_filename
), "%s/%s/%s",
1450 tc
.currdir
, dircache
[start_index
].name
, dir_thumbnail_name
);
1452 DEBUGF("Checking for %s\n", dirname_mp3_filename
);
1454 fd
= open(dirname_mp3_filename
, O_RDONLY
);
1457 DEBUGF("Failed to find: %s\n", dirname_mp3_filename
);
1463 DEBUGF("Found: %s\n", dirname_mp3_filename
);
1465 talk_file(dirname_mp3_filename
, false);
1469 void ft_play_filename(char *dir
, char *file
)
1471 char name_mp3_filename
[MAX_PATH
+1];
1473 if (mpeg_status() & MPEG_STATUS_PLAY
)
1476 if (strcasecmp(&file
[strlen(file
) - strlen(file_thumbnail_ext
)],
1477 file_thumbnail_ext
))
1478 { /* file has no .talk extension */
1479 snprintf(name_mp3_filename
, sizeof(name_mp3_filename
),
1480 "%s/%s%s", dir
, file
, file_thumbnail_ext
);
1482 talk_file(name_mp3_filename
, false);
1485 { /* it already is a .talk file, play this directly */
1486 snprintf(name_mp3_filename
, sizeof(name_mp3_filename
),
1487 "%s/%s", dir
, file
);
1488 talk_id(LANG_VOICE_DIR_HOVER
, false); /* prefix it */
1489 talk_file(name_mp3_filename
, true);