summaryrefslogtreecommitdiff
path: root/apps/root_menu.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/root_menu.c')
-rw-r--r--apps/root_menu.c361
1 files changed, 361 insertions, 0 deletions
diff --git a/apps/root_menu.c b/apps/root_menu.c
new file mode 100644
index 0000000000..0f2153b03b
--- /dev/null
+++ b/apps/root_menu.c
@@ -0,0 +1,361 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: main.c 12101 2007-01-24 02:19:22Z jdgordon $
9 *
10 * Copyright (C) 2007 Jonathan Gordon
11 *
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.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19#include <stdio.h>
20#include <string.h>
21#include <stdlib.h>
22#include <stdbool.h>
23#include "config.h"
24#include "menu.h"
25#include "root_menu.h"
26#include "lang.h"
27#include "settings.h"
28#include "kernel.h"
29#include "debug.h"
30#include "misc.h"
31#include "rolo.h"
32#include "backdrop.h"
33#include "talk.h"
34#include "audio.h"
35
36/* gui api */
37#include "list.h"
38#include "statusbar.h"
39#include "splash.h"
40#include "buttonbar.h"
41#include "textarea.h"
42#include "action.h"
43#include "yesno.h"
44
45#include "main_menu.h"
46#include "tree.h"
47#include "radio.h"
48#ifdef HAVE_RECORDING
49#include "recording.h"
50#endif
51#include "gwps-common.h"
52#include "bookmark.h"
53#include "tagtree.h"
54#include "menus/exported_menus.h"
55
56struct root_items {
57 int (*function)(void* param);
58 void* param;
59};
60static int last_screen = GO_TO_ROOT; /* unfortunatly needed so we can resume
61 or goto current track based on previous
62 screen */
63static int browser(void* param)
64{
65 int ret_val;
66 struct tree_context* tc = tree_get_context();
67 int filter = SHOW_SUPPORTED;
68 char folder[MAX_PATH] = "/";
69 /* stuff needed to remember position in file browser */
70 static char last_folder[MAX_PATH] = "/";
71 /* and stuff for the database browser */
72 static int last_db_dirlevel = 0;
73
74 switch ((int)param)
75 {
76 case GO_TO_FILEBROWSER:
77 filter = global_settings.dirfilter;
78 if (global_settings.browse_current &&
79 last_screen == GO_TO_WPS && audio_status() &&
80 wps_state.current_track_path[0] != '\0')
81 {
82 snprintf(folder, MAX_PATH, "%s", wps_state.current_track_path);
83 }
84 else
85 snprintf(folder, MAX_PATH, "%s/", last_folder);
86 break;
87 case GO_TO_DBBROWSER:
88 if (!tagcache_is_usable())
89 {
90 gui_syncsplash(HZ, true, str(LANG_TAGCACHE_BUSY));
91 return GO_TO_PREVIOUS;
92 }
93 filter = SHOW_ID3DB;
94 tc->dirlevel = last_db_dirlevel;
95 break;
96 case GO_TO_BROWSEPLUGINS:
97 filter = SHOW_PLUGINS;
98 snprintf(folder, MAX_PATH, "%s/", PLUGIN_DIR);
99 break;
100 }
101 ret_val = rockbox_browse(folder, filter);
102 switch ((int)param)
103 {
104 case GO_TO_FILEBROWSER:
105 strcpy(last_folder, tc->currdir);
106 break;
107 case GO_TO_DBBROWSER:
108 last_db_dirlevel = tc->dirlevel;
109 break;
110 }
111 return ret_val;
112}
113
114static int menu(void* param)
115{
116 (void)param;
117 return main_menu();
118
119}
120#ifdef HAVE_RECORDING
121static int recscrn(void* param)
122{
123 (void)param;
124 recording_screen(false);
125 return GO_TO_ROOT;
126}
127#endif
128static int wpsscrn(void* param)
129{
130 int ret_val = GO_TO_PREVIOUS;
131 (void)param;
132 if (audio_status())
133 {
134 ret_val = gui_wps_show();
135 }
136 else if ( global_status.resume_index != -1 )
137 {
138 DEBUGF("Resume index %X offset %X\n",
139 global_status.resume_index,
140 global_status.resume_offset);
141
142#ifdef HAVE_ALARM_MOD
143 if ( rtc_check_alarm_started(true) ) {
144 rtc_enable_alarm(false);
145 }
146#endif
147
148 if (playlist_resume() != -1)
149 {
150 playlist_start(global_status.resume_index,
151 global_status.resume_offset);
152 ret_val = gui_wps_show();
153 }
154 }
155 else
156 {
157 gui_syncsplash(HZ*2, true, str(LANG_NOTHING_TO_RESUME));
158 }
159#if LCD_DEPTH > 1
160 show_main_backdrop();
161#endif
162 return ret_val;
163}
164#if CONFIG_TUNER
165static int radio(void* param)
166{
167 (void)param;
168 radio_screen();
169 return GO_TO_ROOT;
170}
171#endif
172
173static int load_bmarks(void* param)
174{
175 (void)param;
176 bookmark_mrb_load();
177 return GO_TO_PREVIOUS;
178}
179
180static const struct root_items items[] = {
181 [GO_TO_FILEBROWSER] = { browser, (void*)GO_TO_FILEBROWSER },
182 [GO_TO_DBBROWSER] = { browser, (void*)GO_TO_DBBROWSER },
183 [GO_TO_WPS] = { wpsscrn, NULL },
184 [GO_TO_MAINMENU] = { menu, NULL },
185
186#ifdef HAVE_RECORDING
187 [GO_TO_RECSCREEN] = { recscrn, NULL },
188#endif
189
190#if CONFIG_TUNER
191 [GO_TO_FM] = { radio, NULL },
192#endif
193
194 [GO_TO_RECENTBMARKS] = { load_bmarks, NULL },
195 [GO_TO_BROWSEPLUGINS] = { browser, (void*)GO_TO_BROWSEPLUGINS },
196
197};
198static const int nb_items = sizeof(items)/sizeof(*items);
199
200#ifdef BOOTFILE
201extern bool boot_changed; /* from tree.c */
202static void check_boot(void)
203{
204 if (boot_changed) {
205 char *lines[]={str(LANG_BOOT_CHANGED), str(LANG_REBOOT_NOW)};
206 struct text_message message={lines, 2};
207 if(gui_syncyesno_run(&message, NULL, NULL)==YESNO_YES)
208 rolo_load("/" BOOTFILE);
209 boot_changed = false;
210 }
211}
212#else
213# define check_boot()
214#endif
215int item_callback(int action, const struct menu_item_ex *this_item) ;
216
217MENUITEM_RETURNVALUE(file_browser, ID2P(LANG_DIR_BROWSER), GO_TO_FILEBROWSER,
218 NULL, bitmap_icons_6x8[Icon_file_view_menu]);
219MENUITEM_RETURNVALUE(db_browser, ID2P(LANG_TAGCACHE), GO_TO_DBBROWSER,
220 NULL, bitmap_icons_6x8[Icon_Audio]);
221MENUITEM_RETURNVALUE(rocks_browser, ID2P(LANG_PLUGINS), GO_TO_BROWSEPLUGINS,
222 NULL, bitmap_icons_6x8[Icon_Plugin]);
223char *get_wps_item_name(int selected_item, void * data, char *buffer)
224{
225 (void)selected_item; (void)data; (void)buffer;
226 if (audio_status())
227 return str(LANG_NOW_PLAYING);
228 return str(LANG_RESUME_PLAYBACK);
229}
230MENUITEM_RETURNVALUE_DYNTEXT(wps_item, GO_TO_WPS, NULL, get_wps_item_name,
231 NULL, bitmap_icons_6x8[Icon_Playback_menu]);
232#ifdef HAVE_RECORDING
233MENUITEM_RETURNVALUE(rec, ID2P(LANG_RECORDING_MENU), GO_TO_RECSCREEN,
234 NULL, bitmap_icons_6x8[Icon_Recording]);
235#endif
236#if CONFIG_TUNER
237MENUITEM_RETURNVALUE(fm, ID2P(LANG_FM_RADIO), GO_TO_FM,
238 item_callback, bitmap_icons_6x8[Icon_Radio_screen]);
239#endif
240MENUITEM_RETURNVALUE(menu_, ID2P(LANG_SETTINGS_MENU), GO_TO_MAINMENU,
241 NULL, bitmap_icons_6x8[Icon_Submenu_Entered]);
242MENUITEM_RETURNVALUE(bookmarks, ID2P(LANG_BOOKMARK_MENU_RECENT_BOOKMARKS),
243 GO_TO_RECENTBMARKS, item_callback,
244 bitmap_icons_6x8[Icon_Bookmark]);
245#ifdef HAVE_LCD_CHARCELLS
246static int do_shutdown(void)
247{
248 sys_poweroff();
249 return 0;
250}
251MENUITEM_FUNCTION(do_shutdown_item, ID2P(LANG_SHUTDOWN), do_shutdown, NULL, NOICON);
252#endif
253MAKE_MENU(root_menu_, ID2P(LANG_ROCKBOX_TITLE),
254 NULL, bitmap_icons_6x8[Icon_Rockbox],
255 &bookmarks, &file_browser, &db_browser,
256 &wps_item, &menu_,
257#ifdef HAVE_RECORDING
258 &rec,
259#endif
260#if CONFIG_TUNER
261 &fm,
262#endif
263 &playlist_options, &rocks_browser, &info_menu
264
265#ifdef HAVE_LCD_CHARCELLS
266 ,&do_shutdown_item
267#endif
268 );
269
270int item_callback(int action, const struct menu_item_ex *this_item)
271{
272 switch (action)
273 {
274 case ACTION_REQUEST_MENUITEM:
275#if CONFIG_TUNER
276 if (this_item == &fm)
277 {
278 if (radio_hardware_present() == 0)
279 return ACTION_EXIT_MENUITEM;
280 }
281 else
282#endif
283 if (this_item == &bookmarks)
284 {
285 if (global_settings.usemrb == 0)
286 return ACTION_EXIT_MENUITEM;
287 }
288 break;
289 }
290 return action;
291}
292
293void root_menu(void)
294{
295 int previous_browser = GO_TO_FILEBROWSER;
296 int previous_music = GO_TO_WPS;
297 int ret_val = GO_TO_ROOT;
298 int this_screen = GO_TO_ROOT;
299 int selected = 0;
300
301 if (global_settings.start_in_screen == 0)
302 ret_val = (int)global_status.last_screen;
303 else ret_val = global_settings.start_in_screen - 2;
304
305 while (true)
306 {
307 switch (ret_val)
308 {
309 case GO_TO_ROOT:
310 ret_val = do_menu(&root_menu_, &selected);
311 /* As long as MENU_ATTACHED_USB == GO_TO_ROOT this works */
312 if (ret_val == MENU_ATTACHED_USB)
313 {
314 check_boot();
315 continue;
316 }
317
318 if (ret_val == GO_TO_PREVIOUS_MUSIC)
319 ret_val = previous_music;
320 last_screen = GO_TO_ROOT;
321 break;
322 case GO_TO_PREVIOUS:
323 ret_val = last_screen;
324 if (last_screen == GO_TO_ROOT)
325 continue;
326 break;
327 case GO_TO_PREVIOUS_BROWSER:
328 if ((previous_browser == GO_TO_DBBROWSER) &&
329 !tagcache_is_usable())
330 ret_val = GO_TO_FILEBROWSER;
331 else
332 ret_val = previous_browser;
333 break;
334 case GO_TO_PREVIOUS_MUSIC:
335 ret_val = previous_music;
336 break;
337 }
338 this_screen = ret_val;
339
340 if (this_screen == GO_TO_FILEBROWSER)
341 previous_browser = GO_TO_FILEBROWSER;
342 else if (this_screen == GO_TO_DBBROWSER)
343 previous_browser = GO_TO_DBBROWSER;
344 else if (this_screen == GO_TO_WPS)
345 previous_music = GO_TO_WPS;
346#if CONFIG_TUNER
347 else if (this_screen == GO_TO_FM)
348 previous_music = GO_TO_FM;
349#endif
350
351 /* set the global_status.last_screen before entering,
352 if we dont we will always return to the wrong screen on boot */
353 global_status.last_screen = (char)this_screen;
354 status_save();
355 action_signalscreenchange();
356 ret_val = items[this_screen].function(items[this_screen].param);
357 if (ret_val != GO_TO_PREVIOUS)
358 last_screen = this_screen;
359 }
360 return;
361}