1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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 ****************************************************************************/
30 #include "powermgmt.h"
33 #include "exported_menus.h"
36 #include "recording.h"
46 #include "debug_menu.h"
47 #if defined(SIMULATOR) && defined(ROCKBOX_HAS_LOGF)
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
[]={
63 ID2P(LANG_RESET_DONE_CLEAR
)
65 static const char *no_lines
[]={
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
))
87 static int write_settings_file(void* param
)
89 return settings_save_config((intptr_t)param
);
92 MENUITEM_FUNCTION(browse_configs
, MENU_FUNC_USEPARAM
, ID2P(LANG_CUSTOM_CFG
),
93 browse_folder
, (void*)&config
, NULL
, Icon_NOICON
);
94 MENUITEM_FUNCTION(save_settings_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_SAVE_SETTINGS
),
95 write_settings_file
, (void*)SETTINGS_SAVE_ALL
, NULL
, Icon_NOICON
);
96 MENUITEM_FUNCTION(save_theme_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_SAVE_THEME
),
97 write_settings_file
, (void*)SETTINGS_SAVE_THEME
, NULL
, Icon_NOICON
);
98 MENUITEM_FUNCTION(save_sound_item
, MENU_FUNC_USEPARAM
, ID2P(LANG_SAVE_SOUND
),
99 write_settings_file
, (void*)SETTINGS_SAVE_SOUND
, NULL
, Icon_NOICON
);
100 MENUITEM_FUNCTION(reset_settings_item
, 0, ID2P(LANG_RESET
),
101 reset_settings
, NULL
, NULL
, Icon_NOICON
);
103 MAKE_MENU(manage_settings
, ID2P(LANG_MANAGE_MENU
), NULL
, Icon_Config
,
104 &browse_configs
, &reset_settings_item
,
105 &save_settings_item
, &save_sound_item
, &save_theme_item
);
106 /* MANAGE SETTINGS MENU */
107 /**********************************/
109 /***********************************/
112 static bool show_credits(void)
114 if (plugin_load(VIEWERS_DIR
"/credits.rock",NULL
) != PLUGIN_OK
)
116 /* show the rockbox logo and version untill a button is pressed */
118 get_action(CONTEXT_STD
, TIMEOUT_BLOCK
);
123 #ifdef HAVE_LCD_CHARCELLS
124 #define SIZE_FMT "%s%s"
126 #define SIZE_FMT "%s %s"
134 #ifdef HAVE_MULTIVOLUME
142 INFO_DISK1
, /* capacity or internal capacity/free on hotswap */
143 INFO_DISK2
, /* free space or external capacity/free on hotswap */
153 static const unsigned char *kbyte_units
[] =
160 static char* info_getname(int selected_item
, void *data
,
161 char *buffer
, size_t buffer_len
)
163 struct info_data
*info
= (struct info_data
*)data
;
168 #ifdef HAVE_MULTIVOLUME
173 fat_size(IF_MV2(0,) &info
->size
, &info
->free
);
174 #ifdef HAVE_MULTIVOLUME
175 if (fat_ismounted(1))
176 fat_size(1, &info
->size2
, &info
->free2
);
180 info
->new_data
= false;
182 switch (selected_item
)
185 snprintf(buffer
, buffer_len
, "%s: %s",
186 str(LANG_VERSION
), appsversion
);
193 snprintf(buffer
, buffer_len
, "%02d:%02d:%02d %s",
194 global_settings
.timeformat
== 0 ? tm
->tm_hour
:
195 ((tm
->tm_hour
+ 11) % 12) + 1,
198 global_settings
.timeformat
== 0 ? "" :
199 tm
->tm_hour
>11 ? "P" : "A");
203 snprintf(buffer
, buffer_len
, "%s", "--:--:--");
210 snprintf(buffer
, buffer_len
, "%s %d %d",
211 str(LANG_MONTH_JANUARY
+ tm
->tm_mon
),
217 snprintf(buffer
, buffer_len
, "%s", str(LANG_UNKNOWN
));
221 case INFO_BUFFER
: /* buffer */
223 long buflen
= ((audiobufend
- audiobuf
) * 2) / 2097; /* avoid overflow */
224 int integer
= buflen
/ 1000;
225 int decimal
= buflen
% 1000;
226 snprintf(buffer
, buffer_len
, (char *)str(LANG_BUFFER_STAT
),
230 case INFO_BATTERY
: /* battery */
231 #if CONFIG_CHARGING == CHARGING_SIMPLE
232 if (charger_input_state
== CHARGER
)
233 return (char *)str(LANG_BATTERY_CHARGE
);
235 #elif CONFIG_CHARGING >= CHARGING_MONITOR
236 if (charge_state
== CHARGING
)
237 return (char *)str(LANG_BATTERY_CHARGE
);
239 #if CONFIG_CHARGING == CHARGING_CONTROL
240 if (charge_state
== TOPOFF
)
241 return (char *)str(LANG_BATTERY_TOPOFF_CHARGE
);
244 if (charge_state
== TRICKLE
)
245 return (char *)str(LANG_BATTERY_TRICKLE_CHARGE
);
248 if (battery_level() >= 0)
249 snprintf(buffer
, buffer_len
, (char *)str(LANG_BATTERY_TIME
),
250 battery_level(), battery_time() / 60, battery_time() % 60);
254 case INFO_DISK1
: /* disk usage 1 */
255 #ifdef HAVE_MULTIVOLUME
256 output_dyn_value(s1
, sizeof s1
, info
->free
, kbyte_units
, true);
257 output_dyn_value(s2
, sizeof s2
, info
->size
, kbyte_units
, true);
258 snprintf(buffer
, buffer_len
, "%s %s/%s", str(LANG_DISK_NAME_INTERNAL
),
261 output_dyn_value(s1
, sizeof s1
, info
->free
, kbyte_units
, true);
262 snprintf(buffer
, buffer_len
, SIZE_FMT
, str(LANG_DISK_FREE_INFO
), s1
);
265 case INFO_DISK2
: /* disk usage 2 */
266 #ifdef HAVE_MULTIVOLUME
269 output_dyn_value(s1
, sizeof s1
, info
->free2
, kbyte_units
, true);
270 output_dyn_value(s2
, sizeof s2
, info
->size2
, kbyte_units
, true);
271 snprintf(buffer
, buffer_len
, "%s %s/%s", str(LANG_DISK_NAME_MMC
),
276 snprintf(buffer
, buffer_len
, "%s %s", str(LANG_DISK_NAME_MMC
),
277 str(LANG_NOT_PRESENT
));
280 output_dyn_value(s1
, sizeof s1
, info
->size
, kbyte_units
, true);
281 snprintf(buffer
, buffer_len
, SIZE_FMT
, str(LANG_DISK_SIZE_INFO
), s1
);
288 static int info_speak_item(int selected_item
, void * data
)
290 struct info_data
*info
= (struct info_data
*)data
;
296 switch (selected_item
)
298 case INFO_VERSION
: /* version */
299 talk_id(LANG_VERSION
, false);
300 talk_spell(appsversion
, true);
305 talk_id(VOICE_CURRENT_TIME
, false);
312 talk_id(LANG_UNKNOWN
, true);
319 talk_date(get_time(), true);
323 talk_id(LANG_UNKNOWN
, true);
327 case INFO_BUFFER
: /* buffer */
329 talk_id(LANG_BUFFER_STAT
, false);
330 long buflen
= ((audiobufend
- audiobuf
) * 2) / 2097; /* avoid overflow */
331 output_dyn_value(NULL
, 0, buflen
, kbyte_units
, true);
334 case INFO_BATTERY
: /* battery */
335 #if CONFIG_CHARGING == CHARGING_SIMPLE
336 if (charger_input_state
== CHARGER
)
337 talk_id(LANG_BATTERY_CHARGE
, true);
339 #elif CONFIG_CHARGING >= CHARGING_MONITOR
340 if (charge_state
== CHARGING
)
341 talk_id(LANG_BATTERY_CHARGE
, true);
343 #if CONFIG_CHARGING == CHARGING_CONTROL
344 if (charge_state
== TOPOFF
)
345 talk_id(LANG_BATTERY_TOPOFF_CHARGE
, true);
348 if (charge_state
== TRICKLE
)
349 talk_id(LANG_BATTERY_TRICKLE_CHARGE
, true);
352 if (battery_level() >= 0)
354 talk_id(LANG_BATTERY_TIME
, false);
355 talk_value(battery_level(), UNIT_PERCENT
, true);
356 talk_value(battery_time() *60, UNIT_TIME
, true);
358 else talk_id(VOICE_BLANK
, false);
360 case INFO_DISK1
: /* disk 1 */
361 #ifdef HAVE_MULTIVOLUME
362 talk_id(LANG_DISK_NAME_INTERNAL
, false);
363 talk_id(LANG_DISK_FREE_INFO
, true);
364 output_dyn_value(NULL
, 0, info
->free
, kbyte_units
, true);
365 talk_id(LANG_DISK_SIZE_INFO
, true);
366 output_dyn_value(NULL
, 0, info
->size
, kbyte_units
, true);
368 talk_id(LANG_DISK_FREE_INFO
, false);
369 output_dyn_value(NULL
, 0, info
->free
, kbyte_units
, true);
372 case INFO_DISK2
: /* disk 2 */
373 #ifdef HAVE_MULTIVOLUME
374 talk_id(LANG_DISK_NAME_MMC
, false);
377 talk_id(LANG_DISK_FREE_INFO
, true);
378 output_dyn_value(NULL
, 0, info
->free2
, kbyte_units
, true);
379 talk_id(LANG_DISK_SIZE_INFO
, true);
380 output_dyn_value(NULL
, 0, info
->size2
, kbyte_units
, true);
382 else talk_id(LANG_NOT_PRESENT
, true);
384 talk_id(LANG_DISK_SIZE_INFO
, false);
385 output_dyn_value(NULL
, 0, info
->size
, kbyte_units
, true);
392 static int info_action_callback(int action
, struct gui_synclist
*lists
)
394 if (action
== ACTION_STD_CANCEL
)
396 else if ((action
== ACTION_STD_OK
)
397 #ifdef HAVE_MULTIVOLUME
398 || action
== SYS_HOTSWAP_INSERTED
399 || action
== SYS_HOTSWAP_EXTRACTED
404 struct info_data
*info
= (struct info_data
*)lists
->data
;
405 info
->new_data
= true;
406 gui_syncsplash(0, ID2P(LANG_SCANNING_DISK
));
407 fat_recalc_free(IF_MV(0));
408 #ifdef HAVE_MULTIVOLUME
409 if (fat_ismounted(1))
417 return ACTION_REDRAW
;
420 else if (action
== ACTION_NONE
&& lists
->selected_item
== INFO_TIME
)
422 static int last_redraw
= 0;
423 if (TIME_AFTER(current_tick
, last_redraw
+ HZ
/2))
425 last_redraw
= current_tick
;
426 return ACTION_REDRAW
;
432 static bool show_info(void)
434 struct info_data data
= {.new_data
= true };
435 struct simplelist_info info
;
436 simplelist_info_init(&info
, str(LANG_ROCKBOX_INFO
), INFO_COUNT
, (void*)&data
);
437 info
.hide_selection
= !global_settings
.talk_menu
;
438 if (info
.hide_selection
)
439 info
.scroll_all
= true;
440 info
.get_name
= info_getname
;
441 if(global_settings
.talk_menu
)
442 info
.get_talk
= info_speak_item
;
443 info
.action_callback
= info_action_callback
;
444 return simplelist_show_list(&info
);
446 MENUITEM_FUNCTION(show_info_item
, 0, ID2P(LANG_ROCKBOX_INFO
),
447 (menu_function
)show_info
, NULL
, NULL
, Icon_NOICON
);
451 static void sleep_timer_formatter(char* buffer
, size_t buffer_size
, int value
,
460 minutes
= value
- (hours
* 60);
461 snprintf(buffer
, buffer_size
, "%d:%02d", hours
, minutes
);
463 snprintf(buffer
, buffer_size
, "%s", str(LANG_OFF
));
467 static void sleep_timer_set(int minutes
)
469 set_sleep_timer(minutes
* 60);
472 static int sleep_timer(void)
474 int minutes
= (get_sleep_timer() + 59) / 60; /* round up */
475 return (int)set_int(str(LANG_SLEEP_TIMER
), "", UNIT_MIN
, &minutes
,
476 &sleep_timer_set
, -5, 300, 0, sleep_timer_formatter
);
479 MENUITEM_FUNCTION(sleep_timer_call
, 0, ID2P(LANG_SLEEP_TIMER
), sleep_timer
,
480 NULL
, NULL
, Icon_Menu_setting
); /* make it look like a
481 setting to the user */
482 MENUITEM_FUNCTION(show_credits_item
, 0, ID2P(LANG_VERSION
),
483 (menu_function
)show_credits
, NULL
, NULL
, Icon_NOICON
);
484 MENUITEM_FUNCTION(show_runtime_item
, 0, ID2P(LANG_RUNNING_TIME
),
485 (menu_function
)view_runtime
, NULL
, NULL
, Icon_NOICON
);
486 MENUITEM_FUNCTION(debug_menu_item
, 0, ID2P(LANG_DEBUG
),
487 (menu_function
)debug_menu
, NULL
, NULL
, Icon_NOICON
);
489 MAKE_MENU(info_menu
, ID2P(LANG_SYSTEM
), 0, Icon_Questionmark
,
490 &show_info_item
, &show_credits_item
, &show_runtime_item
,
491 &sleep_timer_call
, &debug_menu_item
);
493 /***********************************/
495 /***********************************/
499 #ifdef HAVE_LCD_CHARCELLS
500 int mainmenu_callback(int action
,const struct menu_item_ex
*this_item
)
505 case ACTION_ENTER_MENUITEM
:
506 status_set_param(true);
508 case ACTION_EXIT_MENUITEM
:
509 status_set_param(false);
515 #define mainmenu_callback NULL
517 MAKE_MENU(main_menu_
, ID2P(LANG_SETTINGS
), mainmenu_callback
,
518 Icon_Submenu_Entered
,
520 &settings_menu_item
, &theme_menu
,
521 #ifdef HAVE_RECORDING
527 /***********************************/