FS#8961 - Anti-Aliased Fonts.
[kugel-rb.git] / apps / menus / main_menu.c
blob99c73f2cdbd589daea385164158ec3c5c1d4208f
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_apply(true);
80 settings_save();
81 break;
82 case YESNO_NO:
83 break;
84 case YESNO_USB:
85 return 1;
87 return 0;
89 static int write_settings_file(void* param)
91 return settings_save_config((intptr_t)param);
94 MENUITEM_FUNCTION(browse_configs, MENU_FUNC_USEPARAM, ID2P(LANG_CUSTOM_CFG),
95 browse_folder, (void*)&config, NULL, Icon_NOICON);
96 MENUITEM_FUNCTION(save_settings_item, MENU_FUNC_USEPARAM, ID2P(LANG_SAVE_SETTINGS),
97 write_settings_file, (void*)SETTINGS_SAVE_ALL, NULL, Icon_NOICON);
98 MENUITEM_FUNCTION(save_theme_item, MENU_FUNC_USEPARAM, ID2P(LANG_SAVE_THEME),
99 write_settings_file, (void*)SETTINGS_SAVE_THEME, NULL, Icon_NOICON);
100 MENUITEM_FUNCTION(save_sound_item, MENU_FUNC_USEPARAM, ID2P(LANG_SAVE_SOUND),
101 write_settings_file, (void*)SETTINGS_SAVE_SOUND, NULL, Icon_NOICON);
102 MENUITEM_FUNCTION(reset_settings_item, 0, ID2P(LANG_RESET),
103 reset_settings, NULL, NULL, Icon_NOICON);
105 MAKE_MENU(manage_settings, ID2P(LANG_MANAGE_MENU), NULL, Icon_Config,
106 &browse_configs, &reset_settings_item,
107 &save_settings_item, &save_sound_item, &save_theme_item);
108 /* MANAGE SETTINGS MENU */
109 /**********************************/
111 /***********************************/
112 /* INFO MENU */
114 static bool show_credits(void)
116 if (plugin_load(VIEWERS_DIR "/credits.rock",NULL) != PLUGIN_OK)
118 /* show the rockbox logo and version untill a button is pressed */
119 show_logo();
120 while (IS_SYSEVENT(get_action(CONTEXT_STD, TIMEOUT_BLOCK)))
123 return false;
126 #ifdef HAVE_LCD_CHARCELLS
127 #define SIZE_FMT "%s%s"
128 #else
129 #define SIZE_FMT "%s %s"
130 #endif
131 struct info_data
134 bool new_data;
135 unsigned long size;
136 unsigned long free;
137 #ifdef HAVE_MULTIVOLUME
138 unsigned long size2;
139 unsigned long free2;
140 #endif
142 enum infoscreenorder
144 INFO_BATTERY = 0,
145 INFO_DISK1, /* capacity or internal capacity/free on hotswap */
146 INFO_DISK2, /* free space or external capacity/free on hotswap */
147 INFO_BUFFER,
148 INFO_SKIN_USAGE, /* ram usage of the skins */
149 INFO_VERSION,
150 INFO_COUNT
153 static const unsigned char *kbyte_units[] =
155 ID2P(LANG_KILOBYTE),
156 ID2P(LANG_MEGABYTE),
157 ID2P(LANG_GIGABYTE)
160 static const unsigned char *byte_units[] =
162 ID2P(LANG_BYTE),
163 ID2P(LANG_KILOBYTE),
164 ID2P(LANG_MEGABYTE)
167 static const char* info_getname(int selected_item, void *data,
168 char *buffer, size_t buffer_len)
170 struct info_data *info = (struct info_data*)data;
171 char s1[32];
172 char s2[32];
173 if (info->new_data)
175 fat_size(IF_MV2(0,) &info->size, &info->free);
176 #ifdef HAVE_MULTIVOLUME
177 if (fat_ismounted(1))
178 fat_size(1, &info->size2, &info->free2);
179 else
180 info->size2 = 0;
181 #endif
182 info->new_data = false;
184 switch (selected_item)
186 case INFO_VERSION:
187 snprintf(buffer, buffer_len, "%s: %s",
188 str(LANG_VERSION), appsversion);
189 break;
191 case INFO_BUFFER: /* buffer */
193 long kib = (audiobufend - audiobuf) / 1024; /* to KiB */
194 output_dyn_value(s1, sizeof(s1), kib, kbyte_units, true);
195 snprintf(buffer, buffer_len, "%s %s", str(LANG_BUFFER_STAT), s1);
197 break;
198 case INFO_BATTERY: /* battery */
199 #if CONFIG_CHARGING == CHARGING_SIMPLE
200 /* Only know if plugged */
201 if (charger_inserted())
202 return str(LANG_BATTERY_CHARGE);
203 else
204 #elif CONFIG_CHARGING >= CHARGING_MONITOR
205 #ifdef ARCHOS_RECORDER
206 /* Report the particular algorithm state */
207 if (charge_state == CHARGING)
208 return str(LANG_BATTERY_CHARGE);
209 else if (charge_state == TOPOFF)
210 return str(LANG_BATTERY_TOPOFF_CHARGE);
211 else if (charge_state == TRICKLE)
212 return str(LANG_BATTERY_TRICKLE_CHARGE);
213 else
214 #else /* !ARCHOS_RECORDER */
215 /* Go by what power management reports */
216 if (charging_state())
217 return str(LANG_BATTERY_CHARGE);
218 else
219 #endif /* ARCHOS_RECORDER */
220 #endif /* CONFIG_CHARGING = */
221 if (battery_level() >= 0)
222 snprintf(buffer, buffer_len, str(LANG_BATTERY_TIME),
223 battery_level(), battery_time() / 60, battery_time() % 60);
224 else
225 return "(n/a)";
226 break;
227 case INFO_DISK1: /* disk usage 1 */
228 #ifdef HAVE_MULTIVOLUME
229 output_dyn_value(s1, sizeof s1, info->free, kbyte_units, true);
230 output_dyn_value(s2, sizeof s2, info->size, kbyte_units, true);
231 snprintf(buffer, buffer_len, "%s %s/%s", str(LANG_DISK_NAME_INTERNAL),
232 s1, s2);
233 #else
234 output_dyn_value(s1, sizeof s1, info->free, kbyte_units, true);
235 snprintf(buffer, buffer_len, SIZE_FMT, str(LANG_DISK_FREE_INFO), s1);
236 #endif
237 break;
238 case INFO_DISK2: /* disk usage 2 */
239 #ifdef HAVE_MULTIVOLUME
240 if (info->size2)
242 output_dyn_value(s1, sizeof s1, info->free2, kbyte_units, true);
243 output_dyn_value(s2, sizeof s2, info->size2, kbyte_units, true);
244 snprintf(buffer, buffer_len, "%s %s/%s", str(LANG_DISK_NAME_MMC),
245 s1, s2);
247 else
249 snprintf(buffer, buffer_len, "%s %s", str(LANG_DISK_NAME_MMC),
250 str(LANG_NOT_PRESENT));
252 #else
253 output_dyn_value(s1, sizeof s1, info->size, kbyte_units, true);
254 snprintf(buffer, buffer_len, SIZE_FMT, str(LANG_DISK_SIZE_INFO), s1);
255 #endif
256 break;
257 case INFO_SKIN_USAGE:
258 output_dyn_value(s1, sizeof s1, skin_buffer_usage(), byte_units, true);
259 output_dyn_value(s2, sizeof s2, skin_buffer_usage()
260 +skin_buffer_freespace(), byte_units, true);
261 snprintf(buffer, buffer_len, "%s %s / %s", str(LANG_SKIN_RAM_USAGE), s1, s2);
262 break;
264 return buffer;
267 static int info_speak_item(int selected_item, void * data)
269 struct info_data *info = (struct info_data*)data;
271 switch (selected_item)
273 case INFO_VERSION: /* version */
274 talk_id(LANG_VERSION, false);
275 talk_spell(appsversion, true);
276 break;
278 case INFO_BUFFER: /* buffer */
280 talk_id(LANG_BUFFER_STAT, false);
281 long kib = (audiobufend - audiobuf) / 1024; /* to KiB */
282 output_dyn_value(NULL, 0, kib, kbyte_units, true);
283 break;
285 case INFO_BATTERY: /* battery */
286 #if CONFIG_CHARGING == CHARGING_SIMPLE
287 /* Only know if plugged */
288 if (charger_inserted())
289 talk_id(LANG_BATTERY_CHARGE, true);
290 else
291 #elif CONFIG_CHARGING >= CHARGING_MONITOR
292 #ifdef ARCHOS_RECORDER
293 /* Report the particular algorithm state */
294 if (charge_state == CHARGING)
295 talk_id(LANG_BATTERY_CHARGE, true);
296 else if (charge_state == TOPOFF)
297 talk_id(LANG_BATTERY_TOPOFF_CHARGE, true);
298 else if (charge_state == TRICKLE)
299 talk_id(LANG_BATTERY_TRICKLE_CHARGE, true);
300 else
301 #else /* !ARCHOS_RECORDER */
302 /* Go by what power management reports */
303 if (charging_state())
304 talk_id(LANG_BATTERY_CHARGE, true);
305 else
306 #endif /* ARCHOS_RECORDER */
307 #endif /* CONFIG_CHARGING = */
308 if (battery_level() >= 0)
310 talk_id(LANG_BATTERY_TIME, false);
311 talk_value(battery_level(), UNIT_PERCENT, true);
312 talk_value(battery_time() *60, UNIT_TIME, true);
314 else talk_id(VOICE_BLANK, false);
315 break;
316 case INFO_DISK1: /* disk 1 */
317 #ifdef HAVE_MULTIVOLUME
318 talk_id(LANG_DISK_NAME_INTERNAL, false);
319 talk_id(LANG_DISK_FREE_INFO, true);
320 output_dyn_value(NULL, 0, info->free, kbyte_units, true);
321 talk_id(LANG_DISK_SIZE_INFO, true);
322 output_dyn_value(NULL, 0, info->size, kbyte_units, true);
323 #else
324 talk_id(LANG_DISK_FREE_INFO, false);
325 output_dyn_value(NULL, 0, info->free, kbyte_units, true);
326 #endif
327 break;
328 case INFO_DISK2: /* disk 2 */
329 #ifdef HAVE_MULTIVOLUME
330 talk_id(LANG_DISK_NAME_MMC, false);
331 if (info->size2)
333 talk_id(LANG_DISK_FREE_INFO, true);
334 output_dyn_value(NULL, 0, info->free2, kbyte_units, true);
335 talk_id(LANG_DISK_SIZE_INFO, true);
336 output_dyn_value(NULL, 0, info->size2, kbyte_units, true);
338 else talk_id(LANG_NOT_PRESENT, true);
339 #else
340 talk_id(LANG_DISK_SIZE_INFO, false);
341 output_dyn_value(NULL, 0, info->size, kbyte_units, true);
342 #endif
343 break;
344 case INFO_SKIN_USAGE:
345 talk_id(LANG_SKIN_RAM_USAGE, false);
346 output_dyn_value(NULL, 0, skin_buffer_usage(), byte_units, true);
347 break;
350 return 0;
353 static int info_action_callback(int action, struct gui_synclist *lists)
355 if (action == ACTION_STD_CANCEL)
356 return action;
357 else if ((action == ACTION_STD_OK)
358 #ifdef HAVE_MULTIVOLUME
359 || action == SYS_HOTSWAP_INSERTED
360 || action == SYS_HOTSWAP_EXTRACTED
361 #endif
364 #ifndef SIMULATOR
365 struct info_data *info = (struct info_data *)lists->data;
366 info->new_data = true;
367 splash(0, ID2P(LANG_SCANNING_DISK));
368 fat_recalc_free(IF_MV(0));
369 #ifdef HAVE_MULTIVOLUME
370 if (fat_ismounted(1))
371 fat_recalc_free(1);
372 #endif
374 #else
376 (void) lists;
377 #endif
378 gui_synclist_speak_item(lists);
379 return ACTION_REDRAW;
381 return action;
383 static bool show_info(void)
385 struct info_data data = {.new_data = true };
386 struct simplelist_info info;
387 simplelist_info_init(&info, str(LANG_ROCKBOX_INFO), INFO_COUNT, (void*)&data);
388 info.hide_selection = !global_settings.talk_menu;
389 if (info.hide_selection)
390 info.scroll_all = true;
391 info.get_name = info_getname;
392 if(global_settings.talk_menu)
393 info.get_talk = info_speak_item;
394 info.action_callback = info_action_callback;
395 return simplelist_show_list(&info);
397 MENUITEM_FUNCTION(show_info_item, 0, ID2P(LANG_ROCKBOX_INFO),
398 (menu_function)show_info, NULL, NULL, Icon_NOICON);
401 /* sleep Menu */
402 static const char* sleep_timer_formatter(char* buffer, size_t buffer_size,
403 int value, const char* unit)
405 (void) unit;
406 int minutes, hours;
408 if (value) {
409 hours = value / 60;
410 minutes = value - (hours * 60);
411 snprintf(buffer, buffer_size, "%d:%02d", hours, minutes);
412 return buffer;
413 } else {
414 return str(LANG_OFF);
418 static void sleep_timer_set(int minutes)
420 set_sleep_timer(minutes * 60);
423 static int sleep_timer(void)
425 int minutes = (get_sleep_timer() + 59) / 60; /* round up */
426 return (int)set_int(str(LANG_SLEEP_TIMER), "", UNIT_MIN, &minutes,
427 &sleep_timer_set, -5, 300, 0, sleep_timer_formatter);
431 #if CONFIG_RTC
432 int time_screen(void* ignored);
433 MENUITEM_FUNCTION(timedate_item, MENU_FUNC_CHECK_RETVAL, ID2P(LANG_TIME_MENU), time_screen,
434 NULL, NULL, Icon_Menu_setting );
435 #endif
436 /* This item is in the time/date screen if there is a RTC */
437 MENUITEM_FUNCTION(sleep_timer_call, 0, ID2P(LANG_SLEEP_TIMER), sleep_timer,
438 NULL, NULL, Icon_Menu_setting); /* make it look like a
439 setting to the user */
441 MENUITEM_FUNCTION(show_credits_item, 0, ID2P(LANG_CREDITS),
442 (menu_function)show_credits, NULL, NULL, Icon_NOICON);
443 MENUITEM_FUNCTION(show_runtime_item, 0, ID2P(LANG_RUNNING_TIME),
444 (menu_function)view_runtime, NULL, NULL, Icon_NOICON);
445 MENUITEM_FUNCTION(debug_menu_item, 0, ID2P(LANG_DEBUG),
446 (menu_function)debug_menu, NULL, NULL, Icon_NOICON);
448 MAKE_MENU(info_menu, ID2P(LANG_SYSTEM), 0, Icon_Questionmark,
449 #if CONFIG_RTC
450 &timedate_item,
451 #endif
452 &show_info_item, &show_credits_item, &show_runtime_item,
453 #if CONFIG_RTC == 0
454 &sleep_timer_call,
455 #endif
456 &debug_menu_item);
457 /* INFO MENU */
458 /***********************************/
460 /***********************************/
461 /* MAIN MENU */
464 #ifdef HAVE_LCD_CHARCELLS
465 static int mainmenu_callback(int action,const struct menu_item_ex *this_item)
467 (void)this_item;
468 switch (action)
470 case ACTION_ENTER_MENUITEM:
471 status_set_param(true);
472 break;
473 case ACTION_EXIT_MENUITEM:
474 status_set_param(false);
475 break;
477 return action;
479 #else
480 #define mainmenu_callback NULL
481 #endif
482 MAKE_MENU(main_menu_, ID2P(LANG_SETTINGS), mainmenu_callback,
483 Icon_Submenu_Entered,
484 &sound_settings,
485 &playback_settings,
486 &settings_menu_item, &theme_menu,
487 #ifdef HAVE_RECORDING
488 &recording_settings,
489 #endif
490 &manage_settings,
492 /* MAIN MENU */
493 /***********************************/