1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
8 * $Id: main.c 12101 2007-01-24 02:19:22Z jdgordon $
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
;
190 /* hopefully only happens trying to go back into the WPS
191 from plugins, if music is stopped... */
192 if ((ret_val
== GO_TO_PREVIOUS
) && (last_screen
== (intptr_t)param
))
193 ret_val
= GO_TO_ROOT
;
198 static int menu(void* param
)
201 return do_menu(NULL
, 0);
204 #ifdef HAVE_RECORDING
205 static int recscrn(void* param
)
208 recording_screen(false);
212 static int wpsscrn(void* param
)
214 int ret_val
= GO_TO_PREVIOUS
;
218 ret_val
= gui_wps_show();
220 else if ( global_status
.resume_index
!= -1 )
222 DEBUGF("Resume index %X offset %lX\n",
223 global_status
.resume_index
,
224 (unsigned long)global_status
.resume_offset
);
225 if (playlist_resume() != -1)
227 playlist_start(global_status
.resume_index
,
228 global_status
.resume_offset
);
229 ret_val
= gui_wps_show();
234 gui_syncsplash(HZ
*2, str(LANG_NOTHING_TO_RESUME
));
237 show_main_backdrop();
242 static int radio(void* param
)
250 static int load_bmarks(void* param
)
254 return GO_TO_PREVIOUS
;
257 static const struct root_items items
[] = {
258 [GO_TO_FILEBROWSER
] = { browser
, (void*)GO_TO_FILEBROWSER
},
259 [GO_TO_DBBROWSER
] = { browser
, (void*)GO_TO_DBBROWSER
},
260 [GO_TO_WPS
] = { wpsscrn
, NULL
},
261 [GO_TO_MAINMENU
] = { menu
, NULL
},
263 #ifdef HAVE_RECORDING
264 [GO_TO_RECSCREEN
] = { recscrn
, NULL
},
268 [GO_TO_FM
] = { radio
, NULL
},
271 [GO_TO_RECENTBMARKS
] = { load_bmarks
, NULL
},
272 [GO_TO_BROWSEPLUGINS
] = { browser
, (void*)GO_TO_BROWSEPLUGINS
},
275 static const int nb_items
= sizeof(items
)/sizeof(*items
);
278 extern bool boot_changed
; /* from tree.c */
279 static void check_boot(void)
282 char *lines
[]={str(LANG_BOOT_CHANGED
), str(LANG_REBOOT_NOW
)};
283 struct text_message message
={lines
, 2};
284 if(gui_syncyesno_run(&message
, NULL
, NULL
)==YESNO_YES
)
285 rolo_load("/" BOOTFILE
);
286 boot_changed
= false;
290 # define check_boot()
292 int item_callback(int action
, const struct menu_item_ex
*this_item
) ;
294 MENUITEM_RETURNVALUE(file_browser
, ID2P(LANG_DIR_BROWSER
), GO_TO_FILEBROWSER
,
295 NULL
, Icon_file_view_menu
);
297 MENUITEM_RETURNVALUE(db_browser
, ID2P(LANG_TAGCACHE
), GO_TO_DBBROWSER
,
300 MENUITEM_RETURNVALUE(rocks_browser
, ID2P(LANG_PLUGINS
), GO_TO_BROWSEPLUGINS
,
302 char *get_wps_item_name(int selected_item
, void * data
, char *buffer
)
304 (void)selected_item
; (void)data
; (void)buffer
;
306 return ID2P(LANG_NOW_PLAYING
);
307 return ID2P(LANG_RESUME_PLAYBACK
);
309 MENUITEM_RETURNVALUE_DYNTEXT(wps_item
, GO_TO_WPS
, NULL
, get_wps_item_name
,
310 NULL
, Icon_Playback_menu
);
311 #ifdef HAVE_RECORDING
312 MENUITEM_RETURNVALUE(rec
, ID2P(LANG_RECORDING_MENU
), GO_TO_RECSCREEN
,
313 NULL
, Icon_Recording
);
316 MENUITEM_RETURNVALUE(fm
, ID2P(LANG_FM_RADIO
), GO_TO_FM
,
317 item_callback
, Icon_Radio_screen
);
319 MENUITEM_RETURNVALUE(menu_
, ID2P(LANG_SETTINGS_MENU
), GO_TO_MAINMENU
,
320 NULL
, Icon_Submenu_Entered
);
321 MENUITEM_RETURNVALUE(bookmarks
, ID2P(LANG_BOOKMARK_MENU_RECENT_BOOKMARKS
),
322 GO_TO_RECENTBMARKS
, item_callback
,
324 #ifdef HAVE_LCD_CHARCELLS
325 static int do_shutdown(void)
330 MENUITEM_FUNCTION(do_shutdown_item
, 0, ID2P(LANG_SHUTDOWN
),
331 do_shutdown
, NULL
, 0, NULL
, Icon_NOICON
);
333 MAKE_MENU(root_menu_
, ID2P(LANG_ROCKBOX_TITLE
),
335 &bookmarks
, &file_browser
,
340 #ifdef HAVE_RECORDING
346 &playlist_options
, &rocks_browser
, &info_menu
348 #ifdef HAVE_LCD_CHARCELLS
353 int item_callback(int action
, const struct menu_item_ex
*this_item
)
357 case ACTION_REQUEST_MENUITEM
:
359 if (this_item
== &fm
)
361 if (radio_hardware_present() == 0)
362 return ACTION_EXIT_MENUITEM
;
366 if (this_item
== &bookmarks
)
368 if (global_settings
.usemrb
== 0)
369 return ACTION_EXIT_MENUITEM
;
375 static int get_selection(int last_screen
)
378 for(i
=0; i
< sizeof(root_menu__
)/sizeof(*root_menu__
); i
++)
380 if ((root_menu__
[i
]->flags
&MT_RETURN_VALUE
) &&
381 (root_menu__
[i
]->value
== last_screen
))
391 int previous_browser
= GO_TO_FILEBROWSER
;
392 int previous_music
= GO_TO_WPS
;
393 int ret_val
= GO_TO_ROOT
;
394 int this_screen
= GO_TO_ROOT
;
397 if (global_settings
.start_in_screen
== 0)
398 ret_val
= (int)global_status
.last_screen
;
399 else ret_val
= global_settings
.start_in_screen
- 2;
401 #ifdef HAVE_RTC_ALARM
402 if ( rtc_check_alarm_started(true) )
404 rtc_enable_alarm(false);
407 if (global_settings
.alarm_wake_up_screen
== ALARM_START_FM
)
410 #ifdef HAVE_RECORDING
411 if (global_settings
.alarm_wake_up_screen
== ALARM_START_REC
)
413 recording_start_automatic
= true;
414 ret_val
= GO_TO_RECSCREEN
;
418 #endif /* HAVE_RTC_ALARM */
420 #ifdef HAVE_HEADPHONE_DETECTION
421 if (ret_val
== GO_TO_WPS
&&
422 (global_settings
.unplug_autoresume
&& !headphones_inserted() ))
423 ret_val
= GO_TO_ROOT
;
431 if (last_screen
!= GO_TO_ROOT
)
432 selected
= get_selection(last_screen
);
433 ret_val
= do_menu(&root_menu_
, &selected
);
434 /* As long as MENU_ATTACHED_USB == GO_TO_ROOT this works */
435 if (ret_val
<= GO_TO_ROOT
)
437 if (ret_val
== MENU_ATTACHED_USB
)
439 else if (ret_val
== GO_TO_PREVIOUS
)
441 ret_val
= last_screen
;
442 last_screen
= GO_TO_ROOT
;
446 last_screen
= GO_TO_ROOT
;
450 ret_val
= last_screen
;
454 case GO_TO_PREVIOUS_BROWSER
:
455 ret_val
= previous_browser
;
458 case GO_TO_PREVIOUS_MUSIC
:
459 ret_val
= previous_music
;
462 this_screen
= ret_val
;
463 /* set the global_status.last_screen before entering,
464 if we dont we will always return to the wrong screen on boot */
465 global_status
.last_screen
= (char)this_screen
;
466 if (this_screen
== GO_TO_FILEBROWSER
468 || this_screen
== GO_TO_DBBROWSER
471 previous_browser
= this_screen
;
472 if (this_screen
== GO_TO_WPS
474 || this_screen
== GO_TO_FM
477 previous_music
= this_screen
;
479 action_signalscreenchange();
480 ret_val
= items
[this_screen
].function(items
[this_screen
].param
);
481 if (ret_val
!= GO_TO_PREVIOUS
)
482 last_screen
= this_screen
;