blob: de01ff8371ad09bb08f46a36c72adb6a535d9001 [file] [log] [blame]
Jonathan Gordon91cb68a2007-03-01 11:14:46 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
Peter D'Hoye4d28b2f2007-03-29 22:51:03 +00008 * $Id$
Jonathan Gordon91cb68a2007-03-01 11:14:46 +00009 *
10 * Copyright (C) 2007 Jonathan Gordon
11 *
Daniel Stenberg2acc0ac2008-06-28 18:10:04 +000012 * 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.
Jonathan Gordon91cb68a2007-03-01 11:14:46 +000016 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#include <stdio.h>
22#include <string.h>
23#include <stdlib.h>
24#include <stdbool.h>
25#include "config.h"
26#include "menu.h"
27#include "root_menu.h"
28#include "lang.h"
29#include "settings.h"
Jens Arnold178c5652007-04-09 13:39:37 +000030#include "screens.h"
Jonathan Gordon91cb68a2007-03-01 11:14:46 +000031#include "kernel.h"
32#include "debug.h"
33#include "misc.h"
34#include "rolo.h"
Jonathan Gordon5462a912007-03-01 12:35:24 +000035#include "powermgmt.h"
Jens Arnold178c5652007-04-09 13:39:37 +000036#include "power.h"
Jonathan Gordon91cb68a2007-03-01 11:14:46 +000037#include "talk.h"
38#include "audio.h"
Jonathan Gordon2ca895b2007-07-03 08:43:38 +000039#include "hotswap.h"
Nicolas Pennequin1cf2ec32007-04-25 22:08:00 +000040#include "backdrop.h"
Nicolas Pennequin1cf2ec32007-04-25 22:08:00 +000041
Jonathan Gordon91cb68a2007-03-01 11:14:46 +000042/* gui api */
43#include "list.h"
44#include "statusbar.h"
45#include "splash.h"
46#include "buttonbar.h"
Jonathan Gordon91cb68a2007-03-01 11:14:46 +000047#include "action.h"
48#include "yesno.h"
49
Jonathan Gordon91cb68a2007-03-01 11:14:46 +000050#include "tree.h"
Jonathan Gordon08575f02007-03-01 12:18:30 +000051#if CONFIG_TUNER
Jonathan Gordon91cb68a2007-03-01 11:14:46 +000052#include "radio.h"
Jonathan Gordon08575f02007-03-01 12:18:30 +000053#endif
Jonathan Gordon91cb68a2007-03-01 11:14:46 +000054#ifdef HAVE_RECORDING
55#include "recording.h"
56#endif
57#include "gwps-common.h"
58#include "bookmark.h"
Dave Chapman78d29f52008-03-26 23:35:34 +000059#include "playlist.h"
Jonathan Gordon91cb68a2007-03-01 11:14:46 +000060#include "tagtree.h"
61#include "menus/exported_menus.h"
Dan Evertonc423e872007-03-01 11:46:26 +000062#ifdef HAVE_RTC_ALARM
63#include "rtc.h"
64#endif
Steve Bavin81374892007-03-07 19:56:15 +000065#ifdef HAVE_TAGCACHE
66#include "tagcache.h"
67#endif
Jonathan Gordon91cb68a2007-03-01 11:14:46 +000068
69struct root_items {
70 int (*function)(void* param);
71 void* param;
Jonathan Gordonf9fb4922007-04-12 15:28:51 +000072 const struct menu_item_ex *context_menu;
Jonathan Gordon91cb68a2007-03-01 11:14:46 +000073};
74static int last_screen = GO_TO_ROOT; /* unfortunatly needed so we can resume
75 or goto current track based on previous
76 screen */
77static int browser(void* param)
78{
79 int ret_val;
Jonathan Gordon798ddf22007-03-07 04:36:02 +000080#ifdef HAVE_TAGCACHE
Jonathan Gordon91cb68a2007-03-01 11:14:46 +000081 struct tree_context* tc = tree_get_context();
Jonathan Gordon798ddf22007-03-07 04:36:02 +000082#endif
Jonathan Gordon91cb68a2007-03-01 11:14:46 +000083 int filter = SHOW_SUPPORTED;
84 char folder[MAX_PATH] = "/";
85 /* stuff needed to remember position in file browser */
86 static char last_folder[MAX_PATH] = "/";
87 /* and stuff for the database browser */
Jonathan Gordon798ddf22007-03-07 04:36:02 +000088#ifdef HAVE_TAGCACHE
Jonathan Gordonfd30be52007-03-10 12:51:08 +000089 static int last_db_dirlevel = 0, last_db_selection = 0;
Jonathan Gordon798ddf22007-03-07 04:36:02 +000090#endif
Jonathan Gordon91cb68a2007-03-01 11:14:46 +000091
Jonathan Gordon08575f02007-03-01 12:18:30 +000092 switch ((intptr_t)param)
Jonathan Gordon91cb68a2007-03-01 11:14:46 +000093 {
94 case GO_TO_FILEBROWSER:
95 filter = global_settings.dirfilter;
96 if (global_settings.browse_current &&
Steve Bavin6cc38952008-02-09 15:20:15 +000097 last_screen == GO_TO_WPS &&
Jonathan Gordon91cb68a2007-03-01 11:14:46 +000098 wps_state.current_track_path[0] != '\0')
99 {
Jonathan Gordon1b07ed02007-03-06 08:21:18 +0000100 strcpy(folder, wps_state.current_track_path);
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000101 }
Jonathan Gordon2ca895b2007-07-03 08:43:38 +0000102#ifdef HAVE_HOTSWAP /* quick hack to stop crashing if you try entering
103 the browser from the menu when you were in the card
104 and it was removed */
105 else if (strchr(last_folder, '<') && (card_detect() == false))
106 strcpy(folder, "/");
107#endif
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000108 else
Jonathan Gordon1b07ed02007-03-06 08:21:18 +0000109 strcpy(folder, last_folder);
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000110 break;
Jonathan Gordon798ddf22007-03-07 04:36:02 +0000111#ifdef HAVE_TAGCACHE
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000112 case GO_TO_DBBROWSER:
Steve Bavin81374892007-03-07 19:56:15 +0000113 if (!tagcache_is_usable())
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000114 {
Steve Bavin149bc032007-03-08 08:20:30 +0000115 bool reinit_attempted = false;
Steve Bavin81374892007-03-07 19:56:15 +0000116
117 /* Now display progress until it's ready or the user exits */
118 while(!tagcache_is_usable())
119 {
120 gui_syncstatusbar_draw(&statusbars, false);
Steve Bavin149bc032007-03-08 08:20:30 +0000121 struct tagcache_stat *stat = tagcache_get_stat();
122
123 /* Allow user to exit */
124 if (action_userabort(HZ/2))
125 break;
Steve Bavin81374892007-03-07 19:56:15 +0000126
127 /* Maybe just needs to reboot due to delayed commit */
128 if (stat->commit_delayed)
129 {
Nils Wallménius5b769362007-08-06 13:08:36 +0000130 gui_syncsplash(HZ*2, ID2P(LANG_PLEASE_REBOOT));
Steve Bavin81374892007-03-07 19:56:15 +0000131 break;
132 }
133
Steve Bavin149bc032007-03-08 08:20:30 +0000134 /* Check if ready status is known */
135 if (!stat->readyvalid)
136 {
Jens Arnold4d6374c2007-03-16 21:56:08 +0000137 gui_syncsplash(0, str(LANG_TAGCACHE_BUSY));
Steve Bavin149bc032007-03-08 08:20:30 +0000138 continue;
139 }
140
141 /* Re-init if required */
142 if (!reinit_attempted && !stat->ready &&
143 stat->processed_entries == 0 && stat->commit_step == 0)
144 {
145 /* Prompt the user */
146 reinit_attempted = true;
Nils Wallménius33c44462008-04-26 09:30:24 +0000147 static const char *lines[]={
148 ID2P(LANG_TAGCACHE_BUSY), ID2P(LANG_TAGCACHE_FORCE_UPDATE)};
149 static const struct text_message message={lines, 2};
Steve Bavin149bc032007-03-08 08:20:30 +0000150 if(gui_syncyesno_run(&message, NULL, NULL) == YESNO_NO)
151 break;
152 int i;
153 FOR_NB_SCREENS(i)
154 screens[i].clear_display();
155
156 /* Start initialisation */
157 tagcache_rebuild();
158 }
159
Steve Bavin81374892007-03-07 19:56:15 +0000160 /* Display building progress */
Nils Wallménius5b769362007-08-06 13:08:36 +0000161 static long talked_tick = 0;
Steve Bavin32a95752007-10-19 15:31:42 +0000162 if(global_settings.talk_menu &&
Nils Wallménius5b769362007-08-06 13:08:36 +0000163 (talked_tick == 0
164 || TIME_AFTER(current_tick, talked_tick+7*HZ)))
165 {
166 talked_tick = current_tick;
167 if (stat->commit_step > 0)
168 {
169 talk_id(LANG_TAGCACHE_INIT, false);
170 talk_number(stat->commit_step, true);
171 talk_id(VOICE_OF, true);
172 talk_number(tagcache_get_max_commit_step(), true);
173 } else if(stat->processed_entries)
174 {
175 talk_number(stat->processed_entries, false);
176 talk_id(LANG_BUILDING_DATABASE, true);
177 }
178 }
Steve Bavin81374892007-03-07 19:56:15 +0000179 if (stat->commit_step > 0)
180 {
Jens Arnold4d6374c2007-03-16 21:56:08 +0000181 gui_syncsplash(0, "%s [%d/%d]",
Steve Bavin81374892007-03-07 19:56:15 +0000182 str(LANG_TAGCACHE_INIT), stat->commit_step,
183 tagcache_get_max_commit_step());
184 }
185 else
186 {
Jens Arnold4d6374c2007-03-16 21:56:08 +0000187 gui_syncsplash(0, str(LANG_BUILDING_DATABASE),
Steve Bavin81374892007-03-07 19:56:15 +0000188 stat->processed_entries);
189 }
Steve Bavin81374892007-03-07 19:56:15 +0000190 }
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000191 }
Steve Bavin81374892007-03-07 19:56:15 +0000192 if (!tagcache_is_usable())
193 return GO_TO_PREVIOUS;
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000194 filter = SHOW_ID3DB;
195 tc->dirlevel = last_db_dirlevel;
Jonathan Gordonfd30be52007-03-10 12:51:08 +0000196 tc->selected_item = last_db_selection;
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000197 break;
Jonathan Gordon798ddf22007-03-07 04:36:02 +0000198#endif
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000199 case GO_TO_BROWSEPLUGINS:
200 filter = SHOW_PLUGINS;
Peter D'Hoye57372542007-07-11 22:05:38 +0000201 snprintf(folder, MAX_PATH, "%s", PLUGIN_DIR);
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000202 break;
203 }
204 ret_val = rockbox_browse(folder, filter);
Jonathan Gordon08575f02007-03-01 12:18:30 +0000205 switch ((intptr_t)param)
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000206 {
207 case GO_TO_FILEBROWSER:
Jonathan Gordon1b07ed02007-03-06 08:21:18 +0000208 get_current_file(last_folder, MAX_PATH);
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000209 break;
Jonathan Gordon798ddf22007-03-07 04:36:02 +0000210#ifdef HAVE_TAGCACHE
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000211 case GO_TO_DBBROWSER:
212 last_db_dirlevel = tc->dirlevel;
Jonathan Gordonfd30be52007-03-10 12:51:08 +0000213 last_db_selection = tc->selected_item;
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000214 break;
Jonathan Gordon798ddf22007-03-07 04:36:02 +0000215#endif
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000216 }
217 return ret_val;
218}
219
220static int menu(void* param)
221{
222 (void)param;
Jonathan Gordon5ca15392008-03-26 03:35:24 +0000223 return do_menu(NULL, 0, NULL, false);
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000224
225}
226#ifdef HAVE_RECORDING
227static int recscrn(void* param)
228{
229 (void)param;
230 recording_screen(false);
231 return GO_TO_ROOT;
232}
233#endif
234static int wpsscrn(void* param)
235{
236 int ret_val = GO_TO_PREVIOUS;
237 (void)param;
238 if (audio_status())
239 {
Steve Bavin32a95752007-10-19 15:31:42 +0000240 talk_shutup();
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000241 ret_val = gui_wps_show();
242 }
243 else if ( global_status.resume_index != -1 )
244 {
Jens Arnoldf68362a2007-03-17 09:54:28 +0000245 DEBUGF("Resume index %X offset %lX\n",
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000246 global_status.resume_index,
Jens Arnoldbd5c0ad2007-03-17 10:50:58 +0000247 (unsigned long)global_status.resume_offset);
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000248 if (playlist_resume() != -1)
249 {
250 playlist_start(global_status.resume_index,
251 global_status.resume_offset);
252 ret_val = gui_wps_show();
253 }
254 }
Jens Arnoldf68362a2007-03-17 09:54:28 +0000255 else
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000256 {
Nils Wallménius5b769362007-08-06 13:08:36 +0000257 gui_syncsplash(HZ*2, ID2P(LANG_NOTHING_TO_RESUME));
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000258 }
259#if LCD_DEPTH > 1
260 show_main_backdrop();
261#endif
Nicolas Pennequin7fdfa562007-04-25 21:44:56 +0000262#if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
263 show_remote_main_backdrop();
264#endif
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000265 return ret_val;
266}
267#if CONFIG_TUNER
268static int radio(void* param)
269{
270 (void)param;
271 radio_screen();
272 return GO_TO_ROOT;
273}
274#endif
275
276static int load_bmarks(void* param)
277{
278 (void)param;
Stéphane Doyon84ed3fd2007-10-12 04:10:08 +0000279 if(bookmark_mrb_load())
280 return GO_TO_WPS;
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000281 return GO_TO_PREVIOUS;
282}
Jonathan Gordonfda7d722007-08-06 13:42:52 +0000283static int plugins_menu(void* param)
284{
285 (void)param;
286 MENUITEM_STRINGLIST(plugins_menu_items, ID2P(LANG_PLUGINS), NULL,
287 ID2P(LANG_PLUGIN_GAMES),
288 ID2P(LANG_PLUGIN_APPS), ID2P(LANG_PLUGIN_DEMOS));
289 char *folder;
290 int retval = GO_TO_PREVIOUS;
291 int selection = 0, current = 0;
292 while (retval == GO_TO_PREVIOUS)
293 {
Jonathan Gordon5ca15392008-03-26 03:35:24 +0000294 selection = do_menu(&plugins_menu_items, &current, NULL, false);
Jonathan Gordonfda7d722007-08-06 13:42:52 +0000295 switch (selection)
296 {
297 case 0:
298 folder = PLUGIN_GAMES_DIR;
299 break;
300 case 1:
301 folder = PLUGIN_APPS_DIR;
302 break;
303 case 2:
304 folder = PLUGIN_DEMOS_DIR;
305 break;
306 default:
307 return selection;
308 }
309 retval = rockbox_browse(folder, SHOW_PLUGINS);
310 }
311 return retval;
312}
313
Jonathan Gordonf9fb4922007-04-12 15:28:51 +0000314/* These are all static const'd from apps/menus/ *.c
315 so little hack so we can use them */
316extern struct menu_item_ex
317 file_menu,
Brandon Lowb44b6602007-04-18 19:46:34 +0000318#ifdef HAVE_TAGCACHE
Jonathan Gordonf9fb4922007-04-12 15:28:51 +0000319 tagcache_menu,
Brandon Lowb44b6602007-04-18 19:46:34 +0000320#endif
Jonathan Gordonf9fb4922007-04-12 15:28:51 +0000321 manage_settings,
Peter D'Hoye9337efd2007-07-03 18:31:13 +0000322 recording_settings_menu,
323 radio_settings_menu,
Jonathan Gordonf9fb4922007-04-12 15:28:51 +0000324 bookmark_settings_menu,
325 system_menu;
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000326static const struct root_items items[] = {
Jonathan Gordonf9fb4922007-04-12 15:28:51 +0000327 [GO_TO_FILEBROWSER] = { browser, (void*)GO_TO_FILEBROWSER, &file_menu},
Brandon Lowb44b6602007-04-18 19:46:34 +0000328#ifdef HAVE_TAGCACHE
Jonathan Gordonf9fb4922007-04-12 15:28:51 +0000329 [GO_TO_DBBROWSER] = { browser, (void*)GO_TO_DBBROWSER, &tagcache_menu },
Brandon Lowb44b6602007-04-18 19:46:34 +0000330#endif
Steve Bavin5f8bd632008-05-22 08:02:48 +0000331 [GO_TO_WPS] = { wpsscrn, NULL, &playback_settings },
Jonathan Gordonf9fb4922007-04-12 15:28:51 +0000332 [GO_TO_MAINMENU] = { menu, NULL, &manage_settings },
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000333
334#ifdef HAVE_RECORDING
Peter D'Hoye9337efd2007-07-03 18:31:13 +0000335 [GO_TO_RECSCREEN] = { recscrn, NULL, &recording_settings_menu },
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000336#endif
337
338#if CONFIG_TUNER
Peter D'Hoye9337efd2007-07-03 18:31:13 +0000339 [GO_TO_FM] = { radio, NULL, &radio_settings_menu },
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000340#endif
341
Jonathan Gordonf9fb4922007-04-12 15:28:51 +0000342 [GO_TO_RECENTBMARKS] = { load_bmarks, NULL, &bookmark_settings_menu },
Jonathan Gordonfda7d722007-08-06 13:42:52 +0000343 [GO_TO_BROWSEPLUGINS] = { plugins_menu, NULL, NULL },
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000344
345};
346static const int nb_items = sizeof(items)/sizeof(*items);
347
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000348int item_callback(int action, const struct menu_item_ex *this_item) ;
349
350MENUITEM_RETURNVALUE(file_browser, ID2P(LANG_DIR_BROWSER), GO_TO_FILEBROWSER,
Jonathan Gordon02a87172007-03-03 13:52:14 +0000351 NULL, Icon_file_view_menu);
Jonathan Gordon798ddf22007-03-07 04:36:02 +0000352#ifdef HAVE_TAGCACHE
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000353MENUITEM_RETURNVALUE(db_browser, ID2P(LANG_TAGCACHE), GO_TO_DBBROWSER,
Jonathan Gordon02a87172007-03-03 13:52:14 +0000354 NULL, Icon_Audio);
Jonathan Gordon798ddf22007-03-07 04:36:02 +0000355#endif
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000356MENUITEM_RETURNVALUE(rocks_browser, ID2P(LANG_PLUGINS), GO_TO_BROWSEPLUGINS,
Jonathan Gordon02a87172007-03-03 13:52:14 +0000357 NULL, Icon_Plugin);
Bertrik Sikkene15f8a22008-05-03 08:35:14 +0000358static char *get_wps_item_name(int selected_item, void * data, char *buffer)
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000359{
360 (void)selected_item; (void)data; (void)buffer;
361 if (audio_status())
Linus Nielsen Feltzing298c2bb2007-03-05 00:32:33 +0000362 return ID2P(LANG_NOW_PLAYING);
363 return ID2P(LANG_RESUME_PLAYBACK);
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000364}
365MENUITEM_RETURNVALUE_DYNTEXT(wps_item, GO_TO_WPS, NULL, get_wps_item_name,
Stéphane Doyon5acf0912007-10-09 03:48:56 +0000366 NULL, NULL, Icon_Playback_menu);
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000367#ifdef HAVE_RECORDING
Nils Wallméniusb3113672007-08-05 19:19:39 +0000368MENUITEM_RETURNVALUE(rec, ID2P(LANG_RECORDING), GO_TO_RECSCREEN,
Jonathan Gordon02a87172007-03-03 13:52:14 +0000369 NULL, Icon_Recording);
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000370#endif
371#if CONFIG_TUNER
372MENUITEM_RETURNVALUE(fm, ID2P(LANG_FM_RADIO), GO_TO_FM,
Jonathan Gordon02a87172007-03-03 13:52:14 +0000373 item_callback, Icon_Radio_screen);
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000374#endif
Nils Wallméniusb3113672007-08-05 19:19:39 +0000375MENUITEM_RETURNVALUE(menu_, ID2P(LANG_SETTINGS), GO_TO_MAINMENU,
Jonathan Gordon02a87172007-03-03 13:52:14 +0000376 NULL, Icon_Submenu_Entered);
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000377MENUITEM_RETURNVALUE(bookmarks, ID2P(LANG_BOOKMARK_MENU_RECENT_BOOKMARKS),
378 GO_TO_RECENTBMARKS, item_callback,
Jonathan Gordon02a87172007-03-03 13:52:14 +0000379 Icon_Bookmark);
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000380#ifdef HAVE_LCD_CHARCELLS
381static int do_shutdown(void)
382{
Jens Arnold5764ff52007-04-09 13:54:38 +0000383#if CONFIG_CHARGING
Jens Arnold178c5652007-04-09 13:39:37 +0000384 if (charger_inserted())
385 charging_splash();
386 else
Jens Arnold5764ff52007-04-09 13:54:38 +0000387#endif
Jens Arnold178c5652007-04-09 13:39:37 +0000388 sys_poweroff();
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000389 return 0;
390}
Jonathan Gordondaf66942007-03-17 12:33:34 +0000391MENUITEM_FUNCTION(do_shutdown_item, 0, ID2P(LANG_SHUTDOWN),
Jonathan Gordon458648b2007-03-18 07:25:01 +0000392 do_shutdown, NULL, NULL, Icon_NOICON);
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000393#endif
394MAKE_MENU(root_menu_, ID2P(LANG_ROCKBOX_TITLE),
Jonathan Gordon411f3e22007-07-11 02:22:03 +0000395 item_callback, Icon_Rockbox,
Jonathan Gordon798ddf22007-03-07 04:36:02 +0000396 &bookmarks, &file_browser,
397#ifdef HAVE_TAGCACHE
398 &db_browser,
399#endif
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000400 &wps_item, &menu_,
401#ifdef HAVE_RECORDING
402 &rec,
403#endif
404#if CONFIG_TUNER
405 &fm,
406#endif
407 &playlist_options, &rocks_browser, &info_menu
408
409#ifdef HAVE_LCD_CHARCELLS
410 ,&do_shutdown_item
411#endif
412 );
413
414int item_callback(int action, const struct menu_item_ex *this_item)
415{
416 switch (action)
417 {
Jonathan Gordon411f3e22007-07-11 02:22:03 +0000418 case ACTION_TREE_STOP:
419 return ACTION_REDRAW;
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000420 case ACTION_REQUEST_MENUITEM:
421#if CONFIG_TUNER
422 if (this_item == &fm)
423 {
424 if (radio_hardware_present() == 0)
425 return ACTION_EXIT_MENUITEM;
426 }
427 else
428#endif
429 if (this_item == &bookmarks)
430 {
431 if (global_settings.usemrb == 0)
432 return ACTION_EXIT_MENUITEM;
433 }
434 break;
435 }
436 return action;
437}
Jonathan Gordon6bb473d2007-03-05 13:36:00 +0000438static int get_selection(int last_screen)
439{
440 unsigned int i;
441 for(i=0; i< sizeof(root_menu__)/sizeof(*root_menu__); i++)
442 {
Jonathan Gordon680acbf2007-04-25 10:41:17 +0000443 if (((root_menu__[i]->flags&MENU_TYPE_MASK) == MT_RETURN_VALUE) &&
Jonathan Gordon6bb473d2007-03-05 13:36:00 +0000444 (root_menu__[i]->value == last_screen))
445 {
446 return i;
447 }
448 }
449 return 0;
450}
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000451
Jonathan Gordon678705c2007-03-29 14:19:28 +0000452static inline int load_screen(int screen)
453{
454 /* set the global_status.last_screen before entering,
455 if we dont we will always return to the wrong screen on boot */
456 int old_previous = last_screen;
457 int ret_val;
458 if (screen <= GO_TO_ROOT)
459 return screen;
460 if (screen == old_previous)
461 old_previous = GO_TO_ROOT;
462 global_status.last_screen = (char)screen;
463 status_save();
Jonathan Gordon678705c2007-03-29 14:19:28 +0000464 ret_val = items[screen].function(items[screen].param);
Robert Kukla1f337352007-03-31 21:59:57 +0000465 last_screen = screen;
Jonathan Gordon678705c2007-03-29 14:19:28 +0000466 if (ret_val == GO_TO_PREVIOUS)
467 last_screen = old_previous;
468 return ret_val;
469}
Jonathan Gordonf9fb4922007-04-12 15:28:51 +0000470static int load_context_screen(int selection)
471{
472 const struct menu_item_ex *context_menu = NULL;
Jonathan Gordon680acbf2007-04-25 10:41:17 +0000473 if ((root_menu__[selection]->flags&MENU_TYPE_MASK) == MT_RETURN_VALUE)
Jonathan Gordonf9fb4922007-04-12 15:28:51 +0000474 {
475 int item = root_menu__[selection]->value;
476 context_menu = items[item].context_menu;
477 }
478 /* special cases */
479 else if (root_menu__[selection] == &info_menu)
480 {
481 context_menu = &system_menu;
482 }
483
484 if (context_menu)
Jonathan Gordon5ca15392008-03-26 03:35:24 +0000485 return do_menu(context_menu, NULL, NULL, false);
Jonathan Gordonf9fb4922007-04-12 15:28:51 +0000486 else
487 return GO_TO_PREVIOUS;
488}
Stéphane Doyon6d081162007-10-12 04:20:20 +0000489
490static int previous_music = GO_TO_WPS;
491
492void previous_music_is_wps(void)
493{
494 previous_music = GO_TO_WPS;
495}
496
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000497void root_menu(void)
498{
499 int previous_browser = GO_TO_FILEBROWSER;
Jonathan Gordon678705c2007-03-29 14:19:28 +0000500 int next_screen = GO_TO_ROOT;
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000501 int selected = 0;
502
503 if (global_settings.start_in_screen == 0)
Jonathan Gordon678705c2007-03-29 14:19:28 +0000504 next_screen = (int)global_status.last_screen;
505 else next_screen = global_settings.start_in_screen - 2;
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000506
Jonathan Gordon9e554a82007-03-07 01:16:25 +0000507#ifdef HAVE_RTC_ALARM
508 if ( rtc_check_alarm_started(true) )
509 {
510 rtc_enable_alarm(false);
Jonathan Gordon678705c2007-03-29 14:19:28 +0000511 next_screen = GO_TO_WPS;
Jonathan Gordon9e554a82007-03-07 01:16:25 +0000512#if CONFIG_TUNER
513 if (global_settings.alarm_wake_up_screen == ALARM_START_FM)
Jonathan Gordon678705c2007-03-29 14:19:28 +0000514 next_screen = GO_TO_FM;
Jonathan Gordon9e554a82007-03-07 01:16:25 +0000515#endif
516#ifdef HAVE_RECORDING
517 if (global_settings.alarm_wake_up_screen == ALARM_START_REC)
Jonathan Gordone900a902007-03-07 01:59:29 +0000518 {
519 recording_start_automatic = true;
Jonathan Gordon678705c2007-03-29 14:19:28 +0000520 next_screen = GO_TO_RECSCREEN;
Jonathan Gordone900a902007-03-07 01:59:29 +0000521 }
Jonathan Gordon9e554a82007-03-07 01:16:25 +0000522#endif
523 }
524#endif /* HAVE_RTC_ALARM */
525
Jonathan Gordon7ce492e2007-03-08 00:37:58 +0000526#ifdef HAVE_HEADPHONE_DETECTION
Jonathan Gordon678705c2007-03-29 14:19:28 +0000527 if (next_screen == GO_TO_WPS &&
Jonathan Gordon7ce492e2007-03-08 00:37:58 +0000528 (global_settings.unplug_autoresume && !headphones_inserted() ))
Jonathan Gordon678705c2007-03-29 14:19:28 +0000529 next_screen = GO_TO_ROOT;
Jonathan Gordon7ce492e2007-03-08 00:37:58 +0000530#endif
531
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000532 while (true)
533 {
Jonathan Gordon678705c2007-03-29 14:19:28 +0000534 switch (next_screen)
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000535 {
Jonathan Gordon91e726a2007-03-27 06:38:11 +0000536 case MENU_ATTACHED_USB:
537 case MENU_SELECTED_EXIT:
Jonathan Gordon91e726a2007-03-27 06:38:11 +0000538 /* fall through */
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000539 case GO_TO_ROOT:
Jonathan Gordon43b2d092007-03-07 10:13:07 +0000540 if (last_screen != GO_TO_ROOT)
541 selected = get_selection(last_screen);
Jonathan Gordon5ca15392008-03-26 03:35:24 +0000542 next_screen = do_menu(&root_menu_, &selected, NULL, false);
Jonathan Gordon678705c2007-03-29 14:19:28 +0000543 if (next_screen != GO_TO_PREVIOUS)
544 last_screen = GO_TO_ROOT;
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000545 break;
Jonathan Gordona74eefe2007-03-06 13:35:15 +0000546
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000547 case GO_TO_PREVIOUS:
Jonathan Gordon678705c2007-03-29 14:19:28 +0000548 next_screen = last_screen;
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000549 break;
Jonathan Gordona74eefe2007-03-06 13:35:15 +0000550
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000551 case GO_TO_PREVIOUS_BROWSER:
Jonathan Gordon678705c2007-03-29 14:19:28 +0000552 next_screen = previous_browser;
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000553 break;
Jonathan Gordona74eefe2007-03-06 13:35:15 +0000554
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000555 case GO_TO_PREVIOUS_MUSIC:
Jonathan Gordon678705c2007-03-29 14:19:28 +0000556 next_screen = previous_music;
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000557 break;
Jonathan Gordonf9fb4922007-04-12 15:28:51 +0000558 case GO_TO_ROOTITEM_CONTEXT:
559 next_screen = load_context_screen(selected);
560 break;
Jonathan Gordon678705c2007-03-29 14:19:28 +0000561 default:
562 if (next_screen == GO_TO_FILEBROWSER
Steve Bavin888890a2007-03-09 16:54:35 +0000563#ifdef HAVE_TAGCACHE
Jonathan Gordon678705c2007-03-29 14:19:28 +0000564 || next_screen == GO_TO_DBBROWSER
Steve Bavin888890a2007-03-09 16:54:35 +0000565#endif
Jonathan Gordon678705c2007-03-29 14:19:28 +0000566 )
567 previous_browser = next_screen;
568 if (next_screen == GO_TO_WPS
Jonathan Gordonec7ca332007-04-05 02:50:43 +0000569#if CONFIG_TUNER
Jonathan Gordon678705c2007-03-29 14:19:28 +0000570 || next_screen == GO_TO_FM
Steve Bavin888890a2007-03-09 16:54:35 +0000571#endif
Jonathan Gordon678705c2007-03-29 14:19:28 +0000572 )
573 previous_music = next_screen;
574 next_screen = load_screen(next_screen);
575 break;
576 } /* switch() */
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000577 }
578 return;
579}