FFT Plugin: Revamp the main code to rid it of 64-bit math. Use 32-bit kiss_fft_scalar...
[kugel-rb.git] / apps / menus / main_menu.c
blob76ceaa483e68f3e5c0909cb8cf76fccc612a81a9
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 #ifdef HAVE_RECORDING
37 #include "recording.h"
38 #endif
39 #include "yesno.h"
40 #include "keyboard.h"
41 #include "screens.h"
42 #include "plugin.h"
43 #include "talk.h"
44 #include "buffer.h"
45 #include "splash.h"
46 #include "debug_menu.h"
47 #if defined(SIMULATOR) && defined(ROCKBOX_HAS_LOGF)
48 #include "logfdisp.h"
49 #endif
50 #include "version.h"
51 #include "time.h"
52 #include "wps.h"
53 #include "skin_engine/skin_buffer.h"
55 static const struct browse_folder_info config = {ROCKBOX_DIR, SHOW_CFG};
57 /***********************************/
58 /* MANAGE SETTINGS MENU */
60 static int reset_settings(void)
62 static const char *lines[]={ID2P(LANG_RESET_ASK)};
63 static const char *yes_lines[]={
64 ID2P(LANG_SETTINGS),
65 ID2P(LANG_RESET_DONE_CLEAR)
67 static const char *no_lines[]={
68 ID2P(LANG_SETTINGS),
69 ID2P(LANG_CANCEL)
71 static const struct text_message message={lines, 1};
72 static const struct text_message yes_message={yes_lines, 2};
73 static const struct text_message no_message={no_lines, 2};
75 switch(gui_syncyesno_run(&message, &yes_message, &no_message))
77 case YESNO_YES:
78 settings_reset();
79 settings_save();
80 settings_apply(true);
81 settings_apply_skins();
82 break;
83 case YESNO_NO:
84 break;
85 case YESNO_USB:
86 return 1;
88 return 0;
90 static int write_settings_file(void* param)
92 return settings_save_config((intptr_t)param);
95 MENUITEM_FUNCTION(browse_configs, MENU_FUNC_USEPARAM, ID2P(LANG_CUSTOM_CFG),
96 browse_folder, (void*)&config, NULL, Icon_NOICON);
97 MENUITEM_FUNCTION(save_settings_item, MENU_FUNC_USEPARAM, ID2P(LANG_SAVE_SETTINGS),
98 write_settings_file, (void*)SETTINGS_SAVE_ALL, NULL, Icon_NOICON);
99 MENUITEM_FUNCTION(save_theme_item, MENU_FUNC_USEPARAM, ID2P(LANG_SAVE_THEME),
100 write_settings_file, (void*)SETTINGS_SAVE_THEME, NULL, Icon_NOICON);
101 MENUITEM_FUNCTION(save_sound_item, MENU_FUNC_USEPARAM, ID2P(LANG_SAVE_SOUND),
102 write_settings_file, (void*)SETTINGS_SAVE_SOUND, NULL, Icon_NOICON);
103 MENUITEM_FUNCTION(reset_settings_item, 0, ID2P(LANG_RESET),
104 reset_settings, NULL, NULL, Icon_NOICON);
106 MAKE_MENU(manage_settings, ID2P(LANG_MANAGE_MENU), NULL, Icon_Config,
107 &browse_configs, &reset_settings_item,
108 &save_settings_item, &save_sound_item, &save_theme_item);
109 /* MANAGE SETTINGS MENU */
110 /**********************************/
112 /***********************************/
113 /* INFO MENU */
115 static bool show_credits(void)
117 if (plugin_load(VIEWERS_DIR "/credits.rock",NULL) != PLUGIN_OK)
119 /* show the rockbox logo and version untill a button is pressed */
120 show_logo();
121 while (IS_SYSEVENT(get_action(CONTEXT_STD, TIMEOUT_BLOCK)))
124 return false;
127 #ifdef HAVE_LCD_CHARCELLS
128 #define SIZE_FMT "%s%s"
129 #else
130 #define SIZE_FMT "%s %s"
131 #endif
132 struct info_data
135 bool new_data;
136 unsigned long size;
137 unsigned long free;
138 #ifdef HAVE_MULTIVOLUME
139 unsigned long size2;
140 unsigned long free2;
141 #endif
143 enum infoscreenorder
145 INFO_BATTERY = 0,
146 INFO_DISK1, /* capacity or internal capacity/free on hotswap */
147 INFO_DISK2, /* free space or external capacity/free on hotswap */
148 INFO_BUFFER,
149 INFO_SKIN_USAGE, /* ram usage of the skins */
150 INFO_VERSION,
151 INFO_COUNT
154 static const char* info_getname(int selected_item, void *data,
155 char *buffer, size_t buffer_len)
157 struct info_data *info = (struct info_data*)data;
158 char s1[32];
159 char s2[32];
160 if (info->new_data)
162 fat_size(IF_MV2(0,) &info->size, &info->free);
163 #ifdef HAVE_MULTIVOLUME
164 if (fat_ismounted(1))
165 fat_size(1, &info->size2, &info->free2);
166 else
167 info->size2 = 0;
168 #endif
169 info->new_data = false;
171 switch (selected_item)
173 case INFO_VERSION:
174 snprintf(buffer, buffer_len, "%s: %s",
175 str(LANG_VERSION), rbversion);
176 break;
178 case INFO_BUFFER: /* buffer */
180 long kib = (audiobufend - audiobuf) / 1024; /* to KiB */
181 output_dyn_value(s1, sizeof(s1), kib, kbyte_units, true);
182 snprintf(buffer, buffer_len, "%s %s", str(LANG_BUFFER_STAT), s1);
184 break;
185 case INFO_BATTERY: /* battery */
186 #if CONFIG_CHARGING == CHARGING_SIMPLE
187 /* Only know if plugged */
188 if (charger_inserted())
189 return str(LANG_BATTERY_CHARGE);
190 else
191 #elif CONFIG_CHARGING >= CHARGING_MONITOR
192 #ifdef ARCHOS_RECORDER
193 /* Report the particular algorithm state */
194 if (charge_state == CHARGING)
195 return str(LANG_BATTERY_CHARGE);
196 else if (charge_state == TOPOFF)
197 return str(LANG_BATTERY_TOPOFF_CHARGE);
198 else if (charge_state == TRICKLE)
199 return str(LANG_BATTERY_TRICKLE_CHARGE);
200 else
201 #else /* !ARCHOS_RECORDER */
202 /* Go by what power management reports */
203 if (charging_state())
204 return str(LANG_BATTERY_CHARGE);
205 else
206 #endif /* ARCHOS_RECORDER */
207 #endif /* CONFIG_CHARGING = */
208 if (battery_level() >= 0)
209 snprintf(buffer, buffer_len, str(LANG_BATTERY_TIME),
210 battery_level(), battery_time() / 60, battery_time() % 60);
211 else
212 return "(n/a)";
213 break;
214 case INFO_DISK1: /* disk usage 1 */
215 #ifdef HAVE_MULTIVOLUME
216 output_dyn_value(s1, sizeof s1, info->free, kbyte_units, true);
217 output_dyn_value(s2, sizeof s2, info->size, kbyte_units, true);
218 snprintf(buffer, buffer_len, "%s %s/%s", str(LANG_DISK_NAME_INTERNAL),
219 s1, s2);
220 #else
221 output_dyn_value(s1, sizeof s1, info->free, kbyte_units, true);
222 snprintf(buffer, buffer_len, SIZE_FMT, str(LANG_DISK_FREE_INFO), s1);
223 #endif
224 break;
225 case INFO_DISK2: /* disk usage 2 */
226 #ifdef HAVE_MULTIVOLUME
227 if (info->size2)
229 output_dyn_value(s1, sizeof s1, info->free2, kbyte_units, true);
230 output_dyn_value(s2, sizeof s2, info->size2, kbyte_units, true);
231 snprintf(buffer, buffer_len, "%s %s/%s", str(LANG_DISK_NAME_MMC),
232 s1, s2);
234 else
236 snprintf(buffer, buffer_len, "%s %s", str(LANG_DISK_NAME_MMC),
237 str(LANG_NOT_PRESENT));
239 #else
240 output_dyn_value(s1, sizeof s1, info->size, kbyte_units, true);
241 snprintf(buffer, buffer_len, SIZE_FMT, str(LANG_DISK_SIZE_INFO), s1);
242 #endif
243 break;
244 case INFO_SKIN_USAGE:
245 output_dyn_value(s1, sizeof s1, skin_buffer_usage(), byte_units, true);
246 output_dyn_value(s2, sizeof s2, skin_buffer_usage()
247 +skin_buffer_freespace(), byte_units, true);
248 snprintf(buffer, buffer_len, "%s %s / %s", str(LANG_SKIN_RAM_USAGE), s1, s2);
249 break;
251 return buffer;
254 static int info_speak_item(int selected_item, void * data)
256 struct info_data *info = (struct info_data*)data;
258 switch (selected_item)
260 case INFO_VERSION: /* version */
261 talk_id(LANG_VERSION, false);
262 talk_spell(rbversion, true);
263 break;
265 case INFO_BUFFER: /* buffer */
267 talk_id(LANG_BUFFER_STAT, false);
268 long kib = (audiobufend - audiobuf) / 1024; /* to KiB */
269 output_dyn_value(NULL, 0, kib, kbyte_units, true);
270 break;
272 case INFO_BATTERY: /* battery */
273 #if CONFIG_CHARGING == CHARGING_SIMPLE
274 /* Only know if plugged */
275 if (charger_inserted())
276 talk_id(LANG_BATTERY_CHARGE, true);
277 else
278 #elif CONFIG_CHARGING >= CHARGING_MONITOR
279 #ifdef ARCHOS_RECORDER
280 /* Report the particular algorithm state */
281 if (charge_state == CHARGING)
282 talk_id(LANG_BATTERY_CHARGE, true);
283 else if (charge_state == TOPOFF)
284 talk_id(LANG_BATTERY_TOPOFF_CHARGE, true);
285 else if (charge_state == TRICKLE)
286 talk_id(LANG_BATTERY_TRICKLE_CHARGE, true);
287 else
288 #else /* !ARCHOS_RECORDER */
289 /* Go by what power management reports */
290 if (charging_state())
291 talk_id(LANG_BATTERY_CHARGE, true);
292 else
293 #endif /* ARCHOS_RECORDER */
294 #endif /* CONFIG_CHARGING = */
295 if (battery_level() >= 0)
297 talk_id(LANG_BATTERY_TIME, false);
298 talk_value(battery_level(), UNIT_PERCENT, true);
299 talk_value(battery_time() *60, UNIT_TIME, true);
301 else talk_id(VOICE_BLANK, false);
302 break;
303 case INFO_DISK1: /* disk 1 */
304 #ifdef HAVE_MULTIVOLUME
305 talk_ids(false, LANG_DISK_NAME_INTERNAL, LANG_DISK_FREE_INFO);
306 output_dyn_value(NULL, 0, info->free, kbyte_units, true);
307 talk_id(LANG_DISK_SIZE_INFO, true);
308 output_dyn_value(NULL, 0, info->size, kbyte_units, true);
309 #else
310 talk_id(LANG_DISK_FREE_INFO, false);
311 output_dyn_value(NULL, 0, info->free, kbyte_units, true);
312 #endif
313 break;
314 case INFO_DISK2: /* disk 2 */
315 #ifdef HAVE_MULTIVOLUME
316 talk_id(LANG_DISK_NAME_MMC, false);
317 if (info->size2)
319 talk_id(LANG_DISK_FREE_INFO, true);
320 output_dyn_value(NULL, 0, info->free2, kbyte_units, true);
321 talk_id(LANG_DISK_SIZE_INFO, true);
322 output_dyn_value(NULL, 0, info->size2, kbyte_units, true);
324 else talk_id(LANG_NOT_PRESENT, true);
325 #else
326 talk_id(LANG_DISK_SIZE_INFO, false);
327 output_dyn_value(NULL, 0, info->size, kbyte_units, true);
328 #endif
329 break;
330 case INFO_SKIN_USAGE:
331 talk_id(LANG_SKIN_RAM_USAGE, false);
332 output_dyn_value(NULL, 0, skin_buffer_usage(), byte_units, true);
333 break;
336 return 0;
339 static int info_action_callback(int action, struct gui_synclist *lists)
341 if (action == ACTION_STD_CANCEL)
342 return action;
343 else if ((action == ACTION_STD_OK)
344 #ifdef HAVE_MULTIVOLUME
345 || action == SYS_HOTSWAP_INSERTED
346 || action == SYS_HOTSWAP_EXTRACTED
347 #endif
350 #ifndef SIMULATOR
351 struct info_data *info = (struct info_data *)lists->data;
352 info->new_data = true;
353 splash(0, ID2P(LANG_SCANNING_DISK));
354 fat_recalc_free(IF_MV(0));
355 #ifdef HAVE_MULTIVOLUME
356 if (fat_ismounted(1))
357 fat_recalc_free(1);
358 #endif
360 #else
362 (void) lists;
363 #endif
364 gui_synclist_speak_item(lists);
365 return ACTION_REDRAW;
367 return action;
369 static bool show_info(void)
371 struct info_data data = {.new_data = true };
372 struct simplelist_info info;
373 simplelist_info_init(&info, str(LANG_ROCKBOX_INFO), INFO_COUNT, (void*)&data);
374 info.hide_selection = !global_settings.talk_menu;
375 if (info.hide_selection)
376 info.scroll_all = true;
377 info.get_name = info_getname;
378 if(global_settings.talk_menu)
379 info.get_talk = info_speak_item;
380 info.action_callback = info_action_callback;
381 return simplelist_show_list(&info);
383 MENUITEM_FUNCTION(show_info_item, 0, ID2P(LANG_ROCKBOX_INFO),
384 (menu_function)show_info, NULL, NULL, Icon_NOICON);
387 /* sleep Menu */
388 static const char* sleep_timer_formatter(char* buffer, size_t buffer_size,
389 int value, const char* unit)
391 (void) unit;
392 int minutes, hours;
394 if (value) {
395 hours = value / 60;
396 minutes = value - (hours * 60);
397 snprintf(buffer, buffer_size, "%d:%02d", hours, minutes);
398 return buffer;
399 } else {
400 return str(LANG_OFF);
404 static void sleep_timer_set(int minutes)
406 set_sleep_timer(minutes * 60);
409 static int sleep_timer(void)
411 int minutes = (get_sleep_timer() + 59) / 60; /* round up */
412 return (int)set_int(str(LANG_SLEEP_TIMER), "", UNIT_MIN, &minutes,
413 &sleep_timer_set, -5, 300, 0, sleep_timer_formatter);
417 #if CONFIG_RTC
418 int time_screen(void* ignored);
419 MENUITEM_FUNCTION(timedate_item, MENU_FUNC_CHECK_RETVAL, ID2P(LANG_TIME_MENU),
420 time_screen, NULL, NULL, Icon_Menu_setting );
421 #endif
422 /* This item is in the time/date screen if there is a RTC */
423 MENUITEM_FUNCTION(sleep_timer_call, 0, ID2P(LANG_SLEEP_TIMER), sleep_timer,
424 NULL, NULL, Icon_Menu_setting); /* make it look like a
425 setting to the user */
427 MENUITEM_FUNCTION(show_credits_item, 0, ID2P(LANG_CREDITS),
428 (menu_function)show_credits, NULL, NULL, Icon_NOICON);
429 MENUITEM_FUNCTION(show_runtime_item, 0, ID2P(LANG_RUNNING_TIME),
430 (menu_function)view_runtime, NULL, NULL, Icon_NOICON);
431 MENUITEM_FUNCTION(debug_menu_item, 0, ID2P(LANG_DEBUG),
432 (menu_function)debug_menu, NULL, NULL, Icon_NOICON);
434 MAKE_MENU(info_menu, ID2P(LANG_SYSTEM), 0, Icon_System_menu,
435 #if CONFIG_RTC
436 &timedate_item,
437 #endif
438 &show_info_item, &show_credits_item, &show_runtime_item,
439 #if CONFIG_RTC == 0
440 &sleep_timer_call,
441 #endif
442 &debug_menu_item);
443 /* INFO MENU */
444 /***********************************/
446 /***********************************/
447 /* MAIN MENU */
450 #ifdef HAVE_LCD_CHARCELLS
451 static int mainmenu_callback(int action,const struct menu_item_ex *this_item)
453 (void)this_item;
454 switch (action)
456 case ACTION_ENTER_MENUITEM:
457 status_set_param(true);
458 break;
459 case ACTION_EXIT_MENUITEM:
460 status_set_param(false);
461 break;
463 return action;
465 #else
466 #define mainmenu_callback NULL
467 #endif
468 MAKE_MENU(main_menu_, ID2P(LANG_SETTINGS), mainmenu_callback,
469 Icon_Submenu_Entered,
470 &sound_settings,
471 &playback_settings,
472 &settings_menu_item, &theme_menu,
473 #ifdef HAVE_RECORDING
474 &recording_settings,
475 #endif
476 &manage_settings,
478 /* MAIN MENU */
479 /***********************************/