1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2007 Jonathan Gordon
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
26 #include "appevents.h"
28 #include "root_menu.h"
36 #include "powermgmt.h"
45 #include "statusbar.h"
47 #include "buttonbar.h"
57 #include "recording.h"
59 #include "gwps-common.h"
63 #include "menus/exported_menus.h"
72 int (*function
)(void* param
);
74 const struct menu_item_ex
*context_menu
;
76 static int last_screen
= GO_TO_ROOT
; /* unfortunatly needed so we can resume
77 or goto current track based on previous
79 static char current_track_path
[MAX_PATH
];
80 static void rootmenu_track_changed_callback(void* param
)
82 struct mp3entry
*id3
= (struct mp3entry
*)param
;
83 strncpy(current_track_path
, id3
->path
, MAX_PATH
);
85 static int browser(void* param
)
89 struct tree_context
* tc
= tree_get_context();
91 int filter
= SHOW_SUPPORTED
;
92 char folder
[MAX_PATH
] = "/";
93 /* stuff needed to remember position in file browser */
94 static char last_folder
[MAX_PATH
] = "/";
95 /* and stuff for the database browser */
97 static int last_db_dirlevel
= 0, last_db_selection
= 0;
100 switch ((intptr_t)param
)
102 case GO_TO_FILEBROWSER
:
103 filter
= global_settings
.dirfilter
;
104 if (global_settings
.browse_current
&&
105 last_screen
== GO_TO_WPS
&&
106 current_track_path
[0])
108 strcpy(folder
, current_track_path
);
110 #ifdef HAVE_HOTSWAP /* quick hack to stop crashing if you try entering
111 the browser from the menu when you were in the card
112 and it was removed */
113 else if (strchr(last_folder
, '<') && (card_detect() == false))
117 strcpy(folder
, last_folder
);
120 case GO_TO_DBBROWSER
:
121 if (!tagcache_is_usable())
123 bool reinit_attempted
= false;
125 /* Now display progress until it's ready or the user exits */
126 while(!tagcache_is_usable())
128 struct tagcache_stat
*stat
= tagcache_get_stat();
130 /* Allow user to exit */
131 if (action_userabort(HZ
/2))
134 /* Maybe just needs to reboot due to delayed commit */
135 if (stat
->commit_delayed
)
137 splash(HZ
*2, ID2P(LANG_PLEASE_REBOOT
));
141 /* Check if ready status is known */
142 if (!stat
->readyvalid
)
144 splash(0, str(LANG_TAGCACHE_BUSY
));
148 /* Re-init if required */
149 if (!reinit_attempted
&& !stat
->ready
&&
150 stat
->processed_entries
== 0 && stat
->commit_step
== 0)
152 /* Prompt the user */
153 reinit_attempted
= true;
154 static const char *lines
[]={
155 ID2P(LANG_TAGCACHE_BUSY
), ID2P(LANG_TAGCACHE_FORCE_UPDATE
)};
156 static const struct text_message message
={lines
, 2};
157 if(gui_syncyesno_run(&message
, NULL
, NULL
) == YESNO_NO
)
161 screens
[i
].clear_display();
163 /* Start initialisation */
167 /* Display building progress */
168 static long talked_tick
= 0;
169 if(global_settings
.talk_menu
&&
171 || TIME_AFTER(current_tick
, talked_tick
+7*HZ
)))
173 talked_tick
= current_tick
;
174 if (stat
->commit_step
> 0)
176 talk_id(LANG_TAGCACHE_INIT
, false);
177 talk_number(stat
->commit_step
, true);
178 talk_id(VOICE_OF
, true);
179 talk_number(tagcache_get_max_commit_step(), true);
180 } else if(stat
->processed_entries
)
182 talk_number(stat
->processed_entries
, false);
183 talk_id(LANG_BUILDING_DATABASE
, true);
186 if (stat
->commit_step
> 0)
188 splashf(0, "%s [%d/%d]",
189 str(LANG_TAGCACHE_INIT
), stat
->commit_step
,
190 tagcache_get_max_commit_step());
194 splashf(0, str(LANG_BUILDING_DATABASE
),
195 stat
->processed_entries
);
199 if (!tagcache_is_usable())
200 return GO_TO_PREVIOUS
;
202 tc
->dirlevel
= last_db_dirlevel
;
203 tc
->selected_item
= last_db_selection
;
206 case GO_TO_BROWSEPLUGINS
:
207 filter
= SHOW_PLUGINS
;
208 strncpy(folder
, PLUGIN_DIR
, MAX_PATH
);
211 ret_val
= rockbox_browse(folder
, filter
);
212 switch ((intptr_t)param
)
214 case GO_TO_FILEBROWSER
:
215 get_current_file(last_folder
, MAX_PATH
);
218 case GO_TO_DBBROWSER
:
219 last_db_dirlevel
= tc
->dirlevel
;
220 last_db_selection
= tc
->selected_item
;
227 static int menu(void* param
)
230 return do_menu(NULL
, 0, NULL
, false);
233 #ifdef HAVE_RECORDING
234 static int recscrn(void* param
)
237 recording_screen(false);
241 static int wpsscrn(void* param
)
243 int ret_val
= GO_TO_PREVIOUS
;
248 ret_val
= gui_wps_show();
250 else if ( global_status
.resume_index
!= -1 )
252 DEBUGF("Resume index %X offset %lX\n",
253 global_status
.resume_index
,
254 (unsigned long)global_status
.resume_offset
);
255 if (playlist_resume() != -1)
257 playlist_start(global_status
.resume_index
,
258 global_status
.resume_offset
);
259 ret_val
= gui_wps_show();
264 splash(HZ
*2, ID2P(LANG_NOTHING_TO_RESUME
));
267 show_main_backdrop();
269 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
270 show_remote_main_backdrop();
272 /* always re-enable the statusbar after the WPS */
273 viewportmanager_set_statusbar(VP_SB_ALLSCREENS
);
277 static int radio(void* param
)
285 static int load_bmarks(void* param
)
288 if(bookmark_mrb_load())
290 return GO_TO_PREVIOUS
;
292 static int plugins_menu(void* param
)
295 MENUITEM_STRINGLIST(plugins_menu_items
, ID2P(LANG_PLUGINS
), NULL
,
296 ID2P(LANG_PLUGIN_GAMES
),
297 ID2P(LANG_PLUGIN_APPS
), ID2P(LANG_PLUGIN_DEMOS
));
299 int retval
= GO_TO_PREVIOUS
;
300 int selection
= 0, current
= 0;
301 while (retval
== GO_TO_PREVIOUS
)
303 selection
= do_menu(&plugins_menu_items
, ¤t
, NULL
, false);
307 folder
= PLUGIN_GAMES_DIR
;
310 folder
= PLUGIN_APPS_DIR
;
313 folder
= PLUGIN_DEMOS_DIR
;
318 retval
= rockbox_browse(folder
, SHOW_PLUGINS
);
322 int time_screen(void* ignored
);
324 /* These are all static const'd from apps/menus/ *.c
325 so little hack so we can use them */
326 extern struct menu_item_ex
332 recording_settings_menu
,
334 bookmark_settings_menu
,
336 static const struct root_items items
[] = {
337 [GO_TO_FILEBROWSER
] = { browser
, (void*)GO_TO_FILEBROWSER
, &file_menu
},
339 [GO_TO_DBBROWSER
] = { browser
, (void*)GO_TO_DBBROWSER
, &tagcache_menu
},
341 [GO_TO_WPS
] = { wpsscrn
, NULL
, &playback_settings
},
342 [GO_TO_MAINMENU
] = { menu
, NULL
, &manage_settings
},
344 #ifdef HAVE_RECORDING
345 [GO_TO_RECSCREEN
] = { recscrn
, NULL
, &recording_settings_menu
},
349 [GO_TO_FM
] = { radio
, NULL
, &radio_settings_menu
},
352 [GO_TO_RECENTBMARKS
] = { load_bmarks
, NULL
, &bookmark_settings_menu
},
353 [GO_TO_BROWSEPLUGINS
] = { plugins_menu
, NULL
, NULL
},
356 static const int nb_items
= sizeof(items
)/sizeof(*items
);
358 static int item_callback(int action
, const struct menu_item_ex
*this_item
) ;
360 MENUITEM_RETURNVALUE(file_browser
, ID2P(LANG_DIR_BROWSER
), GO_TO_FILEBROWSER
,
361 NULL
, Icon_file_view_menu
);
363 MENUITEM_RETURNVALUE(db_browser
, ID2P(LANG_TAGCACHE
), GO_TO_DBBROWSER
,
366 MENUITEM_RETURNVALUE(rocks_browser
, ID2P(LANG_PLUGINS
), GO_TO_BROWSEPLUGINS
,
368 static char *get_wps_item_name(int selected_item
, void * data
, char *buffer
)
370 (void)selected_item
; (void)data
; (void)buffer
;
372 return ID2P(LANG_NOW_PLAYING
);
373 return ID2P(LANG_RESUME_PLAYBACK
);
375 MENUITEM_RETURNVALUE_DYNTEXT(wps_item
, GO_TO_WPS
, NULL
, get_wps_item_name
,
376 NULL
, NULL
, Icon_Playback_menu
);
377 #ifdef HAVE_RECORDING
378 MENUITEM_RETURNVALUE(rec
, ID2P(LANG_RECORDING
), GO_TO_RECSCREEN
,
379 NULL
, Icon_Recording
);
382 MENUITEM_RETURNVALUE(fm
, ID2P(LANG_FM_RADIO
), GO_TO_FM
,
383 item_callback
, Icon_Radio_screen
);
385 MENUITEM_RETURNVALUE(menu_
, ID2P(LANG_SETTINGS
), GO_TO_MAINMENU
,
386 NULL
, Icon_Submenu_Entered
);
387 MENUITEM_RETURNVALUE(bookmarks
, ID2P(LANG_BOOKMARK_MENU_RECENT_BOOKMARKS
),
388 GO_TO_RECENTBMARKS
, item_callback
,
390 #ifdef HAVE_LCD_CHARCELLS
391 static int do_shutdown(void)
394 if (charger_inserted())
401 MENUITEM_FUNCTION(do_shutdown_item
, 0, ID2P(LANG_SHUTDOWN
),
402 do_shutdown
, NULL
, NULL
, Icon_NOICON
);
404 MAKE_MENU(root_menu_
, ID2P(LANG_ROCKBOX_TITLE
),
405 item_callback
, Icon_Rockbox
,
406 &bookmarks
, &file_browser
,
411 #ifdef HAVE_RECORDING
417 &playlist_options
, &rocks_browser
, &info_menu
419 #ifdef HAVE_LCD_CHARCELLS
424 static int item_callback(int action
, const struct menu_item_ex
*this_item
)
428 case ACTION_TREE_STOP
:
429 return ACTION_REDRAW
;
430 case ACTION_REQUEST_MENUITEM
:
432 if (this_item
== &fm
)
434 if (radio_hardware_present() == 0)
435 return ACTION_EXIT_MENUITEM
;
439 if (this_item
== &bookmarks
)
441 if (global_settings
.usemrb
== 0)
442 return ACTION_EXIT_MENUITEM
;
448 static int get_selection(int last_screen
)
451 for(i
=0; i
< sizeof(root_menu__
)/sizeof(*root_menu__
); i
++)
453 if (((root_menu__
[i
]->flags
&MENU_TYPE_MASK
) == MT_RETURN_VALUE
) &&
454 (root_menu__
[i
]->value
== last_screen
))
462 static inline int load_screen(int screen
)
464 /* set the global_status.last_screen before entering,
465 if we dont we will always return to the wrong screen on boot */
466 int old_previous
= last_screen
;
468 if (screen
<= GO_TO_ROOT
)
470 if (screen
== old_previous
)
471 old_previous
= GO_TO_ROOT
;
472 global_status
.last_screen
= (char)screen
;
474 ret_val
= items
[screen
].function(items
[screen
].param
);
475 last_screen
= screen
;
476 if (ret_val
== GO_TO_PREVIOUS
)
477 last_screen
= old_previous
;
480 static int load_context_screen(int selection
)
482 const struct menu_item_ex
*context_menu
= NULL
;
483 if ((root_menu__
[selection
]->flags
&MENU_TYPE_MASK
) == MT_RETURN_VALUE
)
485 int item
= root_menu__
[selection
]->value
;
486 context_menu
= items
[item
].context_menu
;
489 else if (root_menu__
[selection
] == &info_menu
)
491 context_menu
= &system_menu
;
495 return do_menu(context_menu
, NULL
, NULL
, false);
497 return GO_TO_PREVIOUS
;
500 static int previous_music
= GO_TO_WPS
;
502 void previous_music_is_wps(void)
504 previous_music
= GO_TO_WPS
;
509 int previous_browser
= GO_TO_FILEBROWSER
;
510 int next_screen
= GO_TO_ROOT
;
513 if (global_settings
.start_in_screen
== 0)
514 next_screen
= (int)global_status
.last_screen
;
515 else next_screen
= global_settings
.start_in_screen
- 2;
516 add_event(PLAYBACK_EVENT_TRACK_CHANGE
, false, rootmenu_track_changed_callback
);
517 #ifdef HAVE_RTC_ALARM
518 if ( rtc_check_alarm_started(true) )
520 rtc_enable_alarm(false);
521 next_screen
= GO_TO_WPS
;
523 if (global_settings
.alarm_wake_up_screen
== ALARM_START_FM
)
524 next_screen
= GO_TO_FM
;
526 #ifdef HAVE_RECORDING
527 if (global_settings
.alarm_wake_up_screen
== ALARM_START_REC
)
529 recording_start_automatic
= true;
530 next_screen
= GO_TO_RECSCREEN
;
534 #endif /* HAVE_RTC_ALARM */
536 #ifdef HAVE_HEADPHONE_DETECTION
537 if (next_screen
== GO_TO_WPS
&&
538 (global_settings
.unplug_autoresume
&& !headphones_inserted() ))
539 next_screen
= GO_TO_ROOT
;
546 case MENU_ATTACHED_USB
:
547 case MENU_SELECTED_EXIT
:
550 if (last_screen
!= GO_TO_ROOT
)
551 selected
= get_selection(last_screen
);
552 next_screen
= do_menu(&root_menu_
, &selected
, NULL
, false);
553 if (next_screen
!= GO_TO_PREVIOUS
)
554 last_screen
= GO_TO_ROOT
;
558 next_screen
= last_screen
;
561 case GO_TO_PREVIOUS_BROWSER
:
562 next_screen
= previous_browser
;
565 case GO_TO_PREVIOUS_MUSIC
:
566 next_screen
= previous_music
;
568 case GO_TO_ROOTITEM_CONTEXT
:
569 next_screen
= load_context_screen(selected
);
572 if (next_screen
== GO_TO_FILEBROWSER
574 || next_screen
== GO_TO_DBBROWSER
577 previous_browser
= next_screen
;
578 if (next_screen
== GO_TO_WPS
580 || next_screen
== GO_TO_FM
583 previous_music
= next_screen
;
584 next_screen
= load_screen(next_screen
);