A bit of indentation/whitespace changes in the xml files.
[kugel-rb.git] / apps / menus / main_menu.c
blob54fdb55b093787d889d576f03aaea1fe0cfcd914
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2007 Jonathan Gordon
12 * 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.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include <stdbool.h>
23 #include <stddef.h>
24 #include <limits.h>
25 #include "config.h"
26 #include "string.h"
27 #include "lang.h"
28 #include "action.h"
29 #include "settings.h"
30 #include "power.h"
31 #include "powermgmt.h"
32 #include "menu.h"
33 #include "misc.h"
34 #include "exported_menus.h"
35 #include "tree.h"
36 #include "storage.h"
37 #ifdef HAVE_RECORDING
38 #include "recording.h"
39 #endif
40 #include "yesno.h"
41 #include "keyboard.h"
42 #include "screens.h"
43 #include "plugin.h"
44 #include "talk.h"
45 #include "buffer.h"
46 #include "splash.h"
47 #include "debug_menu.h"
48 #include "version.h"
49 #include "time.h"
50 #include "wps.h"
51 #include "skin_buffer.h"
53 static const struct browse_folder_info config = {ROCKBOX_DIR, SHOW_CFG};
55 /***********************************/
56 /* MANAGE SETTINGS MENU */
58 static int reset_settings(void)
60 static const char *lines[]={ID2P(LANG_RESET_ASK)};
61 static const char *yes_lines[]={
62 ID2P(LANG_SETTINGS),
63 ID2P(LANG_RESET_DONE_CLEAR)
65 static const char *no_lines[]={
66 ID2P(LANG_SETTINGS),
67 ID2P(LANG_CANCEL)
69 static const struct text_message message={lines, 1};
70 static const struct text_message yes_message={yes_lines, 2};
71 static const struct text_message no_message={no_lines, 2};
73 switch(gui_syncyesno_run(&message, &yes_message, &no_message))
75 case YESNO_YES:
76 settings_reset();
77 settings_save();
78 settings_apply(true);
79 settings_apply_skins();
80 break;
81 case YESNO_NO:
82 break;
83 case YESNO_USB:
84 return 1;
86 return 0;
88 static int write_settings_file(void* param)
90 return settings_save_config((intptr_t)param);
93 MENUITEM_FUNCTION(browse_configs, MENU_FUNC_USEPARAM, ID2P(LANG_CUSTOM_CFG),
94 browse_folder, (void*)&config, NULL, Icon_NOICON);
95 MENUITEM_FUNCTION(save_settings_item, MENU_FUNC_USEPARAM, ID2P(LANG_SAVE_SETTINGS),
96 write_settings_file, (void*)SETTINGS_SAVE_ALL, NULL, Icon_NOICON);
97 MENUITEM_FUNCTION(save_theme_item, MENU_FUNC_USEPARAM, ID2P(LANG_SAVE_THEME),
98 write_settings_file, (void*)SETTINGS_SAVE_THEME, NULL, Icon_NOICON);
99 MENUITEM_FUNCTION(save_sound_item, MENU_FUNC_USEPARAM, ID2P(LANG_SAVE_SOUND),
100 write_settings_file, (void*)SETTINGS_SAVE_SOUND, NULL, Icon_NOICON);
101 MENUITEM_FUNCTION(reset_settings_item, 0, ID2P(LANG_RESET),
102 reset_settings, NULL, NULL, Icon_NOICON);
104 MAKE_MENU(manage_settings, ID2P(LANG_MANAGE_MENU), NULL, Icon_Config,
105 &browse_configs, &reset_settings_item,
106 &save_settings_item, &save_sound_item, &save_theme_item);
107 /* MANAGE SETTINGS MENU */
108 /**********************************/
110 /***********************************/
111 /* INFO MENU */
114 static bool show_credits(void)
116 char credits[MAX_PATH] = { '\0' };
117 snprintf(credits, MAX_PATH, "%s/credits.rock", VIEWERS_DIR);
118 if (plugin_load(credits, NULL) != PLUGIN_OK)
120 /* show the rockbox logo and version untill a button is pressed */
121 show_logo();
122 while (IS_SYSEVENT(get_action(CONTEXT_STD, TIMEOUT_BLOCK)))
125 return false;
128 #ifdef HAVE_LCD_CHARCELLS
129 #define SIZE_FMT "%s%s"
130 #else
131 #define SIZE_FMT "%s %s"
132 #endif
133 struct info_data
136 bool new_data;
137 unsigned long size;
138 unsigned long free;
139 #ifdef HAVE_MULTIVOLUME
140 unsigned long size2;
141 unsigned long free2;
142 #endif
144 enum infoscreenorder
146 INFO_BATTERY = 0,
147 INFO_DISK1, /* capacity or internal capacity/free on hotswap */
148 INFO_DISK2, /* free space or external capacity/free on hotswap */
149 INFO_BUFFER,
150 #ifndef APPLICATION
151 INFO_SKIN_USAGE, /* ram usage of the skins */
152 #endif
153 INFO_VERSION,
154 INFO_COUNT
157 static const char* info_getname(int selected_item, void *data,
158 char *buffer, size_t buffer_len)
160 struct info_data *info = (struct info_data*)data;
161 char s1[32];
162 #if defined(HAVE_MULTIVOLUME) || !defined(APPLICATION)
163 char s2[32];
164 #endif
165 if (info->new_data)
167 fat_size(IF_MV2(0,) &info->size, &info->free);
168 #ifdef HAVE_MULTIVOLUME
169 if (fat_ismounted(1))
170 fat_size(1, &info->size2, &info->free2);
171 else
172 info->size2 = 0;
173 #endif
174 info->new_data = false;
176 switch (selected_item)
178 case INFO_VERSION:
179 snprintf(buffer, buffer_len, "%s: %s",
180 str(LANG_VERSION), rbversion);
181 break;
183 case INFO_BUFFER: /* buffer */
185 long kib = (audiobufend - audiobuf) / 1024; /* to KiB */
186 output_dyn_value(s1, sizeof(s1), kib, kbyte_units, true);
187 snprintf(buffer, buffer_len, "%s %s", str(LANG_BUFFER_STAT), s1);
189 break;
190 case INFO_BATTERY: /* battery */
191 #if CONFIG_CHARGING == CHARGING_SIMPLE
192 /* Only know if plugged */
193 if (charger_inserted())
194 return str(LANG_BATTERY_CHARGE);
195 else
196 #elif CONFIG_CHARGING >= CHARGING_MONITOR
197 #ifdef ARCHOS_RECORDER
198 /* Report the particular algorithm state */
199 if (charge_state == CHARGING)
200 return str(LANG_BATTERY_CHARGE);
201 else if (charge_state == TOPOFF)
202 return str(LANG_BATTERY_TOPOFF_CHARGE);
203 else if (charge_state == TRICKLE)
204 return str(LANG_BATTERY_TRICKLE_CHARGE);
205 else
206 #else /* !ARCHOS_RECORDER */
207 /* Go by what power management reports */
208 if (charging_state())
209 return str(LANG_BATTERY_CHARGE);
210 else
211 #endif /* ARCHOS_RECORDER */
212 #endif /* CONFIG_CHARGING = */
213 if (battery_level() >= 0)
214 snprintf(buffer, buffer_len, str(LANG_BATTERY_TIME),
215 battery_level(), battery_time() / 60, battery_time() % 60);
216 else
217 return "(n/a)";
218 break;
219 case INFO_DISK1: /* disk usage 1 */
220 #ifdef HAVE_MULTIVOLUME
221 output_dyn_value(s1, sizeof s1, info->free, kbyte_units, true);
222 output_dyn_value(s2, sizeof s2, info->size, kbyte_units, true);
223 snprintf(buffer, buffer_len, "%s %s/%s", str(LANG_DISK_NAME_INTERNAL),
224 s1, s2);
225 #else
226 output_dyn_value(s1, sizeof s1, info->free, kbyte_units, true);
227 snprintf(buffer, buffer_len, SIZE_FMT, str(LANG_DISK_FREE_INFO), s1);
228 #endif
229 break;
230 case INFO_DISK2: /* disk usage 2 */
231 #ifdef HAVE_MULTIVOLUME
232 if (info->size2)
234 output_dyn_value(s1, sizeof s1, info->free2, kbyte_units, true);
235 output_dyn_value(s2, sizeof s2, info->size2, kbyte_units, true);
236 snprintf(buffer, buffer_len, "%s %s/%s", str(LANG_DISK_NAME_MMC),
237 s1, s2);
239 else
241 snprintf(buffer, buffer_len, "%s %s", str(LANG_DISK_NAME_MMC),
242 str(LANG_NOT_PRESENT));
244 #else
245 output_dyn_value(s1, sizeof s1, info->size, kbyte_units, true);
246 snprintf(buffer, buffer_len, SIZE_FMT, str(LANG_DISK_SIZE_INFO), s1);
247 #endif
248 break;
249 #ifndef APPLICATION
250 case INFO_SKIN_USAGE:
251 output_dyn_value(s1, sizeof s1, skin_buffer_usage(), byte_units, true);
252 output_dyn_value(s2, sizeof s2, skin_buffer_usage()
253 +skin_buffer_freespace(), byte_units, true);
254 snprintf(buffer, buffer_len, "%s %s / %s", str(LANG_SKIN_RAM_USAGE), s1, s2);
255 break;
256 #endif
258 return buffer;
261 static int info_speak_item(int selected_item, void * data)
263 struct info_data *info = (struct info_data*)data;
265 switch (selected_item)
267 case INFO_VERSION: /* version */
268 talk_id(LANG_VERSION, false);
269 talk_spell(rbversion, true);
270 break;
272 case INFO_BUFFER: /* buffer */
274 talk_id(LANG_BUFFER_STAT, false);
275 long kib = (audiobufend - audiobuf) / 1024; /* to KiB */
276 output_dyn_value(NULL, 0, kib, kbyte_units, true);
277 break;
279 case INFO_BATTERY: /* battery */
280 #if CONFIG_CHARGING == CHARGING_SIMPLE
281 /* Only know if plugged */
282 if (charger_inserted())
283 talk_id(LANG_BATTERY_CHARGE, true);
284 else
285 #elif CONFIG_CHARGING >= CHARGING_MONITOR
286 #ifdef ARCHOS_RECORDER
287 /* Report the particular algorithm state */
288 if (charge_state == CHARGING)
289 talk_id(LANG_BATTERY_CHARGE, true);
290 else if (charge_state == TOPOFF)
291 talk_id(LANG_BATTERY_TOPOFF_CHARGE, true);
292 else if (charge_state == TRICKLE)
293 talk_id(LANG_BATTERY_TRICKLE_CHARGE, true);
294 else
295 #else /* !ARCHOS_RECORDER */
296 /* Go by what power management reports */
297 if (charging_state())
298 talk_id(LANG_BATTERY_CHARGE, true);
299 else
300 #endif /* ARCHOS_RECORDER */
301 #endif /* CONFIG_CHARGING = */
302 if (battery_level() >= 0)
304 talk_id(LANG_BATTERY_TIME, false);
305 talk_value(battery_level(), UNIT_PERCENT, true);
306 talk_value(battery_time() *60, UNIT_TIME, true);
308 else talk_id(VOICE_BLANK, false);
309 break;
310 case INFO_DISK1: /* disk 1 */
311 #ifdef HAVE_MULTIVOLUME
312 talk_ids(false, LANG_DISK_NAME_INTERNAL, LANG_DISK_FREE_INFO);
313 output_dyn_value(NULL, 0, info->free, kbyte_units, true);
314 talk_id(LANG_DISK_SIZE_INFO, true);
315 output_dyn_value(NULL, 0, info->size, kbyte_units, true);
316 #else
317 talk_id(LANG_DISK_FREE_INFO, false);
318 output_dyn_value(NULL, 0, info->free, kbyte_units, true);
319 #endif
320 break;
321 case INFO_DISK2: /* disk 2 */
322 #ifdef HAVE_MULTIVOLUME
323 talk_id(LANG_DISK_NAME_MMC, false);
324 if (info->size2)
326 talk_id(LANG_DISK_FREE_INFO, true);
327 output_dyn_value(NULL, 0, info->free2, kbyte_units, true);
328 talk_id(LANG_DISK_SIZE_INFO, true);
329 output_dyn_value(NULL, 0, info->size2, kbyte_units, true);
331 else talk_id(LANG_NOT_PRESENT, true);
332 #else
333 talk_id(LANG_DISK_SIZE_INFO, false);
334 output_dyn_value(NULL, 0, info->size, kbyte_units, true);
335 #endif
336 break;
337 #ifndef APPLICATION
338 case INFO_SKIN_USAGE:
339 talk_id(LANG_SKIN_RAM_USAGE, false);
340 output_dyn_value(NULL, 0, skin_buffer_usage(), byte_units, true);
341 break;
342 #endif
345 return 0;
348 static int info_action_callback(int action, struct gui_synclist *lists)
350 if (action == ACTION_STD_CANCEL)
351 return action;
352 else if ((action == ACTION_STD_OK)
353 #ifdef HAVE_HOTSWAP
354 || action == SYS_FS_CHANGED
355 #endif
358 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
359 struct info_data *info = (struct info_data *)lists->data;
360 int i;
361 info->new_data = true;
362 splash(0, ID2P(LANG_SCANNING_DISK));
363 for (i = 0; i < NUM_VOLUMES; i++)
365 #ifdef HAVE_HOTSWAP
366 if (fat_ismounted(i))
367 #endif
368 fat_recalc_free(IF_MV(i));
370 #else
371 (void) lists;
372 #endif
373 gui_synclist_speak_item(lists);
374 return ACTION_REDRAW;
376 return action;
378 static bool show_info(void)
380 struct info_data data = {.new_data = true };
381 struct simplelist_info info;
382 simplelist_info_init(&info, str(LANG_ROCKBOX_INFO), INFO_COUNT, (void*)&data);
383 info.hide_selection = !global_settings.talk_menu;
384 if (info.hide_selection)
385 info.scroll_all = true;
386 info.get_name = info_getname;
387 if(global_settings.talk_menu)
388 info.get_talk = info_speak_item;
389 info.action_callback = info_action_callback;
390 return simplelist_show_list(&info);
392 MENUITEM_FUNCTION(show_info_item, 0, ID2P(LANG_ROCKBOX_INFO),
393 (menu_function)show_info, NULL, NULL, Icon_NOICON);
396 /* sleep Menu */
397 static const char* sleep_timer_formatter(char* buffer, size_t buffer_size,
398 int value, const char* unit)
400 (void) unit;
401 int minutes, hours;
403 if (value) {
404 hours = value / 60;
405 minutes = value - (hours * 60);
406 snprintf(buffer, buffer_size, "%d:%02d", hours, minutes);
407 return buffer;
408 } else {
409 return str(LANG_OFF);
413 static void sleep_timer_set(int minutes)
415 set_sleep_timer(minutes * 60);
418 static int sleep_timer(void)
420 int minutes = (get_sleep_timer() + 59) / 60; /* round up */
421 return (int)set_int(str(LANG_SLEEP_TIMER), "", UNIT_MIN, &minutes,
422 &sleep_timer_set, -5, 300, 0, sleep_timer_formatter);
426 #if CONFIG_RTC
427 int time_screen(void* ignored);
428 MENUITEM_FUNCTION(timedate_item, MENU_FUNC_CHECK_RETVAL, ID2P(LANG_TIME_MENU),
429 time_screen, NULL, NULL, Icon_Menu_setting );
430 #endif
431 /* This item is in the time/date screen if there is a RTC */
432 MENUITEM_FUNCTION(sleep_timer_call, 0, ID2P(LANG_SLEEP_TIMER), sleep_timer,
433 NULL, NULL, Icon_Menu_setting); /* make it look like a
434 setting to the user */
436 MENUITEM_FUNCTION(show_credits_item, 0, ID2P(LANG_CREDITS),
437 (menu_function)show_credits, NULL, NULL, Icon_NOICON);
438 MENUITEM_FUNCTION(show_runtime_item, 0, ID2P(LANG_RUNNING_TIME),
439 (menu_function)view_runtime, NULL, NULL, Icon_NOICON);
440 MENUITEM_FUNCTION(debug_menu_item, 0, ID2P(LANG_DEBUG),
441 (menu_function)debug_menu, NULL, NULL, Icon_NOICON);
443 MAKE_MENU(info_menu, ID2P(LANG_SYSTEM), 0, Icon_System_menu,
444 #if CONFIG_RTC
445 &timedate_item,
446 #endif
447 &show_info_item, &show_credits_item, &show_runtime_item,
448 #if CONFIG_RTC == 0
449 &sleep_timer_call,
450 #endif
451 &debug_menu_item);
452 /* INFO MENU */
453 /***********************************/
455 /***********************************/
456 /* MAIN MENU */
459 #ifdef HAVE_LCD_CHARCELLS
460 static int mainmenu_callback(int action,const struct menu_item_ex *this_item)
462 (void)this_item;
463 switch (action)
465 case ACTION_ENTER_MENUITEM:
466 status_set_param(true);
467 break;
468 case ACTION_EXIT_MENUITEM:
469 status_set_param(false);
470 break;
472 return action;
474 #else
475 #define mainmenu_callback NULL
476 #endif
477 MAKE_MENU(main_menu_, ID2P(LANG_SETTINGS), mainmenu_callback,
478 Icon_Submenu_Entered,
479 &sound_settings,
480 &playback_settings,
481 &settings_menu_item, &theme_menu,
482 #ifdef HAVE_RECORDING
483 &recording_settings,
484 #endif
485 &manage_settings,
487 /* MAIN MENU */
488 /***********************************/