Add AAC audio type
[Rockbox.git] / apps / main_menu.c
blobf76c211f0aa8d89a880b517ce3b8b5c0e0a959c0
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 "button.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"
54 #ifdef HAVE_RECORDING
55 #include "recording.h"
56 #endif
58 #ifdef HAVE_REMOTE_LCD
59 #include "lcd-remote.h"
60 #endif
62 bool show_credits(void)
64 plugin_load("/.rockbox/rocks/credits.rock",NULL);
65 return false;
68 #ifdef SIMULATOR
69 extern bool simulate_usb(void);
70 #endif
72 #ifdef HAVE_LCD_CHARCELLS
73 #define SIZE_FMT "%s%s"
74 #else
75 #define SIZE_FMT "%s %s"
76 #endif
78 bool show_info(void)
80 char s[32], s1[32];
81 long buflen = ((audiobufend - audiobuf) * 2) / 2097; /* avoid overflow */
82 int integer, decimal;
83 bool done = false;
84 int key;
85 int state = 1;
86 unsigned long size, free;
87 #ifdef HAVE_MULTIVOLUME
88 char s2[32];
89 unsigned long size2 = 0;
90 unsigned long free2 = 0;
91 #endif
93 const unsigned char *kbyte_units[] = {
94 ID2P(LANG_KILOBYTE),
95 ID2P(LANG_MEGABYTE),
96 ID2P(LANG_GIGABYTE)
99 fat_size( IF_MV2(0,) &size, &free );
100 #ifdef HAVE_MULTIVOLUME
101 if (fat_ismounted(1))
102 fat_size( 1, &size2, &free2 );
103 #endif
105 if (global_settings.talk_menu)
106 { /* say whatever is reasonable, no real connection to the screen */
107 bool enqueue = false; /* enqueue all but the first */
108 if (battery_level() >= 0)
110 talk_id(LANG_BATTERY_TIME, enqueue);
111 enqueue = true;
112 talk_value(battery_level(), UNIT_PERCENT, true);
115 talk_id(LANG_DISK_FREE_INFO, enqueue);
116 #ifdef HAVE_MULTIVOLUME
117 talk_id(LANG_DISK_NAME_INTERNAL, true);
118 output_dyn_value(NULL, 0, free, kbyte_units, true);
119 if (size2)
121 talk_id(LANG_DISK_NAME_MMC, true);
122 output_dyn_value(NULL, 0, free2, kbyte_units, true);
124 #else
125 output_dyn_value(NULL, 0, free, kbyte_units, true); /* NULL == talk */
126 #endif
128 #ifdef HAVE_RTC
130 struct tm* tm = get_time();
131 talk_id(VOICE_CURRENT_TIME, true);
132 talk_value(tm->tm_hour, UNIT_HOUR, true);
133 talk_value(tm->tm_min, UNIT_MIN, true);
134 talk_value(tm->tm_sec, UNIT_SEC, true);
135 talk_id(LANG_MONTH_JANUARY + tm->tm_mon, true);
136 talk_number(tm->tm_mday, true);
137 talk_number(1900 + tm->tm_year, true);
139 #endif
142 while(!done)
144 int y=0;
145 lcd_clear_display();
146 #ifdef HAVE_LCD_BITMAP
147 lcd_puts(0, y++, str(LANG_ROCKBOX_INFO));
148 y++;
149 state = 3;
150 #endif
152 if (state & 1) {
153 integer = buflen / 1000;
154 decimal = buflen % 1000;
155 #ifdef HAVE_LCD_CHARCELLS
156 snprintf(s, sizeof(s), str(LANG_BUFFER_STAT_PLAYER),
157 integer, decimal);
158 #else
159 snprintf(s, sizeof(s), str(LANG_BUFFER_STAT_RECORDER),
160 integer, decimal);
161 #endif
162 lcd_puts(0, y++, s);
164 #ifdef HAVE_CHARGE_CTRL
165 if (charge_state == 1)
166 snprintf(s, sizeof(s), str(LANG_BATTERY_CHARGE));
167 else if (charge_state == 2)
168 snprintf(s, sizeof(s), str(LANG_BATTERY_TOPOFF_CHARGE));
169 else if (charge_state == 3)
170 snprintf(s, sizeof(s), str(LANG_BATTERY_TRICKLE_CHARGE));
171 else
172 #endif
173 if (battery_level() >= 0)
174 snprintf(s, sizeof(s), str(LANG_BATTERY_TIME), battery_level(),
175 battery_time() / 60, battery_time() % 60);
176 else
177 strncpy(s, "(n/a)", sizeof(s));
178 lcd_puts(0, y++, s);
181 if (state & 2) {
182 #ifdef HAVE_MULTIVOLUME
183 output_dyn_value(s1, sizeof s1, free, kbyte_units, true);
184 output_dyn_value(s2, sizeof s2, size, kbyte_units, true);
185 snprintf(s, sizeof s, "%s %s/%s", str(LANG_DISK_NAME_INTERNAL),
186 s1, s2);
187 #else
188 output_dyn_value(s1, sizeof s1, size, kbyte_units, true);
189 snprintf(s, sizeof s, SIZE_FMT, str(LANG_DISK_SIZE_INFO), s1);
190 #endif
191 lcd_puts(0, y++, s);
193 #ifdef HAVE_MULTIVOLUME
194 if (size2) {
195 output_dyn_value(s1, sizeof s1, free2, kbyte_units, true);
196 output_dyn_value(s2, sizeof s2, size2, kbyte_units, true);
197 snprintf(s, sizeof s, "%s %s/%s", str(LANG_DISK_NAME_MMC),
198 s1, s2);
199 lcd_puts(0, y++, s);
201 #else
202 output_dyn_value(s1, sizeof s1, free, kbyte_units, true);
203 snprintf(s, sizeof s, SIZE_FMT, str(LANG_DISK_FREE_INFO), s1);
204 lcd_puts(0, y++, s);
205 #endif
207 lcd_update();
209 /* Wait for a key to be pushed */
210 key = button_get_w_tmo(HZ*5);
211 switch(key) {
213 case SETTINGS_OK:
214 #ifdef SETTINGS_OK2
215 case SETTINGS_OK2:
216 #endif
217 case SETTINGS_CANCEL:
218 done = true;
219 break;
221 case SETTINGS_INC:
222 case SETTINGS_DEC:
223 if (state == 1)
224 state = 2;
225 else
226 state = 1;
227 break;
229 default:
230 if(default_event_handler(key) == SYS_USB_CONNECTED)
231 return true;
232 break;
236 return false;
239 static bool plugin_browse(void)
241 return rockbox_browse(PLUGIN_DIR, SHOW_PLUGINS);
244 #ifdef HAVE_RECORDING
246 static bool recording_settings(void)
248 return recording_menu(false);
251 bool rec_menu(void)
253 int m;
254 bool result;
256 /* recording menu */
257 static const struct menu_item items[] = {
258 { ID2P(LANG_RECORDING_MENU), recording_screen },
259 { ID2P(LANG_RECORDING_SETTINGS), recording_settings},
262 m=menu_init( items, sizeof(items) / sizeof(*items), NULL,
263 NULL, NULL, NULL);
264 result = menu_run(m);
265 menu_exit(m);
267 return result;
269 #endif
271 bool info_menu(void)
273 int m;
274 bool result;
276 /* info menu */
277 static const struct menu_item items[] = {
278 { ID2P(LANG_INFO_MENU), show_info },
279 { ID2P(LANG_VERSION), show_credits },
280 #ifndef SIMULATOR
281 { ID2P(LANG_DEBUG), debug_menu },
282 #else
283 { ID2P(LANG_USB), simulate_usb },
284 #ifdef ROCKBOX_HAS_LOGF
285 {"logf", logfdisplay },
286 {"logfdump", logfdump },
287 #endif
288 #endif
291 m=menu_init( items, sizeof(items) / sizeof(*items), NULL,
292 NULL, NULL, NULL);
293 result = menu_run(m);
294 menu_exit(m);
296 return result;
299 #ifdef HAVE_LCD_CHARCELLS
300 static bool do_shutdown(void)
302 sys_poweroff();
303 return false;
305 #endif
307 bool main_menu(void)
309 int m;
310 bool result;
311 int i = 0;
313 /* main menu */
314 struct menu_item items[10];
316 items[i].desc = ID2P(LANG_BOOKMARK_MENU_RECENT_BOOKMARKS);
317 items[i++].function = bookmark_mrb_load;
319 items[i].desc = ID2P(LANG_SOUND_SETTINGS);
320 items[i++].function = sound_menu;
322 items[i].desc = ID2P(LANG_GENERAL_SETTINGS);
323 items[i++].function = settings_menu;
325 items[i].desc = ID2P(LANG_MANAGE_MENU);
326 items[i++].function = manage_settings_menu;
328 #ifdef CONFIG_TUNER
329 if(radio_hardware_present()) {
330 items[i].desc = ID2P(LANG_FM_RADIO);
331 items[i++].function = radio_screen;
333 #endif
335 #ifdef HAVE_RECORDING
336 items[i].desc = ID2P(LANG_RECORDING);
337 items[i++].function = rec_menu;
338 #endif
340 items[i].desc = ID2P(LANG_PLAYLIST_MENU);
341 items[i++].function = playlist_menu;
343 items[i].desc = ID2P(LANG_PLUGINS);
344 items[i++].function = plugin_browse;
346 items[i].desc = ID2P(LANG_INFO);
347 items[i++].function = info_menu;
349 #ifdef HAVE_LCD_CHARCELLS
350 items[i].desc = ID2P(LANG_SHUTDOWN);
351 items[i++].function = do_shutdown;
352 #endif
354 m=menu_init( items, i, NULL, NULL, NULL, NULL );
355 #ifdef HAVE_LCD_CHARCELLS
356 status_set_param(true);
357 #endif
358 result = menu_run(m);
359 #ifdef HAVE_LCD_CHARCELLS
360 status_set_param(false);
361 #endif
362 menu_exit(m);
364 settings_save();
365 return result;
368 /* -----------------------------------------------------------------
369 * vim: et sw=4 ts=8 sts=4 tw=78