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"
32 #include "powermgmt.h"
42 #include "statusbar.h"
44 #include "buttonbar.h"
49 #include "main_menu.h"
55 #include "recording.h"
57 #include "gwps-common.h"
60 #include "menus/exported_menus.h"
69 int (*function
)(void* param
);
72 static int last_screen
= GO_TO_ROOT
; /* unfortunatly needed so we can resume
73 or goto current track based on previous
75 static int browser(void* param
)
79 struct tree_context
* tc
= tree_get_context();
81 int filter
= SHOW_SUPPORTED
;
82 char folder
[MAX_PATH
] = "/";
83 /* stuff needed to remember position in file browser */
84 static char last_folder
[MAX_PATH
] = "/";
85 /* and stuff for the database browser */
87 static int last_db_dirlevel
= 0, last_db_selection
= 0;
90 switch ((intptr_t)param
)
92 case GO_TO_FILEBROWSER
:
93 filter
= global_settings
.dirfilter
;
94 if (global_settings
.browse_current
&&
95 last_screen
== GO_TO_WPS
&& audio_status() &&
96 wps_state
.current_track_path
[0] != '\0')
98 strcpy(folder
, wps_state
.current_track_path
);
101 strcpy(folder
, last_folder
);
104 case GO_TO_DBBROWSER
:
105 if (!tagcache_is_usable())
107 bool reinit_attempted
= false;
109 /* Now display progress until it's ready or the user exits */
110 while(!tagcache_is_usable())
112 gui_syncstatusbar_draw(&statusbars
, false);
113 struct tagcache_stat
*stat
= tagcache_get_stat();
115 /* Allow user to exit */
116 if (action_userabort(HZ
/2))
119 /* Maybe just needs to reboot due to delayed commit */
120 if (stat
->commit_delayed
)
122 gui_syncsplash(HZ
*2, str(LANG_PLEASE_REBOOT
));
126 /* Check if ready status is known */
127 if (!stat
->readyvalid
)
129 gui_syncsplash(0, str(LANG_TAGCACHE_BUSY
));
133 /* Re-init if required */
134 if (!reinit_attempted
&& !stat
->ready
&&
135 stat
->processed_entries
== 0 && stat
->commit_step
== 0)
137 /* Prompt the user */
138 reinit_attempted
= true;
139 char *lines
[]={str(LANG_TAGCACHE_BUSY
), str(LANG_TAGCACHE_FORCE_UPDATE
)};
140 struct text_message message
={lines
, 2};
141 if(gui_syncyesno_run(&message
, NULL
, NULL
) == YESNO_NO
)
145 screens
[i
].clear_display();
147 /* Start initialisation */
151 /* Display building progress */
152 if (stat
->commit_step
> 0)
154 gui_syncsplash(0, "%s [%d/%d]",
155 str(LANG_TAGCACHE_INIT
), stat
->commit_step
,
156 tagcache_get_max_commit_step());
160 gui_syncsplash(0, str(LANG_BUILDING_DATABASE
),
161 stat
->processed_entries
);
165 if (!tagcache_is_usable())
166 return GO_TO_PREVIOUS
;
168 tc
->dirlevel
= last_db_dirlevel
;
169 tc
->selected_item
= last_db_selection
;
172 case GO_TO_BROWSEPLUGINS
:
173 filter
= SHOW_PLUGINS
;
174 snprintf(folder
, MAX_PATH
, "%s/", PLUGIN_DIR
);
177 ret_val
= rockbox_browse(folder
, filter
);
178 switch ((intptr_t)param
)
180 case GO_TO_FILEBROWSER
:
181 get_current_file(last_folder
, MAX_PATH
);
184 case GO_TO_DBBROWSER
:
185 last_db_dirlevel
= tc
->dirlevel
;
186 last_db_selection
= tc
->selected_item
;
193 static int menu(void* param
)
196 return do_menu(NULL
, 0);
199 #ifdef HAVE_RECORDING
200 static int recscrn(void* param
)
203 recording_screen(false);
207 static int wpsscrn(void* param
)
209 int ret_val
= GO_TO_PREVIOUS
;
213 ret_val
= gui_wps_show();
215 else if ( global_status
.resume_index
!= -1 )
217 DEBUGF("Resume index %X offset %lX\n",
218 global_status
.resume_index
,
219 (unsigned long)global_status
.resume_offset
);
220 if (playlist_resume() != -1)
222 playlist_start(global_status
.resume_index
,
223 global_status
.resume_offset
);
224 ret_val
= gui_wps_show();
229 gui_syncsplash(HZ
*2, str(LANG_NOTHING_TO_RESUME
));
232 show_main_backdrop();
237 static int radio(void* param
)
245 static int load_bmarks(void* param
)
249 return GO_TO_PREVIOUS
;
252 static const struct root_items items
[] = {
253 [GO_TO_FILEBROWSER
] = { browser
, (void*)GO_TO_FILEBROWSER
},
254 [GO_TO_DBBROWSER
] = { browser
, (void*)GO_TO_DBBROWSER
},
255 [GO_TO_WPS
] = { wpsscrn
, NULL
},
256 [GO_TO_MAINMENU
] = { menu
, NULL
},
258 #ifdef HAVE_RECORDING
259 [GO_TO_RECSCREEN
] = { recscrn
, NULL
},
263 [GO_TO_FM
] = { radio
, NULL
},
266 [GO_TO_RECENTBMARKS
] = { load_bmarks
, NULL
},
267 [GO_TO_BROWSEPLUGINS
] = { browser
, (void*)GO_TO_BROWSEPLUGINS
},
270 static const int nb_items
= sizeof(items
)/sizeof(*items
);
272 int item_callback(int action
, const struct menu_item_ex
*this_item
) ;
274 MENUITEM_RETURNVALUE(file_browser
, ID2P(LANG_DIR_BROWSER
), GO_TO_FILEBROWSER
,
275 NULL
, Icon_file_view_menu
);
277 MENUITEM_RETURNVALUE(db_browser
, ID2P(LANG_TAGCACHE
), GO_TO_DBBROWSER
,
280 MENUITEM_RETURNVALUE(rocks_browser
, ID2P(LANG_PLUGINS
), GO_TO_BROWSEPLUGINS
,
282 char *get_wps_item_name(int selected_item
, void * data
, char *buffer
)
284 (void)selected_item
; (void)data
; (void)buffer
;
286 return ID2P(LANG_NOW_PLAYING
);
287 return ID2P(LANG_RESUME_PLAYBACK
);
289 MENUITEM_RETURNVALUE_DYNTEXT(wps_item
, GO_TO_WPS
, NULL
, get_wps_item_name
,
290 NULL
, Icon_Playback_menu
);
291 #ifdef HAVE_RECORDING
292 MENUITEM_RETURNVALUE(rec
, ID2P(LANG_RECORDING_MENU
), GO_TO_RECSCREEN
,
293 NULL
, Icon_Recording
);
296 MENUITEM_RETURNVALUE(fm
, ID2P(LANG_FM_RADIO
), GO_TO_FM
,
297 item_callback
, Icon_Radio_screen
);
299 MENUITEM_RETURNVALUE(menu_
, ID2P(LANG_SETTINGS_MENU
), GO_TO_MAINMENU
,
300 NULL
, Icon_Submenu_Entered
);
301 MENUITEM_RETURNVALUE(bookmarks
, ID2P(LANG_BOOKMARK_MENU_RECENT_BOOKMARKS
),
302 GO_TO_RECENTBMARKS
, item_callback
,
304 #ifdef HAVE_LCD_CHARCELLS
305 static int do_shutdown(void)
310 MENUITEM_FUNCTION(do_shutdown_item
, 0, ID2P(LANG_SHUTDOWN
),
311 do_shutdown
, NULL
, NULL
, Icon_NOICON
);
313 MAKE_MENU(root_menu_
, ID2P(LANG_ROCKBOX_TITLE
),
315 &bookmarks
, &file_browser
,
320 #ifdef HAVE_RECORDING
326 &playlist_options
, &rocks_browser
, &info_menu
328 #ifdef HAVE_LCD_CHARCELLS
333 int item_callback(int action
, const struct menu_item_ex
*this_item
)
337 case ACTION_REQUEST_MENUITEM
:
339 if (this_item
== &fm
)
341 if (radio_hardware_present() == 0)
342 return ACTION_EXIT_MENUITEM
;
346 if (this_item
== &bookmarks
)
348 if (global_settings
.usemrb
== 0)
349 return ACTION_EXIT_MENUITEM
;
355 static int get_selection(int last_screen
)
358 for(i
=0; i
< sizeof(root_menu__
)/sizeof(*root_menu__
); i
++)
360 if ((root_menu__
[i
]->flags
&MT_RETURN_VALUE
) &&
361 (root_menu__
[i
]->value
== last_screen
))
369 static inline int load_screen(int screen
)
371 /* set the global_status.last_screen before entering,
372 if we dont we will always return to the wrong screen on boot */
373 int old_previous
= last_screen
;
375 if (screen
<= GO_TO_ROOT
)
377 if (screen
== old_previous
)
378 old_previous
= GO_TO_ROOT
;
379 global_status
.last_screen
= (char)screen
;
381 action_signalscreenchange();
382 ret_val
= items
[screen
].function(items
[screen
].param
);
383 last_screen
= screen
;
384 if (ret_val
== GO_TO_PREVIOUS
)
385 last_screen
= old_previous
;
391 int previous_browser
= GO_TO_FILEBROWSER
;
392 int previous_music
= GO_TO_WPS
;
393 int next_screen
= GO_TO_ROOT
;
396 if (global_settings
.start_in_screen
== 0)
397 next_screen
= (int)global_status
.last_screen
;
398 else next_screen
= global_settings
.start_in_screen
- 2;
400 #ifdef HAVE_RTC_ALARM
401 if ( rtc_check_alarm_started(true) )
403 rtc_enable_alarm(false);
404 next_screen
= GO_TO_WPS
;
406 if (global_settings
.alarm_wake_up_screen
== ALARM_START_FM
)
407 next_screen
= GO_TO_FM
;
409 #ifdef HAVE_RECORDING
410 if (global_settings
.alarm_wake_up_screen
== ALARM_START_REC
)
412 recording_start_automatic
= true;
413 next_screen
= GO_TO_RECSCREEN
;
417 #endif /* HAVE_RTC_ALARM */
419 #ifdef HAVE_HEADPHONE_DETECTION
420 if (next_screen
== GO_TO_WPS
&&
421 (global_settings
.unplug_autoresume
&& !headphones_inserted() ))
422 next_screen
= GO_TO_ROOT
;
429 case MENU_ATTACHED_USB
:
430 case MENU_SELECTED_EXIT
:
433 if (last_screen
!= GO_TO_ROOT
)
434 selected
= get_selection(last_screen
);
435 next_screen
= do_menu(&root_menu_
, &selected
);
436 if (next_screen
!= GO_TO_PREVIOUS
)
437 last_screen
= GO_TO_ROOT
;
441 next_screen
= last_screen
;
444 case GO_TO_PREVIOUS_BROWSER
:
445 next_screen
= previous_browser
;
448 case GO_TO_PREVIOUS_MUSIC
:
449 next_screen
= previous_music
;
453 if (next_screen
== GO_TO_FILEBROWSER
455 || next_screen
== GO_TO_DBBROWSER
458 previous_browser
= next_screen
;
459 if (next_screen
== GO_TO_WPS
461 || next_screen
== GO_TO_FM
464 previous_music
= next_screen
;
465 next_screen
= load_screen(next_screen
);