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 ****************************************************************************/
31 #include "powermgmt.h"
34 #include "exported_menus.h"
38 #include "recording.h"
47 #include "debug_menu.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
[]={
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
))
79 settings_apply_skins();
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 /***********************************/
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 */
122 while (IS_SYSEVENT(get_action(CONTEXT_STD
, TIMEOUT_BLOCK
)))
128 #ifdef HAVE_LCD_CHARCELLS
129 #define SIZE_FMT "%s%s"
131 #define SIZE_FMT "%s %s"
139 #ifdef HAVE_MULTIVOLUME
147 INFO_DISK1
, /* capacity or internal capacity/free on hotswap */
148 INFO_DISK2
, /* free space or external capacity/free on hotswap */
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
;
159 #if defined(HAVE_MULTIVOLUME)
164 fat_size(IF_MV2(0,) &info
->size
, &info
->free
);
165 #ifdef HAVE_MULTIVOLUME
166 if (fat_ismounted(1))
167 fat_size(1, &info
->size2
, &info
->free2
);
171 info
->new_data
= false;
173 switch (selected_item
)
176 snprintf(buffer
, buffer_len
, "%s: %s",
177 str(LANG_VERSION
), rbversion
);
180 case INFO_BUFFER
: /* buffer */
182 long kib
= audio_buffer_available() / 1024; /* to KiB */
183 output_dyn_value(s1
, sizeof(s1
), kib
, kbyte_units
, true);
184 snprintf(buffer
, buffer_len
, "%s %s", str(LANG_BUFFER_STAT
), s1
);
187 case INFO_BATTERY
: /* battery */
188 #if CONFIG_CHARGING == CHARGING_SIMPLE
189 /* Only know if plugged */
190 if (charger_inserted())
191 return str(LANG_BATTERY_CHARGE
);
193 #elif CONFIG_CHARGING >= CHARGING_MONITOR
194 #ifdef ARCHOS_RECORDER
195 /* Report the particular algorithm state */
196 if (charge_state
== CHARGING
)
197 return str(LANG_BATTERY_CHARGE
);
198 else if (charge_state
== TOPOFF
)
199 return str(LANG_BATTERY_TOPOFF_CHARGE
);
200 else if (charge_state
== TRICKLE
)
201 return str(LANG_BATTERY_TRICKLE_CHARGE
);
203 #else /* !ARCHOS_RECORDER */
204 /* Go by what power management reports */
205 if (charging_state())
206 return str(LANG_BATTERY_CHARGE
);
208 #endif /* ARCHOS_RECORDER */
209 #endif /* CONFIG_CHARGING = */
210 if (battery_level() >= 0)
211 snprintf(buffer
, buffer_len
, str(LANG_BATTERY_TIME
),
212 battery_level(), battery_time() / 60, battery_time() % 60);
216 case INFO_DISK1
: /* disk usage 1 */
217 #ifdef HAVE_MULTIVOLUME
218 output_dyn_value(s1
, sizeof s1
, info
->free
, kbyte_units
, true);
219 output_dyn_value(s2
, sizeof s2
, info
->size
, kbyte_units
, true);
220 snprintf(buffer
, buffer_len
, "%s %s/%s", str(LANG_DISK_NAME_INTERNAL
),
223 output_dyn_value(s1
, sizeof s1
, info
->free
, kbyte_units
, true);
224 snprintf(buffer
, buffer_len
, SIZE_FMT
, str(LANG_DISK_FREE_INFO
), s1
);
227 case INFO_DISK2
: /* disk usage 2 */
228 #ifdef HAVE_MULTIVOLUME
231 output_dyn_value(s1
, sizeof s1
, info
->free2
, kbyte_units
, true);
232 output_dyn_value(s2
, sizeof s2
, info
->size2
, kbyte_units
, true);
233 snprintf(buffer
, buffer_len
, "%s %s/%s", str(LANG_DISK_NAME_MMC
),
238 snprintf(buffer
, buffer_len
, "%s %s", str(LANG_DISK_NAME_MMC
),
239 str(LANG_NOT_PRESENT
));
242 output_dyn_value(s1
, sizeof s1
, info
->size
, kbyte_units
, true);
243 snprintf(buffer
, buffer_len
, SIZE_FMT
, str(LANG_DISK_SIZE_INFO
), s1
);
250 static int info_speak_item(int selected_item
, void * data
)
252 struct info_data
*info
= (struct info_data
*)data
;
254 switch (selected_item
)
256 case INFO_VERSION
: /* version */
257 talk_id(LANG_VERSION
, false);
258 talk_spell(rbversion
, true);
261 case INFO_BUFFER
: /* buffer */
263 talk_id(LANG_BUFFER_STAT
, false);
264 long kib
= audio_buffer_available() / 1024; /* to KiB */
265 output_dyn_value(NULL
, 0, kib
, kbyte_units
, true);
268 case INFO_BATTERY
: /* battery */
269 #if CONFIG_CHARGING == CHARGING_SIMPLE
270 /* Only know if plugged */
271 if (charger_inserted())
272 talk_id(LANG_BATTERY_CHARGE
, true);
274 #elif CONFIG_CHARGING >= CHARGING_MONITOR
275 #ifdef ARCHOS_RECORDER
276 /* Report the particular algorithm state */
277 if (charge_state
== CHARGING
)
278 talk_id(LANG_BATTERY_CHARGE
, true);
279 else if (charge_state
== TOPOFF
)
280 talk_id(LANG_BATTERY_TOPOFF_CHARGE
, true);
281 else if (charge_state
== TRICKLE
)
282 talk_id(LANG_BATTERY_TRICKLE_CHARGE
, true);
284 #else /* !ARCHOS_RECORDER */
285 /* Go by what power management reports */
286 if (charging_state())
287 talk_id(LANG_BATTERY_CHARGE
, true);
289 #endif /* ARCHOS_RECORDER */
290 #endif /* CONFIG_CHARGING = */
291 if (battery_level() >= 0)
293 talk_id(LANG_BATTERY_TIME
, false);
294 talk_value(battery_level(), UNIT_PERCENT
, true);
295 talk_value(battery_time() *60, UNIT_TIME
, true);
297 else talk_id(VOICE_BLANK
, false);
299 case INFO_DISK1
: /* disk 1 */
300 #ifdef HAVE_MULTIVOLUME
301 talk_ids(false, LANG_DISK_NAME_INTERNAL
, LANG_DISK_FREE_INFO
);
302 output_dyn_value(NULL
, 0, info
->free
, kbyte_units
, true);
303 talk_id(LANG_DISK_SIZE_INFO
, true);
304 output_dyn_value(NULL
, 0, info
->size
, kbyte_units
, true);
306 talk_id(LANG_DISK_FREE_INFO
, false);
307 output_dyn_value(NULL
, 0, info
->free
, kbyte_units
, true);
310 case INFO_DISK2
: /* disk 2 */
311 #ifdef HAVE_MULTIVOLUME
312 talk_id(LANG_DISK_NAME_MMC
, false);
315 talk_id(LANG_DISK_FREE_INFO
, true);
316 output_dyn_value(NULL
, 0, info
->free2
, kbyte_units
, true);
317 talk_id(LANG_DISK_SIZE_INFO
, true);
318 output_dyn_value(NULL
, 0, info
->size2
, kbyte_units
, true);
320 else talk_id(LANG_NOT_PRESENT
, true);
322 talk_id(LANG_DISK_SIZE_INFO
, false);
323 output_dyn_value(NULL
, 0, info
->size
, kbyte_units
, true);
331 static int info_action_callback(int action
, struct gui_synclist
*lists
)
333 if (action
== ACTION_STD_CANCEL
)
335 else if ((action
== ACTION_STD_OK
)
337 || action
== SYS_FS_CHANGED
341 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
342 struct info_data
*info
= (struct info_data
*)lists
->data
;
344 info
->new_data
= true;
345 splash(0, ID2P(LANG_SCANNING_DISK
));
346 for (i
= 0; i
< NUM_VOLUMES
; i
++)
349 if (fat_ismounted(i
))
351 fat_recalc_free(IF_MV(i
));
356 gui_synclist_speak_item(lists
);
357 return ACTION_REDRAW
;
361 static bool show_info(void)
363 struct info_data data
= {.new_data
= true };
364 struct simplelist_info info
;
365 simplelist_info_init(&info
, str(LANG_ROCKBOX_INFO
), INFO_COUNT
, (void*)&data
);
366 info
.hide_selection
= !global_settings
.talk_menu
;
367 if (info
.hide_selection
)
368 info
.scroll_all
= true;
369 info
.get_name
= info_getname
;
370 if(global_settings
.talk_menu
)
371 info
.get_talk
= info_speak_item
;
372 info
.action_callback
= info_action_callback
;
373 return simplelist_show_list(&info
);
375 MENUITEM_FUNCTION(show_info_item
, 0, ID2P(LANG_ROCKBOX_INFO
),
376 (menu_function
)show_info
, NULL
, NULL
, Icon_NOICON
);
380 static const char* sleep_timer_formatter(char* buffer
, size_t buffer_size
,
381 int value
, const char* unit
)
388 minutes
= value
- (hours
* 60);
389 snprintf(buffer
, buffer_size
, "%d:%02d", hours
, minutes
);
392 return str(LANG_OFF
);
396 static void sleep_timer_set(int minutes
)
399 global_settings
.sleeptimer_duration
= minutes
;
400 set_sleep_timer(minutes
* 60);
403 static int sleep_timer(void)
405 int minutes
= global_settings
.sleeptimer_duration
;
406 if (get_sleep_timer())
409 set_int(str(LANG_SLEEP_TIMER
), "", UNIT_MIN
, &minutes
,
410 &sleep_timer_set
, 5, 0, 300, sleep_timer_formatter
);
414 static int seconds_to_min(int secs
)
416 return (secs
+ 10) / 60; /* round up for 50+ seconds */
419 static char* sleep_timer_getname(int selected_item
, void * data
, char *buffer
)
423 int sec
= get_sleep_timer();
425 /* we have no sprintf, so MAX_PATH is a guess */
427 { /* show cancel and countdown if running */
428 snprintf(buffer
, MAX_PATH
, "%s (%s)", str(LANG_SLEEP_TIMER_CANCEL_CURRENT
),
429 sleep_timer_formatter(timer_buf
, sizeof(timer_buf
), seconds_to_min(sec
), NULL
));
432 snprintf(buffer
, MAX_PATH
, "%s", str(LANG_SLEEP_TIMER
));
437 static int sleep_timer_voice(int selected_item
, void*data
)
441 int seconds
= get_sleep_timer();
445 LANG_SLEEP_TIMER_CANCEL_CURRENT
,
447 seconds_to_min(seconds
) | UNIT_MIN
<< UNIT_SHIFT
,
450 talk_idarray(talk_ids
, true);
453 talk_id(LANG_SLEEP_TIMER
, true);
458 int time_screen(void* ignored
);
459 MENUITEM_FUNCTION(timedate_item
, MENU_FUNC_CHECK_RETVAL
, ID2P(LANG_TIME_MENU
),
460 time_screen
, NULL
, NULL
, Icon_Menu_setting
);
462 MENUITEM_FUNCTION_DYNTEXT(sleep_timer_call
, 0, sleep_timer
, NULL
, sleep_timer_getname
,
463 sleep_timer_voice
, NULL
, NULL
, Icon_Menu_setting
);
464 /* make it look like a setting to the user */
466 MENUITEM_SETTING(sleeptimer_on_startup
,
467 &global_settings
.sleeptimer_on_startup
, NULL
);
470 MENUITEM_FUNCTION(show_credits_item
, 0, ID2P(LANG_CREDITS
),
471 (menu_function
)show_credits
, NULL
, NULL
, Icon_NOICON
);
472 MENUITEM_FUNCTION(show_runtime_item
, 0, ID2P(LANG_RUNNING_TIME
),
473 (menu_function
)view_runtime
, NULL
, NULL
, Icon_NOICON
);
474 MENUITEM_FUNCTION(debug_menu_item
, 0, ID2P(LANG_DEBUG
),
475 (menu_function
)debug_menu
, NULL
, NULL
, Icon_NOICON
);
477 MAKE_MENU(info_menu
, ID2P(LANG_SYSTEM
), 0, Icon_System_menu
,
478 &show_info_item
, &show_credits_item
,
479 &show_runtime_item
, &debug_menu_item
);
481 /***********************************/
483 /***********************************/
487 #ifdef HAVE_LCD_CHARCELLS
488 static int mainmenu_callback(int action
,const struct menu_item_ex
*this_item
)
493 case ACTION_ENTER_MENUITEM
:
494 status_set_param(true);
496 case ACTION_EXIT_MENUITEM
:
497 status_set_param(false);
503 #define mainmenu_callback NULL
505 MAKE_MENU(main_menu_
, ID2P(LANG_SETTINGS
), mainmenu_callback
,
506 Icon_Submenu_Entered
,
509 &settings_menu_item
, &theme_menu
,
510 #ifdef HAVE_RECORDING
516 &sleep_timer_call
, &sleeptimer_on_startup
,
521 /***********************************/