add missing command line to ipod 3g installation instructions
[Rockbox.git] / apps / main_menu.c
blob0ac4d9475374cba6f9bb8e8da0a33d968b36dd8b
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 Björn Stenberg
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 ****************************************************************************/
19 #include <timefuncs.h>
20 #include "config.h"
21 #include "options.h"
23 #include "menu.h"
24 #include "tree.h"
25 #include "lcd.h"
26 #include "font.h"
27 #include "action.h"
28 #include "kernel.h"
29 #include "main_menu.h"
30 #include "debug_menu.h"
31 #include "sprintf.h"
32 #include <string.h>
33 #include "settings.h"
34 #include "settings_menu.h"
35 #include "power.h"
36 #include "powermgmt.h"
37 #include "sound_menu.h"
38 #include "status.h"
39 #include "fat.h"
40 #include "bookmark.h"
41 #include "buffer.h"
42 #include "screens.h"
43 #include "playlist_menu.h"
44 #include "talk.h"
45 #ifdef CONFIG_TUNER
46 #include "radio.h"
47 #endif
48 #include "misc.h"
49 #include "lang.h"
50 #include "logfdisp.h"
51 #include "plugin.h"
52 #include "filetypes.h"
53 #include "splash.h"
55 #ifdef HAVE_RECORDING
56 #include "recording.h"
57 #endif
59 bool show_credits(void)
61 plugin_load("/.rockbox/rocks/credits.rock",NULL);
62 return false;
65 #ifdef SIMULATOR
66 extern bool simulate_usb(void);
67 #endif
69 #ifdef HAVE_LCD_CHARCELLS
70 #define SIZE_FMT "%s%s"
71 #else
72 #define SIZE_FMT "%s %s"
73 #endif
75 bool show_info(void)
77 char s[64], s1[32];
78 unsigned long size, free;
79 long buflen = ((audiobufend - audiobuf) * 2) / 2097; /* avoid overflow */
80 int key;
81 int i;
82 bool done = false;
83 bool new_info = true;
84 #ifdef HAVE_MULTIVOLUME
85 char s2[32];
86 unsigned long size2, free2;
87 #endif
88 #ifdef HAVE_LCD_CHARCELLS
89 int page = 0;
90 #endif
92 const unsigned char *kbyte_units[] = {
93 ID2P(LANG_KILOBYTE),
94 ID2P(LANG_MEGABYTE),
95 ID2P(LANG_GIGABYTE)
98 while (!done)
100 int y=0;
102 if (new_info)
104 fat_size( IF_MV2(0,) &size, &free );
105 #ifdef HAVE_MULTIVOLUME
106 if (fat_ismounted(1))
107 fat_size( 1, &size2, &free2 );
108 else
109 size2 = 0;
110 #endif
112 if (global_settings.talk_menu)
113 { /* say whatever is reasonable, no real connection to the screen */
114 bool enqueue = false; /* enqueue all but the first */
115 if (battery_level() >= 0)
117 talk_id(LANG_BATTERY_TIME, enqueue);
118 enqueue = true;
119 talk_value(battery_level(), UNIT_PERCENT, true);
120 #if CONFIG_CHARGING >= CHARGING_MONITOR
121 if (charge_state == CHARGING)
122 talk_id(LANG_BATTERY_CHARGE, true);
123 else if (charge_state == TOPOFF)
124 talk_id(LANG_BATTERY_TOPOFF_CHARGE, true);
125 else if (charge_state == TRICKLE)
126 talk_id(LANG_BATTERY_TRICKLE_CHARGE, true);
127 #endif
130 talk_id(LANG_DISK_FREE_INFO, enqueue);
131 #ifdef HAVE_MULTIVOLUME
132 talk_id(LANG_DISK_NAME_INTERNAL, true);
133 output_dyn_value(NULL, 0, free, kbyte_units, true);
134 if (size2)
136 talk_id(LANG_DISK_NAME_MMC, true);
137 output_dyn_value(NULL, 0, free2, kbyte_units, true);
139 #else
140 output_dyn_value(NULL, 0, free, kbyte_units, true);
141 #endif
143 #ifdef CONFIG_RTC
145 struct tm* tm = get_time();
146 talk_id(VOICE_CURRENT_TIME, true);
147 talk_value(tm->tm_hour, UNIT_HOUR, true);
148 talk_value(tm->tm_min, UNIT_MIN, true);
149 talk_value(tm->tm_sec, UNIT_SEC, true);
150 talk_id(LANG_MONTH_JANUARY + tm->tm_mon, true);
151 talk_number(tm->tm_mday, true);
152 talk_number(1900 + tm->tm_year, true);
154 #endif
156 new_info = false;
159 FOR_NB_SCREENS(i)
161 screens[i].clear_display();
162 #ifdef HAVE_LCD_BITMAP
163 screens[i].puts(0, y, str(LANG_ROCKBOX_INFO));
164 #endif
166 #ifdef HAVE_LCD_BITMAP
167 y += 2;
168 #endif
170 #ifdef HAVE_LCD_CHARCELLS
171 if (page == 0)
172 #endif
174 int integer = buflen / 1000;
175 int decimal = buflen % 1000;
177 #ifdef HAVE_LCD_CHARCELLS
178 snprintf(s, sizeof(s), (char *)str(LANG_BUFFER_STAT_PLAYER),
179 integer, decimal);
180 #else
181 snprintf(s, sizeof(s), (char *)str(LANG_BUFFER_STAT_RECORDER),
182 integer, decimal);
183 #endif
184 FOR_NB_SCREENS(i)
185 screens[i].puts_scroll(0, y, (unsigned char *)s);
186 y++;
187 #if CONFIG_CHARGING == CHARGING_CONTROL
188 if (charge_state == CHARGING)
189 snprintf(s, sizeof(s), (char *)str(LANG_BATTERY_CHARGE));
190 else if (charge_state == TOPOFF)
191 snprintf(s, sizeof(s), (char *)str(LANG_BATTERY_TOPOFF_CHARGE));
192 else if (charge_state == TRICKLE)
193 snprintf(s, sizeof(s), (char *)str(LANG_BATTERY_TRICKLE_CHARGE));
194 else
195 #endif
196 if (battery_level() >= 0)
197 snprintf(s, sizeof(s), (char *)str(LANG_BATTERY_TIME), battery_level(),
198 battery_time() / 60, battery_time() % 60);
199 else
200 strncpy(s, "(n/a)", sizeof(s));
201 FOR_NB_SCREENS(i)
202 screens[i].puts_scroll(0, y, (unsigned char *)s);
203 y++;
206 #ifdef HAVE_LCD_CHARCELLS
207 if (page == 1)
208 #endif
210 #ifdef HAVE_MULTIVOLUME
211 output_dyn_value(s1, sizeof s1, free, kbyte_units, true);
212 output_dyn_value(s2, sizeof s2, size, kbyte_units, true);
213 snprintf(s, sizeof s, "%s %s/%s", str(LANG_DISK_NAME_INTERNAL),
214 s1, s2);
215 FOR_NB_SCREENS(i)
216 screens[i].puts_scroll(0, y, (unsigned char *)s);
217 y++;
219 if (size2) {
220 output_dyn_value(s1, sizeof s1, free2, kbyte_units, true);
221 output_dyn_value(s2, sizeof s2, size2, kbyte_units, true);
222 snprintf(s, sizeof s, "%s %s/%s", str(LANG_DISK_NAME_MMC),
223 s1, s2);
224 FOR_NB_SCREENS(i)
225 screens[i].puts_scroll(0, y, (unsigned char *)s);
226 y++;
228 #else
229 output_dyn_value(s1, sizeof s1, size, kbyte_units, true);
230 snprintf(s, sizeof s, SIZE_FMT, str(LANG_DISK_SIZE_INFO), s1);
231 FOR_NB_SCREENS(i)
232 screens[i].puts_scroll(0, y, (unsigned char *)s);
233 y++;
234 output_dyn_value(s1, sizeof s1, free, kbyte_units, true);
235 snprintf(s, sizeof s, SIZE_FMT, str(LANG_DISK_FREE_INFO), s1);
236 FOR_NB_SCREENS(i)
237 screens[i].puts_scroll(0, y, (unsigned char *)s);
238 y++;
239 #endif
242 #if defined(HAVE_LCD_BITMAP) || defined(SIMULATOR)
243 FOR_NB_SCREENS(i)
244 screens[i].update();
245 #endif
247 /* Wait for a key to be pushed */
248 key = get_action(CONTEXT_MAINMENU,HZ*5);
249 switch(key) {
251 case ACTION_STD_CANCEL:
252 done = true;
253 break;
255 #ifdef HAVE_LCD_CHARCELLS
256 case ACTION_STD_NEXT:
257 case ACTION_STD_PREV:
258 page = (page == 0) ? 1 : 0;
259 break;
260 #endif
262 #ifndef SIMULATOR
263 case ACTION_STD_OK:
264 gui_syncsplash(0, true, str(LANG_DIRCACHE_BUILDING));
265 fat_recalc_free(IF_MV(0));
266 #ifdef HAVE_MULTIVOLUME
267 if (fat_ismounted(1))
268 fat_recalc_free(1);
269 #endif
270 new_info = true;
271 break;
272 #endif
274 default:
275 if (default_event_handler(key) == SYS_USB_CONNECTED)
276 return true;
277 break;
280 action_signalscreenchange();
281 return false;
284 static bool plugin_browse(void)
286 return rockbox_browse(PLUGIN_DIR, SHOW_PLUGINS);
289 static bool custom_theme_browse(void)
291 return rockbox_browse(THEME_DIR, SHOW_CFG);
294 #ifdef HAVE_RECORDING
296 static bool rec_menu_recording_screen(void)
298 return recording_screen(false);
301 static bool recording_settings(void)
303 bool ret;
304 #ifdef HAVE_FMRADIO_IN
305 int rec_source = global_settings.rec_source;
306 #endif
308 ret = recording_menu(false);
310 #ifdef HAVE_FMRADIO_IN
311 if (rec_source != global_settings.rec_source)
313 if (rec_source == AUDIO_SRC_FMRADIO)
314 radio_stop();
315 /* If AUDIO_SRC_FMRADIO was selected from something else,
316 the recording screen will start the radio */
318 #endif
320 return ret;
323 bool rec_menu(void)
325 int m;
326 bool result;
328 /* recording menu */
329 static const struct menu_item items[] = {
330 { ID2P(LANG_RECORDING_MENU), rec_menu_recording_screen },
331 { ID2P(LANG_RECORDING_SETTINGS), recording_settings},
334 m=menu_init( items, sizeof(items) / sizeof(*items), NULL,
335 NULL, NULL, NULL);
336 result = menu_run(m);
337 menu_exit(m);
339 return result;
341 #endif
343 bool info_menu(void)
345 int m;
346 bool result;
348 /* info menu */
349 static const struct menu_item items[] = {
350 { ID2P(LANG_INFO_MENU), show_info },
351 { ID2P(LANG_VERSION), show_credits },
352 { ID2P(LANG_DEBUG), debug_menu },
353 #ifdef SIMULATOR
354 { ID2P(LANG_USB), simulate_usb },
355 #ifdef ROCKBOX_HAS_LOGF
356 {"logf", logfdisplay },
357 {"logfdump", logfdump },
358 #endif
359 #endif
362 m=menu_init( items, sizeof(items) / sizeof(*items), NULL,
363 NULL, NULL, NULL);
364 result = menu_run(m);
365 menu_exit(m);
367 return result;
370 #ifdef HAVE_LCD_CHARCELLS
371 static bool do_shutdown(void)
373 sys_poweroff();
374 return false;
376 #endif
378 bool main_menu(void)
380 int m;
381 bool result;
382 int i = 0;
384 /* main menu */
385 struct menu_item items[11];
387 items[i].desc = ID2P(LANG_BOOKMARK_MENU_RECENT_BOOKMARKS);
388 items[i++].function = bookmark_mrb_load;
390 items[i].desc = ID2P(LANG_SOUND_SETTINGS);
391 items[i++].function = sound_menu;
393 items[i].desc = ID2P(LANG_GENERAL_SETTINGS);
394 items[i++].function = settings_menu;
396 items[i].desc = ID2P(LANG_MANAGE_MENU);
397 items[i++].function = manage_settings_menu;
399 items[i].desc = ID2P(LANG_CUSTOM_THEME);
400 items[i++].function = custom_theme_browse;
402 #ifdef CONFIG_TUNER
403 if(radio_hardware_present()) {
404 items[i].desc = ID2P(LANG_FM_RADIO);
405 items[i++].function = radio_screen;
407 #endif
409 #ifdef HAVE_RECORDING
410 items[i].desc = ID2P(LANG_RECORDING);
411 items[i++].function = rec_menu;
412 #endif
414 items[i].desc = ID2P(LANG_PLAYLIST_MENU);
415 items[i++].function = playlist_menu;
417 items[i].desc = ID2P(LANG_PLUGINS);
418 items[i++].function = plugin_browse;
420 items[i].desc = ID2P(LANG_INFO);
421 items[i++].function = info_menu;
423 #ifdef HAVE_LCD_CHARCELLS
424 items[i].desc = ID2P(LANG_SHUTDOWN);
425 items[i++].function = do_shutdown;
426 #endif
428 m=menu_init( items, i, NULL, NULL, NULL, NULL );
429 #ifdef HAVE_LCD_CHARCELLS
430 status_set_param(true);
431 #endif
432 result = menu_run(m);
433 #ifdef HAVE_LCD_CHARCELLS
434 status_set_param(false);
435 #endif
436 menu_exit(m);
438 settings_save();
439 return result;
442 /* -----------------------------------------------------------------
443 * vim: et sw=4 ts=8 sts=4 tw=78