revert unrelated app.lds change
[kugel-rb.git] / apps / menus / main_menu.c
blob32164ff3e005119d23951d5c0f75f2ff389333f9
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 #if defined(SIMULATOR) && defined(ROCKBOX_HAS_LOGF)
49 #include "logfdisp.h"
50 #endif
51 #include "version.h"
52 #include "time.h"
53 #include "wps.h"
54 #include "skin_engine/skin_buffer.h"
56 static const struct browse_folder_info config = {ROCKBOX_DIR, SHOW_CFG};
58 /***********************************/
59 /* MANAGE SETTINGS MENU */
61 static int reset_settings(void)
63 static const char *lines[]={ID2P(LANG_RESET_ASK)};
64 static const char *yes_lines[]={
65 ID2P(LANG_SETTINGS),
66 ID2P(LANG_RESET_DONE_CLEAR)
68 static const char *no_lines[]={
69 ID2P(LANG_SETTINGS),
70 ID2P(LANG_CANCEL)
72 static const struct text_message message={lines, 1};
73 static const struct text_message yes_message={yes_lines, 2};
74 static const struct text_message no_message={no_lines, 2};
76 switch(gui_syncyesno_run(&message, &yes_message, &no_message))
78 case YESNO_YES:
79 settings_reset();
80 settings_save();
81 settings_apply(true);
82 settings_apply_skins();
83 break;
84 case YESNO_NO:
85 break;
86 case YESNO_USB:
87 return 1;
89 return 0;
91 static int write_settings_file(void* param)
93 return settings_save_config((intptr_t)param);
96 MENUITEM_FUNCTION(browse_configs, MENU_FUNC_USEPARAM, ID2P(LANG_CUSTOM_CFG),
97 browse_folder, (void*)&config, NULL, Icon_NOICON);
98 MENUITEM_FUNCTION(save_settings_item, MENU_FUNC_USEPARAM, ID2P(LANG_SAVE_SETTINGS),
99 write_settings_file, (void*)SETTINGS_SAVE_ALL, NULL, Icon_NOICON);
100 MENUITEM_FUNCTION(save_theme_item, MENU_FUNC_USEPARAM, ID2P(LANG_SAVE_THEME),
101 write_settings_file, (void*)SETTINGS_SAVE_THEME, NULL, Icon_NOICON);
102 MENUITEM_FUNCTION(save_sound_item, MENU_FUNC_USEPARAM, ID2P(LANG_SAVE_SOUND),
103 write_settings_file, (void*)SETTINGS_SAVE_SOUND, NULL, Icon_NOICON);
104 MENUITEM_FUNCTION(reset_settings_item, 0, ID2P(LANG_RESET),
105 reset_settings, NULL, NULL, Icon_NOICON);
107 MAKE_MENU(manage_settings, ID2P(LANG_MANAGE_MENU), NULL, Icon_Config,
108 &browse_configs, &reset_settings_item,
109 &save_settings_item, &save_sound_item, &save_theme_item);
110 /* MANAGE SETTINGS MENU */
111 /**********************************/
113 /***********************************/
114 /* INFO MENU */
116 static bool show_credits(void)
118 if (plugin_load(VIEWERS_DIR "/credits.rock",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 INFO_SKIN_USAGE, /* ram usage of the skins */
151 INFO_VERSION,
152 INFO_COUNT
155 static const char* info_getname(int selected_item, void *data,
156 char *buffer, size_t buffer_len)
158 struct info_data *info = (struct info_data*)data;
159 char s1[32];
160 char s2[32];
161 if (info->new_data)
163 fat_size(IF_MV2(0,) &info->size, &info->free);
164 #ifdef HAVE_MULTIVOLUME
165 if (fat_ismounted(1))
166 fat_size(1, &info->size2, &info->free2);
167 else
168 info->size2 = 0;
169 #endif
170 info->new_data = false;
172 switch (selected_item)
174 case INFO_VERSION:
175 snprintf(buffer, buffer_len, "%s: %s",
176 str(LANG_VERSION), rbversion);
177 break;
179 case INFO_BUFFER: /* buffer */
181 long kib = (audiobufend - audiobuf) / 1024; /* to KiB */
182 output_dyn_value(s1, sizeof(s1), kib, kbyte_units, true);
183 snprintf(buffer, buffer_len, "%s %s", str(LANG_BUFFER_STAT), s1);
185 break;
186 case INFO_BATTERY: /* battery */
187 #if CONFIG_CHARGING == CHARGING_SIMPLE
188 /* Only know if plugged */
189 if (charger_inserted())
190 return str(LANG_BATTERY_CHARGE);
191 else
192 #elif CONFIG_CHARGING >= CHARGING_MONITOR
193 #ifdef ARCHOS_RECORDER
194 /* Report the particular algorithm state */
195 if (charge_state == CHARGING)
196 return str(LANG_BATTERY_CHARGE);
197 else if (charge_state == TOPOFF)
198 return str(LANG_BATTERY_TOPOFF_CHARGE);
199 else if (charge_state == TRICKLE)
200 return str(LANG_BATTERY_TRICKLE_CHARGE);
201 else
202 #else /* !ARCHOS_RECORDER */
203 /* Go by what power management reports */
204 if (charging_state())
205 return str(LANG_BATTERY_CHARGE);
206 else
207 #endif /* ARCHOS_RECORDER */
208 #endif /* CONFIG_CHARGING = */
209 if (battery_level() >= 0)
210 snprintf(buffer, buffer_len, str(LANG_BATTERY_TIME),
211 battery_level(), battery_time() / 60, battery_time() % 60);
212 else
213 return "(n/a)";
214 break;
215 case INFO_DISK1: /* disk usage 1 */
216 #ifdef HAVE_MULTIVOLUME
217 output_dyn_value(s1, sizeof s1, info->free, kbyte_units, true);
218 output_dyn_value(s2, sizeof s2, info->size, kbyte_units, true);
219 snprintf(buffer, buffer_len, "%s %s/%s", str(LANG_DISK_NAME_INTERNAL),
220 s1, s2);
221 #else
222 output_dyn_value(s1, sizeof s1, info->free, kbyte_units, true);
223 snprintf(buffer, buffer_len, SIZE_FMT, str(LANG_DISK_FREE_INFO), s1);
224 #endif
225 break;
226 case INFO_DISK2: /* disk usage 2 */
227 #ifdef HAVE_MULTIVOLUME
228 if (info->size2)
230 output_dyn_value(s1, sizeof s1, info->free2, kbyte_units, true);
231 output_dyn_value(s2, sizeof s2, info->size2, kbyte_units, true);
232 snprintf(buffer, buffer_len, "%s %s/%s", str(LANG_DISK_NAME_MMC),
233 s1, s2);
235 else
237 snprintf(buffer, buffer_len, "%s %s", str(LANG_DISK_NAME_MMC),
238 str(LANG_NOT_PRESENT));
240 #else
241 output_dyn_value(s1, sizeof s1, info->size, kbyte_units, true);
242 snprintf(buffer, buffer_len, SIZE_FMT, str(LANG_DISK_SIZE_INFO), s1);
243 #endif
244 break;
245 case INFO_SKIN_USAGE:
246 output_dyn_value(s1, sizeof s1, skin_buffer_usage(), byte_units, true);
247 output_dyn_value(s2, sizeof s2, skin_buffer_usage()
248 +skin_buffer_freespace(), byte_units, true);
249 snprintf(buffer, buffer_len, "%s %s / %s", str(LANG_SKIN_RAM_USAGE), s1, s2);
250 break;
252 return buffer;
255 static int info_speak_item(int selected_item, void * data)
257 struct info_data *info = (struct info_data*)data;
259 switch (selected_item)
261 case INFO_VERSION: /* version */
262 talk_id(LANG_VERSION, false);
263 talk_spell(rbversion, true);
264 break;
266 case INFO_BUFFER: /* buffer */
268 talk_id(LANG_BUFFER_STAT, false);
269 long kib = (audiobufend - audiobuf) / 1024; /* to KiB */
270 output_dyn_value(NULL, 0, kib, kbyte_units, true);
271 break;
273 case INFO_BATTERY: /* battery */
274 #if CONFIG_CHARGING == CHARGING_SIMPLE
275 /* Only know if plugged */
276 if (charger_inserted())
277 talk_id(LANG_BATTERY_CHARGE, true);
278 else
279 #elif CONFIG_CHARGING >= CHARGING_MONITOR
280 #ifdef ARCHOS_RECORDER
281 /* Report the particular algorithm state */
282 if (charge_state == CHARGING)
283 talk_id(LANG_BATTERY_CHARGE, true);
284 else if (charge_state == TOPOFF)
285 talk_id(LANG_BATTERY_TOPOFF_CHARGE, true);
286 else if (charge_state == TRICKLE)
287 talk_id(LANG_BATTERY_TRICKLE_CHARGE, true);
288 else
289 #else /* !ARCHOS_RECORDER */
290 /* Go by what power management reports */
291 if (charging_state())
292 talk_id(LANG_BATTERY_CHARGE, true);
293 else
294 #endif /* ARCHOS_RECORDER */
295 #endif /* CONFIG_CHARGING = */
296 if (battery_level() >= 0)
298 talk_id(LANG_BATTERY_TIME, false);
299 talk_value(battery_level(), UNIT_PERCENT, true);
300 talk_value(battery_time() *60, UNIT_TIME, true);
302 else talk_id(VOICE_BLANK, false);
303 break;
304 case INFO_DISK1: /* disk 1 */
305 #ifdef HAVE_MULTIVOLUME
306 talk_ids(false, LANG_DISK_NAME_INTERNAL, LANG_DISK_FREE_INFO);
307 output_dyn_value(NULL, 0, info->free, kbyte_units, true);
308 talk_id(LANG_DISK_SIZE_INFO, true);
309 output_dyn_value(NULL, 0, info->size, kbyte_units, true);
310 #else
311 talk_id(LANG_DISK_FREE_INFO, false);
312 output_dyn_value(NULL, 0, info->free, kbyte_units, true);
313 #endif
314 break;
315 case INFO_DISK2: /* disk 2 */
316 #ifdef HAVE_MULTIVOLUME
317 talk_id(LANG_DISK_NAME_MMC, false);
318 if (info->size2)
320 talk_id(LANG_DISK_FREE_INFO, true);
321 output_dyn_value(NULL, 0, info->free2, kbyte_units, true);
322 talk_id(LANG_DISK_SIZE_INFO, true);
323 output_dyn_value(NULL, 0, info->size2, kbyte_units, true);
325 else talk_id(LANG_NOT_PRESENT, true);
326 #else
327 talk_id(LANG_DISK_SIZE_INFO, false);
328 output_dyn_value(NULL, 0, info->size, kbyte_units, true);
329 #endif
330 break;
331 case INFO_SKIN_USAGE:
332 talk_id(LANG_SKIN_RAM_USAGE, false);
333 output_dyn_value(NULL, 0, skin_buffer_usage(), byte_units, true);
334 break;
337 return 0;
340 static int info_action_callback(int action, struct gui_synclist *lists)
342 if (action == ACTION_STD_CANCEL)
343 return action;
344 else if ((action == ACTION_STD_OK)
345 #ifdef HAVE_HOTSWAP
346 || action == SYS_FS_CHANGED
347 #endif
350 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
351 struct info_data *info = (struct info_data *)lists->data;
352 int i;
353 info->new_data = true;
354 splash(0, ID2P(LANG_SCANNING_DISK));
355 for (i = 0; i < NUM_VOLUMES; i++)
357 #ifdef HAVE_HOTSWAP
358 if (fat_ismounted(i))
359 #endif
360 fat_recalc_free(IF_MV(i));
362 #else
363 (void) lists;
364 #endif
365 gui_synclist_speak_item(lists);
366 return ACTION_REDRAW;
368 return action;
370 static bool show_info(void)
372 struct info_data data = {.new_data = true };
373 struct simplelist_info info;
374 simplelist_info_init(&info, str(LANG_ROCKBOX_INFO), INFO_COUNT, (void*)&data);
375 info.hide_selection = !global_settings.talk_menu;
376 if (info.hide_selection)
377 info.scroll_all = true;
378 info.get_name = info_getname;
379 if(global_settings.talk_menu)
380 info.get_talk = info_speak_item;
381 info.action_callback = info_action_callback;
382 return simplelist_show_list(&info);
384 MENUITEM_FUNCTION(show_info_item, 0, ID2P(LANG_ROCKBOX_INFO),
385 (menu_function)show_info, NULL, NULL, Icon_NOICON);
388 /* sleep Menu */
389 static const char* sleep_timer_formatter(char* buffer, size_t buffer_size,
390 int value, const char* unit)
392 (void) unit;
393 int minutes, hours;
395 if (value) {
396 hours = value / 60;
397 minutes = value - (hours * 60);
398 snprintf(buffer, buffer_size, "%d:%02d", hours, minutes);
399 return buffer;
400 } else {
401 return str(LANG_OFF);
405 static void sleep_timer_set(int minutes)
407 set_sleep_timer(minutes * 60);
410 static int sleep_timer(void)
412 int minutes = (get_sleep_timer() + 59) / 60; /* round up */
413 return (int)set_int(str(LANG_SLEEP_TIMER), "", UNIT_MIN, &minutes,
414 &sleep_timer_set, -5, 300, 0, sleep_timer_formatter);
418 #if CONFIG_RTC
419 int time_screen(void* ignored);
420 MENUITEM_FUNCTION(timedate_item, MENU_FUNC_CHECK_RETVAL, ID2P(LANG_TIME_MENU),
421 time_screen, NULL, NULL, Icon_Menu_setting );
422 #endif
423 /* This item is in the time/date screen if there is a RTC */
424 MENUITEM_FUNCTION(sleep_timer_call, 0, ID2P(LANG_SLEEP_TIMER), sleep_timer,
425 NULL, NULL, Icon_Menu_setting); /* make it look like a
426 setting to the user */
428 MENUITEM_FUNCTION(show_credits_item, 0, ID2P(LANG_CREDITS),
429 (menu_function)show_credits, NULL, NULL, Icon_NOICON);
430 MENUITEM_FUNCTION(show_runtime_item, 0, ID2P(LANG_RUNNING_TIME),
431 (menu_function)view_runtime, NULL, NULL, Icon_NOICON);
432 MENUITEM_FUNCTION(debug_menu_item, 0, ID2P(LANG_DEBUG),
433 (menu_function)debug_menu, NULL, NULL, Icon_NOICON);
435 MAKE_MENU(info_menu, ID2P(LANG_SYSTEM), 0, Icon_System_menu,
436 #if CONFIG_RTC
437 &timedate_item,
438 #endif
439 &show_info_item, &show_credits_item, &show_runtime_item,
440 #if CONFIG_RTC == 0
441 &sleep_timer_call,
442 #endif
443 &debug_menu_item);
444 /* INFO MENU */
445 /***********************************/
447 /***********************************/
448 /* MAIN MENU */
451 #ifdef HAVE_LCD_CHARCELLS
452 static int mainmenu_callback(int action,const struct menu_item_ex *this_item)
454 (void)this_item;
455 switch (action)
457 case ACTION_ENTER_MENUITEM:
458 status_set_param(true);
459 break;
460 case ACTION_EXIT_MENUITEM:
461 status_set_param(false);
462 break;
464 return action;
466 #else
467 #define mainmenu_callback NULL
468 #endif
469 MAKE_MENU(main_menu_, ID2P(LANG_SETTINGS), mainmenu_callback,
470 Icon_Submenu_Entered,
471 &sound_settings,
472 &playback_settings,
473 &settings_menu_item, &theme_menu,
474 #ifdef HAVE_RECORDING
475 &recording_settings,
476 #endif
477 &manage_settings,
479 /* MAIN MENU */
480 /***********************************/