1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2007 Jonathan Gordon
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 ****************************************************************************/
25 #include "root_menu.h"
33 #include "powermgmt.h"
38 #if (LCD_DEPTH > 1) || (defined(HAVE_LCD_REMOTE) && (LCD_REMOTE_DEPTH > 1))
45 #include "statusbar.h"
47 #include "buttonbar.h"
52 #include "main_menu.h"
58 #include "recording.h"
60 #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 int browser(void* param
)
83 struct tree_context
* tc
= tree_get_context();
85 int filter
= SHOW_SUPPORTED
;
86 char folder
[MAX_PATH
] = "/";
87 /* stuff needed to remember position in file browser */
88 static char last_folder
[MAX_PATH
] = "/";
89 /* and stuff for the database browser */
91 static int last_db_dirlevel
= 0, last_db_selection
= 0;
94 switch ((intptr_t)param
)
96 case GO_TO_FILEBROWSER
:
97 filter
= global_settings
.dirfilter
;
98 if (global_settings
.browse_current
&&
99 last_screen
== GO_TO_WPS
&& audio_status() &&
100 wps_state
.current_track_path
[0] != '\0')
102 strcpy(folder
, wps_state
.current_track_path
);
105 strcpy(folder
, last_folder
);
108 case GO_TO_DBBROWSER
:
109 if (!tagcache_is_usable())
111 bool reinit_attempted
= false;
113 /* Now display progress until it's ready or the user exits */
114 while(!tagcache_is_usable())
116 gui_syncstatusbar_draw(&statusbars
, false);
117 struct tagcache_stat
*stat
= tagcache_get_stat();
119 /* Allow user to exit */
120 if (action_userabort(HZ
/2))
123 /* Maybe just needs to reboot due to delayed commit */
124 if (stat
->commit_delayed
)
126 gui_syncsplash(HZ
*2, str(LANG_PLEASE_REBOOT
));
130 /* Check if ready status is known */
131 if (!stat
->readyvalid
)
133 gui_syncsplash(0, str(LANG_TAGCACHE_BUSY
));
137 /* Re-init if required */
138 if (!reinit_attempted
&& !stat
->ready
&&
139 stat
->processed_entries
== 0 && stat
->commit_step
== 0)
141 /* Prompt the user */
142 reinit_attempted
= true;
143 char *lines
[]={str(LANG_TAGCACHE_BUSY
), str(LANG_TAGCACHE_FORCE_UPDATE
)};
144 struct text_message message
={lines
, 2};
145 if(gui_syncyesno_run(&message
, NULL
, NULL
) == YESNO_NO
)
149 screens
[i
].clear_display();
151 /* Start initialisation */
155 /* Display building progress */
156 if (stat
->commit_step
> 0)
158 gui_syncsplash(0, "%s [%d/%d]",
159 str(LANG_TAGCACHE_INIT
), stat
->commit_step
,
160 tagcache_get_max_commit_step());
164 gui_syncsplash(0, str(LANG_BUILDING_DATABASE
),
165 stat
->processed_entries
);
169 if (!tagcache_is_usable())
170 return GO_TO_PREVIOUS
;
172 tc
->dirlevel
= last_db_dirlevel
;
173 tc
->selected_item
= last_db_selection
;
176 case GO_TO_BROWSEPLUGINS
:
177 filter
= SHOW_PLUGINS
;
178 snprintf(folder
, MAX_PATH
, "%s/", PLUGIN_DIR
);
181 ret_val
= rockbox_browse(folder
, filter
);
182 switch ((intptr_t)param
)
184 case GO_TO_FILEBROWSER
:
185 get_current_file(last_folder
, MAX_PATH
);
188 case GO_TO_DBBROWSER
:
189 last_db_dirlevel
= tc
->dirlevel
;
190 last_db_selection
= tc
->selected_item
;
197 static int menu(void* param
)
200 return do_menu(NULL
, 0);
203 #ifdef HAVE_RECORDING
204 static int recscrn(void* param
)
207 recording_screen(false);
211 static int wpsscrn(void* param
)
213 int ret_val
= GO_TO_PREVIOUS
;
217 ret_val
= gui_wps_show();
219 else if ( global_status
.resume_index
!= -1 )
221 DEBUGF("Resume index %X offset %lX\n",
222 global_status
.resume_index
,
223 (unsigned long)global_status
.resume_offset
);
224 if (playlist_resume() != -1)
226 playlist_start(global_status
.resume_index
,
227 global_status
.resume_offset
);
228 ret_val
= gui_wps_show();
233 gui_syncsplash(HZ
*2, str(LANG_NOTHING_TO_RESUME
));
236 show_main_backdrop();
238 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
239 show_remote_main_backdrop();
244 static int radio(void* param
)
252 static int load_bmarks(void* param
)
256 return GO_TO_PREVIOUS
;
258 /* These are all static const'd from apps/menus/ *.c
259 so little hack so we can use them */
260 extern struct menu_item_ex
266 recording_setting_menu
,
267 bookmark_settings_menu
,
269 static const struct root_items items
[] = {
270 [GO_TO_FILEBROWSER
] = { browser
, (void*)GO_TO_FILEBROWSER
, &file_menu
},
272 [GO_TO_DBBROWSER
] = { browser
, (void*)GO_TO_DBBROWSER
, &tagcache_menu
},
274 [GO_TO_WPS
] = { wpsscrn
, NULL
, &playback_menu_item
},
275 [GO_TO_MAINMENU
] = { menu
, NULL
, &manage_settings
},
277 #ifdef HAVE_RECORDING
278 [GO_TO_RECSCREEN
] = { recscrn
, NULL
, &recording_setting_menu
},
282 [GO_TO_FM
] = { radio
, NULL
, NULL
},
285 [GO_TO_RECENTBMARKS
] = { load_bmarks
, NULL
, &bookmark_settings_menu
},
286 [GO_TO_BROWSEPLUGINS
] = { browser
, (void*)GO_TO_BROWSEPLUGINS
, NULL
},
289 static const int nb_items
= sizeof(items
)/sizeof(*items
);
291 int item_callback(int action
, const struct menu_item_ex
*this_item
) ;
293 MENUITEM_RETURNVALUE(file_browser
, ID2P(LANG_DIR_BROWSER
), GO_TO_FILEBROWSER
,
294 NULL
, Icon_file_view_menu
);
296 MENUITEM_RETURNVALUE(db_browser
, ID2P(LANG_TAGCACHE
), GO_TO_DBBROWSER
,
299 MENUITEM_RETURNVALUE(rocks_browser
, ID2P(LANG_PLUGINS
), GO_TO_BROWSEPLUGINS
,
301 char *get_wps_item_name(int selected_item
, void * data
, char *buffer
)
303 (void)selected_item
; (void)data
; (void)buffer
;
305 return ID2P(LANG_NOW_PLAYING
);
306 return ID2P(LANG_RESUME_PLAYBACK
);
308 MENUITEM_RETURNVALUE_DYNTEXT(wps_item
, GO_TO_WPS
, NULL
, get_wps_item_name
,
309 NULL
, Icon_Playback_menu
);
310 #ifdef HAVE_RECORDING
311 MENUITEM_RETURNVALUE(rec
, ID2P(LANG_RECORDING_MENU
), GO_TO_RECSCREEN
,
312 NULL
, Icon_Recording
);
315 MENUITEM_RETURNVALUE(fm
, ID2P(LANG_FM_RADIO
), GO_TO_FM
,
316 item_callback
, Icon_Radio_screen
);
318 MENUITEM_RETURNVALUE(menu_
, ID2P(LANG_SETTINGS_MENU
), GO_TO_MAINMENU
,
319 NULL
, Icon_Submenu_Entered
);
320 MENUITEM_RETURNVALUE(bookmarks
, ID2P(LANG_BOOKMARK_MENU_RECENT_BOOKMARKS
),
321 GO_TO_RECENTBMARKS
, item_callback
,
323 #ifdef HAVE_LCD_CHARCELLS
324 static int do_shutdown(void)
327 if (charger_inserted())
334 MENUITEM_FUNCTION(do_shutdown_item
, 0, ID2P(LANG_SHUTDOWN
),
335 do_shutdown
, NULL
, NULL
, Icon_NOICON
);
337 MAKE_MENU(root_menu_
, ID2P(LANG_ROCKBOX_TITLE
),
339 &bookmarks
, &file_browser
,
344 #ifdef HAVE_RECORDING
350 &playlist_options
, &rocks_browser
, &info_menu
352 #ifdef HAVE_LCD_CHARCELLS
357 int item_callback(int action
, const struct menu_item_ex
*this_item
)
361 case ACTION_REQUEST_MENUITEM
:
363 if (this_item
== &fm
)
365 if (radio_hardware_present() == 0)
366 return ACTION_EXIT_MENUITEM
;
370 if (this_item
== &bookmarks
)
372 if (global_settings
.usemrb
== 0)
373 return ACTION_EXIT_MENUITEM
;
379 static int get_selection(int last_screen
)
382 for(i
=0; i
< sizeof(root_menu__
)/sizeof(*root_menu__
); i
++)
384 if (((root_menu__
[i
]->flags
&MENU_TYPE_MASK
) == MT_RETURN_VALUE
) &&
385 (root_menu__
[i
]->value
== last_screen
))
393 static inline int load_screen(int screen
)
395 /* set the global_status.last_screen before entering,
396 if we dont we will always return to the wrong screen on boot */
397 int old_previous
= last_screen
;
399 if (screen
<= GO_TO_ROOT
)
401 if (screen
== old_previous
)
402 old_previous
= GO_TO_ROOT
;
403 global_status
.last_screen
= (char)screen
;
405 action_signalscreenchange();
406 ret_val
= items
[screen
].function(items
[screen
].param
);
407 last_screen
= screen
;
408 if (ret_val
== GO_TO_PREVIOUS
)
409 last_screen
= old_previous
;
412 static int load_context_screen(int selection
)
414 const struct menu_item_ex
*context_menu
= NULL
;
415 if ((root_menu__
[selection
]->flags
&MENU_TYPE_MASK
) == MT_RETURN_VALUE
)
417 int item
= root_menu__
[selection
]->value
;
418 context_menu
= items
[item
].context_menu
;
421 else if (root_menu__
[selection
] == &info_menu
)
423 context_menu
= &system_menu
;
427 return do_menu(context_menu
, NULL
);
429 return GO_TO_PREVIOUS
;
433 int previous_browser
= GO_TO_FILEBROWSER
;
434 int previous_music
= GO_TO_WPS
;
435 int next_screen
= GO_TO_ROOT
;
438 if (global_settings
.start_in_screen
== 0)
439 next_screen
= (int)global_status
.last_screen
;
440 else next_screen
= global_settings
.start_in_screen
- 2;
442 #ifdef HAVE_RTC_ALARM
443 if ( rtc_check_alarm_started(true) )
445 rtc_enable_alarm(false);
446 next_screen
= GO_TO_WPS
;
448 if (global_settings
.alarm_wake_up_screen
== ALARM_START_FM
)
449 next_screen
= GO_TO_FM
;
451 #ifdef HAVE_RECORDING
452 if (global_settings
.alarm_wake_up_screen
== ALARM_START_REC
)
454 recording_start_automatic
= true;
455 next_screen
= GO_TO_RECSCREEN
;
459 #endif /* HAVE_RTC_ALARM */
461 #ifdef HAVE_HEADPHONE_DETECTION
462 if (next_screen
== GO_TO_WPS
&&
463 (global_settings
.unplug_autoresume
&& !headphones_inserted() ))
464 next_screen
= GO_TO_ROOT
;
471 case MENU_ATTACHED_USB
:
472 case MENU_SELECTED_EXIT
:
475 if (last_screen
!= GO_TO_ROOT
)
476 selected
= get_selection(last_screen
);
477 next_screen
= do_menu(&root_menu_
, &selected
);
478 if (next_screen
!= GO_TO_PREVIOUS
)
479 last_screen
= GO_TO_ROOT
;
483 next_screen
= last_screen
;
486 case GO_TO_PREVIOUS_BROWSER
:
487 next_screen
= previous_browser
;
490 case GO_TO_PREVIOUS_MUSIC
:
491 next_screen
= previous_music
;
493 case GO_TO_ROOTITEM_CONTEXT
:
494 next_screen
= load_context_screen(selected
);
497 if (next_screen
== GO_TO_FILEBROWSER
499 || next_screen
== GO_TO_DBBROWSER
502 previous_browser
= next_screen
;
503 if (next_screen
== GO_TO_WPS
505 || next_screen
== GO_TO_FM
508 previous_music
= next_screen
;
509 next_screen
= load_screen(next_screen
);